You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(112) |
Nov
(44) |
Dec
(49) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(14) |
Feb
(12) |
Mar
(12) |
Apr
(12) |
May
(6) |
Jun
(11) |
Jul
(10) |
Aug
(6) |
Sep
(17) |
Oct
(3) |
Nov
(22) |
Dec
|
2008 |
Jan
(3) |
Feb
(7) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(3) |
Sep
(6) |
Oct
|
Nov
|
Dec
|
2009 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2010 |
Jan
|
Feb
(1) |
Mar
(9) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
(2) |
Dec
|
2011 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
(3) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
2012 |
Jan
(3) |
Feb
|
Mar
(2) |
Apr
(8) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <be...@us...> - 2012-04-16 22:46:25
|
Revision: 442 http://flatpack.svn.sourceforge.net/flatpack/?rev=442&view=rev Author: benoitx Date: 2012-04-16 22:46:19 +0000 (Mon, 16 Apr 2012) Log Message: ----------- Re-org the printHeader or not depending on the way the factory is called. Modified Paths: -------------- trunk/flatpack-samples/.classpath trunk/flatpack-samples/.project Modified: trunk/flatpack-samples/.classpath =================================================================== --- trunk/flatpack-samples/.classpath 2012-04-16 22:46:03 UTC (rev 441) +++ trunk/flatpack-samples/.classpath 2012-04-16 22:46:19 UTC (rev 442) @@ -1,11 +1,13 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="src" path="src/main/java"/> - <classpathentry kind="var" path="MAVEN_REPO/net.sf.flatpack/jars/flatpack-3.2.0-SNAPSHOT.jar"/> - <classpathentry kind="var" path="MAVEN_REPO/jdom/jars/jdom-1.0.jar"/> - <classpathentry kind="var" path="MAVEN_REPO/jexcelapi/jars/jxl-2.4.2.jar"/> - <classpathentry kind="var" path="MAVEN_REPO/org.slf4j/jars/slf4j-api-1.1.0-RC1.jar"/> - <classpathentry kind="var" path="MAVEN_REPO/org.slf4j/jars/slf4j-simple-1.1.0-RC1.jar"/> - <classpathentry kind="output" path="target/classes"/> -</classpath> + <classpathentry kind="src" path="src/main/java"/> + <classpathentry kind="src" path="/Users/xhensevalb/project/flatpack/common-build/lib" including="**/*.jar" excluding="**/*.java"/> + <classpathentry kind="output" path="target/classes"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="var" path="M2_REPO/net/sf/flatpack/flatpack/3.3.0-SNAPSHOT/flatpack-3.3.0-SNAPSHOT.jar"/> + <classpathentry kind="var" path="M2_REPO/jdom/jdom/1.0/jdom-1.0.jar"/> + <classpathentry kind="var" path="M2_REPO/jexcelapi/jxl/2.4.2/jxl-2.4.2.jar"/> + <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.1.0-RC1/slf4j-api-1.1.0-RC1.jar"/> + <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-simple/1.1.0-RC1/slf4j-simple-1.1.0-RC1.jar"/> + <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.2/junit-3.8.2.jar"/> +</classpath> \ No newline at end of file Modified: trunk/flatpack-samples/.project =================================================================== --- trunk/flatpack-samples/.project 2012-04-16 22:46:03 UTC (rev 441) +++ trunk/flatpack-samples/.project 2012-04-16 22:46:19 UTC (rev 442) @@ -1,13 +1,12 @@ <?xml version="1.0" encoding="UTF-8"?> - <projectDescription> <name>flatpack-examples</name> - <comment>Simple Java delimited and fixed width file parser. Handles CSV, Excel CSV, Tab, Pipe delimiters, just to name a few. Maps column positions in the file to user friendly names via XML. See PZFileReader Feature List under News for complete feature list.</comment> - <projects></projects> + <comment>Simple Java delimited and fixed width file parser. Handles CSV, Excel CSV, Tab, Pipe delimiters, just to name a few. + Maps column positions in the file to user friendly names via XML. See FlatPack Feature List under News for complete feature list. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment> + <projects/> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> - <arguments></arguments> </buildCommand> </buildSpec> <natures> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-04-16 22:46:09
|
Revision: 441 http://flatpack.svn.sourceforge.net/flatpack/?rev=441&view=rev Author: benoitx Date: 2012-04-16 22:46:03 +0000 (Mon, 16 Apr 2012) Log Message: ----------- Re-org the printHeader or not depending on the way the factory is called. Modified Paths: -------------- trunk/flatpack/.classpath trunk/flatpack/.project Modified: trunk/flatpack/.classpath =================================================================== --- trunk/flatpack/.classpath 2012-04-16 22:44:49 UTC (rev 440) +++ trunk/flatpack/.classpath 2012-04-16 22:46:03 UTC (rev 441) @@ -1,13 +1,13 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="src" path="src/main/java"/> - <classpathentry kind="src" output="target/test-classes" path="src/test/java"/> - <classpathentry kind="var" path="MAVEN_REPO/junit/jars/junit-3.8.2.jar"/> - <classpathentry kind="var" path="MAVEN_REPO/jdom/jars/jdom-1.0.jar"/> - <classpathentry kind="var" path="MAVEN_REPO/org.slf4j/jars/slf4j-api-1.1.0-RC1.jar"/> - <classpathentry kind="var" path="MAVEN_REPO/org.slf4j/jars/slf4j-simple-1.1.0-RC1.jar"/> - <classpathentry kind="var" path="MAVEN_REPO/jexcelapi/jars/jxl-2.4.2.jar"/> - <classpathentry kind="var" path="MAVEN_REPO"/> - <classpathentry kind="output" path="target/classes"/> -</classpath> + <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/> + <classpathentry kind="src" path="src/test/resources" output="target/test-classes" including="**/*.xml" excluding="**/*.java"/> + <classpathentry kind="src" path="src/main/java"/> + <classpathentry kind="output" path="target/classes"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="var" path="M2_REPO/jdom/jdom/1.0/jdom-1.0.jar"/> + <classpathentry kind="var" path="M2_REPO/jexcelapi/jxl/2.4.2/jxl-2.4.2.jar"/> + <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.1.0-RC1/slf4j-api-1.1.0-RC1.jar"/> + <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-simple/1.1.0-RC1/slf4j-simple-1.1.0-RC1.jar"/> + <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.2/junit-3.8.2.jar"/> +</classpath> \ No newline at end of file Modified: trunk/flatpack/.project =================================================================== --- trunk/flatpack/.project 2012-04-16 22:44:49 UTC (rev 440) +++ trunk/flatpack/.project 2012-04-16 22:46:03 UTC (rev 441) @@ -1,13 +1,12 @@ <?xml version="1.0" encoding="UTF-8"?> - <projectDescription> <name>flatpack</name> - <comment>Simple Java delimited and fixed width file parser. Handles CSV, Excel CSV, Tab, Pipe delimiters, just to name a few. Maps column positions in the file to user friendly names via XML. See FlatPack Feature List under News for complete feature list.</comment> - <projects></projects> + <comment>Simple Java delimited and fixed width file parser. Handles CSV, Excel CSV, Tab, Pipe delimiters, just to name a few. + Maps column positions in the file to user friendly names via XML. See FlatPack Feature List under News for complete feature list. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment> + <projects/> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> - <arguments></arguments> </buildCommand> </buildSpec> <natures> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-04-16 22:44:55
|
Revision: 440 http://flatpack.svn.sourceforge.net/flatpack/?rev=440&view=rev Author: benoitx Date: 2012-04-16 22:44:49 +0000 (Mon, 16 Apr 2012) Log Message: ----------- Re-org the printHeader or not depending on the way the factory is called. Modified Paths: -------------- trunk/flatpack/src/main/java/net/sf/flatpack/writer/AbstractWriter.java trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterFactory.java trunk/flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java trunk/flatpack/src/main/java/net/sf/flatpack/writer/Writer.java Added Paths: ----------- trunk/flatpack/src/main/java/net/sf/flatpack/writer/WriterOptions.java Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/AbstractWriter.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/AbstractWriter.java 2012-04-16 22:42:45 UTC (rev 439) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/AbstractWriter.java 2012-04-16 22:44:49 UTC (rev 440) @@ -4,21 +4,14 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -import java.util.Set; -import net.sf.flatpack.util.FPConstants; - /** * This class encapsulates the writer that's used to output the data. * @author Dirk Holmes and Holger Holger Hoffstatte */ -public abstract class AbstractWriter extends Object implements Writer { +public abstract class AbstractWriter implements Writer { private final BufferedWriter writer; - - private Map rowMap; //used when using column headers - - //the record ID that is currently being written. The default is the DETAIL_ID which are <columns> that are mapped outside of <record> elements - private String recordId = FPConstants.DETAIL_ID; + private Map rowMap; public AbstractWriter(final java.io.Writer output) { super(); @@ -35,20 +28,6 @@ } rowMap.put(columnName, value); } - - //TODO implement writing for no column titles -// public void addRecordEntry(final Object value) { -// if ( -// -// if (rowMap == null) { -// rowMap = new HashMap(); -// } -// -// if (!validateColumnTitle(columnName)) { -// throw new IllegalArgumentException("unknown column: \"" + columnName + "\""); -// } -// rowMap.put(columnName, value); -// } /** * Subclasses must implement this method to perform validation of @@ -71,8 +50,6 @@ // the row should have been written out by the subclass so it's safe to // discard it here rowMap = null; - //default the recordId when we go to the next record - recordId = FPConstants.DETAIL_ID; writer.newLine(); } @@ -101,30 +78,8 @@ writer.flush(); writer.close(); } - protected Map getRowMap() { return rowMap; } - - /** - * @return the recordId - */ - public String getRecordId() { - return recordId; - } - - /** - * Sets the record ID for the record that is being written. This should be used when mapping <record> elements. - * The "id" attribute of the record element should be specified here and needs to be called before calling addRecordEntry(). - * This will throw an exception if addRecordEntry() has been called for the record currently being processed. - * - * @param recordId the recordId to set - */ - public void setRecordId(String recordId) { - if (rowMap != null && !rowMap.isEmpty()) { - throw new RuntimeException("addRecordEntry() has already been called for this row. Please set the record id prior to adding data to this row."); - } - this.recordId = recordId; - } } Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java 2012-04-16 22:42:45 UTC (rev 439) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java 2012-04-16 22:44:49 UTC (rev 440) @@ -1,14 +1,14 @@ package net.sf.flatpack.writer; import java.io.IOException; -import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.math.BigDecimal; import net.sf.flatpack.structure.ColumnMetaData; import net.sf.flatpack.util.FPConstants; -import net.sf.flatpack.xml.XMLRecordElement; /** * @@ -16,50 +16,29 @@ */ public class DelimiterWriter extends AbstractWriter { private char delimiter; - private char qualifier; - - //private List columnTitles = null; - + private List columnTitles = null; private boolean columnTitlesWritten = false; - - private Map columnMapping; - - private DelimiterWriterOptions writerOptions; - - //this is used when using addRecordEntry() and no column names - private boolean delimitNextEntry = false; protected DelimiterWriter(final Map columnMapping, final java.io.Writer output, final char delimiter, - final char qualifier) throws IOException { - - this(columnMapping, output, delimiter, qualifier, new DelimiterWriterOptions()); - } - - protected DelimiterWriter(final Map columnMapping, - final java.io.Writer output, final char delimiter, - final char qualifier, DelimiterWriterOptions writerOptions) throws IOException { + final char qualifier, + final WriterOptions options) throws IOException { super(output); this.delimiter = delimiter; this.qualifier = qualifier; -// columnTitles = new ArrayList(); -// final List columns = (List) columnMapping.get(FPConstants.DETAIL_ID); -// final Iterator columnIter = columns.iterator(); -// while (columnIter.hasNext()) { -// final ColumnMetaData element = (ColumnMetaData) columnIter.next(); -// columnTitles.add(element.getColName()); -// } - this.columnMapping = columnMapping; - this.writerOptions = writerOptions; - if (!writerOptions.isNoColumnMappings()) { - // write the column headers - this.nextRecord(); - } else { - //flag the headers as written so that we don't try to write them when calling nextRecord() - columnTitlesWritten = true; - } + columnTitles = new ArrayList(); + final List columns = (List) columnMapping.get(FPConstants.DETAIL_ID); + final Iterator columnIter = columns.iterator(); + while (columnIter.hasNext()) { + final ColumnMetaData element = (ColumnMetaData) columnIter.next(); + columnTitles.add(element.getColName()); + } + // write the column headers + if (options.isAutoPrintHeader()) { + printHeader(); + } } protected void writeWithDelimiter(final Object value) throws IOException { @@ -80,7 +59,9 @@ } } - final boolean needsQuoting = stringValue.indexOf(delimiter) != -1 || (qualifier != FPConstants.NO_QUALIFIER && stringValue.indexOf(qualifier) != -1); + final boolean needsQuoting = stringValue.indexOf(delimiter) != -1 + || (qualifier != FPConstants.NO_QUALIFIER && stringValue + .indexOf(qualifier) != -1); if (needsQuoting) { super.write(qualifier); @@ -92,75 +73,18 @@ super.write(qualifier); } } - - public void addRecordEntry(String columnName, Object value) { - if (writerOptions.isNoColumnMappings()) { - throw new UnsupportedOperationException("Column Names Cannot Be Bound To Values When Column Mappings Have Been Turned Off..."); + + protected void addColumnTitle(final String string) { + if (string == null) { + throw new IllegalArgumentException("column title may not be null"); } - super.addRecordEntry(columnName, value); + columnTitles.add(string); } - - /** - * Adds a record entry when not using column names in the file - * - * @param value - * @throws IOException - */ - public void addRecordEntry(Object value) throws IOException{ - if (!writerOptions.isNoColumnMappings()) { - throw new UnsupportedOperationException("Must use addRecordEntry(String,Object) When Using Column Names..."); - } - - if (delimitNextEntry) { - //need to use the super write here. The write in this class will try and qualify the delimiter. - //we also cannot use the writeWithDelimiter() here. It puts the delimiter after the value. We don't - //know the last column to be written so we cannot utilize that here as we did with the mappings - super.write(this.delimiter); - - } - - this.write(value.toString()); - delimitNextEntry = true; - } - //TODO find out if these are needed since the titles can already be added from the Factory -// protected void addColumnTitle(final String string) { -// addColumnTitle(string, FPConstants.DETAIL_ID); -// } -// -// protected void addColumnTitle(final String string, final String recordId) { -// if (string == null) { -// throw new IllegalArgumentException("column title may not be null"); -// } -// List cols = null; -// if (FPConstants.DETAIL_ID.equals(recordId)) { -// //the key for the detail key contains a List in the Map -// cols = (List)this.columnMapping.get(FPConstants.DETAIL_ID); -// if (cols == null) { -// cols = new ArrayList(); -// this.columnMapping.put(FPConstants.DETAIL_ID, cols); -// } -// -// } else { -// //the map contains an XMLRecord element and then the list is contained under that -// XMLRecordElement xmlRec = (XMLRecordElement)this.columnMapping.get(recordId); -// if (xmlRec == null) { -// cols = new ArrayList(); -// xmlRec = new XMLRecordElement(); -// xmlRec.setColumns(cols, null); -// this.columnMapping.put(recordId, xmlRec); -// } else { -// cols = xmlRec.getColumns(); -// } -// } -// -// cols.add(string); -// } - protected void writeColumnTitles() throws IOException { - final Iterator titleIter = ((List)this.columnMapping.get(FPConstants.DETAIL_ID)).iterator(); + final Iterator titleIter = columnTitles.iterator(); while (titleIter.hasNext()) { - final String title = ((ColumnMetaData)titleIter.next()).getColName(); + final String title = (String) titleIter.next(); if (titleIter.hasNext()) { this.writeWithDelimiter(title); @@ -171,15 +95,9 @@ } protected void writeRow() throws IOException { - Iterator titlesIter = null; - if (FPConstants.DETAIL_ID.equals(getRecordId())) { - titlesIter = ((List)this.columnMapping.get(FPConstants.DETAIL_ID)).iterator(); - } else { - final XMLRecordElement xmlRec = (XMLRecordElement)this.columnMapping.get(getRecordId()); - titlesIter = xmlRec.getColumns().iterator(); - } + final Iterator titlesIter = columnTitles.iterator(); while (titlesIter.hasNext()) { - final String columnTitle = ((ColumnMetaData)titlesIter.next()).getColName(); + final String columnTitle = (String) titlesIter.next(); if (getRowMap() != null) { if (titlesIter.hasNext()) { writeWithDelimiter(getRowMap().get(columnTitle)); @@ -189,33 +107,31 @@ } } } - public final void nextRecord() throws IOException { - if (!writerOptions.isNoColumnMappings()) { - if (!columnTitlesWritten) { - this.writeColumnTitles(); - columnTitlesWritten = true; - } else { - this.writeRow(); - } - } - - delimitNextEntry = false; + // if (!columnTitlesWritten) { + // this.writeColumnTitles(); + // columnTitlesWritten = true; + // } else { + this.writeRow(); + // } + super.nextRecord(); } - protected boolean validateColumnTitle(final String columnTitle) { - //return columnTitles.contains(columnTitle); - - //the column index for <record> elements is stored in the Map as the COL_IDX constant_<record id attribute> - final Map columnNameToIndex = (Map) columnMapping - .get(getRecordId().equals(FPConstants.DETAIL_ID) ? FPConstants.COL_IDX : FPConstants.COL_IDX + "_" + getRecordId()); - if (columnNameToIndex == null) { - //TODO this needs to be moved to the AbstractWriter, but the columnMapping is not exposed to it currently - //This should only happen if the getRecordId() contained an invalid record id - throw new RuntimeException("The record ID[" + getRecordId() + "] Is Not Mapped"); + public void printFooter() throws IOException { + // TODO DO: implement footer handling + } + + public void printHeader() throws IOException { + if (!columnTitlesWritten) { + this.writeColumnTitles(); + columnTitlesWritten = true; + super.nextRecord(); } - return columnNameToIndex.keySet().contains(columnTitle); } + + protected boolean validateColumnTitle(final String columnTitle) { + return columnTitles.contains(columnTitle); + } } Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterFactory.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterFactory.java 2012-04-16 22:42:45 UTC (rev 439) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterFactory.java 2012-04-16 22:44:49 UTC (rev 440) @@ -2,14 +2,11 @@ import java.io.IOException; import java.io.Reader; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import net.sf.flatpack.structure.ColumnMetaData; import net.sf.flatpack.util.FPConstants; -import net.sf.flatpack.xml.XMLRecordElement; import org.jdom.JDOMException; @@ -23,7 +20,6 @@ private final char delimiter; private final char qualifier; - public DelimiterWriterFactory(final char delimiter, final char qualifier) { super(); @@ -66,76 +62,26 @@ public char getQualifier() { return qualifier; } - - public Writer createWriter(final java.io.Writer out) throws IOException { - return createWriter(out, new DelimiterWriterOptions()); - + public Writer createWriter(final java.io.Writer out, final WriterOptions options) throws IOException { + return new DelimiterWriter(this.getColumnMapping(), out, delimiter, qualifier, options); } - - /** - * Create an instance of the DelimterWriter - * - * @param out - * @param delimiterWriterOptions - * Options for Writing - * @return {@link DelimiterWriter} - * @throws IOException - */ - public Writer createWriter(final java.io.Writer out, final DelimiterWriterOptions delimiterWriterOptions) throws IOException { - return new DelimiterWriter(this.getColumnMapping(), out, delimiter, qualifier, delimiterWriterOptions); + + public Writer createWriter(final java.io.Writer out) throws IOException { + return new DelimiterWriter(this.getColumnMapping(), out, delimiter, qualifier, WriterOptions.getInstance()); } - /** - * Add column titles for mapping. This can be done in lieu of using an XML Mapping. This needs to be done before calling createWriter() - * - * @param columnTitle - * @param recordId - */ - public void addColumnTitle(final String columnTitle, final String recordId) { - final String colIdxKey = FPConstants.DETAIL_ID.equals(recordId) ? FPConstants.COL_IDX : FPConstants.COL_IDX + "_" + recordId; + // TODO DO: check that no column titles can be added after first nextRecord + public void addColumnTitle(final String columnTitle) { final Map columnMapping = this.getColumnMapping(); - List columnMetaDatas = null; - if (FPConstants.DETAIL_ID.equals(recordId)) { - //the detail record will always be there. It is being setup by the AbstractWriter if it - //is not coming off of the XML - columnMetaDatas = (List) columnMapping.get(FPConstants.DETAIL_ID); - } else { - //this has a XMLRecord in the map, for anything other than the detail id - XMLRecordElement xmlRec = (XMLRecordElement)columnMapping.get(recordId); - if (xmlRec == null) { - columnMetaDatas = new ArrayList(); - xmlRec = new XMLRecordElement(); - xmlRec.setColumns(columnMetaDatas, null); - columnMapping.put(recordId, xmlRec); - } else { - columnMetaDatas = xmlRec.getColumns(); - } - } - - Map columnIndices = (Map) columnMapping.get(colIdxKey); - if (columnIndices == null) { - columnIndices = new HashMap(); - columnMapping.put(recordId, columnIndices); - } + final List columnMetaDatas = (List) columnMapping.get(FPConstants.DETAIL_ID); + final Map columnIndices = (Map) columnMapping.get(FPConstants.COL_IDX); final ColumnMetaData metaData = new ColumnMetaData(); metaData.setColName(columnTitle); columnMetaDatas.add(metaData); final Integer columnIndex = Integer.valueOf(columnMetaDatas.indexOf(metaData)); - columnIndices.put(columnTitle, columnIndex); + columnIndices.put(columnIndex, columnTitle); } - - /** - * Add column titles for mapping. This can be done in lieu of using an XML Mapping. This needs to be done before calling createWriter() - * - * @param string - */ - public void addColumnTitle(final String string) { - addColumnTitle(string, FPConstants.DETAIL_ID); - } - - - } Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java 2012-04-16 22:42:45 UTC (rev 439) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java 2012-04-16 22:44:49 UTC (rev 440) @@ -9,7 +9,6 @@ import net.sf.flatpack.structure.ColumnMetaData; import net.sf.flatpack.util.FPConstants; -import net.sf.flatpack.xml.XMLRecordElement; /** * @@ -97,27 +96,27 @@ } protected boolean validateColumnTitle(final String columnTitle) { - //the column index for <record> elements is stored in the Map as the COL_IDX constant_<record id attribute> final Map columnNameToIndex = (Map) columnMapping - .get(getRecordId().equals(FPConstants.DETAIL_ID) ? FPConstants.COL_IDX : FPConstants.COL_IDX + "_" + getRecordId()); - if (columnNameToIndex == null) { - //TODO this needs to be moved to the AbstractWriter, but the columnMapping is not exposed to it currently - //This should only happen if the getRecordId() contained an invalid record id - throw new RuntimeException("The record ID[" + getRecordId() + "] Is Not Mapped"); - } + .get(FPConstants.COL_IDX); return columnNameToIndex.keySet().contains(columnTitle); } + public void printFooter() { + // TODO DO: implement footer handling + + } + + public void printHeader() { + // TODO DO: implement header handling + + } + /** * @return List of ColumnMetaData objects describing the mapping defined in * the XML file. */ private List getColumnMetaData() { - if (getRecordId().equals(FPConstants.DETAIL_ID)) { - return (List) columnMapping.get(getRecordId()); - } - - return ((XMLRecordElement)columnMapping.get(getRecordId())).getColumns(); + return (List) columnMapping.get(FPConstants.DETAIL_ID); } private ColumnMetaData getColumnMetaData(final String columnName) { @@ -129,7 +128,7 @@ } } - throw new IllegalArgumentException("Record ID[" + getRecordId() + "] Column \"" + columnName + throw new IllegalArgumentException("Column \"" + columnName + "\" unknown"); } } Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/Writer.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/Writer.java 2012-04-16 22:42:45 UTC (rev 439) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/Writer.java 2012-04-16 22:44:49 UTC (rev 440) @@ -7,21 +7,17 @@ * @author Dirk Holmes and Holger Holger Hoffstatte */ public interface Writer { + /** Export header */ + void printHeader() throws IOException; - void addRecordEntry(String columnName, Object value); + /** Export footer */ + void printFooter() throws IOException; + void addRecordEntry(String columnName, Object value); + void nextRecord() throws IOException; void flush() throws IOException; void close() throws IOException; - - /** - * Sets the record ID for the record that is being written. This should be used when mapping <record> elements. - * The "id" attribute of the record element should be specified here and needs to be called before calling addRecordEntry(). - * This will throw an exception if addRecordEntry() has been called for the record currently being processed. - * - * @param recordId the recordId to set - */ - void setRecordId(String recordId); } Copied: trunk/flatpack/src/main/java/net/sf/flatpack/writer/WriterOptions.java (from rev 436, trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterOptions.java) =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/WriterOptions.java (rev 0) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/WriterOptions.java 2012-04-16 22:44:49 UTC (rev 440) @@ -0,0 +1,45 @@ +package net.sf.flatpack.writer; + +/** + * Defines options for various Writer behaviours + * + * @author Paul Zepernick + */ +public class WriterOptions { + + private boolean autoPrintHeader = true; + + + + /** + * Returns a DelimiterWriterOptions instance + * + * @return DelimiterWriterOptions + */ + public static WriterOptions getInstance() { + return new WriterOptions(); + } + + + + /** + * @return the noColumnMappings + */ + public boolean isAutoPrintHeader() { + return autoPrintHeader; + } + + + + /** + * When this is set to true, the addRecordEntry(column, value) will throw an exception. You + * must use addRecordEntry(value). + * + * @param noColumnMappings the noColumnMappings to set + */ + public WriterOptions autoPrintHeader(boolean autoPrintHeader) { + this.autoPrintHeader = autoPrintHeader; + return this; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-04-16 22:42:51
|
Revision: 439 http://flatpack.svn.sourceforge.net/flatpack/?rev=439&view=rev Author: benoitx Date: 2012-04-16 22:42:45 +0000 (Mon, 16 Apr 2012) Log Message: ----------- Re-org the printHeader or not depending on the way the factory is called. Modified Paths: -------------- trunk/flatpack/src/test/java/net/sf/flatpack/writer/AllTests.java Added Paths: ----------- trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTest.java trunk/flatpack/src/test/java/net/sf/flatpack/writer/FixedLengthWriterTest.java trunk/flatpack/src/test/java/net/sf/flatpack/writer/PZWriterTestCase.java Removed Paths: ------------- trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java trunk/flatpack/src/test/java/net/sf/flatpack/writer/FixedLengthWriterTestCase.java trunk/flatpack/src/test/java/net/sf/flatpack/writer/PZWriterTestCase.java Modified: trunk/flatpack/src/test/java/net/sf/flatpack/writer/AllTests.java =================================================================== --- trunk/flatpack/src/test/java/net/sf/flatpack/writer/AllTests.java 2012-04-16 22:42:18 UTC (rev 438) +++ trunk/flatpack/src/test/java/net/sf/flatpack/writer/AllTests.java 2012-04-16 22:42:45 UTC (rev 439) @@ -12,8 +12,8 @@ public static Test suite() { final TestSuite suite = new TestSuite("Test for net.sf.flatpack.writer"); //$JUnit-BEGIN$ - suite.addTestSuite(DelimiterWriterTestCase.class); - suite.addTestSuite(FixedLengthWriterTestCase.class); + suite.addTestSuite(DelimiterWriterTest.class); + suite.addTestSuite(FixedLengthWriterTest.class); //$JUnit-END$ return suite; } Copied: trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTest.java (from rev 436, trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java) =================================================================== --- trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTest.java (rev 0) +++ trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTest.java 2012-04-16 22:42:45 UTC (rev 439) @@ -0,0 +1,148 @@ +package net.sf.flatpack.writer; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringWriter; +import java.util.Map; + +import junit.framework.Assert; + +import net.sf.flatpack.writer.DelimiterWriterFactory; +import net.sf.flatpack.writer.Writer; + +/** + * + * @author Dirk Holmes and Holger Holger Hoffstatte + */ +public class DelimiterWriterTest extends PZWriterTestCase { + public void testWriteCsvNoMappingFile() throws Exception { + final StringWriter out = new StringWriter(); + + final DelimiterWriterFactory factory = new DelimiterWriterFactory(';', '"'); + factory.addColumnTitle("FIRSTNAME"); + factory.addColumnTitle("LASTNAME"); + factory.addColumnTitle("ADDRESS"); + factory.addColumnTitle("CITY"); + factory.addColumnTitle("STATE"); + factory.addColumnTitle("ZIP"); + + final Writer writer = factory.createWriter(out); + // write one line of data ... not in the correct order of fields + writer.addRecordEntry("LASTNAME", "ANAME"); + writer.addRecordEntry("FIRSTNAME", "JOHN"); + writer.addRecordEntry("ZIP", "44035"); + writer.addRecordEntry("CITY", "ELYRIA"); + writer.addRecordEntry("STATE", "OH"); + writer.addRecordEntry("ADDRESS", "1234 CIRCLE CT"); + writer.nextRecord(); + writer.flush(); + + // make sure the tests work on Windows and on Linux + final String expected = this.joinLines("FIRSTNAME;LASTNAME;ADDRESS;CITY;STATE;ZIP", "JOHN;ANAME;1234 CIRCLE CT;ELYRIA;OH;44035"); + + Assert.assertEquals(expected, out.toString()); + } + + public void testWriteCsvWithMappingFile() throws Exception { + final InputStream mapping = this.getClass().getClassLoader().getResourceAsStream("DelimitedWithHeader.pzmap.xml"); + final Reader mappingReader = new InputStreamReader(mapping); + final StringWriter out = new StringWriter(); + + final Writer writer = new DelimiterWriterFactory(mappingReader, ';', '"').createWriter(out); + writer.addRecordEntry("LASTNAME", "ANAME"); + writer.addRecordEntry("FIRSTNAME", "JOHN"); + writer.addRecordEntry("ZIP", "44035"); + writer.addRecordEntry("CITY", "ELYRIA"); + writer.addRecordEntry("STATE", "OH"); + writer.addRecordEntry("ADDRESS", "1234 CIRCLE CT"); + writer.nextRecord(); + writer.flush(); + + final String expected = this.joinLines("FIRSTNAME;LASTNAME;ADDRESS;CITY;STATE;ZIP", "JOHN;ANAME;1234 CIRCLE CT;ELYRIA;OH;44035"); + + Assert.assertEquals(expected, out.toString()); + } + + public void testWriteCsvWithMissingColumns() throws Exception { + final InputStream mapping = this.getClass().getClassLoader().getResourceAsStream("DelimitedWithHeader.pzmap.xml"); + final InputStreamReader mappingReader = new InputStreamReader(mapping); + final StringWriter out = new StringWriter(); + + final Writer writer = new DelimiterWriterFactory(mappingReader, ';', '"').createWriter(out); + // note that we do not provide values for FIRSTNAME and ADDRESS + writer.addRecordEntry("LASTNAME", "ANAME"); + writer.addRecordEntry("ZIP", "44035"); + writer.addRecordEntry("CITY", "ELYRIA"); + writer.addRecordEntry("STATE", "OH"); + writer.nextRecord(); + writer.flush(); + + final String expected = this.joinLines("FIRSTNAME;LASTNAME;ADDRESS;CITY;STATE;ZIP", ";ANAME;;ELYRIA;OH;44035"); + + Assert.assertEquals(expected, out.toString()); + } + + public void testCreateWriterWithoutColumnMapping() throws Exception { + try { + final Writer writer = new DelimiterWriterFactory(';', '"').createWriter(new StringWriter()); + writer.addRecordEntry("ThisColumnDoesNotExist", "foo"); + Assert.fail("Writing to a DelimiterWriter without column mapping is not supported"); + } catch (final IllegalArgumentException iae) { + // exception was expected + } + } + + public void testCreateWriterWithNullOutputStream() throws IOException { + try { + new DelimiterWriterFactory((Map) null).createWriter(null); + } catch (final NullPointerException npe) { + // this one was expected + } + } + + public void testAllowWriteWithNoMapping() throws Exception { + final StringWriter sw = new StringWriter(); + + final DelimiterWriterFactory factory = new DelimiterWriterFactory(';', '"'); +// final DelimiterWriter dwriter = (DelimiterWriter)factory.createWriter(sw); + + factory.addColumnTitle("col1"); + factory.addColumnTitle("col2"); + factory.addColumnTitle("col3"); + factory.addColumnTitle("col4"); + + + final StringWriter out = new StringWriter(); + final Writer writer = factory.createWriter(out, WriterOptions.getInstance().autoPrintHeader(false)); + writer.addRecordEntry("col1", "a"); + writer.addRecordEntry("col2", "b"); + writer.addRecordEntry("col3", "c"); + writer.addRecordEntry("col4", "d"); + writer.nextRecord(); + writer.flush(); + + Assert.assertTrue(out.toString().startsWith("a;b;c;d")); + } + + public void testWriteValueWithQualifier() throws Exception { + final DelimiterWriterFactory factory = new DelimiterWriterFactory(';', '"'); + factory.addColumnTitle("col1"); + factory.addColumnTitle("col2"); + factory.addColumnTitle("col3"); + factory.addColumnTitle("col4"); + + final StringWriter out = new StringWriter(); + final Writer writer = factory.createWriter(out); + writer.addRecordEntry("col1", "value;with;delimiter"); + writer.addRecordEntry("col2", "normal value"); + writer.addRecordEntry("col3", "value \"with qualifier\""); + writer.addRecordEntry("col4", "value \"with qualifier\" and ;delimiter;"); + writer.nextRecord(); + writer.flush(); + + final String expected = this.joinLines("col1;col2;col3;col4", "\"value;with;delimiter\";normal value;\"value \"with qualifier\"\";\"value \"with qualifier\" and ;delimiter;\""); + Assert.assertEquals(expected, out.toString()); + } +} Deleted: trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java =================================================================== --- trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java 2012-04-16 22:42:18 UTC (rev 438) +++ trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java 2012-04-16 22:42:45 UTC (rev 439) @@ -1,147 +0,0 @@ -package net.sf.flatpack.writer; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringWriter; -import java.util.Map; - -import junit.framework.Assert; - -import net.sf.flatpack.writer.DelimiterWriterFactory; -import net.sf.flatpack.writer.Writer; - -/** - * - * @author Dirk Holmes and Holger Holger Hoffstatte - */ -public class DelimiterWriterTestCase extends PZWriterTestCase { - public void testWriteCsvNoMappingFile() throws Exception { - final StringWriter out = new StringWriter(); - - final DelimiterWriterFactory factory = new DelimiterWriterFactory(';', '"'); - factory.addColumnTitle("FIRSTNAME"); - factory.addColumnTitle("LASTNAME"); - factory.addColumnTitle("ADDRESS"); - factory.addColumnTitle("CITY"); - factory.addColumnTitle("STATE"); - factory.addColumnTitle("ZIP"); - - final Writer writer = factory.createWriter(out); - // write one line of data ... not in the correct order of fields - writer.addRecordEntry("LASTNAME", "ANAME"); - writer.addRecordEntry("FIRSTNAME", "JOHN"); - writer.addRecordEntry("ZIP", "44035"); - writer.addRecordEntry("CITY", "ELYRIA"); - writer.addRecordEntry("STATE", "OH"); - writer.addRecordEntry("ADDRESS", "1234 CIRCLE CT"); - writer.nextRecord(); - writer.flush(); - - // make sure the tests work on Windows and on Linux - final String expected = this.joinLines("FIRSTNAME;LASTNAME;ADDRESS;CITY;STATE;ZIP", "JOHN;ANAME;1234 CIRCLE CT;ELYRIA;OH;44035"); - - Assert.assertEquals(expected, out.toString()); - } - - public void testWriteCsvWithMappingFile() throws Exception { - final InputStream mapping = this.getClass().getClassLoader().getResourceAsStream("DelimitedWithHeader.pzmap.xml"); - final Reader mappingReader = new InputStreamReader(mapping); - final StringWriter out = new StringWriter(); - - final Writer writer = new DelimiterWriterFactory(mappingReader, ';', '"').createWriter(out); - writer.addRecordEntry("LASTNAME", "ANAME"); - writer.addRecordEntry("FIRSTNAME", "JOHN"); - writer.addRecordEntry("ZIP", "44035"); - writer.addRecordEntry("CITY", "ELYRIA"); - writer.addRecordEntry("STATE", "OH"); - writer.addRecordEntry("ADDRESS", "1234 CIRCLE CT"); - writer.nextRecord(); - writer.flush(); - - final String expected = this.joinLines("FIRSTNAME;LASTNAME;ADDRESS;CITY;STATE;ZIP", "JOHN;ANAME;1234 CIRCLE CT;ELYRIA;OH;44035"); - - Assert.assertEquals(expected, out.toString()); - } - - public void testWriteCsvWithMissingColumns() throws Exception { - final InputStream mapping = this.getClass().getClassLoader().getResourceAsStream("DelimitedWithHeader.pzmap.xml"); - final InputStreamReader mappingReader = new InputStreamReader(mapping); - final StringWriter out = new StringWriter(); - - final Writer writer = new DelimiterWriterFactory(mappingReader, ';', '"').createWriter(out); - // note that we do not provide values for FIRSTNAME and ADDRESS - writer.addRecordEntry("LASTNAME", "ANAME"); - writer.addRecordEntry("ZIP", "44035"); - writer.addRecordEntry("CITY", "ELYRIA"); - writer.addRecordEntry("STATE", "OH"); - writer.nextRecord(); - writer.flush(); - - final String expected = this.joinLines("FIRSTNAME;LASTNAME;ADDRESS;CITY;STATE;ZIP", ";ANAME;;ELYRIA;OH;44035"); - - Assert.assertEquals(expected, out.toString()); - } - - public void testCreateWriterWithoutColumnMapping() throws Exception { - try { - final Writer writer = new DelimiterWriterFactory(';', '"').createWriter(new StringWriter()); - writer.addRecordEntry("ThisColumnDoesNotExist", "foo"); - Assert.fail("Writing to a DelimiterWriter without column mapping is not supported"); - } catch (final IllegalArgumentException iae) { - // exception was expected - } - } - - public void testCreateWriterWithNullOutputStream() throws IOException { - try { - new DelimiterWriterFactory((Map) null).createWriter(null); - } catch (final NullPointerException npe) { - // this one was expected - } - } - - public void testAllowWriteWithNoMapping() throws Exception { - final StringWriter sw = new StringWriter(); - - final DelimiterWriterOptions writerOpts = new DelimiterWriterOptions(); - writerOpts.setNoColumnMappings(true); - final DelimiterWriterFactory factory = new DelimiterWriterFactory(',', '"'); - final DelimiterWriter dwriter = (DelimiterWriter)factory.createWriter(sw, writerOpts); - - dwriter.addRecordEntry("Column1Data"); - dwriter.addRecordEntry("Column2,Data"); - dwriter.addRecordEntry("Column3Data"); - dwriter.nextRecord(); - dwriter.flush(); - - final String ls = System.getProperty("line.separator"); - final StringBuilder expected = new StringBuilder(); - expected.append("Column1Data").append(","); - expected.append("\"").append("Column2,Data").append("\"").append(","); - expected.append("Column3Data").append(ls); - - assertEquals("Testing writer with no colum mapping", expected.toString(), sw.toString()); - } - - public void testWriteValueWithQualifier() throws Exception { - final DelimiterWriterFactory factory = new DelimiterWriterFactory(';', '"'); - factory.addColumnTitle("col1"); - factory.addColumnTitle("col2"); - factory.addColumnTitle("col3"); - factory.addColumnTitle("col4"); - - final StringWriter out = new StringWriter(); - final Writer writer = factory.createWriter(out); - writer.addRecordEntry("col1", "value;with;delimiter"); - writer.addRecordEntry("col2", "normal value"); - writer.addRecordEntry("col3", "value \"with qualifier\""); - writer.addRecordEntry("col4", "value \"with qualifier\" and ;delimiter;"); - writer.nextRecord(); - writer.flush(); - - final String expected = this.joinLines("col1;col2;col3;col4", "\"value;with;delimiter\";normal value;\"value \"with qualifier\"\";\"value \"with qualifier\" and ;delimiter;\""); - Assert.assertEquals(expected, out.toString()); - } -} Copied: trunk/flatpack/src/test/java/net/sf/flatpack/writer/FixedLengthWriterTest.java (from rev 436, trunk/flatpack/src/test/java/net/sf/flatpack/writer/FixedLengthWriterTestCase.java) =================================================================== --- trunk/flatpack/src/test/java/net/sf/flatpack/writer/FixedLengthWriterTest.java (rev 0) +++ trunk/flatpack/src/test/java/net/sf/flatpack/writer/FixedLengthWriterTest.java 2012-04-16 22:42:45 UTC (rev 439) @@ -0,0 +1,143 @@ +package net.sf.flatpack.writer; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; + +import junit.framework.Assert; + +import net.sf.flatpack.InitialisationException; +import net.sf.flatpack.writer.FixedWriterFactory; +import net.sf.flatpack.writer.Writer; + +/** + * + * @author Dirk Holmes and Holger Holger Hoffstatte + */ +public class FixedLengthWriterTest extends PZWriterTestCase { + public void testWriteFixedLength() throws Exception { + final StringWriter out = new StringWriter(); + final Writer writer = new FixedWriterFactory(this.getMapping()).createWriter(out); + + writer.addRecordEntry("LASTNAME", "DOE"); + writer.addRecordEntry("ADDRESS", "1234 CIRCLE CT"); + writer.addRecordEntry("STATE", "OH"); + writer.addRecordEntry("ZIP", "44035"); + writer.addRecordEntry("FIRSTNAME", "JOHN"); + writer.addRecordEntry("CITY", "ELYRIA"); + writer.nextRecord(); + writer.flush(); + + final String expected = + this + .normalizeLineEnding("JOHN DOE 1234 CIRCLE CT ELYRIA OH44035"); + Assert.assertEquals(expected, out.toString()); + } + + public void testWriterWithDifferentFillChar() throws Exception { + final StringWriter out = new StringWriter(); + final Writer writer = new FixedWriterFactory(this.getMapping(), '.').createWriter(out); + + writer.addRecordEntry("LASTNAME", "DOE"); + writer.addRecordEntry("ADDRESS", "1234 CIRCLE CT"); + writer.addRecordEntry("STATE", "OH"); + writer.addRecordEntry("ZIP", "44035"); + writer.addRecordEntry("FIRSTNAME", "JOHN"); + writer.addRecordEntry("CITY", "ELYRIA"); + writer.nextRecord(); + writer.flush(); + + final String expected = + this + .normalizeLineEnding("JOHN...............................DOE................................1234 CIRCLE CT......................................................................................ELYRIA..............................................................................................OH44035"); + Assert.assertEquals(expected, out.toString()); + } + + public void testCreateParserWithMalformedMappingFile() throws Exception { + try { + final InputStream mapping = this.getClass().getClassLoader().getResourceAsStream("BrokenMapping.pzmap.xml"); + final InputStreamReader mappingReader = new InputStreamReader(mapping); + new FixedWriterFactory(mappingReader); + Assert.fail(); + } catch (final InitialisationException ie) { + // this excecption must occur, mapping xml is invalid + } + } + + public void testWriteStringWiderThanColumnDefinition() throws Exception { + final StringWriter out = new StringWriter(); + final Writer writer = new FixedWriterFactory(this.getMapping()).createWriter(out); + try { + writer.addRecordEntry("STATE", "THISISTOOLONG"); + Assert.fail("writing entries that are too long should fail"); + } catch (final IllegalArgumentException iae) { + // expected exception + } + } + + public void testWriteNullColumn() throws Exception { + final StringWriter out = new StringWriter(); + final Writer writer = new FixedWriterFactory(this.getMapping()).createWriter(out); + + writer.addRecordEntry("LASTNAME", "DOE"); + writer.addRecordEntry("ADDRESS", "1234 CIRCLE CT"); + writer.addRecordEntry("STATE", "OH"); + writer.addRecordEntry("ZIP", "44035"); + // note that we don't write a firstname + writer.addRecordEntry("FIRSTNAME", null); + writer.addRecordEntry("CITY", "ELYRIA"); + writer.nextRecord(); + writer.flush(); + + final String expected = + this + .normalizeLineEnding(" DOE 1234 CIRCLE CT ELYRIA OH44035"); + Assert.assertEquals(expected, out.toString()); + } + + public void DONOTtestWriteDifferentRecords() throws Exception{ + final String ls = System.getProperty("line.separator"); + final StringWriter out = new StringWriter(); + final Writer writer = new FixedWriterFactory(getMappingDiffRecordTypes()).createWriter(out); +// writer.setRecordId("header"); + writer.addRecordEntry("recordtype", "H"); + writer.addRecordEntry("headerdata1", "header data"); + writer.nextRecord(); + + writer.addRecordEntry("recordtype", "D"); + writer.addRecordEntry("detaildata1", "detail data"); + writer.nextRecord(); + writer.flush(); + + final StringBuilder expected = new StringBuilder(); + expected.append("H"); + expected.append("header data ").append(ls); + expected.append("D"); + expected.append("detail data ").append(ls); + + assertEquals("Checking writer for different record types...", expected.toString(), out.toString()); + + } + + private Reader getMapping() { + final InputStream mapping = this.getClass().getClassLoader().getResourceAsStream("FixedLength.pzmap.xml"); + return new InputStreamReader(mapping); + } + + private Reader getMappingDiffRecordTypes() { + String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \r\n" + + "<!DOCTYPE PZMAP SYSTEM \"pzfilereader.dtd\" > \r\n" + + " <PZMAP>\r\n" + + " <RECORD id=\"header\" startPosition=\"1\" endPosition=\"1\" indicator=\"H\">" + + " <COLUMN name=\"recordtype\" length=\"1\" /> \r\n" + + " <COLUMN name=\"headerdata1\" length=\"20\" /> \r\n" + + " </RECORD>" + + " <COLUMN name=\"recordtype\" length=\"1\" /> \r\n" + + " <COLUMN name=\"detaildata1\" length=\"20\" /> \r\n" + + " </PZMAP>"; + + return new StringReader(xml); + } +} Deleted: trunk/flatpack/src/test/java/net/sf/flatpack/writer/FixedLengthWriterTestCase.java =================================================================== --- trunk/flatpack/src/test/java/net/sf/flatpack/writer/FixedLengthWriterTestCase.java 2012-04-16 22:42:18 UTC (rev 438) +++ trunk/flatpack/src/test/java/net/sf/flatpack/writer/FixedLengthWriterTestCase.java 2012-04-16 22:42:45 UTC (rev 439) @@ -1,143 +0,0 @@ -package net.sf.flatpack.writer; - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; - -import junit.framework.Assert; - -import net.sf.flatpack.InitialisationException; -import net.sf.flatpack.writer.FixedWriterFactory; -import net.sf.flatpack.writer.Writer; - -/** - * - * @author Dirk Holmes and Holger Holger Hoffstatte - */ -public class FixedLengthWriterTestCase extends PZWriterTestCase { - public void testWriteFixedLength() throws Exception { - final StringWriter out = new StringWriter(); - final Writer writer = new FixedWriterFactory(this.getMapping()).createWriter(out); - - writer.addRecordEntry("LASTNAME", "DOE"); - writer.addRecordEntry("ADDRESS", "1234 CIRCLE CT"); - writer.addRecordEntry("STATE", "OH"); - writer.addRecordEntry("ZIP", "44035"); - writer.addRecordEntry("FIRSTNAME", "JOHN"); - writer.addRecordEntry("CITY", "ELYRIA"); - writer.nextRecord(); - writer.flush(); - - final String expected = - this - .normalizeLineEnding("JOHN DOE 1234 CIRCLE CT ELYRIA OH44035"); - Assert.assertEquals(expected, out.toString()); - } - - public void testWriterWithDifferentFillChar() throws Exception { - final StringWriter out = new StringWriter(); - final Writer writer = new FixedWriterFactory(this.getMapping(), '.').createWriter(out); - - writer.addRecordEntry("LASTNAME", "DOE"); - writer.addRecordEntry("ADDRESS", "1234 CIRCLE CT"); - writer.addRecordEntry("STATE", "OH"); - writer.addRecordEntry("ZIP", "44035"); - writer.addRecordEntry("FIRSTNAME", "JOHN"); - writer.addRecordEntry("CITY", "ELYRIA"); - writer.nextRecord(); - writer.flush(); - - final String expected = - this - .normalizeLineEnding("JOHN...............................DOE................................1234 CIRCLE CT......................................................................................ELYRIA..............................................................................................OH44035"); - Assert.assertEquals(expected, out.toString()); - } - - public void testCreateParserWithMalformedMappingFile() throws Exception { - try { - final InputStream mapping = this.getClass().getClassLoader().getResourceAsStream("BrokenMapping.pzmap.xml"); - final InputStreamReader mappingReader = new InputStreamReader(mapping); - new FixedWriterFactory(mappingReader); - Assert.fail(); - } catch (final InitialisationException ie) { - // this excecption must occur, mapping xml is invalid - } - } - - public void testWriteStringWiderThanColumnDefinition() throws Exception { - final StringWriter out = new StringWriter(); - final Writer writer = new FixedWriterFactory(this.getMapping()).createWriter(out); - try { - writer.addRecordEntry("STATE", "THISISTOOLONG"); - Assert.fail("writing entries that are too long should fail"); - } catch (final IllegalArgumentException iae) { - // expected exception - } - } - - public void testWriteNullColumn() throws Exception { - final StringWriter out = new StringWriter(); - final Writer writer = new FixedWriterFactory(this.getMapping()).createWriter(out); - - writer.addRecordEntry("LASTNAME", "DOE"); - writer.addRecordEntry("ADDRESS", "1234 CIRCLE CT"); - writer.addRecordEntry("STATE", "OH"); - writer.addRecordEntry("ZIP", "44035"); - // note that we don't write a firstname - writer.addRecordEntry("FIRSTNAME", null); - writer.addRecordEntry("CITY", "ELYRIA"); - writer.nextRecord(); - writer.flush(); - - final String expected = - this - .normalizeLineEnding(" DOE 1234 CIRCLE CT ELYRIA OH44035"); - Assert.assertEquals(expected, out.toString()); - } - - public void testWriteDifferentRecords() throws Exception{ - final String ls = System.getProperty("line.separator"); - final StringWriter out = new StringWriter(); - final Writer writer = new FixedWriterFactory(getMappingDiffRecordTypes()).createWriter(out); - writer.setRecordId("header"); - writer.addRecordEntry("recordtype", "H"); - writer.addRecordEntry("headerdata1", "header data"); - writer.nextRecord(); - - writer.addRecordEntry("recordtype", "D"); - writer.addRecordEntry("detaildata1", "detail data"); - writer.nextRecord(); - writer.flush(); - - final StringBuilder expected = new StringBuilder(); - expected.append("H"); - expected.append("header data ").append(ls); - expected.append("D"); - expected.append("detail data ").append(ls); - - assertEquals("Checking writer for different record types...", expected.toString(), out.toString()); - - } - - private Reader getMapping() { - final InputStream mapping = this.getClass().getClassLoader().getResourceAsStream("FixedLength.pzmap.xml"); - return new InputStreamReader(mapping); - } - - private Reader getMappingDiffRecordTypes() { - String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \r\n" + - "<!DOCTYPE PZMAP SYSTEM \"pzfilereader.dtd\" > \r\n" + - " <PZMAP>\r\n" + - " <RECORD id=\"header\" startPosition=\"1\" endPosition=\"1\" indicator=\"H\">" + - " <COLUMN name=\"recordtype\" length=\"1\" /> \r\n" + - " <COLUMN name=\"headerdata1\" length=\"20\" /> \r\n" + - " </RECORD>" + - " <COLUMN name=\"recordtype\" length=\"1\" /> \r\n" + - " <COLUMN name=\"detaildata1\" length=\"20\" /> \r\n" + - " </PZMAP>"; - - return new StringReader(xml); - } -} Deleted: trunk/flatpack/src/test/java/net/sf/flatpack/writer/PZWriterTestCase.java =================================================================== --- trunk/flatpack/src/test/java/net/sf/flatpack/writer/PZWriterTestCase.java 2012-04-16 22:42:18 UTC (rev 438) +++ trunk/flatpack/src/test/java/net/sf/flatpack/writer/PZWriterTestCase.java 2012-04-16 22:42:45 UTC (rev 439) @@ -1,30 +0,0 @@ -package net.sf.flatpack.writer; - -import junit.framework.TestCase; - -/** - * - * @author Dirk Holmes and Holger Holger Hoffstatte - */ -public abstract class PZWriterTestCase extends TestCase { - private final String lineSeparator = System.getProperty("line.separator"); - - protected String joinLines(final String line1, final String line2) { - if (line1 == null) { - throw new IllegalArgumentException("parameter string1 may not be null"); - } - - final StringBuffer result = new StringBuffer(line1); - result.append(lineSeparator); - if (line2 != null) { - result.append(line2); - result.append(lineSeparator); - } - - return result.toString(); - } - - protected String normalizeLineEnding(final String line) { - return this.joinLines(line, null); - } -} Added: trunk/flatpack/src/test/java/net/sf/flatpack/writer/PZWriterTestCase.java =================================================================== --- trunk/flatpack/src/test/java/net/sf/flatpack/writer/PZWriterTestCase.java (rev 0) +++ trunk/flatpack/src/test/java/net/sf/flatpack/writer/PZWriterTestCase.java 2012-04-16 22:42:45 UTC (rev 439) @@ -0,0 +1,30 @@ +package net.sf.flatpack.writer; + +import junit.framework.TestCase; + +/** + * + * @author Dirk Holmes and Holger Holger Hoffstatte + */ +public abstract class PZWriterTestCase extends TestCase { + private final String lineSeparator = System.getProperty("line.separator"); + + protected String joinLines(final String line1, final String line2) { + if (line1 == null) { + throw new IllegalArgumentException("parameter string1 may not be null"); + } + + final StringBuffer result = new StringBuffer(line1); + result.append(lineSeparator); + if (line2 != null) { + result.append(line2); + result.append(lineSeparator); + } + + return result.toString(); + } + + protected String normalizeLineEnding(final String line) { + return this.joinLines(line, null); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-04-16 22:42:24
|
Revision: 438 http://flatpack.svn.sourceforge.net/flatpack/?rev=438&view=rev Author: benoitx Date: 2012-04-16 22:42:18 +0000 (Mon, 16 Apr 2012) Log Message: ----------- Re-org the printHeader or not depending on the way the factory is called. Removed Paths: ------------- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterOptions.java Deleted: trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterOptions.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterOptions.java 2012-04-13 13:48:38 UTC (rev 437) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterOptions.java 2012-04-16 22:42:18 UTC (rev 438) @@ -1,44 +0,0 @@ -package net.sf.flatpack.writer; - -/** - * Defines options for various DelimiterWriter behaviors - * - * @author Paul Zepernick - */ -public class DelimiterWriterOptions { - - private boolean noColumnMappings; - - - - /** - * Returns a DelimiterWriterOptions instance - * - * @return DelimiterWriterOptions - */ - public static DelimiterWriterOptions getInstance() { - return new DelimiterWriterOptions(); - } - - - - /** - * @return the noColumnMappings - */ - public boolean isNoColumnMappings() { - return noColumnMappings; - } - - - - /** - * When this is set to true, the addRecordEntry(column, value) will throw an exception. You - * must use addRecordEntry(value). - * - * @param noColumnMappings the noColumnMappings to set - */ - public void setNoColumnMappings(boolean noColumnMappings) { - this.noColumnMappings = noColumnMappings; - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-04-13 13:48:44
|
Revision: 437 http://flatpack.svn.sourceforge.net/flatpack/?rev=437&view=rev Author: benoitx Date: 2012-04-13 13:48:38 +0000 (Fri, 13 Apr 2012) Log Message: ----------- BAD PRACTICE.. the dependencies to slf4j should not be compile but provided. Modified Paths: -------------- trunk/flatpack/pom.xml trunk/flatpack-samples/pom.xml trunk/pom.xml Modified: trunk/flatpack/pom.xml =================================================================== --- trunk/flatpack/pom.xml 2012-04-04 14:53:43 UTC (rev 436) +++ trunk/flatpack/pom.xml 2012-04-13 13:48:38 UTC (rev 437) @@ -5,7 +5,7 @@ <parent> <groupId>net.sf.flatpack</groupId> <artifactId>flatpack-parent</artifactId> - <version>3.3.0-SNAPSHOT</version> + <version>3.3.3-SNAPSHOT</version> </parent> @@ -104,21 +104,25 @@ <groupId>jdom</groupId> <artifactId>jdom</artifactId> <version>1.0</version> + <scope>provided</scope> </dependency> <dependency> <groupId>jexcelapi</groupId> <artifactId>jxl</artifactId> <version>2.4.2</version> + <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.1.0-RC1</version> + <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.1.0-RC1</version> + <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> Modified: trunk/flatpack-samples/pom.xml =================================================================== --- trunk/flatpack-samples/pom.xml 2012-04-04 14:53:43 UTC (rev 436) +++ trunk/flatpack-samples/pom.xml 2012-04-13 13:48:38 UTC (rev 437) @@ -5,7 +5,7 @@ <parent> <groupId>net.sf.flatpack</groupId> <artifactId>flatpack-parent</artifactId> - <version>3.3.0-SNAPSHOT</version> + <version>3.3.3-SNAPSHOT</version> </parent> @@ -102,21 +102,25 @@ <groupId>jdom</groupId> <artifactId>jdom</artifactId> <version>1.0</version> + <scope>provided</scope> </dependency> <dependency> <groupId>jexcelapi</groupId> <artifactId>jxl</artifactId> <version>2.4.2</version> + <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.1.0-RC1</version> + <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.1.0-RC1</version> + <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-04-04 14:53:43 UTC (rev 436) +++ trunk/pom.xml 2012-04-13 13:48:38 UTC (rev 437) @@ -5,7 +5,7 @@ <groupId>net.sf.flatpack</groupId> <artifactId>flatpack-parent</artifactId> <name>FlatPack</name> - <version>3.3.0-SNAPSHOT</version> + <version>3.3.3-SNAPSHOT</version> <packaging>pom</packaging> <description>Simple Java delimited and fixed width file parser. Handles CSV, Excel CSV, Tab, Pipe delimiters. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2012-04-04 14:53:50
|
Revision: 436 http://flatpack.svn.sourceforge.net/flatpack/?rev=436&view=rev Author: zepernick Date: 2012-04-04 14:53:43 +0000 (Wed, 04 Apr 2012) Log Message: ----------- Enhancements to the Writer: No column mapping required on delimiter writer. Ability to write different record types. Modified Paths: -------------- trunk/flatpack/src/main/java/net/sf/flatpack/writer/AbstractWriter.java trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterFactory.java trunk/flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java trunk/flatpack/src/main/java/net/sf/flatpack/writer/Writer.java trunk/flatpack/src/main/java/net/sf/flatpack/xml/MapParser.java trunk/flatpack/src/test/java/net/sf/flatpack/pzparser/PZParserOptsTest.java trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java trunk/flatpack/src/test/java/net/sf/flatpack/writer/FixedLengthWriterTestCase.java Added Paths: ----------- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterOptions.java Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/AbstractWriter.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/AbstractWriter.java 2012-04-04 14:51:39 UTC (rev 435) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/AbstractWriter.java 2012-04-04 14:53:43 UTC (rev 436) @@ -4,14 +4,21 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.Set; +import net.sf.flatpack.util.FPConstants; + /** * This class encapsulates the writer that's used to output the data. * @author Dirk Holmes and Holger Holger Hoffstatte */ public abstract class AbstractWriter extends Object implements Writer { private final BufferedWriter writer; - private Map rowMap; + + private Map rowMap; //used when using column headers + + //the record ID that is currently being written. The default is the DETAIL_ID which are <columns> that are mapped outside of <record> elements + private String recordId = FPConstants.DETAIL_ID; public AbstractWriter(final java.io.Writer output) { super(); @@ -28,6 +35,20 @@ } rowMap.put(columnName, value); } + + //TODO implement writing for no column titles +// public void addRecordEntry(final Object value) { +// if ( +// +// if (rowMap == null) { +// rowMap = new HashMap(); +// } +// +// if (!validateColumnTitle(columnName)) { +// throw new IllegalArgumentException("unknown column: \"" + columnName + "\""); +// } +// rowMap.put(columnName, value); +// } /** * Subclasses must implement this method to perform validation of @@ -50,6 +71,8 @@ // the row should have been written out by the subclass so it's safe to // discard it here rowMap = null; + //default the recordId when we go to the next record + recordId = FPConstants.DETAIL_ID; writer.newLine(); } @@ -78,8 +101,30 @@ writer.flush(); writer.close(); } + protected Map getRowMap() { return rowMap; } + + /** + * @return the recordId + */ + public String getRecordId() { + return recordId; + } + + /** + * Sets the record ID for the record that is being written. This should be used when mapping <record> elements. + * The "id" attribute of the record element should be specified here and needs to be called before calling addRecordEntry(). + * This will throw an exception if addRecordEntry() has been called for the record currently being processed. + * + * @param recordId the recordId to set + */ + public void setRecordId(String recordId) { + if (rowMap != null && !rowMap.isEmpty()) { + throw new RuntimeException("addRecordEntry() has already been called for this row. Please set the record id prior to adding data to this row."); + } + this.recordId = recordId; + } } Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java 2012-04-04 14:51:39 UTC (rev 435) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java 2012-04-04 14:53:43 UTC (rev 436) @@ -1,14 +1,14 @@ package net.sf.flatpack.writer; import java.io.IOException; -import java.util.ArrayList; +import java.math.BigDecimal; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.math.BigDecimal; import net.sf.flatpack.structure.ColumnMetaData; import net.sf.flatpack.util.FPConstants; +import net.sf.flatpack.xml.XMLRecordElement; /** * @@ -16,26 +16,50 @@ */ public class DelimiterWriter extends AbstractWriter { private char delimiter; + private char qualifier; - private List columnTitles = null; + + //private List columnTitles = null; + private boolean columnTitlesWritten = false; + + private Map columnMapping; + + private DelimiterWriterOptions writerOptions; + + //this is used when using addRecordEntry() and no column names + private boolean delimitNextEntry = false; protected DelimiterWriter(final Map columnMapping, final java.io.Writer output, final char delimiter, final char qualifier) throws IOException { + + this(columnMapping, output, delimiter, qualifier, new DelimiterWriterOptions()); + } + + protected DelimiterWriter(final Map columnMapping, + final java.io.Writer output, final char delimiter, + final char qualifier, DelimiterWriterOptions writerOptions) throws IOException { super(output); this.delimiter = delimiter; this.qualifier = qualifier; - columnTitles = new ArrayList(); - final List columns = (List) columnMapping.get(FPConstants.DETAIL_ID); - final Iterator columnIter = columns.iterator(); - while (columnIter.hasNext()) { - final ColumnMetaData element = (ColumnMetaData) columnIter.next(); - columnTitles.add(element.getColName()); - } - // write the column headers - this.nextRecord(); +// columnTitles = new ArrayList(); +// final List columns = (List) columnMapping.get(FPConstants.DETAIL_ID); +// final Iterator columnIter = columns.iterator(); +// while (columnIter.hasNext()) { +// final ColumnMetaData element = (ColumnMetaData) columnIter.next(); +// columnTitles.add(element.getColName()); +// } + this.columnMapping = columnMapping; + this.writerOptions = writerOptions; + if (!writerOptions.isNoColumnMappings()) { + // write the column headers + this.nextRecord(); + } else { + //flag the headers as written so that we don't try to write them when calling nextRecord() + columnTitlesWritten = true; + } } protected void writeWithDelimiter(final Object value) throws IOException { @@ -68,18 +92,75 @@ super.write(qualifier); } } - - protected void addColumnTitle(final String string) { - if (string == null) { - throw new IllegalArgumentException("column title may not be null"); + + public void addRecordEntry(String columnName, Object value) { + if (writerOptions.isNoColumnMappings()) { + throw new UnsupportedOperationException("Column Names Cannot Be Bound To Values When Column Mappings Have Been Turned Off..."); } - columnTitles.add(string); + super.addRecordEntry(columnName, value); } + + /** + * Adds a record entry when not using column names in the file + * + * @param value + * @throws IOException + */ + public void addRecordEntry(Object value) throws IOException{ + if (!writerOptions.isNoColumnMappings()) { + throw new UnsupportedOperationException("Must use addRecordEntry(String,Object) When Using Column Names..."); + } + + if (delimitNextEntry) { + //need to use the super write here. The write in this class will try and qualify the delimiter. + //we also cannot use the writeWithDelimiter() here. It puts the delimiter after the value. We don't + //know the last column to be written so we cannot utilize that here as we did with the mappings + super.write(this.delimiter); + + } + + this.write(value.toString()); + delimitNextEntry = true; + } + //TODO find out if these are needed since the titles can already be added from the Factory +// protected void addColumnTitle(final String string) { +// addColumnTitle(string, FPConstants.DETAIL_ID); +// } +// +// protected void addColumnTitle(final String string, final String recordId) { +// if (string == null) { +// throw new IllegalArgumentException("column title may not be null"); +// } +// List cols = null; +// if (FPConstants.DETAIL_ID.equals(recordId)) { +// //the key for the detail key contains a List in the Map +// cols = (List)this.columnMapping.get(FPConstants.DETAIL_ID); +// if (cols == null) { +// cols = new ArrayList(); +// this.columnMapping.put(FPConstants.DETAIL_ID, cols); +// } +// +// } else { +// //the map contains an XMLRecord element and then the list is contained under that +// XMLRecordElement xmlRec = (XMLRecordElement)this.columnMapping.get(recordId); +// if (xmlRec == null) { +// cols = new ArrayList(); +// xmlRec = new XMLRecordElement(); +// xmlRec.setColumns(cols, null); +// this.columnMapping.put(recordId, xmlRec); +// } else { +// cols = xmlRec.getColumns(); +// } +// } +// +// cols.add(string); +// } + protected void writeColumnTitles() throws IOException { - final Iterator titleIter = columnTitles.iterator(); + final Iterator titleIter = ((List)this.columnMapping.get(FPConstants.DETAIL_ID)).iterator(); while (titleIter.hasNext()) { - final String title = (String) titleIter.next(); + final String title = ((ColumnMetaData)titleIter.next()).getColName(); if (titleIter.hasNext()) { this.writeWithDelimiter(title); @@ -90,9 +171,15 @@ } protected void writeRow() throws IOException { - final Iterator titlesIter = columnTitles.iterator(); + Iterator titlesIter = null; + if (FPConstants.DETAIL_ID.equals(getRecordId())) { + titlesIter = ((List)this.columnMapping.get(FPConstants.DETAIL_ID)).iterator(); + } else { + final XMLRecordElement xmlRec = (XMLRecordElement)this.columnMapping.get(getRecordId()); + titlesIter = xmlRec.getColumns().iterator(); + } while (titlesIter.hasNext()) { - final String columnTitle = (String) titlesIter.next(); + final String columnTitle = ((ColumnMetaData)titlesIter.next()).getColName(); if (getRowMap() != null) { if (titlesIter.hasNext()) { writeWithDelimiter(getRowMap().get(columnTitle)); @@ -102,27 +189,33 @@ } } } + public final void nextRecord() throws IOException { - if (!columnTitlesWritten) { - this.writeColumnTitles(); - columnTitlesWritten = true; - } else { - this.writeRow(); - } - + if (!writerOptions.isNoColumnMappings()) { + if (!columnTitlesWritten) { + this.writeColumnTitles(); + columnTitlesWritten = true; + } else { + this.writeRow(); + } + } + + delimitNextEntry = false; super.nextRecord(); } - public void printFooter() { - // TODO DO: implement footer handling - } - - public void printHeader() { - // TODO DO: implement header handling - } - protected boolean validateColumnTitle(final String columnTitle) { - return columnTitles.contains(columnTitle); + //return columnTitles.contains(columnTitle); + + //the column index for <record> elements is stored in the Map as the COL_IDX constant_<record id attribute> + final Map columnNameToIndex = (Map) columnMapping + .get(getRecordId().equals(FPConstants.DETAIL_ID) ? FPConstants.COL_IDX : FPConstants.COL_IDX + "_" + getRecordId()); + if (columnNameToIndex == null) { + //TODO this needs to be moved to the AbstractWriter, but the columnMapping is not exposed to it currently + //This should only happen if the getRecordId() contained an invalid record id + throw new RuntimeException("The record ID[" + getRecordId() + "] Is Not Mapped"); + } + return columnNameToIndex.keySet().contains(columnTitle); } } Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterFactory.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterFactory.java 2012-04-04 14:51:39 UTC (rev 435) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterFactory.java 2012-04-04 14:53:43 UTC (rev 436) @@ -2,11 +2,14 @@ import java.io.IOException; import java.io.Reader; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import net.sf.flatpack.structure.ColumnMetaData; import net.sf.flatpack.util.FPConstants; +import net.sf.flatpack.xml.XMLRecordElement; import org.jdom.JDOMException; @@ -20,6 +23,7 @@ private final char delimiter; private final char qualifier; + public DelimiterWriterFactory(final char delimiter, final char qualifier) { super(); @@ -62,22 +66,76 @@ public char getQualifier() { return qualifier; } + - public Writer createWriter(final java.io.Writer out) throws IOException { - return new DelimiterWriter(this.getColumnMapping(), out, delimiter, qualifier); + public Writer createWriter(final java.io.Writer out) throws IOException { + return createWriter(out, new DelimiterWriterOptions()); + } + + /** + * Create an instance of the DelimterWriter + * + * @param out + * @param delimiterWriterOptions + * Options for Writing + * @return {@link DelimiterWriter} + * @throws IOException + */ + public Writer createWriter(final java.io.Writer out, final DelimiterWriterOptions delimiterWriterOptions) throws IOException { + return new DelimiterWriter(this.getColumnMapping(), out, delimiter, qualifier, delimiterWriterOptions); + } - // TODO DO: check that no column titles can be added after first nextRecord - public void addColumnTitle(final String columnTitle) { + /** + * Add column titles for mapping. This can be done in lieu of using an XML Mapping. This needs to be done before calling createWriter() + * + * @param columnTitle + * @param recordId + */ + public void addColumnTitle(final String columnTitle, final String recordId) { + final String colIdxKey = FPConstants.DETAIL_ID.equals(recordId) ? FPConstants.COL_IDX : FPConstants.COL_IDX + "_" + recordId; final Map columnMapping = this.getColumnMapping(); - final List columnMetaDatas = (List) columnMapping.get(FPConstants.DETAIL_ID); - final Map columnIndices = (Map) columnMapping.get(FPConstants.COL_IDX); + List columnMetaDatas = null; + if (FPConstants.DETAIL_ID.equals(recordId)) { + //the detail record will always be there. It is being setup by the AbstractWriter if it + //is not coming off of the XML + columnMetaDatas = (List) columnMapping.get(FPConstants.DETAIL_ID); + } else { + //this has a XMLRecord in the map, for anything other than the detail id + XMLRecordElement xmlRec = (XMLRecordElement)columnMapping.get(recordId); + if (xmlRec == null) { + columnMetaDatas = new ArrayList(); + xmlRec = new XMLRecordElement(); + xmlRec.setColumns(columnMetaDatas, null); + columnMapping.put(recordId, xmlRec); + } else { + columnMetaDatas = xmlRec.getColumns(); + } + } + + Map columnIndices = (Map) columnMapping.get(colIdxKey); + if (columnIndices == null) { + columnIndices = new HashMap(); + columnMapping.put(recordId, columnIndices); + } final ColumnMetaData metaData = new ColumnMetaData(); metaData.setColName(columnTitle); columnMetaDatas.add(metaData); final Integer columnIndex = Integer.valueOf(columnMetaDatas.indexOf(metaData)); - columnIndices.put(columnIndex, columnTitle); + columnIndices.put(columnTitle, columnIndex); } + + /** + * Add column titles for mapping. This can be done in lieu of using an XML Mapping. This needs to be done before calling createWriter() + * + * @param string + */ + public void addColumnTitle(final String string) { + addColumnTitle(string, FPConstants.DETAIL_ID); + } + + + } Added: trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterOptions.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterOptions.java (rev 0) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriterOptions.java 2012-04-04 14:53:43 UTC (rev 436) @@ -0,0 +1,44 @@ +package net.sf.flatpack.writer; + +/** + * Defines options for various DelimiterWriter behaviors + * + * @author Paul Zepernick + */ +public class DelimiterWriterOptions { + + private boolean noColumnMappings; + + + + /** + * Returns a DelimiterWriterOptions instance + * + * @return DelimiterWriterOptions + */ + public static DelimiterWriterOptions getInstance() { + return new DelimiterWriterOptions(); + } + + + + /** + * @return the noColumnMappings + */ + public boolean isNoColumnMappings() { + return noColumnMappings; + } + + + + /** + * When this is set to true, the addRecordEntry(column, value) will throw an exception. You + * must use addRecordEntry(value). + * + * @param noColumnMappings the noColumnMappings to set + */ + public void setNoColumnMappings(boolean noColumnMappings) { + this.noColumnMappings = noColumnMappings; + } + +} Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java 2012-04-04 14:51:39 UTC (rev 435) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java 2012-04-04 14:53:43 UTC (rev 436) @@ -9,6 +9,7 @@ import net.sf.flatpack.structure.ColumnMetaData; import net.sf.flatpack.util.FPConstants; +import net.sf.flatpack.xml.XMLRecordElement; /** * @@ -96,27 +97,27 @@ } protected boolean validateColumnTitle(final String columnTitle) { + //the column index for <record> elements is stored in the Map as the COL_IDX constant_<record id attribute> final Map columnNameToIndex = (Map) columnMapping - .get(FPConstants.COL_IDX); + .get(getRecordId().equals(FPConstants.DETAIL_ID) ? FPConstants.COL_IDX : FPConstants.COL_IDX + "_" + getRecordId()); + if (columnNameToIndex == null) { + //TODO this needs to be moved to the AbstractWriter, but the columnMapping is not exposed to it currently + //This should only happen if the getRecordId() contained an invalid record id + throw new RuntimeException("The record ID[" + getRecordId() + "] Is Not Mapped"); + } return columnNameToIndex.keySet().contains(columnTitle); } - public void printFooter() { - // TODO DO: implement footer handling - - } - - public void printHeader() { - // TODO DO: implement header handling - - } - /** * @return List of ColumnMetaData objects describing the mapping defined in * the XML file. */ private List getColumnMetaData() { - return (List) columnMapping.get(FPConstants.DETAIL_ID); + if (getRecordId().equals(FPConstants.DETAIL_ID)) { + return (List) columnMapping.get(getRecordId()); + } + + return ((XMLRecordElement)columnMapping.get(getRecordId())).getColumns(); } private ColumnMetaData getColumnMetaData(final String columnName) { @@ -128,7 +129,7 @@ } } - throw new IllegalArgumentException("Column \"" + columnName + throw new IllegalArgumentException("Record ID[" + getRecordId() + "] Column \"" + columnName + "\" unknown"); } } Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/Writer.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/Writer.java 2012-04-04 14:51:39 UTC (rev 435) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/Writer.java 2012-04-04 14:53:43 UTC (rev 436) @@ -7,17 +7,21 @@ * @author Dirk Holmes and Holger Holger Hoffstatte */ public interface Writer { - /** put writer into header mode. TODO: how to handle multiple header lines? */ - void printHeader(); - /** put writer into footer mode. TODO: how to handle multiple footer lines? */ - void printFooter(); + void addRecordEntry(String columnName, Object value); - void addRecordEntry(String columnName, Object value); - void nextRecord() throws IOException; void flush() throws IOException; void close() throws IOException; + + /** + * Sets the record ID for the record that is being written. This should be used when mapping <record> elements. + * The "id" attribute of the record element should be specified here and needs to be called before calling addRecordEntry(). + * This will throw an exception if addRecordEntry() has been called for the record currently being processed. + * + * @param recordId the recordId to set + */ + void setRecordId(String recordId); } Modified: trunk/flatpack/src/main/java/net/sf/flatpack/xml/MapParser.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/xml/MapParser.java 2012-04-04 14:51:39 UTC (rev 435) +++ trunk/flatpack/src/main/java/net/sf/flatpack/xml/MapParser.java 2012-04-04 14:53:43 UTC (rev 436) @@ -174,12 +174,14 @@ xmlre.setEndPositition(convertAttributeToInt(xmlElement.getAttribute("endPosition"))); xmlre.setElementCount(convertAttributeToInt(xmlElement.getAttribute("elementCount"))); mdIndex.put(xmlElement.getAttributeValue("id"), xmlre); + //make a column index for non detail records + mdIndex.put(FPConstants.COL_IDX + "_" + xmlElement.getAttributeValue("id"), ParserUtils.buidColumnIndexMap(columns, pzparser)); } if (showDebug) { setShowDebug(mdIndex); } - + return mdIndex; } @@ -292,6 +294,20 @@ final Map m = (Map) map.get(FPConstants.COL_IDX); map.remove(FPConstants.COL_IDX); + + //loop through the map and remove anything else that is an index of FPConstancts.COL_IDX + _ + //these were put in for the writer. + //TODO maybe these shoudld be thrown into the MetaData instead of just discarded, but they are unused + //in the Reader the moment. This parseMap is not utilized in the writer so it is safe to remove them here + final Iterator entrySetIt = map.entrySet().iterator(); + while (entrySetIt.hasNext()) { + final Entry e = (Entry)entrySetIt.next(); + if (((String)e.getKey()).startsWith(FPConstants.COL_IDX + "_")) { + entrySetIt.remove(); + } + } + + // System.out.println(map); return new MetaData(col, m, map); } } Modified: trunk/flatpack/src/test/java/net/sf/flatpack/pzparser/PZParserOptsTest.java =================================================================== --- trunk/flatpack/src/test/java/net/sf/flatpack/pzparser/PZParserOptsTest.java 2012-04-04 14:51:39 UTC (rev 435) +++ trunk/flatpack/src/test/java/net/sf/flatpack/pzparser/PZParserOptsTest.java 2012-04-04 14:53:43 UTC (rev 436) @@ -218,6 +218,38 @@ assertEquals(true, ds.next()); } + public void testFixedWidthMultipleRecordElementsInMapping() { + DataSet ds; + String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \r\n" + + "<!DOCTYPE PZMAP SYSTEM \"pzfilereader.dtd\" > \r\n" + + " <PZMAP>\r\n" + + " <RECORD id=\"header\" startPosition=\"1\" endPosition=\"1\" indicator=\"H\">" + + " <COLUMN name=\"recordtype\" length=\"1\" /> \r\n" + + " <COLUMN name=\"headerdata1\" length=\"20\" /> \r\n" + + " </RECORD>" + + " <COLUMN name=\"recordtype\" length=\"1\" /> \r\n" + + " <COLUMN name=\"detaildata1\" length=\"20\" /> \r\n" + + " </PZMAP>"; + + String cols = "HHEADER DATA \r\n" + + "DDETAIL DATA \r\n"; + + Parser p = DefaultParserFactory.getInstance().newFixedLengthParser(new StringReader(xml), new StringReader(cols)); + ds = p.parse(); + int i = 0; + while (ds.next()) { + if (i == 0 ) { + assertEquals("Checking to see if we have the header record...", ds.isRecordID("header"), true); + assertEquals("Checking header data", ds.getString("headerdata1"), "HEADER DATA"); + } else { + assertEquals("Checking detail data", ds.getString("detaildata1"), "DETAIL DATA"); + } + + i++; + } + + } + public void testSorting() { DataSet ds; String cols = "fname,lname,dob,anumber\r\npaul,zepernick,06/21/1981,2\r\nbenoit,xhenseval,05/01/1970,12"; Modified: trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java =================================================================== --- trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java 2012-04-04 14:51:39 UTC (rev 435) +++ trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java 2012-04-04 14:53:43 UTC (rev 436) @@ -101,6 +101,29 @@ // this one was expected } } + + public void testAllowWriteWithNoMapping() throws Exception { + final StringWriter sw = new StringWriter(); + + final DelimiterWriterOptions writerOpts = new DelimiterWriterOptions(); + writerOpts.setNoColumnMappings(true); + final DelimiterWriterFactory factory = new DelimiterWriterFactory(',', '"'); + final DelimiterWriter dwriter = (DelimiterWriter)factory.createWriter(sw, writerOpts); + + dwriter.addRecordEntry("Column1Data"); + dwriter.addRecordEntry("Column2,Data"); + dwriter.addRecordEntry("Column3Data"); + dwriter.nextRecord(); + dwriter.flush(); + + final String ls = System.getProperty("line.separator"); + final StringBuilder expected = new StringBuilder(); + expected.append("Column1Data").append(","); + expected.append("\"").append("Column2,Data").append("\"").append(","); + expected.append("Column3Data").append(ls); + + assertEquals("Testing writer with no colum mapping", expected.toString(), sw.toString()); + } public void testWriteValueWithQualifier() throws Exception { final DelimiterWriterFactory factory = new DelimiterWriterFactory(';', '"'); Modified: trunk/flatpack/src/test/java/net/sf/flatpack/writer/FixedLengthWriterTestCase.java =================================================================== --- trunk/flatpack/src/test/java/net/sf/flatpack/writer/FixedLengthWriterTestCase.java 2012-04-04 14:51:39 UTC (rev 435) +++ trunk/flatpack/src/test/java/net/sf/flatpack/writer/FixedLengthWriterTestCase.java 2012-04-04 14:53:43 UTC (rev 436) @@ -3,6 +3,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.io.StringReader; import java.io.StringWriter; import junit.framework.Assert; @@ -95,9 +96,48 @@ .normalizeLineEnding(" DOE 1234 CIRCLE CT ELYRIA OH44035"); Assert.assertEquals(expected, out.toString()); } + + public void testWriteDifferentRecords() throws Exception{ + final String ls = System.getProperty("line.separator"); + final StringWriter out = new StringWriter(); + final Writer writer = new FixedWriterFactory(getMappingDiffRecordTypes()).createWriter(out); + writer.setRecordId("header"); + writer.addRecordEntry("recordtype", "H"); + writer.addRecordEntry("headerdata1", "header data"); + writer.nextRecord(); + + writer.addRecordEntry("recordtype", "D"); + writer.addRecordEntry("detaildata1", "detail data"); + writer.nextRecord(); + writer.flush(); + + final StringBuilder expected = new StringBuilder(); + expected.append("H"); + expected.append("header data ").append(ls); + expected.append("D"); + expected.append("detail data ").append(ls); + + assertEquals("Checking writer for different record types...", expected.toString(), out.toString()); + + } private Reader getMapping() { final InputStream mapping = this.getClass().getClassLoader().getResourceAsStream("FixedLength.pzmap.xml"); return new InputStreamReader(mapping); } + + private Reader getMappingDiffRecordTypes() { + String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \r\n" + + "<!DOCTYPE PZMAP SYSTEM \"pzfilereader.dtd\" > \r\n" + + " <PZMAP>\r\n" + + " <RECORD id=\"header\" startPosition=\"1\" endPosition=\"1\" indicator=\"H\">" + + " <COLUMN name=\"recordtype\" length=\"1\" /> \r\n" + + " <COLUMN name=\"headerdata1\" length=\"20\" /> \r\n" + + " </RECORD>" + + " <COLUMN name=\"recordtype\" length=\"1\" /> \r\n" + + " <COLUMN name=\"detaildata1\" length=\"20\" /> \r\n" + + " </PZMAP>"; + + return new StringReader(xml); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2012-04-04 14:51:49
|
Revision: 435 http://flatpack.svn.sourceforge.net/flatpack/?rev=435&view=rev Author: zepernick Date: 2012-04-04 14:51:39 +0000 (Wed, 04 Apr 2012) Log Message: ----------- Enhancements to the Writer: No column mapping required on delimiter writer. Ability to write different record types. Modified Paths: -------------- trunk/src/site/changes.xml Modified: trunk/src/site/changes.xml =================================================================== --- trunk/src/site/changes.xml 2012-03-09 20:56:26 UTC (rev 434) +++ trunk/src/site/changes.xml 2012-04-04 14:51:39 UTC (rev 435) @@ -19,6 +19,10 @@ qualifier. It was previously only checking to see if the data contained a delmiter.</action> <action dev="zepernick" type="add">Added a setNumericColumns(String[]) to the ExcelTransformer. Any columns contained in the array will be written to Excel as a Numeric instead of a Text field.</action> + <action dev="zepernick" type="add">Added the ability to use the DelimiterWriter with no column + mappings. Added new class DelimiterWriterOptions to achieve this.</action> + <action dev="zepernick" type="add">Fixed and Delimiter writers now support multiple record + types in the same file.</action> </release> <release version="3.2.0" date="2010-03-03" description="New parse options"> <action dev="benoitx" type="add">Added a getBigDecimal method on DataSet.</action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2012-03-09 20:56:32
|
Revision: 434 http://flatpack.svn.sourceforge.net/flatpack/?rev=434&view=rev Author: zepernick Date: 2012-03-09 20:56:26 +0000 (Fri, 09 Mar 2012) Log Message: ----------- Modified Paths: -------------- trunk/flatpack/src/main/java/net/sf/flatpack/util/ExcelTransformer.java Modified: trunk/flatpack/src/main/java/net/sf/flatpack/util/ExcelTransformer.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/util/ExcelTransformer.java 2012-03-09 20:56:11 UTC (rev 433) +++ trunk/flatpack/src/main/java/net/sf/flatpack/util/ExcelTransformer.java 2012-03-09 20:56:26 UTC (rev 434) @@ -16,11 +16,14 @@ import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import jxl.Workbook; import jxl.write.Label; +import jxl.write.Number; +import jxl.write.WritableCell; import jxl.write.WritableCellFormat; import jxl.write.WritableFont; import jxl.write.WritableSheet; @@ -39,9 +42,14 @@ */ public class ExcelTransformer { private final DataSet ds; + private final File xlsFile; + private String[] exportOnlyColumns; + private String[] excludeFromExportColumns; + + private String[] numericColumns; /** * Constructs a new Excel transformer @@ -68,9 +76,9 @@ try { final String[] columnNames = ds.getColumns(); - final List exportOnlyColumnsList = exportOnlyColumns != null ? Arrays.asList(exportOnlyColumns) : null; - - final List excludeFromExportColumnsList = excludeFromExportColumns != null ? Arrays.asList(excludeFromExportColumns) : null; + final List exportOnlyColumnsList = getExportOnlyColumns() != null ? Arrays.asList(exportOnlyColumns) : null; + final List excludeFromExportColumnsList = getExcludeFromExportColumns() != null ? Arrays.asList(excludeFromExportColumns) : null; + final List numericColumnList = getNumericColumns() != null ? Arrays.asList(getNumericColumns()) : new ArrayList(); // get the current position of the DataSet. We have to go to the top // to do this write, // and we will put the pionter back where it was after we are done @@ -93,6 +101,8 @@ colOffset++; continue; } + + final Label xlsTextLbl = new Label(i - colOffset, 0, columnNames[i], cellFormat); wrkSheet.addCell(xlsTextLbl); } @@ -114,8 +124,14 @@ continue; } - final Label xlsTextLbl = new Label(i - colOffset, row, ds.getString(columnNames[i]), cellFormat); - wrkSheet.addCell(xlsTextLbl); + WritableCell wc = null; + if (numericColumnList.contains(columnNames[i])) { + wc = new Number(i - colOffset, row, ds.getDouble(columnNames[i]), cellFormat); + } else { + wc = new Label(i - colOffset, row, ds.getString(columnNames[i]), cellFormat); + } + + wrkSheet.addCell(wc); } row++; @@ -164,4 +180,34 @@ this.exportOnlyColumns = null; } } + + /** + * @return the numericColumns + */ + public String[] getNumericColumns() { + return numericColumns; + } + + /** + * Columns contained in this array will be writen as numerics to Excel instead of Text + * + * @param numericColumns the numericColumns to set + */ + public void setNumericColumns(String[] numericColumns) { + this.numericColumns = numericColumns; + } + + /** + * @return the exportOnlyColumns + */ + public String[] getExportOnlyColumns() { + return exportOnlyColumns; + } + + /** + * @return the excludeFromExportColumns + */ + public String[] getExcludeFromExportColumns() { + return excludeFromExportColumns; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2012-03-09 20:56:17
|
Revision: 433 http://flatpack.svn.sourceforge.net/flatpack/?rev=433&view=rev Author: zepernick Date: 2012-03-09 20:56:11 +0000 (Fri, 09 Mar 2012) Log Message: ----------- Modified Paths: -------------- trunk/src/site/changes.xml Modified: trunk/src/site/changes.xml =================================================================== --- trunk/src/site/changes.xml 2012-01-10 15:56:36 UTC (rev 432) +++ trunk/src/site/changes.xml 2012-03-09 20:56:11 UTC (rev 433) @@ -17,6 +17,8 @@ <action dev="zepernick" type="add">BuffReader Parser now support Database Column Mappings</action> <action dev="zepernick" type="fix">DelimiterWriter now also quotes elements that contain a qualifier. It was previously only checking to see if the data contained a delmiter.</action> + <action dev="zepernick" type="add">Added a setNumericColumns(String[]) to the ExcelTransformer. + Any columns contained in the array will be written to Excel as a Numeric instead of a Text field.</action> </release> <release version="3.2.0" date="2010-03-03" description="New parse options"> <action dev="benoitx" type="add">Added a getBigDecimal method on DataSet.</action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2012-01-10 15:56:47
|
Revision: 432 http://flatpack.svn.sourceforge.net/flatpack/?rev=432&view=rev Author: zepernick Date: 2012-01-10 15:56:36 +0000 (Tue, 10 Jan 2012) Log Message: ----------- Modified Paths: -------------- trunk/flatpack/src/test/java/net/sf/flatpack/parserutils/ParserUtilsSplitLineTest.java Modified: trunk/flatpack/src/test/java/net/sf/flatpack/parserutils/ParserUtilsSplitLineTest.java =================================================================== --- trunk/flatpack/src/test/java/net/sf/flatpack/parserutils/ParserUtilsSplitLineTest.java 2012-01-10 15:54:32 UTC (rev 431) +++ trunk/flatpack/src/test/java/net/sf/flatpack/parserutils/ParserUtilsSplitLineTest.java 2012-01-10 15:56:36 UTC (rev 432) @@ -153,6 +153,16 @@ check(" \t \t ", '\t', FPConstants.NO_QUALIFIER, new String[] { "", "", "" }); check(" ", ' ', '"', new String[] { "", "", "" }); check(" ", ' ', FPConstants.NO_QUALIFIER, new String[] { "", "", "" }); + + check("\"3881\",\"2272\",\"\",\"\"We don't have any medical records on file, but claim was precerted under PME 5490-6125-0000. I'm following up with Jeri and Megan regarding the Never Event question. based upon the ICD 9 procedure codes on the sample claim & the diagnosis codes and claim history, appears patient had a laminotomy on 6/4/2010. Based upon the sample claim, appears that there was post-op infection + a laceration of the dura. Based on the EWM screen information from INQ62, the post-op infection diagnosis and staph infection diagnosis were indicated as yes, these conditions were present on admission. This doesn't mean that the patient got the infection during the outpatient surgery on 6/4/2010--it doesn't mean he didn't either.\r\n" + + "Based upon the Never event wording in e.Policies, we do not consider a diagnosis of post-op infection or laceration during a procedure a Never event. Therefore, we would not deny charges. For purposes of this policy, Aetna has determined the following events to be \x93Never Events:\x94\r\n" + + "*\",\"1\",\"2011-06-17\",\"1\"", ',', '"', + + new String[]{"3881", "2272", "", + "\"We don't have any medical records on file, but claim was precerted under PME 5490-6125-0000. I'm following up with Jeri and Megan regarding the Never Event question. based upon the ICD 9 procedure codes on the sample claim & the diagnosis codes and claim history, appears patient had a laminotomy on 6/4/2010. Based upon the sample claim, appears that there was post-op infection + a laceration of the dura. Based on the EWM screen information from INQ62, the post-op infection diagnosis and staph infection diagnosis were indicated as yes, these conditions were present on admission. This doesn't mean that the patient got the infection during the outpatient surgery on 6/4/2010--it doesn't mean he didn't either.\r\n" + + "Based upon the Never event wording in e.Policies, we do not consider a diagnosis of post-op infection or laceration during a procedure a Never event. Therefore, we would not deny charges. For purposes of this policy, Aetna has determined the following events to be \x93Never Events:\x94\r\n" + + "*", + "1", "2011-06-17", "1"}); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2012-01-10 15:54:42
|
Revision: 431 http://flatpack.svn.sourceforge.net/flatpack/?rev=431&view=rev Author: zepernick Date: 2012-01-10 15:54:32 +0000 (Tue, 10 Jan 2012) Log Message: ----------- Fixed a bug where the writer was not qualifying elements that contained a qualifier Modified Paths: -------------- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java 2012-01-10 15:43:41 UTC (rev 430) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java 2012-01-10 15:54:32 UTC (rev 431) @@ -56,7 +56,7 @@ } } - final boolean needsQuoting = (stringValue.indexOf(delimiter) != -1); + final boolean needsQuoting = stringValue.indexOf(delimiter) != -1 || (qualifier != FPConstants.NO_QUALIFIER && stringValue.indexOf(qualifier) != -1); if (needsQuoting) { super.write(qualifier); Modified: trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java =================================================================== --- trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java 2012-01-10 15:43:41 UTC (rev 430) +++ trunk/flatpack/src/test/java/net/sf/flatpack/writer/DelimiterWriterTestCase.java 2012-01-10 15:54:32 UTC (rev 431) @@ -106,15 +106,19 @@ final DelimiterWriterFactory factory = new DelimiterWriterFactory(';', '"'); factory.addColumnTitle("col1"); factory.addColumnTitle("col2"); + factory.addColumnTitle("col3"); + factory.addColumnTitle("col4"); final StringWriter out = new StringWriter(); final Writer writer = factory.createWriter(out); writer.addRecordEntry("col1", "value;with;delimiter"); writer.addRecordEntry("col2", "normal value"); + writer.addRecordEntry("col3", "value \"with qualifier\""); + writer.addRecordEntry("col4", "value \"with qualifier\" and ;delimiter;"); writer.nextRecord(); writer.flush(); - final String expected = this.joinLines("col1;col2", "\"value;with;delimiter\";normal value"); + final String expected = this.joinLines("col1;col2;col3;col4", "\"value;with;delimiter\";normal value;\"value \"with qualifier\"\";\"value \"with qualifier\" and ;delimiter;\""); Assert.assertEquals(expected, out.toString()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2012-01-10 15:43:52
|
Revision: 430 http://flatpack.svn.sourceforge.net/flatpack/?rev=430&view=rev Author: zepernick Date: 2012-01-10 15:43:41 +0000 (Tue, 10 Jan 2012) Log Message: ----------- Modified Paths: -------------- trunk/src/site/changes.xml Modified: trunk/src/site/changes.xml =================================================================== --- trunk/src/site/changes.xml 2011-12-12 23:31:41 UTC (rev 429) +++ trunk/src/site/changes.xml 2012-01-10 15:43:41 UTC (rev 430) @@ -15,6 +15,8 @@ the first record when ignore first was set to false. Column mappings should always come from the DB for this class.</action> <action dev="zepernick" type="add">BuffReader Parser now support Database Column Mappings</action> + <action dev="zepernick" type="fix">DelimiterWriter now also quotes elements that contain a + qualifier. It was previously only checking to see if the data contained a delmiter.</action> </release> <release version="3.2.0" date="2010-03-03" description="New parse options"> <action dev="benoitx" type="add">Added a getBigDecimal method on DataSet.</action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2011-12-12 23:31:48
|
Revision: 429 http://flatpack.svn.sourceforge.net/flatpack/?rev=429&view=rev Author: benoitx Date: 2011-12-12 23:31:41 +0000 (Mon, 12 Dec 2011) Log Message: ----------- BigDecimal should not use the engineering/E-08 formats but simple plain strings. Modified Paths: -------------- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java trunk/flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java 2011-06-23 20:39:18 UTC (rev 428) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java 2011-12-12 23:31:41 UTC (rev 429) @@ -5,6 +5,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.math.BigDecimal; import net.sf.flatpack.structure.ColumnMetaData; import net.sf.flatpack.util.FPConstants; @@ -14,107 +15,114 @@ * @author Dirk Holmes and Holger Holger Hoffstatte */ public class DelimiterWriter extends AbstractWriter { - private char delimiter; - private char qualifier; - private List columnTitles = null; - private boolean columnTitlesWritten = false; + private char delimiter; + private char qualifier; + private List columnTitles = null; + private boolean columnTitlesWritten = false; - protected DelimiterWriter(final Map columnMapping, final java.io.Writer output, final char delimiter, final char qualifier) throws IOException { - super(output); - this.delimiter = delimiter; - this.qualifier = qualifier; + protected DelimiterWriter(final Map columnMapping, + final java.io.Writer output, final char delimiter, + final char qualifier) throws IOException { + super(output); + this.delimiter = delimiter; + this.qualifier = qualifier; - columnTitles = new ArrayList(); - final List columns = (List) columnMapping.get(FPConstants.DETAIL_ID); - final Iterator columnIter = columns.iterator(); - while (columnIter.hasNext()) { - final ColumnMetaData element = (ColumnMetaData) columnIter.next(); - columnTitles.add(element.getColName()); - } - // write the column headers - this.nextRecord(); - } + columnTitles = new ArrayList(); + final List columns = (List) columnMapping.get(FPConstants.DETAIL_ID); + final Iterator columnIter = columns.iterator(); + while (columnIter.hasNext()) { + final ColumnMetaData element = (ColumnMetaData) columnIter.next(); + columnTitles.add(element.getColName()); + } + // write the column headers + this.nextRecord(); + } - protected void writeWithDelimiter(final Object value) throws IOException { - this.write(value); - this.write(delimiter); - } + protected void writeWithDelimiter(final Object value) throws IOException { + this.write(value); + this.write(delimiter); + } - protected void write(final Object value) throws IOException { - String stringValue = ""; + protected void write(final Object value) throws IOException { + String stringValue = ""; - if (value != null) { - // TODO DO: format the value - stringValue = value.toString(); - } + if (value != null) { + // TODO DO: format the value + if (value instanceof BigDecimal) { + final BigDecimal bd = (BigDecimal) value; + stringValue = bd.signum() == 0 ? "0" : bd.toPlainString(); + } else { + stringValue = value.toString(); + } + } - final boolean needsQuoting = (stringValue.indexOf(delimiter) != -1); + final boolean needsQuoting = (stringValue.indexOf(delimiter) != -1); - if (needsQuoting) { - super.write(qualifier); - } + if (needsQuoting) { + super.write(qualifier); + } - super.write(stringValue); + super.write(stringValue); - if (needsQuoting) { - super.write(qualifier); - } - } + if (needsQuoting) { + super.write(qualifier); + } + } - protected void addColumnTitle(final String string) { - if (string == null) { - throw new IllegalArgumentException("column title may not be null"); - } - columnTitles.add(string); - } + protected void addColumnTitle(final String string) { + if (string == null) { + throw new IllegalArgumentException("column title may not be null"); + } + columnTitles.add(string); + } - protected void writeColumnTitles() throws IOException { - final Iterator titleIter = columnTitles.iterator(); - while (titleIter.hasNext()) { - final String title = (String) titleIter.next(); + protected void writeColumnTitles() throws IOException { + final Iterator titleIter = columnTitles.iterator(); + while (titleIter.hasNext()) { + final String title = (String) titleIter.next(); - if (titleIter.hasNext()) { - this.writeWithDelimiter(title); - } else { - this.write(title); - } - } - } + if (titleIter.hasNext()) { + this.writeWithDelimiter(title); + } else { + this.write(title); + } + } + } - protected void writeRow() throws IOException { - final Iterator titlesIter = columnTitles.iterator(); - while (titlesIter.hasNext()) { - final String columnTitle = (String) titlesIter.next(); - if (getRowMap() != null) { - if (titlesIter.hasNext()) { - writeWithDelimiter(getRowMap().get(columnTitle)); - } else { - write(getRowMap().get(columnTitle)); - } - } - } - } + protected void writeRow() throws IOException { + final Iterator titlesIter = columnTitles.iterator(); + while (titlesIter.hasNext()) { + final String columnTitle = (String) titlesIter.next(); + if (getRowMap() != null) { + if (titlesIter.hasNext()) { + writeWithDelimiter(getRowMap().get(columnTitle)); + } else { + write(getRowMap().get(columnTitle)); + } + } + } + } - public final void nextRecord() throws IOException { - if (!columnTitlesWritten) { - this.writeColumnTitles(); - columnTitlesWritten = true; - } else { - this.writeRow(); - } + public final void nextRecord() throws IOException { + if (!columnTitlesWritten) { + this.writeColumnTitles(); + columnTitlesWritten = true; + } else { + this.writeRow(); + } - super.nextRecord(); - } + super.nextRecord(); + } - public void printFooter() { - // TODO DO: implement footer handling - } + public void printFooter() { + // TODO DO: implement footer handling + } - public void printHeader() { - // TODO DO: implement header handling - } + public void printHeader() { + // TODO DO: implement header handling + } - protected boolean validateColumnTitle(final String columnTitle) { - return columnTitles.contains(columnTitle); - } + protected boolean validateColumnTitle(final String columnTitle) { + return columnTitles.contains(columnTitle); + } } Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java 2011-06-23 20:39:18 UTC (rev 428) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/FixedLengthWriter.java 2011-12-12 23:31:41 UTC (rev 429) @@ -5,6 +5,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.math.BigDecimal; import net.sf.flatpack.structure.ColumnMetaData; import net.sf.flatpack.util.FPConstants; @@ -14,108 +15,120 @@ * @author Dirk Holmes and Holger Holger Hoffstatte */ public class FixedLengthWriter extends AbstractWriter { - private static final int MAX_CHAR_TO_USE_LOOP = 8; - private final Map columnMapping; - private final char padChar; + private static final int MAX_CHAR_TO_USE_LOOP = 8; + private final Map columnMapping; + private final char padChar; - protected FixedLengthWriter(final Map parsedMapping, final java.io.Writer output, final char padChar) throws IOException { - super(output); - this.columnMapping = parsedMapping; - this.padChar = padChar; - } + protected FixedLengthWriter(final Map parsedMapping, + final java.io.Writer output, final char padChar) throws IOException { + super(output); + this.columnMapping = parsedMapping; + this.padChar = padChar; + } - public void addRecordEntry(final String columnName, final Object value) { - if (value != null) { - final ColumnMetaData metaData = this.getColumnMetaData(columnName); + public void addRecordEntry(final String columnName, final Object value) { + if (value != null) { + final ColumnMetaData metaData = this.getColumnMetaData(columnName); - final String valueString = value.toString(); - if (valueString.length() > metaData.getColLength()) { - throw new IllegalArgumentException(valueString + " exceeds the maximum length for column " + columnName + "(" - + metaData.getColLength() + ")"); - } - } - super.addRecordEntry(columnName, value); - } + final String valueString = value.toString(); + if (valueString.length() > metaData.getColLength()) { + throw new IllegalArgumentException(valueString + + " exceeds the maximum length for column " + + columnName + "(" + metaData.getColLength() + ")"); + } + } + super.addRecordEntry(columnName, value); + } - public void nextRecord() throws IOException { - final Iterator columnIter = this.getColumnMetaData().iterator(); - while (columnIter.hasNext()) { - final ColumnMetaData element = (ColumnMetaData) columnIter.next(); - final Object value = this.getRowMap().get(element.getColName()); - this.write(this.formattedValue(value, element)); - } + public void nextRecord() throws IOException { + final Iterator columnIter = this.getColumnMetaData().iterator(); + while (columnIter.hasNext()) { + final ColumnMetaData element = (ColumnMetaData) columnIter.next(); + final Object value = this.getRowMap().get(element.getColName()); + this.write(this.formattedValue(value, element)); + } - super.nextRecord(); - } + super.nextRecord(); + } - protected char[] formattedValue(final Object val, final ColumnMetaData element) { - Object value = val; - if (value == null) { - // TODO DO: maybe have a way to substitute default values here? - value = ""; - } + protected char[] formattedValue(final Object val, + final ColumnMetaData element) { + Object value = val; + if (value == null) { + // TODO DO: maybe have a way to substitute default values here? + value = ""; + } - // TODO DO: add formatting of values - final String stringValue = value.toString(); - final int stringLength = stringValue.length(); + String stringValue; + if (value instanceof BigDecimal) { + final BigDecimal bd = (BigDecimal) value; + stringValue = bd.signum() == 0 ? "0" : bd.toPlainString(); + } else { + stringValue = value.toString(); + } - final int columnLength = element.getColLength(); - final char[] formattedValue = new char[columnLength]; + final int stringLength = stringValue.length(); - /* - * Copy the contents of the original string; for Strings up to ~8-10 - * characters this loop is consistently faster than String.getChars(). Short - * Strings are usually the majority of values in fixed-width data columns. - */ - final int numCharacters = Math.min(stringLength, columnLength); - if (numCharacters < MAX_CHAR_TO_USE_LOOP) { - for (int i = 0; i < numCharacters; i++) { - formattedValue[i] = stringValue.charAt(i); - } - } else { - stringValue.getChars(0, numCharacters, formattedValue, 0); - } + final int columnLength = element.getColLength(); + final char[] formattedValue = new char[columnLength]; - if (stringLength < columnLength) { - // pad if necessary - Arrays.fill(formattedValue, stringLength, columnLength, padChar); - } + /* + * Copy the contents of the original string; for Strings up to ~8-10 + * characters this loop is consistently faster than String.getChars(). + * Short Strings are usually the majority of values in fixed-width data + * columns. + */ + final int numCharacters = Math.min(stringLength, columnLength); + if (numCharacters < MAX_CHAR_TO_USE_LOOP) { + for (int i = 0; i < numCharacters; i++) { + formattedValue[i] = stringValue.charAt(i); + } + } else { + stringValue.getChars(0, numCharacters, formattedValue, 0); + } - return formattedValue; - } + if (stringLength < columnLength) { + // pad if necessary + Arrays.fill(formattedValue, stringLength, columnLength, padChar); + } - protected boolean validateColumnTitle(final String columnTitle) { - final Map columnNameToIndex = (Map) columnMapping.get(FPConstants.COL_IDX); - return columnNameToIndex.keySet().contains(columnTitle); - } + return formattedValue; + } - public void printFooter() { - // TODO DO: implement footer handling + protected boolean validateColumnTitle(final String columnTitle) { + final Map columnNameToIndex = (Map) columnMapping + .get(FPConstants.COL_IDX); + return columnNameToIndex.keySet().contains(columnTitle); + } - } + public void printFooter() { + // TODO DO: implement footer handling - public void printHeader() { - // TODO DO: implement header handling + } - } + public void printHeader() { + // TODO DO: implement header handling - /** - * @return List of ColumnMetaData objects describing the mapping defined in the - * XML file. - */ - private List getColumnMetaData() { - return (List) columnMapping.get(FPConstants.DETAIL_ID); - } + } - private ColumnMetaData getColumnMetaData(final String columnName) { - final Iterator metaDataIter = this.getColumnMetaData().iterator(); - while (metaDataIter.hasNext()) { - final ColumnMetaData element = (ColumnMetaData) metaDataIter.next(); - if (element.getColName().equals(columnName)) { - return element; - } - } + /** + * @return List of ColumnMetaData objects describing the mapping defined in + * the XML file. + */ + private List getColumnMetaData() { + return (List) columnMapping.get(FPConstants.DETAIL_ID); + } - throw new IllegalArgumentException("Column \"" + columnName + "\" unknown"); - } + private ColumnMetaData getColumnMetaData(final String columnName) { + final Iterator metaDataIter = this.getColumnMetaData().iterator(); + while (metaDataIter.hasNext()) { + final ColumnMetaData element = (ColumnMetaData) metaDataIter.next(); + if (element.getColName().equals(columnName)) { + return element; + } + } + + throw new IllegalArgumentException("Column \"" + columnName + + "\" unknown"); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nou...@go...> - 2011-08-21 23:50:49
|
If you have trouble viewing or submitting this form, you can fill it out online: https://docs.google.com/spreadsheet/viewform?formkey=dFo5V2JpdzZYZ3M5N2tweUNYcmxHR3c6MQ Effectiveness of Test Driven Development in Open Source Projects Hello there, My name is Noumi Nooruddeen, currently pursing MSc. Software Engineering in University of Hertfordshire. At present I am on my thesis which is ' The effectiveness of Test Driven Development on code quality'. For this purpose I am observing the open source projects developed on both test driven development and traditional manner. Please take few seconds to fill out this survey, which can eventually help my thesis. Your response will be highly beneficial for me. Thankyou for your time, I really appreciate this. Noumi What is the name of the project that you are working on? * If you are working on more than one OSS project, please fill one survey for each of them Is the project developed using Test Driven Development? * Yes No Powered by Google Docs Report Abuse - Terms of Service - Additional Terms |
From: <zep...@us...> - 2011-06-23 20:39:24
|
Revision: 428 http://flatpack.svn.sourceforge.net/flatpack/?rev=428&view=rev Author: zepernick Date: 2011-06-23 20:39:18 +0000 (Thu, 23 Jun 2011) Log Message: ----------- Fixed bug in determining when a line is part of a multiline record Modified Paths: -------------- trunk/flatpack/src/main/java/net/sf/flatpack/AbstractDelimiterParser.java trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java Modified: trunk/flatpack/src/main/java/net/sf/flatpack/AbstractDelimiterParser.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/AbstractDelimiterParser.java 2011-06-08 20:13:00 UTC (rev 427) +++ trunk/flatpack/src/main/java/net/sf/flatpack/AbstractDelimiterParser.java 2011-06-23 20:39:18 UTC (rev 428) @@ -145,7 +145,6 @@ ds.setMetaData(getPzMetaData()); continue; } - // column values List columns = ParserUtils.splitLine(line, getDelimiter(), getQualifier(), FPConstants.SPLITLINE_SIZE_INIT); final String mdkey = ParserUtils.getCMDKeyForDelimitedFile(getPzMetaData(), columns); @@ -248,7 +247,7 @@ // be checked if we have specified a delimiter // ******************************************************** final char[] chrArry = trimmed.toCharArray(); - if (!processingMultiLine && delim > 0) { + if (!processingMultiLine && delim > 0 && qual != FPConstants.NO_QUALIFIER) { processingMultiLine = ParserUtils.isMultiLine(chrArry, delim, qual); } Modified: trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java 2011-06-08 20:13:00 UTC (rev 427) +++ trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java 2011-06-23 20:39:18 UTC (rev 428) @@ -506,7 +506,8 @@ // } /** - * Determines if the given line is the first part of a multiline record + * Determines if the given line is the first part of a multiline record. It does this by verifying that the + * qualifer on the last element is not closed * * @param chrArry - * char data of the line @@ -524,21 +525,20 @@ // could be a potential line break boolean qualiFound = false; for (int i = chrArry.length - 1; i >= 0; i--) { + //System.out.println(chrArry[i]); + if (chrArry[i] == ' ') { + continue; + } + // check to see if we can find a qualifier followed by a // delimiter // remember we are working are way backwards on the line if (qualiFound) { - if (chrArry[i] == ' ') { - continue; - } else { - // not a space, if this char is the delimiter, then we - // have a line break in the record - if (chrArry[i] == delimiter) { - return true; - } - qualiFound = false; - continue; + if (chrArry[i] == delimiter) { + return true; } + //guard against multiple qualifiers in the sequence [ ,""We ] + qualiFound = chrArry[i] == qualifier; } else if (chrArry[i] == delimiter) { // if we have a delimiter followed by a qualifier, then we // have moved on to a new element and this could not be multiline. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2011-06-08 20:13:06
|
Revision: 427 http://flatpack.svn.sourceforge.net/flatpack/?rev=427&view=rev Author: zepernick Date: 2011-06-08 20:13:00 +0000 (Wed, 08 Jun 2011) Log Message: ----------- Modified Paths: -------------- trunk/src/site/changes.xml Modified: trunk/src/site/changes.xml =================================================================== --- trunk/src/site/changes.xml 2011-06-08 20:06:57 UTC (rev 426) +++ trunk/src/site/changes.xml 2011-06-08 20:13:00 UTC (rev 427) @@ -14,6 +14,7 @@ <action dev="zepernick" type="fix">DBDelimitedParser was trying to build column names from the first record when ignore first was set to false. Column mappings should always come from the DB for this class.</action> + <action dev="zepernick" type="add">BuffReader Parser now support Database Column Mappings</action> </release> <release version="3.2.0" date="2010-03-03" description="New parse options"> <action dev="benoitx" type="add">Added a getBigDecimal method on DataSet.</action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2011-06-08 20:07:04
|
Revision: 426 http://flatpack.svn.sourceforge.net/flatpack/?rev=426&view=rev Author: zepernick Date: 2011-06-08 20:06:57 +0000 (Wed, 08 Jun 2011) Log Message: ----------- Added mappings from DB using the BufferedReader classes Modified Paths: -------------- trunk/flatpack/src/main/java/net/sf/flatpack/FixedLengthParser.java trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderDataSet.java trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderDelimParser.java trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderFixedParser.java trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderParseFactory.java Added Paths: ----------- trunk/flatpack/src/main/java/net/sf/flatpack/brparse/DBBuffReaderDelimParser.java trunk/flatpack/src/main/java/net/sf/flatpack/brparse/DBBuffReaderFixedParser.java trunk/flatpack/src/main/java/net/sf/flatpack/brparse/InterfaceBuffReaderParse.java Modified: trunk/flatpack/src/main/java/net/sf/flatpack/FixedLengthParser.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/FixedLengthParser.java 2011-03-05 11:46:45 UTC (rev 425) +++ trunk/flatpack/src/main/java/net/sf/flatpack/FixedLengthParser.java 2011-06-08 20:06:57 UTC (rev 426) @@ -78,6 +78,10 @@ super(dataSourceReader); this.pzmapReader = pzmapReader; } + + protected FixedLengthParser(final Reader dataSourceReader, final String dataDefinition) { + super(dataSourceReader, dataDefinition); + } protected void init() { try { Modified: trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderDataSet.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderDataSet.java 2011-03-05 11:46:45 UTC (rev 425) +++ trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderDataSet.java 2011-06-08 20:06:57 UTC (rev 426) @@ -32,9 +32,9 @@ */ package net.sf.flatpack.brparse; -import java.io.IOException; - +import net.sf.flatpack.AbstractParser; import net.sf.flatpack.DefaultDataSet; +import net.sf.flatpack.Parser; import net.sf.flatpack.ordering.OrderBy; import net.sf.flatpack.structure.Row; import net.sf.flatpack.xml.MetaData; @@ -42,56 +42,48 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * + * + * @author Paul Zepernick + */ public class BuffReaderDataSet extends DefaultDataSet { private static final Logger LOGGER = LoggerFactory.getLogger(BuffReaderDataSet.class); - private final BuffReaderDelimParser brDelimPzParser; - private final BuffReaderFixedParser brFixedPzParser; + + private final InterfaceBuffReaderParse brParser; - public BuffReaderDataSet(final MetaData columnMD2, final BuffReaderDelimParser brDelimPzParser) { - super(columnMD2, brDelimPzParser); + /** + * + * @param columnMD2 + * @param brParser + */ + public BuffReaderDataSet(final MetaData columnMD2, final InterfaceBuffReaderParse brParser) { + super(columnMD2, (Parser)brParser); //register the parser with the dataset so we can fetch rows from //the bufferedreader as needed - this.brDelimPzParser = brDelimPzParser; - this.brFixedPzParser = null; + this.brParser = brParser; } - public BuffReaderDataSet(final MetaData columnMD2, final BuffReaderFixedParser brFixedPzParser) { - super(columnMD2, brFixedPzParser); - //register the parser with the dataset so we can fetch rows from - //the bufferedreader as needed - this.brFixedPzParser = brFixedPzParser; - this.brDelimPzParser = null; - } - public boolean next() { - try { + Row r = null; - - if (brDelimPzParser != null) { - r = brDelimPzParser.buildRow(this); - } else if (brFixedPzParser != null) { - r = brFixedPzParser.buildRow(this); + + if (brParser != null) { + r = brParser.buildRow(this); } else { //this should not happen, throw exception throw new RuntimeException("No parser available to fetch row"); } + if (getMetaData() == null) { + setMetaData(((AbstractParser)brParser).getPzMetaData()); + } + if (r == null) { setPointer(-1); return false; } - - //make sure we have some MD - // if (getColumnMD() == null) { - // //create a new map so the user cannot change the internal - // //DataSet representation of the MD through the parser - // setColumnMD(new LinkedHashMap(brDelimPzParser.getColumnMD())); - // } - - if (getMetaData() == null) { - setMetaData(brDelimPzParser.getPzMetaData()); - } - + clearRows(); addRow(r); @@ -99,11 +91,6 @@ return true; - } catch (final IOException ex) { - LOGGER.error("error building Row on next()", ex); - } - - return false; } /** Modified: trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderDelimParser.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderDelimParser.java 2011-03-05 11:46:45 UTC (rev 425) +++ trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderDelimParser.java 2011-06-08 20:06:57 UTC (rev 426) @@ -49,7 +49,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class BuffReaderDelimParser extends DelimiterParser { +public class BuffReaderDelimParser extends DelimiterParser implements InterfaceBuffReaderParse{ private BufferedReader br; private boolean processedFirst = false; @@ -108,10 +108,15 @@ * @return Row * @throws IOException */ - public Row buildRow(final DefaultDataSet ds) throws IOException { + public Row buildRow(final DefaultDataSet ds) { /** loop through each line in the file */ while (true) { - final String line = fetchNextRecord(br, getQualifier(), getDelimiter()); + String line; + try { + line = fetchNextRecord(br, getQualifier(), getDelimiter()); + } catch (IOException e) { + throw new RuntimeException("Error Fetching Record From File...", e); + } if (line == null) { return null; Modified: trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderFixedParser.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderFixedParser.java 2011-03-05 11:46:45 UTC (rev 425) +++ trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderFixedParser.java 2011-06-08 20:06:57 UTC (rev 426) @@ -51,7 +51,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class BuffReaderFixedParser extends FixedLengthParser { + +/** + * + * + * @author Paul Zepernick + */ +public class BuffReaderFixedParser extends FixedLengthParser implements InterfaceBuffReaderParse{ private BufferedReader br = null; private int lineCount = 0; @@ -60,17 +66,39 @@ private static final Logger LOGGER = LoggerFactory.getLogger(BuffReaderFixedParser.class); + + /** + * + * @param pzmapXMLStream + * @param dataSourceStream + */ public BuffReaderFixedParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream) { super(pzmapXMLStream, dataSourceStream); } + + /** + * + * @param pzmapXML + * @param dataSource + */ public BuffReaderFixedParser(final File pzmapXML, final File dataSource) { super(pzmapXML, dataSource); } + /** + * + * + * @param pzmapXML + * @param dataSource + */ public BuffReaderFixedParser(final Reader pzmapXML, final Reader dataSource) { super(pzmapXML, dataSource); } + + protected BuffReaderFixedParser(final Reader dataSourceReader, final String dataDefinition) { + super(dataSourceReader, dataDefinition); + } protected DataSet doParse() { final DataSet ds = new BuffReaderDataSet(getPzMetaData(), this); @@ -98,67 +126,71 @@ * @return Row * @throws IOException */ - public Row buildRow(final DefaultDataSet ds) throws IOException { + public Row buildRow(final DefaultDataSet ds) { String line = null; - - while ((line = br.readLine()) != null) { - lineCount++; - // empty line skip past it - if (line.trim().length() == 0) { - continue; - } - - final String mdkey = FixedWidthParserUtils.getCMDKey(getPzMetaData(), line); - final int recordLength = ((Integer) recordLengths.get(mdkey)).intValue(); - - if (line.length() > recordLength) { - // Incorrect record length on line log the error. Line will not - // be included in the - // dataset - if (isIgnoreExtraColumns()) { - //user has chosen to ignore the fact that we have too many bytes in the fixed - //width file. Truncate the line to the correct length - line = line.substring(0, recordLength); - addError(ds, "TRUNCATED LINE TO CORRECT LENGTH", lineCount, 1); - } else { - addError(ds, "LINE TOO LONG. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2, - isStoreRawDataToDataError() ? line : null); - continue; - } - } else if (line.length() < recordLength) { - if (isHandlingShortLines()) { - // We can pad this line out - line += ParserUtils.padding(recordLength - line.length(), ' '); - - // log a warning - addError(ds, "PADDED LINE TO CORRECT RECORD LENGTH", lineCount, 1); - - } else { - addError(ds, "LINE TOO SHORT. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2, - isStoreRawDataToDataError() ? line : null); - continue; - } - } - - final Row row = new Row(); - row.setMdkey(mdkey.equals(FPConstants.DETAIL_ID) ? null : mdkey); - - final List cmds = ParserUtils.getColumnMetaData(mdkey, getPzMetaData()); - row.addColumn(FixedWidthParserUtils.splitFixedText(cmds, line)); - - row.setRowNumber(lineCount); - - if (isFlagEmptyRows()) { - //user has elected to have the parser flag rows that are empty - row.setEmpty(ParserUtils.isListElementsEmpty(row.getCols())); - } - if (isStoreRawDataToDataSet()) { - //user told the parser to keep a copy of the raw data in the row - //WARNING potential for high memory usage here - row.setRawData(line); - } - - return row; + try { + while ((line = br.readLine()) != null) { + lineCount++; + // empty line skip past it + if (line.trim().length() == 0) { + continue; + } + + final String mdkey = FixedWidthParserUtils.getCMDKey(getPzMetaData(), line); + final int recordLength = ((Integer) recordLengths.get(mdkey)).intValue(); + + if (line.length() > recordLength) { + // Incorrect record length on line log the error. Line will not + // be included in the + // dataset + if (isIgnoreExtraColumns()) { + //user has chosen to ignore the fact that we have too many bytes in the fixed + //width file. Truncate the line to the correct length + line = line.substring(0, recordLength); + addError(ds, "TRUNCATED LINE TO CORRECT LENGTH", lineCount, 1); + } else { + addError(ds, "LINE TOO LONG. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2, + isStoreRawDataToDataError() ? line : null); + continue; + } + } else if (line.length() < recordLength) { + if (isHandlingShortLines()) { + // We can pad this line out + line += ParserUtils.padding(recordLength - line.length(), ' '); + + // log a warning + addError(ds, "PADDED LINE TO CORRECT RECORD LENGTH", lineCount, 1); + + } else { + addError(ds, "LINE TOO SHORT. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2, + isStoreRawDataToDataError() ? line : null); + continue; + } + } + + final Row row = new Row(); + row.setMdkey(mdkey.equals(FPConstants.DETAIL_ID) ? null : mdkey); + + final List cmds = ParserUtils.getColumnMetaData(mdkey, getPzMetaData()); + row.addColumn(FixedWidthParserUtils.splitFixedText(cmds, line)); + + row.setRowNumber(lineCount); + + if (isFlagEmptyRows()) { + //user has elected to have the parser flag rows that are empty + row.setEmpty(ParserUtils.isListElementsEmpty(row.getCols())); + } + if (isStoreRawDataToDataSet()) { + //user told the parser to keep a copy of the raw data in the row + //WARNING potential for high memory usage here + row.setRawData(line); + } + + return row; + } + + } catch(IOException e) { + throw new RuntimeException("Error Fetching Record From File...", e); } return null; Modified: trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderParseFactory.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderParseFactory.java 2011-03-05 11:46:45 UTC (rev 425) +++ trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderParseFactory.java 2011-06-08 20:06:57 UTC (rev 426) @@ -84,11 +84,9 @@ return new BuffReaderFixedParser(pzmapXML, dataSource); } - /** - * Not supported at this time. - */ + public Parser newFixedLengthParser(final Connection con, final Reader dataSource, final String dataDefinition) { - throw new UnsupportedOperationException("Not supported..."); + return new DBBuffReaderFixedParser(con, dataSource, dataDefinition); } public Parser newFixedLengthParser(final Reader pzmapXMLStream, final Reader dataSource) { @@ -105,12 +103,10 @@ return new BuffReaderFixedParser(pzmapXMLStream, dataSourceStream); } - /** - * Not supported at this time. - */ + public Parser newDelimitedParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition, final char delimiter, final char qualifier, final boolean ignoreFirstRecord) { - throw new UnsupportedOperationException("Not supported..."); + throw new UnsupportedOperationException("Not supported. Use 'Reader' Constructor Instead Of InputStream."); } /* @@ -160,7 +156,8 @@ */ public Parser newDelimitedParser(final Connection con, final Reader dataSource, final String dataDefinition, final char delimiter, final char qualifier, final boolean ignoreFirstRecord) { - throw new UnsupportedOperationException("Not supported..."); + //throw new UnsupportedOperationException("Not supported..."); + return new DBBuffReaderDelimParser(con, dataSource, dataDefinition, delimiter, qualifier, ignoreFirstRecord); } public Parser newDelimitedParser(final Reader dataSource, final char delimiter, final char qualifier) { Added: trunk/flatpack/src/main/java/net/sf/flatpack/brparse/DBBuffReaderDelimParser.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/brparse/DBBuffReaderDelimParser.java (rev 0) +++ trunk/flatpack/src/main/java/net/sf/flatpack/brparse/DBBuffReaderDelimParser.java 2011-06-08 20:06:57 UTC (rev 426) @@ -0,0 +1,64 @@ +package net.sf.flatpack.brparse; + +import java.io.FileNotFoundException; +import java.io.Reader; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.List; + +import net.sf.flatpack.InitialisationException; +import net.sf.flatpack.util.ParserUtils; + +/** + * + * + * @author Paul Zepernick + */ +public class DBBuffReaderDelimParser extends BuffReaderDelimParser implements InterfaceBuffReaderParse{ + + private Connection con; + + /** + * + * + * + * @param con + * @param dataSourceReader + * @param dataDefinition + * @param delimiter + * @param qualifier + * @param ignoreFirstRecord + */ + public DBBuffReaderDelimParser(Connection con, Reader dataSourceReader, String dataDefinition, char delimiter, char qualifier, + boolean ignoreFirstRecord) { + super(dataSourceReader, delimiter, qualifier, ignoreFirstRecord); + setDataDefinition(dataDefinition); + this.con = con; + } + + protected void init() { + try { + + final List cmds = ParserUtils.buildMDFromSQLTable(con, getDataDefinition(), this); + addToMetaData(cmds); + // addToColumnMD(PZConstants.DETAIL_ID, cmds); + // addToColumnMD(PZConstants.COL_IDX, ParserUtils.buidColumnIndexMap(cmds, this)); + + if (cmds.isEmpty()) { + throw new FileNotFoundException("DATA DEFINITION CAN NOT BE FOUND IN THE DATABASE " + getDataDefinition()); + } + setInitialised(true); + } catch (final SQLException e) { + throw new InitialisationException(e); + } catch (final FileNotFoundException e) { + throw new InitialisationException(e); + } + } + + protected boolean shouldCreateMDFromFile() { + //The MetaData should always be pulled from the DB for this implementation + return false; + } + + +} Added: trunk/flatpack/src/main/java/net/sf/flatpack/brparse/DBBuffReaderFixedParser.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/brparse/DBBuffReaderFixedParser.java (rev 0) +++ trunk/flatpack/src/main/java/net/sf/flatpack/brparse/DBBuffReaderFixedParser.java 2011-06-08 20:06:57 UTC (rev 426) @@ -0,0 +1,44 @@ +package net.sf.flatpack.brparse; + +import java.io.FileNotFoundException; +import java.io.Reader; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.List; + +import net.sf.flatpack.InitialisationException; +import net.sf.flatpack.util.ParserUtils; + +public class DBBuffReaderFixedParser extends BuffReaderFixedParser implements InterfaceBuffReaderParse { + private Connection con; + + + public DBBuffReaderFixedParser(final Connection con, final Reader dataSourceReader, final String dataDefinition) { + super(dataSourceReader, dataDefinition); + this.con = con; + } + + protected void init() { + try { + + final List cmds = ParserUtils.buildMDFromSQLTable(con, getDataDefinition(), this); + addToMetaData(cmds); + // addToColumnMD(PZConstants.DETAIL_ID, cmds); + // addToColumnMD(PZConstants.COL_IDX, ParserUtils.buidColumnIndexMap(cmds, this)); + + if (cmds.isEmpty()) { + throw new FileNotFoundException("DATA DEFINITION CAN NOT BE FOUND IN THE DATABASE " + getDataDefinition()); + } + setInitialised(true); + } catch (final SQLException e) { + throw new InitialisationException(e); + } catch (final FileNotFoundException e) { + throw new InitialisationException(e); + } + } + + protected boolean shouldCreateMDFromFile() { + //The MetaData should always be pulled from the DB for this implementation + return false; + } +} Added: trunk/flatpack/src/main/java/net/sf/flatpack/brparse/InterfaceBuffReaderParse.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/brparse/InterfaceBuffReaderParse.java (rev 0) +++ trunk/flatpack/src/main/java/net/sf/flatpack/brparse/InterfaceBuffReaderParse.java 2011-06-08 20:06:57 UTC (rev 426) @@ -0,0 +1,22 @@ +package net.sf.flatpack.brparse; + +import net.sf.flatpack.DefaultDataSet; +import net.sf.flatpack.structure.Row; + +/** + * All buffered reader parsers should implement this interface and provide + * an implementation for the buildRow + * + * @author Paul Zepernick + */ +public interface InterfaceBuffReaderParse { + + /** + * Builds a row into the DataSet using the current record from the File + * + * @param ds + * @return Row object + */ + public Row buildRow(final DefaultDataSet ds); + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2011-03-05 11:46:51
|
Revision: 425 http://flatpack.svn.sourceforge.net/flatpack/?rev=425&view=rev Author: benoitx Date: 2011-03-05 11:46:45 +0000 (Sat, 05 Mar 2011) Log Message: ----------- Fix an NPE Modified Paths: -------------- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java Modified: trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java 2010-11-03 19:09:51 UTC (rev 424) +++ trunk/flatpack/src/main/java/net/sf/flatpack/writer/DelimiterWriter.java 2011-03-05 11:46:45 UTC (rev 425) @@ -85,10 +85,12 @@ final Iterator titlesIter = columnTitles.iterator(); while (titlesIter.hasNext()) { final String columnTitle = (String) titlesIter.next(); - if (titlesIter.hasNext()) { - this.writeWithDelimiter(this.getRowMap().get(columnTitle)); - } else { - this.write(this.getRowMap().get(columnTitle)); + if (getRowMap() != null) { + if (titlesIter.hasNext()) { + writeWithDelimiter(getRowMap().get(columnTitle)); + } else { + write(getRowMap().get(columnTitle)); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2010-11-03 19:09:57
|
Revision: 424 http://flatpack.svn.sourceforge.net/flatpack/?rev=424&view=rev Author: zepernick Date: 2010-11-03 19:09:51 +0000 (Wed, 03 Nov 2010) Log Message: ----------- Fixed bug in DBDelimitedParser. Trying to use the column headers to build the meta data when ignore first was set to false. Modified Paths: -------------- trunk/flatpack/src/main/java/net/sf/flatpack/DBDelimiterParser.java Modified: trunk/flatpack/src/main/java/net/sf/flatpack/DBDelimiterParser.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/DBDelimiterParser.java 2010-11-03 19:09:40 UTC (rev 423) +++ trunk/flatpack/src/main/java/net/sf/flatpack/DBDelimiterParser.java 2010-11-03 19:09:51 UTC (rev 424) @@ -92,6 +92,7 @@ } protected boolean shouldCreateMDFromFile() { - return true; + //The MetaData should always be pulled from the DB for this implementation + return false; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2010-11-03 19:09:45
|
Revision: 423 http://flatpack.svn.sourceforge.net/flatpack/?rev=423&view=rev Author: zepernick Date: 2010-11-03 19:09:40 +0000 (Wed, 03 Nov 2010) Log Message: ----------- Fixed bug in DBDelimitedParser. Trying to use the column headers to build the meta data when ignore first was set to false. Modified Paths: -------------- trunk/src/site/changes.xml Modified: trunk/src/site/changes.xml =================================================================== --- trunk/src/site/changes.xml 2010-10-26 19:12:12 UTC (rev 422) +++ trunk/src/site/changes.xml 2010-11-03 19:09:40 UTC (rev 423) @@ -10,7 +10,10 @@ <release version="3.3.0" date="in svn" description="Maintenance"> <action dev="benoitx" type="fix">Use JDK 1.5.</action> <action dev="zepernick" type="add">Ability to over ride the table names for DATAFILE and - DATASTRUCTURE when using the DB for the MetaData.</action> + DATASTRUCTURE when using the DB for the MetaData.</action> + <action dev="zepernick" type="fix">DBDelimitedParser was trying to build column names from + the first record when ignore first was set to false. Column mappings should always come + from the DB for this class.</action> </release> <release version="3.2.0" date="2010-03-03" description="New parse options"> <action dev="benoitx" type="add">Added a getBigDecimal method on DataSet.</action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2010-10-26 20:04:51
|
Revision: 422 http://flatpack.svn.sourceforge.net/flatpack/?rev=422&view=rev Author: zepernick Date: 2010-10-26 19:12:12 +0000 (Tue, 26 Oct 2010) Log Message: ----------- Added a check for a bad DataFile key to produce a better exception than a NPE Modified Paths: -------------- trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java Modified: trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java 2010-10-26 18:47:23 UTC (rev 421) +++ trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java 2010-10-26 19:12:12 UTC (rev 422) @@ -1146,6 +1146,10 @@ cmds.add(column); } + + if (cmds.isEmpty()) { + throw new FPException("Data File Key [" + dataDefinition + "] Is Not In The database OR No Columns Specified In Table"); + } } finally { if (rs != null) { rs.close(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2010-10-26 18:47:29
|
Revision: 421 http://flatpack.svn.sourceforge.net/flatpack/?rev=421&view=rev Author: zepernick Date: 2010-10-26 18:47:23 +0000 (Tue, 26 Oct 2010) Log Message: ----------- Added an option to over ride the table names for DATASTRUCTURE and DATAFILE. The table names can now be changed all together, or be set to lower case if so desired. Modified Paths: -------------- trunk/src/site/changes.xml Modified: trunk/src/site/changes.xml =================================================================== --- trunk/src/site/changes.xml 2010-10-26 18:45:26 UTC (rev 420) +++ trunk/src/site/changes.xml 2010-10-26 18:47:23 UTC (rev 421) @@ -9,6 +9,8 @@ <body> <release version="3.3.0" date="in svn" description="Maintenance"> <action dev="benoitx" type="fix">Use JDK 1.5.</action> + <action dev="zepernick" type="add">Ability to over ride the table names for DATAFILE and + DATASTRUCTURE when using the DB for the MetaData.</action> </release> <release version="3.2.0" date="2010-03-03" description="New parse options"> <action dev="benoitx" type="add">Added a getBigDecimal method on DataSet.</action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2010-10-26 18:45:32
|
Revision: 420 http://flatpack.svn.sourceforge.net/flatpack/?rev=420&view=rev Author: zepernick Date: 2010-10-26 18:45:26 +0000 (Tue, 26 Oct 2010) Log Message: ----------- Added an option to over ride the table names for DATASTRUCTURE and DATAFILE. The table names can now be changed all together, or be set to lower case if so desired. Modified Paths: -------------- trunk/common-build/project.xml Modified: trunk/common-build/project.xml =================================================================== --- trunk/common-build/project.xml 2010-10-26 18:44:57 UTC (rev 419) +++ trunk/common-build/project.xml 2010-10-26 18:45:26 UTC (rev 420) @@ -27,7 +27,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/3.0.0 http://maven.apache.org/maven-v3_0_0.xsd"> <pomVersion>3</pomVersion> <groupId>net.sf.flatpack</groupId> - <currentVersion>3.2.0</currentVersion> + <currentVersion>3.3.0-SNAPSHOT</currentVersion> <organization> <name>ObjectLab Financial Ltd</name> <url>http://www.objectlab.co.uk</url> @@ -198,6 +198,11 @@ <versions> <version> + <id>3.3.0-SNAPSHOT</id> + <name>3.3.0-SNAPSHOT</name> + <tag>3.3.0-SNAPSHOT</tag> + </version> + <version> <id>3.2.0</id> <name>3.2.0</name> <tag>3.2.0</tag> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2010-10-26 18:45:03
|
Revision: 419 http://flatpack.svn.sourceforge.net/flatpack/?rev=419&view=rev Author: zepernick Date: 2010-10-26 18:44:57 +0000 (Tue, 26 Oct 2010) Log Message: ----------- Added an option to over ride the table names for DATASTRUCTURE and DATAFILE. The table names can now be changed all together, or be set to lower case if so desired. Modified Paths: -------------- trunk/flatpack/src/main/java/net/sf/flatpack/AbstractParser.java trunk/flatpack/src/main/java/net/sf/flatpack/DBDelimiterParser.java trunk/flatpack/src/main/java/net/sf/flatpack/DBFixedLengthParser.java trunk/flatpack/src/main/java/net/sf/flatpack/Parser.java trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java Modified: trunk/flatpack/src/main/java/net/sf/flatpack/AbstractParser.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/AbstractParser.java 2010-03-23 21:33:47 UTC (rev 418) +++ trunk/flatpack/src/main/java/net/sf/flatpack/AbstractParser.java 2010-10-26 18:44:57 UTC (rev 419) @@ -75,6 +75,10 @@ private boolean storeRawDataToDataError; private boolean storeRawDataToDataSet; + + private String dataFileTable = "DATAFILE"; + + private String dataStructureTable = "DATASTRUCTURE"; protected AbstractParser(final Reader dataSourceReader) { this.dataSourceReader = dataSourceReader; @@ -303,4 +307,22 @@ public void setStoreRawDataToDataSet(boolean storeRawDataToDataSet) { this.storeRawDataToDataSet = storeRawDataToDataSet; } + + public String getDataFileTable() { + return dataFileTable; + } + + public void setDataFileTable(String dataFileTable) { + this.dataFileTable = dataFileTable; + } + + public String getDataStructureTable() { + return dataStructureTable; + } + + public void setDataStructureTable(String dataStructureTable) { + this.dataStructureTable = dataStructureTable; + } + + } Modified: trunk/flatpack/src/main/java/net/sf/flatpack/DBDelimiterParser.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/DBDelimiterParser.java 2010-03-23 21:33:47 UTC (rev 418) +++ trunk/flatpack/src/main/java/net/sf/flatpack/DBDelimiterParser.java 2010-10-26 18:44:57 UTC (rev 419) @@ -75,7 +75,7 @@ addToCloseReaderList(r); } - final List cmds = ParserUtils.buildMDFromSQLTable(con, getDataDefinition()); + final List cmds = ParserUtils.buildMDFromSQLTable(con, getDataDefinition(), this); addToMetaData(cmds); // addToColumnMD(PZConstants.DETAIL_ID, cmds); // addToColumnMD(PZConstants.COL_IDX, ParserUtils.buidColumnIndexMap(cmds, this)); Modified: trunk/flatpack/src/main/java/net/sf/flatpack/DBFixedLengthParser.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/DBFixedLengthParser.java 2010-03-23 21:33:47 UTC (rev 418) +++ trunk/flatpack/src/main/java/net/sf/flatpack/DBFixedLengthParser.java 2010-10-26 18:44:57 UTC (rev 419) @@ -92,7 +92,7 @@ addToCloseReaderList(r); } - final List cmds = ParserUtils.buildMDFromSQLTable(con, getDataDefinition()); + final List cmds = ParserUtils.buildMDFromSQLTable(con, getDataDefinition(), this); addToMetaData(cmds); // addToColumnMD(PZConstants.DETAIL_ID, cmds); Modified: trunk/flatpack/src/main/java/net/sf/flatpack/Parser.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/Parser.java 2010-03-23 21:33:47 UTC (rev 418) +++ trunk/flatpack/src/main/java/net/sf/flatpack/Parser.java 2010-10-26 18:44:57 UTC (rev 419) @@ -185,5 +185,55 @@ */ void setStoreRawDataToDataSet(final boolean storeRawDataToDataError); + /** + * Returns the table name that will be used to read the MetaData from the db. The + * default table name is DATAFILE. This may be problimatic for some who are using case + * sensistive db table names or who wish to provide a different table name in the db. + * + * This is only applicable when using a database for file mappings. + * + * @return the DATAFILE table name + */ + String getDataFileTable(); + + /** + * Sets the table name that will be used to read the MetaData from the db. The + * default table name is DATAFILE. This may be problimatic for some who are using case + * sensistive db table names or who wish to provide a different table name in the db. + * + * This is only applicable when using a database for file mappings. + * + * @param dataFileTable + * Name of the table name to use in place of "DATAFILE" + */ + void setDataFileTable(final String dataFileTable); + + /** + * Returns the table name that will be used to read the MetaData from the db. The + * default table name is DATASTRUCTURE. This may be problimatic for some who are using case + * sensistive db table names or who wish to provide a different table name in the db. + * + * This is only applicable when using a database for file mappings. + * + * @return the DATASTRUCTURE table name + */ + String getDataStructureTable(); + + + + /** + * Sets the table name that will be used to read the MetaData from the db. The + * default table name is DATASTRUCTURE. This may be problimatic for some who are using case + * sensistive db table names or who wish to provide a different table name in the db. + * + * This is only applicable when using a database for file mappings. + * + * @param dataStructureTable + * Name of the table name to us in placfe of "DATASTRUCTURE" + * + */ + void setDataStructureTable(String dataStructureTable); + + } Modified: trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java =================================================================== --- trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java 2010-03-23 21:33:47 UTC (rev 418) +++ trunk/flatpack/src/main/java/net/sf/flatpack/util/ParserUtils.java 2010-10-26 18:44:57 UTC (rev 419) @@ -1082,6 +1082,7 @@ } } + /** * Returns a definition of pz column metadata from a given * pz datastructure held in an SQL database @@ -1095,14 +1096,38 @@ * @return List */ public static List buildMDFromSQLTable(final Connection con, final String dataDefinition) throws SQLException { + return buildMDFromSQLTable(con, dataDefinition, null); + } + + + /** + * Returns a definition of pz column metadata from a given + * pz datastructure held in an SQL database + * + * @param con + * Database connection containing the Datafile and Datastructure + * tables + * @param dataDefinition + * Name of the data definition stored in the Datafile table + * @param parser + * Instance of the parser being used for the file. It will be checked to get the table names + * for the DATASTRUCTURE table and DATAFILE table. + * @throws SQLException + * @return List + */ + public static List buildMDFromSQLTable(final Connection con, final String dataDefinition, final Parser parser) throws SQLException { PreparedStatement stmt = null; ResultSet rs = null; final List cmds = new ArrayList(); + String dfTbl = parser != null ? parser.getDataFileTable() : "DATAFILE"; + String dsTbl = parser != null ? parser.getDataStructureTable() : "DATASTRUCTURE"; try { - final String sql = "SELECT * FROM DATAFILE INNER JOIN DATASTRUCTURE ON " + "DATAFILE.DATAFILE_NO = DATASTRUCTURE.DATAFILE_NO " - + "WHERE DATAFILE.DATAFILE_DESC = ? " + "ORDER BY DATASTRUCTURE_COL_ORDER"; + final StringBuffer sqlSb = new StringBuffer(); + + sqlSb.append("SELECT * FROM ").append(dfTbl).append(" INNER JOIN ").append(dsTbl).append(" ON ").append(dfTbl).append(".DATAFILE_NO = ").append(dsTbl).append(".DATAFILE_NO " + + "WHERE DATAFILE_DESC = ? ORDER BY DATASTRUCTURE_COL_ORDER"); - stmt = con.prepareStatement(sql); // always use PreparedStatement + stmt = con.prepareStatement(sqlSb.toString()); // always use PreparedStatement // as the DB can do clever things. stmt.setString(1, dataDefinition); rs = stmt.executeQuery(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |