sboag 00/06/24 11:38:57
Modified: java/src/org/apache/xalan/xpath SourceTreeManager.java
Log:
Use SystemIDResolver instead of duplicated code.
Revision Changes Path
1.2 +10 -295
xml-xalan/java/src/org/apache/xalan/xpath/SourceTreeManager.java
Index: SourceTreeManager.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xpath/SourceTreeManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SourceTreeManager.java 2000/06/19 16:53:22 1.1
+++ SourceTreeManager.java 2000/06/24 18:38:56 1.2
@@ -56,7 +56,6 @@
*/
package org.apache.xalan.xpath;
-import java.net.URL;
import java.net.MalformedURLException;
import java.io.File;
import java.io.IOException;
@@ -73,6 +72,7 @@
import org.apache.xalan.res.XSLMessages;
import org.apache.xalan.xpath.res.XPATHErrorResources;
import org.apache.xalan.stree.SourceTreeHandler;
+import org.apache.xalan.utils.SystemIDResolver;
/**
* This class bottlenecks all management of source trees. The methods
@@ -91,7 +91,7 @@
* the association based on the root of the tree that the
* node is parented by.
*/
- public void associateXLocatorToNode(Node node, URL url, XLocator xlocator)
+ public void associateXLocatorToNode(Node node, String url, XLocator
xlocator)
{
Node root = node.getOwnerDocument();
if(null == root)
@@ -148,7 +148,7 @@
Node root = owner.getOwnerDocument();
if(null == root)
root = owner;
- URL url = null;
+ String url = null;
int n = m_size;
for(int i = 0; i < n; i++)
{
@@ -159,14 +159,14 @@
break;
}
}
- return url.toExternalForm();
+ return url;
}
/**
* Given a document, find the URL associated with that document.
* @param owner Document that was previously processed by this liaison.
*/
- public Node findNodeFromURL(URL url)
+ public Node findNodeFromURL(String url)
{
Node node = null;
int n = m_size;
@@ -183,26 +183,6 @@
}
/**
- * Given a document, find the URL associated with that document.
- * @param owner Document that was previously processed by this liaison.
- */
- public Node findNodeFromURL(String url)
- {
- Node node = null;
- int n = m_size;
- for(int i = 0; i < n; i++)
- {
- SourceTree ass = m_sourceTree[i];
- if(url == ass.m_url.toExternalForm())
- {
- node = ass.m_root;
- break;
- }
- }
- return node;
- }
-
- /**
* Return a string suitible for telling the user what parser is being used.
*/
public String getParserDescription()
@@ -222,283 +202,18 @@
public InputSource resolveURI (String base, String urlString)
throws TransformException, IOException
{
- String origURLString = urlString;
- String origBase = base;
-
- // System.out.println("getURLFromString - urlString: "+urlString+",
base: "+base);
- Object doc;
- URL url = null;
- int fileStartType = 0;
+ String uri;
try
{
-
- if(null != base)
- {
- if(base.toLowerCase().startsWith("file:/"))
- {
- fileStartType = 1;
- }
- else if(base.toLowerCase().startsWith("file:"))
- {
- fileStartType = 2;
- }
- }
-
- boolean isAbsoluteURL;
-
- // From http://www.ics.uci.edu/pub/ietf/uri/rfc1630.txt
- // A partial form can be distinguished from an absolute form in that
the
- // latter must have a colon and that colon must occur before any slash
- // characters. Systems not requiring partial forms should not use any
- // unencoded slashes in their naming schemes. If they do, absolute
URIs
- // will still work, but confusion may result.
- int indexOfColon = urlString.indexOf(':');
- int indexOfSlash = urlString.indexOf('/');
- if((indexOfColon != -1) && (indexOfSlash != -1) && (indexOfColon <
indexOfSlash))
- {
- // The url (or filename, for that matter) is absolute.
- isAbsoluteURL = true;
- }
- else
- {
- isAbsoluteURL = false;
- }
-
- if(isAbsoluteURL || (null == base) || (base.length() == 0))
- {
- try
- {
- url = new URL(urlString);
- }
- catch (MalformedURLException e) {}
- }
- // The Java URL handling doesn't seem to handle relative file names.
- else if(!((urlString.charAt(0) == '.') || (fileStartType > 0)))
- {
- try
- {
- URL baseUrl = new URL(base);
- url = new URL(baseUrl, urlString);
- }
- catch (MalformedURLException e)
- {
- }
- }
-
- if(null == url)
- {
- // Then we're going to try and make a file URL below, so strip
- // off the protocol header.
- if(urlString.toLowerCase().startsWith("file:/"))
- {
- urlString = urlString.substring(6);
- }
- else if(urlString.toLowerCase().startsWith("file:"))
- {
- urlString = urlString.substring(5);
- }
- }
-
- if((null == url) && ((null == base) || (fileStartType > 0)))
- {
- if(1 == fileStartType)
- {
- if(null != base)
- base = base.substring(6);
- fileStartType = 1;
- }
- else if(2 == fileStartType)
- {
- if(null != base)
- base = base.substring(5);
- fileStartType = 2;
- }
-
- File f = new File(urlString);
-
- if(!f.isAbsolute() && (null != base))
- {
- // String dir = f.isDirectory() ? f.getAbsolutePath() :
f.getParent();
- // System.out.println("prebuiltUrlString (1): "+base);
- StringTokenizer tokenizer = new StringTokenizer(base, "\\/");
- String fixedBase = null;
- while(tokenizer.hasMoreTokens())
- {
- String token = tokenizer.nextToken();
- if (null == fixedBase)
- {
- // Thanks to Rick Maddy for the bug fix for UNIX here.
- if (base.charAt(0) == '\\' || base.charAt(0) == '/')
- {
- fixedBase = File.separator + token;
- }
- else
- {
- fixedBase = token;
- }
- }
- else
- {
- fixedBase+= File.separator + token;
- }
- }
- // System.out.println("rebuiltUrlString (1): "+fixedBase);
- f = new File(fixedBase);
- String dir = f.isDirectory() ? f.getAbsolutePath() : f.getParent();
- // System.out.println("dir: "+dir);
- // System.out.println("urlString: "+urlString);
- // f = new File(dir, urlString);
- // System.out.println("f (1): "+f.toString());
- // urlString = f.getAbsolutePath();
- f = new File(urlString);
- boolean isAbsolute = f.isAbsolute()
- || (urlString.charAt( 0 ) == '\\')
- || (urlString.charAt( 0 ) == '/');
- if(!isAbsolute)
- {
- // Getting more and more ugly...
- if(dir.charAt( dir.length()-1 ) != File.separator.charAt(0) &&
- urlString.charAt( 0 ) != File.separator.charAt(0))
- {
- urlString = dir + File.separator + urlString;
- }
- else
- {
- urlString = dir + urlString;
- }
-
- // System.out.println("prebuiltUrlString (2): "+urlString);
- tokenizer = new StringTokenizer(urlString, "\\/");
- String rebuiltUrlString = null;
- while(tokenizer.hasMoreTokens())
- {
- String token = tokenizer.nextToken();
- if (null == rebuiltUrlString)
- {
- // Thanks to Rick Maddy for the bug fix for UNIX here.
- if (urlString.charAt(0) == '\\' || urlString.charAt(0) ==
'/')
- {
- rebuiltUrlString = File.separator + token;
- }
- else
- {
- rebuiltUrlString = token;
- }
- }
- else
- {
- rebuiltUrlString+= File.separator + token;
- }
- }
- // System.out.println("rebuiltUrlString (2): "+rebuiltUrlString);
- if(null != rebuiltUrlString)
- urlString = rebuiltUrlString;
- }
- // System.out.println("fileStartType: "+fileStartType);
- if(1 == fileStartType)
- {
- if (urlString.charAt(0) == '/')
- {
- urlString = "file://"+urlString;
- }
- else
- {
- urlString = "file:/"+urlString;
- }
- }
- else if(2 == fileStartType)
- {
- urlString = "file:"+urlString;
- }
- try
- {
- // System.out.println("Final before try: "+urlString);
- url = new URL(urlString);
- }
- catch (MalformedURLException e)
- {
- // System.out.println("Error trying to make URL from
"+urlString);
- }
- }
- }
- if(null == url)
- {
- // The sun java VM doesn't do this correctly, but I'll
- // try it here as a second-to-last resort.
- if((null != origBase) && (origBase.length() > 0))
- {
- try
- {
- URL baseURL = new URL(origBase);
- // System.out.println("Trying to make URL from "+origBase+" and
"+origURLString);
- url = new URL(baseURL, origURLString);
- // System.out.println("Success! New URL is: "+url.toString());
- }
- catch (MalformedURLException e)
- {
- // System.out.println("Error trying to make URL from
"+origBase+" and "+origURLString);
- }
- }
-
- if(null == url)
- {
- try
- {
- String lastPart;
- if(null != origBase)
- {
- File baseFile = new File(origBase);
- if(baseFile.isDirectory())
- {
- lastPart = new File(baseFile, urlString).getAbsolutePath ();
- }
- else
- {
- String parentDir = baseFile.getParent();
- lastPart = new File(parentDir, urlString).getAbsolutePath ();
- }
- }
- else
- {
- lastPart = new File (urlString).getAbsolutePath ();
- }
- // Hack
- // if((lastPart.charAt(0) == '/') && (lastPart.charAt(2) == ':'))
- // lastPart = lastPart.substring(1, lastPart.length() - 1);
-
- String fullpath;
- if (lastPart.charAt(0) == '\\' || lastPart.charAt(0) == '/')
- {
- fullpath = "file://" + lastPart;
- }
- else
- {
- fullpath = "file:" + lastPart;
- }
- url = new URL(fullpath);
- }
- catch (MalformedURLException e2)
- {
- throw new TransformException(
XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_CREATE_URL, new
Object[]{urlString}),e2); //"Cannot create url for: " + urlString, e2 );
- }
- }
- }
+ uri = SystemIDResolver.getAbsoluteURI(base, urlString);
}
- catch(SecurityException se)
+ catch(SAXException se)
{
- try
- {
- url = new
URL("http://xml.apache.org/xslt/"+java.lang.Math.random()); // dummy
- }
- catch (MalformedURLException e2)
- {
- // I give up
- }
+ throw new TransformException(se);
}
-
InputSource source = new InputSource();
- source.setSystemId(url.toExternalForm());
+ source.setSystemId(uri);
return source;
}