You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mi...@apache.org on 2003/10/06 16:31:31 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/templates ElemLiteralResult.java ElemExtensionCall.java
minchau 2003/10/06 07:31:31
Modified: java/src/org/apache/xalan/templates ElemLiteralResult.java
ElemExtensionCall.java
Log:
PR: bugzilla 21471
Submitted by: Joanne Tong
Reviewed by: Brian Minchau
Stop some SAXExceptions from being quietly caught by the serializer.
Revision Changes Path
1.37 +106 -63 xml-xalan/java/src/org/apache/xalan/templates/ElemLiteralResult.java
Index: ElemLiteralResult.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemLiteralResult.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- ElemLiteralResult.java 13 May 2003 17:42:30 -0000 1.36
+++ ElemLiteralResult.java 6 Oct 2003 14:31:31 -0000 1.37
@@ -65,6 +65,7 @@
import org.apache.xml.serializer.SerializationHandler;
import org.apache.xml.utils.StringVector;
import org.apache.xpath.XPathContext;
+import org.xml.sax.SAXException;
/**
* <meta name="usage" content="advanced"/>
@@ -640,84 +641,126 @@
*
* @throws TransformerException
*/
- public void execute(
- TransformerImpl transformer)
- throws TransformerException
- {
-
- if (TransformerImpl.S_DEBUG)
- transformer.getTraceManager().fireTraceEvent(this);
-
- try
+ public void execute(TransformerImpl transformer)
+ throws TransformerException
{
- SerializationHandler rhandler = transformer.getSerializationHandler();
-
- // JJK Bugzilla 3464, test namespace85 -- make sure LRE's
- // namespace is asserted even if default, since xsl:element
- // may have changed the context.
- rhandler.startPrefixMapping(getPrefix(),getNamespace());
-
- // Add namespace declarations.
- executeNSDecls(transformer);
- rhandler.startElement(getNamespace(), getLocalName(), getRawName());
- try
- {
+ if (TransformerImpl.S_DEBUG)
+ transformer.getTraceManager().fireTraceEvent(this);
+ SerializationHandler rhandler = transformer.getSerializationHandler();
- // Process any possible attributes from xsl:use-attribute-sets first
- super.execute(transformer);
+ try
+ {
+ // JJK Bugzilla 3464, test namespace85 -- make sure LRE's
+ // namespace is asserted even if default, since xsl:element
+ // may have changed the context.
+ rhandler.startPrefixMapping(getPrefix(), getNamespace());
+
+ // Add namespace declarations.
+ executeNSDecls(transformer);
+ rhandler.startElement(getNamespace(), getLocalName(), getRawName());
+ }
+ catch (SAXException se)
+ {
+ throw new TransformerException(se);
+ }
- //xsl:version, excludeResultPrefixes???
- // Process the list of avts next
- if (null != m_avts)
+ /*
+ * If we make it to here we have done a successful startElement()
+ * we will do an endElement() call for balance, no matter what happens
+ * in the middle.
+ */
+
+ // tException remembers if we had an exception "in the middle"
+ TransformerException tException = null;
+ try
{
- int nAttrs = m_avts.size();
- for (int i = (nAttrs - 1); i >= 0; i--)
- {
- AVT avt = (AVT) m_avts.elementAt(i);
- XPathContext xctxt = transformer.getXPathContext();
- int sourceNode = xctxt.getCurrentNode();
- String stringedValue = avt.evaluate(xctxt, sourceNode, this);
+ // Process any possible attributes from xsl:use-attribute-sets first
+ super.execute(transformer);
- if (null != stringedValue)
+ //xsl:version, excludeResultPrefixes???
+ // Process the list of avts next
+ if (null != m_avts)
{
+ int nAttrs = m_avts.size();
- // Important Note: I'm not going to check for excluded namespace
- // prefixes here. It seems like it's too expensive, and I'm not
- // even sure this is right. But I could be wrong, so this needs
- // to be tested against other implementations.
-
- rhandler.addAttribute(avt.getURI(), avt.getName(),
- avt.getRawName(), "CDATA", stringedValue);
+ for (int i = (nAttrs - 1); i >= 0; i--)
+ {
+ AVT avt = (AVT) m_avts.elementAt(i);
+ XPathContext xctxt = transformer.getXPathContext();
+ int sourceNode = xctxt.getCurrentNode();
+ String stringedValue =
+ avt.evaluate(xctxt, sourceNode, this);
+
+ if (null != stringedValue)
+ {
+
+ // Important Note: I'm not going to check for excluded namespace
+ // prefixes here. It seems like it's too expensive, and I'm not
+ // even sure this is right. But I could be wrong, so this needs
+ // to be tested against other implementations.
+
+ rhandler.addAttribute(
+ avt.getURI(),
+ avt.getName(),
+ avt.getRawName(),
+ "CDATA",
+ stringedValue);
+ }
+ } // end for
}
- } // end for
+
+ // Now process all the elements in this subtree
+ // TODO: Process m_extensionElementPrefixes && m_attributeSetsNames
+ transformer.executeChildTemplates(this, true);
+ }
+ catch (TransformerException te)
+ {
+ // thrown in finally to prevent original exception consumed by subsequent exceptions
+ tException = te;
+ }
+ catch (SAXException se)
+ {
+ tException = new TransformerException(se);
}
- // Now process all the elements in this subtree
- // TODO: Process m_extensionElementPrefixes && m_attributeSetsNames
- transformer.executeChildTemplates(this, true);
- }
- finally
- {
- // If you don't do this in a finally statement, an exception could
- // cause a system hang.
- rhandler.endElement(getNamespace(), getLocalName(), getRawName());
+ try
+ {
+ /* we need to do this endElement() to balance the
+ * successful startElement() call even if
+ * there was an exception in the middle.
+ * Otherwise an exception in the middle could cause a system to hang.
+ */
+ rhandler.endElement(getNamespace(), getLocalName(), getRawName());
+ }
+ catch (SAXException se)
+ {
+ /* we did call endElement(). If thee was an exception
+ * in the middle throw that one, otherwise if there
+ * was an exception from endElement() throw that one.
+ */
+ if (tException != null)
+ throw tException;
+ else
+ throw new TransformerException(se);
+ }
unexecuteNSDecls(transformer);
-
- // JJK Bugzilla 3464, test namespace85 -- balance explicit start.
- rhandler.endPrefixMapping(getPrefix());
- }
- }
- catch (org.xml.sax.SAXException se)
- {
- throw new TransformerException(se);
- }
- if (TransformerImpl.S_DEBUG)
- transformer.getTraceManager().fireTraceEndEvent(this);
+ // JJK Bugzilla 3464, test namespace85 -- balance explicit start.
+ try
+ {
+ rhandler.endPrefixMapping(getPrefix());
+ }
+ catch (SAXException se)
+ {
+ throw new TransformerException(se);
+ }
- }
+ if (TransformerImpl.S_DEBUG)
+ transformer.getTraceManager().fireTraceEndEvent(this);
+
+ }
/**
* Compiling templates requires that we be able to list the AVTs
1.36 +4 -0 xml-xalan/java/src/org/apache/xalan/templates/ElemExtensionCall.java
Index: ElemExtensionCall.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemExtensionCall.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- ElemExtensionCall.java 18 Sep 2003 19:18:53 -0000 1.35
+++ ElemExtensionCall.java 6 Oct 2003 14:31:31 -0000 1.36
@@ -64,6 +64,7 @@
import org.apache.xalan.res.XSLTErrorResources;
import org.apache.xalan.transformer.TransformerImpl;
import org.apache.xpath.XPathContext;
+import org.xml.sax.SAXException;
/**
* <meta name="usage" content="advanced"/>
@@ -296,6 +297,9 @@
catch(TransformerException e)
{
transformer.getErrorListener().fatalError(e);
+ }
+ catch(SAXException se) {
+ throw new TransformerException(se);
}
if (TransformerImpl.S_DEBUG)
transformer.getTraceManager().fireTraceEndEvent(this);
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org