|
From: <zep...@us...> - 2007-11-23 14:08:39
|
Revision: 380
http://flatpack.svn.sourceforge.net/flatpack/?rev=380&view=rev
Author: zepernick
Date: 2007-11-23 06:08:40 -0800 (Fri, 23 Nov 2007)
Log Message:
-----------
added an option to store the raw data in the DataError object when a parse error occurs
Modified Paths:
--------------
trunk/flatpack/src/main/java/net/sf/flatpack/AbstractDelimiterParser.java
trunk/flatpack/src/main/java/net/sf/flatpack/AbstractFixedLengthParser.java
trunk/flatpack/src/main/java/net/sf/flatpack/AbstractParser.java
trunk/flatpack/src/main/java/net/sf/flatpack/DataError.java
trunk/flatpack/src/main/java/net/sf/flatpack/Parser.java
trunk/flatpack/src/main/java/net/sf/flatpack/Version.java
trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderDelimParser.java
trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderFixedParser.java
Modified: trunk/flatpack/src/main/java/net/sf/flatpack/AbstractDelimiterParser.java
===================================================================
--- trunk/flatpack/src/main/java/net/sf/flatpack/AbstractDelimiterParser.java 2007-11-17 16:15:41 UTC (rev 379)
+++ trunk/flatpack/src/main/java/net/sf/flatpack/AbstractDelimiterParser.java 2007-11-23 14:08:40 UTC (rev 380)
@@ -165,7 +165,8 @@
columns = columns.subList(0, columnCount);
addError(ds, "TRUNCATED LINE TO CORRECT NUMBER OF COLUMNS", lineCount, 1);
} else {
- addError(ds, "TOO MANY COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2);
+ addError(ds, "TOO MANY COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2,
+ isStoreRawDataToDataError() ? line : null);
continue;
}
} else if (columns.size() < columnCount) {
@@ -179,7 +180,8 @@
addError(ds, "PADDED LINE TO CORRECT NUMBER OF COLUMNS", lineCount, 1);
} else {
- addError(ds, "TOO FEW COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2);
+ addError(ds, "TOO FEW COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), lineCount, 2,
+ isStoreRawDataToDataError() ? line : null);
continue;
}
}
Modified: trunk/flatpack/src/main/java/net/sf/flatpack/AbstractFixedLengthParser.java
===================================================================
--- trunk/flatpack/src/main/java/net/sf/flatpack/AbstractFixedLengthParser.java 2007-11-17 16:15:41 UTC (rev 379)
+++ trunk/flatpack/src/main/java/net/sf/flatpack/AbstractFixedLengthParser.java 2007-11-23 14:08:40 UTC (rev 380)
@@ -115,7 +115,8 @@
line = line.substring(0, recordLength);
addError(ds, "TRUNCATED LINE TO CORRECT LENGTH", lineCount, 1);
} else {
- addError(ds, "LINE TOO LONG. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2);
+ addError(ds, "LINE TOO LONG. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2,
+ isStoreRawDataToDataError() ? line : null);
continue;
}
} else if (line.length() < recordLength) {
@@ -127,7 +128,8 @@
addError(ds, "PADDED LINE TO CORRECT RECORD LENGTH", lineCount, 1);
} else {
- addError(ds, "LINE TOO SHORT. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2);
+ addError(ds, "LINE TOO SHORT. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2,
+ isStoreRawDataToDataError() ? line : null);
continue;
}
}
Modified: trunk/flatpack/src/main/java/net/sf/flatpack/AbstractParser.java
===================================================================
--- trunk/flatpack/src/main/java/net/sf/flatpack/AbstractParser.java 2007-11-17 16:15:41 UTC (rev 379)
+++ trunk/flatpack/src/main/java/net/sf/flatpack/AbstractParser.java 2007-11-23 14:08:40 UTC (rev 380)
@@ -71,6 +71,8 @@
private List readersToClose = null;
private boolean flagEmptyRows;
+
+ private boolean storeRawDataToDataError;
protected AbstractParser(final Reader dataSourceReader) {
this.dataSourceReader = dataSourceReader;
@@ -178,23 +180,41 @@
}
/**
- * Adds a new error to this DataSet. These can be collected, and retreived
+ * Adds a new error to this DataSet. These can be collected, and retrieved
* after processing
*
- * @param errorDesc -
+ * @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
+ * @param lineNo
+ * line number error occurred on
+ * @param errorLevel
+ * errorLevel 1,2,3 1=warning 2=error 3= severe error
*/
protected void addError(final DefaultDataSet ds, final String errorDesc,
final int lineNo, final int errorLevel) {
+ addError(ds, errorDesc, lineNo, errorLevel, null);
+ }
+
+ /**
+ * Adds a new error to this DataSet. These can be collected, and retrieved
+ * after processing
+ *
+ * @param errorDesc
+ * String description of error
+ * @param lineNo
+ * line number error occurred on
+ * @param errorLevel
+ * errorLevel 1,2,3 1=warning 2=error 3= severe error'
+ * @param lineData
+ * Data of the line which failed the parse
+ */
+ protected void addError(final DefaultDataSet ds, final String errorDesc,
+ final int lineNo, final int errorLevel, final String lineData) {
if (errorLevel == 1 && isIgnoreParseWarnings()) {
// user has selected to not log warnings in the parser
return;
}
- final DataError de = new DataError(errorDesc, lineNo, errorLevel);
+ final DataError de = new DataError(errorDesc, lineNo, errorLevel, lineData);
ds.addError(de);
}
@@ -259,4 +279,18 @@
public void setFlagEmptyRows(boolean flagEmptyRows) {
this.flagEmptyRows = flagEmptyRows;
}
+
+ /**
+ * @return the storeRawDataToDataError
+ */
+ public boolean isStoreRawDataToDataError() {
+ return storeRawDataToDataError;
+ }
+
+ /**
+ * @param storeRawDataToDataError the storeRawDataToDataError to set
+ */
+ public void setStoreRawDataToDataError(boolean storeRawDataToDataError) {
+ this.storeRawDataToDataError = storeRawDataToDataError;
+ }
}
Modified: trunk/flatpack/src/main/java/net/sf/flatpack/DataError.java
===================================================================
--- trunk/flatpack/src/main/java/net/sf/flatpack/DataError.java 2007-11-17 16:15:41 UTC (rev 379)
+++ trunk/flatpack/src/main/java/net/sf/flatpack/DataError.java 2007-11-23 14:08:40 UTC (rev 380)
@@ -33,7 +33,7 @@
package net.sf.flatpack;
/**
- * This class holds errors that occured while parsing or processing a data file.
+ * This class holds errors that occurred while parsing or processing a data file.
*
* @author Paul Zepernick
* @version 2.0
@@ -44,21 +44,39 @@
private final int lineNo;
private final int errorLevel;
+
+ private final String rawData;
/**
*
* @param errorDesc
- * Text description of the error that occured
+ * Text description of the error that occurred
* @param lineNo
- * Line number in the data file the error occured on
+ * Line number in the data file the error occurred on
* @param errorLevel
* Level of the error (1=warning, 2=moderate, 3=severe)
*/
public DataError(final String errorDesc, final int lineNo, final int errorLevel) {
- this.errorDesc = errorDesc;
- this.lineNo = lineNo;
- this.errorLevel = errorLevel;
+ this(errorDesc, lineNo, errorLevel, null);
}
+
+ /**
+ *
+ * @param errorDesc
+ * Text description of the error that occurred
+ * @param lineNo
+ * Line number in the data file the error occurred on
+ * @param errorLevel
+ * Level of the error (1=warning, 2=moderate, 3=severe)
+ * @param rawData
+ * String of data which the parse failed on
+ */
+ public DataError(final String errorDesc, final int lineNo, final int errorLevel, final String rawData) {
+ this.errorDesc = errorDesc;
+ this.lineNo = lineNo;
+ this.errorLevel = errorLevel;
+ this.rawData = rawData;
+ }
/**
* Returns the errorDesc.
@@ -93,4 +111,14 @@
System.getProperty("line.separator"));
return buf.toString();
}
+
+ /**
+ * Option must be set on parser, otherwise this is
+ * null by default
+ *
+ * @return the rawData
+ */
+ protected String getRawData() {
+ return rawData;
+ }
}
Modified: trunk/flatpack/src/main/java/net/sf/flatpack/Parser.java
===================================================================
--- trunk/flatpack/src/main/java/net/sf/flatpack/Parser.java 2007-11-17 16:15:41 UTC (rev 379)
+++ trunk/flatpack/src/main/java/net/sf/flatpack/Parser.java 2007-11-23 14:08:40 UTC (rev 380)
@@ -151,4 +151,13 @@
* @param flagEmptyRows
*/
void setFlagEmptyRows(final boolean flagEmptyRows);
+
+ /**
+ * when true, the parser will place the data of the line which failed the parse and
+ * place it into the DataError object. DataError.getRawData() can be called to retrieve
+ * the line.
+ *
+ * @param storeRawDataToDataError
+ */
+ void setStoreRawDataToDataError(final boolean storeRawDataToDataError);
}
Modified: trunk/flatpack/src/main/java/net/sf/flatpack/Version.java
===================================================================
--- trunk/flatpack/src/main/java/net/sf/flatpack/Version.java 2007-11-17 16:15:41 UTC (rev 379)
+++ trunk/flatpack/src/main/java/net/sf/flatpack/Version.java 2007-11-23 14:08:40 UTC (rev 380)
@@ -19,5 +19,5 @@
* Static class which stores the version of this FlatPack
*/
public class Version {
- public static final String VERSION = "3.1.1";
+ public static final String VERSION = "3.2.0-SNAPSHOT";
}
Modified: trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderDelimParser.java
===================================================================
--- trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderDelimParser.java 2007-11-17 16:15:41 UTC (rev 379)
+++ trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderDelimParser.java 2007-11-23 14:08:40 UTC (rev 380)
@@ -152,7 +152,8 @@
addError(ds, "TRUNCATED LINE TO CORRECT NUMBER OF COLUMNS", getLineCount(), 1);
} else {
//log the error
- addError(ds, "TOO MANY COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), getLineCount(), 2);
+ addError(ds, "TOO MANY COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), getLineCount(), 2,
+ isStoreRawDataToDataError() ? line : null);
continue;
}
} else if (columns.size() < columnCount) {
@@ -166,7 +167,8 @@
addError(ds, "PADDED LINE TO CORRECT NUMBER OF COLUMNS", getLineCount(), 1);
} else {
- addError(ds, "TOO FEW COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), getLineCount(), 2);
+ addError(ds, "TOO FEW COLUMNS WANTED: " + columnCount + " GOT: " + columns.size(), getLineCount(), 2,
+ isStoreRawDataToDataError() ? line : null);
continue;
}
}
@@ -177,6 +179,11 @@
row.setCols(columns);
row.setRowNumber(getLineCount());
+ if (isFlagEmptyRows()) {
+ //user has elected to have the parser flag rows that are empty
+ row.setEmpty(ParserUtils.isListElementsEmpty(columns));
+ }
+
return row;
}
}
Modified: trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderFixedParser.java
===================================================================
--- trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderFixedParser.java 2007-11-17 16:15:41 UTC (rev 379)
+++ trunk/flatpack/src/main/java/net/sf/flatpack/brparse/BuffReaderFixedParser.java 2007-11-23 14:08:40 UTC (rev 380)
@@ -116,12 +116,13 @@
// be included in the
// dataset
if (isIgnoreExtraColumns()) {
- //user has choosen to ignore the fact that we have too many bytes in the fixed
+ //user has chosen to ignore the fact that we have too many bytes in the fixed
//width file. Truncate the line to the correct length
line = line.substring(0, recordLength);
addError(ds, "TRUNCATED LINE TO CORRECT LENGTH", lineCount, 1);
} else {
- addError(ds, "LINE TOO LONG. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2);
+ addError(ds, "LINE TOO LONG. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2,
+ isStoreRawDataToDataError() ? line : null);
continue;
}
} else if (line.length() < recordLength) {
@@ -133,7 +134,8 @@
addError(ds, "PADDED LINE TO CORRECT RECORD LENGTH", lineCount, 1);
} else {
- addError(ds, "LINE TOO SHORT. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2);
+ addError(ds, "LINE TOO SHORT. LINE IS " + line.length() + " LONG. SHOULD BE " + recordLength, lineCount, 2,
+ isStoreRawDataToDataError() ? line : null);
continue;
}
}
@@ -145,6 +147,11 @@
row.addColumn(FixedWidthParserUtils.splitFixedText(cmds, line));
row.setRowNumber(lineCount);
+
+ if (isFlagEmptyRows()) {
+ //user has elected to have the parser flag rows that are empty
+ row.setEmpty(ParserUtils.isListElementsEmpty(row.getCols()));
+ }
return row;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|