From: <be...@us...> - 2006-10-17 16:49:25
|
Revision: 69 http://svn.sourceforge.net/pzfilereader/?rev=69&view=rev Author: benoitx Date: 2006-10-17 09:49:14 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Added Paths: ----------- trunk/PZFileReader/src/main/java/net/ trunk/PZFileReader/src/main/java/net/sf/ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-17 16:51:25
|
Revision: 70 http://svn.sourceforge.net/pzfilereader/?rev=70&view=rev Author: benoitx Date: 2006-10-17 09:51:10 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Moved remotely Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/Version.java Removed Paths: ------------- trunk/PZFileReader/src/main/java/com/pz/reader/Version.java Deleted: trunk/PZFileReader/src/main/java/com/pz/reader/Version.java =================================================================== --- trunk/PZFileReader/src/main/java/com/pz/reader/Version.java 2006-10-17 16:49:14 UTC (rev 69) +++ trunk/PZFileReader/src/main/java/com/pz/reader/Version.java 2006-10-17 16:51:10 UTC (rev 70) @@ -1,23 +0,0 @@ -/* - 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 - - 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 com.pz.reader; - -/** - * - * Static class which stores the version of this pzFileReader - */ -public class Version { - public static final String VERSION = "2.2.2"; -} Copied: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/Version.java (from rev 69, trunk/PZFileReader/src/main/java/com/pz/reader/Version.java) =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/Version.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/Version.java 2006-10-17 16:51:10 UTC (rev 70) @@ -0,0 +1,23 @@ +/* + 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 + + 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 com.pz.reader; + +/** + * + * Static class which stores the version of this pzFileReader + */ +public class Version { + public static final String VERSION = "2.2.2"; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-17 16:52:09
|
Revision: 71 http://svn.sourceforge.net/pzfilereader/?rev=71&view=rev Author: benoitx Date: 2006-10-17 09:51:42 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Moved remotely Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java Removed Paths: ------------- trunk/PZFileReader/src/main/java/com/pz/reader/LargeDataSet.java Deleted: trunk/PZFileReader/src/main/java/com/pz/reader/LargeDataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/com/pz/reader/LargeDataSet.java 2006-10-17 16:51:10 UTC (rev 70) +++ trunk/PZFileReader/src/main/java/com/pz/reader/LargeDataSet.java 2006-10-17 16:51:42 UTC (rev 71) @@ -1,563 +0,0 @@ -/* - 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 - - 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 com.pz.reader; - -import java.io.BufferedReader; -import java.io.File; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import com.pz.reader.ordering.OrderBy; -import com.pz.reader.structure.ColumnMetaData; -import com.pz.reader.structure.Row; -import com.pz.reader.util.ParserUtils; -import com.pz.reader.xml.PZMapParser; - -/** - * @author Paul Zepernick - * - * Provides limited DataSet functionality for large files. This will not read - * the file into memory. The following methods have been disabled previous(), - * goTop(), goBottom(), remove(), getIndex(), absolute(), orderRows() - */ -public class LargeDataSet extends DataSet { - - private static final String DELIMITED_FILE = "delimited"; - - private static final String FIXEDLENGTH_FILE = "fixed"; - - private String fileType; // file type being parsed - - private BufferedReader br = null; // reader used to read the file - - private InputStreamReader isr = null; - - private InputStream is = null; // stream used to read the file - - private int lineCount = 0; // keeps track of the current line being - // procssed in the file - - // used for delimited files - private boolean ignoreFirstRecord = false; - - private boolean createMDFromFile = false; - - private boolean processedFirst = false; - - private String delimiter = null; - - private String qualifier = null; - - private int columnCount = 0; - - /** used for fixed length files, map of record lengths corresponding to the - * ID's in the columnMD array. - */ - private Map recordLengths = null; - - /** - * Constructor based on InputStream. Constructs a new LargeDataSet using the - * PZMAP XML file layout method. This is used for a DELIMITED text file. - * esacpe sequence reference:<br> - * \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param pzmapXMLStream - - * Reference to the xml file holding the pzmap - * @param dataSourceStream - - * text file datasource InputStream to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - */ - public LargeDataSet(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final String delimiter, - final String qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - - this.fileType = DELIMITED_FILE; - this.is = dataSourceStream; - this.isr = new InputStreamReader(is); - this.br = new BufferedReader(this.isr); - this.delimiter = delimiter; - this.qualifier = qualifier; - this.ignoreFirstRecord = ignoreFirstRecord; - setHandleShortLines(handleShortLines); - setColumnMD(PZMapParser.parse(pzmapXMLStream)); - - } - - /** - * Constructs a new LargeDataSet using the first line of data found in the - * text file as the column names. This is used for a DELIMITED text file. - * esacpe sequence reference:<br> - * \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param dataSource - - * text file datasource to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param handleShortLines - - * when flaged as true, lines with less columns then the amount - * of column headers will be added as empty's instead of - * producing an error - * @exception Exception - */ - public LargeDataSet(final File dataSource, final String delimiter, final String qualifier, final boolean handleShortLines) - throws Exception { - this(ParserUtils.createInputStream(dataSource), delimiter, qualifier, handleShortLines); - } - - /** - * Constructs a new LargeDataSet using the first line of data found in the - * text file as the column names. This is used for a DELIMITED text file. - * esacpe sequence reference:<br> - * \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param dataSource - - * text file datasource to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param handleShortLines - - * when flaged as true, lines with less columns then the amount - * of column headers will be added as empty's instead of - * producing an error - * @exception Exception - */ - public LargeDataSet(final InputStream dataSource, final String delimiter, final String qualifier, - final boolean handleShortLines) throws Exception { - this.fileType = DELIMITED_FILE; - setHandleShortLines(handleShortLines); - this.is = dataSource; - this.isr = new InputStreamReader(is); - this.br = new BufferedReader(this.isr); - this.delimiter = delimiter; - this.qualifier = qualifier; - this.ignoreFirstRecord = false; - this.createMDFromFile = true; - } - - /** - * New constructor based on InputStream. Constructs a new LargeDataSet using - * the PZMAP XML file layout method. This is used for a FIXED LENGTH text - * file. - * - * @param pzmapXMLStream - - * Reference to the xml file InputStream holding the pzmap - * @param dataSourceStream - - * Delimited file InputStream to read from - * @param handleShortLines - - * Pad lines out to fit the fixed length - * @exception Exception - */ - public LargeDataSet(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final boolean handleShortLines) - throws Exception { - this.fileType = FIXEDLENGTH_FILE; - this.is = dataSourceStream; - this.isr = new InputStreamReader(is); - this.br = new BufferedReader(this.isr); - setHandleShortLines(handleShortLines); - - setColumnMD(PZMapParser.parse(pzmapXMLStream)); - - } - - /** - * Loads up the next record from the file, returns false if EOF - * - * @return boolean - */ - public boolean next() { - try { - if (this.fileType.equals(DELIMITED_FILE)) { - return readNextDelimited(); - } - - // assume fixed length file - return readNextFixedLen(); - } catch (final Exception ex) { - throw new RuntimeException(ex); - } finally { - // Advance the pointer in the DataSet to the first position if - // needed - // we only throw one record into the array at a time - if (super.getIndex() == -1) { - super.next(); - } - } - } - - /** - * Not Supported! - * - * @return boolean - */ - public boolean previous() { - throw new RuntimeException("previous() is Not Implemented For LargeDataSet"); - } - - /** - * Not Supported! - * - * @param excelFileToBeWritten - * @exception Exception - */ - public void writeToExcel(final File excelFileToBeWritten) throws Exception { - throw new RuntimeException("writeToExcel() is Not Implemented For LargeDataSet"); - } - - /** - * Not Supported! - * - * @param ob - - * OrderBy object - * @exception Exception - * @see com.pz.reader.ordering.OrderBy - * @see com.pz.reader.ordering.OrderColumn - */ - public void orderRows(final OrderBy ob) throws Exception { - throw new RuntimeException("orderRows() is Not Implemented For LargeDataSet"); - } - - /** - * Not Supported! - * - * @param localPointer - - * int - * @exception IndexOutOfBoundsException - */ - public void absolute(final int localPointer) { - throw new RuntimeException("absolute() is Not Implemented For LargeDataSet"); - } - - /** - * Not Supported! - */ - public void remove() { - throw new RuntimeException("remove() is Not Implemented For LargeDataSet"); - } - - /** - * Not Supported! - * - * @return int - */ - public int getIndex() { - throw new RuntimeException("getIndex() is Not Implemented For LargeDataSet"); - } - - /** - * Not Supported! - */ - public void goBottom() { - throw new RuntimeException("goBottom() is Not Implemented For LargeDataSet"); - } - - /** - * Not Supported! - */ - public void goTop() { - throw new RuntimeException("goTop() is Not Implemented For LargeDataSet"); - } - - /** - * Not Supported! - * - * @param columnName - - * String Name of the column - * @param value - - * String value to assign to the column. - * @exception Exception - - * exception will be thrown if pointer in not on a valid row - */ - public void setValue(final String columnName, final String value) throws Exception { - throw new RuntimeException("setValue() is Not Implemented For LargeDataSet"); - - } - - /** - * erases the dataset and releases memory for the JVM to reclaim. This will - * also close out the readers used to read the file in. - */ - public void freeMemory() { - super.freeMemory(); - - ParserUtils.closeReader(br); - ParserUtils.closeReader(isr); - ParserUtils.closeReader(is); - } - - // reads the next record and sets it into the row array - private boolean readNextDelimited() throws Exception { - String line = null; - Row row = null; - List columns = null; - boolean processingMultiLine = false; - boolean readRecordOk = false; - String lineData = ""; - String mdkey = null; - List cmds = null; - - if (getRows() == null) { - setRows(new ArrayList()); - } - if (getErrors() == null) { - setErrors(new ArrayList()); - } - - getRows().clear(); - /** loop through each line in the file */ - while ((line = br.readLine()) != null) { - lineCount++; - /** empty line skip past it */ - if (!processingMultiLine && line.trim().length() == 0) { - continue; - } - // check to see if the user has elected to skip the first record - if (!this.processedFirst && this.ignoreFirstRecord) { - this.processedFirst = true; - continue; - } else if (!this.processedFirst && this.createMDFromFile) { - // column names are coming from inside the CSV file - this.processedFirst = true; - setColumnMD(ParserUtils.getColumnMDFromFile(line, delimiter, qualifier)); - 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 = line.trim().toCharArray(); - if (!processingMultiLine && delimiter != null && delimiter.trim().length() > 0) { - processingMultiLine = ParserUtils.isMultiLine(chrArry, delimiter, qualifier); - } - - // check to see if we have reached the end of the linebreak in the - // record - - if (processingMultiLine && lineData.trim().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 (line.trim().endsWith(qualifier) && !line.trim().endsWith(qualifier + qualifier)) { - // it is safe to assume we have reached the end of the line - // break - processingMultiLine = false; - if (lineData.trim().length() > 0) { - 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 (lineData.trim().length() > 0) { - 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.charAt(0)) { - // 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.charAt(0)) { - 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 - columns = ParserUtils.splitLine(lineData, this.delimiter, this.qualifier); - lineData = ""; - mdkey = ParserUtils.getCMDKeyForDelimitedFile(getColumnMD(), columns); - cmds = ParserUtils.getColumnMetaData(mdkey, getColumnMD()); - this.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("TOO MANY COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2); - continue; - } else if (columns.size() < columnCount) { - if (isHandleShortLines()) { - // We can pad this line out - while (columns.size() < columnCount) { - columns.add(""); - } - - // log a warning - addError("PADDED LINE TO CORRECT NUMBER OF COLUMNS", lineCount, 1); - - } else { - addError("TOO FEW COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2); - continue; - } - } - - row = new Row(); - row.setCols(columns); - row.setRowNumber(lineCount); - // with the LargeDataSet we are never going to store more than 1 - // record in memory - getRows().add(row); - readRecordOk = true; - break; - } - - return readRecordOk; - - } - - private boolean readNextFixedLen() throws Exception { - String line = null; - Row row = null; - int recordLength = 0; - final int aLineCount = 0; - int recPosition = 0; - String mdkey = null; - List cmds = null; - boolean readRecordOk = false; - - if (getRows() == null) { - setRows(new ArrayList()); - } - if (getErrors() == null) { - setErrors(new ArrayList()); - } - - if (this.recordLengths == null) { - this.recordLengths = ParserUtils.calculateRecordLengths(getColumnMD()); - } - - getRows().clear(); - // loop through each line in the file - while ((line = br.readLine()) != null) { - this.lineCount++; - // empty line skip past it - if (line.trim().length() == 0) { - continue; - } - - mdkey = ParserUtils.getCMDKeyForFixedLengthFile(getColumnMD(), line); - recordLength = ((Integer) recordLengths.get(mdkey)).intValue(); - cmds = ParserUtils.getColumnMetaData(mdkey, getColumnMD()); - - // Incorrect record length on line log the error. Line will not be - // included in the - // dataset - if (line.length() > recordLength) { - addError("LINE TOO LONG. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, aLineCount, 2); - continue; - } else if (line.length() < recordLength) { - if (isHandleShortLines()) { - // We can pad this line out - while (line.length() < recordLength) { - line += ParserUtils.padding(recordLength-line.length(), ' '); - } - - // log a warning - addError("PADDED LINE TO CORRECT RECORD LENGTH", aLineCount, 1); - - } else { - addError("LINE TOO SHORT. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, aLineCount, 2); - continue; - } - } - - recPosition = 1; - row = new Row(); - row.setMdkey(mdkey.equals("detail") ? null : mdkey); // try to - // limit the - // memory - // use - // Build the columns for the row - for (int i = 0; i < cmds.size(); i++) { - String tempValue = null; - tempValue = line.substring(recPosition - 1, recPosition + (((ColumnMetaData) cmds.get(i)).getColLength() - 1)); - recPosition += ((ColumnMetaData) cmds.get(i)).getColLength(); - row.addColumn(tempValue.trim()); - } - row.setRowNumber(aLineCount); - // add the row to the array - getRows().add(row); - - readRecordOk = true; - break; - } - - return readRecordOk; - - } -} Copied: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java (from rev 70, trunk/PZFileReader/src/main/java/com/pz/reader/LargeDataSet.java) =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java 2006-10-17 16:51:42 UTC (rev 71) @@ -0,0 +1,563 @@ +/* + 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 + + 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 com.pz.reader; + +import java.io.BufferedReader; +import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.pz.reader.ordering.OrderBy; +import com.pz.reader.structure.ColumnMetaData; +import com.pz.reader.structure.Row; +import com.pz.reader.util.ParserUtils; +import com.pz.reader.xml.PZMapParser; + +/** + * @author Paul Zepernick + * + * Provides limited DataSet functionality for large files. This will not read + * the file into memory. The following methods have been disabled previous(), + * goTop(), goBottom(), remove(), getIndex(), absolute(), orderRows() + */ +public class LargeDataSet extends DataSet { + + private static final String DELIMITED_FILE = "delimited"; + + private static final String FIXEDLENGTH_FILE = "fixed"; + + private String fileType; // file type being parsed + + private BufferedReader br = null; // reader used to read the file + + private InputStreamReader isr = null; + + private InputStream is = null; // stream used to read the file + + private int lineCount = 0; // keeps track of the current line being + // procssed in the file + + // used for delimited files + private boolean ignoreFirstRecord = false; + + private boolean createMDFromFile = false; + + private boolean processedFirst = false; + + private String delimiter = null; + + private String qualifier = null; + + private int columnCount = 0; + + /** used for fixed length files, map of record lengths corresponding to the + * ID's in the columnMD array. + */ + private Map recordLengths = null; + + /** + * Constructor based on InputStream. Constructs a new LargeDataSet using the + * PZMAP XML file layout method. This is used for a DELIMITED text file. + * esacpe sequence reference:<br> + * \n newline <br> + * \t tab <br> + * \b backspace <br> + * \r return <br> + * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote + * + * @param pzmapXMLStream - + * Reference to the xml file holding the pzmap + * @param dataSourceStream - + * text file datasource InputStream to read from + * @param delimiter - + * Char the file is delimited By + * @param qualifier - + * Char text is qualified by + * @param ignoreFirstRecord - + * skips the first line that contains data in the file + * @param handleShortLines - + * Adds missing columns as empty's to the DataSet instead of + * logging them as an error + * @exception Exception + */ + public LargeDataSet(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final String delimiter, + final String qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { + + this.fileType = DELIMITED_FILE; + this.is = dataSourceStream; + this.isr = new InputStreamReader(is); + this.br = new BufferedReader(this.isr); + this.delimiter = delimiter; + this.qualifier = qualifier; + this.ignoreFirstRecord = ignoreFirstRecord; + setHandleShortLines(handleShortLines); + setColumnMD(PZMapParser.parse(pzmapXMLStream)); + + } + + /** + * Constructs a new LargeDataSet using the first line of data found in the + * text file as the column names. This is used for a DELIMITED text file. + * esacpe sequence reference:<br> + * \n newline <br> + * \t tab <br> + * \b backspace <br> + * \r return <br> + * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote + * + * @param dataSource - + * text file datasource to read from + * @param delimiter - + * Char the file is delimited By + * @param qualifier - + * Char text is qualified by + * @param handleShortLines - + * when flaged as true, lines with less columns then the amount + * of column headers will be added as empty's instead of + * producing an error + * @exception Exception + */ + public LargeDataSet(final File dataSource, final String delimiter, final String qualifier, final boolean handleShortLines) + throws Exception { + this(ParserUtils.createInputStream(dataSource), delimiter, qualifier, handleShortLines); + } + + /** + * Constructs a new LargeDataSet using the first line of data found in the + * text file as the column names. This is used for a DELIMITED text file. + * esacpe sequence reference:<br> + * \n newline <br> + * \t tab <br> + * \b backspace <br> + * \r return <br> + * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote + * + * @param dataSource - + * text file datasource to read from + * @param delimiter - + * Char the file is delimited By + * @param qualifier - + * Char text is qualified by + * @param handleShortLines - + * when flaged as true, lines with less columns then the amount + * of column headers will be added as empty's instead of + * producing an error + * @exception Exception + */ + public LargeDataSet(final InputStream dataSource, final String delimiter, final String qualifier, + final boolean handleShortLines) throws Exception { + this.fileType = DELIMITED_FILE; + setHandleShortLines(handleShortLines); + this.is = dataSource; + this.isr = new InputStreamReader(is); + this.br = new BufferedReader(this.isr); + this.delimiter = delimiter; + this.qualifier = qualifier; + this.ignoreFirstRecord = false; + this.createMDFromFile = true; + } + + /** + * New constructor based on InputStream. Constructs a new LargeDataSet using + * the PZMAP XML file layout method. This is used for a FIXED LENGTH text + * file. + * + * @param pzmapXMLStream - + * Reference to the xml file InputStream holding the pzmap + * @param dataSourceStream - + * Delimited file InputStream to read from + * @param handleShortLines - + * Pad lines out to fit the fixed length + * @exception Exception + */ + public LargeDataSet(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final boolean handleShortLines) + throws Exception { + this.fileType = FIXEDLENGTH_FILE; + this.is = dataSourceStream; + this.isr = new InputStreamReader(is); + this.br = new BufferedReader(this.isr); + setHandleShortLines(handleShortLines); + + setColumnMD(PZMapParser.parse(pzmapXMLStream)); + + } + + /** + * Loads up the next record from the file, returns false if EOF + * + * @return boolean + */ + public boolean next() { + try { + if (this.fileType.equals(DELIMITED_FILE)) { + return readNextDelimited(); + } + + // assume fixed length file + return readNextFixedLen(); + } catch (final Exception ex) { + throw new RuntimeException(ex); + } finally { + // Advance the pointer in the DataSet to the first position if + // needed + // we only throw one record into the array at a time + if (super.getIndex() == -1) { + super.next(); + } + } + } + + /** + * Not Supported! + * + * @return boolean + */ + public boolean previous() { + throw new RuntimeException("previous() is Not Implemented For LargeDataSet"); + } + + /** + * Not Supported! + * + * @param excelFileToBeWritten + * @exception Exception + */ + public void writeToExcel(final File excelFileToBeWritten) throws Exception { + throw new RuntimeException("writeToExcel() is Not Implemented For LargeDataSet"); + } + + /** + * Not Supported! + * + * @param ob - + * OrderBy object + * @exception Exception + * @see com.pz.reader.ordering.OrderBy + * @see com.pz.reader.ordering.OrderColumn + */ + public void orderRows(final OrderBy ob) throws Exception { + throw new RuntimeException("orderRows() is Not Implemented For LargeDataSet"); + } + + /** + * Not Supported! + * + * @param localPointer - + * int + * @exception IndexOutOfBoundsException + */ + public void absolute(final int localPointer) { + throw new RuntimeException("absolute() is Not Implemented For LargeDataSet"); + } + + /** + * Not Supported! + */ + public void remove() { + throw new RuntimeException("remove() is Not Implemented For LargeDataSet"); + } + + /** + * Not Supported! + * + * @return int + */ + public int getIndex() { + throw new RuntimeException("getIndex() is Not Implemented For LargeDataSet"); + } + + /** + * Not Supported! + */ + public void goBottom() { + throw new RuntimeException("goBottom() is Not Implemented For LargeDataSet"); + } + + /** + * Not Supported! + */ + public void goTop() { + throw new RuntimeException("goTop() is Not Implemented For LargeDataSet"); + } + + /** + * Not Supported! + * + * @param columnName - + * String Name of the column + * @param value - + * String value to assign to the column. + * @exception Exception - + * exception will be thrown if pointer in not on a valid row + */ + public void setValue(final String columnName, final String value) throws Exception { + throw new RuntimeException("setValue() is Not Implemented For LargeDataSet"); + + } + + /** + * erases the dataset and releases memory for the JVM to reclaim. This will + * also close out the readers used to read the file in. + */ + public void freeMemory() { + super.freeMemory(); + + ParserUtils.closeReader(br); + ParserUtils.closeReader(isr); + ParserUtils.closeReader(is); + } + + // reads the next record and sets it into the row array + private boolean readNextDelimited() throws Exception { + String line = null; + Row row = null; + List columns = null; + boolean processingMultiLine = false; + boolean readRecordOk = false; + String lineData = ""; + String mdkey = null; + List cmds = null; + + if (getRows() == null) { + setRows(new ArrayList()); + } + if (getErrors() == null) { + setErrors(new ArrayList()); + } + + getRows().clear(); + /** loop through each line in the file */ + while ((line = br.readLine()) != null) { + lineCount++; + /** empty line skip past it */ + if (!processingMultiLine && line.trim().length() == 0) { + continue; + } + // check to see if the user has elected to skip the first record + if (!this.processedFirst && this.ignoreFirstRecord) { + this.processedFirst = true; + continue; + } else if (!this.processedFirst && this.createMDFromFile) { + // column names are coming from inside the CSV file + this.processedFirst = true; + setColumnMD(ParserUtils.getColumnMDFromFile(line, delimiter, qualifier)); + 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 = line.trim().toCharArray(); + if (!processingMultiLine && delimiter != null && delimiter.trim().length() > 0) { + processingMultiLine = ParserUtils.isMultiLine(chrArry, delimiter, qualifier); + } + + // check to see if we have reached the end of the linebreak in the + // record + + if (processingMultiLine && lineData.trim().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 (line.trim().endsWith(qualifier) && !line.trim().endsWith(qualifier + qualifier)) { + // it is safe to assume we have reached the end of the line + // break + processingMultiLine = false; + if (lineData.trim().length() > 0) { + 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 (lineData.trim().length() > 0) { + 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.charAt(0)) { + // 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.charAt(0)) { + 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 + columns = ParserUtils.splitLine(lineData, this.delimiter, this.qualifier); + lineData = ""; + mdkey = ParserUtils.getCMDKeyForDelimitedFile(getColumnMD(), columns); + cmds = ParserUtils.getColumnMetaData(mdkey, getColumnMD()); + this.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("TOO MANY COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2); + continue; + } else if (columns.size() < columnCount) { + if (isHandleShortLines()) { + // We can pad this line out + while (columns.size() < columnCount) { + columns.add(""); + } + + // log a warning + addError("PADDED LINE TO CORRECT NUMBER OF COLUMNS", lineCount, 1); + + } else { + addError("TOO FEW COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2); + continue; + } + } + + row = new Row(); + row.setCols(columns); + row.setRowNumber(lineCount); + // with the LargeDataSet we are never going to store more than 1 + // record in memory + getRows().add(row); + readRecordOk = true; + break; + } + + return readRecordOk; + + } + + private boolean readNextFixedLen() throws Exception { + String line = null; + Row row = null; + int recordLength = 0; + final int aLineCount = 0; + int recPosition = 0; + String mdkey = null; + List cmds = null; + boolean readRecordOk = false; + + if (getRows() == null) { + setRows(new ArrayList()); + } + if (getErrors() == null) { + setErrors(new ArrayList()); + } + + if (this.recordLengths == null) { + this.recordLengths = ParserUtils.calculateRecordLengths(getColumnMD()); + } + + getRows().clear(); + // loop through each line in the file + while ((line = br.readLine()) != null) { + this.lineCount++; + // empty line skip past it + if (line.trim().length() == 0) { + continue; + } + + mdkey = ParserUtils.getCMDKeyForFixedLengthFile(getColumnMD(), line); + recordLength = ((Integer) recordLengths.get(mdkey)).intValue(); + cmds = ParserUtils.getColumnMetaData(mdkey, getColumnMD()); + + // Incorrect record length on line log the error. Line will not be + // included in the + // dataset + if (line.length() > recordLength) { + addError("LINE TOO LONG. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, aLineCount, 2); + continue; + } else if (line.length() < recordLength) { + if (isHandleShortLines()) { + // We can pad this line out + while (line.length() < recordLength) { + line += ParserUtils.padding(recordLength-line.length(), ' '); + } + + // log a warning + addError("PADDED LINE TO CORRECT RECORD LENGTH", aLineCount, 1); + + } else { + addError("LINE TOO SHORT. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, aLineCount, 2); + continue; + } + } + + recPosition = 1; + row = new Row(); + row.setMdkey(mdkey.equals("detail") ? null : mdkey); // try to + // limit the + // memory + // use + // Build the columns for the row + for (int i = 0; i < cmds.size(); i++) { + String tempValue = null; + tempValue = line.substring(recPosition - 1, recPosition + (((ColumnMetaData) cmds.get(i)).getColLength() - 1)); + recPosition += ((ColumnMetaData) cmds.get(i)).getColLength(); + row.addColumn(tempValue.trim()); + } + row.setRowNumber(aLineCount); + // add the row to the array + getRows().add(row); + + readRecordOk = true; + break; + } + + return readRecordOk; + + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-17 16:52:58
|
Revision: 72 http://svn.sourceforge.net/pzfilereader/?rev=72&view=rev Author: benoitx Date: 2006-10-17 09:52:35 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Moved remotely Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java Removed Paths: ------------- trunk/PZFileReader/src/main/java/com/pz/reader/DataSet.java Deleted: trunk/PZFileReader/src/main/java/com/pz/reader/DataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/com/pz/reader/DataSet.java 2006-10-17 16:51:42 UTC (rev 71) +++ trunk/PZFileReader/src/main/java/com/pz/reader/DataSet.java 2006-10-17 16:52:35 UTC (rev 72) @@ -1,1274 +0,0 @@ -/* - 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 - - 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 com.pz.reader; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.Statement; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.NoSuchElementException; - -import com.pz.reader.ordering.OrderBy; -import com.pz.reader.structure.ColumnMetaData; -import com.pz.reader.structure.Row; -import com.pz.reader.util.ExcelTransformer; -import com.pz.reader.util.ParserUtils; -import com.pz.reader.xml.PZMapParser; - -/** - * This class parses a datafile and holds methods to scroll back and forth - * through the datafile along with methods to retreive values from columns. - * - * @author Paul Zepernick - * @version 2.0.1 - */ -public class DataSet { - - /** Array to hold the rows and their values in the text file */ - private List rows = null; - - /** Array of errors that have occured during processing */ - private List errors = null; - - /** Map of column metadata's */ - private Map columnMD = null; - - /** 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; - - /** - * Flag to indicate that we can cope with lines shorter than the required - * lengh - */ - private boolean handleShortLines = false; - - /** - * empty constructor. THIS SHOULD ONLY BE USED FOR CUSTOM DataSet - * implementations. It provides NO parsing abilities - */ - public DataSet() { - } - - /** - * Constructs a new DataSet using the database table file layout method. - * This is used for a FIXED LENGTH text file. - * - * @param con - - * Connection to database with DATAFILE and DATASTRUCTURE tables - * @param dataSource - - * Fixed length file to read from - * @param dataDefinition - - * Name of dataDefinition in the DATAFILE table DATAFILE_DESC - * column - * @param handleShortLines - - * Pad lines out to fit the fixed length - * @exception Exception - */ - public DataSet(final Connection con, final File dataSource, final String dataDefinition, final boolean handleShortLines) - throws Exception { - this(con, ParserUtils.createInputStream(dataSource), dataDefinition, handleShortLines); - } - - /** - * Constructs a new DataSet using the database table file layout method. - * This is used for a FIXED LENGTH text file. - * - * @param con - - * Connection to database with DATAFILE and DATASTRUCTURE tables - * @param dataSourceStream - - * text file datasource InputStream to read from - * @param dataDefinition - - * Name of dataDefinition in the DATAFILE table DATAFILE_DESC - * column - * @param handleShortLines - - * Pad lines out to fit the fixed length - * @exception Exception - */ - public DataSet(final Connection con, final InputStream dataSourceStream, final String dataDefinition, - final boolean handleShortLines) throws Exception { - super(); - this.handleShortLines = handleShortLines; - - String sql = null; - ResultSet rs = null; - Statement stmt = null; - ColumnMetaData column = null; - boolean hasResults = false; - int recPosition = 1; - final List cmds = new ArrayList(); - - try { - columnMD = new LinkedHashMap(); - stmt = con.createStatement(); - - sql = "SELECT * FROM DATAFILE INNER JOIN DATASTRUCTURE ON " + "DATAFILE.DATAFILE_NO = DATASTRUCTURE.DATAFILE_NO " - + "WHERE DATAFILE.DATAFILE_DESC = '" + dataDefinition + "' " + "ORDER BY DATASTRUCTURE_COL_ORDER"; - - rs = stmt.executeQuery(sql); - - // put array of columns together. These will be used to put together - // the dataset when reading in the file - while (rs.next()) { - - 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); - - hasResults = true; - } - - columnMD.put("detail", cmds); - - if (!hasResults) { - throw new FileNotFoundException("DATA DEFINITION CAN NOT BE FOUND IN THE DATABASE " + dataDefinition); - } - - // read in the fixed length file and construct the DataSet object - doFixedLengthFile(dataSourceStream); - - } finally { - if (rs != null) { - rs.close(); - } - if (stmt != null) { - stmt.close(); - } - } - - } - - /** - * Constructs a new DataSet using the database table file layout method. - * This is used for a DELIMITED text file. esacpe sequence reference: \n - * newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param con - - * Connection to database with DATAFILE and DATASTRUCTURE tables - * @param dataSource - - * text file datasource to read from - * @param dataDefinition - - * Name of dataDefinition in the DATAFILE table DATAFILE_DESC - * column - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - */ - public DataSet(final Connection con, final File dataSource, final String dataDefinition, final String delimiter, - final String qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - this(con, ParserUtils.createInputStream(dataSource), dataDefinition, delimiter, qualifier, ignoreFirstRecord, - handleShortLines); - } - - /** - * New constructor based on InputStream. Constructs a new DataSet using the - * database table file layout method. This is used for a DELIMITED text - * file. esacpe sequence reference: \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param con - - * Connection to database with DATAFILE and DATASTRUCTURE tables - * @param dataSourceStream - - * text file datasource InputStream to read from - * @param dataDefinition - - * Name of dataDefinition in the DATAFILE table DATAFILE_DESC - * column - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - */ - public DataSet(final Connection con, final InputStream dataSourceStream, final String dataDefinition, final String delimiter, - final String qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - super(); - - this.handleShortLines = handleShortLines; - - String sql = null; - ResultSet rs = null; - Statement stmt = null; - ColumnMetaData column = null; - boolean hasResults = false; - final List cmds = new ArrayList(); - - try { - columnMD = new LinkedHashMap(); - stmt = con.createStatement(); - - sql = "SELECT * FROM DATAFILE INNER JOIN DATASTRUCTURE ON " + "DATAFILE.DATAFILE_NO = DATASTRUCTURE.DATAFILE_NO " - + "WHERE DATAFILE.DATAFILE_DESC = '" + dataDefinition + "' " + "ORDER BY DATASTRUCTURE_COL_ORDER"; - - rs = stmt.executeQuery(sql); - - // put array of columns together. These will be used to put together - // the dataset when reading in the file - while (rs.next()) { - - column = new ColumnMetaData(); - column.setColName(rs.getString("DATASTRUCTURE_COLUMN")); - column.setColLength(rs.getInt("DATASTRUCTURE_LENGTH")); - cmds.add(column); - - hasResults = true; - } - - columnMD.put("detail", cmds); - - if (!hasResults) { - throw new FileNotFoundException("DATA DEFINITION CAN NOT BE FOUND IN THE DATABASE " + dataDefinition); - } - - // read in the fixed length file and construct the DataSet object - doDelimitedFile(dataSourceStream, delimiter, qualifier, ignoreFirstRecord, false); - - } finally { - if (rs != null) { - rs.close(); - } - if (stmt != null) { - stmt.close(); - } - } - - } - - /** - * Constructs a new DataSet using the PZMAP XML file layout method. This is - * used for a DELIMITED text file. esacpe sequence reference: \n newline - * <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param pzmapXML - - * Reference to the xml file holding the pzmap - * @param dataSource - - * text file datasource to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - */ - public DataSet(final File pzmapXML, final File dataSource, final String delimiter, final String qualifier, - final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - 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. - * esacpe sequence reference: \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param pzmapXMLStream - - * Reference to the xml file holding the pzmap - * @param dataSourceStream - - * text file datasource InputStream to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param ignoreFirstRecord - - * skips the first line that contains data in the file - * @param handleShortLines - - * Adds missing columns as empty's to the DataSet instead of - * logging them as an error - * @exception Exception - */ - public DataSet(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final String delimiter, - final String qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { - - this.handleShortLines = handleShortLines; - columnMD = PZMapParser.parse(pzmapXMLStream); - - doDelimitedFile(dataSourceStream, delimiter, qualifier, ignoreFirstRecord, false); - - } - - /** - * Constructs a new DataSet using the first line of data found in the text - * file as the column names. This is used for a DELIMITED text file. esacpe - * sequence reference: \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param dataSource - - * text file datasource to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param handleShortLines - - * when flaged as true, lines with less columns then the amount - * of column headers will be added as empty's instead of - * producing an error - * @exception Exception - */ - public DataSet(final File dataSource, final String delimiter, final String qualifier, final boolean handleShortLines) - throws Exception { - - this.handleShortLines = handleShortLines; - InputStream dataSourceStream = null; - - try { - dataSourceStream = ParserUtils.createInputStream(dataSource); - doDelimitedFile(dataSourceStream, delimiter, qualifier, false, true); - } finally { - if (dataSourceStream != null) { - dataSourceStream.close(); - } - } - } - - /** - * Constructs a new DataSet using the first line of data found in the text - * file as the column names. This is used for a DELIMITED text file. esacpe - * sequence reference: \n newline <br> - * \t tab <br> - * \b backspace <br> - * \r return <br> - * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote - * - * @param dataSource - - * text file InputStream to read from - * @param delimiter - - * Char the file is delimited By - * @param qualifier - - * Char text is qualified by - * @param handleShortLines - - * when flaged as true, lines with less columns then the amount - * of column headers will be added as empty's instead of - * producing an error - * @exception Exception - */ - public DataSet(final InputStream dataSource, final String delimiter, final String qualifier, final boolean handleShortLines) - throws Exception { - - this.handleShortLines = handleShortLines; - - try { - doDelimitedFile(dataSource, delimiter, qualifier, false, true); - } finally { - if (dataSource != null) { - dataSource.close(); - } - } - } - - /** - * Constructs a new DataSet using the PZMAP XML file layout method. This is - * used for a FIXED LENGTH text file. - * - * @param pzmapXML - - * Reference to the xml file holding the pzmap - * @param dataSource - - * Delimited file to read from - * @param handleShortLines - - * Pad lines out to fit the fixed length - * @exception Exception - */ - public DataSet(final File pzmapXML, final File dataSource, final boolean handleShortLines) throws Exception { - this(ParserUtils.createInputStream(pzmapXML), ParserUtils.createInputStream(dataSource), handleShortLines); - } - - /** - * New constructor based on InputStream. Constructs a new DataSet using the - * PZMAP XML file layout method. This is used for a FIXED LENGTH text file. - * - * @param pzmapXMLStream - - * Reference to the xml file InputStream holding the pzmap - * @param dataSourceStream - - * Delimited file InputStream to read from - * @param handleShortLines - - * Pad lines out to fit the fixed length - * @exception Exception - */ - public DataSet(final InputStream pzmapXMLStream, final InputStream dataSourceStream, final boolean handleShortLines) - throws Exception { - - this.handleShortLines = handleShortLines; - - columnMD = PZMapParser.parse(pzmapXMLStream); - - // read in the fixed length file and construct the DataSet object - doFixedLengthFile(dataSourceStream); - - } - - /* - * 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 void doFixedLengthFile(final InputStream dataSource) throws Exception { - String line = null; - InputStreamReader isr = null; - BufferedReader br = null; - Row row = null; - int recordLength = 0; - int lineCount = 0; - int recPosition = 0; - // map of record lengths corrisponding to the ID's in the columnMD array - Map recordLengths = null; - String mdkey = null; - List cmds = null; - - try { - rows = new ArrayList(); - errors = new ArrayList(); - - recordLengths = ParserUtils.calculateRecordLengths(columnMD); - - // Read in the flat file - isr = new InputStreamReader(dataSource); - br = new BufferedReader(isr); - // loop through each line in the file - while ((line = br.readLine()) != null) { - lineCount++; - // empty line skip past it - if (line.trim().length() == 0) { - continue; - } - - mdkey = ParserUtils.getCMDKeyForFixedLengthFile(columnMD, line); - recordLength = ((Integer) recordLengths.get(mdkey)).intValue(); - cmds = ParserUtils.getColumnMetaData(mdkey, columnMD); - - // Incorrect record length on line log the error. Line will not - // be included in the - // dataset - if (line.length() > recordLength) { - addError("LINE TOO LONG. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2); - continue; - } else if (line.length() < recordLength) { - if (handleShortLines) { - // We can pad this line out - while (line.length() < recordLength) { - line = line + " "; - } - - // log a warning - addError("PADDED LINE TO CORRECT RECORD LENGTH", lineCount, 1); - - } else { - addError("LINE TOO SHORT. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2); - continue; - } - } - - recPosition = 1; - row = new Row(); - row.setMdkey(mdkey.equals("detail") ? null : mdkey); // try - // to - // limit - // the - // memory - // use - // Build the columns for the row - for (int i = 0; i < cmds.size(); i++) { - String tempValue = null; - 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); - } - } finally { - if (isr != null) { - isr.close(); - } - if (br != null) { - br.close(); - } - } - } - - /* - * 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 void doDelimitedFile(final InputStream dataSource, final String delimiter, final String qualifier, - final boolean ignoreFirstRecord, final boolean createMDFromFile) throws Exception { - if (dataSource == null) { - throw new NullPointerException("dataSource is null"); - } - String line = null; - - InputStreamReader isr = null; - BufferedReader br = null; - Row row = null; - int columnCount = 0; - int lineCount = 0; - List columns = null; - boolean processedFirst = false; - boolean processingMultiLine = false; - String lineData = ""; - List cmds = null; - String mdkey = null; - - try { - rows = new ArrayList(); - errors = new ArrayList(); - - // 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); - /** loop through each line in the file */ - while ((line = br.readLine()) != null) { - lineCount++; - /** empty line skip past it */ - if (!processingMultiLine && line.trim().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; - columnMD = ParserUtils.getColumnMDFromFile(line, delimiter, qualifier); - 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 = line.trim().toCharArray(); - if (!processingMultiLine && delimiter != null && delimiter.trim().length() > 0) { - processingMultiLine = ParserUtils.isMultiLine(chrArry, delimiter, qualifier); - } - - // check to see if we have reached the end of the linebreak in - // the record - - if (processingMultiLine && lineData.trim().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 (line.trim().endsWith(qualifier) && !line.trim().endsWith(qualifier + qualifier)) { - // it is safe to assume we have reached the end of the - // line break - processingMultiLine = false; - if (lineData.trim().length() > 0) { - 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 (lineData.trim().length() > 0) { - 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.charAt(0)) { - // 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.charAt(0)) { - 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 - columns = ParserUtils.splitLine(lineData, delimiter, qualifier); - lineData = ""; - mdkey = ParserUtils.getCMDKeyForDelimitedFile(columnMD, columns); - cmds = ParserUtils.getColumnMetaData(mdkey, columnMD); - 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("TOO MANY COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2); - continue; - } else if (columns.size() < columnCount) { - if (handleShortLines) { - // We can pad this line out - while (columns.size() < columnCount) { - columns.add(""); - } - - // log a warning - addError("PADDED LINE TO CORRECT NUMBER OF COLUMNS", lineCount, 1); - - } else { - addError("TOO FEW COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2); - continue; - } - } - - row = new Row(); - row.setMdkey(mdkey.equals("detail") ? null : mdkey); // try - // to - // limit - // the - // memory - // use - row.setCols(columns); - row.setRowNumber(lineCount); - /** add the row to the array */ - rows.add(row); - } - } finally { - if (isr != null) { - isr.close(); - } - if (br != null) { - br.close(); - } - } - } - - /** - * Changes the value of a specified column in a row in the set. This change - * is in memory, and does not actually change the data in the file that was - * read in. - * - * @param columnName - - * String Name of the column - * @param value - - * String value to assign to the column. - * @exception Exception - - * exception will be thrown if pointer in not on a valid row - */ - public void setValue(final String columnName, final String value) throws Exception { - Row row = null; - - /** get a reference to the row */ - row = (Row) rows.get(pointer); - final List cmds = ParserUtils.getColumnMetaData(row.getMdkey(), columnMD); - /** change the value of the column */ - row.setValue(ParserUtils.findColumn(columnName, cmds), value); - - } - - /** - * Goes to the top of the data set. This will put the pointer one record - * before the first in the set. Next() will have to be called to get the - * first record after this call. - */ - public void goTop() { - pointer = -1; - } - - /** - * Goes to the last record in the dataset - */ - public void goBottom() { - pointer = rows.size() - 1; - } - - /** - * Moves to the next record in the set. Returns true if move was a success, - * false if not - * - * @return boolean - */ - public boolean next() { - if (pointer < rows.size() && pointer + 1 != rows.size()) { - pointer++; - return true; - } - return false; - } - - /** - * Moves back to the previous record in the set return true if move was a - * success, false if not - * - * @return boolean - */ - public boolean previous() { - if (pointer <= 0) { - return false; - } - pointer--; - return true; - } - - /** - * Returns the string value of a specified column - * - * @param column - - * Name of the column - * @exception NoSuchElementException - * @return String - */ - public String getString(final String column) { - final Row row = (Row) rows.get(pointer); - final List cmds = ParserUtils.getColumnMetaData(row.getMdkey(), columnMD); - - if (upperCase) { - // convert data to uppercase before returning - return row.getValue(ParserUtils.findColumn(column, cmds)).toUpperCase(Locale.getDefault()); - } - - if (lowerCase) { - // convert data to lowercase before returning - return row.getValue(ParserUtils.findColumn(column, cmds)).toLowerCase(Locale.getDefault()); - } - - // return value as how it is in the file - return row.getValue(ParserUtils.findColumn(column, cmds)); - } - - /** - * Returns the double value of a specified column - * - * @param column - - * Name of the column - * @exception NoSuchElementException - * @exception NumberFormatException - * @return double - */ - public double getDouble(final String column) { - String s = null; - final StringBuffer newString = new StringBuffer(); - final String[] allowedChars = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "-" }; - final Row row = (Row) rows.get(pointer); - - final List cmds = ParserUtils.getColumnMetaData(row.getMdkey(), columnMD); - s = ((Row) rows.get(pointer)).getValue(ParserUtils.findColumn(column, cmds)); - - if (!strictNumericParse) { - if (s.trim().length() == 0) { - return 0; - } - for (int i = 0; i < s.length(); i++) { - for (int j = 0; j < allowedChars.length; j++) { - if (s.substring(i, i + 1).equals(allowedChars[j])) { - newString.append(s.substring(i, i + 1)); - break; - } - } - } - 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()); - } - - /** - * Returns the interger value of a specified column - * - * @param column - - * Name of the column - * @exception NoSuchElementException - * @exception NumberFormatException - * @return double - */ - public int getInt(final String column) { - String s = null; - final StringBuffer newString = new StringBuffer(); - final String[] allowedChars = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-" }; - final Row row = (Row) rows.get(pointer); - final List cmds = ParserUtils.getColumnMetaData(row.getMdkey(), columnMD); - - s = row.getValue(ParserUtils.findColumn(column, cmds)); - - if (!strictNumericParse) { - if (s.trim().length() == 0) { - return 0; - } - for (int i = 0; i < s.length(); i++) { - for (int j = 0; j < allowedChars.length; j++) { - if (s.substring(i, i + 1).equals(allowedChars[j])) { - newString.append(s.substring(i, i + 1)); - break; - } - } - } - // 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()); - } - - /** - * Returns the date value of a specified column. This assumes the date is in - * yyyyMMdd. If your date is not in this format, see - * getDate(String,SimpleDateFormat) - * - * @param column - - * Name of the column - * @exception ParseException - * @return Date - */ - public Date getDate(final String column) throws ParseException { - final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); - String s = null; - final Row row = (Row) rows.get(pointer); - final List cmds = ParserUtils.getColumnMetaData(row.getMdkey(), columnMD); - - s = row.getValue(ParserUtils.findColumn(column, cmds)); - return sdf.parse(s); - } - - /** - * Returns the date value of a specified column. This should be used if the - * date is NOT in yyyyMMdd format. The SimpleDateFormat object will specify - * what kind of format the date is in. - * - * @param column - - * Name of the column - * @param sdf - - * SimpleDateFormat of the date - * @exception ParseException - * @see java.text.SimpleDateFormat - * @return Date - */ - public Date getDate(final String column, final SimpleDateFormat sdf) throws ParseException { - String s = null; - final Row row = (Row) rows.get(pointer); - final List cmds = ParserUtils.getColumnMetaData(row.getMdkey(), columnMD); - - s = row.getValue(ParserUtils.findColumn(column, cmds)); - return sdf.parse(s); - } - - /** - * Returns a String array of column names in the DataSet. This will assume - * 'detail' <RECORD> ID. - * - * @return String[] - */ - public String[] getColumns() { - ColumnMetaData column = null; - String[] array = null; - - if (columnMD != null) { - final List cmds = ParserUtils.getColumnMetaData("detail", 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; - } - - /** - * Returns a String array of column names in the DataSet for a given - * <RECORD> id - * - * @param recordID - * @return String[] - */ - public String[] getColumns(final String recordID) { - ColumnMetaData column = null; - 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++) { - column = (ColumnMetaData) cmds.get(i); - array[i] = column.getColName(); - } - } - - return array; - } - - /** - * Returns the line number the pointer is on. These are the actual line - * numbers from the flat file, before any sorting. - * - * @exception NoSuchElementException - * @exception NumberFormatException - * @return int - */ - public int getRowNo() { - return ((Row) rows.get(pointer)).getRowNumber(); - } - - /** - * Returns A Collection Of DataErrors that happened during processing - * - * @return Vector - */ - public List getErrors() { - return errors; - } - - /** - * 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 - */ - public void addError(final String errorDesc, final int lineNo, final int errorLevel) { - final DataError de = new DataError(); - de.setErrorDesc(errorDesc); - de.setLineNo(lineNo); - de.setErrorLevel(errorLevel); - errors.add(de); - } - - /** - * Removes a row from the dataset. Once the row is removed the pointer will - * be sitting on the record previous to the deleted row. - */ - public void remove() { - rows.remove(pointer); - pointer--; - } - - /** - * Returns the index the pointer is on for the array - * - * @return int - */ - public int getIndex() { - return pointer; - } - - /** - * 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; - } - - /** - * 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 = "detail"; - } - - return rowID.equals(recordID); - } - - /** - * Returns the total number of rows parsed in from the file - * - * - * @return int - Row Count - */ - public int getRowCount() { - return rows.size(); - } - - /** - * Returns total number of records which contained a parse error in the - * file. - * - * @return int - Record Error Count - */ - public int getErrorCount() { - if (getErrors() != null) { - return getErrors().size(); - } - - return 0; - } - - /** - * Returns true or false as to whether or not the line number contains an - * error. The import will skip the line if it contains an error and it will - * not be processed - * - * @param lineNo - - * int line number - * @return boolean - */ - 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; - } - } - return false; - } - - /** - * Orders the data by column(s) specified. This will reposition the cursor - * to the top of the DataSet when executed. This is currently not supported - * when specying <RECORD> elements in the mapping. An exception will be - * thrown if this situation occurs - * - * @param ob - - * OrderBy object - * @exception Exception - * @see com.pz.reader.ordering.OrderBy - * @see com.pz.reader.ordering.OrderColumn - */ - 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) { - // throw new Exception("orderRows does not currently support ordering with <RECORD> mappings"); - // } - final List cmds = ParserUtils.getColumnMetaData("detail", columnMD); - if (ob != null && rows != null) { - ob.setColumnMD(cmds); - Collections.sort(rows, ob); - goTop(); - } - } - - /** - * 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; - } - - /** - * 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; - } - - /** - * erases the dataset and releases memory for the JVM to reclaim - */ - public void freeMemory() { - if (rows != null) { - rows.clear(); - } - if (errors != null) { - errors.clear(); - } - if (columnMD != null) { - columnMD.clear(); - } - } - - /** - * Writes this current DataSet out to the specified Excel file - * - * @param excelFileToBeWritten - * @exception Exception - */ - public void writeToExcel(final File excelFileToBeWritten) throws Exception { - - final ExcelTransformer et = new ExcelTransformer(this, excelFileToBeWritten); - et.writeExcelFile(); - - } - - /** - * Returns the version number of this pzFileReader - * - * @return String - */ - public String getReaderVersion() { - return Version.VERSION; - } - - /** - * @return Returns the handleShortLines. - */ - public boolean isHandleShortLines() { - return handleShortLines; - } - - /** - * This is used for LargeDataSet compatability. Setting this will have no - * affect on the DataSet parser. It must be passed on the constructor - * - * @param handleShortLines - * The handleShortLines to set. - */ - public void setHandleShortLines(final boolean handleShortLines) { - this.handleShortLines = handleShortLines; - } - - public Map getColumnMD() { - return columnMD; - } - - public void setColumnMD(Map columnMD) { - this.columnMD = columnMD; - } - - public List getRows() { - return rows; - } - - public void setRows(List rows) { - this.rows = rows; - } - - public void setErrors(List errors) { - this.errors = errors; - } -} Copied: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java (from rev 71, trunk/PZFileReader/src/main/java/com/pz/reader/DataSet.java) =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java 2006-10-17 16:52:35 UTC (rev 72) @@ -0,0 +1,1274 @@ +/* + 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 + + 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 com.pz.reader; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.NoSuchElementException; + +import com.pz.reader.ordering.OrderBy; +import com.pz.reader.structure.ColumnMetaData; +import com.pz.reader.structure.Row; +import com.pz.reader.util.ExcelTransformer; +import com.pz.reader.util.ParserUtils; +import com.pz.reader.xml.PZMapParser; + +/** + * This class parses a datafile and holds methods to scroll back and forth + * through the datafile along with methods to retreive values from columns. + * + * @author Paul Zepernick + * @version 2.0.1 + */ +public class DataSet { + + /** Array to hold the rows and their values in the text file */ + private List rows = null; + + /** Array of errors that have occured during processing */ + private List errors = null; + + /** Map of column metadata's */ + private Map columnMD = null; + + /** 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; + + /** + * Flag to indicate that we can cope with lines shorter than the required + * lengh + */ + private boolean handleShortLines = false; + + /** + * empty constructor. THIS SHOULD ONLY BE USED FOR CUSTOM DataSet + * implementations. It provides NO parsing abilities + */ + public DataSet() { + } + + /** + * Constructs a new DataSet using the database table file layout method. + * This is used for a FIXED LENGTH text file. + * + * @param con - + * Connection to database with DATAFILE and DATASTRUCTURE tables + * @param dataSource - + * Fixed length file to read from + * @param dataDefinition - + * Name of dataDefinition in the DATAFILE table DATAFILE_DESC + * column + * @param handleShortLines - + * Pad lines out to fit the fixed length + * @exception Exception + */ + public DataSet(final Connection con, final File dataSource, final String dataDefinition, final boolean handleShortLines) + throws Exception { + this(con, ParserUtils.createInputStream(dataSource), dataDefinition, handleShortLines); + } + + /** + * Constructs a new DataSet using the database table file layout method. + * This is used for a FIXED LENGTH text file. + * + * @param con - + * Connection to database with DATAFILE and DATASTRUCTURE tables + * @param dataSourceStream - + * text file datasource InputStream to read from + * @param dataDefinition - + * Name of dataDefinition in the DATAFILE table DATAFILE_DESC + * column + * @param handleShortLines - + * Pad lines out to fit the fixed length + * @exception Exception + */ + public DataSet(final Connection con, final InputStream dataSourceStream, final String dataDefinition, + final boolean handleShortLines) throws Exception { + super(); + this.handleShortLines = handleShortLines; + + String sql = null; + ResultSet rs = null; + Statement stmt = null; + ColumnMetaData column = null; + boolean hasResults = false; + int recPosition = 1; + final List cmds = new ArrayList(); + + try { + columnMD = new LinkedHashMap(); + stmt = con.createStatement(); + + sql = "SELECT * FROM DATAFILE INNER JOIN DATASTRUCTURE ON " + "DATAFILE.DATAFILE_NO = DATASTRUCTURE.DATAFILE_NO " + + "WHERE DATAFILE.DATAFILE_DESC = '" + dataDefinition + "' " + "ORDER BY DATASTRUCTURE_COL_ORDER"; + + rs = stmt.executeQuery(sql); + + // put array of columns together. These will be used to put together + // the dataset when reading in the file + while (rs.next()) { + + 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); + + hasResults = true; + } + + columnMD.put("detail", cmds); + + if (!hasResults) { + throw new FileNotFoundException("DATA DEFINITION CAN NOT BE FOUND IN THE DATABASE " + dataDefinition); + } + + // read in the fixed length file and construct the DataSet object + doFixedLengthFile(dataSourceStream); + + } finally { + if (rs != null) { + rs.close(); + } + if (stmt != null) { + stmt.close(); + } + } + + } + + /** + * Constructs a new DataSet using the database table file layout method. + * This is used for a DELIMITED text file. esacpe sequence reference: \n + * newline <br> + * \t tab <br> + * \b backspace <br> + * \r return <br> + * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote + * + * @param con - + * Connection to database with DATAFILE and DATASTRUCTURE tables + * @param dataSource - + * text file datasource to read from + * @param dataDefinition - + * Name of dataDefinition in the DATAFILE table DATAFILE_DESC + * column + * @param delimiter - + * Char the file is delimited By + * @param qualifier - + * Char text is qualified by + * @param ignoreFirstRecord - + * skips the first line that contains data in the file + * @param handleShortLines - + * Adds missing columns as empty's to the DataSet instead of + * logging them as an error + * @exception Exception + */ + public DataSet(final Connection con, final File dataSource, final String dataDefinition, final String delimiter, + final String qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { + this(con, ParserUtils.createInputStream(dataSource), dataDefinition, delimiter, qualifier, ignoreFirstRecord, + handleShortLines); + } + + /** + * New constructor based on InputStream. Constructs a new DataSet using the + * database table file layout method. This is used for a DELIMITED text + * file. esacpe sequence reference: \n newline <br> + * \t tab <br> + * \b backspace <br> + * \r return <br> + * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote + * + * @param con - + * Connection to database with DATAFILE and DATASTRUCTURE tables + * @param dataSourceStream - + * text file datasource InputStream to read from + * @param dataDefinition - + * Name of dataDefinition in the DATAFILE table DATAFILE_DESC + * column + * @param delimiter - + * Char the file is delimited By + * @param qualifier - + * Char text is qualified by + * @param ignoreFirstRecord - + * skips the first line that contains data in the file + * @param handleShortLines - + * Adds missing columns as empty's to the DataSet instead of + * logging them as an error + * @exception Exception + */ + public DataSet(final Connection con, final InputStream dataSourceStream, final String dataDefinition, final String delimiter, + final String qualifier, final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { + super(); + + this.handleShortLines = handleShortLines; + + String sql = null; + ResultSet rs = null; + Statement stmt = null; + ColumnMetaData column = null; + boolean hasResults = false; + final List cmds = new ArrayList(); + + try { + columnMD = new LinkedHashMap(); + stmt = con.createStatement(); + + sql = "SELECT * FROM DATAFILE INNER JOIN DATASTRUCTURE ON " + "DATAFILE.DATAFILE_NO = DATASTRUCTURE.DATAFILE_NO " + + "WHERE DATAFILE.DATAFILE_DESC = '" + dataDefinition + "' " + "ORDER BY DATASTRUCTURE_COL_ORDER"; + + rs = stmt.executeQuery(sql); + + // put array of columns together. These will be used to put together + // the dataset when reading in the file + while (rs.next()) { + + column = new ColumnMetaData(); + column.setColName(rs.getString("DATASTRUCTURE_COLUMN")); + column.setColLength(rs.getInt("DATASTRUCTURE_LENGTH")); + cmds.add(column); + + hasResults = true; + } + + columnMD.put("detail", cmds); + + if (!hasResults) { + throw new FileNotFoundException("DATA DEFINITION CAN NOT BE FOUND IN THE DATABASE " + dataDefinition); + } + + // read in the fixed length file and construct the DataSet object + doDelimitedFile(dataSourceStream, delimiter, qualifier, ignoreFirstRecord, false); + + } finally { + if (rs != null) { + rs.close(); + } + if (stmt != null) { + stmt.close(); + } + } + + } + + /** + * Constructs a new DataSet using the PZMAP XML file layout method. This is + * used for a DELIMITED text file. esacpe sequence reference: \n newline + * <br> + * \t tab <br> + * \b backspace <br> + * \r return <br> + * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote + * + * @param pzmapXML - + * Reference to the xml file holding the pzmap + * @param dataSource - + * text file datasource to read from + * @param delimiter - + * Char the file is delimited By + * @param qualifier - + * Char text is qualified by + * @param ignoreFirstRecord - + * skips the first line that contains data in the file + * @param handleShortLines - + * Adds missing columns as empty's to the DataSet instead of + * logging them as an error + * @exception Exception + */ + public DataSet(final File pzmapXML, final File dataSource, final String delimiter, final String qualifier, + final boolean ignoreFirstRecord, final boolean handleShortLines) throws Exception { + 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. + * esacpe sequence reference: \n newline <br> + * \t tab <br> + * \b backspace <br> + * \r return <br> + * \f form feed <br> \\ backslash <br> \' single quote <br> \" double quote + * + * @param pzmapXMLStream - + * Reference to the xml file holding the pzmap + * @param dataSourceStream - + * text file datasource InputStream to re... [truncated message content] |
From: <be...@us...> - 2006-10-17 16:53:59
|
Revision: 73 http://svn.sourceforge.net/pzfilereader/?rev=73&view=rev Author: benoitx Date: 2006-10-17 09:53:24 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Moved remotely Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java Removed Paths: ------------- trunk/PZFileReader/src/main/java/com/pz/reader/DataError.java Deleted: trunk/PZFileReader/src/main/java/com/pz/reader/DataError.java =================================================================== --- trunk/PZFileReader/src/main/java/com/pz/reader/DataError.java 2006-10-17 16:52:35 UTC (rev 72) +++ trunk/PZFileReader/src/main/java/com/pz/reader/DataError.java 2006-10-17 16:53:24 UTC (rev 73) @@ -1,96 +0,0 @@ -/* - 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 - - 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 com.pz.reader; - -/** - * This class holds errors that occured while parsing or processing a data file. - * - * @author Paul Zepernick - * @version 2.0 - */ -public class DataError { - - /** Description of error. */ - private String errorDesc = null; - - /** line number in file error occured on. */ - private int lineNo = 0; - - /** - * Severity of the error 1 = Warning 2 = Moderate 3 = Severe. - */ - private int errorLevel = 0; - - /** default constructor */ - public DataError() { - } - - /** - * Returns the errorDesc. - * - * @return String - */ - public String getErrorDesc() { - return errorDesc; - } - - /** - * Returns the errorLevel. - * - * @return int - */ - public int getErrorLevel() { - return errorLevel; - } - - /** - * Returns the lineNo. - * - * @return int - */ - public int getLineNo() { - return lineNo; - } - - /** - * Sets the errorDesc. - * - * @param errorDesc - * The errorDesc to set - */ - public void setErrorDesc(final String errorDesc) { - this.errorDesc = errorDesc; - } - - /** - * Sets the errorLevel. - * - * @param errorLevel - * The errorLevel to set - */ - public void setErrorLevel(final int errorLevel) { - this.errorLevel = errorLevel; - } - - /** - * Sets the lineNo. - * - * @param lineNo - * The lineNo to set - */ - public void setLineNo(final int lineNo) { - this.lineNo = lineNo; - } -} Copied: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java (from rev 72, trunk/PZFileReader/src/main/java/com/pz/reader/DataError.java) =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java 2006-10-17 16:53:24 UTC (rev 73) @@ -0,0 +1,96 @@ +/* + 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 + + 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 com.pz.reader; + +/** + * This class holds errors that occured while parsing or processing a data file. + * + * @author Paul Zepernick + * @version 2.0 + */ +public class DataError { + + /** Description of error. */ + private String errorDesc = null; + + /** line number in file error occured on. */ + private int lineNo = 0; + + /** + * Severity of the error 1 = Warning 2 = Moderate 3 = Severe. + */ + private int errorLevel = 0; + + /** default constructor */ + public DataError() { + } + + /** + * Returns the errorDesc. + * + * @return String + */ + public String getErrorDesc() { + return errorDesc; + } + + /** + * Returns the errorLevel. + * + * @return int + */ + public int getErrorLevel() { + return errorLevel; + } + + /** + * Returns the lineNo. + * + * @return int + */ + public int getLineNo() { + return lineNo; + } + + /** + * Sets the errorDesc. + * + * @param errorDesc + * The errorDesc to set + */ + public void setErrorDesc(final String errorDesc) { + this.errorDesc = errorDesc; + } + + /** + * Sets the errorLevel. + * + * @param errorLevel + * The errorLevel to set + */ + public void setErrorLevel(final int errorLevel) { + this.errorLevel = errorLevel; + } + + /** + * Sets the lineNo. + * + * @param lineNo + * The lineNo to set + */ + 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. |
From: <be...@us...> - 2006-10-17 16:55:19
|
Revision: 74 http://svn.sourceforge.net/pzfilereader/?rev=74&view=rev Author: benoitx Date: 2006-10-17 09:54:30 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Moved remotely Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/ Removed Paths: ------------- trunk/PZFileReader/src/main/java/com/pz/reader/xml/ Copied: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml (from rev 73, trunk/PZFileReader/src/main/java/com/pz/reader/xml) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-17 16:57:55
|
Revision: 75 http://svn.sourceforge.net/pzfilereader/?rev=75&view=rev Author: benoitx Date: 2006-10-17 09:57:27 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Moved remotely Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ Removed Paths: ------------- trunk/PZFileReader/src/main/java/com/pz/reader/util/ Copied: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util (from rev 74, trunk/PZFileReader/src/main/java/com/pz/reader/util) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-17 16:59:06
|
Revision: 76 http://svn.sourceforge.net/pzfilereader/?rev=76&view=rev Author: benoitx Date: 2006-10-17 09:58:11 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Moved remotely Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/structure/ Removed Paths: ------------- trunk/PZFileReader/src/main/java/com/pz/reader/structure/ Copied: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/structure (from rev 75, trunk/PZFileReader/src/main/java/com/pz/reader/structure) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-17 17:03:16
|
Revision: 77 http://svn.sourceforge.net/pzfilereader/?rev=77&view=rev Author: benoitx Date: 2006-10-17 10:01:08 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Moved remotely Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/ordering/ Removed Paths: ------------- trunk/PZFileReader/src/main/java/com/pz/reader/ordering/ Copied: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/ordering (from rev 76, trunk/PZFileReader/src/main/java/com/pz/reader/ordering) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2006-10-17 17:09:43
|
Revision: 78 http://svn.sourceforge.net/pzfilereader/?rev=78&view=rev Author: benoitx Date: 2006-10-17 10:09:30 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Moved to net.sf.pzfilereader Modified Paths: -------------- 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/LargeDataSet.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/Version.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/ordering/OrderBy.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/ordering/OrderColumn.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/structure/ColumnMetaData.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/structure/Row.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ExcelTransformer.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/ResolveLocalDTD.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/XMLRecordElement.java Removed Paths: ------------- trunk/PZFileReader/src/main/java/com/ Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java 2006-10-17 17:01:08 UTC (rev 77) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataError.java 2006-10-17 17:09:30 UTC (rev 78) @@ -12,7 +12,7 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.pz.reader; +package net.sf.pzfilereader; /** * This class holds errors that occured while parsing or processing a data file. Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java 2006-10-17 17:01:08 UTC (rev 77) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java 2006-10-17 17:09:30 UTC (rev 78) @@ -12,7 +12,7 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.pz.reader; +package net.sf.pzfilereader; import java.io.BufferedReader; import java.io.File; @@ -33,12 +33,12 @@ import java.util.Map; import java.util.NoSuchElementException; -import com.pz.reader.ordering.OrderBy; -import com.pz.reader.structure.ColumnMetaData; -import com.pz.reader.structure.Row; -import com.pz.reader.util.ExcelTransformer; -import com.pz.reader.util.ParserUtils; -import com.pz.reader.xml.PZMapParser; +import net.sf.pzfilereader.ordering.OrderBy; +import net.sf.pzfilereader.structure.ColumnMetaData; +import net.sf.pzfilereader.structure.Row; +import net.sf.pzfilereader.util.ExcelTransformer; +import net.sf.pzfilereader.util.ParserUtils; +import net.sf.pzfilereader.xml.PZMapParser; /** * This class parses a datafile and holds methods to scroll back and forth @@ -1150,8 +1150,8 @@ * @param ob - * OrderBy object * @exception Exception - * @see com.pz.reader.ordering.OrderBy - * @see com.pz.reader.ordering.OrderColumn + * @see net.sf.pzfilereader.ordering.OrderBy + * @see net.sf.pzfilereader.ordering.OrderColumn */ public void orderRows(final OrderBy ob) throws Exception { //PZ try to handle other <records> by sending them to Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java 2006-10-17 17:01:08 UTC (rev 77) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/LargeDataSet.java 2006-10-17 17:09:30 UTC (rev 78) @@ -12,7 +12,7 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.pz.reader; +package net.sf.pzfilereader; import java.io.BufferedReader; import java.io.File; @@ -22,11 +22,11 @@ import java.util.List; import java.util.Map; -import com.pz.reader.ordering.OrderBy; -import com.pz.reader.structure.ColumnMetaData; -import com.pz.reader.structure.Row; -import com.pz.reader.util.ParserUtils; -import com.pz.reader.xml.PZMapParser; +import net.sf.pzfilereader.ordering.OrderBy; +import net.sf.pzfilereader.structure.ColumnMetaData; +import net.sf.pzfilereader.structure.Row; +import net.sf.pzfilereader.util.ParserUtils; +import net.sf.pzfilereader.xml.PZMapParser; /** * @author Paul Zepernick Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/Version.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/Version.java 2006-10-17 17:01:08 UTC (rev 77) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/Version.java 2006-10-17 17:09:30 UTC (rev 78) @@ -12,7 +12,7 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.pz.reader; +package net.sf.pzfilereader; /** * 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-17 17:01:08 UTC (rev 77) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/ordering/OrderBy.java 2006-10-17 17:09:30 UTC (rev 78) @@ -12,14 +12,14 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.pz.reader.ordering; +package net.sf.pzfilereader.ordering; import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import com.pz.reader.structure.Row; -import com.pz.reader.util.ParserUtils; +import net.sf.pzfilereader.structure.Row; +import net.sf.pzfilereader.util.ParserUtils; /** * @author paul zepernick Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/ordering/OrderColumn.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/ordering/OrderColumn.java 2006-10-17 17:01:08 UTC (rev 77) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/ordering/OrderColumn.java 2006-10-17 17:09:30 UTC (rev 78) @@ -12,7 +12,7 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.pz.reader.ordering; +package net.sf.pzfilereader.ordering; /** * @author paul zepernick Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/structure/ColumnMetaData.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/structure/ColumnMetaData.java 2006-10-17 17:01:08 UTC (rev 77) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/structure/ColumnMetaData.java 2006-10-17 17:09:30 UTC (rev 78) @@ -12,7 +12,7 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.pz.reader.structure; +package net.sf.pzfilereader.structure; /** * @author Paul zepernick Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/structure/Row.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/structure/Row.java 2006-10-17 17:01:08 UTC (rev 77) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/structure/Row.java 2006-10-17 17:09:30 UTC (rev 78) @@ -12,7 +12,7 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.pz.reader.structure; +package net.sf.pzfilereader.structure; import java.util.ArrayList; import java.util.List; 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-17 17:01:08 UTC (rev 77) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ExcelTransformer.java 2006-10-17 17:09:30 UTC (rev 78) @@ -12,7 +12,7 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.pz.reader.util; +package net.sf.pzfilereader.util; import java.io.File; @@ -23,7 +23,7 @@ import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; -import com.pz.reader.DataSet; +import net.sf.pzfilereader.DataSet; /** * @author Paul Zepernick 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-17 17:01:08 UTC (rev 77) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/util/ParserUtils.java 2006-10-17 17:09:30 UTC (rev 78) @@ -12,7 +12,7 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.pz.reader.util; +package net.sf.pzfilereader.util; import java.io.BufferedReader; import java.io.File; @@ -30,8 +30,8 @@ import java.util.Map; import java.util.NoSuchElementException; -import com.pz.reader.structure.ColumnMetaData; -import com.pz.reader.xml.XMLRecordElement; +import net.sf.pzfilereader.structure.ColumnMetaData; +import net.sf.pzfilereader.xml.XMLRecordElement; /** * @author zepernick Static utilities that are used to perform parsing in the Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/PZMapParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/PZMapParser.java 2006-10-17 17:01:08 UTC (rev 77) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/PZMapParser.java 2006-10-17 17:09:30 UTC (rev 78) @@ -12,7 +12,7 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.pz.reader.xml; +package net.sf.pzfilereader.xml; import java.io.File; import java.io.InputStream; @@ -27,8 +27,8 @@ import org.jdom.Element; import org.jdom.input.SAXBuilder; -import com.pz.reader.structure.ColumnMetaData; -import com.pz.reader.util.ParserUtils; +import net.sf.pzfilereader.structure.ColumnMetaData; +import net.sf.pzfilereader.util.ParserUtils; /** * @author zepernick Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/ResolveLocalDTD.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/ResolveLocalDTD.java 2006-10-17 17:01:08 UTC (rev 77) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/ResolveLocalDTD.java 2006-10-17 17:09:30 UTC (rev 78) @@ -12,7 +12,7 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.pz.reader.xml; +package net.sf.pzfilereader.xml; import java.io.IOException; import java.net.URL; Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/XMLRecordElement.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/XMLRecordElement.java 2006-10-17 17:01:08 UTC (rev 77) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/xml/XMLRecordElement.java 2006-10-17 17:09:30 UTC (rev 78) @@ -12,7 +12,7 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package com.pz.reader.xml; +package net.sf.pzfilereader.xml; import java.util.List; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zep...@us...> - 2006-11-25 15:52:28
|
Revision: 189 http://svn.sourceforge.net/pzfilereader/?rev=189&view=rev Author: zepernick Date: 2006-11-25 07:52:23 -0800 (Sat, 25 Nov 2006) Log Message: ----------- - adding some new converter's - shored up some comments and added license agreement to files Modified Paths: -------------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertBigDecimal.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/PZConvertException.java trunk/PZFileReader/src/main/java/pzconvert.properties Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertDouble.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertInteger.java Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertBigDecimal.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertBigDecimal.java 2006-11-25 14:36:50 UTC (rev 188) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertBigDecimal.java 2006-11-25 15:52:23 UTC (rev 189) @@ -5,8 +5,11 @@ import net.sf.pzfilereader.util.ParserUtils; /** - * Returns a BigInt - * @author zepernick + * Returns a BigDecimal + * Non numeric chars are removed from the string + * before converting + * + * @author Paul Zepernick */ public class ConvertBigDecimal implements PZConverter{ /* Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertDouble.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertDouble.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertDouble.java 2006-11-25 15:52:23 UTC (rev 189) @@ -0,0 +1,56 @@ +/* + * 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.converter; + +import net.sf.pzfilereader.util.ParserUtils; + +/** + * Returns a Double + * Non numeric chars are removed from the string + * before converting + * + * @author Paul Zepernick + */ +public class ConvertDouble implements PZConverter { + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.converter#convertValue(java.lang.String) + */ + public Object convertValue(String valueToConvert) { + return new Double(ParserUtils.stripNonDoubleChars(valueToConvert)); + } + +} Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertInteger.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertInteger.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertInteger.java 2006-11-25 15:52:23 UTC (rev 189) @@ -0,0 +1,56 @@ +/* + * 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.converter; + +import net.sf.pzfilereader.util.ParserUtils; + +/** + * Returns a Integer + * Non numeric chars are removed from the string + * before converting + * + * @author Paul Zepernick + */ +public class ConvertInteger implements PZConverter { + + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.converter#convertValue(java.lang.String) + */ + public Object convertValue(String valueToConvert) { + return new Integer(ParserUtils.stripNonLongChars(valueToConvert)); + } + +} Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/PZConvertException.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/PZConvertException.java 2006-11-25 14:36:50 UTC (rev 188) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/PZConvertException.java 2006-11-25 15:52:23 UTC (rev 189) @@ -1,3 +1,36 @@ +/* + * 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.converter; /** Modified: trunk/PZFileReader/src/main/java/pzconvert.properties =================================================================== --- trunk/PZFileReader/src/main/java/pzconvert.properties 2006-11-25 14:36:50 UTC (rev 188) +++ trunk/PZFileReader/src/main/java/pzconvert.properties 2006-11-25 15:52:23 UTC (rev 189) @@ -1 +1,3 @@ -java.math.BigDecimal=net.sf.pzfilereader.converter.ConvertBigInt \ No newline at end of file +java.math.BigDecimal=net.sf.pzfilereader.converter.ConvertBigDecimal +java.lang.Double=net.sf.pzfilereader.converter.ConvertDouble +java.lang.Integer=net.sf.pzfilereader.converter.ConvertInteger \ 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-11-11 20:42:27
|
Revision: 174 http://svn.sourceforge.net/pzfilereader/?rev=174&view=rev Author: zepernick Date: 2006-11-11 12:42:15 -0800 (Sat, 11 Nov 2006) Log Message: ----------- first attempt at a new getObject() method in the IDataSet Benoit, if you get a chance take a look and let me know what you think of the implementation. I am currently getting some NPE's in the unit tests. This is because it is not finding the pzconvert.properties file. I tried to modify the ant script to make sure it was getting included, but I am having some trouble. I can take a look at it later and see what the deal is. Paul 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/DataSet.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/IDataSet.java Added Paths: ----------- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertBigDecimal.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/PZConvertException.java trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/PZConverter.java trunk/PZFileReader/src/main/java/pzconvert.properties Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java 2006-11-04 17:11:08 UTC (rev 173) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractDelimiterPZParser.java 2006-11-11 20:42:15 UTC (rev 174) @@ -38,7 +38,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.URL; import java.util.List; +import java.util.Properties; import net.sf.pzfilereader.structure.Row; import net.sf.pzfilereader.util.PZConstants; @@ -152,6 +154,13 @@ BufferedReader br = null; final DefaultDataSet ds = new DefaultDataSet(getColumnMD()); try { + //gather the conversion properties + final Properties pzConvertProps = new Properties(); + final URL url = getClass().getClassLoader().getResource("pzconvert.properties"); + pzConvertProps.load(url.openStream()); + ds.setPZConvertProps(pzConvertProps); + + // get the total column count // columnCount = columnMD.size(); Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java 2006-11-04 17:11:08 UTC (rev 173) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/AbstractFixedLengthPZParser.java 2006-11-11 20:42:15 UTC (rev 174) @@ -38,8 +38,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.URL; import java.util.List; import java.util.Map; +import java.util.Properties; import net.sf.pzfilereader.structure.Row; import net.sf.pzfilereader.util.FixedWidthParserUtils; @@ -110,6 +112,13 @@ final DefaultDataSet ds = new DefaultDataSet(getColumnMD()); try { + //gather the conversion properties + final Properties pzConvertProps = new Properties(); + final URL url = getClass().getClassLoader().getResource("pzconvert.properties"); + pzConvertProps.load(url.openStream()); + ds.setPZConvertProps(pzConvertProps); + + final Map recordLengths = ParserUtils.calculateRecordLengths(getColumnMD()); // Read in the flat file Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java 2006-11-04 17:11:08 UTC (rev 173) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DataSet.java 2006-11-11 20:42:15 UTC (rev 174) @@ -31,6 +31,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Properties; import net.sf.pzfilereader.ordering.OrderBy; import net.sf.pzfilereader.structure.ColumnMetaData; @@ -1383,4 +1384,17 @@ public void setErrors(final List errors) { this.errors = errors; } + + public Object getObject(String column, Class classToConvertTo) { + // TODO May have to do something here if we plan on keeping + //this around for the next version. I believe this will + //be leaving + return null; + } + + public void setPZConvertProps(Properties props) { + // TODO May have to do something here if we plan on keeping + //this around for the next version. I believe this will + //be leaving + } } Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java 2006-11-04 17:11:08 UTC (rev 173) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/DefaultDataSet.java 2006-11-11 20:42:15 UTC (rev 174) @@ -40,7 +40,10 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Properties; +import net.sf.pzfilereader.converter.PZConvertException; +import net.sf.pzfilereader.converter.PZConverter; import net.sf.pzfilereader.ordering.OrderBy; import net.sf.pzfilereader.structure.ColumnMetaData; import net.sf.pzfilereader.structure.Row; @@ -55,6 +58,8 @@ private final List rows = new ArrayList(); private final List errors = new ArrayList(); + + private Properties pzConvertProps = null; /** Pointer for the current row in the array we are on */ private int pointer = -1; @@ -170,6 +175,24 @@ return Double.parseDouble(newString.toString()); } + + + public Object getObject(String column, Class classToConvertTo) { + final String sConverter = pzConvertProps.getProperty(classToConvertTo.getName()); + if (sConverter == null) { + throw new PZConvertException (classToConvertTo.getName() + " is not registered in pzconvert.properties"); + } + try{ + final Row row = (Row) rows.get(pointer); + final String s = row.getValue(ParserUtils.getColumnIndex(row.getMdkey(), columnMD, column)); + final PZConverter pzconverter = (PZConverter)Class.forName(sConverter).newInstance(); + + return pzconverter.convertValue(s); + + } catch (Exception ex) { + throw new PZConvertException (ex); + } + } /* * (non-Javadoc) @@ -422,6 +445,10 @@ rows.remove(pointer); pointer--; } + + public void setPZConvertProps(Properties props) { + this.pzConvertProps = props; + } void setColumnMD(final Map columnMD) { this.columnMD = columnMD; Modified: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/IDataSet.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/IDataSet.java 2006-11-04 17:11:08 UTC (rev 173) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/IDataSet.java 2006-11-11 20:42:15 UTC (rev 174) @@ -37,6 +37,7 @@ import java.util.Date; import java.util.List; import java.util.NoSuchElementException; +import java.util.Properties; import net.sf.pzfilereader.ordering.OrderBy; @@ -128,6 +129,20 @@ * @return Date */ Date getDate(final String column, final SimpleDateFormat sdf) throws ParseException; + + + /** + * Returns the value of the column with the type of object + * specified + * + * @param column + * Name of the column + * @param classToConvertTo + * Class type to convert to + * @return Object + * Value of the column in the specified object + */ + Object getObject(final String column, final Class classToConvertTo); /** * Returns a String array of column names in the DataSet. This will assume @@ -257,4 +272,14 @@ * The strictNumericParse to set. */ void setStrictNumericParse(final boolean strictNumericParse); + + /** + * Sets the properties from the pzconvert.properties file. + * This file specifies the PZConverter implementation to use + * for a particular class + * + * @param props + * Property mapping for String to Object conversion + */ + void setPZConvertProps(Properties props); } \ No newline at end of file Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertBigDecimal.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertBigDecimal.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/ConvertBigDecimal.java 2006-11-11 20:42:15 UTC (rev 174) @@ -0,0 +1,20 @@ +package net.sf.pzfilereader.converter; + +import java.math.BigDecimal; + +import net.sf.pzfilereader.util.ParserUtils; + +/** + * Returns a BigInt + * @author zepernick + */ +public class ConvertBigDecimal implements PZConverter{ + /* + * (non-Javadoc) + * + * @see net.sf.pzfilereader.converter#convertValue(java.lang.String) + */ + public Object convertValue(String valueToConvert) { + return new BigDecimal(ParserUtils.stripNonDoubleChars(valueToConvert)); + } +} Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/PZConvertException.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/PZConvertException.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/PZConvertException.java 2006-11-11 20:42:15 UTC (rev 174) @@ -0,0 +1,39 @@ +package net.sf.pzfilereader.converter; + +/** + * Exception thrown when a conversion error occurs + * + * @author Paul Zepernick + */ +public class PZConvertException extends RuntimeException{ + private static final long serialVersionUID = 1L; + + /** + * + */ + public PZConvertException() { + } + + /** + * @param message + */ + public PZConvertException(final String message) { + super(message); + } + + /** + * @param cause + */ + public PZConvertException(final Throwable cause) { + super(cause); + } + + /** + * @param message + * @param cause + */ + public PZConvertException(final String message, final Throwable cause) { + super(message, cause); + } + +} Added: trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/PZConverter.java =================================================================== --- trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/PZConverter.java (rev 0) +++ trunk/PZFileReader/src/main/java/net/sf/pzfilereader/converter/PZConverter.java 2006-11-11 20:42:15 UTC (rev 174) @@ -0,0 +1,51 @@ +/* + * 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.converter; + +/** + * Responsible for converting a column in IDataSet + * to the desired Object. + * + * @author Paul Zepernick + */ +public interface PZConverter { + + /** + * Returns the converted object from the + * column in IDataSet + * + * @param valueToConvert + * @return Object + */ + Object convertValue(String valueToConvert); +} Added: trunk/PZFileReader/src/main/java/pzconvert.properties =================================================================== --- trunk/PZFileReader/src/main/java/pzconvert.properties (rev 0) +++ trunk/PZFileReader/src/main/java/pzconvert.properties 2006-11-11 20:42:15 UTC (rev 174) @@ -0,0 +1 @@ +java.math.BigDecimal=net.sf.pzfilereader.converter.ConvertBigInt \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |