santiagopg    2003/10/17 09:14:20

  Modified:    java/src/org/apache/xalan/xsltc/compiler Import.java
                        Include.java Stylesheet.java
               java/src/org/apache/xalan/xsltc/dom SAXImpl.java
  Log:
  Replace ad-hoc code to resolve relative URIs by calls to the 
xml.utils.SystemIDResolver class. This change fixes a few a regressions and 
also simplifies the code in XSLTC.
  
  Revision  Changes    Path
  1.23      +6 -22     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Import.java
  
  Index: Import.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Import.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Import.java       6 Oct 2003 18:25:57 -0000       1.22
  +++ Import.java       17 Oct 2003 16:14:19 -0000      1.23
  @@ -70,6 +70,7 @@
   import java.net.MalformedURLException;
   import java.util.Enumeration;
   
  +import org.apache.xml.utils.SystemIDResolver;
   import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
   import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
   import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
  @@ -100,21 +101,10 @@
                return;
            }
   
  -         String currLoadedDoc = context.getSystemId();
  -         SourceLoader loader = context.getSourceLoader();
            InputSource input = null;
            XMLReader reader = null;
  -
  -            // Initialize currLoadedDocURL using currLoadedDoc
  -            URL docToLoadURL = null, currLoadedDocURL = null;      
  -            if (currLoadedDoc != null && currLoadedDoc.length() > 0) {
  -                try {
  -                    currLoadedDocURL = new URL(currLoadedDoc);
  -                }
  -                catch (MalformedURLException e) {
  -                    // ignore
  -                }
  -            }
  +         String currLoadedDoc = context.getSystemId();
  +         SourceLoader loader = context.getSourceLoader();
               
               // Use SourceLoader if available
            if (loader != null) {
  @@ -127,14 +117,8 @@
   
               // No SourceLoader or not resolved by SourceLoader
               if (input == null) {
  -                docToLoadURL = (currLoadedDocURL != null) ?
  -                    new URL(currLoadedDocURL, docToLoad) :
  -                    new URL("file", "", System.getProperty("user.dir")
  -                            + System.getProperty("file.separator")
  -                            + docToLoad);
  -                
  -             docToLoad = docToLoadURL.toString();
  -             input = new InputSource(docToLoad);
  +                docToLoad = SystemIDResolver.getAbsoluteURI(docToLoad, 
currLoadedDoc);
  +                input = new InputSource(docToLoad);
            }
   
            // Return if we could not resolve the URL
  
  
  
  1.27      +5 -29     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Include.java
  
  Index: Include.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Include.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- Include.java      6 Oct 2003 18:25:57 -0000       1.26
  +++ Include.java      17 Oct 2003 16:14:19 -0000      1.27
  @@ -70,6 +70,7 @@
   import java.net.URL;
   import java.util.Enumeration;
   
  +import org.apache.xml.utils.SystemIDResolver;
   import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
   import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
   import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
  @@ -104,17 +105,6 @@
            XMLReader reader = null;
            String currLoadedDoc = context.getSystemId();
            SourceLoader loader = context.getSourceLoader();
  -
  -            // Initialize currLoadedDocURL using currLoadedDoc
  -            URL docToLoadURL = null, currLoadedDocURL = null;      
  -            if (currLoadedDoc != null && currLoadedDoc.length() > 0) {
  -                try {
  -                    currLoadedDocURL = new URL(currLoadedDoc);
  -                }
  -                catch (MalformedURLException e) {
  -                    // ignore
  -                }
  -            }
               
               // Use SourceLoader if available
            if (loader != null) {
  @@ -127,14 +117,8 @@
   
               // No SourceLoader or not resolved by SourceLoader
               if (input == null) {
  -                docToLoadURL = (currLoadedDocURL != null) ?
  -                    new URL(currLoadedDocURL, docToLoad) :
  -                    new URL("file", "", System.getProperty("user.dir")
  -                            + System.getProperty("file.separator")
  -                            + docToLoad);
  -                
  -             docToLoad = docToLoadURL.toString();
  -             input = new InputSource(docToLoad);
  +                docToLoad = SystemIDResolver.getAbsoluteURI(docToLoad, 
currLoadedDoc);
  +                input = new InputSource(docToLoad);
            }
   
            // Return if we could not resolve the URL
  @@ -158,7 +142,7 @@
            if (_included == null) return;
   
            _included.setSourceLoader(loader);
  -         _included.setSystemId(docToLoadURL.toString());
  +         _included.setSystemId(docToLoad);
            _included.setParentStylesheet(context);
            _included.setIncludingStylesheet(context);
            _included.setTemplateInlining(context.getTemplateInlining());
  @@ -186,14 +170,6 @@
                    }
                }
            }
  -     }
  -     catch (MalformedURLException e) {
  -         // Update systemId in parent stylesheet for error reporting
  -         context.setSystemId(getAttribute("href"));
  -
  -         final ErrorMsg msg = 
  -             new ErrorMsg(ErrorMsg.FILE_NOT_FOUND_ERR, docToLoad, this);
  -         parser.reportError(Constants.FATAL, msg);
        }
        catch (Exception e) {
            e.printStackTrace();
  
  
  
  1.56      +4 -30     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java
  
  Index: Stylesheet.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Stylesheet.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- Stylesheet.java   6 Oct 2003 18:18:57 -0000       1.55
  +++ Stylesheet.java   17 Oct 2003 16:14:19 -0000      1.56
  @@ -74,6 +74,7 @@
   import java.util.Properties;
   import java.util.StringTokenizer;
   
  +import org.apache.xml.utils.SystemIDResolver;
   import org.apache.bcel.generic.ANEWARRAY;
   import org.apache.bcel.generic.ConstantPoolGen;
   import org.apache.bcel.generic.FieldGen;
  @@ -415,35 +416,8 @@
       }
   
       public void setSystemId(String systemId) {
  -        URL systemIdURL = null; 
  -        
  -        if (systemId != null && systemId.length() > 0) {
  -            try {
  -                systemIdURL = new URL(systemId);
  -            }
  -            catch (MalformedURLException e) {
  -                String userDir = System.getProperty("user.dir");
  -                String fileSep = System.getProperty("file.separator");
  -                
  -                // Make it absolute if a relative path (drive letters?)
  -                if (!systemId.startsWith(fileSep)) {
  -                    systemId = userDir + fileSep + systemId;
  -                }
  -                try {
  -                    systemIdURL = new URL("file", "", systemId);
  -                }
  -                catch (MalformedURLException ep) {
  -                    try {
  -                        systemIdURL = new URL("file", "", userDir + fileSep);
  -                    }
  -                    catch (MalformedURLException epp) {
  -                        // ignore
  -                    }
  -                }
  -            }
  -        }
  -        if (systemIdURL != null) {
  -            _systemId = systemIdURL.toString();
  +        if (systemId != null) {
  +            _systemId = SystemIDResolver.getAbsoluteURI(systemId);
           }
       }
       
  
  
  
  1.12      +3 -32     
xml-xalan/java/src/org/apache/xalan/xsltc/dom/SAXImpl.java
  
  Index: SAXImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/SAXImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SAXImpl.java      15 Oct 2003 17:49:38 -0000      1.11
  +++ SAXImpl.java      17 Oct 2003 16:14:19 -0000      1.12
  @@ -89,6 +89,7 @@
   import org.apache.xml.serializer.SerializationHandler;
   import org.apache.xml.serializer.ToXMLSAXHandler;
   import org.apache.xml.utils.XMLStringFactory;
  +import org.apache.xml.utils.SystemIDResolver;
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
   import org.w3c.dom.Document;
  @@ -189,37 +190,7 @@
        * Define the origin of the document from which the tree was built
        */
       public void setDocumentURI(String uri) {
  -        URL documentURI = null; 
  -        
  -        if (uri != null && uri.length() > 0) {
  -            try {
  -                documentURI = new URL(uri);
  -            }
  -            catch (MalformedURLException e) {
  -                String userDir = System.getProperty("user.dir");
  -                String fileSep = System.getProperty("file.separator");
  -                
  -                // Make it absolute if a relative path
  -                if (!uri.startsWith(fileSep)) {
  -                    uri = userDir + fileSep + uri;
  -                }
  -                try {
  -                    documentURI = new URL("file", "", uri);
  -                }
  -                catch (MalformedURLException ep) {
  -                    try {
  -                        documentURI = new URL("file", "", userDir + fileSep);
  -                    }
  -                    catch (MalformedURLException epp) {
  -                        // ignore
  -                    }
  -                }
  -            }
  -        }
  -        if (documentURI != null) {       
  -            _documentURI = documentURI.toString();
  -            setDocumentBaseURI(_documentURI);
  -        }
  +        setDocumentBaseURI(SystemIDResolver.getAbsoluteURI(uri));
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to