foray-commit Mailing List for FOray (Page 21)
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
|
Dec
|
|
From: <vic...@us...> - 2025-02-13 13:47:46
|
Revision: 13376
http://sourceforge.net/p/foray/code/13376
Author: victormote
Date: 2025-02-13 13:47:43 +0000 (Thu, 13 Feb 2025)
Log Message:
-----------
Fixes to locations of start and end element tags.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-13 13:21:27 UTC (rev 13375)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-13 13:47:43 UTC (rev 13376)
@@ -372,16 +372,15 @@
* @return The number of levels of indentation for the start tag of the current element.
*/
private int computeStartTagIndentation() {
- return this.elementStack.size() - 1;
-// final ElementUsage usage = this.elementStack.peek().getUsage();
-// switch (usage) {
-// case STRUCTURAL: return true;
-// case BLOCK: return true;
-// case INLINE_MIXED: return false;
-// case INLINE_UNMIXED: return false;
-// case INLINE_UNMIXED_CONTENT: return true;
-// default: throw new IllegalStateException("Unexpected Element Usage: " + usage);
-// }
+ final ModelElementUsage modelElement = this.elementStack.peek();
+ switch (modelElement.getUsage()) {
+ case STRUCTURAL:
+ case BLOCK: return this.elementStack.size() - 1;
+ case INLINE_MIXED:
+ case INLINE_UNMIXED: return 0;
+ case INLINE_UNMIXED_CONTENT: return modelElement.getDistanceFromNearestBlock() - 1;
+ default: throw new IllegalStateException("Unexpected Element Usage: " + modelElement.getUsage());
+ }
}
@@ -416,17 +415,15 @@
* @return The number of levels of indentation for the end tag of the current element.
*/
private int computeEndTagIndentation() {
- return this.elementStack.size() - 1;
-//
-// final ElementUsage usage = this.elementStack.peek().getUsage();
-// switch (usage) {
-// case STRUCTURAL: return true;
-// case BLOCK: return true;
-// case INLINE_MIXED: return false;
-// case INLINE_UNMIXED: return false;
-// case INLINE_UNMIXED_CONTENT: return true;
-// default: throw new IllegalStateException("Unexpected Element Usage: " + usage);
-// }
+ final ModelElementUsage modelElementUsage = this.elementStack.peek();
+ switch (modelElementUsage.getUsage()) {
+ case STRUCTURAL: return this.elementStack.size() - 1;
+ case BLOCK:
+ case INLINE_MIXED:
+ case INLINE_UNMIXED: return 0;
+ case INLINE_UNMIXED_CONTENT: return modelElementUsage.getDistanceFromNearestBlock();
+ default: throw new IllegalStateException("Unexpected Element Usage: " + modelElementUsage.getUsage());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-13 13:21:30
|
Revision: 13375
http://sourceforge.net/p/foray/code/13375
Author: victormote
Date: 2025-02-13 13:21:27 +0000 (Thu, 13 Feb 2025)
Log Message:
-----------
Consolidate logic for whether indentation should occur with the computation of the amount.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-13 12:38:04 UTC (rev 13374)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-13 13:21:27 UTC (rev 13375)
@@ -263,8 +263,9 @@
if (this.startTagOnNewLine()) {
this.prettyOutput.flush();
this.prettyOutput.write(this.config.getLineTerminator());
- if (this.shouldIndent()) {
- this.prettyOutput.write(indent(currentIndentation()));
+ final int indentLevels = this.computeStartTagIndentation();
+ if (indentLevels > 0) {
+ this.prettyOutput.write(indent(indentLevels));
}
this.prettyOutput.write(startTagOpen.toString());
} else {
@@ -294,10 +295,8 @@
/* Whitespace at beginning of attribute. */
if (this.elementStack.peek().getUsage() == ElementUsage.BLOCK
|| this.elementStack.peek().getUsage() == ElementUsage.STRUCTURAL) {
- if (shouldIndent()) {
- final int indentLevels = currentIndentation() + this.config.getExtraAttributeIndentationLevels();
- attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
- }
+ final int indentLevels = computeStartTagIndentation() + this.config.getExtraAttributeIndentationLevels();
+ attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
} else {
attributesContent.add(StringUtils.SINGLE_SPACE);
}
@@ -323,28 +322,6 @@
}
- /**
- * Returns what should be written to indent a line.
- * @param qtyLevels The number of levels of indentation to be returned.
- * @return The String content that should be written to indent a line.
- */
- private String indent(final int qtyLevels) {
- if (qtyLevels > MAX_QTY_INDENTATION_LEVELS) {
- throw new IllegalArgumentException("Maximum indentation levels is " + MAX_QTY_INDENTATION_LEVELS);
- }
- if (INDENTATION[qtyLevels] == null) {
- final StringBuilder buffer = new StringBuilder(this.config.getIndentString().length() * qtyLevels);
- int numIndents = qtyLevels;
- while (numIndents > 0) {
- buffer.append(this.config.getIndentString());
- numIndents --;
- }
- INDENTATION[qtyLevels] = buffer.toString();
- }
- return INDENTATION[qtyLevels];
- }
-
-
@Override
public void endElement(final String uri, final String local, final String qName) {
flushCharacters();
@@ -353,7 +330,8 @@
if (endTagOnNewLine()) {
this.prettyOutput.flush();
this.prettyOutput.write(this.config.getLineTerminator());
- this.prettyOutput.write(indent(currentIndentation()));
+ final int indentationLevels = computeEndTagIndentation();
+ this.prettyOutput.write(indent(indentationLevels));
}
this.prettyOutput.add("</" + qName + ">");
if (endTagOnNewLine()) {
@@ -390,19 +368,20 @@
/**
- * Indicates whether the top element in the stack should be indented.
- * @return True if and only if the top element in the stack should be indented.
+ * Computes the indentation for the start tag of the element at the top of the stack.
+ * @return The number of levels of indentation for the start tag of the current element.
*/
- private boolean shouldIndent() {
- final ElementUsage usage = this.elementStack.peek().getUsage();
- switch (usage) {
- case STRUCTURAL: return true;
- case BLOCK: return true;
- case INLINE_MIXED: return false;
- case INLINE_UNMIXED: return false;
- case INLINE_UNMIXED_CONTENT: return true;
- default: throw new IllegalStateException("Unexpected Element Usage: " + usage);
- }
+ private int computeStartTagIndentation() {
+ return this.elementStack.size() - 1;
+// final ElementUsage usage = this.elementStack.peek().getUsage();
+// switch (usage) {
+// case STRUCTURAL: return true;
+// case BLOCK: return true;
+// case INLINE_MIXED: return false;
+// case INLINE_UNMIXED: return false;
+// case INLINE_UNMIXED_CONTENT: return true;
+// default: throw new IllegalStateException("Unexpected Element Usage: " + usage);
+// }
}
@@ -431,6 +410,48 @@
}
}
+
+ /**
+ * Computes the indentation for the end tag of the element at the top of the stack.
+ * @return The number of levels of indentation for the end tag of the current element.
+ */
+ private int computeEndTagIndentation() {
+ return this.elementStack.size() - 1;
+//
+// final ElementUsage usage = this.elementStack.peek().getUsage();
+// switch (usage) {
+// case STRUCTURAL: return true;
+// case BLOCK: return true;
+// case INLINE_MIXED: return false;
+// case INLINE_UNMIXED: return false;
+// case INLINE_UNMIXED_CONTENT: return true;
+// default: throw new IllegalStateException("Unexpected Element Usage: " + usage);
+// }
+ }
+
+
+ /**
+ * Returns what should be written to indent a line.
+ * @param qtyLevels The number of levels of indentation to be returned.
+ * @return The String content that should be written to indent a line.
+ */
+ private String indent(final int qtyLevels) {
+ if (qtyLevels > MAX_QTY_INDENTATION_LEVELS) {
+ throw new IllegalArgumentException("Maximum indentation levels is " + MAX_QTY_INDENTATION_LEVELS);
+ }
+ if (INDENTATION[qtyLevels] == null) {
+ final StringBuilder buffer = new StringBuilder(this.config.getIndentString().length() * qtyLevels);
+ int numIndents = qtyLevels;
+ while (numIndents > 0) {
+ buffer.append(this.config.getIndentString());
+ numIndents --;
+ }
+ INDENTATION[qtyLevels] = buffer.toString();
+ }
+ return INDENTATION[qtyLevels];
+ }
+
+
@Override
public void characters(final char[] buffer, final int offset, final int length) {
/* For whatever insanely sadly stupid reason, ignorable whitespace is treated as ignorable whitespace only if
@@ -580,14 +601,6 @@
public void endEntity(final String name) {
}
- /**
- * 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.
- */
- private int currentIndentation() {
- return this.elementStack.size() - 1;
- }
@Override
public void reset() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-13 12:38:07
|
Revision: 13374
http://sourceforge.net/p/foray/code/13374
Author: victormote
Date: 2025-02-13 12:38:04 +0000 (Thu, 13 Feb 2025)
Log Message:
-----------
Store indentation Strings so that they can be reused.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-13 12:27:05 UTC (rev 13373)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-13 12:38:04 UTC (rev 13374)
@@ -83,6 +83,12 @@
/** Command-line return status constant indicating that there was an error parsing the input file. */
public static final byte STATUS_PARSING_ERROR = 3;
+ /** Constant used to create the {@link #INDENTATION} array. */
+ private static final int MAX_QTY_INDENTATION_LEVELS = 20;
+
+ /** Array containing already already-created indentation strings. */
+ private static final String[] INDENTATION = new String[MAX_QTY_INDENTATION_LEVELS];
+
/** The configuration for this pretty-printer. */
private ForayPrettyConfig config;
@@ -258,7 +264,7 @@
this.prettyOutput.flush();
this.prettyOutput.write(this.config.getLineTerminator());
if (this.shouldIndent()) {
- this.prettyOutput.write(indent());
+ this.prettyOutput.write(indent(currentIndentation()));
}
this.prettyOutput.write(startTagOpen.toString());
} else {
@@ -319,16 +325,23 @@
/**
* Returns what should be written to indent a line.
+ * @param qtyLevels The number of levels of indentation to be returned.
* @return The String content that should be written to indent a line.
*/
- private String indent() {
- int numIndents = currentIndentation();
- final StringBuilder buffer = new StringBuilder();
- while (numIndents > 0) {
- buffer.append(this.config.getIndentString());
- numIndents --;
+ private String indent(final int qtyLevels) {
+ if (qtyLevels > MAX_QTY_INDENTATION_LEVELS) {
+ throw new IllegalArgumentException("Maximum indentation levels is " + MAX_QTY_INDENTATION_LEVELS);
}
- return buffer.toString();
+ if (INDENTATION[qtyLevels] == null) {
+ final StringBuilder buffer = new StringBuilder(this.config.getIndentString().length() * qtyLevels);
+ int numIndents = qtyLevels;
+ while (numIndents > 0) {
+ buffer.append(this.config.getIndentString());
+ numIndents --;
+ }
+ INDENTATION[qtyLevels] = buffer.toString();
+ }
+ return INDENTATION[qtyLevels];
}
@@ -340,7 +353,7 @@
if (endTagOnNewLine()) {
this.prettyOutput.flush();
this.prettyOutput.write(this.config.getLineTerminator());
- this.prettyOutput.write(indent());
+ this.prettyOutput.write(indent(currentIndentation()));
}
this.prettyOutput.add("</" + qName + ">");
if (endTagOnNewLine()) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-13 12:27:07
|
Revision: 13373
http://sourceforge.net/p/foray/code/13373
Author: victormote
Date: 2025-02-13 12:27:05 +0000 (Thu, 13 Feb 2025)
Log Message:
-----------
Accommodate non-space indentation (in case someone wants to use tabs, for example).
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java 2025-02-13 11:51:34 UTC (rev 13372)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java 2025-02-13 12:27:05 UTC (rev 13373)
@@ -63,8 +63,8 @@
/** Set this to true if PCDATA content can have space characters replaced by line terminators and vice versa. */
private boolean breakPCDATA = true;
- /** The number of spaces that should be indented for each level. */
- private int indent = 2;
+ /** The String that should be used as indentation for each level. */
+ private String indentString = " ";
/** The maximum number of characters desired on each line. */
private int desiredLineLength = DEFAULT_LINE_LENGTH;
@@ -199,21 +199,19 @@
}
/**
- * Returns the number of spaces that should be indented for each level.
- * @return The number of spaces that should be indented for each level.
+ * Returns the string that should be used for one level of indentation.
+ * @return The string that should be used for one level of indentation.
*/
- public int getIndent() {
- return indent;
+ public String getIndentString() {
+ return this.indentString;
}
/**
- * Use this configuration parameter to set the number of spaces that each successive block level of the document
- * should be indented.
- * The default is 2.
- * @param indent The new value.
+ * Set the string that should be used for one level of indentation.
+ * @param indentString The new string.
*/
- public void setIndent(final int indent) {
- this.indent = indent;
+ public void setIndentString(final String indentString) {
+ this.indentString = indentString;
}
/**
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java 2025-02-13 11:51:34 UTC (rev 13372)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java 2025-02-13 12:27:05 UTC (rev 13373)
@@ -35,7 +35,6 @@
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
/**
@@ -54,7 +53,7 @@
private final class ContingentIndentation implements CharSequence {
/** The number of indentation levels to be used if indentation takes place. */
- private final int levels;
+ private final String indentString;
/**
* Constructor.
@@ -61,38 +60,33 @@
* @param levels The number of space characters to be used if indentation takes place.
*/
private ContingentIndentation(final int levels) {
- this.levels = levels;
+ int numIndents = levels;
+ final StringBuilder buffer = new StringBuilder();
+ while (numIndents > 0) {
+ buffer.append(ForayPrettyOutput.this.config.getIndentString());
+ numIndents --;
+ }
+ this.indentString = buffer.toString();
}
@Override
public int length() {
- return this.levels * ForayPrettyOutput.this.config.getIndent();
+ return this.indentString.length();
}
@Override
public char charAt(final int index) {
- if (index < 0 || index >= (levels * ForayPrettyOutput.this.config.getIndent())) {
- throw new IndexOutOfBoundsException();
- }
- /* All content is the space character. */
- return ' ';
+ return this.indentString.charAt(index);
}
@Override
- public String subSequence(final int start, final int end) {
- if (start < 0
- || end > (levels * ForayPrettyOutput.this.config.getIndent())
- || end < start) {
- throw new IndexOutOfBoundsException();
- }
- final char[] array = new char[end - start];
- Arrays.fill(array, ' ');
- return new String(array);
+ public CharSequence subSequence(final int start, final int end) {
+ return this.indentString.subSequence(start, end);
}
@Override
public String toString() {
- return subSequence(0, this.levels * ForayPrettyOutput.this.config.getIndent());
+ return this.indentString;
}
}
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-13 11:51:34 UTC (rev 13372)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-13 12:27:05 UTC (rev 13373)
@@ -322,10 +322,10 @@
* @return The String content that should be written to indent a line.
*/
private String indent() {
- int numIndents = currentIndentation() * this.config.getIndent();
+ int numIndents = currentIndentation();
final StringBuilder buffer = new StringBuilder();
while (numIndents > 0) {
- buffer.append(StringUtils.SINGLE_SPACE);
+ buffer.append(this.config.getIndentString());
numIndents --;
}
return buffer.toString();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-13 11:51:37
|
Revision: 13372
http://sourceforge.net/p/foray/code/13372
Author: victormote
Date: 2025-02-13 11:51:34 +0000 (Thu, 13 Feb 2025)
Log Message:
-----------
1. Handle content within BLOCK elements better. 2. Don't try to indent within attributes.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/model/ElementStack.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 23:21:19 UTC (rev 13371)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-13 11:51:34 UTC (rev 13372)
@@ -32,6 +32,7 @@
import org.foray.xml.dtd.DtdElement;
import org.foray.xml.model.ElementStack;
import org.foray.xml.model.ElementStack.ElementUsage;
+import org.foray.xml.model.ElementStack.ModelElementUsage;
import org.foray.xml.model.XmlModelElement;
import org.foray.xml.model.XsdElement;
@@ -306,13 +307,7 @@
for (int pieceIndex = 0; pieceIndex < pieces.length; pieceIndex ++) {
attributesContent.add(pieces[pieceIndex]);
if (pieceIndex < pieces.length - 1) {
- if (shouldIndent()) {
- final int indentLevels = currentIndentation() +
- this.config.getExtraIntraAttributeIndentationLevels();
- attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
- } else {
- attributesContent.add(StringUtils.SINGLE_SPACE);
- }
+ attributesContent.add(StringUtils.SINGLE_SPACE);
}
}
} else {
@@ -321,20 +316,6 @@
attributesContent.add("\"");
}
- /**
- * Indicates whether the top element in the stack should be indented.
- * @return True if and only if the top element in the stack should be indented.
- */
- private boolean shouldIndent() {
- final ElementUsage usage = this.elementStack.peek().getUsage();
- switch (usage) {
- case STRUCTURAL: return true;
- case BLOCK: return true;
- case INLINE_MIXED: return false;
- case INLINE_UNMIXED: return false;
- default: throw new IllegalStateException("Unexpected Element Usage: " + usage);
- }
- }
/**
* Returns what should be written to indent a line.
@@ -350,6 +331,7 @@
return buffer.toString();
}
+
@Override
public void endElement(final String uri, final String local, final String qName) {
flushCharacters();
@@ -388,22 +370,50 @@
case BLOCK: return true;
case INLINE_MIXED: return false;
case INLINE_UNMIXED: return false;
+ case INLINE_UNMIXED_CONTENT: return true;
default: throw new IllegalStateException("Unexpected Element Usage: " + usage);
}
}
+
/**
+ * Indicates whether the top element in the stack should be indented.
+ * @return True if and only if the top element in the stack should be indented.
+ */
+ private boolean shouldIndent() {
+ final ElementUsage usage = this.elementStack.peek().getUsage();
+ switch (usage) {
+ case STRUCTURAL: return true;
+ case BLOCK: return true;
+ case INLINE_MIXED: return false;
+ case INLINE_UNMIXED: return false;
+ case INLINE_UNMIXED_CONTENT: return true;
+ default: throw new IllegalStateException("Unexpected Element Usage: " + usage);
+ }
+ }
+
+
+ /**
* Determines whether the end tag for the current element should be written on a new line or whether it should be
* written immediately after the contents.
* @return True if the end tag for the current element should be written on a new line.
*/
private boolean endTagOnNewLine() {
- final ElementUsage usage = this.elementStack.peek().getUsage();
+ final ModelElementUsage modelElementUsage = this.elementStack.peek();
+ final ElementUsage usage = modelElementUsage.getUsage();
switch (usage) {
case STRUCTURAL: return true;
case BLOCK: return false;
case INLINE_MIXED: return false;
case INLINE_UNMIXED: return true;
+ case INLINE_UNMIXED_CONTENT: {
+ final XmlModelElement modelElement = modelElementUsage.getModelElement();
+ if (modelElement.canContainPCDATA()
+ || modelElement.isPCDATA()) {
+ return false;
+ }
+ return true;
+ }
default: throw new IllegalStateException("Unexpected Element Usage: " + usage);
}
}
@@ -413,17 +423,11 @@
/* For whatever insanely sadly stupid reason, ignorable whitespace is treated as ignorable whitespace only if
* the document is validated with a DTD. If it is validated with XML Schema, the ignorable whitespace is
* passed through to the characters() method. We must manually handle that decision here. */
- final ElementUsage usage = this.elementStack.peek().getUsage();
- switch (usage) {
- case BLOCK:
- case INLINE_MIXED: {
+ final XmlModelElement modelElement = this.elementStack.peek().getModelElement();
+ if (modelElement.canContainPCDATA()
+ || modelElement.isPCDATA()) {
getTextAccumulator().append(buffer, offset + this.charsToSkip, length - this.charsToSkip);
- break;
}
- case OTHER: throw new IllegalStateException("Unexpected Element Usage: " + usage);
- default: break;
- }
-
this.charsToSkip = 0;
}
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/model/ElementStack.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/model/ElementStack.java 2025-02-12 23:21:19 UTC (rev 13371)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/model/ElementStack.java 2025-02-13 11:51:34 UTC (rev 13372)
@@ -55,9 +55,12 @@
/** An element whose parent is BLOCK, and who has mixed content. */
INLINE_MIXED,
- /** An element whose parent is BLOCK, and which does not have mixed content.*/
+ /** An element whose parent is BLOCK, and which does not have mixed content. */
INLINE_UNMIXED,
+ /** An element whose parent is INLINE_UNMIXED. */
+ INLINE_UNMIXED_CONTENT,
+
/** An element not satisfying any of the other usages. */
OTHER
}
@@ -73,14 +76,22 @@
/** The usage for {@link #modelElement} in this stack. */
private ElementUsage usage;
+ /** The number of levels in the stack between this element and its nearest ancestor
+ * {@link ElementUsage#BLOCK}. */
+ private int distanceFromNearestBlock;
+
/**
* Constuctor.
* @param modelElement The wrapped model element.
* @param usage The usage for {@code modelElement} in this stack.
+ * @param distanceFromNearestBlock The number of levels in the stack between this element and its nearest
+ * ancestor {@link ElementUsage#BLOCK}.
*/
- private ModelElementUsage(final XmlModelElement modelElement, final ElementUsage usage) {
+ private ModelElementUsage(final XmlModelElement modelElement, final ElementUsage usage,
+ final int distanceFromNearestBlock) {
this.modelElement = modelElement;
this.usage = usage;
+ this.distanceFromNearestBlock = distanceFromNearestBlock;
}
/**
@@ -98,6 +109,16 @@
public ElementUsage getUsage() {
return this.usage;
}
+
+ /**
+ * Returns the number of levels in the stack between this element and its nearest ancestor
+ * {@link ElementUsage#BLOCK}.
+ * @return The number of levels in the stack between this element and its nearest ancestor
+ * {@link ElementUsage#BLOCK}.
+ */
+ public int getDistanceFromNearestBlock() {
+ return this.distanceFromNearestBlock;
+ }
}
/** The actual element stack. */
@@ -118,14 +139,15 @@
throw new IllegalArgumentException("Cannot add a null item to the element stack.");
}
final ElementUsage usage = computeUsage(element);
- final ModelElementUsage elementUsage = new ModelElementUsage(element, usage);
- this.stack.add(elementUsage);
+ final int distanceFromNearestBlock = computeDistanceFromNearestBlock(element);
+ final ModelElementUsage modelElement = new ModelElementUsage(element, usage, distanceFromNearestBlock);
+ this.stack.add(modelElement);
}
/**
* Computes the usage of the element that is about to be added to the stack.
* @param newElement The element to be added to the stack.
- * @return The computed usage for {@code element}.
+ * @return The computed usage for {@code newElement}.
*/
private ElementUsage computeUsage(final XmlModelElement newElement) {
final ModelElementUsage topElement = peek();
@@ -145,6 +167,9 @@
}
}
if (topElement.usage == ElementUsage.INLINE_UNMIXED) {
+ return ElementUsage.INLINE_UNMIXED_CONTENT;
+ }
+ if (topElement.usage == ElementUsage.INLINE_MIXED) {
if (newElement.canContainPCDATA()) {
return ElementUsage.INLINE_MIXED;
} else {
@@ -151,7 +176,7 @@
return ElementUsage.INLINE_UNMIXED;
}
}
- if (topElement.usage == ElementUsage.INLINE_MIXED) {
+ if (topElement.usage == ElementUsage.INLINE_UNMIXED_CONTENT) {
if (newElement.canContainPCDATA()) {
return ElementUsage.INLINE_MIXED;
} else {
@@ -163,6 +188,26 @@
/**
+ * Computes the number of levels in the stack between the new element and its nearest ancestor
+ * {@link ElementUsage#BLOCK}.
+ * @param newElement The element to be added to the stack.
+ * @return The computed levels for {@code newElement}.
+ */
+ private int computeDistanceFromNearestBlock(final XmlModelElement newElement) {
+ final ModelElementUsage modelElement = peek();
+ if (modelElement == null) {
+ return 0;
+ }
+ if (modelElement.getUsage() == ElementUsage.BLOCK) {
+ return 1;
+ }
+ if (modelElement.getDistanceFromNearestBlock() == 0) {
+ return 0;
+ }
+ return modelElement.getDistanceFromNearestBlock() + 1;
+ }
+
+ /**
* Pop an item off of the stack.
* @return The popped element, or null if the stack is empty.
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-12 23:21:22
|
Revision: 13371
http://sourceforge.net/p/foray/code/13371
Author: victormote
Date: 2025-02-12 23:21:19 +0000 (Wed, 12 Feb 2025)
Log Message:
-----------
Fix indentation of attributes.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 22:57:32 UTC (rev 13370)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 23:21:19 UTC (rev 13371)
@@ -287,8 +287,10 @@
/* Whitespace at beginning of attribute. */
if (this.elementStack.peek().getUsage() == ElementUsage.BLOCK
|| this.elementStack.peek().getUsage() == ElementUsage.STRUCTURAL) {
- final int indentLevels = currentIndentation() + this.config.getExtraAttributeIndentationLevels();
- attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
+ if (shouldIndent()) {
+ final int indentLevels = currentIndentation() + this.config.getExtraAttributeIndentationLevels();
+ attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
+ }
} else {
attributesContent.add(StringUtils.SINGLE_SPACE);
}
@@ -304,9 +306,13 @@
for (int pieceIndex = 0; pieceIndex < pieces.length; pieceIndex ++) {
attributesContent.add(pieces[pieceIndex]);
if (pieceIndex < pieces.length - 1) {
- final int indentLevels = currentIndentation() +
- this.config.getExtraIntraAttributeIndentationLevels();
- attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
+ if (shouldIndent()) {
+ final int indentLevels = currentIndentation() +
+ this.config.getExtraIntraAttributeIndentationLevels();
+ attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
+ } else {
+ attributesContent.add(StringUtils.SINGLE_SPACE);
+ }
}
}
} else {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-12 22:57:35
|
Revision: 13370
http://sourceforge.net/p/foray/code/13370
Author: victormote
Date: 2025-02-12 22:57:32 +0000 (Wed, 12 Feb 2025)
Log Message:
-----------
Compute, store in the stack, and use the usages of each element to improve decision-making regarding line breaks and indentation.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/model/ElementStack.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XsdElement.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 17:38:40 UTC (rev 13369)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 22:57:32 UTC (rev 13370)
@@ -31,6 +31,7 @@
import org.foray.primitive.StringUtils;
import org.foray.xml.dtd.DtdElement;
import org.foray.xml.model.ElementStack;
+import org.foray.xml.model.ElementStack.ElementUsage;
import org.foray.xml.model.XmlModelElement;
import org.foray.xml.model.XsdElement;
@@ -284,7 +285,8 @@
}
/* Whitespace at beginning of attribute. */
- if (this.elementStack.topIsBlockElement()) {
+ if (this.elementStack.peek().getUsage() == ElementUsage.BLOCK
+ || this.elementStack.peek().getUsage() == ElementUsage.STRUCTURAL) {
final int indentLevels = currentIndentation() + this.config.getExtraAttributeIndentationLevels();
attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
} else {
@@ -318,14 +320,14 @@
* @return True if and only if the top element in the stack should be indented.
*/
private boolean shouldIndent() {
- if (! this.elementStack.topIsBlockElement()) {
- return false;
+ final ElementUsage usage = this.elementStack.peek().getUsage();
+ switch (usage) {
+ case STRUCTURAL: return true;
+ case BLOCK: return true;
+ case INLINE_MIXED: return false;
+ case INLINE_UNMIXED: return false;
+ default: throw new IllegalStateException("Unexpected Element Usage: " + usage);
}
- if (this.elementStack.topIsInsideMixedContent()) {
- return this.config.isIndentBlocksInsideMixedContent();
- }
- /* It is a block element, not inside mixed content. Indent it. */
- return true;
}
/**
@@ -374,7 +376,14 @@
* @return True if the start tag for the current element should be written on a new line.
*/
private boolean startTagOnNewLine() {
- return this.elementStack.topIsBlockElement();
+ final ElementUsage usage = this.elementStack.peek().getUsage();
+ switch (usage) {
+ case STRUCTURAL: return true;
+ case BLOCK: return true;
+ case INLINE_MIXED: return false;
+ case INLINE_UNMIXED: return false;
+ default: throw new IllegalStateException("Unexpected Element Usage: " + usage);
+ }
}
/**
@@ -383,14 +392,14 @@
* @return True if the end tag for the current element should be written on a new line.
*/
private boolean endTagOnNewLine() {
- if (! this.elementStack.topIsBlockElement()) {
- return false;
+ final ElementUsage usage = this.elementStack.peek().getUsage();
+ switch (usage) {
+ case STRUCTURAL: return true;
+ case BLOCK: return false;
+ case INLINE_MIXED: return false;
+ case INLINE_UNMIXED: return true;
+ default: throw new IllegalStateException("Unexpected Element Usage: " + usage);
}
- /* If the current element contains PCDATA, the end tag should be written in-line instead of on a new line. */
- if (this.elementStack.topCanHavePCDATA()) {
- return false;
- }
- return true;
}
@Override
@@ -398,9 +407,17 @@
/* For whatever insanely sadly stupid reason, ignorable whitespace is treated as ignorable whitespace only if
* the document is validated with a DTD. If it is validated with XML Schema, the ignorable whitespace is
* passed through to the characters() method. We must manually handle that decision here. */
- if (this.elementStack.topCanHavePCDATA()) {
+ final ElementUsage usage = this.elementStack.peek().getUsage();
+ switch (usage) {
+ case BLOCK:
+ case INLINE_MIXED: {
getTextAccumulator().append(buffer, offset + this.charsToSkip, length - this.charsToSkip);
+ break;
}
+ case OTHER: throw new IllegalStateException("Unexpected Element Usage: " + usage);
+ default: break;
+ }
+
this.charsToSkip = 0;
}
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/model/ElementStack.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/model/ElementStack.java 2025-02-12 17:38:40 UTC (rev 13369)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/model/ElementStack.java 2025-02-12 22:57:32 UTC (rev 13370)
@@ -36,8 +36,72 @@
*/
public class ElementStack {
+ /**
+ * Enumeration of element usages.
+ * These usages are not fixed by the element type, but are dependent on the element's position in the stack.
+ * For example, suppose a "Comment" element can appear anywhere in the document, and that it can have mixed content
+ * (i.e. can contain text).
+ * If all of its ancestors are of usage "STRUCTURAL", it is usage "BLOCK".
+ * If instead its immediate ancestor is usage "BLOCK", it is usage "INLINE_MIXED".
+ */
+ public enum ElementUsage {
+ /** An element whose content is not mixed (contains no text), and whose ancestors are all also STRUCTURAL
+ * elements. */
+ STRUCTURAL,
+
+ /** An element whose ancestors are all STRUCTURAL, but which has mixed content. */
+ BLOCK,
+
+ /** An element whose parent is BLOCK, and who has mixed content. */
+ INLINE_MIXED,
+
+ /** An element whose parent is BLOCK, and which does not have mixed content.*/
+ INLINE_UNMIXED,
+
+ /** An element not satisfying any of the other usages. */
+ OTHER
+ }
+
+ /**
+ * Wrapper around an {@link XmlModelElement}, storing its usage in this stack.
+ */
+ public final class ModelElementUsage {
+
+ /** The wrapped model element. */
+ private XmlModelElement modelElement;
+
+ /** The usage for {@link #modelElement} in this stack. */
+ private ElementUsage usage;
+
+ /**
+ * Constuctor.
+ * @param modelElement The wrapped model element.
+ * @param usage The usage for {@code modelElement} in this stack.
+ */
+ private ModelElementUsage(final XmlModelElement modelElement, final ElementUsage usage) {
+ this.modelElement = modelElement;
+ this.usage = usage;
+ }
+
+ /**
+ * Returns the wrapped model element.
+ * @return The wrapped model element.
+ */
+ public XmlModelElement getModelElement() {
+ return this.modelElement;
+ }
+
+ /**
+ * Returns the usage for {@link #getModelElement()} in this stack.
+ * @return the usage for {@link #getModelElement()} in this stack.
+ */
+ public ElementUsage getUsage() {
+ return this.usage;
+ }
+ }
+
/** The actual element stack. */
- private List<XmlModelElement> stack = new ArrayList<XmlModelElement>();
+ private List<ModelElementUsage> stack = new ArrayList<ModelElementUsage>();
/**
* Constructor.
@@ -53,15 +117,57 @@
if (element == null) {
throw new IllegalArgumentException("Cannot add a null item to the element stack.");
}
- this.stack.add(element);
+ final ElementUsage usage = computeUsage(element);
+ final ModelElementUsage elementUsage = new ModelElementUsage(element, usage);
+ this.stack.add(elementUsage);
}
/**
+ * Computes the usage of the element that is about to be added to the stack.
+ * @param newElement The element to be added to the stack.
+ * @return The computed usage for {@code element}.
+ */
+ private ElementUsage computeUsage(final XmlModelElement newElement) {
+ final ModelElementUsage topElement = peek();
+ if (topElement == null
+ || topElement.usage == ElementUsage.STRUCTURAL) {
+ if (newElement.canContainPCDATA()) {
+ return ElementUsage.BLOCK;
+ } else {
+ return ElementUsage.STRUCTURAL;
+ }
+ }
+ if (topElement.usage == ElementUsage.BLOCK) {
+ if (newElement.canContainPCDATA()) {
+ return ElementUsage.INLINE_MIXED;
+ } else {
+ return ElementUsage.INLINE_UNMIXED;
+ }
+ }
+ if (topElement.usage == ElementUsage.INLINE_UNMIXED) {
+ if (newElement.canContainPCDATA()) {
+ return ElementUsage.INLINE_MIXED;
+ } else {
+ return ElementUsage.INLINE_UNMIXED;
+ }
+ }
+ if (topElement.usage == ElementUsage.INLINE_MIXED) {
+ if (newElement.canContainPCDATA()) {
+ return ElementUsage.INLINE_MIXED;
+ } else {
+ return ElementUsage.INLINE_UNMIXED;
+ }
+ }
+ return ElementUsage.OTHER;
+ }
+
+
+ /**
* Pop an item off of the stack.
* @return The popped element, or null if the stack is empty.
*/
- public XmlModelElement pop() {
- final XmlModelElement topElement = peek();
+ public ModelElementUsage pop() {
+ final ModelElementUsage topElement = peek();
if (topElement != null) {
this.stack.remove(this.stack.size() - 1);
}
@@ -72,7 +178,7 @@
* Peek at the top element on the stack without removing it from the stack.
* @return The top element on the stack.
*/
- public XmlModelElement peek() {
+ public ModelElementUsage peek() {
return peek(0);
}
@@ -82,7 +188,7 @@
* To get the top element, set to 0. To get the next element down, set to 1, etc.
* @return The nth item down the stack, where n is indexFromTop.
*/
- public XmlModelElement peek(final int indexFromTop) {
+ public ModelElementUsage peek(final int indexFromTop) {
if (this.stack.size() <= indexFromTop) {
return null;
}
@@ -94,7 +200,7 @@
* Returns the element at the bottom of the stack.
* @return The element at the bottom of the stack, or null if the stack is empty.
*/
- public XmlModelElement getBottom() {
+ public ModelElementUsage getBottom() {
if (this.stack.size() < 1) {
return null;
}
@@ -117,57 +223,4 @@
return this.stack.isEmpty();
}
- /**
- * Reports whether the top element on the stack should be treated as a block element or as an inline element.
- * A block element is any element whose immediate parent in the document does not contain PCDATA.
- * Note that an element may be a block element but still be part of mixed content, if some other ancestor does
- * contain PCDATA.
- * @return True if and only if the top element on the stack is a block element, or if the stack is empty.
- */
- public boolean topIsBlockElement() {
- final XmlModelElement parentElement = peek(1);
- if (parentElement == null) {
- return true;
- }
- if (! parentElement.canContainPCDATA()) {
- return true;
- }
- return false;
- }
-
- /**
- * Reports whether the top element on the stack is inside of any element that contains mixed content.
- * @return True if and only if any ancestor element of the top of the stack can contain PCDATA.
- */
- public boolean topIsInsideMixedContent() {
- /* Start the loop at 1, because we don't care whether the top of the
- * stack contains PCDATA or not. */
- for (int i = 1; i < this.stack.size(); i++) {
- final XmlModelElement element = peek(i);
- if (element == null) {
- return false;
- }
- if (element.canContainPCDATA()) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Indicates whether the top item on the stack can have PCDATA content.
- * @return True if and only if the top item on the stack can have PCDATA content.
- */
- public boolean topCanHavePCDATA() {
- final XmlModelElement topElement = peek();
- if (topElement == null) {
- return false;
- }
- if (topElement.canContainPCDATA()
- || topElement.isPCDATA()) {
- return true;
- }
- return false;
- }
-
}
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XsdElement.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XsdElement.java 2025-02-12 17:38:40 UTC (rev 13369)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XsdElement.java 2025-02-12 22:57:32 UTC (rev 13370)
@@ -60,8 +60,16 @@
}
@Override
+ public String toString() {
+ return getQname().toString();
+ }
+
+ @Override
public boolean isPCDATA() {
final XmlSchemaType type = this.element.getSchemaType();
+ if (type == null) {
+ return false;
+ }
final QName qname = type.getQName();
if (qname == null) {
/* This cannot be a simple type. */
@@ -79,7 +87,15 @@
@Override
public boolean canContainPCDATA() {
- return element.getSchemaType().isMixed();
+ if (isPCDATA()) {
+ return true;
+ }
+ final XmlSchemaType schemaType = element.getSchemaType();
+ if (schemaType == null) {
+ /* If it has no type, it cannot have any content at all. */
+ return false;
+ }
+ return schemaType.isMixed();
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-12 17:38:43
|
Revision: 13369
http://sourceforge.net/p/foray/code/13369
Author: victormote
Date: 2025-02-12 17:38:40 +0000 (Wed, 12 Feb 2025)
Log Message:
-----------
Simplify writeAttribute, eliminate extraneous StringBuilder.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 17:18:56 UTC (rev 13368)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 17:38:40 UTC (rev 13369)
@@ -28,6 +28,7 @@
package org.foray.xml;
+import org.foray.primitive.StringUtils;
import org.foray.xml.dtd.DtdElement;
import org.foray.xml.model.ElementStack;
import org.foray.xml.model.XmlModelElement;
@@ -282,20 +283,22 @@
return;
}
- final StringBuilder attributesBuffer = new StringBuilder();
+ /* Whitespace at beginning of attribute. */
if (this.elementStack.topIsBlockElement()) {
final int indentLevels = currentIndentation() + this.config.getExtraAttributeIndentationLevels();
attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
} else {
- attributesBuffer.append(" ");
+ attributesContent.add(StringUtils.SINGLE_SPACE);
}
- attributesBuffer.append(attributes.getQName(attributesIndex));
- attributesBuffer.append("=\"");
+
+ /* Attribute name. */
+ attributesContent.add(attributes.getQName(attributesIndex));
+ attributesContent.add("=\"");
+
+ /* Attribute value. */
final String attributeValue = attributes.getValue(attributesIndex);
- if (attributeValue.contains(" ")) {
- attributesContent.add(attributesBuffer.toString());
- attributesBuffer.setLength(0);
- final String[] pieces = attributeValue.split(" ");
+ if (attributeValue.contains(StringUtils.SINGLE_SPACE)) {
+ final String[] pieces = attributeValue.split(StringUtils.SINGLE_SPACE);
for (int pieceIndex = 0; pieceIndex < pieces.length; pieceIndex ++) {
attributesContent.add(pieces[pieceIndex]);
if (pieceIndex < pieces.length - 1) {
@@ -305,10 +308,9 @@
}
}
} else {
- attributesBuffer.append(attributeValue);
+ attributesContent.add(attributeValue);
}
- attributesBuffer.append("\"");
- attributesContent.add(attributesBuffer.toString());
+ attributesContent.add("\"");
}
/**
@@ -334,7 +336,7 @@
int numIndents = currentIndentation() * this.config.getIndent();
final StringBuilder buffer = new StringBuilder();
while (numIndents > 0) {
- buffer.append(" ");
+ buffer.append(StringUtils.SINGLE_SPACE);
numIndents --;
}
return buffer.toString();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-12 17:18:59
|
Revision: 13368
http://sourceforge.net/p/foray/code/13368
Author: victormote
Date: 2025-02-12 17:18:56 +0000 (Wed, 12 Feb 2025)
Log Message:
-----------
Extract method writeAttribute, to reduce complexity.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 17:07:11 UTC (rev 13367)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 17:18:56 UTC (rev 13368)
@@ -239,37 +239,7 @@
/* Accumulate the attributes. */
final List<CharSequence> attributesContent = new ArrayList<CharSequence>();
for (int i = 0; i < attributes.getLength(); i++) {
- /* Check "isSpecified" to eliminate any attributes that were included by the parser as a default, in other
- * words, attributes that did not actually exist in the parsed text. */
- if (attributes.isSpecified(i)) {
- final StringBuilder attributesBuffer = new StringBuilder();
- if (this.elementStack.topIsBlockElement()) {
- final int indentLevels = currentIndentation() + this.config.getExtraAttributeIndentationLevels();
- attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
- } else {
- attributesBuffer.append(" ");
- }
- attributesBuffer.append(attributes.getQName(i));
- attributesBuffer.append("=\"");
- final String attributeValue = attributes.getValue(i);
- if (attributeValue.contains(" ")) {
- attributesContent.add(attributesBuffer.toString());
- attributesBuffer.setLength(0);
- final String[] pieces = attributeValue.split(" ");
- for (int pieceIndex = 0; pieceIndex < pieces.length; pieceIndex ++) {
- attributesContent.add(pieces[pieceIndex]);
- if (pieceIndex < pieces.length - 1) {
- final int indentLevels = currentIndentation() +
- this.config.getExtraIntraAttributeIndentationLevels();
- attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
- }
- }
- } else {
- attributesBuffer.append(attributeValue);
- }
- attributesBuffer.append("\"");
- attributesContent.add(attributesBuffer.toString());
- }
+ writeAttribute(attributes, i, attributesContent);
}
/* Accumulate the tag closer. */
@@ -299,6 +269,49 @@
}
/**
+ * Write a single attribute.
+ * @param attributes The parsed attributes.
+ * @param attributesIndex Index into {@code attributes}.
+ * @param attributesContent The list of sequences for attributes.
+ */
+ private void writeAttribute(final Attributes2 attributes, final int attributesIndex,
+ final List<CharSequence> attributesContent) {
+ /* Check "isSpecified" to eliminate any attributes that were included by the parser as a default, in other
+ * words, attributes that did not actually exist in the parsed text. */
+ if (! attributes.isSpecified(attributesIndex)) {
+ return;
+ }
+
+ final StringBuilder attributesBuffer = new StringBuilder();
+ if (this.elementStack.topIsBlockElement()) {
+ final int indentLevels = currentIndentation() + this.config.getExtraAttributeIndentationLevels();
+ attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
+ } else {
+ attributesBuffer.append(" ");
+ }
+ attributesBuffer.append(attributes.getQName(attributesIndex));
+ attributesBuffer.append("=\"");
+ final String attributeValue = attributes.getValue(attributesIndex);
+ if (attributeValue.contains(" ")) {
+ attributesContent.add(attributesBuffer.toString());
+ attributesBuffer.setLength(0);
+ final String[] pieces = attributeValue.split(" ");
+ for (int pieceIndex = 0; pieceIndex < pieces.length; pieceIndex ++) {
+ attributesContent.add(pieces[pieceIndex]);
+ if (pieceIndex < pieces.length - 1) {
+ final int indentLevels = currentIndentation() +
+ this.config.getExtraIntraAttributeIndentationLevels();
+ attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
+ }
+ }
+ } else {
+ attributesBuffer.append(attributeValue);
+ }
+ attributesBuffer.append("\"");
+ attributesContent.add(attributesBuffer.toString());
+ }
+
+ /**
* Indicates whether the top element in the stack should be indented.
* @return True if and only if the top element in the stack should be indented.
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-12 17:07:14
|
Revision: 13367
http://sourceforge.net/p/foray/code/13367
Author: victormote
Date: 2025-02-12 17:07:11 +0000 (Wed, 12 Feb 2025)
Log Message:
-----------
Make extra attribute indentation configurable.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java 2025-02-12 16:06:19 UTC (rev 13366)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java 2025-02-12 17:07:11 UTC (rev 13367)
@@ -38,6 +38,12 @@
/** The default line length that should be used in the pretty-printed output. */
private static final byte DEFAULT_LINE_LENGTH = 80;
+ /** The default value for {@link #extraAttributeIndentationLevels}. */
+ private static final int DEFAULT_EXTRA_ATTRIBUTE_INDENTATION_LEVELS = 2;
+
+ /** The default value for {@link #extraIntraAttributeIndentationLevels}. */
+ private static final int DEFAULT_EXTRA_INTRA_ATTRIBUTE_INDENTATION_LEVELS = 4;
+
/** The encoding to use for the pretty-printed output. */
private String outputEncoding = "UTF-8";
@@ -63,6 +69,12 @@
/** The maximum number of characters desired on each line. */
private int desiredLineLength = DEFAULT_LINE_LENGTH;
+ /** See {@link #getExtraAttributeIndentationLevels()}. */
+ private int extraAttributeIndentationLevels = DEFAULT_EXTRA_ATTRIBUTE_INDENTATION_LEVELS;
+
+ /** See {@link #getExtraIntraAttributeIndentationLevels()}. */
+ private int extraIntraAttributeIndentationLevels = DEFAULT_EXTRA_INTRA_ATTRIBUTE_INDENTATION_LEVELS;
+
/**
* Block elements are started on a new line.
* However, if they are inside elements containing mixed content, the default behavior is to start the element at
@@ -255,4 +267,40 @@
this.catalogs = catalogs;
}
+ /**
+ * Returns the number of extra levels of indentation that should be applied to attributes if they are forced to a
+ * new line.
+ * @return The extra attribute indentation levels.
+ */
+ public int getExtraAttributeIndentationLevels() {
+ return extraAttributeIndentationLevels;
+ }
+
+ /**
+ * Sets the extra attribute indentation levels.
+ * @param extraAttributeIndentationLevels the extraAttributeIndentationLevels to set.
+ * @see #getExtraAttributeIndentationLevels()
+ */
+ public void setExtraAttributeIndentationLevels(final int extraAttributeIndentationLevels) {
+ this.extraAttributeIndentationLevels = extraAttributeIndentationLevels;
+ }
+
+ /**
+ * Returns the number of extra levels of indentation that should be applied to attribute content if it has
+ * whitespace content and some of the content is forced to a new line.
+ * @return The extra intra-attribute indentation levels.
+ */
+ public int getExtraIntraAttributeIndentationLevels() {
+ return extraIntraAttributeIndentationLevels;
+ }
+
+ /**
+ * Sets the extra intra-attribute indentation levels.
+ * @param extraIntraAttributeIndentationLevels the extraIntraAttributeIndentationLevels to set
+ * @see #getExtraIntraAttributeIndentationLevels()
+ */
+ public void setExtraIntraAttributeIndentationLevels(final int extraIntraAttributeIndentationLevels) {
+ this.extraIntraAttributeIndentationLevels = extraIntraAttributeIndentationLevels;
+ }
+
}
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 16:06:19 UTC (rev 13366)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 17:07:11 UTC (rev 13367)
@@ -238,10 +238,6 @@
/* Accumulate the attributes. */
final List<CharSequence> attributesContent = new ArrayList<CharSequence>();
- /* For attributes, indent two additional levels. */
- final int attributeIndentationLevels = currentIndentation() + 2;
- /* For attribute values that go to another line, indent even further. */
- final int intraAttributeIndentationLevels = currentIndentation() + 4;
for (int i = 0; i < attributes.getLength(); i++) {
/* Check "isSpecified" to eliminate any attributes that were included by the parser as a default, in other
* words, attributes that did not actually exist in the parsed text. */
@@ -248,7 +244,8 @@
if (attributes.isSpecified(i)) {
final StringBuilder attributesBuffer = new StringBuilder();
if (this.elementStack.topIsBlockElement()) {
- attributesContent.add(this.prettyOutput.getContingentIndentation(attributeIndentationLevels));
+ final int indentLevels = currentIndentation() + this.config.getExtraAttributeIndentationLevels();
+ attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
} else {
attributesBuffer.append(" ");
}
@@ -262,8 +259,9 @@
for (int pieceIndex = 0; pieceIndex < pieces.length; pieceIndex ++) {
attributesContent.add(pieces[pieceIndex]);
if (pieceIndex < pieces.length - 1) {
- attributesContent.add(
- this.prettyOutput.getContingentIndentation(intraAttributeIndentationLevels));
+ final int indentLevels = currentIndentation() +
+ this.config.getExtraIntraAttributeIndentationLevels();
+ attributesContent.add(this.prettyOutput.getContingentIndentation(indentLevels));
}
}
} else {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-12 16:06:22
|
Revision: 13366
http://sourceforge.net/p/foray/code/13366
Author: victormote
Date: 2025-02-12 16:06:19 +0000 (Wed, 12 Feb 2025)
Log Message:
-----------
Fix mis-computation of size of ContingentIndentation.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java 2025-02-12 15:59:21 UTC (rev 13365)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java 2025-02-12 16:06:19 UTC (rev 13366)
@@ -80,6 +80,11 @@
@Override
public String subSequence(final int start, final int end) {
+ if (start < 0
+ || end > (levels * ForayPrettyOutput.this.config.getIndent())
+ || end < start) {
+ throw new IndexOutOfBoundsException();
+ }
final char[] array = new char[end - start];
Arrays.fill(array, ' ');
return new String(array);
@@ -87,7 +92,7 @@
@Override
public String toString() {
- return subSequence(0, this.levels);
+ return subSequence(0, this.levels * ForayPrettyOutput.this.config.getIndent());
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-12 15:59:24
|
Revision: 13365
http://sourceforge.net/p/foray/code/13365
Author: victormote
Date: 2025-02-12 15:59:21 +0000 (Wed, 12 Feb 2025)
Log Message:
-----------
Rename method and variables, for clarity.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 15:33:39 UTC (rev 13364)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 15:59:21 UTC (rev 13365)
@@ -207,7 +207,7 @@
if (this.topElementWritten) {
return;
}
- writeElement(this.lastStartedElement, this.lastStartedAttributes, isEmpty);
+ writeElementStart(this.lastStartedElement, this.lastStartedAttributes, isEmpty);
this.topElementWritten = true;
}
@@ -218,7 +218,8 @@
* @param attributes The attributes for the element to be written.
* @param isEmpty Indicates whether the element has any content or not.
*/
- private void writeElement(final XmlModelElement modelElement, final Attributes2 attributes, final boolean isEmpty) {
+ private void writeElementStart(final XmlModelElement modelElement, final Attributes2 attributes,
+ final boolean isEmpty) {
if (modelElement == null) {
return;
}
@@ -231,9 +232,9 @@
}
/* Accumulate the tag opener. */
- final StringBuilder tagOpenBuffer = new StringBuilder();
- tagOpenBuffer.append("<");
- tagOpenBuffer.append(qname.getLocalPart());
+ final StringBuilder startTagOpen = new StringBuilder();
+ startTagOpen.append("<");
+ startTagOpen.append(qname.getLocalPart());
/* Accumulate the attributes. */
final List<CharSequence> attributesContent = new ArrayList<CharSequence>();
@@ -274,11 +275,11 @@
}
/* Accumulate the tag closer. */
- final StringBuilder tagCloseBuffer = new StringBuilder();
+ final StringBuilder startTagClose = new StringBuilder();
if (isEmpty) {
- tagCloseBuffer.append("/>");
+ startTagClose.append("/>");
} else {
- tagCloseBuffer.append(">");
+ startTagClose.append(">");
}
/* If starting on new line, write the tag open buffer. */
@@ -288,15 +289,15 @@
if (this.shouldIndent()) {
this.prettyOutput.write(indent());
}
- this.prettyOutput.write(tagOpenBuffer.toString());
+ this.prettyOutput.write(startTagOpen.toString());
} else {
/* Otherwise queue it up. */
- this.prettyOutput.add(tagOpenBuffer.toString());
+ this.prettyOutput.add(startTagOpen.toString());
}
/* Queue up the attributes and tag close. */
this.prettyOutput.add(attributesContent);
- this.prettyOutput.add(tagCloseBuffer.toString());
+ this.prettyOutput.add(startTagClose.toString());
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-12 15:33:41
|
Revision: 13364
http://sourceforge.net/p/foray/code/13364
Author: victormote
Date: 2025-02-12 15:33:39 +0000 (Wed, 12 Feb 2025)
Log Message:
-----------
Add inner class to manage forced linebreaks.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java 2025-02-12 14:40:31 UTC (rev 13363)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java 2025-02-12 15:33:39 UTC (rev 13364)
@@ -91,7 +91,35 @@
}
}
+
/**
+ * A whitespace placeholder to be used when a forced line break is needed.
+ * Instances are immutable.
+ */
+ private final class ForcedLinebreak implements CharSequence {
+
+ @Override
+ public int length() {
+ final String terminator = ForayPrettyOutput.this.config.getLineTerminator();
+ return terminator.length();
+ }
+
+ @Override
+ public char charAt(final int index) {
+ final String terminator = ForayPrettyOutput.this.config.getLineTerminator();
+ return terminator.charAt(index);
+ }
+
+ @Override
+ public CharSequence subSequence(final int start, final int end) {
+ final String terminator = ForayPrettyOutput.this.config.getLineTerminator();
+ return terminator.subSequence(start, end);
+ }
+
+ }
+
+
+ /**
* An opportunity for a line-break in the flow of content.
*/
private class BreakOpportunity {
@@ -131,10 +159,14 @@
/** The maximum number of notional indentation levels. */
private static final int MAX_CONTINGENT_INDENTATIONS = 20;
- /** Singleton instance of the array of {ContingentIndentation} instances. */
- private static final ContingentIndentation[] CONTINGENT_INDENTATION_INSTANCES =
+ /** Singleton instance of the array of {@link ContingentIndentation} instances. */
+ private final ContingentIndentation[] contingentIndentationInstances =
new ContingentIndentation[MAX_CONTINGENT_INDENTATIONS];
+ /** Singleton instance of the {@link ForcedLinebreak} instance. */
+ private final ForcedLinebreak forcedLinebreakInstance = new ForcedLinebreak();
+
+
/** The output stream to which the pretty-printed output should be sent. */
private OutputStream output;
@@ -603,10 +635,18 @@
if (indentationLevels >= MAX_CONTINGENT_INDENTATIONS) {
throw new IndexOutOfBoundsException("Maximum indentation levels is " + MAX_CONTINGENT_INDENTATIONS);
}
- if (CONTINGENT_INDENTATION_INSTANCES[indentationLevels] == null) {
- CONTINGENT_INDENTATION_INSTANCES[indentationLevels] = new ContingentIndentation(indentationLevels);
+ if (contingentIndentationInstances[indentationLevels] == null) {
+ contingentIndentationInstances[indentationLevels] = new ContingentIndentation(indentationLevels);
}
- return CONTINGENT_INDENTATION_INSTANCES[indentationLevels];
+ return contingentIndentationInstances[indentationLevels];
}
+ /**
+ * Returns a forced linebreak instance.
+ * @return An appropriate instance.
+ */
+ public ForcedLinebreak getForcedLinebreak() {
+ return this.forcedLinebreakInstance;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-12 14:40:34
|
Revision: 13363
http://sourceforge.net/p/foray/code/13363
Author: victormote
Date: 2025-02-12 14:40:31 +0000 (Wed, 12 Feb 2025)
Log Message:
-----------
1. Use notional indentation levels in the API instead of the actual spaces. 2. Make singleton array to store ContingentIndentation items.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java 2025-02-12 12:24:21 UTC (rev 13362)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java 2025-02-12 14:40:31 UTC (rev 13363)
@@ -187,8 +187,8 @@
}
/**
- * Returns the indent.
- * @return The indent.
+ * Returns the number of spaces that should be indented for each level.
+ * @return The number of spaces that should be indented for each level.
*/
public int getIndent() {
return indent;
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java 2025-02-12 12:24:21 UTC (rev 13362)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyOutput.java 2025-02-12 14:40:31 UTC (rev 13363)
@@ -46,32 +46,32 @@
/**
* A whitespace placeholder to be used between output items that, if the line-breaking places them at the beginning
* of a line (i.e. interprets them as the line-breaking characters), they are to expand by a specified number of
- * spaces, or, stated differently, to indent the content that follows on the new line.
+ * indentation levels, or, stated differently, to indent the content that follows on the new line.
* This is useful for cases where element attributes should be indented under the element declaration, for
* readability.
* Instances are immutable.
*/
- private class ContingentIndentation implements CharSequence {
+ private final class ContingentIndentation implements CharSequence {
- /** The number of space characters to be used if indentation takes place. */
- private final int length;
+ /** The number of indentation levels to be used if indentation takes place. */
+ private final int levels;
/**
* Constructor.
- * @param length The number of space characters to be used if indentation takes place.
+ * @param levels The number of space characters to be used if indentation takes place.
*/
- ContingentIndentation(final int length) {
- this.length = length;
+ private ContingentIndentation(final int levels) {
+ this.levels = levels;
}
@Override
public int length() {
- return this.length;
+ return this.levels * ForayPrettyOutput.this.config.getIndent();
}
@Override
public char charAt(final int index) {
- if (index < 0 || index >= length) {
+ if (index < 0 || index >= (levels * ForayPrettyOutput.this.config.getIndent())) {
throw new IndexOutOfBoundsException();
}
/* All content is the space character. */
@@ -87,7 +87,7 @@
@Override
public String toString() {
- return subSequence(0, this.length);
+ return subSequence(0, this.levels);
}
}
@@ -128,6 +128,13 @@
/** Initial size of {@link #breaksChosen}. */
private static final int INITIAL_BREAKS_CHOSEN_SIZE = 2048;
+ /** The maximum number of notional indentation levels. */
+ private static final int MAX_CONTINGENT_INDENTATIONS = 20;
+
+ /** Singleton instance of the array of {ContingentIndentation} instances. */
+ private static final ContingentIndentation[] CONTINGENT_INDENTATION_INSTANCES =
+ new ContingentIndentation[MAX_CONTINGENT_INDENTATIONS];
+
/** The output stream to which the pretty-printed output should be sent. */
private OutputStream output;
@@ -588,12 +595,18 @@
}
/**
- * Return a contingent indentation instance.
- * @param length The length of the contingent indentation to be returned.
+ * Returns a contingent indentation instance.
+ * @param indentationLevels The number of levels of indentation to be used.
* @return An appropriate instance.
*/
- public ContingentIndentation getContingentIndentation(final int length) {
- return new ContingentIndentation(length);
+ public ContingentIndentation getContingentIndentation(final int indentationLevels) {
+ if (indentationLevels >= MAX_CONTINGENT_INDENTATIONS) {
+ throw new IndexOutOfBoundsException("Maximum indentation levels is " + MAX_CONTINGENT_INDENTATIONS);
+ }
+ if (CONTINGENT_INDENTATION_INSTANCES[indentationLevels] == null) {
+ CONTINGENT_INDENTATION_INSTANCES[indentationLevels] = new ContingentIndentation(indentationLevels);
+ }
+ return CONTINGENT_INDENTATION_INSTANCES[indentationLevels];
}
}
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 12:24:21 UTC (rev 13362)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 14:40:31 UTC (rev 13363)
@@ -238,9 +238,9 @@
/* Accumulate the attributes. */
final List<CharSequence> attributesContent = new ArrayList<CharSequence>();
/* For attributes, indent two additional levels. */
- final int attributeIndentation = (currentIndentation() + 2) * config.getIndent();
+ final int attributeIndentationLevels = currentIndentation() + 2;
/* For attribute values that go to another line, indent even further. */
- final int intraAttributeIndentation = (currentIndentation() + 4) * config.getIndent();
+ final int intraAttributeIndentationLevels = currentIndentation() + 4;
for (int i = 0; i < attributes.getLength(); i++) {
/* Check "isSpecified" to eliminate any attributes that were included by the parser as a default, in other
* words, attributes that did not actually exist in the parsed text. */
@@ -247,7 +247,7 @@
if (attributes.isSpecified(i)) {
final StringBuilder attributesBuffer = new StringBuilder();
if (this.elementStack.topIsBlockElement()) {
- attributesContent.add(this.prettyOutput.getContingentIndentation(attributeIndentation));
+ attributesContent.add(this.prettyOutput.getContingentIndentation(attributeIndentationLevels));
} else {
attributesBuffer.append(" ");
}
@@ -262,7 +262,7 @@
attributesContent.add(pieces[pieceIndex]);
if (pieceIndex < pieces.length - 1) {
attributesContent.add(
- this.prettyOutput.getContingentIndentation(intraAttributeIndentation));
+ this.prettyOutput.getContingentIndentation(intraAttributeIndentationLevels));
}
}
} else {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-12 12:24:25
|
Revision: 13362
http://sourceforge.net/p/foray/code/13362
Author: victormote
Date: 2025-02-12 12:24:21 +0000 (Wed, 12 Feb 2025)
Log Message:
-----------
Store XmlModelElement instances instead of element names.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XsdElement.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java 2025-02-12 00:50:45 UTC (rev 13361)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyConfig.java 2025-02-12 12:24:21 UTC (rev 13362)
@@ -41,12 +41,13 @@
/** The encoding to use for the pretty-printed output. */
private String outputEncoding = "UTF-8";
- /** The XML declaration string. */
- private String xmlDeclaration = "<?xml version=\"1.0\" encoding=\"" + this.outputEncoding + "\"?>";
-
/** The line terminator that should be used in the output. */
private String lineTerminator = System.getProperty("line.separator");
+ /** The XML declaration string. */
+ private String xmlDeclaration = "<?xml version=\"1.0\" encoding=\"" + this.outputEncoding + "\"?>"
+ + lineTerminator + lineTerminator;
+
/** The text that should be output before the root element. */
private String preRootText = StringUtils.EMPTY_STRING;
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 00:50:45 UTC (rev 13361)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 12:24:21 UTC (rev 13362)
@@ -28,7 +28,9 @@
package org.foray.xml;
+import org.foray.xml.dtd.DtdElement;
import org.foray.xml.model.ElementStack;
+import org.foray.xml.model.XmlModelElement;
import org.foray.xml.model.XsdElement;
import org.apache.commons.cli.CommandLine;
@@ -58,6 +60,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -83,12 +86,16 @@
/** A output for this pretty-printer. */
private ForayPrettyOutput prettyOutput;
- /** The name of the root element of this document. */
- private String rootElement;
+ /** The root element of this document. This only needs to be tracked for DTD documents. */
+ private DtdElement rootElement;
/** The element stack. */
private ElementStack elementStack = new ElementStack();
+ /** Map whose key is a String qname, and whose value is a QName instance. Used to avoid unnecessary object
+ * creation. */
+ private Map<String, QName> qnameMap = new HashMap<String, QName>();
+
/* Begin state variables. */
/** State variable tracking whether we are currently inside the Dtd or not. */
@@ -103,8 +110,8 @@
/** Indicates whether the item on the top of the element stack has been written. */
private boolean topElementWritten = true;
- /** The name of the last started-element. */
- private String lastStartedElement;
+ /** The the last started-element. */
+ private XmlModelElement lastStartedElement;
/** The attributes belonging to the last-started element. */
private Attributes2 lastStartedAttributes;
@@ -150,7 +157,6 @@
@Override
public void startDocument() {
this.prettyOutput.write(this.config.getXmlDeclaration());
- this.prettyOutput.write(this.config.getLineTerminator());
}
@Override
@@ -159,22 +165,24 @@
}
@Override
- public void startElement(final String uri, final String local, final String qName, final Attributes attributes)
- throws SAXException {
+ public void startElement(final String uri, final String local, final String qNameString,
+ final Attributes attributes) throws SAXException {
flushCharacters();
ensureTopElementWritten(false);
parseSchemaLocation(attributes);
-
-
/* Cache the parameters in instance variable for later processing.
* We don't want to write the element yet, because the next event received might be the close of the same
* element, and empty elements can be written two different ways.*/
- this.lastStartedElement = qName;
+
/* Must copy the attributes as they are reset on each callback. */
this.lastStartedAttributes = new Attributes2Impl(attributes);
if (getDtd() == null) {
- final QName qname = new QName(uri, local);
+ QName qname = this.qnameMap.get(qNameString);
+ if (qname == null) {
+ qname = new QName(uri, local);
+ this.qnameMap.put(qNameString, qname);
+ }
final XmlSchemaElement schemaElement = getSchemaElement(qname);
final Map<XmlSchemaElement, XsdElement> schemaElementMap = getSchemaElementMap();
@@ -184,8 +192,9 @@
schemaElementMap.put(schemaElement, xsdElement);
}
this.elementStack.push(xsdElement);
+ this.lastStartedElement = xsdElement;
} else {
- this.elementStack.push(getDtd().getElement(qName));
+ this.elementStack.push(getDtd().getElement(qNameString));
}
this.topElementWritten = false;
}
@@ -202,17 +211,20 @@
this.topElementWritten = true;
}
+
/**
* Writes an element.
- * @param qName The namespace-qualified name of the element to be written.
+ * @param modelElement The namespace-qualified name of the element to be written.
* @param attributes The attributes for the element to be written.
* @param isEmpty Indicates whether the element has any content or not.
*/
- private void writeElement(final String qName, final Attributes2 attributes, final boolean isEmpty) {
- if (qName == null) {
+ private void writeElement(final XmlModelElement modelElement, final Attributes2 attributes, final boolean isEmpty) {
+ if (modelElement == null) {
return;
}
- if (qName.equals(this.rootElement)) {
+ final QName qname = modelElement.getQname();
+
+ if (modelElement.equals(this.rootElement)) {
/* Whitespace before and after the end of the root element is
* discarded by SAX, so we need to control it manually. */
this.prettyOutput.write(this.config.getPreRootText());
@@ -221,7 +233,7 @@
/* Accumulate the tag opener. */
final StringBuilder tagOpenBuffer = new StringBuilder();
tagOpenBuffer.append("<");
- tagOpenBuffer.append(qName);
+ tagOpenBuffer.append(qname.getLocalPart());
/* Accumulate the attributes. */
final List<CharSequence> attributesContent = new ArrayList<CharSequence>();
@@ -468,7 +480,7 @@
builder.append(this.config.getLineTerminator());
this.prettyOutput.write(builder.toString());
this.inDTD = true;
- this.rootElement = name;
+ this.rootElement = getDtd().getElement(name);
}
@Override
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XsdElement.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XsdElement.java 2025-02-12 00:50:45 UTC (rev 13361)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XsdElement.java 2025-02-12 12:24:21 UTC (rev 13362)
@@ -84,7 +84,7 @@
@Override
public QName getQname() {
- return this.element.getSchemaTypeName();
+ return this.element.getQName();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-12 00:50:48
|
Revision: 13361
http://sourceforge.net/p/foray/code/13361
Author: victormote
Date: 2025-02-12 00:50:45 +0000 (Wed, 12 Feb 2025)
Log Message:
-----------
Move ElementStack class to the model package.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
Added Paths:
-----------
trunk/foray/foray-xml/src/main/java/org/foray/xml/model/ElementStack.java
Removed Paths:
-------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/dtd/ElementStack.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 00:30:03 UTC (rev 13360)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 00:50:45 UTC (rev 13361)
@@ -28,7 +28,7 @@
package org.foray.xml;
-import org.foray.xml.dtd.ElementStack;
+import org.foray.xml.model.ElementStack;
import org.foray.xml.model.XsdElement;
import org.apache.commons.cli.CommandLine;
Deleted: trunk/foray/foray-xml/src/main/java/org/foray/xml/dtd/ElementStack.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/dtd/ElementStack.java 2025-02-12 00:30:03 UTC (rev 13360)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/dtd/ElementStack.java 2025-02-12 00:50:45 UTC (rev 13361)
@@ -1,175 +0,0 @@
-/*
- * Copyright 2006 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.xml.dtd;
-
-import org.foray.xml.model.XmlModelElement;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A stack of {@link XmlModelElement} instances.
- */
-public class ElementStack {
-
- /** The actual element stack. */
- private List<XmlModelElement> stack = new ArrayList<XmlModelElement>();
-
- /**
- * Constructor.
- */
- public ElementStack() {
- }
-
- /**
- * Push an item onto the stack.
- * @param element The element to push onto the stack.
- */
- public void push(final XmlModelElement element) {
- if (element == null) {
- throw new IllegalArgumentException("Cannot add a null item to the element stack.");
- }
- this.stack.add(element);
- }
-
- /**
- * Pop an item off of the stack.
- * @return The popped element, or null if the stack is empty.
- */
- public XmlModelElement pop() {
- final XmlModelElement topElement = peek();
- if (topElement != null) {
- this.stack.remove(this.stack.size() - 1);
- }
- return topElement;
- }
-
- /**
- * Peek at the top element on the stack without removing it from the stack.
- * @return The top element on the stack.
- */
- public XmlModelElement peek() {
- return peek(0);
- }
-
- /**
- * Return an element from the stack without removing either it or anything else from the stack.
- * @param indexFromTop The number of items deep in the stack the desired element is.
- * To get the top element, set to 0. To get the next element down, set to 1, etc.
- * @return The nth item down the stack, where n is indexFromTop.
- */
- public XmlModelElement peek(final int indexFromTop) {
- if (this.stack.size() <= indexFromTop) {
- return null;
- }
- final int index = this.stack.size() - indexFromTop - 1;
- return this.stack.get(index);
- }
-
- /**
- * Returns the element at the bottom of the stack.
- * @return The element at the bottom of the stack, or null if the stack is empty.
- */
- public XmlModelElement getBottom() {
- if (this.stack.size() < 1) {
- return null;
- }
- return this.stack.get(0);
- }
-
- /**
- * Return the number of elements on the stack.
- * @return The number of elements on the stack.
- */
- public int size() {
- return this.stack.size();
- }
-
- /**
- * Indicates whether the stack is empty.
- * @return True if and only if the stack has no elements on it.
- */
- public boolean isEmpty() {
- return this.stack.isEmpty();
- }
-
- /**
- * Reports whether the top element on the stack should be treated as a block element or as an inline element.
- * A block element is any element whose immediate parent in the document does not contain PCDATA.
- * Note that an element may be a block element but still be part of mixed content, if some other ancestor does
- * contain PCDATA.
- * @return True if and only if the top element on the stack is a block element, or if the stack is empty.
- */
- public boolean topIsBlockElement() {
- final XmlModelElement parentElement = peek(1);
- if (parentElement == null) {
- return true;
- }
- if (! parentElement.canContainPCDATA()) {
- return true;
- }
- return false;
- }
-
- /**
- * Reports whether the top element on the stack is inside of any element that contains mixed content.
- * @return True if and only if any ancestor element of the top of the stack can contain PCDATA.
- */
- public boolean topIsInsideMixedContent() {
- /* Start the loop at 1, because we don't care whether the top of the
- * stack contains PCDATA or not. */
- for (int i = 1; i < this.stack.size(); i++) {
- final XmlModelElement element = peek(i);
- if (element == null) {
- return false;
- }
- if (element.canContainPCDATA()) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Indicates whether the top item on the stack can have PCDATA content.
- * @return True if and only if the top item on the stack can have PCDATA content.
- */
- public boolean topCanHavePCDATA() {
- final XmlModelElement topElement = peek();
- if (topElement == null) {
- return false;
- }
- if (topElement.canContainPCDATA()
- || topElement.isPCDATA()) {
- return true;
- }
- return false;
- }
-
-}
Copied: trunk/foray/foray-xml/src/main/java/org/foray/xml/model/ElementStack.java (from rev 13359, trunk/foray/foray-xml/src/main/java/org/foray/xml/dtd/ElementStack.java)
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/model/ElementStack.java (rev 0)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/model/ElementStack.java 2025-02-12 00:50:45 UTC (rev 13361)
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2006 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.xml.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A stack of {@link XmlModelElement} instances.
+ */
+public class ElementStack {
+
+ /** The actual element stack. */
+ private List<XmlModelElement> stack = new ArrayList<XmlModelElement>();
+
+ /**
+ * Constructor.
+ */
+ public ElementStack() {
+ }
+
+ /**
+ * Push an item onto the stack.
+ * @param element The element to push onto the stack.
+ */
+ public void push(final XmlModelElement element) {
+ if (element == null) {
+ throw new IllegalArgumentException("Cannot add a null item to the element stack.");
+ }
+ this.stack.add(element);
+ }
+
+ /**
+ * Pop an item off of the stack.
+ * @return The popped element, or null if the stack is empty.
+ */
+ public XmlModelElement pop() {
+ final XmlModelElement topElement = peek();
+ if (topElement != null) {
+ this.stack.remove(this.stack.size() - 1);
+ }
+ return topElement;
+ }
+
+ /**
+ * Peek at the top element on the stack without removing it from the stack.
+ * @return The top element on the stack.
+ */
+ public XmlModelElement peek() {
+ return peek(0);
+ }
+
+ /**
+ * Return an element from the stack without removing either it or anything else from the stack.
+ * @param indexFromTop The number of items deep in the stack the desired element is.
+ * To get the top element, set to 0. To get the next element down, set to 1, etc.
+ * @return The nth item down the stack, where n is indexFromTop.
+ */
+ public XmlModelElement peek(final int indexFromTop) {
+ if (this.stack.size() <= indexFromTop) {
+ return null;
+ }
+ final int index = this.stack.size() - indexFromTop - 1;
+ return this.stack.get(index);
+ }
+
+ /**
+ * Returns the element at the bottom of the stack.
+ * @return The element at the bottom of the stack, or null if the stack is empty.
+ */
+ public XmlModelElement getBottom() {
+ if (this.stack.size() < 1) {
+ return null;
+ }
+ return this.stack.get(0);
+ }
+
+ /**
+ * Return the number of elements on the stack.
+ * @return The number of elements on the stack.
+ */
+ public int size() {
+ return this.stack.size();
+ }
+
+ /**
+ * Indicates whether the stack is empty.
+ * @return True if and only if the stack has no elements on it.
+ */
+ public boolean isEmpty() {
+ return this.stack.isEmpty();
+ }
+
+ /**
+ * Reports whether the top element on the stack should be treated as a block element or as an inline element.
+ * A block element is any element whose immediate parent in the document does not contain PCDATA.
+ * Note that an element may be a block element but still be part of mixed content, if some other ancestor does
+ * contain PCDATA.
+ * @return True if and only if the top element on the stack is a block element, or if the stack is empty.
+ */
+ public boolean topIsBlockElement() {
+ final XmlModelElement parentElement = peek(1);
+ if (parentElement == null) {
+ return true;
+ }
+ if (! parentElement.canContainPCDATA()) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Reports whether the top element on the stack is inside of any element that contains mixed content.
+ * @return True if and only if any ancestor element of the top of the stack can contain PCDATA.
+ */
+ public boolean topIsInsideMixedContent() {
+ /* Start the loop at 1, because we don't care whether the top of the
+ * stack contains PCDATA or not. */
+ for (int i = 1; i < this.stack.size(); i++) {
+ final XmlModelElement element = peek(i);
+ if (element == null) {
+ return false;
+ }
+ if (element.canContainPCDATA()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Indicates whether the top item on the stack can have PCDATA content.
+ * @return True if and only if the top item on the stack can have PCDATA content.
+ */
+ public boolean topCanHavePCDATA() {
+ final XmlModelElement topElement = peek();
+ if (topElement == null) {
+ return false;
+ }
+ if (topElement.canContainPCDATA()
+ || topElement.isPCDATA()) {
+ return true;
+ }
+ return false;
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-12 00:30:06
|
Revision: 13360
http://sourceforge.net/p/foray/code/13360
Author: victormote
Date: 2025-02-12 00:30:03 +0000 (Wed, 12 Feb 2025)
Log Message:
-----------
Use configurable locations to standardize Eclipse launch configs.
Modified Paths:
--------------
trunk/foray/foray-00-dev/ide/eclipse/launch-configurations/xml-ForayPrettyPush.launch
Added Paths:
-----------
trunk/foray/foray-00-dev/ide/eclipse/launch-configurations/xml-ForayXdiff.launch
Modified: trunk/foray/foray-00-dev/ide/eclipse/launch-configurations/xml-ForayPrettyPush.launch
===================================================================
--- trunk/foray/foray-00-dev/ide/eclipse/launch-configurations/xml-ForayPrettyPush.launch 2025-02-12 00:10:15 UTC (rev 13359)
+++ trunk/foray/foray-00-dev/ide/eclipse/launch-configurations/xml-ForayPrettyPush.launch 2025-02-12 00:30:03 UTC (rev 13360)
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
+ <booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java"/>
</listAttribute>
Added: trunk/foray/foray-00-dev/ide/eclipse/launch-configurations/xml-ForayXdiff.launch
===================================================================
--- trunk/foray/foray-00-dev/ide/eclipse/launch-configurations/xml-ForayXdiff.launch (rev 0)
+++ trunk/foray/foray-00-dev/ide/eclipse/launch-configurations/xml-ForayXdiff.launch 2025-02-12 00:30:03 UTC (rev 13360)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
+ <booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
+ <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+ <listEntry value="/foray-xml/src/main/java/org/foray/xml/ForayXdiff.java"/>
+ </listAttribute>
+ <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+ <listEntry value="1"/>
+ </listAttribute>
+ <booleanAttribute key="org.eclipse.jdt.launching.ATTR_EXCLUDE_TEST_CODE" value="true"/>
+ <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
+ <listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
+ <listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/" javaProject="foray-xml" path="1" type="4"/> "/>
+ <listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento exportedEntriesOnly="false" project="foray-xml"/> </runtimeClasspathEntry> "/>
+ <listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.USER_LIBRARY/logback" path="3" type="4"/> "/>
+ </listAttribute>
+ <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
+ <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.foray.xml.ForayXdiff"/>
+ <stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="foray-xml"/>
+ <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-f file:///${foray-test-input-dir}/pretty-print-input.xml file:///${foray-test-output-dir}/pretty-print-output.xml -c ${foray-catalog-file}"/>
+ <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="foray-xml"/>
+</launchConfiguration>
Property changes on: trunk/foray/foray-00-dev/ide/eclipse/launch-configurations/xml-ForayXdiff.launch
___________________________________________________________________
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...> - 2025-02-12 00:10:17
|
Revision: 13359
http://sourceforge.net/p/foray/code/13359
Author: victormote
Date: 2025-02-12 00:10:15 +0000 (Wed, 12 Feb 2025)
Log Message:
-----------
Allow text to be processed for elements that contain certain simple XML Schema types.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/dtd/DtdElement.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/dtd/ElementStack.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XmlModelElement.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XsdElement.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-11 20:28:52 UTC (rev 13358)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-02-12 00:10:15 UTC (rev 13359)
@@ -407,7 +407,7 @@
@Override
public void ignorableWhitespace(final char[] buffer, final int offset, final int length) {
/* Ignorable white space is just ignored. However, please note that it is only ignored for documents that are
- * validate by DTD. If the document is validated by XML Schema, the parser is required to include ignorable
+ * validated by DTD. If the document is validated by XML Schema, the parser is required to include ignorable
* whitespace as part of character() data. */
}
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/dtd/DtdElement.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/dtd/DtdElement.java 2025-02-11 20:28:52 UTC (rev 13358)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/dtd/DtdElement.java 2025-02-12 00:10:15 UTC (rev 13359)
@@ -84,6 +84,12 @@
}
@Override
+ /* Unlike XML schema, We don't know of any way for a DTD element to contain text other than containing PCDATA. */
+ public boolean isPCDATA() {
+ return false;
+ }
+
+ @Override
public boolean canContainPCDATA() {
return this.canContainPCDATA;
}
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/dtd/ElementStack.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/dtd/ElementStack.java 2025-02-11 20:28:52 UTC (rev 13358)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/dtd/ElementStack.java 2025-02-12 00:10:15 UTC (rev 13359)
@@ -165,7 +165,8 @@
if (topElement == null) {
return false;
}
- if (topElement.canContainPCDATA()) {
+ if (topElement.canContainPCDATA()
+ || topElement.isPCDATA()) {
return true;
}
return false;
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XmlModelElement.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XmlModelElement.java 2025-02-11 20:28:52 UTC (rev 13358)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XmlModelElement.java 2025-02-12 00:10:15 UTC (rev 13359)
@@ -36,11 +36,20 @@
public interface XmlModelElement {
/**
+ * Indicated whether this element's content model actually is PCDATA. An example would be an element that is a
+ * primitive XML Schema type, for example xs:date. The content of the element is actually text.
+ * @return True if and only if this element's content model indicates that it is a primitive XML Schema type.
+ */
+ boolean isPCDATA();
+
+
+ /**
* Indicates whether this element's content model contains PCDATA.
* @return True if and only if this element's content model contains PCDATA.
*/
boolean canContainPCDATA();
+
/**
* Returns the QName for this element.
* @return THe QName for this element.
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XsdElement.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XsdElement.java 2025-02-11 20:28:52 UTC (rev 13358)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/model/XsdElement.java 2025-02-12 00:10:15 UTC (rev 13359)
@@ -29,7 +29,9 @@
package org.foray.xml.model;
import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
/**
@@ -58,6 +60,24 @@
}
@Override
+ public boolean isPCDATA() {
+ final XmlSchemaType type = this.element.getSchemaType();
+ final QName qname = type.getQName();
+ if (qname == null) {
+ /* This cannot be a simple type. */
+ return false;
+ }
+ final String nsuri = qname.getNamespaceURI();
+ if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(nsuri)) {
+ /* This list is very incomplete. */
+ if ("date".equals(qname.getLocalPart())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
public boolean canContainPCDATA() {
return element.getSchemaType().isMixed();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-11 20:28:55
|
Revision: 13358
http://sourceforge.net/p/foray/code/13358
Author: victormote
Date: 2025-02-11 20:28:52 +0000 (Tue, 11 Feb 2025)
Log Message:
-----------
Remove Stream constructor, so that we always have the URL of the underlying files.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayXdiff.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayXdiff.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayXdiff.java 2025-02-11 13:14:37 UTC (rev 13357)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayXdiff.java 2025-02-11 20:28:52 UTC (rev 13358)
@@ -40,11 +40,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
@@ -124,19 +122,6 @@
convertStreams(catalog, streams);
}
- /**
- * Constructor accepting InputStreams to compare.
- * @param streams An array of InputStreams to be compared.
- * @param catalog The location of a catalog file that should be used to find the Dtd for this document.
- * @throws XMLStreamException For errors during the diff.
- * @see #ForayXdiff(URL[], String) For a constructor that takes {@link URL}s.
- */
- public ForayXdiff(final InputStream[] streams, final String catalog) throws XMLStreamException {
- if (this.readerIDs == null) {
- this.readerIDs = new String[streams.length];
- }
- convertStreams(catalog, streams);
- }
/**
* Converts the input streams to XMLStreamReaders for pull-parsing.
@@ -692,21 +677,20 @@
final String catalog = parsedCommandLine.getOptionValue("catalog");
final String[] files = parsedCommandLine.getOptionValues("files");
- final InputStream[] streamsToCompare = new InputStream[files.length];
+ final URL[] resourcesToCompare = new URL[files.length];
for (int i = 0; i < files.length; i++) {
- InputStream stream = null;
+
try {
- final File file = new File(files[i]);
- stream = new FileInputStream(file);
- } catch (final FileNotFoundException e) {
+ final URL url = new URL(files[i]);
+ resourcesToCompare[i] = url;
+ } catch (final MalformedURLException e) {
logger.error("File Not Found: " + files[i], e);
/* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayXdiff.STATUS_MALFORMED_URL);
}
- streamsToCompare[i] = stream;
}
try {
- final ForayXdiff processor = new ForayXdiff(streamsToCompare, catalog);
+ final ForayXdiff processor = new ForayXdiff(resourcesToCompare, catalog);
final boolean equivalent = processor.equivalent();
if (equivalent) {
logger.info("All XML Streams are equivalent.");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-02-11 13:14:39
|
Revision: 13357
http://sourceforge.net/p/foray/code/13357
Author: victormote
Date: 2025-02-11 13:14:37 +0000 (Tue, 11 Feb 2025)
Log Message:
-----------
Upgrade Gradle from 8.12 to 8.12.1.
Modified Paths:
--------------
trunk/foray/gradle/wrapper/gradle-wrapper.jar
trunk/foray/gradle/wrapper/gradle-wrapper.properties
trunk/foray/gradlew
trunk/foray/gradlew.bat
Modified: trunk/foray/gradle/wrapper/gradle-wrapper.jar
===================================================================
(Binary files differ)
Modified: trunk/foray/gradle/wrapper/gradle-wrapper.properties
===================================================================
--- trunk/foray/gradle/wrapper/gradle-wrapper.properties 2025-01-11 17:00:27 UTC (rev 13356)
+++ trunk/foray/gradle/wrapper/gradle-wrapper.properties 2025-02-11 13:14:37 UTC (rev 13357)
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Modified: trunk/foray/gradlew
===================================================================
--- trunk/foray/gradlew 2025-01-11 17:00:27 UTC (rev 13356)
+++ trunk/foray/gradlew 2025-02-11 13:14:37 UTC (rev 13357)
@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+# SPDX-License-Identifier: Apache-2.0
+#
##############################################################################
#
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
-# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -83,7 +85,8 @@
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
-APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -144,7 +147,7 @@
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
- # shellcheck disable=SC3045
+ # shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
@@ -152,7 +155,7 @@
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
- # shellcheck disable=SC3045
+ # shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -201,11 +204,11 @@
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
-# Collect all arguments for the java command;
-# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
-# shell script including quotes and variable substitutions, so put them in
-# double quotes to make sure that they get re-expanded; and
-# * put everything else in single quotes, so that it's not re-expanded.
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Modified: trunk/foray/gradlew.bat
===================================================================
--- trunk/foray/gradlew.bat 2025-01-11 17:00:27 UTC (rev 13356)
+++ trunk/foray/gradlew.bat 2025-02-11 13:14:37 UTC (rev 13357)
@@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
+@rem SPDX-License-Identifier: Apache-2.0
+@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@@ -43,11 +45,11 @@
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
goto fail
@@ -57,11 +59,11 @@
if exist "%JAVA_EXE%" goto execute
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
goto fail
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-01-11 17:00:29
|
Revision: 13356
http://sourceforge.net/p/foray/code/13356
Author: victormote
Date: 2025-01-11 17:00:27 +0000 (Sat, 11 Jan 2025)
Log Message:
-----------
Conform to axsl changes: Add text-align and text-align last traits to NormalBlockArea.
Modified Paths:
--------------
trunk/foray/foray-app/src/test/java/org/foray/app/area/BlockTests.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/NormalBlockArea4a.java
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/area/BlockTests.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/area/BlockTests.java 2025-01-10 16:51:18 UTC (rev 13355)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/area/BlockTests.java 2025-01-11 17:00:27 UTC (rev 13356)
@@ -42,6 +42,7 @@
import org.axsl.font.FontException;
import org.axsl.font.FontUse;
import org.axsl.font.zzz.FontContextMdo;
+import org.axsl.value.TextAlign;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -290,8 +291,7 @@
/**
* Test of fo/block-004.fo.
- * This is a test of centering of a text-area on a line, where the text-area
- * has word-spacing = ".3em".
+ * This is a test of centering of a text-area on a line, where the text-area has word-spacing = ".3em".
* @throws FontException For font system errors in obtaining the font.
*/
@Test
@@ -301,10 +301,15 @@
final AreaTree4a areaTree = creator.buildAreaTreeFromFile("fo/block-004.fo", getLineBreakerFactory());
final NormalFlowRa firstNormalFlowArea = this.getFirstNormalFlowArea(areaTree);
- /* Test location and dimensions of the block area. */
AreaNode node = firstNormalFlowArea.areaChildAt(0);
assertTrue(node instanceof NormalBlockArea4a);
final NormalBlockArea4a blockArea = (NormalBlockArea4a) node;
+
+ /* Tests of the block area. */
+ assertEquals("Helvetica", blockArea.traitNominalFont().getFont().getFontName());
+ assertEquals(12000, blockArea.traitFontSize());
+ assertEquals(TextAlign.CENTER, blockArea.traitTextAlign());
+
/* 1 inch left margin. */
assertEquals(72000, blockArea.crOriginX());
/* 10 inches from bottom (11 inches high, 1 inch top margin). */
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/NormalBlockArea4a.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/NormalBlockArea4a.java 2025-01-10 16:51:18 UTC (rev 13355)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/NormalBlockArea4a.java 2025-01-11 17:00:27 UTC (rev 13356)
@@ -47,6 +47,8 @@
import org.axsl.value.BackgroundRepeat;
import org.axsl.value.BorderStyle;
import org.axsl.value.RelativeAxis;
+import org.axsl.value.TextAlign;
+import org.axsl.value.TextAlignLast;
import java.awt.Color;
import java.util.ArrayList;
@@ -451,4 +453,19 @@
return this.crIpd();
}
+ @Override
+ public TextAlign traitTextAlign() {
+ return traitGeneratedBy().traitTextAlign(this);
+ }
+
+ @Override
+ public String traitTextAlignString() {
+ return traitGeneratedBy().traitTextAlignString();
+ }
+
+ @Override
+ public TextAlignLast traitTextAlignLast() {
+ return traitGeneratedBy().traitTextAlignLast(this);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-01-10 16:51:21
|
Revision: 13355
http://sourceforge.net/p/foray/code/13355
Author: victormote
Date: 2025-01-10 16:51:18 +0000 (Fri, 10 Jan 2025)
Log Message:
-----------
Rename SaxParser to SaxParser4a to avoid confusion with standard libraries.
Modified Paths:
--------------
trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java
trunk/foray/foray-core/src/main/java/org/foray/core/ForayDocument.java
trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/GraphicServer4a.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/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-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/Sax2DomParser.java
trunk/foray/foray-zz-attic/src/main/java/org/foray/orthography/NatLangParser.java
trunk/foray/foray-zz-attic/src/main/java/org/foray/orthography/ValidateChars.java
Added Paths:
-----------
trunk/foray/foray-xml/src/main/java/org/foray/xml/SaxParser4a.java
Removed Paths:
-------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/SaxParser.java
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 2025-01-10 16:31:20 UTC (rev 13354)
+++ trunk/foray/foray-core/src/main/java/org/foray/core/ForayConfigParser.java 2025-01-10 16:51:18 UTC (rev 13355)
@@ -31,7 +31,7 @@
import org.foray.common.Configuration;
import org.foray.common.ConfigurationException;
import org.foray.common.ForayEntityResolver;
-import org.foray.xml.SaxParser;
+import org.foray.xml.SaxParser4a;
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver;
@@ -47,7 +47,7 @@
* in Configuration.
* Normally this class doesn't need to be accessed directly.
*/
-public class ForayConfigParser extends SaxParser<Object> {
+public class ForayConfigParser extends SaxParser4a<Object> {
/** Constant indicating that the current status of the parser is outside
* of either key or value. */
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 2025-01-10 16:31:20 UTC (rev 13354)
+++ trunk/foray/foray-core/src/main/java/org/foray/core/ForayDocument.java 2025-01-10 16:51:18 UTC (rev 13355)
@@ -30,7 +30,7 @@
import org.foray.xml.DocumentInputSource;
import org.foray.xml.DocumentReader;
-import org.foray.xml.SaxParser;
+import org.foray.xml.SaxParser4a;
import org.axsl.area.AreaTreeFactory;
import org.axsl.font.FontConsumer;
@@ -341,7 +341,7 @@
* @return The name of the SAX parser.
*/
public String getParserClassName() {
- return SaxParser.getParserClassName();
+ return SaxParser4a.getParserClassName();
}
/**
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 2025-01-10 16:31:20 UTC (rev 13354)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java 2025-01-10 16:51:18 UTC (rev 13355)
@@ -33,7 +33,7 @@
import org.foray.font.FontServer4a;
import org.foray.primitive.StringUtils;
import org.foray.xml.SaxLocation;
-import org.foray.xml.SaxParser;
+import org.foray.xml.SaxParser4a;
import org.axsl.font.Font;
import org.axsl.font.FontException;
@@ -66,7 +66,7 @@
* 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<Object> {
+public class FontConfigParser extends SaxParser4a<Object> {
/**
* Inner class for storing font-group items.
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 2025-01-10 16:31:20 UTC (rev 13354)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeParser4a.java 2025-01-10 16:51:18 UTC (rev 13355)
@@ -36,7 +36,7 @@
import org.foray.fotree.fo.obj.PageSequence4a;
import org.foray.fotree.fo.obj.Root4a;
import org.foray.fotree.foreign.ForeignNamespaceHandler;
-import org.foray.xml.SaxParser;
+import org.foray.xml.SaxParser4a;
import org.axsl.constants.XmlConstants;
import org.axsl.fotree.FoTreeEvent;
@@ -71,7 +71,7 @@
/**
* SAX Handler that builds the formatting object tree.
*/
-public class FoTreeParser4a extends SaxParser<FoTree4a> implements FoTreeParser, NamespaceNative.ErrorHandler {
+public class FoTreeParser4a extends SaxParser4a<FoTree4a> implements FoTreeParser, NamespaceNative.ErrorHandler {
/** The initial size of the text buffer for accumulating text. */
private static final int INITIAL_TEXT_BUFFER_SIZE = 4096;
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/GraphicServer4a.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/GraphicServer4a.java 2025-01-10 16:31:20 UTC (rev 13354)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/GraphicServer4a.java 2025-01-10 16:51:18 UTC (rev 13355)
@@ -42,7 +42,7 @@
import org.foray.graphic.output.GraphicOutputFactory;
import org.foray.graphic.output.GraphicPdfFactory;
import org.foray.graphic.output.GraphicPsFactory;
-import org.foray.xml.SaxParser;
+import org.foray.xml.SaxParser4a;
import org.axsl.constants.XmlConstants;
import org.axsl.graphic.GraphicException;
@@ -117,7 +117,7 @@
* Constructor.
*/
public GraphicServer4a() {
- this.svgParserClassName = SaxParser.getParserClassName();
+ this.svgParserClassName = SaxParser4a.getParserClassName();
registerStandardFactories();
registerStandardOutputFactories();
}
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 2025-01-10 16:31:20 UTC (rev 13354)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/DictionaryParser.java 2025-01-10 16:51:18 UTC (rev 13355)
@@ -40,7 +40,7 @@
import org.foray.orthography.StringWordSegmentLatin1Factory;
import org.foray.orthography.StringWordSegmentUtf16Factory;
import org.foray.primitive.StringUtils;
-import org.foray.xml.SaxParser;
+import org.foray.xml.SaxParser4a;
import org.axsl.orthography.Word.PartOfSpeech;
@@ -65,7 +65,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<List<SegmentDictionary>> {
+public class DictionaryParser extends SaxParser4a<List<SegmentDictionary>> {
/**
* Container for the "axsl-dictionary" element as it is being parsed.
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 2025-01-10 16:31:20 UTC (rev 13354)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/OrthographyParser.java 2025-01-10 16:51:18 UTC (rev 13355)
@@ -44,7 +44,7 @@
import org.foray.orthography.OrthographyServer4aStandard;
import org.foray.orthography.PosUtils;
import org.foray.orthography.WordWrapperFactory;
-import org.foray.xml.SaxParser;
+import org.foray.xml.SaxParser4a;
import org.axsl.orthography.Word;
import org.axsl.orthography.Word.DerivativeType;
@@ -71,7 +71,7 @@
* {@link OrthographyServer4aStandard} instance.
* Normally this class doesn't need to be accessed directly.
*/
-public class OrthographyParser extends SaxParser<Orthography4aStandard> {
+public class OrthographyParser extends SaxParser4a<Orthography4aStandard> {
/** Stateful variable. */
private DictionaryResource currentDictionaryResource;
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 2025-01-10 16:31:20 UTC (rev 13354)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/PatternParser.java 2025-01-10 16:51:18 UTC (rev 13355)
@@ -34,7 +34,7 @@
package org.foray.orthography.util;
import org.foray.orthography.PatternTree;
-import org.foray.xml.SaxParser;
+import org.foray.xml.SaxParser4a;
import org.axsl.orthography.OrthographyException;
@@ -49,7 +49,7 @@
/**
* A SAX document handler to read and parse hyphenation patterns from an XML file.
*/
-public class PatternParser extends SaxParser<PatternTree> {
+public class PatternParser extends SaxParser4a<PatternTree> {
/** Constant indicating that the current element is "classes". */
static final int ELEM_CLASSES = 1;
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 2025-01-10 16:31:20 UTC (rev 13354)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/SpellChecker.java 2025-01-10 16:51:18 UTC (rev 13355)
@@ -39,7 +39,7 @@
import org.foray.orthography.OrthographyServerConfig;
import org.foray.orthography.SegmentDictionary;
import org.foray.primitive.StringUtils;
-import org.foray.xml.SaxParser;
+import org.foray.xml.SaxParser4a;
import org.foray.xml.SaxUtils;
import org.foray.xml.dtd.DtdAttribute;
import org.foray.xml.parse.Element;
@@ -95,7 +95,7 @@
* That document is then processed by this class, which reports on any words that are not found in the appropriate
* dictionaries.</p>
*/
-public class SpellChecker extends SaxParser<Object> {
+public class SpellChecker extends SaxParser4a<Object> {
/**
* Stores "axsl-spell-check-input", "text", "word", and "foreign" elements.
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-01-10 16:31:20 UTC (rev 13354)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPrettyPush.java 2025-01-10 16:51:18 UTC (rev 13355)
@@ -66,7 +66,7 @@
/**
* Reads an XML file and writes a pretty-printed version of it.
*/
-public class ForayPrettyPush extends SaxParser<Object> {
+public class ForayPrettyPush extends SaxParser4a<Object> {
/** Command-line status constant indicating that the command line itself was not properly formed. */
public static final byte STATUS_COMMAND_LINE_ERROR = 1;
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/Sax2DomParser.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/Sax2DomParser.java 2025-01-10 16:31:20 UTC (rev 13354)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/Sax2DomParser.java 2025-01-10 16:51:18 UTC (rev 13355)
@@ -48,7 +48,7 @@
* for the main SAX parser when that parser encounters embedded XML from a different namespace, and wishes to parse that
* content into a generic DOM for later processing.
*/
-public class Sax2DomParser extends SaxParser<Document> {
+public class Sax2DomParser extends SaxParser4a<Document> {
/** The DOM {@link Document} being parsed. */
private Document domDocument;
Deleted: trunk/foray/foray-xml/src/main/java/org/foray/xml/SaxParser.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/SaxParser.java 2025-01-10 16:31:20 UTC (rev 13354)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/SaxParser.java 2025-01-10 16:51:18 UTC (rev 13355)
@@ -1,703 +0,0 @@
-/*
- * Copyright 2005 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.xml;
-
-import org.foray.primitive.StringUtils;
-import org.foray.xml.dtd.Dtd;
-import org.foray.xml.dtd.DtdElement;
-import org.foray.xml.model.XsdElement;
-
-import org.apache.ws.commons.schema.XmlSchemaCollection;
-import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.resolver.URIResolver;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.event.Level;
-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.SAXParseException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.ext.DefaultHandler2;
-import org.xml.sax.ext.Locator2;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import javax.xml.XMLConstants;
-import javax.xml.namespace.QName;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.transform.stream.StreamSource;
-
-/**
- * <p>Abstract superclass for SAX parsers.</p>
- *
- * <p>In order to avoid exposing a logger in the API, this class implements basic logging functions on behalf of the
- * subclass.
- * If these basic functions are not adequate to the needs of the subclass, it is of course free to implement a
- * different logging solution.</p>
- *
- * @param <T> The type of object that should be produced by this parser.
- */
-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)";
-
- /** 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;
-
- /** The Dtd for this document, which can be null. */
- private Dtd dtd;
-
- /** The XML Schema for this document, which can be null. */
- private XmlSchemaCollection schemaCollection;
-
- /** Map whose key is an (Apache) schema element, and whose value is a (FOray) schema element. */
- private Map<XmlSchemaElement, XsdElement> schemaElementMap = new HashMap<XmlSchemaElement, XsdElement>();
-
- /* 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 Locator2 locator;
-
- /** The logger. */
- private Logger logger = LoggerFactory.getLogger(this.getClass());
-
- /** 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;
-
- /** The entity resolver. */
- private EntityResolver entityResolver;
-
- /**
- * 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 SAXException For errors found by the SAX parser.
- */
- public abstract T parse(InputSource inputSource) throws IOException, 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 SAXException For errors found by the SAX parser.
- */
- public T parse(final URL input) throws IOException, SAXException {
- final InputSource inputSource = new InputSource(input.toExternalForm());
- return parse(inputSource);
- }
-
- @Override
- public void setDocumentLocator(final Locator locator) {
- this.locator = (Locator2) 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.
- */
- public static String getParserClassName() {
- try {
- return SAXParserFactory.newInstance().newSAXParser().getXMLReader().getClass().getName();
- } catch (final SAXException | ParserConfigurationException e) {
- return null;
- }
- }
-
- /**
- * Returns a location in the input document as a formatted string.
- * @param location The location being marked.
- * @return A location in the input document as a formatted string.
- */
- protected String getLocationString(final Locator location) {
- if (location == null) {
- return StringUtils.EMPTY_STRING;
- }
- return String.format(LOCATION_FORMAT_STRING, location.getSystemId(), location.getLineNumber(),
- location.getColumnNumber());
- }
-
- /**
- * Returns the line and column number of a location in the input document as a formatted string.
- * @param location The location being marked.
- * @return The line and column number of a location in the input document as a formatted string.
- */
- protected String getShortLocationString(final Locator location) {
- if (location == null) {
- return StringUtils.EMPTY_STRING;
- }
- return String.format(SHORT_LOCATION_FORMAT_STRING, location.getLineNumber(), location.getColumnNumber());
- }
-
- /**
- * 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 instead want
- * to use one of the methods mentioned in the "See ..." documentation for this method.
- * @return The locator.
- * @see #errorMessage(String, Object...)
- * @see #errorMessage(Locator, String, Object...)
- * @see #warningMessage(String, Object...)
- * @see #warningMessage(Locator, String, Object...)
- * @see #infoMessage(String, Object...)
- * @see #infoMessage(Locator, String, Object...)
- * @see #debugMessage(String, Object...)
- * @see #debugMessage(Locator, String, Object...)
- * @see #traceMessage(String, Object...)
- * @see #traceMessage(Locator, String, Object...)
- * @see #getLocationString(Locator)
- * @see #getShortLocationString(Locator)
- */
- protected Locator getLocator() {
- return this.locator;
- }
-
- /**
- * Creates a standard SAX2 parser, suitable for general XML parsing.
- * This method is intended for subclass convenience, and makes quite a few assumptions about what is "suitable for
- * general XML parsing," generally erring toward thoroughness instead of speed.
- * Subclasses that wish to override features of the parser created by this method can do so easily by setting those
- * features on the returned parser after it is created.
- * @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.
- * @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.
- */
- public XMLReader createSax2Parser(final boolean validate, final boolean namespaceAware,
- final boolean namespacePrefixes, final EntityResolver entityResolver, final boolean notifyCharRefs)
- throws SAXException {
- this.entityResolver = entityResolver;
-
- /* TODO: Using XMLReaderFactory (now deprecated), there was an option createXMLReader(String) that allowed a
- * specific implementation of SAXParser to be specified.
- * There does not seem to be a way to do this when creating the SAXParser from the SAXParserFactory.
- * Perhaps the same effect can be achieved some other way.
- * If so, we would like to use the org.apache.xerces.parsers.SAXParser implementation, because it reports
- * numeric character references in startEntity and endEntity.
- */
-
- final SAXParserFactory parserFactory = SAXParserFactory.newInstance();
- parserFactory.setValidating(validate);
- parserFactory.setNamespaceAware(namespaceAware);
- final SAXParser saxParser;
- try {
- saxParser = parserFactory.newSAXParser();
- } catch (final ParserConfigurationException e) {
- throw new SAXException(e);
- }
- final XMLReader xmlReader = saxParser.getXMLReader();
-
-
- this.schemaCollection = new XmlSchemaCollection();
- if (entityResolver != null) {
- final URIResolver uriResolver = new EntityResolverUriResolver(entityResolver);
- if (uriResolver != null) {
- this.schemaCollection.setSchemaResolver(uriResolver);
- }
- }
- this.logger.info("Using SAX2 Parser {}", xmlReader.getClass().getName());
- xmlReader.setEntityResolver(entityResolver);
- xmlReader.setContentHandler(this);
- xmlReader.setErrorHandler(this);
-
-
- /* Standard SAX features and properties. */
- /* First, make some assertions about read-only settings. */
- assertFeature(xmlReader, SaxStdFeatures.USE_ATTRIBUTES2, true, Level.ERROR);
- assertFeature(xmlReader, SaxStdFeatures.USE_LOCATOR2, true, Level.ERROR);
-
- /* Second, adjust settings for writable options. */
- setFeature(xmlReader, SaxStdFeatures.NAMESPACES, namespacePrefixes, Level.ERROR);
- setFeature(xmlReader, SaxStdFeatures.NAMESPACE_PREFIXES, namespacePrefixes, Level.ERROR);
- /* Turn on validation if it is available. */
- if (validate) {
- setFeature(xmlReader, SaxStdFeatures.VALIDATION, true, Level.WARN);
- }
- /* Report the beginning and end of parameter entities. */
- setFeature(xmlReader, SaxStdFeatures.LEXICAL_HANDLER_PARAMETER_ENTITIES, true, Level.ERROR);
-
- /* Bind the LexicalHandler to the XMLReader if possible. */
- setProperty(xmlReader, SaxStdProperties.LEXICAL_HANDLER, this, Level.ERROR);
- /* Bind the DeclHandler to the XMLReader if possible. */
- setProperty(xmlReader, SaxStdProperties.DECLARATION_HANDLER, this, Level.ERROR);
-
-
- /* Xerces-specific features. These features have a higher likelihood of NOT being supported by all parsers. */
-
- if (notifyCharRefs) {
- /* If requested, it is a fatal error if it is not available.*/
- setFeature(xmlReader, XercesFeatures.SCANNER_NOTIFY_CHAR_REFS, true, Level.ERROR);
- }
-
- setFeature(xmlReader, XercesFeatures.VALIDATION_SCHEMA, true, Level.WARN);
- setFeature(xmlReader, XercesFeatures.VALIDATION_SCHEMA_FULL_CHECKING, true, Level.WARN);
- setFeature(xmlReader, XercesFeatures.HONOUR_ALL_SCHEMALOCATIONS, true, Level.WARN);
-
-
- return xmlReader;
- }
-
- /**
- * Convenience method used to set parser features, handling exceptions with appropriate log messages.
- * @param xmlReader The reader to which the feature should be set.
- * @param feature The name of the feature.
- * @param value The value of the feature.
- * @param loggingLevel The logging level to which any exceptions should be logged. A logging level of null implies
- * that the exception should be rethrown instead of logged.
- */
- private void setFeature(final XMLReader xmlReader, final String feature, final boolean value,
- final org.slf4j.event.Level loggingLevel) throws SAXException {
- try {
- xmlReader.setFeature(feature, value);
- } catch (final SAXNotRecognizedException e) {
- if (loggingLevel == null) {
- throw e;
- } else {
- this.logger.atLevel(loggingLevel).log("SAX2 parser does not recognize feature: " + feature);
- }
- } catch (final SAXNotSupportedException e) {
- if (loggingLevel == null) {
- throw e;
- } else {
- this.logger.atLevel(loggingLevel).log("SAX2 parser does not support feature: " + feature);
- }
- }
- }
-
- /**
- * Convenience method used to check parser features.
- * @param xmlReader The reader on which the feature is being checked.
- * @param feature The feature being tested.
- * @param expectedValue The expected value of {@code feature}.
- * @param loggingLevel The logging level to which any exceptions or assertion failures should be logged.
- * @throws SAXException For unrecognized features, unsupported features, or assertion failures, when the logging
- * level has not been set.
- */
- protected void assertFeature(final XMLReader xmlReader, final String feature, final boolean expectedValue,
- final org.slf4j.event.Level loggingLevel) throws SAXException {
- try {
- final boolean value = xmlReader.getFeature(feature);
- if (value != expectedValue) {
- final String message = "Parser feature failure. Feature: " + feature + ", Expected: " + expectedValue
- + ", Actual: " + value;
- if (loggingLevel == null) {
- throw new SAXException(message);
- } else {
- this.logger.atLevel(loggingLevel).log(message);
- }
- }
- } catch (final SAXNotRecognizedException e) {
- if (loggingLevel == null) {
- throw e;
- } else {
- this.logger.atLevel(loggingLevel).log("SAX2 parser does not recognize feature: " + feature);
- }
- } catch (final SAXNotSupportedException e) {
- if (loggingLevel == null) {
- throw e;
- } else {
- this.logger.atLevel(loggingLevel).log("SAX2 parser does not support feature: " + feature);
- }
- }
- }
-
- /**
- * Convenience method used to set parser properties, handling exceptions with appropriate log messages.
- * @param xmlReader The reader to which the property should be set.
- * @param property The name of the property.
- * @param value The value of the property.
- * @param loggingLevel The logging level to which any exceptions should be logged. A logging level of null implies
- * that the exception rethrown instead of logged.
- */
- private void setProperty(final XMLReader xmlReader, final String property, final Object value,
- final org.slf4j.event.Level loggingLevel) throws SAXException {
- try {
- xmlReader.setProperty(property, value);
- } catch (final SAXNotRecognizedException e) {
- if (loggingLevel == null) {
- throw e;
- } else {
- this.logger.atLevel(loggingLevel).log("SAX2 parser does not recognize property: " + property);
- }
- } catch (final SAXNotSupportedException e) {
- if (loggingLevel == null) {
- throw e;
- } else {
- this.logger.atLevel(loggingLevel).log("SAX2 parser does not support property: " + property);
- }
- }
- }
-
- /**
- * 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 <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 <T2 extends Object> T2 instantiate(final String className, final Class<T2> expectedType,
- final Class<?>[] parameterTypes, final Object[] parameters) throws SAXException {
- Class<?> theClass = null;
- try {
- theClass = Class.forName(className);
- } catch (final ClassNotFoundException e) {
- throw new SAXException(e);
- }
- if (! expectedType.isAssignableFrom(theClass)) {
- this.logger.warn("Class \"{}\" is not a {} class.", className, expectedType.getName());
- return null;
- }
-
- @SuppressWarnings("unchecked")
- final Class<T2> factoryClass = (Class<T2>) theClass;
- Constructor<T2> constructor = null;
- try {
- constructor = factoryClass.getConstructor(parameterTypes);
- } catch (final SecurityException e) {
- throw new SAXException(e);
- } catch (final NoSuchMethodException e) {
- throw new SAXException(e);
- }
-
- T2 newInstance = null;
- try {
- newInstance = constructor.newInstance(parameters);
- } catch (final IllegalArgumentException e) {
- throw new SAXException(e);
- } catch (final InstantiationException e) {
- throw new SAXException(e);
- } catch (final IllegalAccessException e) {
- throw new SAXException(e);
- } catch (final InvocationTargetException e) {
- throw new SAXException(e);
- }
- return newInstance;
- }
-
- /**
- * Used 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();
-
- @Override
- public void characters(final char[] chars, final int start, final int length) throws SAXException {
- if (this.textParsingActive) {
- 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();
- this.textAccumulator.setLength(0);
- 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);
- }
-
- /**
- * Returns the {@link StringBuilder} in which text is being accumulated.
- * This should not ordinarily be needed by subclasses, but is exposed here for cases where it is more efficient to
- * operate directly on the builder than with immutable strings.
- * @return The text accumulator.
- */
- protected StringBuilder getTextAccumulator() {
- return this.textAccumulator;
- }
-
- @Override
- public void startPrefixMapping(final String prefix, final String uri) throws SAXException {
- // no op
- }
-
- @Override
- public void endPrefixMapping(final String prefix) throws SAXException {
- // no op
- }
-
- @Override
- public void elementDecl(final String name, final String model) {
- final DtdElement dtdElement = new DtdElement(name, model);
- if (this.dtd == null) {
- this.dtd = new Dtd();
- }
- this.dtd.addElement(dtdElement);
- }
-
- /**
- * Returns the parsed DTD.
- * @return The parsed DTD.
- */
- public Dtd getDtd() {
- return this.dtd;
- }
-
- /**
- * Returns the map of schema elements.
- * @return The map of schema elements.
- */
- public Map<XmlSchemaElement, XsdElement> getSchemaElementMap() {
- return this.schemaElementMap;
- }
-
- /**
- * Checks a set of attributes to see whether they contain a reference to a schema that needs to be parsed.
- * @param attributes The attributes being tested.
- * @throws SAXException For problems opening, reading, or closing the schema file.
- */
- protected void parseSchemaLocation(final Attributes attributes) throws SAXException {
- for (int index = 0; index < attributes.getLength(); index ++) {
- if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(attributes.getURI(index))
- && "schemaLocation".equals(attributes.getLocalName(index))) {
- final String schemaLocation = attributes.getValue(index);
- final StringTokenizer tokenizer = new StringTokenizer(schemaLocation);
- /* Discard the first token, which is the namespace part. */
- tokenizer.nextToken();
- final String schemaUrlString = tokenizer.nextToken();
- InputStream is = null;
- try {
- if (this.entityResolver == null) {
- final URL schemaUrl = new URL(schemaUrlString);
- is = schemaUrl.openStream();
- } else {
- final InputSource inputSource = this.entityResolver.resolveEntity(null, schemaUrlString);
- is = inputSource.getByteStream();
- }
- } catch (final IOException e) {
- throw new SAXException(e);
- }
- this.schemaCollection.read(new StreamSource(is));
- }
- }
- }
-
- @Override
- public void error(final SAXParseException ex) {
- this.logger.error(ex.getMessage());
- }
-
- @Override
- public void warning(final SAXParseException ex) {
- this.logger.warn(ex.getMessage());
- }
-
- /**
- * Logs an error message, noting the location of the event being tagged.
- * @param location The location of the event being tagged.
- * @param message The message to be logged.
- * @param arguments Parameters for the string template, if needed.
- */
- public void errorMessage(final Locator location, final String message, final Object... arguments) {
- final String template = getLocationString(location) + ": " + message;
- this.logger.error(template, arguments);
- }
-
- /**
- * Logs an error message, noting the location currently being parsed.
- * @param message The message to be logged.
- * @param arguments Parameters for the string template, if needed.
- */
- public void errorMessage(final String message, final Object... arguments) {
- errorMessage(this.locator, message, arguments);
- }
-
- /**
- * Logs a warning message, noting the location of the event being tagged.
- * @param location The location of the event being tagged.
- * @param message The message to be logged.
- * @param arguments Parameters for the string template, if needed.
- */
- public void warningMessage(final Locator location, final String message, final Object... arguments) {
- final String template = getLocationString(location) + ": " + message;
- this.logger.warn(template, arguments);
- }
-
- /**
- * Logs a warning message, noting the location currently being parsed.
- * @param message The message to be logged.
- * @param arguments Parameters for the string template, if needed.
- */
- public void warningMessage(final String message, final Object... arguments) {
- warningMessage(this.locator, message, arguments);
- }
-
- /**
- * Logs an info message, noting the location of the event being logged.
- * @param location The location of the event being tagged.
- * @param message The message to be logged.
- * @param arguments Parameters for the string template, if needed.
- */
- public void infoMessage(final Locator location, final String message, final Object... arguments) {
- final String template = getLocationString(location) + ": " + message;
- this.logger.info(template, arguments);
- }
-
- /**
- * Logs an info message, noting the location currently being parsed.
- * @param message The message to be logged.
- * @param arguments Parameters for the string template, if needed.
- */
- public void infoMessage(final String message, final Object... arguments) {
- infoMessage(this.locator, message, arguments);
- }
-
- /**
- * Logs a debug message, noting the location of the event being logged.
- * @param location The location of the event being tagged.
- * @param message The message to be logged.
- * @param arguments Parameters for the string template, if needed.
- */
- public void debugMessage(final Locator location, final String message, final Object... arguments) {
- final String template = getLocationString(location) + ": " + message;
- this.logger.debug(template, arguments);
- }
-
- /**
- * Logs a debug message, noting the location currently being parsed.
- * @param message The message to be logged.
- * @param arguments Parameters for the string template, if needed.
- */
- public void debugMessage(final String message, final Object... arguments) {
- debugMessage(this.locator, message, arguments);
- }
-
- /**
- * Logs a trace message, noting the location currently being parsed.
- * @param location The location of the event being tagged.
- * @param message The message to be logged.
- * @param arguments Parameters for the string template, if needed.
- */
- public void traceMessage(final Locator location, final String message, final Object... arguments) {
- final String template = getLocationString(location) + ": " + message;
- this.logger.trace(template, arguments);
- }
-
- /**
- * Logs a trace message, noting the location currently being parsed.
- * @param message The message to be logged.
- * @param arguments Parameters for the string template, if needed.
- */
- public void traceMessage(final String message, final Object... arguments) {
- traceMessage(this.locator, message, arguments);
- }
-
- /**
- * 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;
- }
-
- /**
- * Retrieves a given required attribute, throwing a {@link SAXException} if it is missing.
- * @param attributes The attributes collection in which we expect to find the requested attribute.
- * @param attributeName The name of the attribute to be retrieved.
- * @return The attribute value, if it is found.
- * @throws SAXException If the attribute is not found.
- */
- public String required(final Attributes attributes, final String attributeName) throws SAXException {
- final String attributeValue = attributes.getValue(attributeName);
- if (attributeValue == null) {
- throw new SAXException();
- }
- return attributeValue;
- }
-
- /**
- * Retrieves a given optional attribute, returning a provided default value if it is missing.
- * @param attributes The attributes collection in which we expect to find the requested attribute.
- * @param attributeName The name of the attribute to be retrieved.
- * @param defaultValue The value to be returned if the attribute is not found.
- * @return The attribute value, if it is found, otherwise {@code defaultValue}.
- */
- public String optional(final Attributes attributes, final String attributeName, final String defaultValue) {
- final String attributeValue = attributes.getValue(attributeName);
- return attributeValue == null ? defaultValue : attributeValue;
- }
-
- /**
- * Returns the (Apache) schema element for a given QName.
- * @param qname The qname of the element to be returned.
- * @return The (Apache) schema element matching {@code qname}.
- */
- public XmlSchemaElement getSchemaElement(final QName qname) {
- return this.schemaCollection.getElementByQName(qname);
- }
-
-}
Copied: trunk/foray/foray-xml/src/main/java/org/foray/xml/SaxParser4a.java (from rev 13354, trunk/foray/foray-xml/src/main/java/org/foray/xml/SaxParser.java)
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/SaxParser4a.java (rev 0)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/SaxParser4a.java 2025-01-10 16:51:18 UTC (rev 13355)
@@ -0,0 +1,703 @@
+/*
+ * Copyright 2005 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.xml;
+
+import org.foray.primitive.StringUtils;
+import org.foray.xml.dtd.Dtd;
+import org.foray.xml.dtd.DtdElement;
+import org.foray.xml.model.XsdElement;
+
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.resolver.URIResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.event.Level;
+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.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.ext.DefaultHandler2;
+import org.xml.sax.ext.Locator2;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.stream.StreamSource;
+
+/**
+ * <p>Abstract superclass for SAX parsers used in FORay.</p>
+ *
+ * <p>In order to avoid exposing a logger in the API, this class implements basic logging functions on behalf of the
+ * subclass.
+ * If these basic functions are not adequate to the needs of the subclass, it is of course free to implement a
+ * different logging solution.</p>
+ *
+ * @param <T> The type of object that should be produced by this parser.
+ */
+public abstract class SaxParser4a<T extends Object> extends DefaultHandler2 {
+
+ /** 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;
+
+ /** The Dtd for this document, which can be null. */
+ private Dtd dtd;
+
+ /** The XML Schema for this document, which can be null. */
+ private XmlSchemaCollection schemaCollection;
+
+ /** Map whose key is an (Apache) schema element, and whose value is a (FOray) schema element. */
+ private Map<XmlSchemaElement, XsdElement> schemaElementMap = new HashMap<XmlSchemaElement, XsdElement>();
+
+ /* 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 Locator2 locator;
+
+ /** The logger. */
+ private Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ /** 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;
+
+ /** The entity resolver. */
+ private EntityResolver entityResolver;
+
+ /**
+ * 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 SAXException For errors found by the SAX parser.
+ */
+ public abstract T parse(InputSource inputSource) throws IOException, 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 SAXException For errors found by the SAX parser.
+ */
+ public T parse(final URL input) throws IOException, SAXException {
+ final InputSource inputSource = new InputSource(input.toExternalForm());
+ return parse(inputSource);
+ }
+
+ @Override
+ public void setDocumentLocator(final Locator locator) {
+ this.locator = (Locator2) 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.
+ */
+ public static String getParserClassName() {
+ try {
+ return SAXParserFactory.newInstance().newSAXParser().getXMLReader().getClass().getName();
+ } catch (final SAXException | ParserConfigurationException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Returns a location in the input document as a formatted string.
+ * @param location The location being marked.
+ * @return A location in the input document as a formatted string.
+ */
+ protected String getLocationString(final Locator location) {
+ if (location == null) {
+ return StringUtils.EMPTY_STRING;
+ }
+ return String.format(LOCATION_FORMAT_STRING, location.getSystemId(), location.getLineNumber(),
+ location.getColumnNumber());
+ }
+
+ /**
+ * Returns the line and column number of a location in the input document as a formatted string.
+ * @param location The location being marked.
+ * @return The line and column number of a location in the input document as a formatted string.
+ */
+ protected String getShortLocationString(final Locator location) {
+ if (location == null) {
+ return StringUtils.EMPTY_STRING;
+ }
+ return String.format(SHORT_LOCATION_FORMAT_STRING, location.getLineNumber(), location.getColumnNumber());
+ }
+
+ /**
+ * 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 instead want
+ * to use one of the methods mentioned in the "See ..." documentation for this method.
+ * @return The locator.
+ * @see #errorMessage(String, Object...)
+ * @see #errorMessage(Locator, String, Object...)
+ * @see #warningMessage(String, Object...)
+ * @see #warningMessage(Locator, String, Object...)
+ * @see #infoMessage(String, Object...)
+ * @see #infoMessage(Locator, String, Object...)
+ * @see #debugMessage(String, Object...)
+ * @see #debugMessage(Locator, String, Object...)
+ * @see #traceMessage(String, Object...)
+ * @see #traceMessage(Locator, String, Object...)
+ * @see #getLocationString(Locator)
+ * @see #getShortLocationString(Locator)
+ */
+ protected Locator getLocator() {
+ return this.locator;
+ }
+
+ /**
+ * Creates a standard SAX2 parser, suitable for general XML parsing.
+ * This method is intended for subclass convenience, and makes quite a few assumptions about what is "suitable for
+ * general XML parsing," generally erring toward thoroughness instead of speed.
+ * Subclasses that wish to override features of the parser created by this method can do so easily by setting those
+ * features on the returned parser after it is created.
+ * @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.
+ * @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.
+ */
+ public XMLReader createSax2Parser(final boolean validate, final boolean namespaceAware,
+ final boolean namespacePrefixes, final EntityResolver entityResolver, final boolean notifyCharRefs)
+ throws SAXException {
+ this.entityResolver = entityResolver;
+
+ /* TODO: Using XMLReaderFactory (now deprecated), there was an option createXMLReader(String) that allowed a
+ * specific implementation of SAXParser to be specified.
+ * There does not seem to be a way to do this when creating the SAXParser from the SAXParserFactory.
+ * Perhaps the same effect can be achieved some other way.
+ * If so, we would like to use the org.apache.xerces.parsers.SAXParser implementation, because it reports
+ * numeric character references in startEntity and endEntity.
+ */
+
+ final SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+ parserFactory.setValidating(validate);
+ parserFactory.setNamespaceAware(namespaceAware);
+ final SAXParser saxParser;
+ try {
+ saxParser = parserFactory.newSAXParser();
+ } catch (final ParserConfigurationException e) {
+ throw new SAXException(e);
+ }
+ final XMLReader xmlReader = saxParser.getXMLReader();
+
+
+ this.schemaCollection = new XmlSchemaCollection();
+ if (entityResolver != null) {
+ final URIResolver uriResolver = new EntityResolverUriResolver(entityResolver);
+ if (uriResolver != null) {
+ this.schemaCollection.setSchemaResolver(uriResolver);
+ }
+ }
+ this.logger.info("Using SAX2 Parser {}", xmlReader.getClass().getName());
+ xmlReader.setEntityResolver(entityResolver);
+ xmlReader.setContentHandler(this);
+ xmlReader.setErrorHandler(this);
+
+
+ /* Standard SAX features and properties. */
+ /* First, make some assertions about read-only settings. */
+ assertFeature(xmlReader, SaxStdFeatures.USE_ATTRIBUTES2, true, Level.ERROR);
+ assertFeature(xmlReader, SaxStdFeatures.USE_LOCATOR2, true, Level.ERROR);
+
+ /* Second, adjust settings for writable options. */
+ setFeature(xmlReader, SaxStdFeatures.NAMESPACES, namespacePrefixes, Level.ERROR);
+ setFeature(xmlReader, SaxStdFeatures.NAMESPACE_PREFIXES, namespacePrefixes, Level.ERROR);
+ /* Turn on validation if it is available. */
+ if (validate) {
+ setFeature(xmlReader, SaxStdFeatures.VALIDATION, true, Level.WARN);
+ }
+ /* Report the beginning and end of parameter entities. */
+ setFeature(xmlReader, SaxStdFeatures.LEXICAL_HANDLER_PARAMETER_ENTITIES, true, Level.ERROR);
+
+ /* Bind the LexicalHandler to the XMLReader if possible. */
+ setProperty(xmlReader, SaxStdProperties.LEXICAL_HANDLER, this, Level.ERROR);
+ /* Bind the DeclHandler to the XMLReader if possible. */
+ setProperty(xmlReader, SaxStdProperties.DECLARATION_HANDLER, this, Level.ERROR);
+
+
+ /* Xerces-specific features. These features have a higher likelihood of NOT being supported by all parsers. */
+
+ if (notifyCharRefs) {
+ /* If requested, it is a fatal error if it is not available.*/
+ setFeature(xmlReader, XercesFeatures.SCANNER_NOTIFY_CHAR_REFS, true, Level.ERROR);
+ }
+
+ setFeature(xmlReader, XercesFeatures.VALIDATION_SCHEMA, true, Level.WARN);
+ setFeature(xmlReader, XercesFeatures.VALIDATION_SCHEMA_FULL_CHECKING, true, Level.WARN);
+ setFeature(xmlReader, XercesFeatures.HONOUR_ALL_SCHEMALOCATIONS, true, Level.WARN);
+
+
+ return xmlReader;
+ }
+
+ /**
+ * Convenience method used to set parser features, handling exceptions with appropriate log messages.
+ * @param xmlReader The reader to which the feature should be set.
+ * @param feature The name of the feature.
+ * @param value The value of the feature.
+ * @param loggingLevel The logging level to which any exceptions should be logged. A logging level of null implies
+ * that the exception should be rethrown instead of logged.
+ */
+ private void setFeature(final XMLReader xmlReader, final String feature, final boolean value,
+ final org.slf4j.event.Level loggingLevel) throws SAXException {
+ try {
+ xmlReader.setFeature(feature, value);
+ } catch (final SAXNotRecognizedException e) {
+ if (loggingLevel == null) {
+ throw e;
+ } else {
+ this.logger.atLevel(loggingLevel).log("SAX2 parser does not recognize feature: " + feature);
+ }
+ } catch (final SAXNotSupportedException e) {
+ if (loggingLevel == null) {
+ throw e;
+ } else {
+ this.logger.atLevel(loggingLevel).log("SAX2 parser does not support feature: " + feature);
+ }
+ }
+ }
+
+ /**
+ * Convenience method used to check parser features.
+ * @param xmlReader The reader on which the feature is being checked.
+ * @param feature The feature being tested.
+ * @param expectedValue The expected value of {@code feature}.
+ * @param loggingLevel The logging level to which any exceptions or assertion failures should be logged.
+ * @throws SAXException For unrecognized features, unsupported features, or assertion failures, when the logging
+ * level has not been set.
+ */
+ protected void assertFeature(final XMLReader xmlReader, final String feature, final boolean expectedValue,
+ final org.slf4j.event.Level loggingLevel) throws SAXException {
+ try {
+ final boolean value = xmlReader.getFeature(feature);
+ if (value != expectedValue) {
+ final String message = "Parser feature failure. Feature: " + feature + ", Expected: " + expectedValue
+ + ", Actual: " + value;
+ if (loggingLevel == null) {
+ throw new SAXException(message);
+ } else {
+ this.logger.atLevel(loggingLevel).log(message);
+ }
+ }
+ } catch (final SAXNotRecognizedException e) {
+ if (loggingLevel == null) {
+ throw e;
+ } else {
+ this.logger.atLevel(loggingLevel).log("SAX2 parser does not recognize feature: " + feature);
+ }
+ } catch (final SAXNotSupportedException e) {
+ if (loggingLevel == null) {
+ throw e;
+ } else {
+ this.logger.atLevel(loggingLevel).log("SAX2 parser does not support feature: " + feature);
+ }
+ }
+ }
+
+ /**
+ * Convenience method used to set parser properties, handling exceptions with appropriate log messages.
+ * @param xmlReader The reader to which the ...
[truncated message content] |
|
From: <vic...@us...> - 2025-01-10 16:31:23
|
Revision: 13354
http://sourceforge.net/p/foray/code/13354
Author: victormote
Date: 2025-01-10 16:31:20 +0000 (Fri, 10 Jan 2025)
Log Message:
-----------
1. Add deprecation reporting. 2. Fix use of deprecated API in SaxParser.
Modified Paths:
--------------
trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle
trunk/foray/foray-xml/src/main/java/org/foray/xml/SaxParser.java
Modified: trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle
===================================================================
--- trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle 2025-01-10 14:36:27 UTC (rev 13353)
+++ trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle 2025-01-10 16:31:20 UTC (rev 13354)
@@ -204,4 +204,9 @@
toolVersion = versions.checkstyle
}
+tasks.withType(JavaCompile) {
+ options.deprecation = true
+}
+
+
/* Last line of script. */
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/SaxParser.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/SaxParser.java 2025-01-10 14:36:27 UTC (rev 13353)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/SaxParser.java 2025-01-10 16:31:20 UTC (rev 13354)
@@ -50,7 +50,6 @@
import org.xml.sax.XMLReader;
import org.xml.sax.ext.DefaultHandler2;
import org.xml.sax.ext.Locator2;
-import org.xml.sax.helpers.XMLReaderFactory;
import java.io.IOException;
import java.io.InputStream;
@@ -63,6 +62,9 @@
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.stream.StreamSource;
/**
@@ -149,8 +151,8 @@
*/
public static String getParserClassName() {
try {
- return org.xml.sax.helpers.XMLReaderFactory.createXMLReader().getClass().getName();
- } catch (final SAXException e) {
+ return SAXParserFactory.newInstance().newSAXParser().getXMLReader().getClass().getName();
+ } catch (final SAXException | ParserConfigurationException e) {
return null;
}
}
@@ -226,9 +228,27 @@
final boolean namespacePrefixes, final EntityResolver entityResolver, final boolean notifyCharRefs)
throws SAXException {
this.entityResolver = entityResolver;
- /* Explicitly use the Xerces parser, because it reports numeric character references in startEntity and
- * endEntity. */
- final XMLReader xmlReader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
+
+ /* TODO: Using XMLReaderFactory (now deprecated), there was an option createXMLReader(String) that allowed a
+ * specific implementation of SAXParser to be specified.
+ * There does not seem to be a way to do this when creating the SAXParser from the SAXParserFactory.
+ * Perhaps the same effect can be achieved some other way.
+ * If so, we would like to use the org.apache.xerces.parsers.SAXParser implementation, because it reports
+ * numeric character references in startEntity and endEntity.
+ */
+
+ final SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+ parserFactory.setValidating(validate);
+ parserFactory.setNamespaceAware(namespaceAware);
+ final SAXParser saxParser;
+ try {
+ saxParser = parserFactory.newSAXParser();
+ } catch (final ParserConfigurationException e) {
+ throw new SAXException(e);
+ }
+ final XMLReader xmlReader = saxParser.getXMLReader();
+
+
this.schemaCollection = new XmlSchemaCollection();
if (entityResolver != null) {
final URIResolver uriResolver = new EntityResolverUriResolver(entityResolver);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-01-10 14:36:29
|
Revision: 13353
http://sourceforge.net/p/foray/code/13353
Author: victormote
Date: 2025-01-10 14:36:27 +0000 (Fri, 10 Jan 2025)
Log Message:
-----------
Fix compiler warning about synchronization. Not sure what the side-effects of this change might be.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/ImageConsumerImpl.java
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/ImageConsumerImpl.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/ImageConsumerImpl.java 2025-01-10 14:21:14 UTC (rev 13352)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/ImageConsumerImpl.java 2025-01-10 14:36:27 UTC (rev 13353)
@@ -102,7 +102,7 @@
* MessageHandler.errorln("TopDownLeftRight");
* }
*/
- synchronized (this.imageStatus) {
+ synchronized (this.ip) {
// Need to stop status if image done
if (this.imageStatus.intValue() != ImageConsumer.STATICIMAGEDONE
&& this.imageStatus.intValue()
@@ -157,7 +157,7 @@
* has an error.
*/
public boolean isImageReady() throws GraphicException {
- synchronized (this.imageStatus) {
+ synchronized (this.ip) {
if (this.imageStatus.intValue() == ImageConsumer.IMAGEABORTED) {
throw new GraphicException("Image aborted");
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-01-10 14:21:17
|
Revision: 13352
http://sourceforge.net/p/foray/code/13352
Author: victormote
Date: 2025-01-10 14:21:14 +0000 (Fri, 10 Jan 2025)
Log Message:
-----------
Partial fix of warnings about java build version.
Modified Paths:
--------------
trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle
Modified: trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle
===================================================================
--- trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle 2025-01-10 13:57:52 UTC (rev 13351)
+++ trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle 2025-01-10 14:21:14 UTC (rev 13352)
@@ -97,6 +97,9 @@
java {
sourceCompatibility = versions.javaSourceCompatibility
targetCompatibility = versions.javaTargetCompatibility
+ toolchain {
+ languageVersion.set(JavaLanguageVersion.of(17))
+ }
}
tasks.withType(JavaCompile) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|