public InputSource resolveEntity(
final String publicId,
final String systemId)
throws SAXException, IOException
{
InputSource source = null;
if (this.xmlResource != null)
{
String path = systemId;
if (path != null && path.startsWith(SYSTEM_ID_FILE))
{
final String xmlResource = this.xmlResource.toString();
path = path.replaceFirst(
SYSTEM_ID_FILE,
"");
// - remove any extra starting slashes
path = ResourceUtils.normalizePath(path);
// - if we still have one starting slash, remove it
if (path.startsWith("/"))
{
path = path.substring(
1,
path.length());
}
final String xmlResourceName = xmlResource.replaceAll(
".*(\\+|/)",
"");
URL uri = null;
InputStream inputStream = null;
try
{
uri = ResourceUtils.toURL(StringUtils.replace(
xmlResource,
xmlResourceName,
path));
if (uri != null)
{
inputStream = uri.openStream();
}
}
catch (final IOException exception)
{
// - ignore
}
if (inputStream == null)
{
try
{
uri = ResourceUtils.getResource(path);
if (uri != null)
{
inputStream = uri.openStream();
}
}
catch (final IOException exception)
{
// - ignore
}
}
if (inputStream != null)
{
source = new InputSource(inputStream);
source.setPublicId(publicId);
source.setSystemId(uri.toString());
}
}
}
return source;
}