[FOray-commit] SF.net SVN: foray:[10835] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2009-04-30 16:23:05
|
Revision: 10835
http://foray.svn.sourceforge.net/foray/?rev=10835&view=rev
Author: victormote
Date: 2009-04-30 16:22:59 +0000 (Thu, 30 Apr 2009)
Log Message:
-----------
Throw Exceptions instead of logging errors.
Modified Paths:
--------------
trunk/foray/foray-font/src/java/org/foray/font/ConfigParser.java
trunk/foray/foray-ps/src/java/org/foray/ps/encode/CharSetParser.java
trunk/foray/foray-ps/src/java/org/foray/ps/encode/EncodingParser.java
trunk/foray/foray-ps/src/java/org/foray/ps/encode/GlyphListParser.java
trunk/foray/foray-ps/src/javatest/org/foray/ps/encode/TestEncodingParser.java
trunk/foray/foray-ps/src/javatest/org/foray/ps/encode/TestGlyphListParser.java
Modified: trunk/foray/foray-font/src/java/org/foray/font/ConfigParser.java
===================================================================
--- trunk/foray/foray-font/src/java/org/foray/font/ConfigParser.java 2009-04-30 16:03:09 UTC (rev 10834)
+++ trunk/foray/foray-font/src/java/org/foray/font/ConfigParser.java 2009-04-30 16:22:59 UTC (rev 10835)
@@ -36,6 +36,7 @@
import org.foray.ps.encode.GlyphListParser;
import org.axsl.font.FontException;
+import org.axsl.ps.PsException;
import org.apache.commons.logging.Log;
@@ -761,13 +762,14 @@
return;
}
final int radix = Integer.parseInt(radixString);
- final EncodingParser parser = new EncodingParser(
- this.fontServer.getLogger(), input, columnNumber, radix,
+ final EncodingParser parser = new EncodingParser(input, columnNumber, radix,
attributes.getValue("glyph-lists"));
try {
parser.parseList();
} catch (final IOException e2) {
logError("Error parsing: " + encodingFile);
+ } catch (final PsException e2) {
+ logError("Error parsing: " + encodingFile);
}
encoding = new EncodingCustom(name, parser.getGlyphListsToCheck(),
parser.getCodePoints(),
@@ -813,11 +815,13 @@
logError("Unable to read: " + file);
return;
}
- final GlyphListParser parser = new GlyphListParser(this.fontServer.getLogger(), input);
+ final GlyphListParser parser = new GlyphListParser(input);
try {
parser.parseList();
} catch (final IOException e2) {
logError("Error parsing: " + file);
+ } catch (final PsException e2) {
+ logError("Error parsing: " + file);
}
glyphList = new GlyphList4a(name, parser.getGlyphNames(),
parser.getCodePointsForGlyphNames(), parser.getCodePoints(),
Modified: trunk/foray/foray-ps/src/java/org/foray/ps/encode/CharSetParser.java
===================================================================
--- trunk/foray/foray-ps/src/java/org/foray/ps/encode/CharSetParser.java 2009-04-30 16:03:09 UTC (rev 10834)
+++ trunk/foray/foray-ps/src/java/org/foray/ps/encode/CharSetParser.java 2009-04-30 16:22:59 UTC (rev 10835)
@@ -33,6 +33,8 @@
import org.foray.common.StringUtil;
import org.foray.common.url.URLFactory;
+import org.axsl.ps.PsException;
+
import org.apache.commons.logging.Log;
import java.io.BufferedReader;
@@ -76,16 +78,11 @@
/** The array of glyph names in the character set. */
private List<String> glyphNames = new ArrayList<String>();
- /** The logger. */
- private Log logger;
-
/**
* Create a new CharSetParser instance.
- * @param logger The logger to use for user messages.
* @param input The reader encapsulating the file to be read.
*/
- public CharSetParser(final Log logger, final InputStream input) {
- this.logger = logger;
+ public CharSetParser(final InputStream input) {
final InputStreamReader isr = new InputStreamReader(input);
this.reader = new BufferedReader(isr);
}
@@ -93,8 +90,9 @@
/**
* Parses a glyph list.
* @throws IOException For I/O error.
+ * @throws PsException For errors parsing the input.
*/
- public void parseList() throws IOException {
+ public void parseList() throws IOException, PsException {
parseLines();
sortCharacterSet();
}
@@ -102,8 +100,9 @@
/**
* Parses the lines of the character set input file.
* @throws IOException For I/O error.
+ * @throws PsException For errors parsing the input.
*/
- private void parseLines() throws IOException {
+ private void parseLines() throws IOException, PsException {
boolean endOfFile = false;
endOfFile = false;
int arrayIndex = 0;
@@ -147,14 +146,15 @@
* Process a content line.
* @param line The text from the line.
* @param arrayIndex The current glyph index being processed.
+ * @throws PsException For errors parsing the line.
*/
- private void processCurrentLine(final String line, final int arrayIndex) {
+ private void processCurrentLine(final String line, final int arrayIndex) throws PsException {
this.characterSet.add(Character.MIN_VALUE);
this.glyphNames.add(StringUtil.EMPTY_STRING);
final GlyphList4a gl = GlyphList4a.getGlyphList("AGL");
final char theChar = gl.mapGlyphNameToCodePoint(line);
if (theChar == Character.MAX_VALUE) {
- this.logger.error("Character not found in Adobe Glyph List, line "
+ throw new PsException("Character not found in Adobe Glyph List, line "
+ this.currentLineNumber + ": " + line);
}
@@ -274,13 +274,17 @@
+ args[1] + "\n");
System.exit(1);
}
- final CharSetParser parser = new CharSetParser(logger, input);
+ final CharSetParser parser = new CharSetParser(input);
try {
parser.parseList();
} catch (final IOException e3) {
logger.error("Error parsing: " + args[0] + "\n");
logger.error(" " + e3.getMessage());
System.exit(1);
+ } catch (final PsException e3) {
+ logger.error("Error parsing: " + args[0] + "\n");
+ logger.error(" " + e3.getMessage());
+ System.exit(1);
}
try {
parser.writeAsJavaStatics(output);
Modified: trunk/foray/foray-ps/src/java/org/foray/ps/encode/EncodingParser.java
===================================================================
--- trunk/foray/foray-ps/src/java/org/foray/ps/encode/EncodingParser.java 2009-04-30 16:03:09 UTC (rev 10834)
+++ trunk/foray/foray-ps/src/java/org/foray/ps/encode/EncodingParser.java 2009-04-30 16:22:59 UTC (rev 10835)
@@ -34,6 +34,8 @@
import org.foray.common.WKConstants;
import org.foray.common.url.URLFactory;
+import org.axsl.ps.PsException;
+
import org.apache.commons.logging.Log;
import java.io.BufferedReader;
@@ -129,9 +131,6 @@
* different column. */
private int columnNum = -1;
- /** The logger. */
- private Log logger;
-
/** The raw space-separated list of glyphs lists that should be consulted to
* map glyph names to Unicode codepoints for this encoding. */
private String glyphLists;
@@ -157,22 +156,16 @@
/**
* Create a new EncodingParser instance.
- * @param logger The logger.
* @param input The reader encapsulating the file to be parsed.
- * @param columnNum The column number in the input file that should be
- * read to get the encoded value for this encoding.
- * Column number 1 is the first field after the glyph name, that is, field
- * 2.
- * @param radix The radix of the numbering system (10 for decimal, 8 for
- * octal, etc.).
- * @param glyphLists A space-separated list of glyph lists to be consulted
- * when mapping glyph names to Unicode code points.
- * The Adobe Glyph List is always consulted, but only after any custom ones
- * listed here.
+ * @param columnNum The column number in the input file that should be read to get the encoded value for this
+ * encoding.
+ * Column number 1 is the first field after the glyph name, that is, field 2.
+ * @param radix The radix of the numbering system (10 for decimal, 8 for octal, etc.).
+ * @param glyphLists A space-separated list of glyph lists to be consulted when mapping glyph names to Unicode code
+ * points.
+ * The Adobe Glyph List is always consulted, but only after any custom ones listed here.
*/
- public EncodingParser(final Log logger, final InputStream input, final int columnNum, final int radix,
- final String glyphLists) {
- this.logger = logger;
+ public EncodingParser(final InputStream input, final int columnNum, final int radix, final String glyphLists) {
final InputStreamReader isr = new InputStreamReader(input);
this.reader = new BufferedReader(isr);
this.columnNum = columnNum;
@@ -183,8 +176,9 @@
/**
* Parses a glyph list.
* @throws IOException For I/O Errors.
+ * @throws PsException For errors parsing the input.
*/
- public void parseList() throws IOException {
+ public void parseList() throws IOException, PsException {
parseLines();
sortGlyphNames();
createCodePoints();
@@ -194,8 +188,9 @@
/**
* Parses the lines of the file.
* @throws IOException For I/O Error.
+ * @throws PsException For errors parsing the input.
*/
- private void parseLines() throws IOException {
+ private void parseLines() throws IOException, PsException {
boolean endOfFile = false;
endOfFile = false;
int arrayIndex = 0;
@@ -258,10 +253,10 @@
/**
* Parsed the content line.
* @param line The String of text for the line being parsed.
- * @param arrayIndex The current index into the arrays containing the parsed
- * data.
+ * @param arrayIndex The current index into the arrays containing the parsed data.
+ * @throws PsException For errors parsing the line.
*/
- private void processCurrentLine(final String line, final int arrayIndex) {
+ private void processCurrentLine(final String line, final int arrayIndex) throws PsException {
this.glyphNames.add(StringUtil.EMPTY_STRING);
this.glyphIndexes.add(Character.MIN_VALUE);
this.codePoints.add(Character.MIN_VALUE);
@@ -274,9 +269,7 @@
try {
index = Integer.parseInt(numericString, this.radix);
} catch (final NumberFormatException e) {
- this.logger.error("Invalid octal string, line "
- + this.currentLineNumber
- + ": " + numericString);
+ throw new PsException("Invalid octal string, line " + this.currentLineNumber + ": " + numericString, e);
}
if (index > WKConstants.MAX_8_BIT_UNSIGNED_VALUES - 1) {
index = WKConstants.MAX_8_BIT_UNSIGNED_VALUES - 1;
@@ -333,8 +326,9 @@
* For each glyph name in the encoding, finds all known Unicode code points
* that map to that glyph name, and writes them to an array. It also writes
* the glyph index for this encoding to a parallel array.
+ * @throws PsException If a glyph name cannot be mapped to a code point.
*/
- private void createCodePoints() {
+ private void createCodePoints() throws PsException {
StringTokenizer tokenizer = null;
int numListsToCheck = 1;
if (this.glyphLists != null
@@ -368,7 +362,7 @@
}
if (this.codePointIndexes.get(i) == 0
&& ! glyphName.equals(EncodingVector4a.NOTDEF)) {
- this.logger.error("Glyph name not found: " + glyphName);
+ throw new PsException("Glyph name not found: " + glyphName);
}
}
}
@@ -658,8 +652,7 @@
if (args.length > EncodingParser.ARG_GLYPH_LISTS) {
customGlyphLists = args[EncodingParser.ARG_GLYPH_LISTS];
}
- final EncodingParser parser = new EncodingParser(logger, input,
- columnNum, radix, customGlyphLists);
+ final EncodingParser parser = new EncodingParser(input, columnNum, radix, customGlyphLists);
try {
parser.parseList();
} catch (final IOException e3) {
@@ -667,6 +660,11 @@
+ args[EncodingParser.ARG_INPUT_URL] + "\n");
logger.error(" " + e3.getMessage());
System.exit(1);
+ } catch (final PsException e3) {
+ logger.error("Error parsing: "
+ + args[EncodingParser.ARG_INPUT_URL] + "\n");
+ logger.error(" " + e3.getMessage());
+ System.exit(1);
}
try {
parser.writeAsJavaStatics(output);
Modified: trunk/foray/foray-ps/src/java/org/foray/ps/encode/GlyphListParser.java
===================================================================
--- trunk/foray/foray-ps/src/java/org/foray/ps/encode/GlyphListParser.java 2009-04-30 16:03:09 UTC (rev 10834)
+++ trunk/foray/foray-ps/src/java/org/foray/ps/encode/GlyphListParser.java 2009-04-30 16:22:59 UTC (rev 10835)
@@ -33,6 +33,8 @@
import org.foray.common.WKConstants;
import org.foray.common.url.URLFactory;
+import org.axsl.ps.PsException;
+
import org.apache.commons.logging.Log;
import java.io.BufferedReader;
@@ -80,16 +82,11 @@
* @see #getGlyphNameIndex() */
private short[] glyphNameIndex;
- /** The logger. */
- private Log logger;
-
/**
* Create a new GlyphListParser instance.
- * @param logger The logger.
* @param input The file to be parsed.
*/
- public GlyphListParser(final Log logger, final InputStream input) {
- this.logger = logger;
+ public GlyphListParser(final InputStream input) {
final InputStreamReader isr = new InputStreamReader(input);
this.reader = new BufferedReader(isr);
}
@@ -97,8 +94,9 @@
/**
* Parses a glyph list.
* @throws IOException For I/O Error.
+ * @throws PsException For errors parsing the input.
*/
- public void parseList() throws IOException {
+ public void parseList() throws IOException, PsException {
parseLines();
sortGlyphNames();
copyCodePoints();
@@ -109,8 +107,9 @@
/**
* Parse the lines of the file.
* @throws IOException For I/O Error.
+ * @throws PsException For errors parsing the input.
*/
- private void parseLines() throws IOException {
+ private void parseLines() throws IOException, PsException {
boolean endOfFile = false;
endOfFile = false;
int arrayIndex = 0;
@@ -153,10 +152,10 @@
/**
* Parsed the current line of content.
* @param line The line from the input file.
- * @param arrayIndex The index into the arrays of parsed input into which
- * the parsed input should be placed.
+ * @param arrayIndex The index into the arrays of parsed input into which the parsed input should be placed.
+ * @throws PsException For errors parsing the line.
*/
- private void processCurrentLine(final String line, final int arrayIndex) {
+ private void processCurrentLine(final String line, final int arrayIndex) throws PsException {
this.glyphNames.add(StringUtil.EMPTY_STRING);
this.codePointsForGlyphNames.add(GlyphListParser.EMPTY_CHAR_ARRAY);
@@ -167,17 +166,12 @@
this.glyphNames.set(arrayIndex, tokens[0]);
final char[] charArray = new char[tokens.length - 1];
for (int i = 1; i < tokens.length; i++) {
- int parsedValue = Integer.parseInt(tokens[i],
- WKConstants.MAX_4_BIT_UNSIGNED_VALUES);
+ final int parsedValue = Integer.parseInt(tokens[i], WKConstants.MAX_4_BIT_UNSIGNED_VALUES);
if (parsedValue < 0) {
- this.logger.error("Value out of range, line "
- + this.currentLineNumber);
- parsedValue = 0;
+ throw new PsException("Value out of range, line " + this.currentLineNumber);
}
if (parsedValue > WKConstants.MAX_16_BIT_UNSIGNED_VALUES - 1) {
- this.logger.error("Value out of range, line "
- + this.currentLineNumber);
- parsedValue = WKConstants.MAX_16_BIT_UNSIGNED_VALUES - 1;
+ throw new PsException("Value out of range, line " + this.currentLineNumber);
}
charArray[i - 1] = (char) parsedValue;
}
@@ -437,13 +431,17 @@
+ args[1] + "\n");
System.exit(1);
}
- final GlyphListParser parser = new GlyphListParser(logger, input);
+ final GlyphListParser parser = new GlyphListParser(input);
try {
parser.parseList();
} catch (final IOException e3) {
logger.error("Error parsing: " + args[0] + "\n");
logger.error(" " + e3.getMessage());
System.exit(1);
+ } catch (final PsException e3) {
+ logger.error("Error parsing: " + args[0] + "\n");
+ logger.error(" " + e3.getMessage());
+ System.exit(1);
}
try {
parser.writeAsJavaStatics(output);
Modified: trunk/foray/foray-ps/src/javatest/org/foray/ps/encode/TestEncodingParser.java
===================================================================
--- trunk/foray/foray-ps/src/javatest/org/foray/ps/encode/TestEncodingParser.java 2009-04-30 16:03:09 UTC (rev 10834)
+++ trunk/foray/foray-ps/src/javatest/org/foray/ps/encode/TestEncodingParser.java 2009-04-30 16:22:59 UTC (rev 10835)
@@ -28,9 +28,10 @@
package org.foray.ps.encode;
-import org.foray.common.Logging;
import org.foray.common.TestFOrayCommon;
+import org.axsl.ps.PsException;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -46,15 +47,16 @@
/**
* Black-box test, parsing the glyph list for the WinAnsi Encoding.
* @throws IOException For errors opening or reading the input file.
+ * @throws PsException For errors parsing the input.
*/
- public void testWinAnsi() throws IOException {
+ public void testWinAnsi() throws IOException, PsException {
final File sandbox = TestFOrayCommon.getSandbox();
final File testFile = new File(sandbox, "foray-ps/resource/encoding/latin-pdf.txt");
final InputStream input = new FileInputStream(testFile);
assertNotNull(input);
/* The WinAnsi content is in column 3, and the radix is octal. See the file itself for details. */
- final EncodingParser parser = new EncodingParser(Logging.makeDefaultLogger(), input, 3, 8, null);
+ final EncodingParser parser = new EncodingParser(input, 3, 8, null);
parser.parseList();
/* Did we parse the right number of elements. Last element is on line 237. First 8 lines are blank. In the
Modified: trunk/foray/foray-ps/src/javatest/org/foray/ps/encode/TestGlyphListParser.java
===================================================================
--- trunk/foray/foray-ps/src/javatest/org/foray/ps/encode/TestGlyphListParser.java 2009-04-30 16:03:09 UTC (rev 10834)
+++ trunk/foray/foray-ps/src/javatest/org/foray/ps/encode/TestGlyphListParser.java 2009-04-30 16:22:59 UTC (rev 10835)
@@ -28,9 +28,10 @@
package org.foray.ps.encode;
-import org.foray.common.Logging;
import org.foray.common.TestFOrayCommon;
+import org.axsl.ps.PsException;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -45,14 +46,15 @@
/**
* Black-box test, parsing the glyph list for Zapf Dingbats.
* @throws IOException For errors opening or reading the input file.
+ * @throws PsException For errors parsing the input.
*/
- public void testZdGl() throws IOException {
+ public void testZdGl() throws IOException, PsException {
final File sandbox = TestFOrayCommon.getSandbox();
final File testFile = new File(sandbox, "foray-ps/resource/glyph-list/zapfdingbats.txt");
final FileInputStream input = new FileInputStream(testFile);
assertNotNull(input);
- final GlyphListParser parser = new GlyphListParser(Logging.makeDefaultLogger(), input);
+ final GlyphListParser parser = new GlyphListParser(input);
parser.parseList();
/* Test that we parsed the right number of elements. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|