xml-xalan-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mk...@apache.org
Subject cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/runtime BasisLibrary.java ErrorMessages.java
Date Wed, 22 Oct 2003 20:23:48 GMT
mkwan       2003/10/22 13:23:48

  Modified:    java/src/org/apache/xalan/xsltc/compiler Parser.java
                        UnsupportedElement.java
               java/src/org/apache/xalan/xsltc/runtime BasisLibrary.java
                        ErrorMessages.java
  Log:
  Apply Joanne Tong (joannet@ca.ibm.com) patch for bugzilla 23706,
  with my own modifications. I also fixed bug 23896 in the same
  patch.
  
  This patch includes the fixes for the following:
  1. an unsupported XSL element will trigger a syntax error in 1.0 mode.
  2. In forward-compatibility mode, if an unsupported XSL element is in
  a template, has no fallback, it will trigger a runtime error if it is
  instantiated.
  3. All fallback children are called in sequence. The old code only makes
  use of the first fallback child.
  4. Only direct fallback children are processed. The old code finds the fallback
  from all descendants of an unsupported element, which is wrong behavior
  according to the spec.
  
  Revision  Changes    Path
  1.62      +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.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- Parser.java	16 Oct 2003 16:15:03 -0000	1.61
  +++ Parser.java	22 Oct 2003 20:23:48 -0000	1.62
  @@ -973,17 +973,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);
  @@ -994,7 +995,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.7       +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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- UnsupportedElement.java	16 Oct 2003 16:15:03 -0000	1.6
  +++ UnsupportedElement.java	22 Oct 2003 20:23:48 -0000	1.7
  @@ -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));		
  +	}
       }
   }
  
  
  
  1.62      +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.62
  diff -u -r1.61 -r1.62
  --- BasisLibrary.java	1 Apr 2003 21:28:38 -0000	1.61
  +++ BasisLibrary.java	22 Oct 2003 20:23:48 -0000	1.62
  @@ -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.7       +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.7
  diff -u -r1.6 -r1.7
  --- ErrorMessages.java	19 Mar 2003 22:14:10 -0000	1.6
  +++ ErrorMessages.java	22 Oct 2003 20:23:48 -0000	1.7
  @@ -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: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org


Mime
View raw message