mkwan 2003/10/22 13:45:14
Modified: java/src/org/apache/xalan/xsltc/compiler Tag:
xslt20-compiled Parser.java UnsupportedElement.java
java/src/org/apache/xalan/xsltc/runtime Tag: xslt20-compiled
BasisLibrary.java ErrorMessages.java
Log:
Propagate the fixes for bug 23706 and 23896 from the head.
Fix a few problems for unsupported element and xsl:fallback.
Revision Changes Path
No revision
No revision
1.59.2.2 +9 -8
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java
Index: Parser.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java,v
retrieving revision 1.59.2.1
retrieving revision 1.59.2.2
diff -u -r1.59.2.1 -r1.59.2.2
--- Parser.java 16 Oct 2003 16:17:01 -0000 1.59.2.1
+++ Parser.java 22 Oct 2003 20:45:14 -0000 1.59.2.2
@@ -971,17 +971,18 @@
if (uri != null) {
// Check if the element belongs in our namespace
if (uri.equals(XSLT_URI)) {
- node = new UnsupportedElement(uri, prefix, local);
+ node = new UnsupportedElement(uri, prefix, local, false);
UnsupportedElement element = (UnsupportedElement)node;
- if (versionIsOne) {
- ErrorMsg msg = new
ErrorMsg(ErrorMsg.UNSUPPORTED_XSL_ERR,
+ ErrorMsg msg = new ErrorMsg(ErrorMsg.UNSUPPORTED_XSL_ERR,
_locator.getLineNumber(),local);
- element.setErrorMessage(msg);
- }
+ element.setErrorMessage(msg);
+ if (versionIsOne) {
+ reportError(UNSUPPORTED,msg);
+ }
}
// Check if this is an XSLTC extension element
else if (uri.equals(TRANSLET_URI)) {
- node = new UnsupportedElement(uri, prefix, local);
+ node = new UnsupportedElement(uri, prefix, local, true);
UnsupportedElement element = (UnsupportedElement)node;
ErrorMsg msg = new ErrorMsg(ErrorMsg.UNSUPPORTED_EXT_ERR,
_locator.getLineNumber(),local);
@@ -992,7 +993,7 @@
Stylesheet sheet = _xsltc.getStylesheet();
if ((sheet != null) && (sheet.isExtension(uri))) {
if (sheet != (SyntaxTreeNode)_parentStack.peek()) {
- node = new UnsupportedElement(uri, prefix, local);
+ node = new UnsupportedElement(uri, prefix, local,
true);
UnsupportedElement elem = (UnsupportedElement)node;
ErrorMsg msg =
new ErrorMsg(ErrorMsg.UNSUPPORTED_EXT_ERR,
1.5.6.2 +55 -30
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnsupportedElement.java
Index: UnsupportedElement.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnsupportedElement.java,v
retrieving revision 1.5.6.1
retrieving revision 1.5.6.2
diff -u -r1.5.6.1 -r1.5.6.2
--- UnsupportedElement.java 16 Oct 2003 16:17:01 -0000 1.5.6.1
+++ UnsupportedElement.java 22 Oct 2003 20:45:14 -0000 1.5.6.2
@@ -64,6 +64,11 @@
import java.util.Vector;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.INVOKESTATIC;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.PUSH;
+
import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
@@ -73,14 +78,16 @@
final class UnsupportedElement extends SyntaxTreeNode {
- private Fallback _fallback = null;
+ private Vector _fallbacks = null;
private ErrorMsg _message = null;
+ private boolean _isExtension = false;
/**
* Basic consutrcor - stores element uri/prefix/localname
*/
- public UnsupportedElement(String uri, String prefix, String local) {
+ public UnsupportedElement(String uri, String prefix, String local,
boolean isExtension) {
super(uri, prefix, local);
+ _isExtension = isExtension;
}
/**
@@ -108,56 +115,74 @@
/**
- * Scan all descendants and find the first xsl:fallback element (if any)
+ * Scan and process all fallback children of the unsupported element.
*/
- private SyntaxTreeNode findFallback(SyntaxTreeNode root) {
-
- // First check if this element exists at all
- if (root == null) return null;
+ private void processFallbacks(Parser parser) {
- // Then check if the element is an xsl:fallback element
- if (root instanceof Fallback) return((Fallback)root);
-
- // Then traverse all child elements
- Vector children = root.getContents();
+ Vector children = getContents();
if (children != null) {
final int count = children.size();
for (int i = 0; i < count; i++) {
SyntaxTreeNode child = (SyntaxTreeNode)children.elementAt(i);
- SyntaxTreeNode node = findFallback(child);
- if (node != null) return node;
+ if (child instanceof Fallback) {
+ Fallback fallback = (Fallback)child;
+ fallback.activate();
+ fallback.parseContents(parser);
+ if (_fallbacks == null) {
+ _fallbacks = new Vector();
+ }
+ _fallbacks.addElement(child);
+ }
}
}
- return null;
}
/**
* Find any fallback in the descendant nodes; then activate & parse it
*/
public void parseContents(Parser parser) {
- _fallback = (Fallback)findFallback(this);
- if (_fallback != null) {
- _fallback.activate();
- _fallback.parseContents(parser);
- }
+ processFallbacks(parser);
}
/**
* Run type check on the fallback element (if any).
*/
- public Type typeCheck(SymbolTable stable) throws TypeCheckError {
- if (_fallback != null) {
- _fallback.typeCheck(stable);
- }
- return Type.Void;
+ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+ if (_fallbacks != null) {
+ int count = _fallbacks.size();
+ for (int i = 0; i < count; i++) {
+ Fallback fallback = (Fallback)_fallbacks.elementAt(i);
+ fallback.typeCheck(stable);
+ }
+ }
+ return Type.Void;
}
/**
- * Translate the fallback element (if any). The stylesheet should never
- * be compiled if an unsupported element does not have a fallback
element,
- * so this method should never be called unless _fallback != null
+ * Translate the fallback element (if any).
*/
public void translate(ClassGenerator classGen, MethodGenerator
methodGen) {
- if (_fallback != null) _fallback.translate(classGen, methodGen);
+ if (_fallbacks != null) {
+ int count = _fallbacks.size();
+ for (int i = 0; i < count; i++) {
+ Fallback fallback = (Fallback)_fallbacks.elementAt(i);
+ fallback.translate(classGen, methodGen);
+ }
+ }
+ // We only go into the else block in forward-compatibility mode, when
+ // the unsupported element has no fallback.
+ else {
+ // If the unsupported element does not have any fallback child, then
+ // at runtime, a runtime error should be raised when the unsupported
+ // element is instantiated. Otherwise, no error is thrown.
+ ConstantPoolGen cpg = classGen.getConstantPool();
+ InstructionList il = methodGen.getInstructionList();
+
+ final int unsupportedElem = cpg.addMethodref(BASIS_LIBRARY_CLASS,
"unsupported_ElementF",
+ "(" + STRING_SIG +
"Z)V");
+ il.append(new PUSH(cpg, getQName().toString()));
+ il.append(new PUSH(cpg, _isExtension));
+ il.append(new INVOKESTATIC(unsupportedElem));
+ }
}
}
No revision
No revision
1.61.4.1 +19 -1
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java
Index: BasisLibrary.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java,v
retrieving revision 1.61
retrieving revision 1.61.4.1
diff -u -r1.61 -r1.61.4.1
--- BasisLibrary.java 1 Apr 2003 21:28:38 -0000 1.61
+++ BasisLibrary.java 22 Oct 2003 20:45:14 -0000 1.61.4.1
@@ -438,6 +438,20 @@
}
/**
+ * Utility function to throw a runtime error for an unsupported element.
+ *
+ * This is only used in forward-compatibility mode, when the control flow
+ * cannot be determined. In 1.0 mode, the error message is emitted at
+ * compile time.
+ */
+ public static void unsupported_ElementF(String qname, boolean
isExtension) {
+ if (isExtension)
+ runTimeError(UNSUPPORTED_EXT_ERR, qname);
+ else
+ runTimeError(UNSUPPORTED_XSL_ERR, qname);
+ }
+
+ /**
* XSLT Standard function namespace-uri(node-set).
*/
public static String namespace_uriF(DTMAxisIterator iter, DOM dom) {
@@ -1352,6 +1366,10 @@
"NAMESPACES_SUPPORT_ERR";
public static final String CANT_RESOLVE_RELATIVE_URI_ERR =
"CANT_RESOLVE_RELATIVE_URI_ERR";
+ public static final String UNSUPPORTED_XSL_ERR =
+ "UNSUPPORTED_XSL_ERR";
+ public static final String UNSUPPORTED_EXT_ERR =
+ "UNSUPPORTED_EXT_ERR";
// All error messages are localized and are stored in resource bundles.
protected static ResourceBundle m_bundle;
1.6.6.1 +20 -2
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/ErrorMessages.java
Index: ErrorMessages.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/ErrorMessages.java,v
retrieving revision 1.6
retrieving revision 1.6.6.1
diff -u -r1.6 -r1.6.6.1
--- ErrorMessages.java 19 Mar 2003 22:14:10 -0000 1.6
+++ ErrorMessages.java 22 Oct 2003 20:45:14 -0000 1.6.6.1
@@ -256,7 +256,25 @@
* error.
*/
{BasisLibrary.CANT_RESOLVE_RELATIVE_URI_ERR,
- "Could not resolve the URI reference ''{0}''."}
+ "Could not resolve the URI reference ''{0}''."},
+
+ /*
+ * Note to translators: The stylesheet contained an element that was
+ * not recognized as part of the XSL syntax. The substitution text
+ * gives the element name.
+ */
+ {BasisLibrary.UNSUPPORTED_XSL_ERR,
+ "Unsupported XSL element ''{0}''"},
+
+ /*
+ * Note to translators: The stylesheet referred to an extension to
the
+ * XSL syntax and indicated that it was defined by XSLTC, but XSTLC
does
+ * not recognized the particular extension named. The substitution
text
+ * gives the extension name.
+ */
+ {BasisLibrary.UNSUPPORTED_EXT_ERR,
+ "Unrecognised XSLTC extension ''{0}''"}
+
};
public Object[][] getContents() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]