1 | |
package org.jbehave.core.model; |
2 | |
|
3 | |
import org.jbehave.core.configuration.Configuration; |
4 | |
import org.jbehave.core.configuration.Keywords; |
5 | |
import org.jbehave.core.i18n.LocalizedKeywords; |
6 | |
import org.jbehave.core.io.LoadFromClasspath; |
7 | |
import org.jbehave.core.io.ResourceLoader; |
8 | |
import org.jbehave.core.steps.ParameterConverters; |
9 | |
|
10 | |
import static org.apache.commons.lang.StringUtils.isBlank; |
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public class ExamplesTableFactory { |
31 | |
|
32 | |
private final Keywords keywords; |
33 | |
private final ResourceLoader resourceLoader; |
34 | |
private final ParameterConverters parameterConverters; |
35 | |
|
36 | |
public ExamplesTableFactory() { |
37 | 487 | this(new LocalizedKeywords()); |
38 | 487 | } |
39 | |
|
40 | |
public ExamplesTableFactory(Keywords keywords) { |
41 | 487 | this(keywords, new LoadFromClasspath(), new ParameterConverters()); |
42 | 487 | } |
43 | |
|
44 | |
public ExamplesTableFactory(ParameterConverters parameterConverters) { |
45 | 794 | this(new LocalizedKeywords(), new LoadFromClasspath(), parameterConverters); |
46 | 794 | } |
47 | |
|
48 | |
public ExamplesTableFactory(ResourceLoader resourceLoader) { |
49 | 1 | this(new LocalizedKeywords(), resourceLoader, new ParameterConverters()); |
50 | 1 | } |
51 | |
|
52 | |
public ExamplesTableFactory(Keywords keywords, ResourceLoader resourceLoader, |
53 | 1282 | ParameterConverters parameterConverters) { |
54 | 1282 | this.keywords = keywords; |
55 | 1282 | this.resourceLoader = resourceLoader; |
56 | 1282 | this.parameterConverters = parameterConverters; |
57 | 1282 | } |
58 | |
|
59 | |
public ExamplesTable createExamplesTable(String input) { |
60 | |
String tableAsString; |
61 | 127 | if (isBlank(input) || isTable(input)) { |
62 | 126 | tableAsString = input; |
63 | |
} else { |
64 | 1 | tableAsString = resourceLoader.loadResourceAsText(input); |
65 | |
} |
66 | 127 | return new ExamplesTable(tableAsString, keywords.examplesTableHeaderSeparator(), |
67 | |
keywords.examplesTableValueSeparator(), keywords.examplesTableIgnorableSeparator(), parameterConverters); |
68 | |
} |
69 | |
|
70 | |
protected boolean isTable(String input) { |
71 | 9 | return input.contains(keywords.examplesTableHeaderSeparator()); |
72 | |
} |
73 | |
|
74 | |
} |