[FOray-commit] SF.net SVN: foray:[12083] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2021-11-18 14:35:20
|
Revision: 12083
http://sourceforge.net/p/foray/code/12083
Author: victormote
Date: 2021-11-18 14:35:17 +0000 (Thu, 18 Nov 2021)
Log Message:
-----------
Convert SaxParser from a utility class to an abstract superclass, to promote sharing of code amongst parsers.
Modified Paths:
--------------
trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java
trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java
trunk/foray/foray-core/src/main/java/org/foray/core/ForayDocument.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/NatLangParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyConfigParser.java
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java 2021-11-18 13:52:42 UTC (rev 12082)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java 2021-11-18 14:35:17 UTC (rev 12083)
@@ -31,7 +31,6 @@
import org.foray.app.ForaySpecific;
import org.foray.common.Environment;
import org.foray.common.url.UrlFactory;
-import org.foray.common.xml.SaxParser;
import org.foray.core.ForayException;
import org.foray.core.SessionConfig;
import org.foray.fotree.FoTreeBuilder;
@@ -127,6 +126,7 @@
* @throws ForayException For errors building the FO Tree.
*/
public FoTreeBuilder buildFoTree(final String file) throws ForayException {
+ final FoTreeBuilder foTreeBuilder = this.treeServer.makeFoTree();
final File foFile = new File(this.testDirectory, file);
final InputStream foInputStream;
try {
@@ -137,17 +137,16 @@
final InputSource foInputSource = new InputSource(foInputStream);
final XMLReader xmlReader;
try {
- xmlReader = SaxParser.createSax2Parser();
+ xmlReader = foTreeBuilder.createSax2Parser();
} catch (final SAXException e) {
throw new ForayException(e);
} catch (final ParserConfigurationException e) {
throw new ForayException(e);
}
- final FoTreeBuilder foTree = this.treeServer.makeFoTree();
final FontServer fontServer = this.treeServer.getFontServer();
final FontConsumer fontConsumer = fontServer.makeFontConsumer();
- foTree.setFontConsumer(fontConsumer);
- xmlReader.setContentHandler(foTree);
+ foTreeBuilder.setFontConsumer(fontConsumer);
+ xmlReader.setContentHandler(foTreeBuilder);
try {
xmlReader.parse(foInputSource);
} catch (final IOException e) {
@@ -155,7 +154,7 @@
} catch (final SAXException e) {
throw new ForayException(e);
}
- return foTree;
+ return foTreeBuilder;
}
/**
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java 2021-11-18 13:52:42 UTC (rev 12082)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java 2021-11-18 14:35:17 UTC (rev 12083)
@@ -30,22 +30,17 @@
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
+import org.xml.sax.ext.DefaultHandler2;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
/**
- * Utility class that provides information about an XML Parser.
+ * Abstract superclass for SAX parsers.
*/
-public final class SaxParser {
+public abstract class SaxParser extends DefaultHandler2 {
/**
- * Private constructor (should not be instantiated).
- */
- private SaxParser() {
- }
-
- /**
* Returns the name of the SAX Parser class that is found in the classpath.
* @return The name of the SAX Parser class that is found in the classpath.
*/
@@ -68,7 +63,7 @@
* @throws SAXException For errors creating the parser.
* @throws ParserConfigurationException For errors configuring the parser.
*/
- public static XMLReader createSax2Parser() throws SAXException, ParserConfigurationException {
+ public XMLReader createSax2Parser() throws SAXException, ParserConfigurationException {
final SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
XMLReader xmlReader = null;
Modified: trunk/foray/foray-core/src/main/java/org/foray/core/ForayDocument.java
===================================================================
--- trunk/foray/foray-core/src/main/java/org/foray/core/ForayDocument.java 2021-11-18 13:52:42 UTC (rev 12082)
+++ trunk/foray/foray-core/src/main/java/org/foray/core/ForayDocument.java 2021-11-18 14:35:17 UTC (rev 12083)
@@ -54,6 +54,7 @@
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
@@ -458,7 +459,10 @@
XMLReader createParser() throws ForayException {
final XMLReader xmlReader;
try {
- xmlReader = SaxParser.createSax2Parser();
+ final SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
+ spf.setNamespaceAware(true);
+ xmlReader = spf.newSAXParser().getXMLReader();
+ xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
} catch (final SAXException e) {
throw new ForayException(e);
} catch (final ParserConfigurationException e) {
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java 2021-11-18 13:52:42 UTC (rev 12082)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java 2021-11-18 14:35:17 UTC (rev 12083)
@@ -28,6 +28,7 @@
package org.foray.fotree;
+import org.foray.common.xml.SaxParser;
import org.foray.fotree.axsl.NamespaceAxsl;
import org.foray.fotree.fo.NamespaceFo;
import org.foray.fotree.fo.obj.PageSequence;
@@ -51,7 +52,6 @@
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
import java.net.URL;
import java.util.ArrayList;
@@ -60,8 +60,7 @@
/**
* SAX Handler that builds the formatting object tree.
*/
-public class FoTreeBuilder extends DefaultHandler
- implements org.axsl.fo.FoTree {
+public class FoTreeBuilder extends SaxParser implements org.axsl.fo.FoTree {
/** The current formatting object being parsed. */
private FoObj currentFObj = null;
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternParser.java 2021-11-18 13:52:42 UTC (rev 12082)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternParser.java 2021-11-18 14:35:17 UTC (rev 12083)
@@ -45,7 +45,6 @@
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.DefaultHandler;
import java.io.IOException;
import java.io.InputStream;
@@ -57,7 +56,7 @@
* A SAX document handler to read and parse hyphenation patterns
* from a XML file.
*/
-public class PatternParser extends DefaultHandler {
+public class PatternParser extends SaxParser {
/** Constant indicating that the current element is "classes". */
static final int ELEM_CLASSES = 1;
@@ -101,7 +100,7 @@
}
this.token = new StringBuilder();
try {
- this.parser = SaxParser.createSax2Parser();
+ this.parser = createSax2Parser();
} catch (final SAXException | ParserConfigurationException e) {
throw new OrthographyException(e);
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/NatLangParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/NatLangParser.java 2021-11-18 13:52:42 UTC (rev 12082)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/NatLangParser.java 2021-11-18 14:35:17 UTC (rev 12083)
@@ -48,7 +48,6 @@
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.DefaultHandler;
import java.io.IOException;
import java.io.InputStream;
@@ -61,7 +60,7 @@
* A SAX document handler to read and parse natural-language descriptions
* from an XML file.
*/
-public class NatLangParser extends DefaultHandler {
+public class NatLangParser extends SaxParser {
/** The natural language instance being parsed. */
private NaturalLanguage nl;
@@ -87,7 +86,7 @@
this.logger = logger;
}
try {
- this.parser = SaxParser.createSax2Parser();
+ this.parser = createSax2Parser();
} catch (final SAXException e) {
this.logger.error(e.getMessage(), e);
} catch (final ParserConfigurationException e) {
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyConfigParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyConfigParser.java 2021-11-18 13:52:42 UTC (rev 12082)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyConfigParser.java 2021-11-18 14:35:17 UTC (rev 12083)
@@ -533,7 +533,6 @@
@SuppressWarnings("unchecked")
final Class<T> factoryClass = (Class<T>) theClass;
- /* For now, use only the no-args constructor. */
Constructor<T> constructor = null;
try {
constructor = factoryClass.getConstructor(parameterTypes);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|