foray-commit Mailing List for FOray (Page 71)
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
(139) |
Apr
(98) |
May
(250) |
Jun
(394) |
Jul
(84) |
Aug
(13) |
Sep
(420) |
Oct
(186) |
Nov
(1) |
Dec
(3) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(108) |
Feb
(202) |
Mar
(291) |
Apr
(247) |
May
(374) |
Jun
(227) |
Jul
(231) |
Aug
(60) |
Sep
(31) |
Oct
(45) |
Nov
(18) |
Dec
|
| 2008 |
Jan
(38) |
Feb
(71) |
Mar
(142) |
Apr
|
May
(59) |
Jun
(6) |
Jul
(10) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2009 |
Jan
(12) |
Feb
(4) |
Mar
(88) |
Apr
(121) |
May
(17) |
Jun
(30) |
Jul
|
Aug
(5) |
Sep
|
Oct
(1) |
Nov
|
Dec
|
| 2010 |
Jan
(11) |
Feb
(76) |
Mar
(11) |
Apr
|
May
(11) |
Jun
|
Jul
|
Aug
(44) |
Sep
(14) |
Oct
(7) |
Nov
|
Dec
|
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(9) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(10) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(3) |
Jul
(4) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(168) |
| 2017 |
Jan
(77) |
Feb
(11) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
(6) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
|
Feb
(88) |
Mar
(118) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(6) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(141) |
| 2021 |
Jan
(170) |
Feb
(20) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(62) |
Nov
(189) |
Dec
(162) |
| 2022 |
Jan
(201) |
Feb
(118) |
Mar
(8) |
Apr
|
May
(2) |
Jun
(47) |
Jul
(19) |
Aug
(14) |
Sep
(3) |
Oct
|
Nov
(28) |
Dec
(235) |
| 2023 |
Jan
(112) |
Feb
(23) |
Mar
(2) |
Apr
(2) |
May
|
Jun
(1) |
Jul
|
Aug
(70) |
Sep
(92) |
Oct
(20) |
Nov
(1) |
Dec
(1) |
| 2024 |
Jan
|
Feb
|
Mar
(1) |
Apr
(1) |
May
(14) |
Jun
(11) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2025 |
Jan
(10) |
Feb
(29) |
Mar
|
Apr
(162) |
May
(245) |
Jun
(83) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(4) |
Dec
|
|
From: <vic...@us...> - 2021-11-24 14:01:22
|
Revision: 12127
http://sourceforge.net/p/foray/code/12127
Author: victormote
Date: 2021-11-24 14:01:19 +0000 (Wed, 24 Nov 2021)
Log Message:
-----------
Allow TernaryTree and related classes to specify an initial capacity so that the correct data structure for the nodes can be selected the first time.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryNodesChar.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryTree.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryTreeMap.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/TernaryTreeMapTests.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/PropertyType.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionary.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserText.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/SegmentDictionaryTests.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryNodesChar.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryNodesChar.java 2021-11-24 12:32:34 UTC (rev 12126)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryNodesChar.java 2021-11-24 14:01:19 UTC (rev 12127)
@@ -41,6 +41,9 @@
*/
public class TernaryNodesChar extends TernaryNodes {
+ /** The maximum number of nodes that can be stored. */
+ public static final int MAX_NODES = 65_536;
+
/** Constant needed for serialization. */
private static final long serialVersionUID = 6351290262839607022L;
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryTree.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryTree.java 2021-11-24 12:32:34 UTC (rev 12126)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryTree.java 2021-11-24 14:01:19 UTC (rev 12127)
@@ -120,13 +120,27 @@
/**
* Constructor.
+ * @param initialCapacity The number of nodes expected to be used by this tree.
+ * Note that the number of nodes is not the same as (is usually greater than) the number of key-value pairs.
*/
- public TernaryTree() {
- this.nodes = new TernaryNodesChar();
+ public TernaryTree(final int initialCapacity) {
+ if (initialCapacity > TernaryNodesChar.MAX_NODES) {
+ this.nodes = new TernaryNodesInt();
+ } else {
+ this.nodes = new TernaryNodesChar();
+ }
init();
}
/**
+ * Constructor which assumes that the number of nodes will not exceed {@link TernaryNodesChar#MAX_NODES}.
+ * @see TernaryTree#TernaryTree(int)
+ */
+ public TernaryTree() {
+ this(-1);
+ }
+
+ /**
* Private constructor used during cloning.
* @param nodes The data structure containing the branch indexes.
*/
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryTreeMap.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryTreeMap.java 2021-11-24 12:32:34 UTC (rev 12126)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryTreeMap.java 2021-11-24 14:01:19 UTC (rev 12127)
@@ -53,10 +53,16 @@
/** The values stored in this map. */
private List<V> values;
+ /** The number of nodes expected to be added to this map. */
+ private int initialCapacity;
+
/**
* Constructor.
+ * @param initialCapacity The number of nodes expected to be added to this map.
*/
- public TernaryTreeMap() {
+ public TernaryTreeMap(final int initialCapacity) {
+ /* Cache this in case we need to access it for clear(). */
+ this.initialCapacity = initialCapacity;
init();
}
@@ -64,7 +70,11 @@
* Initialize or clear the map data.
*/
private void init() {
- this.keys = new TernaryTree();
+ /* There is no good way to estimate the number of nodes in the ternary tree that will be needed to store a
+ * certain number of key-value pairs. If we estimate too high, we may waste some memory. If we estimate too
+ * low, we may waste some time as the tree resizes itself. */
+ final int estimatedQtyTernaryNodes = this.initialCapacity * 3;
+ this.keys = new TernaryTree(estimatedQtyTernaryNodes);
this.values = new ArrayList<V>();
}
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/data/TernaryTreeMapTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/data/TernaryTreeMapTests.java 2021-11-24 12:32:34 UTC (rev 12126)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/TernaryTreeMapTests.java 2021-11-24 14:01:19 UTC (rev 12127)
@@ -49,7 +49,7 @@
*/
@Before
public void setUp() {
- this.out = new TernaryTreeMap<String>();
+ this.out = new TernaryTreeMap<String>(1000);
Assert.assertTrue(this.out.isEmpty());
this.out.put("Key 1", "Value 1");
this.out.put("Key 2", "Value 2");
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/PropertyType.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/PropertyType.java 2021-11-24 12:32:34 UTC (rev 12126)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/PropertyType.java 2021-11-24 14:01:19 UTC (rev 12127)
@@ -30,6 +30,7 @@
/**
* Common interface for all enumerated property classes.
+ * Use of this interface allows the enumerated property types from different namespaces to have a common parent.
*/
public interface PropertyType {
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionary.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionary.java 2021-11-24 12:32:34 UTC (rev 12126)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionary.java 2021-11-24 14:01:19 UTC (rev 12127)
@@ -49,11 +49,8 @@
/** Constant needed for serialization. */
private static final long serialVersionUID = -8752423281137349847L;
- /** The data structure containing the dictionary words.
- * TODO: More work needs to be done to determine which Map implementation should be used here.
- * The TernaryTreeMap currently uses approximately 50% more memory, but has not been optimized for memory use.
- * The other tradeoff axis is speed, and we are not sure which implementation is faster. */
- private Map<CharSequence, SegmentDictionaryWord> wordMap = new TernaryTreeMap<SegmentDictionaryWord>();
+ /** The data structure containing the dictionary words. */
+ private Map<CharSequence, SegmentDictionaryWord> wordMap;
/** Map of the ambiguous words. These are expected to be few, so we worry less about memory and performance. */
private Map<CharSequence, AmbiguousWord<SegmentDictionaryWord>> ambiguousWordMap =
@@ -65,8 +62,10 @@
/**
* Constructor.
* @param uniqueWordSegments The array of word segments that can be used by words in this dictionary.
+ * @param initialCapacity The number of words that are expected to be added to this dictionary.
+ * This will give the dictionary a clue about how best to balance memory and performance issues.
*/
- public SegmentDictionary(final StringWordSegment[] uniqueWordSegments) {
+ public SegmentDictionary(final StringWordSegment[] uniqueWordSegments, final int initialCapacity) {
if (uniqueWordSegments.length > Character.MAX_VALUE + 1) {
throw new IllegalArgumentException("Size of segments: " + uniqueWordSegments.length +
" exceeds capacity: " + (Character.MAX_VALUE + 1));
@@ -73,6 +72,11 @@
}
Arrays.sort(uniqueWordSegments);
this.wordSegments = uniqueWordSegments;
+
+ /* TODO: More work needs to be done to determine which Map implementation should be used here.
+ * The TernaryTreeMap currently uses approximately 50% more memory, but has not been optimized for memory use.
+ * The other tradeoff axis is speed, and we are not sure which implementation is faster.*/
+ this.wordMap = new TernaryTreeMap<SegmentDictionaryWord>(initialCapacity);
}
/**
@@ -132,7 +136,7 @@
}
final StringWordSegmentUtf16[] segmentArray = new StringWordSegmentUtf16[segments.size()];
segments.toArray(segmentArray);
- final SegmentDictionary dictionary = new SegmentDictionary(segmentArray);
+ final SegmentDictionary dictionary = new SegmentDictionary(segmentArray, stringWords.size());
for (int index = 0; index < stringWords.size(); index ++) {
final StringWord stringWord = stringWords.get(index);
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-24 12:32:34 UTC (rev 12126)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-24 14:01:19 UTC (rev 12127)
@@ -150,7 +150,7 @@
final StringWordSegment[] uniqueWordSegments = new StringWordSegment[segmentSet.size()];
segmentSet.toArray(uniqueWordSegments);
Arrays.sort(uniqueWordSegments);
- final SegmentDictionary dictionary = new SegmentDictionary(uniqueWordSegments);
+ final SegmentDictionary dictionary = new SegmentDictionary(uniqueWordSegments, this.wordMap.size());
for (Map.Entry<String, StringWord> entry : this.wordMap.entrySet()) {
dictionary.addWord(entry.getKey(), entry.getValue());
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserText.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserText.java 2021-11-24 12:32:34 UTC (rev 12126)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserText.java 2021-11-24 14:01:19 UTC (rev 12127)
@@ -158,7 +158,7 @@
final StringWordSegment[] uniqueWordSegments = new StringWordSegment[segmentSet.size()];
segmentSet.toArray(uniqueWordSegments);
Arrays.sort(uniqueWordSegments);
- final SegmentDictionary dictionary = new SegmentDictionary(uniqueWordSegments);
+ final SegmentDictionary dictionary = new SegmentDictionary(uniqueWordSegments, wordMap.size());
for (Map.Entry<String, StringWord> entry : wordMap.entrySet()) {
dictionary.addWord(entry.getKey(), entry.getValue());
}
Modified: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/SegmentDictionaryTests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/SegmentDictionaryTests.java 2021-11-24 12:32:34 UTC (rev 12126)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/SegmentDictionaryTests.java 2021-11-24 14:01:19 UTC (rev 12127)
@@ -92,7 +92,7 @@
* */
Assert.assertEquals(8, segmentsArray.length);
- out = new SegmentDictionary(segmentsArray);
+ out = new SegmentDictionary(segmentsArray, 1000);
out.addWord(WORD_ATTENTION.getActualContent().toString(), WORD_ATTENTION);
out.addWord(WORD_INTENTION.getActualContent().toString(), WORD_INTENTION);
out.addWord(WORD_AMBITION.getActualContent().toString(), WORD_AMBITION);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-24 12:32:37
|
Revision: 12126
http://sourceforge.net/p/foray/code/12126
Author: victormote
Date: 2021-11-24 12:32:34 +0000 (Wed, 24 Nov 2021)
Log Message:
-----------
Minor cleanup of FoTreeParser4a.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java
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-24 11:56:29 UTC (rev 12125)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java 2021-11-24 12:32:34 UTC (rev 12126)
@@ -157,6 +157,18 @@
}
/**
+ * Returns the locator, if any, for this parsing session.
+ * This may be useful for some subclasses that need fine-grained control over reporting, but most will want to use
+ * {@link #getLocationString()} or {@link #getShortLocationString()} instead.
+ * @return The locator.
+ * @see #getLocationString()
+ * @see #getShortLocationString()
+ */
+ protected Locator getLocator() {
+ return this.locator;
+ }
+
+ /**
* Creates a SAX2 parser.
* @param validate Indicates whether the parser should validate the document as it parses.
* @param namespaceAware Indicates whether the parser should be namespace-aware.
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java 2021-11-24 11:56:29 UTC (rev 12125)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java 2021-11-24 12:32:34 UTC (rev 12126)
@@ -64,9 +64,6 @@
/** The root of the formatting object tree. */
private Root rootFObj = null;
- /** The SAX locator. */
- private Locator locator;
-
/** Collection of objects that have registered to be notified about FOTreeEvent firings. */
private List<FoTreeListener> foTreeListeners = new ArrayList<FoTreeListener>();
@@ -83,6 +80,8 @@
* Constructor.
* @param server The parent server.
* @param parser The parser. If null, one will be created.
+ * If not null, something upstream is providing the parser, probably as part of a pipeline, and we will use the
+ * provided parser.
*/
public FoTreeParser4a(final FoTreeServer4a server, final XMLReader parser) {
this.server = server;
@@ -131,8 +130,8 @@
}
@Override
- public void characters(final char[] data, final int start, final int length)
- throws SAXException {
+ public void characters(final char[] data, final int start, final int length) throws SAXException {
+ /* Overrides the standard Sax2Parser processing. */
if (this.activeForeignXML != null) {
// If inside foreign XML, let the ForeignXml instance handle it.
this.activeForeignXML.characters(data, start, length);
@@ -141,9 +140,9 @@
if (this.currentFObj != null) {
try {
this.currentFObj.addCharacters(data, start, length,
- this.locator.getSystemId(),
- this.locator.getLineNumber(),
- this.locator.getColumnNumber());
+ getLocator().getSystemId(),
+ getLocator().getLineNumber(),
+ getLocator().getColumnNumber());
} catch (final FoTreeException e) {
throw new SAXException(e);
}
@@ -198,11 +197,6 @@
}
@Override
- public void setDocumentLocator(final Locator locator) {
- this.locator = locator;
- }
-
- @Override
public void startElement(final String namespaceURI, final String localName,
final String rawName, final Attributes attlist)
throws SAXException {
@@ -214,8 +208,7 @@
}
final Namespace namespace = getTreeServer().getNamespace(namespaceURI);
if (namespace == null) {
- final String message = "Unregistered namespace: " + namespaceURI + ": " + getLine()
- + ":" + getColumn();
+ final String message = "Unregistered namespace: " + namespaceURI + ": " + getShortLocationString();
throw new SAXException(message);
}
/* the formatting object started */
@@ -228,14 +221,13 @@
+ "parsed");
}
}
- fobj = namespace.parseElement(this.foTree, localName, this.currentFObj, list, this.locator, this);
- if (this.locator != null) {
- fobj.setLocation(this.locator.getSystemId(),
- this.locator.getLineNumber(),
- this.locator.getColumnNumber());
+ fobj = namespace.parseElement(this.foTree, localName, this.currentFObj, list, getLocator(), this);
+ if (getLocator() != null) {
+ final Locator locator = getLocator();
+ fobj.setLocation(locator.getSystemId(), locator.getLineNumber(), locator.getColumnNumber());
}
fobj.validateAncestry();
- namespace.parseAttributes(list, attlist, fobj, this.locator, this);
+ namespace.parseAttributes(list, attlist, fobj, getLocator(), this);
fobj.validateProperties();
/* If the parent is not null (which it can be for Root), register
* the newly-created object as a child of the parent. */
@@ -258,11 +250,10 @@
/**
* Sets the root object if it is not already set.
- * @param fobj The FoObj that is being processed, which is a candidate to be
- * the root element if it is not already set.
- * @throws SAXException If the root element is missing its namespace
- * declaration, or if there is an element in the tree before any root
- * element.
+ * @param fobj The FoObj that is being processed, which is a candidate to be the root element if it is not already
+ * set.
+ * @throws SAXException If the root element is missing its namespace declaration, or if there is an element in the
+ * tree before any root element.
*/
private void checkRoot(final FoObj fobj) throws SAXException {
if (this.rootFObj != null) {
@@ -286,30 +277,6 @@
throw new SAXException(new FoTreeException(fote));
}
- /**
- * Returns the line number currently showing in the SAX Locator.
- * @return The line number currently showing in the SAX Locator.
- */
- private int getLine() {
- int line = -1;
- if (this.locator != null) {
- line = this.locator.getLineNumber();
- }
- return line;
- }
-
- /**
- * Returns the column number currently showing in the SAX Locator.
- * @return The column number currently showing in the SAX Locator.
- */
- private int getColumn() {
- int column = -1;
- if (this.locator != null) {
- column = this.locator.getColumnNumber();
- }
- return column;
- }
-
@Override
public void registerListener(final FoTreeListener listener) {
if (listener == null) {
@@ -389,15 +356,6 @@
}
/**
- * Returns the name of a given property type.
- * @param propertyType The property type whose name is needed.
- * @return The name of the property.
- */
- public String getPropertyName(final PropertyType propertyType) {
- return propertyType.toStringUnparsed();
- }
-
- /**
* Set a flag indicating that we are currently processing foreign XML.
* @param foreign The foreign XML item that we are currently processing.
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-24 11:56:31
|
Revision: 12125
http://sourceforge.net/p/foray/code/12125
Author: victormote
Date: 2021-11-24 11:56:29 +0000 (Wed, 24 Nov 2021)
Log Message:
-----------
Minor doc improvements.
Modified Paths:
--------------
trunk/foray/foray-core/src/main/java/org/foray/core/ForayDocument.java
trunk/foray/foray-core/src/main/java/org/foray/core/ForayTarget.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java
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-24 01:17:35 UTC (rev 12124)
+++ trunk/foray/foray-core/src/main/java/org/foray/core/ForayDocument.java 2021-11-24 11:56:29 UTC (rev 12125)
@@ -64,8 +64,7 @@
import javax.xml.transform.stream.StreamSource;
/**
- * This class manages the process of parsing an input FO document and creating
- * an FOTree.
+ * This class manages the process of parsing an input FO document and creating an FOTree.
*/
public class ForayDocument {
@@ -91,17 +90,15 @@
*/
private Source jaxpSource;
- /**
- * The JAXP Result encapsulating our FOTreeBuilder.
- * Should be null if the SAX constructor was used.
- */
+ /** The JAXP Result encapsulating our {@link FoTreeParser}.
+ * Should be null if the SAX constructor was used. */
private SAXResult jaxpResult;
/** The collection of ForayTarget "children". */
private List<ForayTarget> targetList = new ArrayList<ForayTarget>();
- /** The FO tree builder, which handles the SAX events. */
- private FoTreeParser treeBuilder;
+ /** The FO tree parser. */
+ private FoTreeParser treeParser;
/** The current target being processed. */
private ForayTarget currentTarget;
@@ -118,7 +115,7 @@
this.session = session;
this.inputSource = inputSource;
session.registerDocument(this);
- this.treeBuilder = this.session.getFOTreeFactory().makeFoTreeParser();
+ this.treeParser = this.session.getFOTreeFactory().makeFoTreeParser();
}
/**
@@ -136,7 +133,7 @@
this.inputSource = inputSource;
if (parser != null) {
this.parser = parser;
- this.parser.setContentHandler(this.treeBuilder.getContentHandler());
+ this.parser.setContentHandler(this.treeParser.getContentHandler());
}
}
@@ -150,12 +147,11 @@
public ForayDocument(final ForaySession session, final Document domDocument) throws ForayException {
this(session, new DocumentInputSource(domDocument));
this.parser = new DocumentReader();
- this.parser.setContentHandler(this.treeBuilder.getContentHandler());
+ this.parser.setContentHandler(this.treeParser.getContentHandler());
}
/**
- * Constructor for processing a semantic XML document using a JAXP
- * Transformer.
+ * Constructor for processing a semantic XML document using a JAXP Transformer.
* @param session The parent ForaySession.
* @param jaxpTransformer The JAXP Transformer.
* @param jaxpSource The JAXP source.
@@ -166,12 +162,11 @@
this(session, new InputSource(jaxpSource.getSystemId()));
this.jaxpTransformer = jaxpTransformer;
this.jaxpSource = jaxpSource;
- this.jaxpResult = new SAXResult(this.treeBuilder.getContentHandler());
+ this.jaxpResult = new SAXResult(this.treeParser.getContentHandler());
}
/**
- * Constructor for JAXP processing, using supplied URLs to the xml and
- * xslt input.
+ * Constructor for JAXP processing, using supplied URLs to the xml and xslt input.
* @param session The parent ForaySession.
* @param xmlInput The semantic XML input file to be processed.
* @param xsltInput The stylesheet to be processed.
@@ -203,7 +198,7 @@
} catch (final TransformerConfigurationException e) {
throw new ForayException(e);
}
- this.jaxpResult = new SAXResult(this.treeBuilder.getContentHandler());
+ this.jaxpResult = new SAXResult(this.treeParser.getContentHandler());
}
/**
@@ -218,16 +213,15 @@
}
/**
- * Returns the tree builder (a SAX ContentHandler).
- * Used in situations where SAX is used but not via a FOray-invoked
- * SAX parser, i.e. where some upstream process wishes to be in control
- * of the parsing and event-firing, usually because there is a pipeline of
- * processes that are both SAX consumers and producers. Cocoon is one
- * example of such a system.
+ * Returns the content handler.
+ * Used in situations where SAX is used but not via a FOray-invoked SAX parser, i.e. where some upstream process
+ * wishes to be in control of the parsing and event-firing, usually because there is a pipeline of processes that
+ * are both SAX consumers and producers.
+ * Cocoon is one example of such a system.
* @return The SAX content handler.
*/
public ContentHandler getContentHandler() {
- return this.treeBuilder.getContentHandler();
+ return this.treeParser.getContentHandler();
}
/**
@@ -242,8 +236,7 @@
/**
* Sets the target of this document.
* @param target The child target.
- * @throws ForayException If the child target is not a child of this
- * document.
+ * @throws ForayException If the child target is not a child of this document.
*/
public void setTarget(final ForayTarget target) throws ForayException {
if (target.getDocument() != this) {
@@ -264,8 +257,7 @@
}
/**
- * Process a given target by building the formatting object tree from the
- * input.
+ * Process a given target by building the formatting object tree from the input.
* @param target The target to be processed.
* @throws ForayException For errors during processing.
*/
@@ -272,16 +264,13 @@
public synchronized void processTarget(final ForayTarget target)
throws ForayException {
this.setTarget(target);
-// this.treeBuilder.setFontConsumer(this.getFontConsumer());
-// this.treeBuilder.setSpeechServer(this.getSpeechServer());
try {
if (this.jaxpTransformer == null) {
// Regular SAX Input
- this.treeBuilder.parseFoTree(inputSource);
+ this.treeParser.parseFoTree(inputSource);
} else {
// SAX Events generated by a JAXP Transformer
- this.jaxpTransformer.transform(this.jaxpSource,
- this.jaxpResult);
+ this.jaxpTransformer.transform(this.jaxpSource, this.jaxpResult);
}
} catch (final TransformerException | FoTreeException e) {
throw new ForayException(e);
@@ -291,8 +280,7 @@
}
/**
- * A hook for clients to call, allowing the document to clean up after
- * itself.
+ * A hook for clients to call, allowing the document to clean up after itself.
* @param target The target for which cleanup is needed.
*/
public void cleanup(final ForayTarget target) {
@@ -322,8 +310,7 @@
}
/**
- * Runs the formatting and renderering process using the previously set
- * inputsource and outputstream.
+ * Runs the formatting and renderering process using the previously set inputsource and outputstream.
* @throws IOException For I/O errors.
* @throws ForayException For errors during processing.
*/
@@ -365,8 +352,7 @@
/**
* Required by FOTreeControl interface.
- * @return The base URL that should be used for finding external files, like
- * graphical images, etc.
+ * @return The base URL that should be used for finding external files, like graphical images, etc.
*/
public URL getBaseURL() {
return getSessionConfig().optionBaseDirectory();
@@ -413,11 +399,11 @@
}
/**
- * Returns the FOTree for this document.
- * @return The FOTree for this document.
+ * Returns the FO tree parser for this document.
+ * @return The FO tree parser for this document.
*/
- public org.axsl.fo.FoTreeParser getFOTreeBuilder() {
- return this.treeBuilder;
+ public FoTreeParser getFoTreeParser() {
+ return this.treeParser;
}
/**
Modified: trunk/foray/foray-core/src/main/java/org/foray/core/ForayTarget.java
===================================================================
--- trunk/foray/foray-core/src/main/java/org/foray/core/ForayTarget.java 2021-11-24 01:17:35 UTC (rev 12124)
+++ trunk/foray/foray-core/src/main/java/org/foray/core/ForayTarget.java 2021-11-24 11:56:29 UTC (rev 12125)
@@ -133,7 +133,7 @@
document.registerTarget(this);
// Register this ForayTarget as a listener for FO Tree events.
- document.getFOTreeBuilder().registerListener(this);
+ document.getFoTreeParser().registerListener(this);
// Validate the OutputTarget.
this.outputTarget = outputTarget;
@@ -275,7 +275,7 @@
*/
private org.axsl.area.AreaTree getCreatedAreaTree() {
if (this.areaTree == null) {
- final FoTree foTree = this.document.getFOTreeBuilder().getFoTree();
+ final FoTree foTree = this.document.getFoTreeParser().getFoTree();
this.areaTree = this.getAreaTreeFactory().makeAreaTree(foTree);
this.areaTree.registerListener(this);
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java 2021-11-24 01:17:35 UTC (rev 12124)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java 2021-11-24 11:56:29 UTC (rev 12125)
@@ -388,54 +388,6 @@
}
}
-// /**
-// * Return the FO namespace instance.
-// * @return The FO namespace instance.
-// */
-// public NamespaceFo getFONamespace() {
-// return getTreeServer().getFONamespace();
-// }
-//
-// /**
-// * Return the Extension namespace instance.
-// * @return The Extension namespace instance.
-// */
-// public NamespaceForay getForayNamespace() {
-// return getTreeServer().getForayNamespace();
-// }
-//
-// /**
-// * Return the SVG namespace instance.
-// * @return The SVG namespace instance.
-// */
-// public NamespaceSvg getSVGNamespace() {
-// return getTreeServer().getSVGNamespace();
-// }
-//
-// /**
-// * Return the MathML namespace instance.
-// * @return The MathML namespace instance.
-// */
-// public MathNamespace getMathNamespace() {
-// return getTreeServer().getMathNamespace();
-// }
-//
-// /**
-// * Return the XML namespace instance.
-// * @return The XML namespace instance.
-// */
-// public NamespaceXml getXMLNamespace() {
-// return getTreeServer().getXMLNamespace();
-// }
-//
-// /**
-// * Returns the aXSL namespace instance.
-// * @return The aXSL namespace instance.
-// */
-// public NamespaceAxsl getAxslNamespace() {
-// return getTreeServer().getAxslNamespace();
-// }
-//
/**
* Returns the name of a given property type.
* @param propertyType The property type whose name is needed.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-24 01:17:37
|
Revision: 12124
http://sourceforge.net/p/foray/code/12124
Author: victormote
Date: 2021-11-24 01:17:35 +0000 (Wed, 24 Nov 2021)
Log Message:
-----------
Fix graphics location problem caused by recent refactoring.
Modified Paths:
--------------
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java 2021-11-24 01:12:19 UTC (rev 12123)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java 2021-11-24 01:17:35 UTC (rev 12124)
@@ -45,7 +45,6 @@
import org.xml.sax.XMLReader;
import java.io.IOException;
-import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -77,12 +76,6 @@
/** The parent server. */
private FoTreeServer4a server;
- /** The paths to search when looking for graphics. */
- private URL[] graphicSearchPath;
-
- /** Indicates whether graphics should be cached. */
- private boolean cachingGraphics;
-
/** Externally-provided parser, if any. */
private XMLReader parser;
@@ -106,8 +99,8 @@
foTree.setGraphicServer(this.server.getGraphicServer());
foTree.setTextServer(this.server.getTextServer());
foTree.setOrthographyServer(this.server.getOrthographyServer());
- foTree.setGraphicSearchPath(this.graphicSearchPath);
- foTree.setCachingGraphics(this.cachingGraphics);
+ foTree.setGraphicSearchPath(this.server.getGraphicSearchPath());
+ foTree.setCachingGraphics(this.server.isCachingGraphics());
foTree.setFontConsumer(this.server.getFontServer().makeFontConsumer());
}
@@ -475,22 +468,6 @@
return this.server;
}
- /**
- * Return the graphic search path.
- * @return The graphic search path.
- */
- public URL[] getGraphicSearchPath() {
- return this.graphicSearchPath;
- }
-
- /**
- * Indicates whether graphics should be cached.
- * @return True iff graphics should be cached.
- */
- public boolean getCachingGraphics() {
- return this.cachingGraphics;
- }
-
@Override
public ContentHandler getContentHandler() {
return this;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-24 01:12:22
|
Revision: 12123
http://sourceforge.net/p/foray/code/12123
Author: victormote
Date: 2021-11-24 01:12:19 +0000 (Wed, 24 Nov 2021)
Log Message:
-----------
Rename class for clarity and consistency.
Modified Paths:
--------------
trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeServer4a.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/ForeignXml.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/Namespace.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/NamespaceAxsl.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/NamespaceFo.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/foray/NamespaceForay.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/math/MathNamespace.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/svg/NamespaceSvg.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/xml/NamespaceXml.java
trunk/foray/foray-fotree/src/test/java/org/foray/fotree/AbstractPropertyTest.java
Added Paths:
-----------
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java
Removed Paths:
-------------
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.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-23 20:49:25 UTC (rev 12122)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -34,7 +34,7 @@
import org.foray.core.ForayException;
import org.foray.core.SessionConfig;
import org.foray.fotree.FoTree4a;
-import org.foray.fotree.FoTreeBuilder;
+import org.foray.fotree.FoTreeParser4a;
import org.foray.fotree.FoTreeServer4a;
import org.axsl.fo.FoTreeException;
@@ -128,7 +128,7 @@
try {
final Reader reader = new FileReader(file);
final InputSource inputSource = new InputSource(reader);
- final FoTreeBuilder parser = this.treeServer.makeFoTreeParser();
+ final FoTreeParser4a parser = this.treeServer.makeFoTreeParser();
parser.parseFoTree(inputSource);
foTree = parser.getFoTree();
} catch (FileNotFoundException | FoTreeException e) {
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java 2021-11-23 20:49:25 UTC (rev 12122)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -53,7 +53,7 @@
private FoTreeServer4a treeServer;
/** The builder building this tree. */
- private FoTreeBuilder treeBuilder;
+ private FoTreeParser4a treeBuilder;
/** The root of the FO tree. */
private org.foray.fotree.fo.obj.Root root;
@@ -92,7 +92,7 @@
* @param treeServer The parent tree server.
* @param treeBuilder The tree builder building this instance.
*/
- public FoTree4a(final FoTreeServer4a treeServer, final FoTreeBuilder treeBuilder) {
+ public FoTree4a(final FoTreeServer4a treeServer, final FoTreeParser4a treeBuilder) {
this.treeServer = treeServer;
this.treeBuilder = treeBuilder;
}
Deleted: 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-23 20:49:25 UTC (rev 12122)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -1,499 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * 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.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.fotree;
-
-import org.foray.common.xml.SaxParser;
-import org.foray.fotree.fo.obj.PageSequence;
-import org.foray.fotree.fo.obj.Root;
-
-import org.axsl.fo.FoTreeEvent;
-import org.axsl.fo.FoTreeException;
-import org.axsl.fo.FoTreeListener;
-import org.axsl.fo.FoTreeParser;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.parsers.ParserConfigurationException;
-
-/**
- * SAX Handler that builds the formatting object tree.
- */
-public class FoTreeBuilder extends SaxParser<FoTree4a> implements FoTreeParser {
-
- /** The FO tree being created by this parser. */
- private FoTree4a foTree;
-
- /** The current formatting object being parsed. */
- private FoObj currentFObj = null;
-
- /** The root of the formatting object tree. */
- private Root rootFObj = null;
-
- /** The SAX locator. */
- private Locator locator;
-
- /** Collection of objects that have registered to be notified about FOTreeEvent firings. */
- private List<FoTreeListener> foTreeListeners = new ArrayList<FoTreeListener>();
-
- /** Indicates whether we are currently inside foreign XML. */
- private ForeignXml activeForeignXML = null;
-
- /** The parent server. */
- private FoTreeServer4a server;
-
- /** The paths to search when looking for graphics. */
- private URL[] graphicSearchPath;
-
- /** Indicates whether graphics should be cached. */
- private boolean cachingGraphics;
-
- /** Externally-provided parser, if any. */
- private XMLReader parser;
-
- /**
- * Constructor.
- * @param server The parent server.
- * @param parser The parser. If null, one will be created.
- */
- public FoTreeBuilder(final FoTreeServer4a server, final XMLReader parser) {
- this.server = server;
- this.parser = parser;
- reset();
- }
-
- @Override
- public void reset() {
- this.currentFObj = null;
- this.rootFObj = null;
- this.foTreeListeners.clear();
- this.foTree = new FoTree4a(this.server, this);
- foTree.setGraphicServer(this.server.getGraphicServer());
- foTree.setTextServer(this.server.getTextServer());
- foTree.setOrthographyServer(this.server.getOrthographyServer());
- foTree.setGraphicSearchPath(this.graphicSearchPath);
- foTree.setCachingGraphics(this.cachingGraphics);
- foTree.setFontConsumer(this.server.getFontServer().makeFontConsumer());
- }
-
- @Override
- public void parseFoTree(final InputSource inputSource) throws FoTreeException {
- try {
- parse(inputSource);
- } catch (IOException | ParserConfigurationException | SAXException e) {
- throw new FoTreeException(e);
- }
- }
-
- @Override
- public FoTree4a getFoTree() {
- return this.foTree;
- }
-
- @Override
- public FoTree4a parse(final InputSource inputSource)
- throws IOException, ParserConfigurationException, SAXException {
- XMLReader parser = this.parser;
- if (parser == null) {
- parser = createSax2Parser(false, true, true, null, false);
- }
- parser.parse(inputSource);
- foTree.setRootFo(this.rootFObj);
- return this.foTree;
- }
-
- @Override
- public void characters(final char[] data, final int start, final int length)
- throws SAXException {
- if (this.activeForeignXML != null) {
- // If inside foreign XML, let the ForeignXml instance handle it.
- this.activeForeignXML.characters(data, start, length);
- return;
- }
- if (this.currentFObj != null) {
- try {
- this.currentFObj.addCharacters(data, start, length,
- this.locator.getSystemId(),
- this.locator.getLineNumber(),
- this.locator.getColumnNumber());
- } catch (final FoTreeException e) {
- throw new SAXException(e);
- }
- }
- }
-
- @Override
- public void endElement(final String uri, final String localName,
- final String rawName) throws SAXException {
- if (this.activeForeignXML != null) {
- // If inside foreign XML, let the ForeignXml instance handle it.
- this.activeForeignXML.endElement(uri, localName, rawName);
- // It may have disactivated the foreign XML, so check again.
- if (this.activeForeignXML != null) {
- return;
- }
- }
- try {
- this.currentFObj.end();
- this.currentFObj.validateDescendants();
- } catch (final FoTreeException e) {
- throw new SAXException(e);
- }
- try {
- notifyFObjComplete(this.currentFObj);
-
- if (this.currentFObj instanceof PageSequence) {
- // Notify the listeners that this page-sequence is complete.
- notifyPageSequenceComplete((PageSequence) this.currentFObj);
- }
- } catch (final FoTreeException e) {
- throw new SAXException(e);
- }
- this.currentFObj = this.currentFObj.getParsedParent();
- }
-
- @Override
- public void startDocument() throws SAXException {
- // Allow the FoTreeBuilder to be reused
- this.rootFObj = null;
- getLogger().info("Begin parsing the Formatting Object (FO) input.");
- }
-
- @Override
- public void endDocument() throws SAXException {
- getLogger().info("End parsing the Formatting Object (FO) input.");
- try {
- notifyDocumentComplete();
- } catch (final FoTreeException e) {
- throw new SAXException(e);
- }
- }
-
- @Override
- public void setDocumentLocator(final Locator locator) {
- this.locator = locator;
- }
-
- @Override
- public void startElement(final String namespaceURI, final String localName,
- final String rawName, final Attributes attlist)
- throws SAXException {
- if (this.activeForeignXML != null) {
- // If inside foreign XML, let the ForeignXml instance handle it.
- this.activeForeignXML.startElement(namespaceURI, localName, rawName,
- attlist);
- return;
- }
- final Namespace namespace = getTreeServer().getNamespace(namespaceURI);
- if (namespace == null) {
- final String message = "Unregistered namespace: " + namespaceURI + ": " + getLine()
- + ":" + getColumn();
- throw new SAXException(message);
- }
- /* the formatting object started */
- FoObj fobj = null;
- try {
- final PropertyList list = namespace.createNewPropertyList(attlist);
- if (this.currentFObj == null) {
- if (! "root".equals(localName)) {
- throw new SAXException("fo:root must be first element "
- + "parsed");
- }
- }
- fobj = namespace.parseElement(this.foTree, localName, this.currentFObj, list, this.locator, this);
- if (this.locator != null) {
- fobj.setLocation(this.locator.getSystemId(),
- this.locator.getLineNumber(),
- this.locator.getColumnNumber());
- }
- fobj.validateAncestry();
- namespace.parseAttributes(list, attlist, fobj, this.locator, this);
- fobj.validateProperties();
- /* If the parent is not null (which it can be for Root), register
- * the newly-created object as a child of the parent. */
- if (this.currentFObj != null) {
- this.currentFObj.addChild(fobj);
- }
- /* Give the fobj a chance to do some validation and/or setup before
- * the children are processed. */
- fobj.setup();
- checkRoot(fobj);
- // Let Root register an "id", if any.
- this.rootFObj.addId(fobj);
- // Let Root register an unmatched "ref-id", if any.
- this.rootFObj.checkUnmatchedReference(fobj);
- } catch (final FoTreeException e) {
- throw new SAXException(e);
- }
- this.currentFObj = fobj;
- }
-
- /**
- * Sets the root object if it is not already set.
- * @param fobj The FoObj that is being processed, which is a candidate to be
- * the root element if it is not already set.
- * @throws SAXException If the root element is missing its namespace
- * declaration, or if there is an element in the tree before any root
- * element.
- */
- private void checkRoot(final FoObj fobj) throws SAXException {
- if (this.rootFObj != null) {
- return;
- }
- if (fobj instanceof Root) {
- this.rootFObj = (Root) fobj;
- this.rootFObj.setFOTreeBuilder(this.foTree);
- return;
- }
- if (fobj.getName().equals("root")) {
- final FoTreeException fote = new FoTreeException("Root element is "
- + "missing the namespace declaration: "
- + "http://www.w3.org/1999/XSL/Format");
- fote.setContextMessage(fobj.getContextMessage());
- throw new SAXException(fote);
- }
- final FoTreeException fote = new FoTreeException("Root element must be "
- + "root, not " + fobj.getName());
- fote.setContextMessage(fobj.getContextMessage());
- throw new SAXException(new FoTreeException(fote));
- }
-
- /**
- * Returns the line number currently showing in the SAX Locator.
- * @return The line number currently showing in the SAX Locator.
- */
- private int getLine() {
- int line = -1;
- if (this.locator != null) {
- line = this.locator.getLineNumber();
- }
- return line;
- }
-
- /**
- * Returns the column number currently showing in the SAX Locator.
- * @return The column number currently showing in the SAX Locator.
- */
- private int getColumn() {
- int column = -1;
- if (this.locator != null) {
- column = this.locator.getColumnNumber();
- }
- return column;
- }
-
- @Override
- public void registerListener(final FoTreeListener listener) {
- if (listener == null) {
- return;
- }
- this.foTreeListeners.add(listener);
- }
-
- /**
- * Remove an object from the collection of objects that should be notified
- * about FOTreeEvent firings.
- * @param listener the Object which should no longer be notified
- */
- public void removeFOTreeListener(final FoTreeListener listener) {
- if (listener == null) {
- return;
- }
- this.foTreeListeners.remove(listener);
- }
-
- private int qtyFoCompleteListeners() {
- int count = 0;
- for (int index = 0; index < this.foTreeListeners.size(); index ++) {
- final FoTreeListener listener = this.foTreeListeners.get(index);
- if (listener.wantsFoCompleteEvents()) {
- count ++;
- }
- }
- return count;
- }
-
- /**
- * Notify all objects in the foTreeListeners that an "FoObj Complete"
- * FOTreeEvent has been fired.
- * @param fobj The FoObj instance that was just completed.
- * @throws FoTreeException For errors while the event is being processed.
- */
- private void notifyFObjComplete(final FoObj fobj) throws FoTreeException {
- /* If nobody wants these events, don't waste resources creating
- * them. */
- if (qtyFoCompleteListeners() < 1) {
- return;
- }
- final FoTreeEvent event = new FoTreeEvent(this, fobj);
- for (int i = 0; i < this.foTreeListeners.size(); i++) {
- final FoTreeListener listener = this.foTreeListeners.get(i);
- listener.foComplete(event);
- }
- }
-
- /**
- * Notify all objects in the foTreeListeners that a "PageSequence Complete"
- * FOTreeEvent has been fired.
- * @param pageSequence The PageSequence instance that was just completed.
- * @throws FoTreeException For errors while the event is being processed.
- */
- private void notifyPageSequenceComplete(final PageSequence pageSequence)
- throws FoTreeException {
- final FoTreeEvent event = new FoTreeEvent(this, pageSequence);
- for (int i = 0; i < this.foTreeListeners.size(); i++) {
- final FoTreeListener listener = this.foTreeListeners.get(i);
- listener.foPageSequenceComplete(event);
- }
- }
-
- /**
- * Notify all objects in the foTreeListeners that a "Document Complete"
- * FOTreeEvent has been fired.
- * @throws FoTreeException For errors while the event is being processed.
- */
- private void notifyDocumentComplete() throws FoTreeException {
- final FoTreeEvent event = new FoTreeEvent(this);
- for (int i = 0; i < this.foTreeListeners.size(); i++) {
- final FoTreeListener listener = this.foTreeListeners.get(i);
- listener.foDocumentComplete(event);
- }
- }
-
-// /**
-// * Return the FO namespace instance.
-// * @return The FO namespace instance.
-// */
-// public NamespaceFo getFONamespace() {
-// return getTreeServer().getFONamespace();
-// }
-//
-// /**
-// * Return the Extension namespace instance.
-// * @return The Extension namespace instance.
-// */
-// public NamespaceForay getForayNamespace() {
-// return getTreeServer().getForayNamespace();
-// }
-//
-// /**
-// * Return the SVG namespace instance.
-// * @return The SVG namespace instance.
-// */
-// public NamespaceSvg getSVGNamespace() {
-// return getTreeServer().getSVGNamespace();
-// }
-//
-// /**
-// * Return the MathML namespace instance.
-// * @return The MathML namespace instance.
-// */
-// public MathNamespace getMathNamespace() {
-// return getTreeServer().getMathNamespace();
-// }
-//
-// /**
-// * Return the XML namespace instance.
-// * @return The XML namespace instance.
-// */
-// public NamespaceXml getXMLNamespace() {
-// return getTreeServer().getXMLNamespace();
-// }
-//
-// /**
-// * Returns the aXSL namespace instance.
-// * @return The aXSL namespace instance.
-// */
-// public NamespaceAxsl getAxslNamespace() {
-// return getTreeServer().getAxslNamespace();
-// }
-//
- /**
- * Returns the name of a given property type.
- * @param propertyType The property type whose name is needed.
- * @return The name of the property.
- */
- public String getPropertyName(final PropertyType propertyType) {
- return propertyType.toStringUnparsed();
- }
-
- /**
- * Set a flag indicating that we are currently processing foreign XML.
- * @param foreign The foreign XML item that we are currently processing.
- */
- public void activateForeignXML(final ForeignXml foreign) {
- this.activeForeignXML = foreign;
- }
-
- /**
- * Unset the flag indicating that we are currently processing foreign XML.
- */
- public void deactivateForeignXML() {
- this.activeForeignXML = null;
- }
-
- /**
- * Return the "parent" FO Tree server.
- * @return The FO Tree server.
- */
- public FoTreeServer4a getTreeServer() {
- return this.server;
- }
-
- /**
- * Return the graphic search path.
- * @return The graphic search path.
- */
- public URL[] getGraphicSearchPath() {
- return this.graphicSearchPath;
- }
-
- /**
- * Indicates whether graphics should be cached.
- * @return True iff graphics should be cached.
- */
- public boolean getCachingGraphics() {
- return this.cachingGraphics;
- }
-
- @Override
- public ContentHandler getContentHandler() {
- return this;
- }
-
-}
Copied: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java (from rev 12122, trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java)
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java (rev 0)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -0,0 +1,499 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * 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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fotree;
+
+import org.foray.common.xml.SaxParser;
+import org.foray.fotree.fo.obj.PageSequence;
+import org.foray.fotree.fo.obj.Root;
+
+import org.axsl.fo.FoTreeEvent;
+import org.axsl.fo.FoTreeException;
+import org.axsl.fo.FoTreeListener;
+import org.axsl.fo.FoTreeParser;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+/**
+ * SAX Handler that builds the formatting object tree.
+ */
+public class FoTreeParser4a extends SaxParser<FoTree4a> implements FoTreeParser {
+
+ /** The FO tree being created by this parser. */
+ private FoTree4a foTree;
+
+ /** The current formatting object being parsed. */
+ private FoObj currentFObj = null;
+
+ /** The root of the formatting object tree. */
+ private Root rootFObj = null;
+
+ /** The SAX locator. */
+ private Locator locator;
+
+ /** Collection of objects that have registered to be notified about FOTreeEvent firings. */
+ private List<FoTreeListener> foTreeListeners = new ArrayList<FoTreeListener>();
+
+ /** Indicates whether we are currently inside foreign XML. */
+ private ForeignXml activeForeignXML = null;
+
+ /** The parent server. */
+ private FoTreeServer4a server;
+
+ /** The paths to search when looking for graphics. */
+ private URL[] graphicSearchPath;
+
+ /** Indicates whether graphics should be cached. */
+ private boolean cachingGraphics;
+
+ /** Externally-provided parser, if any. */
+ private XMLReader parser;
+
+ /**
+ * Constructor.
+ * @param server The parent server.
+ * @param parser The parser. If null, one will be created.
+ */
+ public FoTreeParser4a(final FoTreeServer4a server, final XMLReader parser) {
+ this.server = server;
+ this.parser = parser;
+ reset();
+ }
+
+ @Override
+ public void reset() {
+ this.currentFObj = null;
+ this.rootFObj = null;
+ this.foTreeListeners.clear();
+ this.foTree = new FoTree4a(this.server, this);
+ foTree.setGraphicServer(this.server.getGraphicServer());
+ foTree.setTextServer(this.server.getTextServer());
+ foTree.setOrthographyServer(this.server.getOrthographyServer());
+ foTree.setGraphicSearchPath(this.graphicSearchPath);
+ foTree.setCachingGraphics(this.cachingGraphics);
+ foTree.setFontConsumer(this.server.getFontServer().makeFontConsumer());
+ }
+
+ @Override
+ public void parseFoTree(final InputSource inputSource) throws FoTreeException {
+ try {
+ parse(inputSource);
+ } catch (IOException | ParserConfigurationException | SAXException e) {
+ throw new FoTreeException(e);
+ }
+ }
+
+ @Override
+ public FoTree4a getFoTree() {
+ return this.foTree;
+ }
+
+ @Override
+ public FoTree4a parse(final InputSource inputSource)
+ throws IOException, ParserConfigurationException, SAXException {
+ XMLReader parser = this.parser;
+ if (parser == null) {
+ parser = createSax2Parser(false, true, true, null, false);
+ }
+ parser.parse(inputSource);
+ foTree.setRootFo(this.rootFObj);
+ return this.foTree;
+ }
+
+ @Override
+ public void characters(final char[] data, final int start, final int length)
+ throws SAXException {
+ if (this.activeForeignXML != null) {
+ // If inside foreign XML, let the ForeignXml instance handle it.
+ this.activeForeignXML.characters(data, start, length);
+ return;
+ }
+ if (this.currentFObj != null) {
+ try {
+ this.currentFObj.addCharacters(data, start, length,
+ this.locator.getSystemId(),
+ this.locator.getLineNumber(),
+ this.locator.getColumnNumber());
+ } catch (final FoTreeException e) {
+ throw new SAXException(e);
+ }
+ }
+ }
+
+ @Override
+ public void endElement(final String uri, final String localName,
+ final String rawName) throws SAXException {
+ if (this.activeForeignXML != null) {
+ // If inside foreign XML, let the ForeignXml instance handle it.
+ this.activeForeignXML.endElement(uri, localName, rawName);
+ // It may have disactivated the foreign XML, so check again.
+ if (this.activeForeignXML != null) {
+ return;
+ }
+ }
+ try {
+ this.currentFObj.end();
+ this.currentFObj.validateDescendants();
+ } catch (final FoTreeException e) {
+ throw new SAXException(e);
+ }
+ try {
+ notifyFObjComplete(this.currentFObj);
+
+ if (this.currentFObj instanceof PageSequence) {
+ // Notify the listeners that this page-sequence is complete.
+ notifyPageSequenceComplete((PageSequence) this.currentFObj);
+ }
+ } catch (final FoTreeException e) {
+ throw new SAXException(e);
+ }
+ this.currentFObj = this.currentFObj.getParsedParent();
+ }
+
+ @Override
+ public void startDocument() throws SAXException {
+ // Allow the FoTreeBuilder to be reused
+ this.rootFObj = null;
+ getLogger().info("Begin parsing the Formatting Object (FO) input.");
+ }
+
+ @Override
+ public void endDocument() throws SAXException {
+ getLogger().info("End parsing the Formatting Object (FO) input.");
+ try {
+ notifyDocumentComplete();
+ } catch (final FoTreeException e) {
+ throw new SAXException(e);
+ }
+ }
+
+ @Override
+ public void setDocumentLocator(final Locator locator) {
+ this.locator = locator;
+ }
+
+ @Override
+ public void startElement(final String namespaceURI, final String localName,
+ final String rawName, final Attributes attlist)
+ throws SAXException {
+ if (this.activeForeignXML != null) {
+ // If inside foreign XML, let the ForeignXml instance handle it.
+ this.activeForeignXML.startElement(namespaceURI, localName, rawName,
+ attlist);
+ return;
+ }
+ final Namespace namespace = getTreeServer().getNamespace(namespaceURI);
+ if (namespace == null) {
+ final String message = "Unregistered namespace: " + namespaceURI + ": " + getLine()
+ + ":" + getColumn();
+ throw new SAXException(message);
+ }
+ /* the formatting object started */
+ FoObj fobj = null;
+ try {
+ final PropertyList list = namespace.createNewPropertyList(attlist);
+ if (this.currentFObj == null) {
+ if (! "root".equals(localName)) {
+ throw new SAXException("fo:root must be first element "
+ + "parsed");
+ }
+ }
+ fobj = namespace.parseElement(this.foTree, localName, this.currentFObj, list, this.locator, this);
+ if (this.locator != null) {
+ fobj.setLocation(this.locator.getSystemId(),
+ this.locator.getLineNumber(),
+ this.locator.getColumnNumber());
+ }
+ fobj.validateAncestry();
+ namespace.parseAttributes(list, attlist, fobj, this.locator, this);
+ fobj.validateProperties();
+ /* If the parent is not null (which it can be for Root), register
+ * the newly-created object as a child of the parent. */
+ if (this.currentFObj != null) {
+ this.currentFObj.addChild(fobj);
+ }
+ /* Give the fobj a chance to do some validation and/or setup before
+ * the children are processed. */
+ fobj.setup();
+ checkRoot(fobj);
+ // Let Root register an "id", if any.
+ this.rootFObj.addId(fobj);
+ // Let Root register an unmatched "ref-id", if any.
+ this.rootFObj.checkUnmatchedReference(fobj);
+ } catch (final FoTreeException e) {
+ throw new SAXException(e);
+ }
+ this.currentFObj = fobj;
+ }
+
+ /**
+ * Sets the root object if it is not already set.
+ * @param fobj The FoObj that is being processed, which is a candidate to be
+ * the root element if it is not already set.
+ * @throws SAXException If the root element is missing its namespace
+ * declaration, or if there is an element in the tree before any root
+ * element.
+ */
+ private void checkRoot(final FoObj fobj) throws SAXException {
+ if (this.rootFObj != null) {
+ return;
+ }
+ if (fobj instanceof Root) {
+ this.rootFObj = (Root) fobj;
+ this.rootFObj.setFOTreeBuilder(this.foTree);
+ return;
+ }
+ if (fobj.getName().equals("root")) {
+ final FoTreeException fote = new FoTreeException("Root element is "
+ + "missing the namespace declaration: "
+ + "http://www.w3.org/1999/XSL/Format");
+ fote.setContextMessage(fobj.getContextMessage());
+ throw new SAXException(fote);
+ }
+ final FoTreeException fote = new FoTreeException("Root element must be "
+ + "root, not " + fobj.getName());
+ fote.setContextMessage(fobj.getContextMessage());
+ throw new SAXException(new FoTreeException(fote));
+ }
+
+ /**
+ * Returns the line number currently showing in the SAX Locator.
+ * @return The line number currently showing in the SAX Locator.
+ */
+ private int getLine() {
+ int line = -1;
+ if (this.locator != null) {
+ line = this.locator.getLineNumber();
+ }
+ return line;
+ }
+
+ /**
+ * Returns the column number currently showing in the SAX Locator.
+ * @return The column number currently showing in the SAX Locator.
+ */
+ private int getColumn() {
+ int column = -1;
+ if (this.locator != null) {
+ column = this.locator.getColumnNumber();
+ }
+ return column;
+ }
+
+ @Override
+ public void registerListener(final FoTreeListener listener) {
+ if (listener == null) {
+ return;
+ }
+ this.foTreeListeners.add(listener);
+ }
+
+ /**
+ * Remove an object from the collection of objects that should be notified
+ * about FOTreeEvent firings.
+ * @param listener the Object which should no longer be notified
+ */
+ public void removeFOTreeListener(final FoTreeListener listener) {
+ if (listener == null) {
+ return;
+ }
+ this.foTreeListeners.remove(listener);
+ }
+
+ private int qtyFoCompleteListeners() {
+ int count = 0;
+ for (int index = 0; index < this.foTreeListeners.size(); index ++) {
+ final FoTreeListener listener = this.foTreeListeners.get(index);
+ if (listener.wantsFoCompleteEvents()) {
+ count ++;
+ }
+ }
+ return count;
+ }
+
+ /**
+ * Notify all objects in the foTreeListeners that an "FoObj Complete"
+ * FOTreeEvent has been fired.
+ * @param fobj The FoObj instance that was just completed.
+ * @throws FoTreeException For errors while the event is being processed.
+ */
+ private void notifyFObjComplete(final FoObj fobj) throws FoTreeException {
+ /* If nobody wants these events, don't waste resources creating
+ * them. */
+ if (qtyFoCompleteListeners() < 1) {
+ return;
+ }
+ final FoTreeEvent event = new FoTreeEvent(this, fobj);
+ for (int i = 0; i < this.foTreeListeners.size(); i++) {
+ final FoTreeListener listener = this.foTreeListeners.get(i);
+ listener.foComplete(event);
+ }
+ }
+
+ /**
+ * Notify all objects in the foTreeListeners that a "PageSequence Complete"
+ * FOTreeEvent has been fired.
+ * @param pageSequence The PageSequence instance that was just completed.
+ * @throws FoTreeException For errors while the event is being processed.
+ */
+ private void notifyPageSequenceComplete(final PageSequence pageSequence)
+ throws FoTreeException {
+ final FoTreeEvent event = new FoTreeEvent(this, pageSequence);
+ for (int i = 0; i < this.foTreeListeners.size(); i++) {
+ final FoTreeListener listener = this.foTreeListeners.get(i);
+ listener.foPageSequenceComplete(event);
+ }
+ }
+
+ /**
+ * Notify all objects in the foTreeListeners that a "Document Complete"
+ * FOTreeEvent has been fired.
+ * @throws FoTreeException For errors while the event is being processed.
+ */
+ private void notifyDocumentComplete() throws FoTreeException {
+ final FoTreeEvent event = new FoTreeEvent(this);
+ for (int i = 0; i < this.foTreeListeners.size(); i++) {
+ final FoTreeListener listener = this.foTreeListeners.get(i);
+ listener.foDocumentComplete(event);
+ }
+ }
+
+// /**
+// * Return the FO namespace instance.
+// * @return The FO namespace instance.
+// */
+// public NamespaceFo getFONamespace() {
+// return getTreeServer().getFONamespace();
+// }
+//
+// /**
+// * Return the Extension namespace instance.
+// * @return The Extension namespace instance.
+// */
+// public NamespaceForay getForayNamespace() {
+// return getTreeServer().getForayNamespace();
+// }
+//
+// /**
+// * Return the SVG namespace instance.
+// * @return The SVG namespace instance.
+// */
+// public NamespaceSvg getSVGNamespace() {
+// return getTreeServer().getSVGNamespace();
+// }
+//
+// /**
+// * Return the MathML namespace instance.
+// * @return The MathML namespace instance.
+// */
+// public MathNamespace getMathNamespace() {
+// return getTreeServer().getMathNamespace();
+// }
+//
+// /**
+// * Return the XML namespace instance.
+// * @return The XML namespace instance.
+// */
+// public NamespaceXml getXMLNamespace() {
+// return getTreeServer().getXMLNamespace();
+// }
+//
+// /**
+// * Returns the aXSL namespace instance.
+// * @return The aXSL namespace instance.
+// */
+// public NamespaceAxsl getAxslNamespace() {
+// return getTreeServer().getAxslNamespace();
+// }
+//
+ /**
+ * Returns the name of a given property type.
+ * @param propertyType The property type whose name is needed.
+ * @return The name of the property.
+ */
+ public String getPropertyName(final PropertyType propertyType) {
+ return propertyType.toStringUnparsed();
+ }
+
+ /**
+ * Set a flag indicating that we are currently processing foreign XML.
+ * @param foreign The foreign XML item that we are currently processing.
+ */
+ public void activateForeignXML(final ForeignXml foreign) {
+ this.activeForeignXML = foreign;
+ }
+
+ /**
+ * Unset the flag indicating that we are currently processing foreign XML.
+ */
+ public void deactivateForeignXML() {
+ this.activeForeignXML = null;
+ }
+
+ /**
+ * Return the "parent" FO Tree server.
+ * @return The FO Tree server.
+ */
+ public FoTreeServer4a getTreeServer() {
+ return this.server;
+ }
+
+ /**
+ * Return the graphic search path.
+ * @return The graphic search path.
+ */
+ public URL[] getGraphicSearchPath() {
+ return this.graphicSearchPath;
+ }
+
+ /**
+ * Indicates whether graphics should be cached.
+ * @return True iff graphics should be cached.
+ */
+ public boolean getCachingGraphics() {
+ return this.cachingGraphics;
+ }
+
+ @Override
+ public ContentHandler getContentHandler() {
+ return this;
+ }
+
+}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeServer4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeServer4a.java 2021-11-23 20:49:25 UTC (rev 12122)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeServer4a.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -279,8 +279,8 @@
}
@Override
- public FoTreeBuilder makeFoTreeParser() {
- final FoTreeBuilder foTreeBuilder = new FoTreeBuilder(this, null);
+ public FoTreeParser4a makeFoTreeParser() {
+ final FoTreeParser4a foTreeBuilder = new FoTreeParser4a(this, null);
return foTreeBuilder;
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/ForeignXml.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/ForeignXml.java 2021-11-23 20:49:25 UTC (rev 12122)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/ForeignXml.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -147,7 +147,7 @@
/**
* This is pretending to be a SAX Handler for the start of an element.
- * Control is passed here from {@link FoTreeBuilder#startElement(String,
+ * Control is passed here from {@link FoTreeParser4a#startElement(String,
* String, String, Attributes)} while foreign XML is being processed.
* @param namespaceURI The Namespace URI, or the empty string if the element
* has no Namespace URI or if Namespace processing is not being performed.
@@ -194,7 +194,7 @@
/**
* This is pretending to be a SAX Handler for the end of an element.
- * Control is passed here from {@link FoTreeBuilder#endElement(String,
+ * Control is passed here from {@link FoTreeParser4a#endElement(String,
* String, String)} while foreign XML is being processed.
* @param uri The Namespace URI, or the empty string if the element has no
* Namespace URI or if Namespace processing is not being performed.
@@ -230,7 +230,7 @@
/**
* This is pretending to be a SAX Handler for the characters (content) of
* an element.
- * Control is passed here from {@link FoTreeBuilder#characters(char[], int,
+ * Control is passed here from {@link FoTreeParser4a#characters(char[], int,
* int)} while foreign XML is being processed.
* @param data The characters.
* @param start The start position in the character array.
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/Namespace.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/Namespace.java 2021-11-23 20:49:25 UTC (rev 12122)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/Namespace.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -85,7 +85,7 @@
public FoObj parseElement(final FoTree4a foTree, final String localName,
final FoObj currentFObj, final PropertyList list,
final Locator locator,
- final FoTreeBuilder builder) throws FoTreeException {
+ final FoTreeParser4a builder) throws FoTreeException {
final FoObj fobj = parseElementForNS(foTree, localName, currentFObj,
list, locator);
if (fobj == null) {
@@ -118,7 +118,7 @@
* @param locator The Locator instance indicating the source of the foreign
* element.
*/
- private void checkUnknownElement(final FoTreeBuilder builder,
+ private void checkUnknownElement(final FoTreeParser4a builder,
final String localName, final Locator locator) {
if (this.unknownFOs.contains(localName)) {
return;
@@ -178,7 +178,7 @@
*/
public abstract void parseAttributes(PropertyList list,
Attributes attlist, FoObj currentFObj, Locator locator,
- FoTreeBuilder builder) throws FoTreeException;
+ FoTreeParser4a builder) throws FoTreeException;
/**
* Reads through the list of attributes and returns an array that contains
@@ -243,7 +243,7 @@
public Property parseAttribute(final Attributes attributes,
final String attributeName, final String attributeValue,
final FoObj fobj, final Locator locator,
- final FoTreeBuilder builder) throws PropertyException {
+ final FoTreeParser4a builder) throws PropertyException {
final Property property = parseAttributeForNS(attributes, attributeName,
attributeValue, fobj, locator);
return property;
@@ -279,7 +279,7 @@
protected void makeList(final PropertyList propertyList,
final Attributes attributes, final FoObj parentFO,
final int[] attributeSort, final Locator locator,
- final FoTreeBuilder builder) throws PropertyException {
+ final FoTreeParser4a builder) throws PropertyException {
for (int j = 0; j < attributeSort.length; j++) {
/* We are reading through the attributes elements in attributeSort
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/NamespaceAxsl.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/NamespaceAxsl.java 2021-11-23 20:49:25 UTC (rev 12122)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/NamespaceAxsl.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -30,7 +30,7 @@
import org.foray.fotree.FoObj;
import org.foray.fotree.FoTree4a;
-import org.foray.fotree.FoTreeBuilder;
+import org.foray.fotree.FoTreeParser4a;
import org.foray.fotree.Namespace;
import org.foray.fotree.Property;
import org.foray.fotree.PropertyException;
@@ -74,7 +74,7 @@
@Override
public void parseAttributes(final PropertyList propertyList,
final Attributes attlist, final FoObj currentFObj,
- final Locator locator, final FoTreeBuilder builder)
+ final Locator locator, final FoTreeParser4a builder)
throws FoTreeException {
final int[] attributeSort = sortAttributes(attlist);
try {
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/NamespaceFo.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/NamespaceFo.java 2021-11-23 20:49:25 UTC (rev 12122)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/NamespaceFo.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -30,7 +30,7 @@
import org.foray.fotree.FoObj;
import org.foray.fotree.FoTree4a;
-import org.foray.fotree.FoTreeBuilder;
+import org.foray.fotree.FoTreeParser4a;
import org.foray.fotree.Namespace;
import org.foray.fotree.Property;
import org.foray.fotree.PropertyException;
@@ -73,7 +73,7 @@
@Override
public void parseAttributes(final PropertyList propertyList,
final Attributes attlist, final FoObj currentFObj,
- final Locator locator, final FoTreeBuilder builder)
+ final Locator locator, final FoTreeParser4a builder)
throws FoTreeException {
final int[] attributeSort = sortAttributes(attlist);
try {
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/foray/NamespaceForay.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/foray/NamespaceForay.java 2021-11-23 20:49:25 UTC (rev 12122)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/foray/NamespaceForay.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -30,7 +30,7 @@
import org.foray.fotree.FoObj;
import org.foray.fotree.FoTree4a;
-import org.foray.fotree.FoTreeBuilder;
+import org.foray.fotree.FoTreeParser4a;
import org.foray.fotree.Namespace;
import org.foray.fotree.Property;
import org.foray.fotree.PropertyException;
@@ -74,7 +74,7 @@
@Override
public void parseAttributes(final PropertyList propertyList,
final Attributes attlist, final FoObj currentFObj,
- final Locator locator, final FoTreeBuilder builder)
+ final Locator locator, final FoTreeParser4a builder)
throws FoTreeException {
final int[] attributeSort = sortAttributes(attlist);
try {
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/math/MathNamespace.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/math/MathNamespace.java 2021-11-23 20:49:25 UTC (rev 12122)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/math/MathNamespace.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -30,7 +30,7 @@
import org.foray.fotree.FoObj;
import org.foray.fotree.FoTree4a;
-import org.foray.fotree.FoTreeBuilder;
+import org.foray.fotree.FoTreeParser4a;
import org.foray.fotree.Namespace;
import org.foray.fotree.Property;
import org.foray.fotree.PropertyException;
@@ -75,7 +75,7 @@
@Override
public void parseAttributes(final PropertyList propertyList,
final Attributes attlist, final FoObj currentFObj,
- final Locator locator, final FoTreeBuilder builder) {
+ final Locator locator, final FoTreeParser4a builder) {
/*
* There is nothing to do here. We passed the raw attributes when
* we created the propertyList instance.
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/svg/NamespaceSvg.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/svg/NamespaceSvg.java 2021-11-23 20:49:25 UTC (rev 12122)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/svg/NamespaceSvg.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -31,7 +31,7 @@
import org.foray.common.SvgUtil;
import org.foray.fotree.FoObj;
import org.foray.fotree.FoTree4a;
-import org.foray.fotree.FoTreeBuilder;
+import org.foray.fotree.FoTreeParser4a;
import org.foray.fotree.Namespace;
import org.foray.fotree.Property;
import org.foray.fotree.PropertyException;
@@ -75,7 +75,7 @@
@Override
public void parseAttributes(final PropertyList propertyList,
final Attributes attlist, final FoObj currentFObj,
- final Locator locator, final FoTreeBuilder builder) {
+ final Locator locator, final FoTreeParser4a builder) {
/*
* There is nothing to do here. We passed the raw attributes when
* we created the propertyList instance.
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/xml/NamespaceXml.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/xml/NamespaceXml.java 2021-11-23 20:49:25 UTC (rev 12122)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/xml/NamespaceXml.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -30,7 +30,7 @@
import org.foray.fotree.FoObj;
import org.foray.fotree.FoTree4a;
-import org.foray.fotree.FoTreeBuilder;
+import org.foray.fotree.FoTreeParser4a;
import org.foray.fotree.Namespace;
import org.foray.fotree.Property;
import org.foray.fotree.PropertyException;
@@ -75,7 +75,7 @@
@Override
public void parseAttributes(final PropertyList propertyList,
final Attributes attlist, final FoObj currentFObj,
- final Locator locator, final FoTreeBuilder builder) {
+ final Locator locator, final FoTreeParser4a builder) {
// This isn't needed for the xml: namespace.
return;
}
Modified: trunk/foray/foray-fotree/src/test/java/org/foray/fotree/AbstractPropertyTest.java
===================================================================
--- trunk/foray/foray-fotree/src/test/java/org/foray/fotree/AbstractPropertyTest.java 2021-11-23 20:49:25 UTC (rev 12122)
+++ trunk/foray/foray-fotree/src/test/java/org/foray/fotree/AbstractPropertyTest.java 2021-11-24 01:12:19 UTC (rev 12123)
@@ -103,7 +103,7 @@
final FoTreeServer4a server = Mockito.mock(FoTreeServer4a.class);
Mockito.when(server.getFontServer()).thenReturn(fontServer);
- final FoTreeBuilder foTreeBuilder = new FoTreeBuilder(server, null);
+ final FoTreeParser4a foTreeBuilder = new FoTreeParser4a(server, null);
final FoTree4a foTree = new FoTree4a(null, foTreeBuilder);
final PropertyList propertyList = new PropertyList(0);
final Root root = new Root(foTree, propertyList);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-23 20:49:29
|
Revision: 12122
http://sourceforge.net/p/foray/code/12122
Author: victormote
Date: 2021-11-23 20:49:25 +0000 (Tue, 23 Nov 2021)
Log Message:
-----------
Conform to aXSL changes: Improvements to the API for FO Tree parsing.
Modified Paths:
--------------
trunk/foray/foray-app/src/test/java/org/foray/app/area/AreaTreeCreator.java
trunk/foray/foray-app/src/test/java/org/foray/app/fo/AbstractFoTreeTest.java
trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java
trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestFont.java
trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestGraphic.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTree4a.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTreeFactory4a.java
trunk/foray/foray-core/src/main/java/org/foray/core/ForayDocument.java
trunk/foray/foray-core/src/main/java/org/foray/core/ForayTarget.java
trunk/foray/foray-fotree/build.gradle
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeServer4a.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/ForeignXml.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/Namespace.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/NamespaceAxsl.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/NamespaceFo.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/ObjectMakerFo.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/ExternalGraphic.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Root.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/prop/PdBackgroundImage.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/foray/NamespaceForay.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/math/MathNamespace.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/svg/NamespaceSvg.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/xml/NamespaceXml.java
trunk/foray/foray-fotree/src/test/java/org/foray/fotree/AbstractPropertyTest.java
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/area/AreaTreeCreator.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/area/AreaTreeCreator.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/area/AreaTreeCreator.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -34,7 +34,7 @@
import org.foray.area.AreaTreeFactory4a;
import org.foray.area.PageCollection;
import org.foray.core.ForayException;
-import org.foray.fotree.FoTreeBuilder;
+import org.foray.fotree.FoTree4a;
import org.foray.fotree.FoTreeServer4a;
import org.foray.fotree.fo.obj.PageSequence;
import org.foray.fotree.fo.obj.Root;
@@ -102,9 +102,9 @@
*/
public AreaTree4a buildAreaTree(final String file) throws ForayException {
final FoDocumentReader foReader = FoDocumentReader.getInstance();
- final FoTreeBuilder foTree = foReader.buildFoTree(file);
+ final FoTree4a foTree = foReader.buildFoTree(file);
final Root root = foTree.getRootFo();
- final AreaTree4a areaTree = this.areaTreeFactory.makeAreaTree(root);
+ final AreaTree4a areaTree = this.areaTreeFactory.makeAreaTree(foTree);
final PioneerLayoutStrategy layout = this.layoutFactory.makeLayout();
final Iterator<PageSequence> iterator = root.getPageSequenceIterator();
while (iterator.hasNext()) {
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/fo/AbstractFoTreeTest.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/fo/AbstractFoTreeTest.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/fo/AbstractFoTreeTest.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -29,7 +29,7 @@
package org.foray.app.fo;
import org.foray.fotree.FoObj;
-import org.foray.fotree.FoTreeBuilder;
+import org.foray.fotree.FoTree4a;
import org.foray.fotree.fo.obj.Flow;
import org.foray.fotree.fo.obj.PageSequence;
import org.foray.fotree.fo.obj.Root;
@@ -46,7 +46,7 @@
* @param foTree The fo tree whose first flow is needed.
* @return The first flow in {@code foTree}.
*/
- protected Flow getFlow(final FoTreeBuilder foTree) {
+ protected Flow getFlow(final FoTree4a foTree) {
final Root root = foTree.getRootFo();
FoObj node = root.getChildAt(1);
Assert.assertTrue(node instanceof PageSequence);
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-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -33,9 +33,11 @@
import org.foray.common.url.UrlFactory;
import org.foray.core.ForayException;
import org.foray.core.SessionConfig;
+import org.foray.fotree.FoTree4a;
import org.foray.fotree.FoTreeBuilder;
import org.foray.fotree.FoTreeServer4a;
+import org.axsl.fo.FoTreeException;
import org.axsl.font.FontConsumer;
import org.axsl.font.FontServer;
import org.axsl.graphic.GraphicServer;
@@ -45,20 +47,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
import org.mockito.Mockito;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.io.IOException;
-import java.io.InputStream;
+import java.io.Reader;
import java.net.URL;
-import javax.xml.parsers.ParserConfigurationException;
-
/**
* Singleton Helper class for tests that parses an input file and returns an
* FoTree instance for testing.
@@ -125,34 +123,22 @@
* @return The parsed FO Tree instance.
* @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;
+ public FoTree4a buildFoTree(final String file) throws ForayException {
+ final FoTree4a foTree;
try {
- foInputStream = new FileInputStream(foFile);
- } catch (final FileNotFoundException e) {
+ final Reader reader = new FileReader(file);
+ final InputSource inputSource = new InputSource(reader);
+ final FoTreeBuilder parser = this.treeServer.makeFoTreeParser();
+ parser.parseFoTree(inputSource);
+ foTree = parser.getFoTree();
+ } catch (FileNotFoundException | FoTreeException e) {
throw new ForayException(e);
}
- final InputSource foInputSource = new InputSource(foInputStream);
- final XMLReader xmlReader;
- try {
- xmlReader = foTreeBuilder.createSax2Parser(false, false, false, null, false);
- } catch (final SAXException | ParserConfigurationException e) {
- throw new ForayException(e);
- }
+
final FontServer fontServer = this.treeServer.getFontServer();
final FontConsumer fontConsumer = fontServer.makeFontConsumer();
- foTreeBuilder.setFontConsumer(fontConsumer);
- xmlReader.setContentHandler(foTreeBuilder);
- try {
- xmlReader.parse(foInputSource);
- } catch (final IOException e) {
- throw new ForayException(e);
- } catch (final SAXException e) {
- throw new ForayException(e);
- }
- return foTreeBuilder;
+ foTree.setFontConsumer(fontConsumer);
+ return foTree;
}
/**
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestFont.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestFont.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestFont.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -30,7 +30,7 @@
import org.foray.core.ForayException;
import org.foray.fotree.FoObj;
-import org.foray.fotree.FoTreeBuilder;
+import org.foray.fotree.FoTree4a;
import org.foray.fotree.fo.obj.Block;
import org.foray.fotree.fo.obj.Flow;
@@ -55,7 +55,7 @@
@Ignore
public void testFontFamily001() throws ForayException {
final FoDocumentReader reader = FoDocumentReader.getInstance();
- final FoTreeBuilder foTree = reader.buildFoTree(
+ final FoTree4a foTree = reader.buildFoTree(
"fo/font-family-001.fo");
final Flow flow = this.getFlow(foTree);
@@ -86,7 +86,7 @@
@Ignore
public void testFontSize001() throws ForayException {
final FoDocumentReader reader = FoDocumentReader.getInstance();
- final FoTreeBuilder foTree = reader.buildFoTree("fo/font-size-001.fo");
+ final FoTree4a foTree = reader.buildFoTree("fo/font-size-001.fo");
final Flow flow = this.getFlow(foTree);
FoObj node = flow.getChildAt(0);
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestGraphic.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestGraphic.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestGraphic.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -30,7 +30,7 @@
import org.foray.core.ForayException;
import org.foray.fotree.FoObj;
-import org.foray.fotree.FoTreeBuilder;
+import org.foray.fotree.FoTree4a;
import org.foray.fotree.fo.obj.Block;
import org.foray.fotree.fo.obj.Flow;
import org.foray.fotree.fo.obj.InstreamForeignObject;
@@ -50,7 +50,7 @@
*/
public void testGraphic001() throws ForayException {
final FoDocumentReader reader = FoDocumentReader.getInstance();
- final FoTreeBuilder foTree = reader.buildFoTree(
+ final FoTree4a foTree = reader.buildFoTree(
"fo/graphic-001.fo");
final Flow flow = this.getFlow(foTree);
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTree4a.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTree4a.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTree4a.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -59,7 +59,8 @@
private static final short INITIAL_LINKAGE_MAP_SIZE = 200;
/** The "generated-by" trait, as defined in Section 6.1.1. */
- private FoLinkage generatedBy;
+// private FoLinkage generatedBy;
+ private FoTree foTree;
/** The children of this node. */
private List<PageCollection> children = new ArrayList<PageCollection>();
@@ -114,14 +115,16 @@
/**
* Private Constructor.
+ * @param foTree The FO tree instance that generates this area tree.
* @param fontConsumer The Font Consumer.
* @param textServer The Text Server.
* @param logger The logger.
*/
- private AreaTree4a(final FontConsumer fontConsumer,
+ private AreaTree4a(final FoTree foTree, final FontConsumer fontConsumer,
final TextServer textServer, final Logger logger) {
/* AreaTree has no parent with which to register. And it cannot
* create linkage because the AreaTreeControl isn't registered.*/
+ this.foTree = foTree;
this.fontConsumer = fontConsumer;
this.textServer = textServer;
this.logger = logger;
@@ -129,20 +132,19 @@
/**
* Package-visible factory method.
- * @param root The FO Root object that generates this area tree.
+ * @param foTree The FO tree instance that generates this area tree.
* @param logger The logger.
* @return The new instance.
*/
- static AreaTree4a makeAreaTree(final Root root, final Logger logger) {
- final FoTree foTree = root.getFoTree();
- final AreaTree4a newAreaTree = new AreaTree4a(foTree.getFontConsumer(),
+ static AreaTree4a makeAreaTree(final FoTree foTree, final Logger logger) {
+ final AreaTree4a newAreaTree = new AreaTree4a(foTree, foTree.getFontConsumer(),
foTree.getTextServer(), logger);
/*
* These registration steps must take place after the AreaTreeControl
* has been stored.
*/
- newAreaTree.generatedBy = newAreaTree.linkage(root, null);
- newAreaTree.getNormalLinkage().registerGeneratedArea(newAreaTree);
+// newAreaTree.generatedBy = newAreaTree.linkage(foTree, null);
+// newAreaTree.getNormalLinkage().registerGeneratedArea(newAreaTree);
return newAreaTree;
}
@@ -200,9 +202,10 @@
* @return The FO Root.
*/
public Root getRoot() {
- final FoLinkageNormal linkage = this.getNormalLinkage();
+// final FoLinkageNormal linkage = this.getNormalLinkage();
/* Cast verified at construction. */
- return (Root) linkage.getFONode();
+// return (Root) linkage.getFONode();
+ return this.foTree.getRootFo();
}
/**
@@ -210,7 +213,7 @@
* @param rootFObj The root object.
*/
private void layoutBookmarkTree(final Root rootFObj) {
- final BookmarkTree bookmarkTree = rootFObj.getBookmarkTree();
+ final BookmarkTree bookmarkTree = getRoot().getBookmarkTree();
if (bookmarkTree == null) {
return;
}
@@ -381,12 +384,14 @@
@Override
public FoLinkage getLinkage() {
- return this.generatedBy;
+ return null;
+// return this.generatedBy;
}
@Override
public Root traitGeneratedBy() {
- return (Root) this.getLinkage().getFONode();
+// return (Root) this.getLinkage().getFONode();
+ return this.foTree.getRootFo();
}
/**
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTreeFactory4a.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTreeFactory4a.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaTreeFactory4a.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -29,7 +29,7 @@
package org.foray.area;
import org.axsl.area.AreaTreeFactory;
-import org.axsl.fo.fo.Root;
+import org.axsl.fo.FoTree;
import org.slf4j.Logger;
@@ -52,8 +52,8 @@
}
@Override
- public AreaTree4a makeAreaTree(final Root root) {
- final AreaTree4a areaTree = AreaTree4a.makeAreaTree(root, getLogger());
+ public AreaTree4a makeAreaTree(final FoTree foTree) {
+ final AreaTree4a areaTree = AreaTree4a.makeAreaTree(foTree, getLogger());
return areaTree;
}
@@ -68,7 +68,7 @@
/**
* Sets the logger to be used by AreaTree instances.
* If a new logger is needed for each AreaTree instance created, this method
- * should be run before running {@link #makeAreaTree(Root)}.
+ * should be run before running {@link #makeAreaTree(FoTree)}.
* @param logger The new logger.
*/
public void setLogger(final Logger logger) {
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-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-core/src/main/java/org/foray/core/ForayDocument.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -33,6 +33,8 @@
import org.foray.common.xml.SaxParser;
import org.axsl.area.AreaTreeFactory;
+import org.axsl.fo.FoTreeException;
+import org.axsl.fo.FoTreeParser;
import org.axsl.font.FontConsumer;
import org.axsl.font.FontServer;
import org.axsl.graphic.GraphicServer;
@@ -53,8 +55,6 @@
import java.util.ArrayList;
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;
@@ -101,7 +101,7 @@
private List<ForayTarget> targetList = new ArrayList<ForayTarget>();
/** The FO tree builder, which handles the SAX events. */
- private org.axsl.fo.FoTree treeBuilder;
+ private FoTreeParser treeBuilder;
/** The current target being processed. */
private ForayTarget currentTarget;
@@ -112,49 +112,43 @@
/**
* Private constructor used only by the other constructors.
* @param session The parent ForaySession.
+ * @param inputSource The input source to be parsed.
*/
- private ForayDocument(final ForaySession session) {
+ private ForayDocument(final ForaySession session, final InputSource inputSource) throws ForayException {
this.session = session;
+ this.inputSource = inputSource;
session.registerDocument(this);
- this.treeBuilder = this.session.getFOTreeFactory().makeFoTree();
+ this.treeBuilder = this.session.getFOTreeFactory().makeFoTreeParser();
}
/**
* Constructor for processing a SAX InputSource containing an FO document.
- * If the document has not yet been transformed to XSL-FO, use the JAXP
- * constructor instead.
+ * If the document has not yet been transformed to XSL-FO, use the JAXP constructor instead.
* @param session The parent ForaySession.
- * @param inputSource A SAX InputSource which encapsulated an FO document,
- * that is, a document which is already in the XSL-FO namespace.
- * @param parser A SAX parser. If null is passed, a default parser will be
- * provided.
- * @throws ForayException If "null" parser is passed and there is an error
- * creating one.
+ * @param inputSource A SAX InputSource which encapsulated an FO document, that is, a document which is already in
+ * the XSL-FO namespace.
+ * @param parser A SAX parser. If null is passed, a default parser will be provided.
+ * @throws ForayException If "null" parser is passed and there is an error creating one.
*/
- public ForayDocument(final ForaySession session,
- final InputSource inputSource, final XMLReader parser)
+ public ForayDocument(final ForaySession session, final InputSource inputSource, final XMLReader parser)
throws ForayException {
- this(session);
+ this(session, inputSource);
this.inputSource = inputSource;
- this.parser = parser;
- if (parser == null) {
- this.parser = this.createParser();
+ if (parser != null) {
+ this.parser = parser;
+ this.parser.setContentHandler(this.treeBuilder.getContentHandler());
}
- this.parser.setContentHandler(this.treeBuilder.getContentHandler());
}
/**
* Constructor for processing a DOM Document containing an FO document.
- * If the document has not yet been transformed to XSL-FO, use the JAXP
- * constructor instead.
+ * If the document has not yet been transformed to XSL-FO, use the JAXP constructor instead.
* @param session The parent ForaySession.
* @param domDocument A DOM Document.
* @throws ForayException For errors instantiating the document.
*/
- public ForayDocument(final ForaySession session,
- final Document domDocument) throws ForayException {
- this(session);
- this.inputSource = new DocumentInputSource(domDocument);
+ public ForayDocument(final ForaySession session, final Document domDocument) throws ForayException {
+ this(session, new DocumentInputSource(domDocument));
this.parser = new DocumentReader();
this.parser.setContentHandler(this.treeBuilder.getContentHandler());
}
@@ -167,10 +161,9 @@
* @param jaxpSource The JAXP source.
* @throws ForayException For errors instantiating the document.
*/
- public ForayDocument(final ForaySession session,
- final Transformer jaxpTransformer, final Source jaxpSource)
+ public ForayDocument(final ForaySession session, final Transformer jaxpTransformer, final Source jaxpSource)
throws ForayException {
- this(session);
+ this(session, new InputSource(jaxpSource.getSystemId()));
this.jaxpTransformer = jaxpTransformer;
this.jaxpSource = jaxpSource;
this.jaxpResult = new SAXResult(this.treeBuilder.getContentHandler());
@@ -184,9 +177,11 @@
* @param xsltInput The stylesheet to be processed.
* @throws ForayException For errors instantiating the document.
*/
- public ForayDocument(final ForaySession session, final URL xmlInput,
- final URL xsltInput) throws ForayException {
- this(session);
+ public ForayDocument(final ForaySession session, final URL xmlInput, final URL xsltInput) throws ForayException {
+ this(session, (InputSource) null);
+ this.session = session;
+ session.registerDocument(this);
+
InputStream xmlInputStream = null;
try {
xmlInputStream = xmlInput.openStream();
@@ -277,29 +272,19 @@
public synchronized void processTarget(final ForayTarget target)
throws ForayException {
this.setTarget(target);
- this.treeBuilder.setFontConsumer(this.getFontConsumer());
- this.treeBuilder.setSpeechServer(this.getSpeechServer());
+// this.treeBuilder.setFontConsumer(this.getFontConsumer());
+// this.treeBuilder.setSpeechServer(this.getSpeechServer());
try {
if (this.jaxpTransformer == null) {
// Regular SAX Input
- this.parser.parse(this.inputSource);
+ this.treeBuilder.parseFoTree(inputSource);
} else {
// SAX Events generated by a JAXP Transformer
this.jaxpTransformer.transform(this.jaxpSource,
this.jaxpResult);
}
- } catch (final SAXException e) {
- if (e.getException() instanceof ForayException) {
- throw (ForayException) e.getException();
- }
+ } catch (final TransformerException | FoTreeException e) {
throw new ForayException(e);
- } catch (final TransformerException e) {
- if (e.getException() instanceof ForayException) {
- throw (ForayException) e.getException();
- }
- throw new ForayException(e);
- } catch (final IOException e) {
- throw new ForayException(e);
} finally {
cleanup(this.currentTarget);
}
@@ -431,7 +416,7 @@
* Returns the FOTree for this document.
* @return The FOTree for this document.
*/
- public org.axsl.fo.FoTree getFOTreeBuilder() {
+ public org.axsl.fo.FoTreeParser getFOTreeBuilder() {
return this.treeBuilder;
}
@@ -451,24 +436,4 @@
return this.session.getLayoutFactory();
}
- /**
- * Creates a SAX parser.
- * @return The newly-created SAX parser.
- * @throws ForayException For errors creating the parser.
- */
- XMLReader createParser() throws ForayException {
- final XMLReader xmlReader;
- try {
- 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) {
- throw new ForayException(e);
- }
- return xmlReader;
- }
-
}
Modified: trunk/foray/foray-core/src/main/java/org/foray/core/ForayTarget.java
===================================================================
--- trunk/foray/foray-core/src/main/java/org/foray/core/ForayTarget.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-core/src/main/java/org/foray/core/ForayTarget.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -34,6 +34,7 @@
import org.axsl.area.AreaTreeException;
import org.axsl.area.AreaTreeFactory;
import org.axsl.area.AreaTreeListener;
+import org.axsl.fo.FoTree;
import org.axsl.fo.FoTreeEvent;
import org.axsl.fo.FoTreeException;
import org.axsl.fo.FoTreeListener;
@@ -274,8 +275,8 @@
*/
private org.axsl.area.AreaTree getCreatedAreaTree() {
if (this.areaTree == null) {
- this.areaTree = this.getAreaTreeFactory().makeAreaTree(
- this.document.getFOTreeBuilder().getRootFo());
+ final FoTree foTree = this.document.getFOTreeBuilder().getFoTree();
+ this.areaTree = this.getAreaTreeFactory().makeAreaTree(foTree);
this.areaTree.registerListener(this);
}
return this.areaTree;
Modified: trunk/foray/foray-fotree/build.gradle
===================================================================
--- trunk/foray/foray-fotree/build.gradle 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/build.gradle 2021-11-23 20:49:25 UTC (rev 12122)
@@ -8,6 +8,7 @@
implementation group: 'ch.qos.logback', name: 'logback-classic', version: logbackClassicVersion
testImplementation group: 'junit', name: 'junit', version: junitVersion
+ testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
}
javadoc {
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -189,7 +189,7 @@
/* We reserve and hard-code zero for the root node. */
this.sequentialIndex = 0;
} else {
- final FoTreeBuilder builder = parent.getFoTree();
+ final FoTree4a builder = parent.getFoTree();
this.sequentialIndex = builder.getNextSequentialIndex();
}
}
@@ -320,7 +320,7 @@
* Return the ancestor tree builder.
* @return The ancestor tree builder.
*/
- public FoTreeBuilder getFoTree() {
+ public FoTree4a getFoTree() {
return getParent().getFoTree();
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -28,9 +28,15 @@
package org.foray.fotree;
+import org.foray.fotree.axsl.NamespaceAxsl;
+import org.foray.fotree.fo.NamespaceFo;
+import org.foray.fotree.fo.obj.Root;
+import org.foray.fotree.foray.NamespaceForay;
+import org.foray.fotree.math.MathNamespace;
+import org.foray.fotree.svg.NamespaceSvg;
+import org.foray.fotree.xml.NamespaceXml;
+
import org.axsl.fo.FoTree;
-import org.axsl.fo.FoTreeListener;
-import org.axsl.fo.fo.Root;
import org.axsl.font.FontConsumer;
import org.axsl.graphic.GraphicServer;
import org.axsl.orthography.OrthographyServer;
@@ -37,23 +43,24 @@
import org.axsl.speech.SpeechServer;
import org.axsl.text.TextServer;
-import org.xml.sax.ContentHandler;
+import org.slf4j.Logger;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
public class FoTree4a implements FoTree {
+ /** The parent server. */
+ private FoTreeServer4a treeServer;
+
/** The builder building this tree. */
private FoTreeBuilder treeBuilder;
/** The root of the FO tree. */
- private Root root;
+ private org.foray.fotree.fo.obj.Root root;
- /** Listeners that have registered to be notified about FOTreeEvent firings. */
- private List<FoTreeListener> foTreeListeners = new ArrayList<FoTreeListener>();
-
+// /** Listeners that have registered to be notified about FOTreeEvent firings. */
+// private List<FoTreeListener> foTreeListeners = new ArrayList<FoTreeListener>();
+//
/** The graphic server. */
private GraphicServer graphicServer;
@@ -75,35 +82,33 @@
/** Indicates whether graphics should be cached. */
private boolean cachingGraphics;
+ /** The last sequential index assigned. Zero is reserved for Root, but that
+ * value is hard-coded, and not obtained from this variable, so we
+ * initialize the variable to zero.*/
+ private int lastSequentialIndex = 0;
+
/**
* Constructor.
+ * @param treeServer The parent tree server.
* @param treeBuilder The tree builder building this instance.
*/
- public FoTree4a(final FoTreeBuilder treeBuilder) {
+ public FoTree4a(final FoTreeServer4a treeServer, final FoTreeBuilder treeBuilder) {
+ this.treeServer = treeServer;
this.treeBuilder = treeBuilder;
}
@Override
- public ContentHandler getContentHandler() {
- return this.treeBuilder;
- }
-
- @Override
public boolean hasData() {
return this.root != null;
}
- @Override
- public Root getRootFo() {
- return this.root;
+ public void setRootFo(final Root root) {
+ this.root = root;
}
@Override
- public void registerListener(final FoTreeListener listener) {
- if (listener == null) {
- return;
- }
- this.foTreeListeners.add(listener);
+ public org.foray.fotree.fo.obj.Root getRootFo() {
+ return this.root;
}
@Override
@@ -174,4 +179,96 @@
return this.cachingGraphics;
}
+ /**
+ * Returns the next sequential index.
+ * @return The next sequential index.
+ */
+ public synchronized int getNextSequentialIndex() {
+ this.lastSequentialIndex++;
+ return this.lastSequentialIndex;
+ }
+
+ public FoTreeServer4a getTreeServer() {
+ return this.treeServer;
+ }
+
+ /**
+ * Return the FO namespace instance.
+ * @return The FO namespace instance.
+ */
+ public NamespaceFo getFONamespace() {
+ return getTreeServer().getFONamespace();
+ }
+
+ /**
+ * Return the Extension namespace instance.
+ * @return The Extension namespace instance.
+ */
+ public NamespaceForay getForayNamespace() {
+ return getTreeServer().getForayNamespace();
+ }
+
+ /**
+ * Return the SVG namespace instance.
+ * @return The SVG namespace instance.
+ */
+ public NamespaceSvg getSVGNamespace() {
+ return getTreeServer().getSVGNamespace();
+ }
+
+ /**
+ * Return the MathML namespace instance.
+ * @return The MathML namespace instance.
+ */
+ public MathNamespace getMathNamespace() {
+ return getTreeServer().getMathNamespace();
+ }
+
+ /**
+ * Return the XML namespace instance.
+ * @return The XML namespace instance.
+ */
+ public NamespaceXml getXMLNamespace() {
+ return getTreeServer().getXMLNamespace();
+ }
+
+ /**
+ * Returns the aXSL namespace instance.
+ * @return The aXSL namespace instance.
+ */
+ public NamespaceAxsl getAxslNamespace() {
+ return getTreeServer().getAxslNamespace();
+ }
+
+ public Logger getLogger() {
+ return this.treeBuilder.getLogger();
+ }
+
+ /**
+ * Indicates whether we wish to preserve the raw FO Tree content so that it can be round-tripped.
+ * Setting this value to true will generally increase the amount of memory consumed, the amount of processing time
+ * consumed, or both.
+ * Setting it to false allows the system to use less memory or processing cycles, but at the cost of modifying the
+ * underlying data.
+ * @return True if the raw document content should be preserved intact.
+ */
+ public boolean preserveRawContent() {
+ return false;
+ }
+
+ /**
+ * Set a flag indicating that we are currently processing foreign XML.
+ * @param foreign The foreign XML item that we are currently processing.
+ */
+ public void activateForeignXML(final ForeignXml foreign) {
+ this.treeBuilder.activateForeignXML(foreign);
+ }
+
+ /**
+ * Unset the flag indicating that we are currently processing foreign XML.
+ */
+ public void deactivateForeignXML() {
+ this.treeBuilder.deactivateForeignXML();
+ }
+
}
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-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -29,23 +29,13 @@
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;
import org.foray.fotree.fo.obj.Root;
-import org.foray.fotree.foray.NamespaceForay;
-import org.foray.fotree.math.MathNamespace;
-import org.foray.fotree.svg.NamespaceSvg;
-import org.foray.fotree.xml.NamespaceXml;
import org.axsl.fo.FoTreeEvent;
import org.axsl.fo.FoTreeException;
import org.axsl.fo.FoTreeListener;
-import org.axsl.font.FontConsumer;
-import org.axsl.graphic.GraphicServer;
-import org.axsl.orthography.OrthographyServer;
-import org.axsl.speech.SpeechServer;
-import org.axsl.text.TextServer;
+import org.axsl.fo.FoTreeParser;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
@@ -52,6 +42,7 @@
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
import java.io.IOException;
import java.net.URL;
@@ -63,8 +54,11 @@
/**
* SAX Handler that builds the formatting object tree.
*/
-public class FoTreeBuilder extends SaxParser<Object> implements org.axsl.fo.FoTree {
+public class FoTreeBuilder extends SaxParser<FoTree4a> implements FoTreeParser {
+ /** The FO tree being created by this parser. */
+ private FoTree4a foTree;
+
/** The current formatting object being parsed. */
private FoObj currentFObj = null;
@@ -74,10 +68,8 @@
/** The SAX locator. */
private Locator locator;
- /** Collection of objects that have registered to be notified about
- * FOTreeEvent firings. */
- private List<FoTreeListener> foTreeListeners
- = new ArrayList<FoTreeListener>();
+ /** Collection of objects that have registered to be notified about FOTreeEvent firings. */
+ private List<FoTreeListener> foTreeListeners = new ArrayList<FoTreeListener>();
/** Indicates whether we are currently inside foreign XML. */
private ForeignXml activeForeignXML = null;
@@ -85,21 +77,6 @@
/** The parent server. */
private FoTreeServer4a server;
- /** The graphic server. */
- private GraphicServer graphicServer;
-
- /** The text server. */
- private TextServer textServer;
-
- /** The font consumer. */
- private FontConsumer fontConsumer;
-
- /** The speech server. */
- private SpeechServer speechServer;
-
- /** The orthography server for this document. */
- private OrthographyServer orthographyServer;
-
/** The paths to search when looking for graphics. */
private URL[] graphicSearchPath;
@@ -106,26 +83,61 @@
/** Indicates whether graphics should be cached. */
private boolean cachingGraphics;
- /** The last sequential index assigned. Zero is reserved for Root, but that
- * value is hard-coded, and not obtained from this variable, so we
- * initialize the variable to zero.*/
- private int lastSequentialIndex = 0;
+ /** Externally-provided parser, if any. */
+ private XMLReader parser;
/**
* Constructor.
* @param server The parent server.
+ * @param parser The parser. If null, one will be created.
*/
- public FoTreeBuilder(final FoTreeServer4a server) {
+ public FoTreeBuilder(final FoTreeServer4a server, final XMLReader parser) {
this.server = server;
+ this.parser = parser;
+ reset();
}
@Override
- public Object parse(final InputSource inputSource) throws IOException, ParserConfigurationException, SAXException {
- /* TODO: Not sure how this class is getting used. There doesn't seem to be a reader anywhere. */
- return null;
+ public void reset() {
+ this.currentFObj = null;
+ this.rootFObj = null;
+ this.foTreeListeners.clear();
+ this.foTree = new FoTree4a(this.server, this);
+ foTree.setGraphicServer(this.server.getGraphicServer());
+ foTree.setTextServer(this.server.getTextServer());
+ foTree.setOrthographyServer(this.server.getOrthographyServer());
+ foTree.setGraphicSearchPath(this.graphicSearchPath);
+ foTree.setCachingGraphics(this.cachingGraphics);
+ foTree.setFontConsumer(this.server.getFontServer().makeFontConsumer());
}
@Override
+ public void parseFoTree(final InputSource inputSource) throws FoTreeException {
+ try {
+ parse(inputSource);
+ } catch (IOException | ParserConfigurationException | SAXException e) {
+ throw new FoTreeException(e);
+ }
+ }
+
+ @Override
+ public FoTree4a getFoTree() {
+ return this.foTree;
+ }
+
+ @Override
+ public FoTree4a parse(final InputSource inputSource)
+ throws IOException, ParserConfigurationException, SAXException {
+ XMLReader parser = this.parser;
+ if (parser == null) {
+ parser = createSax2Parser(false, true, true, null, false);
+ }
+ parser.parse(inputSource);
+ foTree.setRootFo(this.rootFObj);
+ return this.foTree;
+ }
+
+ @Override
public void characters(final char[] data, final int start, final int length)
throws SAXException {
if (this.activeForeignXML != null) {
@@ -223,8 +235,7 @@
+ "parsed");
}
}
- fobj = namespace.parseElement(localName, this.currentFObj, list,
- this.locator, this);
+ fobj = namespace.parseElement(this.foTree, localName, this.currentFObj, list, this.locator, this);
if (this.locator != null) {
fobj.setLocation(this.locator.getSystemId(),
this.locator.getLineNumber(),
@@ -266,7 +277,7 @@
}
if (fobj instanceof Root) {
this.rootFObj = (Root) fobj;
- this.rootFObj.setFOTreeBuilder(this);
+ this.rootFObj.setFOTreeBuilder(this.foTree);
return;
}
if (fobj.getName().equals("root")) {
@@ -283,19 +294,6 @@
}
/**
- * Reset this parser for reuse.
- */
- public void reset() {
- this.currentFObj = null;
- this.rootFObj = null;
- }
-
- @Override
- public boolean hasData() {
- return this.rootFObj != null;
- }
-
- /**
* Returns the line number currently showing in the SAX Locator.
* @return The line number currently showing in the SAX Locator.
*/
@@ -319,11 +317,7 @@
return column;
}
- /**
- * Add an object to the collection of objects that should be notified about
- * FOTreeEvent firings.
- * @param listener the Object which should be notified
- */
+ @Override
public void registerListener(final FoTreeListener listener) {
if (listener == null) {
return;
@@ -401,55 +395,55 @@
}
}
+// /**
+// * Return the FO namespace instance.
+// * @return The FO namespace instance.
+// */
+// public NamespaceFo getFONamespace() {
+// return getTreeServer().getFONamespace();
+// }
+//
+// /**
+// * Return the Extension namespace instance.
+// * @return The Extension namespace instance.
+// */
+// public NamespaceForay getForayNamespace() {
+// return getTreeServer().getForayNamespace();
+// }
+//
+// /**
+// * Return the SVG namespace instance.
+// * @return The SVG namespace instance.
+// */
+// public NamespaceSvg getSVGNamespace() {
+// return getTreeServer().getSVGNamespace();
+// }
+//
+// /**
+// * Return the MathML namespace instance.
+// * @return The MathML namespace instance.
+// */
+// public MathNamespace getMathNamespace() {
+// return getTreeServer().getMathNamespace();
+// }
+//
+// /**
+// * Return the XML namespace instance.
+// * @return The XML namespace instance.
+// */
+// public NamespaceXml getXMLNamespace() {
+// return getTreeServer().getXMLNamespace();
+// }
+//
+// /**
+// * Returns the aXSL namespace instance.
+// * @return The aXSL namespace instance.
+// */
+// public NamespaceAxsl getAxslNamespace() {
+// return getTreeServer().getAxslNamespace();
+// }
+//
/**
- * Return the FO namespace instance.
- * @return The FO namespace instance.
- */
- public NamespaceFo getFONamespace() {
- return getTreeServer().getFONamespace();
- }
-
- /**
- * Return the Extension namespace instance.
- * @return The Extension namespace instance.
- */
- public NamespaceForay getForayNamespace() {
- return getTreeServer().getForayNamespace();
- }
-
- /**
- * Return the SVG namespace instance.
- * @return The SVG namespace instance.
- */
- public NamespaceSvg getSVGNamespace() {
- return getTreeServer().getSVGNamespace();
- }
-
- /**
- * Return the MathML namespace instance.
- * @return The MathML namespace instance.
- */
- public MathNamespace getMathNamespace() {
- return getTreeServer().getMathNamespace();
- }
-
- /**
- * Return the XML namespace instance.
- * @return The XML namespace instance.
- */
- public NamespaceXml getXMLNamespace() {
- return getTreeServer().getXMLNamespace();
- }
-
- /**
- * Returns the aXSL namespace instance.
- * @return The aXSL namespace instance.
- */
- public NamespaceAxsl getAxslNamespace() {
- return getTreeServer().getAxslNamespace();
- }
-
- /**
* Returns the name of a given property type.
* @param propertyType The property type whose name is needed.
* @return The name of the property.
@@ -458,11 +452,6 @@
return propertyType.toStringUnparsed();
}
- @Override
- public Root getRootFo() {
- return this.rootFObj;
- }
-
/**
* Set a flag indicating that we are currently processing foreign XML.
* @param foreign The foreign XML item that we are currently processing.
@@ -474,7 +463,7 @@
/**
* Unset the flag indicating that we are currently processing foreign XML.
*/
- public void disactivateForeignXML() {
+ public void deactivateForeignXML() {
this.activeForeignXML = null;
}
@@ -486,61 +475,6 @@
return this.server;
}
- @Override
- public void setGraphicServer(final GraphicServer graphicServer) {
- this.graphicServer = graphicServer;
- }
-
- @Override
- public GraphicServer getGraphicServer() {
- return this.graphicServer;
- }
-
- @Override
- public void setTextServer(final TextServer textServer) {
- this.textServer = textServer;
- }
-
- @Override
- public TextServer getTextServer() {
- return this.textServer;
- }
-
- @Override
- public void setFontConsumer(final FontConsumer consumer) {
- this.fontConsumer = consumer;
- }
-
- @Override
- public void setSpeechServer(final SpeechServer server) {
- this.speechServer = server;
- }
-
- @Override
- public FontConsumer getFontConsumer() {
- return this.fontConsumer;
- }
-
- @Override
- public SpeechServer getSpeechServer() {
- return this.speechServer;
- }
-
- @Override
- public void setOrthographyServer(final OrthographyServer orthographyServer) {
- this.orthographyServer = orthographyServer;
- }
-
- @Override
- public OrthographyServer getOrthographyServer() {
- return this.orthographyServer;
- }
-
- @Override
- public void setGraphicSearchPath(final URL[] graphicSearchPath) {
- this.graphicSearchPath = graphicSearchPath;
- }
-
/**
* Return the graphic search path.
* @return The graphic search path.
@@ -549,11 +483,6 @@
return this.graphicSearchPath;
}
- @Override
- public void setCachingGraphics(final boolean cachingGraphics) {
- this.cachingGraphics = cachingGraphics;
- }
-
/**
* Indicates whether graphics should be cached.
* @return True iff graphics should be cached.
@@ -562,28 +491,6 @@
return this.cachingGraphics;
}
- /**
- * Indicates whether we wish to preserve the raw FO Tree content so that it
- * can be round-tripped. Setting this value to true will generally increase
- * the amount of memory consumed, the amount of processing time consumed,
- * or both.
- * Setting it to false allows the system to use less memory or processing
- * cycles, but at the cost of modifying the underlying data.
- * @return True if the raw document content should be preserved intact.
- */
- public boolean preserveRawContent() {
- return false;
- }
-
- /**
- * Returns the next sequential index.
- * @return The next sequential index.
- */
- public synchronized int getNextSequentialIndex() {
- this.lastSequentialIndex++;
- return this.lastSequentialIndex;
- }
-
@Override
public ContentHandler getContentHandler() {
return this;
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeServer4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeServer4a.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeServer4a.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -279,13 +279,8 @@
}
@Override
- public FoTreeBuilder makeFoTree() {
- final FoTreeBuilder foTreeBuilder = new FoTreeBuilder(this);
- foTreeBuilder.setGraphicServer(this.graphicServer);
- foTreeBuilder.setTextServer(this.textServer);
- foTreeBuilder.setOrthographyServer(this.orthographyServer);
- foTreeBuilder.setGraphicSearchPath(this.graphicSearchPath);
- foTreeBuilder.setCachingGraphics(this.cachingGraphics);
+ public FoTreeBuilder makeFoTreeParser() {
+ final FoTreeBuilder foTreeBuilder = new FoTreeBuilder(this, null);
return foTreeBuilder;
}
@@ -313,4 +308,28 @@
return this.fontServer;
}
+ public GraphicServer getGraphicServer() {
+ return this.graphicServer;
+ }
+
+ public OrthographyServer getOrthographyServer() {
+ return this.orthographyServer;
+ }
+
+ /**
+ * Returns the URLs to be searched for graphic files.
+ * @return The graphicSearchPath.
+ */
+ public URL[] getGraphicSearchPath() {
+ return this.graphicSearchPath;
+ }
+
+ /**
+ * Indicates whether graphics should be cached.
+ * @return The cachingGraphics.
+ */
+ public boolean isCachingGraphics() {
+ return this.cachingGraphics;
+ }
+
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/ForeignXml.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/ForeignXml.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/ForeignXml.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -219,7 +219,7 @@
// back over to the FoTreeBuilder.
if (this.currentElement == this.domDocument.getDocumentElement()) {
this.currentElement.normalize();
- getFoTree().disactivateForeignXML();
+ getFoTree().deactivateForeignXML();
return;
}
// Otherwise go back up the tree one level.
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/Namespace.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/Namespace.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/Namespace.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -71,6 +71,7 @@
/**
* Parse an element in this namespace.
+ * @param foTree The parent FO Tree.
* @param localName The local name of the element.
* @param currentFObj The current FoObj, that is, the parent of the one
* being parsed.
@@ -81,11 +82,11 @@
* @return The newly-created FoObj instance.
* @throws FoTreeException For parsing errors.
*/
- public FoObj parseElement(final String localName,
+ public FoObj parseElement(final FoTree4a foTree, final String localName,
final FoObj currentFObj, final PropertyList list,
final Locator locator,
final FoTreeBuilder builder) throws FoTreeException {
- final FoObj fobj = parseElementForNS(localName, currentFObj,
+ final FoObj fobj = parseElementForNS(foTree, localName, currentFObj,
list, locator);
if (fobj == null) {
checkUnknownElement(builder, localName, locator);
@@ -94,7 +95,8 @@
}
/**
- * The namespace-specific logic for paring an element.
+ * The namespace-specific logic for parsing an element.
+ * @param foTree The parent FO Tree.
* @param localName The local name of the element.
* @param currentFObj The current FoObj, that is, the parent of the one
* being parsed.
@@ -104,7 +106,7 @@
* @return The newly-created FoObj instance.
* @throws FoTreeException For parsing errors.
*/
- protected abstract FoObj parseElementForNS(
+ protected abstract FoObj parseElementForNS(FoTree4a foTree,
String localName, FoObj currentFObj, PropertyList list,
Locator locator) throws FoTreeException;
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/NamespaceAxsl.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/NamespaceAxsl.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/NamespaceAxsl.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -29,6 +29,7 @@
package org.foray.fotree.axsl;
import org.foray.fotree.FoObj;
+import org.foray.fotree.FoTree4a;
import org.foray.fotree.FoTreeBuilder;
import org.foray.fotree.Namespace;
import org.foray.fotree.Property;
@@ -63,7 +64,7 @@
}
@Override
- public FoObj parseElementForNS(final String localName,
+ public FoObj parseElementForNS(final FoTree4a foTree, final String localName,
final FoObj currentFObj, final PropertyList list,
final Locator locator) throws FoTreeException {
return ObjectMakerAxsl.makeObject(localName, currentFObj, list,
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/NamespaceFo.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/NamespaceFo.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/NamespaceFo.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -29,6 +29,7 @@
package org.foray.fotree.fo;
import org.foray.fotree.FoObj;
+import org.foray.fotree.FoTree4a;
import org.foray.fotree.FoTreeBuilder;
import org.foray.fotree.Namespace;
import org.foray.fotree.Property;
@@ -63,10 +64,10 @@
}
@Override
- public FoObj parseElementForNS(final String localName,
+ public FoObj parseElementForNS(final FoTree4a foTree, final String localName,
final FoObj currentFObj, final PropertyList list,
final Locator locator) throws FoTreeException {
- return ObjectMakerFo.makeObject(localName, currentFObj, list, locator);
+ return ObjectMakerFo.makeObject(foTree, localName, currentFObj, list, locator);
}
@Override
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/ObjectMakerFo.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/ObjectMakerFo.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/ObjectMakerFo.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -29,6 +29,7 @@
package org.foray.fotree.fo;
import org.foray.fotree.FoObj;
+import org.foray.fotree.FoTree4a;
import org.foray.fotree.PropertyList;
import org.foray.fotree.fo.obj.AbstractTablePart;
import org.foray.fotree.fo.obj.BasicLink;
@@ -130,8 +131,8 @@
private ObjectMakerFo() { }
/**
- * Converts an unparsed XSL-FO element into an FoObj instance that can be
- * added to the FO Tree.
+ * Converts an unparsed XSL-FO element into an FoObj instance that can be added to the FO Tree.
+ * @param foTree The parent FO Tree.
* @param objectName The unparsed XSL-FO element name.
* @param parent The parent FoObj.
* @param propertyList The property list of the parent FoObj.
@@ -139,7 +140,7 @@
* @return The new FoObj instance for this XSL-FO element.
* @throws FoTreeException For errors during Fo construction.
*/
- public static FoObj makeObject(final String objectName, final FoObj parent,
+ public static FoObj makeObject(final FoTree4a foTree, final String objectName, final FoObj parent,
final PropertyList propertyList, final Locator locator)
throws FoTreeException {
final FoObject enumeration = FoObject.xslValueOf(objectName);
@@ -369,7 +370,9 @@
return new RetrieveTableMarker(parent, propertyList);
}
case ROOT: {
- return new Root(propertyList);
+ final Root root = new Root(foTree, propertyList);
+ foTree.setRootFo(root);
+ return root;
}
case SCALING_VALUE_CITATION: {
return new ScalingValueCitation(parent, propertyList);
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/ExternalGraphic.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/ExternalGraphic.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/ExternalGraphic.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -127,7 +127,7 @@
try {
this.graphic = getGraphicServer().makeGraphic(traitSrc(context),
getFoTree().getGraphicSearchPath(),
- getFoTree().getCachingGraphics());
+ getFoTree().isCachingGraphics());
} catch (final GraphicException e) {
getLogger().error(e.getMessage() + "\n"
+ this.getContextMessage());
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Root.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Root.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Root.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -30,7 +30,7 @@
import org.foray.common.data.OrderedTreeNode;
import org.foray.fotree.FoObj;
-import org.foray.fotree.FoTreeBuilder;
+import org.foray.fotree.FoTree4a;
import org.foray.fotree.Namespace;
import org.foray.fotree.PropertyList;
import org.foray.fotree.axsl.obj.Metadata;
@@ -56,7 +56,7 @@
public class Root extends FoObj implements org.axsl.fo.fo.Root {
/** The "parent" FoTreeBuilder. */
- private FoTreeBuilder treeBuilder;
+ private FoTree4a treeBuilder;
/** The children of this object. */
private List<FoObj> children = new ArrayList<FoObj>();
@@ -86,10 +86,12 @@
/**
* Constructor.
+ * @param foTree The parent FO Tree.
* @param propertyList The property list for this FoObj.
*/
- public Root(final PropertyList propertyList) {
+ public Root(final FoTree4a foTree, final PropertyList propertyList) {
super(null);
+ this.treeBuilder = foTree;
this.propertyList = propertyList;
}
@@ -228,7 +230,7 @@
* Overrides the method in FONode because this is the root.
*/
@Override
- public FoTreeBuilder getFoTree() {
+ public FoTree4a getFoTree() {
return this.treeBuilder;
}
@@ -236,7 +238,7 @@
* Sets the "parent" tree builder.
* @param treeBuilder The new "parent" tree builder.
*/
- public void setFOTreeBuilder(final FoTreeBuilder treeBuilder) {
+ public void setFOTreeBuilder(final FoTree4a treeBuilder) {
this.treeBuilder = treeBuilder;
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/prop/PdBackgroundImage.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/prop/PdBackgroundImage.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/prop/PdBackgroundImage.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -135,7 +135,7 @@
try {
backgroundImage = fobj.getGraphicServer().makeGraphic(src,
fobj.getFoTree().getGraphicSearchPath(),
- fobj.getFoTree().getCachingGraphics());
+ fobj.getFoTree().isCachingGraphics());
} catch (final GraphicException imgex) {
backgroundImage = null;
fobj.getLogger().error("Error creating background image: "
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/foray/NamespaceForay.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/foray/NamespaceForay.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/foray/NamespaceForay.java 2021-11-23 20:49:25 UTC (rev 12122)
@@ -29,6 +29,7 @@
package org.foray.fotree.foray;
import org.foray.fotree.FoObj;
+import org.foray.fotree.FoTree4a;
import org.foray.fotree.FoTreeBuilder;
import org.foray.fotree.Namespace;
import org.foray.fotree.Property;
@@ -64,7 +65,7 @@
}
@Override
- public FoObj parseElementForNS(final String localName,
+ public FoObj parseElementForNS(final FoTree4a foTree, final String localName,
final FoObj currentFObj, final PropertyList list,
final Locator locator) throws FoTreeException {
return ObjectMakerForay.makeObject(localName, currentFObj, list);
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/math/MathNamespace.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/math/MathNamespace.java 2021-11-23 14:15:42 UTC (rev 12121)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/math/MathNa...
[truncated message content] |
|
From: <vic...@us...> - 2021-11-23 14:15:44
|
Revision: 12121
http://sourceforge.net/p/foray/code/12121
Author: victormote
Date: 2021-11-23 14:15:42 +0000 (Tue, 23 Nov 2021)
Log Message:
-----------
Rough-in new implementation of FoTree, to begin to separate the tree from the parsing of it.
Modified Paths:
--------------
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java
Added Paths:
-----------
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java
Added: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java (rev 0)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java 2021-11-23 14:15:42 UTC (rev 12121)
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * 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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fotree;
+
+import org.axsl.fo.FoTree;
+import org.axsl.fo.FoTreeListener;
+import org.axsl.fo.fo.Root;
+import org.axsl.font.FontConsumer;
+import org.axsl.graphic.GraphicServer;
+import org.axsl.orthography.OrthographyServer;
+import org.axsl.speech.SpeechServer;
+import org.axsl.text.TextServer;
+
+import org.xml.sax.ContentHandler;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+public class FoTree4a implements FoTree {
+
+ /** The builder building this tree. */
+ private FoTreeBuilder treeBuilder;
+
+ /** The root of the FO tree. */
+ private Root root;
+
+ /** Listeners that have registered to be notified about FOTreeEvent firings. */
+ private List<FoTreeListener> foTreeListeners = new ArrayList<FoTreeListener>();
+
+ /** The graphic server. */
+ private GraphicServer graphicServer;
+
+ /** The text server. */
+ private TextServer textServer;
+
+ /** The font consumer. */
+ private FontConsumer fontConsumer;
+
+ /** The speech server. */
+ private SpeechServer speechServer;
+
+ /** The orthography server. */
+ private OrthographyServer orthographyServer;
+
+ /** The URLs to be searched when looking for graphics files. */
+ private URL[] graphicSearchPath;
+
+ /** Indicates whether graphics should be cached. */
+ private boolean cachingGraphics;
+
+ /**
+ * Constructor.
+ * @param treeBuilder The tree builder building this instance.
+ */
+ public FoTree4a(final FoTreeBuilder treeBuilder) {
+ this.treeBuilder = treeBuilder;
+ }
+
+ @Override
+ public ContentHandler getContentHandler() {
+ return this.treeBuilder;
+ }
+
+ @Override
+ public boolean hasData() {
+ return this.root != null;
+ }
+
+ @Override
+ public Root getRootFo() {
+ return this.root;
+ }
+
+ @Override
+ public void registerListener(final FoTreeListener listener) {
+ if (listener == null) {
+ return;
+ }
+ this.foTreeListeners.add(listener);
+ }
+
+ @Override
+ public void setGraphicServer(final GraphicServer graphicServer) {
+ this.graphicServer = graphicServer;
+ }
+
+ @Override
+ public GraphicServer getGraphicServer() {
+ return this.graphicServer;
+ }
+
+ @Override
+ public void setTextServer(final TextServer textServer) {
+ this.textServer = textServer;
+ }
+
+ @Override
+ public TextServer getTextServer() {
+ return this.textServer;
+ }
+
+ @Override
+ public void setFontConsumer(final FontConsumer consumer) {
+ this.fontConsumer = consumer;
+ }
+
+ @Override
+ public FontConsumer getFontConsumer() {
+ return this.fontConsumer;
+ }
+
+ @Override
+ public void setSpeechServer(final SpeechServer server) {
+ this.speechServer = server;
+ }
+
+ @Override
+ public SpeechServer getSpeechServer() {
+ return this.speechServer;
+ }
+
+ @Override
+ public void setOrthographyServer(final OrthographyServer orthographyServer) {
+ this.orthographyServer = orthographyServer;
+ }
+
+ @Override
+ public OrthographyServer getOrthographyServer() {
+ return this.orthographyServer;
+ }
+
+ @Override
+ public void setGraphicSearchPath(final URL[] graphicSearchPath) {
+ this.graphicSearchPath = graphicSearchPath;
+ }
+
+ public URL[] getGraphicSearchPath() {
+ return this.graphicSearchPath;
+ }
+
+ @Override
+ public void setCachingGraphics(final boolean cachingGraphics) {
+ this.cachingGraphics = cachingGraphics;
+ }
+
+ public boolean isCachingGraphics() {
+ return this.cachingGraphics;
+ }
+
+}
Property changes on: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
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-23 13:45:58 UTC (rev 12120)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java 2021-11-23 14:15:42 UTC (rev 12121)
@@ -79,10 +79,6 @@
private List<FoTreeListener> foTreeListeners
= new ArrayList<FoTreeListener>();
- /** Keeps a count of how many FOTreeListeners have requested notification
- * of FoObj-complete events. */
- private int qtyFObjListeners = 0;
-
/** Indicates whether we are currently inside foreign XML. */
private ForeignXml activeForeignXML = null;
@@ -333,9 +329,6 @@
return;
}
this.foTreeListeners.add(listener);
- if (listener.wantsFoCompleteEvents()) {
- this.qtyFObjListeners ++;
- }
}
/**
@@ -348,9 +341,17 @@
return;
}
this.foTreeListeners.remove(listener);
- if (listener.wantsFoCompleteEvents()) {
- this.qtyFObjListeners --;
+ }
+
+ private int qtyFoCompleteListeners() {
+ int count = 0;
+ for (int index = 0; index < this.foTreeListeners.size(); index ++) {
+ final FoTreeListener listener = this.foTreeListeners.get(index);
+ if (listener.wantsFoCompleteEvents()) {
+ count ++;
+ }
}
+ return count;
}
/**
@@ -362,7 +363,7 @@
private void notifyFObjComplete(final FoObj fobj) throws FoTreeException {
/* If nobody wants these events, don't waste resources creating
* them. */
- if (this.qtyFObjListeners < 1) {
+ if (qtyFoCompleteListeners() < 1) {
return;
}
final FoTreeEvent event = new FoTreeEvent(this, fobj);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-23 13:46:00
|
Revision: 12120
http://sourceforge.net/p/foray/code/12120
Author: victormote
Date: 2021-11-23 13:45:58 +0000 (Tue, 23 Nov 2021)
Log Message:
-----------
Conform to aXSL change: Begin refactoring to remove dependency on ContentHandler.
Modified Paths:
--------------
trunk/foray/foray-core/src/main/java/org/foray/core/ForayDocument.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java
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-23 11:47:09 UTC (rev 12119)
+++ trunk/foray/foray-core/src/main/java/org/foray/core/ForayDocument.java 2021-11-23 13:45:58 UTC (rev 12120)
@@ -140,7 +140,7 @@
if (parser == null) {
this.parser = this.createParser();
}
- this.parser.setContentHandler(this.treeBuilder);
+ this.parser.setContentHandler(this.treeBuilder.getContentHandler());
}
/**
@@ -156,7 +156,7 @@
this(session);
this.inputSource = new DocumentInputSource(domDocument);
this.parser = new DocumentReader();
- this.parser.setContentHandler(this.treeBuilder);
+ this.parser.setContentHandler(this.treeBuilder.getContentHandler());
}
/**
@@ -173,7 +173,7 @@
this(session);
this.jaxpTransformer = jaxpTransformer;
this.jaxpSource = jaxpSource;
- this.jaxpResult = new SAXResult(this.treeBuilder);
+ this.jaxpResult = new SAXResult(this.treeBuilder.getContentHandler());
}
/**
@@ -208,7 +208,7 @@
} catch (final TransformerConfigurationException e) {
throw new ForayException(e);
}
- this.jaxpResult = new SAXResult(this.treeBuilder);
+ this.jaxpResult = new SAXResult(this.treeBuilder.getContentHandler());
}
/**
@@ -232,7 +232,7 @@
* @return The SAX content handler.
*/
public ContentHandler getContentHandler() {
- return this.treeBuilder;
+ return this.treeBuilder.getContentHandler();
}
/**
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-23 11:47:09 UTC (rev 12119)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java 2021-11-23 13:45:58 UTC (rev 12120)
@@ -48,6 +48,7 @@
import org.axsl.text.TextServer;
import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
@@ -582,4 +583,9 @@
return this.lastSequentialIndex;
}
+ @Override
+ public ContentHandler getContentHandler() {
+ return this;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-23 11:47:12
|
Revision: 12119
http://sourceforge.net/p/foray/code/12119
Author: victormote
Date: 2021-11-23 11:47:09 +0000 (Tue, 23 Nov 2021)
Log Message:
-----------
Convert PatternParser to use our normal parsing pattern.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/HyphenationPatternsResource.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternSerializer.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/util/PatternParserTests.java
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/HyphenationPatternsResource.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/HyphenationPatternsResource.java 2021-11-23 01:26:19 UTC (rev 12118)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/HyphenationPatternsResource.java 2021-11-23 11:47:09 UTC (rev 12119)
@@ -29,11 +29,16 @@
package org.foray.orthography;
import org.foray.common.resource.ResourceLocation;
+import org.foray.orthography.util.PatternParser;
-import org.axsl.orthography.OrthographyException;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
-import java.io.InputStream;
+import java.io.IOException;
+import java.net.URL;
+import javax.xml.parsers.ParserConfigurationException;
+
/**
* Configuration information for a hyphenation patterns resource.
*/
@@ -62,19 +67,18 @@
return null;
}
- /* Does the XML file exist? */
- final InputStream inputStream = this.unparsedPatternsLocation.getInputStream();
- if (inputStream == null) {
- return null;
- }
+ final URL url = this.unparsedPatternsLocation.toUrl();
+ final InputSource inputSource = new InputSource(url.toExternalForm());
getLogger().debug("Parsing {}", this.unparsedPatternsLocation.getLocationDescription());
- final PatternTree patternTree = new PatternTree();
+ final PatternParser patternParser = new PatternParser();
+ PatternTree patternTree = null;
try {
- patternTree.loadPatterns(inputStream, getLogger());
- } catch (final OrthographyException e) {
+ patternTree = patternParser.parse(inputSource);
+ } catch (SAXException | ParserConfigurationException | IOException e) {
getLogger().info("Error parsing: " + this.unparsedPatternsLocation.getLocationDescription(), e);
}
+
return patternTree;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java 2021-11-23 01:26:19 UTC (rev 12118)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java 2021-11-23 11:47:09 UTC (rev 12119)
@@ -37,28 +37,20 @@
import org.foray.common.data.TernaryTree;
import org.foray.common.primitive.BitUtils;
import org.foray.common.primitive.StringUtils;
-import org.foray.orthography.util.PatternParser;
import org.axsl.orthography.OrthographyException;
-import org.slf4j.Logger;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
import java.io.IOException;
-import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
-import javax.xml.parsers.ParserConfigurationException;
-
/**
* <p>An implementation of the Knuth/Liang hyphenation scheme that is part of TeX.
* This scheme has three data components: classes, exceptions, and patterns.
- * More information about these components can be found in Appendix H of "The
- * "TeXbook", which is also volume A of "Computers & Typesetting".</p>
+ * More information about these components can be found in Appendix H of "The "TeXbook", which is also volume A of
+ * "Computers & Typesetting".</p>
*
* <p>The strings patterns are usually small (from 2 to 5 characters), but each
* char in the tree is stored in a node.
@@ -150,6 +142,15 @@
}
/**
+ * Constructor for the case where the pattern tree will be built by parsing.
+ * @param source The source of this object, either from parsing or deserialization.
+ */
+ public PatternTree(final Source source) {
+ this();
+ this.source = source;
+ }
+
+ /**
* Packs the interletter values by storing each one of them in 4 bits, two
* values into a byte, in big endian order, that is, the higher order byte
* into the high order 4-bits, and storing these packed values in
@@ -175,26 +176,6 @@
return start;
}
- /**
- * Read hyphenation patterns from an XML file.
- * @param inputStream The input stream containing the XML file containing the patterns.
- * @param logger A logger for user messages.
- * @throws OrthographyException For errors obtaining a parser or errors during the parsing.
- */
- public void loadPatterns(final InputStream inputStream, final Logger logger) throws OrthographyException {
- this.source = PatternTree.Source.PARSED;
- final PatternParser pp = new PatternParser(this);
-
- try {
- pp.parse(new InputSource(inputStream));
- } catch (SAXException | ParserConfigurationException | IOException e) {
- throw new OrthographyException(e);
- }
-
- // patterns/values should be now in the tree
- optimize();
- }
-
public void optimize() {
this.patternKeys.optimize();
this.patternValues.trimToSize();
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-23 01:26:19 UTC (rev 12118)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-23 11:47:09 UTC (rev 12119)
@@ -76,14 +76,8 @@
/**
* Constructor.
- * @param patternTree The pattern tree that is being built by this parser.
- * @throws OrthographyException For errors during construction.
*/
- public PatternParser(final PatternTree patternTree) throws OrthographyException {
- if (patternTree == null) {
- throw new NullPointerException("PatternConsumer may not be null.");
- }
- this.patternTree = patternTree;
+ public PatternParser() {
this.token = new StringBuilder();
}
@@ -90,9 +84,12 @@
@Override
public PatternTree parse(final InputSource inputSource)
throws SAXException, ParserConfigurationException, IOException {
+ this.patternTree = new PatternTree(PatternTree.Source.PARSED);
+
final XMLReader parser = createSax2Parser(false, false, false, null, false);
/* TODO: If PatternConsumer is not needed, use the implementation here instead. */
parser.parse(inputSource);
+ this.patternTree.optimize();
return this.patternTree;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternSerializer.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternSerializer.java 2021-11-23 01:26:19 UTC (rev 12118)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternSerializer.java 2021-11-23 11:47:09 UTC (rev 12119)
@@ -32,8 +32,6 @@
import org.foray.common.IoUtil;
import org.foray.orthography.PatternTree;
-import org.axsl.orthography.OrthographyException;
-
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
@@ -45,14 +43,17 @@
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
-import java.net.MalformedURLException;
import java.net.URL;
+import javax.xml.parsers.ParserConfigurationException;
+
/**
* Parse and serialize hyphenation patterns so that they can be packaged for runtime use without the need to parse them
* then.
@@ -122,18 +123,16 @@
*/
private void buildPatternFile(final File infile, final File outfile) {
getLogger().info("Processing " + infile);
- final PatternTree hTree = new PatternTree();
+ PatternTree hTree = null;
try {
final URL url = infile.toURI().toURL();
- hTree.loadPatterns(url.openStream(), getLogger());
- } catch (final OrthographyException ex) {
- getLogger().error("Can't load patterns from xml file " + infile + " - Maybe hyphenation.dtd is missing?");
- getLogger().error(ex.toString());
- } catch (final MalformedURLException e) {
- getLogger().error(e.getMessage());
- } catch (final IOException e) {
- getLogger().error(e.getMessage());
+ final InputSource inputSource = new InputSource(url.toExternalForm());
+ final PatternParser patternParser = new PatternParser();
+ hTree = patternParser.parse(inputSource);
+ } catch (SAXException | ParserConfigurationException | IOException e) {
+ getLogger().error("Error parsing " + infile + ": " + e.getMessage());
}
+
/* Serialize the object. */
try {
final ObjectOutputStream out =
Modified: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/util/PatternParserTests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/util/PatternParserTests.java 2021-11-23 01:26:19 UTC (rev 12118)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/util/PatternParserTests.java 2021-11-23 11:47:09 UTC (rev 12119)
@@ -30,8 +30,6 @@
import org.foray.orthography.PatternTree;
-import org.axsl.orthography.OrthographyException;
-
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -81,20 +79,17 @@
+ "</axsl-hyphenation>";
/**
- * Tests various Strings against the method
- * {@link WordListCreator#containsNonWord(String)}.
- * @throws OrthographyException Not expected here.
- * @throws IOException
- * @throws ParserConfigurationException
- * @throws SAXException
+ * Tests the basic ability to parse a patterns file.
+ * @throws IOException Not expected here.
+ * @throws ParserConfigurationException Not expected here.
+ * @throws SAXException Not expected here.
*/
@Test
- public void basicParserTest() throws OrthographyException, SAXException, ParserConfigurationException, IOException {
- final PatternTree patternTree = new PatternTree();
+ public void basicParserTest() throws SAXException, ParserConfigurationException, IOException {
final Reader reader = new StringReader(input);
final InputSource inputSource = new InputSource(reader);
- final PatternParser out = new PatternParser(patternTree);
- out.parse(inputSource);
+ final PatternParser out = new PatternParser();
+ final PatternTree patternTree = out.parse(inputSource);
Assert.assertEquals('-', patternTree.getHyphenChar());
Assert.assertEquals(3, patternTree.getMinBefore());
Assert.assertEquals(2, patternTree.getMinAfter());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-23 01:26:22
|
Revision: 12118
http://sourceforge.net/p/foray/code/12118
Author: victormote
Date: 2021-11-23 01:26:19 +0000 (Tue, 23 Nov 2021)
Log Message:
-----------
More standardization of SAX parsers.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java
Added Paths:
-----------
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/util/PatternParserTests.java
Removed Paths:
-------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternConsumer.java
Deleted: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternConsumer.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternConsumer.java 2021-11-23 00:22:06 UTC (rev 12117)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternConsumer.java 2021-11-23 01:26:19 UTC (rev 12118)
@@ -1,143 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * 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.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-/*
- * Known Contributors:
- * Carlos Villegas <ca...@un...> (Original author)
- */
-
-package org.foray.orthography;
-
-import org.foray.orthography.util.PatternParser;
-
-import org.axsl.orthography.OrthographyException;
-
-/**
- * Implementations of this interface take the information parsed by a
- * {@link PatternParser} while it is parsing a Liang-style hyphenation file,
- * and do something useful with it, presumably storing it in a structure that
- * makes it available to other applications.
- */
-public interface PatternConsumer {
-
- /**
- * Sets the character that should be interpreted as the hyphenation
- * character in exceptions.
- * @param hyphenChar The hyphenation character to set.
- * @see #addException(String, int)
- */
- void setHyphenChar(char hyphenChar);
-
- /**
- * Sets the minimum number of characters that should be at the beginning of
- * a line after a hyphenation break.
- * This is different than the similar concept that might be specified by a
- * client application at document-processing time, which is discretionary
- * and for aesthetic purposes.
- * Instead this value is needed to ensure that inaccurate hyphenation
- * breaks are not generated.
- * @param minBefore The minimum number of characters that should be at the
- * beginning of a line after a hyphenation break.
- */
- void setMinBefore(byte minBefore);
-
- /**
- * Sets the minimum number of characters that should be left on a line
- * before a hyphenation break.
- * This is different than the similar concept that might be specified by a
- * client application at document-processing time, which is discretionary
- * and for aesthetic purposes.
- * Instead this value is needed at parse-time to ensure that inaccurate
- * hyphenation breaks are not generated.
- * @param minAfter The minimum number of characters that should be left on a
- * line before a hyphenation break.
- */
- void setMinAfter(byte minAfter);
-
- /**
- * Add a Liang-style character class.
- * Character classes define the valid word characters for hyphenation.
- * If a word contains a character not defined in any of the classes, it is
- * not hyphenated.
- * Character classes also define a way to normalize the characters in order
- * to compare them with the stored patterns.
- * Hyphenation is generally a case-insensitive operation, that is, the
- * Strings "CE", "Ce", "cE", and "ce" should all be treated as equivalent
- * for purposes of making hyphenation decisions.
- * Therefore, pattern files usually use only lower case characters.
- * To mark two characters as equivalent, they are included in the same
- * character class, with the normalized character recorded first in that
- * class.
- * So, for the example above, a class "cC" and another "eE" would ensure
- * that those characters were treated in a case-insensitive way.
- * @param characterClass The character class to add.
- */
- void addClass(String characterClass);
-
- /**
- * Add a Liang-style hyphenation exception.
- * An exception supercedes the result obtained by the algorithm.
- * It is useful in cases where the algorith gives a bad result, in in which
- * the user otherwise wants to provide his own hyphenation.
- * @param exceptionWord The raw word for which the exception is being
- * created.
- * For example, the English pattern dictionary distributed with TeX includes
- * the exception "oblig-a-tory", which is the text expected here.
- * @param qtyMorphing The number of morph exceptions that will be added to
- * this exception word.
- * @see #addMorphException(String, String, String, String)
- */
- void addException(String exceptionWord, int qtyMorphing);
-
- /**
- * Add a morphing hyphenation break to an exception word.
- * A morphing break opportunity is one that changes the spelling of the word
- * if it is selected.
- * A morph exception can only be added to a word that already is recorded
- * as an exception, and for which the "qtyMorphing" is greater than 0.
- * @param exceptionWord The raw word for which the exception is being
- * created.
- * This must be the same word that was used in
- * {@link #addException(String, int)}.
- * @param pre The "pre" portion of the special exception.
- * @param post The "post" portion of the special exception.
- * @param no The "no" portion of the special exception.
- * @throws OrthographyException If {@code exceptionWord} is not found
- * in the exception words.
- */
- void addMorphException(String exceptionWord, String pre, String post,
- String no) throws OrthographyException;
-
- /**
- * Add a Liang-style hyphenation pattern.
- * @param pattern The raw Liang-style pattern to be added, for example
- * ".ab4i".
- */
- void addPattern(String pattern);
-
-}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java 2021-11-23 00:22:06 UTC (rev 12117)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java 2021-11-23 01:26:19 UTC (rev 12118)
@@ -42,6 +42,8 @@
import org.axsl.orthography.OrthographyException;
import org.slf4j.Logger;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.InputStream;
@@ -50,6 +52,8 @@
import java.util.HashMap;
import java.util.Map;
+import javax.xml.parsers.ParserConfigurationException;
+
/**
* <p>An implementation of the Knuth/Liang hyphenation scheme that is part of TeX.
* This scheme has three data components: classes, exceptions, and patterns.
@@ -75,7 +79,7 @@
* took 7694 nodes and the german patterns 10055 nodes, so we are well within
* the 65,000 node limitation."</p>
*/
-public class PatternTree implements PatternConsumer, Serializable {
+public class PatternTree implements Serializable {
/**
* Enumeration of the possible sources of this tree.
@@ -108,18 +112,15 @@
/** The character to be interpreted as the hyphenation character for exceptions that are added. */
private transient char hyphenChar = '-';
- /** The minimum number of characters that should be left on a line before
- * a hyphenation break.
- * @see PatternConsumer#setMinBefore(byte) */
+ /** The minimum number of characters that should be left on a line before a hyphenation break.
+ * @see #setMinBefore(byte) */
private byte minBefore = 0;
- /** The minimum number of characters that should be at the beginning of a
- * line after a hyphenation break.
- * @see PatternConsumer#setMinAfter(byte) */
+ /** The minimum number of characters that should be at the beginning of a line after a hyphenation break.
+ * @see #setMinAfter(byte) */
private byte minAfter = 0;
- /** A map whose key is String patterns, and whose value is an index into
- * {@link #patternValues}. */
+ /** A map whose key is String patterns, and whose value is an index into {@link #patternValues}. */
private TernaryTree patternKeys = new TernaryTree();
/**
@@ -138,7 +139,7 @@
private TernaryTree classes = new TernaryTree();
/** Temporary map to store interletter values during pattern loading. */
- private transient TernaryTree tempInterletterValues;
+ private transient TernaryTree tempInterletterValues = new TernaryTree();
/**
* Constructor.
@@ -183,17 +184,23 @@
public void loadPatterns(final InputStream inputStream, final Logger logger) throws OrthographyException {
this.source = PatternTree.Source.PARSED;
final PatternParser pp = new PatternParser(this);
- this.tempInterletterValues = new TernaryTree();
- pp.parse(inputStream);
+ try {
+ pp.parse(new InputSource(inputStream));
+ } catch (SAXException | ParserConfigurationException | IOException e) {
+ throw new OrthographyException(e);
+ }
// patterns/values should be now in the tree
- // let's optimize a bit
+ optimize();
+ }
+
+ public void optimize() {
this.patternKeys.optimize();
this.patternValues.trimToSize();
this.classes.optimize();
- // get rid of the auxiliary map
+ /* Remove the auxiliary map. */
this.tempInterletterValues = null;
}
@@ -415,14 +422,28 @@
return false;
}
- @Override
- public void addClass(final String chargroup) {
- if (chargroup.length() > 0) {
- final char equivChar = chargroup.charAt(0);
+ /**
+ * Add a Liang-style character class.
+ * Character classes define the valid word characters for hyphenation.
+ * If a word contains a character not defined in any of the classes, it is not hyphenated.
+ * Character classes also define a way to normalize the characters in order to compare them with the stored
+ * patterns.
+ * Hyphenation is generally a case-insensitive operation, that is, the Strings "CE", "Ce", "cE", and "ce" should all
+ * be treated as equivalent for purposes of making hyphenation decisions.
+ * Therefore, pattern files usually use only lower case characters.
+ * To mark two characters as equivalent, they are included in the same character class, with the normalized
+ * character recorded first in that class.
+ * So, for the example above, a class "cC" and another "eE" would ensure that those characters were treated in a
+ * case-insensitive way.
+ * @param characterClass The character class to add.
+ */
+ public void addClass(final String characterClass) {
+ if (characterClass.length() > 0) {
+ final char equivChar = characterClass.charAt(0);
final char[] key = new char[2];
key[1] = 0;
- for (int i = 0; i < chargroup.length(); i++) {
- key[0] = chargroup.charAt(i);
+ for (int i = 0; i < characterClass.length(); i++) {
+ key[0] = characterClass.charAt(i);
final int len = StringUtils.nullTerminatedLength(key, 0);
this.classes.put(key, 0, len, equivChar);
}
@@ -429,19 +450,28 @@
}
}
- @Override
- public void addException(final String hyphenatedWord,
- final int qtyMorphExceptions) {
- if (hyphenatedWord == null) {
+ /**
+ * Add a Liang-style hyphenation exception.
+ * An exception supercedes the result obtained by the algorithm.
+ * It is useful in cases where the algorith gives a bad result, in in which the user otherwise wants to provide his
+ * own hyphenation.
+ * @param exceptionWord The raw word for which the exception is being created.
+ * For example, the English pattern dictionary distributed with TeX includes the exception "oblig-a-tory", which is
+ * the text expected here.
+ * @param qtyMorphExceptions The number of morph exceptions that will be added to this exception word.
+ * @see #addMorphException(String, String, String, String)
+ */
+ public void addException(final String exceptionWord, final int qtyMorphExceptions) {
+ if (exceptionWord == null) {
return;
}
/* Count the number of hyphens in the input. */
int qtyOpportunities = 0;
- for (int i = 0; i < hyphenatedWord.length(); i++) {
- if (hyphenatedWord.charAt(i) == this.hyphenChar
+ for (int i = 0; i < exceptionWord.length(); i++) {
+ if (exceptionWord.charAt(i) == this.hyphenChar
&& i >= this.minBefore
- && i < hyphenatedWord.length() - this.minAfter) {
+ && i < exceptionWord.length() - this.minAfter) {
qtyOpportunities ++;
}
}
@@ -452,10 +482,10 @@
/* Create the points array. */
final byte[] points = new byte[qtyOpportunities];
int index = 0;
- for (int i = 0; i < hyphenatedWord.length(); i++) {
- if (hyphenatedWord.charAt(i) == this.hyphenChar
+ for (int i = 0; i < exceptionWord.length(); i++) {
+ if (exceptionWord.charAt(i) == this.hyphenChar
&& i >= this.minBefore
- && i < hyphenatedWord.length() - this.minAfter) {
+ && i < exceptionWord.length() - this.minAfter) {
/* Subtract the index from the value, because the hyphen
* characters will be */
points[index] = (byte) (i - index);
@@ -472,7 +502,7 @@
/* Normalize the word, create the hyphenation instance, and add both
* to the map of exceptions. */
final String unhyphenatedWord = StringWord.normalizeException(
- hyphenatedWord, this.hyphenChar);
+ exceptionWord, this.hyphenChar);
final StringWord exception;
@@ -484,13 +514,27 @@
this.exceptions.put(unhyphenatedWord, exception);
}
- @Override
+ /**
+ * Add a morphing hyphenation break to an exception word.
+ * A morphing break opportunity is one that changes the spelling of the word if it is selected.
+ * A morph exception can only be added to a word that already is recorded as an exception, and for which the
+ * {@code qtyMorphExceptions} is greater than 0.
+ * @param exceptionWord The raw word for which the exception is being created.
+ * This must be the same word that was used in {@link #addException(String, int)}.
+ * @param pre The "pre" portion of the special exception.
+ * @param post The "post" portion of the special exception.
+ * @param no The "no" portion of the special exception.
+ * @throws OrthographyException If {@code exceptionWord} is not found in the exception words.
+ */
public void addMorphException(final String exceptionWord, final String pre,
final String post, final String no) throws OrthographyException {
/* Implement this. */
}
- @Override
+ /**
+ * Add a Liang-style hyphenation pattern.
+ * @param rawPattern The raw Liang-style pattern to be added, for example ".ab4i".
+ */
public void addPattern(final String rawPattern) {
/* Split the pattern into its raw characters and its inter-letter
* values. */
@@ -558,17 +602,34 @@
return il.toString();
}
- @Override
+ /**
+ * Sets the character that should be interpreted as the hyphenation character in exceptions.
+ * @param hyphenChar The hyphenation character to set.
+ * @see #addException(String, int)
+ */
public void setHyphenChar(final char hyphenChar) {
this.hyphenChar = hyphenChar;
}
- @Override
+ /**
+ * Sets the minimum number of characters that should be left on a line before a hyphenation break.
+ * This is different than the similar concept that might be specified by a client application at
+ * document-processing time, which is discretionary and for aesthetic purposes.
+ * Instead this value is needed at parse-time to ensure that inaccurate hyphenation breaks are not generated.
+ * @param minAfter The minimum number of characters that should be left on a line before a hyphenation break.
+ */
public void setMinAfter(final byte minAfter) {
this.minAfter = minAfter;
}
- @Override
+ /**
+ * Sets the minimum number of characters that should be at the beginning of a line after a hyphenation break.
+ * This is different than the similar concept that might be specified by a client application at
+ * document-processing time, which is discretionary and for aesthetic purposes.
+ * Instead this value is needed to ensure that inaccurate hyphenation breaks are not generated.
+ * @param minBefore The minimum number of characters that should be at the beginning of a line after a hyphenation
+ * break.
+ */
public void setMinBefore(final byte minBefore) {
this.minBefore = minBefore;
}
@@ -593,4 +654,28 @@
this.source = PatternTree.Source.RESOURCES;
}
+ /**
+ * Returns the hyphen character.
+ * @return The hyphen character.
+ */
+ public char getHyphenChar() {
+ return hyphenChar;
+ }
+
+ /**
+ * Returns the minBefore value.
+ * @return The minBefore value.
+ */
+ public byte getMinBefore() {
+ return this.minBefore;
+ }
+
+ /**
+ * Returns the minAfter value.
+ * @return The minAfter value.
+ */
+ public byte getMinAfter() {
+ return this.minAfter;
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-23 00:22:06 UTC (rev 12117)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-23 01:26:19 UTC (rev 12118)
@@ -34,7 +34,7 @@
package org.foray.orthography.util;
import org.foray.common.xml.SaxParser;
-import org.foray.orthography.PatternConsumer;
+import org.foray.orthography.PatternTree;
import org.axsl.orthography.OrthographyException;
@@ -45,7 +45,6 @@
import org.xml.sax.XMLReader;
import java.io.IOException;
-import java.io.InputStream;
import javax.xml.parsers.ParserConfigurationException;
@@ -52,7 +51,7 @@
/**
* A SAX document handler to read and parse hyphenation patterns from an XML file.
*/
-public class PatternParser extends SaxParser<PatternConsumer> {
+public class PatternParser extends SaxParser<PatternTree> {
/** Constant indicating that the current element is "classes". */
static final int ELEM_CLASSES = 1;
@@ -66,67 +65,38 @@
/** Constant indicating that the current element is "hyphen". */
static final int ELEM_HYPHEN = 4;
- /** The SAX parser. */
- private XMLReader parser;
-
/** The current element being parsed. */
private int currElement;
- /** The PatternConsumer implementation. */
- private PatternConsumer consumer;
+ /** The object being built by this parser. */
+ private PatternTree patternTree;
/** The current token being parsed. */
private StringBuilder token;
- /** The last error message generated. Used to enhance the messages that
- * are returned with exceptions. */
- private String errMsg;
-
/**
* Constructor.
- * @param consumer The pattern consumer implementation that will accept the data created by this parser.
+ * @param patternTree The pattern tree that is being built by this parser.
* @throws OrthographyException For errors during construction.
*/
- public PatternParser(final PatternConsumer consumer) throws OrthographyException {
- if (consumer == null) {
+ public PatternParser(final PatternTree patternTree) throws OrthographyException {
+ if (patternTree == null) {
throw new NullPointerException("PatternConsumer may not be null.");
}
- this.consumer = consumer;
+ this.patternTree = patternTree;
this.token = new StringBuilder();
- try {
- this.parser = createSax2Parser(false, false, false, null, false);
- } catch (final SAXException | ParserConfigurationException e) {
- throw new OrthographyException(e);
- }
}
@Override
- public PatternConsumer parse(final InputSource inputSource) {
+ public PatternTree parse(final InputSource inputSource)
+ throws SAXException, ParserConfigurationException, IOException {
+ final XMLReader parser = createSax2Parser(false, false, false, null, false);
/* TODO: If PatternConsumer is not needed, use the implementation here instead. */
- parse(inputSource);
- return this.consumer;
+ parser.parse(inputSource);
+ return this.patternTree;
}
/**
- * Parses a given input stream, using the PatternConsumer to consume the data retrieved during the parse.
- * @param inputStream The input stream to parse.
- * @throws OrthographyException For errors during parsing.
- */
- public void parse(final InputStream inputStream) throws OrthographyException {
- final InputSource uri = new InputSource(inputStream);
-
- try {
- this.parser.parse(uri);
- } catch (final SAXException e) {
- throw new OrthographyException(this.errMsg);
- } catch (final IOException e) {
- throw new OrthographyException(e.getMessage());
- } catch (final NullPointerException e) {
- throw new OrthographyException("SAX parser not available");
- }
- }
-
- /**
* Returns the next token from the buffer.
* @param chars The buffer which is being parsed.
* @return The next token.
@@ -175,25 +145,45 @@
}
@Override
- public void startElement(final String uri, final String local,
- final String raw, final Attributes attrs) {
- if (local.equals("hyphen-char")) {
+ public void startElement(final String uri, final String local, final String raw, final Attributes attrs) {
+ switch(raw) {
+ case "axsl-hyphenation": {
+ break;
+ }
+ case "hyphen-char": {
final String h = attrs.getValue("value");
if (h != null && h.length() == 1) {
- this.consumer.setHyphenChar(h.charAt(0));
+ this.patternTree.setHyphenChar(h.charAt(0));
}
- } else if (local.equals("classes")) {
+ break;
+ }
+ case "hyphen-min": {
+ final String beforeString = attrs.getValue("before");
+ final String afterString = attrs.getValue("after");
+ final byte before = Byte.parseByte(beforeString);
+ final byte after = Byte.parseByte(afterString);
+ this.patternTree.setMinBefore(before);
+ this.patternTree.setMinAfter(after);
+ break;
+ }
+ case "classes": {
this.currElement = PatternParser.ELEM_CLASSES;
- } else if (local.equals("patterns")) {
+ break;
+ }
+ case "patterns": {
this.currElement = PatternParser.ELEM_PATTERNS;
- } else if (local.equals("exceptions")) {
+ break;
+ }
+ case "exceptions": {
this.currElement = PatternParser.ELEM_EXCEPTIONS;
- } else if (local.equals("hyphen")) {
+ break;
+ }
+ case "hyphen": {
if (this.token.length() > 0) {
- this.consumer.addException(this.token.toString(), 0);
+ this.patternTree.addException(this.token.toString(), 0);
}
try {
- this.consumer.addMorphException(attrs.getValue("no"),
+ this.patternTree.addMorphException(attrs.getValue("no"),
attrs.getValue("pre"), attrs.getValue("post"),
attrs.getValue("no"));
} catch (final OrthographyException e) {
@@ -200,7 +190,12 @@
this.error(new SAXParseException("", null, e));
}
this.currElement = PatternParser.ELEM_HYPHEN;
+ break;
}
+ default: {
+ throw new IllegalStateException("Unknown element started: " + local + ", " + getLocationString());
+ }
+ }
this.token.setLength(0);
}
@@ -211,13 +206,13 @@
final String word = this.token.toString();
switch (this.currElement) {
case PatternParser.ELEM_CLASSES:
- this.consumer.addClass(word);
+ this.patternTree.addClass(word);
break;
case PatternParser.ELEM_EXCEPTIONS:
- this.consumer.addException(word, 0);
+ this.patternTree.addException(word, 0);
break;
case PatternParser.ELEM_PATTERNS:
- this.consumer.addPattern(word);
+ this.patternTree.addPattern(word);
break;
case PatternParser.ELEM_HYPHEN:
break;
@@ -242,13 +237,13 @@
while (word != null) {
switch (this.currElement) {
case PatternParser.ELEM_CLASSES:
- this.consumer.addClass(word);
+ this.patternTree.addClass(word);
break;
case PatternParser.ELEM_EXCEPTIONS:
- this.consumer.addException(word, 0);
+ this.patternTree.addException(word, 0);
break;
case PatternParser.ELEM_PATTERNS:
- this.consumer.addPattern(word);
+ this.patternTree.addPattern(word);
break;
}
word = readToken(chars);
Added: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/util/PatternParserTests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/util/PatternParserTests.java (rev 0)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/util/PatternParserTests.java 2021-11-23 01:26:19 UTC (rev 12118)
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * 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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.orthography.util;
+
+import org.foray.orthography.PatternTree;
+
+import org.axsl.orthography.OrthographyException;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+/**
+ * JUnit test class for the class {@link PatternParser}.
+ */
+public class PatternParserTests {
+
+ /** A raw patterns file snippet for testing. */
+ private String input =
+ "<axsl-hyphenation>\n"
+ + "<hyphen-char value=\"-\"/>\n"
+ + "<hyphen-min before=\"3\" after=\"2\"/>\n"
+ + "<classes>\n"
+ + "aA\n"
+ + "bB\n"
+ + "cC\n"
+ + "</classes>\n"
+ + "\n"
+ + "<exceptions>\n"
+ + "as-so-ciate\n"
+ + "as-so-ciates\n"
+ + "</exceptions>\n"
+ + "\n"
+ + "<patterns>\n"
+ + ".ab4i\n"
+ + ".ab3ol\n"
+ + ".ace4\n"
+ + ".acet3\n"
+ + ".ach4\n"
+ + ".ac5tiva\n"
+ + ".ad4din\n"
+ + ".ad3e\n"
+ + ".ad3o\n"
+ + ".ae5d\n"
+ + ".aer3i\n"
+ + "</patterns>"
+ + "</axsl-hyphenation>";
+
+ /**
+ * Tests various Strings against the method
+ * {@link WordListCreator#containsNonWord(String)}.
+ * @throws OrthographyException Not expected here.
+ * @throws IOException
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ */
+ @Test
+ public void basicParserTest() throws OrthographyException, SAXException, ParserConfigurationException, IOException {
+ final PatternTree patternTree = new PatternTree();
+ final Reader reader = new StringReader(input);
+ final InputSource inputSource = new InputSource(reader);
+ final PatternParser out = new PatternParser(patternTree);
+ out.parse(inputSource);
+ Assert.assertEquals('-', patternTree.getHyphenChar());
+ Assert.assertEquals(3, patternTree.getMinBefore());
+ Assert.assertEquals(2, patternTree.getMinAfter());
+
+ /* TODO: Add more assertions here. */
+ }
+
+}
Property changes on: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/util/PatternParserTests.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-23 00:22:08
|
Revision: 12117
http://sourceforge.net/p/foray/code/12117
Author: victormote
Date: 2021-11-23 00:22:06 +0000 (Tue, 23 Nov 2021)
Log Message:
-----------
Add method returning a URL.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/resource/ResourceLocation.java
trunk/foray/foray-common/src/main/java/org/foray/common/resource/ResourceLocationClasspath.java
trunk/foray/foray-common/src/main/java/org/foray/common/resource/ResourceLocationUrl.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/resource/ResourceLocation.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/resource/ResourceLocation.java 2021-11-22 23:22:01 UTC (rev 12116)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/resource/ResourceLocation.java 2021-11-23 00:22:06 UTC (rev 12117)
@@ -29,6 +29,7 @@
package org.foray.common.resource;
import java.io.InputStream;
+import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -124,4 +125,10 @@
return getLocationDescription();
}
+ /**
+ * Returns this location as a URL.
+ * @return This location as a URL.
+ */
+ public abstract URL toUrl();
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/resource/ResourceLocationClasspath.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/resource/ResourceLocationClasspath.java 2021-11-22 23:22:01 UTC (rev 12116)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/resource/ResourceLocationClasspath.java 2021-11-23 00:22:06 UTC (rev 12117)
@@ -31,6 +31,8 @@
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
/**
* Describes the location of a resource that is in the classpath.
@@ -101,4 +103,13 @@
return is;
}
+ @Override
+ public URL toUrl() {
+ try {
+ return new URL("classpath://" + this.path);
+ } catch (final MalformedURLException e) {
+ return null;
+ }
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/resource/ResourceLocationUrl.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/resource/ResourceLocationUrl.java 2021-11-22 23:22:01 UTC (rev 12116)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/resource/ResourceLocationUrl.java 2021-11-23 00:22:06 UTC (rev 12117)
@@ -85,4 +85,9 @@
return is;
}
+ @Override
+ public URL toUrl() {
+ return this.url;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-22 23:22:04
|
Revision: 12116
http://sourceforge.net/p/foray/code/12116
Author: victormote
Date: 2021-11-22 23:22:01 +0000 (Mon, 22 Nov 2021)
Log Message:
-----------
More standardization of SAX parsers.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.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/OrthographyParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
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-22 22:04:38 UTC (rev 12115)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java 2021-11-22 23:22:01 UTC (rev 12116)
@@ -59,6 +59,9 @@
/** Format string for formatting the current location. */
private static final String LOCATION_FORMAT_STRING = "(%1s:%2$d:%3$d)";
+ /** Format string for formatting the current location. */
+ private static final String SHORT_LOCATION_FORMAT_STRING = "(%1$d:%2$d)";
+
/** Constant used to initialize string builders. */
private static final int MAX_EXPECTED_TEXT_LENGTH = 4096;
@@ -79,6 +82,10 @@
/** Receives content of text nodes. */
private StringBuilder textAccumulator = new StringBuilder(MAX_EXPECTED_TEXT_LENGTH);
+ /** Flag indicating whether text parsing is active. Some elements in some parsers contain text that should not be
+ * accumulated. */
+ private boolean textParsingActive = true;
+
/**
* Parses an input document and returns the object that was created.
* @param inputSource The input document.
@@ -141,6 +148,15 @@
}
/**
+ * Returns the line and column number of the current location in the input document as a formatted string.
+ * @return The line and column number of the current location in the input document as a formatted string.
+ */
+ protected String getShortLocationString() {
+ return String.format(SHORT_LOCATION_FORMAT_STRING, this.locator.getLineNumber(),
+ this.locator.getColumnNumber());
+ }
+
+ /**
* Creates a SAX2 parser.
* @param validate Indicates whether the parser should validate the document as it parses.
* @param namespaceAware Indicates whether the parser should be namespace-aware.
@@ -261,7 +277,9 @@
@Override
public void characters(final char[] chars, final int start, final int length) throws SAXException {
- this.textAccumulator.append(chars, start, length);
+ if (this.textParsingActive) {
+ this.textAccumulator.append(chars, start, length);
+ }
}
/**
@@ -297,4 +315,13 @@
throw new SAXException(ex);
}
+ /**
+ * Sets or unsets whether text parsing is active.
+ * If not active, the text will not be accumulated.
+ * @param isActive The new value for text parsing active.
+ */
+ public void setTextParsingActive(final boolean isActive) {
+ this.textParsingActive = isActive;
+ }
+
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java 2021-11-22 22:04:38 UTC (rev 12115)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java 2021-11-22 23:22:01 UTC (rev 12116)
@@ -684,7 +684,7 @@
private void readFontConfig(final InputStream inputStream) throws FontException {
final InputSource source = new InputSource(inputStream);
final FontConfigParser parser =
- new FontConfigParser(this, source);
+ new FontConfigParser(this);
try {
parser.parse(source);
} catch (IOException | ParserConfigurationException | SAXException e) {
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java 2021-11-22 22:04:38 UTC (rev 12115)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java 2021-11-22 23:22:01 UTC (rev 12116)
@@ -41,7 +41,6 @@
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
@@ -117,9 +116,6 @@
* axsl-font-config element. */
private String parsedRootEmbed;
- /** The InputSource encapsulating the configuration file. */
- private InputSource filename;
-
/** The parent FontServer. */
private FontServer4a fontServer;
@@ -128,10 +124,6 @@
* that should be transformed to. */
private Map<String, String> parameters = new HashMap<String, String>();
- /** The XML parser's Locator instance, used to indicate line and column
- * numbers in user messages. */
- private Locator locator;
-
/** Map of GlyphList instances that have already been registered.
* The key is a String with the GlyphList name, and the value is the GlyphList instance. */
private Map<String, GlyphList> glyphListMap = new HashMap<String, GlyphList>();
@@ -144,13 +136,9 @@
/**
* Constructor.
* @param server The parent font server.
- * @param filename The file which contains the configuration information
- * to be parsed.
*/
- public FontConfigParser(final FontServer4a server,
- final InputSource filename) {
+ public FontConfigParser(final FontServer4a server) {
this.fontServer = server;
- this.filename = filename;
try {
this.currentXMLBase = UrlFactory.createURL("file", null, ".");
} catch (final MalformedURLException e) {
@@ -163,7 +151,7 @@
@Override
public Object parse(final InputSource inputSource) throws IOException, ParserConfigurationException, SAXException {
final XMLReader parser = createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver(), false);
- parser.parse(this.filename);
+ parser.parse(inputSource);
return null;
}
@@ -579,10 +567,6 @@
}
}
- /**
- * {@inheritDoc}
- * Wraps up parsing for elements that need to be finalized.
- */
@Override
public void endElement(final String uri, final String localName,
final String qName) {
@@ -809,14 +793,6 @@
}
/**
- * Sets the document locator for this parser.
- * @param locator The new locator.
- */
- public void setDocumentLocator(final Locator locator) {
- this.locator = locator;
- }
-
- /**
* Logs a warning to the logger.
* @param message The warning message.
*/
@@ -839,12 +815,7 @@
* @return The formatted context message.
*/
private String getContextMessage() {
- if (this.locator == null) {
- return null;
- }
- return " Context: " + this.locator.getSystemId() + "\n"
- + " (Line " + this.locator.getLineNumber() + ", Column "
- + this.locator.getColumnNumber() + ")";
+ return " Context: " + getLocationString();
}
/**
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java 2021-11-22 22:04:38 UTC (rev 12115)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java 2021-11-22 23:22:01 UTC (rev 12116)
@@ -108,7 +108,7 @@
}
final InputSource inputSource = new InputSource(inputStream);
- final OrthographyParser parser = new OrthographyParser(this, inputSource);
+ final OrthographyParser parser = new OrthographyParser(this);
try {
parser.parse(inputSource);
} catch (IOException | SAXException | ParserConfigurationException 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-22 22:04:38 UTC (rev 12115)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/NatLangParser.java 2021-11-22 23:22:01 UTC (rev 12116)
@@ -54,14 +54,11 @@
/** The natural language instance being parsed. */
private NaturalLanguage nl;
- /** The SAX parser. */
- private XMLReader parser;
-
@Override
public NaturalLanguage parse(final InputSource inputSource)
throws IOException, SAXException, ParserConfigurationException {
- this.parser = createSax2Parser(false, true, true, AxslDtdUtil.getEntityResolver(), false);
- this.parser.parse(inputSource);
+ final XMLReader parser = createSax2Parser(false, true, true, AxslDtdUtil.getEntityResolver(), false);
+ parser.parse(inputSource);
return this.nl;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java 2021-11-22 22:04:38 UTC (rev 12115)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java 2021-11-22 23:22:01 UTC (rev 12116)
@@ -135,9 +135,6 @@
private Map<String, HyphenationPatternsResource> hyphenationPatterns =
new HashMap<String, HyphenationPatternsResource>();
- /** The InputSource encapsulating the configuration file. */
- private InputSource filename;
-
/** The hyphenation server receiving the parsed information. */
private OrthographyServer4a hyphenationServer;
@@ -147,12 +144,9 @@
/**
* Constructor.
* @param server The hyphenation server which will capture the information from the parsed configuration.
- * @param filename The file which contains the configuration information
- * to be parsed.
*/
- public OrthographyParser(final OrthographyServer4a server, final InputSource filename) {
+ public OrthographyParser(final OrthographyServer4a server) {
this.hyphenationServer = server;
- this.filename = filename;
}
@Override
@@ -159,7 +153,7 @@
public Orthography4a parse(final InputSource inputSource)
throws IOException, SAXException, ParserConfigurationException {
final XMLReader parser = createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver(), false);
- parser.parse(this.filename);
+ parser.parse(inputSource);
return this.currentOrthographyConfig;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-22 22:04:38 UTC (rev 12115)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-22 23:22:01 UTC (rev 12116)
@@ -33,7 +33,6 @@
import org.foray.common.i18n.Script4a;
import org.foray.common.i18n.WritingSystem4a;
import org.foray.common.primitive.ObjectUtils;
-import org.foray.common.primitive.StringUtils;
import org.foray.common.primitive.XmlUtils;
import org.foray.common.xml.SaxParser;
import org.foray.orthography.Orthography4a;
@@ -56,7 +55,6 @@
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
@@ -130,22 +128,10 @@
/** Command-line return status constant indicating that there was an error parsing the input file. */
public static final byte STATUS_PARSING_ERROR = 3;
- /** Format string for formatting the current location. */
- private static final String LOCATION_FORMAT_STRING = "(%1$d:%2$d)";
-
/** The output stream to which the output should be sent. */
private PrintStream output;
- /** The locator instance for identifying the document, line, and column
- * number of specific elements. */
- private Locator locator;
- /** Flag indicating whether text parsing is active. Some elements contain text that should not be accumulated. */
- private boolean textParsingActive;
-
- /** A reusable buffer used to accumulate the parsed text content. */
- private StringBuilder charBuffer = new StringBuilder();
-
/** The element stack. */
private Stack<Element> elementStack = new Stack<Element>();
@@ -214,7 +200,7 @@
@Override
public void startDocument() throws SAXException {
- this.textParsingActive = true;
+ setTextParsingActive(true);
}
@@ -225,11 +211,6 @@
@Override
- public void setDocumentLocator(final Locator locator) {
- this.locator = locator;
- }
-
- @Override
public void startElement(final String uri, final String localName, final String qName, final Attributes attributes)
throws SAXException {
/* Some elements, having no content, can be placed in the middle of a word, making it look like that word is
@@ -256,7 +237,7 @@
if (languageAttr == null) {
if (this.currentOrthographyConfig == null) {
- this.output.println("Orthography not specified. " + this.locationString());
+ this.output.println("Orthography not specified. " + getLocationString());
}
} else {
/* Is there a country code? */
@@ -279,7 +260,7 @@
final String message = String.format(
"Orthography not found. Language: %1$s, Country: %2$s, Script: %3$s ", languageString,
countryString, script.getAlphaCode());
- this.output.println(message + locationString());
+ this.output.println(message + getLocationString());
} else {
final Orthography4a config = this.server.getOrthography(element.writingSystem);
if (config == null) {
@@ -286,7 +267,7 @@
final String message = String.format(
"Unconfigured orthography. Language: %1$s, Country: %2$s, Script: %3$s ",
languageString, countryString, script.getAlphaCode());
- this.output.println(message + locationString());
+ this.output.println(message + getLocationString());
} else {
element.orthographyConfig = config;
}
@@ -312,14 +293,11 @@
List<CharSequence> words = null;
if (this.currentOrthographyConfig != null) {
- words = this.currentOrthographyConfig.getLexer().tokenize(this.charBuffer);
+ words = this.currentOrthographyConfig.getLexer().tokenize(getAndClearText());
}
checkWords(words);
- /* Clear the character buffer. */
- StringUtils.clear(this.charBuffer);
-
/* This element should match the top of the element stack. Pop it. */
if (element.matches(uri, localName, qName)) {
this.elementStack.pop();
@@ -340,14 +318,6 @@
/**
- * Returns the current location in the input document as a formatted string.
- * @return The current location in the input document as a formatted string.
- */
- private String locationString() {
- return String.format(LOCATION_FORMAT_STRING, this.locator.getLineNumber(), this.locator.getColumnNumber());
- }
-
- /**
* Spell-check each word in a sequence of words.
* @param words The words to be checked.
*/
@@ -383,17 +353,10 @@
return;
}
- this.output.println("Not found: " + word + " " + locationString());
+ this.output.println("Not found: " + word + " " + getShortLocationString());
this.notFoundCounter ++;
}
- @Override
- public void characters(final char[] buffer, final int offset, final int length) {
- if (this.textParsingActive) {
- this.charBuffer.append(buffer, offset, length);
- }
- }
-
/**
* Returns the command-line options for the {@link #main(String[])} method.
* @return Command-line options.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-22 22:04:42
|
Revision: 12115
http://sourceforge.net/p/foray/code/12115
Author: victormote
Date: 2021-11-22 22:04:38 +0000 (Mon, 22 Nov 2021)
Log Message:
-----------
More standardization of SAX 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/primitive/XmlUtils.java
trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java
trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.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/OrthographyParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/ValidateChars.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.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-22 20:09:48 UTC (rev 12114)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java 2021-11-22 22:04:38 UTC (rev 12115)
@@ -137,7 +137,7 @@
final InputSource foInputSource = new InputSource(foInputStream);
final XMLReader xmlReader;
try {
- xmlReader = foTreeBuilder.createSax2Parser(false, false, false, null);
+ xmlReader = foTreeBuilder.createSax2Parser(false, false, false, null, false);
} catch (final SAXException | ParserConfigurationException e) {
throw new ForayException(e);
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/primitive/XmlUtils.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/primitive/XmlUtils.java 2021-11-22 20:09:48 UTC (rev 12114)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/primitive/XmlUtils.java 2021-11-22 22:04:38 UTC (rev 12115)
@@ -30,6 +30,7 @@
import org.apache.xml.resolver.CatalogManager;
import org.apache.xml.resolver.tools.CatalogResolver;
+import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import javax.xml.stream.XMLResolver;
@@ -127,6 +128,16 @@
}
/**
+ * Creates an EntityResolver.
+ * @param catalog The catalog which should be encapsulated in an EntityResolver.
+ * @return The created EntityResolver.
+ */
+ public static EntityResolver getEntityResolver(final String catalog) {
+ final String[] catalogs = new String[] {catalog};
+ return XmlUtils.getEntityResolver(catalogs);
+ }
+
+ /**
* Creates an EntityResolver for one or more XML catalogs.
* @param catalogs The array of URIs indicating where the XML catalogs are located.
* @return The created EntityResolver.
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-22 20:09:48 UTC (rev 12114)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java 2021-11-22 22:04:38 UTC (rev 12115)
@@ -146,12 +146,19 @@
* @param namespaceAware Indicates whether the parser should be namespace-aware.
* @param namespacePrefixes Indicates wehther the parser should process namespace prefixes.
* @param entityResolver Specifies the entity resolver, if any that should be used.
+ * @param notifyCharRefs Indicates whether the "notify-char-refs" feature should be turned on.
+ * This appears to be a Xerces-only feature.
+ * This feature, or something like it is <em>very</em> important for cases where we wish to pass content through
+ * <em>absolutely unchanged.</em>
+ * Without it, character entities get silently transformed into characters without notification.
+ * When we are notified of this transformation, we have the option of ignoring the transformed characters and using
+ * the character entities instead.
* @return The newly-created SAX2 parser.
* @throws SAXException For errors creating the parser.
* @throws ParserConfigurationException For errors configuring the parser.
*/
public XMLReader createSax2Parser(final boolean validate, final boolean namespaceAware,
- final boolean namespacePrefixes, final EntityResolver entityResolver)
+ final boolean namespacePrefixes, final EntityResolver entityResolver, final boolean notifyCharRefs)
throws SAXException, ParserConfigurationException {
final SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
spf.setNamespaceAware(namespaceAware);
@@ -184,6 +191,12 @@
getLogger().error("Parser does not support Declaration Handler.");
}
+ if (notifyCharRefs) {
+ /* Let any exceptions thrown here bubble up. If this feature has been requested, it is a fatal error if it
+ * is not available. */
+ xmlReader.setFeature("http://apache.org/xml/features/scanner/notify-char-refs", true);
+ }
+
xmlReader.setContentHandler(this);
xmlReader.setErrorHandler(this);
@@ -261,6 +274,14 @@
return content;
}
+ /**
+ * Appends text to the text buffer.
+ * @param chars The text to append to the buffer.
+ */
+ public void appendText(final CharSequence chars) {
+ this.textAccumulator.append(chars);
+ }
+
@Override
public void warning(final SAXParseException ex) {
this.logger.warn(getLocationString() + ": " + ex.getMessage());
Modified: trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java
===================================================================
--- trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java 2021-11-22 20:09:48 UTC (rev 12114)
+++ trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java 2021-11-22 22:04:38 UTC (rev 12115)
@@ -130,7 +130,7 @@
return null;
}
};
- final XMLReader parser = createSax2Parser(true, true, true, resolver);
+ final XMLReader parser = createSax2Parser(true, true, true, resolver, false);
parser.parse(inputSource);
return null;
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java 2021-11-22 20:09:48 UTC (rev 12114)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java 2021-11-22 22:04:38 UTC (rev 12115)
@@ -162,7 +162,7 @@
@Override
public Object parse(final InputSource inputSource) throws IOException, ParserConfigurationException, SAXException {
- final XMLReader parser = createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver());
+ final XMLReader parser = createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver(), false);
parser.parse(this.filename);
return null;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-22 20:09:48 UTC (rev 12114)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-22 22:04:38 UTC (rev 12115)
@@ -141,7 +141,7 @@
throws IOException, SAXException, ParserConfigurationException {
getLogger().info("Begin dictionary word list parsing: " + inputSource.getSystemId());
- final XMLReader parser = this.createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver());
+ final XMLReader parser = this.createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver(), false);
if (parser != null) {
parser.parse(inputSource);
}
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-22 20:09:48 UTC (rev 12114)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/NatLangParser.java 2021-11-22 22:04:38 UTC (rev 12115)
@@ -60,7 +60,7 @@
@Override
public NaturalLanguage parse(final InputSource inputSource)
throws IOException, SAXException, ParserConfigurationException {
- this.parser = createSax2Parser(false, true, true, AxslDtdUtil.getEntityResolver());
+ this.parser = createSax2Parser(false, true, true, AxslDtdUtil.getEntityResolver(), false);
this.parser.parse(inputSource);
return this.nl;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java 2021-11-22 20:09:48 UTC (rev 12114)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java 2021-11-22 22:04:38 UTC (rev 12115)
@@ -158,7 +158,7 @@
@Override
public Orthography4a parse(final InputSource inputSource)
throws IOException, SAXException, ParserConfigurationException {
- final XMLReader parser = createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver());
+ final XMLReader parser = createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver(), false);
parser.parse(this.filename);
return this.currentOrthographyConfig;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-22 20:09:48 UTC (rev 12114)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-22 22:04:38 UTC (rev 12115)
@@ -94,7 +94,7 @@
this.consumer = consumer;
this.token = new StringBuilder();
try {
- this.parser = createSax2Parser(false, false, false, null);
+ this.parser = createSax2Parser(false, false, false, null, false);
} catch (final SAXException | ParserConfigurationException e) {
throw new OrthographyException(e);
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-22 20:09:48 UTC (rev 12114)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-22 22:04:38 UTC (rev 12115)
@@ -199,7 +199,7 @@
@Override
public Object parse(final InputSource inputSource) throws IOException, ParserConfigurationException, SAXException {
/* Skip validation. That should be handled upstream of this process. */
- final XMLReader parser = createSax2Parser(false, true, true, null);
+ final XMLReader parser = createSax2Parser(false, true, true, null, false);
parser.parse(inputSource);
cleanup();
return null;
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/ValidateChars.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/ValidateChars.java 2021-11-22 20:09:48 UTC (rev 12114)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/ValidateChars.java 2021-11-22 22:04:38 UTC (rev 12115)
@@ -29,6 +29,7 @@
package org.foray.orthography.util;
import org.foray.common.i18n.Language4a;
+import org.foray.common.primitive.XmlUtils;
import org.foray.common.url.UrlFactory;
import org.foray.common.xml.SaxParser;
import org.foray.orthography.OrthographyServer4a;
@@ -37,17 +38,12 @@
import org.axsl.common.i18n.Language;
import org.axsl.orthography.OrthographyException;
-import org.apache.xml.resolver.CatalogManager;
-import org.apache.xml.resolver.tools.CatalogResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import java.io.BufferedInputStream;
@@ -60,7 +56,6 @@
import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParserFactory;
/**
* Command-line application that reads an XML file and checks its content
@@ -89,20 +84,10 @@
/** The maximum number of command-line arguments. */
private static final byte MAX_CL_ARGUMENTS = 4;
- /** The input source to be pretty-printed. */
- private InputSource input;
-
- /** The locator instance for identifying the document, line, and column
- * number of specific elements. */
- private Locator locator;
-
/** The entity resolver to be used for resolving DTD catalogs and other
* entities. */
private EntityResolver entityResolver;
- /** A reusable buffer. */
- private StringBuilder charBuffer = new StringBuilder();
-
/** The String languageCode passed in the constructor. */
private String languageCode;
@@ -126,106 +111,22 @@
*/
public ValidateChars(final OrthographyServer4a server, final String catalog, final String languageCode) {
this.server = server;
- this.entityResolver = getEntityResolver(catalog);
+ this.entityResolver = XmlUtils.getEntityResolver(catalog);
this.languageCode = languageCode;
this.iso639 = Language4a.findFromAlpha(languageCode);
+ if (this.iso639 == null) {
+ throw new IllegalArgumentException("Not a valid ISO-639 code: " + this.languageCode);
+ }
}
@Override
public Object parse(final InputSource input) throws IOException, SAXException, ParserConfigurationException {
- if (this.iso639 == null) {
- logError("Not a valid ISO-639 code: " + this.languageCode);
- return null;
- }
- final XMLReader parser = createParser();
-
- /* Bind the LexicalHandler to the XMLReader if possible. */
- try {
- parser.setProperty("http://xml.org/sax/properties/lexical-handler",
- this);
- } catch (final SAXNotSupportedException e1) {
- logError("Parser does not support LexicalHandler.");
- }
-
- /* Bind the DeclHandler to the XMLReader if possible. */
- try {
- parser.setProperty("http://xml.org/sax/properties/"
- + "declaration-handler", this);
- } catch (final SAXNotSupportedException e) {
- logError("Parser does not support Declaration Handler.");
- }
-
- /* Turn on namespace-prefixes so that we get the namespace declarations
- * returned with other attributes and can therefore write them out
- * along with them. */
- try {
- parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
- true);
- } catch (final SAXNotRecognizedException e1) {
- logError("Parser does not recognize the \"namespace-prefixes\" "
- + "feature.");
- } catch (final SAXNotSupportedException e1) {
- logError("Parser unable to supply namespace-prefixes.");
- }
-
- /* Turn on validation if it is available. */
- try {
- parser.setFeature("http://xml.org/sax/features/validation", true);
- } catch (final SAXNotRecognizedException e1) {
- logError("Parser does not recognize the \"validation\" feature.");
- } catch (final SAXNotSupportedException e1) {
- logError("Parser unable to validate.");
- }
-
- /* Turn on "notify-char-refs" feature.
- * Sadly, this only works with Xerces.
- * This feature, or something like it is very important.
- * Without it, character entities get transformed into characters
- * without notification.
- * When notified, we can (and do) ignore the transformed characters
- * and use the character entities instead.
- * We do NOT want to change the user's content. */
- try {
- parser.setFeature("http://apache.org/xml/features/scanner/"
- + "notify-char-refs", true);
- } catch (final SAXNotRecognizedException e) {
- /* Make this a fatal error. */
- logError("Parser cannot report character entities. Aborting.");
- return null;
- } catch (final SAXNotSupportedException e) {
- /* Make this a fatal error. */
- logError("Parser cannot report character entities. Aborting.");
- return null;
- }
- parser.setContentHandler(this);
- parser.parse(this.input);
+ final XMLReader parser = createSax2Parser(true, true, true, this.entityResolver, true);
+ parser.parse(input);
return null;
}
- /**
- * Creates a SAX parser.
- * @return The created SAX parser.
- * @throws SAXException For error creating parser.
- * @throws ParserConfigurationException For error configuring parser.
- */
- public XMLReader createParser() throws SAXException,
- ParserConfigurationException {
- final SAXParserFactory spf =
- javax.xml.parsers.SAXParserFactory.newInstance();
- spf.setNamespaceAware(true);
- final XMLReader xmlReader = spf.newSAXParser().getXMLReader();
- if (this.entityResolver != null) {
- xmlReader.setEntityResolver(this.entityResolver);
- }
- return xmlReader;
- }
-
@Override
- public void setDocumentLocator(final Locator locator) {
- this.locator = locator;
- }
-
- @Override
public void startDocument() {
}
@@ -236,7 +137,7 @@
@Override
public void startElement(final String uri, final String local,
final String qName, final Attributes attributes) {
- final String content = flushCharacters();
+ final String content = getAndClearText();
this.checkContent(content);
}
@@ -243,60 +144,11 @@
@Override
public void endElement(final String uri, final String local,
final String qName) {
- final String content = flushCharacters();
+ final String content = getAndClearText();
this.checkContent(content);
}
- @Override
- public void characters(final char[] buffer, final int offset,
- final int length) {
- this.charBuffer.append(buffer, offset, length);
- }
-
/**
- * Returns the characters in the buffer as a String and resets the buffer.
- * @return The contents of the buffer as a String.
- */
- private String flushCharacters() {
- if (this.charBuffer.length() < 1) {
- return null;
- }
- final String returnString = this.charBuffer.toString();
- this.charBuffer.setLength(0);
- return returnString;
- }
-
- /**
- * Creates an EntityResolver.
- * @param catalog The catalog which should be encapsulated in an
- * EntityResolver.
- * @return The created EntityResolver.
- */
- private EntityResolver getEntityResolver(final String catalog) {
- if (catalog == null) {
- return null;
- }
- final CatalogManager manager = new CatalogManager();
- manager.setPreferPublic(true);
- manager.setCatalogFiles(catalog);
- final CatalogResolver resolver = new CatalogResolver(manager);
- return resolver;
- }
-
- /**
- * Convenience method to log an error.
- * @param message The message to be logged.
- */
- private void logError(final String message) {
- if (this.locator != null) {
- getLogger().error(this.locator.getSystemId() + ":"
- + this.locator.getLineNumber() + ":"
- + this.locator.getColumnNumber() + "\n ");
- }
- getLogger().error(message + "\n");
- }
-
- /**
* Examines the content character-by-character, logging any invalid content
* found.
* @param content The current content String to be processed.
@@ -308,7 +160,7 @@
final NaturalLanguage nl = this.server.getNaturalLanguage(
this.iso639);
if (nl == null) {
- logError("Cannot get NaturalLanguage instance for: "
+ getLogger().error("Cannot get NaturalLanguage instance for: "
+ this.iso639.getEnglishName());
return;
}
@@ -316,7 +168,7 @@
if (invalidChar < 0) {
return;
}
- this.logError("Invalid char at index: " + invalidChar);
+ this.getLogger().error("Invalid char at index: " + invalidChar);
}
/**
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java 2021-11-22 20:09:48 UTC (rev 12114)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java 2021-11-22 22:04:38 UTC (rev 12115)
@@ -46,10 +46,7 @@
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.AttributesImpl;
@@ -65,7 +62,6 @@
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParserFactory;
/**
* Command-line application that reads an XML file and writes a pretty-printed
@@ -86,20 +82,9 @@
* output. */
private static final byte DEFAULT_LINE_LENGTH = 80;
- /** The input source to be pretty-printed. */
- private InputSource input;
-
/** The output stream to which the pretty-printed output should be sent. */
private OutputStream output;
- /** The locator instance for identifying the document, line, and column
- * number of specific elements. */
- private Locator locator;
-
- /** The entity resolver to be used for resolving Dtd catalogs and other
- * entities. */
- private EntityResolver entityResolver;
-
/** A reusable buffer. */
private StringBuilder charBuffer = new StringBuilder();
@@ -181,21 +166,21 @@
*/
private boolean indentBlocksInsideMixedContent = false;
+ /** The location of catalogs to use during parsing. */
+ private String[] catalogs;
+
/* End configuration variables. */
/**
* Constructor.
- * @param input The input source encapsulating the document to be pretty-printed.
* @param output The output stream to which the pretty-printed document should be sent.
* @param catalog The location of a catalog file that should be used to find the Dtd for this document.
* This may be null.
*/
- public ForayPretty(final InputSource input, final OutputStream output, final String catalog) {
- this.input = input;
+ public ForayPretty(final OutputStream output, final String catalog) {
this.output = output;
if (catalog != null) {
- final String[] catalogs = {catalog};
- this.entityResolver = XmlUtils.getEntityResolver(catalogs);
+ this.catalogs = new String[] {catalog};
}
/* Set the line terminator to the default for this operating system. */
@@ -207,101 +192,14 @@
@Override
public Object parse(final InputSource inputSource) throws IOException, ParserConfigurationException, SAXException {
- /* TODO: Attempt to get this class to follow the usual pattern. */
- throw new UnsupportedOperationException("This parser does not follow the usual parser pattern.");
- }
-
- /**
- * Intantiates parser and starts parsing of input.
- * @throws IOException For I/O Errors.
- * @throws SAXException For parsing errors.
- * @throws ParserConfigurationException For errors configuring parser.
- */
- public void start() throws IOException, SAXException, ParserConfigurationException {
- final XMLReader parser = createParser();
-
- /* Bind the LexicalHandler to the XMLReader if possible. */
- try {
- parser.setProperty("http://xml.org/sax/properties/lexical-handler", this);
- } catch (final SAXNotSupportedException e1) {
- logError("Parser does not support LexicalHandler.");
- }
-
- /* Bind the DeclHandler to the XMLReader if possible. */
- try {
- parser.setProperty("http://xml.org/sax/properties/declaration-handler", this);
- } catch (final SAXNotSupportedException e) {
- logError("Parser does not support Declaration Handler.");
- }
-
- /* Turn on namespace-prefixes so that we get the namespace declarations
- * returned with other attributes and can therefore write them out
- * along with them. */
- try {
- parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
- } catch (final SAXNotRecognizedException e1) {
- logError("Parser does not recognize the \"namespace-prefixes\" feature.");
- } catch (final SAXNotSupportedException e1) {
- logError("Parser unable to supply namespace-prefixes.");
- }
-
- /* Turn on validation if it is available. */
- try {
- parser.setFeature("http://xml.org/sax/features/validation", true);
- } catch (final SAXNotRecognizedException e1) {
- logError("Parser does not recognize the \"validation\" feature.");
- } catch (final SAXNotSupportedException e1) {
- logError("Parser unable to validate.");
- }
-
- /* Turn on "notify-char-refs" feature.
- * Sadly, this only works with Xerces.
- * This feature, or something like it is very important.
- * Without it, character entities get transformed into characters
- * without notification.
- * When notified, we can (and do) ignore the transformed characters
- * and use the character entities instead.
- * We do NOT want to change the user's content. */
- try {
- parser.setFeature("http://apache.org/xml/features/scanner/notify-char-refs", true);
- } catch (final SAXNotRecognizedException e) {
- /* Make this a fatal error. */
- logError("Parser cannot report character entities. Aborting.");
- cleanup();
- return;
- } catch (final SAXNotSupportedException e) {
- /* Make this a fatal error. */
- logError("Parser cannot report character entities. Aborting.");
- cleanup();
- return;
- }
- parser.setContentHandler(this);
- parser.parse(this.input);
+ final EntityResolver entityResolver = XmlUtils.getEntityResolver(catalogs);
+ final XMLReader parser = createSax2Parser(true, true, true, entityResolver, true);
+ parser.parse(inputSource);
cleanup();
+ return null;
}
/**
- * Creates a SAX parser.
- * @return The created SAX parser.
- * @throws SAXException For error creating parser.
- * @throws ParserConfigurationException For error configuring parser.
- */
- public XMLReader createParser() throws SAXException, ParserConfigurationException {
- final SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
- spf.setNamespaceAware(true);
- final XMLReader xmlReader = spf.newSAXParser().getXMLReader();
- if (this.entityResolver != null) {
- xmlReader.setEntityResolver(this.entityResolver);
- }
- return xmlReader;
- }
-
- @Override
- public void setDocumentLocator(final Locator locator) {
- this.locator = locator;
- }
-
- /**
* Finalize the processing.
*/
private void cleanup() {
@@ -699,7 +597,7 @@
/* Following line for debugging only */
this.output.flush();
} catch (final IOException e) {
- logError("Error converting text.");
+ getLogger().error("Error converting text.");
}
final int lastLineBreakIndex = outputString.lastIndexOf(
this.lineTerminator);
@@ -715,19 +613,6 @@
}
/**
- * Convenience method to log an error.
- * @param message The message to be logged.
- */
- private void logError(final String message) {
- if (this.locator != null) {
- this.getLogger().error(this.locator.getSystemId() + ":"
- + this.locator.getLineNumber() + ":"
- + this.locator.getColumnNumber());
- }
- this.getLogger().error(message);
- }
-
- /**
* Compute the current indentation level.
* @return The number of indents for the current state. This is the number
* of levels that should be indented, not necessarily the number of spaces.
@@ -1290,10 +1175,9 @@
/* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayPretty.STATUS_FILE_NOT_FOUND);
}
- final ForayPretty processor = new ForayPretty(inputSource, outputStream,
- catalog);
+ final ForayPretty processor = new ForayPretty(outputStream, catalog);
try {
- processor.start();
+ processor.parse(inputSource);
} catch (final IOException e) {
logger.error("Error parsing " + input, e);
/* CheckStyle: Allow System.exit() in main method. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-22 20:09:51
|
Revision: 12114
http://sourceforge.net/p/foray/code/12114
Author: victormote
Date: 2021-11-22 20:09:48 +0000 (Mon, 22 Nov 2021)
Log Message:
-----------
More standardization of SAX parsers.
Modified Paths:
--------------
trunk/foray/foray-app/src/main/java/org/foray/app/Options.java
trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java
trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.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/OrthographyParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/ValidateChars.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java
Modified: trunk/foray/foray-app/src/main/java/org/foray/app/Options.java
===================================================================
--- trunk/foray/foray-app/src/main/java/org/foray/app/Options.java 2021-11-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-app/src/main/java/org/foray/app/Options.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -33,8 +33,13 @@
import org.foray.core.OutputConfig;
import org.foray.core.SessionConfig;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
import java.net.URL;
+import javax.xml.parsers.ParserConfigurationException;
+
/**
* Loads configuration files and additional setting of commandline options.
*/
@@ -113,8 +118,8 @@
try {
final ForayConfigParser reader = new ForayConfigParser(userConfigUrl, this.sessionConfig,
this.renderConfig);
- reader.parseDocument();
- } catch (final ForayException e) {
+ reader.parse(userConfigUrl);
+ } catch (IOException | ParserConfigurationException | SAXException e) {
throw new ForayException("Could not load user configuration:\n"
+ " " + userConfigUrl.toExternalForm() + "\n"
+ " Error: " + e.getMessage() + "\n"
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-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -33,6 +33,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
@@ -41,8 +42,10 @@
import org.xml.sax.XMLReader;
import org.xml.sax.ext.DefaultHandler2;
+import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
@@ -49,8 +52,9 @@
/**
* Abstract superclass for SAX parsers.
+ * @param <T> The type of object that should be produced by this parser.
*/
-public abstract class SaxParser extends DefaultHandler2 {
+public abstract class SaxParser<T extends Object> extends DefaultHandler2 {
/** Format string for formatting the current location. */
private static final String LOCATION_FORMAT_STRING = "(%1s:%2$d:%3$d)";
@@ -75,6 +79,30 @@
/** Receives content of text nodes. */
private StringBuilder textAccumulator = new StringBuilder(MAX_EXPECTED_TEXT_LENGTH);
+ /**
+ * Parses an input document and returns the object that was created.
+ * @param inputSource The input document.
+ * @return The object created by the parsing process.
+ * @throws IOException For IO errors during parsing.
+ * @throws ParserConfigurationException For errors during parser configuration.
+ * @throws SAXException For errors found by the SAX parser.
+ */
+ public abstract T parse(InputSource inputSource) throws IOException, ParserConfigurationException, SAXException;
+
+ /**
+ * Converts a URL to an InputSource and parses it.
+ * @param input The URL whose content is to be parsed.
+ * @return The object created by the parsing process.
+ * @throws IOException For IO errors during parsing.
+ * @throws ParserConfigurationException For errors during parser configuration.
+ * @throws SAXException For errors found by the SAX parser.
+ */
+ public T parse(final URL input)
+ throws IOException, ParserConfigurationException, SAXException {
+ final InputSource inputSource = new InputSource(input.toExternalForm());
+ return parse(inputSource);
+ }
+
@Override
public void setDocumentLocator(final Locator locator) {
this.locator = locator;
@@ -167,13 +195,13 @@
* Instantiates an instance of a specified class using reflection, and ensures that it is a subtype of a given type.
* @param className The name of the class that should be instantiated.
* @param expectedType The expected superclass for {@code className}.
- * @param <T> The type of the superclass object that is being instantiated.
+ * @param <T2> The type of the superclass object that is being instantiated.
* @param parameterTypes The array of parameter types.
* @param parameters The array of parameters.
* @return The new instance of {@code className}, or null if it could not be created.
* @throws SAXException Wraps a number of exceptions that can be thrown during instantiation by reflection.
*/
- protected <T extends Object> T instantiate(final String className, final Class<T> expectedType,
+ protected <T2 extends Object> T2 instantiate(final String className, final Class<T2> expectedType,
final Class<?>[] parameterTypes, final Object[] parameters) throws SAXException {
Class<?> theClass = null;
try {
@@ -187,8 +215,8 @@
}
@SuppressWarnings("unchecked")
- final Class<T> factoryClass = (Class<T>) theClass;
- Constructor<T> constructor = null;
+ final Class<T2> factoryClass = (Class<T2>) theClass;
+ Constructor<T2> constructor = null;
try {
constructor = factoryClass.getConstructor(parameterTypes);
} catch (final SecurityException e) {
@@ -197,7 +225,7 @@
throw new SAXException(e);
}
- T newInstance = null;
+ T2 newInstance = null;
try {
newInstance = constructor.newInstance(parameters);
} catch (final IllegalArgumentException e) {
Modified: trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java
===================================================================
--- trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java 2021-11-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -34,10 +34,8 @@
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import java.io.IOException;
@@ -44,7 +42,7 @@
import java.io.InputStream;
import java.net.URL;
-import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.ParserConfigurationException;
/**
* SAX2 Handler which retrieves the configuration information and stores them
@@ -51,7 +49,7 @@
* in Configuration.
* Normally this class doesn't need to be accessed directly.
*/
-public class ForayConfigParser extends SaxParser {
+public class ForayConfigParser extends SaxParser<Object> {
/** Public ID of the FOray configuration DTD. */
public static final String FORAY_CONFIG_DTD_PUBLIC_ID = "-//FOray//DTD FOray Configuration V0.1//EN";
@@ -116,76 +114,25 @@
this.outputConfig = outputConfig;
}
- /**
- * Parses the encapsulated SAX InputSource and updates the encapsulated
- * Configuration instances accordingly.
- * @throws ForayException If there are errors parsing the input.
- */
- public void parseDocument() throws ForayException {
- final XMLReader parser = createParser();
- try {
- final InputSource inputSource = new InputSource(this.configUrl.openStream());
- parser.parse(inputSource);
- } catch (final SAXException e) {
- if (e.getException() instanceof ForayException) {
- throw (ForayException) e.getException();
- }
- throw new ForayException(e);
- } catch (final IOException e) {
- throw new ForayException(e);
- }
- }
-
- /**
- * Creates a SAX parser.
- * @return The created SAX parser.
- * @throws ForayException For errors during parser creation.
- */
- private XMLReader createParser() throws ForayException {
- try {
- final SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
- spf.setNamespaceAware(true);
- spf.setValidating(true);
- final XMLReader xmlReader = spf.newSAXParser().getXMLReader();
- /* TODO: This is not the right EntityResolver to use. We need to
- * use or create one that can find the configuration parser DTD
- * in a jar file that is part of the distribution. */
- final EntityResolver entityResolver = this.sessionConfig.makeEntityResolver();
- xmlReader.setEntityResolver(entityResolver);
- xmlReader.setContentHandler(this);
- final ErrorHandler errorHandler = new ErrorHandler() {
- public void warning(final SAXParseException exception) throws SAXException {
- throw exception;
- }
- public void error(final SAXParseException exception) throws SAXException {
- throw exception;
- }
- public void fatalError(final SAXParseException exception) throws SAXException {
- throw exception;
- }
- };
- xmlReader.setErrorHandler(errorHandler);
- final EntityResolver resolver = new EntityResolver() {
- public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException,
- IOException {
- if (ForayConfigParser.FORAY_CONFIG_DTD_PUBLIC_ID.equals(publicId)) {
- final InputStream inputStream = ForayConfigParser.class.getResourceAsStream(
- "/org/foray/common/dtds/foray-config.dtd");
- if (inputStream == null) {
- return null;
- }
- return new InputSource(inputStream);
+ @Override
+ public Object parse(final InputSource inputSource) throws IOException, ParserConfigurationException, SAXException {
+ final EntityResolver resolver = new EntityResolver() {
+ public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException,
+ IOException {
+ if (ForayConfigParser.FORAY_CONFIG_DTD_PUBLIC_ID.equals(publicId)) {
+ final InputStream inputStream = ForayConfigParser.class.getResourceAsStream(
+ "/org/foray/common/dtds/foray-config.dtd");
+ if (inputStream == null) {
+ return null;
}
- return null;
+ return new InputSource(inputStream);
}
- };
- xmlReader.setEntityResolver(resolver);
- return xmlReader;
- } catch (final javax.xml.parsers.ParserConfigurationException e) {
- throw new ForayException(e);
- } catch (final SAXException e) {
- throw new ForayException(e);
- }
+ return null;
+ }
+ };
+ final XMLReader parser = createSax2Parser(true, true, true, resolver);
+ parser.parse(inputSource);
+ return null;
}
@Override
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java 2021-11-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -46,6 +46,7 @@
import org.slf4j.LoggerFactory;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
import java.awt.Font;
import java.awt.Graphics2D;
@@ -53,6 +54,7 @@
import java.awt.RenderingHints;
import java.awt.font.TextAttribute;
import java.awt.image.BufferedImage;
+import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
@@ -65,6 +67,7 @@
import java.util.Map.Entry;
import javax.activation.DataSource;
+import javax.xml.parsers.ParserConfigurationException;
/**
* An implementation of the aXSL {@link FontServer} interface.
@@ -682,7 +685,11 @@
final InputSource source = new InputSource(inputStream);
final FontConfigParser parser =
new FontConfigParser(this, source);
- parser.start();
+ try {
+ parser.parse(source);
+ } catch (IOException | ParserConfigurationException | SAXException e) {
+ throw new FontException(e);
+ }
if (this.hasFatalConfigurationError) {
throw new FontException("Font Configuration has fatal error(s).");
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java 2021-11-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -40,12 +40,9 @@
import org.axsl.ps.PsException;
import org.xml.sax.Attributes;
-import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import java.io.File;
@@ -62,13 +59,13 @@
import javax.activation.DataSource;
import javax.activation.URLDataSource;
-import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.ParserConfigurationException;
/**
* SAX2 Handler which retrieves the font configuration information and stores it in a {@link FontServer4a} instance.
* Normally this class doesn't need to be accessed directly.
*/
-public class FontConfigParser extends SaxParser {
+public class FontConfigParser extends SaxParser<Object> {
/** Stateful variable tracking which RegisteredFontFamily is currently
* being parsed. */
@@ -144,14 +141,6 @@
*/
private Map<String, PsEncoding> encodingsMap = new HashMap<String, PsEncoding>();
- /*
- * Register the URLStreamHandler for classpath: URLs. This has to be done
- * only once, hence a static statement.
- */
- static {
- org.foray.common.url.classpath.Handler.register();
- }
-
/**
* Constructor.
* @param server The parent font server.
@@ -171,61 +160,14 @@
}
}
- /**
- * Parses the configuration file.
- * @throws FontException For errors during parsing.
- */
- public void start() throws FontException {
- final XMLReader parser = createParser();
- /* Turn on validation if it is available. */
- try {
- parser.setFeature("http://xml.org/sax/features/validation", true);
- } catch (final SAXNotRecognizedException e1) {
- logError("Parser does not recognize validation.");
- } catch (final SAXNotSupportedException e1) {
- logError("Parser unable to validate font-configuration.");
- }
- parser.setContentHandler(this);
- final EntityResolver resolver = AxslDtdUtil.getEntityResolver();
- parser.setEntityResolver(resolver);
-
- try {
- parser.parse(this.filename);
- } catch (final SAXException e) {
- if (e.getException() instanceof FontException) {
- throw (FontException) e.getException();
- }
- throw new FontException(e);
- } catch (final IOException e) {
- throw new FontException(e);
- }
+ @Override
+ public Object parse(final InputSource inputSource) throws IOException, ParserConfigurationException, SAXException {
+ final XMLReader parser = createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver());
+ parser.parse(this.filename);
+ return null;
}
/**
- * Creates a SAX parser for parsing the configuration file.
- * @return The created SAX parser.
- * @throws FontException For errors creating or configuring the parser.
- */
- private XMLReader createParser() throws FontException {
- try {
- final SAXParserFactory spf =
- javax.xml.parsers.SAXParserFactory.newInstance();
- spf.setNamespaceAware(true);
- final XMLReader xmlReader = spf.newSAXParser().getXMLReader();
- final EntityResolver entityResolver = this.fontServer
- .getEntityResolver();
- xmlReader.setEntityResolver(entityResolver);
- getLogger().debug("Font Config: Using "
- + xmlReader.getClass().getName() + " as SAX2 Parser");
- return xmlReader;
- } catch (final javax.xml.parsers.ParserConfigurationException e) {
- throw new FontException(e);
- } catch (final org.xml.sax.SAXException e) {
- throw new FontException(e);
- }
- }
-
- /**
* {@inheritDoc}
* Recognizes each valid element and parses its attributes.
*/
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-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeBuilder.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -48,17 +48,21 @@
import org.axsl.text.TextServer;
import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
+import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import javax.xml.parsers.ParserConfigurationException;
+
/**
* SAX Handler that builds the formatting object tree.
*/
-public class FoTreeBuilder extends SaxParser implements org.axsl.fo.FoTree {
+public class FoTreeBuilder extends SaxParser<Object> implements org.axsl.fo.FoTree {
/** The current formatting object being parsed. */
private FoObj currentFObj = null;
@@ -119,6 +123,12 @@
}
@Override
+ public Object parse(final InputSource inputSource) throws IOException, ParserConfigurationException, SAXException {
+ /* TODO: Not sure how this class is getting used. There doesn't seem to be a reader anywhere. */
+ return null;
+ }
+
+ @Override
public void characters(final char[] data, final int start, final int length)
throws SAXException {
if (this.activeForeignXML != null) {
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java 2021-11-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -49,6 +49,7 @@
import org.slf4j.LoggerFactory;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.InputStream;
@@ -60,6 +61,8 @@
import java.util.Map;
import java.util.regex.Pattern;
+import javax.xml.parsers.ParserConfigurationException;
+
/**
* This class is the main entry point to the hyphenation package.
*/
@@ -106,7 +109,11 @@
final InputSource inputSource = new InputSource(inputStream);
final OrthographyParser parser = new OrthographyParser(this, inputSource);
- parser.start();
+ try {
+ parser.parse(inputSource);
+ } catch (IOException | SAXException | ParserConfigurationException e) {
+ throw new OrthographyException(e);
+ }
}
}
@@ -173,8 +180,7 @@
/**
* Parse a NaturalLanguage instance from its description.
* @param languageCode The language code of the language to be parsed.
- * @return The parsed NaturalLanguage instance, if it can be found, or null
- * otherwise.
+ * @return The parsed NaturalLanguage instance, if it can be found, or null otherwise.
* @throws OrthographyException For errors finding or parsing the files.
*/
private NaturalLanguage parseNaturalLanguage(final String languageCode)
@@ -256,7 +262,11 @@
+ ".xml");
}
final NatLangParser parser = new NatLangParser();
- nl = parser.parse(nlFile);
+ try {
+ nl = parser.parse(nlFile);
+ } catch (IOException | ParserConfigurationException | SAXException e) {
+ throw new OrthographyException(e);
+ }
return nl;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -64,7 +64,7 @@
* Parses an axsl-dictionary XML document into a SegmentDictionary.
* @see DictionaryParserText for a parser for similar data in simple text format.
*/
-public class DictionaryParser extends SaxParser {
+public class DictionaryParser extends SaxParser<List<SegmentDictionary>> {
private class DictionaryElement {
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-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/NatLangParser.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -29,12 +29,9 @@
package org.foray.orthography.util;
import org.foray.common.AxslDtdUtil;
-import org.foray.common.ForayConstants;
import org.foray.common.primitive.UnicodeCharUtils;
import org.foray.common.xml.SaxParser;
-import org.axsl.orthography.OrthographyException;
-
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -41,8 +38,6 @@
import org.xml.sax.XMLReader;
import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
import java.util.StringTokenizer;
import javax.xml.parsers.ParserConfigurationException;
@@ -51,7 +46,7 @@
* A SAX document handler to read and parse natural-language descriptions
* from an XML file.
*/
-public class NatLangParser extends SaxParser {
+public class NatLangParser extends SaxParser<NaturalLanguage> {
/*
* TODO: This class should probably be converted to work with the CLDR/LDML (see src/main/schema/ldml).
*/
@@ -62,54 +57,11 @@
/** The SAX parser. */
private XMLReader parser;
- /** The last error message generated. Used to enhance the messages that
- * are returned with exceptions. */
- private String errMsg;
-
- /**
- * Constructor.
- */
- public NatLangParser() {
- try {
- this.parser = createSax2Parser(false, true, true, AxslDtdUtil.getEntityResolver());
- } catch (final SAXException e) {
- getLogger().error(e.getMessage(), e);
- } catch (final ParserConfigurationException e) {
- getLogger().error(e.getMessage(), e);
- }
- }
-
- /**
- * Parses a given URL, creating a new NaturalLanguage instance for the
- * contents.
- * @param url The URL to parse.
- * @throws OrthographyException For errors during parsing.
- * @return The newly-parsed NaturalLanguage instance.
- */
- public NaturalLanguage parse(final URL url) throws OrthographyException {
- InputStream inputStream = null;
- try {
- inputStream = url.openStream();
- } catch (final IOException e) {
- /* This is a normal condition, and just means that the URL to the
- * pattern file does not exist. */
- getLogger().error("Cannot open hyphenation pattern: "
- + url.toString() + ForayConstants.LOG_NEWLINE
- + e.getMessage());
- return null;
- }
-
- final InputSource uri = new InputSource(inputStream);
-
- try {
- this.parser.parse(uri);
- } catch (final SAXException e) {
- throw new OrthographyException(this.errMsg);
- } catch (final IOException e) {
- throw new OrthographyException(e.getMessage());
- } catch (final NullPointerException e) {
- throw new OrthographyException("SAX parser not available");
- }
+ @Override
+ public NaturalLanguage parse(final InputSource inputSource)
+ throws IOException, SAXException, ParserConfigurationException {
+ this.parser = createSax2Parser(false, true, true, AxslDtdUtil.getEntityResolver());
+ this.parser.parse(inputSource);
return this.nl;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java 2021-11-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -46,7 +46,6 @@
import org.foray.orthography.PosUtils;
import org.foray.orthography.WordWrapperFactory;
-import org.axsl.orthography.OrthographyException;
import org.axsl.orthography.Word;
import org.axsl.orthography.Word.DerivativeType;
import org.axsl.orthography.Word.PartOfSpeech;
@@ -75,7 +74,7 @@
* instance.
* Normally this class doesn't need to be accessed directly.
*/
-public class OrthographyParser extends SaxParser {
+public class OrthographyParser extends SaxParser<Orthography4a> {
/** Stateful variable. */
private DictionaryResource currentDictionaryResource;
@@ -156,17 +155,12 @@
this.filename = filename;
}
- /**
- * Parses the configuration file.
- * @throws OrthographyException For errors during parsing.
- */
- public void start() throws OrthographyException {
- try {
- final XMLReader parser = createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver());
- parser.parse(this.filename);
- } catch (final SAXException | IOException | ParserConfigurationException e) {
- throw new OrthographyException(e);
- }
+ @Override
+ public Orthography4a parse(final InputSource inputSource)
+ throws IOException, SAXException, ParserConfigurationException {
+ final XMLReader parser = createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver());
+ parser.parse(this.filename);
+ return this.currentOrthographyConfig;
}
@Override
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -33,7 +33,6 @@
package org.foray.orthography.util;
-import org.foray.common.ForayConstants;
import org.foray.common.xml.SaxParser;
import org.foray.orthography.PatternConsumer;
@@ -47,15 +46,13 @@
import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
/**
- * A SAX document handler to read and parse hyphenation patterns
- * from a XML file.
+ * A SAX document handler to read and parse hyphenation patterns from an XML file.
*/
-public class PatternParser extends SaxParser {
+public class PatternParser extends SaxParser<PatternConsumer> {
/** Constant indicating that the current element is "classes". */
static final int ELEM_CLASSES = 1;
@@ -103,24 +100,11 @@
}
}
- /**
- * Parses a given URL, using the PatternConsumer to consume the data retrieved during the parse.
- * @param url The URL to parse.
- * @throws OrthographyException For errors during parsing.
- */
- public void parse(final URL url) throws OrthographyException {
- InputStream inputStream = null;
- try {
- inputStream = url.openStream();
- } catch (final IOException e) {
- /* This is a normal condition, and just means that the URL to the
- * pattern file does not exist. */
- getLogger().error("Cannot open hyphenation pattern: "
- + url.toString() + ForayConstants.LOG_NEWLINE
- + e.getMessage());
- return;
- }
- parse(inputStream);
+ @Override
+ public PatternConsumer parse(final InputSource inputSource) {
+ /* TODO: If PatternConsumer is not needed, use the implementation here instead. */
+ parse(inputSource);
+ return this.consumer;
}
/**
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -58,8 +58,6 @@
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import java.io.BufferedInputStream;
@@ -75,7 +73,6 @@
import java.util.Stack;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParserFactory;
/**
* Parses a document, looking for spelling errors.
@@ -82,7 +79,7 @@
* The specified natural language can change at any time, and must be tracked
* General plan is to capture all of the text data in one CharSequence, then parse and compare to dictionary entries.
*/
-public class SpellChecker extends SaxParser {
+public class SpellChecker extends SaxParser<Object> {
private class Element {
@@ -136,9 +133,6 @@
/** Format string for formatting the current location. */
private static final String LOCATION_FORMAT_STRING = "(%1$d:%2$d)";
- /** The input source to be spell-checked. */
- private InputSource input;
-
/** The output stream to which the output should be sent. */
private PrintStream output;
@@ -146,10 +140,6 @@
* number of specific elements. */
private Locator locator;
- /** The entity resolver to be used for resolving Dtd catalogs and other
- * entities. */
-// private EntityResolver entityResolver;
-
/** Flag indicating whether text parsing is active. Some elements contain text that should not be accumulated. */
private boolean textParsingActive;
@@ -162,9 +152,6 @@
/** The current orthography configuration. */
private Orthography4a currentOrthographyConfig;
- /** The logger. */
- private Logger logger = LoggerFactory.getLogger(SpellChecker.class);
-
/** The Hyphenation server. */
private OrthographyServer4a server;
@@ -179,7 +166,6 @@
/**
* Constructor.
- * @param input The input source encapsulating the document to be spell-checked.
* @param output The output stream to which the spelling errors should be written.
* @param orthographyConfigPath The path to the orthography configuration.
* @param adhocDictionaryPaths (optional) List of paths to ad-hoc dictionaries to be used by the spell-checker.
@@ -190,10 +176,9 @@
* @throws ParserConfigurationException For errors configuring the parser.
* @throws SAXException For errors found by the SAX parser.
*/
- public SpellChecker(final InputSource input, final PrintStream output, final URL orthographyConfigPath,
+ public SpellChecker(final PrintStream output, final URL orthographyConfigPath,
final List<URL> adhocDictionaryPaths)
throws OrthographyException, IOException, SAXException, ParserConfigurationException {
- this.input = input;
this.output = output;
final OrthographyServerConfig serverConfig = new OrthographyServerConfig();
@@ -211,86 +196,16 @@
}
}
- public void start() throws SAXException, ParserConfigurationException, IOException {
- final XMLReader parser = createParser();
-
- /* Bind the LexicalHandler to the XMLReader if possible. */
- try {
- parser.setProperty("http://xml.org/sax/properties/lexical-handler", this);
- } catch (final SAXNotSupportedException e1) {
- this.logger.error("Parser does not support LexicalHandler.");
- }
-
- /* Bind the DeclHandler to the XMLReader if possible. */
- try {
- parser.setProperty("http://xml.org/sax/properties/declaration-handler", this);
- } catch (final SAXNotSupportedException e) {
- this.logger.error("Parser does not support Declaration Handler.");
- }
-
- /* Turn on namespace-prefixes so that we get the namespace declarations
- * returned with other attributes and can therefore write them out
- * along with them. */
- try {
- parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
- } catch (final SAXNotRecognizedException e1) {
- this.logger.error("Parser does not recognize the \"namespace-prefixes\" feature.");
- } catch (final SAXNotSupportedException e1) {
- this.logger.error("Parser unable to supply namespace-prefixes.");
- }
-
+ @Override
+ public Object parse(final InputSource inputSource) throws IOException, ParserConfigurationException, SAXException {
/* Skip validation. That should be handled upstream of this process. */
-// try {
-// parser.setFeature("http://xml.org/sax/features/validation", true);
-// } catch (final SAXNotRecognizedException e1) {
-// this.logger.error("Parser does not recognize the \"validation\" feature.");
-// } catch (final SAXNotSupportedException e1) {
-// this.logger.error("Parser unable to validate.");
-// }
-
- /* Turn on "notify-char-refs" feature.
- * Sadly, this only works with Xerces.
- * This feature, or something like it is very important.
- * Without it, character entities get transformed into characters
- * without notification.
- * When notified, we can (and do) ignore the transformed characters
- * and use the character entities instead.
- * We do NOT want to change the user's content. */
-// try {
-// parser.setFeature("http://apache.org/xml/features/scanner/notify-char-refs", true);
-// } catch (final SAXNotRecognizedException e) {
-// /* Make this a fatal error. */
-// this.logger.error("Parser cannot report character entities. Aborting.");
-// cleanup();
-// return;
-// } catch (final SAXNotSupportedException e) {
-// /* Make this a fatal error. */
-// this.logger.error("Parser cannot report character entities. Aborting.");
-// cleanup();
-// return;
-// }
- parser.setContentHandler(this);
- parser.parse(this.input);
+ final XMLReader parser = createSax2Parser(false, true, true, null);
+ parser.parse(inputSource);
cleanup();
+ return null;
}
/**
- * Creates a SAX parser.
- * @return The created SAX parser.
- * @throws SAXException For error creating parser.
- * @throws ParserConfigurationException For error configuring parser.
- */
- public XMLReader createParser() throws SAXException, ParserConfigurationException {
- final SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
- spf.setNamespaceAware(true);
- final XMLReader xmlReader = spf.newSAXParser().getXMLReader();
-// if (this.entityResolver != null) {
-// xmlReader.setEntityResolver(this.entityResolver);
-// }
- return xmlReader;
- }
-
- /**
* Finalize the processing.
*/
private void cleanup() {
@@ -551,8 +466,8 @@
}
}
- final SpellChecker checker = new SpellChecker(inputSource, output, orthographyConfigPath, dictionaries);
- checker.start();
+ final SpellChecker checker = new SpellChecker(output, orthographyConfigPath, dictionaries);
+ checker.parse(inputSource);
} catch (final OrthographyException | IOException | SAXException | ParserConfigurationException e) {
logger.error("Error configuring or running: " + input, e);
/* CheckStyle: Allow System.exit() in main method. */
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/ValidateChars.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/ValidateChars.java 2021-11-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/ValidateChars.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -69,7 +69,7 @@
* misspelled or that are not encoded properly, so that they can be fixed in
* preparation for creating a word list.
*/
-public class ValidateChars extends SaxParser {
+public class ValidateChars extends SaxParser<Object> {
/** Command-line return status constant indicating that the number of
* arguments is wrong. */
@@ -118,8 +118,6 @@
/**
* Constructor.
* @param server The server used to find natural language resources.
- * @param input The input source encapsulating the document to be
- * pretty-printed.
* @param catalog The location of a catalog file that should be used to find
* DTDs.
* @param languageCode The valid ISO-639 language against which this
@@ -126,27 +124,18 @@
* document will be tested.
* find the DTD for this document.
*/
- public ValidateChars(final OrthographyServer4a server,
- final InputSource input, final String catalog,
- final String languageCode) {
+ public ValidateChars(final OrthographyServer4a server, final String catalog, final String languageCode) {
this.server = server;
- this.input = input;
this.entityResolver = getEntityResolver(catalog);
this.languageCode = languageCode;
this.iso639 = Language4a.findFromAlpha(languageCode);
}
- /**
- * Intantiates parser and starts parsing of input.
- * @throws IOException For I/O Errors.
- * @throws SAXException For parsing errors.
- * @throws ParserConfigurationException For errors configuring parser.
- */
- public void start() throws IOException, SAXException,
- ParserConfigurationException {
+ @Override
+ public Object parse(final InputSource input) throws IOException, SAXException, ParserConfigurationException {
if (this.iso639 == null) {
logError("Not a valid ISO-639 code: " + this.languageCode);
- return;
+ return null;
}
final XMLReader parser = createParser();
@@ -202,14 +191,15 @@
} catch (final SAXNotRecognizedException e) {
/* Make this a fatal error. */
logError("Parser cannot report character entities. Aborting.");
- return;
+ return null;
} catch (final SAXNotSupportedException e) {
/* Make this a fatal error. */
logError("Parser cannot report character entities. Aborting.");
- return;
+ return null;
}
parser.setContentHandler(this);
parser.parse(this.input);
+ return null;
}
/**
@@ -414,10 +404,9 @@
}
final InputStream inputStream = new BufferedInputStream(fis);
final InputSource inputSource = new InputSource(inputStream);
- final ValidateChars validator = new ValidateChars(server,
- inputSource, catalog, iso639);
+ final ValidateChars validator = new ValidateChars(server, catalog, iso639);
try {
- validator.start();
+ validator.parse(inputSource);
} catch (final IOException | ParserConfigurationException | SAXException e) {
logger.error(e.getMessage(), e);
/* CheckStyle: Allow System.exit() in main method. */
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java 2021-11-22 18:54:07 UTC (rev 12113)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java 2021-11-22 20:09:48 UTC (rev 12114)
@@ -71,7 +71,7 @@
* Command-line application that reads an XML file and writes a pretty-printed
* version of it.
*/
-public class ForayPretty extends SaxParser {
+public class ForayPretty extends SaxParser<Object> {
/** Command-line status constant indicating that the command line itself was not properly formed. */
public static final byte STATUS_COMMAND_LINE_ERROR = 1;
@@ -205,6 +205,12 @@
this.postRootText = this.lineTerminator;
}
+ @Override
+ public Object parse(final InputSource inputSource) throws IOException, ParserConfigurationException, SAXException {
+ /* TODO: Attempt to get this class to follow the usual pattern. */
+ throw new UnsupportedOperationException("This parser does not follow the usual parser pattern.");
+ }
+
/**
* Intantiates parser and starts parsing of input.
* @throws IOException For I/O Errors.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-22 18:54:09
|
Revision: 12113
http://sourceforge.net/p/foray/code/12113
Author: victormote
Date: 2021-11-22 18:54:07 +0000 (Mon, 22 Nov 2021)
Log Message:
-----------
More standardization of SAX parsers.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.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/OrthographyParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java
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-22 18:12:50 UTC (rev 12112)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java 2021-11-22 18:54:07 UTC (rev 12113)
@@ -28,6 +28,8 @@
package org.foray.common.xml;
+import org.foray.common.primitive.StringUtils;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.EntityResolver;
@@ -35,6 +37,7 @@
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.DefaultHandler2;
@@ -52,6 +55,17 @@
/** Format string for formatting the current location. */
private static final String LOCATION_FORMAT_STRING = "(%1s:%2$d:%3$d)";
+ /** Constant used to initialize string builders. */
+ private static final int MAX_EXPECTED_TEXT_LENGTH = 4096;
+
+ /**
+ * Register the URLStreamHandler for classpath: URLs.
+ * This has to be done only once, hence a static statement.
+ */
+ static {
+ org.foray.common.url.classpath.Handler.register();
+ }
+
/** The locator instance for identifying the document, line, and column number of specific elements. */
private Locator locator;
@@ -58,6 +72,9 @@
/** The logger. */
private Logger logger = LoggerFactory.getLogger(this.getClass());
+ /** Receives content of text nodes. */
+ private StringBuilder textAccumulator = new StringBuilder(MAX_EXPECTED_TEXT_LENGTH);
+
@Override
public void setDocumentLocator(final Locator locator) {
this.locator = locator;
@@ -125,8 +142,23 @@
}
}
+ /* Bind the LexicalHandler to the XMLReader if possible. */
+ try {
+ xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", this);
+ } catch (final SAXNotSupportedException e1) {
+ getLogger().error("Parser does not support LexicalHandler.");
+ }
+
+ /* Bind the DeclHandler to the XMLReader if possible. */
+ try {
+ xmlReader.setProperty("http://xml.org/sax/properties/declaration-handler", this);
+ } catch (final SAXNotSupportedException e) {
+ getLogger().error("Parser does not support Declaration Handler.");
+ }
+
xmlReader.setContentHandler(this);
xmlReader.setErrorHandler(this);
+
getLogger().debug("{}: Using {} as SAX2 Parser", this.getClass().getName(), xmlReader.getClass().getName());
return xmlReader;
}
@@ -186,4 +218,34 @@
*/
public abstract void reset();
+ @Override
+ public void characters(final char[] chars, final int start, final int length) throws SAXException {
+ this.textAccumulator.append(chars, start, length);
+ }
+
+ /**
+ * Returns whatever text is accumulated, and clears the text buffer.
+ * @return The content of the text buffer before it is cleared.
+ */
+ public String getAndClearText() {
+ final String content = this.textAccumulator.toString();
+ StringUtils.clear(this.textAccumulator);
+ return content;
+ }
+
+ @Override
+ public void warning(final SAXParseException ex) {
+ this.logger.warn(getLocationString() + ": " + ex.getMessage());
+ }
+
+ @Override
+ public void error(final SAXParseException ex) {
+ this.logger.error(getLocationString() + ": " + ex.getMessage());
+ }
+
+ @Override
+ public void fatalError(final SAXParseException ex) throws SAXException {
+ throw new SAXException(ex);
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-22 18:12:50 UTC (rev 12112)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-22 18:54:07 UTC (rev 12113)
@@ -45,11 +45,8 @@
import org.axsl.orthography.Word.PartOfSpeech;
import org.xml.sax.Attributes;
-import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import java.io.IOException;
@@ -62,7 +59,6 @@
import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParserFactory;
/**
* Parses an axsl-dictionary XML document into a SegmentDictionary.
@@ -127,9 +123,6 @@
/** Reusable segment list. */
private List<StringWordSegment> segmentList = new ArrayList<StringWordSegment>(MAX_EXPECTED_QTY_SEGMENTS);
- /** Buffer in which to capture parsed element content. */
- private StringBuilder charBuffer = new StringBuilder(MAX_EXPECTED_WORD_LENGTH);
-
/** Indicates whether this parser should log dictionary problems. */
private boolean logDictionaryProblems = false;
@@ -148,9 +141,8 @@
throws IOException, SAXException, ParserConfigurationException {
getLogger().info("Begin dictionary word list parsing: " + inputSource.getSystemId());
- final XMLReader parser = createParser();
+ final XMLReader parser = this.createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver());
if (parser != null) {
- parser.setContentHandler(this);
parser.parse(inputSource);
}
cleanup();
@@ -179,71 +171,6 @@
return this.parsedDictionaries;
}
- private XMLReader createParser() throws SAXException, ParserConfigurationException {
- final SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
- spf.setNamespaceAware(true);
- final XMLReader parser = spf.newSAXParser().getXMLReader();
-
- final EntityResolver resolver = AxslDtdUtil.getEntityResolver();
- parser.setEntityResolver(resolver);
-
- /* Bind the LexicalHandler to the XMLReader if possible. */
- try {
- parser.setProperty("http://xml.org/sax/properties/lexical-handler", this);
- } catch (final SAXNotSupportedException e1) {
- getLogger().error("Parser does not support LexicalHandler.");
- }
-
- /* Bind the DeclHandler to the XMLReader if possible. */
- try {
- parser.setProperty("http://xml.org/sax/properties/declaration-handler", this);
- } catch (final SAXNotSupportedException e) {
- getLogger().error("Parser does not support Declaration Handler.");
- }
-
- /* Turn on namespace-prefixes so that we get the namespace declarations
- * returned with other attributes and can therefore write them out
- * along with them. */
- try {
- parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
- } catch (final SAXNotRecognizedException e1) {
- getLogger().error("Parser does not recognize the \"namespace-prefixes\" feature.");
- } catch (final SAXNotSupportedException e1) {
- getLogger().error("Parser unable to supply namespace-prefixes.");
- }
-
- try {
- parser.setFeature("http://xml.org/sax/features/validation", true);
- } catch (final SAXNotRecognizedException e1) {
- getLogger().error("Parser does not recognize the \"validation\" feature.");
- } catch (final SAXNotSupportedException e1) {
- getLogger().error("Parser unable to validate.");
- }
-
- /* Turn on "notify-char-refs" feature.
- * Sadly, this only works with Xerces.
- * This feature, or something like it is very important.
- * Without it, character entities get transformed into characters
- * without notification.
- * When notified, we can (and do) ignore the transformed characters
- * and use the character entities instead.
- * We do NOT want to change the user's content. */
-// try {
-// parser.setFeature("http://apache.org/xml/features/scanner/notify-char-refs", true);
-// } catch (final SAXNotRecognizedException e) {
-// /* Make this a fatal error. */
-// this.logger.error("Parser cannot report character entities. Aborting.");
-// cleanup();
-// return null;
-// } catch (final SAXNotSupportedException e) {
-// /* Make this a fatal error. */
-// this.logger.error("Parser cannot report character entities. Aborting.");
-// cleanup();
-// return null;
-// }
- return parser;
- }
-
/**
* Finalize the processing.
*/
@@ -261,11 +188,6 @@
@Override
- public void characters(final char ch[], final int start, final int length) throws SAXException {
- this.charBuffer.append(ch, start, length);
- }
-
- @Override
public void startElement(final String uri, final String localName, final String qName, final Attributes attributes)
throws SAXException {
switch(localName) {
@@ -452,9 +374,7 @@
break;
}
case "t": {
- final String inputLine = this.charBuffer.toString().trim();
- StringUtils.clear(this.charBuffer);
-
+ final String inputLine = getAndClearText();
StringUtils.clear(this.builder);
this.segmentList.clear();
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-22 18:12:50 UTC (rev 12112)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/NatLangParser.java 2021-11-22 18:54:07 UTC (rev 12113)
@@ -38,7 +38,6 @@
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import java.io.IOException;
@@ -163,55 +162,6 @@
}
@Override
- public void characters(final char ch[], final int start, final int length) {
- /* We currently have not content, so there is nothing to do here. */
- }
-
- @Override
- public void warning(final SAXParseException ex) {
- this.errMsg = "[Warning] " + getLocationString(ex) + ": "
- + ex.getMessage();
- }
-
- @Override
- public void error(final SAXParseException ex) {
- this.errMsg = "[Error] " + getLocationString(ex) + ": "
- + ex.getMessage();
- }
-
- @Override
- public void fatalError(final SAXParseException ex) throws SAXException {
- this.errMsg = "[Fatal Error] " + getLocationString(ex) + ": "
- + ex.getMessage();
- throw ex;
- }
-
- /**
- * For a given exception, returns a string description of the document
- * location that caused the exception.
- * @param ex The exception whose location is needed.
- * @return The string description of the document location.
- */
- private String getLocationString(final SAXParseException ex) {
- final StringBuilder str = new StringBuilder();
-
- String systemId = ex.getSystemId();
- if (systemId != null) {
- final int index = systemId.lastIndexOf('/');
- if (index != -1) {
- systemId = systemId.substring(index + 1);
- }
- str.append(systemId);
- }
- str.append(':');
- str.append(ex.getLineNumber());
- str.append(':');
- str.append(ex.getColumnNumber());
-
- return str.toString();
- }
-
- @Override
public void reset() {
throw new UnsupportedOperationException();
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java 2021-11-22 18:12:50 UTC (rev 12112)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java 2021-11-22 18:54:07 UTC (rev 12113)
@@ -33,7 +33,6 @@
import org.foray.common.i18n.Language4a;
import org.foray.common.i18n.Script4a;
import org.foray.common.i18n.WritingSystem4a;
-import org.foray.common.primitive.StringUtils;
import org.foray.common.resource.ResourceLocation;
import org.foray.common.resource.ResourceLocationClasspath;
import org.foray.common.resource.ResourceLocationUrl;
@@ -120,9 +119,6 @@
/** Stateful variable. */
private ResourceLocation currentResourceLocation;
- /** Receives content of text nodes. */
- private StringBuilder textAccumulator = new StringBuilder();
-
/** Stateful variable tracking the current orthography configuration. */
private transient Orthography4a currentOrthographyConfig;
@@ -150,14 +146,6 @@
private Stack<String> elementStack = new Stack<String>();
/**
- * Register the URLStreamHandler for classpath: URLs.
- * This has to be done only once, hence a static statement.
- */
- static {
- org.foray.common.url.classpath.Handler.register();
- }
-
- /**
* Constructor.
* @param server The hyphenation server which will capture the information from the parsed configuration.
* @param filename The file which contains the configuration information
@@ -530,8 +518,7 @@
return;
}
case "match": {
- final String matchString = this.textAccumulator.toString();
- StringUtils.clear(this.textAccumulator);
+ final String matchString = getAndClearText();
final Pattern pattern = Pattern.compile(matchString);
if (this.currentDerivativeRuleList != null) {
this.currentDerivativeRuleMatch = pattern;
@@ -541,8 +528,7 @@
return;
}
case "replace": {
- final String replaceString = this.textAccumulator.toString();
- StringUtils.clear(this.textAccumulator);
+ final String replaceString = getAndClearText();
this.currentDerivativeRuleReplace = replaceString;
return;
}
@@ -586,8 +572,7 @@
return;
}
case "resource-location": {
- final String content = this.textAccumulator.toString();
- StringUtils.clear(this.textAccumulator);
+ final String content = getAndClearText();
switch (this.currentResourceLocationType) {
case CLASSPATH_RESOURCE: {
this.currentResourceLocation = new ResourceLocationClasspath(content);
@@ -638,11 +623,6 @@
}
}
- @Override
- public void characters(final char[] chars, final int start, final int length) throws SAXException {
- this.textAccumulator.append(chars, start, length);
- }
-
/**
* Converts a string to a URL.
* @param urlString The string to be converted.
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-22 18:12:50 UTC (rev 12112)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-22 18:54:07 UTC (rev 12113)
@@ -273,51 +273,6 @@
}
@Override
- public void warning(final SAXParseException ex) {
- this.errMsg = "[Warning] " + getLocationString(ex) + ": "
- + ex.getMessage();
- }
-
- @Override
- public void error(final SAXParseException ex) {
- this.errMsg = "[Error] " + getLocationString(ex) + ": "
- + ex.getMessage();
- }
-
- @Override
- public void fatalError(final SAXParseException ex) throws SAXException {
- this.errMsg = "[Fatal Error] " + getLocationString(ex) + ": "
- + ex.getMessage();
- throw ex;
- }
-
- /**
- * For a given exception, returns a string description of the document
- * location that caused the exception.
- * @param ex The exception whose location is needed.
- * @return The string description of the document location.
- */
- private String getLocationString(final SAXParseException ex) {
- final StringBuilder str = new StringBuilder();
-
- String systemId = ex.getSystemId();
- if (systemId != null) {
- final int index = systemId.lastIndexOf('/');
- if (index != -1) {
- systemId = systemId.substring(index + 1);
- }
- str.append(systemId);
- }
- str.append(':');
- str.append(ex.getLineNumber());
- str.append(':');
- str.append(ex.getColumnNumber());
-
- return str.toString();
-
- }
-
- @Override
public void reset() {
throw new UnsupportedOperationException();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-22 18:12:54
|
Revision: 12112
http://sourceforge.net/p/foray/code/12112
Author: victormote
Date: 2021-11-22 18:12:50 +0000 (Mon, 22 Nov 2021)
Log Message:
-----------
Add abstract method reset() for parsers that can be reused.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java
trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.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/OrthographyParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/ValidateChars.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java
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-22 17:58:44 UTC (rev 12111)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java 2021-11-22 18:12:50 UTC (rev 12112)
@@ -180,4 +180,10 @@
return newInstance;
}
+ /**
+ * Uses by subclasses to clear their state so that they can be reused to parse another document.
+ * @throws UnsupportedOperationException If the subclass does not support reuse.
+ */
+ public abstract void reset();
+
}
Modified: trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java
===================================================================
--- trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java 2021-11-22 17:58:44 UTC (rev 12111)
+++ trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java 2021-11-22 18:12:50 UTC (rev 12112)
@@ -259,4 +259,9 @@
this.outputConfig.parseOption(this.configUrl, key, value, SessionConfig.PRECEDENCE_CONFIG_FILE);
}
+ @Override
+ public void reset() {
+ throw new UnsupportedOperationException();
+ }
+
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java 2021-11-22 17:58:44 UTC (rev 12111)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java 2021-11-22 18:12:50 UTC (rev 12112)
@@ -1019,4 +1019,10 @@
this.simulateStretch = simulateStretch;
}
}
+
+ @Override
+ public void reset() {
+ throw new UnsupportedOperationException();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-22 17:58:44 UTC (rev 12111)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-22 18:12:50 UTC (rev 12112)
@@ -572,4 +572,9 @@
this.logDictionaryProblems = logDictionaryProblems;
}
+ @Override
+ public void reset() {
+ throw new UnsupportedOperationException();
+ }
+
}
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-22 17:58:44 UTC (rev 12111)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/NatLangParser.java 2021-11-22 18:12:50 UTC (rev 12112)
@@ -209,7 +209,11 @@
str.append(ex.getColumnNumber());
return str.toString();
+ }
+ @Override
+ public void reset() {
+ throw new UnsupportedOperationException();
}
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java 2021-11-22 17:58:44 UTC (rev 12111)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java 2021-11-22 18:12:50 UTC (rev 12112)
@@ -673,4 +673,9 @@
return this.elementStack.get(parentIndex);
}
+ @Override
+ public void reset() {
+ throw new UnsupportedOperationException();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-22 17:58:44 UTC (rev 12111)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-22 18:12:50 UTC (rev 12112)
@@ -317,4 +317,9 @@
}
+ @Override
+ public void reset() {
+ throw new UnsupportedOperationException();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-22 17:58:44 UTC (rev 12111)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-22 18:12:50 UTC (rev 12112)
@@ -561,4 +561,9 @@
}
+ @Override
+ public void reset() {
+ throw new UnsupportedOperationException();
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/ValidateChars.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/ValidateChars.java 2021-11-22 17:58:44 UTC (rev 12111)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/ValidateChars.java 2021-11-22 18:12:50 UTC (rev 12112)
@@ -426,4 +426,9 @@
}
}
+ @Override
+ public void reset() {
+ throw new UnsupportedOperationException();
+ }
+
}
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java 2021-11-22 17:58:44 UTC (rev 12111)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java 2021-11-22 18:12:50 UTC (rev 12112)
@@ -1304,4 +1304,9 @@
logger.info("Input: " + input + " successfully pretty-printed,\n output in: " + output);
}
+ @Override
+ public void reset() {
+ throw new UnsupportedOperationException();
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-22 17:58:46
|
Revision: 12111
http://sourceforge.net/p/foray/code/12111
Author: victormote
Date: 2021-11-22 17:58:44 +0000 (Mon, 22 Nov 2021)
Log Message:
-----------
More standardization of SAX 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-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.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/OrthographyParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.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-22 16:33:31 UTC (rev 12110)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java 2021-11-22 17:58:44 UTC (rev 12111)
@@ -137,11 +137,9 @@
final InputSource foInputSource = new InputSource(foInputStream);
final XMLReader xmlReader;
try {
- xmlReader = foTreeBuilder.createSax2Parser();
- } catch (final SAXException e) {
+ xmlReader = foTreeBuilder.createSax2Parser(false, false, false, null);
+ } catch (final SAXException | ParserConfigurationException e) {
throw new ForayException(e);
- } catch (final ParserConfigurationException e) {
- throw new ForayException(e);
}
final FontServer fontServer = this.treeServer.getFontServer();
final FontConsumer fontConsumer = fontServer.makeFontConsumer();
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-22 16:33:31 UTC (rev 12110)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java 2021-11-22 17:58:44 UTC (rev 12111)
@@ -30,8 +30,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.xml.sax.EntityResolver;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.DefaultHandler2;
@@ -93,19 +96,38 @@
}
/**
- * Creates a SAX2 parser with a standard configuration. Specifically,
- * the parser is namespace-aware and has the "namespace-prefixes" feature
- * set to true.
+ * Creates a SAX2 parser.
+ * @param validate Indicates whether the parser should validate the document as it parses.
+ * @param namespaceAware Indicates whether the parser should be namespace-aware.
+ * @param namespacePrefixes Indicates wehther the parser should process namespace prefixes.
+ * @param entityResolver Specifies the entity resolver, if any that should be used.
* @return The newly-created SAX2 parser.
* @throws SAXException For errors creating the parser.
* @throws ParserConfigurationException For errors configuring the parser.
*/
- public XMLReader createSax2Parser() throws SAXException, ParserConfigurationException {
+ public XMLReader createSax2Parser(final boolean validate, final boolean namespaceAware,
+ final boolean namespacePrefixes, final EntityResolver entityResolver)
+ throws SAXException, ParserConfigurationException {
final SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
- spf.setNamespaceAware(true);
- XMLReader xmlReader = null;
- xmlReader = spf.newSAXParser().getXMLReader();
- xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
+ spf.setNamespaceAware(namespaceAware);
+ final XMLReader xmlReader = spf.newSAXParser().getXMLReader();
+ xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", namespacePrefixes);
+ xmlReader.setEntityResolver(entityResolver);
+
+ /* Turn on validation if it is available. */
+ if (validate) {
+ try {
+ xmlReader.setFeature("http://xml.org/sax/features/validation", true);
+ } catch (final SAXNotRecognizedException e) {
+ getLogger().warn("Parser does not recognize validation.");
+ } catch (final SAXNotSupportedException e) {
+ getLogger().warn("Parser does not support validation.");
+ }
+ }
+
+ xmlReader.setContentHandler(this);
+ xmlReader.setErrorHandler(this);
+ getLogger().debug("{}: Using {} as SAX2 Parser", this.getClass().getName(), xmlReader.getClass().getName());
return xmlReader;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java 2021-11-22 16:33:31 UTC (rev 12110)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java 2021-11-22 17:58:44 UTC (rev 12111)
@@ -189,8 +189,7 @@
/* Use the language code as the base name for the file. */
/* First look for the serialized object. */
- String fileName = filePrefix
- + ForayConstants.BINARY_SERIALIZATION_EXTENSION;
+ String fileName = filePrefix + "." + ForayConstants.BINARY_SERIALIZATION_EXTENSION;
URL nlFile = null;
try {
nlFile = UrlFactory.createURL(naturalLanguageDir, fileName);
@@ -246,6 +245,7 @@
/* Does the XML file exist? */
try {
inputStream = nlFile.openStream();
+ inputStream.close();
} catch (final IOException e) {
/* The XML pattern file does not exist. Do not try to parse it. */
return null;
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-22 16:33:31 UTC (rev 12110)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/NatLangParser.java 2021-11-22 17:58:44 UTC (rev 12111)
@@ -36,7 +36,6 @@
import org.axsl.orthography.OrthographyException;
import org.xml.sax.Attributes;
-import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
@@ -73,16 +72,12 @@
*/
public NatLangParser() {
try {
- this.parser = createSax2Parser();
+ this.parser = createSax2Parser(false, true, true, AxslDtdUtil.getEntityResolver());
} catch (final SAXException e) {
getLogger().error(e.getMessage(), e);
} catch (final ParserConfigurationException e) {
getLogger().error(e.getMessage(), e);
}
- this.parser.setContentHandler(this);
- this.parser.setErrorHandler(this);
- final EntityResolver resolver = AxslDtdUtil.getEntityResolver();
- this.parser.setEntityResolver(resolver);
}
/**
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java 2021-11-22 16:33:31 UTC (rev 12110)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java 2021-11-22 17:58:44 UTC (rev 12111)
@@ -55,11 +55,8 @@
import org.axsl.orthography.optional.Lexer;
import org.xml.sax.Attributes;
-import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import java.io.IOException;
@@ -72,7 +69,7 @@
import java.util.Stack;
import java.util.regex.Pattern;
-import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.ParserConfigurationException;
/**
* SAX2 Handler which retrieves the orthography configuration information and stores it in a {@link OrthographyServer4a}
@@ -176,54 +173,14 @@
* @throws OrthographyException For errors during parsing.
*/
public void start() throws OrthographyException {
- final XMLReader parser = createParser();
- /* Turn on validation if it is available. */
try {
- parser.setFeature("http://xml.org/sax/features/validation", true);
- } catch (final SAXNotRecognizedException e) {
- getLogger().warn("Parser does not recognize validation.");
- } catch (final SAXNotSupportedException e) {
- getLogger().warn("Parser does not support validation.");
- }
- parser.setContentHandler(this);
- final EntityResolver resolver = AxslDtdUtil.getEntityResolver();
- parser.setEntityResolver(resolver);
-
- try {
+ final XMLReader parser = createSax2Parser(true, true, true, AxslDtdUtil.getEntityResolver());
parser.parse(this.filename);
- } catch (final SAXException e) {
- if (e.getException() instanceof OrthographyException) {
- throw (OrthographyException) e.getException();
- }
+ } catch (final SAXException | IOException | ParserConfigurationException e) {
throw new OrthographyException(e);
- } catch (final IOException e) {
- throw new OrthographyException(e);
}
}
- /**
- * Creates a SAX parser for parsing the configuration file.
- * @return The created SAX parser.
- * @throws OrthographyException For errors creating or configuring the parser.
- */
- private XMLReader createParser() throws OrthographyException {
- try {
- final SAXParserFactory spf =
- javax.xml.parsers.SAXParserFactory.newInstance();
- spf.setNamespaceAware(true);
- final XMLReader xmlReader = spf.newSAXParser().getXMLReader();
- final EntityResolver entityResolver = this.hyphenationServer.getEntityResolver();
- xmlReader.setEntityResolver(entityResolver);
- getLogger().debug("Orthography Configuration Parsing: Using {} as SAX2 Parser",
- xmlReader.getClass().getName());
- return xmlReader;
- } catch (final javax.xml.parsers.ParserConfigurationException e) {
- throw new OrthographyException(e);
- } catch (final org.xml.sax.SAXException e) {
- throw new OrthographyException(e);
- }
- }
-
@Override
public void startElement(final String uri, final String localName, final String qName,
final Attributes attributes) throws SAXException {
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-22 16:33:31 UTC (rev 12110)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2021-11-22 17:58:44 UTC (rev 12111)
@@ -94,15 +94,13 @@
if (consumer == null) {
throw new NullPointerException("PatternConsumer may not be null.");
}
+ this.consumer = consumer;
this.token = new StringBuilder();
try {
- this.parser = createSax2Parser();
+ this.parser = createSax2Parser(false, false, false, null);
} catch (final SAXException | ParserConfigurationException e) {
throw new OrthographyException(e);
}
- this.parser.setContentHandler(this);
- this.parser.setErrorHandler(this);
- this.consumer = consumer;
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-22 16:33:33
|
Revision: 12110
http://sourceforge.net/p/foray/code/12110
Author: victormote
Date: 2021-11-22 16:33:31 +0000 (Mon, 22 Nov 2021)
Log Message:
-----------
Rename some parser classes for consistency and clarity.
Modified Paths:
--------------
trunk/foray/foray-app/src/main/java/org/foray/app/Options.java
trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java
Added Paths:
-----------
trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
Removed Paths:
-------------
trunk/foray/foray-core/src/main/java/org/foray/core/ConfigurationParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/config/ConfigParser.java
Modified: trunk/foray/foray-app/src/main/java/org/foray/app/Options.java
===================================================================
--- trunk/foray/foray-app/src/main/java/org/foray/app/Options.java 2021-11-22 16:22:34 UTC (rev 12109)
+++ trunk/foray/foray-app/src/main/java/org/foray/app/Options.java 2021-11-22 16:33:31 UTC (rev 12110)
@@ -28,7 +28,7 @@
package org.foray.app;
-import org.foray.core.ConfigurationParser;
+import org.foray.core.ForayConfigParser;
import org.foray.core.ForayException;
import org.foray.core.OutputConfig;
import org.foray.core.SessionConfig;
@@ -111,7 +111,7 @@
return;
}
try {
- final ConfigurationParser reader = new ConfigurationParser(userConfigUrl, this.sessionConfig,
+ final ForayConfigParser reader = new ForayConfigParser(userConfigUrl, this.sessionConfig,
this.renderConfig);
reader.parseDocument();
} catch (final ForayException e) {
Deleted: trunk/foray/foray-core/src/main/java/org/foray/core/ConfigurationParser.java
===================================================================
--- trunk/foray/foray-core/src/main/java/org/foray/core/ConfigurationParser.java 2021-11-22 16:22:34 UTC (rev 12109)
+++ trunk/foray/foray-core/src/main/java/org/foray/core/ConfigurationParser.java 2021-11-22 16:33:31 UTC (rev 12110)
@@ -1,262 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * 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.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.core;
-
-import org.foray.common.Configuration;
-import org.foray.common.ConfigurationException;
-import org.foray.common.xml.SaxParser;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.XMLReader;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-
-import javax.xml.parsers.SAXParserFactory;
-
-/**
- * SAX2 Handler which retrieves the configuration information and stores them
- * in Configuration.
- * Normally this class doesn't need to be accessed directly.
- */
-public class ConfigurationParser extends SaxParser {
-
- /** Public ID of the FOray configuration DTD. */
- public static final String FORAY_CONFIG_DTD_PUBLIC_ID = "-//FOray//DTD FOray Configuration V0.1//EN";
-
- /** Constant indicating that the current status of the parser is outside
- * of either key or value. */
- private static final int OUT = 0;
-
- /** Constant indicating that the current status of the parser is inside
- * a key element. */
- private static final int IN_KEY = 2;
-
- /** Constant indicating that the current status of the parser is inside
- * a value element. */
- private static final int IN_VALUE = 4;
-
- /** The current status of the parser, one of {@link #OUT}, {@link #IN_KEY},
- * or {@link #IN_VALUE}. */
- private int status = ConfigurationParser.OUT;
-
- /** The session configuration into which the configuration file is being
- * parsed. */
- private SessionConfig sessionConfig;
-
- /** The output configuration into which the configuration file is being
- * parsed. */
- private Configuration outputConfig;
-
- /** The current key being processed. */
- private String key = "";
-
- /** The current value being processed. */
- private String value = "";
-
- /** The location of the configuration file being parsed. This is useful for resolving relative addresses. */
- private URL configUrl;
-
- /**
- * Constructor.
- * @param configUrl The location of the configuration file to be parsed.
- * @param sessionConfig The SessionConfig instance which should be updated
- * with general options found in the configuration file.
- * @param outputConfig The RenderConfig instance which should be updated
- * with renderer-specific options found in the configuration file.
- * file XML that should be parsed.
- * @throws ForayException For null {@code sessionConfig} or null
- * {@code outputConfig}.
- */
- public ConfigurationParser(final URL configUrl, final SessionConfig sessionConfig, final Configuration outputConfig)
- throws ForayException {
- if (configUrl == null) {
- throw new ForayException("Configuration URL is null.");
- }
- if (sessionConfig == null) {
- throw new ForayException("Session Configuration is null.");
- }
- if (outputConfig == null) {
- throw new ForayException("Output Configuration is null.");
- }
- this.configUrl = configUrl;
- this.sessionConfig = sessionConfig;
- this.outputConfig = outputConfig;
- }
-
- /**
- * Parses the encapsulated SAX InputSource and updates the encapsulated
- * Configuration instances accordingly.
- * @throws ForayException If there are errors parsing the input.
- */
- public void parseDocument() throws ForayException {
- final XMLReader parser = createParser();
- try {
- final InputSource inputSource = new InputSource(this.configUrl.openStream());
- parser.parse(inputSource);
- } catch (final SAXException e) {
- if (e.getException() instanceof ForayException) {
- throw (ForayException) e.getException();
- }
- throw new ForayException(e);
- } catch (final IOException e) {
- throw new ForayException(e);
- }
- }
-
- /**
- * Creates a SAX parser.
- * @return The created SAX parser.
- * @throws ForayException For errors during parser creation.
- */
- private XMLReader createParser() throws ForayException {
- try {
- final SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
- spf.setNamespaceAware(true);
- spf.setValidating(true);
- final XMLReader xmlReader = spf.newSAXParser().getXMLReader();
- /* TODO: This is not the right EntityResolver to use. We need to
- * use or create one that can find the configuration parser DTD
- * in a jar file that is part of the distribution. */
- final EntityResolver entityResolver = this.sessionConfig.makeEntityResolver();
- xmlReader.setEntityResolver(entityResolver);
- xmlReader.setContentHandler(this);
- final ErrorHandler errorHandler = new ErrorHandler() {
- public void warning(final SAXParseException exception) throws SAXException {
- throw exception;
- }
- public void error(final SAXParseException exception) throws SAXException {
- throw exception;
- }
- public void fatalError(final SAXParseException exception) throws SAXException {
- throw exception;
- }
- };
- xmlReader.setErrorHandler(errorHandler);
- final EntityResolver resolver = new EntityResolver() {
- public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException,
- IOException {
- if (ConfigurationParser.FORAY_CONFIG_DTD_PUBLIC_ID.equals(publicId)) {
- final InputStream inputStream = ConfigurationParser.class.getResourceAsStream(
- "/org/foray/common/dtds/foray-config.dtd");
- if (inputStream == null) {
- return null;
- }
- return new InputSource(inputStream);
- }
- return null;
- }
- };
- xmlReader.setEntityResolver(resolver);
- return xmlReader;
- } catch (final javax.xml.parsers.ParserConfigurationException e) {
- throw new ForayException(e);
- } catch (final SAXException e) {
- throw new ForayException(e);
- }
- }
-
- @Override
- public void startDocument() {
- }
-
- @Override
- public void startElement(final String uri, final String localName,
- final String qName, final Attributes attributes) {
- if (localName.equals("key")) {
- this.status += ConfigurationParser.IN_KEY;
- return;
- }
- if (localName.equals("value")) {
- this.status += ConfigurationParser.IN_VALUE;
- return;
- }
- if (localName.equals("entry")) {
- return;
- }
- if (localName.equals("foray-config")) {
- return;
- }
- }
-
- @Override
- public void endElement(final String uri, final String localName, final String qName) throws SAXException {
- if (localName.equals("entry")) {
- try {
- this.store(this.key, this.value);
- } catch (final ConfigurationException e) {
- throw new SAXException(e);
- }
- this.status = ConfigurationParser.OUT;
- this.key = "";
- this.value = "";
- } else if (localName.equals("key")) {
- this.status -= ConfigurationParser.IN_KEY;
- } else if (localName.equals("value")) {
- this.status -= ConfigurationParser.IN_VALUE;
- }
- }
-
- @Override
- public void characters(final char[] ch, final int start, final int length) {
- final char characters[] = new char[length];
- System.arraycopy(ch, start, characters, 0, length);
- final String text = new String(characters);
- switch (this.status) {
- case ConfigurationParser.IN_KEY:
- this.key = text;
- break;
- case ConfigurationParser.IN_VALUE:
- this.value = text;
- break;
- }
- }
-
- /**
- * Stores configuration entry into configuration Map according to the role.
- * @param key a string containing the key value for the configuration
- * @param value a string containing the value for the configuration
- * @throws ConfigurationException For errors in {@code value}.
- */
- private void store(final String key, final String value) throws ConfigurationException {
- // Try the SessionConfig first.
- if (this.sessionConfig.parseOption(this.configUrl, key, value, SessionConfig.PRECEDENCE_CONFIG_FILE)) {
- return;
- }
- // Now try the OutputConfig.
- this.outputConfig.parseOption(this.configUrl, key, value, SessionConfig.PRECEDENCE_CONFIG_FILE);
- }
-
-}
Copied: trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java (from rev 12085, trunk/foray/foray-core/src/main/java/org/foray/core/ConfigurationParser.java)
===================================================================
--- trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java (rev 0)
+++ trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java 2021-11-22 16:33:31 UTC (rev 12110)
@@ -0,0 +1,262 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * 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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.core;
+
+import org.foray.common.Configuration;
+import org.foray.common.ConfigurationException;
+import org.foray.common.xml.SaxParser;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.xml.parsers.SAXParserFactory;
+
+/**
+ * SAX2 Handler which retrieves the configuration information and stores them
+ * in Configuration.
+ * Normally this class doesn't need to be accessed directly.
+ */
+public class ForayConfigParser extends SaxParser {
+
+ /** Public ID of the FOray configuration DTD. */
+ public static final String FORAY_CONFIG_DTD_PUBLIC_ID = "-//FOray//DTD FOray Configuration V0.1//EN";
+
+ /** Constant indicating that the current status of the parser is outside
+ * of either key or value. */
+ private static final int OUT = 0;
+
+ /** Constant indicating that the current status of the parser is inside
+ * a key element. */
+ private static final int IN_KEY = 2;
+
+ /** Constant indicating that the current status of the parser is inside
+ * a value element. */
+ private static final int IN_VALUE = 4;
+
+ /** The current status of the parser, one of {@link #OUT}, {@link #IN_KEY},
+ * or {@link #IN_VALUE}. */
+ private int status = ForayConfigParser.OUT;
+
+ /** The session configuration into which the configuration file is being
+ * parsed. */
+ private SessionConfig sessionConfig;
+
+ /** The output configuration into which the configuration file is being
+ * parsed. */
+ private Configuration outputConfig;
+
+ /** The current key being processed. */
+ private String key = "";
+
+ /** The current value being processed. */
+ private String value = "";
+
+ /** The location of the configuration file being parsed. This is useful for resolving relative addresses. */
+ private URL configUrl;
+
+ /**
+ * Constructor.
+ * @param configUrl The location of the configuration file to be parsed.
+ * @param sessionConfig The SessionConfig instance which should be updated
+ * with general options found in the configuration file.
+ * @param outputConfig The RenderConfig instance which should be updated
+ * with renderer-specific options found in the configuration file.
+ * file XML that should be parsed.
+ * @throws ForayException For null {@code sessionConfig} or null
+ * {@code outputConfig}.
+ */
+ public ForayConfigParser(final URL configUrl, final SessionConfig sessionConfig, final Configuration outputConfig)
+ throws ForayException {
+ if (configUrl == null) {
+ throw new ForayException("Configuration URL is null.");
+ }
+ if (sessionConfig == null) {
+ throw new ForayException("Session Configuration is null.");
+ }
+ if (outputConfig == null) {
+ throw new ForayException("Output Configuration is null.");
+ }
+ this.configUrl = configUrl;
+ this.sessionConfig = sessionConfig;
+ this.outputConfig = outputConfig;
+ }
+
+ /**
+ * Parses the encapsulated SAX InputSource and updates the encapsulated
+ * Configuration instances accordingly.
+ * @throws ForayException If there are errors parsing the input.
+ */
+ public void parseDocument() throws ForayException {
+ final XMLReader parser = createParser();
+ try {
+ final InputSource inputSource = new InputSource(this.configUrl.openStream());
+ parser.parse(inputSource);
+ } catch (final SAXException e) {
+ if (e.getException() instanceof ForayException) {
+ throw (ForayException) e.getException();
+ }
+ throw new ForayException(e);
+ } catch (final IOException e) {
+ throw new ForayException(e);
+ }
+ }
+
+ /**
+ * Creates a SAX parser.
+ * @return The created SAX parser.
+ * @throws ForayException For errors during parser creation.
+ */
+ private XMLReader createParser() throws ForayException {
+ try {
+ final SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
+ spf.setNamespaceAware(true);
+ spf.setValidating(true);
+ final XMLReader xmlReader = spf.newSAXParser().getXMLReader();
+ /* TODO: This is not the right EntityResolver to use. We need to
+ * use or create one that can find the configuration parser DTD
+ * in a jar file that is part of the distribution. */
+ final EntityResolver entityResolver = this.sessionConfig.makeEntityResolver();
+ xmlReader.setEntityResolver(entityResolver);
+ xmlReader.setContentHandler(this);
+ final ErrorHandler errorHandler = new ErrorHandler() {
+ public void warning(final SAXParseException exception) throws SAXException {
+ throw exception;
+ }
+ public void error(final SAXParseException exception) throws SAXException {
+ throw exception;
+ }
+ public void fatalError(final SAXParseException exception) throws SAXException {
+ throw exception;
+ }
+ };
+ xmlReader.setErrorHandler(errorHandler);
+ final EntityResolver resolver = new EntityResolver() {
+ public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException,
+ IOException {
+ if (ForayConfigParser.FORAY_CONFIG_DTD_PUBLIC_ID.equals(publicId)) {
+ final InputStream inputStream = ForayConfigParser.class.getResourceAsStream(
+ "/org/foray/common/dtds/foray-config.dtd");
+ if (inputStream == null) {
+ return null;
+ }
+ return new InputSource(inputStream);
+ }
+ return null;
+ }
+ };
+ xmlReader.setEntityResolver(resolver);
+ return xmlReader;
+ } catch (final javax.xml.parsers.ParserConfigurationException e) {
+ throw new ForayException(e);
+ } catch (final SAXException e) {
+ throw new ForayException(e);
+ }
+ }
+
+ @Override
+ public void startDocument() {
+ }
+
+ @Override
+ public void startElement(final String uri, final String localName,
+ final String qName, final Attributes attributes) {
+ if (localName.equals("key")) {
+ this.status += ForayConfigParser.IN_KEY;
+ return;
+ }
+ if (localName.equals("value")) {
+ this.status += ForayConfigParser.IN_VALUE;
+ return;
+ }
+ if (localName.equals("entry")) {
+ return;
+ }
+ if (localName.equals("foray-config")) {
+ return;
+ }
+ }
+
+ @Override
+ public void endElement(final String uri, final String localName, final String qName) throws SAXException {
+ if (localName.equals("entry")) {
+ try {
+ this.store(this.key, this.value);
+ } catch (final ConfigurationException e) {
+ throw new SAXException(e);
+ }
+ this.status = ForayConfigParser.OUT;
+ this.key = "";
+ this.value = "";
+ } else if (localName.equals("key")) {
+ this.status -= ForayConfigParser.IN_KEY;
+ } else if (localName.equals("value")) {
+ this.status -= ForayConfigParser.IN_VALUE;
+ }
+ }
+
+ @Override
+ public void characters(final char[] ch, final int start, final int length) {
+ final char characters[] = new char[length];
+ System.arraycopy(ch, start, characters, 0, length);
+ final String text = new String(characters);
+ switch (this.status) {
+ case ForayConfigParser.IN_KEY:
+ this.key = text;
+ break;
+ case ForayConfigParser.IN_VALUE:
+ this.value = text;
+ break;
+ }
+ }
+
+ /**
+ * Stores configuration entry into configuration Map according to the role.
+ * @param key a string containing the key value for the configuration
+ * @param value a string containing the value for the configuration
+ * @throws ConfigurationException For errors in {@code value}.
+ */
+ private void store(final String key, final String value) throws ConfigurationException {
+ // Try the SessionConfig first.
+ if (this.sessionConfig.parseOption(this.configUrl, key, value, SessionConfig.PRECEDENCE_CONFIG_FILE)) {
+ return;
+ }
+ // Now try the OutputConfig.
+ this.outputConfig.parseOption(this.configUrl, key, value, SessionConfig.PRECEDENCE_CONFIG_FILE);
+ }
+
+}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java 2021-11-22 16:22:34 UTC (rev 12109)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java 2021-11-22 16:33:31 UTC (rev 12110)
@@ -30,7 +30,7 @@
import org.foray.common.Environment;
import org.foray.common.url.classpath.Handler;
-import org.foray.font.config.ConfigParser;
+import org.foray.font.config.FontConfigParser;
import org.foray.font.config.RegisteredFont;
import org.foray.font.config.RegisteredFontFamily;
import org.foray.font.config.RegisteredFontFamilyMember;
@@ -680,8 +680,8 @@
*/
private void readFontConfig(final InputStream inputStream) throws FontException {
final InputSource source = new InputSource(inputStream);
- final ConfigParser parser =
- new ConfigParser(this, source);
+ final FontConfigParser parser =
+ new FontConfigParser(this, source);
parser.start();
if (this.hasFatalConfigurationError) {
throw new FontException("Font Configuration has fatal error(s).");
Deleted: trunk/foray/foray-font/src/main/java/org/foray/font/config/ConfigParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/config/ConfigParser.java 2021-11-22 16:22:34 UTC (rev 12109)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/config/ConfigParser.java 2021-11-22 16:33:31 UTC (rev 12110)
@@ -1,1022 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * 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.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.font.config;
-
-import org.foray.common.AxslDtdUtil;
-import org.foray.common.url.UrlFactory;
-import org.foray.common.xml.SaxParser;
-import org.foray.font.FontServer4a;
-
-import org.axsl.font.Font;
-import org.axsl.font.FontException;
-import org.axsl.ps.GlyphList;
-import org.axsl.ps.PsEncoding;
-import org.axsl.ps.PsException;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXNotSupportedException;
-import org.xml.sax.XMLReader;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Stack;
-import java.util.StringTokenizer;
-
-import javax.activation.DataSource;
-import javax.activation.URLDataSource;
-import javax.xml.parsers.SAXParserFactory;
-
-/**
- * SAX2 Handler which retrieves the font configuration information and stores it in a {@link FontServer4a} instance.
- * Normally this class doesn't need to be accessed directly.
- */
-public class ConfigParser extends SaxParser {
-
- /** Stateful variable tracking which RegisteredFontFamily is currently
- * being parsed. */
- private RegisteredFontFamily currentFontFamily = null;
-
- /**
- * Counter for registering fonts which haven't been given an id. It will
- * be reset at the beginning of each font-family. The font name will be the
- * name of the font family + "Member" + counter. Starting at 1 because it
- * is more natural for humans (the name may appear in error messages).
- */
- private int fontIdCounter = 1;
-
- /** Stateful variable tracking which FontFamilyMember is currently
- * being parsed. */
- private transient FontFamilyMember currentFontFamilyMember = null;
-
- /** The current "simulate-small-caps" value. */
- private transient String currentSimulateSmallCaps = null;
-
- /** The current "encoding" value. */
- private transient String currentEncoding = null;
-
- /** Stateful stack of the font-group elements.
- * If the contents are empty, we are not inside any font-group element.
- * Otherwise, the bottom of the stack contains grand-ancestor of any
- * other items in the stack. */
- private Stack<FontGroup> fontGroupStack = new Stack<FontGroup>();
-
- /** Stateful variable tracking the current base directory. */
- private URL currentXMLBase = null;
-
- /** Stateful variable tracking the current embed directive. */
- private Font.Embedding currentEmbed = Font.Embedding.NONE;
-
- /** Stateful variable tracking the previous base directory. currentXMLBase
- * will be overriden when parsing a font-family element. */
- private URL previousXMLBase = null;
-
- /** Stateful variable tracking the previous embed directive. currentEmbed
- * will be overriden when parsing a font-family element. */
- private Font.Embedding previousEmbed = Font.Embedding.NONE;
-
- /** The "xml:base" attribute, if any, that was parsed from the root
- * axsl-font-config element. */
- private String parsedRootXMLBase;
-
- /** The "embed" attribute, if any, that was parsed from the root
- * axsl-font-config element. */
- private String parsedRootEmbed;
-
- /** The InputSource encapsulating the configuration file. */
- private InputSource filename;
-
- /** The parent FontServer. */
- private FontServer4a fontServer;
-
- /** Map containing the parsed parameters. The key is a String containing the
- * value to be transformed, and the value is a String containing the value
- * that should be transformed to. */
- private Map<String, String> parameters = new HashMap<String, String>();
-
- /** The XML parser's Locator instance, used to indicate line and column
- * numbers in user messages. */
- private Locator locator;
-
- /** Map of GlyphList instances that have already been registered.
- * The key is a String with the GlyphList name, and the value is the GlyphList instance. */
- private Map<String, GlyphList> glyphListMap = new HashMap<String, GlyphList>();
-
- /** A map of all of the encodings that have already been parsed.
- * The key to the map is a String containing the name of the encoding. The value is the Encoding instance.
- */
- private Map<String, PsEncoding> encodingsMap = new HashMap<String, PsEncoding>();
-
- /*
- * Register the URLStreamHandler for classpath: URLs. This has to be done
- * only once, hence a static statement.
- */
- static {
- org.foray.common.url.classpath.Handler.register();
- }
-
- /**
- * Constructor.
- * @param server The parent font server.
- * @param filename The file which contains the configuration information
- * to be parsed.
- */
- public ConfigParser(final FontServer4a server,
- final InputSource filename) {
- this.fontServer = server;
- this.filename = filename;
- try {
- this.currentXMLBase = UrlFactory.createURL("file", null, ".");
- } catch (final MalformedURLException e) {
- /* This shouldn't fail, but if it does, there isn't much that can
- * be done. */
- getLogger().error(e.getMessage());
- }
- }
-
- /**
- * Parses the configuration file.
- * @throws FontException For errors during parsing.
- */
- public void start() throws FontException {
- final XMLReader parser = createParser();
- /* Turn on validation if it is available. */
- try {
- parser.setFeature("http://xml.org/sax/features/validation", true);
- } catch (final SAXNotRecognizedException e1) {
- logError("Parser does not recognize validation.");
- } catch (final SAXNotSupportedException e1) {
- logError("Parser unable to validate font-configuration.");
- }
- parser.setContentHandler(this);
- final EntityResolver resolver = AxslDtdUtil.getEntityResolver();
- parser.setEntityResolver(resolver);
-
- try {
- parser.parse(this.filename);
- } catch (final SAXException e) {
- if (e.getException() instanceof FontException) {
- throw (FontException) e.getException();
- }
- throw new FontException(e);
- } catch (final IOException e) {
- throw new FontException(e);
- }
- }
-
- /**
- * Creates a SAX parser for parsing the configuration file.
- * @return The created SAX parser.
- * @throws FontException For errors creating or configuring the parser.
- */
- private XMLReader createParser() throws FontException {
- try {
- final SAXParserFactory spf =
- javax.xml.parsers.SAXParserFactory.newInstance();
- spf.setNamespaceAware(true);
- final XMLReader xmlReader = spf.newSAXParser().getXMLReader();
- final EntityResolver entityResolver = this.fontServer
- .getEntityResolver();
- xmlReader.setEntityResolver(entityResolver);
- getLogger().debug("Font Config: Using "
- + xmlReader.getClass().getName() + " as SAX2 Parser");
- return xmlReader;
- } catch (final javax.xml.parsers.ParserConfigurationException e) {
- throw new FontException(e);
- } catch (final org.xml.sax.SAXException e) {
- throw new FontException(e);
- }
- }
-
- /**
- * {@inheritDoc}
- * Recognizes each valid element and parses its attributes.
- */
- @Override
- public void startElement(final String uri, final String localName,
- final String qName, final Attributes attributes) {
- if (localName.equals("axsl-font-config")) {
- parseElementRoot(attributes);
- return;
- }
- if (localName.equals("glyph-list")) {
- parseElementGlyphList(attributes);
- return;
- }
- if (localName.equals("encoding")) {
- parseElementEncoding(attributes);
- return;
- }
- if (localName.equals("font-group")) {
- parseElementFontGroup(attributes);
- return;
- }
- if (localName.equals("font")) {
- parseElementFont(attributes);
- return;
- }
- if (localName.equals("family-member")) {
- parseElementFamilyMember(attributes);
- return;
- }
- if (localName.equals("server")) {
- parseElementServer(attributes);
- return;
- }
- if (localName.equals("font-family")) {
- parseElementFontFamily(attributes);
- return;
- }
- if (localName.equals("font-family-alias")) {
- parseElementFontFamilyAlias(attributes);
- return;
- }
- if (localName.equals("parameter")) {
- parseElementParameter(attributes);
- return;
- }
- // Make sure user knows about unknown tag
- logError("Unknown tag in font configuration " + "file: " + localName);
- }
-
- /**
- * Parses the "axsl-font-config" element.
- * @param attributes The raw parsed attributes.
- */
- private void parseElementRoot(final Attributes attributes) {
- this.parsedRootXMLBase = attributes.getValue("xml:base");
- this.parsedRootEmbed = attributes.getValue("embed");
- }
-
- /**
- * Parses the "font-family-alias" element.
- * @param attributes The raw parsed attributes.
- */
- private void parseElementFontFamilyAlias(final Attributes attributes) {
- final String alias = attributes.getValue("alias");
- final String family = attributes.getValue("family");
- if (alias == null
- || alias.equals("")
- || family == null
- || family.equals("")) {
- logError("font-family-alias entry invalid. " + "Ignored.");
- } else {
- try {
- this.fontServer.registerFontFamilyAlias(alias, family);
- } catch (final FontException e) {
- logError(e.getMessage());
- }
- }
- }
-
- /**
- * Parses a "parameter" element.
- * @param attributes The raw parsed attributes.
- */
- private void parseElementParameter(final Attributes attributes) {
- final String key = attributes.getValue("key");
- String value = attributes.getValue("value");
- final String fromEnvironment = attributes.getValue("from-environment");
- if (! validParameter(key, value, fromEnvironment)) {
- return;
- }
- if (fromEnvironment != null
- && ! fromEnvironment.equals("")) {
- /* Check the Java environment first. */
- value = System.getProperty(fromEnvironment);
- if (value == null
- || value.equals("")) {
- /* Try the o/s environment next. */
- value = System.getenv(fromEnvironment);
- }
- if (value == null
- && "FONT_BASE_DIRECTORY".equals(fromEnvironment)) {
- final URL baseFontUrl = this.fontServer.getBaseFontURL();
- if (baseFontUrl != null) {
- value = baseFontUrl.toExternalForm();
- getLogger().debug("FONT_BASE_DIRECTORY interpreted as: "
- + value);
- }
- }
- }
- if (value == null) {
- logWarning("Environment variable '" + fromEnvironment
- + "' not found.");
- } else {
- this.parameters.put(key, value);
- }
- }
-
- /**
- * Indicates whether a given parameter is valid.
- * @param key The parameter key.
- * @param value The parameter value.
- * @param fromEnvironment The from-environment value.
- * @return True iff the parameter is valid.
- */
- private boolean validParameter(final String key, final String value,
- final String fromEnvironment) {
- if (key == null
- || key.equals("")) {
- logError("<parameter> element requires 'key' attribute. Ignored.");
- return false;
- }
- final boolean valueNull =
- value == null
- || value.equals("");
- final boolean fromEnvironmentNull =
- fromEnvironment == null
- || fromEnvironment.equals("");
- if (valueNull && fromEnvironmentNull) {
- logError("<parameter> element requires either 'value' or "
- + "'from-environment' attribute. Ignored.");
- return false;
- }
- if (! valueNull && ! fromEnvironmentNull) {
- logError("<parameter> element cannot have both a 'value' and a "
- + "'from-environment' attribute. Ignored.");
- return false;
- }
- return true;
- }
-
- /**
- * Parses a "font-family" element.
- * @param attributes The raw parsed attributes.
- */
- private void parseElementFontFamily(final Attributes attributes) {
- /* Save the current state for later restoration. */
- this.previousXMLBase = this.currentXMLBase;
- this.previousEmbed = this.currentEmbed;
-
- final String name = attributes.getValue("name");
- if (name == null
- || name.equals("")) {
- logError("\"name\" attribute required for font-family. Ignored.");
- return;
- }
- try {
- this.currentFontFamily
- = this.fontServer.registerFontFamily2(name);
- } catch (final FontException e) {
- /* Log a warning. */
- logWarning(e.getMessage());
- /* Use the existing font family if you can. */
- this.currentFontFamily = this.fontServer.getRegisteredFontFamily(
- name);
- return;
- }
- this.currentSimulateSmallCaps = attributes.getValue(
- "simulate-small-caps");
- this.currentEncoding = attributes.getValue("encoding");
- final String embed = attributes.getValue("embed");
- if (embed != null && !embed.equals("")) {
- this.currentEmbed = Font.Embedding.valueOf(embed.toUpperCase());
- }
- final String xmlBase = replaceParameters(attributes.getValue(
- "xml:base"));
- if (xmlBase != null && !xmlBase.equals("")) {
- try {
- /* Update the current xml base. */
- this.currentXMLBase = UrlFactory.createURL(this.previousXMLBase,
- xmlBase);
- } catch (final MalformedURLException e) {
- logError("Unable to create URL from "
- + this.previousXMLBase.getPath()
- + " AND " + xmlBase);
- }
- }
- this.fontIdCounter = 0;
- }
-
- /**
- * Parses a "server" element.
- * @param attributes The raw parsed attributes.
- */
- private void parseElementServer(final Attributes attributes) {
- if (attributes.getValue("setup-free-standing-fonts")
- .equalsIgnoreCase("true")) {
- this.fontServer.setUsingFreeStandingFonts(true);
- } else {
- this.fontServer.setUsingFreeStandingFonts(false);
- }
- if (attributes.getValue("setup-system-fonts")
- .equalsIgnoreCase("true")) {
- this.fontServer.setUsingSystemFonts(true);
- } else {
- this.fontServer.setUsingSystemFonts(false);
- }
- }
-
- /**
- * Parses the "family-member" element.
- * @param attributes The raw parsed attributes.
- */
- private void parseElementFamilyMember(final Attributes attributes) {
- if (this.currentFontFamily == null) {
- return;
- }
- final String style = attributes.getValue("style");
- final String weight = attributes.getValue("weight");
- final String variant = attributes.getValue("variant");
- final String stretch = attributes.getValue("stretch");
- String simulateSmallCaps = attributes.getValue("simulate-small-caps");
- if (simulateSmallCaps == null) {
- /* Inherit the value from font-family. */
- simulateSmallCaps = this.currentSimulateSmallCaps;
- }
- final String simulateOblique = attributes.getValue("simulate-oblique");
- final String simulateBackslant = attributes.getValue(
- "simulate-backslant");
- String encodingName = attributes.getValue("encoding");
- if (encodingName == null) {
- /* Inherit the value from font-family. */
- encodingName = this.currentEncoding;
- }
- PsEncoding encoding = null;
- if (encodingName != null) {
- encoding = this.fontServer.getPsServer().getPredefinedEncoding(encodingName);
- }
- final String[] simulateStretch
- = new String[RegisteredFontFamilyMember.QTY_SIMULATED_STRETCH];
- simulateStretch[RegisteredFontFamilyMember.SIMULATE_ULTRA_CONDENSED_INDEX]
- = attributes.getValue("simulate-ultra-condensed");
- simulateStretch[RegisteredFontFamilyMember.SIMULATE_EXTRA_CONDENSED_INDEX]
- = attributes.getValue("simulate-extra-condensed");
- simulateStretch[RegisteredFontFamilyMember.SIMULATE_CONDENSED_INDEX]
- = attributes.getValue("simulate-condensed");
- simulateStretch[RegisteredFontFamilyMember.SIMULATE_SEMI_CONDENSED_INDEX]
- = attributes.getValue("simulate-semi-condensed");
- simulateStretch[RegisteredFontFamilyMember.SIMULATE_SEMI_EXPANDED_INDEX]
- = attributes.getValue("simulate-semi-expanded");
- simulateStretch[RegisteredFontFamilyMember.SIMULATE_EXPANDED_INDEX]
- = attributes.getValue("simulate-expanded");
- simulateStretch[RegisteredFontFamilyMember.SIMULATE_EXTRA_EXPANDED_INDEX]
- = attributes.getValue("simulate-extra-expanded");
- simulateStretch[RegisteredFontFamilyMember.SIMULATE_ULTRA_EXPANDED_INDEX]
- = attributes.getValue("simulate-ultra-expanded");
- this.currentFontFamilyMember = new FontFamilyMember(
- encoding,
- style,
- weight,
- variant,
- stretch,
- simulateSmallCaps,
- simulateOblique,
- simulateBackslant,
- simulateStretch);
- this.fontIdCounter++;
- }
-
- /**
- * Parses a "font" element.
- * @param attributes The raw parsed attributes.
- */
- private void parseElementFont(final Attributes attributes) {
- final String fontFile = replaceParameters(attributes.getValue(
- "font-file"));
- String fontID = attributes.getValue("id");
- final String metricsFile = replaceParameters(attributes.getValue(
- "metrics-file"));
- final String collectionID = attributes.getValue("collection-id");
- final String embedString = attributes.getValue("embed");
- Font.Embedding embed = null;
- if (embedString == null
- || embedString.equals("")) {
- /* If not set, inherit it. */
- embed = this.currentEmbed;
- } else {
- embed = Font.Embedding.valueOf(replaceParameters(embedString.toLowerCase()).toUpperCase());
- }
- final String systemName = attributes.getValue("system-name");
- String refID = attributes.getValue("ref");
-
- DataSource fontFileSource = null;
- if (fontFile != null) {
- try {
- final URL fontFileURL = UrlFactory.createURL(this.currentXMLBase,
- fontFile);
- fontFileSource = new URLDataSource(fontFileURL);
- } catch (final MalformedURLException e) {
- this.logError("Malformed URL in font configuration:\n"
- + " " + fontFile);
- /* TODO: Just invalidate this one font and warn the user instead
- * of invalidating everything. */
- this.fontServer.setFatalConfigurationError(true);
- }
- }
-
- DataSource metricsFileSource = null;
- if (metricsFile != null) {
- try {
- final URL metricsFileURL = UrlFactory.createURL(this.currentXMLBase,
- metricsFile);
- metricsFileSource = new URLDataSource(metricsFileURL);
- } catch (final MalformedURLException e) {
- this.logError("Malformed URL in font configuration:\n"
- + " " + metricsFile);
- /* TODO: Just invalidate this one font and warn the user instead
- * of invalidating everything. */
- this.fontServer.setFatalConfigurationError(true);
- }
- }
-
- /* TODO vh: check that if ref is declared, it is alone */
- if (this.currentFontFamilyMember == null) {
- return; // Font declared outside a family-member element
- }
- if (refID == null || refID.equals("")) {
- if (fontID == null || fontID.equals("")) {
- final StringBuilder name = new StringBuilder(
- this.currentFontFamily.getName());
- if (this.currentFontFamilyMember.weight != null) {
- name.append(this.currentFontFamilyMember.weight);
- }
- if (this.currentFontFamilyMember.style != null) {
- name.append(this.currentFontFamilyMember.style);
- }
- name.append(this.fontIdCounter);
- fontID = name.toString();
- }
- try {
- this.fontServer.registerFont(fontID, fontFileSource,
- metricsFileSource, collectionID, embed, systemName);
- } catch (final FontException e) {
- this.logError(e.getMessage());
- return;
- }
- refID = fontID;
- }
- final RegisteredFont registeredFont = this.fontServer.getRegisteredFont(
- refID);
- if (registeredFont == null) {
- logWarning("Font is not registered: " + refID);
- return;
- }
- try {
- this.currentFontFamily.registerFontDesc(registeredFont,
- this.currentFontFamilyMember.encoding,
- this.currentFontFamilyMember.style,
- this.currentFontFamilyMember.weight,
- this.currentFontFamilyMember.variant,
- this.currentFontFamilyMember.stretch,
- this.currentFontFamilyMember.simulateSmallCaps,
- this.currentFontFamilyMember.simulateOblique,
- this.currentFontFamilyMember.simulateBackslant,
- this.currentFontFamilyMember.simulateStretch);
- } catch (final FontException e) {
- logWarning(e.getMessage());
- }
- }
-
- /**
- * Parses a "font-group" element.
- * @param attributes The raw parsed attributes.
- */
- private void parseElementFontGroup(final Attributes attributes) {
- final String label = attributes.getValue("label");
- final String embed = replaceParameters(attributes.getValue("embed"));
- final String xmlBase = replaceParameters(attributes.getValue(
- "xml:base"));
- final FontGroup fontGroup = new FontGroup(label, this.currentEmbed, this.currentXMLBase);
- /* Push the FontGroup onto the stack. */
- this.fontGroupStack.push(fontGroup);
- if (embed == null || embed.equals("")) {
- // Do nothing. The inherited embed status will continue to operate.
- } else {
- this.currentEmbed = Font.Embedding.valueOf(embed.toUpperCase());
- }
- if (xmlBase == null || xmlBase.equals("")) {
- return;
- }
- try {
- /* Update the current xml base. */
- this.currentXMLBase = UrlFactory.createURL(this.currentXMLBase,
- xmlBase);
- } catch (final MalformedURLException e) {
- logError("Unable to create URL from "
- + this.currentXMLBase.getPath()
- + " AND " + xmlBase);
- }
- }
-
- /**
- * {@inheritDoc}
- * Wraps up parsing for elements that need to be finalized.
- */
- @Override
- public void endElement(final String uri, final String localName,
- final String qName) {
- if (localName.equals("axsl-font-config")) {
- return;
- }
- if (localName.equals("server")) {
- configureRootAttributes();
- return;
- }
- if (localName.equals("font")) {
- return;
- }
- if (localName.equals("font-family")) {
- this.currentSimulateSmallCaps = null;
- this.currentEncoding = null;
- this.currentXMLBase = this.previousXMLBase;
- this.currentEmbed = this.previousEmbed;
- return;
- }
- if (localName.equals("font-description")) {
- return;
- }
- if (localName.equals("family-member")) {
- this.currentFontFamilyMember = null;
- return;
- }
- if (localName.equals("font-family-alias")) {
- return;
- }
- if (localName.equals("font-group")) {
- /* Pop the font-group stack. */
- final FontGroup fontGroup = this.fontGroupStack.pop();
- if (fontGroup != null) {
- /* Restore the state to what it was when the font-group
- * started. */
- this.currentXMLBase = fontGroup.getPreviousXMLBase();
- this.currentEmbed = fontGroup.getPreviousEmbed();
- }
- return;
- }
- }
-
- /**
- * Configures the root, default attributes.
- */
- private void configureRootAttributes() {
- /* Don't configure attributes of the root element until the
- * parameters have all been parsed. */
- if (this.parsedRootEmbed != null
- && ! this.parsedRootEmbed.equals("")) {
- this.currentEmbed = Font.Embedding.valueOf(this.replaceParameters(this.parsedRootEmbed).toUpperCase());
- }
- /* Let the value from FontServer override the value in the font-config
- * file. */
- if (this.fontServer.getBaseFontURL() != null) {
- this.currentXMLBase = this.fontServer.getBaseFontURL();
- return;
- }
- if (this.parsedRootXMLBase == null
- || this.parsedRootXMLBase.equals("")) {
- /* Set it to the current directory. */
- final String directory = System.getProperty("user.dir");
- final File dir = new File(directory);
- try {
- if (dir.isDirectory()) {
- this.currentXMLBase = dir.toURI().toURL();
- } else {
- this.currentXMLBase = UrlFactory.createURL(directory);
- }
- } catch (final MalformedURLException e1) {
- logError("Cannot create URL from current directory: "
- + directory);
- }
- return;
- }
- try {
- final String modifiedBase = replaceParameters(
- this.parsedRootXMLBase);
- this.currentXMLBase = UrlFactory.createURL(modifiedBase);
- } catch (final MalformedURLException e) {
- logError("Cannot create URL from: " + this.parsedRootXMLBase);
- }
- }
-
- /**
- * Parses the "encoding" element.
- * @param attributes The element attributes.
- */
- private void parseElementEncoding(final Attributes attributes) {
- final String name = attributes.getValue("name");
- if (name == null
- || name.equals("")) {
- logError("Attribute \"name\" required for element \"encoding\".");
- return;
- }
- PsEncoding encoding = this.fontServer.getPsServer().getPredefinedEncoding(name);
- if (encoding != null) {
- logError("Encoding already defined: " + name);
- return;
- }
- final String encodingFile = attributes.getValue("file");
- if (encodingFile == null
- || encodingFile.equals("")) {
- logError("Attribute \"file\" required for "
- + "element \"encoding\".");
- return;
- }
- final URL url;
- try {
- url = UrlFactory.createURL(encodingFile);
- } catch (final MalformedURLException e) {
- logError("Unable to create URL: " + encodingFile);
- return;
- }
- final InputStream input;
- try {
- input = url.openStream();
- } catch (final IOException e1) {
- logError("Unable to read: " + encodingFile);
- return;
- }
- final String parseColumn = attributes.getValue("column-to-parse");
- if (parseColumn == null
- || parseColumn.equals("")) {
- logError("Attribute \"column-to-parse\" "
- + "required for element \"encoding\".");
- return;
- }
- final int columnNumber = Integer.parseInt(parseColumn);
- final String radixString = attributes.getValue("radix");
- if (radixString == null
- || parseColumn.equals("")) {
- logError("Attribute \"radix\" "
- + "required for element \"encoding\".");
- return;
- }
- final int radix = Integer.parseInt(radixString);
- final List<String> glyphList = new ArrayList<String>();
- final String glyphListString = attributes.getValue("glyph-lists");
- final StringTokenizer tokenizer = new StringTokenizer(glyphListString);
- while (tokenizer.hasMoreTokens()) {
- final String token = tokenizer.nextToken();
- glyphList.add(token);
- }
- try {
- encoding = this.fontServer.getPsServer().parseEncodingVector(name, input, columnNumber, radix, glyphList);
- this.encodingsMap.put(name, encoding);
- } catch (final IOException e) {
- logError("Error parsing Encoding Vector \"" + name + "\": " + e.getMessage());
- } catch (final PsException e) {
- logError("Error parsing Encoding Vector \"" + name + "\": " + e.getMessage());
- }
- }
-
- /**
- * Parses the "glyph-list" element.
- * @param attributes The element attributes.
- */
- private void parseElementGlyphList(final Attributes attributes) {
- final String name = attributes.getValue("name");
- if (name == null
- || name.equals("")) {
- logError("Attribute \"name\" required for "
- + "element \"glyph-list\".");
- return;
- }
- final String file = attributes.getValue("file");
- if (file == null
- || file.equals("")) {
- logError("Attribute \"file\" required for "
- + "element \"glyph-list\".");
- return;
- }
- final URL url;
- try {
- url = UrlFactory.createURL(file);
- } catch (final MalformedURLException e) {
- logError("Unable to create URL: " + file);
- return;
- }
- final InputStream input;
- try {
- input = url.openStream();
- } catch (final IOException e1) {
- logError("Unable to read: " + file);
- return;
- }
- try {
- final GlyphList glyphList = this.fontServer.getPsServer().parseGlyphList(name, input);
- this.glyphListMap.put(name, glyphList);
- } catch (final IOException e) {
- logError("Error parsing \"" + file + "\": " + e.getMessage());
- } catch (final PsException e) {
- logError("Error parsing \"" + file + "\": " + e.getMessage());
- }
- }
-
- /**
- * Replace parameters with their replacement values.
- * @param input The input String to be searched and replaced.
- * @return The input after parameter replacement.
- */
- private String replaceParameters(final String input) {
- if (input == null) {
- return null;
- }
- final StringBuilder output = new StringBuilder(input);
- for (String key : this.parameters.keySet()) {
- final String value = this.parameters.get(key);
- boolean anyChanges = true;
- while (anyChanges) {
- /* Regex would be more fun here, but throws exceptions on some
- * platforms, possibly because of slashes in the input. */
- anyChanges = false;
- final int startIndex = output.indexOf("{" + key + "}");
- if (startIndex > -1) {
- anyChanges = true;
- output.replace(startIndex, key.length() + 2, value);
- }
- }
- }
- return output.toString();
- }
-
- /**
- * Sets the document locator for this parser.
- * @param locator The new locator.
- */
- public void setDocumentLocator(final Locator locator) {
- this.locator = locator;
- }
-
- /**
- * Logs a warning to the logger.
- * @param message The warning message.
- */
- private void logWarning(final String message) {
- getLogger().warn(message + "\n" + getContextMessage());
- }
-
- /**
- * Logs an error to the logger.
- * @param message The error message.
- */
- private void logError(final String message) {
- getLogger().error(message + "\n" + getContextMessage());
- }
-
- /**
- * Provides a formatted string showing the current locator context, which
- * is useful in user messages to indicate where in the document a condition
- * arose.
- * @return The formatted context message.
- */
- private String getContextMessage() {
- if (this.locator == null) {
- return null;
- }
- return " Context: " + this.locator.getSystemId() + "\n"
- + " (Line " + this.locator.getLineNumber() + ", Column "
- + this.locator.getColumnNumber() + ")";
- }
-
- /**
- * Inner class for storing font-group items.
- */...
[truncated message content] |
|
From: <vic...@us...> - 2021-11-22 16:22:37
|
Revision: 12109
http://sourceforge.net/p/foray/code/12109
Author: victormote
Date: 2021-11-22 16:22:34 +0000 (Mon, 22 Nov 2021)
Log Message:
-----------
Rename parser classes for clarity.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DictionaryResource.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionarySerializer.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/WordChecker.java
Added Paths:
-----------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserText.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java
Removed Paths:
-------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyConfigParser.java
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DictionaryResource.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DictionaryResource.java 2021-11-22 16:12:21 UTC (rev 12108)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DictionaryResource.java 2021-11-22 16:22:34 UTC (rev 12109)
@@ -30,7 +30,7 @@
import org.foray.common.resource.ResourceLocation;
import org.foray.common.resource.ResourceLocationUrl;
-import org.foray.orthography.util.DictionaryParserXml;
+import org.foray.orthography.util.DictionaryParser;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -135,7 +135,7 @@
}
getLogger().debug("Parsing {}", rawResource.toExternalForm());
- final DictionaryParserXml parser = new DictionaryParserXml();
+ final DictionaryParser parser = new DictionaryParser();
parser.setLogDictionaryProblems(true);
SegmentDictionary dictionary = null;
try {
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java 2021-11-22 16:12:21 UTC (rev 12108)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java 2021-11-22 16:22:34 UTC (rev 12109)
@@ -38,7 +38,7 @@
import org.foray.common.url.UrlFactory;
import org.foray.orthography.util.NatLangParser;
import org.foray.orthography.util.NaturalLanguage;
-import org.foray.orthography.util.OrthographyConfigParser;
+import org.foray.orthography.util.OrthographyParser;
import org.axsl.common.i18n.Language;
import org.axsl.orthography.OrthographyException;
@@ -105,7 +105,7 @@
}
final InputSource inputSource = new InputSource(inputStream);
- final OrthographyConfigParser parser = new OrthographyConfigParser(this, inputSource);
+ final OrthographyParser parser = new OrthographyParser(this, inputSource);
parser.start();
}
}
Deleted: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-22 16:12:21 UTC (rev 12108)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-22 16:22:34 UTC (rev 12109)
@@ -1,185 +0,0 @@
-/*
- * Copyright 2019 The FOray Project.
- * http://www.foray.org
- *
- * 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.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.orthography.util;
-
-import org.foray.orthography.SegmentDictionary;
-import org.foray.orthography.StringWord;
-import org.foray.orthography.StringWordSegment;
-import org.foray.orthography.StringWordSegmentFactory;
-import org.foray.orthography.StringWordSegmentLatin1Factory;
-import org.foray.orthography.StringWordSegmentUtf16Factory;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Parses a list of words into a SegmentDictionary.
- * @see DictionaryParserXml for a parser for similar data in XML format.
- */
-public class DictionaryParser {
-
- /** The logger. */
- private Logger logger = LoggerFactory.getLogger(this.getClass());
-
- /** The character in the input file that marks a soft hyphen. */
- private char inputSoftHyphenChar = '-';
-
- /** The character in the input file that marks a hard hyphen. */
- private char inputHardHyphenChar = '=';
-
- /** The character that should actually be used in the word content as the hard hyphen characters. */
- private char actualHardHyphenChar = '-';
-
- /* TODO: The following List and contents are oriented toward English & Western European languages.
- * They should be moved to the orthography configuration. */
- /** The list of string factories that should be tried when building the strings. */
- private List<StringWordSegmentFactory<?>> stringFactories = new ArrayList<StringWordSegmentFactory<?>>();
- {
- stringFactories.add(new StringWordSegmentLatin1Factory());
- stringFactories.add(new StringWordSegmentUtf16Factory());
- }
-
- /**
- * Parses a given InputStream and places the parsed information into the dictionary.
- * @param inputStream The input stream to parse.
- * @param description Description of {@literal inputStream}, useful for user messages.
- * @throws IOException For IO errors during parsing.
- * @return The parsed dictionary.
- */
- public SegmentDictionary parse(final InputStream inputStream, final String description) throws IOException {
- logger.info("Begin dictionary word list parsing: " + description);
-
- final InputStreamReader isReader = new InputStreamReader(inputStream);
- final BufferedReader reader = new BufferedReader(isReader);
- final Set<StringWordSegment> segmentSet = new HashSet<StringWordSegment>();
- /** The data structure containing the dictionary words. */
- final Map<String, StringWord> wordMap = new HashMap<String, StringWord>();
-
- /* Reusable builder. */
- final StringBuilder builder = new StringBuilder(100);
- /* Reusable segment list. */
- final List<StringWordSegment> segmentList = new ArrayList<StringWordSegment>(100);
-
- int lineNumber = 0;
- String inputLine = reader.readLine();
- while (inputLine != null) {
- lineNumber ++;
- builder.delete(0, builder.length());
- segmentList.clear();
-
- if (inputLine.length() < 1) {
- inputLine = reader.readLine();
- continue;
- }
- if (inputLine.charAt(0) == '#') {
- inputLine = reader.readLine();
- continue;
- }
- final int charIndex = inputLine.indexOf('#');
- if (charIndex > -1) {
- inputLine = inputLine.substring(0, charIndex - 1);
- }
- inputLine = inputLine.trim();
- int inputLineIndex = 0;
- while (inputLineIndex < inputLine.length()) {
- final char theChar = inputLine.charAt(inputLineIndex);
- if (theChar == this.inputSoftHyphenChar) {
- if (builder.length() < 1) {
- throw new IllegalStateException("0-length syllable on line: " + lineNumber);
- }
- final StringWordSegment wordSegment = createSegment(builder.toString());
- segmentList.add(wordSegment);
- segmentSet.add(wordSegment);
- builder.delete(0, builder.length());
- } else {
- if (theChar == this.inputHardHyphenChar) {
- builder.append(this.actualHardHyphenChar);
- } else {
- builder.append(theChar);
- }
- }
- inputLineIndex ++;
- }
- if (builder.length() > 0) {
- final StringWordSegment wordSegment = createSegment(builder.toString());
- segmentList.add(wordSegment);
- segmentSet.add(wordSegment);
- }
- if (segmentList.size() < 1) {
- throw new IllegalStateException("0-syllable word on line: " + lineNumber);
- }
- final StringWordSegment[] segments = new StringWordSegment[segmentList.size()];
- segmentList.toArray(segments);
- final StringWord word = new StringWord(0, segments);
- wordMap.put(word.getActualContent().toString(), word);
- inputLine = reader.readLine();
- }
- logger.info("End dictionary word list parsing.");
- logger.info("Qty of unique word segments parsed: " + segmentSet.size());
- logger.info("Qty of words parsed: " + wordMap.size());
- final StringWordSegment[] uniqueWordSegments = new StringWordSegment[segmentSet.size()];
- segmentSet.toArray(uniqueWordSegments);
- Arrays.sort(uniqueWordSegments);
- final SegmentDictionary dictionary = new SegmentDictionary(uniqueWordSegments);
- for (Map.Entry<String, StringWord> entry : wordMap.entrySet()) {
- dictionary.addWord(entry.getKey(), entry.getValue());
- }
- dictionary.optimize();
- return dictionary;
- }
-
- /**
- * Create a pseudo-string instance.
- * @param string The String instance to replace.
- * @return A new instance of StringWordSegment encapsulating the content in {@code string}.
- */
- private StringWordSegment createSegment(final String string) {
- for (int index = 0; index < this.stringFactories.size(); index ++) {
- final StringWordSegmentFactory<?> factory = this.stringFactories.get(index);
- final StringWordSegment newString = factory.makeInstance(string);
- if (newString != null) {
- return newString;
- }
- }
- return null;
- }
-
-}
Copied: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java (from rev 12108, trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java)
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java (rev 0)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2021-11-22 16:22:34 UTC (rev 12109)
@@ -0,0 +1,575 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * 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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.orthography.util;
+
+import org.foray.common.AxslDtdUtil;
+import org.foray.common.i18n.WritingSystem4a;
+import org.foray.common.primitive.StringUtils;
+import org.foray.common.xml.SaxParser;
+import org.foray.orthography.AmbiguousWord;
+import org.foray.orthography.PosUtils;
+import org.foray.orthography.SegmentDictionary;
+import org.foray.orthography.SegmentDictionaryWord;
+import org.foray.orthography.StringWord;
+import org.foray.orthography.StringWordSegment;
+import org.foray.orthography.StringWordSegmentFactory;
+import org.foray.orthography.StringWordSegmentLatin1Factory;
+import org.foray.orthography.StringWordSegmentUtf16Factory;
+
+import org.axsl.orthography.Word.PartOfSpeech;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.XMLReader;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+/**
+ * Parses an axsl-dictionary XML document into a SegmentDictionary.
+ * @see DictionaryParserText for a parser for similar data in simple text format.
+ */
+public class DictionaryParser extends SaxParser {
+
+ private class DictionaryElement {
+
+ /** The orthography for this dictionary. */
+ private WritingSystem4a orthography;
+
+ /** The soft hyphen char for this dictionary. */
+ private char softHyphenChar;
+
+ /** The hard hyphen char for this dictionary. */
+ private char hardHyphenChar;
+ }
+
+ /** Constant used to initialize string builders. */
+ private static final int MAX_EXPECTED_WORD_LENGTH = 100;
+
+ /** Constant used to initialize segment collections. */
+ private static final int MAX_EXPECTED_QTY_SEGMENTS = 100;
+
+ /** The character that should actually be used in the word content as the hard hyphen characters. */
+ private char actualHardHyphenChar = '-';
+
+ /** The list of dictionaries that have been parsed by this parser. */
+ private List<SegmentDictionary> parsedDictionaries = new ArrayList<SegmentDictionary>();
+
+ /** The current dictionary being parsed. */
+ private DictionaryElement currentDictionary;
+
+ /** The current word content being parsed. */
+ private StringWordSegment[] currentSegments;
+
+ /** The current parts of speech being parsed. */
+ private int currentPartsOfSpeech;
+
+ /* TODO: The following List and contents are oriented toward English & Western European languages.
+ * They should be moved to the orthography configuration. */
+ /** The list of string factories that should be tried when building the strings. */
+ private List<StringWordSegmentFactory<?>> stringFactories = new ArrayList<StringWordSegmentFactory<?>>();
+ {
+ stringFactories.add(new StringWordSegmentLatin1Factory());
+ stringFactories.add(new StringWordSegmentUtf16Factory());
+ }
+
+ /** The set of all segments that have been parsed by this parser. */
+ private Set<StringWordSegment> segmentSet = new HashSet<StringWordSegment>();
+
+ /** The data structure containing the dictionary words. */
+ private Map<String, StringWord> wordMap = new HashMap<String, StringWord>();
+
+ /** The data structure containing ambiguous words. */
+ private Map<String, List<StringWord>> ambiguousWordMap = new HashMap<String, List<StringWord>>();
+
+ /** Reusable builder. */
+ private StringBuilder builder = new StringBuilder(MAX_EXPECTED_WORD_LENGTH);
+
+ /** Reusable segment list. */
+ private List<StringWordSegment> segmentList = new ArrayList<StringWordSegment>(MAX_EXPECTED_QTY_SEGMENTS);
+
+ /** Buffer in which to capture parsed element content. */
+ private StringBuilder charBuffer = new StringBuilder(MAX_EXPECTED_WORD_LENGTH);
+
+ /** Indicates whether this parser should log dictionary problems. */
+ private boolean logDictionaryProblems = false;
+
+ /** The last parsed word, used to verify alphabetical order. */
+ private String lastWord = StringUtils.EMPTY_STRING;
+
+ /**
+ * Parses a given InputStream and places the parsed information into the dictionary.
+ * @param inputSource The input source to parse.
+ * @return The parsed dictionaries.
+ * @throws IOException For IO errors during parsing.
+ * @throws ParserConfigurationException For errors during parser configuration.
+ * @throws SAXException For errors found by the SAX parser.
+ */
+ public List<SegmentDictionary> parse(final InputSource inputSource)
+ throws IOException, SAXException, ParserConfigurationException {
+ getLogger().info("Begin dictionary word list parsing: " + inputSource.getSystemId());
+
+ final XMLReader parser = createParser();
+ if (parser != null) {
+ parser.setContentHandler(this);
+ parser.parse(inputSource);
+ }
+ cleanup();
+
+ final StringWordSegment[] uniqueWordSegments = new StringWordSegment[segmentSet.size()];
+ segmentSet.toArray(uniqueWordSegments);
+ Arrays.sort(uniqueWordSegments);
+ final SegmentDictionary dictionary = new SegmentDictionary(uniqueWordSegments);
+
+ for (Map.Entry<String, StringWord> entry : this.wordMap.entrySet()) {
+ dictionary.addWord(entry.getKey(), entry.getValue());
+ }
+ for (Map.Entry<String, List<StringWord>> entry : this.ambiguousWordMap.entrySet()) {
+ final List<StringWord> list = entry.getValue();
+ final SegmentDictionaryWord[] sdWords = new SegmentDictionaryWord[list.size()];
+ for (int index = 0; index < list.size(); index ++) {
+ final StringWord stringWord = list.get(index);
+ sdWords[index] = new SegmentDictionaryWord(stringWord.getPartsOfSpeech(), dictionary, stringWord);
+ }
+ final AmbiguousWord<SegmentDictionaryWord> ambWord = new AmbiguousWord<SegmentDictionaryWord>(sdWords);
+ dictionary.addAmbiguousWord(entry.getKey(), ambWord);
+ }
+
+ dictionary.optimize();
+ this.parsedDictionaries.add(dictionary);
+ return this.parsedDictionaries;
+ }
+
+ private XMLReader createParser() throws SAXException, ParserConfigurationException {
+ final SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
+ spf.setNamespaceAware(true);
+ final XMLReader parser = spf.newSAXParser().getXMLReader();
+
+ final EntityResolver resolver = AxslDtdUtil.getEntityResolver();
+ parser.setEntityResolver(resolver);
+
+ /* Bind the LexicalHandler to the XMLReader if possible. */
+ try {
+ parser.setProperty("http://xml.org/sax/properties/lexical-handler", this);
+ } catch (final SAXNotSupportedException e1) {
+ getLogger().error("Parser does not support LexicalHandler.");
+ }
+
+ /* Bind the DeclHandler to the XMLReader if possible. */
+ try {
+ parser.setProperty("http://xml.org/sax/properties/declaration-handler", this);
+ } catch (final SAXNotSupportedException e) {
+ getLogger().error("Parser does not support Declaration Handler.");
+ }
+
+ /* Turn on namespace-prefixes so that we get the namespace declarations
+ * returned with other attributes and can therefore write them out
+ * along with them. */
+ try {
+ parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
+ } catch (final SAXNotRecognizedException e1) {
+ getLogger().error("Parser does not recognize the \"namespace-prefixes\" feature.");
+ } catch (final SAXNotSupportedException e1) {
+ getLogger().error("Parser unable to supply namespace-prefixes.");
+ }
+
+ try {
+ parser.setFeature("http://xml.org/sax/features/validation", true);
+ } catch (final SAXNotRecognizedException e1) {
+ getLogger().error("Parser does not recognize the \"validation\" feature.");
+ } catch (final SAXNotSupportedException e1) {
+ getLogger().error("Parser unable to validate.");
+ }
+
+ /* Turn on "notify-char-refs" feature.
+ * Sadly, this only works with Xerces.
+ * This feature, or something like it is very important.
+ * Without it, character entities get transformed into characters
+ * without notification.
+ * When notified, we can (and do) ignore the transformed characters
+ * and use the character entities instead.
+ * We do NOT want to change the user's content. */
+// try {
+// parser.setFeature("http://apache.org/xml/features/scanner/notify-char-refs", true);
+// } catch (final SAXNotRecognizedException e) {
+// /* Make this a fatal error. */
+// this.logger.error("Parser cannot report character entities. Aborting.");
+// cleanup();
+// return null;
+// } catch (final SAXNotSupportedException e) {
+// /* Make this a fatal error. */
+// this.logger.error("Parser cannot report character entities. Aborting.");
+// cleanup();
+// return null;
+// }
+ return parser;
+ }
+
+ /**
+ * Finalize the processing.
+ */
+ private void cleanup() {
+ }
+
+ @Override
+ public void startDocument() throws SAXException {
+ }
+
+
+ @Override
+ public void endDocument() throws SAXException {
+ }
+
+
+ @Override
+ public void characters(final char ch[], final int start, final int length) throws SAXException {
+ this.charBuffer.append(ch, start, length);
+ }
+
+ @Override
+ public void startElement(final String uri, final String localName, final String qName, final Attributes attributes)
+ throws SAXException {
+ switch(localName) {
+ case "w": {
+ this.currentPartsOfSpeech = 0;
+ break;
+ }
+ case "t": {
+ break;
+ }
+ case "noun": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.NOUN);
+ this.currentPartsOfSpeech =
+ PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.NOUN, attributes);
+ break;
+ }
+ case "pronoun": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.PRONOUN);
+ this.currentPartsOfSpeech =
+ PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.PRONOUN, attributes);
+ break;
+ }
+ case "verb": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.VERB);
+ this.currentPartsOfSpeech =
+ PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.VERB, attributes);
+ break;
+ }
+ case "adjective": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.ADJECTIVE);
+ this.currentPartsOfSpeech =
+ PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.ADJECTIVE, attributes);
+ break;
+ }
+ case "adverb": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.ADVERB);
+ this.currentPartsOfSpeech =
+ PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.ADVERB, attributes);
+ break;
+ }
+ case "preposition": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.PREPOSITION);
+ this.currentPartsOfSpeech =
+ PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.PREPOSITION, attributes);
+ break;
+ }
+ case "conjunction": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.CONJUNCTION);
+ this.currentPartsOfSpeech =
+ PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.CONJUNCTION, attributes);
+ break;
+ }
+ case "determiner": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.DETERMINER);
+ this.currentPartsOfSpeech =
+ PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.DETERMINER, attributes);
+ break;
+ }
+ case "interjection": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.INTERJECTION);
+ this.currentPartsOfSpeech =
+ PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.INTERJECTION, attributes);
+ break;
+ }
+ case "past-participle": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.PAST_PARTICIPLE);
+ this.currentPartsOfSpeech = PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech,
+ PartOfSpeech.PAST_PARTICIPLE, attributes);
+ break;
+ }
+ case "present-participle": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech,
+ PartOfSpeech.PRESENT_PARTICIPLE);
+ this.currentPartsOfSpeech = PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech,
+ PartOfSpeech.PRESENT_PARTICIPLE, attributes);
+ break;
+ }
+ case "future-participle": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech,
+ PartOfSpeech.FUTURE_PARTICIPLE);
+ this.currentPartsOfSpeech = PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech,
+ PartOfSpeech.FUTURE_PARTICIPLE, attributes);
+ break;
+ }
+ case "cardinal": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.CARDINAL);
+ this.currentPartsOfSpeech =
+ PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.CARDINAL, attributes);
+ break;
+ }
+ case "ordinal": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.ORDINAL);
+ this.currentPartsOfSpeech =
+ PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.ORDINAL, attributes);
+ break;
+ }
+ case "word-group": break;
+ case "axsl-dictionary": {
+ this.currentDictionary = new DictionaryElement();
+ final String language = attributes.getValue(StringUtils.EMPTY_STRING, "language");
+ final String country = attributes.getValue(StringUtils.EMPTY_STRING, "country");
+ final String script = attributes.getValue(StringUtils.EMPTY_STRING, "script");
+ this.currentDictionary.orthography = WritingSystem4a.find(language, script, country);
+ getLogger().info("Begin dictionary word list parsing: " + this.currentDictionary.orthography.toString());
+ final String soft = attributes.getValue(StringUtils.EMPTY_STRING, "soft-hyphen-char");
+ if (soft.length() != 1) {
+ throw new SAXException("Attribute soft-hyphen-char must have exactly one char.");
+ }
+ this.currentDictionary.softHyphenChar = soft.charAt(0);
+ final String hard = attributes.getValue(StringUtils.EMPTY_STRING, "hard-hyphen-char");
+ if (hard.length() != 1) {
+ throw new SAXException("Attribute hard-hyphen-char must have exactly one char.");
+ }
+ this.currentDictionary.hardHyphenChar = hard.charAt(0);
+ break;
+ }
+ case "axsl-dictionaries": break;
+ case "phrase": break;
+ case "vf": break;
+ case "lemma": break;
+ case "regular-root": break;
+ case "remote-past": break;
+ case "past": break;
+ case "present": break;
+ case "future": break;
+ case "remote-future": break;
+ case "perfect": break;
+ case "imperfect": break;
+ case "indicative": break;
+ case "subjunctive": break;
+ case "conditional": break;
+ case "person-1st": break;
+ case "person-2nd": break;
+ case "person-3rd": break;
+ case "person-any": break;
+ case "singular": break;
+ case "plural": break;
+ case "pluralizable": break;
+ case "number-any": break;
+ case "masculine": break;
+ case "feminine": break;
+ case "neuter": break;
+ case "gender-any": break;
+ case "convertible-to-possessive": break;
+ case "possessive": break;
+ case "extensible": break;
+ default: {
+ throw new IllegalStateException("Unknown element started: " + localName + ", " + getLocationString());
+ }
+ }
+ }
+
+
+ @Override
+ public void endElement(final String uri, final String localName, final String qName) throws SAXException {
+ switch(localName) {
+ case "w": {
+ final StringWord word = new StringWord(this.currentPartsOfSpeech, this.currentSegments);
+ final String actualContent = word.getActualContent().toString();
+ if (this.logDictionaryProblems) {
+ final String actualContentLowercase = actualContent.toLowerCase();
+ if (actualContentLowercase.compareTo(this.lastWord) < 0) {
+ getLogger().warn("Out of alphabetical sequence: " + actualContent + " " + getLocationString());
+ }
+ this.lastWord = actualContentLowercase;
+ }
+
+ /* Look in the ambiguous words first. */
+ if (this.ambiguousWordMap.containsKey(actualContent)) {
+ final List<StringWord> list = this.ambiguousWordMap.get(actualContent);
+ list.add(word);
+ } else {
+ /* See if this is a new ambiguous word. */
+ if (wordMap.containsKey(actualContent)) {
+ final StringWord existingMapEntry = wordMap.remove(actualContent);
+ final List<StringWord> list = new ArrayList<StringWord>();
+ list.add(existingMapEntry);
+ list.add(word);
+ this.ambiguousWordMap.put(actualContent, list);
+ } else {
+ wordMap.put(actualContent, word);
+ }
+ }
+ break;
+ }
+ case "t": {
+ final String inputLine = this.charBuffer.toString().trim();
+ StringUtils.clear(this.charBuffer);
+
+ StringUtils.clear(this.builder);
+ this.segmentList.clear();
+
+ int inputLineIndex = 0;
+ while (inputLineIndex < inputLine.length()) {
+ final char theChar = inputLine.charAt(inputLineIndex);
+ if (theChar == this.currentDictionary.softHyphenChar) {
+ if (builder.length() < 1) {
+ throw new SAXException("0-length syllable on line: " + getLocationString());
+ }
+ final StringWordSegment wordSegment = createSegment(builder.toString());
+ segmentList.add(wordSegment);
+ segmentSet.add(wordSegment);
+ builder.delete(0, builder.length());
+ } else {
+ if (theChar == this.currentDictionary.hardHyphenChar) {
+ builder.append(this.actualHardHyphenChar);
+ } else {
+ builder.append(theChar);
+ }
+ }
+ inputLineIndex ++;
+ }
+ if (builder.length() > 0) {
+ final StringWordSegment wordSegment = createSegment(builder.toString());
+ segmentList.add(wordSegment);
+ segmentSet.add(wordSegment);
+ }
+ if (segmentList.size() < 1) {
+ throw new SAXException("0-syllable word: " + getLocationString());
+ }
+ this.currentSegments = new StringWordSegment[segmentList.size()];
+ segmentList.toArray(this.currentSegments);
+ break;
+ }
+ case "noun": break;
+ case "pronoun": break;
+ case "verb": break;
+ case "adjective": break;
+ case "adverb": break;
+ case "preposition": break;
+ case "conjunction": break;
+ case "determiner": break;
+ case "interjection": break;
+ case "past-participle": break;
+ case "present-participle": break;
+ case "future-participle": break;
+ case "cardinal": break;
+ case "ordinal": break;
+ case "word-group": break;
+ case "axsl-dictionary": {
+ getLogger().info("End parsing for dictionary: " + this.currentDictionary.orthography.toString());
+ getLogger().info("Qty of unique word segments parsed: " + segmentSet.size());
+ getLogger().info("Qty of words parsed: " + wordMap.size());
+ break;
+ }
+ case "axsl-dictionaries": break;
+ case "phrase": break;
+ case "vf": break;
+ case "lemma": break;
+ case "regular-root": break;
+ case "remote-past": break;
+ case "past": break;
+ case "present": break;
+ case "future": break;
+ case "remote-future": break;
+ case "perfect": break;
+ case "imperfect": break;
+ case "indicative": break;
+ case "subjunctive": break;
+ case "conditional": break;
+ case "person-1st": break;
+ case "person-2nd": break;
+ case "person-3rd": break;
+ case "person-any": break;
+ case "singular": break;
+ case "plural": break;
+ case "pluralizable": break;
+ case "number-any": break;
+ case "masculine": break;
+ case "feminine": break;
+ case "neuter": break;
+ case "gender-any": break;
+ case "convertible-to-possessive": break;
+ case "possessive": break;
+ case "extensible": break;
+ default: {
+ throw new IllegalStateException("Unknown element ended: " + localName);
+ }
+ }
+ }
+
+
+ /**
+ * Create a pseudo-string instance.
+ * @param string The String instance to replace.
+ * @return A new instance of StringWordSegment encapsulating the content in {@code string}.
+ */
+ private StringWordSegment createSegment(final String string) {
+ for (int index = 0; index < this.stringFactories.size(); index ++) {
+ final StringWordSegmentFactory<?> factory = this.stringFactories.get(index);
+ final StringWordSegment newString = factory.makeInstance(string);
+ if (newString != null) {
+ return newString;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Sets flag that tells parser to log warnings about problems found in the dictionary input.
+ * @param logDictionaryProblems The logDictionaryProblems to set.
+ */
+ public void setLogDictionaryProblems(final boolean logDictionaryProblems) {
+ this.logDictionaryProblems = logDictionaryProblems;
+ }
+
+}
Copied: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserText.java (from rev 12032, trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java)
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserText.java (rev 0)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserText.java 2021-11-22 16:22:34 UTC (rev 12109)
@@ -0,0 +1,185 @@
+/*
+ * Copyright 2019 The FOray Project.
+ * http://www.foray.org
+ *
+ * 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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.orthography.util;
+
+import org.foray.orthography.SegmentDictionary;
+import org.foray.orthography.StringWord;
+import org.foray.orthography.StringWordSegment;
+import org.foray.orthography.StringWordSegmentFactory;
+import org.foray.orthography.StringWordSegmentLatin1Factory;
+import org.foray.orthography.StringWordSegmentUtf16Factory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Parses a list of words into a SegmentDictionary.
+ * @see DictionaryParser for a parser for similar data in XML format.
+ */
+public class DictionaryParserText {
+
+ /** The logger. */
+ private Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ /** The character in the input file that marks a soft hyphen. */
+ private char inputSoftHyphenChar = '-';
+
+ /** The character in the input file that marks a hard hyphen. */
+ private char inputHardHyphenChar = '=';
+
+ /** The character that should actually be used in the word content as the hard hyphen characters. */
+ private char actualHardHyphenChar = '-';
+
+ /* TODO: The following List and contents are oriented toward English & Western European languages.
+ * They should be moved to the orthography configuration. */
+ /** The list of string factories that should be tried when building the strings. */
+ private List<StringWordSegmentFactory<?>> stringFactories = new ArrayList<StringWordSegmentFactory<?>>();
+ {
+ stringFactories.add(new StringWordSegmentLatin1Factory());
+ stringFactories.add(new StringWordSegmentUtf16Factory());
+ }
+
+ /**
+ * Parses a given InputStream and places the parsed information into the dictionary.
+ * @param inputStream The input stream to parse.
+ * @param description Description of {@literal inputStream}, useful for user messages.
+ * @throws IOException For IO errors during parsing.
+ * @return The parsed dictionary.
+ */
+ public SegmentDictionary parse(final InputStream inputStream, final String description) throws IOException {
+ logger.info("Begin dictionary word list parsing: " + description);
+
+ final InputStreamReader isReader = new InputStreamReader(inputStream);
+ final BufferedReader reader = new BufferedReader(isReader);
+ final Set<StringWordSegment> segmentSet = new HashSet<StringWordSegment>();
+ /** The data structure containing the dictionary words. */
+ final Map<String, StringWord> wordMap = new HashMap<String, StringWord>();
+
+ /* Reusable builder. */
+ final StringBuilder builder = new StringBuilder(100);
+ /* Reusable segment list. */
+ final List<StringWordSegment> segmentList = new ArrayList<StringWordSegment>(100);
+
+ int lineNumber = 0;
+ String inputLine = reader.readLine();
+ while (inputLine != null) {
+ lineNumber ++;
+ builder.delete(0, builder.length());
+ segmentList.clear();
+
+ if (inputLine.length() < 1) {
+ inputLine = reader.readLine();
+ continue;
+ }
+ if (inputLine.charAt(0) == '#') {
+ inputLine = reader.readLine();
+ continue;
+ }
+ final int charIndex = inputLine.indexOf('#');
+ if (charIndex > -1) {
+ inputLine = inputLine.substring(0, charIndex - 1);
+ }
+ inputLine = inputLine.trim();
+ int inputLineIndex = 0;
+ while (inputLineIndex < inputLine.length()) {
+ final char theChar = inputLine.charAt(inputLineIndex);
+ if (theChar == this.inputSoftHyphenChar) {
+ if (builder.length() < 1) {
+ throw new IllegalStateException("0-length syllable on line: " + lineNumber);
+ }
+ final StringWordSegment wordSegment = createSegment(builder.toString());
+ segmentList.add(wordSegment);
+ segmentSet.add(wordSegment);
+ builder.delete(0, builder.length());
+ } else {
+ if (theChar == this.inputHardHyphenChar) {
+ builder.append(this.actualHardHyphenChar);
+ } else {
+ builder.append(theChar);
+ }
+ }
+ inputLineIndex ++;
+ }
+ if (builder.length() > 0) {
+ final StringWordSegment wordSegment = createSegment(builder.toString());
+ segmentList.add(wordSegment);
+ segmentSet.add(wordSegment);
+ }
+ if (segmentList.size() < 1) {
+ throw new IllegalStateException("0-syllable word on line: " + lineNumber);
+ }
+ final StringWordSegment[] segments = new StringWordSegment[segmentList.size()];
+ segmentList.toArray(segments);
+ final StringWord word = new StringWord(0, segments);
+ wordMap.put(word.getActualContent().toString(), word);
+ inputLine = reader.readLine();
+ }
+ logger.info("End dictionary word list parsing.");
+ logger.info("Qty of unique word segments parsed: " + segmentSet.size());
+ logger.info("Qty of words parsed: " + wordMap.size());
+ final StringWordSegment[] uniqueWordSegments = new StringWordSegment[segmentSet.size()];
+ segmentSet.toArray(uniqueWordSegments);
+ Arrays.sort(uniqueWordSegments);
+ final SegmentDictionary dictionary = new SegmentDictionary(uniqueWordSegments);
+ for (Map.Entry<String, StringWord> entry : wordMap.entrySet()) {
+ dictionary.addWord(entry.getKey(), entry.getValue());
+ }
+ dictionary.optimize();
+ return dictionary;
+ }
+
+ /**
+ * Create a pseudo-string instance.
+ * @param string The String instance to replace.
+ * @return A new instance of StringWordSegment encapsulating the content in {@code string}.
+ */
+ private StringWordSegment createSegment(final String string) {
+ for (int index = 0; index < this.stringFactories.size(); index ++) {
+ final StringWordSegmentFactory<?> factory = this.stringFactories.get(index);
+ final StringWordSegment newString = factory.makeInstance(string);
+ if (newString != null) {
+ return newString;
+ }
+ }
+ return null;
+ }
+
+}
Deleted: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java 2021-11-22 16:12:21 UTC (rev 12108)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java 2021-11-22 16:22:34 UTC (rev 12109)
@@ -1,575 +0,0 @@
-/*
- * Copyright 2021 The FOray Project.
- * http://www.foray.org
- *
- * 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.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.orthography.util;
-
-import org.foray.common.AxslDtdUtil;
-import org.foray.common.i18n.WritingSystem4a;
-import org.foray.common.primitive.StringUtils;
-import org.foray.common.xml.SaxParser;
-import org.foray.orthography.AmbiguousWord;
-import org.foray.orthography.PosUtils;
-import org.foray.orthography.SegmentDictionary;
-import org.foray.orthography.SegmentDictionaryWord;
-import org.foray.orthography.StringWord;
-import org.foray.orthography.StringWordSegment;
-import org.foray.orthography.StringWordSegmentFactory;
-import org.foray.orthography.StringWordSegmentLatin1Factory;
-import org.foray.orthography.StringWordSegmentUtf16Factory;
-
-import org.axsl.orthography.Word.PartOfSpeech;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXNotSupportedException;
-import org.xml.sax.XMLReader;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParserFactory;
-
-/**
- * Parses an axsl-dictionary XML document into a SegmentDictionary.
- * @see DictionaryParser for a parser for similar data in simple text format.
- */
-public class DictionaryParserXml extends SaxParser {
-
- private class DictionaryElement {
-
- /** The orthography for this dictionary. */
- private WritingSystem4a orthography;
-
- /** The soft hyphen char for this dictionary. */
- private char softHyphenChar;
-
- /** The hard hyphen char for this dictionary. */
- private char hardHyphenChar;
- }
-
- /** Constant used to initialize string builders. */
- private static final int MAX_EXPECTED_WORD_LENGTH = 100;
-
- /** Constant used to initialize segment collections. */
- private static final int MAX_EXPECTED_QTY_SEGMENTS = 100;
-
- /** The character that should actually be used in the word content as the hard hyphen characters. */
- private char actualHardHyphenChar = '-';
-
- /** The list of dictionaries that have been parsed by this parser. */
- private List<SegmentDictionary> parsedDictionaries = new ArrayList<SegmentDictionary>();
-
- /** The current dictionary being parsed. */
- private DictionaryElement currentDictionary;
-
- /** The current word content being parsed. */
- private StringWordSegment[] currentSegments;
-
- /** The current parts of speech being parsed. */
- private int currentPartsOfSpeech;
-
- /* TODO: The following List and contents are oriented toward English & Western European languages.
- * They should be moved to the orthography configuration. */
- /** The list of string factories that should be tried when building the strings. */
- private List<StringWordSegmentFactory<?>> stringFactories = new ArrayList<StringWordSegmentFactory<?>>();
- {
- stringFactories.add(new StringWordSegmentLatin1Factory());
- stringFactories.add(new StringWordSegmentUtf16Factory());
- }
-
- /** The set of all segments that have been parsed by this parser. */
- private Set<StringWordSegment> segmentSet = new HashSet<StringWordSegment>();
-
- /** The data structure containing the dictionary words. */
- private Map<String, StringWord> wordMap = new HashMap<String, StringWord>();
-
- /** The data structure containing ambiguous words. */
- private Map<String, List<StringWord>> ambiguousWordMap = new HashMap<String, List<StringWord>>();
-
- /** Reusable builder. */
- private StringBuilder builder = new StringBuilder(MAX_EXPECTED_WORD_LENGTH);
-
- /** Reusable segment list. */
- private List<StringWordSegment> segmentList = new ArrayList<StringWordSegment>(MAX_EXPECTED_QTY_SEGMENTS);
-
- /** Buffer in which to capture parsed element content. */
- private StringBuilder charBuffer = new StringBuilder(MAX_EXPECTED_WORD_LENGTH);
-
- /** Indicates whether this parser should log dictionary problems. */
- private boolean logDictionaryProblems = false;
-
- /** The last parsed word, used to verify alphabetical order. */
- private String lastWord = StringUtils.EMPTY_STRING;
-
- /**
- * Parses a given InputStream and places the parsed information into the dictionary.
- * @param inputSource The input source to parse.
- * @return The parsed dictionaries.
- * @throws IOException For IO errors during parsing.
- * @throws ParserConfigurationException For errors during parser configuration.
- * @throws SAXException For errors found by the SAX parser.
- */
- public List<SegmentDictionary> parse(final InputSource inputSource)
- throws IOException, SAXException, ParserConfigurationException {
- getLogger().info("Begin dictionary word list parsing: " + inputSource.getSystemId());
-
- final XMLReader parser = createParser();
- if (parser != null) {
- parser.setContentHandler(this);
- parser.parse(inputSource);
- }
- cleanup();
-
- final StringWordSegment[] uniqueWordSegments = new StringWordSegment[segmentSet.size()];
- segmentSet.toArray(uniqueWordSegments);
- Arrays.sort(uniqueWordSegments);
- final SegmentDictionary dictionary = new SegmentDictionary(uniqueWordSegments);
-
- for (Map.Entry<String, StringWord> entry : this.wordMap.entrySet()) {
- dictionary.addWord(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, List<StringWord>> entry : this.ambiguousWordMap.entrySet()) {
- final List<StringWord> list = entry.getValue();
- final SegmentDictionaryWord[] sdWords = new SegmentDictionaryWord[list.size()];
- for (int index = 0; index < list.size(); index ++) {
- final StringWord stringWord = list.get(index);
- sdWords[index] = new SegmentDictionaryWord(stringWord.getPartsOfSpeech(), dictionary, stringWord);
- }
- final AmbiguousWord<SegmentDictionaryWord> ambWord = new AmbiguousWord<SegmentDictionaryWord>(sdWords);
- dictionary.addAmbiguousWord(entry.getKey(), ambWord);
- }
-
- dictionary.optimize();
- this.parsedDictionaries.add(dictionary);
- return this.parsedDictionaries;
- }
-
- private XMLReader createParser() throws SAXException, ParserConfigurationException {
- final SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
- spf.setNamespaceAware(true);
- final XMLReader parser = spf.newSAXParser().getXMLReader();
-
- final EntityResolver resolver = AxslDtdUtil.getEntityResolver();
- parser.setEntityResolver(resolver);
-
- /* Bind the LexicalHandler to the XMLReader if possible. */
- try {
- parser.setProperty("http://xml.org/sax/properties/lexical-handler", this);
- } catch (final SAXNotSupportedException e1) {
- getLogger().error("Parser does not support LexicalHandler.");
- }
-
- /* Bind the DeclHandler to the XMLReader if possible. */
- try {
- parser.setProperty("http://xml.org/sax/properties/declaration-handler", this);
- } catch (final SAXNotSupportedException e) {
- getLogger().error("Parser does not support Declaration Handler.");
- }
-
- /* Turn on namespace-prefixes so that we get the namespace declarations
- * returned with other attributes and can therefore write them out
- * along with them. */
- try {
- parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
- } catch (final SAXNotRecognizedException e1) {
- getLogger().error("Parser does not recognize the \"namespace-prefixes\" feature.");
- } catch (final SAXNotSupportedException e1) {
- getLogger().error("Parser unable to supply namespace-prefixes.");
- }
-
- try {
- parser.setFeature("http://xml.org/sax/features/validation", true);
- } catch (final SAXNotRecognizedException e1) {
- getLogger().error("Parser does not recognize the \"validation\" feature.");
- } catch (final SAXNotSupportedException e1) {
- getLogger().error("Parser unable to validate.");
- }
-
- /* Turn on "notify-char-refs" feature.
- * Sadly, this only works with Xerces.
- * This feature, or something like it is very important.
- * Without it, character entities get transformed into characters
- * without notification.
- * When notified, we can (and do) ignore the transformed characters
- * and use the character entities instead.
- * We do NOT want to change the user's content. */
-// try {
-// parser.setFeature("http://apache.org/xml/features/scanner/notify-char-refs", true);
-// } catch (final SAXNotRecognizedException e) {
-// /* Make this a fatal error. */
-// this.logger.error("Parser cannot report character entities. Aborting.");
-// cleanup();
-// return null;
-// } catch (final SAXNotSupportedException e) {
-// /* Make this a fatal error. */
-// this.logger.error("Parser cannot report character entities. Aborting.");
-// cleanup();
-// return null;
-// }
- return parser;
- }
-
- /**
- * Finalize the processing.
- */
- private void cleanup() {
- }
-
- @Override
- public void startDocument() throws SAXException {
- }
-
-
- @Override
- public void endDocument() throws SAXException {
- }
-
-
- @Override
- public void characters(final char ch[], final int start, final int length) throws SAXException {
- this.charBuffer.append(ch, start, length);
- }
-
- @Override
- public void startElement(final String uri, final String localName, final String qName, final Attributes attributes)
- throws SAXException {
- switch(localName) {
- case "w": {
- this.currentPartsOfSpeech = 0;
- break;
- }
- case "t": {
- break;
- }
- case "noun": {
- this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.NOUN);
- this.currentPartsOfSpeech =
- PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.NOUN, attributes);
- break;
- }
- case "pronoun": {
- this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.PRONOUN);
- this.currentPartsOfSpeech =
- PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.PRONOUN, attributes);
- break;
- }
- case "verb": {
- this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.VERB);
- this.currentPartsOfSpeech =
- PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.VERB, attributes);
- break;
- }
- case "adjective": {
- this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.ADJECTIVE);
- this.currentPartsOfSpeech =
- PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.ADJECTIVE, attributes);
- break;
- }
- case "adverb": {
- this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.ADVERB);
- this.currentPartsOfSpeech =
- PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.ADVERB, attributes);
- break;
- }
- case "preposition": {
- this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.PREPOSITION);
- this.currentPartsOfSpeech =
- PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.PREPOSITION, attributes);
- break;
- }
- case "conjunction": {
- this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.CONJUNCTION);
- this.currentPartsOfSpeech =
- PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.CONJUNCTION, attributes);
- break;
- }
- case "determiner": {
- this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.DETERMINER);
- this.currentPartsOfSpeech =
- PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.DETERMINER, attributes);
- break;
- }
- case "interjection": {
- this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.INTERJECTION);
- this.currentPartsOfSpeech =
- PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.INTERJECTION, attributes);
- break;
- }
- case "past-participle": {
- this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.PAST_PARTICIPLE);
- this.currentPartsOfSpeech =...
[truncated message content] |
|
From: <vic...@us...> - 2021-11-22 16:12:22
|
Revision: 12108
http://sourceforge.net/p/foray/code/12108
Author: victormote
Date: 2021-11-22 16:12:21 +0000 (Mon, 22 Nov 2021)
Log Message:
-----------
Partially conform to aXSL changes: Add more part-of-speech qualifiers.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PosUtils.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyConfigParser.java
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PosUtils.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PosUtils.java 2021-11-21 20:41:03 UTC (rev 12107)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PosUtils.java 2021-11-22 16:12:21 UTC (rev 12108)
@@ -289,7 +289,7 @@
* @param value The attribute value.
* @return The qualifier signified by the parameters.
*/
- public static PosQualifier parseQualifier(final String attribute, final String value) {
+ static PosQualifier parseQualifier(final String attribute, final String value) {
if (attribute == null) {
return null;
}
@@ -299,7 +299,7 @@
case "singular": return PosQualifier.SINGULAR;
case "plural": return PosQualifier.PLURAL;
case "pluralizable": return PosQualifier.PLURALIZABLE;
- case "both": return PosQualifier.NUMBER_BOTH;
+ case "both": return null; //PosQualifier.NUMBER_BOTH;
// default: invalidQualifierValue(attribute, value);
default: return null;
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java 2021-11-21 20:41:03 UTC (rev 12107)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java 2021-11-22 16:12:21 UTC (rev 12108)
@@ -387,6 +387,16 @@
case "vf": break;
case "lemma": break;
case "regular-root": break;
+ case "remote-past": break;
+ case "past": break;
+ case "present": break;
+ case "future": break;
+ case "remote-future": break;
+ case "perfect": break;
+ case "imperfect": break;
+ case "indicative": break;
+ case "subjunctive": break;
+ case "conditional": break;
case "person-1st": break;
case "person-2nd": break;
case "person-3rd": break;
@@ -506,6 +516,16 @@
case "vf": break;
case "lemma": break;
case "regular-root": break;
+ case "remote-past": break;
+ case "past": break;
+ case "present": break;
+ case "future": break;
+ case "remote-future": break;
+ case "perfect": break;
+ case "imperfect": break;
+ case "indicative": break;
+ case "subjunctive": break;
+ case "conditional": break;
case "person-1st": break;
case "person-2nd": break;
case "person-3rd": break;
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-21 20:41:03 UTC (rev 12107)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyConfigParser.java 2021-11-22 16:12:21 UTC (rev 12108)
@@ -462,6 +462,16 @@
case "vf": return;
case "lemma": return;
case "regular-root": return;
+ case "remote-past": break;
+ case "past": break;
+ case "present": break;
+ case "future": break;
+ case "remote-future": break;
+ case "perfect": break;
+ case "imperfect": break;
+ case "indicative": break;
+ case "subjunctive": break;
+ case "conditional": break;
case "person-1st": return;
case "person-2nd": return;
case "person-3rd": return;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-21 20:41:06
|
Revision: 12107
http://sourceforge.net/p/foray/code/12107
Author: victormote
Date: 2021-11-21 20:41:03 +0000 (Sun, 21 Nov 2021)
Log Message:
-----------
Adjust Dictionary parser and POS utilities to match changes to parts-of-speech.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PosUtils.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/PosUtilsTests.java
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PosUtils.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PosUtils.java 2021-11-21 16:53:51 UTC (rev 12106)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PosUtils.java 2021-11-21 20:41:03 UTC (rev 12107)
@@ -45,44 +45,63 @@
/** Return value indicating that the requested qualifier is a valid qualifier in this context, but that there is no
* index for it, i.e. we have chosen not to store it. */
- private static final int VALID_QUALIFIER_WITH_NO_INDEX = -1;
+ public static final int VALID_QUALIFIER_WITH_NO_INDEX = -1;
- /** Return valud indicating that the requested qualifier is not valid in this context, i.e. does not apply to the
+ /** Return value indicating that the requested qualifier is not valid in this context, i.e. does not apply to the
* corresponding part of speech. */
- private static final int INVALID_QUALIFIER = -2;
+ public static final int INVALID_QUALIFIER = -2;
/** Index to the flag indicating whether the noun is pluralizable. */
- private static final int NOUN_PLURALIZABLE_INDEX = 12;
+ public static final int NOUN_PLURALIZABLE_INDEX = 28;
/** Index to the flag indicating whether the noun is convertible to a possessive. */
- private static final int NOUN_CONVERTIBLE_TO_POSSESSIVE_INDEX = 13;
+ public static final int NOUN_CONVERTIBLE_TO_POSSESSIVE_INDEX = 29;
/** Index to the flag indicating whether the verb is a regular verb. */
- private static final int REGULAR_VERB_INDEX = 14;
+ public static final int REGULAR_VERB_INDEX = 30;
/** Index to the flag indicating whether the word is a regular adjective. */
- private static final int ADJ_EXTENSIBLE_INDEX = 15;
+ public static final int ADJ_EXTENSIBLE_INDEX = 31;
/** Mask suitable for accumulating multiple parts of speech in one char. */
- private static final char[] MASKS = new char[16];
+ private static final int[] MASKS = new int[32];
static {
- MASKS[PartOfSpeech.NOUN.getIndex()] = 0x0001; // Index 0. 1
- MASKS[PartOfSpeech.PRONOUN.getIndex()] = 0x0002; // Index 1. 2
- MASKS[PartOfSpeech.VERB.getIndex()] = 0x0004; // Index 2. 4
- MASKS[PartOfSpeech.ADJECTIVE.getIndex()] = 0x0008; // Index 3. 8
- MASKS[PartOfSpeech.ADVERB.getIndex()] = 0x0010; // Index 4. 16
- MASKS[PartOfSpeech.PREPOSITION.getIndex()] = 0x0020; // Index 5. 32
- MASKS[PartOfSpeech.CONJUNCTION.getIndex()] = 0x0040; // Index 6. 64
- MASKS[PartOfSpeech.DETERMINER.getIndex()] = 0x0080; // Index 7. 128
- MASKS[PartOfSpeech.INTERJECTION.getIndex()] = 0x0100; // Index 8. 256
- MASKS[PartOfSpeech.CARDINAL.getIndex()] = 0x0200; // Index 9. 512
- MASKS[PartOfSpeech.ORDINAL.getIndex()] = 0x0400; // Index 10. 1,024
+ MASKS[PartOfSpeech.NOUN.getIndex()] = 2 >> 1; // Index 0. 1
+ MASKS[PartOfSpeech.PRONOUN.getIndex()] = 2; // Index 1. 2
+ MASKS[PartOfSpeech.VERB.getIndex()] = 2 << 1; // Index 2. 4
+ MASKS[PartOfSpeech.ADJECTIVE.getIndex()] = 2 << 2; // Index 3. 8
+ MASKS[PartOfSpeech.ADVERB.getIndex()] = 2 << 3; // Index 4. 16
+ MASKS[PartOfSpeech.PREPOSITION.getIndex()] = 2 << 4; // Index 5. 32
+ MASKS[PartOfSpeech.CONJUNCTION.getIndex()] = 2 << 5; // Index 6. 64
+ MASKS[PartOfSpeech.DETERMINER.getIndex()] = 2 << 6; // Index 7. 128
+ MASKS[PartOfSpeech.INTERJECTION.getIndex()] = 2 << 7; // Index 8. 256
+ MASKS[PartOfSpeech.PAST_PARTICIPLE.getIndex()] = 2 << 8; // Index 9. 512
+ MASKS[PartOfSpeech.PRESENT_PARTICIPLE.getIndex()] = 2 << 9; // Index 10. 1,024
+ MASKS[PartOfSpeech.FUTURE_PARTICIPLE.getIndex()] = 2 << 10; // Index 11. 2,048
+ MASKS[PartOfSpeech.CARDINAL.getIndex()] = 2 << 11; // Index 12. 4,096
+ MASKS[PartOfSpeech.ORDINAL.getIndex()] = 2 << 12; // Index 13. 8,192
+
/* Leave some room in the middle for expansion from either end. */
- MASKS[11] = 0x0800; // Index 11. 2,048
- MASKS[NOUN_PLURALIZABLE_INDEX] = 0x1000; // Index 12. 4,096
- MASKS[NOUN_CONVERTIBLE_TO_POSSESSIVE_INDEX] = 0x2000; // Index 13. 8,192
- MASKS[REGULAR_VERB_INDEX] = 0x4000; // Index 14. 16,384
- MASKS[ADJ_EXTENSIBLE_INDEX] = 0x8000; // Index 15. 32,768
+
+ MASKS[14] = 2 << 13; // Index 14. 16,384
+ MASKS[15] = 2 << 14; // Index 15. 32,768
+ MASKS[16] = 2 << 15; // Index 16. 65,536
+ MASKS[17] = 2 << 16; // Index 17. 131,072
+ MASKS[18] = 2 << 17; // Index 18. 262,144
+ MASKS[19] = 2 << 18; // Index 19. 524288
+ MASKS[20] = 2 << 19; // Index 20. 1,048,576
+ MASKS[21] = 2 << 20; // Index 21. 2,097,152
+ MASKS[22] = 2 << 21; // Index 22. 4,194,304
+ MASKS[23] = 2 << 22; // Index 23. 8,388,608
+ MASKS[24] = 2 << 23; // Index 24. 16,777,216
+ MASKS[25] = 2 << 24; // Index 25. 33,554,432
+ MASKS[26] = 2 << 25; // Index 26. 67,108,864
+ MASKS[27] = 2 << 26; // Index 27.
+
+ MASKS[NOUN_PLURALIZABLE_INDEX] = 2 << 27; // Index 28.
+ MASKS[NOUN_CONVERTIBLE_TO_POSSESSIVE_INDEX] = 2 << 28; // Index 29.
+ MASKS[REGULAR_VERB_INDEX] = 2 << 29; // Index 30.
+ MASKS[ADJ_EXTENSIBLE_INDEX] = 2 << 30; // Index 31. 2,147,483,648
}
/* Checkstyle: Restart Magic Number checking. */
@@ -161,10 +180,10 @@
* @param pos The part of speech to be added to existing flags.
* @return The new flags, consisting of all existing flags plus the one just added.
*/
- public static char encodePosInfo(final char existing, final PartOfSpeech pos) {
+ public static int encodePosInfo(final int existing, final PartOfSpeech pos) {
final int index = pos.getIndex();
- final char mask = MASKS[index];
- return (char) (existing | mask);
+ final int mask = MASKS[index];
+ return existing | mask;
}
/**
@@ -174,11 +193,7 @@
* @param qualifier The qualifier which should be added.
* @return The new flags, consisting of all existing flags plus the one just added.
*/
- public static char encodePosQualifier(final char existing, final PartOfSpeech pos, final PosQualifier qualifier) {
-
-
-
-
+ public static int encodePosQualifier(final int existing, final PartOfSpeech pos, final PosQualifier qualifier) {
if (! isPartOfSpeech(existing, pos)) {
throw new IllegalStateException("Part-of-speech " + pos + " has not been set.");
}
@@ -186,8 +201,8 @@
if (index < 0) {
return existing;
}
- final char mask = MASKS[index];
- return (char) (existing | mask);
+ final int mask = MASKS[index];
+ return existing | mask;
}
@@ -197,9 +212,9 @@
* @param pos The part of speech being tested for.
* @return True if and only if the flag is set for {@code pos}.
*/
- public static boolean isPartOfSpeech(final char flags, final PartOfSpeech pos) {
+ public static boolean isPartOfSpeech(final int flags, final PartOfSpeech pos) {
final int index = pos.getIndex();
- final char mask = MASKS[index];
+ final int mask = MASKS[index];
return (flags & mask) != 0;
}
@@ -212,7 +227,7 @@
* This can be null, which implies that only the part-of-speech should be tested.
* @return True if and only if the flags match both the part of speech and the qualifier.
*/
- public static boolean isOfQualifiedType(final char flags, final PartOfSpeech pos, final PosQualifier qualifier) {
+ public static boolean isOfQualifiedType(final int flags, final PartOfSpeech pos, final PosQualifier qualifier) {
final boolean isPosMatch = PosUtils.isPartOfSpeech(flags, pos);
if (isPosMatch == false) {
return false;
@@ -225,7 +240,7 @@
if (index < 0) {
return false;
}
- final char mask = MASKS[index];
+ final int mask = MASKS[index];
return (flags & mask) != 0;
}
@@ -248,9 +263,9 @@
return qualifier;
}
- public static char parseAndEncodeQualifier(final char existing, final PartOfSpeech pos,
+ public static int parseAndEncodeQualifier(final int existing, final PartOfSpeech pos,
final Attributes attributes) {
- char encoded = existing;
+ int encoded = existing;
for (int index = 0; index < attributes.getLength(); index ++) {
final String attributeName = attributes.getLocalName(index);
final String value = attributes.getValue(index);
@@ -335,4 +350,14 @@
}
}
+ /**
+ * Returns the mask at a given index.
+ * Useful mostly for testing.
+ * @param index The index for the mask to be returned.
+ * @return The mask at {@code index}.
+ */
+ static int getMask(final int index) {
+ return MASKS[index];
+ }
+
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java 2021-11-21 16:53:51 UTC (rev 12106)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java 2021-11-21 20:41:03 UTC (rev 12107)
@@ -101,7 +101,7 @@
private StringWordSegment[] currentSegments;
/** The current parts of speech being parsed. */
- private char currentPartsOfSpeech;
+ private int currentPartsOfSpeech;
/* TODO: The following List and contents are oriented toward English & Western European languages.
* They should be moved to the orthography configuration. */
Modified: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/PosUtilsTests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/PosUtilsTests.java 2021-11-21 16:53:51 UTC (rev 12106)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/PosUtilsTests.java 2021-11-21 20:41:03 UTC (rev 12107)
@@ -44,43 +44,77 @@
*/
@Test
public void testEncoding() {
- char running = 0;
+ int running = 0;
+ int expected = 2 >> 1;
running = PosUtils.encodePosInfo(running, PartOfSpeech.NOUN);
- Assert.assertEquals(1, running);
+ Assert.assertEquals(expected, running);
+ expected += 2;
running = PosUtils.encodePosInfo(running, PartOfSpeech.PRONOUN);
- Assert.assertEquals(3, running);
+ Assert.assertEquals(expected, running);
+ expected += 2 << 1;
running = PosUtils.encodePosInfo(running, PartOfSpeech.VERB);
- Assert.assertEquals(7, running);
+ Assert.assertEquals(expected, running);
+ expected += 2 << 2;
running = PosUtils.encodePosInfo(running, PartOfSpeech.ADJECTIVE);
- Assert.assertEquals(15, running);
+ Assert.assertEquals(expected, running);
+ expected += 2 << 3;
running = PosUtils.encodePosInfo(running, PartOfSpeech.ADVERB);
- Assert.assertEquals(31, running);
+ Assert.assertEquals(expected, running);
+ expected += 2 << 4;
running = PosUtils.encodePosInfo(running, PartOfSpeech.PREPOSITION);
- Assert.assertEquals(63, running);
+ Assert.assertEquals(expected, running);
+ expected += 2 << 5;
running = PosUtils.encodePosInfo(running, PartOfSpeech.CONJUNCTION);
- Assert.assertEquals(127, running);
+ Assert.assertEquals(expected, running);
+ expected += 2 << 6;
running = PosUtils.encodePosInfo(running, PartOfSpeech.DETERMINER);
- Assert.assertEquals(255, running);
+ Assert.assertEquals(expected, running);
+ expected += 2 << 7;
running = PosUtils.encodePosInfo(running, PartOfSpeech.INTERJECTION);
- Assert.assertEquals(511, running);
+ Assert.assertEquals(expected, running);
+ expected += 2 << 8;
+ running = PosUtils.encodePosInfo(running, PartOfSpeech.PAST_PARTICIPLE);
+ Assert.assertEquals(expected, running);
+ expected += 2 << 9;
+ running = PosUtils.encodePosInfo(running, PartOfSpeech.PRESENT_PARTICIPLE);
+ Assert.assertEquals(expected, running);
+ expected += 2 << 10;
+ running = PosUtils.encodePosInfo(running, PartOfSpeech.FUTURE_PARTICIPLE);
+ Assert.assertEquals(expected, running);
+ expected += 2 << 11;
running = PosUtils.encodePosInfo(running, PartOfSpeech.CARDINAL);
- Assert.assertEquals(1_023, running);
+ Assert.assertEquals(expected, running);
+ expected += 2 << 12;
running = PosUtils.encodePosInfo(running, PartOfSpeech.ORDINAL);
- Assert.assertEquals(2_047, running);
- /* Index 11, if used, would add 2048. */
+ Assert.assertEquals(expected, running);
+// expected += 2 << 13;
+// expected += 2 << 14;
+// expected += 2 << 15;
+// expected += 2 << 16;
+// expected += 2 << 17;
+// expected += 2 << 18;
+// expected += 2 << 19;
+// expected += 2 << 20;
+// expected += 2 << 21;
+// expected += 2 << 22;
+// expected += 2 << 23;
+// expected += 2 << 24;
+// expected += 2 << 25;
+// expected += 2 << 26;
+
+ expected += 2 << 27;
running = PosUtils.encodePosQualifier(running, PartOfSpeech.NOUN, PosQualifier.PLURALIZABLE);
- Assert.assertEquals(2_047 + 4_096, running); // 6,143
-
- /* Add 8192. */
+ Assert.assertEquals(expected, running);
+ expected += 2 << 28;
running = PosUtils.encodePosQualifier(running, PartOfSpeech.NOUN, PosQualifier.CONVERTIBLE_TO_POSSESSIVE);
- Assert.assertEquals(6_143 + 8_192, running); // 14,335
- /* Add 16,384. */
+ Assert.assertEquals(expected, running);
+ expected += 2 << 29;
running = PosUtils.encodePosQualifier(running, PartOfSpeech.VERB, PosQualifier.REGULAR_ROOT);
- Assert.assertEquals(14_335 + 16_384, running); // 30,719
- /* Add 32,768. */
+ Assert.assertEquals(expected, running);
+ expected += 2 << 30;
running = PosUtils.encodePosQualifier(running, PartOfSpeech.ADJECTIVE, PosQualifier.EXTENSIBLE);
- Assert.assertEquals(30_719 + 32_768, running);
+ Assert.assertEquals(expected, running);
}
/**
@@ -88,7 +122,7 @@
*/
@Test
public void testOfOrInsteadOfAdd() {
- char running = 0;
+ int running = 0;
running = PosUtils.encodePosInfo(running, PartOfSpeech.INTERJECTION);
Assert.assertEquals(256, running);
/* Deliberately set the same one again, which should not change the value. */
@@ -102,7 +136,7 @@
*/
@Test
public void testOfIllegalStates() {
- char flags = 0;
+ int flags = 0;
try {
flags = PosUtils.encodePosQualifier(flags, PartOfSpeech.NOUN, PosQualifier.PLURALIZABLE);
Assert.fail("Exception expected.");
@@ -132,9 +166,11 @@
/* Now make sure the normal cases work correctly. */
flags = 0;
flags = PosUtils.encodePosInfo(flags, PartOfSpeech.NOUN);
- Assert.assertEquals(1, flags);
+ int expected = PosUtils.getMask(PartOfSpeech.NOUN.getIndex());
+ Assert.assertEquals(expected, flags);
flags = PosUtils.encodePosQualifier(flags, PartOfSpeech.NOUN, PosQualifier.PLURALIZABLE);
- Assert.assertEquals(1 + 4_096, flags);
+ expected += PosUtils.getMask(PosUtils.NOUN_PLURALIZABLE_INDEX);
+ Assert.assertEquals(expected, flags);
Assert.assertTrue(PosUtils.isPartOfSpeech(flags, PartOfSpeech.NOUN));
Assert.assertTrue(PosUtils.isOfQualifiedType(flags, PartOfSpeech.NOUN, PosQualifier.PLURALIZABLE));
@@ -141,9 +177,11 @@
/* Now make sure the normal cases work correctly. */
flags = 0;
flags = PosUtils.encodePosInfo(flags, PartOfSpeech.VERB);
- Assert.assertEquals(4, flags);
+ expected = PosUtils.getMask(PartOfSpeech.VERB.getIndex());
+ Assert.assertEquals(expected, flags);
flags = PosUtils.encodePosQualifier(flags, PartOfSpeech.VERB, PosQualifier.REGULAR_ROOT);
- Assert.assertEquals(4 + 16_384, flags);
+ expected += PosUtils.getMask(PosUtils.REGULAR_VERB_INDEX);
+ Assert.assertEquals(expected, flags);
Assert.assertTrue(PosUtils.isPartOfSpeech(flags, PartOfSpeech.VERB));
Assert.assertTrue(PosUtils.isOfQualifiedType(flags, PartOfSpeech.VERB, PosQualifier.REGULAR_ROOT));
@@ -150,9 +188,11 @@
/* Now make sure the normal cases work correctly. */
flags = 0;
flags = PosUtils.encodePosInfo(flags, PartOfSpeech.ADJECTIVE);
- Assert.assertEquals(8, flags);
+ expected = PosUtils.getMask(PartOfSpeech.ADJECTIVE.getIndex());
+ Assert.assertEquals(expected, flags);
flags = PosUtils.encodePosQualifier(flags, PartOfSpeech.ADJECTIVE, PosQualifier.EXTENSIBLE);
- Assert.assertEquals(8 + 32_768, flags);
+ expected += PosUtils.getMask(PosUtils.ADJ_EXTENSIBLE_INDEX);
+ Assert.assertEquals(expected, flags);
Assert.assertTrue(PosUtils.isPartOfSpeech(flags, PartOfSpeech.ADJECTIVE));
Assert.assertTrue(PosUtils.isOfQualifiedType(flags, PartOfSpeech.ADJECTIVE, PosQualifier.EXTENSIBLE));
}
@@ -162,7 +202,7 @@
*/
@Test
public void testIsPartOfSpeech() {
- char flags = 0;
+ int flags = 0;
flags = PosUtils.encodePosInfo(flags, PartOfSpeech.PREPOSITION);
Assert.assertFalse(PosUtils.isPartOfSpeech(flags, PartOfSpeech.NOUN));
Assert.assertFalse(PosUtils.isPartOfSpeech(flags, PartOfSpeech.PRONOUN));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-21 16:53:54
|
Revision: 12106
http://sourceforge.net/p/foray/code/12106
Author: victormote
Date: 2021-11-21 16:53:51 +0000 (Sun, 21 Nov 2021)
Log Message:
-----------
Use InputSource system ID instead of an explicit document description.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DictionaryResource.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/WordChecker.java
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-21 16:36:41 UTC (rev 12105)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java 2021-11-21 16:53:51 UTC (rev 12106)
@@ -49,9 +49,6 @@
/** Format string for formatting the current location. */
private static final String LOCATION_FORMAT_STRING = "(%1s:%2$d:%3$d)";
- /** Human-meaningful description of the document being parsed. */
- private String documentDescription;
-
/** The locator instance for identifying the document, line, and column number of specific elements. */
private Locator locator;
@@ -58,14 +55,6 @@
/** The logger. */
private Logger logger = LoggerFactory.getLogger(this.getClass());
- /**
- * Sets the document description to be used in logging messages and exceptions.
- * @param newDescription The new document description.
- */
- public void setDocumentDescription(final String newDescription) {
- this.documentDescription = newDescription;
- }
-
@Override
public void setDocumentLocator(final Locator locator) {
this.locator = locator;
@@ -99,7 +88,7 @@
* @return The current location in the input document as a formatted string.
*/
protected String getLocationString() {
- return String.format(LOCATION_FORMAT_STRING, this.documentDescription, this.locator.getLineNumber(),
+ return String.format(LOCATION_FORMAT_STRING, this.locator.getSystemId(), this.locator.getLineNumber(),
this.locator.getColumnNumber());
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DictionaryResource.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DictionaryResource.java 2021-11-21 16:36:41 UTC (rev 12105)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DictionaryResource.java 2021-11-21 16:53:51 UTC (rev 12106)
@@ -139,8 +139,8 @@
parser.setLogDictionaryProblems(true);
SegmentDictionary dictionary = null;
try {
- final InputSource source = new InputSource(inputStream);
- dictionary = parser.parse(source, location.getLocationDescription()).get(0);
+ final InputSource source = new InputSource(rawResource.toExternalForm());
+ dictionary = parser.parse(source).get(0);
} catch (final IOException e) {
getLogger().error("IOException", e);
return null;
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java 2021-11-21 16:36:41 UTC (rev 12105)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java 2021-11-21 16:53:51 UTC (rev 12106)
@@ -91,9 +91,6 @@
/** The character that should actually be used in the word content as the hard hyphen characters. */
private char actualHardHyphenChar = '-';
- /** The input source to be parsed. */
-// private InputSource input;
-
/** The list of dictionaries that have been parsed by this parser. */
private List<SegmentDictionary> parsedDictionaries = new ArrayList<SegmentDictionary>();
@@ -142,16 +139,14 @@
/**
* Parses a given InputStream and places the parsed information into the dictionary.
* @param inputSource The input source to parse.
- * @param description Description of {@literal inputStream}, useful for user messages.
+ * @return The parsed dictionaries.
* @throws IOException For IO errors during parsing.
- * @return The parsed dictionary.
* @throws ParserConfigurationException For errors during parser configuration.
* @throws SAXException For errors found by the SAX parser.
*/
- public List<SegmentDictionary> parse(final InputSource inputSource, final String description)
+ public List<SegmentDictionary> parse(final InputSource inputSource)
throws IOException, SAXException, ParserConfigurationException {
- setDocumentDescription(description);
- getLogger().info("Begin dictionary word list parsing: " + description);
+ getLogger().info("Begin dictionary word list parsing: " + inputSource.getSystemId());
final XMLReader parser = createParser();
if (parser != null) {
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-21 16:36:41 UTC (rev 12105)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-21 16:53:51 UTC (rev 12106)
@@ -205,7 +205,7 @@
final DictionaryParserXml dictParser = new DictionaryParserXml();
dictParser.setLogDictionaryProblems(true);
final InputSource source = new InputSource(adhocDictionaryPath.toExternalForm());
- final List<SegmentDictionary> dictionaries = dictParser.parse(source, adhocDictionaryPath.toString());
+ final List<SegmentDictionary> dictionaries = dictParser.parse(source);
this.currentDictionaries.addAll(dictionaries);
}
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/WordChecker.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/WordChecker.java 2021-11-21 16:36:41 UTC (rev 12105)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/WordChecker.java 2021-11-21 16:53:51 UTC (rev 12106)
@@ -52,7 +52,6 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
-import java.io.InputStream;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
@@ -123,9 +122,8 @@
for (URL adhocDictionaryPath : adhocDictionaryPaths) {
final DictionaryParserXml dictParser = new DictionaryParserXml();
dictParser.setLogDictionaryProblems(true);
- final InputStream dictInput = adhocDictionaryPath.openStream();
- final InputSource source = new InputSource(dictInput);
- final List<SegmentDictionary> dictionaries = dictParser.parse(source, adhocDictionaryPath.toString());
+ final InputSource source = new InputSource(adhocDictionaryPath.toExternalForm());
+ final List<SegmentDictionary> dictionaries = dictParser.parse(source);
this.currentDictionaries.addAll(dictionaries);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-21 16:36:43
|
Revision: 12105
http://sourceforge.net/p/foray/code/12105
Author: victormote
Date: 2021-11-21 16:36:41 +0000 (Sun, 21 Nov 2021)
Log Message:
-----------
1. Conform to aXSL change: Add more part-of-speech elements. 2. Move more XML parsing logic to SaxParser.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java
trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml
trunk/foray/foray-orthography/src/main/data/orthographies/foray-orthography-config.xml
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyConfigParser.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
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-20 17:26:39 UTC (rev 12104)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/xml/SaxParser.java 2021-11-21 16:36:41 UTC (rev 12105)
@@ -30,6 +30,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.DefaultHandler2;
@@ -45,10 +46,32 @@
*/
public abstract class SaxParser extends DefaultHandler2 {
+ /** Format string for formatting the current location. */
+ private static final String LOCATION_FORMAT_STRING = "(%1s:%2$d:%3$d)";
+
+ /** Human-meaningful description of the document being parsed. */
+ private String documentDescription;
+
+ /** The locator instance for identifying the document, line, and column number of specific elements. */
+ private Locator locator;
+
/** The logger. */
private Logger logger = LoggerFactory.getLogger(this.getClass());
/**
+ * Sets the document description to be used in logging messages and exceptions.
+ * @param newDescription The new document description.
+ */
+ public void setDocumentDescription(final String newDescription) {
+ this.documentDescription = newDescription;
+ }
+
+ @Override
+ public void setDocumentLocator(final Locator locator) {
+ this.locator = locator;
+ }
+
+ /**
* 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.
*/
@@ -72,6 +95,15 @@
}
/**
+ * Returns the current location in the input document as a formatted string.
+ * @return The current location in the input document as a formatted string.
+ */
+ protected String getLocationString() {
+ return String.format(LOCATION_FORMAT_STRING, this.documentDescription, this.locator.getLineNumber(),
+ this.locator.getColumnNumber());
+ }
+
+ /**
* Creates a SAX2 parser with a standard configuration. Specifically,
* the parser is namespace-aware and has the "namespace-prefixes" feature
* set to true.
Modified: trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml
===================================================================
--- trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml 2021-11-20 17:26:39 UTC (rev 12104)
+++ trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml 2021-11-21 16:36:41 UTC (rev 12105)
@@ -24180,7 +24180,7 @@
<w><t>catch-a-ble</t></w>
<w><t>catch-all</t></w>
<w><t>catch-er</t></w>
-<w><t>catch-es</t><verb><vu><person-3rd/><singular/></vu></verb></w>
+<w><t>catch-es</t><verb><vf><person-3rd/><singular/></vf></verb></w>
<w><t>catch-fly</t></w>
<w><t>catch-ie</t></w>
<w><t>catch-i-er</t></w>
Modified: trunk/foray/foray-orthography/src/main/data/orthographies/foray-orthography-config.xml
===================================================================
--- trunk/foray/foray-orthography/src/main/data/orthographies/foray-orthography-config.xml 2021-11-20 17:26:39 UTC (rev 12104)
+++ trunk/foray/foray-orthography/src/main/data/orthographies/foray-orthography-config.xml 2021-11-21 16:36:41 UTC (rev 12105)
@@ -23,7 +23,7 @@
<match>^([a-zA-Z\-]+)’s$</match>
<replace>$1</replace>
<derivative-rule>
- <noun convertible-to-possessive="true"/>
+ <noun><convertible-to-possessive/></noun>
<derivative-type type="possessive"/>
</derivative-rule>
</derivative-pattern>
@@ -31,11 +31,11 @@
<match>^([a-zA-Z\-]+)ies$</match>
<replace>$1y</replace>
<derivative-rule>
- <noun number="pluralizable"/>
+ <noun><pluralizable/></noun>
<derivative-type type="plural"/>
</derivative-rule>
<derivative-rule>
- <verb regular-root="true"/>
+ <verb><regular-root/></verb>
<derivative-type type="verb-form" desc="3rd person singular, present tense"/>
</derivative-rule>
<derivative-rule>
@@ -47,7 +47,7 @@
<match>^([a-zA-Z\-]+)ied$</match>
<replace>$1y</replace>
<derivative-rule>
- <verb regular-root="true"/>
+ <verb><regular-root/></verb>
<derivative-type type="verb-form" desc="past tense"/>
<derivative-type type="past-participle"/>
</derivative-rule>
@@ -56,11 +56,11 @@
<match>^([a-zA-Z\-]+)([sxz]|sh|ch)es$</match>
<replace>$1$2</replace>
<derivative-rule>
- <noun number="pluralizable"/>
+ <noun><pluralizable/></noun>
<derivative-type type="plural"/>
</derivative-rule>
<derivative-rule>
- <verb regular-root="true"/>
+ <verb><regular-root/></verb>
<derivative-type type="verb-form" desc="3rd person singular present tense"/>
</derivative-rule>
<derivative-rule>
@@ -72,7 +72,7 @@
<match>^([a-zA-Z\-]+)s$</match>
<replace>$1</replace>
<derivative-rule>
- <noun number="pluralizable"/>
+ <noun><pluralizable/></noun>
<derivative-type type="plural"/>
</derivative-rule>
<derivative-rule>
@@ -84,7 +84,7 @@
<derivative-type type="plural"/>
</derivative-rule>
<derivative-rule>
- <verb regular-root="true"/>
+ <verb><regular-root/></verb>
<derivative-type type="verb-form" desc="3rd person singular present tense"/>
</derivative-rule>
</derivative-pattern>
@@ -92,7 +92,7 @@
<match>^([a-zA-Z\-]+)([bcdfgklmnpstvz])(\2)ed$</match>
<replace>$1$2</replace>
<derivative-rule>
- <verb regular-root="true"/>
+ <verb><regular-root/></verb>
<derivative-type type="verb-form" desc="past tense"/>
<derivative-type type="past-participle"/>
</derivative-rule>
@@ -101,7 +101,7 @@
<match>^([a-zA-Z\-]+)ed$</match>
<replace>$1</replace>
<derivative-rule>
- <verb regular-root="true"/>
+ <verb><regular-root/></verb>
<derivative-type type="verb-form" desc="past tense"/>
<derivative-type type="past-participle"/>
</derivative-rule>
@@ -110,7 +110,7 @@
<match>^([a-zA-Z\-]+e)d$</match>
<replace>$1</replace>
<derivative-rule>
- <verb regular-root="true"/>
+ <verb><regular-root/></verb>
<derivative-type type="verb-form" desc="past tense"/>
<derivative-type type="past-participle" desc="past tense"/>
</derivative-rule>
@@ -119,7 +119,7 @@
<match>^([a-zA-Z\-]+)([bcdfgklmnprstvz])(\2)ing$</match>
<replace>$1$2</replace>
<derivative-rule>
- <verb regular-root="true"/>
+ <verb><regular-root/></verb>
<derivative-type type="present-participle"/>
</derivative-rule>
</derivative-pattern>
@@ -127,7 +127,7 @@
<match>^([a-zA-Z\-]+)ing$</match>
<replace>$1e</replace>
<derivative-rule>
- <verb regular-root="true"/>
+ <verb><regular-root/></verb>
<derivative-type type="present-participle"/>
</derivative-rule>
</derivative-pattern>
@@ -135,7 +135,7 @@
<match>^([a-zA-Z\-]+)ing$</match>
<replace>$1</replace>
<derivative-rule>
- <verb regular-root="true"/>
+ <verb><regular-root/></verb>
<derivative-type type="present-participle"/>
</derivative-rule>
</derivative-pattern>
@@ -143,7 +143,7 @@
<match>^([a-zA-Z\-]+)er$</match>
<replace>$1</replace>
<derivative-rule>
- <adjective extensible="true"/>
+ <adjective><extensible/></adjective>
<derivative-type type="comparative" desc="single-syllable root"/>
</derivative-rule>
</derivative-pattern>
@@ -151,7 +151,7 @@
<match>^([a-zA-Z\-]+)est$</match>
<replace>$1</replace>
<derivative-rule>
- <adjective extensible="true"/>
+ <adjective><extensible/></adjective>
<derivative-type type="superlative" desc="single-syllable root"/>
</derivative-rule>
</derivative-pattern>
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java 2021-11-20 17:26:39 UTC (rev 12104)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParserXml.java 2021-11-21 16:36:41 UTC (rev 12105)
@@ -44,12 +44,9 @@
import org.axsl.orthography.Word.PartOfSpeech;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
@@ -85,9 +82,6 @@
private char hardHyphenChar;
}
- /** Format string for formatting the current location. */
- private static final String LOCATION_FORMAT_STRING = "(%1$d:%2$d)";
-
/** Constant used to initialize string builders. */
private static final int MAX_EXPECTED_WORD_LENGTH = 100;
@@ -94,9 +88,6 @@
/** Constant used to initialize segment collections. */
private static final int MAX_EXPECTED_QTY_SEGMENTS = 100;
- /** The logger. */
- private Logger logger = LoggerFactory.getLogger(this.getClass());
-
/** The character that should actually be used in the word content as the hard hyphen characters. */
private char actualHardHyphenChar = '-';
@@ -103,9 +94,6 @@
/** The input source to be parsed. */
// private InputSource input;
- /** The locator instance for identifying the document, line, and column number of specific elements. */
- private Locator locator;
-
/** The list of dictionaries that have been parsed by this parser. */
private List<SegmentDictionary> parsedDictionaries = new ArrayList<SegmentDictionary>();
@@ -162,7 +150,8 @@
*/
public List<SegmentDictionary> parse(final InputSource inputSource, final String description)
throws IOException, SAXException, ParserConfigurationException {
- logger.info("Begin dictionary word list parsing: " + description);
+ setDocumentDescription(description);
+ getLogger().info("Begin dictionary word list parsing: " + description);
final XMLReader parser = createParser();
if (parser != null) {
@@ -207,7 +196,7 @@
try {
parser.setProperty("http://xml.org/sax/properties/lexical-handler", this);
} catch (final SAXNotSupportedException e1) {
- this.logger.error("Parser does not support LexicalHandler.");
+ getLogger().error("Parser does not support LexicalHandler.");
}
/* Bind the DeclHandler to the XMLReader if possible. */
@@ -214,7 +203,7 @@
try {
parser.setProperty("http://xml.org/sax/properties/declaration-handler", this);
} catch (final SAXNotSupportedException e) {
- this.logger.error("Parser does not support Declaration Handler.");
+ getLogger().error("Parser does not support Declaration Handler.");
}
/* Turn on namespace-prefixes so that we get the namespace declarations
@@ -223,17 +212,17 @@
try {
parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
} catch (final SAXNotRecognizedException e1) {
- this.logger.error("Parser does not recognize the \"namespace-prefixes\" feature.");
+ getLogger().error("Parser does not recognize the \"namespace-prefixes\" feature.");
} catch (final SAXNotSupportedException e1) {
- this.logger.error("Parser unable to supply namespace-prefixes.");
+ getLogger().error("Parser unable to supply namespace-prefixes.");
}
try {
parser.setFeature("http://xml.org/sax/features/validation", true);
} catch (final SAXNotRecognizedException e1) {
- this.logger.error("Parser does not recognize the \"validation\" feature.");
+ getLogger().error("Parser does not recognize the \"validation\" feature.");
} catch (final SAXNotSupportedException e1) {
- this.logger.error("Parser unable to validate.");
+ getLogger().error("Parser unable to validate.");
}
/* Turn on "notify-char-refs" feature.
@@ -277,11 +266,6 @@
@Override
- public void setDocumentLocator(final Locator locator) {
- this.locator = locator;
- }
-
- @Override
public void characters(final char ch[], final int start, final int length) throws SAXException {
this.charBuffer.append(ch, start, length);
}
@@ -351,6 +335,26 @@
PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech, PartOfSpeech.INTERJECTION, attributes);
break;
}
+ case "past-participle": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.PAST_PARTICIPLE);
+ this.currentPartsOfSpeech = PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech,
+ PartOfSpeech.PAST_PARTICIPLE, attributes);
+ break;
+ }
+ case "present-participle": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech,
+ PartOfSpeech.PRESENT_PARTICIPLE);
+ this.currentPartsOfSpeech = PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech,
+ PartOfSpeech.PRESENT_PARTICIPLE, attributes);
+ break;
+ }
+ case "future-participle": {
+ this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech,
+ PartOfSpeech.FUTURE_PARTICIPLE);
+ this.currentPartsOfSpeech = PosUtils.parseAndEncodeQualifier(this.currentPartsOfSpeech,
+ PartOfSpeech.FUTURE_PARTICIPLE, attributes);
+ break;
+ }
case "cardinal": {
this.currentPartsOfSpeech = PosUtils.encodePosInfo(this.currentPartsOfSpeech, PartOfSpeech.CARDINAL);
this.currentPartsOfSpeech =
@@ -370,7 +374,7 @@
final String country = attributes.getValue(StringUtils.EMPTY_STRING, "country");
final String script = attributes.getValue(StringUtils.EMPTY_STRING, "script");
this.currentDictionary.orthography = WritingSystem4a.find(language, script, country);
- logger.info("Begin dictionary word list parsing: " + this.currentDictionary.orthography.toString());
+ getLogger().info("Begin dictionary word list parsing: " + this.currentDictionary.orthography.toString());
final String soft = attributes.getValue(StringUtils.EMPTY_STRING, "soft-hyphen-char");
if (soft.length() != 1) {
throw new SAXException("Attribute soft-hyphen-char must have exactly one char.");
@@ -385,8 +389,26 @@
}
case "axsl-dictionaries": break;
case "phrase": break;
+ case "vf": break;
+ case "lemma": break;
+ case "regular-root": break;
+ case "person-1st": break;
+ case "person-2nd": break;
+ case "person-3rd": break;
+ case "person-any": break;
+ case "singular": break;
+ case "plural": break;
+ case "pluralizable": break;
+ case "number-any": break;
+ case "masculine": break;
+ case "feminine": break;
+ case "neuter": break;
+ case "gender-any": break;
+ case "convertible-to-possessive": break;
+ case "possessive": break;
+ case "extensible": break;
default: {
- throw new IllegalStateException("Unknown element started: " + localName);
+ throw new IllegalStateException("Unknown element started: " + localName + ", " + getLocationString());
}
}
}
@@ -401,7 +423,7 @@
if (this.logDictionaryProblems) {
final String actualContentLowercase = actualContent.toLowerCase();
if (actualContentLowercase.compareTo(this.lastWord) < 0) {
- this.logger.warn("Out of alphabetical sequence: " + actualContent + " " + locationString());
+ getLogger().warn("Out of alphabetical sequence: " + actualContent + " " + getLocationString());
}
this.lastWord = actualContentLowercase;
}
@@ -436,7 +458,7 @@
final char theChar = inputLine.charAt(inputLineIndex);
if (theChar == this.currentDictionary.softHyphenChar) {
if (builder.length() < 1) {
- throw new SAXException("0-length syllable on line: " + locationString());
+ throw new SAXException("0-length syllable on line: " + getLocationString());
}
final StringWordSegment wordSegment = createSegment(builder.toString());
segmentList.add(wordSegment);
@@ -457,7 +479,7 @@
segmentSet.add(wordSegment);
}
if (segmentList.size() < 1) {
- throw new SAXException("0-syllable word: " + this.locationString());
+ throw new SAXException("0-syllable word: " + getLocationString());
}
this.currentSegments = new StringWordSegment[segmentList.size()];
segmentList.toArray(this.currentSegments);
@@ -472,17 +494,38 @@
case "conjunction": break;
case "determiner": break;
case "interjection": break;
+ case "past-participle": break;
+ case "present-participle": break;
+ case "future-participle": break;
case "cardinal": break;
case "ordinal": break;
case "word-group": break;
case "axsl-dictionary": {
- logger.info("End parsing for dictionary: " + this.currentDictionary.orthography.toString());
- logger.info("Qty of unique word segments parsed: " + segmentSet.size());
- logger.info("Qty of words parsed: " + wordMap.size());
+ getLogger().info("End parsing for dictionary: " + this.currentDictionary.orthography.toString());
+ getLogger().info("Qty of unique word segments parsed: " + segmentSet.size());
+ getLogger().info("Qty of words parsed: " + wordMap.size());
break;
}
case "axsl-dictionaries": break;
case "phrase": break;
+ case "vf": break;
+ case "lemma": break;
+ case "regular-root": break;
+ case "person-1st": break;
+ case "person-2nd": break;
+ case "person-3rd": break;
+ case "person-any": break;
+ case "singular": break;
+ case "plural": break;
+ case "pluralizable": break;
+ case "number-any": break;
+ case "masculine": break;
+ case "feminine": break;
+ case "neuter": break;
+ case "gender-any": break;
+ case "convertible-to-possessive": break;
+ case "possessive": break;
+ case "extensible": break;
default: {
throw new IllegalStateException("Unknown element ended: " + localName);
}
@@ -491,14 +534,6 @@
/**
- * Returns the current location in the input document as a formatted string.
- * @return The current location in the input document as a formatted string.
- */
- private String locationString() {
- return String.format(LOCATION_FORMAT_STRING, this.locator.getLineNumber(), this.locator.getColumnNumber());
- }
-
- /**
* Create a pseudo-string instance.
* @param string The String instance to replace.
* @return A new instance of StringWordSegment encapsulating the content in {@code string}.
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-20 17:26:39 UTC (rev 12104)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyConfigParser.java 2021-11-21 16:36:41 UTC (rev 12105)
@@ -57,7 +57,6 @@
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
@@ -150,9 +149,6 @@
/** The hyphenation server receiving the parsed information. */
private OrthographyServer4a hyphenationServer;
- /** The XML parser's Locator instance, used to indicate line and column numbers in user messages. */
- private Locator locator;
-
/** The stack of elements currently being processed. */
private Stack<String> elementStack = new Stack<String>();
@@ -313,7 +309,7 @@
final DictionaryResource resource = this.dictionaries.get(reference);
if (resource == null) {
getLogger().error("dictionary-resource not found: {}", reference);
- getLogger().error(getContextMessage());
+ getLogger().error(getLocationString());
} else {
this.currentOrthographyConfig.setDictionaryResource(resource);
}
@@ -324,7 +320,7 @@
final HyphenationPatternsResource resource = this.hyphenationPatterns.get(reference);
if (resource == null) {
getLogger().error("hyphenation-patterns-resource not found: {}", reference);
- getLogger().error(getContextMessage());
+ getLogger().error(getLocationString());
} else {
this.currentOrthographyConfig.setHyphenationPatternsResource(resource);
}
@@ -335,7 +331,7 @@
final List<Pattern> patterns = this.hyphenationServer.getMatchRules(reference);
if (patterns == null) {
getLogger().error("match-rules not found: {}", reference);
- getLogger().error(getContextMessage());
+ getLogger().error(getLocationString());
} else {
this.currentOrthographyConfig.registerMatchRuleListId(reference);
}
@@ -346,7 +342,7 @@
final List<DerivativePattern> rules = this.hyphenationServer.getDerivativePatterns(reference);
if (rules == null) {
getLogger().error("derivative-rules not found: {}", reference);
- getLogger().error(getContextMessage());
+ getLogger().error(getLocationString());
} else {
this.currentOrthographyConfig.registerDerivativeRuleListId(reference);
}
@@ -357,7 +353,7 @@
final List<WordWrapperFactory<?>> factories = this.derivativeLists.get(reference);
if (factories == null) {
getLogger().error("derivative-factories not found: {}", reference);
- getLogger().error(getContextMessage());
+ getLogger().error(getLocationString());
} else {
this.currentOrthographyConfig.setWordWrapperFactories(factories);
}
@@ -463,6 +459,24 @@
this.currentQualifier = PosUtils.parseSingleQualifier(attributes);
return;
}
+ case "vf": return;
+ case "lemma": return;
+ case "regular-root": return;
+ case "person-1st": return;
+ case "person-2nd": return;
+ case "person-3rd": return;
+ case "person-any": return;
+ case "singular": return;
+ case "plural": return;
+ case "pluralizable": return;
+ case "number-any": return;
+ case "masculine": return;
+ case "feminine": return;
+ case "neuter": return;
+ case "gender-any": return;
+ case "convertible-to-possessive": return;
+ case "possessive": return;
+ case "extensible": return;
default: {
/* Make sure user knows about unknown tag. */
getLogger().error("Unknown tag in orthography configuration: {}", localName);
@@ -481,22 +495,22 @@
final Language4a language = Language4a.findFrom3Char(languageString);
if (language == null) {
getLogger().error("Unable to find language for: {}", languageString);
- getLogger().error(getContextMessage());
+ getLogger().error(getLocationString());
}
final Script4a script = Script4a.findFromAlpha(scriptString);
if (script == null) {
getLogger().error("Unable to find script for: {}", scriptString);
- getLogger().error(getContextMessage());
+ getLogger().error(getLocationString());
}
final Country4a country = Country4a.findFrom3Char(countryString);
if (country == null) {
getLogger().error("Unable to find country for: {}", countryString);
- getLogger().error(getContextMessage());
+ getLogger().error(getLocationString());
}
final WritingSystem4a writingSystem = WritingSystem4a.find(language, script, country);
if (writingSystem == null) {
getLogger().error("Unable to find script for: {}_{}_{}", languageString, scriptString, countryString);
- getLogger().error(getContextMessage());
+ getLogger().error(getLocationString());
}
this.hyphenationServer.registerOrthography(writingSystem, this.currentOrthographyConfig);
}
@@ -657,14 +671,6 @@
}
}
- /**
- * Sets the document locator for this parser.
- * @param locator The new locator.
- */
- public void setDocumentLocator(final Locator locator) {
- this.locator = locator;
- }
-
@Override
public void characters(final char[] chars, final int start, final int length) throws SAXException {
this.textAccumulator.append(chars, start, length);
@@ -671,20 +677,6 @@
}
/**
- * Provides a formatted string showing the current locator context, which is useful in user messages to indicate
- * where in the document a condition arose.
- * @return The formatted context message.
- */
- private String getContextMessage() {
- if (this.locator == null) {
- return null;
- }
- return " Context: " + this.locator.getSystemId() + "\n"
- + " (Line " + this.locator.getLineNumber() + ", Column "
- + this.locator.getColumnNumber() + ")";
- }
-
- /**
* Converts a string to a URL.
* @param urlString The string to be converted.
* @return The URL.
@@ -694,7 +686,7 @@
return new URL(urlString);
} catch (final MalformedURLException e) {
getLogger().error("Invalid URL: {}", urlString);
- getLogger().error(getContextMessage());
+ getLogger().error(getLocationString());
return null;
}
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-20 17:26:39 UTC (rev 12104)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-21 16:36:41 UTC (rev 12105)
@@ -204,8 +204,7 @@
for (URL adhocDictionaryPath : adhocDictionaryPaths) {
final DictionaryParserXml dictParser = new DictionaryParserXml();
dictParser.setLogDictionaryProblems(true);
- final InputStream dictInput = adhocDictionaryPath.openStream();
- final InputSource source = new InputSource(dictInput);
+ final InputSource source = new InputSource(adhocDictionaryPath.toExternalForm());
final List<SegmentDictionary> dictionaries = dictParser.parse(source, adhocDictionaryPath.toString());
this.currentDictionaries.addAll(dictionaries);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-20 17:26:42
|
Revision: 12104
http://sourceforge.net/p/foray/code/12104
Author: victormote
Date: 2021-11-20 17:26:39 +0000 (Sat, 20 Nov 2021)
Log Message:
-----------
Conform dictionaries to aXSL DTD changes.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml
trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-GBR.dict.xml
trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-USA.dict.xml
Modified: trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml
===================================================================
--- trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml 2021-11-19 17:56:05 UTC (rev 12103)
+++ trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-999.dict.xml 2021-11-20 17:26:39 UTC (rev 12104)
@@ -1725,7 +1725,7 @@
<phrase><t>A-dar She-ni</t></phrase>
<w><t>a-dat</t></w>
<w><t>ad-ax-i-al</t></w>
-<w><t>add</t><verb regular-root="true"/></w>
+<w><t>add</t><verb><regular-root/></verb></w>
<w><t>add-a-ble</t></w>
<w><t>Ad-dams</t></w>
<w><t>ad-dax</t></w>
@@ -2280,7 +2280,7 @@
<w><t>ad-vi-so-ry</t></w>
<w><t>ad-vo-caat</t></w>
<w><t>ad-vo-ca-cy</t></w>
-<w><t>ad-vo-cate</t><noun number="pluralizable" convertible-to-possessive="true"/><verb/></w>
+<w><t>ad-vo-cate</t><noun><pluralizable/><convertible-to-possessive/></noun><verb/></w>
<phrase><t>Ad-vo-cate De-pute</t></phrase>
<w><t>ad-vo-cat-ed</t></w>
<w><t>ad-vo-cat-ing</t></w>
@@ -2598,10 +2598,10 @@
<w><t>af-fect-er</t></w>
<w><t>af-fect-ing</t></w>
<w><t>af-fect-ing-ly</t></w>
-<w><t>af-fec-tion</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
-<w><t>af-fec-tion-al</t><adjective extensible="false"/></w>
+<w><t>af-fec-tion</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
+<w><t>af-fec-tion-al</t><adjective><extensible value="false"/></adjective></w>
<w><t>af-fec-tion-al-ly</t></w>
-<w><t>af-fec-tion-ate</t><adjective extensible="false"/></w>
+<w><t>af-fec-tion-ate</t><adjective><extensible value="false"/></adjective></w>
<w><t>af-fec-tion-ate-ly</t><adverb/></w>
<w><t>af-fec-tion-ate-ness</t></w>
<w><t>af-fec-tive</t></w>
@@ -4588,7 +4588,7 @@
<w><t>Al-tair</t></w>
<w><t>Al-ta-ir</t></w>
<w><t>Al-ta-mi-ra</t></w>
-<w><t>al-tar</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>al-tar</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>al-tar boy</t></phrase>
<w><t>al-tar-age</t></w>
<w><t>al-tar-piece</t></w>
@@ -6121,7 +6121,7 @@
<w><t>An-garsk</t></w>
<w><t>an-ga-ry</t></w>
<w><t>an-ge-kok</t></w>
-<w><t>an-gel</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>an-gel</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>An-gel</t></w>
<phrase><t>an-gel cake</t></phrase>
<phrase><t>An-gel Falls</t></phrase>
@@ -11840,13 +11840,13 @@
<w><t>a-wake</t></w>
<w><t>a-wake-a-ble</t></w>
<w><t>a-waked</t></w>
-<w><t>a-wak-en</t><verb regular-root="true"/></w>
+<w><t>a-wak-en</t><verb><regular-root/></verb></w>
<w><t>a-wak-en-a-ble</t></w>
<w><t>a-wak-en-er</t></w>
<w><t>a-wak-en-ing</t></w>
<w><t>a-wak-en-ing-ly</t></w>
<w><t>a-wak-ing</t></w>
-<w><t>a-ward</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>a-ward</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<phrase><t>a-ward wage</t></phrase>
<w><t>a-ward-a-ble</t></w>
<w><t>a-ward-er</t></w>
@@ -14248,7 +14248,7 @@
<w><t>beak-like</t></w>
<w><t>beak-y</t></w>
<w><t>Beal</t></w>
-<w><t>beam</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>beam</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<phrase><t>beam aer-i-al</t></phrase>
<phrase><t>beam com-pass</t></phrase>
<phrase><t>beam rid-ing</t></phrase>
@@ -14407,7 +14407,7 @@
<w><t>Beb-ry-ces</t></w>
<w><t>be-calm</t></w>
<w><t>be-calmed</t></w>
-<w><t>be-came</t><verb regular-root="false"/></w>
+<w><t>be-came</t><verb><regular-root value="false"/></verb></w>
<w><t>be-cause</t></w>
<w><t>bec-ca-fi-co</t></w>
<w><t>be-chance</t></w>
@@ -14435,9 +14435,9 @@
<w><t>Beck-y</t></w>
<w><t>be-clasp</t></w>
<w><t>be-cloud</t></w>
-<w><t>be-come</t><verb regular-root="false"/></w>
-<w><t>be-comes</t><verb regular-root="false"/></w>
-<w><t>be-com-ing</t><verb regular-root="false"/><adjective/></w>
+<w><t>be-come</t><verb><regular-root value="false"/></verb></w>
+<w><t>be-comes</t><verb><regular-root value="false"/></verb></w>
+<w><t>be-com-ing</t><verb><regular-root value="false"/></verb><adjective/></w>
<w><t>be-com-ing-ly</t><adverb/></w>
<w><t>be-com-ing-ness</t></w>
<w><t>Bec-que-rel</t></w>
@@ -19634,7 +19634,7 @@
<w><t>Brig-ham</t></w>
<w><t>Brig-house</t></w>
<w><t>Bright</t></w>
-<w><t>bright</t><adjective extensible="true"/></w>
+<w><t>bright</t><adjective><extensible/></adjective></w>
<phrase><t>Bright's dis-ease</t></phrase>
<w><t>bright-en</t></w>
<w><t>bright-en-er</t></w>
@@ -20903,7 +20903,7 @@
<w><t>Bur-mese</t></w>
<phrase><t>Bur-mese cat</t></phrase>
<w><t>bur-mite</t></w>
-<w><t>burn</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>burn</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>burn=up</t></w>
<w><t>burn-a-ble</t></w>
<w><t>burned</t></w>
@@ -21997,7 +21997,7 @@
<w><t>calk</t></w>
<w><t>calk-er</t></w>
<w><t>cal-kin</t></w>
-<w><t>call</t><verb regular-root="true"/></w>
+<w><t>call</t><verb><regular-root/></verb></w>
<phrase><t>call let-ters</t></phrase>
<phrase><t>call mon-ey</t></phrase>
<phrase><t>call num-ber</t></phrase>
@@ -24175,11 +24175,12 @@
<w><t>cat-call</t></w>
<w><t>cat-call-er</t></w>
<w><t>cat-cat-ing</t></w>
-<w><t>catch</t></w>
+<w><t>catch</t><noun><pluralizable/></noun><verb><regular-root value="false"/></verb></w>
<phrase><t>catch ba-sin</t></phrase>
<w><t>catch-a-ble</t></w>
<w><t>catch-all</t></w>
<w><t>catch-er</t></w>
+<w><t>catch-es</t><verb><vu><person-3rd/><singular/></vu></verb></w>
<w><t>catch-fly</t></w>
<w><t>catch-ie</t></w>
<w><t>catch-i-er</t></w>
@@ -26570,9 +26571,9 @@
<w><t>chief-dom</t></w>
<w><t>chief-less</t></w>
<w><t>chief-ly</t></w>
-<w><t>chief-tain</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
-<w><t>chief-tain-cy</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
-<w><t>chief-tain-ship</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>chief-tain</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
+<w><t>chief-tain-cy</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
+<w><t>chief-tain-ship</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>chield</t></w>
<w><t>Chieng-mai</t></w>
<w><t>Chieng-rai</t></w>
@@ -27281,7 +27282,7 @@
<w><t>chris-mon</t></w>
<w><t>chris-om</t></w>
<w><t>Chris-sie</t></w>
-<w><t>Christ</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>Christ</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>Chris-ta-bel</t></w>
<w><t>Chris-ta-del-phi-an</t></w>
<w><t>Christ-church</t></w>
@@ -28802,7 +28803,7 @@
<phrase><t>climb-ing i-rons</t></phrase>
<w><t>climb-ing-fish</t></w>
<w><t>climb-ing-fish-es</t></w>
-<w><t>clime</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>clime</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>cli-nah</t></w>
<w><t>clin-al</t></w>
<w><t>clin-al-ly</t></w>
@@ -30400,7 +30401,7 @@
<w><t>com-bi-na-to-ri-al</t></w>
<phrase><t>com-bi-na-to-ri-al a-nal-y-sis</t></phrase>
<w><t>com-bi-na-to-ry</t></w>
-<w><t>com-bine</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>com-bine</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<phrase><t>com-bine har-ves-ter</t></phrase>
<w><t>com-bined-ly</t></w>
<w><t>com-bined-ness</t></w>
@@ -31647,7 +31648,7 @@
<w><t>con-fed-rit</t></w>
<w><t>con-fer</t></w>
<w><t>con-fer-ee</t></w>
-<w><t>con-fer-ence</t></w>
+<w><t>con-fer-ence</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>con-fer-en-tial</t></w>
<w><t>con-fer-ment</t></w>
<w><t>con-fer-ra-ble</t></w>
@@ -32066,7 +32067,7 @@
<w><t>co-no-scen-ti</t></w>
<w><t>co-no-scope</t></w>
<w><t>co-no-scop-ic</t></w>
-<w><t>con-quer</t><verb regular-root="true"/></w>
+<w><t>con-quer</t><verb><regular-root/></verb></w>
<w><t>con-quer-a-ble</t></w>
<w><t>con-quer-a-ble-ness</t></w>
<w><t>con-quer-ing-ly</t></w>
@@ -32381,12 +32382,11 @@
<phrase><t>con-su-lar a-gent</t></phrase>
<w><t>con-su-late</t></w>
<w><t>con-sul-ship</t></w>
-<w><t>con-sult</t></w>
+<w><t>con-sult</t><verb><regular-root/></verb></w>
<w><t>con-sult-a-ble</t></w>
-<w><t>con-sult-ant</t></w>
+<w><t>con-sult-ant</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>con-sul-ta-tion</t></w>
-<w><t>con-sult-a-tive</t></w>
-<w><t>con-sul-ta-tive</t></w>
+<w><t>con-sul-ta-tive</t><adjective><extensible value="false"/></adjective></w>
<w><t>con-sult-a-tive-ly</t></w>
<w><t>con-sul-ta-to-ry</t></w>
<w><t>con-sult-er</t></w>
@@ -34403,7 +34403,7 @@
<w><t>cours-es</t></w>
<w><t>cours-ing</t></w>
<w><t>Court</t></w>
-<w><t>court</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>court</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<phrase><t>court cir-cu-lar</t></phrase>
<phrase><t>court mar-tial</t></phrase>
<phrase><t>Court of Ap-peal</t></phrase>
@@ -35668,10 +35668,10 @@
<w><t>cross-wort</t></w>
<w><t>cro-ta-lar-i-a</t></w>
<w><t>cro-ta-lin</t></w>
-<w><t>crotch</t><noun number="singular" convertible-to-possessive="true"/></w>
-<w><t>crotch-et</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
-<w><t>crotch-et-i-ness</t><noun number="singular" convertible-to-possessive="false"/></w>
-<w><t>crotch-et-y</t><adjective extensible="false"/></w>
+<w><t>crotch</t><noun><singular/><convertible-to-possessive/></noun></w>
+<w><t>crotch-et</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
+<w><t>crotch-et-i-ness</t><noun><singular/><convertible-to-possessive value="false"/></noun></w>
+<w><t>crotch-et-y</t><adjective><extensible value="false"/></adjective></w>
<w><t>crotch-wood</t></w>
<w><t>cro-ton</t></w>
<phrase><t>Cro-ton bug</t></phrase>
@@ -35849,7 +35849,7 @@
<w><t>cru-sad-ing</t></w>
<w><t>cru-sa-do</t></w>
<w><t>cruse</t></w>
-<w><t>crush</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>crush</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<phrase><t>crush bar-ri-er</t></phrase>
<w><t>crush-a-bil-i-ty</t></w>
<w><t>crush-a-ble</t></w>
@@ -38745,7 +38745,7 @@
<w><t>de-duc-tive-ly</t></w>
<w><t>Dee</t></w>
<w><t>dee</t></w>
-<w><t>deed</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>deed</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>deed-less</t></w>
<w><t>dee-jay</t></w>
<w><t>deek</t></w>
@@ -38754,7 +38754,7 @@
<w><t>Deems</t></w>
<w><t>deem-ster</t></w>
<w><t>deem-ster-ship</t></w>
-<w><t>deep</t><noun number="pluralizable" convertible-to-possessive="true"/><adjective extensible="true"/><adverb/></w>
+<w><t>deep</t><noun><pluralizable/><convertible-to-possessive/></noun><adjective><extensible/></adjective><adverb/></w>
<phrase><t>deep struc-ture</t></phrase>
<phrase><t>deep ther-a-py</t></phrase>
<w><t>deep=chest-draw-ing</t></w>
@@ -40457,8 +40457,8 @@
<w><t>de-sen-si-tized</t></w>
<w><t>de-sen-si-tiz-er</t></w>
<w><t>de-sen-si-tiz-ing</t></w>
-<w><t>des-ert</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
-<w><t>de-sert</t><noun/><verb regular-root="true"/></w>
+<w><t>des-ert</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
+<w><t>de-sert</t><noun/><verb><regular-root/></verb></w>
<phrase><t>des-ert boots</t></phrase>
<phrase><t>des-ert cool-er</t></phrase>
<phrase><t>des-ert is-land</t></phrase>
@@ -40474,7 +40474,7 @@
<w><t>des-er-tic-o-lous</t></w>
<w><t>de-ser-tion</t></w>
<w><t>des-ert-like</t></w>
-<w><t>de-serve</t><verb regular-root="true"/></w>
+<w><t>de-serve</t><verb><regular-root/></verb></w>
<w><t>de-served</t><adjective/></w>
<w><t>de-serv-ed-ly</t><adverb/></w>
<w><t>de-serv-ed-ness</t></w>
@@ -40481,7 +40481,7 @@
<w><t>de-serv-er</t></w>
<w><t>de-serv-ing</t><adjective/></w>
<w><t>de-serv-ing-ly</t><adverb/></w>
-<w><t>de-serv-ing-ness</t><noun number="singular" convertible-to-possessive="false"/></w>
+<w><t>de-serv-ing-ness</t><noun><singular/><convertible-to-possessive value="false"/></noun></w>
<w><t>de-sex</t></w>
<w><t>de-sex-u-al-ise</t></w>
<w><t>de-sex-u-al-ize</t></w>
@@ -47278,12 +47278,12 @@
<w><t>ef-flu-vi-al</t></w>
<w><t>ef-flu-vi-um</t></w>
<w><t>ef-flux</t></w>
-<w><t>ef-fort</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>ef-fort</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>ef-fort-ful</t><adjective/></w>
<w><t>ef-fort-ful-ly</t><adverb/></w>
<w><t>ef-fort-less</t><adjective/></w>
<w><t>ef-fort-less-ly</t><adverb/></w>
-<w><t>ef-fort-less-ness</t><noun number="singular"/></w>
+<w><t>ef-fort-less-ness</t><noun><singular/></noun></w>
<w><t>ef-frac-tion</t></w>
<w><t>ef-frac-tor</t></w>
<w><t>ef-fron-ter-ies</t></w>
@@ -47938,7 +47938,7 @@
<w><t>E-lei-a</t></w>
<w><t>e-lek-tra</t></w>
<w><t>elem</t></w>
-<w><t>el-e-ment</t></w>
+<w><t>el-e-ment</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>el-e-ment-al</t></w>
<w><t>el-e-men-tal</t></w>
<w><t>el-e-men-tal-ly</t></w>
@@ -48706,7 +48706,7 @@
<w><t>emp-ti-ly</t></w>
<w><t>emp-ti-ness</t></w>
<w><t>emp-tor</t></w>
-<w><t>emp-ty</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/><adjective/></w>
+<w><t>emp-ty</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb><adjective/></w>
<phrase><t>Emp-ty Quar-ter</t></phrase>
<w><t>emp-ty=hand-ed</t></w>
<w><t>emp-ty=head-ed</t></w>
@@ -49157,9 +49157,9 @@
<w><t>en-do-tox-oid</t></w>
<w><t>en-do-troph-ic</t></w>
<w><t>end-o-ver</t></w>
-<w><t>en-dow</t><verb regular-root="true"/></w>
-<w><t>en-dow-er</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
-<w><t>en-dow-ment</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>en-dow</t><verb><regular-root/></verb></w>
+<w><t>en-dow-er</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
+<w><t>en-dow-ment</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>en-dow-ment as-sur-ance</t></phrase>
<w><t>end-pa-per</t></w>
<w><t>end-piece</t></w>
@@ -49389,7 +49389,7 @@
<w><t>en-joy-a-bly</t></w>
<w><t>en-joy-er</t></w>
<w><t>en-joy-ing-ly</t></w>
-<w><t>en-joy-ment</t><noun number="pluralizable"/></w>
+<w><t>en-joy-ment</t><noun><pluralizable/></noun></w>
<w><t>en-keph-a-lin</t></w>
<w><t>En-ki</t></w>
<w><t>En-ki-du</t></w>
@@ -50805,7 +50805,7 @@
<w><t>er-ro-ne-ous</t></w>
<w><t>er-ro-ne-ous-ly</t></w>
<w><t>er-ro-ne-ous-ness</t></w>
-<w><t>er-ror</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>er-ror</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>er-ror of clo-sure</t></phrase>
<w><t>er-ror-less</t></w>
<w><t>ers</t></w>
@@ -52470,8 +52470,8 @@
<w><t>ex-er-gon-ic</t></w>
<w><t>ex-ergu-al</t></w>
<w><t>ex-ergue</t></w>
-<w><t>ex-ert</t><verb regular-root="true"/></w>
-<w><t>ex-er-tion</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>ex-ert</t><verb><regular-root/></verb></w>
+<w><t>ex-er-tion</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>ex-er-tive</t></w>
<w><t>Ex-e-ter</t></w>
<w><t>ex-e-unt</t></w>
@@ -52671,7 +52671,7 @@
<w><t>ex-o-tox-in</t></w>
<w><t>ex-o-tro-pi-a</t></w>
<w><t>exp</t></w>
-<w><t>ex-pand</t><verb regular-root="true"/></w>
+<w><t>ex-pand</t><verb><regular-root/></verb></w>
<w><t>ex-pand-a-bil-i-ty</t></w>
<w><t>ex-pand-a-ble</t></w>
<w><t>ex-pand-ed</t></w>
@@ -54473,7 +54473,7 @@
<w><t>feath-er-y</t></w>
<w><t>feat-li-ness</t></w>
<w><t>feat-ly</t></w>
-<w><t>fea-ture</t><noun number="pluralizable"/><verb regular-root="true"/></w>
+<w><t>fea-ture</t><noun><pluralizable/></noun><verb><regular-root/></verb></w>
<w><t>fea-ture=length</t></w>
<w><t>fea-tured</t></w>
<w><t>fea-ture-less</t></w>
@@ -57703,7 +57703,7 @@
<w><t>for-lorn-ly</t></w>
<w><t>for-lorn-ness</t></w>
<w><t>For-lì</t></w>
-<w><t>form</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>form</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>Form</t></w>
<phrase><t>form ge-nus</t></phrase>
<phrase><t>form let-ter</t></phrase>
@@ -61025,7 +61025,7 @@
<w><t>gen-er-ate</t></w>
<w><t>gen-er-at-ed</t></w>
<w><t>gen-er-at-ing</t></w>
-<w><t>gen-er-a-tion</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>gen-er-a-tion</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>gen-er-a-tion gap</t></phrase>
<w><t>gen-er-a-tive</t></w>
<phrase><t>gen-er-a-tive gram-mar</t></phrase>
@@ -61739,9 +61739,9 @@
<w><t>Gie-rek</t></w>
<w><t>Gie-se-king</t></w>
<w><t>Gies-sen</t></w>
-<w><t>gift</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>gift</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>gift=wrap-per</t></w>
-<w><t>gift-ed</t><adjective extensible="false"/></w>
+<w><t>gift-ed</t><adjective><extensible value="false"/></adjective></w>
<w><t>gift-ed-ly</t></w>
<w><t>gift-ed-ness</t></w>
<w><t>gift-less</t></w>
@@ -62011,7 +62011,7 @@
<phrase><t>Giu-lio Ro-ma-no</t></phrase>
<w><t>Giu-sep-pe</t></w>
<w><t>giu-sto</t></w>
-<w><t>give</t><noun number="singular" convertible-to-possessive="false"/><verb regular-root="false"/></w>
+<w><t>give</t><noun><singular/><convertible-to-possessive value="false"/></noun><verb><regular-root value="false"/></verb></w>
<phrase><t>give a-way</t></phrase>
<phrase><t>give on-to</t></phrase>
<phrase><t>give o-ver</t></phrase>
@@ -62020,7 +62020,7 @@
<w><t>giv-en</t></w>
<phrase><t>giv-en name</t></phrase>
<w><t>giv-er</t></w>
-<w><t>gives</t><verb regular-root="false"/></w>
+<w><t>gives</t><verb><regular-root value="false"/></verb></w>
<w><t>giv-ing</t></w>
<w><t>Gi-za</t></w>
<w><t>Gi-zeh</t></w>
@@ -62496,7 +62496,7 @@
<w><t>Glov-er</t></w>
<w><t>Glov-ers-ville</t></w>
<w><t>glov-ing</t></w>
-<w><t>glow</t><noun number="singular"/><verb regular-root="true"/></w>
+<w><t>glow</t><noun><singular/></noun><verb><regular-root/></verb></w>
<phrase><t>glow dis-charge</t></phrase>
<w><t>glow-er</t></w>
<w><t>glow-er-ing-ly</t></w>
@@ -62821,8 +62821,8 @@
<w><t>go-by</t></w>
<w><t>GOC</t></w>
<w><t>Go-clen-i-us</t></w>
-<w><t>God</t><noun number="singular" convertible-to-possessive="true"/></w>
-<w><t>god</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>God</t><noun><singular/><convertible-to-possessive/></noun></w>
+<w><t>god</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>God's a-cre</t></phrase>
<w><t>God=aw-ful</t></w>
<w><t>god=fear-ing</t></w>
@@ -63518,7 +63518,7 @@
<w><t>grab-bler</t></w>
<w><t>gra-ben</t></w>
<w><t>Grac-chus</t></w>
-<w><t>grace</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>grace</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>Grace</t></w>
<w><t>grace=and=fa-vor</t></w>
<w><t>grace=and=fa-vour</t></w>
@@ -63989,7 +63989,7 @@
<w><t>grav</t></w>
<w><t>gra-va-men</t></w>
<w><t>gra-va-vam-i-na</t></w>
-<w><t>grave</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="false"/><adjective extensible="true"/></w>
+<w><t>grave</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root value="false"/></verb><adjective><extensible value="false"/></adjective></w>
<!-- Don't use. Too difficult to disambiguate. <w><t>gra-ve</t></w> -->
<w><t>grave-clothes</t></w>
<w><t>grave-dig-ger</t></w>
@@ -64102,7 +64102,7 @@
<w><t>greas-i-ness</t></w>
<w><t>greas-y</t></w>
<phrase><t>greas-y spoon</t></phrase>
-<w><t>great</t></w>
+<w><t>great</t><noun><pluralizable/></noun><adjective><extensible/></adjective></w>
<phrase><t>Great Aus-tral-i-an Bight</t></phrase>
<phrase><t>Great Bar-ri-er Reef</t></phrase>
<phrase><t>Great Ba-sin</t></phrase>
@@ -67051,7 +67051,7 @@
<w><t>hard-pan</t></w>
<w><t>hards</t></w>
<w><t>hard-scrab-ble</t></w>
-<w><t>hard-ship</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>hard-ship</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>hard-tack</t></w>
<w><t>hard-tail</t></w>
<w><t>hard-top</t></w>
@@ -69547,7 +69547,7 @@
<w><t>hig-gle</t></w>
<w><t>hig-gle-dy=pig-gle-dy</t></w>
<w><t>hig-gler</t></w>
-<w><t>high</t><noun number="pluralizable" convertible-to-possessive="true"/><adjective extensible="true"/><adverb/></w>
+<w><t>high</t><noun><pluralizable/><convertible-to-possessive/></noun><adjective><extensible/></adjective><adverb/></w>
<phrase><t>high al-tar</t></phrase>
<phrase><t>high com-e-dy</t></phrase>
<phrase><t>high com-mand</t></phrase>
@@ -74875,7 +74875,7 @@
<w><t>im-pre-scrip-ti-ble</t></w>
<w><t>im-pre-scrip-ti-bly</t></w>
<w><t>im-prese</t></w>
-<w><t>im-press</t><verb regular-root="true"/></w>
+<w><t>im-press</t><verb><regular-root/></verb></w>
<w><t>im-press-er</t></w>
<w><t>im-press-i-bil-i-ty</t></w>
<w><t>im-press-i-ble</t></w>
@@ -77997,14 +77997,14 @@
<w><t>in-ter-ep-i-dem-ic</t></w>
<w><t>in-ter-ep-i-the-li-al</t></w>
<w><t>in-ter-e-qui-noc-tial</t></w>
-<w><t>in-ter-est</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>in-ter-est</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>in-ter-est-ed</t><adjective/></w>
<w><t>in-ter-est-ed-ly</t><adverb/></w>
-<w><t>in-ter-est-ed-ness</t><noun number="singular"/></w>
+<w><t>in-ter-est-ed-ness</t><noun><singular/></noun></w>
<w><t>in-ter-es-ter-i-fi-ca-tion</t></w>
<w><t>in-ter-est-ing</t><adjective/></w>
<w><t>in-ter-est-ing-ly</t><adverb/></w>
-<w><t>in-ter-est-ing-ness</t><noun number="singular"/></w>
+<w><t>in-ter-est-ing-ness</t><noun><singular/></noun></w>
<w><t>in-ter-es-tu-a-rine</t></w>
<w><t>in-ter-face</t></w>
<w><t>in-ter-faced</t></w>
@@ -79268,7 +79268,7 @@
<w><t>in-vert-i-ble</t></w>
<w><t>in-ver-tin</t></w>
<w><t>in-ver-tor</t></w>
-<w><t>in-vest</t><verb regular-root="true"/></w>
+<w><t>in-vest</t><verb><regular-root/></verb></w>
<w><t>in-vest-a-ble</t></w>
<w><t>in-vest-i-ble</t></w>
<w><t>in-ves-ti-ga-ble</t></w>
@@ -83460,7 +83460,7 @@
<w><t>kin-chin</t></w>
<w><t>Kin-chin-jun-ga</t></w>
<w><t>kin-cob</t></w>
-<w><t>kind</t></w>
+<w><t>kind</t><noun><pluralizable/></noun><adjective><extensible/></adjective></w>
<w><t>kind=heart-ed</t></w>
<w><t>kin-der-gar-ten</t></w>
<w><t>kin-der-gar-ten-er</t></w>
@@ -83470,7 +83470,7 @@
<w><t>kind-heart-ed-ly</t></w>
<w><t>kind-heart-ed-ness</t></w>
<w><t>kind-jal</t></w>
-<w><t>kin-dle</t><verb regular-root="true"/></w>
+<w><t>kin-dle</t><verb><regular-root/></verb></w>
<w><t>kin-dler</t></w>
<w><t>kind-less</t></w>
<w><t>kind-less-ly</t></w>
@@ -87561,7 +87561,7 @@
<phrase><t>lieu-ten-ant gov-er-nor</t></phrase>
<w><t>lieve</t></w>
<w><t>Li-far</t></w>
-<w><t>life</t><noun number="singular" convertible-to-possessive="true"/></w>
+<w><t>life</t><noun><singular/><convertible-to-possessive/></noun></w>
<phrase><t>life as-sur-ance</t></phrase>
<phrase><t>life cy-cle</t></phrase>
<phrase><t>life es-tate</t></phrase>
@@ -88493,7 +88493,7 @@
<w><t>liv-a-bil-i-ty</t></w>
<w><t>liv-a-ble</t></w>
<w><t>liv-a-ble-ness</t></w>
-<w><t>live</t><verb regular-root="true"/><adjective extensible="false"/><adverb/></w>
+<w><t>live</t><verb><regular-root/></verb><adjective><extensible value="false"/></adjective><adverb/></w>
<phrase><t>live cen-tre</t></phrase>
<phrase><t>live to-geth-er</t></phrase>
<w><t>live=bear-er</t></w>
@@ -88537,7 +88537,7 @@
<phrase><t>liv-er-y com-pa-ny</t></phrase>
<phrase><t>liv-er-y sta-ble</t></phrase>
<w><t>liv-er-y-man</t></w>
-<w><t>lives</t><noun number="plural"/></w>
+<w><t>lives</t><noun><plural/></noun></w>
<w><t>liv-est</t></w>
<w><t>live-stock</t></w>
<w><t>live-ware</t></w>
@@ -89044,7 +89044,7 @@
<w><t>lone-some-ness</t></w>
<w><t>Lo-ney</t></w>
<w><t>Long</t></w>
-<w><t>long</t><adjective extensible="true"/></w>
+<w><t>long</t><adjective><extensible/></adjective></w>
<phrase><t>Long Ea-ton</t></phrase>
<phrase><t>long hun-dred-weight</t></phrase>
<phrase><t>Long Is-land</t></phrase>
@@ -89155,7 +89155,7 @@
<w><t>Loo-goo-tee</t></w>
<w><t>loo-ie</t></w>
<w><t>loo-ing</t></w>
-<w><t>look</t></w>
+<w><t>look</t><noun><pluralizable/></noun><verb><regular-root/></verb></w>
<phrase><t>look af-ter</t></phrase>
<phrase><t>look for-ward to</t></phrase>
<phrase><t>look o-ver</t></phrase>
@@ -89491,7 +89491,7 @@
<w><t>lov-age</t></w>
<w><t>lov-at</t></w>
<w><t>Love</t></w>
-<w><t>love</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>love</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<phrase><t>love af-fair</t></phrase>
<phrase><t>love ap-ple</t></phrase>
<phrase><t>love let-ter</t></phrase>
@@ -89539,7 +89539,7 @@
<w><t>lov-ing-ly</t></w>
<w><t>lov-ing-ness</t></w>
<w><t>Lov-ing-ton</t></w>
-<w><t>low</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/><adjective extensible="true"/><adverb/></w>
+<w><t>low</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb><adjective><extensible/></adjective><adverb/></w>
<w><t>Low</t></w>
<phrase><t>Low Ar-chi-pel-a-go</t></phrase>
<phrase><t>low com-e-dy</t></phrase>
@@ -91157,7 +91157,7 @@
<phrase><t>Ma-kar-i-os III</t></phrase>
<w><t>Ma-kas-ar</t></w>
<w><t>Ma-kas-sar</t></w>
-<w><t>make</t><noun number="pluralizable" convertible-to-possessive="true"/><verb/></w>
+<w><t>make</t><noun><pluralizable/><convertible-to-possessive/></noun><verb/></w>
<phrase><t>make a-way</t></phrase>
<phrase><t>make be-lieve</t></phrase>
<phrase><t>make o-ver</t></phrase>
@@ -91688,7 +91688,7 @@
<w><t>man-i-cure</t></w>
<w><t>man-i-cur-ist</t></w>
<w><t>man-i-fer</t></w>
-<w><t>man-i-fest</t><verb regular-root="true"/></w>
+<w><t>man-i-fest</t><verb><regular-root/></verb></w>
<phrase><t>Man-i-fest Des-ti-ny</t></phrase>
<w><t>man-i-fes-tant</t></w>
<w><t>man-i-fes-ta-tion</t></w>
@@ -91942,7 +91942,7 @@
<w><t>ma-qui</t></w>
<w><t>ma-quill-age</t></w>
<w><t>ma-quis</t></w>
-<w><t>mar</t><verb regular-root="true"/></w>
+<w><t>mar</t><verb><regular-root/></verb></w>
<w><t>Mar</t></w>
<w><t>Ma-r</t></w>
<phrase><t>Mar del Pla-ta</t></phrase>
@@ -92678,7 +92678,7 @@
<w><t>mas-ta-bah</t></w>
<w><t>mas-tax</t></w>
<w><t>mas-tec-to-my</t></w>
-<w><t>mas-ter</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/><adjective extensible="false"/></w>
+<w><t>mas-ter</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb><adjective><extensible value="false"/></adjective></w>
<w><t>Mas-ter</t></w>
<phrase><t>mas-ter build-er</t></phrase>
<phrase><t>mas-ter cyl-in-der</t></phrase>
@@ -93850,11 +93850,11 @@
<w><t>Me-los</t></w>
<w><t>Mel-pom-e-ne</t></w>
<w><t>Mel-rose</t></w>
-<w><t>melt</t><noun number="pluralizable"/><verb regular-root="true"/></w>
+<w><t>melt</t><noun><pluralizable/></noun><verb><regular-root/></verb></w>
<w><t>melt-a-bil-i-ty</t></w>
<w><t>melt-a-ble</t><adjective/></w>
<w><t>melt-age</t></w>
-<w><t>melt-er</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>melt-er</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>melt-ing point</t></phrase>
<phrase><t>melt-ing pot</t></phrase>
<w><t>melt-ing-ly</t><adverb/></w>
@@ -94462,7 +94462,7 @@
<w><t>Mes-se-ni-a</t></w>
<w><t>Mes-ser-schmitt</t></w>
<w><t>Mes-siaen</t></w>
-<w><t>mes-si-ah</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>mes-si-ah</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>mes-si-an-ic</t></w>
<w><t>Mes-si-an-i-cal-ly</t></w>
<w><t>Mes-si-dor</t></w>
@@ -94723,7 +94723,7 @@
<w><t>me-thi-o-nine</t></w>
<w><t>meth-o</t></w>
<w><t>Meth-od</t></w>
-<w><t>meth-od</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>meth-od</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>me-thod-ic</t></w>
<w><t>me-thod-i-cal</t></w>
<w><t>me-thod-i-cal-ly</t></w>
@@ -96538,7 +96538,7 @@
<w><t>mis-sil-ry</t></w>
<w><t>mis-sing</t></w>
<phrase><t>mis-sing link</t></phrase>
-<w><t>mis-sion</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>mis-sion</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>Mis-sion</t></w>
<w><t>mis-sion-ar-ies</t></w>
<w><t>mis-sion-ar-y</t></w>
@@ -96909,8 +96909,8 @@
<w><t>mod-at-ed</t></w>
<w><t>mod-at-ing</t></w>
<w><t>mode</t></w>
-<w><t>mod-el</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
-<w><t>mod-el-er</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>mod-el</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
+<w><t>mod-el-er</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<!--<w><t>mod-el-ler</t></w>-->
<w><t>mo-dem</t></w>
<w><t>Mo-de-na</t></w>
@@ -98432,7 +98432,7 @@
<w><t>mov-a-ble</t></w>
<w><t>mov-a-ble-ness</t></w>
<w><t>mov-a-bly</t></w>
-<w><t>move</t><verb regular-root="true"/></w>
+<w><t>move</t><verb><regular-root/></verb></w>
<w><t>move-a-bil-i-ty</t></w>
<w><t>move-a-ble</t></w>
<w><t>move-a-ble-ness</t></w>
@@ -100080,7 +100080,7 @@
<w><t>nathe-less</t></w>
<w><t>nath-less</t></w>
<w><t>Na-tick</t></w>
-<w><t>na-tion</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>na-tion</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>na-tion=state</t></w>
<w><t>Na-tion-al</t></w>
<w><t>na-tion-al</t></w>
@@ -108171,7 +108171,7 @@
<w><t>O-ber-o-ster-reich</t></w>
<w><t>o-bese</t></w>
<w><t>o-bes-i-ty</t></w>
-<w><t>o-bey</t><verb regular-root="true"/></w>
+<w><t>o-bey</t><verb><regular-root/></verb></w>
<w><t>o-bey-a-ble</t></w>
<w><t>o-bey-er</t></w>
<w><t>o-bey-ing-ly</t></w>
@@ -123246,7 +123246,7 @@
<w><t>Prax-it-e-les</t></w>
<w><t>Prax-ith-e-a</t></w>
<w><t>pray</t></w>
-<w><t>prayer</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>prayer</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>prayer meet-ing</t></phrase>
<w><t>prayer-ful</t></w>
<w><t>prayer-ful-ly</t></w>
@@ -127660,7 +127660,7 @@
<w><t>pro-grav-id</t></w>
<w><t>Pro-gre-so</t></w>
<w><t>prog-ress</t><noun/></w>
-<w><t>pro-gress</t><verb regular-root="true"/></w>
+<w><t>pro-gress</t><verb><regular-root/></verb></w>
<w><t>pro-gres-sion</t></w>
<w><t>pro-gres-sion-al</t></w>
<w><t>pro-gres-sion-al-ly</t></w>
@@ -127827,13 +127827,13 @@
<w><t>pro-mis-cu-ous</t></w>
<w><t>pro-mis-cu-ous-ly</t></w>
<w><t>pro-mis-cu-ous-ness</t></w>
-<w><t>prom-ise</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>prom-ise</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<phrase><t>Prom-ised Land</t></phrase>
<w><t>prom-is-ee</t></w>
<w><t>prom-i-see</t></w>
<w><t>prom-ise-ful</t></w>
<w><t>prom-is-er</t></w>
-<w><t>prom-is-ing</t><adjective extensible="false"/></w>
+<w><t>prom-is-ing</t><adjective><extensible value="false"/></adjective></w>
<w><t>prom-i-sor</t></w>
<w><t>prom-is-so-ri-ly</t></w>
<w><t>prom-is-so-ry</t></w>
@@ -128495,7 +128495,7 @@
<w><t>prov-a-bly</t></w>
<w><t>pro-vac-ci-na-tion</t></w>
<w><t>pro-vac-cine</t></w>
-<w><t>prove</t><verb regular-root="true"/></w>
+<w><t>prove</t><verb><regular-root/></verb></w>
<w><t>prov-en</t></w>
<w><t>prov-e-nance</t></w>
<w><t>Pro-ven-cal</t></w>
@@ -129794,7 +129794,7 @@
<w><t>pur-plish-ness</t></w>
<w><t>pur-ply</t></w>
<w><t>pur-port</t></w>
-<w><t>pur-pose</t></w>
+<w><t>pur-pose</t><noun><pluralizable/></noun><verb><regular-root/></verb></w>
<w><t>pur-pose=built</t></w>
<w><t>pur-posed</t></w>
<w><t>pur-pose-ful</t></w>
@@ -130431,7 +130431,7 @@
<w><t>qual-i-ta-tive</t></w>
<phrase><t>qual-i-ta-tive a-nal-y-sis</t></phrase>
<w><t>qual-i-ta-tive-ly</t></w>
-<w><t>qual-i-ty</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>qual-i-ty</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>qual-i-ty con-trol</t></phrase>
<w><t>qual-i-ty-less</t></w>
<w><t>qualm</t></w>
@@ -132949,7 +132949,7 @@
<w><t>re-al-ist</t></w>
<w><t>re-al-is-tic</t></w>
<w><t>re-al-is-ti-cal-ly</t></w>
-<w><t>re-al-i-ty</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>re-al-i-ty</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>re-al-iz-a-bil-i-ty</t></w>
<w><t>re-al-iz-a-ble</t></w>
<w><t>re-al-iz-a-ble-ness</t></w>
@@ -133741,8 +133741,8 @@
<w><t>re-cop-ied</t></w>
<w><t>re-cop-y</t></w>
<w><t>re-cop-y-ing</t></w>
-<w><t>rec-ord</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
-<w><t>re-cord</t><verb regular-root="true"/></w>
+<w><t>rec-ord</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
+<w><t>re-cord</t><verb><regular-root/></verb></w>
<w><t>rec-ord=chang-er</t></w>
<w><t>rec-ord=play-er</t></w>
<w><t>re-cord-a-ble</t></w>
@@ -134243,7 +134243,7 @@
<w><t>Red-stone</t></w>
<w><t>red-tap-ism</t></w>
<w><t>red-top</t></w>
-<w><t>re-duce</t><verb regular-root="true"/></w>
+<w><t>re-duce</t><verb><regular-root/></verb></w>
<w><t>re-duced</t><adjective/></w>
<phrase><t>re-duced lev-el</t></phrase>
<w><t>re-ducer</t></w>
@@ -134792,7 +134792,7 @@
<w><t>re-gal-va-niz-ing</t></w>
<w><t>re-gam-ble</t></w>
<w><t>Re-gan</t></w>
-<w><t>re-gard</t></w>
+<w><t>re-gard</t><noun><pluralizable/><convertible-to-possessive value="false"/></noun><verb><regular-root/></verb></w>
<w><t>re-gard-a-ble</t></w>
<w><t>re-gard-ant</t></w>
<w><t>re-gar-dant</t></w>
@@ -135715,7 +135715,7 @@
<w><t>rem-e-dy</t></w>
<w><t>rem-e-dy-ing</t></w>
<w><t>re-melt</t></w>
-<w><t>re-mem-ber</t><verb regular-root="true"/></w>
+<w><t>re-mem-ber</t><verb><regular-root/></verb></w>
<w><t>re-mem-ber-er</t></w>
<w><t>re-mem-brance</t></w>
<phrase><t>Re-mem-brance Sun-day</t></phrase>
@@ -136965,7 +136965,7 @@
<w><t>re-sprung</t></w>
<w><t>re-squan-der</t></w>
<w><t>res-sen-ti-ment</t></w>
-<w><t>rest</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>rest</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>re-stab</t></w>
<w><t>re-stabbed</t></w>
<w><t>re-stab-bing</t></w>
@@ -140478,7 +140478,7 @@
<w><t>sail-plan-ing</t></w>
<w><t>sain</t></w>
<w><t>sain-foin</t></w>
-<w><t>saint</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>saint</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<phrase><t>Saint Ag-nes's Eve</t></phrase>
<phrase><t>Saint Al-bans</t></phrase>
<phrase><t>Saint An-tho-ny's Cross</t></phrase>
@@ -141626,12 +141626,12 @@
<w><t>Sa-va</t></w>
<w><t>sav-a-ble</t></w>
<w><t>sav-a-ble-ness</t></w>
-<w><t>sav-age</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/><adjective extensible="false"/></w>
+<w><t>sav-age</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb><adjective><extensible value="false"/></adjective></w>
<w><t>Sav-age</t></w>
<phrase><t>Sav-age Is-land</t></phrase>
<w><t>sav-age-ly</t><adverb/></w>
-<w><t>sav-age-ness</t><noun number="singular"/></w>
-<w><t>sav-age-ry</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>sav-age-ness</t><noun><singular/></noun></w>
+<w><t>sav-age-ry</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>sav-ag-ism</t></w>
<w><t>Sa-vai-i</t></w>
<w><t>Sa-van-na</t></w>
@@ -141642,7 +141642,7 @@
<w><t>sa-vants</t></w>
<w><t>sav-a-rin</t></w>
<w><t>sa-vate</t></w>
-<w><t>save</t><verb regular-root="true"/></w>
+<w><t>save</t><verb><regular-root/></verb></w>
<w><t>Save</t></w>
<w><t>save-a-ble</t></w>
<w><t>save-a-ble-ness</t></w>
@@ -142723,7 +142723,7 @@
<w><t>scrip-tur-al</t></w>
<w><t>scrip-tur-al-ly</t></w>
<w><t>scrip-tur-al-ness</t></w>
-<w><t>scrip-ture</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>scrip-ture</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>Scrip-ture</t></w>
<w><t>script-writ-er</t></w>
<w><t>script-writ-ing</t></w>
@@ -143150,7 +143150,7 @@
<w><t>sec-re-tar-i-at</t></w>
<w><t>sec-re-tar-i-ate</t></w>
<w><t>sec-re-tar-ies=gen-er-al</t></w>
-<w><t>sec-re-tar-y</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>sec-re-tar-y</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>sec-re-tar-y bird</t></phrase>
<phrase><t>sec-re-tar-y of state</t></phrase>
<w><t>sec-re-tar-y=gen-er-al</t></w>
@@ -143325,9 +143325,9 @@
<w><t>See-land</t></w>
<w><t>see-li-ly</t></w>
<w><t>see-ly</t></w>
-<w><t>seem</t></w>
+<w><t>seem</t><verb><regular-root/></verb></w>
<w><t>seem-er</t></w>
-<w><t>seem-ing</t></w>
+<w><t>seem-ing</t><noun><singular/><convertible-to-possessive value="false"/></noun><adjective><extensible value="false"/></adjective></w>
<w><t>seem-li-er</t></w>
<w><t>seem-li-est</t></w>
<w><t>seem-li-ness</t></w>
@@ -146935,7 +146935,7 @@
<w><t>shot-ting</t></w>
<w><t>Shot-well</t></w>
<w><t>should</t></w>
-<w><t>shoul-der</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>shoul-der</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<phrase><t>shoulder blade</t></phrase>
<phrase><t>shoulder pad</t></phrase>
<phrase><t>shoulder patch</t></phrase>
@@ -148043,7 +148043,7 @@
<w><t>sis-sonne</t></w>
<w><t>sis-sy</t></w>
<w><t>sis-sy-ish</t></w>
-<w><t>sis-ter</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>sis-ter</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>sis-ter=in=law</t></w>
<w><t>sis-ter-hood</t></w>
<w><t>sis-ter-less</t></w>
@@ -148702,7 +148702,7 @@
<w><t>sli-er</t></w>
<w><t>sliest</t></w>
<w><t>sli-est</t></w>
-<w><t>slight</t><adjective extensible="true"/></w>
+<w><t>slight</t><adjective><extensible/></adjective></w>
<w><t>slight-er</t></w>
<w><t>slight-ing</t></w>
<w><t>slight-ing-ly</t></w>
@@ -149241,7 +149241,7 @@
<w><t>snarl-ing-ly</t></w>
<w><t>snarl-y</t></w>
<w><t>snash</t></w>
-<w><t>snatch</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>snatch</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>snatch-a-ble</t></w>
<w><t>snatch-er</t></w>
<w><t>snatch-i-er</t></w>
@@ -149730,6 +149730,7 @@
<phrase><t>soft shoul-der</t></phrase>
<w><t>soft=cen-tred</t></w>
<w><t>soft=cov-er</t></w>
+<w><t>soft-en</t><verb><regular-root/></verb></w>
<w><t>soft=fo-cus</t></w>
<w><t>soft=head-ed</t></w>
<w><t>soft=head-ed-ness</t></w>
@@ -151834,7 +151835,7 @@
<w><t>spray-ful-ly</t></w>
<w><t>spray-less</t></w>
<w><t>spray-like</t></w>
-<w><t>spread</t><noun/><verb regular-root="false"/></w>
+<w><t>spread</t><noun/><verb><regular-root value="false"/></verb></w>
<phrase><t>spread ea-gle</t></phrase>
<w><t>spread=ea-gle</t></w>
<w><t>spread=ea-gle-ism</t></w>
@@ -152454,7 +152455,7 @@
<w><t>stan-chion</t></w>
<w><t>stanch-less</t></w>
<w><t>stanch-less-ly</t></w>
-<w><t>stand</t><noun number="pluralizable" convertible-to-possessive="true"/><verb/></w>
+<w><t>stand</t><noun><pluralizable/><convertible-to-possessive/></noun><verb/></w>
<phrase><t>stand o-ver</t></phrase>
<w><t>stand=off-ish</t></w>
<w><t>stand=off-ish-ly</t></w>
@@ -152548,7 +152549,7 @@
<w><t>staph-y-lot-o-my</t></w>
<w><t>sta-ple</t></w>
<w><t>sta-pler</t></w>
-<w><t>star</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="false"/></w>
+<w><t>star</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root value="false"/></verb></w>
<phrase><t>Star Cham-ber</t></phrase>
<phrase><t>star con-nec-tion</t></phrase>
<phrase><t>Star of Beth-le-hem</t></phrase>
@@ -152604,7 +152605,7 @@
<w><t>star-ring</t></w>
<w><t>star-ry</t></w>
<w><t>star-ry=eyed</t></w>
-<w><t>stars</t><verb regular-root="false"/></w>
+<w><t>stars</t><verb><regular-root value="false"/></verb></w>
<w><t>stars=of=Beth-le-hem</t></w>
<w><t>stars=of=Je-ru-sa-lem</t></w>
<w><t>start</t></w>
@@ -153630,7 +153631,7 @@
<w><t>stomp-er</t></w>
<w><t>stomp-ing-ly</t></w>
<w><t>ston-a-ble</t></w>
-<w><t>stone</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>stone</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>Stone</t></w>
<phrase><t>stone boil-ing</t></phrase>
<phrase><t>stone bram-ble</t></phrase>
@@ -154028,7 +154029,7 @@
<w><t>Stre-ga</t></w>
<w><t>Strei-sand</t></w>
<w><t>stre-lit-zi-a</t></w>
-<w><t>strength</t><noun number="pluralizable"/></w>
+<w><t>strength</t><noun><pluralizable/></noun></w>
<w><t>strength-en</t></w>
<w><t>strength-en-er</t></w>
<w><t>strength-en-ing-ly</t></w>
@@ -156079,7 +156080,7 @@
<w><t>suc-cess-less</t></w>
<w><t>suc-cess-less-ly</t></w>
<w><t>suc-cess-less-ness</t></w>
-<w><t>suc-ces-sor</t></w>
+<w><t>suc-ces-sor</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>suc-ces-sor-al</t></w>
<w><t>suc-cin-ate</t></w>
<w><t>suc-ci-nate</t></w>
@@ -157947,7 +157948,7 @@
<w><t>sur-plus-age</t></w>
<w><t>sur-print</t></w>
<w><t>sur-pris-al</t></w>
-<w><t>sur-prise</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>sur-prise</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>sur-prised</t><adjective/></w>
<w><t>sur-pris-ed-ly</t></w>
<w><t>sur-pris-er</t></w>
@@ -158311,7 +158312,7 @@
<w><t>sweep-stakes</t></w>
<w><t>sweep-y</t></w>
<w><t>sweer</t></w>
-<w><t>sweet</t><adjective extensible="true"/></w>
+<w><t>sweet</t><adjective><extensible/></adjective></w>
<w><t>Sweet</t></w>
<phrase><t>sweet a-lys-sum</t></phrase>
<phrase><t>sweet bas-il</t></phrase>
@@ -158332,8 +158333,8 @@
<w><t>sweet-bread</t></w>
<w><t>sweet-bri-ar</t></w>
<w><t>sweet-bri-er</t></w>
-<w><t>sweet-en</t><verb regular-root="true"/></w>
-<w><t>sweet-en-er</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>sweet-en</t><verb><regular-root/></verb></w>
+<w><t>sweet-en-er</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>sweet-en-ing</t></w>
<w><t>sweet-heart</t></w>
<phrase><t>sweet-heart a-gree-ment</t></phrase>
@@ -159413,7 +159414,7 @@
<w><t>Tak-a-mat-su</t></w>
<w><t>Ta-ka-ma-tsu</t></w>
<w><t>Ta-kao</t></w>
-<w><t>take</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="false"/></w>
+<w><t>take</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root value="false"/></verb></w>
<phrase><t>take a-back</t></phrase>
<phrase><t>take af-ter</t></phrase>
<phrase><t>take a-part</t></phrase>
@@ -159428,7 +159429,7 @@
<w><t>take-o-ver</t></w>
<w><t>tak-er</t></w>
<w><t>tak-er=in</t></w>
-<w><t>takes</t><verb regular-root="false"/></w>
+<w><t>takes</t><verb><regular-root value="false"/></verb></w>
<w><t>tak-in</t></w>
<w><t>tak-ing</t></w>
<w><t>Ta-ko-ra-di</t></w>
@@ -159471,7 +159472,7 @@
<w><t>tal-is-man</t></w>
<w><t>tal-is-man-ic</t></w>
<w><t>tal-is-man-i-cal-ly</t></w>
-<w><t>talk</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>talk</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<phrase><t>talk a-bout</t></phrase>
<phrase><t>talk in-to</t></phrase>
<w><t>talk-a-bil-i-ty</t></w>
@@ -160184,11 +160185,11 @@
<w><t>tea-ber-ry</t></w>
<w><t>tea-cake</t></w>
<w><t>tea-cart</t></w>
-<w><t>teach</t><verb regular-root="false"/></w>
+<w><t>teach</t><verb><regular-root value="false"/></verb></w>
<w><t>teach-er</t></w>
<w><t>teach-er-less</t></w>
<w><t>teach-er-ship</t></w>
-<w><t>teach-es</t><verb regular-root="false"/></w>
+<w><t>teach-es</t><verb><regular-root value="false"/></verb></w>
<w><t>teach-ing</t></w>
<phrase><t>teach-ing aid</t></phrase>
<phrase><t>teach-ing fel-low</t></phrase>
@@ -160708,7 +160709,7 @@
<w><t>ten-den-tious</t></w>
<w><t>ten-den-tious-ly</t></w>
<w><t>ten-den-tious-ness</t></w>
-<w><t>ten-der</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/><adjective extensible="true"/></w>
+<w><t>ten-der</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb><adjective><extensible/></adjective></w>
<w><t>ten-der=heart-ed</t></w>
<w><t>ten-der=heart-ed-ly</t></w>
<w><t>ten-der-a-bil-i-ty</t></w>
@@ -161907,7 +161908,7 @@
<w><t>Thim-phu</t></w>
<w><t>thin</t></w>
<w><t>thine</t></w>
-<w><t>thing</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>thing</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>thing=in=it-self</t></w>
<w><t>thing-a-ma-bob</t></w>
<w><t>thing-a-ma-jig</t></w>
@@ -162702,7 +162703,7 @@
<w><t>tim-breled</t></w>
<w><t>tim-brelled</t></w>
<w><t>Tim-buk-tu</t></w>
-<w><t>time</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>time</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<phrase><t>time cap-sule</t></phrase>
<phrase><t>time con-stant</t></phrase>
<phrase><t>time de-pos-it</t></phrase>
@@ -163546,7 +163547,7 @@
<w><t>Tor-bay</t></w>
<w><t>tor-bern-ite</t></w>
<w><t>torc</t></w>
-<w><t>torch</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>torch</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>torch-bear-er</t></w>
<w><t>torch-i-er</t></w>
<w><t>tor-chier</t></w>
@@ -164776,7 +164777,7 @@
<phrase><t>treas-ur-y bond</t></phrase>
<phrase><t>treas-ur-y cer-tif-i-cate</t></phrase>
<phrase><t>treas-ur-y note</t></phrase>
-<w><t>treat</t></w>
+<w><t>treat</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>trea-tise</t></w>
<w><t>treat-ment</t></w>
<w><t>trea-ty</t></w>
@@ -164928,7 +164929,7 @@
<w><t>tri-ad-i-cal-ly</t></w>
<w><t>tri-ad-ism</t></w>
<w><t>tri-age</t></w>
-<w><t>tri-al</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>tri-al</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>tri-al and er-ror</t></phrase>
<phrase><t>tri-al bal-ance</t></phrase>
<phrase><t>tri-al bal-loon</t></phrase>
@@ -164971,7 +164972,7 @@
<w><t>trib-al-ist</t></w>
<w><t>trib-al-ly</t></w>
<w><t>tri-ba-sic</t></w>
-<w><t>tribe</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>tribe</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>tribe-less</t></w>
<w><t>tribe-let</t></w>
<w><t>tribes-man</t></w>
@@ -180296,7 +180297,7 @@
<w><t>ven-e-punc-ture</t></w>
<w><t>Ve-ner</t></w>
<w><t>ven-er-a-ble</t></w>
-<w><t>ven-er-ate</t></w>
+<w><t>ven-er-ate</t><verb><regular-root/></verb></w>
<w><t>ven-er-a-tion</t></w>
<w><t>ven-er-a-tion-al</t></w>
<w><t>ven-er-a-tive</t></w>
@@ -181016,7 +181017,7 @@
<w><t>Vi-et-nam-ese</t></w>
<w><t>Vi-et-nam-i-sa-tion</t></w>
<w><t>Vi-et-nam-i-za-tion</t></w>
-<w><t>view</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>view</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<phrase><t>view hal-loo</t></phrase>
<w><t>view-a-ble</t></w>
<w><t>view-er</t></w>
@@ -182710,7 +182711,7 @@
<w><t>watch-tow-er</t></w>
<w><t>Wat-chung</t></w>
<w><t>watch-word</t></w>
-<w><t>wa-ter</t><verb regular-root="true"/></w>
+<w><t>wa-ter</t><verb><regular-root/></verb></w>
<phrase><t>wa-ter back</t></phrase>
<phrase><t>wa-ter bear</t></phrase>
<phrase><t>wa-ter bed</t></phrase>
@@ -184662,7 +184663,7 @@
<w><t>width-wise</t></w>
<w><t>Wi-du-kind</t></w>
<w><t>Wie-land</t></w>
-<w><t>wield</t><verb regular-root="true"/></w>
+<w><t>wield</t><verb><regular-root/></verb></w>
<w><t>wield-a-ble</t></w>
<w><t>wield-er</t></w>
<w><t>wield-i-er</t></w>
@@ -184859,7 +184860,7 @@
<w><t>Wil-ming-to-ni-an</t></w>
<w><t>Wil-more</t></w>
<w><t>Wil-no</t></w>
-<w><t>Wil-son</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>Wil-son</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>Wil-son cloud cham-ber</t></phrase>
<phrase><t>Wil-son's pet-rel</t></phrase>
<phrase><t>Wil-son's snipe</t></phrase>
@@ -185397,7 +185398,7 @@
<w><t>Wol-ver-hamp-ton</t></w>
<w><t>wol-ver-ine</t></w>
<w><t>wolves</t></w>
-<w><t>wom-an</t><noun number="singular" convertible-to-possessive="true"/></w>
+<w><t>wom-an</t><noun><singular/><convertible-to-possessive/></noun></w>
<w><t>wom-an=chas-er</t></w>
<w><t>wom-an=hat-er</t></w>
<w><t>wom-an-hood</t></w>
@@ -185430,7 +185431,7 @@
<w><t>won</t></w>
<w><t>won't</t></w>
<w><t>Won-der</t></w>
-<w><t>won-der</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>won-der</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>won-der=strick-en</t></w>
<w><t>won-der-ber-ry</t></w>
<w><t>won-der-er</t></w>
@@ -185640,7 +185641,7 @@
<w><t>work-book</t></w>
<w><t>work-day</t></w>
<w><t>worked</t></w>
-<w><t>work-er</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>work-er</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>work-er=priest</t></w>
<w><t>work-folks</t></w>
<w><t>work-horse</t></w>
@@ -185681,7 +185682,7 @@
<w><t>work-wom-an</t></w>
<w><t>work-wom-en</t></w>
<w><t>Wor-land</t></w>
-<w><t>world</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>world</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<phrase><t>World Health Or-gan-i-za-tion</t></phrase>
<phrase><t>world lan-guage</t></phrase>
<phrase><t>world pow-er</t></phrase>
@@ -186297,7 +186298,7 @@
<w><t>yeal-ing</t></w>
<w><t>yean</t></w>
<w><t>yean-ling</t></w>
-<w><t>year</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>year</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>year=a-round</t></w>
<w><t>year-book</t></w>
<w><t>year-ling</t></w>
Modified: trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-GBR.dict.xml
===================================================================
--- trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-GBR.dict.xml 2021-11-19 17:56:05 UTC (rev 12103)
+++ trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-GBR.dict.xml 2021-11-20 17:26:39 UTC (rev 12104)
@@ -15,13 +15,13 @@
eng-Latn-999.dict.xml.
-->
-<w><t>co=la-bour-er</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>co=la-bour-er</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>ful-fil</t><verb/></w>
-<w><t>ful-fils</t><verb number="singular"/></w>
+<w><t>ful-fils</t><verb><vu><singular/></vu></verb></w>
<w><t>ful-fil-ment</t><noun/></w>
-<w><t>la-bour</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>la-bour</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>la-boured</t><adjective/></w>
-<w><t>la-bour-er</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>la-bour-er</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>mod-elled</t><verb/></w>
-<w><t>mod-ell-ing</t><noun number="singular" convertible-to-possessive="true"/><verb/></w>
+<w><t>mod-ell-ing</t><noun><singular/><convertible-to-possessive/></noun><verb/></w>
</axsl-dictionary>
Modified: trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-USA.dict.xml
===================================================================
--- trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-USA.dict.xml 2021-11-19 17:56:05 UTC (rev 12103)
+++ trunk/foray/foray-orthography/src/main/data/dictionaries/eng-Latn-USA.dict.xml 2021-11-20 17:26:39 UTC (rev 12104)
@@ -15,12 +15,12 @@
eng-Latn-999.dict.xml.
-->
-<w><t>co=la-bor-er</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
-<w><t>ful-fill</t><verb regular-root="true"/></w>
+<w><t>co=la-bor-er</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
+<w><t>ful-fill</t><verb><regular-root/></verb></w>
<w><t>ful-fill-ment</t><noun/></w>
-<w><t>la-bor</t><noun number="pluralizable" convertible-to-possessive="true"/><verb regular-root="true"/></w>
+<w><t>la-bor</t><noun><pluralizable/><convertible-to-possessive/></noun><verb><regular-root/></verb></w>
<w><t>la-bored</t><adjective/></w>
-<w><t>la-bor-er</t><noun number="pluralizable" convertible-to-possessive="true"/></w>
+<w><t>la-bor-er</t><noun><pluralizable/><convertible-to-possessive/></noun></w>
<w><t>mod-eled</t><verb/></w>
-<w><t>mod-el-ing</t><noun number="singular" convertible-to-possessive="true"/><verb/></w>
+<w><t>mod-el-ing</t><noun><singular/><convertible-to-possessive/></noun><verb/></w>
</axsl-dictionary>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-11-19 17:56:08
|
Revision: 12103
http://sourceforge.net/p/foray/code/12103
Author: victormote
Date: 2021-11-19 17:56:05 +0000 (Fri, 19 Nov 2021)
Log Message:
-----------
Conform to aXSL change: Move WritingSystem interface from axsl-common to axsl-orthography.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/i18n/WritingSystem4a.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/i18n/WritingSystem4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/i18n/WritingSystem4a.java 2021-11-19 17:44:46 UTC (rev 12102)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/i18n/WritingSystem4a.java 2021-11-19 17:56:05 UTC (rev 12103)
@@ -34,7 +34,7 @@
import org.axsl.common.i18n.Country;
import org.axsl.common.i18n.Language;
import org.axsl.common.i18n.Script;
-import org.axsl.common.i18n.WritingSystem;
+import org.axsl.orthography.WritingSystem;
import com.ibm.icu.util.ULocale;
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2021-11-19 17:44:46 UTC (rev 12102)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2021-11-19 17:56:05 UTC (rev 12103)
@@ -60,7 +60,6 @@
import org.foray.fotree.value.DtWritingMode;
import org.axsl.common.i18n.Script;
-import org.axsl.common.i18n.WritingSystem;
import org.axsl.common.para.ParaConfig;
import org.axsl.common.para.ParaGlue;
import org.axsl.common.para.ParaLeaf;
@@ -135,6 +134,7 @@
import org.axsl.graphic.GraphicServer;
import org.axsl.orthography.Orthography;
import org.axsl.orthography.OrthographyServer;
+import org.axsl.orthography.WritingSystem;
import org.axsl.speech.SpeechException;
import org.axsl.speech.SpeechServer;
import org.axsl.speech.Voice;
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java 2021-11-19 17:44:46 UTC (rev 12102)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/OrthographyServer4a.java 2021-11-19 17:56:05 UTC (rev 12103)
@@ -41,9 +41,9 @@
import org.foray.orthography.util.OrthographyConfigParser;
import org.axsl.common.i18n.Language;
-import org.axsl.common.i18n.WritingSystem;
import org.axsl.orthography.OrthographyException;
import org.axsl.orthography.OrthographyServer;
+import org.axsl.orthography.WritingSystem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-19 17:44:46 UTC (rev 12102)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2021-11-19 17:56:05 UTC (rev 12103)
@@ -41,8 +41,8 @@
import org.foray.orthography.OrthographyServerConfig;
import org.foray.orthography.SegmentDictionary;
-import org.axsl.common.i18n.WritingSystem;
import org.axsl.orthography.OrthographyException;
+import org.axsl.orthography.WritingSystem;
import org.axsl.orthography.optional.Dictionary;
import org.apache.commons.cli.CommandLine;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|