[FOray-commit] SF.net SVN: foray: [10485] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2008-03-22 19:09:28
|
Revision: 10485
http://foray.svn.sourceforge.net/foray/?rev=10485&view=rev
Author: victormote
Date: 2008-03-22 12:09:30 -0700 (Sat, 22 Mar 2008)
Log Message:
-----------
1. Add checkstyle restrictions on use of System.out, System.err, and dumping of stack traces.
2. Fix occurrences of same, some by using loggers, others by throwing exceptions, others by suppressing the check.
Modified Paths:
--------------
trunk/foray/foray-common/src/java/org/foray/common/FOrayLogger.java
trunk/foray/foray-core/src/java/org/foray/core/FOrayException.java
trunk/foray/foray-font/src/java/org/foray/font/ConfigGenerator.java
trunk/foray/foray-hyphen/src/java/org/foray/hyphen/PatternGenerator.java
trunk/foray/foray-hyphen/src/java/org/foray/hyphen/util/ValidateChars.java
trunk/foray/foray-pretty/.classpath
trunk/foray/foray-pretty/src/java/org/foray/pretty/FOrayPretty.java
trunk/foray/foray-pretty/src/java/org/foray/pretty/FOrayXDiff.java
trunk/foray/foray-ps/src/java/org/foray/ps/java2d/demo/DemoPanel.java
trunk/foray/scripts/checkstyle-config.xml
Modified: trunk/foray/foray-common/src/java/org/foray/common/FOrayLogger.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/FOrayLogger.java 2008-03-22 18:24:10 UTC (rev 10484)
+++ trunk/foray/foray-common/src/java/org/foray/common/FOrayLogger.java 2008-03-22 19:09:30 UTC (rev 10485)
@@ -53,7 +53,9 @@
* System.err.
*/
protected void write(final StringBuffer buffer) {
+ /* Checkstyle-GenericIllegalRegexp-Off. */
System.out.println(buffer.toString());
+ /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-core/src/java/org/foray/core/FOrayException.java
===================================================================
--- trunk/foray/foray-core/src/java/org/foray/core/FOrayException.java 2008-03-22 18:24:10 UTC (rev 10484)
+++ trunk/foray/foray-core/src/java/org/foray/core/FOrayException.java 2008-03-22 19:09:30 UTC (rev 10485)
@@ -190,6 +190,7 @@
* {@inheritDoc}
*/
public void printStackTrace() {
+ /* Checkstyle-GenericIllegalRegexp-Off. */
synchronized (System.err) {
super.printStackTrace();
if (this.exception != null) {
@@ -201,6 +202,7 @@
getRootException().printStackTrace();
}
}
+ /* Checkstyle-GenericIllegalRegexp-On. */
}
/**
Modified: trunk/foray/foray-font/src/java/org/foray/font/ConfigGenerator.java
===================================================================
--- trunk/foray/foray-font/src/java/org/foray/font/ConfigGenerator.java 2008-03-22 18:24:10 UTC (rev 10484)
+++ trunk/foray/foray-font/src/java/org/foray/font/ConfigGenerator.java 2008-03-22 19:09:30 UTC (rev 10485)
@@ -165,9 +165,8 @@
serializer.setOutputByteStream(tempOut);
try {
serializer.serialize(document);
- } catch (final IOException e1) {
- System.err.println("Error serializing DOM:\n "
- + e1.getMessage());
+ } catch (final IOException e) {
+ throw new FontException("Error serializing DOM: " + e.getMessage());
}
final byte[] serializedDOM = tempOut.toByteArray();
Modified: trunk/foray/foray-hyphen/src/java/org/foray/hyphen/PatternGenerator.java
===================================================================
--- trunk/foray/foray-hyphen/src/java/org/foray/hyphen/PatternGenerator.java 2008-03-22 18:24:10 UTC (rev 10484)
+++ trunk/foray/foray-hyphen/src/java/org/foray/hyphen/PatternGenerator.java 2008-03-22 19:09:30 UTC (rev 10485)
@@ -54,11 +54,14 @@
package org.foray.hyphen;
+import org.foray.common.FOrayLogger;
import org.foray.common.NumberUtil;
import org.foray.common.WKConstants;
import org.axsl.hyphen.HyphenationException;
+import org.apache.commons.logging.Log;
+
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -320,6 +323,9 @@
/** The output stream. */
private PrintStream output;
+ /** The logger (lazily created). Use {#getLogger()} to get the instance. */
+ private Log logger;
+
/**
* Constructor.
* @param input The input stream to be read.
@@ -336,12 +342,12 @@
* @throws HyphenationException For errors during processing.
*/
public void process() throws HyphenationException {
- System.out.println(this.banner);
+ getLogger().info(this.banner);
if (this.input == null) {
- System.out.println("Error: Input cannot be null.");
+ getLogger().error("Error: Input cannot be null.");
}
if (this.output == null) {
- System.out.println("Error: Output cannot be null.");
+ getLogger().error("Error: Output cannot be null.");
}
patgen();
}
@@ -828,7 +834,7 @@
throw new HyphenationException("PATGEN capacity exceeded, sorry ["
+ PatternGenerator.TRIEC_SIZE + " count trie nodes].");
}
- System.out.printf("%ld%s", (long) this.trieckmax / 1024 , "K ");
+ getLogger().info(this.trieckmax / 1024 + "K ");
if (this.trieckmax > PatternGenerator.TRIEC_SIZE - 4096) {
this.trieckmax = PatternGenerator.TRIEC_SIZE;
} else {
@@ -979,7 +985,7 @@
n1String = readInput(System.in);
n2String = readInput(System.in);
} catch (final IOException e) {
- System.err.println("Error reading from stdin.");
+ getLogger().error("Error reading from stdin.");
}
this.n1 = Integer.parseInt(n1String);
this.n2 = Integer.parseInt(n2String);
@@ -992,7 +998,7 @@
try {
n3String = readInput(System.in);
} catch (final IOException e) {
- System.err.println("Error reading from stdin.");
+ getLogger().error("Error reading from stdin.");
}
this.n3 = Integer.parseInt(n3String);
}
@@ -1101,7 +1107,7 @@
if (bad) {
bad = false;
do {
- System.out.print("left_hyphen_min, right_hyphen_min: ");
+ getLogger().info("left_hyphen_min, right_hyphen_min: ");
input2ints();
if ((this.n1 >= 1)
&& (this.n1 < PatternGenerator.MAX_DOT)
@@ -2178,4 +2184,15 @@
/* Checkstyle-GenericIllegalRegexp-On. */
}
+ /**
+ * Returns the logger.
+ * @return The logger.
+ */
+ public Log getLogger() {
+ if (this.logger == null) {
+ this.logger = new FOrayLogger("FOray PatternGenerator");
+ }
+ return this.logger;
+ }
+
}
Modified: trunk/foray/foray-hyphen/src/java/org/foray/hyphen/util/ValidateChars.java
===================================================================
--- trunk/foray/foray-hyphen/src/java/org/foray/hyphen/util/ValidateChars.java 2008-03-22 18:24:10 UTC (rev 10484)
+++ trunk/foray/foray-hyphen/src/java/org/foray/hyphen/util/ValidateChars.java 2008-03-22 19:09:30 UTC (rev 10485)
@@ -28,11 +28,13 @@
package org.foray.hyphen.util;
+import org.foray.common.FOrayLogger;
import org.foray.common.url.URLFactory;
import org.foray.hyphen.HyphenationServer4a;
import org.axsl.common.value.Iso639;
+import org.apache.commons.logging.Log;
import org.apache.xerces.util.XMLCatalogResolver;
import org.xml.sax.Attributes;
@@ -110,6 +112,9 @@
/** The server used to find natural language resources. */
private HyphenationServer4a server;
+ /** The logger (lazily created). Use {#getLogger()} to get the instance. */
+ private Log logger;
+
/**
* Constructor.
* @param server The server used to find natural language resources.
@@ -140,8 +145,7 @@
public void start() throws IOException, SAXException,
ParserConfigurationException {
if (this.iso639 == null) {
- System.err.println("Not a valid ISO-639 code: "
- + this.languageCode);
+ logError("Not a valid ISO-639 code: " + this.languageCode);
return;
}
final XMLReader parser = createParser();
@@ -302,16 +306,27 @@
}
/**
+ * Returns the logger.
+ * @return The logger.
+ */
+ public Log getLogger() {
+ if (this.logger == null) {
+ this.logger = new FOrayLogger("FOray ValidateChars");
+ }
+ return this.logger;
+ }
+
+ /**
* Convenience method to log an error.
* @param message The message to be logged.
*/
private void logError(final String message) {
if (this.locator != null) {
- System.out.print(this.locator.getSystemId() + ":"
+ getLogger().error(this.locator.getSystemId() + ":"
+ this.locator.getLineNumber() + ":"
+ this.locator.getColumnNumber() + "\n ");
}
- System.out.print(message + "\n");
+ getLogger().error(message + "\n");
}
/**
@@ -326,7 +341,7 @@
final NaturalLanguage nl = this.server.getNaturalLanguage(
this.iso639);
if (nl == null) {
- System.err.println("Cannot get NaturalLanguage instance for: "
+ logError("Cannot get NaturalLanguage instance for: "
+ this.iso639.getEnglishName());
return;
}
Modified: trunk/foray/foray-pretty/.classpath
===================================================================
--- trunk/foray/foray-pretty/.classpath 2008-03-22 18:24:10 UTC (rev 10484)
+++ trunk/foray/foray-pretty/.classpath 2008-03-22 19:09:30 UTC (rev 10485)
@@ -7,5 +7,6 @@
<classpathentry kind="lib" path="/FOray Lib/stax-api-1.0.1.jar" sourcepath="/FOray Lib-Build/stax/stax-src-1.2.0.zip"/>
<classpathentry kind="lib" path="/FOray Lib/xercesImpl-2.7.1.jar" sourcepath="/FOray Lib-Build/xerces/Xerces-J-src.2.7.1.zip"/>
<classpathentry kind="lib" path="/FOray Lib/stax-1.2.0.jar" sourcepath="/FOray Lib-Build/stax/stax-src-1.2.0.zip"/>
+ <classpathentry kind="lib" path="/FOray Lib/commons-logging-1.1.jar" sourcepath="/FOray Lib-Build/commons-logging/commons-logging-1.1-src.zip"/>
<classpathentry kind="output" path="build/eclipse"/>
</classpath>
Modified: trunk/foray/foray-pretty/src/java/org/foray/pretty/FOrayPretty.java
===================================================================
--- trunk/foray/foray-pretty/src/java/org/foray/pretty/FOrayPretty.java 2008-03-22 18:24:10 UTC (rev 10484)
+++ trunk/foray/foray-pretty/src/java/org/foray/pretty/FOrayPretty.java 2008-03-22 19:09:30 UTC (rev 10485)
@@ -28,11 +28,13 @@
package org.foray.pretty;
+import org.foray.common.FOrayLogger;
import org.foray.common.XMLUtil;
import org.foray.pretty.dtd.DTD;
import org.foray.pretty.dtd.DTDElement;
import org.foray.pretty.dtd.ElementStack;
+import org.apache.commons.logging.Log;
import org.apache.xerces.util.XMLCatalogResolver;
import org.xml.sax.Attributes;
@@ -117,6 +119,9 @@
/** A queue of unprocessed elements. */
private Queue queue = new Queue();
+ /** The logger (lazily created). Use {#getLogger()} to get the instance. */
+ private Log logger;
+
/* Begin state variables. */
/** State variable tracking whether we are currently inside the DTD or
@@ -738,16 +743,27 @@
}
/**
+ * Returns the logger.
+ * @return The logger.
+ */
+ public Log getLogger() {
+ if (this.logger == null) {
+ this.logger = new FOrayLogger("FOray Pretty Print");
+ }
+ return this.logger;
+ }
+
+ /**
* Convenience method to log an error.
* @param message The message to be logged.
*/
private void logError(final String message) {
if (this.locator != null) {
- System.out.print(this.locator.getSystemId() + ":"
+ this.getLogger().error(this.locator.getSystemId() + ":"
+ this.locator.getLineNumber() + ":"
+ this.locator.getColumnNumber());
}
- System.out.print(message);
+ this.getLogger().error(message);
}
/**
Modified: trunk/foray/foray-pretty/src/java/org/foray/pretty/FOrayXDiff.java
===================================================================
--- trunk/foray/foray-pretty/src/java/org/foray/pretty/FOrayXDiff.java 2008-03-22 18:24:10 UTC (rev 10484)
+++ trunk/foray/foray-pretty/src/java/org/foray/pretty/FOrayXDiff.java 2008-03-22 19:09:30 UTC (rev 10485)
@@ -28,9 +28,12 @@
package org.foray.pretty;
+import org.foray.common.FOrayLogger;
import org.foray.common.StringUtil;
import org.foray.common.XMLUtil;
+import org.apache.commons.logging.Log;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -77,6 +80,9 @@
*/
private String[] readerIDs;
+ /** The logger (lazily created). Use {#getLogger()} to get the instance. */
+ private Log logger;
+
/* Begin configurable parameters. */
/** Ignores character items that are all whitespace. */
private boolean ignoreCharacterWhitespace = true;
@@ -388,16 +394,27 @@
* @param message The raw message to send to the user.
*/
private void message(final String message) {
- System.out.println(message);
+ this.getLogger().info(message);
for (int i = 0; i < this.readers.length; i++) {
final String sourceDescription = getSourceDescription(i);
final String sourceLocation = getSourceLocation(i);
- System.out.println(" Document " + (i + 1) + ": "
+ this.getLogger().info(" Document " + (i + 1) + ": "
+ sourceDescription + ":" + sourceLocation);
}
}
/**
+ * Returns the logger.
+ * @return The logger.
+ */
+ public Log getLogger() {
+ if (this.logger == null) {
+ this.logger = new FOrayLogger("FOrayXDiff");
+ }
+ return this.logger;
+ }
+
+ /**
* Provides a description of the document.
* @param inputIndex The index to the input items.
* @return The description of the input document.
Modified: trunk/foray/foray-ps/src/java/org/foray/ps/java2d/demo/DemoPanel.java
===================================================================
--- trunk/foray/foray-ps/src/java/org/foray/ps/java2d/demo/DemoPanel.java 2008-03-22 18:24:10 UTC (rev 10484)
+++ trunk/foray/foray-ps/src/java/org/foray/ps/java2d/demo/DemoPanel.java 2008-03-22 19:09:30 UTC (rev 10485)
@@ -47,6 +47,7 @@
import java.io.File;
import java.io.IOException;
+import javax.swing.JOptionPane;
import javax.swing.JPanel;
/**
@@ -123,7 +124,8 @@
j2dSystemDict);
interpreter.process();
} catch (final PSException e) {
- System.out.print(e.getMessage());
+ JOptionPane.showMessageDialog(this, e.getMessage(), "PSInterpreter Error",
+ JOptionPane.ERROR_MESSAGE);
}
g2d.setTransform(baktrans);
Modified: trunk/foray/scripts/checkstyle-config.xml
===================================================================
--- trunk/foray/scripts/checkstyle-config.xml 2008-03-22 18:24:10 UTC (rev 10484)
+++ trunk/foray/scripts/checkstyle-config.xml 2008-03-22 19:09:30 UTC (rev 10485)
@@ -211,6 +211,7 @@
</module>
<module name="GenericIllegalRegexp">
+ <property name="ignoreComments" value="false"/>
<property name="format" value="\s+$"/>
<property name="message" value="Line has trailing spaces."/>
</module>
@@ -220,6 +221,21 @@
<property name="format" value="System\.exit"/>
<property name="message" value="Never exit the jvm except in void main(String[])."/>
</module>
+ <module name="GenericIllegalRegexp">
+ <property name="ignoreComments" value="true"/>
+ <property name="format" value="printStacktrace"/>
+ <property name="message" value="Do not dump a stacktrace."/>
+ </module>
+ <module name="GenericIllegalRegexp">
+ <property name="ignoreComments" value="true"/>
+ <property name="format" value=" System.out.print"/>
+ <property name="message" value="Do not dump a stacktrace."/>
+ </module>
+ <module name="GenericIllegalRegexp">
+ <property name="ignoreComments" value="true"/>
+ <property name="format" value=" System.err.print"/>
+ <property name="message" value="Do not dump a stacktrace."/>
+ </module>
</module>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|