/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SystemIDResolver.java,v 1.2.4.1 2005/09/15 08:15:58 suresh_emailid Exp $
*/
/**
* This class is used to resolve relative URIs and SystemID
* strings into absolute URIs.
*
* <p>This is a generic utility for resolving URIs, other than the
* fact that it's declared to throw TransformerException. Please
* see code comments for details on how resolution is performed.</p>
* @xsl.usage internal
*/
public class SystemIDResolver
{
/**
* Get an absolute URI from a given relative URI (local path).
*
* <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 localPath The relative URI to resolve
*
* @return Resolved absolute URI
*/
{
return "";
// If the local path is a relative path, then it is resolved against
// the "user.dir" system property.
if (!isAbsolutePath(localPath))
{
try
{
}
// user.dir not accessible from applet
catch (SecurityException se)
{
return "file:" + localPath;
}
}
if (null != absolutePath)
{
else
}
else
return replaceChars(urlString);
}
/**
* Return an absolute path from a relative path.
*
* @param relativePath A relative path
* @return The absolute path
*/
{
}
/**
* Return true if the systemId denotes an absolute URI .
*
* @param systemId The systemId string
* @return true if the systemId is an an absolute URI
*/
{
* Authors should be aware that a path segment which contains a colon
* character cannot be used as the first segment of a relative URI path
* (e.g., "this:that"), because it would be mistaken for a scheme name.
**/
/**
* %REVIEW% Can we assume here that systemId is a valid URI?
* It looks like we cannot ( See discussion of this common problem in
* Bugzilla Bug 22777 ).
**/
//"fix" for Bugzilla Bug 22777
return false;
}
//finding substring before '#', '?', and '/'
if(fragmentIndex > 0)
index = queryIndex;
index = slashIndex;
// return true if there is ':' before '#', '?', and '/'
}
/**
* Return true if the local path is an absolute path.
*
* @param systemId The path string
* @return true if the path is absolute
*/
{
return false;
return file.isAbsolute();
}
/**
* Return true if the local path is a Windows absolute path.
*
* @param systemId The path string
* @return true if the path is a Windows absolute path
*/
{
if(!isAbsolutePath(systemId))
return false;
// On Windows, an absolute path starts with "[drive_letter]:\".
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.
*
* @param str The input string
* @return The string after conversion
*/
{
for (int i = 0; i < length; i++)
{
// Replace space with "%20"
if (currentChar == ' ')
{
i = i + 2;
}
// Replace backslash with forward slash
else if (currentChar == '\\')
{
}
}
}
/**
* 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
*/
{
if (isAbsoluteURI(systemId))
{
// Only process the systemId if it starts with "file:".
{
// Resolve the absolute path if the systemId starts with "file:///"
// or "file:/". Don't do anything if it only starts with "file://".
{
{
// A Windows path containing a drive letter can be relative.
// A Unix path starting with "file:/" is always absolute.
if (secondColonIndex > 0)
{
try {
if (!isAbsolutePath(localPath))
}
catch (SecurityException se) {
return systemId;
}
}
}
}
else
{
}
return replaceChars(absoluteURI);
}
else
return systemId;
}
else
return getAbsoluteURIFromRelative(systemId);
}
/**
* 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.
*/
throws TransformerException
{
return getAbsoluteURI(urlString);
try
{
}
catch (MalformedURIException mue)
{
throw new TransformerException(mue);
}
}
}