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...> - 2006-10-31 22:47:30
|
Revision: 165 http://svn.sourceforge.net/pzfilereader/?rev=165&view=rev Author: benoitx Date: 2006-10-31 14:47:08 -0800 (Tue, 31 Oct 2006) Log Message: ----------- Paul, some interesting new methods, the BX parser (sorry about the name) seems to be significantly faster than the current one when there are NO qualifiers, If there are qualifiers, it is reasonably faster. But the interesting bits start when I created a new method that uses a StringBuffer rather than using "chunks". The new method is flying when there are qualifiers all over the place... but is slower (albeit not slower than the current one) when there are no qualifier... and that is a bit of a mystery... anyway... getting too late... Have a look and let me know. Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/Examples.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java 2006-10-31 20:47:02 UTC (rev 164) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java 2006-10-31 22:47:08 UTC (rev 165) @@ -12,8 +12,12 @@ */ public class BXParser { public static List splitLine(String line, final char delimiter, char qualifier) { - List list = new ArrayList(); + return splitLine(line, delimiter, qualifier, 10); + } + public static List splitLine(String line, final char delimiter, char qualifier, int initialSize) { + List list = new ArrayList(initialSize); + if (delimiter == 0) { list.add(line); return list; @@ -39,7 +43,6 @@ for (int i = 0; i < size; i++) { final char currentChar = trimmedLine.charAt(i); - if (currentChar != delimiter && currentChar != qualifier) { previousChar = currentChar; endBlock = i + 1; @@ -52,10 +55,9 @@ String trimmed = trimmedLine.substring(startBlock, endBlock > startBlock ? endBlock : startBlock + 1); if (!blockWasInQualifier) { trimmed = trimmed.trim(); + trimmed = trimmed.replaceAll(doubleQualifier, String.valueOf(qualifier)); } - trimmed = trimmed.replaceAll(doubleQualifier, String.valueOf(qualifier)); - if (trimmed.length() == 1 && (trimmed.charAt(0) == delimiter || trimmed.charAt(0) == qualifier)) { list.add(""); } else { @@ -83,7 +85,6 @@ } } } - // antepenultimateChar = previousChar; previousChar = currentChar; } @@ -105,4 +106,108 @@ return list; } + + public static List splitLineWithBuf(String line, final char delimiter, char qualifier, int initialSize) { + List list = new ArrayList(initialSize); + + if (delimiter == 0) { + list.add(line); + return list; + } else if (line == null) { + return list; + } + + final String trimmedLine = line.trim(); + int size = trimmedLine.length(); + + if (size == 0) { + list.add(""); + return list; + } + + boolean insideQualifier = false; + char previousChar = 0; + boolean blockWasInQualifier = false; + StringBuffer buf = new StringBuffer(32); + + // final String doubleQualifier = String.valueOf(qualifier) + + // String.valueOf(qualifier); + for (int i = 0; i < size; i++) { + final char currentChar = trimmedLine.charAt(i); + if (currentChar != delimiter && currentChar != qualifier) { + previousChar = currentChar; + if (' ' != currentChar || insideQualifier || buf.length() > 0) { + buf.append(currentChar); + } + continue; + } + + if (currentChar == delimiter) { + // we've found the delimiter (eg ,) + if (!insideQualifier) { + // String trimmed = trimmedLine.substring(startBlock, + // endBlock > startBlock ? endBlock : startBlock + 1); + String trimmed = buf.toString(); + if (!blockWasInQualifier) { + trimmed = trimmed.trim(); + // trimmed = trimmed.replaceAll(doubleQualifier, + // String.valueOf(qualifier)); + } + + if (trimmed.length() == 1 && (trimmed.charAt(0) == delimiter || trimmed.charAt(0) == qualifier)) { + list.add(""); + } else { + list.add(trimmed); + } + blockWasInQualifier = false; + buf.delete(0, buf.length()); + } else if (buf.length() != 1 || buf.charAt(0) != qualifier) { + buf.append(currentChar); + } else { + buf.delete(0, buf.length()); + insideQualifier = false; + list.add(""); + } + } else if (currentChar == qualifier) { + if (!insideQualifier && previousChar != qualifier) { + if (previousChar == delimiter || previousChar == 0 || previousChar == ' ') { + insideQualifier = true; + int l = buf.length(); + if (l > 0) { + buf.delete(0, l); // just entered a + // qualifier, remove + // whatever was + } + } else { + buf.append(currentChar); + } + } else { + insideQualifier = false; + blockWasInQualifier = true; + if (previousChar == qualifier) { + buf.append(qualifier); + insideQualifier = true; + previousChar = 0; + continue; + } + // last column (e.g. finishes with ") + if (i == size - 1) { + // list.add(trimmedLine.substring(startBlock, size - + // 1)); + list.add(buf.toString()); + buf.delete(0, buf.length()); + } + } + } + previousChar = currentChar; + } + + if (buf.length() > 0) { + list.add(buf.toString().trim()); + } else if (trimmedLine.charAt(size - 1) == delimiter) { + list.add(""); + } + + return list; + } } Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java 2006-10-31 20:47:02 UTC (rev 164) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java 2006-10-31 22:47:08 UTC (rev 165) @@ -44,7 +44,7 @@ final String txtToParse = UnitTestUtils.buildDelimString(DELIMITED_DATA_NO_BREAKS, d, q); - final List splitLineResults = BXParser.splitLine(txtToParse, d, q); + final List splitLineResults = BXParser.splitLineWithBuf(txtToParse, d, q, 10); // check to make sure we have the same amount of elements which were // expected @@ -64,7 +64,7 @@ * Test with any line breaks * */ - public void NOtestLineBreaks() { + public void testLineBreaks() { // loop down all delimiter qualifier pairs to test for (int i = 0; i < DELIM_QUAL_PAIR.length; i++) { final char d = DELIM_QUAL_PAIR[i][0]; @@ -72,7 +72,7 @@ final String txtToParse = UnitTestUtils.buildDelimString(DELIMITED_DATA_WITH_BREAKS, d, q); - final List splitLineResults = BXParser.splitLine(txtToParse, d, q); + final List splitLineResults = BXParser.splitLineWithBuf(txtToParse, d, q, 10); // check to make sure we have the same amount of elements which were // expected @@ -92,7 +92,7 @@ * data */ public void testMalformedData() { - final List splitLineResults = BXParser.splitLine(DELIMITED_BAD_DATA, ',', '\"'); + final List splitLineResults = BXParser.splitLineWithBuf(DELIMITED_BAD_DATA, ',', '\"', 10); assertEquals("Expecting 2 Data Elements From The Malformed Data", 2, splitLineResults.size()); } @@ -134,7 +134,7 @@ } private void check(final String txtToParse, final char delim, final char qualifier, final String[] expected) { - final List splitLineResults = BXParser.splitLine(txtToParse, delim, qualifier); + final List splitLineResults = BXParser.splitLineWithBuf(txtToParse, delim, qualifier, 10); assertEquals( "Did Not Get Amount Of Elements Expected (d = " + delim + " q = " + qualifier + ") txt [" + txtToParse + "]", Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/Examples.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/Examples.java 2006-10-31 20:47:02 UTC (rev 164) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/Examples.java 2006-10-31 22:47:08 UTC (rev 165) @@ -252,11 +252,11 @@ public void doTestParsers() { final int repeat = ConsoleMenu.getInt("How many times?", 1000); - final int characters = ConsoleMenu.getInt("How many columns?", 100); + final int numberOfCols = ConsoleMenu.getInt("How many columns?", 100); final boolean qualif = ConsoleMenu.getBoolean("With qualifier?", true); StringBuilder aRow = new StringBuilder(); - for (int i = 0; i < characters; i++) { + for (int i = 0; i < numberOfCols; i++) { if (qualif) { aRow.append("\""); } @@ -277,14 +277,21 @@ System.out.println("ParserUtil " + (stop - start) + " ms."); start = System.currentTimeMillis(); - StringBuffer sb = new StringBuffer(); for (int i = 0; i < repeat; i++) { - BXParser.splitLine(line, ',', '\"'); + BXParser.splitLine(line, ',', '\"', numberOfCols); } stop = System.currentTimeMillis(); System.out.println("BXParser " + (stop - start) + " ms."); + start = System.currentTimeMillis(); + for (int i = 0; i < repeat; i++) { + BXParser.splitLineWithBuf(line, ',', '\"', numberOfCols); + } + stop = System.currentTimeMillis(); + + System.out.println("BXParser with buf " + (stop - start) + " ms."); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-31 20:47:17
|
Revision: 164 http://svn.sourceforge.net/pzfilereader/?rev=164&view=rev Author: benoitx Date: 2006-10-31 12:47:02 -0800 (Tue, 31 Oct 2006) Log Message: ----------- do not use null for empty fields, use an empty String. Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java 2006-10-31 20:02:48 UTC (rev 163) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java 2006-10-31 20:47:02 UTC (rev 164) @@ -25,7 +25,7 @@ int size = trimmedLine.length(); if (size == 0) { - list.add(null); + list.add(""); return list; } @@ -56,9 +56,7 @@ trimmed = trimmed.replaceAll(doubleQualifier, String.valueOf(qualifier)); - if (trimmed.length() == 1 && trimmed.charAt(0) == delimiter) { - list.add(null); - } else if (trimmed.length() == 1 && trimmed.charAt(0) == qualifier) { + if (trimmed.length() == 1 && (trimmed.charAt(0) == delimiter || trimmed.charAt(0) == qualifier)) { list.add(""); } else { list.add(trimmed); @@ -102,7 +100,7 @@ list.add(str.trim()); } } else if (trimmedLine.charAt(size - 1) == delimiter) { - list.add(null); + list.add(""); } return list; Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java 2006-10-31 20:02:48 UTC (rev 163) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java 2006-10-31 20:47:02 UTC (rev 164) @@ -103,12 +103,12 @@ public void testSomeExtremeCases() { check(null, ',', '\"', new String[] {}); check("a", ',', '\"', new String[] { "a" }); - check("", ',', '\"', new String[] { null }); - check(" ", ',', '\"', new String[] { null }); - check(" ", ',', '\"', new String[] { null }); - check(",", ',', '\"', new String[] { null, null }); - check(",,", ',', '\"', new String[] { null, null, null }); - check(",a,", ',', '\"', new String[] { null, "a", null }); + check("", ',', '\"', new String[] { "" }); + check(" ", ',', '\"', new String[] { "" }); + check(" ", ',', '\"', new String[] { "" }); + check(",", ',', '\"', new String[] { "", "" }); + check(",,", ',', '\"', new String[] { "", "", "" }); + check(",a,", ',', '\"', new String[] { "", "a", "" }); check("\"a,b,c\"", ',', '\"', new String[] { "a,b,c" }); check("\"a,b\",\"c\"", ',', '\"', new String[] { "a,b", "c" }); @@ -126,8 +126,8 @@ check(" a, b ,c ", ',', '\"', new String[] { "a", "b", "c" }); check("\"a\", b , \"c\"", ',', '\"', new String[] { "a", "b", "c" }); - check("\"\",,,,\"last one\"", ',', '\"', new String[] { "", null, null, null, "last one" }); - check("\"first\",\"second\",", ',', '\"', new String[] { "first", "second", null }); + check("\"\",,,,\"last one\"", ',', '\"', new String[] { "", "", "", "", "last one" }); + check("\"first\",\"second\",", ',', '\"', new String[] { "first", "second", "" }); check("\" a,b,c\"", ',', '\"', new String[] { " a,b,c" }); check("\" a,b,c\",d", ',', '\"', new String[] { " a,b,c", "d" }); check("\"a, b,\"\"c\"", ',', '\"', new String[] { "a, b,\"c" }); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-10-31 20:02:53
|
Revision: 163 http://svn.sourceforge.net/pzfilereader/?rev=163&view=rev Author: zepernick Date: 2006-10-31 12:02:48 -0800 (Tue, 31 Oct 2006) Log Message: ----------- modified the last check in testSomeExtremeCases() it appears that it should have 2 " in the result of the parse Benoit, please lmk if this is incorrect. Modified Paths: -------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-31 20:00:17 UTC (rev 162) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-31 20:02:48 UTC (rev 163) @@ -128,7 +128,9 @@ check("\"first\",\"second\",", ',', '\"', new String[] { "first", "second", null }); check("\" a,b,c\"", ',', '\"', new String[] { " a,b,c" }); check("\" a,b,c\",d", ',', '\"', new String[] { " a,b,c", "d" }); - check("\"a, b,\"\"c\"", ',', '\"', new String[] { "a, b,\"c" }); + //++++looks like both quotes should be returned in the result here. + //let me know if I am wrong. pz + check("\"a, b,\"\"c\"", ',', '\"', new String[] { "a, b,\"\"c" }); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-10-31 20:00:21
|
Revision: 162 http://svn.sourceforge.net/pzfilereader/?rev=162&view=rev Author: zepernick Date: 2006-10-31 12:00:17 -0800 (Tue, 31 Oct 2006) Log Message: ----------- - handle null's for lTrim(), lTrimKeepTabs, and splitLine() - splitLine now returns nulls for elements which are empty and have not been qualified - Added a trimToNull method. - All current tests pass with these changes Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-10-31 17:33:49 UTC (rev 161) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-10-31 20:00:17 UTC (rev 162) @@ -73,6 +73,14 @@ */ public static List splitLine(String line, final char delimiter, final char qualifier) { final ArrayList list = new ArrayList(); + + if (line == null) { + return list; + } else if (line.trim().length() == 0){ + list.add(null); + return list; + } + boolean beginQualifier = false; // this will be used for delimted files that have some items qualified // and some items dont @@ -99,7 +107,8 @@ // make sure that this is not just an empty column with no // qualifiers. ie "data",,"data" if (currentChar == delimiter) { - list.add(sb.toString()); + //list.add(sb.toString()); + list.add(null); sb.delete(0, sb.length()); beginNoQualifier = false; continue;// grab the next char @@ -175,7 +184,8 @@ // check to see if we need to add the last column in..this will // happen on empty columns // add the last column - list.add(beginNoQualifier ? lTrim(sb.toString().trim()) : sb.toString()); + list.add(!beginQualifier ? lTrim(trimToNull(sb.toString())) : sb.toString()); + //list.add(null); } sb = null; @@ -210,6 +220,10 @@ * @return String */ public static String lTrim(final String value) { + if (value == null) { + return null; + } + String trimmed = value; int offset = 0; final int maxLength = value.length(); @@ -232,6 +246,10 @@ * @return String */ public static String lTrimKeepTabs(final String value) { + if (value == null) { + return null; + } + String trimmed = value; int offset = 0; final int maxLength = value.length(); @@ -245,6 +263,25 @@ return trimmed; } + + /** + * Will return a null if the String is empty returns the + * trimmed string otherwise. + * + * @param value + * to be trimmed + * @return String + */ + public static String trimToNull(final String value) { + if (value == null) { + return null; + } + + final String ret = value.trim(); + + return ret.length() == 0 ? null : ret; + + } /** * Removes a single string character from a given string This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-31 17:33:53
|
Revision: 161 http://svn.sourceforge.net/pzfilereader/?rev=161&view=rev Author: benoitx Date: 2006-10-31 09:33:49 -0800 (Tue, 31 Oct 2006) Log Message: ----------- Added an option (17) to compare the BX parser and the current parser. It should be noted that the current parser fails on some tests (Paul could you fix?) Just select the number of repeat, the number of columns and whether the column should be qualified or not... tell me your results. ta Modified Paths: -------------- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/Examples.java Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/Examples.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/Examples.java 2006-10-31 17:12:14 UTC (rev 160) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/Examples.java 2006-10-31 17:33:49 UTC (rev 161) @@ -19,6 +19,8 @@ import net.sf.pzfilereader.examples.lowlevelparse.LowLevelParse; import net.sf.pzfilereader.examples.multilinedelimitedrecord.DelimitedMultiLine; import net.sf.pzfilereader.examples.numericsanddates.NumericsAndDates; +import net.sf.pzfilereader.util.BXParser; +import net.sf.pzfilereader.util.ParserUtils; /** * @author Benoit Xhenseval @@ -69,6 +71,7 @@ menu.addMenuItem("NumericsAndDates", "doNumericsAndDates", false); menu.addMenuItem("Ask for GC", "doGC", false); menu.addMenuItem("Test StringBuffer", "doStringBuffer", false); + menu.addMenuItem("Test Parsers", "doTestParsers", false); menu.addMenuItem("Who you gonna call?", "doCall", false); menu.displayMenu(); @@ -247,4 +250,41 @@ } + public void doTestParsers() { + final int repeat = ConsoleMenu.getInt("How many times?", 1000); + final int characters = ConsoleMenu.getInt("How many columns?", 100); + final boolean qualif = ConsoleMenu.getBoolean("With qualifier?", true); + + StringBuilder aRow = new StringBuilder(); + for (int i = 0; i < characters; i++) { + if (qualif) { + aRow.append("\""); + } + aRow.append("Column ").append(i); + if (qualif) { + aRow.append("\""); + } + } + + final String line = aRow.toString(); + + long start = System.currentTimeMillis(); + for (int i = 0; i < repeat; i++) { + ParserUtils.splitLine(line, ',', '\"'); + } + long stop = System.currentTimeMillis(); + + System.out.println("ParserUtil " + (stop - start) + " ms."); + + start = System.currentTimeMillis(); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < repeat; i++) { + BXParser.splitLine(line, ',', '\"'); + } + stop = System.currentTimeMillis(); + + System.out.println("BXParser " + (stop - start) + " ms."); + + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-31 17:12:27
|
Revision: 160 http://svn.sourceforge.net/pzfilereader/?rev=160&view=rev Author: benoitx Date: 2006-10-31 09:12:14 -0800 (Tue, 31 Oct 2006) Log Message: ----------- Paul, I've added some basic tests for null, empty, ",,," kind of things. I've also had a go at a parser, the regular expression is a dead-end or will become **extremely** complex due to our special and whacky cases... The basic tests make quite a few things break in the current version. I'll run a couple of speed tests to see where we're going... Modified Paths: -------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/BXParser.java 2006-10-31 17:12:14 UTC (rev 160) @@ -0,0 +1,110 @@ +/** + * + */ +package net.sf.pzfilereader.util; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author xhensevb + * + */ +public class BXParser { + public static List splitLine(String line, final char delimiter, char qualifier) { + List list = new ArrayList(); + + if (delimiter == 0) { + list.add(line); + return list; + } else if (line == null) { + return list; + } + + final String trimmedLine = line.trim(); + int size = trimmedLine.length(); + + if (size == 0) { + list.add(null); + return list; + } + + boolean insideQualifier = false; + char previousChar = 0; + int startBlock = 0; + int endBlock = 0; + boolean blockWasInQualifier = false; + + final String doubleQualifier = String.valueOf(qualifier) + String.valueOf(qualifier); + for (int i = 0; i < size; i++) { + + final char currentChar = trimmedLine.charAt(i); + + if (currentChar != delimiter && currentChar != qualifier) { + previousChar = currentChar; + endBlock = i + 1; + continue; + } + + if (currentChar == delimiter) { + // we've found the delimiter (eg ,) + if (!insideQualifier) { + String trimmed = trimmedLine.substring(startBlock, endBlock > startBlock ? endBlock : startBlock + 1); + if (!blockWasInQualifier) { + trimmed = trimmed.trim(); + } + + trimmed = trimmed.replaceAll(doubleQualifier, String.valueOf(qualifier)); + + if (trimmed.length() == 1 && trimmed.charAt(0) == delimiter) { + list.add(null); + } else if (trimmed.length() == 1 && trimmed.charAt(0) == qualifier) { + list.add(""); + } else { + list.add(trimmed); + } + blockWasInQualifier = false; + startBlock = i + 1; + } + } else if (currentChar == qualifier) { + if (!insideQualifier && previousChar != qualifier) { + if (previousChar == delimiter || previousChar == 0 || previousChar == ' ') { + insideQualifier = true; + startBlock = i + 1; + } else { + endBlock = i + 1; + } + } else { + insideQualifier = false; + blockWasInQualifier = true; + endBlock = i; + // last column (e.g. finishes with ") + if (i == size - 1) { + list.add(trimmedLine.substring(startBlock, size - 1)); + startBlock = i + 1; + } + } + } + // antepenultimateChar = previousChar; + previousChar = currentChar; + } + + if (startBlock < size) { + String str = trimmedLine.substring(startBlock, size); + str = str.replaceAll(doubleQualifier, String.valueOf(qualifier)); + if (blockWasInQualifier) { + if (str.charAt(str.length() - 1) == qualifier) { + list.add(str.substring(0, str.length() - 1)); + } else { + list.add(str); + } + } else { + list.add(str.trim()); + } + } else if (trimmedLine.charAt(size - 1) == delimiter) { + list.add(null); + } + + return list; + } +} Added: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java (rev 0) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/BXParserTest.java 2006-10-31 17:12:14 UTC (rev 160) @@ -0,0 +1,151 @@ +package net.sf.pzfilereader.parserutils; + +import java.util.List; + +import junit.framework.TestCase; +import net.sf.pzfilereader.util.BXParser; +import net.sf.pzfilereader.util.ParserUtils; +import net.sf.pzfilereader.util.RegExParser; +import net.sf.pzfilereader.utilities.UnitTestUtils; + +/** + * Test the functionality of the splitLine method. This method returns a List of + * Strings. Each element of the list represents a column created by the parser + * from the delimited String. + * + * @author Paul Zepernick + */ +public class BXParserTest extends TestCase { + private static final String[] DELIMITED_DATA_NO_BREAKS = { "Column 1", "Column 2", "Column 3", "Column 4", "Column 5" }; + + private static final String[] DELIMITED_DATA_WITH_BREAKS = { "Column 1 \r\n\r\n Test After Break \r\n Another Break", + "Column 2", "Column 3 \r\n\r\n Test After Break", "Column 4", "Column 5 \r\n\r\n Test After Break\r\n Another Break" }; + + // TODO think of a situation that actually breaks the parse. This still + // works because of the way it is coded + // to handle the excel CSV. Excel CSV has some elements qualified and others + // not + private static final String DELIMITED_BAD_DATA = "\"column 1\",\"column 2 ,\"column3\""; + + // 0 = delimiter + // 1 = qualifier + private static final char[][] DELIM_QUAL_PAIR = { { ',', '\"' }, { '\t', '\"' }, { '|', '\"' }, { '_', '\"' }, { ',', 0 }, + { '|', 0 }, { '\t', 0 } }; + + /** + * Test without any line breaks + * + */ + public void testNoLineBreaks() { + // loop down all delimiter qualifier pairs to test + for (int i = 0; i < DELIM_QUAL_PAIR.length; i++) { + final char d = DELIM_QUAL_PAIR[i][0]; + final char q = DELIM_QUAL_PAIR[i][1]; + + final String txtToParse = UnitTestUtils.buildDelimString(DELIMITED_DATA_NO_BREAKS, d, q); + + final List splitLineResults = BXParser.splitLine(txtToParse, d, q); + + // check to make sure we have the same amount of elements which were + // expected + assertEquals("Expected size (d = [" + d + "] q = [" + (q != 0 ? String.valueOf(q) : "") + "] txt [" + txtToParse + + "])", DELIMITED_DATA_NO_BREAKS.length, splitLineResults.size()); + + // loop through each value and compare what came back + for (int j = 0; j < DELIMITED_DATA_NO_BREAKS.length; j++) { + assertEquals("Data Element Value Does Not Match (d = [" + d + "] q = [" + q + "] txt [" + txtToParse + "])", + DELIMITED_DATA_NO_BREAKS[j], (String) splitLineResults.get(j)); + } + } + + } + + /** + * Test with any line breaks + * + */ + public void NOtestLineBreaks() { + // loop down all delimiter qualifier pairs to test + for (int i = 0; i < DELIM_QUAL_PAIR.length; i++) { + final char d = DELIM_QUAL_PAIR[i][0]; + final char q = DELIM_QUAL_PAIR[i][1]; + + final String txtToParse = UnitTestUtils.buildDelimString(DELIMITED_DATA_WITH_BREAKS, d, q); + + final List splitLineResults = BXParser.splitLine(txtToParse, d, q); + + // check to make sure we have the same amount of elements which were + // expected + assertEquals("Did Not Get Amount Of Elements Expected (d = " + d + " q = " + q + ")", + DELIMITED_DATA_WITH_BREAKS.length, splitLineResults.size()); + + // loop through each value and compare what came back + for (int j = 0; j < DELIMITED_DATA_WITH_BREAKS.length; j++) { + assertEquals("Data Element Value Does Not Match (d = " + d + " q = " + q + ")", DELIMITED_DATA_WITH_BREAKS[j], + (String) splitLineResults.get(j)); + } + } + } + + /** + * Test to make sure we get the correct amount of elements for malformed + * data + */ + public void testMalformedData() { + final List splitLineResults = BXParser.splitLine(DELIMITED_BAD_DATA, ',', '\"'); + + assertEquals("Expecting 2 Data Elements From The Malformed Data", 2, splitLineResults.size()); + } + + /** + * Test some extreme cases + */ + public void testSomeExtremeCases() { + check(null, ',', '\"', new String[] {}); + check("a", ',', '\"', new String[] { "a" }); + check("", ',', '\"', new String[] { null }); + check(" ", ',', '\"', new String[] { null }); + check(" ", ',', '\"', new String[] { null }); + check(",", ',', '\"', new String[] { null, null }); + check(",,", ',', '\"', new String[] { null, null, null }); + check(",a,", ',', '\"', new String[] { null, "a", null }); + + check("\"a,b,c\"", ',', '\"', new String[] { "a,b,c" }); + check("\"a,b\",\"c\"", ',', '\"', new String[] { "a,b", "c" }); + check("\"a , b\",\"c\"", ',', '\"', new String[] { "a , b", "c" }); + check("a,b,c", ',', '\"', new String[] { "a", "b", "c" }); + check("a b,c", ',', '\"', new String[] { "a b", "c" }); + check(" a,b,c ", ',', '\"', new String[] { "a", "b", "c" }); + check(" a, b ,c", ',', '\"', new String[] { "a", "b", "c" }); + + // example typically from Excel. + check("\"test1\",test2,\"0.00\",\"another, element here\",lastone", ',', '\"', new String[] { "test1", "test2", "0.00", + "another, element here", "lastone" }); + + check("a\",b,c\"", ',', '\"', new String[] { "a\"", "b", "c\"" }); + check(" a, b ,c ", ',', '\"', new String[] { "a", "b", "c" }); + check("\"a\", b , \"c\"", ',', '\"', new String[] { "a", "b", "c" }); + + check("\"\",,,,\"last one\"", ',', '\"', new String[] { "", null, null, null, "last one" }); + check("\"first\",\"second\",", ',', '\"', new String[] { "first", "second", null }); + check("\" a,b,c\"", ',', '\"', new String[] { " a,b,c" }); + check("\" a,b,c\",d", ',', '\"', new String[] { " a,b,c", "d" }); + check("\"a, b,\"\"c\"", ',', '\"', new String[] { "a, b,\"c" }); + } + + private void check(final String txtToParse, final char delim, final char qualifier, final String[] expected) { + final List splitLineResults = BXParser.splitLine(txtToParse, delim, qualifier); + + assertEquals( + "Did Not Get Amount Of Elements Expected (d = " + delim + " q = " + qualifier + ") txt [" + txtToParse + "]", + expected.length, splitLineResults.size()); + + for (int i = 0; i < expected.length; i++) { + assertEquals("expecting...", expected[i], splitLineResults.get(i)); + } + } + + public static void main(final String[] args) { + junit.textui.TestRunner.run(BXParserTest.class); + } +} Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-31 16:07:23 UTC (rev 159) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-31 17:12:14 UTC (rev 160) @@ -99,49 +99,36 @@ * Test some extreme cases */ public void testSomeExtremeCases() { - // back to Basic... check(null, ',', '\"', new String[] {}); check("a", ',', '\"', new String[] { "a" }); check("", ',', '\"', new String[] { null }); + check(" ", ',', '\"', new String[] { null }); + check(" ", ',', '\"', new String[] { null }); check(",", ',', '\"', new String[] { null, null }); check(",,", ',', '\"', new String[] { null, null, null }); check(",a,", ',', '\"', new String[] { null, "a", null }); - // - check("\"a,b,c\"", ',', '\"', new String[] { "a,b,c" }); check("\"a,b\",\"c\"", ',', '\"', new String[] { "a,b", "c" }); + check("\"a , b\",\"c\"", ',', '\"', new String[] { "a , b", "c" }); check("a,b,c", ',', '\"', new String[] { "a", "b", "c" }); - check(" a,b,c", ',', '\"', new String[] { "a", "b", "c" }); - check(" a,b,c", ',', '\"', new String[] { "a", "b", "c" }); + check("a b,c", ',', '\"', new String[] { "a b", "c" }); + check(" a,b,c ", ',', '\"', new String[] { "a", "b", "c" }); + check(" a, b ,c", ',', '\"', new String[] { "a", "b", "c" }); // example typically from Excel. check("\"test1\",test2,\"0.00\",\"another, element here\",lastone", ',', '\"', new String[] { "test1", "test2", "0.00", "another, element here", "lastone" }); - // what would you expect of these ones? - - // +++++The parser allows qualified and unqualified elements to be - // contained - // on the same line. so it should break the elements down like so - // 1 = a" -->" is part of the data since the element did not start with - // a qualifier - // 2 = b - // 3 = c" --> same as #1 - // a",b,c" check("a\",b,c\"", ',', '\"', new String[] { "a\"", "b", "c\"" }); - //should not trim leading space inside of a qualified element - check("\" a,b,c\"", ',', '\"', new String[] { " a,b,c" }); - check(" a, b ,c ", ',', '\"', new String[] { "a","b","c" }); - check("\"a\", b , \"c\"", ',', '\"', new String[] {"a","b","c"}); - //check malformed data - //TODO - I believe this should be producing 2 elements. As soon as their is a - //delimter followed by a qualifier a new element shoudl be created - //+++Any thoughts Benoit? - check("\"a, b,\"c\"", ',', '\"', new String[] {"a, b,\"c"}); - check("\"\",,,,\"last one\"", ',', '\"', new String[] {"","","","","last one"}); - check("\"first\",\"second\",", ',', '\"', new String[] {"first","second",""}); + check(" a, b ,c ", ',', '\"', new String[] { "a", "b", "c" }); + check("\"a\", b , \"c\"", ',', '\"', new String[] { "a", "b", "c" }); + check("\"\",,,,\"last one\"", ',', '\"', new String[] { "", null, null, null, "last one" }); + check("\"first\",\"second\",", ',', '\"', new String[] { "first", "second", null }); + check("\" a,b,c\"", ',', '\"', new String[] { " a,b,c" }); + check("\" a,b,c\",d", ',', '\"', new String[] { " a,b,c", "d" }); + check("\"a, b,\"\"c\"", ',', '\"', new String[] { "a, b,\"c" }); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-31 16:07:29
|
Revision: 159 http://svn.sourceforge.net/pzfilereader/?rev=159&view=rev Author: benoitx Date: 2006-10-31 08:07:23 -0800 (Tue, 31 Oct 2006) Log Message: ----------- One more funny test.... Modified Paths: -------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-31 16:05:16 UTC (rev 158) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-31 16:07:23 UTC (rev 159) @@ -102,6 +102,7 @@ // back to Basic... check(null, ',', '\"', new String[] {}); check("a", ',', '\"', new String[] { "a" }); + check("", ',', '\"', new String[] { null }); check(",", ',', '\"', new String[] { null, null }); check(",,", ',', '\"', new String[] { null, null, null }); check(",a,", ',', '\"', new String[] { null, "a", null }); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-31 16:05:20
|
Revision: 158 http://svn.sourceforge.net/pzfilereader/?rev=158&view=rev Author: benoitx Date: 2006-10-31 08:05:16 -0800 (Tue, 31 Oct 2006) Log Message: ----------- I have added a few very basic tests and they all seem to fail... Paul, could you investigate? thanks. Modified Paths: -------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-31 15:04:16 UTC (rev 157) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-31 16:05:16 UTC (rev 158) @@ -99,6 +99,15 @@ * Test some extreme cases */ public void testSomeExtremeCases() { + // back to Basic... + check(null, ',', '\"', new String[] {}); + check("a", ',', '\"', new String[] { "a" }); + check(",", ',', '\"', new String[] { null, null }); + check(",,", ',', '\"', new String[] { null, null, null }); + check(",a,", ',', '\"', new String[] { null, "a", null }); + + // + check("\"a,b,c\"", ',', '\"', new String[] { "a,b,c" }); check("\"a,b\",\"c\"", ',', '\"', new String[] { "a,b", "c" }); check("a,b,c", ',', '\"', new String[] { "a", "b", "c" }); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-10-31 15:04:30
|
Revision: 157 http://svn.sourceforge.net/pzfilereader/?rev=157&view=rev Author: zepernick Date: 2006-10-31 07:04:16 -0800 (Tue, 31 Oct 2006) Log Message: ----------- converted to factory classes Modified Paths: -------------- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvperformancetest/CSVPerformanceTest.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimitedcolumnnamesinfile/DelimitedColumnNamesInFile.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumns/DelimitedWithPZMap.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumnswitherrors/DelimitedWithPZMapErrors.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/exporttoexcel/DelimitedFileExportToExcel.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthdynamiccolumns/FixedLengthWithPZMap.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthheaderandtrailer/FixedLengthHeaderAndTrailer.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/jsptableexample/pzfilereaderwebsamples/index.jsp trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/multilinedelimitedrecord/DelimitedMultiLine.java trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/numericsanddates/NumericsAndDates.java Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvperformancetest/CSVPerformanceTest.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvperformancetest/CSVPerformanceTest.java 2006-10-31 14:38:33 UTC (rev 156) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvperformancetest/CSVPerformanceTest.java 2006-10-31 15:04:16 UTC (rev 157) @@ -8,6 +8,9 @@ import net.sf.pzfilereader.DataError; import net.sf.pzfilereader.DataSet; +import net.sf.pzfilereader.DefaultPZParserFactory; +import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.PZParser; /* * Created on Dec 1, 2005 @@ -42,16 +45,17 @@ } public static void call(String filename, boolean verbose, boolean traverse) throws Exception, InterruptedException { - DataSet ds = null; String[] colNames = null; // delimited by a comma // text qualified by double quotes // ignore first record System.out.println("Parsing...."); + final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(filename), + ',', '"'); long timeStarted = System.currentTimeMillis(); - ds = new DataSet(new File(filename), ',', '"', false); + final IDataSet ds = pzparser.parse(); long timeFinished = System.currentTimeMillis(); - + String timeMessage = ""; if (timeFinished - timeStarted < 1000) { Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimitedcolumnnamesinfile/DelimitedColumnNamesInFile.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimitedcolumnnamesinfile/DelimitedColumnNamesInFile.java 2006-10-31 14:38:33 UTC (rev 156) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimitedcolumnnamesinfile/DelimitedColumnNamesInFile.java 2006-10-31 15:04:16 UTC (rev 157) @@ -7,8 +7,13 @@ import java.io.File; +import com.sun.jmx.snmp.defaults.DefaultPaths; + import net.sf.pzfilereader.DataError; import net.sf.pzfilereader.DataSet; +import net.sf.pzfilereader.DefaultPZParserFactory; +import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.PZParser; import net.sf.pzfilereader.ordering.OrderBy; import net.sf.pzfilereader.ordering.OrderColumn; @@ -20,15 +25,16 @@ */ public class DelimitedColumnNamesInFile { public static void main(final String[] args) throws Exception { - DataSet ds = null; String[] colNames = null; OrderBy orderby = null; // delimited by a comma // text qualified by double quotes // ignore first record - ds = new DataSet(new File("PEOPLE-CommaDelimitedWithQualifier.txt"), ',', '"', false); - + final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser( + new File("PEOPLE-CommaDelimitedWithQualifier.txt"), ',', '"'); + final IDataSet ds = pzparser.parse(); + // re order the data set by last name orderby = new OrderBy(); orderby.addOrderColumn(new OrderColumn("CITY", false)); Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumns/DelimitedWithPZMap.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumns/DelimitedWithPZMap.java 2006-10-31 14:38:33 UTC (rev 156) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumns/DelimitedWithPZMap.java 2006-10-31 15:04:16 UTC (rev 157) @@ -8,6 +8,9 @@ import java.io.File; import net.sf.pzfilereader.DataSet; +import net.sf.pzfilereader.DefaultPZParserFactory; +import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.PZParser; import net.sf.pzfilereader.ordering.OrderBy; import net.sf.pzfilereader.ordering.OrderColumn; @@ -38,9 +41,10 @@ // delimited by a comma // text qualified by double quotes // ignore first record - DataSet ds = null; OrderBy orderby = null; - ds = new DataSet(new File(mapping), new File(data), ',', '"', true, false); + final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(mapping), + new File(data), ',', '"', true); + final IDataSet ds = pzparser.parse(); // re order the data set by last name orderby = new OrderBy(); Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumnswitherrors/DelimitedWithPZMapErrors.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumnswitherrors/DelimitedWithPZMapErrors.java 2006-10-31 14:38:33 UTC (rev 156) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/delimiteddynamiccolumnswitherrors/DelimitedWithPZMapErrors.java 2006-10-31 15:04:16 UTC (rev 157) @@ -10,6 +10,9 @@ import net.sf.pzfilereader.DataError; import net.sf.pzfilereader.DataSet; +import net.sf.pzfilereader.DefaultPZParserFactory; +import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.PZParser; import net.sf.pzfilereader.ordering.OrderBy; import net.sf.pzfilereader.ordering.OrderColumn; @@ -36,25 +39,19 @@ } public static void call(String mapping, String data) throws Exception { - - DataSet ds = null; - String[] colNames = null; - OrderBy orderby = null; - Iterator errors = null; - DataError dataError = null; - - // delimited by a comma + // delimited by a comma // text qualified by double quotes // ignore first record - ds = new DataSet(new File(mapping), new File(data), ',', '"', true, false); - + final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(mapping), new File(data), + ',', '"', true); + final IDataSet ds = pzparser.parse(); // re order the data set by last name - orderby = new OrderBy(); + final OrderBy orderby = new OrderBy(); orderby.addOrderColumn(new OrderColumn("CITY", false)); orderby.addOrderColumn(new OrderColumn("LASTNAME", true)); ds.orderRows(orderby); - colNames = ds.getColumns(); + final String[] colNames = ds.getColumns(); while (ds.next()) { @@ -83,10 +80,9 @@ } System.out.println(">>>>>>ERRORS!!!"); - errors = ds.getErrors().iterator(); - + final Iterator errors = ds.getErrors().iterator(); while (errors.hasNext()) { - dataError = (DataError) errors.next(); + final DataError dataError = (DataError) errors.next(); System.out.println("ERROR: " + dataError.getErrorDesc() + " LINE NUMBER: " + dataError.getLineNo()); } Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/exporttoexcel/DelimitedFileExportToExcel.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/exporttoexcel/DelimitedFileExportToExcel.java 2006-10-31 14:38:33 UTC (rev 156) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/exporttoexcel/DelimitedFileExportToExcel.java 2006-10-31 15:04:16 UTC (rev 157) @@ -9,8 +9,12 @@ import net.sf.pzfilereader.DataError; import net.sf.pzfilereader.DataSet; +import net.sf.pzfilereader.DefaultPZParserFactory; +import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.PZParser; import net.sf.pzfilereader.ordering.OrderBy; import net.sf.pzfilereader.ordering.OrderColumn; +import net.sf.pzfilereader.util.ExcelTransformer; /** * @author zepernick @@ -35,16 +39,15 @@ } public static void call(String mapping, String data) throws Exception { - DataSet ds = null; - OrderBy orderby = null; - // delimited by a comma // text qualified by double quotes // ignore first record - ds = new DataSet(new File(mapping), new File(data), ',', '"', true, false); + final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(mapping), + new File(data), ',', '"', true); + final IDataSet ds = pzparser.parse(); // re order the data set by last name - orderby = new OrderBy(); + final OrderBy orderby = new OrderBy(); orderby.addOrderColumn(new OrderColumn("CITY", false)); orderby.addOrderColumn(new OrderColumn("LASTNAME", true)); ds.orderRows(orderby); @@ -56,9 +59,10 @@ } } - // lets write this file out to excel :) + // lets write this file out to excel File xlFile = new File("MyExcelExport.xls"); - ds.writeToExcel(xlFile); + final ExcelTransformer xlTransformer = new ExcelTransformer(ds, xlFile); + xlTransformer.writeExcelFile(); System.out.println("Excel Workbook Written To: " + xlFile.getAbsolutePath()); } Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthdynamiccolumns/FixedLengthWithPZMap.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthdynamiccolumns/FixedLengthWithPZMap.java 2006-10-31 14:38:33 UTC (rev 156) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthdynamiccolumns/FixedLengthWithPZMap.java 2006-10-31 15:04:16 UTC (rev 157) @@ -8,6 +8,9 @@ import java.io.File; import net.sf.pzfilereader.DataSet; +import net.sf.pzfilereader.DefaultPZParserFactory; +import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.PZParser; /** * @author zepernick @@ -32,13 +35,12 @@ } public static void call(String mapping, String data) throws Exception { - DataSet ds = null; - String[] colNames = null; + final PZParser pzparser = DefaultPZParserFactory.getInstance().newFixedLengthParser( + new File(mapping), new File(data)); + final IDataSet ds = pzparser.parse(); - ds = new DataSet(new File(mapping), new File(data), false); + final String[] colNames = ds.getColumns(); - colNames = ds.getColumns(); - while (ds.next()) { for (int i = 0; i < colNames.length; i++) { System.out.println("COLUMN NAME: " + colNames[i] + " VALUE: " + ds.getString(colNames[i])); Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthheaderandtrailer/FixedLengthHeaderAndTrailer.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthheaderandtrailer/FixedLengthHeaderAndTrailer.java 2006-10-31 14:38:33 UTC (rev 156) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/fixedlengthheaderandtrailer/FixedLengthHeaderAndTrailer.java 2006-10-31 15:04:16 UTC (rev 157) @@ -10,6 +10,9 @@ import net.sf.pzfilereader.DataError; import net.sf.pzfilereader.DataSet; +import net.sf.pzfilereader.DefaultPZParserFactory; +import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.PZParser; /** * @author zepernick @@ -34,12 +37,12 @@ } public static void call(String mapping, String data) throws Exception { - DataSet ds = null; Iterator errors = null; DataError dataError = null; + final PZParser pzparser = DefaultPZParserFactory.getInstance().newFixedLengthParser(new File(mapping), + new File(data)); + final IDataSet ds = pzparser.parse(); - ds = new DataSet(new File(mapping), new File(data), false); - while (ds.next()) { if (ds.isRecordID("header")) { Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/jsptableexample/pzfilereaderwebsamples/index.jsp =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/jsptableexample/pzfilereaderwebsamples/index.jsp 2006-10-31 14:38:33 UTC (rev 156) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/jsptableexample/pzfilereaderwebsamples/index.jsp 2006-10-31 15:04:16 UTC (rev 157) @@ -9,7 +9,6 @@ </head> <% - DataSet ds = null; OrderBy order = null; try{ @@ -23,13 +22,10 @@ mappingFile = new File (appDirectory + "/PEOPLE.pzmap.xml"); txtFile = new File (appDirectory + "/PEOPLE.txt"); - //read in the file a - ds = new DataSet(mappingFile, //mapping file here - txtFile, //text file that is being parsed - ',', //how the file is delimited - 0, //if the text is qualified, pass the qualifier here, otherwise leave empty - false, //ignore the first row in the file if it contain column names - false); //don't auto add missing columns, log them as errors + //read in the file + final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(mappingFile, + txtFile, ',', 0, false) ; + final IDataSet ds = pzparser.parse(); //check to see if there is a paramter in the request that is telling us what column to sort by Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/multilinedelimitedrecord/DelimitedMultiLine.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/multilinedelimitedrecord/DelimitedMultiLine.java 2006-10-31 14:38:33 UTC (rev 156) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/multilinedelimitedrecord/DelimitedMultiLine.java 2006-10-31 15:04:16 UTC (rev 157) @@ -8,6 +8,9 @@ import java.io.File; import net.sf.pzfilereader.DataSet; +import net.sf.pzfilereader.DefaultPZParserFactory; +import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.PZParser; /** * @author zepernick @@ -32,14 +35,14 @@ } public static void call(String data) throws Exception { - DataSet ds = null; - String[] colNames = null; // delimited by a comma // text qualified by double quotes // ignore first record - ds = new DataSet(new File(data), ',', '"', false); + final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(data), + ',', '\"'); + final IDataSet ds = pzparser.parse(); - colNames = ds.getColumns(); + final String[] colNames = ds.getColumns(); while (ds.next()) { for (int i = 0; i < colNames.length; i++) { Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/numericsanddates/NumericsAndDates.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/numericsanddates/NumericsAndDates.java 2006-10-31 14:38:33 UTC (rev 156) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/numericsanddates/NumericsAndDates.java 2006-10-31 15:04:16 UTC (rev 157) @@ -9,6 +9,9 @@ import java.text.SimpleDateFormat; import net.sf.pzfilereader.DataSet; +import net.sf.pzfilereader.DefaultPZParserFactory; +import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.PZParser; /** * @author zepernick @@ -32,15 +35,15 @@ } public static void call(String mapping, String data) throws Exception { - DataSet ds = null; // wll provide a clean format for printing the date to the screen final SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); // delimited by a comma // text qualified by double quotes // ignore first record - ds = new DataSet(new File(mapping), new File(data), ',', '"', true, false); - + final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(new File(mapping), + new File(data), ',', '\"', true); + final IDataSet ds = pzparser.parse(); // demonstrates the casting abilities of PZFileReader while (ds.next()) { System.out.println("Item Desc: " + ds.getString("ITEM_DESC") + " (String)"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-10-31 14:38:37
|
Revision: 156 http://svn.sourceforge.net/pzfilereader/?rev=156&view=rev Author: zepernick Date: 2006-10-31 06:38:33 -0800 (Tue, 31 Oct 2006) Log Message: ----------- converted to IDataSet interface Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ExcelTransformer.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ExcelTransformer.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ExcelTransformer.java 2006-10-31 14:25:17 UTC (rev 155) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ExcelTransformer.java 2006-10-31 14:38:33 UTC (rev 156) @@ -23,6 +23,7 @@ import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import net.sf.pzfilereader.DataSet; +import net.sf.pzfilereader.IDataSet; /** * @author Paul Zepernick @@ -31,7 +32,7 @@ */ public class ExcelTransformer { - private DataSet ds; + private IDataSet ds; private File xlsFile; @@ -43,7 +44,7 @@ * @param xlsFile * Excel file to be created */ - public ExcelTransformer(final DataSet ds, final File xlsFile) { + public ExcelTransformer(final IDataSet ds, final File xlsFile) { this.ds = ds; this.xlsFile = xlsFile; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-10-31 14:25:24
|
Revision: 155 http://svn.sourceforge.net/pzfilereader/?rev=155&view=rev Author: zepernick Date: 2006-10-31 06:25:17 -0800 (Tue, 31 Oct 2006) Log Message: ----------- converted to factory classes Modified Paths: -------------- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvheaderandtrailer/CSVHeaderAndTrailer.java Modified: trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvheaderandtrailer/CSVHeaderAndTrailer.java =================================================================== --- trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvheaderandtrailer/CSVHeaderAndTrailer.java 2006-10-31 13:38:04 UTC (rev 154) +++ trunk/PZFileReaderSamples/src/main/java/net/sf/pzfilereader/examples/csvheaderandtrailer/CSVHeaderAndTrailer.java 2006-10-31 14:25:17 UTC (rev 155) @@ -7,7 +7,9 @@ import java.io.File; -import net.sf.pzfilereader.DataSet; +import net.sf.pzfilereader.DefaultPZParserFactory; +import net.sf.pzfilereader.IDataSet; +import net.sf.pzfilereader.PZParser; /** * @author zepernick @@ -29,13 +31,14 @@ } public static void call(final String mapping, final String data) throws Exception { - File mapFile = new File(mapping); - File dataFile = new File(data); + final File mapFile = new File(mapping); + final File dataFile = new File(data); // delimited by a comma // text qualified by double quotes - // ignore first record - DataSet ds = new DataSet(mapFile, dataFile, ',', '"', true, false); - + // ignore first record + final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(mapFile, dataFile, + ',', '\"', true); + final IDataSet ds = pzparser.parse(); while (ds.next()) { if (ds.isRecordID("header")) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-31 13:38:17
|
Revision: 154 http://svn.sourceforge.net/pzfilereader/?rev=154&view=rev Author: benoitx Date: 2006-10-31 05:38:04 -0800 (Tue, 31 Oct 2006) Log Message: ----------- added a few more tests. Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/RegExParser.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/RegExParserTest.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/RegExParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/RegExParser.java 2006-10-31 11:44:42 UTC (rev 153) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/RegExParser.java 2006-10-31 13:38:04 UTC (rev 154) @@ -4,6 +4,7 @@ package net.sf.pzfilereader.util; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -21,11 +22,13 @@ * third a null field. */ public static final String CSV_PATTERN = "\"(.*?)\",|(\\w+),|\"(.*?)\"|(\\w+),|,"; + public static final String CSV_PATTERN2 = "([^\"]+?),|\"(.*?)\",|(\\w+),|\"(.*?)\"|(\\w+)"; + public static final String ORIGINAL_CSV_PATTERN = "\"([^\"]+?)\",?|([^,]+),?|,"; // public static final String CSV_PATTERN = "\"([^\"]+?)\",?|([^,]+),?|,"; -// private static Pattern csvRE = Pattern.compile(CSV_PATTERN); + // private static Pattern csvRE = Pattern.compile(CSV_PATTERN); public static List splitLine(String line, final char delimiter, char qualifier) { StringBuilder patternBuilder = new StringBuilder(); @@ -68,11 +71,21 @@ String pat = patternBuilder.toString(); + pat = CSV_PATTERN2; + System.out.println(pat); + System.out.println("Input: [" + line + "]"); Pattern pattern = Pattern.compile(pat); - return parse(pattern, line, String.valueOf(delimiter), String.valueOf(qualifier)); + List l = parse(pattern, line, String.valueOf(delimiter), String.valueOf(qualifier)); + + int u = 1; + for (Iterator i = l.iterator(); i.hasNext(); u++) { + System.out.println(u + "/" + l.size() + " -- [" + i.next() + "]"); + } + + return l; } private static String escapeIfRequired(final char c) { @@ -104,6 +117,9 @@ if (match.startsWith(qualifier)) { // assume also ends with match = match.substring(1, match.length() - 1); } + + match = match.trim(); + if (match.length() == 0) match = null; list.add(match); Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-31 11:44:42 UTC (rev 153) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-31 13:38:04 UTC (rev 154) @@ -46,8 +46,8 @@ // check to make sure we have the same amount of elements which were // expected - assertEquals("Did Not Get Amount Of Elements Expected (d = [" + d + "] q = [" + q + "] txt [" + txtToParse + "])", - DELIMITED_DATA_NO_BREAKS.length, splitLineResults.size()); + assertEquals("Expected size (d = [" + d + "] q = [" + (q != 0 ? String.valueOf(q) : "") + "] txt [" + txtToParse + + "])", DELIMITED_DATA_NO_BREAKS.length, splitLineResults.size()); // loop through each value and compare what came back for (int j = 0; j < DELIMITED_DATA_NO_BREAKS.length; j++) { @@ -103,21 +103,26 @@ check("\"a,b\",\"c\"", ',', '\"', new String[] { "a,b", "c" }); check("a,b,c", ',', '\"', new String[] { "a", "b", "c" }); check(" a,b,c", ',', '\"', new String[] { "a", "b", "c" }); - check(" a,b,c", ',', '\"', new String[] { "a","b","c" }); - + check(" a,b,c", ',', '\"', new String[] { "a", "b", "c" }); + + // example typically from Excel. + check("\"test1\",test2,\"0.00\",\"another, element here\",lastone", ',', '\"', new String[] { "test1", "test2", "0.00", + "another, element here", "lastone" }); + // what would you expect of these ones? - - //+++++The parser allows qualified and unqualified elements to be contained - //on the same line. so it should break the elements down like so - //1 = a" -->" is part of the data since the element did not start with a qualifier - //2 = b - //3 = c" --> same as #1 + + // +++++The parser allows qualified and unqualified elements to be + // contained + // on the same line. so it should break the elements down like so + // 1 = a" -->" is part of the data since the element did not start with + // a qualifier + // 2 = b + // 3 = c" --> same as #1 + // a",b,c" check("a\",b,c\"", ',', '\"', new String[] { "a\"", "b", "c\"" }); //should not trim leading space inside of a qualified element check("\" a,b,c\"", ',', '\"', new String[] { " a,b,c" }); check(" a, b ,c ", ',', '\"', new String[] { "a","b","c" }); - - // Paul... please put some more whacky stuff here... check("\"a\", b , \"c\"", ',', '\"', new String[] {"a","b","c"}); //check malformed data //TODO - I believe this should be producing 2 elements. As soon as their is a @@ -129,6 +134,37 @@ } + /** + * Test some extreme cases + */ + public void testSomeExtremeCases2() { + check("\"a,b,c\"", ',', '\'', new String[] { "\"a", "b", "c\"" }); + check("\"a,b\",\"c\"", ',', '\'', new String[] { "\"a", "b\"", "\"c\"" }); + check("a,b,c", ',', '\'', new String[] { "a", "b", "c" }); + check(" a,b,c", ',', '\'', new String[] { "a", "b", "c" }); + check(" a,b,c", ',', '\'', new String[] { "a", "b", "c" }); + + // example typically from Excel. + check("\"test1\",test2,\"0.00\",\"another, element here\",lastone", ',', '\'', new String[] { "\"test1\"", "test2", + "\"0.00\"", "\"another", "element here\"", "lastone" }); + + // what would you expect of these ones? + + // +++++The parser allows qualified and unqualified elements to be + // contained + // on the same line. so it should break the elements down like so + // 1 = a" -->" is part of the data since the element did not start with + // a qualifier + // 2 = b + // 3 = c" --> same as #1 + // a",b,c" + check("a\",b,c\"", ',', '\'', new String[] { "a\"", "b", "c\"" }); + + check("\" a,b,c\"", ',', '\'', new String[] { "\" a", "b", "c\"" }); + check(" a, b ,c ", ',', '\'', new String[] { "a", "b", "c" }); + + } + private void check(final String txtToParse, final char delim, final char qualifier, final String[] expected) { final List splitLineResults = ParserUtils.splitLine(txtToParse, delim, qualifier); Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/RegExParserTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/RegExParserTest.java 2006-10-31 11:44:42 UTC (rev 153) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/RegExParserTest.java 2006-10-31 13:38:04 UTC (rev 154) @@ -102,7 +102,9 @@ public void testSomeExtremeCases() { check("\"a,b,c\"", ',', '\"', new String[] { "a,b,c" }); check("\"a,b\",\"c\"", ',', '\"', new String[] { "a,b", "c" }); + check("\"a , b\",\"c\"", ',', '\"', new String[] { "a , b", "c" }); check("a,b,c", ',', '\"', new String[] { "a", "b", "c" }); + check("a b,c", ',', '\"', new String[] { "a b", "c" }); check(" a,b,c", ',', '\"', new String[] { "a", "b", "c" }); check(" a,b,c", ',', '\"', new String[] { "a", "b", "c" }); @@ -127,7 +129,7 @@ } private void check(final String txtToParse, final char delim, final char qualifier, final String[] expected) { - final List splitLineResults = ParserUtils.splitLine(txtToParse, delim, qualifier); + final List splitLineResults = RegExParser.splitLine(txtToParse, delim, qualifier); assertEquals( "Did Not Get Amount Of Elements Expected (d = " + delim + " q = " + qualifier + ") txt [" + txtToParse + "]", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-31 11:44:46
|
Revision: 153 http://svn.sourceforge.net/pzfilereader/?rev=153&view=rev Author: benoitx Date: 2006-10-31 03:44:42 -0800 (Tue, 31 Oct 2006) Log Message: ----------- Added a few examples for the website. Modified Paths: -------------- trunk/src/site/navigation.xml Added Paths: ----------- trunk/src/site/parsing.xml Modified: trunk/src/site/navigation.xml =================================================================== --- trunk/src/site/navigation.xml 2006-10-31 11:24:43 UTC (rev 152) +++ trunk/src/site/navigation.xml 2006-10-31 11:44:42 UTC (rev 153) @@ -13,6 +13,8 @@ href="multiproject/pzfilereader/index.html" /> <item name="Documentation" href="documentation/index.html" /> + <item name="Examples" + href="parsing.html" /> <item name="History" href="history.html" /> <item name="Features" Added: trunk/src/site/parsing.xml =================================================================== --- trunk/src/site/parsing.xml (rev 0) +++ trunk/src/site/parsing.xml 2006-10-31 11:44:42 UTC (rev 153) @@ -0,0 +1,114 @@ +<document> + <properties> + <title>Parsing Examples</title> + </properties> + <head> + <meta name="description" + content="PZFileReader offers configurable flat file CSV and fixed length parser, released under the business-friendly Apache 2.0 license." + /> + + <meta name="keywords" content="CSV, Fixed length file parser" /> + <meta name="Subject" content="Date Calculators" /> + <meta name="Copyright" content="ObjectLab Financial Ltd" /> + <meta name="Language" content="English" /> + <meta name="Designer" content="ObjectLab Financial Ltd" /> + <meta name="Distribution" content="Global" /> + <meta name="robots" content="ALL"/> + <meta name="Revisit-After" content="20 Days" /> + </head> + <body> + <!-- The body of the document contains a number of sections --> + <section name="Parsing Examples"> + + <p>We thought that a few explicit examples would be good...The idea is to make our parsing extremely robust and flexible.</p> + + <subsection name="Delimiter Parsing"> + <p>Our library is very flexible and lets you define both the delimiter character and the qualifier. The qualifier is character that <strong>may</strong> + surround your element. Typically this would be a " in Excel, but Excel may <strong>not</strong> surround every element with it. Here are some examples:</p> + + <table> + <tr><th>Delimiter</th><th>Qualifier</th><th>Input</th><th>Output</th></tr> + <tr> + <td>,</td> + <td>"</td> + <td>a,b,c</td> + <td>3 elements: "a" "b" "c"</td> + </tr> + <tr> + <td>,</td> + <td>"</td> + <td>"a,b,c"</td> + <td>1 element: "a,b,c"</td> + </tr> + <tr> + <td>,</td> + <td>"</td> + <td>"a,b","c"</td> + <td>2 elements: "a,b" "c"</td> + </tr> + <tr> + <td>,</td> + <td>"</td> + <td> a,b,c</td> + <td>3 elements: "a" "b" "c"</td> + </tr> + <tr> + <td>,</td> + <td>"</td> + <td>a",b,c"</td> + <td>1 element: a",b,c"</td> + </tr> + <tr> + <td>,</td> + <td>"</td> + <td>"test1",test2,"0.00","another, element here",lastone</td> + <td>5 elements: "test1" "test2" "0.00" "another, element here" "lastone"</td> + </tr> + + <tr> + <td>,</td> + <td>'</td> + <td>a,b,c</td> + <td>3 elements: "a" "b" "c"</td> + </tr> + <tr> + <td>,</td> + <td>'</td> + <td>"a,b,c"</td> + <td>3 elements: ""a" "b" "c""</td> + </tr> + <tr> + <td>,</td> + <td>'</td> + <td>"a,b","c"</td> + <td>2 elements: ""a,b"" ""c""</td> + </tr> + <tr> + <td>,</td> + <td>'</td> + <td> a,b,c</td> + <td>3 elements: "a" "b" "c"</td> + </tr> + <tr> + <td>,</td> + <td>'</td> + <td>a",b,c"</td> + <td>3 elements: "a"" "b" "c""</td> + </tr> + <tr> + <td>,</td> + <td>'</td> + <td>"test1",test2,"0.00","another, element here",lastone</td> + <td>6 elements: ""test1"" "test2" ""0.00"" ""another" "element here\"" "lastone"</td> + </tr> + </table> + + </subsection> + + <subsection name="Fixed Width Parsing"> + </subsection> + + </section> + + </body> +</document> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-10-31 11:24:50
|
Revision: 152 http://svn.sourceforge.net/pzfilereader/?rev=152&view=rev Author: zepernick Date: 2006-10-31 03:24:43 -0800 (Tue, 31 Oct 2006) Log Message: ----------- first fixed width test Added Paths: ----------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/FixedWidthParserUtilsTest.java Added: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/FixedWidthParserUtilsTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/FixedWidthParserUtilsTest.java (rev 0) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/FixedWidthParserUtilsTest.java 2006-10-31 11:24:43 UTC (rev 152) @@ -0,0 +1,70 @@ +package net.sf.pzfilereader.parserutils; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import net.sf.pzfilereader.structure.ColumnMetaData; +import net.sf.pzfilereader.util.FixedWidthParserUtils; +import net.sf.pzfilereader.util.ParserUtils; + +/** + * Test the functionality of a fixed width parse + * + * @author Paul Zepernick + */ +public class FixedWidthParserUtilsTest extends TestCase{ + + + /** + * Test fixed width text + * + */ + public void testFixedParse(){ + check (new String[] {"test","test","test"}, new int[] {5,10,20}, + new String[] {"test","test","test"}); + + check (new String[] {"test with some space","test","test"}, new int[] {300,10,20}, + new String[] {"test with some space","test","test"}); + } + + + private void check (String[] columnData, int[] lengths, String[] expected){ + final List columnMetaData = new ArrayList(); + + assertEquals("data and col lengths different size...", columnData.length, + lengths.length); + + for (int i = 0; i < lengths.length; i ++){ + final ColumnMetaData cmd = new ColumnMetaData(); + cmd.setColLength(lengths[i]); + columnMetaData.add(cmd); + } + + StringBuffer lineToParse = new StringBuffer(); + for (int i = 0; i < columnData.length; i ++){ + // padd each column + lineToParse.append(columnData[i]).append(ParserUtils. + padding(lengths[i] - columnData[i].length(),' ')); + } + + List splitResult = FixedWidthParserUtils.splitFixedText(columnMetaData, + lineToParse.toString()); + + + //compare the parse results to the expected results + assertEquals("did not return correct number of cols...", expected.length, + splitResult.size()); + + for (int i = 0; i < expected.length; i ++){ + assertEquals("col values don't match...", expected[i], + (String)splitResult.get(i)); + } + + } + + public static void main(final String[] args) { + junit.textui.TestRunner.run(FixedWidthParserUtilsTest.class); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-30 16:46:45
|
Revision: 151 http://svn.sourceforge.net/pzfilereader/?rev=151&view=rev Author: benoitx Date: 2006-10-30 08:46:27 -0800 (Mon, 30 Oct 2006) Log Message: ----------- first cut at reg expressions... Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/RegExParser.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/RegExParserTest.java Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/RegExParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/RegExParser.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/RegExParser.java 2006-10-30 16:46:27 UTC (rev 151) @@ -0,0 +1,114 @@ +/** + * + */ +package net.sf.pzfilereader.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author xhensevb + * + */ +public class RegExParser { + + // /////////////////////////// + /** + * The rather involved pattern used to match CSV's consists of three + * alternations: the first matches aquoted field, the second unquoted, the + * third a null field. + */ + public static final String CSV_PATTERN = "\"(.*?)\",|(\\w+),|\"(.*?)\"|(\\w+),|,"; + public static final String ORIGINAL_CSV_PATTERN = "\"([^\"]+?)\",?|([^,]+),?|,"; + + // public static final String CSV_PATTERN = "\"([^\"]+?)\",?|([^,]+),?|,"; + +// private static Pattern csvRE = Pattern.compile(CSV_PATTERN); + + public static List splitLine(String line, final char delimiter, char qualifier) { + StringBuilder patternBuilder = new StringBuilder(); + + if (qualifier == 0) { + qualifier = '\"'; + } + + String qualif = escapeIfRequired(qualifier); + String delim = escapeIfRequired(delimiter); + + // first Pattern + if (qualifier != 0) { + patternBuilder.append(qualif); + } + patternBuilder.append("(.*?)"); + if (qualifier != 0) { + patternBuilder.append(qualif); + } + patternBuilder.append(delim); + + // second Pattern + patternBuilder.append("|(\\w+)"); + patternBuilder.append(delim); + + // Third Pattern + patternBuilder.append("|"); + if (qualifier != 0) { + patternBuilder.append(qualif); + } + patternBuilder.append("(.*?)"); + if (qualifier != 0) { + patternBuilder.append(qualif); + } + patternBuilder.append("|(\\w+)"); + patternBuilder.append(delim); + + // Fourth Pattern + patternBuilder.append("|").append(delim); + + String pat = patternBuilder.toString(); + + System.out.println(pat); + + Pattern pattern = Pattern.compile(pat); + + return parse(pattern, line, String.valueOf(delimiter), String.valueOf(qualifier)); + } + + private static String escapeIfRequired(final char c) { + if (c == 0) { + return ""; + } + if ("([{\\^-$|]})?*+.\"\'".indexOf(c) >= 0) { + return "\\" + c; + } + return String.valueOf(c); + } + + /** + * Parse one line. + * + * @return List of Strings, minus their double quotes + */ + public static List parse(Pattern pattern, String line, String delimiter, String qualifier) { + List list = new ArrayList(); + Matcher m = pattern.matcher(line); + // For each field + while (m.find()) { + String match = m.group(); + if (match == null) + break; + if (match.endsWith(delimiter)) { // trim trailing , + match = match.substring(0, match.length() - 1); + } + if (match.startsWith(qualifier)) { // assume also ends with + match = match.substring(1, match.length() - 1); + } + if (match.length() == 0) + match = null; + list.add(match); + } + return list; + } + +} Added: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/RegExParserTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/RegExParserTest.java (rev 0) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/RegExParserTest.java 2006-10-30 16:46:27 UTC (rev 151) @@ -0,0 +1,144 @@ +package net.sf.pzfilereader.parserutils; + +import java.util.List; + +import junit.framework.TestCase; +import net.sf.pzfilereader.util.ParserUtils; +import net.sf.pzfilereader.util.RegExParser; +import net.sf.pzfilereader.utilities.UnitTestUtils; + +/** + * Test the functionality of the splitLine method. This method returns a List of + * Strings. Each element of the list represents a column created by the parser + * from the delimited String. + * + * @author Paul Zepernick + */ +public class RegExParserTest extends TestCase { + private static final String[] DELIMITED_DATA_NO_BREAKS = { "Column 1", "Column 2", "Column 3", "Column 4", "Column 5" }; + + private static final String[] DELIMITED_DATA_WITH_BREAKS = { "Column 1 \r\n\r\n Test After Break \r\n Another Break", + "Column 2", "Column 3 \r\n\r\n Test After Break", "Column 4", "Column 5 \r\n\r\n Test After Break\r\n Another Break" }; + + // TODO think of a situation that actually breaks the parse. This still + // works because of the way it is coded + // to handle the excel CSV. Excel CSV has some elements qualified and others + // not + private static final String DELIMITED_BAD_DATA = "\"column 1\",\"column 2 ,\"column3\""; + + // 0 = delimiter + // 1 = qualifier + private static final char[][] DELIM_QUAL_PAIR = { { ',', '\"' }, { '\t', '\"' }, { '|', '\"' }, { '_', '\"' }, { ',', 0 }, + { '|', 0 }, { '\t', 0 } }; + + /** + * Test without any line breaks + * + */ + public void testNoLineBreaks() { + // loop down all delimiter qualifier pairs to test + for (int i = 0; i < DELIM_QUAL_PAIR.length; i++) { + final char d = DELIM_QUAL_PAIR[i][0]; + final char q = DELIM_QUAL_PAIR[i][1]; + + final String txtToParse = UnitTestUtils.buildDelimString(DELIMITED_DATA_NO_BREAKS, d, q); + + final List splitLineResults = RegExParser.splitLine(txtToParse, d, q); + + // check to make sure we have the same amount of elements which were + // expected + assertEquals("Expected size (d = [" + d + "] q = [" + (q != 0 ? String.valueOf(q) : "") + "] txt [" + txtToParse + + "])", DELIMITED_DATA_NO_BREAKS.length, splitLineResults.size()); + + // loop through each value and compare what came back + for (int j = 0; j < DELIMITED_DATA_NO_BREAKS.length; j++) { + assertEquals("Data Element Value Does Not Match (d = [" + d + "] q = [" + q + "] txt [" + txtToParse + "])", + DELIMITED_DATA_NO_BREAKS[j], (String) splitLineResults.get(j)); + } + } + + } + + /** + * Test with any line breaks + * + */ + public void testLineBreaks() { + // loop down all delimiter qualifier pairs to test + for (int i = 0; i < DELIM_QUAL_PAIR.length; i++) { + final char d = DELIM_QUAL_PAIR[i][0]; + final char q = DELIM_QUAL_PAIR[i][1]; + + final String txtToParse = UnitTestUtils.buildDelimString(DELIMITED_DATA_WITH_BREAKS, d, q); + + final List splitLineResults = RegExParser.splitLine(txtToParse, d, q); + + // check to make sure we have the same amount of elements which were + // expected + assertEquals("Did Not Get Amount Of Elements Expected (d = " + d + " q = " + q + ")", + DELIMITED_DATA_WITH_BREAKS.length, splitLineResults.size()); + + // loop through each value and compare what came back + for (int j = 0; j < DELIMITED_DATA_WITH_BREAKS.length; j++) { + assertEquals("Data Element Value Does Not Match (d = " + d + " q = " + q + ")", DELIMITED_DATA_WITH_BREAKS[j], + (String) splitLineResults.get(j)); + } + } + } + + /** + * Test to make sure we get the correct amount of elements for malformed + * data + */ + public void testMalformedData() { + final List splitLineResults = ParserUtils.splitLine(DELIMITED_BAD_DATA, ',', '\"'); + + assertEquals("Expecting 2 Data Elements From The Malformed Data", 2, splitLineResults.size()); + } + + /** + * Test some extreme cases + */ + public void testSomeExtremeCases() { + check("\"a,b,c\"", ',', '\"', new String[] { "a,b,c" }); + check("\"a,b\",\"c\"", ',', '\"', new String[] { "a,b", "c" }); + check("a,b,c", ',', '\"', new String[] { "a", "b", "c" }); + check(" a,b,c", ',', '\"', new String[] { "a", "b", "c" }); + check(" a,b,c", ',', '\"', new String[] { "a", "b", "c" }); + + // what would you expect of these ones? + + // +++++The parser allows qualified and unqualified elements to be + // contained + // on the same line. so it should break the elements down like so + // 1 = a" -->" is part of the data since the element did not start with + // a qualifier + // 2 = b + // 3 = c" --> same as #1 + check("a\",b,c\"", ',', '\"', new String[] { "a\"", "b", "c\"" }); + + check("\" a,b,c\"", ',', '\"', new String[] { "a,b,c" }); + // check(" a, b ,c ", ',', '\"', new String[] { "a","b","c" }); + // ++++++I think this should probably generate this + check(" a, b ,c ", ',', '\"', new String[] { "a, b ,c" }); + + // Paul... please put some more whacky stuff here... + + } + + private void check(final String txtToParse, final char delim, final char qualifier, final String[] expected) { + final List splitLineResults = ParserUtils.splitLine(txtToParse, delim, qualifier); + + assertEquals( + "Did Not Get Amount Of Elements Expected (d = " + delim + " q = " + qualifier + ") txt [" + txtToParse + "]", + expected.length, splitLineResults.size()); + + for (int i = 0; i < expected.length; i++) { + assertEquals("expecting...", expected[i], splitLineResults.get(i)); + } + } + + public static void main(final String[] args) { + junit.textui.TestRunner.run(RegExParserTest.class); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-10-30 15:57:07
|
Revision: 150 http://svn.sourceforge.net/pzfilereader/?rev=150&view=rev Author: zepernick Date: 2006-10-30 07:57:00 -0800 (Mon, 30 Oct 2006) Log Message: ----------- added a couple more tests Modified Paths: -------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-30 12:20:35 UTC (rev 149) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-30 15:57:00 UTC (rev 150) @@ -123,7 +123,9 @@ //TODO - I believe this should be producing 2 elements. As soon as their is a //delimter followed by a qualifier a new element shoudl be created //+++Any thoughts Benoit? - check("\"a, b,\"c\"", ',', '\"', new String[] {"a, b", "c"}); + check("\"a, b,\"c\"", ',', '\"', new String[] {"a, b,\"c"}); + check("\"\",,,,\"last one\"", ',', '\"', new String[] {"","","","","last one"}); + check("\"first\",\"second\",", ',', '\"', new String[] {"first","second",""}); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-10-30 12:20:42
|
Revision: 149 http://svn.sourceforge.net/pzfilereader/?rev=149&view=rev Author: zepernick Date: 2006-10-30 04:20:35 -0800 (Mon, 30 Oct 2006) Log Message: ----------- added 2 more extreme tests. Possible bug on the last test. Needs more discussion. Modified Paths: -------------- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java Modified: trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java =================================================================== --- trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-30 12:05:55 UTC (rev 148) +++ trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java 2006-10-30 12:20:35 UTC (rev 149) @@ -113,15 +113,17 @@ //2 = b //3 = c" --> same as #1 check("a\",b,c\"", ',', '\"', new String[] { "a\"", "b", "c\"" }); - - - - check("\" a,b,c\"", ',', '\"', new String[] { "a,b,c" }); - //check(" a, b ,c ", ',', '\"', new String[] { "a","b","c" }); - //++++++I think this should probably generate this - check(" a, b ,c ", ',', '\"', new String[] { "a, b ,c" }); + //should not trim leading space inside of a qualified element + check("\" a,b,c\"", ',', '\"', new String[] { " a,b,c" }); + check(" a, b ,c ", ',', '\"', new String[] { "a","b","c" }); // Paul... please put some more whacky stuff here... + check("\"a\", b , \"c\"", ',', '\"', new String[] {"a","b","c"}); + //check malformed data + //TODO - I believe this should be producing 2 elements. As soon as their is a + //delimter followed by a qualifier a new element shoudl be created + //+++Any thoughts Benoit? + check("\"a, b,\"c\"", ',', '\"', new String[] {"a, b", "c"}); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-30 12:06:22
|
Revision: 148 http://svn.sourceforge.net/pzfilereader/?rev=148&view=rev Author: benoitx Date: 2006-10-30 04:05:55 -0800 (Mon, 30 Oct 2006) Log Message: ----------- removed code that was commented out since the new code is now the accepted version. Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-10-30 11:57:30 UTC (rev 147) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-10-30 12:05:55 UTC (rev 148) @@ -1,16 +1,16 @@ /* Copyright 2006 Paul Zepernick - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software distributed - under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. See the License for - the specific language governing permissions and limitations under the License. + Unless required by applicable law or agreed to in writing, software distributed + under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. See the License for + the specific language governing permissions and limitations under the License. */ package net.sf.pzfilereader.util; @@ -60,9 +60,9 @@ * empty. There should not be any line breaks in the string. Each line of * the file should be passed in individually. * Elements which are not qualified will have leading and trailing white - * space removed. This includes unqualified elements, which may be + * space removed. This includes unqualified elements, which may be * contained in an unqualified parse: "data", data ,"data" - * + * * @param line - * String of data to be parsed * @param delimiter - @@ -73,7 +73,6 @@ */ public static List splitLine(String line, final char delimiter, final char qualifier) { final ArrayList list = new ArrayList(); - // String temp = ""; boolean beginQualifier = false; // this will be used for delimted files that have some items qualified // and some items dont @@ -87,7 +86,6 @@ // line which has not yet been read // check to see if there is a text qualifier final char currentChar = line.charAt(i); - // final String currentString = String.valueOf(currentChar); if (qualifier > 0) { if (currentChar == qualifier && !beginQualifier && !beginNoQualifier) { // begining of a set of data @@ -96,12 +94,10 @@ && lTrim(remainderOfLine).charAt(0) != qualifier) { // try to account for empty space before qualifier starts // we have not yet begun a qualifier and the char we are on - // is NOT - // a qualifier. Start reading data + // is NOT a qualifier. Start reading data beginNoQualifier = true; // make sure that this is not just an empty column with no - // qualifiers. ie - // "data",,"data" + // qualifiers. ie "data",,"data" if (currentChar == delimiter) { list.add(sb.toString()); sb.delete(0, sb.length()); @@ -119,8 +115,7 @@ sb.delete(0, sb.length()); beginQualifier = false; // add to "i" so we can get past the qualifier, otherwise it - // is read into a set - // of data which + // is read into a set of data which // may not be qualified. Find out how many spaces to the // delimiter final int offset = getDelimiterOffset(line, i, delimiter) - 1; @@ -133,9 +128,9 @@ } } else if (beginNoQualifier && currentChar == delimiter) { // check to see if we are done with an element that was not - // being qulified - //remove the space from the front and back of unqualified - //elements + // being qualified + // remove the space from the front and back of unqualified + // elements list.add(lTrim(sb.toString().trim())); sb.delete(0, sb.length()); beginNoQualifier = false; @@ -148,7 +143,7 @@ } else { // not using a qualifier. Using a delimiter only if (currentChar == delimiter) { - //remove the space from the front and back of unqualified + //remove the space from the front and back of unqualified //elements list.add(lTrim(sb.toString().trim())); sb.delete(0, sb.length()); @@ -193,42 +188,23 @@ /** * reads from the specified point in the line and returns how many chars to * the specified delimter - * + * * @param line * @param start * @param delimiter * @return int */ - public static int getDelimiterOffset(final String line, final int start, final char delimiter) { int idx = line.indexOf(delimiter, start); if (idx >= 0) { - // idx++; - // idx-=start; idx -= start - 1; } return idx; - - // int offset = 0; - // for (int i = start; i < line.length(); i++) { - // offset++; - // if (line.substring(i, i + 1).equals(delimiter)) { - // if (offset != idx) { - // System.out.println("String [" + line + "] start:" + start + "(" + - // line.charAt(start) + ") delim [" - // + delimiter + "] length:" + delimiter.length() + " Old:" + offset + " - // new:" + idx); - // } - // - // return offset; - // } - // } - // return -1; } /** * Removes empty space from the begining of a string - * + * * @param value - * to be trimmed * @return String @@ -246,27 +222,11 @@ } return trimmed; - // - // - // final StringBuffer returnVal = new StringBuffer(); - // boolean gotAChar = false; - // - // for (int i = 0; i < value.length(); i++) { - // if (value.substring(i, i + 1).trim().length() == 0 && !gotAChar) { - // continue; - // } else { - // gotAChar = true; - // returnVal.append(value.substring(i, i + 1)); - // } - // } - // - // return returnVal.toString(); - // } /** * Removes empty space from the begining of a string, except for tabs - * + * * @param value - * to be trimmed * @return String @@ -284,26 +244,11 @@ } return trimmed; - // final StringBuffer returnVal = new StringBuffer(); - // boolean gotAChar = false; - // - // for (int i = 0; i < value.length(); i++) { - // if (!value.substring(i, i + 1).equals("\t") && value.substring(i, i + - // 1).trim().length() == 0 && !gotAChar) { - // continue; - // } else { - // gotAChar = true; - // returnVal.append(value.substring(i, i + 1)); - // } - // } - // - // return returnVal.toString(); - } /** * Removes a single string character from a given string - * + * * @param character - * string char * @param theString - @@ -320,23 +265,13 @@ } return s.toString(); - // final StringBuffer s = new StringBuffer(); - // for (int i = 0; i < theString.length(); i++) { - // if (theString.substring(i, i + 1).equalsIgnoreCase(character)) { - // continue; - // } - // s.append(theString.substring(i, i + 1)); - // } - // - // return s.toString(); - } /** * Returns a list of ColumnMetaData objects. This is for use with delimited * files. The first line of the file which contains data will be used as the * column names - * + * * @param theStream * @param delimiter * @param qualifier @@ -357,8 +292,6 @@ try { isr = new InputStreamReader(theStream); br = new BufferedReader(isr); - // fr = new FileReader(theFile); - // br = new BufferedReader(fr); while ((line = br.readLine()) != null) { if (line.trim().length() == 0) { @@ -395,7 +328,7 @@ * Returns a list of ColumnMetaData objects. This is for use with delimited * files. The first line of the file which contains data will be used as the * column names - * + * * @param line * @param delimiter * @param qualifier @@ -424,7 +357,7 @@ * Returns a list of ColumnMetaData objects. This is for use with delimited * files. The first line of the file which contains data will be used as the * column names - * + * * @param theFile * @param delimiter * @param qualifier @@ -490,7 +423,7 @@ /** * Determines if the given line is the first part of a multiline record - * + * * @param chrArry - * char data of the line * @param delimiter - @@ -506,7 +439,7 @@ /** * Determines if the given line is the first part of a multiline record - * + * * @param chrArry - * char data of the line * @param delimiter - @@ -531,8 +464,7 @@ continue; } else { // not a space, if this char is the delimiter, then we - // have a line break - // in the record + // have a line break in the record if (chrArry[i] == delimiter) { return true; } @@ -541,9 +473,8 @@ } } 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. start a - // new loop here in case there is + // have moved on to a new element and this could not be multiline. + // start a new loop here in case there is // space between the delimiter and qualifier for (int j = i - 1; j >= 0; j--) { if (chrArry[j] == ' ') { @@ -585,7 +516,7 @@ /** * Returns a map with the MD id's and their record lengths. This is used for * fixed length parsing - * + * * @param columnMD * @return Map */ @@ -618,13 +549,13 @@ /** * Returns the key to the list of ColumnMetaData objects. Returns the * correct MetaData per the mapping file and the data contained on the line - * - * + * + * * @param columnMD * @param line * @return List - ColumMetaData * @deprecated Moved to FixedWidthParserUtils.getCMDKey() - * + * */ public static String getCMDKeyForFixedLengthFile(final Map columnMD, final String line) { if (columnMD.size() == 1) { @@ -666,8 +597,8 @@ /** * Returns the key to the list of ColumnMetaData objects. Returns the * correct MetaData per the mapping file and the data contained on the line - * - * + * + * * @param columnMD * @param lineElements * @return List - ColumMetaData @@ -707,7 +638,7 @@ /** * Returns a list of ColumMetaData objects for the given key - * + * * @param key * @param columnMD * @return List @@ -722,7 +653,7 @@ /** * Use this method to find the index of a column. - * + * * @author Benoit Xhenseval * @param key * @param columnMD @@ -753,7 +684,7 @@ /** * Create an InputStream based on a File. - * + * * @param file * The file. * @return the InputStream. @@ -763,22 +694,14 @@ if (file == null) { throw new IllegalArgumentException("null not allowed"); } - // if (!file.exists()) { - // throw new FileNotFoundException("file does not exist " + - // file.getAbsolutePath()); - // } - // if (!file.canRead()) { - // throw new FileNotFoundException("file cannot be read " + - // file.getAbsolutePath()); - // } return new FileInputStream(file); } /** * Closes the given reader - * + * * @param reader - * + * */ public static void closeReader(final Reader reader) { try { @@ -789,9 +712,9 @@ /** * Closes the given reader - * + * * @param reader - * + * */ public static void closeReader(final InputStream reader) { try { @@ -804,13 +727,13 @@ * <p> * Returns padding using the specified delimiter repeated to a given length. * </p> - * + * * <pre> * StringUtils.padding(0, 'e') = "" * StringUtils.padding(3, 'e') = "eee" * StringUtils.padding(-2, 'e') = IndexOutOfBoundsException * </pre> - * + * * <p> * Note: this method doesn't not support padding with <a * href="http://www.unicode.org/glossary/#supplementary_character">Unicode @@ -818,7 +741,7 @@ * to be represented. If you are needing to support full I18N of your * applications consider using {@link #repeat(String, int)} instead. * </p> - * + * * @param repeat * number of times to repeat delim * @param padChar @@ -841,7 +764,7 @@ /** * Build a map of name/position based on a list of ColumnMetaData. - * + * * @author Benoit Xhenseval * @param columns * @return a new Map @@ -853,8 +776,6 @@ int idx = 0; for (final Iterator it = columns.iterator(); it.hasNext(); idx++) { final ColumnMetaData meta = (ColumnMetaData) it.next(); - // map.put(meta.getColName(), Integer.valueOf(idx)); breaks 1.4 - // compile map.put(meta.getColName(), new Integer(idx)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-30 11:58:10
|
Revision: 147 http://svn.sourceforge.net/pzfilereader/?rev=147&view=rev Author: benoitx Date: 2006-10-30 03:57:30 -0800 (Mon, 30 Oct 2006) Log Message: ----------- Just to keep note. Added Paths: ----------- trunk/src/notes/ trunk/src/notes/how-to-digg.txt Added: trunk/src/notes/how-to-digg.txt =================================================================== --- trunk/src/notes/how-to-digg.txt (rev 0) +++ trunk/src/notes/how-to-digg.txt 2006-10-30 11:57:30 UTC (rev 147) @@ -0,0 +1,11 @@ +http://digg.com/submit?phase=2&url=www.UniqueURL.com&title=StoryTitle&bodytext=StoryDescription&topic=YourSelectedTopic + +http://digg.com/submit?phase=2&url=objectlabkit.sourceforge.net&title=ObjectLab%20Kit%3A%20Open%20Source%20Date%20Calculators%20for%20Business%20and%20Finance&bodytext=ObjectLab%20released%20version%201%2E0%2E1%20of%20ObjectLab%20Kit%20for%20Java%201%2E5,%20available%20for%20download%20via%20SourceForge%20or%20the%20Maven%20Central%20Repository%2E%20The%20Kit%20provides%20a%20Date%20Calculator%20that%20handle%20holidays,%20a%20IMM%20Date%20and%20Period%20Count%20Calculator%20and%20comes%20in%20two%20versions%3A%20one%20based%20on%20pure%20JDK%20(1%2E5)%20and%20one%20based%20on%20the%20Joda-time%20library%20(1%2E3%2B,%20JDK%201%2E5)%2E&topic=programming + +title +ObjectLab Kit: Open Source Date Calculators for Business and Finance + +bodytext +ObjectLab has announced the release of version 1.0.1 of ObjectLab Kit for Java 1.5, available for download via SourceForge or the Maven Central Repository. The Kit provides Date Calculators and comes in two versions: one based on pure JDK (1.5) and one based on the Joda-time library (1.3+, JDK 1.5). +ObjectLab released version 1.0.1 of ObjectLab Kit for Java 1.5, available for download via SourceForge or the Maven Central Repository. The Kit provides a Date Calculator that handle holidays, a IMM Date and Period Count Calculator and comes in two versions: one based on pure JDK (1.5) and one based on the Joda-time library (1.3+, JDK 1.5). +ObjectLab released version 1.0.1 of ObjectLab Kit for Java 1.5, available for download via SourceForge or the Maven Central Repository. The Kit provides a Date Calculator that handle holidays, a IMM Date and Period Count Calculator and comes in two versions: one based on pure JDK (1.5) and one based on the Joda-time library (1.3+, JDK 1.5). \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-10-30 11:57:00
|
Revision: 146 http://svn.sourceforge.net/pzfilereader/?rev=146&view=rev Author: zepernick Date: 2006-10-30 03:56:56 -0800 (Mon, 30 Oct 2006) Log Message: ----------- documented addition to splitLine Modified Paths: -------------- trunk/src/site/changes.xml Modified: trunk/src/site/changes.xml =================================================================== --- trunk/src/site/changes.xml 2006-10-30 11:55:25 UTC (rev 145) +++ trunk/src/site/changes.xml 2006-10-30 11:56:56 UTC (rev 146) @@ -8,6 +8,7 @@ </properties> <body> <release version="2.3.0" date="in svn" description="Move to Maven and Subversion"> + <action dev="zepernick" type="add">Unqualified elements have leading and trailing whitespace removed in a delimited parse</action> <action dev="zepernick" type="add">Ability to issue an OrderBy On DataSet's containing record mapping elements</action> <action dev="benoitx" type="add">Move build to Maven 1.1.x and generate the entire website from the build.</action> <action dev="benoitx" type="fix">Modify code following warning by Findbugs, checkstyle and PMD.</action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-10-30 11:55:32
|
Revision: 145 http://svn.sourceforge.net/pzfilereader/?rev=145&view=rev Author: zepernick Date: 2006-10-30 03:55:25 -0800 (Mon, 30 Oct 2006) Log Message: ----------- added to javadoc description for splitLine Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-10-30 11:51:24 UTC (rev 144) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-10-30 11:55:25 UTC (rev 145) @@ -59,6 +59,9 @@ * qualifier around the text, the qualifier parameter can be left null, or * empty. There should not be any line breaks in the string. Each line of * the file should be passed in individually. + * Elements which are not qualified will have leading and trailing white + * space removed. This includes unqualified elements, which may be + * contained in an unqualified parse: "data", data ,"data" * * @param line - * String of data to be parsed This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-10-30 11:51:29
|
Revision: 144 http://svn.sourceforge.net/pzfilereader/?rev=144&view=rev Author: zepernick Date: 2006-10-30 03:51:24 -0800 (Mon, 30 Oct 2006) Log Message: ----------- Trim left and right space for unqualified elements. Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-10-27 14:14:36 UTC (rev 143) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-10-30 11:51:24 UTC (rev 144) @@ -131,7 +131,9 @@ } else if (beginNoQualifier && currentChar == delimiter) { // check to see if we are done with an element that was not // being qulified - list.add(sb.toString()); + //remove the space from the front and back of unqualified + //elements + list.add(lTrim(sb.toString().trim())); sb.delete(0, sb.length()); beginNoQualifier = false; } else if (beginNoQualifier || beginQualifier) { @@ -143,7 +145,9 @@ } else { // not using a qualifier. Using a delimiter only if (currentChar == delimiter) { - list.add(sb.toString()); + //remove the space from the front and back of unqualified + //elements + list.add(lTrim(sb.toString().trim())); sb.delete(0, sb.length()); } else { sb.append(currentChar); @@ -173,7 +177,7 @@ // check to see if we need to add the last column in..this will // happen on empty columns // add the last column - list.add(sb.toString()); + list.add(beginNoQualifier ? lTrim(sb.toString().trim()) : sb.toString()); } sb = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-27 14:14:51
|
Revision: 143 http://svn.sourceforge.net/pzfilereader/?rev=143&view=rev Author: benoitx Date: 2006-10-27 07:14:36 -0700 (Fri, 27 Oct 2006) Log Message: ----------- General clean Up by Eclipse (cleanup, organise imports and format). Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBDelimiterPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBFixedLengthPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultPZParserFactory.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DelimiterPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/FixedLengthPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/InitialisationException.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/ordering/OrderBy.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/structure/Row.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/FixedWidthParserUtils.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/PZConstants.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/PZMapParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/XMLRecordElement.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java 2006-10-27 14:14:36 UTC (rev 143) @@ -1,5 +1,34 @@ -/** +/* + * ObjectLab, http://www.objectlab.co.uk/open is supporting PZFileReader. * + * Based in London, we are world leaders in the design and development + * of bespoke applications for the securities financing markets. + * + * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> + * ___ _ _ _ _ _ + * / _ \| |__ (_) ___ ___| |_| | __ _| |__ + * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ + * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | + * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ + * |__/ + * + * www.ObjectLab.co.uk + * + * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ + * + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package net.sf.pzfilereader; @@ -26,22 +55,24 @@ private boolean ignoreFirstRecord = false; - public AbstractDelimiterPZParser(InputStream dataSourceStream, String dataDefinition, char delimiter, char qualifier, - boolean ignoreFirstRecord) { + public AbstractDelimiterPZParser(final InputStream dataSourceStream, final String dataDefinition, final char delimiter, + final char qualifier, final boolean ignoreFirstRecord) { super(dataSourceStream, dataDefinition); this.delimiter = delimiter; this.qualifier = qualifier; this.ignoreFirstRecord = ignoreFirstRecord; } - public AbstractDelimiterPZParser(File dataSource, char delimiter, char qualifier, boolean ignoreFirstRecord) { + public AbstractDelimiterPZParser(final File dataSource, final char delimiter, final char qualifier, + final boolean ignoreFirstRecord) { super(dataSource); this.delimiter = delimiter; this.qualifier = qualifier; this.ignoreFirstRecord = ignoreFirstRecord; } - public AbstractDelimiterPZParser(InputStream dataSourceStream, char delimiter, char qualifier, boolean ignoreFirstRecord) { + public AbstractDelimiterPZParser(final InputStream dataSourceStream, final char delimiter, final char qualifier, + final boolean ignoreFirstRecord) { super(dataSourceStream); this.delimiter = delimiter; this.qualifier = qualifier; @@ -51,13 +82,15 @@ public IDataSet doParse() { try { if (getDataSourceStream() != null) { - return doDelimitedFile(getDataSourceStream(), getDelimiter(), getQualifier(), isIgnoreFirstRecord(), shouldCreateMDFromFile()); + return doDelimitedFile(getDataSourceStream(), getDelimiter(), getQualifier(), isIgnoreFirstRecord(), + shouldCreateMDFromFile()); } else { InputStream stream = null; try { stream = ParserUtils.createInputStream(getDataSource()); - return doDelimitedFile(stream, getDelimiter(), getQualifier(), isIgnoreFirstRecord(), shouldCreateMDFromFile()); - } catch (Exception e) { + return doDelimitedFile(stream, getDelimiter(), getQualifier(), isIgnoreFirstRecord(), + shouldCreateMDFromFile()); + } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { @@ -66,23 +99,23 @@ } } } - } catch (FileNotFoundException e) { + } catch (final FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (Exception e) { + } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } - + protected abstract boolean shouldCreateMDFromFile(); protected char getDelimiter() { return delimiter; } - protected void setDelimiter(char delimiter) { + protected void setDelimiter(final char delimiter) { this.delimiter = delimiter; } @@ -90,7 +123,7 @@ return ignoreFirstRecord; } - protected void setIgnoreFirstRecord(boolean ignoreFirstRecord) { + protected void setIgnoreFirstRecord(final boolean ignoreFirstRecord) { this.ignoreFirstRecord = ignoreFirstRecord; } @@ -98,7 +131,7 @@ return qualifier; } - protected void setQualifier(char qualifier) { + protected void setQualifier(final char qualifier) { this.qualifier = qualifier; } @@ -117,7 +150,7 @@ InputStreamReader isr = null; BufferedReader br = null; - DefaultDataSet ds = new DefaultDataSet(getColumnMD()); + final DefaultDataSet ds = new DefaultDataSet(getColumnMD()); try { // get the total column count // columnCount = columnMD.size(); @@ -136,7 +169,7 @@ while ((line = br.readLine()) != null) { lineCount++; /** empty line skip past it */ - String trimmed = line.trim(); + final String trimmed = line.trim(); if (!processingMultiLine && trimmed.length() == 0) { continue; } @@ -177,7 +210,7 @@ // line break processingMultiLine = false; if (trimmedLineData.length() > 0) { // + would always be - // true surely.... + // true surely.... lineData += "\r\n"; } lineData += line; @@ -185,8 +218,8 @@ // check to see if this is the last line of the record // looking for a qualifier followed by a delimiter if (trimmedLineData.length() > 0) { // + here again, - // this should - // always be true... + // this should + // always be true... lineData += "\r\n"; } lineData += line; Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java 2006-10-27 14:14:36 UTC (rev 143) @@ -1,5 +1,34 @@ -/** +/* + * ObjectLab, http://www.objectlab.co.uk/open is supporting PZFileReader. * + * Based in London, we are world leaders in the design and development + * of bespoke applications for the securities financing markets. + * + * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> + * ___ _ _ _ _ _ + * / _ \| |__ (_) ___ ___| |_| | __ _| |__ + * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ + * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | + * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ + * |__/ + * + * www.ObjectLab.co.uk + * + * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ + * + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package net.sf.pzfilereader; @@ -23,19 +52,19 @@ */ public abstract class AbstractFixedLengthPZParser extends AbstractPZParser { - protected AbstractFixedLengthPZParser(File dataSource, String dataDefinition) { + protected AbstractFixedLengthPZParser(final File dataSource, final String dataDefinition) { super(dataSource, dataDefinition); } - protected AbstractFixedLengthPZParser(File dataSource) { + protected AbstractFixedLengthPZParser(final File dataSource) { super(dataSource); } - protected AbstractFixedLengthPZParser(InputStream dataSourceStream, String dataDefinition) { + protected AbstractFixedLengthPZParser(final InputStream dataSourceStream, final String dataDefinition) { super(dataSourceStream, dataDefinition); } - protected AbstractFixedLengthPZParser(InputStream dataSourceStream) { + protected AbstractFixedLengthPZParser(final InputStream dataSourceStream) { super(dataSourceStream); } @@ -48,7 +77,7 @@ stream = ParserUtils.createInputStream(getDataSource()); try { return doFixedLengthFile(stream); - } catch (Exception e) { + } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { @@ -57,10 +86,10 @@ } } } - } catch (FileNotFoundException e) { + } catch (final FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (Exception e) { + } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } @@ -78,7 +107,7 @@ InputStreamReader isr = null; BufferedReader br = null; - DefaultDataSet ds = new DefaultDataSet(getColumnMD()); + final DefaultDataSet ds = new DefaultDataSet(getColumnMD()); try { final Map recordLengths = ParserUtils.calculateRecordLengths(getColumnMD()); Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractPZParser.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractPZParser.java 2006-10-27 14:14:36 UTC (rev 143) @@ -1,5 +1,34 @@ -/** +/* + * ObjectLab, http://www.objectlab.co.uk/open is supporting PZFileReader. * + * Based in London, we are world leaders in the design and development + * of bespoke applications for the securities financing markets. + * + * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> + * ___ _ _ _ _ _ + * / _ \| |__ (_) ___ ___| |_| | __ _| |__ + * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ + * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | + * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ + * |__/ + * + * www.ObjectLab.co.uk + * + * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ + * + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package net.sf.pzfilereader; @@ -27,20 +56,20 @@ private File dataSource = null; - protected AbstractPZParser(File dataSource) { + protected AbstractPZParser(final File dataSource) { this.dataSource = dataSource; } - protected AbstractPZParser(InputStream dataSourceStream) { + protected AbstractPZParser(final InputStream dataSourceStream) { this.dataSourceStream = dataSourceStream; } - protected AbstractPZParser(File dataSource, String dataDefinition) { + protected AbstractPZParser(final File dataSource, final String dataDefinition) { this.dataSource = dataSource; this.dataDefinition = dataDefinition; } - protected AbstractPZParser(InputStream dataSourceStream, String dataDefinition) { + protected AbstractPZParser(final InputStream dataSourceStream, final String dataDefinition) { this.dataSourceStream = dataSourceStream; this.dataDefinition = dataDefinition; } @@ -59,7 +88,7 @@ * * @see net.sf.pzfilereader.PZParser#setHandlingShortLines(boolean) */ - public void setHandlingShortLines(boolean handleShortLines) { + public void setHandlingShortLines(final boolean handleShortLines) { this.handlingShortLines = handleShortLines; } @@ -89,7 +118,7 @@ return initialised; } - protected void setInitialised(boolean initialised) { + protected void setInitialised(final boolean initialised) { this.initialised = initialised; } @@ -97,7 +126,7 @@ return dataDefinition; } - protected void setDataDefinition(String dataDefinition) { + protected void setDataDefinition(final String dataDefinition) { this.dataDefinition = dataDefinition; } @@ -105,7 +134,7 @@ return dataSource; } - protected void setDataSource(File dataSource) { + protected void setDataSource(final File dataSource) { this.dataSource = dataSource; } @@ -113,7 +142,7 @@ return dataSourceStream; } - protected void setDataSourceStream(InputStream dataSourceStream) { + protected void setDataSourceStream(final InputStream dataSourceStream) { this.dataSourceStream = dataSourceStream; } @@ -133,8 +162,8 @@ * int errorLevel 1,2,3 1=warning 2=error 3= severe error */ protected void addError(final DefaultDataSet ds, final String errorDesc, final int lineNo, final int errorLevel) { - final DataError de = new DataError(errorDesc,lineNo,errorLevel); + final DataError de = new DataError(errorDesc, lineNo, errorLevel); ds.addError(de); } - + } Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBDelimiterPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBDelimiterPZParser.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBDelimiterPZParser.java 2006-10-27 14:14:36 UTC (rev 143) @@ -1,5 +1,34 @@ -/** +/* + * ObjectLab, http://www.objectlab.co.uk/open is supporting PZFileReader. * + * Based in London, we are world leaders in the design and development + * of bespoke applications for the securities financing markets. + * + * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> + * ___ _ _ _ _ _ + * / _ \| |__ (_) ___ ___| |_| | __ _| |__ + * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ + * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | + * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ + * |__/ + * + * www.ObjectLab.co.uk + * + * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ + * + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package net.sf.pzfilereader; @@ -24,8 +53,8 @@ private Connection con; - public DBDelimiterPZParser(Connection con, InputStream dataSourceStream, String dataDefinition, char delimiter, - char qualifier, boolean ignoreFirstRecord) { + public DBDelimiterPZParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition, + final char delimiter, final char qualifier, final boolean ignoreFirstRecord) { super(dataSourceStream, dataDefinition, delimiter, qualifier, ignoreFirstRecord); this.con = con; } @@ -69,10 +98,10 @@ // read in the fixed length file and construct the DataSet object // doFixedLengthFile(dataSourceStream); setInitialised(true); - } catch (SQLException e) { + } catch (final SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (FileNotFoundException e) { + } catch (final FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { @@ -83,17 +112,13 @@ if (stmt != null) { stmt.close(); } - } catch (SQLException e) { + } catch (final SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } - public IDataSet doParse() { - return null; - } - protected boolean shouldCreateMDFromFile() { return true; } Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBFixedLengthPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBFixedLengthPZParser.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBFixedLengthPZParser.java 2006-10-27 14:14:36 UTC (rev 143) @@ -1,5 +1,34 @@ -/** +/* + * ObjectLab, http://www.objectlab.co.uk/open is supporting PZFileReader. * + * Based in London, we are world leaders in the design and development + * of bespoke applications for the securities financing markets. + * + * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> + * ___ _ _ _ _ _ + * / _ \| |__ (_) ___ ___| |_| | __ _| |__ + * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ + * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | + * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ + * |__/ + * + * www.ObjectLab.co.uk + * + * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ + * + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package net.sf.pzfilereader; @@ -30,7 +59,7 @@ this.con = con; } - public DBFixedLengthPZParser(Connection con, File dataSource, String dataDefinition) { + public DBFixedLengthPZParser(final Connection con, final File dataSource, final String dataDefinition) { super(dataSource, dataDefinition); this.con = con; } @@ -74,10 +103,10 @@ // read in the fixed length file and construct the DataSet object // doFixedLengthFile(dataSourceStream); setInitialised(true); - } catch (SQLException e) { + } catch (final SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (FileNotFoundException e) { + } catch (final FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { @@ -88,7 +117,7 @@ if (stmt != null) { stmt.close(); } - } catch (SQLException e) { + } catch (final SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java 2006-10-27 14:14:36 UTC (rev 143) @@ -33,9 +33,7 @@ */ private int errorLevel = 0; - - - public DataError(String errorDesc, int lineNo, int errorLevel) { + public DataError(final String errorDesc, final int lineNo, final int errorLevel) { this.errorDesc = errorDesc; this.lineNo = lineNo; this.errorLevel = errorLevel; @@ -43,7 +41,7 @@ /** * @deprecated should use the ctor with fields - * + * */ public DataError() { } @@ -80,7 +78,7 @@ * * @param errorDesc * The errorDesc to set - * @deprecated the DataError should be immutable (i.e. no Set method) + * @deprecated the DataError should be immutable (i.e. no Set method) */ public void setErrorDesc(final String errorDesc) { this.errorDesc = errorDesc; @@ -91,7 +89,7 @@ * * @param errorLevel * The errorLevel to set - * @deprecated the DataError should be immutable (i.e. no Set method) + * @deprecated the DataError should be immutable (i.e. no Set method) */ public void setErrorLevel(final int errorLevel) { this.errorLevel = errorLevel; @@ -102,7 +100,7 @@ * * @param lineNo * The lineNo to set - * @deprecated the DataError should be immutable (i.e. no Set method) + * @deprecated the DataError should be immutable (i.e. no Set method) */ public void setLineNo(final int lineNo) { this.lineNo = lineNo; Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java 2006-10-27 14:14:36 UTC (rev 143) @@ -31,7 +31,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.NoSuchElementException; import net.sf.pzfilereader.ordering.OrderBy; import net.sf.pzfilereader.structure.ColumnMetaData; @@ -391,7 +390,6 @@ .charAt(0) : 0, ignoreFirstRecord, handleShortLines); } - /** * Constructs a new DataSet using the PZMAP XML file layout method. This is * used for a DELIMITED text file. esacpe sequence reference: \n newline @@ -421,7 +419,7 @@ this(ParserUtils.createInputStream(pzmapXML), ParserUtils.createInputStream(dataSource), delimiter, qualifier, ignoreFirstRecord, handleShortLines); } - + /** * New constructor based on InputStream. Constructs a new DataSet using the * PZMAP XML file layout method. This is used for a DELIMITED text file. @@ -677,7 +675,7 @@ } } - //int recPosition = 1; + // int recPosition = 1; final Row row = new Row(); row.setMdkey(mdkey.equals(PZConstants.DETAIL_ID) ? null : mdkey); // try @@ -685,12 +683,13 @@ row.addColumn(FixedWidthParserUtils.splitFixedText(cmds, line)); // to limit the memory use // Build the columns for the row - //for (int i = 0; i < cmds.size(); i++) { - // final String tempValue = line.substring(recPosition - 1, recPosition - // + (((ColumnMetaData) cmds.get(i)).getColLength() - 1)); - // recPosition += ((ColumnMetaData) cmds.get(i)).getColLength(); - // row.addColumn(tempValue.trim()); - // } + // for (int i = 0; i < cmds.size(); i++) { + // final String tempValue = line.substring(recPosition - 1, + // recPosition + // + (((ColumnMetaData) cmds.get(i)).getColLength() - 1)); + // recPosition += ((ColumnMetaData) cmds.get(i)).getColLength(); + // row.addColumn(tempValue.trim()); + // } row.setRowNumber(lineCount); // add the row to the array rows.add(row); @@ -742,7 +741,7 @@ while ((line = br.readLine()) != null) { lineCount++; /** empty line skip past it */ - String trimmed = line.trim(); + final String trimmed = line.trim(); if (!processingMultiLine && trimmed.length() == 0) { continue; } @@ -781,14 +780,17 @@ // it is safe to assume we have reached the end of the // line break processingMultiLine = false; - if (trimmedLineData.length() > 0) { //+ would always be true surely.... + if (trimmedLineData.length() > 0) { // + would always be + // true surely.... lineData += "\r\n"; } lineData += line; } else { // check to see if this is the last line of the record // looking for a qualifier followed by a delimiter - if (trimmedLineData.length() > 0) { //+ here again, this should always be true... + if (trimmedLineData.length() > 0) { // + here again, + // this should + // always be true... lineData += "\r\n"; } lineData += line; @@ -908,21 +910,27 @@ // row.setValue(ParserUtils.findColumn(columnName, cmds), value); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#goTop() */ public void goTop() { pointer = -1; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#goBottom() */ public void goBottom() { pointer = rows.size() - 1; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#next() */ public boolean next() { @@ -933,7 +941,9 @@ return false; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#previous() */ public boolean previous() { @@ -944,7 +954,9 @@ return true; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#getString(java.lang.String) */ public String getString(final String column) { @@ -972,7 +984,9 @@ return s; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#getDouble(java.lang.String) */ public double getDouble(final String column) { @@ -1006,7 +1020,9 @@ return Double.parseDouble(newString.toString()); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#getInt(java.lang.String) */ public int getInt(final String column) { @@ -1040,7 +1056,9 @@ return Integer.parseInt(newString.toString()); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#getDate(java.lang.String) */ public Date getDate(final String column) throws ParseException { @@ -1054,8 +1072,11 @@ return sdf.parse(s); } - /* (non-Javadoc) - * @see net.sf.pzfilereader.IDataSet#getDate(java.lang.String, java.text.SimpleDateFormat) + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getDate(java.lang.String, + * java.text.SimpleDateFormat) */ public Date getDate(final String column, final SimpleDateFormat sdf) throws ParseException { final Row row = (Row) rows.get(pointer); @@ -1067,7 +1088,9 @@ return sdf.parse(s); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#getColumns() */ public String[] getColumns() { @@ -1087,7 +1110,9 @@ return array; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#getColumns(java.lang.String) */ public String[] getColumns(final String recordID) { @@ -1105,14 +1130,18 @@ return array; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#getRowNo() */ public int getRowNo() { return ((Row) rows.get(pointer)).getRowNumber(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#getErrors() */ public List getErrors() { @@ -1138,7 +1167,9 @@ errors.add(de); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#remove() */ public void remove() { @@ -1146,7 +1177,9 @@ pointer--; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#getIndex() */ public int getIndex() { @@ -1183,14 +1216,18 @@ return rowID.equals(recordID); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#getRowCount() */ public int getRowCount() { return rows.size(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#getErrorCount() */ public int getErrorCount() { @@ -1201,7 +1238,9 @@ return 0; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#isAnError(int) */ public boolean isAnError(final int lineNo) { @@ -1213,7 +1252,9 @@ return false; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#orderRows(net.sf.pzfilereader.ordering.OrderBy) */ public void orderRows(final OrderBy ob) throws Exception { @@ -1326,7 +1367,9 @@ this.columnMD = columnMD; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see net.sf.pzfilereader.IDataSet#getRows() */ public List getRows() { Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java 2006-10-27 14:14:36 UTC (rev 143) @@ -1,5 +1,34 @@ -/** +/* + * ObjectLab, http://www.objectlab.co.uk/open is supporting PZFileReader. * + * Based in London, we are world leaders in the design and development + * of bespoke applications for the securities financing markets. + * + * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> + * ___ _ _ _ _ _ + * / _ \| |__ (_) ___ ___| |_| | __ _| |__ + * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ + * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | + * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ + * |__/ + * + * www.ObjectLab.co.uk + * + * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ + * + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package net.sf.pzfilereader; @@ -23,9 +52,9 @@ * */ public class DefaultDataSet implements IDataSet { - private List rows = new ArrayList(); + private final List rows = new ArrayList(); - private List errors = new ArrayList(); + private final List errors = new ArrayList(); /** Pointer for the current row in the array we are on */ private int pointer = -1; @@ -44,15 +73,15 @@ private Map columnMD; - public DefaultDataSet(Map columnMD2) { + public DefaultDataSet(final Map columnMD2) { this.columnMD = columnMD2; } - public void addRow(Row row) { + public void addRow(final Row row) { rows.add(row); } - public void addError(DataError dataError) { + public void addError(final DataError dataError) { errors.add(dataError); } @@ -83,7 +112,7 @@ * * @see net.sf.pzfilereader.IDataSet#getColumns(java.lang.String) */ - public String[] getColumns(String recordID) { + public String[] getColumns(final String recordID) { String[] array = null; if (columnMD != null) { @@ -103,7 +132,7 @@ * * @see net.sf.pzfilereader.IDataSet#getDate(java.lang.String) */ - public Date getDate(String column) throws ParseException { + public Date getDate(final String column) throws ParseException { final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); final Row row = (Row) rows.get(pointer); final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); @@ -116,7 +145,7 @@ * @see net.sf.pzfilereader.IDataSet#getDate(java.lang.String, * java.text.SimpleDateFormat) */ - public Date getDate(String column, SimpleDateFormat sdf) throws ParseException { + public Date getDate(final String column, final SimpleDateFormat sdf) throws ParseException { final Row row = (Row) rows.get(pointer); final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); return sdf.parse(s); @@ -127,7 +156,7 @@ * * @see net.sf.pzfilereader.IDataSet#getDouble(java.lang.String) */ - public double getDouble(String column) { + public double getDouble(final String column) { final StringBuffer newString = new StringBuffer(); final Row row = (Row) rows.get(pointer); @@ -190,7 +219,7 @@ * * @see net.sf.pzfilereader.IDataSet#getInt(java.lang.String) */ - public int getInt(String column) { + public int getInt(final String column) { final StringBuffer newString = new StringBuffer(); final Row row = (Row) rows.get(pointer); final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); @@ -249,7 +278,7 @@ * * @see net.sf.pzfilereader.IDataSet#getString(java.lang.String) */ - public String getString(String column) { + public String getString(final String column) { final Row row = (Row) rows.get(pointer); final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); @@ -294,7 +323,7 @@ * * @see net.sf.pzfilereader.IDataSet#isAnError(int) */ - public boolean isAnError(int lineNo) { + public boolean isAnError(final int lineNo) { for (int i = 0; i < errors.size(); i++) { if (((DataError) errors.get(i)).getLineNo() == lineNo && ((DataError) errors.get(i)).getErrorLevel() > 1) { return true; @@ -321,7 +350,7 @@ * * @see net.sf.pzfilereader.IDataSet#orderRows(net.sf.pzfilereader.ordering.OrderBy) */ - public void orderRows(OrderBy ob) throws Exception { + public void orderRows(final OrderBy ob) throws Exception { // PZ try to handle other <records> by sending them to // the bottom of the sort // if (columnMD.size() > 1) { @@ -419,7 +448,7 @@ pointer--; } - void setColumnMD(Map columnMD) { + void setColumnMD(final Map columnMD) { this.columnMD = columnMD; } Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultPZParserFactory.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultPZParserFactory.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultPZParserFactory.java 2006-10-27 14:14:36 UTC (rev 143) @@ -53,7 +53,7 @@ * @see net.sf.pzfilereader.PZParserFactory#newFixedWidthParser(java.sql.Connection, * java.io.File, java.lang.String) */ - public PZParser newFixedLengthParser(Connection con, File dataSource, String dataDefinition) { + public PZParser newFixedLengthParser(final Connection con, final File dataSource, final String dataDefinition) { return new DBFixedLengthPZParser(con, dataSource, dataDefinition); } @@ -63,7 +63,7 @@ * @see net.sf.pzfilereader.PZParserFactory#newFixedWidthParser(java.sql.Connection, * java.io.InputStream, java.lang.String) */ - public PZParser newFixedLengthParser(Connection con, InputStream dataSourceStream, String dataDefinition) { + public PZParser newFixedLengthParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition) { return new DBFixedLengthPZParser(con, dataSourceStream, dataDefinition); } @@ -73,7 +73,7 @@ * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.File, * java.io.File) */ - public PZParser newFixedLengthParser(File pzmapXML, File dataSource) { + public PZParser newFixedLengthParser(final File pzmapXML, final File dataSource) { return new FixedLengthPZParser(pzmapXML, dataSource); } @@ -83,7 +83,7 @@ * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.InputStream, * java.io.InputStream) */ - public PZParser newFixedLengthParser(InputStream pzmapXMLStream, InputStream dataSourceStream) { + public PZParser newFixedLengthParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream) { return new FixedLengthPZParser(pzmapXMLStream, dataSourceStream); } @@ -93,8 +93,8 @@ * @see net.sf.pzfilereader.PZParserFactory#newParser(java.sql.Connection, * java.io.InputStream, java.lang.String, char, char, boolean) */ - public PZParser newDelimitedParser(Connection con, InputStream dataSourceStream, String dataDefinition, char delimiter, - char qualifier, boolean ignoreFirstRecord) { + public PZParser newDelimitedParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition, + final char delimiter, final char qualifier, final boolean ignoreFirstRecord) { return new DBDelimiterPZParser(con, dataSourceStream, dataDefinition, delimiter, qualifier, ignoreFirstRecord); } @@ -104,7 +104,8 @@ * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.File, * java.io.File, char, char, boolean) */ - public PZParser newDelimitedParser(File pzmapXML, File dataSource, char delimiter, char qualifier, boolean ignoreFirstRecord) { + public PZParser newDelimitedParser(final File pzmapXML, final File dataSource, final char delimiter, final char qualifier, + final boolean ignoreFirstRecord) { return new DelimiterPZParser(pzmapXML, dataSource, delimiter, qualifier, ignoreFirstRecord); } @@ -114,8 +115,8 @@ * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.InputStream, * java.io.InputStream, char, char, boolean) */ - public PZParser newDelimitedParser(InputStream pzmapXMLStream, InputStream dataSourceStream, char delimiter, char qualifier, - boolean ignoreFirstRecord) { + public PZParser newDelimitedParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream, + final char delimiter, final char qualifier, final boolean ignoreFirstRecord) { return new DelimiterPZParser(pzmapXMLStream, dataSourceStream, delimiter, qualifier, ignoreFirstRecord); } @@ -125,7 +126,7 @@ * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.File, char, * char) */ - public PZParser newDelimitedParser(File dataSource, char delimiter, char qualifier) { + public PZParser newDelimitedParser(final File dataSource, final char delimiter, final char qualifier) { return new DelimiterPZParser(dataSource, delimiter, qualifier, false); } @@ -135,7 +136,7 @@ * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.InputStream, * char, char) */ - public PZParser newDelimitedParser(InputStream dataSourceStream, char delimiter, char qualifier) { + public PZParser newDelimitedParser(final InputStream dataSourceStream, final char delimiter, final char qualifier) { return new DelimiterPZParser(dataSourceStream, delimiter, qualifier, false); } Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DelimiterPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DelimiterPZParser.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DelimiterPZParser.java 2006-10-27 14:14:36 UTC (rev 143) @@ -1,5 +1,34 @@ -/** +/* + * ObjectLab, http://www.objectlab.co.uk/open is supporting PZFileReader. * + * Based in London, we are world leaders in the design and development + * of bespoke applications for the securities financing markets. + * + * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> + * ___ _ _ _ _ _ + * / _ \| |__ (_) ___ ___| |_| | __ _| |__ + * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ + * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | + * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ + * |__/ + * + * www.ObjectLab.co.uk + * + * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ + * + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package net.sf.pzfilereader; @@ -21,22 +50,24 @@ private File pzmapXML = null; - public DelimiterPZParser(File pzmapXML, File dataSource, char delimiter, char qualifier, boolean ignoreFirstRecord) { + public DelimiterPZParser(final File pzmapXML, final File dataSource, final char delimiter, final char qualifier, + final boolean ignoreFirstRecord) { super(dataSource, delimiter, qualifier, ignoreFirstRecord); this.pzmapXML = pzmapXML; } - public DelimiterPZParser(InputStream pzmapXMLStream, InputStream dataSourceStream, char delimiter, char qualifier, - boolean ignoreFirstRecord) { + public DelimiterPZParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final char delimiter, + final char qualifier, final boolean ignoreFirstRecord) { super(dataSourceStream, delimiter, qualifier, ignoreFirstRecord); this.pzmapXMLStream = pzmapXMLStream; } - public DelimiterPZParser(File dataSource, char delimiter, char qualifier, boolean ignoreFirstRecord) { + public DelimiterPZParser(final File dataSource, final char delimiter, final char qualifier, final boolean ignoreFirstRecord) { super(dataSource, delimiter, qualifier, ignoreFirstRecord); } - public DelimiterPZParser(InputStream dataSourceStream, char delimiter, char qualifier, boolean ignoreFirstRecord) { + public DelimiterPZParser(final InputStream dataSourceStream, final char delimiter, final char qualifier, + final boolean ignoreFirstRecord) { super(dataSourceStream, delimiter, qualifier, ignoreFirstRecord); } @@ -45,7 +76,7 @@ if (pzmapXMLStream != null) { setColumnMD(PZMapParser.parse(pzmapXMLStream)); } else if (pzmapXML != null) { - InputStream stream = ParserUtils.createInputStream(pzmapXML); + final InputStream stream = ParserUtils.createInputStream(pzmapXML); try { setColumnMD(PZMapParser.parse(stream)); } finally { @@ -55,9 +86,9 @@ } } setInitialised(true); - } catch (JDOMException e) { + } catch (final JDOMException e) { throw new InitialisationException(e); - } catch (IOException e) { + } catch (final IOException e) { throw new InitialisationException(e); } } Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/FixedLengthPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/FixedLengthPZParser.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/FixedLengthPZParser.java 2006-10-27 14:14:36 UTC (rev 143) @@ -1,5 +1,34 @@ -/** +/* + * ObjectLab, http://www.objectlab.co.uk/open is supporting PZFileReader. * + * Based in London, we are world leaders in the design and development + * of bespoke applications for the securities financing markets. + * + * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> + * ___ _ _ _ _ _ + * / _ \| |__ (_) ___ ___| |_| | __ _| |__ + * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ + * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | + * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ + * |__/ + * + * www.ObjectLab.co.uk + * + * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ + * + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package net.sf.pzfilereader; @@ -26,7 +55,7 @@ this.pzmapXMLStream = pzmapXMLStream; } - public FixedLengthPZParser(File pzmapXML, File dataSource) { + public FixedLengthPZParser(final File pzmapXML, final File dataSource) { super(dataSource); this.pzmapXML = pzmapXML; } @@ -36,7 +65,7 @@ if (pzmapXMLStream != null) { setColumnMD(PZMapParser.parse(pzmapXMLStream)); } else { - InputStream stream = ParserUtils.createInputStream(pzmapXML); + final InputStream stream = ParserUtils.createInputStream(pzmapXML); try { setColumnMD(PZMapParser.parse(stream)); } finally { @@ -45,9 +74,9 @@ } } } - } catch (JDOMException e) { + } catch (final JDOMException e) { throw new InitialisationException(e); - } catch (IOException e) { + } catch (final IOException e) { throw new InitialisationException(e); } } Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/InitialisationException.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/InitialisationException.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/InitialisationException.java 2006-10-27 14:14:36 UTC (rev 143) @@ -1,11 +1,40 @@ -/** +/* + * ObjectLab, http://www.objectlab.co.uk/open is supporting PZFileReader. * + * Based in London, we are world leaders in the design and development + * of bespoke applications for the securities financing markets. + * + * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> + * ___ _ _ _ _ _ + * / _ \| |__ (_) ___ ___| |_| | __ _| |__ + * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ + * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | + * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ + * |__/ + * + * www.ObjectLab.co.uk + * + * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ + * + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. */ package net.sf.pzfilereader; /** * @author xhensevb - * + * */ public class InitialisationException extends RuntimeException { private static final long serialVersionUID = -4181701730609348676L; @@ -19,14 +48,14 @@ /** * @param message */ - public InitialisationException(String message) { + public InitialisationException(final String message) { super(message); } /** * @param cause */ - public InitialisationException(Throwable cause) { + public InitialisationException(final Throwable cause) { super(cause); } @@ -34,7 +63,7 @@ * @param message * @param cause */ - public InitialisationException(String message, Throwable cause) { + public InitialisationException(final String message, final Throwable cause) { super(message, cause); } } Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java 2006-10-27 14:14:36 UTC (rev 143) @@ -23,7 +23,6 @@ import java.util.Map; import net.sf.pzfilereader.ordering.OrderBy; -import net.sf.pzfilereader.structure.ColumnMetaData; import net.sf.pzfilereader.structure.Row; import net.sf.pzfilereader.util.FixedWidthParserUtils; import net.sf.pzfilereader.util.PZConstants; @@ -405,7 +404,7 @@ * also close out the readers used to read the file in. */ public void freeMemory() { - //super.freeMemory(); + // super.freeMemory(); ParserUtils.closeReader(br); ParserUtils.closeReader(isr); @@ -430,7 +429,7 @@ /** loop through each line in the file */ while ((line = br.readLine()) != null) { lineCount++; - String trimmed = line.trim(); + final String trimmed = line.trim(); /** empty line skip past it */ if (!processingMultiLine && trimmed.length() == 0) { continue; @@ -569,13 +568,14 @@ private boolean readNextFixedLen() throws Exception { String line = null; - //final int aLineCount = 0; // +++++++++++++++++++++++++++++++++ Paul + // final int aLineCount = 0; // +++++++++++++++++++++++++++++++++ Paul // this does not seem incremented afaLineCountt all... - //******************************************************************** - //Good point, and it is being used to report line errors. Looks like a bug. - //Should be using lineCount - //PZ - + // ******************************************************************** + // Good point, and it is being used to report line errors. Looks like a + // bug. + // Should be using lineCount + // PZ + boolean readRecordOk = false; if (getRows() == null) { @@ -621,19 +621,20 @@ } } - //int recPosition = 1; + // int recPosition = 1; final Row row = new Row(); row.setMdkey(mdkey.equals("detail") ? null : mdkey); // try to // limit the memory use - + // Build the columns for the row row.addColumn(FixedWidthParserUtils.splitFixedText(cmds, line)); - //for (int i = 0; i < cmds.size(); i++) { - // final String tempValue = line.substring(recPosition - 1, recPosition - // + (((ColumnMetaData) cmds.get(i)).getColLength() - 1)); - // recPosition += ((ColumnMetaData) cmds.get(i)).getColLength(); - // row.addColumn(tempValue.trim()); - // } + // for (int i = 0; i < cmds.size(); i++) { + // final String tempValue = line.substring(recPosition - 1, + // recPosition + // + (((ColumnMetaData) cmds.get(i)).getColLength() - 1)); + // recPosition += ((ColumnMetaData) cmds.get(i)).getColLength(); + // row.addColumn(tempValue.trim()); + // } row.setRowNumber(this.lineCount); // add the row to the array getRows().add(row); Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParser.java 2006-10-27 14:06:22 UTC (rev 142) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParser.java 2006-10-27 14:14:36 UTC (rev 143) @@ -33,24 +33,24 @@ package net.sf.pzfilereader; /** - * PZParser is ready to parse the data and return an object that can then be traversed. - * The default parser should NOT handle short lines, the user can change it prior to calling - * parse. + * PZParser is ready to parse the data and return an object that can then be + * traversed. The default parser should NOT handle short lines, the user can + * change it prior to calling parse. * * @author Benoit Xhenseval */ public interface PZParser { - + /** * Start the parsing + * * @return the data set resulting from parsing */ IDataSet parse(); /** - * @return true, lines with less columns then the amount - * of column headers will be added as empty's instead of - * producing an error + * @return true, lines with less columns then the amount of column headers + * will be added as empty's instead of producing an error */ boolean isHandlingShortLines(); Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/ordering/OrderBy.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/ordering/OrderBy.java 2006-10-27... [truncated message content] |
From: <be...@us...> - 2006-10-27 14:06:44
|
Revision: 142 http://svn.sourceforge.net/pzfilereader/?rev=142&view=rev Author: benoitx Date: 2006-10-27 07:06:22 -0700 (Fri, 27 Oct 2006) Log Message: ----------- First cut at re-org to use Factory mechanisms. Converted 2 unit tests and they seem happy... Still using IDataSet for the interface. LargeSet not covered at this stage. Modified Paths: -------------- trunk/PZFileReader/.classpath trunk/PZFileReader/src/main/java/net/sf/pzfilereader/IDataSet.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParserFactory.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFile.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/columninfile/DelimitedColumnNamesInFileTest.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimited.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/delim/tab/TabDelimitedTest.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsLTrimTest.java trunk/PZFileReader/src/test/java/net/sf/pzfilereader/parserutils/ParserUtilsSplitLineTest.java Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBDelimiterPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBFixedLengthPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultPZParserFactory.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DelimiterPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/FixedLengthPZParser.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/InitialisationException.java Modified: trunk/PZFileReader/.classpath =================================================================== --- trunk/PZFileReader/.classpath 2006-10-27 11:55:43 UTC (rev 141) +++ trunk/PZFileReader/.classpath 2006-10-27 14:06:22 UTC (rev 142) @@ -1,11 +1,12 @@ <?xml version="1.0" encoding="UTF-8"?> - <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"></classpathentry> - <classpathentry excluding="" kind="src" path="src/main/java"></classpathentry> - <classpathentry output="target/test-classes" kind="src" path="src/test/java"></classpathentry> - <classpathentry path="MAVEN_REPO/junit/jars/junit-3.8.2.jar" kind="var"></classpathentry> - <classpathentry path="MAVEN_REPO/jdom/jars/jdom-1.0.jar" kind="var"></classpathentry> - <classpathentry path="MAVEN_REPO/jexcelapi/jars/jxl-2.4.2.jar" kind="var"></classpathentry> - <classpathentry kind="output" path="target/classes"></classpathentry> -</classpath> \ No newline at end of file + <classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/> + <classpathentry path="src/main/java" kind="src"/> + <classpathentry path="src/test/java" output="target/test-classes" kind="src"/> + <classpathentry path="MAVEN_REPO/junit/jars/junit-3.8.2.jar" kind="var"/> + <classpathentry path="ECLIPSE_HOME/plugins/org.eclipse.hyades.test.tools.core_4.2.1.v200607310100/common.runner.jar" kind="var"/> + <classpathentry path="ECLIPSE_HOME/plugins/org.eclipse.hyades.test.tools.core_4.2.1.v200607310100/java.runner.jar" kind="var"/> + <classpathentry path="MAVEN_REPO/jdom/jars/jdom-1.0.jar" kind="var"/> + <classpathentry path="MAVEN_REPO/jexcelapi/jars/jxl-2.4.2.jar" kind="var"/> + <classpathentry path="target/classes" kind="output"/> +</classpath> Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java 2006-10-27 14:06:22 UTC (rev 142) @@ -0,0 +1,285 @@ +/** + * + */ +package net.sf.pzfilereader; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.List; + +import net.sf.pzfilereader.structure.Row; +import net.sf.pzfilereader.util.PZConstants; +import net.sf.pzfilereader.util.ParserUtils; + +/** + * @author xhensevb + * + */ +public abstract class AbstractDelimiterPZParser extends AbstractPZParser { + private char delimiter = 0; + + private char qualifier = 0; + + private boolean ignoreFirstRecord = false; + + public AbstractDelimiterPZParser(InputStream dataSourceStream, String dataDefinition, char delimiter, char qualifier, + boolean ignoreFirstRecord) { + super(dataSourceStream, dataDefinition); + this.delimiter = delimiter; + this.qualifier = qualifier; + this.ignoreFirstRecord = ignoreFirstRecord; + } + + public AbstractDelimiterPZParser(File dataSource, char delimiter, char qualifier, boolean ignoreFirstRecord) { + super(dataSource); + this.delimiter = delimiter; + this.qualifier = qualifier; + this.ignoreFirstRecord = ignoreFirstRecord; + } + + public AbstractDelimiterPZParser(InputStream dataSourceStream, char delimiter, char qualifier, boolean ignoreFirstRecord) { + super(dataSourceStream); + this.delimiter = delimiter; + this.qualifier = qualifier; + this.ignoreFirstRecord = ignoreFirstRecord; + } + + public IDataSet doParse() { + try { + if (getDataSourceStream() != null) { + return doDelimitedFile(getDataSourceStream(), getDelimiter(), getQualifier(), isIgnoreFirstRecord(), shouldCreateMDFromFile()); + } else { + InputStream stream = null; + try { + stream = ParserUtils.createInputStream(getDataSource()); + return doDelimitedFile(stream, getDelimiter(), getQualifier(), isIgnoreFirstRecord(), shouldCreateMDFromFile()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + if (stream != null) { + stream.close(); + } + } + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + protected abstract boolean shouldCreateMDFromFile(); + + protected char getDelimiter() { + return delimiter; + } + + protected void setDelimiter(char delimiter) { + this.delimiter = delimiter; + } + + protected boolean isIgnoreFirstRecord() { + return ignoreFirstRecord; + } + + protected void setIgnoreFirstRecord(boolean ignoreFirstRecord) { + this.ignoreFirstRecord = ignoreFirstRecord; + } + + protected char getQualifier() { + return qualifier; + } + + protected void setQualifier(char qualifier) { + this.qualifier = qualifier; + } + + /* + * This is the new version of doDelimitedFile using InputStrem instead of + * File. This is more flexible especially it is working with WebStart. + * + * puts together the dataset for a DELIMITED file. This is used for PZ XML + * mappings, and SQL table mappings + */ + private IDataSet doDelimitedFile(final InputStream dataSource, final char delimiter, final char qualifier, + final boolean ignoreFirstRecord, final boolean createMDFromFile) throws IOException, Exception { + if (dataSource == null) { + throw new NullPointerException("dataSource is null"); + } + + InputStreamReader isr = null; + BufferedReader br = null; + DefaultDataSet ds = new DefaultDataSet(getColumnMD()); + try { + // get the total column count + // columnCount = columnMD.size(); + + /** Read in the flat file */ + // fr = new FileReader(dataSource.getAbsolutePath()); + isr = new InputStreamReader(dataSource); + br = new BufferedReader(isr); + + boolean processedFirst = false; + boolean processingMultiLine = false; + int lineCount = 0; + String lineData = ""; + /** loop through each line in the file */ + String line = null; + while ((line = br.readLine()) != null) { + lineCount++; + /** empty line skip past it */ + String trimmed = line.trim(); + if (!processingMultiLine && trimmed.length() == 0) { + continue; + } + + // check to see if the user has elected to skip the first record + if (!processedFirst && ignoreFirstRecord) { + processedFirst = true; + continue; + } else if (!processedFirst && createMDFromFile) { + processedFirst = true; + setColumnMD(ParserUtils.getColumnMDFromFile(line, delimiter, qualifier)); + ds.setColumnMD(getColumnMD()); + continue; + } + + // ******************************************************** + // new functionality as of 2.1.0 check to see if we have + // any line breaks in the middle of the record, this will only + // be checked if we have specified a delimiter + // ******************************************************** + final char[] chrArry = trimmed.toCharArray(); + if (!processingMultiLine && delimiter > 0) { + processingMultiLine = ParserUtils.isMultiLine(chrArry, delimiter, qualifier); + } + + // check to see if we have reached the end of the linebreak in + // the record + + final String trimmedLineData = lineData.trim(); + if (processingMultiLine && trimmedLineData.length() > 0) { + // need to do one last check here. it is possible that the " + // could be part of the data + // excel will escape these with another quote; here is some + // data "" This would indicate + // there is more to the multiline + if (trimmed.charAt(trimmed.length() - 1) == qualifier && !trimmed.endsWith("" + qualifier + qualifier)) { + // it is safe to assume we have reached the end of the + // line break + processingMultiLine = false; + if (trimmedLineData.length() > 0) { // + would always be + // true surely.... + lineData += "\r\n"; + } + lineData += line; + } else { + // check to see if this is the last line of the record + // looking for a qualifier followed by a delimiter + if (trimmedLineData.length() > 0) { // + here again, + // this should + // always be true... + lineData += "\r\n"; + } + lineData += line; + boolean qualiFound = false; + for (int i = 0; i < chrArry.length; i++) { + if (qualiFound) { + if (chrArry[i] == ' ') { + continue; + } else { + // not a space, if this char is the + // delimiter, then we have reached the end + // of + // the record + if (chrArry[i] == delimiter) { + // processingMultiLine = false; + // fix put in, setting to false caused + // bug when processing multiple + // multi-line + // columns on the same record + processingMultiLine = ParserUtils.isMultiLine(chrArry, delimiter, qualifier); + break; + } + qualiFound = false; + continue; + } + } else if (chrArry[i] == qualifier) { + qualiFound = true; + } + } + // check to see if we are still in multi line mode, if + // so grab the next line + if (processingMultiLine) { + continue; + } + } + } else { + // throw the line into lineData var. + lineData += line; + if (processingMultiLine) { + continue; // if we are working on a multiline rec, get + // the data on the next line + } + } + // ******************************************************************** + // end record line break logic + // ******************************************************************** + + // column values + final List columns = ParserUtils.splitLine(lineData, delimiter, qualifier); + lineData = ""; + final String mdkey = ParserUtils.getCMDKeyForDelimitedFile(getColumnMD(), columns); + final List cmds = ParserUtils.getColumnMetaData(mdkey, getColumnMD()); + final int columnCount = cmds.size(); + // DEBUG + + // Incorrect record length on line log the error. Line + // will not be included in the dataset + if (columns.size() > columnCount) { + // log the error + addError(ds, "TOO MANY COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2); + continue; + } else if (columns.size() < columnCount) { + if (isHandlingShortLines()) { + // We can pad this line out + while (columns.size() < columnCount) { + columns.add(""); + } + + // log a warning + addError(ds, "PADDED LINE TO CORRECT NUMBER OF COLUMNS", lineCount, 1); + + } else { + addError(ds, "TOO FEW COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2); + continue; + } + } + + final Row row = new Row(); + row.setMdkey(mdkey.equals(PZConstants.DETAIL_ID) ? null : mdkey); // try + // to limit the memory use + row.setCols(columns); + row.setRowNumber(lineCount); + /** add the row to the array */ + ds.addRow(row); + } + } finally { + if (isr != null) { + isr.close(); + } + if (br != null) { + br.close(); + } + } + return ds; + } +} Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java 2006-10-27 14:06:22 UTC (rev 142) @@ -0,0 +1,154 @@ +/** + * + */ +package net.sf.pzfilereader; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.List; +import java.util.Map; + +import net.sf.pzfilereader.structure.Row; +import net.sf.pzfilereader.util.FixedWidthParserUtils; +import net.sf.pzfilereader.util.PZConstants; +import net.sf.pzfilereader.util.ParserUtils; + +/** + * @author xhensevb + * + */ +public abstract class AbstractFixedLengthPZParser extends AbstractPZParser { + + protected AbstractFixedLengthPZParser(File dataSource, String dataDefinition) { + super(dataSource, dataDefinition); + } + + protected AbstractFixedLengthPZParser(File dataSource) { + super(dataSource); + } + + protected AbstractFixedLengthPZParser(InputStream dataSourceStream, String dataDefinition) { + super(dataSourceStream, dataDefinition); + } + + protected AbstractFixedLengthPZParser(InputStream dataSourceStream) { + super(dataSourceStream); + } + + public IDataSet doParse() { + try { + if (getDataSourceStream() != null) { + return doFixedLengthFile(getDataSourceStream()); + } else { + InputStream stream; + stream = ParserUtils.createInputStream(getDataSource()); + try { + return doFixedLengthFile(stream); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + if (stream != null) { + stream.close(); + } + } + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + /* + * This is the new version of doDelimitedFile using InputStrem instead of + * File. This is more flexible especially it is working with WebStart. + * + * puts together the dataset for fixed length file. This is used for PZ XML + * mappings, and SQL table mappings + */ + private IDataSet doFixedLengthFile(final InputStream dataSource) throws IOException { + InputStreamReader isr = null; + BufferedReader br = null; + + DefaultDataSet ds = new DefaultDataSet(getColumnMD()); + + try { + final Map recordLengths = ParserUtils.calculateRecordLengths(getColumnMD()); + + // Read in the flat file + isr = new InputStreamReader(dataSource); + br = new BufferedReader(isr); + String line = null; + int lineCount = 0; + // map of record lengths corrisponding to the ID's in the columnMD + // array + // loop through each line in the file + while ((line = br.readLine()) != null) { + lineCount++; + // empty line skip past it + if (line.trim().length() == 0) { + continue; + } + + final String mdkey = FixedWidthParserUtils.getCMDKey(getColumnMD(), line); + final int recordLength = ((Integer) recordLengths.get(mdkey)).intValue(); + + // Incorrect record length on line log the error. Line will not + // be included in the + // dataset + if (line.length() > recordLength) { + addError(ds, "LINE TOO LONG. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2); + 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); + continue; + } + } + + // int recPosition = 1; + final Row row = new Row(); + row.setMdkey(mdkey.equals(PZConstants.DETAIL_ID) ? null : mdkey); // try + + final List cmds = ParserUtils.getColumnMetaData(mdkey, getColumnMD()); + row.addColumn(FixedWidthParserUtils.splitFixedText(cmds, line)); + // to limit the memory use + // Build the columns for the row + // for (int i = 0; i < cmds.size(); i++) { + // final String tempValue = line.substring(recPosition - 1, + // recPosition + // + (((ColumnMetaData) cmds.get(i)).getColLength() - 1)); + // recPosition += ((ColumnMetaData) cmds.get(i)).getColLength(); + // row.addColumn(tempValue.trim()); + // } + row.setRowNumber(lineCount); + // add the row to the array + ds.addRow(row); + } + } finally { + if (isr != null) { + isr.close(); + } + if (br != null) { + br.close(); + } + } + return ds; + } +} Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractPZParser.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractPZParser.java 2006-10-27 14:06:22 UTC (rev 142) @@ -0,0 +1,140 @@ +/** + * + */ +package net.sf.pzfilereader; + +import java.io.File; +import java.io.InputStream; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author xhensevb + * + */ +public abstract class AbstractPZParser implements PZParser { + + private boolean handlingShortLines = false; + + private boolean initialised = false; + + /** Map of column metadata's */ + private Map columnMD = null; + + private String dataDefinition = null; + + private InputStream dataSourceStream = null; + + private File dataSource = null; + + protected AbstractPZParser(File dataSource) { + this.dataSource = dataSource; + } + + protected AbstractPZParser(InputStream dataSourceStream) { + this.dataSourceStream = dataSourceStream; + } + + protected AbstractPZParser(File dataSource, String dataDefinition) { + this.dataSource = dataSource; + this.dataDefinition = dataDefinition; + } + + protected AbstractPZParser(InputStream dataSourceStream, String dataDefinition) { + this.dataSourceStream = dataSourceStream; + this.dataDefinition = dataDefinition; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParser#isHandlingShortLines() + */ + public boolean isHandlingShortLines() { + return handlingShortLines; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParser#setHandlingShortLines(boolean) + */ + public void setHandlingShortLines(boolean handleShortLines) { + this.handlingShortLines = handleShortLines; + } + + public final IDataSet parse() { + if (!initialised) { + init(); + } + return doParse(); + } + + protected abstract IDataSet doParse(); + + protected abstract void init(); + + protected void setColumnMD(final Map map) { + columnMD = map; + } + + protected void addToColumnMD(final Object key, final Object value) { + if (columnMD == null) { + columnMD = new LinkedHashMap(); + } + columnMD.put(key, value); + } + + protected boolean isInitialised() { + return initialised; + } + + protected void setInitialised(boolean initialised) { + this.initialised = initialised; + } + + protected String getDataDefinition() { + return dataDefinition; + } + + protected void setDataDefinition(String dataDefinition) { + this.dataDefinition = dataDefinition; + } + + protected File getDataSource() { + return dataSource; + } + + protected void setDataSource(File dataSource) { + this.dataSource = dataSource; + } + + protected InputStream getDataSourceStream() { + return dataSourceStream; + } + + protected void setDataSourceStream(InputStream dataSourceStream) { + this.dataSourceStream = dataSourceStream; + } + + protected Map getColumnMD() { + return columnMD; + } + + /** + * Adds a new error to this DataSet. These can be collected, and retreived + * after processing + * + * @param errorDesc - + * String description of error + * @param lineNo - + * int line number error occured on + * @param errorLevel - + * int errorLevel 1,2,3 1=warning 2=error 3= severe error + */ + protected void addError(final DefaultDataSet ds, final String errorDesc, final int lineNo, final int errorLevel) { + final DataError de = new DataError(errorDesc,lineNo,errorLevel); + ds.addError(de); + } + +} Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBDelimiterPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBDelimiterPZParser.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBDelimiterPZParser.java 2006-10-27 14:06:22 UTC (rev 142) @@ -0,0 +1,100 @@ +/** + * + */ +package net.sf.pzfilereader; + +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import net.sf.pzfilereader.structure.ColumnMetaData; +import net.sf.pzfilereader.util.PZConstants; +import net.sf.pzfilereader.util.ParserUtils; + +/** + * @author xhensevb + * + */ +public class DBDelimiterPZParser extends AbstractDelimiterPZParser { + + private Connection con; + + public DBDelimiterPZParser(Connection con, InputStream dataSourceStream, String dataDefinition, char delimiter, + char qualifier, boolean ignoreFirstRecord) { + super(dataSourceStream, dataDefinition, delimiter, qualifier, ignoreFirstRecord); + this.con = con; + } + + protected void init() { + ResultSet rs = null; + PreparedStatement stmt = null; + + try { + final String sql = "SELECT * FROM DATAFILE INNER JOIN DATASTRUCTURE ON " + + "DATAFILE.DATAFILE_NO = DATASTRUCTURE.DATAFILE_NO " + "WHERE DATAFILE.DATAFILE_DESC = '" + + getDataDefinition() + "' " + "ORDER BY DATASTRUCTURE_COL_ORDER"; + + stmt = con.prepareStatement(sql); // always use PreparedStatement + // as the DB can do clever things. + rs = stmt.executeQuery(); + + int recPosition = 1; + final List cmds = new ArrayList(); + // put array of columns together. These will be used to put together + // the dataset when reading in the file + while (rs.next()) { + + final ColumnMetaData column = new ColumnMetaData(); + column.setColName(rs.getString("DATASTRUCTURE_COLUMN")); + column.setColLength(rs.getInt("DATASTRUCTURE_LENGTH")); + column.setStartPosition(recPosition); + column.setEndPosition(recPosition + (rs.getInt("DATASTRUCTURE_LENGTH") - 1)); + recPosition += rs.getInt("DATASTRUCTURE_LENGTH"); + + cmds.add(column); + } + + addToColumnMD(PZConstants.DETAIL_ID, cmds); + addToColumnMD(PZConstants.COL_IDX, ParserUtils.buidColumnIndexMap(cmds)); + + if (cmds.isEmpty()) { + throw new FileNotFoundException("DATA DEFINITION CAN NOT BE FOUND IN THE DATABASE " + getDataDefinition()); + } + + // read in the fixed length file and construct the DataSet object + // doFixedLengthFile(dataSourceStream); + setInitialised(true); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + try { + if (rs != null) { + rs.close(); + } + if (stmt != null) { + stmt.close(); + } + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + public IDataSet doParse() { + return null; + } + + protected boolean shouldCreateMDFromFile() { + return true; + } +} Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBFixedLengthPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBFixedLengthPZParser.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DBFixedLengthPZParser.java 2006-10-27 14:06:22 UTC (rev 142) @@ -0,0 +1,101 @@ +/** + * + */ +package net.sf.pzfilereader; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import net.sf.pzfilereader.structure.ColumnMetaData; +import net.sf.pzfilereader.util.PZConstants; +import net.sf.pzfilereader.util.ParserUtils; + +/** + * @author xhensevb + * + */ +public class DBFixedLengthPZParser extends AbstractFixedLengthPZParser { + + private Connection con; + + public DBFixedLengthPZParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition) { + super(dataSourceStream, dataDefinition); + this.con = con; + } + + public DBFixedLengthPZParser(Connection con, File dataSource, String dataDefinition) { + super(dataSource, dataDefinition); + this.con = con; + } + + protected void init() { + ResultSet rs = null; + PreparedStatement stmt = null; + + try { + final String sql = "SELECT * FROM DATAFILE INNER JOIN DATASTRUCTURE ON " + + "DATAFILE.DATAFILE_NO = DATASTRUCTURE.DATAFILE_NO " + "WHERE DATAFILE.DATAFILE_DESC = '" + + getDataDefinition() + "' " + "ORDER BY DATASTRUCTURE_COL_ORDER"; + + stmt = con.prepareStatement(sql); // always use PreparedStatement + // as the DB can do clever things. + rs = stmt.executeQuery(); + + int recPosition = 1; + final List cmds = new ArrayList(); + // put array of columns together. These will be used to put together + // the dataset when reading in the file + while (rs.next()) { + + final ColumnMetaData column = new ColumnMetaData(); + column.setColName(rs.getString("DATASTRUCTURE_COLUMN")); + column.setColLength(rs.getInt("DATASTRUCTURE_LENGTH")); + column.setStartPosition(recPosition); + column.setEndPosition(recPosition + (rs.getInt("DATASTRUCTURE_LENGTH") - 1)); + recPosition += rs.getInt("DATASTRUCTURE_LENGTH"); + + cmds.add(column); + } + + addToColumnMD(PZConstants.DETAIL_ID, cmds); + addToColumnMD(PZConstants.COL_IDX, ParserUtils.buidColumnIndexMap(cmds)); + + if (cmds.isEmpty()) { + throw new FileNotFoundException("DATA DEFINITION CAN NOT BE FOUND IN THE DATABASE " + getDataDefinition()); + } + + // read in the fixed length file and construct the DataSet object + // doFixedLengthFile(dataSourceStream); + setInitialised(true); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + try { + if (rs != null) { + rs.close(); + } + if (stmt != null) { + stmt.close(); + } + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + public IDataSet doParse() { + return null; + } +} Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java 2006-10-27 14:06:22 UTC (rev 142) @@ -0,0 +1,426 @@ +/** + * + */ +package net.sf.pzfilereader; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import net.sf.pzfilereader.ordering.OrderBy; +import net.sf.pzfilereader.structure.ColumnMetaData; +import net.sf.pzfilereader.structure.Row; +import net.sf.pzfilereader.util.PZConstants; +import net.sf.pzfilereader.util.ParserUtils; + +/** + * @author xhensevb + * + */ +public class DefaultDataSet implements IDataSet { + private List rows = new ArrayList(); + + private List errors = new ArrayList(); + + /** Pointer for the current row in the array we are on */ + private int pointer = -1; + + /** flag to indicate if data should be pulled as lower case */ + private boolean lowerCase = false; + + /** flag to inidicate if data should be pulled as upper case */ + private boolean upperCase = false; + + /** + * flag to indicate if a strict parse should be used when getting doubles + * and ints + */ + private boolean strictNumericParse = false; + + private Map columnMD; + + public DefaultDataSet(Map columnMD2) { + this.columnMD = columnMD2; + } + + public void addRow(Row row) { + rows.add(row); + } + + public void addError(DataError dataError) { + errors.add(dataError); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getColumns() + */ + public String[] getColumns() { + ColumnMetaData column = null; + String[] array = null; + + if (columnMD != null) { + final List cmds = ParserUtils.getColumnMetaData(PZConstants.DETAIL_ID, columnMD); + + array = new String[cmds.size()]; + for (int i = 0; i < cmds.size(); i++) { + column = (ColumnMetaData) cmds.get(i); + array[i] = column.getColName(); + } + } + + return array; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getColumns(java.lang.String) + */ + public String[] getColumns(String recordID) { + String[] array = null; + + if (columnMD != null) { + final List cmds = ParserUtils.getColumnMetaData(recordID, columnMD); + array = new String[cmds.size()]; + for (int i = 0; i < cmds.size(); i++) { + final ColumnMetaData column = (ColumnMetaData) cmds.get(i); + array[i] = column.getColName(); + } + } + + return array; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getDate(java.lang.String) + */ + public Date getDate(String column) throws ParseException { + final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + final Row row = (Row) rows.get(pointer); + final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); + return sdf.parse(s); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getDate(java.lang.String, + * java.text.SimpleDateFormat) + */ + public Date getDate(String column, SimpleDateFormat sdf) throws ParseException { + final Row row = (Row) rows.get(pointer); + final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); + return sdf.parse(s); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getDouble(java.lang.String) + */ + public double getDouble(String column) { + final StringBuffer newString = new StringBuffer(); + final Row row = (Row) rows.get(pointer); + + final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); + + if (!strictNumericParse) { + if (s.trim().length() == 0) { + return 0; + } + for (int i = 0; i < s.length(); i++) { + final char c = s.charAt(i); + if (c >= '0' && c <= '9' || c == '.' || c == '-') { + newString.append(c); + } + } + if (newString.length() == 0 || (newString.length() == 1 && newString.toString().equals(".")) + || (newString.length() == 1 && newString.toString().equals("-"))) { + newString.append("0"); + } + } else { + newString.append(s); + } + + return Double.parseDouble(newString.toString()); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getErrorCount() + */ + public int getErrorCount() { + if (getErrors() != null) { + return getErrors().size(); + } + + return 0; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getErrors() + */ + public List getErrors() { + return errors; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getIndex() + */ + public int getIndex() { + return pointer; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getInt(java.lang.String) + */ + public int getInt(String column) { + final StringBuffer newString = new StringBuffer(); + final Row row = (Row) rows.get(pointer); + final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); + + if (!strictNumericParse) { + if (s.trim().length() == 0) { + return 0; + } + for (int i = 0; i < s.length(); i++) { + final char c = s.charAt(i); + if (c >= '0' && c <= '9' || c == '-') { + newString.append(c); + } + } + // check to make sure we do not have a single length string with + // just a minus sign + if (newString.length() == 0 || (newString.length() == 1 && newString.toString().equals("-"))) { + newString.append("0"); + } + } else { + newString.append(s); + } + + return Integer.parseInt(newString.toString()); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getRowCount() + */ + public int getRowCount() { + return rows.size(); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getRowNo() + */ + public int getRowNo() { + return ((Row) rows.get(pointer)).getRowNumber(); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getRows() + */ + public List getRows() { + return rows; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#getString(java.lang.String) + */ + public String getString(String column) { + final Row row = (Row) rows.get(pointer); + final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); + + if (upperCase) { + // convert data to uppercase before returning + // return row.getValue(ParserUtils.findColumn(column, + // cmds)).toUpperCase(Locale.getDefault()); + return s.toUpperCase(Locale.getDefault()); + } + + if (lowerCase) { + // convert data to lowercase before returning + // return row.getValue(ParserUtils.findColumn(column, + // cmds)).toLowerCase(Locale.getDefault()); + return s.toLowerCase(Locale.getDefault()); + } + + // return value as how it is in the file + return s; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#goBottom() + */ + public void goBottom() { + pointer = rows.size() - 1; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#goTop() + */ + public void goTop() { + pointer = -1; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#isAnError(int) + */ + public boolean isAnError(int lineNo) { + for (int i = 0; i < errors.size(); i++) { + if (((DataError) errors.get(i)).getLineNo() == lineNo && ((DataError) errors.get(i)).getErrorLevel() > 1) { + return true; + } + } + return false; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#next() + */ + public boolean next() { + if (pointer < rows.size() && pointer + 1 != rows.size()) { + pointer++; + return true; + } + return false; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#orderRows(net.sf.pzfilereader.ordering.OrderBy) + */ + public void orderRows(OrderBy ob) throws Exception { + // PZ try to handle other <records> by sending them to + // the bottom of the sort + // if (columnMD.size() > 1) { + // throw new Exception("orderRows does not currently support ordering + // with <RECORD> mappings"); + // } + if (ob != null && rows != null) { + final List cmds = ParserUtils.getColumnMetaData(PZConstants.DETAIL_ID, columnMD); + ob.setColumnMD(cmds); + Collections.sort(rows, ob); + goTop(); + } + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#previous() + */ + public boolean previous() { + if (pointer <= 0) { + return false; + } + pointer--; + return true; + } + + /** + * Sets data in the DataSet to lowercase + */ + public void setLowerCase() { + upperCase = false; + lowerCase = true; + } + + /** + * Sets data in the DataSet to uppercase + */ + public void setUpperCase() { + upperCase = true; + lowerCase = false; + } + + /** + * Checks to see if the row has the given <RECORD> id + * + * @param recordID + * @return boolean + */ + public boolean isRecordID(final String recordID) { + String rowID = ((Row) rows.get(pointer)).getMdkey(); + if (rowID == null) { + rowID = PZConstants.DETAIL_ID; + } + + return rowID.equals(recordID); + } + + /** + * Sets the absolute position of the record pointer + * + * @param localPointer - + * int + * @exception IndexOutOfBoundsException + */ + public void absolute(final int localPointer) { + if (localPointer < 0 || localPointer > rows.size() - 1) { + throw new IndexOutOfBoundsException("INVALID POINTER LOCATION: " + localPointer); + } + + pointer = localPointer; + } + + /** + * Setting this to True will parse text as is and throw a + * NumberFormatException. Setting to false, which is the default, will + * remove any non numeric charcter from the field. The remaining numeric + * chars's will be returned. If it is an empty string,or there are no + * numeric chars, 0 will be returned for getInt() and getDouble() + * + * @param strictNumericParse + * The strictNumericParse to set. + */ + public void setStrictNumericParse(final boolean strictNumericParse) { + this.strictNumericParse = strictNumericParse; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.IDataSet#remove() + */ + public void remove() { + rows.remove(pointer); + pointer--; + } + + void setColumnMD(Map columnMD) { + this.columnMD = columnMD; + } + +} Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultPZParserFactory.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultPZParserFactory.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultPZParserFactory.java 2006-10-27 14:06:22 UTC (rev 142) @@ -0,0 +1,142 @@ +/* + * ObjectLab, http://www.objectlab.co.uk/open is supporting PZFileReader. + * + * Based in London, we are world leaders in the design and development + * of bespoke applications for the securities financing markets. + * + * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> + * ___ _ _ _ _ _ + * / _ \| |__ (_) ___ ___| |_| | __ _| |__ + * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ + * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | + * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ + * |__/ + * + * www.ObjectLab.co.uk + * + * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $ + * + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package net.sf.pzfilereader; + +import java.io.File; +import java.io.InputStream; +import java.sql.Connection; + +/** + * @author xhensevb + * + */ +public class DefaultPZParserFactory implements PZParserFactory { + private static final DefaultPZParserFactory INSTANCE = new DefaultPZParserFactory(); + + public static PZParserFactory getInstance() { + return INSTANCE; + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newFixedWidthParser(java.sql.Connection, + * java.io.File, java.lang.String) + */ + public PZParser newFixedLengthParser(Connection con, File dataSource, String dataDefinition) { + return new DBFixedLengthPZParser(con, dataSource, dataDefinition); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newFixedWidthParser(java.sql.Connection, + * java.io.InputStream, java.lang.String) + */ + public PZParser newFixedLengthParser(Connection con, InputStream dataSourceStream, String dataDefinition) { + return new DBFixedLengthPZParser(con, dataSourceStream, dataDefinition); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.File, + * java.io.File) + */ + public PZParser newFixedLengthParser(File pzmapXML, File dataSource) { + return new FixedLengthPZParser(pzmapXML, dataSource); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.InputStream, + * java.io.InputStream) + */ + public PZParser newFixedLengthParser(InputStream pzmapXMLStream, InputStream dataSourceStream) { + return new FixedLengthPZParser(pzmapXMLStream, dataSourceStream); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.sql.Connection, + * java.io.InputStream, java.lang.String, char, char, boolean) + */ + public PZParser newDelimitedParser(Connection con, InputStream dataSourceStream, String dataDefinition, char delimiter, + char qualifier, boolean ignoreFirstRecord) { + return new DBDelimiterPZParser(con, dataSourceStream, dataDefinition, delimiter, qualifier, ignoreFirstRecord); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.File, + * java.io.File, char, char, boolean) + */ + public PZParser newDelimitedParser(File pzmapXML, File dataSource, char delimiter, char qualifier, boolean ignoreFirstRecord) { + return new DelimiterPZParser(pzmapXML, dataSource, delimiter, qualifier, ignoreFirstRecord); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.InputStream, + * java.io.InputStream, char, char, boolean) + */ + public PZParser newDelimitedParser(InputStream pzmapXMLStream, InputStream dataSourceStream, char delimiter, char qualifier, + boolean ignoreFirstRecord) { + return new DelimiterPZParser(pzmapXMLStream, dataSourceStream, delimiter, qualifier, ignoreFirstRecord); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.File, char, + * char) + */ + public PZParser newDelimitedParser(File dataSource, char delimiter, char qualifier) { + return new DelimiterPZParser(dataSource, delimiter, qualifier, false); + } + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.PZParserFactory#newParser(java.io.InputStream, + * char, char) + */ + public PZParser newDelimitedParser(InputStream dataSourceStream, char delimiter, char qualifier) { + return new DelimiterPZParser(dataSourceStream, delimiter, qualifier, false); + } + +} Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DelimiterPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DelimiterPZParser.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DelimiterPZParser.java 2006-10-27 14:06:22 UTC (rev 142) @@ -0,0 +1,68 @@ +/** + * + */ +package net.sf.pzfilereader; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +import net.sf.pzfilereader.util.ParserUtils; +import net.sf.pzfilereader.xml.PZMapParser; + +import org.jdom.JDOMException; + +/** + * @author xhensevb + * + */ +public class DelimiterPZParser extends AbstractDelimiterPZParser { + private InputStream pzmapXMLStream = null; + + private File pzmapXML = null; + + public DelimiterPZParser(File pzmapXML, File dataSource, char delimiter, char qualifier, boolean ignoreFirstRecord) { + super(dataSource, delimiter, qualifier, ignoreFirstRecord); + this.pzmapXML = pzmapXML; + } + + public DelimiterPZParser(InputStream pzmapXMLStream, InputStream dataSourceStream, char delimiter, char qualifier, + boolean ignoreFirstRecord) { + super(dataSourceStream, delimiter, qualifier, ignoreFirstRecord); + this.pzmapXMLStream = pzmapXMLStream; + } + + public DelimiterPZParser(File dataSource, char delimiter, char qualifier, boolean ignoreFirstRecord) { + super(dataSource, delimiter, qualifier, ignoreFirstRecord); + } + + public DelimiterPZParser(InputStream dataSourceStream, char delimiter, char qualifier, boolean ignoreFirstRecord) { + super(dataSourceStream, delimiter, qualifier, ignoreFirstRecord); + } + + protected void init() throws InitialisationException { + try { + if (pzmapXMLStream != null) { + setColumnMD(PZMapParser.parse(pzmapXMLStream)); + } else if (pzmapXML != null) { + InputStream stream = ParserUtils.createInputStream(pzmapXML); + try { + setColumnMD(PZMapParser.parse(stream)); + } finally { + if (stream != null) { + stream.close(); + } + } + } + setInitialised(true); + } catch (JDOMException e) { + throw new InitialisationException(e); + } catch (IOException e) { + throw new InitialisationException(e); + } + } + + protected boolean shouldCreateMDFromFile() { + return pzmapXML == null && pzmapXMLStream == null; + } +} \ No newline at end of file Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/FixedLengthPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/FixedLengthPZParser.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/FixedLengthPZParser.java 2006-10-27 14:06:22 UTC (rev 142) @@ -0,0 +1,54 @@ +/** + * + */ +package net.sf.pzfilereader; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +import net.sf.pzfilereader.util.ParserUtils; +import net.sf.pzfilereader.xml.PZMapParser; + +import org.jdom.JDOMException; + +/** + * @author xhensevb + * + */ +public class FixedLengthPZParser extends AbstractFixedLengthPZParser { + private InputStream pzmapXMLStream; + + private File pzmapXML; + + public FixedLengthPZParser(final InputStream pzmapXMLStream, final InputStream dataSourceStream) { + super(dataSourceStream); + this.pzmapXMLStream = pzmapXMLStream; + } + + public FixedLengthPZParser(File pzmapXML, File dataSource) { + super(dataSource); + this.pzmapXML = pzmapXML; + } + + protected void init() throws InitialisationException { + try { + if (pzmapXMLStream != null) { + setColumnMD(PZMapParser.parse(pzmapXMLStream)); + } else { + InputStream stream = ParserUtils.createInputStream(pzmapXML); + try { + setColumnMD(PZMapParser.parse(stream)); + } finally { + if (stream != null) { + stream.close(); + } + } + } + } catch (JDOMException e) { + throw new InitialisationException(e); + } catch (IOException e) { + throw new InitialisationException(e); + } + } +} Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/IDataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/IDataSet.java 2006-10-27 11:55:43 UTC (rev 141) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/IDataSet.java 2006-10-27 14:06:22 UTC (rev 142) @@ -219,4 +219,42 @@ List getRows(); + /** + * Sets data in the DataSet to lowercase + */ + void setLowerCase(); + + /** + * Sets data in the DataSet to uppercase + */ + void setUpperCase(); + + /** + * Checks to see if the row has the given <RECORD> id + * + * @param recordID + * @return boolean + */ + boolean isRecordID(final String recordID); + + /** + * Sets the absolute position of the record pointer + * + * @param localPointer - + * int + * @exception IndexOutOfBoundsException + */ + void absolute(final int localPointer); + + /** + * Setting this to True will parse text as is and throw a + * NumberFormatException. Setting to false, which is the default, will + * remove any non numeric charcter from the field. The remaining numeric + * chars's will be returned. If it is an empty string,or there are no + * numeric chars, 0 will be returned for getInt() and getDouble() + * + * @param strictNumericParse + * The strictNumericParse to set. + */ + void setStrictNumericParse(final boolean strictNumericParse); } \ No newline at end of file Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/InitialisationException.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/InitialisationException.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/InitialisationException.java 2006-10-27 14:06:22 UTC (rev 142) @@ -0,0 +1,40 @@ +/** + * + */ +package net.sf.pzfilereader; + +/** + * @author xhensevb + * + */ +public class InitialisationException extends RuntimeException { + private static final long serialVersionUID = -4181701730609348676L; + + /** + * + */ + public InitialisationException() { + } + + /** + * @param message + */ + public InitialisationException(String message) { + super(message); + } + + /** + * @param cause + */ + public InitialisationException(Throwable cause) { + super(cause); + } + + /** + * @param message + * @param cause + */ + public InitialisationException(String message, Throwable cause) { + super(message, cause); + } +} Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParserFactory.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParserFactory.java 2006-10-27 11:55:43 UTC (rev 141) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/PZParserFactory.java 2006-10-27 14:06:22 UTC (rev 142) @@ -137,7 +137,7 @@ * @param ignoreFirstRecord - * skips the first line that contains data in the file */ - PZParser newParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition, + PZParser newDelimitedParser(final Connection con, final InputStream dataSourceStream, final String dataDefinition, final char delimiter, final char qualifier, final boolean ignoreFirstRecord); /** @@ -160,7 +160,7 @@ * @param ignoreFirstRecord - * skips the first line that contains data in the file */ - PZParser newParser(final File pzmapXML, final File dataSource, final char delimiter, final char qualifier, + PZParser newDelimitedParser(final File pzmapXML, final File dataSource, final char delimiter, final char qualifier, ... [truncated message content] |
From: <be...@us...> - 2006-10-27 11:55:46
|
Revision: 141 http://svn.sourceforge.net/pzfilereader/?rev=141&view=rev Author: benoitx Date: 2006-10-27 04:55:43 -0700 (Fri, 27 Oct 2006) Log Message: ----------- the DataError should be immutable (i.e. no Set method) Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java 2006-10-27 11:52:52 UTC (rev 140) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java 2006-10-27 11:55:43 UTC (rev 141) @@ -33,7 +33,18 @@ */ private int errorLevel = 0; - /** default constructor */ + + + public DataError(String errorDesc, int lineNo, int errorLevel) { + this.errorDesc = errorDesc; + this.lineNo = lineNo; + this.errorLevel = errorLevel; + } + + /** + * @deprecated should use the ctor with fields + * + */ public DataError() { } @@ -69,6 +80,7 @@ * * @param errorDesc * The errorDesc to set + * @deprecated the DataError should be immutable (i.e. no Set method) */ public void setErrorDesc(final String errorDesc) { this.errorDesc = errorDesc; @@ -79,6 +91,7 @@ * * @param errorLevel * The errorLevel to set + * @deprecated the DataError should be immutable (i.e. no Set method) */ public void setErrorLevel(final int errorLevel) { this.errorLevel = errorLevel; @@ -89,6 +102,7 @@ * * @param lineNo * The lineNo to set + * @deprecated the DataError should be immutable (i.e. no Set method) */ public void setLineNo(final int lineNo) { this.lineNo = lineNo; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |