You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mo...@apache.org on 2001/08/03 13:55:26 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/dom LoadDocument.java

morten      01/08/03 04:55:26

  Modified:    java/src/org/apache/xalan/xsltc/compiler Constants.java
                        DocumentCall.java
               java/src/org/apache/xalan/xsltc/dom LoadDocument.java
  Log:
  Fix for the document() function. The code compiled by DocumentCall now
  passes the context URI to the LoadDocument.document() method, and the
  document() method resolves the base/new URIs and constructs an absolute
  path/URI to the document to load.
  PR:		bugzilla 2832
  Obtained from:	n/a
  Submitted by:	morten@xml.apache.org
  Reviewed by:	morten@xml.apache.org
  
  Revision  Changes    Path
  1.10      +4 -1      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Constants.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Constants.java	2001/08/01 11:52:58	1.9
  +++ Constants.java	2001/08/03 11:55:25	1.10
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Constants.java,v 1.9 2001/08/01 11:52:58 morten Exp $
  + * @(#)$Id: Constants.java,v 1.10 2001/08/03 11:55:25 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -245,6 +245,9 @@
   	= "(I)Lorg/w3c/dom/NodeList;";
       public static final String MAKE_NODE_LIST_SIG2 
   	= "(" + NODE_ITERATOR_SIG + ")Lorg/w3c/dom/NodeList;";
  +
  +    public static final String LOAD_DOCUMENT_CLASS
  +	= "org.apache.xalan.xsltc.dom.LoadDocument";
   
       public static final String KEY_INDEX_CLASS
   	= "org/apache/xalan/xsltc/dom/KeyIndex";
  
  
  
  1.6       +22 -13    xml-xalan/java/src/org/apache/xalan/xsltc/compiler/DocumentCall.java
  
  Index: DocumentCall.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/DocumentCall.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DocumentCall.java	2001/07/19 18:48:31	1.5
  +++ DocumentCall.java	2001/08/03 11:55:25	1.6
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: DocumentCall.java,v 1.5 2001/07/19 18:48:31 morten Exp $
  + * @(#)$Id: DocumentCall.java,v 1.6 2001/08/03 11:55:25 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -146,30 +146,39 @@
   					     DOM_FIELD,
   					     classGen.getDOMClassSig());
   
  -	final int doc = cpg.addMethodref("org.apache.xalan.xsltc.dom.LoadDocument",
  -					 "document",
  -					 "("+
  -					 OBJECT_SIG+
  -					 NODE_ITERATOR_SIG+
  -					 TRANSLET_SIG+
  -					 MULTI_DOM_SIG+
  -					 ")"+NODE_ITERATOR_SIG);
  +	final String docParamList =
  +	    "("+OBJECT_SIG+STRING_SIG+TRANSLET_SIG+MULTI_DOM_SIG+")"+
  +	    NODE_ITERATOR_SIG;
  +	final int docIdx = cpg.addMethodref(LOAD_DOCUMENT_CLASS,
  +					    "document", docParamList);
  +
  +	final int uriIdx = cpg.addMethodref(DOM_CLASS,
  +					    "getNodeURI",
  +					    "(I)"+STRING_SIG);
   
  +	final int nextIdx = cpg.addInterfaceMethodref(NODE_ITERATOR,
  +						      NEXT, NEXT_SIG);
  +
   	// The URI can be either a node-set or something else cast to a string
   	_uri.translate(classGen, methodGen);
   	if (_uriType == Type.NodeSet)
   	    _uri.startResetIterator(classGen, methodGen);
   
   	// The base of the URI may be given as a second argument (a node-set)
  -	if (_base == null)
  -	    il.append(new ACONST_NULL());
  -	else
  +	il.append(methodGen.loadDOM());
  +	if (_base != null) {
   	    _base.translate(classGen, methodGen);
  +	    il.append(new INVOKEINTERFACE(nextIdx, 2));
  +	}
  +	else {
  +	     il.append(methodGen.loadContextNode());
  +	}
  +	il.append(new INVOKEVIRTUAL(uriIdx));
   
   	// Feck the rest of the parameters on the stack
   	il.append(classGen.loadTranslet());
   	il.append(DUP);
   	il.append(new GETFIELD(domField));
  -	il.append(new INVOKESTATIC(doc));
  +	il.append(new INVOKESTATIC(docIdx));
       }
   }
  
  
  
  1.4       +20 -24    xml-xalan/java/src/org/apache/xalan/xsltc/dom/LoadDocument.java
  
  Index: LoadDocument.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/LoadDocument.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LoadDocument.java	2001/07/19 13:16:17	1.3
  +++ LoadDocument.java	2001/08/03 11:55:26	1.4
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: LoadDocument.java,v 1.3 2001/07/19 13:16:17 morten Exp $
  + * @(#)$Id: LoadDocument.java,v 1.4 2001/08/03 11:55:26 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -91,21 +91,26 @@
   					MultiDOM multiplexer)
   	throws Exception {
   
  -	// Check if this is a local file name
  -	final File file = new File(uri);
  -	if (file.exists())
  -	    uri = "file:" + file.getAbsolutePath();
  -	
   	// Return an empty iterator if the URI is clearly invalid
   	// (to prevent some unncessary MalformedURL exceptions).
   	if ((uri == null) || (uri.equals("")))
   	    return(new SingletonIterator(DOM.NULL,true));
   
  +	// Prepend URI base to URI (from context)
   	if ((base != null) && (!base.equals(""))) {
  -	    if (!uri.startsWith(base))
  +	    if ((!uri.startsWith(base)) &&     // unless URI contains base
  +		(!uri.startsWith("/")) &&      // unless URI is abs. file path
  +		(!uri.startsWith("http:/")) && // unless URI is abs. http URL
  +		(!uri.startsWith("file:/"))) { // unless URI is abs. file URL
   		uri = base+uri;
  +	    }
   	}
   
  +	// Check if this is a local file name
  +	final File file = new File(uri);
  +	if (file.exists())
  +	    uri = "file:" + file.getAbsolutePath();
  +	
   	// Check if this DOM has already been added to the multiplexer
   	int mask = multiplexer.getDocumentMask(uri);
   	if (mask != -1) {
  @@ -159,12 +164,11 @@
   
       /**
        * Interprets the arguments passed from the document() function (see
  -     * org/apache/xalan/xsltc/compiler/DocumentCall.java) and returns an iterator
  -     * containing the requested nodes. Builds a union-iterator if several
  -     * documents are requested.
  +     * org/apache/xalan/xsltc/compiler/DocumentCall.java) and returns an
  +     * iterator containing the requested nodes. Builds a union-iterator if
  +     * several documents are requested.
        */
  -    public static NodeIterator document(Object arg,
  -					NodeIterator nodeset,
  +    public static NodeIterator document(Object arg, String contextURI,
   					AbstractTranslet translet,
   					MultiDOM multiplexer)
   	throws TransletException {
  @@ -172,18 +176,10 @@
   
   	    String baseURI = "";
   
  -	    // Get the base of the URI (if any)
  -	    if (nodeset != null) {
  -		final int node = nodeset.next();
  -		if (node != DOM.NULL) {
  -		    baseURI = multiplexer.getNodeURI(node);
  -		    if (baseURI == null) baseURI = "";
  -		    final int sep = baseURI.lastIndexOf('/');
  -		    if (sep > 0)
  -			baseURI = baseURI.substring(0,sep);
  -		    else
  -			baseURI = "";
  -		}
  +	    // Get the base of the conext URI (if any)
  +	    if (contextURI != null) {
  +		final int sep = contextURI.lastIndexOf('/') + 1;
  +		baseURI = contextURI.substring(0, sep); // could be empty string
   	    }
   
   	    // If the argument is just a single string (an URI) we just return
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org