ilene 2003/01/09 12:48:25
Modified: java/src/org/apache/xml/utils Tag: xslt20 URI.java
SystemIDResolver.java
java/src/org/apache/xalan/processor Tag: xslt20
ProcessorInclude.java TransformerFactoryImpl.java
java/src/org/apache/xalan/serialize Tag: xslt20
SerializerToXML.java
Log:
Migrating patches for bugzilla #10519, 13651, 13977.
TestID #impincl27 now works on the xslt20 branch.
Revision Changes Path
No revision
No revision
1.7.2.1.2.1 +6 -9 xml-xalan/java/src/org/apache/xml/utils/URI.java
Index: URI.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/URI.java,v
retrieving revision 1.7.2.1
retrieving revision 1.7.2.1.2.1
diff -u -r1.7.2.1 -r1.7.2.1.2.1
--- URI.java 14 Aug 2002 19:45:36 -0000 1.7.2.1
+++ URI.java 9 Jan 2003 20:48:24 -0000 1.7.2.1.2.1
@@ -59,8 +59,8 @@
import java.io.IOException;
import java.io.Serializable;
-import org.apache.xalan.res.XSLTErrorResources;
import org.apache.xalan.res.XSLMessages;
+import org.apache.xalan.res.XSLTErrorResources;
/**
* A class to represent a Uniform Resource Identifier (URI). This class
@@ -422,7 +422,8 @@
int index = 0;
// check for scheme
- if (uriSpec.indexOf(':') == -1)
+ int colonIndex = uriSpec.indexOf(':');
+ if (colonIndex < 0)
{
if (p_base == null)
{
@@ -432,8 +433,8 @@
else
{
initializeScheme(uriSpec);
-
- index = m_scheme.length() + 1;
+ uriSpec = uriSpec.substring(colonIndex+1);
+ uriSpecLen = uriSpec.length();
}
// two slashes means generic URI syntax, so we get the authority
@@ -509,10 +510,6 @@
if (m_scheme == null)
{
m_scheme = p_base.getScheme();
- }
- else
- {
- return;
}
// check for authority - RFC 2396 5.2 #4
1.16.2.1.2.1 +177 -154
xml-xalan/java/src/org/apache/xml/utils/SystemIDResolver.java
Index: SystemIDResolver.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/utils/SystemIDResolver.java,v
retrieving revision 1.16.2.1
retrieving revision 1.16.2.1.2.1
diff -u -r1.16.2.1 -r1.16.2.1.2.1
--- SystemIDResolver.java 14 Aug 2002 19:45:36 -0000 1.16.2.1
+++ SystemIDResolver.java 9 Jan 2003 20:48:24 -0000 1.16.2.1.2.1
@@ -57,7 +57,6 @@
package org.apache.xml.utils;
import javax.xml.transform.TransformerException;
-
import org.apache.xml.utils.URI;
import org.apache.xml.utils.URI.MalformedURIException;
@@ -78,196 +77,220 @@
{
/**
- * Get absolute URI from a given relative URI.
+ * Get an absolute URI from a given relative URI (local path).
*
- * <p>The URI is resolved relative to the system property "user.dir"
- * if it is available; if not (i.e. in an Applet perhaps which
- * throws SecurityException) then it is currently resolved
- * relative to "" or a blank string. Also replaces all
- * backslashes with forward slashes.</p>
+ * <p>The relative URI is a local filesystem path. The path can be
+ * absolute or relative. If it is a relative path, it is resolved relative
+ * to the system property "user.dir" if it is available; if not (i.e. in
an
+ * Applet perhaps which throws SecurityException) then we just return the
+ * relative path. The space and backslash characters are also replaced to
+ * generate a good absolute URI.</p>
*
- * @param uri Relative URI to resolve
+ * @param localPath The relative URI to resolve
*
- * @return Resolved absolute URI or the input relative URI if
- * it could not be resolved.
+ * @return Resolved absolute URI
*/
- public static String getAbsoluteURIFromRelative(String uri)
+ public static String getAbsoluteURIFromRelative(String localPath)
{
-
- String curdir = "";
- try {
- curdir = System.getProperty("user.dir");
+ if (localPath == null || localPath.length() == 0)
+ return "";
+
+ // If the local path is a relative path, then it is resolved against
+ // the "user.dir" system property.
+ String absolutePath = localPath;
+ if (!isAbsolutePath(localPath))
+ {
+ try
+ {
+ absolutePath = getAbsolutePathFromRelativePath(localPath);
+ }
+ // user.dir not accessible from applet
+ catch (SecurityException se)
+ {
+ return "file:" + localPath;
+ }
}
- catch (SecurityException se) {}// user.dir not accessible from applet
- if (null != curdir)
+ String urlString;
+ if (null != absolutePath)
{
- String base;
- if (curdir.startsWith(File.separator))
- base = "file://" + curdir;
+ if (absolutePath.startsWith(File.separator))
+ urlString = "file://" + absolutePath;
else
- base = "file:///" + curdir;
-
- if (uri != null)
- // Note: this should arguably stick in a '/' forward
- // slash character instead of the file separator,
- // since we're effectively assuming it's a hierarchical
- // URI and adding in the abs_path separator -sc
- uri = base + System.getProperty("file.separator") + uri;
- else
- uri = base + System.getProperty("file.separator");
+ urlString = "file:///" + absolutePath;
}
-
- if (null != uri && (uri.indexOf('\\') > -1))
- uri = uri.replace('\\', '/');
-
- return uri;
+ else
+ urlString = "file:" + localPath;
+
+ return replaceChars(urlString);
}
/**
- * Take a SystemID string and try and turn it into a good absolute URL.
+ * Return an absolute path from a relative path.
*
- * @param urlString url A URL string, which may be relative or absolute.
+ * @param relativePath A relative path
+ * @return The absolute path
+ */
+ private static String getAbsolutePathFromRelativePath(String relativePath)
+ {
+ return new File(relativePath).getAbsolutePath();
+ }
+
+ /**
+ * Return true if the systemId denotes an absolute URI (contains the
scheme part).
*
- * @return The resolved absolute URI
- * @throws TransformerException thrown if the string can't be turned into
a URL.
+ * @param systemId The systemId string
+ * @return true if the systemId contains a scheme part
*/
- public static String getAbsoluteURI(String url)
- throws TransformerException
+ public static boolean isAbsoluteURI(String systemId)
{
- if (url.startsWith(".."))
- url = new File(url).getAbsolutePath();
-
- if (url.startsWith(File.separator))
- {
- // If the url starts with a path separator, we assume it's
- // a reference to a file: scheme (why do we do this? -sc)
- url = "file://" + url;
- }
- else if (url.indexOf(':') < 0)
- {
- // If the url does not have a colon: character (which
- // separates the scheme part from the rest) then it
- // must be a relative one, so go get an absolute one -sc
- url = getAbsoluteURIFromRelative(url);
- }
-
- // Bugzilla#5701: the below else if is incorrect, if you read
- // section 5.2 of RFC 2396. If the url did start with file:,
- // it implies we should assume it's absolute and be done
- // with resolving. Note that I'm not even sure why we put
- // in the second check for '/' anyways -sc
- //else if (url.startsWith("file:") && url.charAt(5) != '/')
- //{
- // url = getAbsoluteURIFromRelative(url.substring(5));
- //}
- // Bugzilla#5701 comment out code end
-
- return url;
+ // If there is more than one character before the ':' character,
+ // then it is considered to be an absolute URI; otherwise it is a local
path.
+ int colonIndex = systemId.indexOf(':');
+ if (colonIndex > 1)
+ return true;
+ else
+ return false;
}
-
-
+
/**
- * Take a SystemID string and try and turn it into a good absolute URL.
+ * Return true if the local path is an absolute path.
*
- * @param urlString SystemID string
- * @param base Base URI to use to resolve the given systemID
+ * @param systemId The path string
+ * @return true if the path is absolute
+ */
+ public static boolean isAbsolutePath(String systemId)
+ {
+ // On Unix, an absolute path starts with '/'.
+ if (systemId.startsWith(File.separator))
+ return true;
+
+ // On Windows, an absolute path starts with "[drive_letter]:\".
+ if (systemId.length() > 2
+ && systemId.charAt(1) == ':'
+ && Character.isLetter(systemId.charAt(0))
+ && (systemId.charAt(2) == '\\' || systemId.charAt(2) == '/'))
+ return true;
+ else
+ return false;
+ }
+
+ /**
+ * Replace spaces with "%20" and backslashes with forward slashes in
+ * the input string to generate a well-formed URI string.
*
- * @return The resolved absolute URI
- * @throws TransformerException thrown if the string can't be turned into
a URL.
+ * @param str The input string
+ * @return The string after conversion
*/
- public static String getAbsoluteURI(String urlString, String base)
- throws TransformerException
+ private static String replaceChars(String str)
{
- boolean isAbsouteUrl = false;
- boolean needToResolve = false;
-
- // Bugzilla#5701: the below if is incorrect, if you read
- // section 5.2 of RFC 2396. If the url did start with file:,
- // it implies we should assume it's absolute and be done
- // with resolving. Note that I'm not even sure why we put
- // in the second check for '/' anyways -sc
- //if(urlString.startsWith("file:") && urlString.charAt(5) != '/')
- //{
- // needToResolve = true;
- //}
- //else if (urlString.indexOf(':') > 0)
- // Bugzilla#5701 comment out code end
- if (urlString.indexOf(':') > 0)
- {
- // If there is a colon to separate the scheme from the rest,
- // it should be an absolute URL
- isAbsouteUrl = true;
- }
- else if (urlString.startsWith(File.separator))
- {
- // If the url starts with a path separator, we assume it's
- // a reference to a file: scheme (why do we do this? -sc)
- urlString = "file://" + urlString;
- isAbsouteUrl = true;
- }
-
- if ((!isAbsouteUrl) && ((null == base)
- || (base.indexOf(':') < 0)))
- {
- if (base != null && base.startsWith(File.separator))
- base = "file://" + base;
- else
- base = getAbsoluteURIFromRelative(base);
- }
-
- // bit of a hack here. Need to talk to URI person to see if this can be
fixed.
- if ((null != base) && needToResolve)
-
- {
- if(base.equals(urlString))
+ StringBuffer buf = new StringBuffer(str);
+ int length = buf.length();
+ for (int i = 0; i < length; i++)
+ {
+ char currentChar = buf.charAt(i);
+ // Replace space with "%20"
+ if (currentChar == ' ')
{
- base = "";
+ buf.setCharAt(i, '%');
+ buf.insert(i+1, "20");
+ length = length + 2;
+ i = i + 2;
}
- else
+ // Replace backslash with forward slash
+ else if (currentChar == '\\')
{
- urlString = urlString.substring(5);
- isAbsouteUrl = false;
+ buf.setCharAt(i, '/');
}
- }
-
- // This is probably a bad idea, we should at least check for quotes...
- if (null != base && (base.indexOf('\\') > -1))
- base = base.replace('\\', '/');
-
- if (null != urlString && (urlString.indexOf('\\') > -1))
- urlString = urlString.replace('\\', '/');
-
- URI uri;
-
- try
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ * Take a SystemID string and try to turn it into a good absolute URI.
+ *
+ * @param systemId A URI string, which may be absolute or relative.
+ *
+ * @return The resolved absolute URI
+ */
+ public static String getAbsoluteURI(String systemId)
+ {
+ String absoluteURI = systemId;
+ if (isAbsoluteURI(systemId))
{
- if ((null == base) || (base.length() == 0) || (isAbsouteUrl))
+ // Only process the systemId if it starts with "file:".
+ if (systemId.startsWith("file:"))
{
- uri = new URI(urlString);
+ String str = systemId.substring(5);
+
+ // Resolve the absolute path if the systemId starts with "file:///"
+ // or "file:/". Don't do anything if it only starts with "file://".
+ if (str != null && str.startsWith("/"))
+ {
+ if (str.startsWith("///") || !str.startsWith("//"))
+ {
+ // A Windows path containing a drive letter can be relative.
+ // A Unix path starting with "file:/" is always absolute.
+ int secondColonIndex = systemId.indexOf(':', 5);
+ if (secondColonIndex > 0)
+ {
+ String localPath = systemId.substring(secondColonIndex-1);
+ try {
+ if (!isAbsolutePath(localPath))
+ absoluteURI = systemId.substring(0, secondColonIndex-1) +
+ getAbsolutePathFromRelativePath(localPath);
+ }
+ catch (SecurityException se) {
+ return systemId;
+ }
+ }
+ }
+ }
+ else
+ {
+ return getAbsoluteURIFromRelative(systemId.substring(5));
+ }
+
+ return replaceChars(absoluteURI);
}
else
- {
- URI baseURI = new URI(base);
+ return systemId;
+ }
+ else
+ return getAbsoluteURIFromRelative(systemId);
+
+ }
- uri = new URI(baseURI, urlString);
- }
+
+ /**
+ * Take a SystemID string and try to turn it into a good absolute URI.
+ *
+ * @param urlString SystemID string
+ * @param base The URI string used as the base for resolving the systemID
+ *
+ * @return The resolved absolute URI
+ * @throws TransformerException thrown if the string can't be turned into
a URI.
+ */
+ public static String getAbsoluteURI(String urlString, String base)
+ throws TransformerException
+ {
+ if (base == null)
+ return getAbsoluteURI(urlString);
+
+ String absoluteBase = getAbsoluteURI(base);
+ URI uri = null;
+ try
+ {
+ URI baseURI = new URI(absoluteBase);
+ uri = new URI(baseURI, urlString);
}
catch (MalformedURIException mue)
{
throw new TransformerException(mue);
}
-
- String uriStr = uri.toString();
- // Not so sure if this is good. But, for now, I'll try it. We really
must
- // make sure the return from this function is a URL!
- if((Character.isLetter(uriStr.charAt(0)) && (uriStr.charAt(1) == ':')
- && (uriStr.charAt(2) == '/') && (uriStr.charAt(3) != '/'))
- || ((uriStr.charAt(0) == '/') && (uriStr.charAt(1) != '/')))
- {
- uriStr = "file:///"+uriStr;
- }
- return uriStr;
+ return replaceChars(uri.toString());
}
+
}
No revision
No revision
1.21.2.1.2.1 +19 -21
xml-xalan/java/src/org/apache/xalan/processor/ProcessorInclude.java
Index: ProcessorInclude.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorInclude.java,v
retrieving revision 1.21.2.1
retrieving revision 1.21.2.1.2.1
diff -u -r1.21.2.1 -r1.21.2.1.2.1
--- ProcessorInclude.java 14 Aug 2002 19:21:26 -0000 1.21.2.1
+++ ProcessorInclude.java 9 Jan 2003 20:48:25 -0000 1.21.2.1.2.1
@@ -56,34 +56,24 @@
*/
package org.apache.xalan.processor;
-import org.apache.xml.utils.TreeWalker;
-import org.apache.xalan.templates.Stylesheet;
-import org.apache.xalan.res.XSLMessages;
-import org.apache.xalan.res.XSLTErrorResources;
-
-import javax.xml.transform.TransformerException;
-import org.xml.sax.Attributes;
-import org.xml.sax.XMLReader;
-import org.xml.sax.InputSource;
-import org.xml.sax.EntityResolver;
-
-import java.net.URL;
-
import java.io.IOException;
-import org.xml.sax.helpers.XMLReaderFactory;
-
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
-import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
-import javax.xml.transform.Source;
-import javax.xml.transform.TransformerException;
-
-import org.w3c.dom.Node;
+import org.apache.xalan.res.XSLMessages;
+import org.apache.xalan.res.XSLTErrorResources;
import org.apache.xml.utils.SystemIDResolver;
+import org.apache.xml.utils.TreeWalker;
+import org.w3c.dom.Node;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
/**
* TransformerFactory class for xsl:include markup.
@@ -238,7 +228,15 @@
if (null != source && source instanceof DOMSource)
{
Node node = ((DOMSource)source).getNode();
- TreeWalker walker = new TreeWalker(handler, new
org.apache.xpath.DOM2Helper(), source.getSystemId());
+ String systemId = source.getSystemId();
+ if (systemId == null)
+ {
+ systemId = SystemIDResolver.getAbsoluteURI(getHref(),
+ handler.getBaseIdentifier());
+
+ }
+
+ TreeWalker walker = new TreeWalker(handler, new
org.apache.xpath.DOM2Helper(), systemId);
try
{
1.42.4.3 +2 -8
xml-xalan/java/src/org/apache/xalan/processor/TransformerFactoryImpl.java
Index: TransformerFactoryImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/processor/TransformerFactoryImpl.java,v
retrieving revision 1.42.4.2
retrieving revision 1.42.4.3
diff -u -r1.42.4.2 -r1.42.4.3
--- TransformerFactoryImpl.java 10 Dec 2002 18:27:47 -0000 1.42.4.2
+++ TransformerFactoryImpl.java 9 Jan 2003 20:48:25 -0000 1.42.4.3
@@ -884,14 +884,7 @@
}
else
{
- try
- {
- baseID = SystemIDResolver.getAbsoluteURI(baseID);
- }
- catch (TransformerException te)
- {
- throw new TransformerConfigurationException(te);
- }
+ baseID = SystemIDResolver.getAbsoluteURI(baseID);
}
if (source instanceof DOMSource)
@@ -916,6 +909,7 @@
try
{
InputSource isource = SAXSource.sourceToInputSource(source);
+ isource.setSystemId(baseID);
XMLReader reader = null;
if (source instanceof SAXSource)
No revision
No revision
1.16.2.1.2.2 +17 -39
xml-xalan/java/src/org/apache/xalan/serialize/SerializerToXML.java
Index: SerializerToXML.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/SerializerToXML.java,v
retrieving revision 1.16.2.1.2.1
retrieving revision 1.16.2.1.2.2
diff -u -r1.16.2.1.2.1 -r1.16.2.1.2.2
--- SerializerToXML.java 19 Dec 2002 19:03:34 -0000 1.16.2.1.2.1
+++ SerializerToXML.java 9 Jan 2003 20:48:25 -0000 1.16.2.1.2.2
@@ -56,39 +56,33 @@
*/
package org.apache.xalan.serialize;
-import java.io.Writer;
+import java.io.IOException;
import java.io.OutputStream;
-import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
-import java.io.IOException;
-
-import java.util.Enumeration;
-import java.util.Stack;
-import java.util.Vector;
+import java.io.Writer;
+import java.util.BitSet;
import java.util.Hashtable;
import java.util.Properties;
-import java.util.BitSet;
-
-import org.xml.sax.*;
-import org.xml.sax.ext.LexicalHandler;
-import org.xml.sax.ext.DeclHandler;
+import java.util.Vector;
-import org.w3c.dom.Node;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
-import org.apache.xalan.serialize.Serializer;
-import org.apache.xalan.serialize.DOMSerializer;
-import org.apache.xml.utils.QName;
+import org.apache.xalan.res.XSLMessages;
import org.apache.xalan.templates.OutputProperties;
import org.apache.xml.utils.BoolStack;
+import org.apache.xml.utils.QName;
+import org.apache.xml.utils.SystemIDResolver;
import org.apache.xml.utils.TreeWalker;
import org.apache.xml.utils.WrappedRuntimeException;
-import org.apache.xml.utils.SystemIDResolver;
-import org.apache.xalan.res.XSLTErrorResources;
-import org.apache.xalan.res.XSLMessages;
import org.apache.xpath.res.XPATHErrorResources;
-
-import javax.xml.transform.Result;
-import javax.xml.transform.OutputKeys;
+import org.w3c.dom.Node;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.DeclHandler;
+import org.xml.sax.ext.LexicalHandler;
/**
* <meta name="usage" content="general"/>
@@ -441,8 +435,6 @@
if (null != entitiesFileName)
{
- try
- {
m_charInfo = null;
if (null == m_charInfos)
@@ -474,26 +466,12 @@
{
String absoluteEntitiesFileName;
- if (entitiesFileName.indexOf(':') < 0)
- {
- absoluteEntitiesFileName =
- SystemIDResolver.getAbsoluteURIFromRelative(entitiesFileName);
- }
- else
- {
- absoluteEntitiesFileName =
- SystemIDResolver.getAbsoluteURI(entitiesFileName, null);
- }
+ absoluteEntitiesFileName =
SystemIDResolver.getAbsoluteURI(entitiesFileName);
m_charInfo = new CharInfo(absoluteEntitiesFileName);
m_charInfos.put(entitiesFileName, m_charInfo);
}
- }
- catch (javax.xml.transform.TransformerException te)
- {
- throw new org.apache.xml.utils.WrappedRuntimeException(te);
- }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]