You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@apache.org on 2001/02/01 05:29:47 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/processor ProcessorCharacters.java StylesheetHandler.java
sboag 01/01/31 20:29:47
Modified: java/src/org/apache/xalan/processor ProcessorCharacters.java
StylesheetHandler.java
Log:
Implement proper xml:space handling, as per bug reported by
"Timm, Sean" <ST...@mailgo.com> 01/31/2001 02:02 PM
A stack of whitespace preserving state is now maintained in StylesheetHandler
and queried in ProcessorCharacters.
Revision Changes Path
1.8 +4 -2 xml-xalan/java/src/org/apache/xalan/processor/ProcessorCharacters.java
Index: ProcessorCharacters.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorCharacters.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ProcessorCharacters.java 2000/11/23 04:57:23 1.7
+++ ProcessorCharacters.java 2001/02/01 04:29:46 1.8
@@ -82,15 +82,17 @@
*/
public void startNonText(StylesheetHandler handler) throws org.xml.sax.SAXException
{
-
if (this == handler.getCurrentProcessor())
+ {
handler.popProcessor();
+ }
int nChars = m_accumulator.length();
if ((nChars > 0)
&& ((null != m_xslTextElement)
- ||!XMLCharacterRecognizer.isWhiteSpace(m_accumulator)))
+ ||!XMLCharacterRecognizer.isWhiteSpace(m_accumulator))
+ || handler.isSpacePreserve())
{
ElemTextLiteral elem = new ElemTextLiteral();
1.35 +86 -0 xml-xalan/java/src/org/apache/xalan/processor/StylesheetHandler.java
Index: StylesheetHandler.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/StylesheetHandler.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- StylesheetHandler.java 2001/01/26 18:04:12 1.34
+++ StylesheetHandler.java 2001/02/01 04:29:46 1.35
@@ -76,6 +76,7 @@
import org.apache.xml.utils.NodeConsumer;
import org.apache.xml.utils.PrefixResolver;
import org.apache.xml.utils.XMLCharacterRecognizer;
+import org.apache.xml.utils.BoolStack;
import org.apache.xpath.compiler.FunctionTable;
import org.apache.xpath.compiler.XPathParser;
import org.apache.xpath.functions.Function;
@@ -453,6 +454,7 @@
public void startDocument() throws org.xml.sax.SAXException
{
m_stylesheetLevel++;
+ pushSpaceHandling(false);
}
@@ -504,6 +506,8 @@
elemProcessor.startNonText(this);
m_stylesheetLevel--;
+
+ popSpaceHandling();
// WARNING: This test works only as long as stylesheets are parsed
// more or less recursively. If we switch to an iterative "work-list"
@@ -618,6 +622,8 @@
return;
flushCharacters();
+
+ pushSpaceHandling(attributes);
XSLTElementProcessor elemProcessor = getProcessorFor(uri, localName,
rawName);
@@ -653,6 +659,8 @@
m_shouldProcess = false;
flushCharacters();
+
+ popSpaceHandling();
XSLTElementProcessor p = getCurrentProcessor();
@@ -1513,4 +1521,82 @@
{
return m_originatingNode;
}
+
+ /**
+ * Stack of booleans that are pushed and popped in start/endElement depending
+ * on the value of xml:space=default/preserve.
+ */
+ private BoolStack m_spacePreserveStack = new BoolStack();
+
+ /**
+ * Return boolean value from the spacePreserve stack depending on the value
+ * of xml:space=default/preserve.
+ *
+ * @return true if space should be preserved, false otherwise.
+ */
+ boolean isSpacePreserve()
+ {
+ return m_spacePreserveStack.peek();
+ }
+
+ /**
+ * Pop boolean value from the spacePreserve stack.
+ */
+ void popSpaceHandling()
+ {
+ m_spacePreserveStack.pop();
+ }
+
+ /**
+ * Push boolean value on to the spacePreserve stack.
+ *
+ * @param b true if space should be preserved, false otherwise.
+ */
+ void pushSpaceHandling(boolean b)
+ throws org.xml.sax.SAXParseException
+ {
+ m_spacePreserveStack.push(b);
+ }
+
+ /**
+ * Push boolean value on to the spacePreserve stack depending on the value
+ * of xml:space=default/preserve.
+ *
+ * @param attrs list of attributes that were passed to startElement.
+ */
+ void pushSpaceHandling(Attributes attrs)
+ throws org.xml.sax.SAXParseException
+ {
+ String value = attrs.getValue("xml:space");
+ if(null == value)
+ {
+ m_spacePreserveStack.push(m_spacePreserveStack.peek());
+ }
+ else if(value.equals("preserve"))
+ {
+ m_spacePreserveStack.push(true);
+ }
+ else if(value.equals("default"))
+ {
+ m_spacePreserveStack.push(false);
+ }
+ else
+ {
+ SAXSourceLocator locator = getLocator();
+ ErrorListener handler = m_stylesheetProcessor.getErrorListener();
+
+ try
+ {
+ handler.error(new TransformerException("Illegal value for xml:space", locator));
+ }
+ catch (TransformerException te)
+ {
+ throw new org.xml.sax.SAXParseException(te.getMessage(), locator, te);
+ }
+ m_spacePreserveStack.push(m_spacePreserveStack.peek());
+ }
+ }
}
+
+
+