|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
package javax.xml.catalog; |
|
|
|
import java.io.File; |
|
import java.io.IOException; |
|
import java.net.MalformedURLException; |
|
import java.net.URI; |
|
import java.util.Iterator; |
|
import java.util.jar.JarEntry; |
|
import java.util.jar.JarFile; |
|
import static javax.xml.catalog.CatalogFeatures.DEFER_FALSE; |
|
import static javax.xml.catalog.CatalogFeatures.DEFER_TRUE; |
|
import javax.xml.catalog.CatalogFeatures.Feature; |
|
import static javax.xml.catalog.CatalogFeatures.PREFER_PUBLIC; |
|
import static javax.xml.catalog.CatalogFeatures.PREFER_SYSTEM; |
|
import static javax.xml.catalog.CatalogFeatures.RESOLVE_CONTINUE; |
|
import static javax.xml.catalog.CatalogFeatures.RESOLVE_IGNORE; |
|
import static javax.xml.catalog.CatalogFeatures.RESOLVE_STRICT; |
|
import jdk.xml.internal.SecuritySupport; |
|
|
|
|
|
|
|
|
|
*/ |
|
class Util { |
|
|
|
final static String URN = "urn:publicid:"; |
|
final static String PUBLICID_PREFIX = "-//"; |
|
final static String PUBLICID_PREFIX_ALT = "+//"; |
|
final static String SCHEME_FILE = "file"; |
|
final static String SCHEME_JAR = "jar"; |
|
final static String SCHEME_JARFILE = "jar:file:"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static String resolve(CatalogImpl catalog, String publicId, String systemId) { |
|
String resolvedSystemId = null; |
|
|
|
|
|
catalog.reset(); |
|
if (systemId != null) { |
|
|
|
|
|
|
|
*/ |
|
resolvedSystemId = catalog.matchSystem(systemId); |
|
} |
|
|
|
if (resolvedSystemId == null && publicId != null) { |
|
resolvedSystemId = catalog.matchPublic(publicId); |
|
} |
|
|
|
if (resolvedSystemId == null && systemId != null) { |
|
resolvedSystemId = catalog.matchURI(systemId); |
|
} |
|
|
|
|
|
catalog.markAsSearched(); |
|
|
|
|
|
if (resolvedSystemId == null) { |
|
Iterator<Catalog> iter = catalog.catalogs().iterator(); |
|
while (iter.hasNext()) { |
|
resolvedSystemId = resolve((CatalogImpl) iter.next(), publicId, systemId); |
|
if (resolvedSystemId != null) { |
|
break; |
|
} |
|
|
|
} |
|
} |
|
|
|
return resolvedSystemId; |
|
} |
|
|
|
static void validateUrisSyntax(URI... uris) { |
|
for (URI uri : uris) { |
|
validateUriSyntax(uri); |
|
} |
|
} |
|
|
|
static void validateUrisSyntax(String... uris) { |
|
for (String uri : uris) { |
|
validateUriSyntax(URI.create(uri)); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static void validateUriSyntax(URI uri) { |
|
CatalogMessages.reportNPEOnNull("URI input", uri); |
|
|
|
if (!uri.isAbsolute()) { |
|
CatalogMessages.reportIAE(CatalogMessages.ERR_URI_NOTABSOLUTE, |
|
new Object[]{uri}, null); |
|
} |
|
|
|
try { |
|
|
|
uri.toURL(); |
|
} catch (MalformedURLException ex) { |
|
CatalogMessages.reportIAE(CatalogMessages.ERR_URI_NOTVALIDURL, |
|
new Object[]{uri}, null); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static boolean isFileUri(URI uri) { |
|
if (SCHEME_FILE.equals(uri.getScheme()) |
|
|| SCHEME_JAR.equals(uri.getScheme())) { |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static boolean isFileUriExist(URI uri, boolean openJarFile) { |
|
if (uri != null && uri.isAbsolute()) { |
|
if (null != uri.getScheme()) { |
|
switch (uri.getScheme()) { |
|
case SCHEME_FILE: |
|
String path = uri.getPath(); |
|
File f1 = new File(path); |
|
if (f1.isFile()) { |
|
return true; |
|
} |
|
break; |
|
case SCHEME_JAR: |
|
String tempUri = uri.toString(); |
|
int pos = tempUri.indexOf("!"); |
|
if (pos < 0) { |
|
return false; |
|
} |
|
if (openJarFile) { |
|
String jarFile = tempUri.substring(SCHEME_JARFILE.length(), pos); |
|
String entryName = tempUri.substring(pos + 2); |
|
try { |
|
JarFile jf = new JarFile(jarFile); |
|
JarEntry je = jf.getJarEntry(entryName); |
|
if (je != null) { |
|
return true; |
|
} |
|
} catch (IOException ex) { |
|
return false; |
|
} |
|
} else { |
|
return true; |
|
} |
|
break; |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static String[] getCatalogFiles(String sysPropertyName) { |
|
String value = SecuritySupport.getJAXPSystemProperty(sysPropertyName); |
|
if (value != null && !value.equals("")) { |
|
return value.split(";"); |
|
} |
|
return null; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static String getNotNullOrEmpty(String test) { |
|
if (test == null) { |
|
return test; |
|
} else { |
|
String temp = test.trim(); |
|
if (temp.length() == 0) { |
|
return null; |
|
} else { |
|
return temp; |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
static void validateFeatureInput(Feature f, String value) { |
|
CatalogMessages.reportNPEOnNull(f.name(), value); |
|
if (value.length() == 0) { |
|
CatalogMessages.reportIAE(CatalogMessages.ERR_INVALID_ARGUMENT, |
|
new Object[]{value, f.name()}, null); |
|
} |
|
|
|
if (f == Feature.PREFER) { |
|
if (!value.equals(PREFER_SYSTEM) && !value.equals(PREFER_PUBLIC)) { |
|
CatalogMessages.reportIAE(CatalogMessages.ERR_INVALID_ARGUMENT, |
|
new Object[]{value, Feature.PREFER.name()}, null); |
|
} |
|
} else if (f == Feature.DEFER) { |
|
if (!value.equals(DEFER_TRUE) && !value.equals(DEFER_FALSE)) { |
|
CatalogMessages.reportIAE(CatalogMessages.ERR_INVALID_ARGUMENT, |
|
new Object[]{value, Feature.DEFER.name()}, null); |
|
} |
|
} else if (f == Feature.RESOLVE) { |
|
if (!value.equals(RESOLVE_STRICT) && !value.equals(RESOLVE_CONTINUE) |
|
&& !value.equals(RESOLVE_IGNORE)) { |
|
CatalogMessages.reportIAE(CatalogMessages.ERR_INVALID_ARGUMENT, |
|
new Object[]{value, Feature.RESOLVE.name()}, null); |
|
} |
|
} else if (f == Feature.FILES) { |
|
Util.validateUrisSyntax(value.split(";")); |
|
} |
|
} |
|
} |