/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file and, per its terms, should not be removed:
*
* Copyright (c) 2004 World Wide Web Consortium,
*
* (Massachusetts Institute of Technology, European Research Consortium for
* Informatics and Mathematics, Keio University). All Rights Reserved. This
* work is distributed under the W3C(r) Software License [1] in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
/**
* A factory that enables applications to obtain instances of
* <code>DOMImplementation</code>.
*
* <p>
* Example:
* </p>
*
* <pre class='example'>
* // get an instance of the DOMImplementation registry
* DOMImplementationRegistry registry =
* DOMImplementationRegistry.newInstance();
* // get a DOM implementation the Level 3 XML module
* DOMImplementation domImpl =
* registry.getDOMImplementation("XML 3.0");
* </pre>
*
* <p>
* This provides an application with an implementation-independent starting
* point. DOM implementations may modify this class to meet new security
* standards or to provide *additional* fallbacks for the list of
* DOMImplementationSources.
* </p>
*
* @see DOMImplementation
* @see DOMImplementationSource
* @since DOM Level 3
*/
public final class DOMImplementationRegistry {
/**
* The system property to specify the
* DOMImplementationSource class names.
*/
"org.w3c.dom.DOMImplementationSourceList";
/**
* Default columns per line.
*/
/**
* The list of DOMImplementationSources.
*/
/**
* Default class name.
*/
"com.sun.org.apache.xerces.internal.dom.DOMXSImplementationSourceImpl";
"com.sun.org.apache.xerces.internal.dom";
/**
* Private constructor.
* @param srcs Vector List of DOMImplementationSources
*/
}
/**
* Obtain a new instance of a <code>DOMImplementationRegistry</code>.
*
* The <code>DOMImplementationRegistry</code> is initialized by the
* application or the implementation, depending on the context, by
* first checking the value of the Java system property
* <code>org.w3c.dom.DOMImplementationSourceList</code> and
* the service provider whose contents are at
* "<code>META_INF/services/org.w3c.dom.DOMImplementationSourceList</code>".
* The value of this property is a white-space separated list of
* names of availables classes implementing the
* <code>DOMImplementationSource</code> interface. Each class listed
* in the class name list is instantiated and any exceptions
* encountered are thrown to the application.
*
* @return an initialized instance of DOMImplementationRegistry
* @throws ClassNotFoundException
* If any specified class can not be found
* @throws InstantiationException
* If any specified class is an interface or abstract class
* @throws IllegalAccessException
* If the default constructor of a specified class is not accessible
* @throws ClassCastException
* If any specified class does not implement
* <code>DOMImplementationSource</code>
*/
throws
// fetch system property:
//
// if property is not specified then use contents of
// META_INF/org.w3c.dom.DOMImplementationSourceList from classpath
if (p == null) {
p = getServiceValue(classLoader);
}
if (p == null) {
//
// DOM Implementations can modify here to add *additional* fallback
// mechanisms to access a list of default DOMImplementationSources.
//fall back to JAXP implementation class com.sun.org.apache.xerces.internal.dom.DOMXSImplementationSourceImpl
p = FALLBACK_CLASS;
}
if (p != null) {
while (st.hasMoreTokens()) {
// make sure we have access to restricted packages
boolean internal = false;
internal = true;
}
}
} else {
}
}
}
return new DOMImplementationRegistry(sources);
}
/**
* Return the first implementation that has the desired
* features, or <code>null</code> if none is found.
*
* @param features
* A string that specifies which features are required. This is
* a space separated list in which each feature is specified by
* its name optionally followed by a space and a version number.
* This is something like: "XML 1.0 Traversal +Events 2.0"
* @return An implementation that has the desired features,
* or <code>null</code> if none found.
*/
for (int i = 0; i < size; i++) {
return impl;
}
}
return null;
}
/**
* Return a list of implementations that support the
* desired features.
*
* @param features
* A string that specifies which features are required. This is
* a space separated list in which each feature is specified by
* its name optionally followed by a space and a version number.
* This is something like: "XML 1.0 Traversal +Events 2.0"
* @return A list of DOMImplementations that support the desired features.
*/
for (int i = 0; i < size; i++) {
}
}
return new DOMImplementationList() {
try {
return (DOMImplementation)
} catch (ArrayIndexOutOfBoundsException e) {
return null;
}
}
return null;
}
public int getLength() {
return implementations.size();
}
};
}
/**
* Register an implementation.
*
* @param s The source to be registered, may not be <code>null</code>
*/
if (s == null) {
throw new NullPointerException();
}
sources.addElement(s);
}
}
/**
*
* Gets a class loader.
*
* @return A class loader, possibly <code>null</code>
*/
try {
if (contextClassLoader != null) {
return contextClassLoader;
}
} catch (Exception e) {
// Assume that the DOM application is in a JRE 1.1, use the
// current ClassLoader
return DOMImplementationRegistry.class.getClassLoader();
}
return DOMImplementationRegistry.class.getClassLoader();
}
/**
* This method attempts to return the first line of the resource
* from the provided ClassLoader.
*
* @param classLoader classLoader, may not be <code>null</code>.
* @return first line of resource, or <code>null</code>
*/
// try to find services in CLASSPATH
try {
try {
rd =
rd =
}
return serviceValue;
}
}
return null;
}
return null;
}
/**
* A simple JRE (Java Runtime Environment) 1.1 test
*
* @return <code>true</code> if JRE 1.1
*/
private static boolean isJRE11() {
try {
// java.security.AccessController existed since 1.2 so, if no
// exception was thrown, the DOM application is running in a JRE
// 1.2 or higher
return false;
// ignore
}
return true;
}
/**
* This method returns the ContextClassLoader or <code>null</code> if
* running in a JRE 1.1
*
* @return The Context Classloader
*/
return isJRE11()
? null
: (ClassLoader)
try {
} catch (SecurityException ex) {
}
return classLoader;
}
});
}
/**
* This method returns the system property indicated by the specified name
* after checking access control privileges. For a JRE 1.1, this check is
* not done.
*
* @param name the name of the system property
* @return the system property
*/
return isJRE11()
}
});
}
/**
* This method returns an Inputstream for the reading resource
* META_INF/services/org.w3c.dom.DOMImplementationSourceList after checking
* access control privileges. For a JRE 1.1, this check is not done.
*
* @param classLoader classLoader
* @param name the resource
* @return an Inputstream for the resource specified
*/
if (isJRE11()) {
if (classLoader == null) {
} else {
}
return ris;
} else {
return (InputStream)
if (classLoader == null) {
ris =
} else {
}
return ris;
}
});
}
}
}