| 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 | |
|
| 31 | |
public class ExamplesTableFactory { |
| 32 | |
|
| 33 | |
private final Keywords keywords; |
| 34 | |
private final ResourceLoader resourceLoader; |
| 35 | |
private final ParameterConverters parameterConverters; |
| 36 | |
private final TableTransformers tableTransformers; |
| 37 | |
|
| 38 | |
public ExamplesTableFactory() { |
| 39 | 624 | this(new LocalizedKeywords()); |
| 40 | 624 | } |
| 41 | |
|
| 42 | |
public ExamplesTableFactory(Keywords keywords) { |
| 43 | 624 | this(keywords, new LoadFromClasspath(), new ParameterConverters(), new TableTransformers()); |
| 44 | 624 | } |
| 45 | |
|
| 46 | |
public ExamplesTableFactory(ResourceLoader resourceLoader) { |
| 47 | 1 | this(new LocalizedKeywords(), resourceLoader, new ParameterConverters(), new TableTransformers()); |
| 48 | 1 | } |
| 49 | |
|
| 50 | |
public ExamplesTableFactory(ParameterConverters parameterConverters) { |
| 51 | 1019 | this(new LocalizedKeywords(), new LoadFromClasspath(), parameterConverters, new TableTransformers()); |
| 52 | 1019 | } |
| 53 | |
|
| 54 | |
public ExamplesTableFactory(TableTransformers tableTransformers) { |
| 55 | 2 | this(new LocalizedKeywords(), new LoadFromClasspath(), new ParameterConverters(), tableTransformers); |
| 56 | 2 | } |
| 57 | |
|
| 58 | |
public ExamplesTableFactory(Keywords keywords, ResourceLoader resourceLoader, |
| 59 | |
ParameterConverters parameterConverters) { |
| 60 | 0 | this(keywords, resourceLoader, parameterConverters, new TableTransformers()); |
| 61 | 0 | } |
| 62 | |
|
| 63 | |
public ExamplesTableFactory(Keywords keywords, ResourceLoader resourceLoader, |
| 64 | 1646 | ParameterConverters parameterConverters, TableTransformers tableTranformers) { |
| 65 | 1646 | this.keywords = keywords; |
| 66 | 1646 | this.resourceLoader = resourceLoader; |
| 67 | 1646 | this.parameterConverters = parameterConverters; |
| 68 | 1646 | this.tableTransformers = tableTranformers; |
| 69 | 1646 | } |
| 70 | |
|
| 71 | |
public ExamplesTable createExamplesTable(String input) { |
| 72 | |
String tableAsString; |
| 73 | 153 | if (isBlank(input) || isTable(input)) { |
| 74 | 152 | tableAsString = input; |
| 75 | |
} else { |
| 76 | 1 | tableAsString = resourceLoader.loadResourceAsText(input); |
| 77 | |
} |
| 78 | 153 | return new ExamplesTable(tableAsString, keywords.examplesTableHeaderSeparator(), |
| 79 | |
keywords.examplesTableValueSeparator(), keywords.examplesTableIgnorableSeparator(), |
| 80 | |
parameterConverters, tableTransformers); |
| 81 | |
} |
| 82 | |
|
| 83 | |
protected boolean isTable(String input) { |
| 84 | 23 | return input.contains(keywords.examplesTableHeaderSeparator()); |
| 85 | |
} |
| 86 | |
|
| 87 | |
} |