From 65dfc5202d9fa7c5931c0b0be5cb38337eefe017 Mon Sep 17 00:00:00 2001
From: "Yuan.Wang" <1536296691@qq.com>
Date: Tue, 23 May 2023 17:31:35 +0800
Subject: [PATCH 1/5] =?UTF-8?q?REPORT-95576=20spring=20framework=20?=
=?UTF-8?q?=E9=AB=98=E5=8D=B1=E6=BC=8F=E6=B4=9E=EF=BC=8C=E9=9C=80=E8=A6=81?=
=?UTF-8?q?=E5=88=A0=E9=99=A4=E7=B1=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../caucho/BurlapClientInterceptor.java | 194 -------
.../remoting/caucho/BurlapExporter.java | 97 ----
.../caucho/BurlapProxyFactoryBean.java | 73 ---
.../caucho/BurlapServiceExporter.java | 76 ---
.../caucho/HessianClientInterceptor.java | 297 ----------
.../remoting/caucho/HessianExporter.java | 247 ---------
.../caucho/HessianProxyFactoryBean.java | 70 ---
.../caucho/HessianServiceExporter.java | 73 ---
.../caucho/SimpleBurlapServiceExporter.java | 79 ---
.../caucho/SimpleHessianServiceExporter.java | 77 ---
.../remoting/caucho/package-info.java | 10 -
.../AbstractHttpInvokerRequestExecutor.java | 299 ----------
...pComponentsHttpInvokerRequestExecutor.java | 418 --------------
.../HttpInvokerClientConfiguration.java | 42 --
.../HttpInvokerClientInterceptor.java | 233 --------
.../HttpInvokerProxyFactoryBean.java | 86 ---
.../HttpInvokerRequestExecutor.java | 59 --
.../HttpInvokerServiceExporter.java | 225 --------
.../SimpleHttpInvokerRequestExecutor.java | 232 --------
.../SimpleHttpInvokerServiceExporter.java | 184 -------
.../remoting/httpinvoker/package-info.java | 11 -
.../rmi/CodebaseAwareObjectInputStream.java | 119 ----
.../rmi/JndiRmiClientInterceptor.java | 510 ------------------
.../remoting/rmi/JndiRmiProxyFactoryBean.java | 102 ----
.../remoting/rmi/JndiRmiServiceExporter.java | 149 -----
.../RemoteInvocationSerializingExporter.java | 181 -------
.../remoting/rmi/RmiBasedExporter.java | 76 ---
.../remoting/rmi/RmiClientInterceptor.java | 416 --------------
.../rmi/RmiClientInterceptorUtils.java | 193 -------
.../remoting/rmi/RmiInvocationHandler.java | 59 --
.../remoting/rmi/RmiInvocationWrapper.java | 77 ---
.../remoting/rmi/RmiProxyFactoryBean.java | 91 ----
.../remoting/rmi/RmiRegistryFactoryBean.java | 314 -----------
.../remoting/rmi/RmiServiceExporter.java | 462 ----------------
.../remoting/rmi/package-info.java | 6 -
35 files changed, 5837 deletions(-)
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/BurlapClientInterceptor.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/BurlapExporter.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/BurlapProxyFactoryBean.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/BurlapServiceExporter.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/HessianClientInterceptor.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/HessianExporter.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/HessianProxyFactoryBean.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/HessianServiceExporter.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/SimpleBurlapServiceExporter.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/SimpleHessianServiceExporter.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/package-info.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/httpinvoker/AbstractHttpInvokerRequestExecutor.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutor.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/httpinvoker/HttpInvokerClientConfiguration.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/httpinvoker/HttpInvokerClientInterceptor.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/httpinvoker/HttpInvokerProxyFactoryBean.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/httpinvoker/HttpInvokerRequestExecutor.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/httpinvoker/HttpInvokerServiceExporter.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/httpinvoker/SimpleHttpInvokerRequestExecutor.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/httpinvoker/SimpleHttpInvokerServiceExporter.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/httpinvoker/package-info.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/CodebaseAwareObjectInputStream.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/JndiRmiClientInterceptor.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/JndiRmiProxyFactoryBean.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/JndiRmiServiceExporter.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/RemoteInvocationSerializingExporter.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/RmiBasedExporter.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/RmiClientInterceptor.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/RmiClientInterceptorUtils.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/RmiInvocationHandler.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/RmiInvocationWrapper.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/RmiProxyFactoryBean.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/RmiRegistryFactoryBean.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/RmiServiceExporter.java
delete mode 100644 fine-spring/src/main/java/com/fr/third/springframework/remoting/rmi/package-info.java
diff --git a/fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/BurlapClientInterceptor.java b/fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/BurlapClientInterceptor.java
deleted file mode 100644
index 1d5217375..000000000
--- a/fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/BurlapClientInterceptor.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * 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
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- */
-
-package com.fr.third.springframework.remoting.caucho;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.net.ConnectException;
-import java.net.MalformedURLException;
-
-import com.caucho.burlap.client.BurlapProxyFactory;
-import com.caucho.burlap.client.BurlapRuntimeException;
-import org.aopalliance.intercept.MethodInterceptor;
-import org.aopalliance.intercept.MethodInvocation;
-
-import com.fr.third.springframework.remoting.RemoteAccessException;
-import com.fr.third.springframework.remoting.RemoteConnectFailureException;
-import com.fr.third.springframework.remoting.RemoteLookupFailureException;
-import com.fr.third.springframework.remoting.RemoteProxyFailureException;
-import com.fr.third.springframework.remoting.support.UrlBasedRemoteAccessor;
-import com.fr.third.springframework.util.Assert;
-
-/**
- * {@link org.aopalliance.intercept.MethodInterceptor} for accessing a Burlap service.
- * Supports authentication via username and password.
- * The service URL must be an HTTP URL exposing a Burlap service.
- *
- *
Burlap is a slim, XML-based RPC protocol.
- * For information on Burlap, see the
- * Burlap website
- *
- *
Note: There is no requirement for services accessed with this proxy factory
- * to have been exported using Spring's {@link BurlapServiceExporter}, as there is
- * no special handling involved. As a consequence, you can also access services that
- * have been exported using Caucho's {@link com.caucho.burlap.server.BurlapServlet}.
- *
- * @author Juergen Hoeller
- * @since 29.09.2003
- * @see #setServiceInterface
- * @see #setServiceUrl
- * @see #setUsername
- * @see #setPassword
- * @see BurlapServiceExporter
- * @see BurlapProxyFactoryBean
- * @see com.caucho.burlap.client.BurlapProxyFactory
- * @see com.caucho.burlap.server.BurlapServlet
- * @deprecated as of Spring 4.0, since Burlap hasn't evolved in years
- * and is effectively retired (in contrast to its sibling Hessian)
- */
-@Deprecated
-public class BurlapClientInterceptor extends UrlBasedRemoteAccessor implements MethodInterceptor {
-
- private BurlapProxyFactory proxyFactory = new BurlapProxyFactory();
-
- private Object burlapProxy;
-
-
- /**
- * Set the BurlapProxyFactory instance to use.
- * If not specified, a default BurlapProxyFactory will be created.
- *
Allows to use an externally configured factory instance,
- * in particular a custom BurlapProxyFactory subclass.
- */
- public void setProxyFactory(BurlapProxyFactory proxyFactory) {
- this.proxyFactory = (proxyFactory != null ? proxyFactory : new BurlapProxyFactory());
- }
-
- /**
- * Set the username that this factory should use to access the remote service.
- * Default is none.
- *
The username will be sent by Burlap via HTTP Basic Authentication.
- * @see com.caucho.burlap.client.BurlapProxyFactory#setUser
- */
- public void setUsername(String username) {
- this.proxyFactory.setUser(username);
- }
-
- /**
- * Set the password that this factory should use to access the remote service.
- * Default is none.
- *
The password will be sent by Burlap via HTTP Basic Authentication.
- * @see com.caucho.burlap.client.BurlapProxyFactory#setPassword
- */
- public void setPassword(String password) {
- this.proxyFactory.setPassword(password);
- }
-
- /**
- * Set whether overloaded methods should be enabled for remote invocations.
- * Default is "false".
- * @see com.caucho.burlap.client.BurlapProxyFactory#setOverloadEnabled
- */
- public void setOverloadEnabled(boolean overloadEnabled) {
- this.proxyFactory.setOverloadEnabled(overloadEnabled);
- }
-
-
- @Override
- public void afterPropertiesSet() {
- super.afterPropertiesSet();
- prepare();
- }
-
- /**
- * Initialize the Burlap proxy for this interceptor.
- * @throws RemoteLookupFailureException if the service URL is invalid
- */
- public void prepare() throws RemoteLookupFailureException {
- try {
- this.burlapProxy = createBurlapProxy(this.proxyFactory);
- }
- catch (MalformedURLException ex) {
- throw new RemoteLookupFailureException("Service URL [" + getServiceUrl() + "] is invalid", ex);
- }
- }
-
- /**
- * Create the Burlap proxy that is wrapped by this interceptor.
- * @param proxyFactory the proxy factory to use
- * @return the Burlap proxy
- * @throws MalformedURLException if thrown by the proxy factory
- * @see com.caucho.burlap.client.BurlapProxyFactory#create
- */
- protected Object createBurlapProxy(BurlapProxyFactory proxyFactory) throws MalformedURLException {
- Assert.notNull(getServiceInterface(), "Property 'serviceInterface' is required");
- return proxyFactory.create(getServiceInterface(), getServiceUrl());
- }
-
-
- @Override
- public Object invoke(MethodInvocation invocation) throws Throwable {
- if (this.burlapProxy == null) {
- throw new IllegalStateException("BurlapClientInterceptor is not properly initialized - " +
- "invoke 'prepare' before attempting any operations");
- }
-
- ClassLoader originalClassLoader = overrideThreadContextClassLoader();
- try {
- return invocation.getMethod().invoke(this.burlapProxy, invocation.getArguments());
- }
- catch (InvocationTargetException ex) {
- Throwable targetEx = ex.getTargetException();
- if (targetEx instanceof BurlapRuntimeException) {
- Throwable cause = targetEx.getCause();
- throw convertBurlapAccessException(cause != null ? cause : targetEx);
- }
- else if (targetEx instanceof UndeclaredThrowableException) {
- UndeclaredThrowableException utex = (UndeclaredThrowableException) targetEx;
- throw convertBurlapAccessException(utex.getUndeclaredThrowable());
- }
- else {
- throw targetEx;
- }
- }
- catch (Throwable ex) {
- throw new RemoteProxyFailureException(
- "Failed to invoke Burlap proxy for remote service [" + getServiceUrl() + "]", ex);
- }
- finally {
- resetThreadContextClassLoader(originalClassLoader);
- }
- }
-
- /**
- * Convert the given Burlap access exception to an appropriate
- * Spring RemoteAccessException.
- * @param ex the exception to convert
- * @return the RemoteAccessException to throw
- */
- protected RemoteAccessException convertBurlapAccessException(Throwable ex) {
- if (ex instanceof ConnectException) {
- return new RemoteConnectFailureException(
- "Cannot connect to Burlap remote service at [" + getServiceUrl() + "]", ex);
- }
- else {
- return new RemoteAccessException(
- "Cannot access Burlap remote service at [" + getServiceUrl() + "]", ex);
- }
- }
-
-}
diff --git a/fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/BurlapExporter.java b/fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/BurlapExporter.java
deleted file mode 100644
index 8f660633f..000000000
--- a/fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/BurlapExporter.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * 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
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- */
-
-package com.fr.third.springframework.remoting.caucho;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import com.caucho.burlap.io.BurlapInput;
-import com.caucho.burlap.io.BurlapOutput;
-import com.caucho.burlap.server.BurlapSkeleton;
-
-import com.fr.third.springframework.beans.factory.InitializingBean;
-import com.fr.third.springframework.remoting.support.RemoteExporter;
-import com.fr.third.springframework.util.Assert;
-
-/**
- * General stream-based protocol exporter for a Burlap endpoint.
- *
- *
Burlap is a slim, XML-based RPC protocol.
- * For information on Burlap, see the
- * Burlap website.
- * This exporter requires Burlap 3.x.
- *
- * @author Juergen Hoeller
- * @since 2.5.1
- * @see #invoke(java.io.InputStream, java.io.OutputStream)
- * @see BurlapServiceExporter
- * @see SimpleBurlapServiceExporter
- * @deprecated as of Spring 4.0, since Burlap hasn't evolved in years
- * and is effectively retired (in contrast to its sibling Hessian)
- */
-@Deprecated
-public class BurlapExporter extends RemoteExporter implements InitializingBean {
-
- private BurlapSkeleton skeleton;
-
-
- @Override
- public void afterPropertiesSet() {
- prepare();
- }
-
- /**
- * Initialize this service exporter.
- */
- public void prepare() {
- checkService();
- checkServiceInterface();
- this.skeleton = new BurlapSkeleton(getProxyForService(), getServiceInterface());
- }
-
-
- /**
- * Perform an invocation on the exported object.
- * @param inputStream the request stream
- * @param outputStream the response stream
- * @throws Throwable if invocation failed
- */
- public void invoke(InputStream inputStream, OutputStream outputStream) throws Throwable {
- Assert.notNull(this.skeleton, "Burlap exporter has not been initialized");
- ClassLoader originalClassLoader = overrideThreadContextClassLoader();
- try {
- this.skeleton.invoke(new BurlapInput(inputStream), new BurlapOutput(outputStream));
- }
- finally {
- try {
- inputStream.close();
- }
- catch (IOException ex) {
- // ignore
- }
- try {
- outputStream.close();
- }
- catch (IOException ex) {
- // ignore
- }
- resetThreadContextClassLoader(originalClassLoader);
- }
- }
-
-}
diff --git a/fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/BurlapProxyFactoryBean.java b/fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/BurlapProxyFactoryBean.java
deleted file mode 100644
index 719641633..000000000
--- a/fine-spring/src/main/java/com/fr/third/springframework/remoting/caucho/BurlapProxyFactoryBean.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * 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
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- */
-
-package com.fr.third.springframework.remoting.caucho;
-
-import com.fr.third.springframework.aop.framework.ProxyFactory;
-import com.fr.third.springframework.beans.factory.FactoryBean;
-
-/**
- * {@link FactoryBean} for Burlap proxies. Exposes the proxied service
- * for use as a bean reference, using the specified service interface.
- *
- *
Burlap is a slim, XML-based RPC protocol.
- * For information on Burlap, see the
- * Burlap website
- *
- *
The service URL must be an HTTP URL exposing a Burlap service.
- * For details, see the {@link BurlapClientInterceptor} javadoc.
- *
- * @author Juergen Hoeller
- * @since 13.05.2003
- * @see #setServiceInterface
- * @see #setServiceUrl
- * @see BurlapClientInterceptor
- * @see BurlapServiceExporter
- * @see com.fr.third.springframework.remoting.caucho.HessianProxyFactoryBean
- * @see com.fr.third.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean
- * @see com.fr.third.springframework.remoting.rmi.RmiProxyFactoryBean
- * @deprecated as of Spring 4.0, since Burlap hasn't evolved in years
- * and is effectively retired (in contrast to its sibling Hessian)
- */
-@Deprecated
-public class BurlapProxyFactoryBean extends BurlapClientInterceptor implements FactoryBean
- *
+ *
* @param xpathFilterExpression
* is the XPath filter expression to evaluate
* @param node
* is the Node on which to evalute the XPath
- *
+ *
* @return the results of all the XPath evaluations as a single list
*/
- public static List selectNodes(String xpathFilterExpression, Node node) {
+ public static List selectNodes(String xpathFilterExpression, Node node) {
XPath xpath = createXPath(xpathFilterExpression);
return xpath.selectNodes(node);
@@ -221,13 +221,13 @@ public final class DocumentHelper {
* sort sorts the given List of Nodes using an XPath
* expression as a {@link java.util.Comparator}.
*
- *
+ *
* @param list
* is the list of Nodes to sort
* @param xpathExpression
* is the XPath expression used for comparison
*/
- public static void sort(List list, String xpathExpression) {
+ public static void sort(List list, String xpathExpression) {
XPath xpath = createXPath(xpathExpression);
xpath.sort(list);
}
@@ -238,7 +238,7 @@ public final class DocumentHelper {
* expression as a {@link java.util.Comparator}and optionally removing
* duplicates.
*
- *
+ *
* @param list
* is the list of Nodes to sort
* @param expression
@@ -247,7 +247,7 @@ public final class DocumentHelper {
* if true then duplicate values (using the sortXPath for
* comparisions) will be removed from the List
*/
- public static void sort(List list, String expression, boolean distinct) {
+ public static void sort(List list, String expression, boolean distinct) {
XPath xpath = createXPath(expression);
xpath.sort(list, distinct);
}
@@ -257,25 +257,26 @@ public final class DocumentHelper {
* parseText parses the given text as an XML document and
* returns the newly created Document.
*
- *
+ *
+ * Loading external DTD and entities is disabled (if it is possible) for security reasons.
+ *
* @param text
* the XML text to be parsed
- *
+ *
* @return a newly parsed Document
- *
+ *
* @throws DocumentException
* if the document could not be parsed
*/
public static Document parseText(String text) throws DocumentException {
- Document result = null;
+ SAXReader reader = SAXReader.createDefault();
- SAXReader reader = new SAXReader();
String encoding = getEncoding(text);
InputSource source = new InputSource(new StringReader(text));
source.setEncoding(encoding);
- result = reader.read(source);
+ Document result = reader.read(source);
// if the XML parser doesn't provide a way to retrieve the encoding,
// specify it manually
@@ -322,14 +323,14 @@ public final class DocumentHelper {
* get the first child <a> element, which would be created if it did
* not exist, then the next child <b> and so on until finally a
* <c> element is returned.
- *
+ *
* @param source
* is the Element or Document to start navigating from
* @param path
* is a simple path expression, seperated by '/' which denotes
* the path from the source to the resulting element such as
* a/b/c
- *
+ *
* @return the first Element on the given path which either already existed
* on the path or were created by this method.
*/
@@ -378,24 +379,24 @@ public final class DocumentHelper {
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the
* following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document.
- *
+ *
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com.
- *
+ *
* 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
- *
+ *
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
- *
+ *
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -407,6 +408,6 @@ public final class DocumentHelper {
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/DocumentType.java b/fine-org-dom4j/src/main/java/org/dom4j/DocumentType.java
index d2c9f3cb2..aaea5eae0 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/DocumentType.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/DocumentType.java
@@ -7,16 +7,17 @@
package org.dom4j;
+import org.dom4j.dtd.Decl;
+
import java.util.List;
/**
- *
* DocumentType defines an XML DOCTYPE declaration.
- *
- *
+ *
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.10 $
*/
+@SuppressWarnings("unused")
public interface DocumentType extends Node {
/**
* This method is the equivalent to the {@link #getName}method. It is added
@@ -49,7 +50,7 @@ public interface DocumentType extends Node {
*
* @return DOCUMENT ME!
*/
- List getInternalDeclarations();
+ List getInternalDeclarations();
/**
* Sets the list of internal DTD declaration objects, defined in the
@@ -58,7 +59,7 @@ public interface DocumentType extends Node {
* @param declarations
* DOCUMENT ME!
*/
- void setInternalDeclarations(List declarations);
+ void setInternalDeclarations(List declarations);
/**
* Returns a list of internal DTD declaration objects, defined in the
@@ -66,7 +67,7 @@ public interface DocumentType extends Node {
*
* @return DOCUMENT ME!
*/
- List getExternalDeclarations();
+ List getExternalDeclarations();
/**
* Sets the list of internal DTD declaration objects, defined in the
@@ -75,7 +76,7 @@ public interface DocumentType extends Node {
* @param declarations
* DOCUMENT ME!
*/
- void setExternalDeclarations(List declarations);
+ void setExternalDeclarations(List declarations);
}
/*
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/Element.java b/fine-org-dom4j/src/main/java/org/dom4j/Element.java
index 56b446b13..9cf2738c3 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/Element.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/Element.java
@@ -12,839 +12,682 @@ import java.util.List;
import java.util.Map;
/**
- *
* Element interface defines an XML element. An element can have
* declared namespaces, attributes, child nodes and textual content.
- *
- *
*
* Some of this interface is optional. Some implementations may be read-only and
* not support being modified. Some implementations may not support the parent
- * relationship and methods such as {@link #getParent}or {@link#getDocument}.
- *
- *
+ * relationship and methods such as {@link #getParent}or {@link #getDocument}.
+ *
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.47 $
*/
+@SuppressWarnings("unused")
public interface Element extends Branch {
- // Name and namespace related methods
- // -------------------------------------------------------------------------
-
- /**
- *
- * Returns the QName of this element which represents the
- * local name, the qualified name and the Namespace.
- *
- *
- * @return the QName associated with this element
- */
- QName getQName();
-
- /**
- *
- * Sets the QName of this element which represents the local
- * name, the qualified name and the Namespace.
- *
- *
- * @param qname
- * is the QName to be associated with this element
- */
- void setQName(QName qname);
-
- /**
- *
- * Returns the Namespace of this element if one exists
- * otherwise Namespace.NO_NAMESPACE is returned.
- *
- *
- * @return the Namespace associated with this element
- */
- Namespace getNamespace();
-
- /**
- *
- * Returns the QName for the given qualified name, using the
- * namespace URI in scope for the given prefix of the qualified name or the
- * default namespace if the qualified name has no prefix.
- *
- *
- * @param qualifiedName
- * DOCUMENT ME!
- *
- * @return the QName for the given qualified name
- */
- QName getQName(String qualifiedName);
-
- /**
- *
- * Returns the Namespace which is mapped to the given prefix
- * or null if it could not be found.
- *
- *
- * @param prefix
- * DOCUMENT ME!
- *
- * @return the Namespace associated with the given prefix
- */
- Namespace getNamespaceForPrefix(String prefix);
-
- /**
- *
- * Returns the Namespace which is mapped to the given URI or
- * null if it could not be found. If there is more than one
- * Namespace mapped to the URI, which of them will be
- * returned is undetermined.
- *
- *
- * @param uri
- * DOCUMENT ME!
- *
- * @return the Namespace associated with the given URI
- */
- Namespace getNamespaceForURI(String uri);
-
- /**
- *
- * Returns the all namespaces which are mapped to the given URI or an empty
- * list if no such namespaces could be found.
- *
- *
- * @param uri
- * DOCUMENT ME!
- *
- * @return the namespaces associated with the given URI
- *
- * @since 1.5
- */
- List getNamespacesForURI(String uri);
-
- /**
- *
- * Returns the namespace prefix of this element if one exists otherwise an
- * empty String is returned.
- *
- *
- * @return the prefix of the Namespace of this element or an
- * empty String
- */
- String getNamespacePrefix();
-
- /**
- *
- * Returns the URI mapped to the namespace of this element if one exists
- * otherwise an empty String is returned.
- *
- *
- * @return the URI for the Namespace of this element or an
- * empty String
- */
- String getNamespaceURI();
-
- /**
- *
- * Returns the fully qualified name of this element. This will be the same
- * as the value returned from {@link #getName}if this element has no
- * namespace attached to this element or an expression of the form
- *
- *
- * getNamespacePrefix() + ":" + getName()
- *
- *
- * will be returned.
- *
- *
- * @return the fully qualified name of the element.
- */
- String getQualifiedName();
-
- /**
- *
- * Returns any additional namespaces declarations for this element other
- * than namespace returned via the {@link #getNamespace()}method. If no
- * additional namespace declarations are present for this element then an
- * empty list will be returned. The list is backed by the element such that
- * changes to the list will be reflected in the element though the reverse
- * is not the case.
- *
- *
- * @return a list of any additional namespace declarations.
- */
- List additionalNamespaces();
-
- /**
- *
- * Returns all the namespaces declared by this element. If no namespaces are
- * declared for this element then an empty list will be returned. The list
- * is backed by the element such that changes to the list will be reflected
- * in the element though the reverse is not the case.
- *
- *
- * @return a list of namespaces declared for this element.
- */
- List declaredNamespaces();
-
- // Builder methods
- // -------------------------------------------------------------------------
-
- /**
- *
- * Adds the attribute value of the given local name. If an attribute already
- * exists for the given name it will be replaced. Attributes with null
- * values are silently ignored. If the value of the attribute is null then
- * this method call will remove any attributes with the given name.
- *
- *
- * @param name
- * is the name of the attribute whose value is to be added or
- * updated
- * @param value
- * is the attribute's value
- *
- * @return this Element instance.
- */
- Element addAttribute(String name, String value);
-
- /**
- *
- * Adds the attribute value of the given fully qualified name. If an
- * attribute already exists for the given name it will be replaced.
- * Attributes with null values are silently ignored. If the value of the
- * attribute is null then this method call will remove any attributes with
- * the given name.
- *
- *
- * @param qName
- * is the fully qualified name of the attribute whose value is to
- * be added or updated
- * @param value
- * is the attribute's value
- *
- * @return this Element instance.
- */
- Element addAttribute(QName qName, String value);
-
- /**
- * Adds a new Comment node with the given text to this
- * element.
- *
- * @param comment
- * is the text for the Comment node.
- *
- * @return this Element instance.
- */
- Element addComment(String comment);
-
- /**
- * Adds a new CDATA node with the given text to this element.
- *
- * @param cdata
- * is the text for the CDATA node.
- *
- * @return this Element instance.
- */
- Element addCDATA(String cdata);
-
- /**
- * Adds a new Entity node with the given name and text to
- * this element and returns a reference to the new node.
- *
- * @param name
- * is the name for the Entity node.
- * @param text
- * is the text for the Entity node.
- *
- * @return this Element instance.
- */
- Element addEntity(String name, String text);
-
- /**
- * Adds a namespace to this element for use by its child content
- *
- * @param prefix
- * is the prefix to use, which should not be null or blank
- * @param uri
- * is the namespace URI
- *
- * @return this Element instance.
- */
- Element addNamespace(String prefix, String uri);
-
- /**
- * Adds a processing instruction for the given target
- *
- * @param target
- * is the target of the processing instruction
- * @param text
- * is the textual data (key/value pairs) of the processing
- * instruction
- *
- * @return this Element instance.
- */
- Element addProcessingInstruction(String target, String text);
-
- /**
- * Adds a processing instruction for the given target
- *
- * @param target
- * is the target of the processing instruction
- * @param data
- * is a Map of the key / value pairs of the processing
- * instruction
- *
- * @return this Element instance.
- */
- Element addProcessingInstruction(String target, Map data);
-
- /**
- * Adds a new Text node with the given text to this element.
- *
- * @param text
- * is the text for the Text node.
- *
- * @return this Element instance.
- */
- Element addText(String text);
-
- // Typesafe modifying methods
- // -------------------------------------------------------------------------
-
- /**
- * Adds the given Attribute to this element. If the given
- * node already has a parent defined then an
- * IllegalAddException will be thrown. Attributes with null
- * values are silently ignored.
- *
- *
- * If the value of the attribute is null then this method call will remove
- * any attributes with the QName of this attribute.
- *
- *
- * @param attribute
- * is the attribute to be added
- */
- void add(Attribute attribute);
-
- /**
- * Adds the given CDATA to this element. If the given node
- * already has a parent defined then an IllegalAddException
- * will be thrown.
- *
- * @param cdata
- * is the CDATA to be added
- */
- void add(CDATA cdata);
-
- /**
- * Adds the given Entity to this element. If the given node
- * already has a parent defined then an IllegalAddException
- * will be thrown.
- *
- * @param entity
- * is the entity to be added
- */
- void add(Entity entity);
-
- /**
- * Adds the given Text to this element. If the given node
- * already has a parent defined then an IllegalAddException
- * will be thrown.
- *
- * @param text
- * is the text to be added
- */
- void add(Text text);
-
- /**
- * Adds the given Namespace to this element. If the given
- * node already has a parent defined then an
- * IllegalAddException will be thrown.
- *
- * @param namespace
- * is the namespace to be added
- */
- void add(Namespace namespace);
-
- /**
- * Removes the given Attribute from this element.
- *
- * @param attribute
- * is the attribute to be removed
- *
- * @return true if the attribute was removed
- */
- boolean remove(Attribute attribute);
-
- /**
- * Removes the given CDATA if the node is an immediate child
- * of this element. If the given node is not an immediate child of this
- * element then the {@link Node#detach()}method should be used instead.
- *
- * @param cdata
- * is the CDATA to be removed
- *
- * @return true if the cdata was removed
- */
- boolean remove(CDATA cdata);
-
- /**
- * Removes the given Entity if the node is an immediate child
- * of this element. If the given node is not an immediate child of this
- * element then the {@link Node#detach()}method should be used instead.
- *
- * @param entity
- * is the entity to be removed
- *
- * @return true if the entity was removed
- */
- boolean remove(Entity entity);
-
- /**
- * Removes the given Namespace if the node is an immediate
- * child of this element. If the given node is not an immediate child of
- * this element then the {@link Node#detach()}method should be used
- * instead.
- *
- * @param namespace
- * is the namespace to be removed
- *
- * @return true if the namespace was removed
- */
- boolean remove(Namespace namespace);
-
- /**
- * Removes the given Text if the node is an immediate child
- * of this element. If the given node is not an immediate child of this
- * element then the {@link Node#detach()}method should be used instead.
- *
- * @param text
- * is the text to be removed
- *
- * @return true if the text was removed
- */
- boolean remove(Text text);
-
- // Text methods
- // -------------------------------------------------------------------------
-
- /**
- * Returns the text value of this element without recursing through child
- * elements. This method iterates through all {@link Text},{@link CDATA}
- * and {@link Entity}nodes that this element contains and appends the text
- * values together.
- *
- * @return the textual content of this Element. Child elements are not
- * navigated. This method does not return null;
- */
- String getText();
-
- /**
- * DOCUMENT ME!
- *
- * @return the trimmed text value where whitespace is trimmed and normalised
- * into single spaces. This method does not return null.
- */
- String getTextTrim();
-
- /**
- * Returns the XPath string-value of this node. The behaviour of this method
- * is defined in the XPath
- * specification . This method returns the string-value of all the
- * contained {@link Text},{@link CDATA},{@link Entity}and {@link
- * Element} nodes all appended together.
- *
- * @return the text from all the child Text and Element nodes appended
- * together.
- */
- String getStringValue();
-
- /**
- * Accesses the data of this element which may implement data typing
- * bindings such as XML Schema or Java Bean bindings or will return the same
- * value as {@link #getText}
- *
- * @return DOCUMENT ME!
- */
- Object getData();
-
- /**
- * Sets the data value of this element if this element supports data binding
- * or calls {@link #setText}if it doesn't
- *
- * @param data
- * DOCUMENT ME!
- */
- void setData(Object data);
-
- // Attribute methods
- // -------------------------------------------------------------------------
-
- /**
- *
- * Returns the {@link Attribute}instances this element contains as a backed
- * {@link List}so that the attributes may be modified directly using the
- * {@link List}interface. The List is backed by the
- * Element so that changes to the list are reflected in the
- * element and vice versa.
- *
- *
- * @return the attributes that this element contains as a List
- */
- List attributes();
-
- /**
- * Sets the attributes that this element contains
- *
- * @param attributes
- * DOCUMENT ME!
- */
- void setAttributes(List attributes);
-
- /**
- * DOCUMENT ME!
- *
- * @return the number of attributes this element contains
- */
- int attributeCount();
-
- /**
- * DOCUMENT ME!
- *
- * @return an iterator over the attributes of this element
- */
- Iterator attributeIterator();
-
- /**
- * Returns the attribute at the specified indexGets the
- *
- * @param index
- * DOCUMENT ME!
- *
- * @return the attribute at the specified index where index >= 0 and
- * index < number of attributes or throws an
- * IndexOutOfBoundsException if the index is not within the
- * allowable range
- */
- Attribute attribute(int index);
-
- /**
- * Returns the attribute with the given name
- *
- * @param name
- * DOCUMENT ME!
- *
- * @return the attribute for the given local name in any namespace. If there
- * are more than one attributes with the given local name in
- * different namespaces then the first one is returned.
- */
- Attribute attribute(String name);
-
- /**
- * DOCUMENT ME!
- *
- * @param qName
- * is the fully qualified name
- *
- * @return the attribute for the given fully qualified name or null if it
- * could not be found.
- */
- Attribute attribute(QName qName);
-
- /**
- *
- * This returns the attribute value for the attribute with the given name
- * and any namespace or null if there is no such attribute or the empty
- * string if the attribute value is empty.
- *
- *
- * @param name
- * is the name of the attribute value to be returnd
- *
- * @return the value of the attribute, null if the attribute does not exist
- * or the empty string
- */
- String attributeValue(String name);
-
- /**
- *
- * This returns the attribute value for the attribute with the given name
- * and any namespace or the default value if there is no such attribute
- * value.
- *
- *
- * @param name
- * is the name of the attribute value to be returnd
- * @param defaultValue
- * is the default value to be returned if the attribute has no
- * value defined.
- *
- * @return the value of the attribute or the defaultValue if the attribute
- * has no value defined.
- */
- String attributeValue(String name, String defaultValue);
-
- /**
- *
- * This returns the attribute value for the attribute with the given fully
- * qualified name or null if there is no such attribute or the empty string
- * if the attribute value is empty.
- *
- *
- * @param qName
- * is the fully qualified name
- *
- * @return the value of the attribute, null if the attribute does not exist
- * or the empty string
- */
- String attributeValue(QName qName);
-
- /**
- *
- * This returns the attribute value for the attribute with the given fully
- * qualified name or the default value if there is no such attribute value.
- *
- *
- * @param qName
- * is the fully qualified name
- * @param defaultValue
- * is the default value to be returned if the attribute has no
- * value defined.
- *
- * @return the value of the attribute or the defaultValue if the attribute
- * has no value defined.
- */
- String attributeValue(QName qName, String defaultValue);
-
- /**
- *
- * Sets the attribute value of the given local name.
- *
- *
- * @param name
- * is the name of the attribute whose value is to be added or
- * updated
- * @param value
- * is the attribute's value
- *
- * @deprecated As of version 0.5. Please use {@link
- * #addAttribute(String,String)} instead. WILL BE REMOVED IN
- * dom4j-1.6 !!
- */
- void setAttributeValue(String name, String value);
-
- /**
- *
- * Sets the attribute value of the given fully qualified name.
- *
- *
- * @param qName
- * is the fully qualified name of the attribute whose value is to
- * be added or updated
- * @param value
- * is the attribute's value
- *
- * @deprecated As of version 0.5. Please use {@link
- * #addAttribute(QName,String)} instead. WILL BE REMOVED IN
- * dom4j-1.6 !!
- */
- void setAttributeValue(QName qName, String value);
-
- // Content methods
- // -------------------------------------------------------------------------
-
- /**
- * Returns the first element for the given local name and any namespace.
- *
- * @param name
- * DOCUMENT ME!
- *
- * @return the first element with the given local name
- */
- Element element(String name);
-
- /**
- * Returns the first element for the given fully qualified name.
- *
- * @param qName
- * is the fully qualified name to search for
- *
- * @return the first element with the given fully qualified name
- */
- Element element(QName qName);
-
- /**
- *
- * Returns the elements contained in this element. If this element does not
- * contain any elements then this method returns an empty list. The list is
- * backed by the element such that changes to the list will be reflected in
- * the element though the reverse is not the case.
- *
- *
- * @return a list of all the elements in this element.
- */
- List elements();
-
- /**
- *
- * Returns the elements contained in this element with the given local name
- * and any namespace. If no elements are found then this method returns an
- * empty list. The list is backed by the element such that changes to the
- * list will be reflected in the element though the reverse is not the case.
- *
- *
- * @param name
- * DOCUMENT ME!
- *
- * @return a list of all the elements in this element for the given local
- * name
- */
- List elements(String name);
-
- /**
- *
- * Returns the elements contained in this element with the given fully
- * qualified name. If no elements are found then this method returns an
- * empty list. The list is backed by the element such that changes to the
- * list will be reflected in the element though the reverse is not the case.
- *
- *
- * @param qName
- * is the fully qualified name to search for
- *
- * @return a list of all the elements in this element for the given fully
- * qualified name.
- */
- List elements(QName qName);
-
- /**
- * Returns an iterator over all this elements child elements.
- *
- * @return an iterator over the contained elements
- */
- Iterator elementIterator();
-
- /**
- * Returns an iterator over the elements contained in this element which
- * match the given local name and any namespace.
- *
- * @param name
- * DOCUMENT ME!
- *
- * @return an iterator over the contained elements matching the given local
- * name
- */
- Iterator elementIterator(String name);
-
- /**
- * Returns an iterator over the elements contained in this element which
- * match the given fully qualified name.
- *
- * @param qName
- * is the fully qualified name to search for
- *
- * @return an iterator over the contained elements matching the given fully
- * qualified name
- */
- Iterator elementIterator(QName qName);
-
- // Helper methods
- // -------------------------------------------------------------------------
-
- /**
- * DOCUMENT ME!
- *
- * @return true if this element is the root element of a document and this
- * element supports the parent relationship else false.
- */
- boolean isRootElement();
-
- /**
- *
- * Returns true if this Element has mixed content. Mixed
- * content means that an element contains both textual data and child
- * elements.
- *
- *
- * @return true if this element contains mixed content.
- */
- boolean hasMixedContent();
-
- /**
- *
- * Returns true if this Element has text only content.
- *
- *
- * @return true if this element is empty or only contains text content.
- */
- boolean isTextOnly();
-
- /**
- * Appends the attributes of the given element to me. This method behaves
- * like the {@link java.util.Collection#addAll(java.util.Collection)}
- * method.
- *
- * @param element
- * is the element whose attributes will be added to me.
- */
- void appendAttributes(Element element);
-
- /**
- *
- * Creates a deep copy of this element The new element is detached from its
- * parent, and getParent() on the clone will return null.
- *
- *
- * @return a new deep copy Element
- */
- Element createCopy();
-
- /**
- *
- * Creates a deep copy of this element with the given local name The new
- * element is detached from its parent, and getParent() on the clone will
- * return null.
- *
- *
- * @param name
- * DOCUMENT ME!
- *
- * @return a new deep copy Element
- */
- Element createCopy(String name);
-
- /**
- *
- * Creates a deep copy of this element with the given fully qualified name.
- * The new element is detached from its parent, and getParent() on the clone
- * will return null.
- *
- *
- * @param qName
- * DOCUMENT ME!
- *
- * @return a new deep copy Element
- */
- Element createCopy(QName qName);
-
- String elementText(String name);
-
- String elementText(QName qname);
-
- String elementTextTrim(String name);
-
- String elementTextTrim(QName qname);
-
- /**
- * Returns a node at the given index suitable for an XPath result set. This
- * means the resulting Node will either be null or it will support the
- * parent relationship.
- *
- * @param index
- * DOCUMENT ME!
- *
- * @return the Node for the given index which will support the parent
- * relationship or null if there is not a node at the given index.
- */
- Node getXPathResult(int index);
+ // Name and namespace related methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns the QName of this element which represents the
+ * local name, the qualified name and the Namespace.
+ *
+ * @return the QName associated with this element
+ */
+ QName getQName();
+
+ /**
+ * Sets the QName of this element which represents the local
+ * name, the qualified name and the Namespace.
+ *
+ * @param qname is the QName to be associated with this element
+ */
+ void setQName(QName qname);
+
+ /**
+ * Returns the Namespace of this element if one exists
+ * otherwise Namespace.NO_NAMESPACE is returned.
+ *
+ * @return the Namespace associated with this element
+ */
+ Namespace getNamespace();
+
+ /**
+ * Returns the QName for the given qualified name, using the
+ * namespace URI in scope for the given prefix of the qualified name or the
+ * default namespace if the qualified name has no prefix.
+ *
+ * @param qualifiedName DOCUMENT ME!
+ * @return the QName for the given qualified name
+ */
+ QName getQName(String qualifiedName);
+
+ /**
+ * Returns the Namespace which is mapped to the given prefix
+ * or null if it could not be found.
+ *
+ * @param prefix DOCUMENT ME!
+ * @return the Namespace associated with the given prefix
+ */
+ Namespace getNamespaceForPrefix(String prefix);
+
+ /**
+ * Returns the Namespace which is mapped to the given URI or
+ * null if it could not be found. If there is more than one
+ * Namespace mapped to the URI, which of them will be
+ * returned is undetermined.
+ *
+ * @param uri DOCUMENT ME!
+ * @return the Namespace associated with the given URI
+ */
+ Namespace getNamespaceForURI(String uri);
+
+ /**
+ * Returns the all namespaces which are mapped to the given URI or an empty
+ * list if no such namespaces could be found.
+ *
+ * @param uri DOCUMENT ME!
+ * @return the namespaces associated with the given URI
+ * @since 1.5
+ */
+ List getNamespacesForURI(String uri);
+
+ /**
+ * Returns the namespace prefix of this element if one exists otherwise an
+ * empty String is returned.
+ *
+ * @return the prefix of the Namespace of this element or an
+ * empty String
+ */
+ String getNamespacePrefix();
+
+ /**
+ * Returns the URI mapped to the namespace of this element if one exists
+ * otherwise an empty String is returned.
+ *
+ * @return the URI for the Namespace of this element or an
+ * empty String
+ */
+ String getNamespaceURI();
+
+ /**
+ * Returns the fully qualified name of this element. This will be the same
+ * as the value returned from {@link #getName}if this element has no
+ * namespace attached to this element or an expression of the form
+ *
+ * getNamespacePrefix() + ":" + getName()
+ *
+ * will be returned.
+ *
+ * @return the fully qualified name of the element.
+ */
+ String getQualifiedName();
+
+ /**
+ * Returns any additional namespaces declarations for this element other
+ * than namespace returned via the {@link #getNamespace()}method. If no
+ * additional namespace declarations are present for this element then an
+ * empty list will be returned. The list is backed by the element such that
+ * changes to the list will be reflected in the element though the reverse
+ * is not the case.
+ *
+ * @return a list of any additional namespace declarations.
+ */
+ List additionalNamespaces();
+
+ /**
+ * Returns all the namespaces declared by this element. If no namespaces are
+ * declared for this element then an empty list will be returned. The list
+ * is backed by the element such that changes to the list will be reflected
+ * in the element though the reverse is not the case.
+ *
+ * @return a list of namespaces declared for this element.
+ */
+ List declaredNamespaces();
+
+ // Builder methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Adds the attribute value of the given local name. If an attribute already
+ * exists for the given name it will be replaced. Attributes with null
+ * values are silently ignored. If the value of the attribute is null then
+ * this method call will remove any attributes with the given name.
+ *
+ * @param name is the name of the attribute whose value is to be added or
+ * updated
+ * @param value is the attribute's value
+ * @return this Element instance.
+ */
+ Element addAttribute(String name, String value);
+
+ /**
+ * Adds the attribute value of the given fully qualified name. If an
+ * attribute already exists for the given name it will be replaced.
+ * Attributes with null values are silently ignored. If the value of the
+ * attribute is null then this method call will remove any attributes with
+ * the given name.
+ *
+ * @param qName is the fully qualified name of the attribute whose value is to
+ * be added or updated
+ * @param value is the attribute's value
+ * @return this Element instance.
+ */
+ Element addAttribute(QName qName, String value);
+
+ /**
+ * Adds a new Comment node with the given text to this
+ * element.
+ *
+ * @param comment is the text for the Comment node.
+ * @return this Element instance.
+ */
+ Element addComment(String comment);
+
+ /**
+ * Adds a new CDATA node with the given text to this element.
+ *
+ * @param cdata is the text for the CDATA node.
+ * @return this Element instance.
+ */
+ Element addCDATA(String cdata);
+
+ /**
+ * Adds a new Entity node with the given name and text to
+ * this element and returns a reference to the new node.
+ *
+ * @param name is the name for the Entity node.
+ * @param text is the text for the Entity node.
+ * @return this Element instance.
+ */
+ Element addEntity(String name, String text);
+
+ /**
+ * Adds a namespace to this element for use by its child content
+ *
+ * @param prefix is the prefix to use, which should not be null or blank
+ * @param uri is the namespace URI
+ * @return this Element instance.
+ */
+ Element addNamespace(String prefix, String uri);
+
+ /**
+ * Adds a processing instruction for the given target
+ *
+ * @param target is the target of the processing instruction
+ * @param text is the textual data (key/value pairs) of the processing
+ * instruction
+ * @return this Element instance.
+ */
+ Element addProcessingInstruction(String target, String text);
+
+ /**
+ * Adds a processing instruction for the given target
+ *
+ * @param target is the target of the processing instruction
+ * @param data is a Map of the key / value pairs of the processing
+ * instruction
+ * @return this Element instance.
+ */
+ Element addProcessingInstruction(String target, Map data);
+
+ /**
+ * Adds a new Text node with the given text to this element.
+ *
+ * @param text is the text for the Text node.
+ * @return this Element instance.
+ */
+ Element addText(String text);
+
+ // Typesafe modifying methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Adds the given Attribute to this element. If the given
+ * node already has a parent defined then an
+ * IllegalAddException will be thrown. Attributes with null
+ * values are silently ignored.
+ *
+ * If the value of the attribute is null then this method call will remove
+ * any attributes with the QName of this attribute.
+ *
+ * @param attribute is the attribute to be added
+ */
+ void add(Attribute attribute);
+
+ /**
+ * Adds the given CDATA to this element. If the given node
+ * already has a parent defined then an IllegalAddException
+ * will be thrown.
+ *
+ * @param cdata is the CDATA to be added
+ */
+ void add(CDATA cdata);
+
+ /**
+ * Adds the given Entity to this element. If the given node
+ * already has a parent defined then an IllegalAddException
+ * will be thrown.
+ *
+ * @param entity is the entity to be added
+ */
+ void add(Entity entity);
+
+ /**
+ * Adds the given Text to this element. If the given node
+ * already has a parent defined then an IllegalAddException
+ * will be thrown.
+ *
+ * @param text is the text to be added
+ */
+ void add(Text text);
+
+ /**
+ * Adds the given Namespace to this element. If the given
+ * node already has a parent defined then an
+ * IllegalAddException will be thrown.
+ *
+ * @param namespace is the namespace to be added
+ */
+ void add(Namespace namespace);
+
+ /**
+ * Removes the given Attribute from this element.
+ *
+ * @param attribute is the attribute to be removed
+ * @return true if the attribute was removed
+ */
+ boolean remove(Attribute attribute);
+
+ /**
+ * Removes the given CDATA if the node is an immediate child
+ * of this element. If the given node is not an immediate child of this
+ * element then the {@link Node#detach()}method should be used instead.
+ *
+ * @param cdata is the CDATA to be removed
+ * @return true if the cdata was removed
+ */
+ boolean remove(CDATA cdata);
+
+ /**
+ * Removes the given Entity if the node is an immediate child
+ * of this element. If the given node is not an immediate child of this
+ * element then the {@link Node#detach()}method should be used instead.
+ *
+ * @param entity is the entity to be removed
+ * @return true if the entity was removed
+ */
+ boolean remove(Entity entity);
+
+ /**
+ * Removes the given Namespace if the node is an immediate
+ * child of this element. If the given node is not an immediate child of
+ * this element then the {@link Node#detach()}method should be used
+ * instead.
+ *
+ * @param namespace is the namespace to be removed
+ * @return true if the namespace was removed
+ */
+ boolean remove(Namespace namespace);
+
+ /**
+ * Removes the given Text if the node is an immediate child
+ * of this element. If the given node is not an immediate child of this
+ * element then the {@link Node#detach()}method should be used instead.
+ *
+ * @param text is the text to be removed
+ * @return true if the text was removed
+ */
+ boolean remove(Text text);
+
+ // Text methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns the text value of this element without recursing through child
+ * elements. This method iterates through all {@link Text},{@link CDATA}
+ * and {@link Entity}nodes that this element contains and appends the text
+ * values together.
+ *
+ * @return the textual content of this Element. Child elements are not
+ * navigated. This method does not return null;
+ */
+ String getText();
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return the trimmed text value where whitespace is trimmed and normalised
+ * into single spaces. This method does not return null.
+ */
+ String getTextTrim();
+
+ /**
+ * Returns the XPath string-value of this node. The behaviour of this method
+ * is defined in the XPath
+ * specification . This method returns the string-value of all the
+ * contained {@link Text},{@link CDATA},{@link Entity}and {@link
+ * Element} nodes all appended together.
+ *
+ * @return the text from all the child Text and Element nodes appended
+ * together.
+ */
+ String getStringValue();
+
+ /**
+ * Accesses the data of this element which may implement data typing
+ * bindings such as XML Schema or Java Bean bindings or will return the same
+ * value as {@link #getText}
+ *
+ * @return DOCUMENT ME!
+ */
+ Object getData();
+
+ /**
+ * Sets the data value of this element if this element supports data binding
+ * or calls {@link #setText}if it doesn't
+ *
+ * @param data DOCUMENT ME!
+ */
+ void setData(Object data);
+
+ // Attribute methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns the {@link Attribute}instances this element contains as a backed
+ * {@link List}so that the attributes may be modified directly using the
+ * {@link List}interface. The List is backed by the
+ * Element so that changes to the list are reflected in the
+ * element and vice versa.
+ *
+ * @return the attributes that this element contains as a List
+ */
+ List attributes();
+
+ /**
+ * Sets the attributes that this element contains
+ *
+ * @param attributes DOCUMENT ME!
+ */
+ void setAttributes(List attributes);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return the number of attributes this element contains
+ */
+ int attributeCount();
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return an iterator over the attributes of this element
+ */
+ Iterator attributeIterator();
+
+ /**
+ * Returns the attribute at the specified indexGets the
+ *
+ * @param index DOCUMENT ME!
+ * @return the attribute at the specified index where index >= 0 and
+ * index < number of attributes or throws an
+ * IndexOutOfBoundsException if the index is not within the
+ * allowable range
+ */
+ Attribute attribute(int index);
+
+ /**
+ * Returns the attribute with the given name
+ *
+ * @param name DOCUMENT ME!
+ * @return the attribute for the given local name in any namespace. If there
+ * are more than one attributes with the given local name in
+ * different namespaces then the first one is returned.
+ */
+ Attribute attribute(String name);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param qName is the fully qualified name
+ * @return the attribute for the given fully qualified name or null if it
+ * could not be found.
+ */
+ Attribute attribute(QName qName);
+
+ /**
+ * This returns the attribute value for the attribute with the given name
+ * and any namespace or null if there is no such attribute or the empty
+ * string if the attribute value is empty.
+ *
+ * @param name is the name of the attribute value to be returned
+ * @return the value of the attribute, null if the attribute does not exist
+ * or the empty string
+ */
+ String attributeValue(String name);
+
+ /**
+ * This returns the attribute value for the attribute with the given name
+ * and any namespace or the default value if there is no such attribute
+ * value.
+ *
+ * @param name is the name of the attribute value to be returned
+ * @param defaultValue is the default value to be returned if the attribute has no
+ * value defined.
+ * @return the value of the attribute or the defaultValue if the attribute
+ * has no value defined.
+ */
+ String attributeValue(String name, String defaultValue);
+
+ /**
+ * This returns the attribute value for the attribute with the given fully
+ * qualified name or null if there is no such attribute or the empty string
+ * if the attribute value is empty.
+ *
+ * @param qName is the fully qualified name
+ * @return the value of the attribute, null if the attribute does not exist
+ * or the empty string
+ */
+ String attributeValue(QName qName);
+
+ /**
+ * This returns the attribute value for the attribute with the given fully
+ * qualified name or the default value if there is no such attribute value.
+ *
+ * @param qName is the fully qualified name
+ * @param defaultValue is the default value to be returned if the attribute has no
+ * value defined.
+ * @return the value of the attribute or the defaultValue if the attribute
+ * has no value defined.
+ */
+ String attributeValue(QName qName, String defaultValue);
+
+ /**
+ * Sets the attribute value of the given local name.
+ *
+ * @param name is the name of the attribute whose value is to be added or
+ * updated
+ * @param value is the attribute's value
+ * @deprecated As of version 0.5. Please use {@link
+ * #addAttribute(String, String)} instead. WILL BE REMOVED IN
+ * dom4j-1.6 !!
+ */
+ void setAttributeValue(String name, String value);
+
+ /**
+ * Sets the attribute value of the given fully qualified name.
+ *
+ * @param qName is the fully qualified name of the attribute whose value is to
+ * be added or updated
+ * @param value is the attribute's value
+ * @deprecated As of version 0.5. Please use {@link
+ * #addAttribute(QName, String)} instead. WILL BE REMOVED IN
+ * dom4j-1.6 !!
+ */
+ void setAttributeValue(QName qName, String value);
+
+ // Content methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns the first element for the given local name and any namespace.
+ *
+ * @param name DOCUMENT ME!
+ * @return the first element with the given local name
+ */
+ Element element(String name);
+
+ /**
+ * Returns the first element for the given fully qualified name.
+ *
+ * @param qName is the fully qualified name to search for
+ * @return the first element with the given fully qualified name
+ */
+ Element element(QName qName);
+
+ /**
+ * Returns the elements contained in this element. If this element does not
+ * contain any elements then this method returns an empty list. The list is
+ * backed by the element such that changes to the list will be reflected in
+ * the element though the reverse is not the case.
+ *
+ * @return a list of all the elements in this element.
+ */
+ List elements();
+
+ /**
+ * Returns the elements contained in this element with the given local name
+ * and any namespace. If no elements are found then this method returns an
+ * empty list. The list is backed by the element such that changes to the
+ * list will be reflected in the element though the reverse is not the case.
+ *
+ * @param name DOCUMENT ME!
+ * @return a list of all the elements in this element for the given local
+ * name
+ */
+ List elements(String name);
+
+ /**
+ * Returns the elements contained in this element with the given fully
+ * qualified name. If no elements are found then this method returns an
+ * empty list. The list is backed by the element such that changes to the
+ * list will be reflected in the element though the reverse is not the case.
+ *
+ * @param qName is the fully qualified name to search for
+ * @return a list of all the elements in this element for the given fully
+ * qualified name.
+ */
+ List elements(QName qName);
+
+ /**
+ * Returns an iterator over all this elements child elements.
+ *
+ * @return an iterator over the contained elements
+ */
+ Iterator elementIterator();
+
+ /**
+ * Returns an iterator over the elements contained in this element which
+ * match the given local name and any namespace.
+ *
+ * @param name DOCUMENT ME!
+ * @return an iterator over the contained elements matching the given local
+ * name
+ */
+ Iterator elementIterator(String name);
+
+ /**
+ * Returns an iterator over the elements contained in this element which
+ * match the given fully qualified name.
+ *
+ * @param qName is the fully qualified name to search for
+ * @return an iterator over the contained elements matching the given fully
+ * qualified name
+ */
+ Iterator elementIterator(QName qName);
+
+ // Helper methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return true if this element is the root element of a document and this
+ * element supports the parent relationship else false.
+ */
+ boolean isRootElement();
+
+ /**
+ * Returns true if this Element has mixed content. Mixed
+ * content means that an element contains both textual data and child
+ * elements.
+ *
+ * @return true if this element contains mixed content.
+ */
+ boolean hasMixedContent();
+
+ /**
+ * Returns true if this Element has text only content.
+ *
+ * @return true if this element is empty or only contains text content.
+ */
+ boolean isTextOnly();
+
+ /**
+ * Appends the attributes of the given element to me. This method behaves
+ * like the {@link java.util.Collection#addAll(java.util.Collection)}
+ * method.
+ *
+ * @param element is the element whose attributes will be added to me.
+ */
+ void appendAttributes(Element element);
+
+ /**
+ * Creates a deep copy of this element The new element is detached from its
+ * parent, and getParent() on the clone will return null.
+ *
+ * @return a new deep copy Element
+ */
+ Element createCopy();
+
+ /**
+ * Creates a deep copy of this element with the given local name The new
+ * element is detached from its parent, and getParent() on the clone will
+ * return null.
+ *
+ * @param name DOCUMENT ME!
+ * @return a new deep copy Element
+ */
+ Element createCopy(String name);
+
+ /**
+ * Creates a deep copy of this element with the given fully qualified name.
+ * The new element is detached from its parent, and getParent() on the clone
+ * will return null.
+ *
+ * @param qName DOCUMENT ME!
+ * @return a new deep copy Element
+ */
+ Element createCopy(QName qName);
+
+ String elementText(String name);
+
+ String elementText(QName qname);
+
+ String elementTextTrim(String name);
+
+ String elementTextTrim(QName qname);
+
+ /**
+ * Returns a node at the given index suitable for an XPath result set. This
+ * means the resulting Node will either be null or it will support the
+ * parent relationship.
+ *
+ * @param index DOCUMENT ME!
+ * @return the Node for the given index which will support the parent
+ * relationship or null if there is not a node at the given index.
+ */
+ Node getXPathResult(int index);
}
/*
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/ElementHandler.java b/fine-org-dom4j/src/main/java/org/dom4j/ElementHandler.java
index a03bf85c0..f195891fc 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/ElementHandler.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/ElementHandler.java
@@ -8,16 +8,15 @@
package org.dom4j;
/**
- *
* ElementHandler interface defines a handler of
* Element objects. It is used primarily in event based
* processing models such as for processing large XML documents as they are
* being parsed rather than waiting until the whole document is parsed.
- *
- *
+ *
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.8 $
*/
+@SuppressWarnings("unused")
public interface ElementHandler {
/**
* Called by an event based processor when an elements openning tag is
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/ElementPath.java b/fine-org-dom4j/src/main/java/org/dom4j/ElementPath.java
index 2d8784c7f..8ddfdf6cc 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/ElementPath.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/ElementPath.java
@@ -13,8 +13,9 @@ package org.dom4j;
* primary use is to retrieve the current {@link Element}being processed.
*
* @author Dave White
- * @version $Revision$
+ * @version $Revision: 1.6 $
*/
+@SuppressWarnings("unused")
public interface ElementPath {
/**
* DOCUMENT ME!
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/Entity.java b/fine-org-dom4j/src/main/java/org/dom4j/Entity.java
index 7c851691e..e79a8e70e 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/Entity.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/Entity.java
@@ -8,13 +8,12 @@
package org.dom4j;
/**
- *
* Namespace is a Flyweight Namespace that can be shared amongst
* nodes.
- *
- *
+ *
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.22 $
*/
public class Namespace extends AbstractNode {
/** Cache of Namespace instances */
@@ -51,6 +49,10 @@ public class Namespace extends AbstractNode {
public Namespace(String prefix, String uri) {
this.prefix = (prefix != null) ? prefix : "";
this.uri = (uri != null) ? uri : "";
+
+ if (!this.prefix.isEmpty()) {
+ QName.validateNCName(this.prefix);
+ }
}
/**
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/Node.java b/fine-org-dom4j/src/main/java/org/dom4j/Node.java
index fd11396cf..1cec5a3da 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/Node.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/Node.java
@@ -12,26 +12,21 @@ import java.io.Writer;
import java.util.List;
/**
- *
* Node defines the polymorphic behavior for all XML nodes in a
* dom4j tree.
- *
- *
- *
+ *
* A node can be output as its XML format, can be detached from its position in
* a document and can have XPath expressions evaluated on itself.
- *
- *
- *
+ *
* A node may optionally support the parent relationship and may be read only.
- *
- *
+ *
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.31 $
*
* @see #supportsParent
* @see #isReadOnly
*/
+@SuppressWarnings("unused")
public interface Node extends Cloneable {
// W3C DOM complient node type codes
@@ -381,7 +376,7 @@ public interface Node extends Cloneable {
* @return the list of Node or String
* instances depending on the XPath expression
*/
- List selectNodes(String xpathExpression);
+ List selectNodes(String xpathExpression);
/**
*
@@ -417,7 +412,7 @@ public interface Node extends Cloneable {
* @return the list of Node instances sorted by the
* comparisonXPathExpression
*/
- List selectNodes(String xpathExpression, String comparisonXPathExpression);
+ List selectNodes(String xpathExpression, String comparisonXPathExpression);
/**
*
@@ -438,7 +433,7 @@ public interface Node extends Cloneable {
* @return the list of Node instances sorted by the
* comparisonXPathExpression
*/
- List selectNodes(String xpathExpression, String comparisonXPathExpression,
+ List selectNodes(String xpathExpression, String comparisonXPathExpression,
boolean removeDuplicates);
/**
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/NodeFilter.java b/fine-org-dom4j/src/main/java/org/dom4j/NodeFilter.java
index 936143323..a5091b9f7 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/NodeFilter.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/NodeFilter.java
@@ -8,15 +8,14 @@
package org.dom4j;
/**
- *
* NodeFilter defines the behavior for a filter or predicate
* which acts on a DOM4J Node. Instances can be generated from an {@link
* DocumentFactory}.
- *
* ProcessingInstruction defines an XML processing instruction.
* The {@link Node#getName}method will return the target of the PI and the
* {@link Node#getText}method will return the data from all of the
* instructions.
- *
- *
+ *
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.10 $
*/
+@SuppressWarnings("unused")
public interface ProcessingInstruction extends Node {
/**
* This method is the equivalent to the {@link #getName}method. It is added
@@ -63,11 +62,11 @@ public interface ProcessingInstruction extends Node {
*
* @return the values for this processing instruction as a Map
*/
- Map getValues();
+ Map getValues();
void setValue(String name, String value);
- void setValues(Map data);
+ void setValues(Map data);
boolean removeValue(String name);
}
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/QName.java b/fine-org-dom4j/src/main/java/org/dom4j/QName.java
index 955c0d386..e9b2170e9 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/QName.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/QName.java
@@ -11,40 +11,114 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.util.regex.Pattern;
import org.dom4j.tree.QNameCache;
import org.dom4j.util.SingletonStrategy;
/**
- *
* QName represents a qualified name value of an XML element or
* attribute. It consists of a local name and a {@link Namespace}instance. This
* object is immutable.
- *
- *
+ *
* @author James Strachan
+ * @author Filip Jirsák
*/
public class QName implements Serializable {
/** The Singleton instance */
- private static SingletonStrategy singleton = null;
+ private static SingletonStrategy singleton = null;
+
+ /**
+ * {@code NameStartChar} without colon.
+ *
+ *
* Visitor is used to implement the Visitor
* pattern in DOM4J. An object of this interface can be passed to a
* Node which will then call its typesafe methods. Please refer
* to the Gang of Four book of Design Patterns for more details on the
* Visitor pattern.
- *
- *
- *
+ *
* This site
* has further discussion on design patterns and links to the GOF book. This link describes the
* Visitor pattern in detail.
- *
* VisitorSupport is an abstract base class which is useful for
* implementation inheritence or when using anonymous inner classes to create
* simple Visitor implementations.
- *
- * getText will return the textual version of the XPath
- * expression.
- *
- *
- * @return the textual format of the XPath expression.
- */
- String getText();
+ /**
+ * getText will return the textual version of the XPath
+ * expression.
+ *
+ * @return the textual format of the XPath expression.
+ */
+ String getText();
- /**
- *
- * matches returns true if the given node matches the XPath
- * expression. To be more precise when evaluating this XPath expression on
- * the given node the result set must include the node.
- *
- *
- * @param node
- * DOCUMENT ME!
- *
- * @return true if the given node matches this XPath expression
- */
- boolean matches(Node node);
+ /**
+ * matches returns true if the given node matches the XPath
+ * expression. To be more precise when evaluating this XPath expression on
+ * the given node the result set must include the node.
+ *
+ * @param node DOCUMENT ME!
+ * @return true if the given node matches this XPath expression
+ */
+ boolean matches(Node node);
- /**
- *
- * evaluate evaluates an XPath expression and returns the
- * result as an {@link Object}. The object returned can either be a {@link
- * List} of {@link Node}instances, a {@link Node}instance, a {@link
- * String} or a {@link Number}instance depending on the XPath expression.
- *
- *
- * @param context
- * is either a node or a list of nodes on which to evalute the
- * XPath
- *
- * @return the value of the XPath expression as a {@link List}of {@link
- * Node} instances, a {@link Node}instance, a {@link String}or a
- * {@link Number}instance depending on the XPath expression.
- */
- Object evaluate(Object context);
+ /**
+ * evaluate evaluates an XPath expression and returns the
+ * result as an {@link Object}. The object returned can either be a {@link
+ * List} of {@link Node}instances, a {@link Node}instance, a {@link
+ * String} or a {@link Number}instance depending on the XPath expression.
+ *
+ * @param context is either a node or a list of nodes on which to evalute the
+ * XPath
+ * @return the value of the XPath expression as a {@link List}of {@link
+ * Node} instances, a {@link Node}instance, a {@link String}or a
+ * {@link Number}instance depending on the XPath expression.
+ */
+ Object evaluate(Object context);
- /**
- *
- * selectObject evaluates an XPath expression and returns the
- * result as an {@link Object}. The object returned can either be a {@link
- * List} of {@link Node}instances, a {@link Node}instance, a {@link
- * String} or a {@link Number}instance depending on the XPath expression.
- *
- *
- * @param context
- * is either a node or a list of nodes on which to evalute the
- * XPath
- *
- * @return the value of the XPath expression as a {@link List}of {@link
- * Node} instances, a {@link Node}instance, a {@link String}or a
- * {@link Number}instance depending on the XPath expression.
- *
- * @deprecated please use evaluate(Object) instead. WILL BE REMOVED IN
- * dom4j-1.6 !!
- */
- Object selectObject(Object context);
+ /**
+ * selectObject evaluates an XPath expression and returns the
+ * result as an {@link Object}. The object returned can either be a {@link
+ * List} of {@link Node}instances, a {@link Node}instance, a {@link
+ * String} or a {@link Number}instance depending on the XPath expression.
+ *
+ * @param context is either a node or a list of nodes on which to evalute the
+ * XPath
+ * @return the value of the XPath expression as a {@link List}of {@link
+ * Node} instances, a {@link Node}instance, a {@link String}or a
+ * {@link Number}instance depending on the XPath expression.
+ * @deprecated please use evaluate(Object) instead. WILL BE REMOVED IN
+ * dom4j-1.6 !!
+ */
+ Object selectObject(Object context);
- /**
- *
- * selectNodes performs this XPath expression on the given
- * {@link Node}or {@link List}of {@link Node}s instances appending all
- * the results together into a single list.
- *
- *
- * @param context
- * is either a node or a list of nodes on which to evalute the
- * XPath
- *
- * @return the results of all the XPath evaluations as a single list
- */
- List selectNodes(Object context);
+ /**
+ * selectNodes performs this XPath expression on the given
+ * {@link Node}or {@link List}of {@link Node}s instances appending all
+ * the results together into a single list.
+ *
+ * @param context is either a node or a list of nodes on which to evalute the
+ * XPath
+ * @return the results of all the XPath evaluations as a single list
+ */
+ List selectNodes(Object context);
- /**
- *
- * selectNodes evaluates the XPath expression on the given
- * {@link Node}or {@link List}of {@link Node}s and returns the result as
- * a List of Node s sorted by the sort XPath
- * expression.
- *
- *
- * @param context
- * is either a node or a list of nodes on which to evalute the
- * XPath
- * @param sortXPath
- * is the XPath expression to sort by
- *
- * @return a list of Node instances
- */
- List selectNodes(Object context, XPath sortXPath);
+ /**
+ * selectNodes evaluates the XPath expression on the given
+ * {@link Node}or {@link List}of {@link Node}s and returns the result as
+ * a List of Node s sorted by the sort XPath
+ * expression.
+ *
+ * @param context is either a node or a list of nodes on which to evalute the
+ * XPath
+ * @param sortXPath is the XPath expression to sort by
+ * @return a list of Node instances
+ */
+ List selectNodes(Object context, XPath sortXPath);
- /**
- *
- * selectNodes evaluates the XPath expression on the given
- * {@link Node}or {@link List}of {@link Node}s and returns the result as
- * a List of Node s sorted by the sort XPath
- * expression.
- *
- *
- * @param context
- * is either a node or a list of nodes on which to evalute the
- * XPath
- * @param sortXPath
- * is the XPath expression to sort by
- * @param distinct
- * specifies whether or not duplicate values of the sort
- * expression are allowed. If this parameter is true then only
- * distinct sort expressions values are included in the result
- *
- * @return a list of Node instances
- */
- List selectNodes(Object context, XPath sortXPath, boolean distinct);
+ /**
+ * selectNodes evaluates the XPath expression on the given
+ * {@link Node}or {@link List}of {@link Node}s and returns the result as
+ * a List of Node s sorted by the sort XPath
+ * expression.
+ *
+ * @param context is either a node or a list of nodes on which to evalute the
+ * XPath
+ * @param sortXPath is the XPath expression to sort by
+ * @param distinct specifies whether or not duplicate values of the sort
+ * expression are allowed. If this parameter is true then only
+ * distinct sort expressions values are included in the result
+ * @return a list of Node instances
+ */
+ List selectNodes(Object context, XPath sortXPath, boolean distinct);
- /**
- *
- * selectSingleNode evaluates this XPath expression on the
- * given {@link Node}or {@link List}of {@link Node}s and returns the
- * result as a single Node instance.
- *
- *
- * @param context
- * is either a node or a list of nodes on which to evalute the
- * XPath
- *
- * @return a single matching Node instance
- */
- Node selectSingleNode(Object context);
+ /**
+ * selectSingleNode evaluates this XPath expression on the
+ * given {@link Node}or {@link List}of {@link Node}s and returns the
+ * result as a single Node instance.
+ *
+ * @param context is either a node or a list of nodes on which to evalute the
+ * XPath
+ * @return a single matching Node instance
+ */
+ Node selectSingleNode(Object context);
- /**
- *
- * valueOf evaluates this XPath expression and returns the
- * textual representation of the results using the XPath string() function.
- *
- *
- * @param context
- * is either a node or a list of nodes on which to evalute the
- * XPath
- *
- * @return the string representation of the results of the XPath expression
- */
- String valueOf(Object context);
+ /**
+ * valueOf evaluates this XPath expression and returns the
+ * textual representation of the results using the XPath string() function.
+ *
+ * @param context is either a node or a list of nodes on which to evalute the
+ * XPath
+ * @return the string representation of the results of the XPath expression
+ */
+ String valueOf(Object context);
- /**
- *
- * numberValueOf evaluates an XPath expression and returns
- * the numeric value of the XPath expression if the XPath expression results
- * is a number, or null if the result is not a number.
- *
- *
- * @param context
- * is either a node or a list of nodes on which to evalute the
- * XPath
- *
- * @return the numeric result of the XPath expression or null if the result
- * is not a number.
- */
- Number numberValueOf(Object context);
+ /**
+ * numberValueOf evaluates an XPath expression and returns
+ * the numeric value of the XPath expression if the XPath expression results
+ * is a number, or null if the result is not a number.
+ *
+ * @param context is either a node or a list of nodes on which to evalute the
+ * XPath
+ * @return the numeric result of the XPath expression or null if the result
+ * is not a number.
+ */
+ Number numberValueOf(Object context);
- /**
- * Retrieve a boolean-value interpretation of this XPath expression when
- * evaluated against a given context.
- *
- *
- * The boolean-value of the expression is determined per the
- * boolean(..) core function as defined in the XPath
- * specification. This means that an expression that selects zero nodes will
- * return false, while an expression that selects
- * one-or-more nodes will return true.
- *
- *
- * @param context
- * The node, nodeset or Context object for evaluation. This value
- * can be null
- *
- * @return The boolean-value interpretation of this expression.
- *
- * @since 1.5
- */
- boolean booleanValueOf(Object context);
+ /**
+ * Retrieve a boolean-value interpretation of this XPath expression when
+ * evaluated against a given context.
+ *
+ * The boolean-value of the expression is determined per the
+ * boolean(..) core function as defined in the XPath
+ * specification. This means that an expression that selects zero nodes will
+ * return false, while an expression that selects
+ * one-or-more nodes will return true.
+ *
+ * @param context The node, nodeset or Context object for evaluation. This value
+ * can be null
+ * @return The boolean-value interpretation of this expression.
+ * @since 1.5
+ */
+ boolean booleanValueOf(Object context);
- /**
- *
- * sort sorts the given List of Nodes using this XPath
- * expression as a {@link java.util.Comparator}.
- *
- *
- * @param list
- * is the list of Nodes to sort
- */
- void sort(List list);
+ /**
+ * sort sorts the given List of Nodes using this XPath
+ * expression as a {@link java.util.Comparator}.
+ *
+ * @param list is the list of Nodes to sort
+ */
+ void sort(List list);
- /**
- *
- * sort sorts the given List of Nodes using this XPath
- * expression as a {@link java.util.Comparator}and optionally removing
- * duplicates.
- *
- *
- * @param list
- * is the list of Nodes to sort
- * @param distinct
- * if true then duplicate values (using the sortXPath for
- * comparisions) will be removed from the List
- */
- void sort(List list, boolean distinct);
+ /**
+ * sort sorts the given List of Nodes using this XPath
+ * expression as a {@link java.util.Comparator}and optionally removing
+ * duplicates.
+ *
+ * @param list is the list of Nodes to sort
+ * @param distinct if true then duplicate values (using the sortXPath for
+ * comparisions) will be removed from the List
+ */
+ void sort(List list, boolean distinct);
- /**
- * DOCUMENT ME!
- *
- * @return the current function context
- */
- FunctionContext getFunctionContext();
+ /**
+ * DOCUMENT ME!
+ *
+ * @return the current function context
+ */
+ FunctionContext getFunctionContext();
- /**
- * Sets the function context to be used when evaluating XPath expressions
- *
- * @param functionContext
- * DOCUMENT ME!
- */
- void setFunctionContext(FunctionContext functionContext);
+ /**
+ * Sets the function context to be used when evaluating XPath expressions
+ *
+ * @param functionContext DOCUMENT ME!
+ */
+ void setFunctionContext(FunctionContext functionContext);
- /**
- * DOCUMENT ME!
- *
- * @return the current namespace context
- */
- NamespaceContext getNamespaceContext();
+ /**
+ * DOCUMENT ME!
+ *
+ * @return the current namespace context
+ */
+ NamespaceContext getNamespaceContext();
- /**
- * Sets the namespace context to be used when evaluating XPath expressions
- *
- * @param namespaceContext
- * DOCUMENT ME!
- */
- void setNamespaceContext(NamespaceContext namespaceContext);
+ /**
+ * Sets the namespace context to be used when evaluating XPath expressions
+ *
+ * @param namespaceContext DOCUMENT ME!
+ */
+ void setNamespaceContext(NamespaceContext namespaceContext);
- /**
- *
- * Sets the current NamespaceContext from a Map where the keys are the
- * String namespace prefixes and the values are the namespace URIs.
- *
- *
- * @param map
- * the map containing the namespace mappings
- */
- void setNamespaceURIs(Map map);
+ /**
+ * Sets the current NamespaceContext from a Map where the keys are the
+ * String namespace prefixes and the values are the namespace URIs.
+ *
+ * For example:
+ *
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.12 $
*/
public class DOMText extends DefaultText implements org.w3c.dom.Text {
public DOMText(String text) {
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/dom/package-info.java b/fine-org-dom4j/src/main/java/org/dom4j/dom/package-info.java
new file mode 100644
index 000000000..cb74834f1
--- /dev/null
+++ b/fine-org-dom4j/src/main/java/org/dom4j/dom/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * An implementation of the dom4j API which also supports the W3C object model.
+ */
+package org.dom4j.dom;
\ No newline at end of file
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/dom/package.html b/fine-org-dom4j/src/main/java/org/dom4j/dom/package.html
deleted file mode 100644
index b86c30f3b..000000000
--- a/fine-org-dom4j/src/main/java/org/dom4j/dom/package.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
An implementation of the dom4j API which also supports the
- W3C object model.
-
-
-
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/dtd/AttributeDecl.java b/fine-org-dom4j/src/main/java/org/dom4j/dtd/AttributeDecl.java
index 77f99eaaf..e20e7202c 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/dtd/AttributeDecl.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/dtd/AttributeDecl.java
@@ -13,9 +13,9 @@ package org.dom4j.dtd;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.7 $
*/
-public class AttributeDecl {
+public class AttributeDecl implements Decl {
/** Holds value of property elementName. */
private String elementName;
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/dtd/Decl.java b/fine-org-dom4j/src/main/java/org/dom4j/dtd/Decl.java
new file mode 100644
index 000000000..f05d32df5
--- /dev/null
+++ b/fine-org-dom4j/src/main/java/org/dom4j/dtd/Decl.java
@@ -0,0 +1,7 @@
+package org.dom4j.dtd;
+
+/**
+ * Created by filip on 5.7.15.
+ */
+public interface Decl {
+}
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/dtd/ElementDecl.java b/fine-org-dom4j/src/main/java/org/dom4j/dtd/ElementDecl.java
index 9447e1873..c4abb3f63 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/dtd/ElementDecl.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/dtd/ElementDecl.java
@@ -13,9 +13,9 @@ package org.dom4j.dtd;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.6 $
*/
-public class ElementDecl {
+public class ElementDecl implements Decl {
/** Holds value of property name. */
private String name;
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/dtd/ExternalEntityDecl.java b/fine-org-dom4j/src/main/java/org/dom4j/dtd/ExternalEntityDecl.java
index 645cbb642..c02da0381 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/dtd/ExternalEntityDecl.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/dtd/ExternalEntityDecl.java
@@ -14,9 +14,9 @@ package org.dom4j.dtd;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.9 $
*/
-public class ExternalEntityDecl {
+public class ExternalEntityDecl implements Decl {
/** Holds value of property name. */
private String name;
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/dtd/InternalEntityDecl.java b/fine-org-dom4j/src/main/java/org/dom4j/dtd/InternalEntityDecl.java
index d53fc96de..cd6d46ebc 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/dtd/InternalEntityDecl.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/dtd/InternalEntityDecl.java
@@ -14,9 +14,9 @@ package org.dom4j.dtd;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.9 $
*/
-public class InternalEntityDecl {
+public class InternalEntityDecl implements Decl {
/** Holds value of property name. */
private String name;
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/dtd/package-info.java b/fine-org-dom4j/src/main/java/org/dom4j/dtd/package-info.java
new file mode 100644
index 000000000..27b3cd690
--- /dev/null
+++ b/fine-org-dom4j/src/main/java/org/dom4j/dtd/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Classes to represent the DTD declarations. They are used inside the {@link org.dom4j.DocumentType} interface.
+ */
+package org.dom4j.dtd;
\ No newline at end of file
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/dtd/package.html b/fine-org-dom4j/src/main/java/org/dom4j/dtd/package.html
deleted file mode 100644
index af655947a..000000000
--- a/fine-org-dom4j/src/main/java/org/dom4j/dtd/package.html
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
Classes to represent the DTD declarations. They are used inside the {@link org.dom4j.DocumentType} interface.
-
-
-
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/DOMDocumentResult.java b/fine-org-dom4j/src/main/java/org/dom4j/io/DOMDocumentResult.java
new file mode 100644
index 000000000..5f579bbe3
--- /dev/null
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/DOMDocumentResult.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
+ *
+ * This software is open source.
+ * See the bottom of this file for the licence.
+ */
+
+package org.dom4j.io;
+
+import javax.xml.transform.sax.SAXResult;
+
+import org.w3c.dom.Document;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ *
+ * DOMDocumentResult implements a JAXP {@link SAXResult} for a
+ * {@link org.w3c.dom.Document}.
+ *
+ *
+ * @author James Strachan
+ * @author Todd Wolff
+ * @version $Revision: 1.1 $
+ */
+public class DOMDocumentResult extends SAXResult {
+ private DOMSAXContentHandler contentHandler;
+
+ public DOMDocumentResult() {
+ this(new DOMSAXContentHandler());
+ }
+
+ public DOMDocumentResult(DOMSAXContentHandler contentHandler) {
+ this.contentHandler = contentHandler;
+ super.setHandler(this.contentHandler);
+ super.setLexicalHandler(this.contentHandler);
+ }
+
+ /**
+ * Retrieves w3c dom object generated via transformation
+ *
+ * @return the Document created by the transformation
+ */
+ public Document getDocument() {
+ return contentHandler.getDocument();
+ }
+
+ // Overloaded methods
+ // -------------------------------------------------------------------------
+ public void setHandler(ContentHandler handler) {
+ if (handler instanceof DOMSAXContentHandler) {
+ this.contentHandler = (DOMSAXContentHandler) handler;
+ super.setHandler(this.contentHandler);
+ }
+ }
+
+ public void setLexicalHandler(LexicalHandler handler) {
+ if (handler instanceof DOMSAXContentHandler) {
+ this.contentHandler = (DOMSAXContentHandler) handler;
+ super.setLexicalHandler(this.contentHandler);
+ }
+ }
+
+}
+
+/*
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided that the
+ * following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright statements and
+ * notices. Redistributions must also contain a copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The name "DOM4J" must not be used to endorse or promote products derived
+ * from this Software without prior written permission of MetaStuff, Ltd. For
+ * written permission, please contact dom4j-info@metastuff.com.
+ *
+ * 4. Products derived from this Software may not be called "DOM4J" nor may
+ * "DOM4J" appear in their names without prior written permission of MetaStuff,
+ * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
+ *
+ * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
+ *
+ * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
+ */
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/DOMReader.java b/fine-org-dom4j/src/main/java/org/dom4j/io/DOMReader.java
index 7debed853..0fc85a951 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/DOMReader.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/DOMReader.java
@@ -10,12 +10,8 @@ package org.dom4j.io;
import java.util.ArrayList;
import java.util.List;
-import org.dom4j.Branch;
-import org.dom4j.Document;
-import org.dom4j.DocumentFactory;
-import org.dom4j.Element;
-import org.dom4j.Namespace;
-import org.dom4j.QName;
+import org.dom4j.*;
+import org.dom4j.dom.DOMAttribute;
import org.dom4j.tree.NamespaceStack;
/**
@@ -25,7 +21,7 @@ import org.dom4j.tree.NamespaceStack;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.17 $
*/
public class DOMReader {
/** DocumentFactory used to create new document objects */
@@ -201,11 +197,10 @@ public class DOMReader {
if (attributeList != null) {
int size = attributeList.getLength();
- List attributes = new ArrayList(size);
+ List attributes = new ArrayList(size);
for (int i = 0; i < size; i++) {
org.w3c.dom.Node attribute = attributeList.item(i);
-
// Define all namespaces first then process attributes later
String name = attribute.getNodeName();
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/DOMSAXContentHandler.java b/fine-org-dom4j/src/main/java/org/dom4j/io/DOMSAXContentHandler.java
new file mode 100644
index 000000000..821590c9b
--- /dev/null
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/DOMSAXContentHandler.java
@@ -0,0 +1,548 @@
+/*
+ * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
+ *
+ * This software is open source.
+ * See the bottom of this file for the licence.
+ */
+
+package org.dom4j.io;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.dom4j.Branch;
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
+import org.dom4j.dom.DOMAttribute;
+import org.dom4j.dom.DOMCDATA;
+import org.dom4j.dom.DOMComment;
+import org.dom4j.dom.DOMDocumentFactory;
+import org.dom4j.dom.DOMElement;
+import org.dom4j.dom.DOMText;
+import org.dom4j.tree.NamespaceStack;
+import org.w3c.dom.ProcessingInstruction;
+import org.xml.sax.Attributes;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.ext.Locator2;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ *
+ * SAXContentHandler builds W3C DOM object via SAX events.
+ *
+ * @author James Strachan
+ * @author Todd Wolff
+ *
+ *
+ */
+public class DOMSAXContentHandler extends DefaultHandler implements LexicalHandler {
+
+ /** The factory used to create new Document instances */
+ private DOMDocumentFactory documentFactory;
+
+ /** The document that is being built */
+ private Document document;
+
+ /** stack of Element objects */
+ private ElementStack elementStack;
+
+ /** stack of Namespace and QName objects */
+ private NamespaceStack namespaceStack;
+
+ /** the Locator */
+ private Locator locator;
+
+ /** Flag used to indicate that we are inside a CDATA section */
+ private boolean insideCDATASection;
+
+ /**
+ * buffer to hold contents of cdata section across multiple characters
+ * events
+ */
+ private StringBuffer cdataText;
+
+ /** The number of namespaces that are declared in the current scope */
+ private int declaredNamespaceIndex;
+
+ private InputSource inputSource;
+
+ /** The current element we are on */
+ private Element currentElement;
+
+ /** The entity resolver */
+ private EntityResolver entityResolver;
+
+ /** Whether adjacent text nodes should be merged */
+ private boolean mergeAdjacentText = false;
+
+ /** Have we added text to the buffer */
+ private boolean textInTextBuffer = false;
+
+ /** Should we ignore comments */
+ private boolean ignoreComments = false;
+
+ /** Buffer used to concatenate text together */
+ private StringBuffer textBuffer;
+
+ /** Holds value of property stripWhitespaceText. */
+ private boolean stripWhitespaceText = false;
+
+ public DOMSAXContentHandler() {
+ this((DOMDocumentFactory)DOMDocumentFactory.getInstance());
+ }
+
+ public DOMSAXContentHandler(DOMDocumentFactory documentFactory) {
+ this.documentFactory = documentFactory;
+ this.elementStack = createElementStack();
+ this.namespaceStack = new NamespaceStack(documentFactory);
+ }
+
+ /**
+ * Retrieves w3c document object built via generated sax events.
+ *
+ * @return the document that has been or is being built
+ */
+ public org.w3c.dom.Document getDocument() {
+ if (document == null) {
+ document = createDocument();
+ }
+
+ return (org.w3c.dom.Document)document;
+ }
+
+ // ContentHandler interface
+ // -------------------------------------------------------------------------
+ public void setDocumentLocator(Locator documentLocator) {
+ this.locator = documentLocator;
+ }
+
+ public void processingInstruction(String target, String data)
+ throws SAXException {
+ if (mergeAdjacentText && textInTextBuffer) {
+ completeCurrentTextNode();
+ }
+ ProcessingInstruction pi = (ProcessingInstruction)documentFactory.createProcessingInstruction(target, data);
+ if (currentElement != null) {
+ ((org.w3c.dom.Element)currentElement).appendChild(pi);
+ } else {
+ getDocument().appendChild(pi);
+ }
+ }
+
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException {
+ namespaceStack.push(prefix, uri);
+ }
+
+ public void endPrefixMapping(String prefix) throws SAXException {
+ namespaceStack.pop(prefix);
+ declaredNamespaceIndex = namespaceStack.size();
+ }
+
+ public void startDocument() throws SAXException {
+ document = null;
+ currentElement = null;
+
+ elementStack.clear();
+
+ namespaceStack.clear();
+ declaredNamespaceIndex = 0;
+
+ if (mergeAdjacentText && (textBuffer == null)) {
+ textBuffer = new StringBuffer();
+ }
+
+ textInTextBuffer = false;
+ }
+
+ public void endDocument() throws SAXException {
+ namespaceStack.clear();
+ elementStack.clear();
+ currentElement = null;
+ textBuffer = null;
+ }
+
+ public void startElement(String namespaceURI, String localName,
+ String qualifiedName, Attributes attributes) throws SAXException {
+ if (mergeAdjacentText && textInTextBuffer) {
+ completeCurrentTextNode();
+ }
+
+ QName qName = namespaceStack.getQName(namespaceURI, localName,
+ qualifiedName);
+
+ Branch branch = currentElement;
+
+ if (branch == null) {
+ branch = (org.dom4j.Document)getDocument();
+ }
+
+ Element element = new DOMElement(qName);
+ branch.add(element);
+
+ // add all declared namespaces
+ addDeclaredNamespaces(element);
+
+ // now lets add all attribute values
+ addAttributes(element, attributes);
+
+ elementStack.pushElement(element);
+ currentElement = element;
+
+ }
+
+ public void endElement(String namespaceURI, String localName, String qName)
+ throws SAXException {
+ if (mergeAdjacentText && textInTextBuffer) {
+ completeCurrentTextNode();
+ }
+
+ elementStack.popElement();
+ currentElement = elementStack.peekElement();
+ }
+
+ public void characters(char[] ch, int start, int end) throws SAXException {
+ if (end == 0) {
+ return;
+ }
+
+ if (currentElement != null) {
+ if (insideCDATASection) {
+ if (mergeAdjacentText && textInTextBuffer) {
+ completeCurrentTextNode();
+ }
+ cdataText.append(new String(ch, start, end));
+ } else {
+ if (mergeAdjacentText) {
+ textBuffer.append(ch, start, end);
+ textInTextBuffer = true;
+ } else {
+ DOMText text = new DOMText(new String(ch, start, end));
+ ((DOMElement)currentElement).add(text);
+ }
+ }
+ }
+ }
+
+ // ErrorHandler interface
+ // -------------------------------------------------------------------------
+
+ /**
+ * This method is called when a warning occurs during the parsing of the
+ * document. This method does nothing.
+ *
+ * @param exception
+ * DOCUMENT ME!
+ *
+ * @throws SAXException
+ * DOCUMENT ME!
+ */
+ public void warning(SAXParseException exception) throws SAXException {
+ // ignore warnings by default
+ }
+
+ /**
+ * This method is called when an error is detected during parsing such as a
+ * validation error. This method rethrows the exception
+ *
+ * @param exception
+ * DOCUMENT ME!
+ *
+ * @throws SAXException
+ * DOCUMENT ME!
+ */
+ public void error(SAXParseException exception) throws SAXException {
+ throw exception;
+ }
+
+ /**
+ * This method is called when a fatal error occurs during parsing. This
+ * method rethrows the exception
+ *
+ * @param exception
+ * DOCUMENT ME!
+ *
+ * @throws SAXException
+ * DOCUMENT ME!
+ */
+ public void fatalError(SAXParseException exception) throws SAXException {
+ throw exception;
+ }
+
+ // LexicalHandler interface
+ // -------------------------------------------------------------------------
+ public void startDTD(String name, String publicId, String systemId)
+ throws SAXException {
+ // not supported
+ }
+
+ public void endDTD() throws SAXException {
+ // not supported
+ }
+
+ public void startEntity(String name) throws SAXException {
+ // not supported
+ }
+
+ public void endEntity(String name) throws SAXException {
+ // not supported
+ }
+
+ public void startCDATA() throws SAXException {
+ insideCDATASection = true;
+ cdataText = new StringBuffer();
+ }
+
+ public void endCDATA() throws SAXException {
+ insideCDATASection = false;
+ DOMCDATA cdata = new DOMCDATA(cdataText.toString());
+ ((DOMElement)currentElement).add(cdata);
+ }
+
+ public void comment(char[] ch, int start, int end) throws SAXException {
+ if (!ignoreComments) {
+ if (mergeAdjacentText && textInTextBuffer) {
+ completeCurrentTextNode();
+ }
+
+ String text = new String(ch, start, end);
+
+ if (text.length() > 0) {
+ DOMComment domComment = new DOMComment(text);
+ if (currentElement != null) {
+ ((DOMElement)currentElement).add(domComment);
+ } else {
+ getDocument().appendChild(domComment);
+ }
+ }
+ }
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+ public ElementStack getElementStack() {
+ return elementStack;
+ }
+
+ public void setElementStack(ElementStack elementStack) {
+ this.elementStack = elementStack;
+ }
+
+ public EntityResolver getEntityResolver() {
+ return entityResolver;
+ }
+
+ public void setEntityResolver(EntityResolver entityResolver) {
+ this.entityResolver = entityResolver;
+ }
+
+ public InputSource getInputSource() {
+ return inputSource;
+ }
+
+ public void setInputSource(InputSource inputSource) {
+ this.inputSource = inputSource;
+ }
+
+ /**
+ * Returns whether adjacent text nodes should be merged together.
+ *
+ * @return Value of property mergeAdjacentText.
+ */
+ public boolean isMergeAdjacentText() {
+ return mergeAdjacentText;
+ }
+
+ /**
+ * Sets whether or not adjacent text nodes should be merged together when
+ * parsing.
+ *
+ * @param mergeAdjacentText
+ * New value of property mergeAdjacentText.
+ */
+ public void setMergeAdjacentText(boolean mergeAdjacentText) {
+ this.mergeAdjacentText = mergeAdjacentText;
+ }
+
+ /**
+ * Sets whether whitespace between element start and end tags should be
+ * ignored
+ *
+ * @return Value of property stripWhitespaceText.
+ */
+ public boolean isStripWhitespaceText() {
+ return stripWhitespaceText;
+ }
+
+ /**
+ * Sets whether whitespace between element start and end tags should be
+ * ignored.
+ *
+ * @param stripWhitespaceText
+ * New value of property stripWhitespaceText.
+ */
+ public void setStripWhitespaceText(boolean stripWhitespaceText) {
+ this.stripWhitespaceText = stripWhitespaceText;
+ }
+
+ /**
+ * Returns whether we should ignore comments or not.
+ *
+ * @return boolean
+ */
+ public boolean isIgnoreComments() {
+ return ignoreComments;
+ }
+
+ /**
+ * Sets whether we should ignore comments or not.
+ *
+ * @param ignoreComments
+ * whether we should ignore comments or not.
+ */
+ public void setIgnoreComments(boolean ignoreComments) {
+ this.ignoreComments = ignoreComments;
+ }
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+
+ protected void completeCurrentTextNode() {
+ if (stripWhitespaceText) {
+ boolean whitespace = true;
+ for (int i = 0, size = textBuffer.length(); i < size; i++) {
+ if (!Character.isWhitespace(textBuffer.charAt(i))) {
+ whitespace = false;
+
+ break;
+ }
+ }
+ if (!whitespace) {
+ DOMText domText = new DOMText(textBuffer.toString());
+ ((DOMElement)currentElement).add(domText);
+ }
+ } else {
+ DOMText domText = new DOMText(textBuffer.toString());
+ ((DOMElement)currentElement).add(domText);
+ }
+
+ textBuffer.setLength(0);
+ textInTextBuffer = false;
+ }
+
+ protected Document createDocument() {
+ String encoding = getEncoding();
+ Document doc = documentFactory.createDocument(encoding);
+
+ // set the EntityResolver
+ doc.setEntityResolver(entityResolver);
+
+ if (inputSource != null) {
+ doc.setName(inputSource.getSystemId());
+ }
+
+ return doc;
+ }
+
+ private String getEncoding() {
+ if (locator == null) {
+ return null;
+ }
+
+ if (locator instanceof Locator2) {
+ return ((Locator2) locator).getEncoding();
+ }
+
+ // couldn't determine encoding, returning null...
+ return null;
+ }
+
+ protected void addDeclaredNamespaces(Element element) {
+ for (int size = namespaceStack.size(); declaredNamespaceIndex < size;
+ declaredNamespaceIndex++) {
+ Namespace namespace = namespaceStack
+ .getNamespace(declaredNamespaceIndex);
+ String attributeName = attributeNameForNamespace(namespace);
+ ((DOMElement)element).setAttribute(attributeName, namespace.getURI());
+ }
+ }
+
+ protected void addAttributes(Element element, Attributes attributes) {
+ int size = attributes.getLength();
+ for (int i = 0; i < size; i++) {
+ String attributeQName = attributes.getQName(i);
+ if (!attributeQName.startsWith("xmlns")) {
+ String attributeURI = attributes.getURI(i);
+ String attributeLocalName = attributes.getLocalName(i);
+ String attributeValue = attributes.getValue(i);
+ QName qName = namespaceStack.getAttributeQName(
+ attributeURI, attributeLocalName, attributeQName);
+ DOMAttribute domAttribute = new DOMAttribute(qName, attributeValue);
+ ((DOMElement)element).setAttributeNode(domAttribute);
+ }
+ }
+ }
+
+ protected ElementStack createElementStack() {
+ return new ElementStack();
+ }
+
+ protected String attributeNameForNamespace(Namespace namespace) {
+ String xmlns = "xmlns";
+ String prefix = namespace.getPrefix();
+
+ if (prefix.length() > 0) {
+ return xmlns + ":" + prefix;
+ }
+
+ return xmlns;
+ }
+
+}
+
+/*
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided that the
+ * following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright statements and
+ * notices. Redistributions must also contain a copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The name "DOM4J" must not be used to endorse or promote products derived
+ * from this Software without prior written permission of MetaStuff, Ltd. For
+ * written permission, please contact dom4j-info@metastuff.com.
+ *
+ * 4. Products derived from this Software may not be called "DOM4J" nor may
+ * "DOM4J" appear in their names without prior written permission of MetaStuff,
+ * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
+ *
+ * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
+ *
+ * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
+ */
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/DOMWriter.java b/fine-org-dom4j/src/main/java/org/dom4j/io/DOMWriter.java
index aa911be0f..a074dbe51 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/DOMWriter.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/DOMWriter.java
@@ -9,28 +9,18 @@ package org.dom4j.io;
import java.util.List;
-import org.dom4j.Attribute;
-import org.dom4j.CDATA;
-import org.dom4j.Comment;
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.Element;
-import org.dom4j.Entity;
-import org.dom4j.Namespace;
-import org.dom4j.ProcessingInstruction;
-import org.dom4j.Text;
+import org.dom4j.*;
+import org.dom4j.dtd.Decl;
import org.dom4j.tree.NamespaceStack;
import org.w3c.dom.DOMImplementation;
/**
- *
* DOMWriter takes a DOM4J tree and outputs it as a W3C DOM
* object
- *
- *
+ *
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.17 $
*/
public class DOMWriter {
private static boolean loggedWarning = false;
@@ -46,7 +36,7 @@ public class DOMWriter {
};
// the Class used to create new DOM Document instances
- private Class domDocumentClass;
+ private Class> domDocumentClass;
/** stack of Namespace objects */
private NamespaceStack namespaceStack = new NamespaceStack();
@@ -54,20 +44,19 @@ public class DOMWriter {
public DOMWriter() {
}
- public DOMWriter(Class domDocumentClass) {
+ public DOMWriter(Class> domDocumentClass) {
this.domDocumentClass = domDocumentClass;
}
- public Class getDomDocumentClass() throws DocumentException {
- Class result = domDocumentClass;
+ public Class> getDomDocumentClass() throws DocumentException {
+ Class> result = domDocumentClass;
if (result == null) {
// lets try and find one in the classpath
int size = DEFAULT_DOM_DOCUMENT_CLASSES.length;
- for (int i = 0; i < size; i++) {
+ for (String name : DEFAULT_DOM_DOCUMENT_CLASSES) {
try {
- String name = DEFAULT_DOM_DOCUMENT_CLASSES[i];
result = Class.forName(name, true, DOMWriter.class
.getClassLoader());
@@ -89,10 +78,10 @@ public class DOMWriter {
* the writer when creating DOM documents.
*
* @param domDocumentClass
- * is the Class implementing the {@linkorg.w3c.dom.Document}
+ * is the Class implementing the {@link org.w3c.dom.Document}
* interface
*/
- public void setDomDocumentClass(Class domDocumentClass) {
+ public void setDomDocumentClass(Class> domDocumentClass) {
this.domDocumentClass = domDocumentClass;
}
@@ -148,28 +137,22 @@ public class DOMWriter {
}
protected void appendDOMTree(org.w3c.dom.Document domDocument,
- org.w3c.dom.Node domCurrent, List content) {
- int size = content.size();
-
- for (int i = 0; i < size; i++) {
- Object object = content.get(i);
-
- if (object instanceof Element) {
- appendDOMTree(domDocument, domCurrent, (Element) object);
- } else if (object instanceof String) {
- appendDOMTree(domDocument, domCurrent, (String) object);
- } else if (object instanceof Text) {
- Text text = (Text) object;
+ org.w3c.dom.Node domCurrent, List content) {
+ for (Node node : content) {
+ if (node instanceof Element) {
+ appendDOMTree(domDocument, domCurrent, (Element) node);
+ } else if (node instanceof Text) {
+ Text text = (Text) node;
appendDOMTree(domDocument, domCurrent, text.getText());
- } else if (object instanceof CDATA) {
- appendDOMTree(domDocument, domCurrent, (CDATA) object);
- } else if (object instanceof Comment) {
- appendDOMTree(domDocument, domCurrent, (Comment) object);
- } else if (object instanceof Entity) {
- appendDOMTree(domDocument, domCurrent, (Entity) object);
- } else if (object instanceof ProcessingInstruction) {
+ } else if (node instanceof CDATA) {
+ appendDOMTree(domDocument, domCurrent, (CDATA) node);
+ } else if (node instanceof Comment) {
+ appendDOMTree(domDocument, domCurrent, (Comment) node);
+ } else if (node instanceof Entity) {
+ appendDOMTree(domDocument, domCurrent, (Entity) node);
+ } else if (node instanceof ProcessingInstruction) {
appendDOMTree(domDocument, domCurrent,
- (ProcessingInstruction) object);
+ (ProcessingInstruction) node);
}
}
}
@@ -192,7 +175,7 @@ public class DOMWriter {
}
// add the additional declared namespaces
- List declaredNamespaces = element.declaredNamespaces();
+ List declaredNamespaces = element.declaredNamespaces();
for (int i = 0, size = declaredNamespaces.size(); i < size; i++) {
Namespace namespace = (Namespace) declaredNamespaces.get(i);
@@ -204,8 +187,7 @@ public class DOMWriter {
}
// add the attributes
- for (int i = 0, size = element.attributeCount(); i < size; i++) {
- Attribute attribute = (Attribute) element.attribute(i);
+ for (Attribute attribute : element.attributes()) {
String attUri = attribute.getNamespaceURI();
String attName = attribute.getQualifiedName();
String value = attribute.getValue();
@@ -294,7 +276,7 @@ public class DOMWriter {
result = createDomDocumentViaJAXP();
if (result == null) {
- Class theClass = getDomDocumentClass();
+ Class> theClass = getDomDocumentClass();
try {
result = (org.w3c.dom.Document) theClass.newInstance();
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/DispatchHandler.java b/fine-org-dom4j/src/main/java/org/dom4j/io/DispatchHandler.java
index b712b5b3e..a2ec88acb 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/DispatchHandler.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/DispatchHandler.java
@@ -27,7 +27,7 @@ import org.dom4j.ElementPath;
*
*
* @author Dave White
- * @version $Revision$
+ * @version $Revision: 1.11 $
*/
class DispatchHandler implements ElementHandler {
/** Whether the parser is at the root element or not */
@@ -37,16 +37,16 @@ class DispatchHandler implements ElementHandler {
private String path;
/** maintains a stack of previously encountered paths */
- private ArrayList pathStack;
+ private ArrayList pathStack;
/** maintains a stack of previously encountered handlers */
- private ArrayList handlerStack;
+ private ArrayList handlerStack;
/**
* HashMap maintains the mapping between element paths and
* handlers
*/
- private HashMap handlers;
+ private HashMap handlers;
/**
* ElementHandler to use by default for element paths with no
@@ -57,9 +57,9 @@ class DispatchHandler implements ElementHandler {
public DispatchHandler() {
atRoot = true;
path = "/";
- pathStack = new ArrayList();
- handlerStack = new ArrayList();
- handlers = new HashMap();
+ pathStack = new ArrayList();
+ handlerStack = new ArrayList();
+ handlers = new HashMap();
}
/**
@@ -86,7 +86,7 @@ class DispatchHandler implements ElementHandler {
* @return DOCUMENT ME!
*/
public ElementHandler removeHandler(String handlerPath) {
- return (ElementHandler) handlers.remove(handlerPath);
+ return handlers.remove(handlerPath);
}
/**
@@ -111,7 +111,7 @@ class DispatchHandler implements ElementHandler {
* @return the registered handler
*/
public ElementHandler getHandler(String handlerPath) {
- return (ElementHandler) handlers.get(handlerPath);
+ return handlers.get(handlerPath);
}
/**
@@ -177,7 +177,7 @@ class DispatchHandler implements ElementHandler {
if ((handlers != null) && (handlers.containsKey(path))) {
// The current node has a handler associated with it.
// Find the handler and save it on the handler stack.
- ElementHandler handler = (ElementHandler) handlers.get(path);
+ ElementHandler handler = handlers.get(path);
handlerStack.add(handler);
// Call the handlers onStart method.
@@ -195,7 +195,7 @@ class DispatchHandler implements ElementHandler {
if ((handlers != null) && (handlers.containsKey(path))) {
// This node has a handler associated with it.
// Find the handler and pop it from the handler stack.
- ElementHandler handler = (ElementHandler) handlers.get(path);
+ ElementHandler handler = handlers.get(path);
handlerStack.remove(handlerStack.size() - 1);
// Call the handlers onEnd method
@@ -209,7 +209,7 @@ class DispatchHandler implements ElementHandler {
}
// Set path back to its parent
- path = (String) pathStack.remove(pathStack.size() - 1);
+ path = pathStack.remove(pathStack.size() - 1);
if (pathStack.size() == 0) {
atRoot = true;
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/DocumentInputSource.java b/fine-org-dom4j/src/main/java/org/dom4j/io/DocumentInputSource.java
index a24bbb92c..35c8ece51 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/DocumentInputSource.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/DocumentInputSource.java
@@ -23,7 +23,7 @@ import org.xml.sax.InputSource;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.8 $
*/
class DocumentInputSource extends InputSource {
/** The document source */
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/DocumentResult.java b/fine-org-dom4j/src/main/java/org/dom4j/io/DocumentResult.java
index efca88575..3bca881ba 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/DocumentResult.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/DocumentResult.java
@@ -21,7 +21,7 @@ import org.xml.sax.ext.LexicalHandler;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.8 $
*/
public class DocumentResult extends SAXResult {
private SAXContentHandler contentHandler;
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/DocumentSource.java b/fine-org-dom4j/src/main/java/org/dom4j/io/DocumentSource.java
index 2745d6cfa..1cc206930 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/DocumentSource.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/DocumentSource.java
@@ -17,13 +17,11 @@ import org.xml.sax.XMLFilter;
import org.xml.sax.XMLReader;
/**
- *
* DocumentSource implements a JAXP {@link SAXSource}for a
- * {@linkDocument}.
- *
- *
+ * {@link Document}.
+ *
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.10 $
*/
public class DocumentSource extends SAXSource {
/**
@@ -93,7 +91,7 @@ public class DocumentSource extends SAXSource {
}
/**
- * This method is not supported as this source is always a {@linkDocument}
+ * This method is not supported as this source is always a {@link Document}
* instance.
*
* @param inputSource
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/ElementStack.java b/fine-org-dom4j/src/main/java/org/dom4j/io/ElementStack.java
index 6466ac03d..1284dd2aa 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/ElementStack.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/ElementStack.java
@@ -20,7 +20,7 @@ import org.dom4j.ElementPath;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.14 $
*/
class ElementStack implements ElementPath {
/** stack of Element objects */
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/HTMLWriter.java b/fine-org-dom4j/src/main/java/org/dom4j/io/HTMLWriter.java
index 3a0b2316f..719d822e9 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/HTMLWriter.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/HTMLWriter.java
@@ -26,25 +26,21 @@ import org.dom4j.Node;
import org.xml.sax.SAXException;
/**
- *
* HTMLWriter takes a DOM4J tree and formats it to a stream as
* HTML. This formatter is similar to XMLWriter but it outputs the text of CDATA
* and Entity sections rather than the serialised format as in XML, it has an
* XHTML mode, it retains whitespace in certain elements such as <PRE>,
* and it supports certain elements which have no corresponding close tag such
* as for <BR> and <P>.
- *
- *
- *
+ *
* The OutputFormat passed in to the constructor is checked for isXHTML() and
* isExpandEmptyElements(). See {@link OutputFormat OutputFormat}for details.
* Here are the rules for this class based on an OutputFormat, "format",
- * passed in to the constructor:
+ * passed in to the constructor:
*
*
*
If an element is in {@link #getOmitElementCloseSet()
* getOmitElementCloseSet}, then it is treated specially:
- *
*
*
It never expands, since some browsers treat this as two separate
* Horizontal Rules: <HR></HR>
@@ -54,7 +50,6 @@ import org.xml.sax.SAXException;
* "/", but that's better than when it refuses to recognize this: <hr/>
* which it thinks is an element named "HR/".
*
- *
*
*
If {@link org.dom4j.io.OutputFormat#isXHTML() format.isXHTML()}, all
* elements must have either a close element, or be a closed single tag.
@@ -62,41 +57,21 @@ import org.xml.sax.SAXException;
* format.isExpandEmptyElements()}() is true, all elements are expanded except
* as above.
*
- *
* Examples
- *
- *
- *
- *
- *
- *
* If isXHTML == true, CDATA sections look like this:
- *
- *
+
+ * Basically, {@link OutputFormat#isXHTML()} ==
* true will produce valid XML, while {@link
- * org.dom4j.io.OutputFormat#isExpandEmptyElements()
- * format.isExpandEmptyElements()} determines whether empty elements are
+ * OutputFormat#isExpandEmptyElements()} determines whether empty elements are
* expanded if isXHTML is true, excepting the special HTML single tags.
- *
- *
- *
+ *
* Also, HTMLWriter handles tags whose contents should be preformatted, that is,
* whitespace-preserved. By default, this set includes the tags <PRE>,
* <SCRIPT>, <STYLE>, and <TEXTAREA>, case insensitively. It
@@ -107,29 +82,15 @@ import org.xml.sax.SAXException;
* However, the parser you use may store comments with linefeed-only text nodes
* (\n) even if your platform uses another line.separator character, and
* HTMLWriter outputs Comment nodes exactly as the DOM is set up by the parser.
- * See examples and discussion here: {@link#setPreformattedTags(java.util.Set)
- * setPreformattedTags}
- *
- *
- *
+ * See examples and discussion here: {@link #setPreformattedTags(java.util.Set)}
+ *
* Examples
- *
- *
- *
* Pretty Printing
- *
- *
- *
* This example shows how to pretty print a string containing a valid HTML
* document to a string. You can also just call the static methods of this
- * class:
- * {@link #prettyPrintHTML(String) prettyPrintHTML(String)}or
- * {@link #prettyPrintHTML(String,boolean,boolean,boolean,boolean)
- * prettyPrintHTML(String,boolean,boolean,boolean,boolean)} or,
- * {@link #prettyPrintXHTML(String) prettyPrintXHTML(String)}for XHTML (note
- * the X)
- *
- *
+ * class: {@link #prettyPrintHTML(String)}or {@link #prettyPrintHTML(String,boolean,boolean,boolean,boolean)}
+ * or {@link #prettyPrintXHTML(String)} for XHTML (note the X)
+ *
*
* This example shows how to create a "squeezed" document, but one that will
* work in browsers even if the browser line length is limited. No newlines are
* included, no extra whitespace at all, except where it it required by
* {@link #setPreformattedTags(java.util.Set) setPreformattedTags}.
- *
- *
+ *
* @author James Strachan
* @author Laramie Crocker
- * @version $Revision$
+ * @version $Revision: 1.21 $
*/
public class HTMLWriter extends XMLWriter {
private static String lineSeparator = System.getProperty("line.separator");
- protected static final HashSet DEFAULT_PREFORMATTED_TAGS;
+ protected static final HashSet DEFAULT_PREFORMATTED_TAGS;
static {
// If you change this list, update the javadoc examples, above in the
// class javadoc, in writeElement, and in setPreformattedTags().
- DEFAULT_PREFORMATTED_TAGS = new HashSet();
+ DEFAULT_PREFORMATTED_TAGS = new HashSet();
DEFAULT_PREFORMATTED_TAGS.add("PRE");
DEFAULT_PREFORMATTED_TAGS.add("SCRIPT");
DEFAULT_PREFORMATTED_TAGS.add("STYLE");
@@ -201,7 +158,7 @@ public class HTMLWriter extends XMLWriter {
DEFAULT_HTML_FORMAT.setSuppressDeclaration(true);
}
- private Stack formatStack = new Stack();
+ private Stack formatStack = new Stack();
private String lastText = "";
@@ -210,13 +167,13 @@ public class HTMLWriter extends XMLWriter {
// legal values are 0+, but -1 signifies lazy initialization.
private int newLineAfterNTags = -1;
- private HashSet preformattedTags = DEFAULT_PREFORMATTED_TAGS;
+ private HashSet preformattedTags = DEFAULT_PREFORMATTED_TAGS;
/**
* Used to store the qualified element names which should have no close
* element tag
*/
- private HashSet omitElementCloseSet;
+ private HashSet omitElementCloseSet;
public HTMLWriter(Writer writer) {
super(writer, DEFAULT_HTML_FORMAT);
@@ -349,9 +306,9 @@ public class HTMLWriter extends XMLWriter {
qualifiedName.toUpperCase());
}
- private HashSet internalGetOmitElementCloseSet() {
+ private HashSet internalGetOmitElementCloseSet() {
if (omitElementCloseSet == null) {
- omitElementCloseSet = new HashSet();
+ omitElementCloseSet = new HashSet();
loadOmitElementCloseSet(omitElementCloseSet);
}
@@ -359,7 +316,7 @@ public class HTMLWriter extends XMLWriter {
}
// If you change this, change the javadoc for getOmitElementCloseSet.
- protected void loadOmitElementCloseSet(Set set) {
+ protected void loadOmitElementCloseSet(Set set) {
set.add("AREA");
set.add("BASE");
set.add("BR");
@@ -382,8 +339,8 @@ public class HTMLWriter extends XMLWriter {
*
* @return A clone of the Set.
*/
- public Set getOmitElementCloseSet() {
- return (Set) (internalGetOmitElementCloseSet().clone());
+ public Set getOmitElementCloseSet() {
+ return (Set) (internalGetOmitElementCloseSet().clone());
}
/**
@@ -402,21 +359,17 @@ public class HTMLWriter extends XMLWriter {
* @param newSet
* DOCUMENT ME!
*/
- public void setOmitElementCloseSet(Set newSet) {
+ public void setOmitElementCloseSet(Set newSet) {
// resets, and safely empties it out if newSet is null.
- omitElementCloseSet = new HashSet();
+ omitElementCloseSet = new HashSet();
if (newSet != null) {
- omitElementCloseSet = new HashSet();
-
- Object aTag;
- Iterator iter = newSet.iterator();
+ omitElementCloseSet = new HashSet();
- while (iter.hasNext()) {
- aTag = iter.next();
+ for (String aTag : newSet) {
if (aTag != null) {
- omitElementCloseSet.add(aTag.toString().toUpperCase());
+ omitElementCloseSet.add(aTag.toUpperCase());
}
}
}
@@ -424,22 +377,18 @@ public class HTMLWriter extends XMLWriter {
/**
* @see #setPreformattedTags(java.util.Set) setPreformattedTags
+ *
+ * @return DOCUMENT ME!
*/
- public Set getPreformattedTags() {
- return (Set) (preformattedTags.clone());
+ public Set getPreformattedTags() {
+ return (Set) (preformattedTags.clone());
}
/**
- *
* Override the default set, which includes PRE, SCRIPT, STYLE, and
* TEXTAREA, case insensitively.
- *
- *
- *
+ *
* Setting Preformatted Tags
- *
- *
- *
* Pass in a Set of Strings, one for each tag name that should be treated
* like a PRE tag. You may pass in null or an empty Set to assign the empty
* set, in which case no tags will be treated as preformatted, except that
@@ -448,9 +397,7 @@ public class HTMLWriter extends XMLWriter {
* preserved, including whitespace on the same line preceding the close tag.
* This will generally make the close tag not line up with the start tag,
* but it preserves the intention of the whitespace within the tag.
- *
- *
- *
+ *
* The browser considers leading whitespace before the close tag to be
* significant, but leading whitespace before the open tag to be
* insignificant. For example, if the HTML author doesn't put the close
@@ -459,13 +406,8 @@ public class HTMLWriter extends XMLWriter {
* the HTML author's intent. Similarly, in a PRE, the browser treats a
* flushed left close PRE tag as different from a close tag with leading
* whitespace. Again, this must be left up to the HTML author.
- *
- *
- *
+ *
* Examples
- *
- *
- *
* Here is an example of how you can set the PreformattedTags list using
* setPreformattedTags to include IFRAME, as well as the default set, if you
* have an instance of this class named myHTMLWriter:
@@ -519,29 +461,21 @@ public class HTMLWriter extends XMLWriter {
*
*
*
- *
- *
- *
- *
+ *
* @param newSet
* DOCUMENT ME!
*/
- public void setPreformattedTags(Set newSet) {
+ public void setPreformattedTags(Set newSet) {
// no fancy merging, just set it, assuming they did a
// getExcludeTrimTags() first if they wanted to preserve the default
// set.
// resets, and safely empties it out if newSet is null.
- preformattedTags = new HashSet();
+ preformattedTags = new HashSet();
if (newSet != null) {
- Object aTag;
- Iterator iter = newSet.iterator();
-
- while (iter.hasNext()) {
- aTag = iter.next();
-
+ for (String aTag : newSet) {
if (aTag != null) {
- preformattedTags.add(aTag.toString().toUpperCase());
+ preformattedTags.add(aTag.toUpperCase());
}
}
}
@@ -687,9 +621,9 @@ public class HTMLWriter extends XMLWriter {
* close tags off of the default omitElementCloseSet set. Use one of
* the write methods if you want stream output.
*
- * @throws java.io.IOException
- * @throws java.io.UnsupportedEncodingException
- * @throws org.dom4j.DocumentException
+ * @throws java.io.IOException DOCUMENT ME!
+ * @throws java.io.UnsupportedEncodingException DOCUMENT ME!
+ * @throws org.dom4j.DocumentException DOCUMENT ME!
*/
public static String prettyPrintHTML(String html)
throws java.io.IOException, java.io.UnsupportedEncodingException,
@@ -709,9 +643,9 @@ public class HTMLWriter extends XMLWriter {
* converted to XHTML empty tags: <HR/> Use one of the write
* methods if you want stream output.
*
- * @throws java.io.IOException
- * @throws java.io.UnsupportedEncodingException
- * @throws org.dom4j.DocumentException
+ * @throws java.io.IOException DOCUMENT ME!
+ * @throws java.io.UnsupportedEncodingException DOCUMENT ME!
+ * @throws org.dom4j.DocumentException DOCUMENT ME!
*/
public static String prettyPrintXHTML(String html)
throws java.io.IOException, java.io.UnsupportedEncodingException,
@@ -739,9 +673,9 @@ public class HTMLWriter extends XMLWriter {
* override allows you to specify various formatter options. Use one
* of the write methods if you want stream output.
*
- * @throws java.io.IOException
- * @throws java.io.UnsupportedEncodingException
- * @throws org.dom4j.DocumentException
+ * @throws java.io.IOException DOCUMENT ME!
+ * @throws java.io.UnsupportedEncodingException DOCUMENT ME!
+ * @throws org.dom4j.DocumentException DOCUMENT ME!
*/
public static String prettyPrintHTML(String html, boolean newlines,
boolean trim, boolean isXHTML, boolean expandEmpty)
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/JAXPHelper.java b/fine-org-dom4j/src/main/java/org/dom4j/io/JAXPHelper.java
index 790d5dc00..e0aa8ebab 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/JAXPHelper.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/JAXPHelper.java
@@ -20,7 +20,7 @@ import org.xml.sax.XMLReader;
* such that dom4j can work without JAXP on the CLASSPATH
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.7 $
*/
class JAXPHelper {
protected JAXPHelper() {
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/OutputFormat.java b/fine-org-dom4j/src/main/java/org/dom4j/io/OutputFormat.java
index b30e1ca2e..c3acf1434 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/OutputFormat.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/OutputFormat.java
@@ -8,13 +8,11 @@
package org.dom4j.io;
/**
- *
* OutputFormat represents the format configuration used by
- * {@linkXMLWriter}and its base classes to format the XML output
- *
- *
+ * {@link XMLWriter}and its base classes to format the XML output
+ *
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.17 $
*/
public class OutputFormat implements Cloneable {
/** standard value to indent by, if we are indenting */
@@ -279,21 +277,14 @@ public class OutputFormat implements Cloneable {
}
/**
- *
* This will set whether the text is output verbatim (false) or with
* whitespace stripped as per {@link
* org.dom4j.Element#getTextTrim()}.
- *
- *
- *
- *
- *
- *
+ *
* Default: false
- *
- *
+ *
* @param trimText
- * boolean true=>trim the whitespace, false=>use
+ * boolean true → trim the whitespace, false → use
* text verbatim
*/
public void setTrimText(boolean trimText) {
@@ -305,7 +296,6 @@ public class OutputFormat implements Cloneable {
}
/**
- *
* Ensure that text immediately preceded by or followed by an element will
* be "padded" with a single space. This is used to allow make
* browser-friendly HTML, avoiding trimText's transformation of, e.g.,
@@ -314,17 +304,12 @@ public class OutputFormat implements Cloneable {
* (the latter will run the three separate words together into a single
* word). This setting is not too useful if you haven't also called
* {@link #setTrimText}.
- *
- *
- *
+ *
* The padding string will only be added if the text itself starts or ends
* with some whitespace characters.
- *
- *
- *
+ *
* Default: false
- *
- *
+ *
* @param padText
* boolean if true, pad string-element boundaries
*/
@@ -337,11 +322,10 @@ public class OutputFormat implements Cloneable {
}
/**
- *
* This will set the indent String to use; this is usually a
* String of empty spaces. If you pass null, or the empty
* string (""), then no indentation will happen.
- *
* This will set the indent String's size; an indentSize of
* 4 would result in the indention being equivalent to the
* String " " (four space characters).
- *
- *
+ *
* @param indentSize
* int number of spaces in indentation.
*/
@@ -392,18 +374,14 @@ public class OutputFormat implements Cloneable {
}
/**
- *
* Whether or not to use the XHTML standard: like HTML but passes an XML
* parser with real, closed tags. Also, XHTML CDATA sections will be output
* with the CDATA delimiters: ( " <![CDATA[ " and "
* ]]> " ) otherwise, the class HTMLWriter will output the
* CDATA text, but not the delimiters.
- *
- *
- *
+ *
* Default is false
- *
- *
+ *
* @return DOCUMENT ME!
*/
public boolean isXHTML() {
@@ -411,20 +389,16 @@ public class OutputFormat implements Cloneable {
}
/**
- *
* This will set whether or not to use the XHTML standard: like HTML but
* passes an XML parser with real, closed tags. Also, XHTML CDATA sections
* will be output with the CDATA delimiters: ( " <[CDATA[
* " and " ]]< ) otherwise, the class HTMLWriter
* will output the CDATA text, but not the delimiters.
- *
- *
- *
+ *
* Default: false
- *
- *
+ *
* @param xhtml
- * boolean true=>conform to XHTML, false=>conform
+ * boolean true → conform to XHTML, false → conform
* to HTML, can have unclosed tags, etc.
*/
public void setXHTML(boolean xhtml) {
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/PruningElementStack.java b/fine-org-dom4j/src/main/java/org/dom4j/io/PruningElementStack.java
index f53a28302..5d8ce416e 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/PruningElementStack.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/PruningElementStack.java
@@ -20,7 +20,7 @@ import org.dom4j.ElementHandler;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.11 $
*/
class PruningElementStack extends ElementStack {
/** ElementHandler to call when pruning occurs */
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXContentHandler.java b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXContentHandler.java
index 0685727fb..cf40de5a7 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXContentHandler.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXContentHandler.java
@@ -21,10 +21,7 @@ import org.dom4j.Element;
import org.dom4j.ElementHandler;
import org.dom4j.Namespace;
import org.dom4j.QName;
-import org.dom4j.dtd.AttributeDecl;
-import org.dom4j.dtd.ElementDecl;
-import org.dom4j.dtd.ExternalEntityDecl;
-import org.dom4j.dtd.InternalEntityDecl;
+import org.dom4j.dtd.*;
import org.dom4j.tree.AbstractElement;
import org.dom4j.tree.NamespaceStack;
@@ -37,6 +34,7 @@ import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.ext.Locator2;
import org.xml.sax.helpers.DefaultHandler;
/**
@@ -45,7 +43,7 @@ import org.xml.sax.helpers.DefaultHandler;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.61 $
*/
public class SAXContentHandler extends DefaultHandler implements
LexicalHandler, DeclHandler, DTDHandler {
@@ -82,17 +80,11 @@ public class SAXContentHandler extends DefaultHandler implements
*/
private StringBuffer cdataText;
- /** namespaces that are available for use */
- private Map availableNamespaceMap = new HashMap();
-
- /** declared namespaces that are not yet available for use */
- private List declaredNamespaceList = new ArrayList();
-
/** internal DTD declarations */
- private List internalDTDDeclarations;
+ private List internalDTDDeclarations;
/** external DTD declarations */
- private List externalDTDDeclarations;
+ private List externalDTDDeclarations;
/** The number of namespaces that are declared in the current scope */
private int declaredNamespaceIndex;
@@ -844,17 +836,8 @@ public class SAXContentHandler extends DefaultHandler implements
return null;
}
- // use reflection to avoid dependency on Locator2
- // or other locator implemenations.
- try {
- Method m = locator.getClass().getMethod("getEncoding",
- new Class[] {});
-
- if (m != null) {
- return (String) m.invoke(locator, null);
- }
- } catch (Exception e) {
- // do nothing
+ if (locator instanceof Locator2) {
+ return ((Locator2) locator).getEncoding();
}
// couldn't determine encoding, returning null...
@@ -941,9 +924,9 @@ public class SAXContentHandler extends DefaultHandler implements
* @param declaration
* DOCUMENT ME!
*/
- protected void addDTDDeclaration(Object declaration) {
+ protected void addDTDDeclaration(Decl declaration) {
if (internalDTDDeclarations == null) {
- internalDTDDeclarations = new ArrayList();
+ internalDTDDeclarations = new ArrayList();
}
internalDTDDeclarations.add(declaration);
@@ -955,9 +938,9 @@ public class SAXContentHandler extends DefaultHandler implements
* @param declaration
* DOCUMENT ME!
*/
- protected void addExternalDTDDeclaration(Object declaration) {
+ protected void addExternalDTDDeclaration(Decl declaration) {
if (externalDTDDeclarations == null) {
- externalDTDDeclarations = new ArrayList();
+ externalDTDDeclarations = new ArrayList();
}
externalDTDDeclarations.add(declaration);
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXEventRecorder.java b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXEventRecorder.java
index 2f791c34d..192a3e8aa 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXEventRecorder.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXEventRecorder.java
@@ -67,9 +67,9 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
private static final byte NULL = 2;
- private List events = new ArrayList();
+ private List events = new ArrayList();
- private Map prefixMappings = new HashMap();
+ private Map> prefixMappings = new HashMap>();
private static final String XMLNS = "xmlns";
@@ -79,11 +79,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
}
public void replay(ContentHandler handler) throws SAXException {
- SAXEvent saxEvent;
- Iterator itr = events.iterator();
-
- while (itr.hasNext()) {
- saxEvent = (SAXEvent) itr.next();
+ for (SAXEvent saxEvent : events) {
switch (saxEvent.event) {
// replay to ContentHandler
@@ -117,13 +113,10 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
case SAXEvent.START_ELEMENT:
AttributesImpl attributes = new AttributesImpl();
- List attParmList = (List) saxEvent.getParm(3);
+ List attParmList = (List) saxEvent.getParm(3);
if (attParmList != null) {
- Iterator attsItr = attParmList.iterator();
-
- while (attsItr.hasNext()) {
- String[] attParms = (String[]) attsItr.next();
+ for (String[] attParms : attParmList) {
attributes.addAttribute(attParms[0], attParms[1],
attParms[2], attParms[3], attParms[4]);
}
@@ -145,8 +138,8 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
case SAXEvent.CHARACTERS:
char[] chars = (char[]) saxEvent.getParm(0);
- int start = ((Integer) saxEvent.getParm(1)).intValue();
- int end = ((Integer) saxEvent.getParm(2)).intValue();
+ int start = (Integer) saxEvent.getParm(1);
+ int end = (Integer) saxEvent.getParm(2);
handler.characters(chars, start, end);
break;
@@ -154,7 +147,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
// replay to LexicalHandler
case SAXEvent.START_DTD:
((LexicalHandler) handler).startDTD((String) saxEvent
- .getParm(0), (String) saxEvent.getParm(1),
+ .getParm(0), (String) saxEvent.getParm(1),
(String) saxEvent.getParm(2));
break;
@@ -189,8 +182,8 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
case SAXEvent.COMMENT:
char[] cchars = (char[]) saxEvent.getParm(0);
- int cstart = ((Integer) saxEvent.getParm(1)).intValue();
- int cend = ((Integer) saxEvent.getParm(2)).intValue();
+ int cstart = (Integer) saxEvent.getParm(1);
+ int cend = (Integer) saxEvent.getParm(2);
((LexicalHandler) handler).comment(cchars, cstart, cend);
break;
@@ -204,7 +197,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
case SAXEvent.ATTRIBUTE_DECL:
((DeclHandler) handler).attributeDecl((String) saxEvent
- .getParm(0), (String) saxEvent.getParm(1),
+ .getParm(0), (String) saxEvent.getParm(1),
(String) saxEvent.getParm(2), (String) saxEvent
.getParm(3), (String) saxEvent.getParm(4));
@@ -272,7 +265,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
saxEvent.addParm(localName);
saxEvent.addParm(qualifiedName);
- QName qName = null;
+ QName qName;
if (namespaceURI != null) {
qName = new QName(localName, Namespace.get(namespaceURI));
} else {
@@ -280,8 +273,8 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
}
if ((attributes != null) && (attributes.getLength() > 0)) {
- List attParmList = new ArrayList(attributes.getLength());
- String[] attParms = null;
+ List attParmList = new ArrayList(attributes.getLength());
+ String[] attParms;
for (int i = 0; i < attributes.getLength(); i++) {
@@ -292,7 +285,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
// if SAXWriter is writing a DOMDocument, namespace
// decls are treated as attributes. record a start
// prefix mapping event
- String prefix = null;
+ String prefix;
if (attLocalName.length() > 5) {
prefix = attLocalName.substring(6);
} else {
@@ -307,9 +300,9 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
// 'register' the prefix so that we can generate
// an end prefix mapping event within endElement
- List prefixes = (List) prefixMappings.get(qName);
+ List prefixes = prefixMappings.get(qName);
if (prefixes == null) {
- prefixes = new ArrayList();
+ prefixes = new ArrayList();
prefixMappings.put(qName, prefixes);
}
prefixes.add(prefix);
@@ -346,20 +339,19 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
// check to see if a we issued a start prefix mapping event
// for DOMDocument namespace decls
- QName elementName = null;
+ QName elementName;
if (namespaceURI != null) {
elementName = new QName(localName, Namespace.get(namespaceURI));
} else {
elementName = new QName(localName);
}
- List prefixes = (List) prefixMappings.get(elementName);
+ List prefixes = prefixMappings.get(elementName);
if (prefixes != null) {
- Iterator itr = prefixes.iterator();
- while (itr.hasNext()) {
- SAXEvent prefixEvent =
+ for (String prefixe : prefixes) {
+ SAXEvent prefixEvent =
new SAXEvent(SAXEvent.END_PREFIX_MAPPING);
- prefixEvent.addParm(itr.next());
+ prefixEvent.addParm(prefixe);
events.add(prefixEvent);
}
}
@@ -369,8 +361,8 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
public void characters(char[] ch, int start, int end) throws SAXException {
SAXEvent saxEvent = new SAXEvent(SAXEvent.CHARACTERS);
saxEvent.addParm(ch);
- saxEvent.addParm(new Integer(start));
- saxEvent.addParm(new Integer(end));
+ saxEvent.addParm(start);
+ saxEvent.addParm(end);
events.add(saxEvent);
}
@@ -415,8 +407,8 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
public void comment(char[] ch, int start, int end) throws SAXException {
SAXEvent saxEvent = new SAXEvent(SAXEvent.COMMENT);
saxEvent.addParm(ch);
- saxEvent.addParm(new Integer(start));
- saxEvent.addParm(new Integer(end));
+ saxEvent.addParm(start);
+ saxEvent.addParm(end);
events.add(saxEvent);
}
@@ -469,7 +461,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
public void readExternal(ObjectInput in) throws ClassNotFoundException,
IOException {
if (in.readByte() != NULL) {
- events = (List) in.readObject();
+ events = (List) in.readObject();
}
}
@@ -518,7 +510,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
protected byte event;
- protected List parms;
+ protected List parms;
public SAXEvent() {
}
@@ -529,7 +521,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
void addParm(Object parm) {
if (parms == null) {
- parms = new ArrayList(3);
+ parms = new ArrayList(3);
}
parms.add(parm);
@@ -559,7 +551,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
event = in.readByte();
if (in.readByte() != NULL) {
- parms = (List) in.readObject();
+ parms = (List) in.readObject();
}
}
}
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXHelper.java b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXHelper.java
index 6ff56312d..e66905e9d 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXHelper.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXHelper.java
@@ -13,14 +13,16 @@ import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
+import javax.xml.parsers.SAXParserFactory;
+
/**
*
* SAXHelper contains some helper methods for working with SAX
* and XMLReader objects.
*
- *
+ *
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.18 $
*/
class SAXHelper {
private static boolean loggedWarning = true;
@@ -61,12 +63,21 @@ class SAXHelper {
/**
* Creats a default XMLReader via the org.xml.sax.driver system property or
* JAXP if the system property is not set.
- *
+ *
+ * This method internally calls {@link SAXParserFactory}{@code .newInstance().newSAXParser().getXMLReader()} or {@link XMLReaderFactory#createXMLReader()}.
+ * Be sure to configure returned reader if the default configuration does not suit you. Consider setting the following properties:
+ *
+ *
+ *
* @param validating
* DOCUMENT ME!
- *
+ *
* @return DOCUMENT ME!
- *
+ *
* @throws SAXException
* DOCUMENT ME!
*/
@@ -103,6 +114,21 @@ class SAXHelper {
throw new SAXException("Couldn't create SAX reader");
}
+ // configure namespace support
+ SAXHelper.setParserFeature(reader, "http://xml.org/sax/features/namespaces", true);
+ SAXHelper.setParserFeature(reader, "http://xml.org/sax/features/namespace-prefixes", false);
+
+ // external entites
+ SAXHelper.setParserFeature(reader, "http://xml.org/sax/properties/external-general-entities", false);
+ SAXHelper.setParserFeature(reader, "http://xml.org/sax/properties/external-parameter-entities", false);
+
+ // external DTD
+ SAXHelper.setParserFeature(reader,"http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
+
+
+ // use Locator2 if possible
+ SAXHelper.setParserFeature(reader,"http://xml.org/sax/features/use-locator2", true);
+
return reader;
}
@@ -110,12 +136,12 @@ class SAXHelper {
* This method attempts to use JAXP to locate the SAX2 XMLReader
* implementation. This method uses reflection to avoid being dependent
* directly on the JAXP classes.
- *
+ *
* @param validating
* DOCUMENT ME!
* @param namespaceAware
* DOCUMENT ME!
- *
+ *
* @return DOCUMENT ME!
*/
protected static XMLReader createXMLReaderViaJAXP(boolean validating,
@@ -161,24 +187,24 @@ class SAXHelper {
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the
* following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document.
- *
+ *
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com.
- *
+ *
* 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
- *
+ *
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
- *
+ *
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -190,6 +216,6 @@ class SAXHelper {
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXModifier.java b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXModifier.java
index 818fe42b4..71777f321 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXModifier.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXModifier.java
@@ -50,7 +50,7 @@ public class SAXModifier {
private SAXModifyReader modifyReader;
- private HashMap modifiers = new HashMap();
+ private HashMap modifiers = new HashMap();
/**
* Creates a new modifier.
@@ -102,7 +102,7 @@ public class SAXModifier {
/**
* Reads a Document from the given {@link java.io.File}and writes it to the
- * specified {@link XMLWriter}using SAX. Registered {@linkElementModifier}
+ * specified {@link XMLWriter}using SAX. Registered {@link ElementModifier}
* objects are invoked on the fly.
*
* @param source
@@ -246,7 +246,7 @@ public class SAXModifier {
/**
* Reads a Document from the given {@link java.net.URL}and writes it to the
- * specified {@link XMLWriter}using SAX. Registered {@linkElementModifier}
+ * specified {@link XMLWriter}using SAX. Registered {@link ElementModifier}
* objects are invoked on the fly.
*
* @param source
@@ -269,7 +269,7 @@ public class SAXModifier {
/**
* Reads a Document from the given URL or filename and writes it to the
- * specified {@link XMLWriter}using SAX. Registered {@linkElementModifier}
+ * specified {@link XMLWriter}using SAX. Registered {@link ElementModifier}
* objects are invoked on the fly.
*
* @param source
@@ -385,14 +385,10 @@ public class SAXModifier {
reader.resetHandlers();
- Iterator modifierIt = this.modifiers.entrySet().iterator();
-
- while (modifierIt.hasNext()) {
- Map.Entry entry = (Map.Entry) modifierIt.next();
-
+ for (Map.Entry entry : this.modifiers.entrySet()) {
SAXModifyElementHandler handler = new SAXModifyElementHandler(
- (ElementModifier) entry.getValue());
- reader.addHandler((String) entry.getKey(), handler);
+ entry.getValue());
+ reader.addHandler(entry.getKey(), handler);
}
reader.setXMLWriter(getXMLWriter());
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXReader.java b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXReader.java
index cfcdaa81f..73660abff 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXReader.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXReader.java
@@ -30,1002 +30,981 @@ import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
+import javax.xml.parsers.SAXParserFactory;
+
/**
- *
* SAXReader creates a DOM4J tree from SAX parsing events.
- *
- *
*
* The actual SAX parser that is used by this class is configurable so you can
* use your favourite SAX parser if you wish. DOM4J comes configured with its
* own SAX parser so you do not need to worry about configuring the SAX parser.
- *
- *
*
* To explicitly configure the SAX parser that is used via Java code you can use
* a constructor or use the {@link #setXMLReader(XMLReader)}or {@link
* #setXMLReaderClassName(String)} methods.
- *
- *
*
* If the parser is not specified explicitly then the standard SAX policy of
* using the org.xml.sax.driver system property is used to
* determine the implementation class of {@link XMLReader}.
- *
- *
*
* If the org.xml.sax.driver system property is not defined then
* JAXP is used via reflection (so that DOM4J is not explicitly dependent on the
* JAXP classes) to load the JAXP configured SAXParser. If there is any error
* creating a JAXP SAXParser an informational message is output and then the
* default (Aelfred) SAX parser is used instead.
- *
- *
*
* If you are trying to use JAXP to explicitly set your SAX parser and are
* experiencing problems, you can turn on verbose error reporting by defining
* the system property org.dom4j.verbose to be "true" which will
* output a more detailed description of why JAXP could not find a SAX parser
- *
+ */
+ public SAXReader() {
+ }
+
+ /**
+ * This method internally calls {@link SAXParserFactory}{@code .newInstance().newSAXParser().getXMLReader()} or {@link XMLReaderFactory#createXMLReader()}.
+ * Be sure to configure returned reader if the default configuration does not suit you. Consider setting the following properties:
+ *
+ *
+ *
+ * @param validating
+ */
+ public SAXReader(boolean validating) {
+ this.validating = validating;
+ }
+
+ /**
+ * This method internally calls {@link SAXParserFactory}{@code .newInstance().newSAXParser().getXMLReader()} or {@link XMLReaderFactory#createXMLReader()}.
+ * Be sure to configure returned reader if the default configuration does not suit you. Consider setting the following properties:
+ *
+ *
+ *
+ * @param factory
+ */
+ public SAXReader(DocumentFactory factory) {
+ this.factory = factory;
+ }
+
+ /**
+ * This method internally calls {@link SAXParserFactory}{@code .newInstance().newSAXParser().getXMLReader()} or {@link XMLReaderFactory#createXMLReader()}.
+ * Be sure to configure returned reader if the default configuration does not suit you. Consider setting the following properties:
+ *
+ *
+ *
+ * @param factory
+ * @param validating
+ */
+ public SAXReader(DocumentFactory factory, boolean validating) {
+ this.factory = factory;
+ this.validating = validating;
+ }
+
+ public SAXReader(XMLReader xmlReader) {
+ this.xmlReader = xmlReader;
+ }
+
+ public SAXReader(XMLReader xmlReader, boolean validating) {
+ this.xmlReader = xmlReader;
+ this.validating = validating;
+ }
+
+ public SAXReader(String xmlReaderClassName) throws SAXException {
+ if (xmlReaderClassName != null) {
+ this.xmlReader = XMLReaderFactory
+ .createXMLReader(xmlReaderClassName);
+ }
+ }
+
+ public SAXReader(String xmlReaderClassName, boolean validating)
+ throws SAXException {
+ if (xmlReaderClassName != null) {
+ this.xmlReader = XMLReaderFactory
+ .createXMLReader(xmlReaderClassName);
+ }
+
+ this.validating = validating;
+ }
+
+ /**
+ * Allows a SAX property to be set on the underlying SAX parser. This can be
+ * useful to set parser-specific properties such as the location of schema
+ * or DTD resources. Though use this method with caution as it has the
+ * possibility of breaking the standard behaviour. An alternative to calling
+ * this method is to correctly configure an XMLReader object instance and
+ * call the {@link #setXMLReader(XMLReader)}method
+ *
+ * @param name is the SAX property name
+ * @param value is the value of the SAX property
+ * @throws SAXException if the XMLReader could not be created or the property could
+ * not be changed.
+ */
+ public void setProperty(String name, Object value) throws SAXException {
+ getXMLReader().setProperty(name, value);
+ }
+
+ /**
+ * Sets a SAX feature on the underlying SAX parser. This can be useful to
+ * set parser-specific features. Though use this method with caution as it
+ * has the possibility of breaking the standard behaviour. An alternative to
+ * calling this method is to correctly configure an XMLReader object
+ * instance and call the {@link #setXMLReader(XMLReader)}method
+ *
+ * @param name is the SAX feature name
+ * @param value is the value of the SAX feature
+ * @throws SAXException if the XMLReader could not be created or the feature could
+ * not be changed.
+ */
+ public void setFeature(String name, boolean value) throws SAXException {
+ getXMLReader().setFeature(name, value);
+ }
+
+ /**
+ *
+ * Reads a Document from the given File
+ *
+ *
+ * @param file is the File to read from.
+ * @return the newly created Document instance
+ * @throws DocumentException if an error occurs during parsing.
+ */
+ public Document read(File file) throws DocumentException {
+ try {
+ /*
+ * We cannot convert the file to an URL because if the filename
+ * contains '#' characters, there will be problems with the URL in
+ * the InputSource (because a URL like
+ * http://myhost.com/index#anchor is treated the same as
+ * http://myhost.com/index) Thanks to Christian Oetterli
+ */
+ InputSource source = new InputSource(new FileInputStream(file));
+ if (this.encoding != null) {
+ source.setEncoding(this.encoding);
+ }
+ String path = file.getAbsolutePath();
+
+ if (path != null) {
+ // Code taken from Ant FileUtils
+ StringBuffer sb = new StringBuffer("file://");
+
+ // add an extra slash for filesystems with drive-specifiers
+ if (!path.startsWith(File.separator)) {
+ sb.append("/");
}
- }
- public SAXReader(String xmlReaderClassName, boolean validating)
- throws SAXException {
- if (xmlReaderClassName != null) {
- this.xmlReader = XMLReaderFactory
- .createXMLReader(xmlReaderClassName);
+ path = path.replace('\\', '/');
+ sb.append(path);
+
+ source.setSystemId(sb.toString());
+ }
+
+ return read(source);
+ } catch (FileNotFoundException e) {
+ throw new DocumentException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ *
+ * Reads a Document from the given URL using SAX
+ *
+ *
+ * @param url URL to read from.
+ * @return the newly created Document instance
+ * @throws DocumentException if an error occurs during parsing.
+ */
+ public Document read(URL url) throws DocumentException {
+ String systemID = url.toExternalForm();
+
+ InputSource source = new InputSource(systemID);
+ if (this.encoding != null) {
+ source.setEncoding(this.encoding);
+ }
+
+ return read(source);
+ }
+
+ /**
+ *
+ * Reads a Document from the given URL or filename using SAX.
+ *
+ *
+ *
+ * If the systemId contains a ':' character then it is
+ * assumed to be a URL otherwise its assumed to be a file name. If you want
+ * finer grained control over this mechansim then please explicitly pass in
+ * either a {@link URL}or a {@link File}instance instead of a {@link
+ * String} to denote the source of the document.
+ *
+ *
+ * @param systemId is a URL for a document or a file name.
+ * @return the newly created Document instance
+ * @throws DocumentException if an error occurs during parsing.
+ */
+ public Document read(String systemId) throws DocumentException {
+ InputSource source = new InputSource(systemId);
+ if (this.encoding != null) {
+ source.setEncoding(this.encoding);
+ }
+
+ return read(source);
+ }
+
+ /**
+ *
+ * Reads a Document from the given stream using SAX
+ *
+ *
+ * @param in InputStream to read from.
+ * @return the newly created Document instance
+ * @throws DocumentException if an error occurs during parsing.
+ */
+ public Document read(InputStream in) throws DocumentException {
+ InputSource source = new InputSource(in);
+ if (this.encoding != null) {
+ source.setEncoding(this.encoding);
+ }
+
+ return read(source);
+ }
+
+ /**
+ * Reads a Document from the given Reader using SAX
+ *
+ * @param reader is the reader for the input
+ * @return the newly created Document instance
+ * @throws DocumentException if an error occurs during parsing.
+ */
+ public Document read(Reader reader) throws DocumentException {
+ InputSource source = new InputSource(reader);
+ if (this.encoding != null) {
+ source.setEncoding(this.encoding);
+ }
+
+ return read(source);
+ }
+
+ /**
+ *
+ * Reads a Document from the given stream using SAX
+ *
+ *
+ * @param in InputStream to read from.
+ * @param systemId is the URI for the input
+ * @return the newly created Document instance
+ * @throws DocumentException if an error occurs during parsing.
+ */
+ public Document read(InputStream in, String systemId)
+ throws DocumentException {
+ InputSource source = new InputSource(in);
+ source.setSystemId(systemId);
+ if (this.encoding != null) {
+ source.setEncoding(this.encoding);
+ }
+
+ return read(source);
+ }
+
+ /**
+ *
+ * Reads a Document from the given Reader using SAX
+ *
+ *
+ * @param reader is the reader for the input
+ * @param systemId is the URI for the input
+ * @return the newly created Document instance
+ * @throws DocumentException if an error occurs during parsing.
+ */
+ public Document read(Reader reader, String systemId)
+ throws DocumentException {
+ InputSource source = new InputSource(reader);
+ source.setSystemId(systemId);
+ if (this.encoding != null) {
+ source.setEncoding(this.encoding);
+ }
+
+ return read(source);
+ }
+
+ /**
+ *
+ * Reads a Document from the given InputSource using SAX
+ *
+ *
+ * @param in InputSource to read from.
+ * @return the newly created Document instance
+ * @throws DocumentException if an error occurs during parsing.
+ */
+ public Document read(InputSource in) throws DocumentException {
+ try {
+ XMLReader reader = getXMLReader();
+
+ reader = installXMLFilter(reader);
+
+ EntityResolver thatEntityResolver = this.entityResolver;
+
+ if (thatEntityResolver == null) {
+ thatEntityResolver = createDefaultEntityResolver(in
+ .getSystemId());
+ this.entityResolver = thatEntityResolver;
+ }
+
+ reader.setEntityResolver(thatEntityResolver);
+
+ SAXContentHandler contentHandler = createContentHandler(reader);
+ contentHandler.setEntityResolver(thatEntityResolver);
+ contentHandler.setInputSource(in);
+
+ boolean internal = isIncludeInternalDTDDeclarations();
+ boolean external = isIncludeExternalDTDDeclarations();
+
+ contentHandler.setIncludeInternalDTDDeclarations(internal);
+ contentHandler.setIncludeExternalDTDDeclarations(external);
+ contentHandler.setMergeAdjacentText(isMergeAdjacentText());
+ contentHandler.setStripWhitespaceText(isStripWhitespaceText());
+ contentHandler.setIgnoreComments(isIgnoreComments());
+ reader.setContentHandler(contentHandler);
+
+ configureReader(reader, contentHandler);
+
+ reader.parse(in);
+
+ return contentHandler.getDocument();
+ } catch (Exception e) {
+ if (e instanceof SAXParseException) {
+ // e.printStackTrace();
+ SAXParseException parseException = (SAXParseException) e;
+ String systemId = parseException.getSystemId();
+
+ if (systemId == null) {
+ systemId = "";
}
- this.validating = validating;
- }
-
- /**
- * Allows a SAX property to be set on the underlying SAX parser. This can be
- * useful to set parser-specific properties such as the location of schema
- * or DTD resources. Though use this method with caution as it has the
- * possibility of breaking the standard behaviour. An alternative to calling
- * this method is to correctly configure an XMLReader object instance and
- * call the {@link #setXMLReader(XMLReader)}method
- *
- * @param name
- * is the SAX property name
- * @param value
- * is the value of the SAX property
- *
- * @throws SAXException
- * if the XMLReader could not be created or the property could
- * not be changed.
- */
- public void setProperty(String name, Object value) throws SAXException {
- getXMLReader().setProperty(name, value);
- }
-
- /**
- * Sets a SAX feature on the underlying SAX parser. This can be useful to
- * set parser-specific features. Though use this method with caution as it
- * has the possibility of breaking the standard behaviour. An alternative to
- * calling this method is to correctly configure an XMLReader object
- * instance and call the {@link #setXMLReader(XMLReader)}method
- *
- * @param name
- * is the SAX feature name
- * @param value
- * is the value of the SAX feature
- *
- * @throws SAXException
- * if the XMLReader could not be created or the feature could
- * not be changed.
- */
- public void setFeature(String name, boolean value) throws SAXException {
- getXMLReader().setFeature(name, value);
- }
-
- /**
- *
- * Reads a Document from the given File
- *
- *
- * @param file
- * is the File to read from.
- *
- * @return the newly created Document instance
- *
- * @throws DocumentException
- * if an error occurs during parsing.
- */
- public Document read(File file) throws DocumentException {
- try {
- /*
- * We cannot convert the file to an URL because if the filename
- * contains '#' characters, there will be problems with the URL in
- * the InputSource (because a URL like
- * http://myhost.com/index#anchor is treated the same as
- * http://myhost.com/index) Thanks to Christian Oetterli
- */
- InputSource source = new InputSource(new FileInputStream(file));
- if (this.encoding != null) {
- source.setEncoding(this.encoding);
- }
- String path = file.getAbsolutePath();
-
- if (path != null) {
- // Code taken from Ant FileUtils
- StringBuffer sb = new StringBuffer("file://");
-
- // add an extra slash for filesystems with drive-specifiers
- if (!path.startsWith(File.separator)) {
- sb.append("/");
- }
-
- path = path.replace('\\', '/');
- sb.append(path);
-
- source.setSystemId(sb.toString());
- }
-
- return read(source);
- } catch (FileNotFoundException e) {
- throw new DocumentException(e.getMessage(), e);
+ String message = "Error on line "
+ + parseException.getLineNumber() + " of document "
+ + systemId + " : " + parseException.getMessage();
+
+ throw new DocumentException(message, e);
+ } else {
+ throw new DocumentException(e.getMessage(), e);
+ }
+ }
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return the validation mode, true if validating will be done otherwise
+ * false.
+ */
+ public boolean isValidating() {
+ return validating;
+ }
+
+ /**
+ * Sets the validation mode.
+ *
+ * @param validation indicates whether or not validation should occur.
+ */
+ public void setValidation(boolean validation) {
+ this.validating = validation;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return whether internal DTD declarations should be expanded into the
+ * DocumentType object or not.
+ */
+ public boolean isIncludeInternalDTDDeclarations() {
+ return includeInternalDTDDeclarations;
+ }
+
+ /**
+ * Sets whether internal DTD declarations should be expanded into the
+ * DocumentType object or not.
+ *
+ * @param include whether or not DTD declarations should be expanded and
+ * included into the DocumentType object.
+ */
+ public void setIncludeInternalDTDDeclarations(boolean include) {
+ this.includeInternalDTDDeclarations = include;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return whether external DTD declarations should be expanded into the
+ * DocumentType object or not.
+ */
+ public boolean isIncludeExternalDTDDeclarations() {
+ return includeExternalDTDDeclarations;
+ }
+
+ /**
+ * Sets whether DTD external declarations should be expanded into the
+ * DocumentType object or not.
+ *
+ * @param include whether or not DTD declarations should be expanded and
+ * included into the DocumentType object.
+ */
+ public void setIncludeExternalDTDDeclarations(boolean include) {
+ this.includeExternalDTDDeclarations = include;
+ }
+
+ /**
+ * Sets whether String interning is enabled or disabled for element &
+ * attribute names and namespace URIs. This proprety is enabled by default.
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean isStringInternEnabled() {
+ return stringInternEnabled;
+ }
+
+ /**
+ * Sets whether String interning is enabled or disabled for element &
+ * attribute names and namespace URIs
+ *
+ * @param stringInternEnabled DOCUMENT ME!
+ */
+ public void setStringInternEnabled(boolean stringInternEnabled) {
+ this.stringInternEnabled = stringInternEnabled;
+ }
+
+ /**
+ * Returns whether adjacent text nodes should be merged together.
+ *
+ * @return Value of property mergeAdjacentText.
+ */
+ public boolean isMergeAdjacentText() {
+ return mergeAdjacentText;
+ }
+
+ /**
+ * Sets whether or not adjacent text nodes should be merged together when
+ * parsing.
+ *
+ * @param mergeAdjacentText New value of property mergeAdjacentText.
+ */
+ public void setMergeAdjacentText(boolean mergeAdjacentText) {
+ this.mergeAdjacentText = mergeAdjacentText;
+ }
+
+ /**
+ * Sets whether whitespace between element start and end tags should be
+ * ignored
+ *
+ * @return Value of property stripWhitespaceText.
+ */
+ public boolean isStripWhitespaceText() {
+ return stripWhitespaceText;
+ }
+
+ /**
+ * Sets whether whitespace between element start and end tags should be
+ * ignored.
+ *
+ * @param stripWhitespaceText New value of property stripWhitespaceText.
+ */
+ public void setStripWhitespaceText(boolean stripWhitespaceText) {
+ this.stripWhitespaceText = stripWhitespaceText;
+ }
+
+ /**
+ * Returns whether we should ignore comments or not.
+ *
+ * @return boolean
+ */
+ public boolean isIgnoreComments() {
+ return ignoreComments;
+ }
+
+ /**
+ * Sets whether we should ignore comments or not.
+ *
+ * @param ignoreComments whether we should ignore comments or not.
+ */
+ public void setIgnoreComments(boolean ignoreComments) {
+ this.ignoreComments = ignoreComments;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return the DocumentFactory used to create document
+ * objects
+ */
+ public DocumentFactory getDocumentFactory() {
+ if (factory == null) {
+ factory = DocumentFactory.getInstance();
+ }
+
+ return factory;
+ }
+
+ /**
+ *
+ * This sets the DocumentFactory used to create new
+ * documents. This method allows the building of custom DOM4J tree objects
+ * to be implemented easily using a custom derivation of
+ * {@link DocumentFactory}
+ *
+ *
+ * @param documentFactory DocumentFactory used to create DOM4J objects
+ */
+ public void setDocumentFactory(DocumentFactory documentFactory) {
+ this.factory = documentFactory;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return the ErrorHandler used by SAX
+ */
+ public ErrorHandler getErrorHandler() {
+ return errorHandler;
+ }
+
+ /**
+ * Sets the ErrorHandler used by the SAX
+ * XMLReader.
+ *
+ * @param errorHandler is the ErrorHandler used by SAX
+ */
+ public void setErrorHandler(ErrorHandler errorHandler) {
+ this.errorHandler = errorHandler;
+ }
+
+ /**
+ * Returns the current entity resolver used to resolve entities
+ *
+ * @return DOCUMENT ME!
+ */
+ public EntityResolver getEntityResolver() {
+ return entityResolver;
+ }
+
+ /**
+ * Sets the entity resolver used to resolve entities.
+ *
+ * @param entityResolver DOCUMENT ME!
+ */
+ public void setEntityResolver(EntityResolver entityResolver) {
+ this.entityResolver = entityResolver;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return the XMLReader used to parse SAX events
+ * @throws SAXException DOCUMENT ME!
+ */
+ public XMLReader getXMLReader() throws SAXException {
+ if (xmlReader == null) {
+ xmlReader = createXMLReader();
+ }
+
+ return xmlReader;
+ }
+
+ /**
+ * Sets the XMLReader used to parse SAX events
+ *
+ * @param reader is the XMLReader to parse SAX events
+ */
+ public void setXMLReader(XMLReader reader) {
+ this.xmlReader = reader;
+ }
+
+ /**
+ * Returns encoding used for InputSource (null means system default
+ * encoding)
+ *
+ * @return encoding used for InputSource
+ */
+ public String getEncoding() {
+ return encoding;
+ }
+
+ /**
+ * Sets encoding used for InputSource (null means system default encoding)
+ *
+ * @param encoding is encoding used for InputSource
+ */
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ /**
+ * Sets the class name of the XMLReader to be used to parse
+ * SAX events.
+ *
+ * @param xmlReaderClassName is the class name of the XMLReader to parse SAX
+ * events
+ * @throws SAXException DOCUMENT ME!
+ */
+ public void setXMLReaderClassName(String xmlReaderClassName)
+ throws SAXException {
+ setXMLReader(XMLReaderFactory.createXMLReader(xmlReaderClassName));
+ }
+
+ /**
+ * Adds the ElementHandler to be called when the specified
+ * path is encounted.
+ *
+ * @param path is the path to be handled
+ * @param handler is the ElementHandler to be called by the event
+ * based processor.
+ */
+ public void addHandler(String path, ElementHandler handler) {
+ getDispatchHandler().addHandler(path, handler);
+ }
+
+ /**
+ * Removes the ElementHandler from the event based processor,
+ * for the specified path.
+ *
+ * @param path is the path to remove the ElementHandler for.
+ */
+ public void removeHandler(String path) {
+ getDispatchHandler().removeHandler(path);
+ }
+
+ /**
+ * When multiple ElementHandler instances have been
+ * registered, this will set a default ElementHandler to be
+ * called for any path which does NOT have a handler registered.
+ *
+ * @param handler is the ElementHandler to be called by the event
+ * based processor.
+ */
+ public void setDefaultHandler(ElementHandler handler) {
+ getDispatchHandler().setDefaultHandler(handler);
+ }
+
+ /**
+ * This method clears out all the existing handlers and default handler
+ * setting things back as if no handler existed. Useful when reusing an
+ * object instance.
+ */
+ public void resetHandlers() {
+ getDispatchHandler().resetHandlers();
+ }
+
+ /**
+ * Returns the SAX filter being used to filter SAX events.
+ *
+ * @return the SAX filter being used or null if no SAX filter is installed
+ */
+ public XMLFilter getXMLFilter() {
+ return xmlFilter;
+ }
+
+ /**
+ * Sets the SAX filter to be used when filtering SAX events
+ *
+ * @param filter is the SAX filter to use or null to disable filtering
+ */
+ public void setXMLFilter(XMLFilter filter) {
+ this.xmlFilter = filter;
+ }
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Installs any XMLFilter objects required to allow the SAX event stream to
+ * be filtered and preprocessed before it gets to dom4j.
+ *
+ * @param reader DOCUMENT ME!
+ * @return the new XMLFilter if applicable or the original XMLReader if no
+ * filter is being used.
+ */
+ protected XMLReader installXMLFilter(XMLReader reader) {
+ XMLFilter filter = getXMLFilter();
+
+ if (filter != null) {
+ // find the root XMLFilter
+ XMLFilter root = filter;
+
+ while (true) {
+ XMLReader parent = root.getParent();
+
+ if (parent instanceof XMLFilter) {
+ root = (XMLFilter) parent;
+ } else {
+ break;
}
+ }
+
+ root.setParent(reader);
+
+ return filter;
}
- /**
- *
- * Reads a Document from the given URL using SAX
- *
- *
- * @param url
- * URL to read from.
- *
- * @return the newly created Document instance
- *
- * @throws DocumentException
- * if an error occurs during parsing.
- */
- public Document read(URL url) throws DocumentException {
- String systemID = url.toExternalForm();
-
- InputSource source = new InputSource(systemID);
- if (this.encoding != null) {
- source.setEncoding(this.encoding);
- }
+ return reader;
+ }
- return read(source);
- }
-
- /**
- *
- * Reads a Document from the given URL or filename using SAX.
- *
- *
- *
- * If the systemId contains a ':' character then it is
- * assumed to be a URL otherwise its assumed to be a file name. If you want
- * finer grained control over this mechansim then please explicitly pass in
- * either a {@link URL}or a {@link File}instance instead of a {@link
- * String} to denote the source of the document.
- *
- *
- * @param systemId
- * is a URL for a document or a file name.
- *
- * @return the newly created Document instance
- *
- * @throws DocumentException
- * if an error occurs during parsing.
- */
- public Document read(String systemId) throws DocumentException {
- InputSource source = new InputSource(systemId);
- if (this.encoding != null) {
- source.setEncoding(this.encoding);
+ protected DispatchHandler getDispatchHandler() {
+ if (dispatchHandler == null) {
+ dispatchHandler = new DispatchHandler();
+ }
+
+ return dispatchHandler;
+ }
+
+ protected void setDispatchHandler(DispatchHandler dispatchHandler) {
+ this.dispatchHandler = dispatchHandler;
+ }
+
+ /**
+ * Factory Method to allow alternate methods of creating and configuring
+ * XMLReader objects
+ *
+ * @return DOCUMENT ME!
+ * @throws SAXException DOCUMENT ME!
+ */
+ protected XMLReader createXMLReader() throws SAXException {
+ return SAXHelper.createXMLReader(isValidating());
+ }
+
+ /**
+ * Configures the XMLReader before use
+ *
+ * @param reader DOCUMENT ME!
+ * @param handler DOCUMENT ME!
+ * @throws DocumentException DOCUMENT ME!
+ */
+ protected void configureReader(XMLReader reader, DefaultHandler handler)
+ throws DocumentException {
+ // configure lexical handling
+ SAXHelper.setParserProperty(reader, SAX_LEXICALHANDLER, handler);
+
+ // try alternate property just in case
+ SAXHelper.setParserProperty(reader, SAX_LEXICAL_HANDLER, handler);
+
+ // register the DeclHandler
+ if (includeInternalDTDDeclarations || includeExternalDTDDeclarations) {
+ SAXHelper.setParserProperty(reader, SAX_DECL_HANDLER, handler);
+ }
+
+ // string interning
+ SAXHelper.setParserFeature(reader, SAX_STRING_INTERNING,
+ isStringInternEnabled());
+
+ try {
+ // configure validation support
+ reader.setFeature("http://xml.org/sax/features/validation",
+ isValidating());
+
+ if (errorHandler != null) {
+ reader.setErrorHandler(errorHandler);
+ } else {
+ reader.setErrorHandler(handler);
+ }
+ } catch (Exception e) {
+ if (isValidating()) {
+ throw new DocumentException("Validation not supported for"
+ + " XMLReader: " + reader, e);
+ }
+ }
+ }
+
+ /**
+ * Factory Method to allow user derived SAXContentHandler objects to be used
+ *
+ * @param reader DOCUMENT ME!
+ * @return DOCUMENT ME!
+ */
+ protected SAXContentHandler createContentHandler(XMLReader reader) {
+ return new SAXContentHandler(getDocumentFactory(), dispatchHandler);
+ }
+
+ protected EntityResolver createDefaultEntityResolver(String systemId) {
+ String prefix = null;
+
+ if ((systemId != null) && (systemId.length() > 0)) {
+ int idx = systemId.lastIndexOf('/');
+
+ if (idx > 0) {
+ prefix = systemId.substring(0, idx + 1);
+ }
+ }
+
+ return new SAXEntityResolver(prefix);
+ }
+
+ protected static class SAXEntityResolver implements EntityResolver,
+ Serializable {
+ protected String uriPrefix;
+
+ public SAXEntityResolver(String uriPrefix) {
+ this.uriPrefix = uriPrefix;
+ }
+
+ public InputSource resolveEntity(String publicId, String systemId) {
+ // try create a relative URI reader...
+ if ((systemId != null) && (systemId.length() > 0)) {
+ if ((uriPrefix != null) && (systemId.indexOf(':') <= 0)) {
+ systemId = uriPrefix + systemId;
}
+ }
- return read(source);
- }
-
- /**
- *
- * Reads a Document from the given stream using SAX
- *
- *
- * @param in
- * InputStream to read from.
- *
- * @return the newly created Document instance
- *
- * @throws DocumentException
- * if an error occurs during parsing.
- */
- public Document read(InputStream in) throws DocumentException {
- InputSource source = new InputSource(in);
- if (this.encoding != null) {
- source.setEncoding(this.encoding);
- }
-
- return read(source);
- }
-
- /**
- *
- * Reads a Document from the given Reader using SAX
- *
- *
- * @param reader
- * is the reader for the input
- *
- * @return the newly created Document instance
- *
- * @throws DocumentException
- * if an error occurs during parsing.
- */
- public Document read(Reader reader) throws DocumentException {
- InputSource source = new InputSource(reader);
- if (this.encoding != null) {
- source.setEncoding(this.encoding);
- }
-
- return read(source);
- }
-
- /**
- *
- * Reads a Document from the given stream using SAX
- *
- *
- * @param in
- * InputStream to read from.
- * @param systemId
- * is the URI for the input
- *
- * @return the newly created Document instance
- *
- * @throws DocumentException
- * if an error occurs during parsing.
- */
- public Document read(InputStream in, String systemId)
- throws DocumentException {
- InputSource source = new InputSource(in);
- source.setSystemId(systemId);
- if (this.encoding != null) {
- source.setEncoding(this.encoding);
- }
-
- return read(source);
- }
-
- /**
- *
- * Reads a Document from the given Reader using SAX
- *
- *
- * @param reader
- * is the reader for the input
- * @param systemId
- * is the URI for the input
- *
- * @return the newly created Document instance
- *
- * @throws DocumentException
- * if an error occurs during parsing.
- */
- public Document read(Reader reader, String systemId)
- throws DocumentException {
- InputSource source = new InputSource(reader);
- source.setSystemId(systemId);
- if (this.encoding != null) {
- source.setEncoding(this.encoding);
- }
-
- return read(source);
- }
-
- /**
- *
- * Reads a Document from the given InputSource using SAX
- *
- *
- * @param in
- * InputSource to read from.
- *
- * @return the newly created Document instance
- *
- * @throws DocumentException
- * if an error occurs during parsing.
- */
- public Document read(InputSource in) throws DocumentException {
- try {
- XMLReader reader = getXMLReader();
-
- reader = installXMLFilter(reader);
-
- EntityResolver thatEntityResolver = this.entityResolver;
-
- if (thatEntityResolver == null) {
- thatEntityResolver = createDefaultEntityResolver(in
- .getSystemId());
- this.entityResolver = thatEntityResolver;
- }
-
- reader.setEntityResolver(thatEntityResolver);
-
- SAXContentHandler contentHandler = createContentHandler(reader);
- contentHandler.setEntityResolver(thatEntityResolver);
- contentHandler.setInputSource(in);
-
- boolean internal = isIncludeInternalDTDDeclarations();
- boolean external = isIncludeExternalDTDDeclarations();
-
- contentHandler.setIncludeInternalDTDDeclarations(internal);
- contentHandler.setIncludeExternalDTDDeclarations(external);
- contentHandler.setMergeAdjacentText(isMergeAdjacentText());
- contentHandler.setStripWhitespaceText(isStripWhitespaceText());
- contentHandler.setIgnoreComments(isIgnoreComments());
- reader.setContentHandler(contentHandler);
-
- configureReader(reader, contentHandler);
-
- reader.parse(in);
-
- return contentHandler.getDocument();
- } catch (Exception e) {
- if (e instanceof SAXParseException) {
- // e.printStackTrace();
- SAXParseException parseException = (SAXParseException) e;
- String systemId = parseException.getSystemId();
-
- if (systemId == null) {
- systemId = "";
- }
-
- String message = "Error on line "
- + parseException.getLineNumber() + " of document "
- + systemId + " : " + parseException.getMessage();
-
- throw new DocumentException(message, e);
- } else {
- throw new DocumentException(e.getMessage(), e);
- }
- }
- }
-
- // Properties
- // -------------------------------------------------------------------------
-
- /**
- * DOCUMENT ME!
- *
- * @return the validation mode, true if validating will be done otherwise
- * false.
- */
- public boolean isValidating() {
- return validating;
- }
-
- /**
- * Sets the validation mode.
- *
- * @param validation
- * indicates whether or not validation should occur.
- */
- public void setValidation(boolean validation) {
- this.validating = validation;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return whether internal DTD declarations should be expanded into the
- * DocumentType object or not.
- */
- public boolean isIncludeInternalDTDDeclarations() {
- return includeInternalDTDDeclarations;
- }
-
- /**
- * Sets whether internal DTD declarations should be expanded into the
- * DocumentType object or not.
- *
- * @param include
- * whether or not DTD declarations should be expanded and
- * included into the DocumentType object.
- */
- public void setIncludeInternalDTDDeclarations(boolean include) {
- this.includeInternalDTDDeclarations = include;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return whether external DTD declarations should be expanded into the
- * DocumentType object or not.
- */
- public boolean isIncludeExternalDTDDeclarations() {
- return includeExternalDTDDeclarations;
- }
-
- /**
- * Sets whether DTD external declarations should be expanded into the
- * DocumentType object or not.
- *
- * @param include
- * whether or not DTD declarations should be expanded and
- * included into the DocumentType object.
- */
- public void setIncludeExternalDTDDeclarations(boolean include) {
- this.includeExternalDTDDeclarations = include;
- }
-
- /**
- * Sets whether String interning is enabled or disabled for element &
- * attribute names and namespace URIs. This proprety is enabled by default.
- *
- * @return DOCUMENT ME!
- */
- public boolean isStringInternEnabled() {
- return stringInternEnabled;
- }
-
- /**
- * Sets whether String interning is enabled or disabled for element &
- * attribute names and namespace URIs
- *
- * @param stringInternEnabled
- * DOCUMENT ME!
- */
- public void setStringInternEnabled(boolean stringInternEnabled) {
- this.stringInternEnabled = stringInternEnabled;
- }
-
- /**
- * Returns whether adjacent text nodes should be merged together.
- *
- * @return Value of property mergeAdjacentText.
- */
- public boolean isMergeAdjacentText() {
- return mergeAdjacentText;
- }
-
- /**
- * Sets whether or not adjacent text nodes should be merged together when
- * parsing.
- *
- * @param mergeAdjacentText
- * New value of property mergeAdjacentText.
- */
- public void setMergeAdjacentText(boolean mergeAdjacentText) {
- this.mergeAdjacentText = mergeAdjacentText;
- }
-
- /**
- * Sets whether whitespace between element start and end tags should be
- * ignored
- *
- * @return Value of property stripWhitespaceText.
- */
- public boolean isStripWhitespaceText() {
- return stripWhitespaceText;
- }
-
- /**
- * Sets whether whitespace between element start and end tags should be
- * ignored.
- *
- * @param stripWhitespaceText
- * New value of property stripWhitespaceText.
- */
- public void setStripWhitespaceText(boolean stripWhitespaceText) {
- this.stripWhitespaceText = stripWhitespaceText;
- }
-
- /**
- * Returns whether we should ignore comments or not.
- *
- * @return boolean
- */
- public boolean isIgnoreComments() {
- return ignoreComments;
- }
-
- /**
- * Sets whether we should ignore comments or not.
- *
- * @param ignoreComments
- * whether we should ignore comments or not.
- */
- public void setIgnoreComments(boolean ignoreComments) {
- this.ignoreComments = ignoreComments;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return the DocumentFactory used to create document
- * objects
- */
- public DocumentFactory getDocumentFactory() {
- if (factory == null) {
- factory = DocumentFactory.getInstance();
- }
-
- return factory;
- }
-
- /**
- *
- * This sets the DocumentFactory used to create new
- * documents. This method allows the building of custom DOM4J tree objects
- * to be implemented easily using a custom derivation of
- * {@link DocumentFactory}
- *
- *
- * @param documentFactory
- * DocumentFactory used to create DOM4J objects
- */
- public void setDocumentFactory(DocumentFactory documentFactory) {
- this.factory = documentFactory;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return the ErrorHandler used by SAX
- */
- public ErrorHandler getErrorHandler() {
- return errorHandler;
- }
-
- /**
- * Sets the ErrorHandler used by the SAX
- * XMLReader.
- *
- * @param errorHandler
- * is the ErrorHandler used by SAX
- */
- public void setErrorHandler(ErrorHandler errorHandler) {
- this.errorHandler = errorHandler;
- }
-
- /**
- * Returns the current entity resolver used to resolve entities
- *
- * @return DOCUMENT ME!
- */
- public EntityResolver getEntityResolver() {
- return entityResolver;
- }
-
- /**
- * Sets the entity resolver used to resolve entities.
- *
- * @param entityResolver
- * DOCUMENT ME!
- */
- public void setEntityResolver(EntityResolver entityResolver) {
- this.entityResolver = entityResolver;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return the XMLReader used to parse SAX events
- *
- * @throws SAXException
- * DOCUMENT ME!
- */
- public XMLReader getXMLReader() throws SAXException {
- if (xmlReader == null) {
- xmlReader = createXMLReader();
- }
-
- return xmlReader;
- }
-
- /**
- * Sets the XMLReader used to parse SAX events
- *
- * @param reader
- * is the XMLReader to parse SAX events
- */
- public void setXMLReader(XMLReader reader) {
- this.xmlReader = reader;
- }
-
- /**
- * Returns encoding used for InputSource (null means system default
- * encoding)
- *
- * @return encoding used for InputSource
- *
- */
- public String getEncoding() {
- return encoding;
- }
-
- /**
- * Sets encoding used for InputSource (null means system default encoding)
- *
- * @param encoding
- * is encoding used for InputSource
- */
- public void setEncoding(String encoding) {
- this.encoding = encoding;
- }
-
- /**
- * Sets the class name of the XMLReader to be used to parse
- * SAX events.
- *
- * @param xmlReaderClassName
- * is the class name of the XMLReader to parse SAX
- * events
- *
- * @throws SAXException
- * DOCUMENT ME!
- */
- public void setXMLReaderClassName(String xmlReaderClassName)
- throws SAXException {
- setXMLReader(XMLReaderFactory.createXMLReader(xmlReaderClassName));
- }
-
- /**
- * Adds the ElementHandler to be called when the specified
- * path is encounted.
- *
- * @param path
- * is the path to be handled
- * @param handler
- * is the ElementHandler to be called by the event
- * based processor.
- */
- public void addHandler(String path, ElementHandler handler) {
- getDispatchHandler().addHandler(path, handler);
- }
-
- /**
- * Removes the ElementHandler from the event based processor,
- * for the specified path.
- *
- * @param path
- * is the path to remove the ElementHandler for.
- */
- public void removeHandler(String path) {
- getDispatchHandler().removeHandler(path);
- }
-
- /**
- * When multiple ElementHandler instances have been
- * registered, this will set a default ElementHandler to be
- * called for any path which does NOT have a handler registered.
- *
- * @param handler
- * is the ElementHandler to be called by the event
- * based processor.
- */
- public void setDefaultHandler(ElementHandler handler) {
- getDispatchHandler().setDefaultHandler(handler);
- }
-
- /**
- * This method clears out all the existing handlers and default handler
- * setting things back as if no handler existed. Useful when reusing an
- * object instance.
- */
- public void resetHandlers() {
- getDispatchHandler().resetHandlers();
- }
-
- /**
- * Returns the SAX filter being used to filter SAX events.
- *
- * @return the SAX filter being used or null if no SAX filter is installed
- */
- public XMLFilter getXMLFilter() {
- return xmlFilter;
- }
-
- /**
- * Sets the SAX filter to be used when filtering SAX events
- *
- * @param filter
- * is the SAX filter to use or null to disable filtering
- */
- public void setXMLFilter(XMLFilter filter) {
- this.xmlFilter = filter;
- }
-
- // Implementation methods
- // -------------------------------------------------------------------------
-
- /**
- * Installs any XMLFilter objects required to allow the SAX event stream to
- * be filtered and preprocessed before it gets to dom4j.
- *
- * @param reader
- * DOCUMENT ME!
- *
- * @return the new XMLFilter if applicable or the original XMLReader if no
- * filter is being used.
- */
- protected XMLReader installXMLFilter(XMLReader reader) {
- XMLFilter filter = getXMLFilter();
-
- if (filter != null) {
- // find the root XMLFilter
- XMLFilter root = filter;
-
- while (true) {
- XMLReader parent = root.getParent();
-
- if (parent instanceof XMLFilter) {
- root = (XMLFilter) parent;
- } else {
- break;
- }
- }
-
- root.setParent(reader);
-
- return filter;
- }
-
- return reader;
- }
-
- protected DispatchHandler getDispatchHandler() {
- if (dispatchHandler == null) {
- dispatchHandler = new DispatchHandler();
- }
-
- return dispatchHandler;
- }
-
- protected void setDispatchHandler(DispatchHandler dispatchHandler) {
- this.dispatchHandler = dispatchHandler;
- }
-
- /**
- * Factory Method to allow alternate methods of creating and configuring
- * XMLReader objects
- *
- * @return DOCUMENT ME!
- *
- * @throws SAXException
- * DOCUMENT ME!
- */
- protected XMLReader createXMLReader() throws SAXException {
- return SAXHelper.createXMLReader(isValidating());
- }
-
- /**
- * Configures the XMLReader before use
- *
- * @param reader
- * DOCUMENT ME!
- * @param handler
- * DOCUMENT ME!
- *
- * @throws DocumentException
- * DOCUMENT ME!
- */
- protected void configureReader(XMLReader reader, DefaultHandler handler)
- throws DocumentException {
- // configure lexical handling
- SAXHelper.setParserProperty(reader, SAX_LEXICALHANDLER, handler);
-
- // try alternate property just in case
- SAXHelper.setParserProperty(reader, SAX_LEXICAL_HANDLER, handler);
-
- // register the DeclHandler
- if (includeInternalDTDDeclarations || includeExternalDTDDeclarations) {
- SAXHelper.setParserProperty(reader, SAX_DECL_HANDLER, handler);
- }
-
- // configure namespace support
- SAXHelper.setParserFeature(reader, SAX_NAMESPACES, true);
-
- SAXHelper.setParserFeature(reader, SAX_NAMESPACE_PREFIXES, false);
-
- // string interning
- SAXHelper.setParserFeature(reader, SAX_STRING_INTERNING,
- isStringInternEnabled());
-
- // external entites
- /*
- * SAXHelper.setParserFeature( reader,
- * "http://xml.org/sax/properties/external-general-entities",
- * includeExternalGeneralEntities ); SAXHelper.setParserFeature( reader,
- * "http://xml.org/sax/properties/external-parameter-entities",
- * includeExternalParameterEntities );
- */
- // use Locator2 if possible
- SAXHelper.setParserFeature(reader,
- "http://xml.org/sax/features/use-locator2", true);
-
- try {
- // configure validation support
- reader.setFeature("http://xml.org/sax/features/validation",
- isValidating());
-
- if (errorHandler != null) {
- reader.setErrorHandler(errorHandler);
- } else {
- reader.setErrorHandler(handler);
- }
- } catch (Exception e) {
- if (isValidating()) {
- throw new DocumentException("Validation not supported for"
- + " XMLReader: " + reader, e);
- }
- }
- }
-
- /**
- * Factory Method to allow user derived SAXContentHandler objects to be used
- *
- * @param reader
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- protected SAXContentHandler createContentHandler(XMLReader reader) {
- return new SAXContentHandler(getDocumentFactory(), dispatchHandler);
- }
-
- protected EntityResolver createDefaultEntityResolver(String systemId) {
- String prefix = null;
-
- if ((systemId != null) && (systemId.length() > 0)) {
- int idx = systemId.lastIndexOf('/');
-
- if (idx > 0) {
- prefix = systemId.substring(0, idx + 1);
- }
- }
-
- return new SAXEntityResolver(prefix);
- }
-
- protected static class SAXEntityResolver implements EntityResolver,
- Serializable {
- protected String uriPrefix;
-
- public SAXEntityResolver(String uriPrefix) {
- this.uriPrefix = uriPrefix;
- }
-
- public InputSource resolveEntity(String publicId, String systemId) {
- // try create a relative URI reader...
- if ((systemId != null) && (systemId.length() > 0)) {
- if ((uriPrefix != null) && (systemId.indexOf(':') <= 0)) {
- systemId = uriPrefix + systemId;
- }
- }
-
- return new InputSource(systemId);
- }
+ return new InputSource(systemId);
}
+ }
}
/*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the
* following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document.
- *
+ *
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com.
- *
+ *
* 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
- *
+ *
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
- *
+ *
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -1037,6 +1016,6 @@ public class SAXReader {
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXValidator.java b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXValidator.java
index 11aa749ca..325ccb94e 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXValidator.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXValidator.java
@@ -27,7 +27,7 @@ import org.xml.sax.helpers.DefaultHandler;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.10 $
*/
public class SAXValidator {
/** XMLReader used to parse the SAX events */
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXWriter.java b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXWriter.java
index bc5ae1027..43082c724 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/SAXWriter.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/SAXWriter.java
@@ -48,7 +48,7 @@ import org.xml.sax.helpers.LocatorImpl;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.24 $
*/
public class SAXWriter implements XMLReader {
protected static final String[] LEXICAL_HANDLER_NAMES = {
@@ -79,10 +79,10 @@ public class SAXWriter implements XMLReader {
private AttributesImpl attributes = new AttributesImpl();
/** Stores the features */
- private Map features = new HashMap();
+ private Map features = new HashMap();
/** Stores the properties */
- private Map properties = new HashMap();
+ private Map properties = new HashMap();
/** Whether namespace declarations are exported as attributes or not */
private boolean declareNamespaceAttributes;
@@ -493,9 +493,9 @@ public class SAXWriter implements XMLReader {
*/
public boolean getFeature(String name) throws SAXNotRecognizedException,
SAXNotSupportedException {
- Boolean answer = (Boolean) features.get(name);
+ Boolean answer = features.get(name);
- return (answer != null) && answer.booleanValue();
+ return (answer != null) && answer;
}
/**
@@ -535,8 +535,8 @@ public class SAXWriter implements XMLReader {
* DOCUMENT ME!
*/
public void setProperty(String name, Object value) {
- for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) {
- if (LEXICAL_HANDLER_NAMES[i].equals(name)) {
+ for (String lexicalHandlerName : LEXICAL_HANDLER_NAMES) {
+ if (lexicalHandlerName.equals(name)) {
setLexicalHandler((LexicalHandler) value);
return;
@@ -561,8 +561,8 @@ public class SAXWriter implements XMLReader {
*/
public Object getProperty(String name) throws SAXNotRecognizedException,
SAXNotSupportedException {
- for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) {
- if (LEXICAL_HANDLER_NAMES[i].equals(name)) {
+ for (String lexicalHandlerName : LEXICAL_HANDLER_NAMES) {
+ if (lexicalHandlerName.equals(name)) {
return getLexicalHandler();
}
}
@@ -612,34 +612,32 @@ public class SAXWriter implements XMLReader {
// -------------------------------------------------------------------------
protected void writeContent(Branch branch, NamespaceStack namespaceStack)
throws SAXException {
- for (Iterator iter = branch.nodeIterator(); iter.hasNext();) {
- Object object = iter.next();
-
- if (object instanceof Element) {
- write((Element) object, namespaceStack);
- } else if (object instanceof CharacterData) {
- if (object instanceof Text) {
- Text text = (Text) object;
+ for (Iterator iter = branch.nodeIterator(); iter.hasNext();) {
+ Node node = iter.next();
+
+ if (node instanceof Element) {
+ write((Element) node, namespaceStack);
+ } else if (node instanceof CharacterData) {
+ if (node instanceof Text) {
+ Text text = (Text) node;
write(text.getText());
- } else if (object instanceof CDATA) {
- write((CDATA) object);
- } else if (object instanceof Comment) {
- write((Comment) object);
+ } else if (node instanceof CDATA) {
+ write((CDATA) node);
+ } else if (node instanceof Comment) {
+ write((Comment) node);
} else {
throw new SAXException("Invalid Node in DOM4J content: "
- + object + " of type: " + object.getClass());
+ + node + " of type: " + node.getClass());
}
- } else if (object instanceof String) {
- write((String) object);
- } else if (object instanceof Entity) {
- write((Entity) object);
- } else if (object instanceof ProcessingInstruction) {
- write((ProcessingInstruction) object);
- } else if (object instanceof Namespace) {
- write((Namespace) object);
+ } else if (node instanceof Entity) {
+ write((Entity) node);
+ } else if (node instanceof ProcessingInstruction) {
+ write((ProcessingInstruction) node);
+ } else if (node instanceof Namespace) {
+ write((Namespace) node);
} else {
throw new SAXException("Invalid Node in DOM4J content: "
- + object);
+ + node);
}
}
}
@@ -765,11 +763,9 @@ public class SAXWriter implements XMLReader {
elementNamespace);
}
- List declaredNamespaces = element.declaredNamespaces();
-
- for (int i = 0, size = declaredNamespaces.size(); i < size; i++) {
- Namespace namespace = (Namespace) declaredNamespaces.get(i);
+ List declaredNamespaces = element.declaredNamespaces();
+ for (Namespace namespace : declaredNamespaces) {
if (!isIgnoreableNamespace(namespace, namespaceStack)) {
namespaceStack.push(namespace);
contentHandler.startPrefixMapping(namespace.getPrefix(),
@@ -825,8 +821,8 @@ public class SAXWriter implements XMLReader {
attributes.setAttributes(namespaceAttributes);
}
- for (Iterator iter = element.attributeIterator(); iter.hasNext();) {
- Attribute attribute = (Attribute) iter.next();
+ for (Iterator iter = element.attributeIterator(); iter.hasNext();) {
+ Attribute attribute = iter.next();
attributes.addAttribute(attribute.getNamespaceURI(), attribute
.getName(), attribute.getQualifiedName(), "CDATA",
attribute.getValue());
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventReader.java b/fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventReader.java
index 18e39b5c5..9c4f5692b 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventReader.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventReader.java
@@ -293,7 +293,7 @@ public class STAXEventReader {
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
- * stream was not positioned before a {@linkStartElement}event.
+ * stream was not positioned before a {@link StartElement}event.
*/
public Element readElement(XMLEventReader eventReader)
throws XMLStreamException {
@@ -348,7 +348,7 @@ public class STAXEventReader {
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
- * stream was not positioned before an {@linkAttribute}event.
+ * stream was not positioned before an {@link Attribute}event.
*/
public org.dom4j.Attribute readAttribute(XMLEventReader reader)
throws XMLStreamException {
@@ -375,7 +375,7 @@ public class STAXEventReader {
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
- * stream was not positioned before a {@linkNamespace}event.
+ * stream was not positioned before a {@link Namespace}event.
*/
public org.dom4j.Namespace readNamespace(XMLEventReader reader)
throws XMLStreamException {
@@ -402,7 +402,7 @@ public class STAXEventReader {
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
- * stream was not positioned before a {@linkCharacters}event.
+ * stream was not positioned before a {@link Characters}event.
*/
public CharacterData readCharacters(XMLEventReader reader)
throws XMLStreamException {
@@ -429,7 +429,7 @@ public class STAXEventReader {
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
- * stream was not positioned before a {@linkComment}event.
+ * stream was not positioned before a {@link Comment}event.
*/
public org.dom4j.Comment readComment(XMLEventReader reader)
throws XMLStreamException {
@@ -455,7 +455,7 @@ public class STAXEventReader {
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
- * stream was not positioned before an {@linkEntityReference}
+ * stream was not positioned before an {@link EntityReference}
* event.
*/
public Entity readEntityReference(XMLEventReader reader)
@@ -518,14 +518,14 @@ public class STAXEventReader {
Element elem = factory.createElement(elemName);
// create attributes
- for (Iterator i = startEvent.getAttributes(); i.hasNext();) {
- Attribute attr = (Attribute) i.next();
+ for (Iterator i = startEvent.getAttributes(); i.hasNext();) {
+ Attribute attr = i.next();
elem.addAttribute(createQName(attr.getName()), attr.getValue());
}
// create namespaces
- for (Iterator i = startEvent.getNamespaces(); i.hasNext();) {
- Namespace ns = (Namespace) i.next();
+ for (Iterator i = startEvent.getNamespaces(); i.hasNext();) {
+ Namespace ns = i.next();
elem.addNamespace(ns.getPrefix(), ns.getNamespaceURI());
}
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventWriter.java b/fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventWriter.java
index aba966298..a97dd0ca6 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventWriter.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventWriter.java
@@ -270,8 +270,8 @@ public class STAXEventWriter {
QName tagName = createQName(elem.getQName());
// create attribute & namespace iterators
- Iterator attrIter = new AttributeIterator(elem.attributeIterator());
- Iterator nsIter = new NamespaceIterator(elem.declaredNamespaces()
+ Iterator attrIter = new AttributeIterator(elem.attributeIterator());
+ Iterator nsIter = new NamespaceIterator(elem.declaredNamespaces()
.iterator());
// create start event
@@ -288,7 +288,7 @@ public class STAXEventWriter {
*/
public EndElement createEndElement(Element elem) {
QName tagName = createQName(elem.getQName());
- Iterator nsIter = new NamespaceIterator(elem.declaredNamespaces()
+ Iterator nsIter = new NamespaceIterator(elem.declaredNamespaces()
.iterator());
return factory.createEndElement(tagName, nsIter);
@@ -593,11 +593,11 @@ public class STAXEventWriter {
* Internal {@link Iterator}implementation used to pass DOM4J {@link
* Attribute}s to the stream.
*/
- private class AttributeIterator implements Iterator {
+ private class AttributeIterator implements Iterator {
/** The underlying DOm4J attribute iterator. */
- private Iterator iter;
+ private Iterator iter;
- public AttributeIterator(Iterator iter) {
+ public AttributeIterator(Iterator iter) {
this.iter = iter;
}
@@ -605,8 +605,8 @@ public class STAXEventWriter {
return iter.hasNext();
}
- public Object next() {
- Attribute attr = (Attribute) iter.next();
+ public javax.xml.stream.events.Attribute next() {
+ Attribute attr = iter.next();
QName attrName = createQName(attr.getQName());
String value = attr.getValue();
@@ -622,10 +622,10 @@ public class STAXEventWriter {
* Internal {@link Iterator}implementation used to pass DOM4J {@link
* Namespace}s to the stream.
*/
- private class NamespaceIterator implements Iterator {
- private Iterator iter;
+ private class NamespaceIterator implements Iterator {
+ private Iterator iter;
- public NamespaceIterator(Iterator iter) {
+ public NamespaceIterator(Iterator iter) {
this.iter = iter;
}
@@ -633,8 +633,8 @@ public class STAXEventWriter {
return iter.hasNext();
}
- public Object next() {
- Namespace ns = (Namespace) iter.next();
+ public javax.xml.stream.events.Namespace next() {
+ Namespace ns = iter.next();
String prefix = ns.getPrefix();
String nsURI = ns.getURI();
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/XMLResult.java b/fine-org-dom4j/src/main/java/org/dom4j/io/XMLResult.java
index 5364f5883..23772e6ef 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/XMLResult.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/XMLResult.java
@@ -24,7 +24,7 @@ import org.xml.sax.ext.LexicalHandler;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.9 $
*/
public class XMLResult extends SAXResult {
private XMLWriter xmlWriter;
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/XMLWriter.java b/fine-org-dom4j/src/main/java/org/dom4j/io/XMLWriter.java
index 9df68eddb..7f698edc7 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/XMLWriter.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/XMLWriter.java
@@ -42,6 +42,9 @@ import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.XMLFilterImpl;
+import static org.dom4j.util.StringUtils.endsWithWhitespace;
+import static org.dom4j.util.StringUtils.startsWithWhitespace;
+
/**
*
* XMLWriter takes a DOM4J tree and formats it to a stream as
@@ -54,7 +57,7 @@ import org.xml.sax.helpers.XMLFilterImpl;
* such as to allow suppression of the XML declaration, the encoding declaration
* or whether empty documents are collapsed.
*
- *
+ *
*
* There are write(...) methods to print any of the standard
* DOM4J classes, including Document and Element,
@@ -63,10 +66,10 @@ import org.xml.sax.helpers.XMLFilterImpl;
* preferred character encoding to be ignored. If you use encodings other than
* UTF8, we recommend using the method that takes an OutputStream instead.
*
- *
+ *
* @author James Strachan
* @author Joseph Bowbeer
- * @version $Revision$
+ * @version $Revision: 1.83 $
*/
public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
private static final String PAD_TEXT = " ";
@@ -139,7 +142,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
private boolean inDTD;
/** The namespaces used for the current element when consuming SAX events */
- private Map namespacesMap;
+ private Map namespacesMap;
/**
* what is the maximum allowed character code such as 127 in US-ASCII (7
@@ -200,7 +203,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* DOCUMENT ME!
- *
+ *
* @return true if text thats output should be escaped. This is enabled by
* default. It could be disabled if the output format is textual,
* like in XSLT where we can have xml, html or text output.
@@ -213,7 +216,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Sets whether text output should be escaped or not. This is enabled by
* default. It could be disabled if the output format is textual, like in
* XSLT where we can have xml, html or text output.
- *
+ *
* @param escapeText
* DOCUMENT ME!
*/
@@ -225,7 +228,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Set the initial indentation level. This can be used to output a document
* (or, more likely, an element) starting at a given indent level, so it's
* not always flush against the left margin. Default: 0
- *
+ *
* @param indentLevel
* the number of indents to start with
*/
@@ -237,7 +240,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Returns the maximum allowed character code that should be allowed
* unescaped which defaults to 127 in US-ASCII (7 bit) or 255 in ISO- (8
* bit).
- *
+ *
* @return DOCUMENT ME!
*/
public int getMaximumAllowedCharacter() {
@@ -254,7 +257,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* escape any characters (other than the special XML characters like <
* > &) If this is not explicitly set then it is defaulted from the
* encoding.
- *
+ *
* @param maximumAllowedCharacter
* The maximumAllowedCharacter to set
*/
@@ -264,7 +267,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Flushes the underlying Writer
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -274,7 +277,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Closes the underlying Writer
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -284,7 +287,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the new line text to the underlying Writer
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -294,10 +297,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link Attribute}.
- *
+ *
* @param attribute
* Attribute to output.
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -313,21 +316,21 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
*
* This will print the Document to the current Writer.
*
- *
+ *
*
* Warning: using your own Writer may cause the writer's preferred character
* encoding to be ignored. If you use encodings other than UTF8, we
* recommend using the method that takes an OutputStream instead.
*
- *
+ *
*
* Note: as with all Writers, you may need to flush() yours after this
* method returns.
*
- *
+ *
* @param doc
* Document to format.
- *
+ *
* @throws IOException
* if there's any problem writing.
*/
@@ -358,10 +361,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* s, and its value, and all its content (child nodes) to the current
* Writer.
*
- *
+ *
* @param element
* Element to output.
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -375,10 +378,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link CDATA}.
- *
+ *
* @param cdata
* CDATA to output.
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -392,10 +395,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link Comment}.
- *
+ *
* @param comment
* Comment to output.
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -409,10 +412,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link DocumentType}.
- *
+ *
* @param docType
* DocumentType to output.
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -426,10 +429,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link Entity}.
- *
+ *
* @param entity
* Entity to output.
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -443,10 +446,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link Namespace}.
- *
+ *
* @param namespace
* Namespace to output.
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -460,10 +463,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link ProcessingInstruction}.
- *
+ *
* @param processingInstruction
* ProcessingInstruction to output.
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -481,10 +484,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Print out a {@link String}, Perfoms the necessary entity escaping and
* whitespace stripping.
*
- *
+ *
* @param text
* is the text to output
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -498,10 +501,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link Text}.
- *
+ *
* @param text
* Text to output.
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -515,10 +518,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link Node}.
- *
+ *
* @param node
* Node to output.
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -533,10 +536,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given object which should be a String, a Node or a List of
* Nodes.
- *
+ *
* @param object
* is the object to output.
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -546,10 +549,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
} else if (object instanceof String) {
write((String) object);
} else if (object instanceof List) {
- List list = (List) object;
+ List> list = (List>) object;
- for (int i = 0, size = list.size(); i < size; i++) {
- write(list.get(i));
+ for (Object aList : list) {
+ write(aList);
}
} else if (object != null) {
throw new IOException("Invalid object: " + object);
@@ -561,16 +564,17 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Writes the opening tag of an {@link Element}, including its {@link
* Attribute}s but without its content.
*
- *
+ *
* @param element
* Element to output.
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
public void writeOpen(Element element) throws IOException {
writer.write("<");
writer.write(element.getQualifiedName());
+ writeNamespaces(element);
writeAttributes(element);
writer.write(">");
}
@@ -579,10 +583,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
*
* Writes the closing tag of an {@link Element}
*
- *
+ *
* @param element
* Element to output.
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -599,8 +603,8 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
public void setProperty(String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
- for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) {
- if (LEXICAL_HANDLER_NAMES[i].equals(name)) {
+ for (String lexicalHandlerName : LEXICAL_HANDLER_NAMES) {
+ if (lexicalHandlerName.equals(name)) {
setLexicalHandler((LexicalHandler) value);
return;
@@ -612,8 +616,8 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
public Object getProperty(String name) throws SAXNotRecognizedException,
SAXNotSupportedException {
- for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) {
- if (LEXICAL_HANDLER_NAMES[i].equals(name)) {
+ for (String lexicalHandlerName : LEXICAL_HANDLER_NAMES) {
+ if (lexicalHandlerName.equals(name)) {
return getLexicalHandler();
}
}
@@ -662,7 +666,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
if (namespacesMap == null) {
- namespacesMap = new HashMap();
+ namespacesMap = new HashMap();
}
namespacesMap.put(prefix, uri);
@@ -975,10 +979,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Determines if element is a special case of XML elements where it contains
* an xml:space attribute of "preserve". If it does, then retain whitespace.
- *
+ *
* @param element
* DOCUMENT ME!
- *
+ *
* @return DOCUMENT ME!
*/
protected final boolean isElementSpacePreserved(Element element) {
@@ -986,12 +990,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
boolean preserveFound = preserve; // default to global state
if (attr != null) {
- if ("xml".equals(attr.getNamespacePrefix())
- && "preserve".equals(attr.getText())) {
- preserveFound = true;
- } else {
- preserveFound = false;
- }
+ preserveFound = "xml".equals(attr.getNamespacePrefix()) && "preserve".equals(attr.getText());
}
return preserveFound;
@@ -1003,10 +1002,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* whitespace trimming occurs to avoid problems with multiple text nodes
* being created due to text content that spans parser buffers in a SAX
* parser.
- *
+ *
* @param element
* DOCUMENT ME!
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -1023,34 +1022,34 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
// concatenate adjacent text nodes together
// so that whitespace trimming works properly
Text lastTextNode = null;
- StringBuffer buff = null;
+ StringBuilder buff = null;
boolean textOnly = true;
- for (int i = 0, size = element.nodeCount(); i < size; i++) {
- Node node = element.node(i);
-
+ for (Node node : element.content()) {
if (node instanceof Text) {
if (lastTextNode == null) {
lastTextNode = (Text) node;
} else {
if (buff == null) {
- buff = new StringBuffer(lastTextNode.getText());
+ buff = new StringBuilder(lastTextNode.getText());
}
- buff.append(((Text) node).getText());
+ buff.append((node).getText());
}
} else {
if (!textOnly && format.isPadText()) {
// only add the PAD_TEXT if the text itself starts with
// whitespace
- char firstChar = 'a';
+ final boolean startsWithWhitespace;
if (buff != null) {
- firstChar = buff.charAt(0);
+ startsWithWhitespace = startsWithWhitespace(buff);
} else if (lastTextNode != null) {
- firstChar = lastTextNode.getText().charAt(0);
+ startsWithWhitespace = startsWithWhitespace(lastTextNode.getText());
+ } else {
+ startsWithWhitespace = false;
}
- if (Character.isWhitespace(firstChar)) {
+ if (startsWithWhitespace) {
writer.write(PAD_TEXT);
}
}
@@ -1066,15 +1065,14 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
if (format.isPadText()) {
// only add the PAD_TEXT if the text itself ends
// with whitespace
- char lastTextChar = 'a';
+ final boolean endsWithWhitespace;
if (buff != null) {
- lastTextChar = buff.charAt(buff.length() - 1);
- } else if (lastTextNode != null) {
- String txt = lastTextNode.getText();
- lastTextChar = txt.charAt(txt.length() - 1);
+ endsWithWhitespace = endsWithWhitespace(buff);
+ } else {
+ endsWithWhitespace = endsWithWhitespace(lastTextNode.getText());
}
- if (Character.isWhitespace(lastTextChar)) {
+ if (endsWithWhitespace) {
writer.write(PAD_TEXT);
}
}
@@ -1091,14 +1089,14 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
if (!textOnly && format.isPadText()) {
// only add the PAD_TEXT if the text itself starts with
// whitespace
- char firstChar = 'a';
+ final boolean startsWithWhitespace;
if (buff != null) {
- firstChar = buff.charAt(0);
+ startsWithWhitespace = startsWithWhitespace(buff);
} else {
- firstChar = lastTextNode.getText().charAt(0);
+ startsWithWhitespace = startsWithWhitespace(lastTextNode.getText());
}
- if (Character.isWhitespace(firstChar)) {
+ if (startsWithWhitespace) {
writer.write(PAD_TEXT);
}
}
@@ -1115,9 +1113,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
} else {
Node lastTextNode = null;
- for (int i = 0, size = element.nodeCount(); i < size; i++) {
- Node node = element.node(i);
-
+ for (Node node : element.content()) {
if (node instanceof Text) {
writeNode(node);
lastTextNode = node;
@@ -1125,10 +1121,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
if ((lastTextNode != null) && format.isPadText()) {
// only add the PAD_TEXT if the text itself ends with
// whitespace
- String txt = lastTextNode.getText();
- char lastTextChar = txt.charAt(txt.length() - 1);
-
- if (Character.isWhitespace(lastTextChar)) {
+ if (endsWithWhitespace(lastTextNode.getText())) {
writer.write(PAD_TEXT);
}
}
@@ -1174,17 +1167,15 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the SAX namepsaces
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
protected void writeNamespaces() throws IOException {
if (namespacesMap != null) {
- for (Iterator iter = namespacesMap.entrySet().iterator(); iter
- .hasNext();) {
- Map.Entry entry = (Map.Entry) iter.next();
- String prefix = (String) entry.getKey();
- String uri = (String) entry.getValue();
+ for (Map.Entry entry : namespacesMap.entrySet()) {
+ String prefix = entry.getKey();
+ String uri = entry.getValue();
writeNamespace(prefix, uri);
}
@@ -1194,15 +1185,15 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the SAX namepsaces
- *
+ *
* @param prefix
* the prefix
* @param uri
* the namespace uri
- *
- * @throws IOException
+ *
+ * @throws IOException DOCUMENT ME!
*/
- protected void writeNamespace(String prefix, String uri)
+ protected void writeNamespace(String prefix, String uri)
throws IOException {
if ((prefix != null) && (prefix.length() > 0)) {
writer.write(" xmlns:");
@@ -1216,6 +1207,19 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
writer.write("\"");
}
+ /**
+ * Writes all namespaces declared directly on element.
+ *
+ * @throws IOException
+ */
+ protected void writeNamespaces(Element element) throws IOException {
+ assert element != null;
+ for (Namespace ns : element.declaredNamespaces()) {
+ writeNamespace(ns);
+ namespaceStack.push(ns);
+ }
+ }
+
protected void writeProcessingInstruction(ProcessingInstruction pi)
throws IOException {
// indent();
@@ -1259,12 +1263,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
writer.write(token);
lastOutputNodeType = Node.TEXT_NODE;
- lastChar = token.charAt(token.length() - 1);
}
} else {
lastOutputNodeType = Node.TEXT_NODE;
writer.write(text);
- lastChar = text.charAt(text.length() - 1);
}
}
}
@@ -1272,10 +1274,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* This method is used to write out Nodes that contain text and still allow
* for xml:space to be handled properly.
- *
+ *
* @param node
* DOCUMENT ME!
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -1289,7 +1291,6 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
lastOutputNodeType = Node.TEXT_NODE;
writer.write(text);
- lastChar = text.charAt(text.length() - 1);
}
}
@@ -1362,9 +1363,9 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
}
// try to register for lexical events
- for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) {
+ for (String lexicalHandlerName : LEXICAL_HANDLER_NAMES) {
try {
- parent.setProperty(LEXICAL_HANDLER_NAMES[i], this);
+ parent.setProperty(lexicalHandlerName, this);
break;
} catch (SAXNotRecognizedException ex) {
@@ -1434,10 +1435,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the attributes of the given element
- *
+ *
* @param element
* DOCUMENT ME!
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -1481,26 +1482,24 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
writeNamespace(null, uri);
}
} else {
- char quote = format.getAttributeQuoteCharacter();
- writer.write(" ");
- writer.write(attribute.getQualifiedName());
- writer.write("=");
- writer.write(quote);
- writeEscapeAttributeEntities(attribute.getValue());
- writer.write(quote);
+ writeAttribute(attribute);
}
}
}
protected void writeAttribute(Attribute attribute) throws IOException {
+ writeAttribute(attribute.getQualifiedName(), attribute.getValue());
+ }
+
+ protected void writeAttribute(String qualifiedName, String value) throws IOException {
writer.write(" ");
- writer.write(attribute.getQualifiedName());
+ writer.write(qualifiedName);
writer.write("=");
char quote = format.getAttributeQuoteCharacter();
writer.write(quote);
- writeEscapeAttributeEntities(attribute.getValue());
+ writeEscapeAttributeEntities(value);
writer.write(quote);
lastOutputNodeType = Node.ATTRIBUTE_NODE;
@@ -1514,13 +1513,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
protected void writeAttribute(Attributes attributes, int index)
throws IOException {
- char quote = format.getAttributeQuoteCharacter();
- writer.write(" ");
- writer.write(attributes.getQName(index));
- writer.write("=");
- writer.write(quote);
- writeEscapeAttributeEntities(attributes.getValue(index));
- writer.write(quote);
+ writeAttribute(attributes.getQName(index), attributes.getValue(index));
}
protected void indent() throws IOException {
@@ -1537,29 +1530,26 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
*
* This will print a new line only if the newlines flag was set to true
*
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
protected void writePrintln() throws IOException {
if (format.isNewlines()) {
- String seperator = format.getLineSeparator();
- if (lastChar != seperator.charAt(seperator.length() - 1)) {
- writer.write(format.getLineSeparator());
- }
+ writer.write(format.getLineSeparator());
}
}
/**
* Get an OutputStreamWriter, use preferred encoding.
- *
+ *
* @param outStream
* DOCUMENT ME!
* @param encoding
* DOCUMENT ME!
- *
+ *
* @return DOCUMENT ME!
- *
+ *
* @throws UnsupportedEncodingException
* DOCUMENT ME!
*/
@@ -1573,7 +1563,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* This will write the declaration to the given Writer. Assumes XML version
* 1.0 since we don't directly know.
*
- *
+ *
* @throws IOException
* DOCUMENT ME!
*/
@@ -1633,10 +1623,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* This will take the pre-defined entities in XML 1.0 and convert their
* character representation to the appropriate entity reference, suitable
* for XML attributes.
- *
+ *
* @param text
* DOCUMENT ME!
- *
+ *
* @return DOCUMENT ME!
*/
protected String escapeElementEntities(String text) {
@@ -1647,44 +1637,37 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
for (i = 0; i < size; i++) {
String entity = null;
- char c = text.charAt(i);
+ int c = text.codePointAt(i);
switch (c) {
case '<':
entity = "<";
-
break;
-
case '>':
entity = ">";
-
break;
-
case '&':
entity = "&";
-
break;
-
case '\t':
case '\n':
case '\r':
-
// don't encode standard whitespace characters
if (preserve) {
- entity = String.valueOf(c);
+ entity = String.valueOf((char) c);
}
-
break;
default:
if ((c < 32) || shouldEncodeChar(c)) {
- entity = "" + (int) c + ";";
+ entity = "" + c + ";";
}
break;
}
+
if (entity != null) {
if (block == null) {
block = text.toCharArray();
@@ -1693,6 +1676,12 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
buffer.append(block, last, i - last);
buffer.append(entity);
last = i + 1;
+ if (Character.isSupplementaryCodePoint(c)) {
+ last++;
+ }
+ }
+ if (Character.isSupplementaryCodePoint(c)) {
+ i++;
}
}
@@ -1725,10 +1714,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* This will take the pre-defined entities in XML 1.0 and convert their
* character representation to the appropriate entity reference, suitable
* for XML attributes.
- *
+ *
* @param text
* DOCUMENT ME!
- *
+ *
* @return DOCUMENT ME!
*/
protected String escapeAttributeEntities(String text) {
@@ -1741,53 +1730,37 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
for (i = 0; i < size; i++) {
String entity = null;
- char c = text.charAt(i);
+ int c = text.codePointAt(i);
switch (c) {
case '<':
entity = "<";
-
break;
-
case '>':
entity = ">";
-
break;
-
case '\'':
-
if (quote == '\'') {
entity = "'";
}
-
break;
-
case '\"':
-
if (quote == '\"') {
entity = """;
}
-
break;
-
case '&':
entity = "&";
-
break;
-
case '\t':
case '\n':
case '\r':
-
// don't encode standard whitespace characters
break;
-
default:
-
if ((c < 32) || shouldEncodeChar(c)) {
- entity = "" + (int) c + ";";
+ entity = "" + c + ";";
}
-
break;
}
@@ -1799,6 +1772,12 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
buffer.append(block, last, i - last);
buffer.append(entity);
last = i + 1;
+ if(Character.isSupplementaryCodePoint(c)) {
+ last++;
+ }
+ }
+ if(Character.isSupplementaryCodePoint(c)) {
+ i++;
}
}
@@ -1823,23 +1802,23 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Should the given character be escaped. This depends on the encoding of
* the document.
- *
- * @param c
+ *
+ * @param codepoint Unicode codepoint.
* DOCUMENT ME!
- *
+ *
* @return boolean
*/
- protected boolean shouldEncodeChar(char c) {
+ protected boolean shouldEncodeChar(int codepoint) {
int max = getMaximumAllowedCharacter();
- return (max > 0) && (c > max);
+ return (max > 0) && (codepoint > max);
}
/**
* Returns the maximum allowed character code that should be allowed
* unescaped which defaults to 127 in US-ASCII (7 bit) or 255 in ISO- (8
* bit).
- *
+ *
* @return DOCUMENT ME!
*/
protected int defaultMaximumAllowedCharacter() {
@@ -1880,7 +1859,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* setTrimText, setNewLines, etc. Put in to support the HTMLWriter, in the
* way that it pushes the current newline/trim state onto a stack and
* overrides the state within preformatted tags.
- *
+ *
* @return DOCUMENT ME!
*/
protected OutputFormat getOutputFormat() {
@@ -1900,24 +1879,24 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the
* following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document.
- *
+ *
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com.
- *
+ *
* 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
- *
+ *
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
- *
+ *
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -1929,6 +1908,6 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/XPP3Reader.java b/fine-org-dom4j/src/main/java/org/dom4j/io/XPP3Reader.java
index b5228cb5d..6cd393dd7 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/XPP3Reader.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/XPP3Reader.java
@@ -37,7 +37,7 @@ import org.xmlpull.v1.XmlPullParserFactory;
*
* @author Pelle Braendgaard
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.3 $
*/
public class XPP3Reader {
/** DocumentFactory used to create new document objects */
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/XPPReader.java b/fine-org-dom4j/src/main/java/org/dom4j/io/XPPReader.java
index d4d2e82d2..4b7529fde 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/XPPReader.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/XPPReader.java
@@ -37,7 +37,7 @@ import org.gjt.xpp.XmlPullParserFactory;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.7 $
*/
public class XPPReader {
/** DocumentFactory used to create new document objects */
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/package-info.java b/fine-org-dom4j/src/main/java/org/dom4j/io/package-info.java
new file mode 100644
index 000000000..0f2f0e9d9
--- /dev/null
+++ b/fine-org-dom4j/src/main/java/org/dom4j/io/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Provides input and output via SAX and DOM together with writing dom4j objects to streams as XML text.
+ */
+package org.dom4j.io;
\ No newline at end of file
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/io/package.html b/fine-org-dom4j/src/main/java/org/dom4j/io/package.html
deleted file mode 100644
index fe02b3a4d..000000000
--- a/fine-org-dom4j/src/main/java/org/dom4j/io/package.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
Provides input and output via SAX and DOM together with writing dom4j
- objects to streams as XML text.
-
-
-
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBModifier.java b/fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBModifier.java
index 8a410d107..acbaed5f7 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBModifier.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBModifier.java
@@ -51,7 +51,7 @@ public class JAXBModifier extends JAXBSupport {
private OutputFormat outputFormat;
- private HashMap modifiers = new HashMap();
+ private HashMap modifiers = new HashMap();
/**
* Creates a new JAXBModifier for the given JAXB context path. This is the
@@ -105,7 +105,7 @@ public class JAXBModifier extends JAXBSupport {
/**
* Creates a new JAXBModifier for the given JAXB context path, using the
- * specified {@link java.lang.Classloader}. The specified {@link
+ * specified {@link java.lang.ClassLoader}. The specified {@link
* org.dom4j.io.OutputFormat} will be used while writing the XML stream.
*
* @param contextPath
@@ -441,13 +441,13 @@ public class JAXBModifier extends JAXBSupport {
modifier.resetModifiers();
- Iterator modifierIt = modifiers.entrySet().iterator();
+ Iterator> modifierIt = modifiers.entrySet().iterator();
while (modifierIt.hasNext()) {
- Map.Entry entry = (Map.Entry) modifierIt.next();
+ Map.Entry entry = modifierIt.next();
ElementModifier mod = new JAXBElementModifier(this,
- (JAXBObjectModifier) entry.getValue());
- getModifier().addModifier((String) entry.getKey(), mod);
+ entry.getValue());
+ getModifier().addModifier(entry.getKey(), mod);
}
modifier.setXMLWriter(getXMLWriter());
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBReader.java b/fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBReader.java
index f35645949..3f5283747 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBReader.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBReader.java
@@ -28,7 +28,7 @@ import org.xml.sax.InputSource;
/**
* Reads an XML document and creates a DOM4J tree from SAX parsing events.
* {@link JAXBObjectHandler}objects can be registered to automatically receive
- * unmarshalled XML fragments. Registered {@linkorg.dom4j.ElementHandler}
+ * unmarshalled XML fragments. Registered {@link org.dom4j.ElementHandler}
* implementations are notified when a certain element path is encountered
*
* @author Wonne Keysers (Realsoftware.be)
@@ -57,7 +57,7 @@ public class JAXBReader extends JAXBSupport {
/**
* Creates a new JAXBReader for the given JAXB context path, using the
- * specified {@link java.lang.Classloader}. This is the Java package where
+ * specified {@link java.lang.ClassLoader}. This is the Java package where
* JAXB can find the generated XML classes. This package MUST contain
* jaxb.properties!
*
@@ -333,7 +333,7 @@ public class JAXBReader extends JAXBSupport {
* Set to true when DOM4J elements must immediately be pruned from the tree.
* The {@link Document}will not be available afterwards!
*
- * @param pruneElements
+ * @param pruneElements DOCUMENT ME!
*/
public void setPruneElements(boolean pruneElements) {
this.pruneElements = pruneElements;
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBWriter.java b/fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBWriter.java
index b713d70ae..191d71357 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBWriter.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBWriter.java
@@ -70,7 +70,7 @@ public class JAXBWriter extends JAXBSupport {
/**
* Creates a new JAXBWriter for the given JAXB context path, using the
- * specified {@link java.lang.Classloader}. (This is the Java package where
+ * specified {@link java.lang.ClassLoader}. (This is the Java package where
* JAXB can find the generated XML classes. This package MUST contain
* jaxb.properties!)
*
@@ -87,7 +87,7 @@ public class JAXBWriter extends JAXBSupport {
/**
* Creates a new JAXBWriter for the given JAXB context path, using the
- * specified {@link java.lang.Classloader}. The specied {@link
+ * specified {@link java.lang.ClassLoader}. The specied {@link
* org.dom4j.io.OutputFormat} will be used while writing the XML stream.
*
* @param contextPath
@@ -148,7 +148,7 @@ public class JAXBWriter extends JAXBSupport {
* @param writer
* writer to write to
*
- * @throws IOException
+ * @throws IOException DOCUMENT ME!
*/
public void setOutput(Writer writer) throws IOException {
getWriter().setWriter(writer);
@@ -185,7 +185,7 @@ public class JAXBWriter extends JAXBSupport {
* {@link javax.xml.bind.Element}instances can be created using the
* ObjectFactory that is generated by the JAXB compiler.
*
- * @param jaxbObject
+ * @param jaxbObject DOCUMENT ME!
*
* @throws IOException
* if an error occured while writing the output
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/package-info.java b/fine-org-dom4j/src/main/java/org/dom4j/package-info.java
new file mode 100644
index 000000000..d4903687b
--- /dev/null
+++ b/fine-org-dom4j/src/main/java/org/dom4j/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Defines the XML Document Object Model in Java interfaces together with some helper classes.
+ */
+package org.dom4j;
\ No newline at end of file
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/package.html b/fine-org-dom4j/src/main/java/org/dom4j/package.html
deleted file mode 100644
index a1b8a9d3e..000000000
--- a/fine-org-dom4j/src/main/java/org/dom4j/package.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
Defines the XML Document Object Model in Java interfaces together
- with some helper classes.
-
-
-
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/rule/Action.java b/fine-org-dom4j/src/main/java/org/dom4j/rule/Action.java
index a10ad9a9b..8f287f9d3 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/rule/Action.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/rule/Action.java
@@ -16,7 +16,7 @@ import org.dom4j.Node;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.7 $
*/
public interface Action {
void run(Node node) throws Exception;
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/rule/Mode.java b/fine-org-dom4j/src/main/java/org/dom4j/rule/Mode.java
index 26e910de8..2293aaa04 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/rule/Mode.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/rule/Mode.java
@@ -24,16 +24,16 @@ import org.dom4j.Node;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.9 $
*/
public class Mode {
private RuleSet[] ruleSets = new RuleSet[Pattern.NUMBER_OF_TYPES];
/** Map of exact (local) element names to RuleSet instances */
- private Map elementNameRuleSets;
+ private Map elementNameRuleSets;
/** Map of exact (local) attribute names to RuleSet instances */
- private Map attributeNameRuleSets;
+ private Map attributeNameRuleSets;
public Mode() {
}
@@ -240,12 +240,12 @@ public class Mode {
*
* @return the Map (which will be created if the given map was null
*/
- protected Map addToNameMap(Map map, String name, Rule rule) {
+ protected Map addToNameMap(Map map, String name, Rule rule) {
if (map == null) {
- map = new HashMap();
+ map = new HashMap();
}
- RuleSet ruleSet = (RuleSet) map.get(name);
+ RuleSet ruleSet = map.get(name);
if (ruleSet == null) {
ruleSet = new RuleSet();
@@ -257,9 +257,9 @@ public class Mode {
return map;
}
- protected void removeFromNameMap(Map map, String name, Rule rule) {
+ protected void removeFromNameMap(Map map, String name, Rule rule) {
if (map != null) {
- RuleSet ruleSet = (RuleSet) map.get(name);
+ RuleSet ruleSet = map.get(name);
if (ruleSet != null) {
ruleSet.removeRule(rule);
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/rule/NullAction.java b/fine-org-dom4j/src/main/java/org/dom4j/rule/NullAction.java
index 93b9ff144..b506df3e5 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/rule/NullAction.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/rule/NullAction.java
@@ -15,7 +15,7 @@ import org.dom4j.Node;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.7 $
*/
public class NullAction implements Action {
/** Singleton instance */
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/rule/Pattern.java b/fine-org-dom4j/src/main/java/org/dom4j/rule/Pattern.java
index 819fcb61b..13583053a 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/rule/Pattern.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/rule/Pattern.java
@@ -17,7 +17,7 @@ import org.dom4j.NodeFilter;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.6 $
*/
public interface Pattern extends NodeFilter {
// These node numbers are compatable with DOM4J's Node types
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/rule/Rule.java b/fine-org-dom4j/src/main/java/org/dom4j/rule/Rule.java
index b3d60e926..a88e369f5 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/rule/Rule.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/rule/Rule.java
@@ -14,283 +14,280 @@ import org.dom4j.Node;
* Rule matches against DOM4J Node so that some action can be
* performed such as in the XSLT processing model.
*
- *
+ *
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.7 $
*/
-public class Rule implements Comparable {
- /** Holds value of property mode. */
- private String mode;
-
- /** Holds value of property importPrecedence. */
- private int importPrecedence;
-
- /** Holds value of property priority. */
- private double priority;
-
- /** Holds value of property appearenceCount. */
- private int appearenceCount;
-
- /** Holds value of property pattern. */
- private Pattern pattern;
-
- /** Holds value of property action. */
- private Action action;
-
- public Rule() {
- this.priority = Pattern.DEFAULT_PRIORITY;
- }
-
- public Rule(Pattern pattern) {
- this.pattern = pattern;
- this.priority = pattern.getPriority();
- }
-
- public Rule(Pattern pattern, Action action) {
- this(pattern);
- this.action = action;
- }
-
- /**
- * Constructs a new Rule with the same instance data as the given rule but a
- * different pattern.
- *
- * @param that
- * DOCUMENT ME!
- * @param pattern
- * DOCUMENT ME!
- */
- public Rule(Rule that, Pattern pattern) {
- this.mode = that.mode;
- this.importPrecedence = that.importPrecedence;
- this.priority = that.priority;
- this.appearenceCount = that.appearenceCount;
- this.action = that.action;
- this.pattern = pattern;
- }
-
- public boolean equals(Object that) {
- if (that instanceof Rule) {
- return compareTo((Rule) that) == 0;
- }
-
- return false;
- }
-
- public int hashCode() {
- return importPrecedence + appearenceCount;
- }
-
- public int compareTo(Object that) {
- if (that instanceof Rule) {
- return compareTo((Rule) that);
- }
-
- return getClass().getName().compareTo(that.getClass().getName());
- }
-
- /**
- * Compares two rules in XSLT processing model order assuming that the modes
- * are equal.
- *
- * @param that
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int compareTo(Rule that) {
- int answer = this.importPrecedence - that.importPrecedence;
-
- if (answer == 0) {
- answer = (int) Math.round(this.priority - that.priority);
-
- if (answer == 0) {
- answer = this.appearenceCount - that.appearenceCount;
- }
- }
-
- return answer;
- }
-
- public String toString() {
- return super.toString() + "[ pattern: " + getPattern() + " action: "
- + getAction() + " ]";
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param node
- * DOCUMENT ME!
- *
- * @return true if the pattern matches the given DOM4J node.
- */
- public final boolean matches(Node node) {
- return pattern.matches(node);
- }
-
- /**
- * If this rule contains a union pattern then this method should return an
- * array of Rules which describe the union rule, which should contain more
- * than one rule. Otherwise this method should return null.
- *
- * @return an array of the rules which make up this union rule or null if
- * this rule is not a union rule
- */
- public Rule[] getUnionRules() {
- Pattern[] patterns = pattern.getUnionPatterns();
-
- if (patterns == null) {
- return null;
- }
-
- int size = patterns.length;
- Rule[] answer = new Rule[size];
-
- for (int i = 0; i < size; i++) {
- answer[i] = new Rule(this, patterns[i]);
- }
-
- return answer;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return the type of node the pattern matches which by default should
- * return ANY_NODE if it can match any kind of node.
- */
- public final short getMatchType() {
- return pattern.getMatchType();
- }
-
- /**
- * For patterns which only match an ATTRIBUTE_NODE or an ELEMENT_NODE then
- * this pattern may return the name of the element or attribute it matches.
- * This allows a more efficient rule matching algorithm to be performed,
- * rather than a brute force approach of evaluating every pattern for a
- * given Node.
- *
- * @return the name of the element or attribute this pattern matches or null
- * if this pattern matches any or more than one name.
- */
- public final String getMatchesNodeName() {
- return pattern.getMatchesNodeName();
- }
-
- /**
- * Getter for property mode.
- *
- * @return Value of property mode.
- */
- public String getMode() {
- return mode;
- }
-
- /**
- * Setter for property mode.
- *
- * @param mode
- * New value of property mode.
- */
- public void setMode(String mode) {
- this.mode = mode;
- }
-
- /**
- * Getter for property importPrecedence.
- *
- * @return Value of property importPrecedence.
- */
- public int getImportPrecedence() {
- return importPrecedence;
- }
-
- /**
- * Setter for property importPrecedence.
- *
- * @param importPrecedence
- * New value of property importPrecedence.
- */
- public void setImportPrecedence(int importPrecedence) {
- this.importPrecedence = importPrecedence;
- }
-
- /**
- * Getter for property priority.
- *
- * @return Value of property priority.
- */
- public double getPriority() {
- return priority;
- }
-
- /**
- * Setter for property priority.
- *
- * @param priority
- * New value of property priority.
- */
- public void setPriority(double priority) {
- this.priority = priority;
- }
-
- /**
- * Getter for property appearenceCount.
- *
- * @return Value of property appearenceCount.
- */
- public int getAppearenceCount() {
- return appearenceCount;
- }
-
- /**
- * Setter for property appearenceCount.
- *
- * @param appearenceCount
- * New value of property appearenceCount.
- */
- public void setAppearenceCount(int appearenceCount) {
- this.appearenceCount = appearenceCount;
- }
-
- /**
- * Getter for property pattern.
- *
- * @return Value of property pattern.
- */
- public Pattern getPattern() {
- return pattern;
- }
-
- /**
- * Setter for property pattern.
- *
- * @param pattern
- * New value of property pattern.
- */
- public void setPattern(Pattern pattern) {
- this.pattern = pattern;
- }
-
- /**
- * Getter for property action.
- *
- * @return Value of property action.
- */
- public Action getAction() {
- return action;
- }
-
- /**
- * Setter for property action.
- *
- * @param action
- * New value of property action.
- */
- public void setAction(Action action) {
- this.action = action;
- }
+public class Rule implements Comparable {
+ /**
+ * Holds value of property mode.
+ */
+ private String mode;
+
+ /**
+ * Holds value of property importPrecedence.
+ */
+ private int importPrecedence;
+
+ /**
+ * Holds value of property priority.
+ */
+ private double priority;
+
+ /**
+ * Holds value of property appearenceCount.
+ */
+ private int appearenceCount;
+
+ /**
+ * Holds value of property pattern.
+ */
+ private Pattern pattern;
+
+ /**
+ * Holds value of property action.
+ */
+ private Action action;
+
+ public Rule() {
+ this.priority = Pattern.DEFAULT_PRIORITY;
+ }
+
+ public Rule(Pattern pattern) {
+ this.pattern = pattern;
+ this.priority = pattern.getPriority();
+ }
+
+ public Rule(Pattern pattern, Action action) {
+ this(pattern);
+ this.action = action;
+ }
+
+ /**
+ * Constructs a new Rule with the same instance data as the given rule but a
+ * different pattern.
+ *
+ * @param that DOCUMENT ME!
+ * @param pattern DOCUMENT ME!
+ */
+ public Rule(Rule that, Pattern pattern) {
+ this.mode = that.mode;
+ this.importPrecedence = that.importPrecedence;
+ this.priority = that.priority;
+ this.appearenceCount = that.appearenceCount;
+ this.action = that.action;
+ this.pattern = pattern;
+ }
+
+ public boolean equals(Object that) {
+ if (that instanceof Rule) {
+ return compareTo((Rule) that) == 0;
+ }
+
+ return false;
+ }
+
+ public int hashCode() {
+ return importPrecedence + appearenceCount;
+ }
+
+ /**
+ * Compares two rules in XSLT processing model order assuming that the modes
+ * are equal.
+ *
+ * @param that DOCUMENT ME!
+ * @return DOCUMENT ME!
+ */
+ public int compareTo(Rule that) {
+ int answer = compareInt(this.importPrecedence, that.importPrecedence);
+
+ if (answer == 0) {
+ answer = Double.compare(this.priority, that.priority);
+
+ if (answer == 0) {
+ answer = compareInt(this.appearenceCount, that.appearenceCount);
+ }
+ }
+
+ return answer;
+ }
+
+ public String toString() {
+ return super.toString() + "[ pattern: " + getPattern() + " action: "
+ + getAction() + " ]";
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param node DOCUMENT ME!
+ * @return true if the pattern matches the given DOM4J node.
+ */
+ public final boolean matches(Node node) {
+ return pattern.matches(node);
+ }
+
+ /**
+ * If this rule contains a union pattern then this method should return an
+ * array of Rules which describe the union rule, which should contain more
+ * than one rule. Otherwise this method should return null.
+ *
+ * @return an array of the rules which make up this union rule or null if
+ * this rule is not a union rule
+ */
+ public Rule[] getUnionRules() {
+ Pattern[] patterns = pattern.getUnionPatterns();
+
+ if (patterns == null) {
+ return null;
+ }
+
+ int size = patterns.length;
+ Rule[] answer = new Rule[size];
+
+ for (int i = 0; i < size; i++) {
+ answer[i] = new Rule(this, patterns[i]);
+ }
+
+ return answer;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return the type of node the pattern matches which by default should
+ * return ANY_NODE if it can match any kind of node.
+ */
+ public final short getMatchType() {
+ return pattern.getMatchType();
+ }
+
+ /**
+ * For patterns which only match an ATTRIBUTE_NODE or an ELEMENT_NODE then
+ * this pattern may return the name of the element or attribute it matches.
+ * This allows a more efficient rule matching algorithm to be performed,
+ * rather than a brute force approach of evaluating every pattern for a
+ * given Node.
+ *
+ * @return the name of the element or attribute this pattern matches or null
+ * if this pattern matches any or more than one name.
+ */
+ public final String getMatchesNodeName() {
+ return pattern.getMatchesNodeName();
+ }
+
+ /**
+ * Getter for property mode.
+ *
+ * @return Value of property mode.
+ */
+ public String getMode() {
+ return mode;
+ }
+
+ /**
+ * Setter for property mode.
+ *
+ * @param mode New value of property mode.
+ */
+ public void setMode(String mode) {
+ this.mode = mode;
+ }
+
+ /**
+ * Getter for property importPrecedence.
+ *
+ * @return Value of property importPrecedence.
+ */
+ public int getImportPrecedence() {
+ return importPrecedence;
+ }
+
+ /**
+ * Setter for property importPrecedence.
+ *
+ * @param importPrecedence New value of property importPrecedence.
+ */
+ public void setImportPrecedence(int importPrecedence) {
+ this.importPrecedence = importPrecedence;
+ }
+
+ /**
+ * Getter for property priority.
+ *
+ * @return Value of property priority.
+ */
+ public double getPriority() {
+ return priority;
+ }
+
+ /**
+ * Setter for property priority.
+ *
+ * @param priority New value of property priority.
+ */
+ public void setPriority(double priority) {
+ this.priority = priority;
+ }
+
+ /**
+ * Getter for property appearenceCount.
+ *
+ * @return Value of property appearenceCount.
+ */
+ public int getAppearenceCount() {
+ return appearenceCount;
+ }
+
+ /**
+ * Setter for property appearenceCount.
+ *
+ * @param appearenceCount New value of property appearenceCount.
+ */
+ public void setAppearenceCount(int appearenceCount) {
+ this.appearenceCount = appearenceCount;
+ }
+
+ /**
+ * Getter for property pattern.
+ *
+ * @return Value of property pattern.
+ */
+ public Pattern getPattern() {
+ return pattern;
+ }
+
+ /**
+ * Setter for property pattern.
+ *
+ * @param pattern New value of property pattern.
+ */
+ public void setPattern(Pattern pattern) {
+ this.pattern = pattern;
+ }
+
+ /**
+ * Getter for property action.
+ *
+ * @return Value of property action.
+ */
+ public Action getAction() {
+ return action;
+ }
+
+ /**
+ * Setter for property action.
+ *
+ * @param action New value of property action.
+ */
+ public void setAction(Action action) {
+ this.action = action;
+ }
+
+ private static int compareInt(int value1, int value2) {
+ //return Integer.compare(value1, value2);
+ return (value1 < value2) ? -1 : ((value1 == value2) ? 0 : 1);
+ }
}
/*
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/rule/RuleManager.java b/fine-org-dom4j/src/main/java/org/dom4j/rule/RuleManager.java
index 72fcd8c61..c84613958 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/rule/RuleManager.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/rule/RuleManager.java
@@ -21,11 +21,11 @@ import org.dom4j.rule.pattern.NodeTypePattern;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.9 $
*/
public class RuleManager {
/** Map of modes indexed by mode */
- private HashMap modes = new HashMap();
+ private HashMap modes = new HashMap();
/**
* A counter so that rules can be ordered by the order in which they were
@@ -49,7 +49,7 @@ public class RuleManager {
* then it will be created.
*/
public Mode getMode(String modeName) {
- Mode mode = (Mode) modes.get(modeName);
+ Mode mode = modes.get(modeName);
if (mode == null) {
mode = createMode();
@@ -66,8 +66,8 @@ public class RuleManager {
Rule[] childRules = rule.getUnionRules();
if (childRules != null) {
- for (int i = 0, size = childRules.length; i < size; i++) {
- mode.addRule(childRules[i]);
+ for (Rule childRule : childRules) {
+ mode.addRule(childRule);
}
} else {
mode.addRule(rule);
@@ -79,8 +79,8 @@ public class RuleManager {
Rule[] childRules = rule.getUnionRules();
if (childRules != null) {
- for (int i = 0, size = childRules.length; i < size; i++) {
- mode.removeRule(childRules[i]);
+ for (Rule childRule : childRules) {
+ mode.removeRule(childRule);
}
} else {
mode.removeRule(rule);
@@ -99,7 +99,7 @@ public class RuleManager {
* @return the matching Rule or no rule if none matched
*/
public Rule getMatchingRule(String modeName, Node node) {
- Mode mode = (Mode) modes.get(modeName);
+ Mode mode = modes.get(modeName);
if (mode != null) {
return mode.getMatchingRule(node);
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/rule/RuleSet.java b/fine-org-dom4j/src/main/java/org/dom4j/rule/RuleSet.java
index 506a0dba0..37f48981f 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/rule/RuleSet.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/rule/RuleSet.java
@@ -21,11 +21,11 @@ import org.dom4j.Node;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.10 $
*/
public class RuleSet {
/** An unordered list of Rule objects */
- private ArrayList rules = new ArrayList();
+ private ArrayList rules = new ArrayList();
/** A lazily evaluated and cached array of rules sorted */
private Rule[] ruleArray;
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/rule/Stylesheet.java b/fine-org-dom4j/src/main/java/org/dom4j/rule/Stylesheet.java
index 9d5585544..59b4b53e9 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/rule/Stylesheet.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/rule/Stylesheet.java
@@ -7,13 +7,9 @@
package org.dom4j.rule;
-import java.util.Iterator;
import java.util.List;
-import org.dom4j.Document;
-import org.dom4j.Element;
-import org.dom4j.Node;
-import org.dom4j.XPath;
+import org.dom4j.*;
/**
*
@@ -23,7 +19,7 @@ import org.dom4j.XPath;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.14 $
*/
public class Stylesheet {
private RuleManager ruleManager = new RuleManager();
@@ -57,39 +53,13 @@ public class Stylesheet {
ruleManager.removeRule(rule);
}
- /**
- * Runs this stylesheet on the given input which should be either a Node or
- * a List of Node objects.
- *
- * @param input
- * the input to run this stylesheet on
- *
- * @throws Exception
- * if something goes wrong
- */
- public void run(Object input) throws Exception {
- run(input, this.modeName);
- }
-
- public void run(Object input, String mode) throws Exception {
- if (input instanceof Node) {
- run((Node) input, mode);
- } else if (input instanceof List) {
- run((List) input, mode);
- }
- }
-
- public void run(List list) throws Exception {
+ public void run(List list) throws Exception {
run(list, this.modeName);
}
- public void run(List list, String mode) throws Exception {
- for (int i = 0, size = list.size(); i < size; i++) {
- Object object = list.get(i);
-
- if (object instanceof Node) {
- run((Node) object, mode);
- }
+ public void run(List list, String mode) throws Exception {
+ for (Node node : list) {
+ run(node, mode);
}
}
@@ -134,56 +104,52 @@ public class Stylesheet {
throws Exception {
Mode mod = ruleManager.getMode(mode);
- List list = xpath.selectNodes(input);
- Iterator it = list.iterator();
- while (it.hasNext()) {
- Node current = (Node) it.next();
+ List list = xpath.selectNodes(input);
+ for (Node current : list) {
mod.fireRule(current);
}
}
/**
- * Processes the result of the xpath expression. The xpath expression is
- * evaluated against the provided input object.
+ * If input is a Node, this will processes all of the
+ * children of that node. If input is a List of
+ * Nodess, these nodes will be iterated and all children of
+ * each node will be processed.
*
- * @param input
- * the input object
- * @param xpath
- * the xpath expression
+ * @param node the input object
* @throws Exception
* if something goes wrong
- * @deprecated Use {@link Stylesheet#applyTemplates(Object, XPath)}instead.
*/
- public void applyTemplates(Object input, org.jaxen.XPath xpath)
- throws Exception {
- applyTemplates(input, xpath, this.modeName);
+ public void applyTemplates(Node node) throws Exception {
+ applyTemplates(node, this.modeName);
}
/**
- * Processes the result of the xpath expression in the given mode. The xpath
- * expression is evaluated against the provided input object.
- *
- * @param input
- * the input object
- * @param xpath
- * the xpath expression
- * @param mode
- * the mode
+ * If input is a Node, this will processes all of the
+ * children of that node. If input is a List of
+ * Nodess, these nodes will be iterated and all children of
+ * each node will be processed.
+ *
+ * @param element the input object
* @throws Exception
* if something goes wrong
- * @deprecated Use {@link Stylesheet#applyTemplates(Object, XPath, String)}
- * instead.
*/
- public void applyTemplates(Object input, org.jaxen.XPath xpath, String mode)
- throws Exception {
- Mode mod = ruleManager.getMode(mode);
+ public void applyTemplates(Element element) throws Exception {
+ applyTemplates(element, this.modeName);
+ }
- List list = xpath.selectNodes(input);
- Iterator it = list.iterator();
- while (it.hasNext()) {
- Node current = (Node) it.next();
- mod.fireRule(current);
- }
+ /**
+ * If input is a Node, this will processes all of the
+ * children of that node. If input is a List of
+ * Nodess, these nodes will be iterated and all children of
+ * each node will be processed.
+ *
+ * @param document the input object
+ * @throws Exception
+ * if something goes wrong
+ */
+ public void applyTemplates(Document document) throws Exception {
+ applyTemplates(document, this.modeName);
}
/**
@@ -191,15 +157,13 @@ public class Stylesheet {
* children of that node. If input is a List of
* Nodess, these nodes will be iterated and all children of
* each node will be processed.
- *
- * @param input
- * the input object, this can either be a Node or
- * a List
+ *
+ * @param list the input object
* @throws Exception
* if something goes wrong
*/
- public void applyTemplates(Object input) throws Exception {
- applyTemplates(input, this.modeName);
+ public void applyTemplates(List list) throws Exception {
+ applyTemplates(list, this.modeName);
}
/**
@@ -208,42 +172,82 @@ public class Stylesheet {
* node. If input is a List of Nodess, these
* nodes will be iterated and all children of each node will be processed.
*
- * @param input
- * the input object, this can either be a Node or
- * a List
+ * @param node the input object
+ * @param mode
+ * the mode
+ * @throws Exception
+ * if something goes wrong
+ */
+ public void applyTemplates(Node node, String mode) throws Exception {
+ if (node instanceof Element) {
+ applyTemplates((Element) node, mode);
+ } else if (node instanceof Document) {
+ applyTemplates((Document) node, mode);
+ }
+ }
+
+ /**
+ * Processes the input object in the given mode. If input is a
+ * Node, this will processes all of the children of that
+ * node. If input is a List of Nodess, these
+ * nodes will be iterated and all children of each node will be processed.
+ *
+ * @param element the input object
* @param mode
* the mode
* @throws Exception
* if something goes wrong
*/
- public void applyTemplates(Object input, String mode) throws Exception {
+ public void applyTemplates(Element element, String mode) throws Exception {
Mode mod = ruleManager.getMode(mode);
- if (input instanceof Element) {
- // iterate through all children
- Element element = (Element) input;
- for (int i = 0, size = element.nodeCount(); i < size; i++) {
- Node node = element.node(i);
- mod.fireRule(node);
- }
- } else if (input instanceof Document) {
- // iterate through all children
- Document document = (Document) input;
- for (int i = 0, size = document.nodeCount(); i < size; i++) {
- Node node = document.node(i);
- mod.fireRule(node);
- }
- } else if (input instanceof List) {
- List list = (List) input;
+ // iterate through all children
+ for (int i = 0, size = element.nodeCount(); i < size; i++) {
+ Node node = element.node(i);
+ mod.fireRule(node);
+ }
+ }
- for (int i = 0, size = list.size(); i < size; i++) {
- Object object = list.get(i);
+ /**
+ * Processes the input object in the given mode. If input is a
+ * Node, this will processes all of the children of that
+ * node. If input is a List of Nodess, these
+ * nodes will be iterated and all children of each node will be processed.
+ *
+ * @param document the input object
+ * @param mode
+ * the mode
+ * @throws Exception
+ * if something goes wrong
+ */
+ public void applyTemplates(Document document, String mode) throws Exception {
+ Mode mod = ruleManager.getMode(mode);
+
+ // iterate through all children
+ for (int i = 0, size = document.nodeCount(); i < size; i++) {
+ Node node = document.node(i);
+ mod.fireRule(node);
+ }
+ }
- if (object instanceof Element) {
- applyTemplates((Element) object, mode);
- } else if (object instanceof Document) {
- applyTemplates((Document) object, mode);
- }
+ /**
+ * Processes the input object in the given mode. If input is a
+ * Node, this will processes all of the children of that
+ * node. If input is a List of Nodess, these
+ * nodes will be iterated and all children of each node will be processed.
+ *
+ * @param list list of Elements or Documents
+ * @param mode
+ * the mode
+ * @throws Exception
+ * if something goes wrong
+ */
+ public void applyTemplates(List extends Node> list, String mode) throws Exception {
+ for (Node node : list) {
+ if (node instanceof Element) {
+ applyTemplates((Element) node, mode);
+ } else if (node instanceof Document) {
+ applyTemplates((Document) node, mode);
}
}
}
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/rule/package-info.java b/fine-org-dom4j/src/main/java/org/dom4j/rule/package-info.java
new file mode 100644
index 000000000..e9a4d74eb
--- /dev/null
+++ b/fine-org-dom4j/src/main/java/org/dom4j/rule/package-info.java
@@ -0,0 +1,5 @@
+/**
+ * A {@link org.dom4j.rule.Pattern} based XML rule engine which implements the full XSLT processing model while allowing any {@link org.dom4j.rule.Action}
+ * to be fired if a pattern matches. This package can be used as a the base for a full XSLT implementation or alternatives, such as a JSP custom tag implementation of XSLT.
+ */
+package org.dom4j.rule;
\ No newline at end of file
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/rule/package.html b/fine-org-dom4j/src/main/java/org/dom4j/rule/package.html
deleted file mode 100644
index ba5db9b67..000000000
--- a/fine-org-dom4j/src/main/java/org/dom4j/rule/package.html
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
A {@link org.dom4j.rule.Pattern} based XML rule engine which implements
-the full XSLT processing model while allowing any {@link org.dom4j.rule.Action}
-to be fired if a pattern matches.
-This package can be used as a the base for a full XSLT implementation
-or alternatives, such as a JSP custom tag implementation of XSLT.
-
-
-
-
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/DefaultPattern.java b/fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/DefaultPattern.java
index 482b20a72..913ef1c5d 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/DefaultPattern.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/DefaultPattern.java
@@ -22,7 +22,7 @@ import org.dom4j.rule.Pattern;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.6 $
*/
public class DefaultPattern implements Pattern {
private NodeFilter filter;
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/NodeTypePattern.java b/fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/NodeTypePattern.java
index 5ec208b0b..fdb61cfa0 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/NodeTypePattern.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/NodeTypePattern.java
@@ -17,7 +17,7 @@ import org.dom4j.rule.Pattern;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.7 $
*/
public class NodeTypePattern implements Pattern {
/** A pattern which matches any Attribute node */
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/swing/BranchTreeNode.java b/fine-org-dom4j/src/main/java/org/dom4j/swing/BranchTreeNode.java
index ed3588da1..8f2bd393a 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/swing/BranchTreeNode.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/swing/BranchTreeNode.java
@@ -26,11 +26,11 @@ import org.dom4j.Node;
*
* @author James Strachan
* @author Jakob Jenkov
- * @version $Revision$
+ * @version $Revision: 1.10 $
*/
public class BranchTreeNode extends LeafTreeNode {
/** Stores the child tree nodes */
- protected List children;
+ protected List children;
public BranchTreeNode() {
}
@@ -45,15 +45,15 @@ public class BranchTreeNode extends LeafTreeNode {
// TreeNode methods
// -------------------------------------------------------------------------
- public Enumeration children() {
- return new Enumeration() {
+ public Enumeration children() {
+ return new Enumeration() {
private int index = -1;
public boolean hasMoreElements() {
return (index + 1) < getChildCount();
}
- public Object nextElement() {
+ public TreeNode nextElement() {
return getChildAt(++index);
}
};
@@ -91,7 +91,7 @@ public class BranchTreeNode extends LeafTreeNode {
*
* @return DOCUMENT ME!
*/
- protected List getChildList() {
+ protected List getChildList() {
// for now lets just create the children once, the first time they
// are asked for.
// XXXX - we may wish to detect inconsistencies here....
@@ -107,11 +107,11 @@ public class BranchTreeNode extends LeafTreeNode {
*
* @return DOCUMENT ME!
*/
- protected List createChildList() {
+ protected List createChildList() {
// add attributes and content as children?
Branch branch = getXmlBranch();
int size = branch.nodeCount();
- List childList = new ArrayList(size);
+ List childList = new ArrayList(size);
for (int i = 0; i < size; i++) {
Node node = branch.node(i);
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/swing/DocumentTreeModel.java b/fine-org-dom4j/src/main/java/org/dom4j/swing/DocumentTreeModel.java
index d8d5ca936..779688c4c 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/swing/DocumentTreeModel.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/swing/DocumentTreeModel.java
@@ -19,7 +19,7 @@ import org.dom4j.Document;
*
* @author James Strachan
* @author Jakob Jenkov
- * @version $Revision$
+ * @version $Revision: 1.7 $
*/
public class DocumentTreeModel extends DefaultTreeModel {
/** The document for this model */
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/swing/LeafTreeNode.java b/fine-org-dom4j/src/main/java/org/dom4j/swing/LeafTreeNode.java
index 81b61211c..69b546513 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/swing/LeafTreeNode.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/swing/LeafTreeNode.java
@@ -21,10 +21,10 @@ import org.dom4j.Node;
*
* @author James Strachan
* @author Jakob Jenkov
- * @version $Revision$
+ * @version $Revision: 1.7 $
*/
public class LeafTreeNode implements TreeNode {
- protected static final Enumeration EMPTY_ENUMERATION = new Enumeration() {
+ protected static final Enumeration extends TreeNode> EMPTY_ENUMERATION = new Enumeration() {
public boolean hasMoreElements() {
return false;
}
@@ -54,7 +54,7 @@ public class LeafTreeNode implements TreeNode {
// TreeNode methods
// -------------------------------------------------------------------------
- public Enumeration children() {
+ public Enumeration extends TreeNode> children() {
return EMPTY_ENUMERATION;
}
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/swing/XMLTableColumnDefinition.java b/fine-org-dom4j/src/main/java/org/dom4j/swing/XMLTableColumnDefinition.java
index 6e7f14537..60e285017 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/swing/XMLTableColumnDefinition.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/swing/XMLTableColumnDefinition.java
@@ -19,7 +19,7 @@ import org.dom4j.XPath;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.10 $
*/
public class XMLTableColumnDefinition implements Serializable {
public static final int OBJECT_TYPE = 0;
@@ -77,7 +77,7 @@ public class XMLTableColumnDefinition implements Serializable {
return OBJECT_TYPE;
}
- public Class getColumnClass() {
+ public Class> getColumnClass() {
switch (type) {
case STRING_TYPE:
return String.class;
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/swing/XMLTableDefinition.java b/fine-org-dom4j/src/main/java/org/dom4j/swing/XMLTableDefinition.java
index 46b826554..19ed35cef 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/swing/XMLTableDefinition.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/swing/XMLTableDefinition.java
@@ -28,20 +28,20 @@ import org.jaxen.VariableContext;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.8 $
*/
public class XMLTableDefinition implements Serializable, VariableContext {
/** Holds value of property rowXPath. */
private XPath rowXPath;
/** The columns to display in this table */
- private List columns = new ArrayList();
+ private List columns = new ArrayList();
/** integer index array cache */
private XMLTableColumnDefinition[] columnArray;
/** name index cache */
- private Map columnNameIndex;
+ private Map columnNameIndex;
/** for cross-row variables */
private VariableContext variableContext;
@@ -76,9 +76,9 @@ public class XMLTableDefinition implements Serializable, VariableContext {
XMLTableDefinition answer = new XMLTableDefinition();
answer.setRowExpression(definition.attributeValue("select"));
- for (Iterator iter = definition.elementIterator("column"); iter
+ for (Iterator iter = definition.elementIterator("column"); iter
.hasNext();) {
- Element element = (Element) iter.next();
+ Element element = iter.next();
String expression = element.attributeValue("select");
String name = element.getText();
String typeName = element.attributeValue("type", "string");
@@ -95,7 +95,7 @@ public class XMLTableDefinition implements Serializable, VariableContext {
return answer;
}
- public Class getColumnClass(int columnIndex) {
+ public Class> getColumnClass(int columnIndex) {
return getColumn(columnIndex).getColumnClass();
}
@@ -205,11 +205,9 @@ public class XMLTableDefinition implements Serializable, VariableContext {
public XMLTableColumnDefinition getColumn(String columnName) {
if (columnNameIndex == null) {
- columnNameIndex = new HashMap();
+ columnNameIndex = new HashMap();
- for (Iterator it = columns.iterator(); it.hasNext();) {
- XMLTableColumnDefinition column = (XMLTableColumnDefinition) it
- .next();
+ for (XMLTableColumnDefinition column : columns) {
columnNameIndex.put(column.getName(), column);
}
}
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/swing/XMLTableModel.java b/fine-org-dom4j/src/main/java/org/dom4j/swing/XMLTableModel.java
index dc4477770..d3151327e 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/swing/XMLTableModel.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/swing/XMLTableModel.java
@@ -13,6 +13,7 @@ import javax.swing.table.AbstractTableModel;
import org.dom4j.Document;
import org.dom4j.Element;
+import org.dom4j.Node;
import org.dom4j.XPath;
/**
@@ -21,7 +22,7 @@ import org.dom4j.XPath;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.8 $
*/
public class XMLTableModel extends AbstractTableModel {
/** Holds value of property definition. */
@@ -31,7 +32,7 @@ public class XMLTableModel extends AbstractTableModel {
private Object source;
/** The rows evaluated from the row XPath expression */
- private List rows;
+ private List rows;
/**
* Creates a TableModel from an XML table definition document and an XML
@@ -68,7 +69,7 @@ public class XMLTableModel extends AbstractTableModel {
return getRows().get(rowIndex);
}
- public List getRows() {
+ public List getRows() {
if (rows == null) {
rows = definition.getRowXPath().selectNodes(source);
}
@@ -78,7 +79,7 @@ public class XMLTableModel extends AbstractTableModel {
// TableModel interface
// -------------------------------------------------------------------------
- public Class getColumnClass(int columnIndex) {
+ public Class> getColumnClass(int columnIndex) {
return definition.getColumnClass(columnIndex);
}
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/swing/package-info.java b/fine-org-dom4j/src/main/java/org/dom4j/swing/package-info.java
new file mode 100644
index 000000000..2b17ec3e4
--- /dev/null
+++ b/fine-org-dom4j/src/main/java/org/dom4j/swing/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * A collection of adapters to allow easy integration with dom4j XML documents and Swing such as TreeModels and TableModels.
+ */
+package org.dom4j.swing;
\ No newline at end of file
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/swing/package.html b/fine-org-dom4j/src/main/java/org/dom4j/swing/package.html
deleted file mode 100644
index e5d074bae..000000000
--- a/fine-org-dom4j/src/main/java/org/dom4j/swing/package.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
A collection of adapters to allow easy integration with dom4j
- XML documents and Swing such as TreeModels and TableModels.
* AbstractDocumentType is an abstract base class for tree
@@ -23,7 +24,7 @@ import org.dom4j.Visitor;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.17 $
*/
public abstract class AbstractDocumentType extends AbstractNode implements
DocumentType {
@@ -59,14 +60,14 @@ public abstract class AbstractDocumentType extends AbstractNode implements
* @return DOCUMENT ME!
*/
public String getText() {
- List list = getInternalDeclarations();
+ List list = getInternalDeclarations();
if ((list != null) && (list.size() > 0)) {
- StringBuffer buffer = new StringBuffer();
- Iterator iter = list.iterator();
+ StringBuilder buffer = new StringBuilder();
+ Iterator iter = list.iterator();
if (iter.hasNext()) {
- Object decl = iter.next();
+ Decl decl = iter.next();
buffer.append(decl.toString());
while (iter.hasNext()) {
@@ -87,7 +88,7 @@ public abstract class AbstractDocumentType extends AbstractNode implements
}
public String asXML() {
- StringBuffer buffer = new StringBuffer(" list = getInternalDeclarations();
if ((list != null) && (list.size() > 0)) {
writer.write(" [");
- for (Iterator iter = list.iterator(); iter.hasNext();) {
- Object decl = iter.next();
+ for (Decl decl : list) {
writer.write("\n ");
writer.write(decl.toString());
}
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractElement.java b/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractElement.java
index 5e3c0c018..5fb4c86a7 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractElement.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractElement.java
@@ -7,1643 +7,1492 @@
package org.dom4j.tree;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.dom4j.Attribute;
-import org.dom4j.CDATA;
-import org.dom4j.CharacterData;
-import org.dom4j.Comment;
-import org.dom4j.Document;
-import org.dom4j.DocumentFactory;
-import org.dom4j.Element;
-import org.dom4j.Entity;
-import org.dom4j.IllegalAddException;
-import org.dom4j.Namespace;
-import org.dom4j.Node;
-import org.dom4j.ProcessingInstruction;
-import org.dom4j.QName;
-import org.dom4j.Text;
-import org.dom4j.Visitor;
+import org.dom4j.*;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
-
import org.xml.sax.Attributes;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.*;
+
/**
*
* AbstractElement is an abstract base class for tree
* implementors to use for implementation inheritence.
*
- *
+ *
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.80 $
*/
+@SuppressWarnings("unused")
public abstract class AbstractElement extends AbstractBranch implements
- org.dom4j.Element {
- /** The DocumentFactory instance used by default */
- private static final DocumentFactory DOCUMENT_FACTORY = DocumentFactory
- .getInstance();
-
- protected static final List EMPTY_LIST = Collections.EMPTY_LIST;
-
- protected static final Iterator EMPTY_ITERATOR = EMPTY_LIST.iterator();
-
- protected static final boolean VERBOSE_TOSTRING = false;
-
- protected static final boolean USE_STRINGVALUE_SEPARATOR = false;
-
- public AbstractElement() {
- }
-
- public short getNodeType() {
- return ELEMENT_NODE;
- }
-
- public boolean isRootElement() {
- Document document = getDocument();
-
- if (document != null) {
- Element root = document.getRootElement();
-
- if (root == this) {
- return true;
- }
- }
-
- return false;
- }
-
- public void setName(String name) {
- setQName(getDocumentFactory().createQName(name));
- }
-
- public void setNamespace(Namespace namespace) {
- setQName(getDocumentFactory().createQName(getName(), namespace));
- }
-
- /**
- * Returns the XPath expression to match this Elements name which is
- * getQualifiedName() if there is a namespace prefix defined or if no
- * namespace is present then it is getName() or if a namespace is defined
- * with no prefix then the expression is [name()='X'] where X = getName().
- *
- * @return DOCUMENT ME!
- */
- public String getXPathNameStep() {
- String uri = getNamespaceURI();
-
- if ((uri == null) || (uri.length() == 0)) {
- return getName();
- }
-
- String prefix = getNamespacePrefix();
-
- if ((prefix == null) || (prefix.length() == 0)) {
- return "*[name()='" + getName() + "']";
- }
-
- return getQualifiedName();
- }
-
- public String getPath(Element context) {
- if (this == context) {
- return ".";
- }
-
- Element parent = getParent();
-
- if (parent == null) {
- return "/" + getXPathNameStep();
- } else if (parent == context) {
- return getXPathNameStep();
- }
-
- return parent.getPath(context) + "/" + getXPathNameStep();
- }
-
- public String getUniquePath(Element context) {
- Element parent = getParent();
-
- if (parent == null) {
- return "/" + getXPathNameStep();
- }
-
- StringBuffer buffer = new StringBuffer();
-
- if (parent != context) {
- buffer.append(parent.getUniquePath(context));
-
- buffer.append("/");
- }
-
- buffer.append(getXPathNameStep());
-
- List mySiblings = parent.elements(getQName());
-
- if (mySiblings.size() > 1) {
- int idx = mySiblings.indexOf(this);
-
- if (idx >= 0) {
- buffer.append("[");
-
- buffer.append(Integer.toString(++idx));
-
- buffer.append("]");
- }
- }
-
- return buffer.toString();
- }
-
- public String asXML() {
- try {
- StringWriter out = new StringWriter();
- XMLWriter writer = new XMLWriter(out, new OutputFormat());
-
- writer.write(this);
- writer.flush();
-
- return out.toString();
- } catch (IOException e) {
- throw new RuntimeException("IOException while generating "
- + "textual representation: " + e.getMessage());
- }
- }
-
- public void write(Writer out) throws IOException {
- XMLWriter writer = new XMLWriter(out, new OutputFormat());
- writer.write(this);
- }
-
- /**
- *
- * accept method is the Visitor Pattern
- * method.
- *
- *
- * @param visitor
- * Visitor is the visitor.
- */
- public void accept(Visitor visitor) {
- visitor.visit(this);
-
- // visit attributes
- for (int i = 0, size = attributeCount(); i < size; i++) {
- Attribute attribute = attribute(i);
-
- visitor.visit(attribute);
- }
-
- // visit content
- for (int i = 0, size = nodeCount(); i < size; i++) {
- Node node = node(i);
-
- node.accept(visitor);
- }
- }
-
- public String toString() {
- String uri = getNamespaceURI();
-
- if ((uri != null) && (uri.length() > 0)) {
- if (VERBOSE_TOSTRING) {
- return super.toString() + " [Element: <" + getQualifiedName()
- + " uri: " + uri + " attributes: " + attributeList()
- + " content: " + contentList() + " />]";
- } else {
- return super.toString() + " [Element: <" + getQualifiedName()
- + " uri: " + uri + " attributes: " + attributeList()
- + "/>]";
- }
- } else {
- if (VERBOSE_TOSTRING) {
- return super.toString() + " [Element: <" + getQualifiedName()
- + " attributes: " + attributeList() + " content: "
- + contentList() + " />]";
- } else {
- return super.toString() + " [Element: <" + getQualifiedName()
- + " attributes: " + attributeList() + "/>]";
- }
- }
- }
-
- // QName methods
- // -------------------------------------------------------------------------
- public Namespace getNamespace() {
- return getQName().getNamespace();
- }
-
- public String getName() {
- return getQName().getName();
- }
-
- public String getNamespacePrefix() {
- return getQName().getNamespacePrefix();
- }
-
- public String getNamespaceURI() {
- return getQName().getNamespaceURI();
- }
-
- public String getQualifiedName() {
- return getQName().getQualifiedName();
- }
-
- public Object getData() {
- return getText();
- }
-
- public void setData(Object data) {
- // ignore this method
- }
-
- // Node methods
- // -------------------------------------------------------------------------
- public Node node(int index) {
- if (index >= 0) {
- List list = contentList();
-
- if (index >= list.size()) {
- return null;
- }
-
- Object node = list.get(index);
-
- if (node != null) {
- if (node instanceof Node) {
- return (Node) node;
- } else {
- return getDocumentFactory().createText(node.toString());
- }
- }
- }
-
- return null;
- }
-
- public int indexOf(Node node) {
- return contentList().indexOf(node);
- }
-
- public int nodeCount() {
- return contentList().size();
- }
-
- public Iterator nodeIterator() {
- return contentList().iterator();
- }
-
- // Element methods
- // -------------------------------------------------------------------------
- public Element element(String name) {
- List list = contentList();
-
- int size = list.size();
+ org.dom4j.Element {
+ /**
+ * The DocumentFactory instance used by default
+ */
+ private static final DocumentFactory DOCUMENT_FACTORY = DocumentFactory
+ .getInstance();
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
+ protected static final boolean VERBOSE_TOSTRING = false;
- if (object instanceof Element) {
- Element element = (Element) object;
+ protected static final boolean USE_STRINGVALUE_SEPARATOR = false;
- if (name.equals(element.getName())) {
- return element;
- }
- }
- }
+ public AbstractElement() {
+ }
- return null;
- }
+ public short getNodeType() {
+ return ELEMENT_NODE;
+ }
- public Element element(QName qName) {
- List list = contentList();
+ public boolean isRootElement() {
+ Document document = getDocument();
- int size = list.size();
+ if (document != null) {
+ Element root = document.getRootElement();
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
+ if (root == this) {
+ return true;
+ }
+ }
- if (object instanceof Element) {
- Element element = (Element) object;
+ return false;
+ }
- if (qName.equals(element.getQName())) {
- return element;
- }
- }
- }
+ public void setName(String name) {
+ setQName(getDocumentFactory().createQName(name));
+ }
- return null;
- }
+ public void setNamespace(Namespace namespace) {
+ setQName(getDocumentFactory().createQName(getName(), namespace));
+ }
- public Element element(String name, Namespace namespace) {
- return element(getDocumentFactory().createQName(name, namespace));
- }
+ /**
+ * Returns the XPath expression to match this Elements name which is
+ * getQualifiedName() if there is a namespace prefix defined or if no
+ * namespace is present then it is getName() or if a namespace is defined
+ * with no prefix then the expression is [name()='X'] where X = getName().
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getXPathNameStep() {
+ String uri = getNamespaceURI();
- public List elements() {
- List list = contentList();
+ if ((uri == null) || (uri.length() == 0)) {
+ return getName();
+ }
- BackedList answer = createResultList();
+ String prefix = getNamespacePrefix();
- int size = list.size();
+ if ((prefix == null) || (prefix.length() == 0)) {
+ return "*[name()='" + getName() + "']";
+ }
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
+ return getQualifiedName();
+ }
- if (object instanceof Element) {
- answer.addLocal(object);
- }
- }
+ public String getPath(Element context) {
+ if (this == context) {
+ return ".";
+ }
- return answer;
- }
+ Element parent = getParent();
- public List elements(String name) {
- List list = contentList();
+ if (parent == null) {
+ return "/" + getXPathNameStep();
+ } else if (parent == context) {
+ return getXPathNameStep();
+ }
+
+ return parent.getPath(context) + "/" + getXPathNameStep();
+ }
+
+ public String getUniquePath(Element context) {
+ Element parent = getParent();
+
+ if (parent == null) {
+ return "/" + getXPathNameStep();
+ }
+
+ StringBuilder buffer = new StringBuilder();
+
+ if (parent != context) {
+ buffer.append(parent.getUniquePath(context));
+
+ buffer.append("/");
+ }
+
+ buffer.append(getXPathNameStep());
+
+ List mySiblings = parent.elements(getQName());
+
+ if (mySiblings.size() > 1) {
+ int idx = mySiblings.indexOf(this);
+
+ if (idx >= 0) {
+ buffer.append("[");
+
+ buffer.append(Integer.toString(++idx));
+
+ buffer.append("]");
+ }
+ }
+
+ return buffer.toString();
+ }
+
+ public String asXML() {
+ try {
+ StringWriter out = new StringWriter();
+ XMLWriter writer = new XMLWriter(out, new OutputFormat());
+
+ writer.write(this);
+ writer.flush();
+
+ return out.toString();
+ } catch (IOException e) {
+ throw new RuntimeException("IOException while generating "
+ + "textual representation: " + e.getMessage());
+ }
+ }
+
+ public void write(Writer out) throws IOException {
+ XMLWriter writer = new XMLWriter(out, new OutputFormat());
+ writer.write(this);
+ }
+
+ /**
+ *
+ * accept method is the Visitor Pattern
+ * method.
+ *
+ *
+ * @param visitor Visitor is the visitor.
+ */
+ public void accept(Visitor visitor) {
+ visitor.visit(this);
+
+ // visit attributes
+ for (int i = 0, size = attributeCount(); i < size; i++) {
+ Attribute attribute = attribute(i);
+
+ visitor.visit(attribute);
+ }
+
+ // visit content
+ for (int i = 0, size = nodeCount(); i < size; i++) {
+ Node node = node(i);
+
+ node.accept(visitor);
+ }
+ }
+
+ public String toString() {
+ String uri = getNamespaceURI();
+
+ if ((uri != null) && (uri.length() > 0)) {
+ if (VERBOSE_TOSTRING) {
+ return super.toString() + " [Element: <" + getQualifiedName()
+ + " uri: " + uri + " attributes: " + attributeList()
+ + " content: " + contentList() + " />]";
+ } else {
+ return super.toString() + " [Element: <" + getQualifiedName()
+ + " uri: " + uri + " attributes: " + attributeList()
+ + "/>]";
+ }
+ } else {
+ if (VERBOSE_TOSTRING) {
+ return super.toString() + " [Element: <" + getQualifiedName()
+ + " attributes: " + attributeList() + " content: "
+ + contentList() + " />]";
+ } else {
+ return super.toString() + " [Element: <" + getQualifiedName()
+ + " attributes: " + attributeList() + "/>]";
+ }
+ }
+ }
+
+ // QName methods
+ // -------------------------------------------------------------------------
+ public Namespace getNamespace() {
+ return getQName().getNamespace();
+ }
+
+ public String getName() {
+ return getQName().getName();
+ }
+
+ public String getNamespacePrefix() {
+ return getQName().getNamespacePrefix();
+ }
+
+ public String getNamespaceURI() {
+ return getQName().getNamespaceURI();
+ }
+
+ public String getQualifiedName() {
+ return getQName().getQualifiedName();
+ }
+
+ public Object getData() {
+ return getText();
+ }
+
+ public void setData(Object data) {
+ // ignore this method
+ }
+
+ // Node methods
+ // -------------------------------------------------------------------------
+ public Node node(int index) {
+ if (index >= 0) {
+ List list = contentList();
+
+ if (index >= list.size()) {
+ return null;
+ }
+
+ Node node = list.get(index);
+
+ if (node != null) {
+ return node;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public int indexOf(Node node) {
+ return contentList().indexOf(node);
+ }
+
+ @Override
+ public int nodeCount() {
+ return contentList().size();
+ }
+
+ @Override
+ public Iterator nodeIterator() {
+ return contentList().iterator();
+ }
+
+ // Element methods
+ // -------------------------------------------------------------------------
+ public Element element(String name) {
+ for (Node node : contentList()) {
+ if (node instanceof Element) {
+ Element element = (Element) node;
+
+ if (name.equals(element.getName())) {
+ return element;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public Element element(QName qName) {
+ for (Node node : contentList()) {
+ if (node instanceof Element) {
+ Element element = (Element) node;
+
+ if (qName.equals(element.getQName())) {
+ return element;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public Element element(String name, Namespace namespace) {
+ return element(getDocumentFactory().createQName(name, namespace));
+ }
+
+ public List elements() {
+ BackedList answer = createResultList();
+
+ for (Node node : contentList()) {
+ if (node instanceof Element) {
+ answer.addLocal((Element) node);
+ }
+ }
+
+ return answer;
+ }
+
+ public List elements(String name) {
+ BackedList answer = createResultList();
+
+ for (Node node : contentList()) {
+ if (node instanceof Element) {
+ Element element = (Element) node;
+
+ if (name.equals(element.getName())) {
+ answer.addLocal(element);
+ }
+ }
+ }
+
+ return answer;
+ }
+
+ public List elements(QName qName) {
+ BackedList answer = createResultList();
+
+ for (Node node : contentList()) {
+ if (node instanceof Element) {
+ Element element = (Element) node;
+
+ if (qName.equals(element.getQName())) {
+ answer.addLocal(element);
+ }
+ }
+ }
+
+ return answer;
+ }
+
+ public List elements(String name, Namespace namespace) {
+ return elements(getDocumentFactory().createQName(name, namespace));
+ }
+
+ public Iterator elementIterator() {
+ List list = elements();
+
+ return list.iterator();
+ }
+
+ public Iterator elementIterator(String name) {
+ List list = elements(name);
+
+ return list.iterator();
+ }
+
+ public Iterator elementIterator(QName qName) {
+ List list = elements(qName);
+
+ return list.iterator();
+ }
+
+ public Iterator elementIterator(String name, Namespace ns) {
+ return elementIterator(getDocumentFactory().createQName(name, ns));
+ }
- BackedList answer = createResultList();
+ // Attribute methods
+ // -------------------------------------------------------------------------
+ public List attributes() {
+ return new ContentListFacade(this, attributeList());
+ }
- int size = list.size();
+ public Iterator attributeIterator() {
+ return attributeList().iterator();
+ }
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
+ public Attribute attribute(int index) {
+ return attributeList().get(index);
+ }
- if (object instanceof Element) {
- Element element = (Element) object;
+ public int attributeCount() {
+ return attributeList().size();
+ }
+
+ public Attribute attribute(String name) {
+ for (Attribute attribute : attributeList()) {
+ if (name.equals(attribute.getName())) {
+ return attribute;
+ }
+ }
- if (name.equals(element.getName())) {
- answer.addLocal(element);
- }
- }
- }
+ return null;
+ }
+
+ public Attribute attribute(QName qName) {
+ for (Attribute attribute : attributeList()) {
+ if (qName.equals(attribute.getQName())) {
+ return attribute;
+ }
+ }
- return answer;
- }
+ return null;
+ }
- public List elements(QName qName) {
- List list = contentList();
+ public Attribute attribute(String name, Namespace namespace) {
+ return attribute(getDocumentFactory().createQName(name, namespace));
+ }
- BackedList answer = createResultList();
+ /**
+ * This method provides a more optimal way of setting all the attributes on
+ * an Element particularly for use in {@link org.dom4j.io.SAXReader}.
+ *
+ * @param attributes DOCUMENT ME!
+ * @param namespaceStack DOCUMENT ME!
+ * @param noNamespaceAttributes DOCUMENT ME!
+ */
+ public void setAttributes(Attributes attributes,
+ NamespaceStack namespaceStack, boolean noNamespaceAttributes) {
+ // now lets add all attribute values
+ int size = attributes.getLength();
+
+ if (size > 0) {
+ DocumentFactory factory = getDocumentFactory();
+
+ if (size == 1) {
+ // allow lazy construction of the List of Attributes
+ String name = attributes.getQName(0);
+
+ if (noNamespaceAttributes || !name.startsWith("xmlns")) {
+ String attributeURI = attributes.getURI(0);
+
+ String attributeLocalName = attributes.getLocalName(0);
+
+ String attributeValue = attributes.getValue(0);
+
+ QName attributeQName = namespaceStack.getAttributeQName(
+ attributeURI, attributeLocalName, name);
+
+ add(factory.createAttribute(this, attributeQName,
+ attributeValue));
+ }
+ } else {
+ List list = attributeList(size);
+
+ list.clear();
+
+ for (int i = 0; i < size; i++) {
+ // optimised to avoid the call to attribute(QName) to
+ // lookup an attribute for a given QName
+ String attributeName = attributes.getQName(i);
+
+ if (noNamespaceAttributes
+ || !attributeName.startsWith("xmlns")) {
+ String attributeURI = attributes.getURI(i);
+
+ String attributeLocalName = attributes.getLocalName(i);
+
+ String attributeValue = attributes.getValue(i);
+
+ QName attributeQName = namespaceStack
+ .getAttributeQName(attributeURI,
+ attributeLocalName, attributeName);
+
+ Attribute attribute = factory.createAttribute(this,
+ attributeQName, attributeValue);
+
+ list.add(attribute);
+
+ childAdded(attribute);
+ }
+ }
+ }
+ }
+ }
+
+ public String attributeValue(String name) {
+ Attribute attrib = attribute(name);
+
+ if (attrib == null) {
+ return null;
+ } else {
+ return attrib.getValue();
+ }
+ }
+
+ public String attributeValue(QName qName) {
+ Attribute attrib = attribute(qName);
+
+ if (attrib == null) {
+ return null;
+ } else {
+ return attrib.getValue();
+ }
+ }
+
+ public String attributeValue(String name, String defaultValue) {
+ String answer = attributeValue(name);
+
+ return (answer != null) ? answer : defaultValue;
+ }
+
+ public String attributeValue(QName qName, String defaultValue) {
+ String answer = attributeValue(qName);
+
+ return (answer != null) ? answer : defaultValue;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param name DOCUMENT ME!
+ * @param value DOCUMENT ME!
+ * @deprecated As of version 0.5. Please use {@link
+ * #addAttribute(String, String)} instead. WILL BE REMOVED IN
+ * dom4j-1.6 !!
+ */
+ public void setAttributeValue(String name, String value) {
+ addAttribute(name, value);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param qName DOCUMENT ME!
+ * @param value DOCUMENT ME!
+ * @deprecated As of version 0.5. Please use {@link
+ * #addAttribute(String, String)} instead. WILL BE REMOVED IN
+ * dom4j-1.6 !!
+ */
+ public void setAttributeValue(QName qName, String value) {
+ addAttribute(qName, value);
+ }
+
+ public void add(Attribute attribute) {
+ if (attribute.getParent() != null) {
+ String message = "The Attribute already has an existing parent \""
+ + attribute.getParent().getQualifiedName() + "\"";
+
+ throw new IllegalAddException(this, attribute, message);
+ }
+
+ if (attribute.getValue() == null) {
+ // try remove a previous attribute with the same
+ // name since adding an attribute with a null value
+ // is equivalent to removing it.
+ Attribute oldAttribute = attribute(attribute.getQName());
+
+ if (oldAttribute != null) {
+ remove(oldAttribute);
+ }
+ } else {
+ attributeList().add(attribute);
+
+ childAdded(attribute);
+ }
+ }
+
+ public boolean remove(Attribute attribute) {
+ List list = attributeList();
+
+ boolean answer = list.remove(attribute);
+
+ if (answer) {
+ childRemoved(attribute);
+ } else {
+ // we may have a copy of the attribute
+ Attribute copy = attribute(attribute.getQName());
+
+ if (copy != null) {
+ list.remove(copy);
+
+ answer = true;
+ }
+ }
+
+ return answer;
+ }
+
+ // Processing instruction API
+ // -------------------------------------------------------------------------
+ public List processingInstructions() {
+ BackedList answer = createResultList();
+
+ for (Node node : contentList()) {
+ if (node instanceof ProcessingInstruction) {
+ answer.addLocal((ProcessingInstruction) node);
+ }
+ }
+
+ return answer;
+ }
+
+ public List processingInstructions(String target) {
+ BackedList answer = createResultList();
+
+ for (Node node : contentList()) {
+
+ if (node instanceof ProcessingInstruction) {
+ ProcessingInstruction pi = (ProcessingInstruction) node;
+
+ if (target.equals(pi.getName())) {
+ answer.addLocal(pi);
+ }
+ }
+ }
+
+ return answer;
+ }
+
+ public ProcessingInstruction processingInstruction(String target) {
+ for (Node node : contentList()) {
+ if (node instanceof ProcessingInstruction) {
+ ProcessingInstruction pi = (ProcessingInstruction) node;
+
+ if (target.equals(pi.getName())) {
+ return pi;
+ }
+ }
+ }
- int size = list.size();
+ return null;
+ }
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
-
- if (object instanceof Element) {
- Element element = (Element) object;
-
- if (qName.equals(element.getQName())) {
- answer.addLocal(element);
- }
- }
- }
-
- return answer;
- }
-
- public List elements(String name, Namespace namespace) {
- return elements(getDocumentFactory().createQName(name, namespace));
- }
-
- public Iterator elementIterator() {
- List list = elements();
-
- return list.iterator();
- }
-
- public Iterator elementIterator(String name) {
- List list = elements(name);
-
- return list.iterator();
- }
-
- public Iterator elementIterator(QName qName) {
- List list = elements(qName);
-
- return list.iterator();
- }
-
- public Iterator elementIterator(String name, Namespace ns) {
- return elementIterator(getDocumentFactory().createQName(name, ns));
- }
-
- // Attribute methods
- // -------------------------------------------------------------------------
- public List attributes() {
- return new ContentListFacade(this, attributeList());
- }
-
- public Iterator attributeIterator() {
- return attributeList().iterator();
- }
-
- public Attribute attribute(int index) {
- return (Attribute) attributeList().get(index);
- }
-
- public int attributeCount() {
- return attributeList().size();
- }
-
- public Attribute attribute(String name) {
- List list = attributeList();
-
- int size = list.size();
-
- for (int i = 0; i < size; i++) {
- Attribute attribute = (Attribute) list.get(i);
-
- if (name.equals(attribute.getName())) {
- return attribute;
- }
- }
-
- return null;
- }
-
- public Attribute attribute(QName qName) {
- List list = attributeList();
-
- int size = list.size();
-
- for (int i = 0; i < size; i++) {
- Attribute attribute = (Attribute) list.get(i);
-
- if (qName.equals(attribute.getQName())) {
- return attribute;
- }
- }
-
- return null;
- }
-
- public Attribute attribute(String name, Namespace namespace) {
- return attribute(getDocumentFactory().createQName(name, namespace));
- }
-
- /**
- * This method provides a more optimal way of setting all the attributes on
- * an Element particularly for use in {@link org.dom4j.io.SAXReader}.
- *
- * @param attributes
- * DOCUMENT ME!
- * @param namespaceStack
- * DOCUMENT ME!
- * @param noNamespaceAttributes
- * DOCUMENT ME!
- */
- public void setAttributes(Attributes attributes,
- NamespaceStack namespaceStack, boolean noNamespaceAttributes) {
- // now lets add all attribute values
- int size = attributes.getLength();
-
- if (size > 0) {
- DocumentFactory factory = getDocumentFactory();
-
- if (size == 1) {
- // allow lazy construction of the List of Attributes
- String name = attributes.getQName(0);
-
- if (noNamespaceAttributes || !name.startsWith("xmlns")) {
- String attributeURI = attributes.getURI(0);
-
- String attributeLocalName = attributes.getLocalName(0);
-
- String attributeValue = attributes.getValue(0);
-
- QName attributeQName = namespaceStack.getAttributeQName(
- attributeURI, attributeLocalName, name);
-
- add(factory.createAttribute(this, attributeQName,
- attributeValue));
- }
- } else {
- List list = attributeList(size);
-
- list.clear();
-
- for (int i = 0; i < size; i++) {
- // optimised to avoid the call to attribute(QName) to
- // lookup an attribute for a given QName
- String attributeName = attributes.getQName(i);
-
- if (noNamespaceAttributes
- || !attributeName.startsWith("xmlns")) {
- String attributeURI = attributes.getURI(i);
-
- String attributeLocalName = attributes.getLocalName(i);
-
- String attributeValue = attributes.getValue(i);
-
- QName attributeQName = namespaceStack
- .getAttributeQName(attributeURI,
- attributeLocalName, attributeName);
-
- Attribute attribute = factory.createAttribute(this,
- attributeQName, attributeValue);
-
- list.add(attribute);
-
- childAdded(attribute);
- }
- }
- }
- }
- }
-
- public String attributeValue(String name) {
- Attribute attrib = attribute(name);
-
- if (attrib == null) {
- return null;
- } else {
- return attrib.getValue();
- }
- }
-
- public String attributeValue(QName qName) {
- Attribute attrib = attribute(qName);
-
- if (attrib == null) {
- return null;
- } else {
- return attrib.getValue();
- }
- }
-
- public String attributeValue(String name, String defaultValue) {
- String answer = attributeValue(name);
-
- return (answer != null) ? answer : defaultValue;
- }
-
- public String attributeValue(QName qName, String defaultValue) {
- String answer = attributeValue(qName);
-
- return (answer != null) ? answer : defaultValue;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param name
- * DOCUMENT ME!
- * @param value
- * DOCUMENT ME!
- *
- * @deprecated As of version 0.5. Please use {@link
- * #addAttribute(String,String)} instead. WILL BE REMOVED IN
- * dom4j-1.6 !!
- */
- public void setAttributeValue(String name, String value) {
- addAttribute(name, value);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param qName
- * DOCUMENT ME!
- * @param value
- * DOCUMENT ME!
- *
- * @deprecated As of version 0.5. Please use {@link
- * #addAttribute(String,String)} instead. WILL BE REMOVED IN
- * dom4j-1.6 !!
- */
- public void setAttributeValue(QName qName, String value) {
- addAttribute(qName, value);
- }
+ public boolean removeProcessingInstruction(String target) {
+ for (Iterator iter = contentList().iterator(); iter.hasNext(); ) {
+ Node node = iter.next();
- public void add(Attribute attribute) {
- if (attribute.getParent() != null) {
- String message = "The Attribute already has an existing parent \""
- + attribute.getParent().getQualifiedName() + "\"";
+ if (node instanceof ProcessingInstruction) {
+ ProcessingInstruction pi = (ProcessingInstruction) node;
- throw new IllegalAddException(this, attribute, message);
- }
+ if (target.equals(pi.getName())) {
+ iter.remove();
- if (attribute.getValue() == null) {
- // try remove a previous attribute with the same
- // name since adding an attribute with a null value
- // is equivalent to removing it.
- Attribute oldAttribute = attribute(attribute.getQName());
+ return true;
+ }
+ }
+ }
- if (oldAttribute != null) {
- remove(oldAttribute);
- }
- } else {
- attributeList().add(attribute);
+ return false;
+ }
- childAdded(attribute);
- }
- }
+ // Content Model methods
+ // -------------------------------------------------------------------------
+ public Node getXPathResult(int index) {
+ Node answer = node(index);
- public boolean remove(Attribute attribute) {
- List list = attributeList();
+ if ((answer != null) && !answer.supportsParent()) {
+ return answer.asXPathResult(this);
+ }
- boolean answer = list.remove(attribute);
+ return answer;
+ }
- if (answer) {
- childRemoved(attribute);
- } else {
- // we may have a copy of the attribute
- Attribute copy = attribute(attribute.getQName());
+ public Element addAttribute(String name, String value) {
+ // adding a null value is equivalent to removing the attribute
+ Attribute attribute = attribute(name);
- if (copy != null) {
- list.remove(copy);
+ if (value != null) {
+ if (attribute == null) {
+ add(getDocumentFactory().createAttribute(this, name, value));
+ } else if (attribute.isReadOnly()) {
+ remove(attribute);
- answer = true;
- }
- }
+ add(getDocumentFactory().createAttribute(this, name, value));
+ } else {
+ attribute.setValue(value);
+ }
+ } else if (attribute != null) {
+ remove(attribute);
+ }
- return answer;
- }
+ return this;
+ }
- // Processing instruction API
- // -------------------------------------------------------------------------
- public List processingInstructions() {
- List list = contentList();
+ public Element addAttribute(QName qName, String value) {
+ // adding a null value is equivalent to removing the attribute
+ Attribute attribute = attribute(qName);
- BackedList answer = createResultList();
+ if (value != null) {
+ if (attribute == null) {
+ add(getDocumentFactory().createAttribute(this, qName, value));
+ } else if (attribute.isReadOnly()) {
+ remove(attribute);
- int size = list.size();
+ add(getDocumentFactory().createAttribute(this, qName, value));
+ } else {
+ attribute.setValue(value);
+ }
+ } else if (attribute != null) {
+ remove(attribute);
+ }
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
+ return this;
+ }
- if (object instanceof ProcessingInstruction) {
- answer.addLocal(object);
- }
- }
+ public Element addCDATA(String cdata) {
+ CDATA node = getDocumentFactory().createCDATA(cdata);
- return answer;
- }
+ addNewNode(node);
- public List processingInstructions(String target) {
- List list = contentList();
+ return this;
+ }
- BackedList answer = createResultList();
+ public Element addComment(String comment) {
+ Comment node = getDocumentFactory().createComment(comment);
- int size = list.size();
+ addNewNode(node);
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
+ return this;
+ }
- if (object instanceof ProcessingInstruction) {
- ProcessingInstruction pi = (ProcessingInstruction) object;
+ public Element addElement(String name) {
+ DocumentFactory factory = getDocumentFactory();
- if (target.equals(pi.getName())) {
- answer.addLocal(pi);
- }
- }
- }
+ int index = name.indexOf(":");
- return answer;
- }
+ String prefix;
- public ProcessingInstruction processingInstruction(String target) {
- List list = contentList();
+ String localName = name;
- int size = list.size();
+ Namespace namespace;
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
+ if (index > 0) {
+ prefix = name.substring(0, index);
- if (object instanceof ProcessingInstruction) {
- ProcessingInstruction pi = (ProcessingInstruction) object;
+ localName = name.substring(index + 1);
- if (target.equals(pi.getName())) {
- return pi;
- }
- }
- }
+ namespace = getNamespaceForPrefix(prefix);
- return null;
- }
+ if (namespace == null) {
+ throw new IllegalAddException("No such namespace prefix: "
+ + prefix + " is in scope on: " + this
+ + " so cannot add element: " + name);
+ }
+ } else {
+ namespace = getNamespaceForPrefix("");
+ }
- public boolean removeProcessingInstruction(String target) {
- List list = contentList();
+ Element node;
- for (Iterator iter = list.iterator(); iter.hasNext();) {
- Object object = iter.next();
+ if (namespace != null) {
+ QName qname = factory.createQName(localName, namespace);
- if (object instanceof ProcessingInstruction) {
- ProcessingInstruction pi = (ProcessingInstruction) object;
+ node = factory.createElement(qname);
+ } else {
+ node = factory.createElement(name);
+ }
- if (target.equals(pi.getName())) {
- iter.remove();
+ addNewNode(node);
- return true;
- }
- }
- }
+ return node;
+ }
- return false;
- }
+ public Element addEntity(String name, String text) {
+ Entity node = getDocumentFactory().createEntity(name, text);
- // Content Model methods
- // -------------------------------------------------------------------------
- public Node getXPathResult(int index) {
- Node answer = node(index);
+ addNewNode(node);
- if ((answer != null) && !answer.supportsParent()) {
- return answer.asXPathResult(this);
- }
+ return this;
+ }
- return answer;
- }
+ public Element addNamespace(String prefix, String uri) {
+ Namespace node = getDocumentFactory().createNamespace(prefix, uri);
- public Element addAttribute(String name, String value) {
- // adding a null value is equivalent to removing the attribute
- Attribute attribute = attribute(name);
+ addNewNode(node);
- if (value != null) {
- if (attribute == null) {
- add(getDocumentFactory().createAttribute(this, name, value));
- } else if (attribute.isReadOnly()) {
- remove(attribute);
+ return this;
+ }
- add(getDocumentFactory().createAttribute(this, name, value));
- } else {
- attribute.setValue(value);
- }
- } else if (attribute != null) {
- remove(attribute);
- }
+ public Element addProcessingInstruction(String target, String data) {
+ ProcessingInstruction node = getDocumentFactory()
+ .createProcessingInstruction(target, data);
- return this;
- }
+ addNewNode(node);
- public Element addAttribute(QName qName, String value) {
- // adding a null value is equivalent to removing the attribute
- Attribute attribute = attribute(qName);
+ return this;
+ }
- if (value != null) {
- if (attribute == null) {
- add(getDocumentFactory().createAttribute(this, qName, value));
- } else if (attribute.isReadOnly()) {
- remove(attribute);
+ public Element addProcessingInstruction(String target, Map data) {
+ ProcessingInstruction node = getDocumentFactory()
+ .createProcessingInstruction(target, data);
- add(getDocumentFactory().createAttribute(this, qName, value));
- } else {
- attribute.setValue(value);
- }
- } else if (attribute != null) {
- remove(attribute);
- }
+ addNewNode(node);
- return this;
- }
+ return this;
+ }
- public Element addCDATA(String cdata) {
- CDATA node = getDocumentFactory().createCDATA(cdata);
+ public Element addText(String text) {
+ Text node = getDocumentFactory().createText(text);
- addNewNode(node);
+ addNewNode(node);
- return this;
- }
+ return this;
+ }
- public Element addComment(String comment) {
- Comment node = getDocumentFactory().createComment(comment);
+ // polymorphic node methods
+ public void add(Node node) {
+ switch (node.getNodeType()) {
+ case ELEMENT_NODE:
+ add((Element) node);
- addNewNode(node);
+ break;
- return this;
- }
+ case ATTRIBUTE_NODE:
+ add((Attribute) node);
- public Element addElement(String name) {
- DocumentFactory factory = getDocumentFactory();
+ break;
- int index = name.indexOf(":");
+ case TEXT_NODE:
+ add((Text) node);
- String prefix = "";
+ break;
- String localName = name;
+ case CDATA_SECTION_NODE:
+ add((CDATA) node);
- Namespace namespace = null;
+ break;
- if (index > 0) {
- prefix = name.substring(0, index);
+ case ENTITY_REFERENCE_NODE:
+ add((Entity) node);
- localName = name.substring(index + 1);
+ break;
- namespace = getNamespaceForPrefix(prefix);
+ case PROCESSING_INSTRUCTION_NODE:
+ add((ProcessingInstruction) node);
- if (namespace == null) {
- throw new IllegalAddException("No such namespace prefix: "
- + prefix + " is in scope on: " + this
- + " so cannot add element: " + name);
- }
- } else {
- namespace = getNamespaceForPrefix("");
- }
+ break;
- Element node;
+ case COMMENT_NODE:
+ add((Comment) node);
- if (namespace != null) {
- QName qname = factory.createQName(localName, namespace);
-
- node = factory.createElement(qname);
- } else {
- node = factory.createElement(name);
- }
-
- addNewNode(node);
-
- return node;
- }
-
- public Element addEntity(String name, String text) {
- Entity node = getDocumentFactory().createEntity(name, text);
-
- addNewNode(node);
-
- return this;
- }
-
- public Element addNamespace(String prefix, String uri) {
- Namespace node = getDocumentFactory().createNamespace(prefix, uri);
-
- addNewNode(node);
-
- return this;
- }
-
- public Element addProcessingInstruction(String target, String data) {
- ProcessingInstruction node = getDocumentFactory()
- .createProcessingInstruction(target, data);
-
- addNewNode(node);
-
- return this;
- }
-
- public Element addProcessingInstruction(String target, Map data) {
- ProcessingInstruction node = getDocumentFactory()
- .createProcessingInstruction(target, data);
-
- addNewNode(node);
-
- return this;
- }
-
- public Element addText(String text) {
- Text node = getDocumentFactory().createText(text);
-
- addNewNode(node);
-
- return this;
- }
-
- // polymorphic node methods
- public void add(Node node) {
- switch (node.getNodeType()) {
- case ELEMENT_NODE:
- add((Element) node);
-
- break;
-
- case ATTRIBUTE_NODE:
- add((Attribute) node);
-
- break;
-
- case TEXT_NODE:
- add((Text) node);
-
- break;
-
- case CDATA_SECTION_NODE:
- add((CDATA) node);
-
- break;
-
- case ENTITY_REFERENCE_NODE:
- add((Entity) node);
-
- break;
-
- case PROCESSING_INSTRUCTION_NODE:
- add((ProcessingInstruction) node);
-
- break;
-
- case COMMENT_NODE:
- add((Comment) node);
-
- break;
+ break;
/*
* XXXX: to do! case DOCUMENT_TYPE_NODE: add((DocumentType) node);
* break;
*/
- case NAMESPACE_NODE:
- add((Namespace) node);
+ case NAMESPACE_NODE:
+ add((Namespace) node);
- break;
+ break;
- default:
- invalidNodeTypeAddException(node);
- }
- }
+ default:
+ invalidNodeTypeAddException(node);
+ }
+ }
- public boolean remove(Node node) {
- switch (node.getNodeType()) {
- case ELEMENT_NODE:
- return remove((Element) node);
+ public boolean remove(Node node) {
+ switch (node.getNodeType()) {
+ case ELEMENT_NODE:
+ return remove((Element) node);
- case ATTRIBUTE_NODE:
- return remove((Attribute) node);
+ case ATTRIBUTE_NODE:
+ return remove((Attribute) node);
- case TEXT_NODE:
- return remove((Text) node);
+ case TEXT_NODE:
+ return remove((Text) node);
- case CDATA_SECTION_NODE:
- return remove((CDATA) node);
+ case CDATA_SECTION_NODE:
+ return remove((CDATA) node);
- case ENTITY_REFERENCE_NODE:
- return remove((Entity) node);
+ case ENTITY_REFERENCE_NODE:
+ return remove((Entity) node);
- case PROCESSING_INSTRUCTION_NODE:
- return remove((ProcessingInstruction) node);
+ case PROCESSING_INSTRUCTION_NODE:
+ return remove((ProcessingInstruction) node);
- case COMMENT_NODE:
- return remove((Comment) node);
+ case COMMENT_NODE:
+ return remove((Comment) node);
/*
* case DOCUMENT_TYPE_NODE: return remove((DocumentType) node);
*/
- case NAMESPACE_NODE:
- return remove((Namespace) node);
-
- default:
- return false;
- }
- }
-
- // typesafe versions using node classes
- public void add(CDATA cdata) {
- addNode(cdata);
- }
-
- public void add(Comment comment) {
- addNode(comment);
- }
-
- public void add(Element element) {
- addNode(element);
- }
-
- public void add(Entity entity) {
- addNode(entity);
- }
-
- public void add(Namespace namespace) {
- addNode(namespace);
- }
-
- public void add(ProcessingInstruction pi) {
- addNode(pi);
- }
-
- public void add(Text text) {
- addNode(text);
- }
-
- public boolean remove(CDATA cdata) {
- return removeNode(cdata);
- }
-
- public boolean remove(Comment comment) {
- return removeNode(comment);
- }
-
- public boolean remove(Element element) {
- return removeNode(element);
- }
-
- public boolean remove(Entity entity) {
- return removeNode(entity);
- }
-
- public boolean remove(Namespace namespace) {
- return removeNode(namespace);
- }
-
- public boolean remove(ProcessingInstruction pi) {
- return removeNode(pi);
- }
-
- public boolean remove(Text text) {
- return removeNode(text);
- }
-
- // Helper methods
- // -------------------------------------------------------------------------
- public boolean hasMixedContent() {
- List content = contentList();
-
- if ((content == null) || content.isEmpty() || (content.size() < 2)) {
- return false;
- }
-
- Class prevClass = null;
-
- for (Iterator iter = content.iterator(); iter.hasNext();) {
- Object object = iter.next();
-
- Class newClass = object.getClass();
-
- if (newClass != prevClass) {
- if (prevClass != null) {
- return true;
- }
-
- prevClass = newClass;
- }
- }
-
- return false;
- }
-
- public boolean isTextOnly() {
- List content = contentList();
-
- if ((content == null) || content.isEmpty()) {
- return true;
- }
-
- for (Iterator iter = content.iterator(); iter.hasNext();) {
- Object object = iter.next();
-
- if (!(object instanceof CharacterData)
- && !(object instanceof String)) {
- return false;
- }
- }
-
- return true;
- }
-
- public void setText(String text) {
- /* remove all text nodes */
- List allContent = contentList();
-
- if (allContent != null) {
- Iterator it = allContent.iterator();
-
- while (it.hasNext()) {
- Node node = (Node) it.next();
-
- switch (node.getNodeType()) {
- case CDATA_SECTION_NODE:
-
- // case ENTITY_NODE:
- case ENTITY_REFERENCE_NODE:
- case TEXT_NODE:
- it.remove();
-
- default:
- break;
- }
- }
- }
-
- addText(text);
- }
-
- public String getStringValue() {
- List list = contentList();
-
- int size = list.size();
-
- if (size > 0) {
- if (size == 1) {
- // optimised to avoid StringBuffer creation
- return getContentAsStringValue(list.get(0));
- } else {
- StringBuffer buffer = new StringBuffer();
-
- for (int i = 0; i < size; i++) {
- Object node = list.get(i);
-
- String string = getContentAsStringValue(node);
-
- if (string.length() > 0) {
- if (USE_STRINGVALUE_SEPARATOR) {
- if (buffer.length() > 0) {
- buffer.append(' ');
- }
- }
-
- buffer.append(string);
- }
- }
-
- return buffer.toString();
- }
- }
-
- return "";
- }
-
- /**
- * Puts all Text nodes in the full depth of the sub-tree
- * underneath this Node, including attribute nodes, into a
- * "normal" form where only structure (e.g., elements, comments, processing
- * instructions, CDATA sections, and entity references) separates
- * Text nodes, i.e., there are neither adjacent
- * Text nodes nor empty Text nodes. This can
- * be used to ensure that the DOM view of a document is the same as if it
- * were saved and re-loaded, and is useful when operations (such as XPointer
- * lookups) that depend on a particular document tree structure are to be
- * used.In cases where the document contains CDATASections,
- * the normalize operation alone may not be sufficient, since XPointers do
- * not differentiate between Text nodes and
- * CDATASection nodes.
- *
- * @since DOM Level 2
- */
- public void normalize() {
- List content = contentList();
-
- Text previousText = null;
+ case NAMESPACE_NODE:
+ return remove((Namespace) node);
- int i = 0;
+ default:
+ return false;
+ }
+ }
- while (i < content.size()) {
- Node node = (Node) content.get(i);
+ // typesafe versions using node classes
+ public void add(CDATA cdata) {
+ addNode(cdata);
+ }
- if (node instanceof Text) {
- Text text = (Text) node;
+ public void add(Comment comment) {
+ addNode(comment);
+ }
- if (previousText != null) {
- previousText.appendText(text.getText());
+ public void add(Element element) {
+ addNode(element);
+ }
- remove(text);
- } else {
- String value = text.getText();
+ public void add(Entity entity) {
+ addNode(entity);
+ }
- // only remove empty Text nodes, not whitespace nodes
- // if ( value == null || value.trim().length() <= 0 ) {
- if ((value == null) || (value.length() <= 0)) {
- remove(text);
- } else {
- previousText = text;
+ public void add(Namespace namespace) {
+ addNode(namespace);
+ }
- i++;
- }
- }
- } else {
- if (node instanceof Element) {
- Element element = (Element) node;
+ public void add(ProcessingInstruction pi) {
+ addNode(pi);
+ }
- element.normalize();
- }
+ public void add(Text text) {
+ addNode(text);
+ }
- previousText = null;
+ public boolean remove(CDATA cdata) {
+ return removeNode(cdata);
+ }
- i++;
- }
- }
- }
+ public boolean remove(Comment comment) {
+ return removeNode(comment);
+ }
- public String elementText(String name) {
- Element element = element(name);
+ public boolean remove(Element element) {
+ return removeNode(element);
+ }
- return (element != null) ? element.getText() : null;
- }
+ public boolean remove(Entity entity) {
+ return removeNode(entity);
+ }
- public String elementText(QName qName) {
- Element element = element(qName);
+ public boolean remove(Namespace namespace) {
+ return removeNode(namespace);
+ }
- return (element != null) ? element.getText() : null;
- }
+ public boolean remove(ProcessingInstruction pi) {
+ return removeNode(pi);
+ }
- public String elementTextTrim(String name) {
- Element element = element(name);
+ public boolean remove(Text text) {
+ return removeNode(text);
+ }
- return (element != null) ? element.getTextTrim() : null;
- }
+ // Helper methods
+ // -------------------------------------------------------------------------
+ public boolean hasMixedContent() {
+ List content = contentList();
- public String elementTextTrim(QName qName) {
- Element element = element(qName);
+ if ((content == null) || content.isEmpty() || (content.size() < 2)) {
+ return false;
+ }
+
+ Class extends Node> prevClass = null;
+
+ for (Node node : content) {
+ Class extends Node> newClass = node.getClass();
+
+ if (newClass != prevClass) {
+ if (prevClass != null) {
+ return true;
+ }
+
+ prevClass = newClass;
+ }
+ }
+
+ return false;
+ }
+
+ public boolean isTextOnly() {
+ List content = contentList();
+
+ if ((content == null) || content.isEmpty()) {
+ return true;
+ }
+
+ for (Node object : content) {
+ if (!(object instanceof CharacterData)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public void setText(String text) {
+ /* remove all text nodes */
+ List allContent = contentList();
+
+ if (allContent != null) {
+ Iterator it = allContent.iterator();
+
+ while (it.hasNext()) {
+ Node node = it.next();
+
+ switch (node.getNodeType()) {
+ case CDATA_SECTION_NODE:
+
+ // case ENTITY_NODE:
+ case ENTITY_REFERENCE_NODE:
+ case TEXT_NODE:
+ it.remove();
+
+ default:
+ break;
+ }
+ }
+ }
+
+ addText(text);
+ }
+
+ public String getStringValue() {
+ List list = contentList();
+
+ int size = list.size();
+
+ if (size > 0) {
+ if (size == 1) {
+ // optimised to avoid StringBuffer creation
+ return getContentAsStringValue(list.get(0));
+ } else {
+ StringBuilder buffer = new StringBuilder();
+
+ for (Node node : list) {
+ String string = getContentAsStringValue(node);
- return (element != null) ? element.getTextTrim() : null;
- }
-
- // add to me content from another element
- // analagous to the addAll(collection) methods in Java 2 collections
- public void appendAttributes(Element element) {
- for (int i = 0, size = element.attributeCount(); i < size; i++) {
- Attribute attribute = element.attribute(i);
-
- if (attribute.supportsParent()) {
- addAttribute(attribute.getQName(), attribute.getValue());
- } else {
- add(attribute);
- }
- }
- }
-
- /**
- *
- * This returns a deep clone of this element. The new element is detached
- * from its parent, and getParent() on the clone will return null.
- *
- *
- * @return the clone of this element
- */
+ if (string.length() > 0) {
+ if (USE_STRINGVALUE_SEPARATOR) {
+ if (buffer.length() > 0) {
+ buffer.append(' ');
+ }
+ }
+
+ buffer.append(string);
+ }
+ }
+
+ return buffer.toString();
+ }
+ }
+
+ return "";
+ }
+
+ /**
+ * Puts all Text nodes in the full depth of the sub-tree
+ * underneath this Node, including attribute nodes, into a
+ * "normal" form where only structure (e.g., elements, comments, processing
+ * instructions, CDATA sections, and entity references) separates
+ * Text nodes, i.e., there are neither adjacent
+ * Text nodes nor empty Text nodes. This can
+ * be used to ensure that the DOM view of a document is the same as if it
+ * were saved and re-loaded, and is useful when operations (such as XPointer
+ * lookups) that depend on a particular document tree structure are to be
+ * used.In cases where the document contains CDATASections,
+ * the normalize operation alone may not be sufficient, since XPointers do
+ * not differentiate between Text nodes and
+ * CDATASection nodes.
+ *
+ * @since DOM Level 2
+ */
+ public void normalize() {
+ List content = contentList();
+
+ Text previousText = null;
+
+ int i = 0;
+
+ while (i < content.size()) {
+ Node node = content.get(i);
+
+ if (node instanceof Text) {
+ Text text = (Text) node;
+
+ if (previousText != null) {
+ previousText.appendText(text.getText());
+
+ remove(text);
+ } else {
+ String value = text.getText();
+
+ // only remove empty Text nodes, not whitespace nodes
+ // if ( value == null || value.trim().length() <= 0 ) {
+ if ((value == null) || (value.length() <= 0)) {
+ remove(text);
+ } else {
+ previousText = text;
+
+ i++;
+ }
+ }
+ } else {
+ if (node instanceof Element) {
+ Element element = (Element) node;
+
+ element.normalize();
+ }
+
+ previousText = null;
+
+ i++;
+ }
+ }
+ }
+
+ public String elementText(String name) {
+ Element element = element(name);
+
+ return (element != null) ? element.getText() : null;
+ }
+
+ public String elementText(QName qName) {
+ Element element = element(qName);
+
+ return (element != null) ? element.getText() : null;
+ }
+
+ public String elementTextTrim(String name) {
+ Element element = element(name);
+
+ return (element != null) ? element.getTextTrim() : null;
+ }
+
+ public String elementTextTrim(QName qName) {
+ Element element = element(qName);
+
+ return (element != null) ? element.getTextTrim() : null;
+ }
+
+ // add to me content from another element
+ // analagous to the addAll(collection) methods in Java 2 collections
+ public void appendAttributes(Element element) {
+ for (int i = 0, size = element.attributeCount(); i < size; i++) {
+ Attribute attribute = element.attribute(i);
+
+ if (attribute.supportsParent()) {
+ addAttribute(attribute.getQName(), attribute.getValue());
+ } else {
+ add(attribute);
+ }
+ }
+ }
+
+ /**
+ *
+ * This returns a deep clone of this element. The new element is detached
+ * from its parent, and getParent() on the clone will return null.
+ *
+ *
+ * @return the clone of this element
+ */
/*
* public Object clone() { Element clone = createElement(getQName());
* clone.appendAttributes(this); clone.appendContent(this); return clone; }
*/
- public Element createCopy() {
- Element clone = createElement(getQName());
-
- clone.appendAttributes(this);
-
- clone.appendContent(this);
-
- return clone;
- }
-
- public Element createCopy(String name) {
- Element clone = createElement(name);
-
- clone.appendAttributes(this);
-
- clone.appendContent(this);
-
- return clone;
- }
-
- public Element createCopy(QName qName) {
- Element clone = createElement(qName);
-
- clone.appendAttributes(this);
-
- clone.appendContent(this);
-
- return clone;
- }
-
- public QName getQName(String qualifiedName) {
- String prefix = "";
-
- String localName = qualifiedName;
-
- int index = qualifiedName.indexOf(":");
-
- if (index > 0) {
- prefix = qualifiedName.substring(0, index);
-
- localName = qualifiedName.substring(index + 1);
- }
-
- Namespace namespace = getNamespaceForPrefix(prefix);
-
- if (namespace != null) {
- return getDocumentFactory().createQName(localName, namespace);
- } else {
- return getDocumentFactory().createQName(localName);
- }
- }
-
- public Namespace getNamespaceForPrefix(String prefix) {
- if (prefix == null) {
- prefix = "";
- }
-
- if (prefix.equals(getNamespacePrefix())) {
- return getNamespace();
- } else if (prefix.equals("xml")) {
- return Namespace.XML_NAMESPACE;
- } else {
- List list = contentList();
-
- int size = list.size();
-
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
-
- if (object instanceof Namespace) {
- Namespace namespace = (Namespace) object;
+ public Element createCopy() {
+ Element clone = createElement(getQName());
- if (prefix.equals(namespace.getPrefix())) {
- return namespace;
- }
- }
- }
- }
+ clone.appendAttributes(this);
- Element parent = getParent();
+ clone.appendContent(this);
- if (parent != null) {
- Namespace answer = parent.getNamespaceForPrefix(prefix);
+ return clone;
+ }
- if (answer != null) {
- return answer;
- }
- }
+ public Element createCopy(String name) {
+ Element clone = createElement(name);
- if ((prefix == null) || (prefix.length() <= 0)) {
- return Namespace.NO_NAMESPACE;
- }
+ clone.appendAttributes(this);
- return null;
- }
+ clone.appendContent(this);
- public Namespace getNamespaceForURI(String uri) {
- if ((uri == null) || (uri.length() <= 0)) {
- return Namespace.NO_NAMESPACE;
- } else if (uri.equals(getNamespaceURI())) {
- return getNamespace();
- } else {
- List list = contentList();
+ return clone;
+ }
- int size = list.size();
+ public Element createCopy(QName qName) {
+ Element clone = createElement(qName);
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
+ clone.appendAttributes(this);
- if (object instanceof Namespace) {
- Namespace namespace = (Namespace) object;
+ clone.appendContent(this);
- if (uri.equals(namespace.getURI())) {
- return namespace;
- }
- }
- }
+ return clone;
+ }
- return null;
- }
- }
+ public QName getQName(String qualifiedName) {
+ String prefix = "";
- public List getNamespacesForURI(String uri) {
- BackedList answer = createResultList();
+ String localName = qualifiedName;
- // if (getNamespaceURI().equals(uri)) {
- //
- // answer.addLocal(getNamespace());
- //
- // }
- List list = contentList();
+ int index = qualifiedName.indexOf(":");
- int size = list.size();
+ if (index > 0) {
+ prefix = qualifiedName.substring(0, index);
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
+ localName = qualifiedName.substring(index + 1);
+ }
- if ((object instanceof Namespace)
- && ((Namespace) object).getURI().equals(uri)) {
- answer.addLocal(object);
- }
- }
+ Namespace namespace = getNamespaceForPrefix(prefix);
- return answer;
- }
+ if (namespace != null) {
+ return getDocumentFactory().createQName(localName, namespace);
+ } else {
+ return getDocumentFactory().createQName(localName);
+ }
+ }
- public List declaredNamespaces() {
- BackedList answer = createResultList();
+ public Namespace getNamespaceForPrefix(String prefix) {
+ if (prefix == null) {
+ prefix = "";
+ }
- // if (getNamespaceURI().length() > 0) {
- //
- // answer.addLocal(getNamespace());
- //
- // }
- //
- List list = contentList();
+ if (prefix.equals(getNamespacePrefix())) {
+ return getNamespace();
+ } else if (prefix.equals("xml")) {
+ return Namespace.XML_NAMESPACE;
+ } else {
+ for (Node node : contentList()) {
+ if (node instanceof Namespace) {
+ Namespace namespace = (Namespace) node;
- int size = list.size();
+ if (prefix.equals(namespace.getPrefix())) {
+ return namespace;
+ }
+ }
+ }
+ }
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
+ Element parent = getParent();
- if (object instanceof Namespace) {
- answer.addLocal(object);
- }
- }
+ if (parent != null) {
+ Namespace answer = parent.getNamespaceForPrefix(prefix);
- return answer;
- }
+ if (answer != null) {
+ return answer;
+ }
+ }
- public List additionalNamespaces() {
- List list = contentList();
+ if ((prefix.length() == 0)) {
+ return Namespace.NO_NAMESPACE;
+ }
- int size = list.size();
+ return null;
+ }
- BackedList answer = createResultList();
+ public Namespace getNamespaceForURI(String uri) {
+ if ((uri == null) || (uri.length() <= 0)) {
+ return Namespace.NO_NAMESPACE;
+ } else if (uri.equals(getNamespaceURI())) {
+ return getNamespace();
+ } else {
+ for (Node node : contentList()) {
+ if (node instanceof Namespace) {
+ Namespace namespace = (Namespace) node;
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
+ if (uri.equals(namespace.getURI())) {
+ return namespace;
+ }
+ }
+ }
- if (object instanceof Namespace) {
- Namespace namespace = (Namespace) object;
+ return null;
+ }
+ }
- if (!namespace.equals(getNamespace())) {
- answer.addLocal(namespace);
- }
- }
- }
+ public List getNamespacesForURI(String uri) {
+ BackedList answer = createResultList();
- return answer;
- }
+ for (Node node : contentList()) {
+ if ((node instanceof Namespace)
+ && ((Namespace) node).getURI().equals(uri)) {
+ answer.addLocal((Namespace) node);
+ }
+ }
- public List additionalNamespaces(String defaultNamespaceURI) {
- List list = contentList();
-
- BackedList answer = createResultList();
-
- int size = list.size();
-
- for (int i = 0; i < size; i++) {
- Object object = list.get(i);
-
- if (object instanceof Namespace) {
- Namespace namespace = (Namespace) object;
-
- if (!defaultNamespaceURI.equals(namespace.getURI())) {
- answer.addLocal(namespace);
- }
- }
- }
-
- return answer;
- }
-
- // Implementation helper methods
- // -------------------------------------------------------------------------
-
- /**
- * Ensures that the list of attributes has the given size
- *
- * @param minCapacity
- * DOCUMENT ME!
- */
- public void ensureAttributesCapacity(int minCapacity) {
- if (minCapacity > 1) {
- List list = attributeList();
-
- if (list instanceof ArrayList) {
- ArrayList arrayList = (ArrayList) list;
-
- arrayList.ensureCapacity(minCapacity);
- }
- }
- }
-
- // Implementation methods
- // -------------------------------------------------------------------------
- protected Element createElement(String name) {
- return getDocumentFactory().createElement(name);
- }
-
- protected Element createElement(QName qName) {
- return getDocumentFactory().createElement(qName);
- }
-
- protected void addNode(Node node) {
- if (node.getParent() != null) {
- // XXX: could clone here
- String message = "The Node already has an existing parent of \""
- + node.getParent().getQualifiedName() + "\"";
-
- throw new IllegalAddException(this, node, message);
- }
-
- addNewNode(node);
- }
-
- protected void addNode(int index, Node node) {
- if (node.getParent() != null) {
- // XXX: could clone here
- String message = "The Node already has an existing parent of \""
- + node.getParent().getQualifiedName() + "\"";
-
- throw new IllegalAddException(this, node, message);
- }
-
- addNewNode(index, node);
- }
-
- /**
- * Like addNode() but does not require a parent check
- *
- * @param node
- * DOCUMENT ME!
- */
- protected void addNewNode(Node node) {
- contentList().add(node);
-
- childAdded(node);
- }
-
- protected void addNewNode(int index, Node node) {
- contentList().add(index, node);
-
- childAdded(node);
- }
-
- protected boolean removeNode(Node node) {
- boolean answer = contentList().remove(node);
-
- if (answer) {
- childRemoved(node);
- }
-
- return answer;
- }
-
- /**
- * Called when a new child node is added to create any parent relationships
- *
- * @param node
- * DOCUMENT ME!
- */
- protected void childAdded(Node node) {
- if (node != null) {
- node.setParent(this);
- }
- }
-
- protected void childRemoved(Node node) {
- if (node != null) {
- node.setParent(null);
-
- node.setDocument(null);
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return the internal List used to store attributes or creates one if one
- * is not available
- */
- protected abstract List attributeList();
-
- /**
- * DOCUMENT ME!
- *
- * @param attributeCount
- * DOCUMENT ME!
- *
- * @return the internal List used to store attributes or creates one with
- * the specified size if one is not available
- */
- protected abstract List attributeList(int attributeCount);
-
- protected DocumentFactory getDocumentFactory() {
- QName qName = getQName();
-
- // QName might be null as we might not have been constructed yet
- if (qName != null) {
- DocumentFactory factory = qName.getDocumentFactory();
-
- if (factory != null) {
- return factory;
- }
- }
-
- return DOCUMENT_FACTORY;
- }
-
- /**
- * A Factory Method pattern which creates a List implementation used to
- * store attributes
- *
- * @return DOCUMENT ME!
- */
- protected List createAttributeList() {
- return createAttributeList(DEFAULT_CONTENT_LIST_SIZE);
- }
-
- /**
- * A Factory Method pattern which creates a List implementation used to
- * store attributes
- *
- * @param size
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- protected List createAttributeList(int size) {
- return new ArrayList(size);
- }
+ return answer;
+ }
- protected Iterator createSingleIterator(Object result) {
- return new SingleIterator(result);
- }
+ public List declaredNamespaces() {
+ BackedList answer = createResultList();
+
+ for (Node node : contentList()) {
+ if (node instanceof Namespace) {
+ answer.addLocal((Namespace) node);
+ }
+ }
+
+ return answer;
+ }
+
+ public List additionalNamespaces() {
+ BackedList answer = createResultList();
+
+ for (Node node : contentList()) {
+
+ if (node instanceof Namespace) {
+ Namespace namespace = (Namespace) node;
+
+ if (!namespace.equals(getNamespace())) {
+ answer.addLocal(namespace);
+ }
+ }
+ }
+
+ return answer;
+ }
+
+ public List additionalNamespaces(String defaultNamespaceURI) {
+ BackedList answer = createResultList();
+
+ for (Node node : contentList()) {
+
+ if (node instanceof Namespace) {
+ Namespace namespace = (Namespace) node;
+
+ if (!defaultNamespaceURI.equals(namespace.getURI())) {
+ answer.addLocal(namespace);
+ }
+ }
+ }
+
+ return answer;
+ }
+
+ // Implementation helper methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Ensures that the list of attributes has the given size
+ *
+ * @param minCapacity DOCUMENT ME!
+ */
+ public void ensureAttributesCapacity(int minCapacity) {
+ if (minCapacity > 1) {
+ List list = attributeList();
+
+ if (list instanceof ArrayList) {
+ ArrayList arrayList = (ArrayList) list;
+
+ arrayList.ensureCapacity(minCapacity);
+ }
+ }
+ }
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+ protected Element createElement(String name) {
+ return getDocumentFactory().createElement(name);
+ }
+
+ protected Element createElement(QName qName) {
+ return getDocumentFactory().createElement(qName);
+ }
+
+ protected void addNode(Node node) {
+ if (node.getParent() != null) {
+ // XXX: could clone here
+ String message = "The Node already has an existing parent of \""
+ + node.getParent().getQualifiedName() + "\"";
+
+ throw new IllegalAddException(this, node, message);
+ }
+
+ addNewNode(node);
+ }
+
+ protected void addNode(int index, Node node) {
+ if (node.getParent() != null) {
+ // XXX: could clone here
+ String message = "The Node already has an existing parent of \""
+ + node.getParent().getQualifiedName() + "\"";
+
+ throw new IllegalAddException(this, node, message);
+ }
+
+ addNewNode(index, node);
+ }
+
+ /**
+ * Like addNode() but does not require a parent check
+ *
+ * @param node DOCUMENT ME!
+ */
+ protected void addNewNode(Node node) {
+ contentList().add(node);
+
+ childAdded(node);
+ }
+
+ protected void addNewNode(int index, Node node) {
+ contentList().add(index, node);
+
+ childAdded(node);
+ }
+
+ protected boolean removeNode(Node node) {
+ boolean answer = contentList().remove(node);
+
+ if (answer) {
+ childRemoved(node);
+ }
+
+ return answer;
+ }
+
+ /**
+ * Called when a new child node is added to create any parent relationships
+ *
+ * @param node DOCUMENT ME!
+ */
+ protected void childAdded(Node node) {
+ if (node != null) {
+ node.setParent(this);
+ }
+ }
+
+ protected void childRemoved(Node node) {
+ if (node != null) {
+ node.setParent(null);
+
+ node.setDocument(null);
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return the internal List used to store attributes or creates one if one
+ * is not available
+ */
+ protected abstract List attributeList();
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param attributeCount DOCUMENT ME!
+ * @return the internal List used to store attributes or creates one with
+ * the specified size if one is not available
+ */
+ protected abstract List attributeList(int attributeCount);
+
+ protected DocumentFactory getDocumentFactory() {
+ QName qName = getQName();
+
+ // QName might be null as we might not have been constructed yet
+ if (qName != null) {
+ DocumentFactory factory = qName.getDocumentFactory();
+
+ if (factory != null) {
+ return factory;
+ }
+ }
+
+ return DOCUMENT_FACTORY;
+ }
+
+ /**
+ * A Factory Method pattern which creates a List implementation used to
+ * store attributes
+ *
+ * @return DOCUMENT ME!
+ */
+ protected List createAttributeList() {
+ return createAttributeList(DEFAULT_CONTENT_LIST_SIZE);
+ }
+
+ /**
+ * A Factory Method pattern which creates a List implementation used to
+ * store attributes
+ *
+ * @param size DOCUMENT ME!
+ * @return DOCUMENT ME!
+ */
+ protected List createAttributeList(int size) {
+ return new ArrayList(size);
+ }
+
+ protected Iterator createSingleIterator(T result) {
+ return new SingleIterator(result);
+ }
}
/*
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractEntity.java b/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractEntity.java
index 0052895a0..3bbefcd9f 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractEntity.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractEntity.java
@@ -21,7 +21,7 @@ import org.dom4j.Visitor;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.15 $
*/
public abstract class AbstractEntity extends AbstractNode implements Entity {
public AbstractEntity() {
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractNode.java b/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractNode.java
index 7bea8502e..3957c297c 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractNode.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractNode.java
@@ -7,19 +7,14 @@
package org.dom4j.tree;
+import org.dom4j.*;
+import org.dom4j.rule.Pattern;
+
import java.io.IOException;
import java.io.Serializable;
import java.io.Writer;
import java.util.List;
-import org.dom4j.Document;
-import org.dom4j.DocumentFactory;
-import org.dom4j.Element;
-import org.dom4j.Node;
-import org.dom4j.NodeFilter;
-import org.dom4j.XPath;
-import org.dom4j.rule.Pattern;
-
/**
*
* AbstractNode is an abstract base class for tree implementors
@@ -27,7 +22,7 @@ import org.dom4j.rule.Pattern;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.31 $
*/
public abstract class AbstractNode implements Node, Cloneable, Serializable {
protected static final String[] NODE_TYPE_NAMES = {"Node", "Element",
@@ -160,18 +155,18 @@ public abstract class AbstractNode implements Node, Cloneable, Serializable {
return xpath.evaluate(this);
}
- public List selectNodes(String xpathExpression) {
+ public List selectNodes(String xpathExpression) {
XPath xpath = createXPath(xpathExpression);
return xpath.selectNodes(this);
}
- public List selectNodes(String xpathExpression,
+ public List selectNodes(String xpathExpression,
String comparisonXPathExpression) {
return selectNodes(xpathExpression, comparisonXPathExpression, false);
}
- public List selectNodes(String xpathExpression,
+ public List selectNodes(String xpathExpression,
String comparisonXPathExpression, boolean removeDuplicates) {
XPath xpath = createXPath(xpathExpression);
XPath sortBy = createXPath(comparisonXPathExpression);
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractProcessingInstruction.java b/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractProcessingInstruction.java
index 3c8672659..fa56897f0 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractProcessingInstruction.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractProcessingInstruction.java
@@ -7,17 +7,16 @@
package org.dom4j.tree;
+import org.dom4j.Element;
+import org.dom4j.ProcessingInstruction;
+import org.dom4j.Visitor;
+
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
-import org.dom4j.Element;
-import org.dom4j.ProcessingInstruction;
-import org.dom4j.Visitor;
-
/**
*
* AbstractProcessingInstruction is an abstract base class for
@@ -25,7 +24,7 @@ import org.dom4j.Visitor;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.17 $
*/
public abstract class AbstractProcessingInstruction extends AbstractNode
implements ProcessingInstruction {
@@ -78,7 +77,7 @@ public abstract class AbstractProcessingInstruction extends AbstractNode
+ "cannot be modified");
}
- public void setValues(Map data) {
+ public void setValues(Map data) {
throw new UnsupportedOperationException("This PI is read-only and "
+ "cannot be modified");
}
@@ -107,13 +106,12 @@ public abstract class AbstractProcessingInstruction extends AbstractNode
*
* @return DOCUMENT ME!
*/
- protected String toString(Map values) {
- StringBuffer buffer = new StringBuffer();
+ protected String toString(Map values) {
+ StringBuilder buffer = new StringBuilder();
- for (Iterator iter = values.entrySet().iterator(); iter.hasNext();) {
- Map.Entry entry = (Map.Entry) iter.next();
- String name = (String) entry.getKey();
- String value = (String) entry.getValue();
+ for (Map.Entry entry : values.entrySet()) {
+ String name = entry.getKey();
+ String value = entry.getValue();
buffer.append(name);
buffer.append("=\"");
@@ -137,8 +135,8 @@ public abstract class AbstractProcessingInstruction extends AbstractNode
*
* @return DOCUMENT ME!
*/
- protected Map parseValues(String text) {
- Map data = new HashMap();
+ protected Map parseValues(String text) {
+ Map data = new HashMap();
StringTokenizer s = new StringTokenizer(text, " =\'\"", true);
@@ -156,7 +154,7 @@ public abstract class AbstractProcessingInstruction extends AbstractNode
private String getName(StringTokenizer tokenizer) {
String token = tokenizer.nextToken();
- StringBuffer name = new StringBuffer(token);
+ StringBuilder name = new StringBuilder(token);
while (tokenizer.hasMoreTokens()) {
token = tokenizer.nextToken();
@@ -173,7 +171,7 @@ public abstract class AbstractProcessingInstruction extends AbstractNode
private String getValue(StringTokenizer tokenizer) {
String token = tokenizer.nextToken();
- StringBuffer value = new StringBuffer();
+ StringBuilder value = new StringBuilder();
/* get the quote */
while (tokenizer.hasMoreTokens() && !token.equals("\'")
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractText.java b/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractText.java
index ab35182fb..e40a7f12e 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractText.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/tree/AbstractText.java
@@ -19,7 +19,7 @@ import org.dom4j.Visitor;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.10 $
*/
public abstract class AbstractText extends AbstractCharacterData implements
org.dom4j.Text {
diff --git a/fine-org-dom4j/src/main/java/org/dom4j/tree/BackedList.java b/fine-org-dom4j/src/main/java/org/dom4j/tree/BackedList.java
index 018993a02..5ea0c131b 100644
--- a/fine-org-dom4j/src/main/java/org/dom4j/tree/BackedList.java
+++ b/fine-org-dom4j/src/main/java/org/dom4j/tree/BackedList.java
@@ -7,14 +7,13 @@
package org.dom4j.tree;
+import org.dom4j.Node;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import org.dom4j.IllegalAddException;
-import org.dom4j.Node;
-
/**
*
* BackedList represents a list of content of a {@link
@@ -23,39 +22,41 @@ import org.dom4j.Node;
*
*
* @author James Strachan
- * @version $Revision$
+ * @version $Revision: 1.14 $
*/
-public class BackedList extends ArrayList {
+public class BackedList extends ArrayList {
/** The content of the Branch which is modified if I am modified */
- private List branchContent;
+ private List branchContent;
/** The AbstractBranch instance which owns the content */
private AbstractBranch branch;
- public BackedList(AbstractBranch branch, List branchContent) {
+ public BackedList(AbstractBranch branch, List branchContent) {
this(branch, branchContent, branchContent.size());
}
- public BackedList(AbstractBranch branch, List branchContent, int capacity) {
+ public BackedList(AbstractBranch branch, List branchContent, int capacity) {
super(capacity);
this.branch = branch;
this.branchContent = branchContent;
}
- public BackedList(AbstractBranch branch, List branchContent,
- List initialContent) {
+ public BackedList(AbstractBranch branch, List branchContent,
+ List