< prev index next >
src/java.xml/share/classes/javax/xml/parsers/DocumentBuilderFactory.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 37,47 ****
*
* @since 1.4
*/
public abstract class DocumentBuilderFactory {
!
private boolean validating = false;
private boolean namespaceAware = false;
private boolean whitespace = false;
private boolean expandEntityRef = true;
private boolean ignoreComments = false;
--- 37,48 ----
*
* @since 1.4
*/
public abstract class DocumentBuilderFactory {
! private static final String DEFAULT_IMPL =
! "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
private boolean validating = false;
private boolean namespaceAware = false;
private boolean whitespace = false;
private boolean expandEntityRef = true;
private boolean ignoreComments = false;
*** 53,62 ****
--- 54,133 ----
*/
protected DocumentBuilderFactory () {
}
/**
+ * Creates a new NamespaceAware instance of the {@code DocumentBuilderFactory}
+ * builtin system-default implementation. Parsers produced by the factory
+ * instance provides support for XML namespaces by default.
+ *
+ * @implSpec
+ * In addition to creating a factory instance using the same process as
+ * {@link #newDefaultInstance()}, this method must set NamespaceAware to true.
+ *
+ * @return a new instance of the {@code DocumentBuilderFactory} builtin
+ * system-default implementation.
+ *
+ * @since 13
+ */
+ public static DocumentBuilderFactory newDefaultNSInstance() {
+ return makeNSAware(new DocumentBuilderFactoryImpl());
+ }
+
+ /**
+ * Creates a new NamespaceAware instance of a {@code DocumentBuilderFactory}.
+ * Parsers produced by the factory instance provides support for XML namespaces
+ * by default.
+ *
+ * @implSpec
+ * In addition to creating a factory instance using the same process as
+ * {@link #newInstance()}, this method must set NamespaceAware to true.
+ *
+ * @return a new instance of a {@code DocumentBuilderFactory}
+ *
+ * @throws FactoryConfigurationError in case of {@linkplain
+ * java.util.ServiceConfigurationError service configuration error}
+ * or if the implementation is not available or cannot be instantiated.
+ *
+ * @since 13
+ */
+ public static DocumentBuilderFactory newNSInstance() {
+ return makeNSAware(FactoryFinder.find(DocumentBuilderFactory.class, DEFAULT_IMPL));
+ }
+
+ /**
+ * Creates a new NamespaceAware instance of a {@code DocumentBuilderFactory}
+ * from the class name. Parsers produced by the factory instance provides
+ * support for XML namespaces by default.
+ *
+ * @implSpec
+ * In addition to creating a factory instance using the same process as
+ * {@link #newInstance(java.lang.String, java.lang.ClassLoader)}, this method
+ * must set NamespaceAware to true.
+ *
+ * @param factoryClassName a fully qualified factory class name that provides
+ * implementation of
+ * {@code javax.xml.parsers.DocumentBuilderFactory}.
+ *
+ * @param classLoader the {@code ClassLoader} used to load the factory class.
+ * If it is {@code null}, the current {@code Thread}'s
+ * context classLoader is used to load the factory class.
+ *
+ * @return a new instance of a {@code DocumentBuilderFactory}
+ *
+ * @throws FactoryConfigurationError if {@code factoryClassName} is {@code null}, or
+ * the factory class cannot be loaded, instantiated.
+ *
+ * @since 13
+ */
+ public static DocumentBuilderFactory newNSInstance(String factoryClassName,
+ ClassLoader classLoader) {
+ return makeNSAware(FactoryFinder.newInstance(
+ DocumentBuilderFactory.class, factoryClassName, classLoader, false));
+ }
+
+ /**
* Creates a new instance of the {@code DocumentBuilderFactory} builtin
* system-default implementation.
*
* @return A new instance of the {@code DocumentBuilderFactory} builtin
* system-default implementation.
*** 139,149 ****
public static DocumentBuilderFactory newInstance() {
return FactoryFinder.find(
/* The default property name according to the JAXP spec */
DocumentBuilderFactory.class, // "javax.xml.parsers.DocumentBuilderFactory"
/* The fallback implementation class name */
! "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
}
/**
* Obtain a new instance of a {@code DocumentBuilderFactory} from class name.
* This function is useful when there are multiple providers in the classpath.
--- 210,220 ----
public static DocumentBuilderFactory newInstance() {
return FactoryFinder.find(
/* The default property name according to the JAXP spec */
DocumentBuilderFactory.class, // "javax.xml.parsers.DocumentBuilderFactory"
/* The fallback implementation class name */
! DEFAULT_IMPL);
}
/**
* Obtain a new instance of a {@code DocumentBuilderFactory} from class name.
* This function is useful when there are multiple providers in the classpath.
*** 183,192 ****
--- 254,268 ----
//do not fallback if given classloader can't find the class, throw exception
return FactoryFinder.newInstance(DocumentBuilderFactory.class,
factoryClassName, classLoader, false);
}
+ private static DocumentBuilderFactory makeNSAware(DocumentBuilderFactory dbf) {
+ dbf.setNamespaceAware(true);
+ return dbf;
+ }
+
/**
* Creates a new instance of a {@link javax.xml.parsers.DocumentBuilder}
* using the currently configured parameters.
*
* @return A new instance of a DocumentBuilder.
< prev index next >