Author: tfennelly
Date: 2010-01-14 15:40:36 -0500 (Thu, 14 Jan 2010)
New Revision: 19758
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.core/src/org/jboss/tools/smooks10/model/smooks/util/SmooksModelUtils.java
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/template/csv/CSVFreeMarkerTemplateBuilder.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/freemarker/FreemarkerCSVContentGenerator.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/template/FreemarkerTemplateContentGraphModelProviderImpl.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/FreemarkerCSVCreationWizardPage.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/FreemarkerCSVTemplateCreationWizard.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/Messages.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/messages.properties
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLauncher.java
trunk/smooks/tests/org.jboss.tools.smooks.templating.test/src/org/jboss/tools/smooks/templating/template/csv/CSVFreeMarkerTemplateBuilderTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5379
Support adding the CSV field names as the first record produced by a CSV template
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.core/src/org/jboss/tools/smooks10/model/smooks/util/SmooksModelUtils.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.core/src/org/jboss/tools/smooks10/model/smooks/util/SmooksModelUtils.java 2010-01-14
17:49:29 UTC (rev 19757)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.core/src/org/jboss/tools/smooks10/model/smooks/util/SmooksModelUtils.java 2010-01-14
20:40:36 UTC (rev 19758)
@@ -50,6 +50,8 @@
public static final String KEY_CSV_FIELDS = "csvFields"; //$NON-NLS-1$
+ public static final String KEY_INCLUDE_FIELD_NAMES = "includeFieldNames";
//$NON-NLS-1$
+
public static final String KEY_TASK_ID_REF = "idref"; //$NON-NLS-1$
public static final String KEY_OBJECT_ID = "id"; //$NON-NLS-1$
@@ -611,6 +613,18 @@
return 0;
}
+ public static boolean getFreemarkerCSVIncludeFieldNames(Freemarker freemarker) {
+ org.jboss.tools.smooks.model.smooks.ParamType typeParam =
getParam(freemarker.getParam(), KEY_INCLUDE_FIELD_NAMES);
+ if (typeParam != null) {
+ String value = typeParam.getStringValue();
+ if (value != null) {
+ return value.equals("true");
+ }
+ }
+
+ return false;
+ }
+
public static String getFreemarkerXMLFileType(Freemarker freemarker) {
org.jboss.tools.smooks.model.smooks.ParamType typeParam =
getParam(freemarker.getParam(), KEY_XML_FILE_TYPE);
if (typeParam != null) {
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/template/csv/CSVFreeMarkerTemplateBuilder.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/template/csv/CSVFreeMarkerTemplateBuilder.java 2010-01-14
17:49:29 UTC (rev 19757)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.templating/src/org/jboss/tools/smooks/templating/template/csv/CSVFreeMarkerTemplateBuilder.java 2010-01-14
20:40:36 UTC (rev 19758)
@@ -32,6 +32,7 @@
import org.jboss.tools.smooks.templating.template.exception.TemplateBuilderException;
import
org.jboss.tools.smooks.templating.template.exception.UnmappedCollectionNodeException;
import org.jboss.tools.smooks.templating.template.util.FreeMarkerUtil;
+import org.milyn.xml.DomUtils;
import au.com.bytecode.opencsv.CSVReader;
@@ -47,19 +48,22 @@
public class CSVFreeMarkerTemplateBuilder extends TemplateBuilder {
private char separatorChar;
- private char quoteChar;
+ private char quoteChar;
+ private boolean includeFieldNames;
/**
* Construct a new FreeMarker Template Builder with no mappings.
* @param model The model.
* @param separatorChar The CSV field separator character.
* @param quoteChar The CSV field quote character.
+ * @param includeFieldNames True if field names are to be added at the start of the
generated message, otherwise false.
* @throws ModelBuilderException Error building model.
*/
- public CSVFreeMarkerTemplateBuilder(ModelBuilder modelBuilder, char separatorChar,
char quoteChar) throws ModelBuilderException {
+ public CSVFreeMarkerTemplateBuilder(ModelBuilder modelBuilder, char separatorChar,
char quoteChar, boolean includeFieldNames) throws ModelBuilderException {
super(modelBuilder);
this.separatorChar = separatorChar;
this.quoteChar = quoteChar;
+ this.includeFieldNames = includeFieldNames;
}
/**
@@ -68,12 +72,13 @@
* @param model The model.
* @param separatorChar The CSV field separator character.
* @param quoteChar The CSV field quote character.
+ * @param includeFieldNames True if field names are to be added at the start of the
generated message, otherwise false.
* @param ftlTemplate The FreeMarker Template from which the mappings are to be
extracted.
* @throws ModelBuilderException Error building model.
* @throws TemplateBuilderException Error adding mappings extracted from template.
*/
- public CSVFreeMarkerTemplateBuilder(ModelBuilder modelBuilder, char separatorChar,
char quoteChar, String ftlTemplate) throws ModelBuilderException, TemplateBuilderException
{
- this(modelBuilder, separatorChar, quoteChar);
+ public CSVFreeMarkerTemplateBuilder(ModelBuilder modelBuilder, char separatorChar,
char quoteChar, boolean includeFieldNames, String ftlTemplate) throws
ModelBuilderException, TemplateBuilderException {
+ this(modelBuilder, separatorChar, quoteChar, includeFieldNames);
addMappings(ftlTemplate);
}
@@ -86,18 +91,41 @@
throw new TemplateBuilderException ("Failed to parse the Supplied FreeMarker
template.", e); //$NON-NLS-1$
}
- TemplateElement listElement = template.getRootTreeNode();
- if(!listElement.getNodeName().equals("IteratorBlock") ||
!listElement.getDescription().startsWith("list")) { //$NON-NLS-1$
- throw new TemplateBuilderException ("Unable to recognize template as being a CSV
template. Expecting first template token to be a 'list' IteratorBlock
node."); //$NON-NLS-1$
+ TemplateElement listNode = findListNode(template.getRootTreeNode());
+ if(listNode == null) { //$NON-NLS-1$
+ throw new TemplateBuilderException ("Unable to recognize template as being a CSV
template"); //$NON-NLS-1$
}
// Add the mapping for the list itself...
- addCSVListMapping(listElement.getDescription());
+ addCSVListMapping(listNode.getDescription());
// Add the mappings for the individual fields...
- addCSVFieldMappings(listElement);
+ addCSVFieldMappings(listNode);
}
+ private TemplateElement findListNode(TemplateElement templateNode) throws
TemplateBuilderException {
+ if(templateNode.getNodeName().equals("IteratorBlock")) {
+ String description = templateNode.getDescription();
+ if(!description.startsWith("list")) { //$NON-NLS-1$
+ throw new TemplateBuilderException ("Unsupported CSV template IteratorBlock type
'" + description + "'. Currently only support 'list'
IteratorBlock nodes."); //$NON-NLS-1$
+ }
+ return templateNode;
+ } else {
+ Enumeration<TemplateElement> children = templateNode.children();
+
+ if(children != null && children.hasMoreElements()) {
+ while(children.hasMoreElements()) {
+ TemplateElement listNode = findListNode(children.nextElement());
+ if(listNode != null) {
+ return listNode;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
private void addCSVListMapping(String description) throws TemplateBuilderException {
String[] tokens = description.split(" +?"); //$NON-NLS-1$
Element csvRecordElement = getModel().getDocumentElement();
@@ -149,9 +177,27 @@
} else {
StringBuilder template = new StringBuilder();
NodeList nodeList = recordElement.getChildNodes();
- int fieldIndex = 0;
+
+ if(includeFieldNames) {
+ int fieldIndex = 0;
+ for(int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if(node.getNodeType() == Node.ELEMENT_NODE) {
+ if(fieldIndex > 0) {
+ template.append(separatorChar);
+ }
+ template.append(quoteChar);
+ template.append(DomUtils.getName((Element) node));
+ template.append(quoteChar);
+ fieldIndex++;
+ }
+ }
+ template.append('\n');
+ }
+
template.append("<#list " + collectionMapping.getSrcPath() +
" as " + collectionMapping.getCollectionItemName() + ">\n");
//$NON-NLS-1$
+ int fieldIndex = 0;
for(int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if(node.getNodeType() == Node.ELEMENT_NODE) {
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/freemarker/FreemarkerCSVContentGenerator.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/freemarker/FreemarkerCSVContentGenerator.java 2010-01-14
17:49:29 UTC (rev 19757)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/freemarker/FreemarkerCSVContentGenerator.java 2010-01-14
20:40:36 UTC (rev 19758)
@@ -80,6 +80,7 @@
char sperator = SmooksModelUtils.getFreemarkerCSVSeperator((Freemarker) freemarker);
char quote = SmooksModelUtils.getFreemarkerCSVQuote((Freemarker) freemarker);
+ boolean includeFieldNames =
SmooksModelUtils.getFreemarkerCSVIncludeFieldNames((Freemarker) freemarker);
List<AbstractSmooksGraphicalModel> childrenGraphModel =
csvRecordGraphicalModel.getChildren();
List<String> fieldsName = new ArrayList<String>();
@@ -96,7 +97,7 @@
CSVFreeMarkerTemplateBuilder builder;
Document model;
- builder = new CSVFreeMarkerTemplateBuilder(modelBuilder, sperator, quote);
+ builder = new CSVFreeMarkerTemplateBuilder(modelBuilder, sperator, quote,
includeFieldNames);
model = builder.getModel();
List<TreeNodeConnection> connections =
csvRecordGraphicalModel.getTargetConnections();
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/template/FreemarkerTemplateContentGraphModelProviderImpl.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/template/FreemarkerTemplateContentGraphModelProviderImpl.java 2010-01-14
17:49:29 UTC (rev 19757)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/template/FreemarkerTemplateContentGraphModelProviderImpl.java 2010-01-14
20:40:36 UTC (rev 19758)
@@ -131,10 +131,12 @@
try {
builder1 = new CSVFreeMarkerTemplateBuilder(modelBuilder, SmooksModelUtils
.getFreemarkerCSVSeperator(freemarker),
SmooksModelUtils.getFreemarkerCSVQuote(freemarker),
+ SmooksModelUtils.getFreemarkerCSVIncludeFieldNames(freemarker),
contents);
} catch (Exception e) {
builder1 = new CSVFreeMarkerTemplateBuilder(modelBuilder, SmooksModelUtils
- .getFreemarkerCSVSeperator(freemarker),
SmooksModelUtils.getFreemarkerCSVQuote(freemarker));
+ .getFreemarkerCSVSeperator(freemarker),
SmooksModelUtils.getFreemarkerCSVQuote(freemarker),
+ SmooksModelUtils.getFreemarkerCSVIncludeFieldNames(freemarker));
}
templateBuilder = builder1;
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/FreemarkerCSVCreationWizardPage.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/FreemarkerCSVCreationWizardPage.java 2010-01-14
17:49:29 UTC (rev 19757)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/FreemarkerCSVCreationWizardPage.java 2010-01-14
20:40:36 UTC (rev 19758)
@@ -23,6 +23,7 @@
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
@@ -37,9 +38,8 @@
private Text seperatorText;
private Text quoteText;
private Text fieldsText;
+ private Button includeFieldNames;
-
-
public FreemarkerCSVCreationWizardPage(String pageName, String title, ImageDescriptor
titleImage) {
super(pageName, title, titleImage);
}
@@ -79,6 +79,10 @@
return quoteText;
}
+ public Button getIncludeFieldNames() {
+ return includeFieldNames;
+ }
+
/*
* (non-Javadoc)
*
@@ -96,26 +100,32 @@
layout.numColumns = 2;
mainComposite.setLayout(layout);
+ Label filedsLabel = new Label(mainComposite, SWT.NONE);
+ filedsLabel.setText(Messages.FreemarkerCSVCreationWizardPage_FieldsGroupText);
+ fieldsText = new Text(mainComposite, SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ fieldsText.setLayoutData(gd);
+
Label seperatorLabel = new Label(mainComposite, SWT.NONE);
seperatorLabel.setText(Messages.FreemarkerCSVCreationWizardPage_SeperatorCharLabel);
seperatorText = new Text(mainComposite, SWT.BORDER);
- gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd = new GridData(GridData.BEGINNING);
seperatorText.setLayoutData(gd);
seperatorText.setTextLimit(1);
Label quoteLabel = new Label(mainComposite, SWT.NONE);
quoteLabel.setText(Messages.FreemarkerCSVCreationWizardPage_QuoteCharLabel);
quoteText = new Text(mainComposite, SWT.BORDER);
- gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd = new GridData(GridData.BEGINNING);
quoteText.setLayoutData(gd);
quoteText.setTextLimit(1);
-
- Label filedsLabel = new Label(mainComposite, SWT.NONE);
- filedsLabel.setText(Messages.FreemarkerCSVCreationWizardPage_FieldsGroupText);
- fieldsText = new Text(mainComposite, SWT.BORDER);
- gd = new GridData(GridData.FILL_HORIZONTAL);
- fieldsText.setLayoutData(gd);
-
+
+ Label includeFieldNamesLabel = new Label(mainComposite, SWT.NONE);
+ includeFieldNamesLabel.setText(Messages.FreemarkerCSVCreationWizardPage_IncludeFieldNamesLabel);
+ includeFieldNames = new Button(mainComposite, SWT.CHECK | SWT.CENTER | SWT.BORDER);
+ gd = new GridData(GridData.BEGINNING);
+ includeFieldNames.setLayoutData(gd);
+
// gd = new GridData(GridData.FILL_HORIZONTAL);
// gd.heightHint = 200;
// gd.horizontalSpan = 2;
@@ -271,7 +281,7 @@
updatePage();
}
});
-
+
this.setPageComplete(false);
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/FreemarkerCSVTemplateCreationWizard.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/FreemarkerCSVTemplateCreationWizard.java 2010-01-14
17:49:29 UTC (rev 19757)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/FreemarkerCSVTemplateCreationWizard.java 2010-01-14
20:40:36 UTC (rev 19758)
@@ -57,6 +57,7 @@
this.addParamter(SmooksModelUtils.KEY_CSV_QUOTE, quote);
this.addParamter(SmooksModelUtils.KEY_CSV_SEPERATOR, seprator);
this.addParamter(SmooksModelUtils.KEY_CSV_FIELDS, fieldsString);
+ this.addParamter(SmooksModelUtils.KEY_INCLUDE_FIELD_NAMES,
Boolean.toString(page.getIncludeFieldNames().getSelection()));
// List<FieldText> fieldList = page.getFieldsList();
// for (Iterator<?> iterator = fieldList.iterator(); iterator.hasNext();) {
// FieldText fieldText = (FieldText) iterator.next();
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/Messages.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/Messages.java 2010-01-14
17:49:29 UTC (rev 19757)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/Messages.java 2010-01-14
20:40:36 UTC (rev 19758)
@@ -11,6 +11,7 @@
/* public static String FreemarkerCSVCreationWizardPage_FieldEmptyErrorMessage; */
public static String FreemarkerCSVCreationWizardPage_FieldsGroupText;
public static String FreemarkerCSVCreationWizardPage_QuoteCharLabel;
+ public static String FreemarkerCSVCreationWizardPage_IncludeFieldNamesLabel;
public static String FreemarkerCSVCreationWizardPage_QuoteEmptyErrorMessage;
/* public static String FreemarkerCSVCreationWizardPage_RemoveFieldButtonLabel; */
public static String FreemarkerCSVCreationWizardPage_SeperatorCharLabel;
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/messages.properties
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/messages.properties 2010-01-14
17:49:29 UTC (rev 19757)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizard/freemarker/messages.properties 2010-01-14
20:40:36 UTC (rev 19758)
@@ -5,6 +5,7 @@
#FreemarkerCSVCreationWizardPage_FieldEmptyErrorMessage=Fields can't be null
FreemarkerCSVCreationWizardPage_FieldsGroupText=Fields
FreemarkerCSVCreationWizardPage_QuoteCharLabel=Quote Character \:
+FreemarkerCSVCreationWizardPage_IncludeFieldNamesLabel=Include Field Names \:
FreemarkerCSVCreationWizardPage_QuoteEmptyErrorMessage=Quote can't be null
#FreemarkerCSVCreationWizardPage_RemoveFieldButtonLabel=Remove
FreemarkerCSVCreationWizardPage_SeperatorCharLabel=Separator Character \:
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLauncher.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLauncher.java 2010-01-14
17:49:29 UTC (rev 19757)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLauncher.java 2010-01-14
20:40:36 UTC (rev 19758)
@@ -79,7 +79,7 @@
StringResult stringResult = new StringResult();
smooks.filterSource(new StreamSource(new FileInputStream(input)), stringResult,
javaResult);
- System.out.println("[" +
localizedMessages.getProperty("SmooksLauncher_Templating_To_StreamResult") +
" ...]\n"); //$NON-NLS-1$
+ System.out.println("[" +
localizedMessages.getProperty("SmooksLauncher_Templating_To_StreamResult") +
" ...]"); //$NON-NLS-1$
System.out.println(" |--"); //$NON-NLS-1$
System.out.println(indent(stringResult.toString()));
System.out.println(" |--\n"); //$NON-NLS-1$
Modified:
trunk/smooks/tests/org.jboss.tools.smooks.templating.test/src/org/jboss/tools/smooks/templating/template/csv/CSVFreeMarkerTemplateBuilderTest.java
===================================================================
---
trunk/smooks/tests/org.jboss.tools.smooks.templating.test/src/org/jboss/tools/smooks/templating/template/csv/CSVFreeMarkerTemplateBuilderTest.java 2010-01-14
17:49:29 UTC (rev 19757)
+++
trunk/smooks/tests/org.jboss.tools.smooks.templating.test/src/org/jboss/tools/smooks/templating/template/csv/CSVFreeMarkerTemplateBuilderTest.java 2010-01-14
20:40:36 UTC (rev 19758)
@@ -37,7 +37,7 @@
public void test_all_fields_mapped_01() throws TemplateBuilderException, IOException,
ModelBuilderException {
CSVModelBuilder modelBuilder = new CSVModelBuilder("firstname",
"lastname", "country");
- CSVFreeMarkerTemplateBuilder builder1 = new
CSVFreeMarkerTemplateBuilder(modelBuilder, ',', '\"');
+ CSVFreeMarkerTemplateBuilder builder1 = new
CSVFreeMarkerTemplateBuilder(modelBuilder, ',', '\"', false);
//System.out.println(XmlUtil.serialize(model, true));
@@ -53,22 +53,51 @@
"</#list>",
template);
- CSVFreeMarkerTemplateBuilder builder2 = new
CSVFreeMarkerTemplateBuilder(modelBuilder, ',', '\"', template);
+ CSVFreeMarkerTemplateBuilder builder2 = new
CSVFreeMarkerTemplateBuilder(modelBuilder, ',', '\"', false,
template);
template = builder2.buildTemplate();
- System.out.println(template);
+ //System.out.println(template);
assertEquals("<#list people as person>\n" +
"\"${person.fname?string}\",\"${person.lname?string}\",\"${person.address.country?string}\"\n"
+
"</#list>",
template);
}
+ public void test_all_fields_mapped_01_includingFieldNames() throws
TemplateBuilderException, IOException, ModelBuilderException {
+ CSVModelBuilder modelBuilder = new CSVModelBuilder("firstname",
"lastname", "country");
+ CSVFreeMarkerTemplateBuilder builder1 = new
CSVFreeMarkerTemplateBuilder(modelBuilder, ',', '\"', true);
+
+ //System.out.println(XmlUtil.serialize(model, true));
+
+ builder1.addCollectionMapping("people",
getRecordElement(builder1.getModel()), "person");
+ builder1.addValueMapping("person.fname",
getFieldElement(builder1.getModel(), "firstname"));
+ builder1.addValueMapping("person.lname",
getFieldElement(builder1.getModel(), "lastname"));
+ builder1.addValueMapping("person.address.country",
getFieldElement(builder1.getModel(), "country"));
+
+ String template = builder1.buildTemplate();
+ //System.out.println(template);
+
assertEquals("\"firstname\",\"lastname\",\"country\"\n"
+
+ "<#list people as person>\n" +
+
"\"${person.fname?string}\",\"${person.lname?string}\",\"${person.address.country?string}\"\n"
+
+ "</#list>",
+ template);
+
+ CSVFreeMarkerTemplateBuilder builder2 = new
CSVFreeMarkerTemplateBuilder(modelBuilder, ',', '\"', true,
template);
+ template = builder2.buildTemplate();
+ //System.out.println(template);
+
assertEquals("\"firstname\",\"lastname\",\"country\"\n"
+
+ "<#list people as person>\n" +
+
"\"${person.fname?string}\",\"${person.lname?string}\",\"${person.address.country?string}\"\n"
+
+ "</#list>",
+ template);
+ }
+
/**
* Same as test above accept it uses different delimiters.
* @throws ModelBuilderException
*/
public void test_all_fields_mapped_02() throws TemplateBuilderException, IOException,
ModelBuilderException {
CSVModelBuilder modelBuilder = new CSVModelBuilder("firstname",
"lastname", "country");
- CSVFreeMarkerTemplateBuilder builder1 = new
CSVFreeMarkerTemplateBuilder(modelBuilder, '|', '\'');
+ CSVFreeMarkerTemplateBuilder builder1 = new
CSVFreeMarkerTemplateBuilder(modelBuilder, '|', '\'', false);
builder1.addCollectionMapping("people",
getRecordElement(builder1.getModel()), "person");
builder1.addValueMapping("person.fname",
getFieldElement(builder1.getModel(), "firstname"));
@@ -82,7 +111,7 @@
"</#list>",
template);
- CSVFreeMarkerTemplateBuilder builder2 = new
CSVFreeMarkerTemplateBuilder(modelBuilder, '|', '\'', template);
+ CSVFreeMarkerTemplateBuilder builder2 = new
CSVFreeMarkerTemplateBuilder(modelBuilder, '|', '\'', false,
template);
template = builder2.buildTemplate();
//System.out.println(template);
assertEquals("<#list people as person>\n" +
@@ -95,7 +124,7 @@
CSVModelBuilder modelBuilder = new CSVModelBuilder("firstname",
"lastname", "country");
CSVFreeMarkerTemplateBuilder builder;
- builder = new CSVFreeMarkerTemplateBuilder(modelBuilder, ',',
'\"');
+ builder = new CSVFreeMarkerTemplateBuilder(modelBuilder, ',',
'\"', false);
builder.addCollectionMapping("people",
getRecordElement(builder.getModel()), "person");
builder.addValueMapping("person.fname",
getFieldElement(builder.getModel(), "firstname"));
@@ -108,7 +137,7 @@
"</#list>",
template);
- CSVFreeMarkerTemplateBuilder builder2 = new
CSVFreeMarkerTemplateBuilder(modelBuilder, ',', '\"', template);
+ CSVFreeMarkerTemplateBuilder builder2 = new
CSVFreeMarkerTemplateBuilder(modelBuilder, ',', '\"', false,
template);
template = builder2.buildTemplate();
//System.out.println(template);
assertEquals("<#list people as person>\n" +
@@ -117,7 +146,7 @@
template);
try {
- new CSVFreeMarkerTemplateBuilder(modelBuilder, ';', '\"',
template);
+ new CSVFreeMarkerTemplateBuilder(modelBuilder, ';', '\"',
false, template);
fail("Expected TemplateBuilderException");
} catch(TemplateBuilderException e) {
assertEquals("CSV Template fieldset size does not match that of the
specified message model. Check the supplied fieldset. Check the specified
'separator' and 'quote' characters match those used in the
template.", e.getMessage());
@@ -128,7 +157,7 @@
CSVModelBuilder modelBuilder = new CSVModelBuilder("firstname",
"lastname", "country");
CSVFreeMarkerTemplateBuilder builder;
- builder = new CSVFreeMarkerTemplateBuilder(modelBuilder, ',',
'\"');
+ builder = new CSVFreeMarkerTemplateBuilder(modelBuilder, ',',
'\"', false);
try {
// Shouldn't be able to add a value binding where the model target is
inside
@@ -144,7 +173,7 @@
CSVModelBuilder modelBuilder = new CSVModelBuilder("firstname",
"lastname", "country");
CSVFreeMarkerTemplateBuilder builder;
- builder = new CSVFreeMarkerTemplateBuilder(modelBuilder, ',',
'\"');
+ builder = new CSVFreeMarkerTemplateBuilder(modelBuilder, ',',
'\"', false);
try {
// For CSV, you need to have at least mapped the collection...