Browse Source

REPORT-95578 dom4j升级

release/10.0
Yuan.Wang 1 year ago
parent
commit
e83f5d8167
  1. 2
      fine-org-dom4j/README.md
  2. 38
      fine-org-dom4j/src/main/java/org/dom4j/Attribute.java
  3. 103
      fine-org-dom4j/src/main/java/org/dom4j/Branch.java
  4. 5
      fine-org-dom4j/src/main/java/org/dom4j/CDATA.java
  5. 5
      fine-org-dom4j/src/main/java/org/dom4j/CharacterData.java
  6. 5
      fine-org-dom4j/src/main/java/org/dom4j/Comment.java
  7. 13
      fine-org-dom4j/src/main/java/org/dom4j/Document.java
  8. 62
      fine-org-dom4j/src/main/java/org/dom4j/DocumentException.java
  9. 42
      fine-org-dom4j/src/main/java/org/dom4j/DocumentFactory.java
  10. 23
      fine-org-dom4j/src/main/java/org/dom4j/DocumentHelper.java
  11. 15
      fine-org-dom4j/src/main/java/org/dom4j/DocumentType.java
  12. 303
      fine-org-dom4j/src/main/java/org/dom4j/Element.java
  13. 5
      fine-org-dom4j/src/main/java/org/dom4j/ElementHandler.java
  14. 3
      fine-org-dom4j/src/main/java/org/dom4j/ElementPath.java
  15. 5
      fine-org-dom4j/src/main/java/org/dom4j/Entity.java
  16. 4
      fine-org-dom4j/src/main/java/org/dom4j/IllegalAddException.java
  17. 12
      fine-org-dom4j/src/main/java/org/dom4j/InvalidXPathException.java
  18. 8
      fine-org-dom4j/src/main/java/org/dom4j/Namespace.java
  19. 15
      fine-org-dom4j/src/main/java/org/dom4j/Node.java
  20. 5
      fine-org-dom4j/src/main/java/org/dom4j/NodeFilter.java
  21. 9
      fine-org-dom4j/src/main/java/org/dom4j/ProcessingInstruction.java
  22. 123
      fine-org-dom4j/src/main/java/org/dom4j/QName.java
  23. 5
      fine-org-dom4j/src/main/java/org/dom4j/Text.java
  24. 7
      fine-org-dom4j/src/main/java/org/dom4j/Visitor.java
  25. 4
      fine-org-dom4j/src/main/java/org/dom4j/VisitorSupport.java
  26. 127
      fine-org-dom4j/src/main/java/org/dom4j/XPath.java
  27. 4
      fine-org-dom4j/src/main/java/org/dom4j/XPathException.java
  28. 2
      fine-org-dom4j/src/main/java/org/dom4j/bean/BeanAttribute.java
  29. 30
      fine-org-dom4j/src/main/java/org/dom4j/bean/BeanAttributeList.java
  30. 4
      fine-org-dom4j/src/main/java/org/dom4j/bean/BeanDocumentFactory.java
  31. 14
      fine-org-dom4j/src/main/java/org/dom4j/bean/BeanElement.java
  32. 31
      fine-org-dom4j/src/main/java/org/dom4j/bean/BeanMetaData.java
  33. 10
      fine-org-dom4j/src/main/java/org/dom4j/bean/package.html
  34. 2
      fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeAttribute.java
  35. 2
      fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeDocumentFactory.java
  36. 2
      fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeElement.java
  37. 10
      fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeElementFactory.java
  38. 2
      fine-org-dom4j/src/main/java/org/dom4j/datatype/InvalidSchemaException.java
  39. 15
      fine-org-dom4j/src/main/java/org/dom4j/datatype/NamedTypeResolver.java
  40. 67
      fine-org-dom4j/src/main/java/org/dom4j/datatype/SchemaParser.java
  41. 10
      fine-org-dom4j/src/main/java/org/dom4j/datatype/package.html
  42. 10
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMAttribute.java
  43. 2
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMAttributeNodeMap.java
  44. 10
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMCDATA.java
  45. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMComment.java
  46. 18
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMDocument.java
  47. 30
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMDocumentFactory.java
  48. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMDocumentType.java
  49. 15
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMElement.java
  50. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMEntityReference.java
  51. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMNamespace.java
  52. 35
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMNodeHelper.java
  53. 11
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMProcessingInstruction.java
  54. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMText.java
  55. 10
      fine-org-dom4j/src/main/java/org/dom4j/dom/package.html
  56. 4
      fine-org-dom4j/src/main/java/org/dom4j/dtd/AttributeDecl.java
  57. 4
      fine-org-dom4j/src/main/java/org/dom4j/dtd/ElementDecl.java
  58. 4
      fine-org-dom4j/src/main/java/org/dom4j/dtd/ExternalEntityDecl.java
  59. 4
      fine-org-dom4j/src/main/java/org/dom4j/dtd/InternalEntityDecl.java
  60. 9
      fine-org-dom4j/src/main/java/org/dom4j/dtd/package.html
  61. 13
      fine-org-dom4j/src/main/java/org/dom4j/io/DOMReader.java
  62. 72
      fine-org-dom4j/src/main/java/org/dom4j/io/DOMWriter.java
  63. 24
      fine-org-dom4j/src/main/java/org/dom4j/io/DispatchHandler.java
  64. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/DocumentInputSource.java
  65. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/DocumentResult.java
  66. 8
      fine-org-dom4j/src/main/java/org/dom4j/io/DocumentSource.java
  67. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/ElementStack.java
  68. 154
      fine-org-dom4j/src/main/java/org/dom4j/io/HTMLWriter.java
  69. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/JAXPHelper.java
  70. 36
      fine-org-dom4j/src/main/java/org/dom4j/io/OutputFormat.java
  71. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/PruningElementStack.java
  72. 39
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXContentHandler.java
  73. 62
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXEventRecorder.java
  74. 28
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXHelper.java
  75. 18
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXModifier.java
  76. 337
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXReader.java
  77. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXValidator.java
  78. 72
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXWriter.java
  79. 20
      fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventReader.java
  80. 26
      fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventWriter.java
  81. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/XMLResult.java
  82. 189
      fine-org-dom4j/src/main/java/org/dom4j/io/XMLWriter.java
  83. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/XPP3Reader.java
  84. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/XPPReader.java
  85. 10
      fine-org-dom4j/src/main/java/org/dom4j/io/package.html
  86. 12
      fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBModifier.java
  87. 6
      fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBReader.java
  88. 8
      fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBWriter.java
  89. 10
      fine-org-dom4j/src/main/java/org/dom4j/package.html
  90. 2
      fine-org-dom4j/src/main/java/org/dom4j/rule/Action.java
  91. 16
      fine-org-dom4j/src/main/java/org/dom4j/rule/Mode.java
  92. 2
      fine-org-dom4j/src/main/java/org/dom4j/rule/NullAction.java
  93. 2
      fine-org-dom4j/src/main/java/org/dom4j/rule/Pattern.java
  94. 79
      fine-org-dom4j/src/main/java/org/dom4j/rule/Rule.java
  95. 16
      fine-org-dom4j/src/main/java/org/dom4j/rule/RuleManager.java
  96. 4
      fine-org-dom4j/src/main/java/org/dom4j/rule/RuleSet.java
  97. 188
      fine-org-dom4j/src/main/java/org/dom4j/rule/Stylesheet.java
  98. 14
      fine-org-dom4j/src/main/java/org/dom4j/rule/package.html
  99. 2
      fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/DefaultPattern.java
  100. 2
      fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/NodeTypePattern.java
  101. Some files were not shown because too many files have changed in this diff Show More

2
fine-org-dom4j/README.md

@ -1,2 +1,2 @@
dom4j的源码地址:https://github.com/dom4j/dom4j <br> dom4j的源码地址:https://github.com/dom4j/dom4j <br>
版本:1.6.1<br> 版本:2.1.4<br>

38
fine-org-dom4j/src/main/java/org/dom4j/Attribute.java

@ -8,51 +8,41 @@
package org.dom4j; package org.dom4j;
/** /**
* <p>
* <code>Attribute</code> defines an XML attribute. An attribute may have a * <code>Attribute</code> defines an XML attribute. An attribute may have a
* name, an optional namespace and a value. * name, an optional namespace and a value.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.9 $
*/ */
@SuppressWarnings("unused")
public interface Attribute extends Node { public interface Attribute extends Node {
/** /**
* <p>
* Returns the <code>QName</code> of this attribute which represents the * Returns the <code>QName</code> of this attribute which represents the
* local name, the qualified name and the <code>Namespace</code>. * local name, the qualified name and the <code>Namespace</code>.
* </p>
* *
* @return the <code>QName</code> associated with this attribute * @return the <code>QName</code> associated with this attribute
*/ */
QName getQName(); QName getQName();
/** /**
* <p>
* Returns the <code>Namespace</code> of this element if one exists * Returns the <code>Namespace</code> of this element if one exists
* otherwise null is returned returned. * otherwise null is returned returned.
* </p>
* *
* @return the <code>Namespace</code> associated with this node * @return the <code>Namespace</code> associated with this node
*/ */
Namespace getNamespace(); Namespace getNamespace();
/** /**
* <p>
* Sets the <code>Namespace</code> of this element or if this element is * Sets the <code>Namespace</code> of this element or if this element is
* read only then an <code>UnsupportedOperationException</code> is thrown. * read only then an <code>UnsupportedOperationException</code> is thrown.
* </p>
* *
* @param namespace * @param namespace is the <code>Namespace</code> to associate with this element
* is the <code>Namespace</code> to associate with this element
*/ */
void setNamespace(Namespace namespace); void setNamespace(Namespace namespace);
/** /**
* <p>
* Returns the namespace prefix of this element if one exists otherwise an * Returns the namespace prefix of this element if one exists otherwise an
* empty <code>String</code> is returned. * empty <code>String</code> is returned.
* </p>
* *
* @return the prefix of the <code>Namespace</code> of this element or an * @return the prefix of the <code>Namespace</code> of this element or an
* empty <code>String</code> * empty <code>String</code>
@ -60,10 +50,8 @@ public interface Attribute extends Node {
String getNamespacePrefix(); String getNamespacePrefix();
/** /**
* <p>
* Returns the URI mapped to the namespace of this element if one exists * Returns the URI mapped to the namespace of this element if one exists
* otherwise an empty <code>String</code> is returned. * otherwise an empty <code>String</code> is returned.
* </p>
* *
* @return the URI for the <code>Namespace</code> of this element or an * @return the URI for the <code>Namespace</code> of this element or an
* empty <code>String</code> * empty <code>String</code>
@ -71,66 +59,50 @@ public interface Attribute extends Node {
String getNamespaceURI(); String getNamespaceURI();
/** /**
* <p>
* Returns the fully qualified name of this element. * Returns the fully qualified name of this element.
* </p>
* *
* <p>
* This will be the same as the value returned from {@link Node#getName()} * This will be the same as the value returned from {@link Node#getName()}
* if this element has no namespace attached to this element or an * if this element has no namespace attached to this element or an
* expression of the form * expression of the form
*
* <pre> * <pre>
* getNamespacePrefix() + &quot;:&quot; + getName() * getNamespacePrefix() + &quot;:&quot; + getName()
* </pre> * </pre>
*
* will be returned. * will be returned.
* </p>
* *
* @return the fully qualified name of the element * @return the fully qualified name of the element
*/ */
String getQualifiedName(); String getQualifiedName();
/** /**
* <p>
* Returns the value of the attribute. This method returns the same value as * Returns the value of the attribute. This method returns the same value as
* the {@link Node#getText()}method. * the {@link Node#getText()}method.
* </p>
* *
* @return the value of the attribute * @return the value of the attribute
*/ */
String getValue(); String getValue();
/** /**
* <p>
* Sets the value of this attribute or this method will throw an * Sets the value of this attribute or this method will throw an
* <code>UnsupportedOperationException</code> if it is read-only. * <code>UnsupportedOperationException</code> if it is read-only.
* </p>
* *
* @param value * @param value is the new value of this attribute
* is the new value of this attribute
*/ */
void setValue(String value); void setValue(String value);
/** /**
* <p>
* Accesses the data of this attribute which may implement data typing * Accesses the data of this attribute which may implement data typing
* bindings such as <code>XML Schema</code> or <code>Java Bean</code> * bindings such as <code>XML Schema</code> or <code>Java Bean</code>
* bindings or will return the same value as {@link Node#getText()}. * bindings or will return the same value as {@link Node#getText()}.
* </p>
* *
* @return the attribute data * @return the attribute data
*/ */
Object getData(); Object getData();
/** /**
* <p>
* Sets the data value of this attribute if this element supports data * Sets the data value of this attribute if this element supports data
* binding or calls {@link Node#setText(String)}if it doesn't. * binding or calls {@link Node#setText(String)}if it doesn't.
* </p>
* *
* @param data * @param data the attribute data
* the attribute data
*/ */
void setData(Object data); void setData(Object data);
} }

103
fine-org-dom4j/src/main/java/org/dom4j/Branch.java

@ -11,27 +11,22 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
* <p>
* <code>Branch</code> interface defines the common behaviour for Nodes which * <code>Branch</code> interface defines the common behaviour for Nodes which
* can contain child nodes (content) such as XML elements and documents. This * can contain child nodes (content) such as XML elements and documents. This
* interface allows both elements and documents to be treated in a polymorphic * interface allows both elements and documents to be treated in a polymorphic
* manner when changing or navigating child nodes (content). * manner when changing or navigating child nodes (content).
* </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.32 $
*/ */
@SuppressWarnings("unused")
public interface Branch extends Node { public interface Branch extends Node {
/** /**
* Returns the <code>Node</code> at the specified index position. * Returns the <code>Node</code> at the specified index position.
* *
* @param index * @param index the index of the node to return.
* the index of the node to return.
*
* @return the <code>Node</code> at the specified position. * @return the <code>Node</code> at the specified position.
* * @throws IndexOutOfBoundsException if the index is out of range (index &lt; 0 || index &gt;=
* @throws IndexOutOfBoundsException
* if the index is out of range (index &lt; 0 || index &gt;=
* {@link Branch#nodeCount()}). * {@link Branch#nodeCount()}).
*/ */
Node node(int index) throws IndexOutOfBoundsException; Node node(int index) throws IndexOutOfBoundsException;
@ -40,9 +35,7 @@ public interface Branch extends Node {
* Returns the index of the given node if it is a child node of this branch * Returns the index of the given node if it is a child node of this branch
* or -1 if the given node is not a child node. * or -1 if the given node is not a child node.
* *
* @param node * @param node the content child node to find.
* the content child node to find.
*
* @return the index of the given node starting at 0 or -1 if the node is * @return the index of the given node starting at 0 or -1 if the node is
* not a child node of this branch * not a child node of this branch
*/ */
@ -61,49 +54,43 @@ public interface Branch extends Node {
* capable of understanding which attribute value should be used for the ID * capable of understanding which attribute value should be used for the ID
* then it should be used, otherwise this method should return null. * then it should be used, otherwise this method should return null.
* *
* @param elementID * @param elementID DOCUMENT ME!
* DOCUMENT ME!
*
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
Element elementByID(String elementID); Element elementByID(String elementID);
/** /**
* <p>
* Returns the content nodes of this branch as a backed {@link List}so that * Returns the content nodes of this branch as a backed {@link List}so that
* the content of this branch may be modified directly using the * the content of this branch may be modified directly using the
* {@link List}interface. The <code>List</code> is backed by the * {@link List}interface. The <code>List</code> is backed by the
* <code>Branch</code> so that changes to the list are reflected in the * <code>Branch</code> so that changes to the list are reflected in the
* branch and vice versa. * branch and vice versa.
* </p>
* *
* @return the nodes that this branch contains as a <code>List</code> * @return the nodes that this branch contains as a <code>List</code>
*/ */
List content(); List<Node> content();
/** /**
* Returns an iterator through the content nodes of this branch * Returns an iterator through the content nodes of this branch
* *
* @return an iterator through the content nodes of this branch * @return an iterator through the content nodes of this branch
*/ */
Iterator nodeIterator(); Iterator<Node> nodeIterator();
/** /**
* Sets the contents of this branch as a <code>List</code> of * Sets the contents of this branch as a <code>List</code> of
* <code>Node</code> instances. * <code>Node</code> instances.
* *
* @param content * @param content is the list of nodes to use as the content for this branch.
* is the list of nodes to use as the content for this branch.
*/ */
void setContent(List content); void setContent(List<Node> content);
/** /**
* Appends the content of the given branch to this branch instance. This * Appends the content of the given branch to this branch instance. This
* method behaves like the {@link * method behaves like the {@link
* java.util.Collection#addAll(java.util.Collection)} method. * java.util.Collection#addAll(java.util.Collection)} method.
* *
* @param branch * @param branch is the branch whose content will be added to me.
* is the branch whose content will be added to me.
*/ */
void appendContent(Branch branch); void appendContent(Branch branch);
@ -114,36 +101,28 @@ public interface Branch extends Node {
void clearContent(); void clearContent();
/** /**
* <p>
* Returns a list of all the processing instructions in this branch. The * Returns a list of all the processing instructions in this branch. The
* list is backed by this branch so that changes to the list will be * list is backed by this branch so that changes to the list will be
* reflected in the branch but the reverse is not the case. * reflected in the branch but the reverse is not the case.
* </p>
* *
* @return a backed list of the processing instructions * @return a backed list of the processing instructions
*/ */
List processingInstructions(); List<ProcessingInstruction> processingInstructions();
/** /**
* <p>
* Returns a list of the processing instructions for the given target. The * Returns a list of the processing instructions for the given target. The
* list is backed by this branch so that changes to the list will be * list is backed by this branch so that changes to the list will be
* reflected in the branch but the reverse is not the case. * reflected in the branch but the reverse is not the case.
* </p>
*
* @param target
* DOCUMENT ME!
* *
* @param target DOCUMENT ME!
* @return a backed list of the processing instructions * @return a backed list of the processing instructions
*/ */
List processingInstructions(String target); List<ProcessingInstruction> processingInstructions(String target);
/** /**
* DOCUMENT ME! * DOCUMENT ME!
* *
* @param target * @param target DOCUMENT ME!
* DOCUMENT ME!
*
* @return the processing instruction for the given target * @return the processing instruction for the given target
*/ */
ProcessingInstruction processingInstruction(String target); ProcessingInstruction processingInstruction(String target);
@ -151,18 +130,15 @@ public interface Branch extends Node {
/** /**
* Sets all the processing instructions for this branch * Sets all the processing instructions for this branch
* *
* @param listOfPIs * @param listOfPIs DOCUMENT ME!
* DOCUMENT ME!
*/ */
void setProcessingInstructions(List listOfPIs); void setProcessingInstructions(List<ProcessingInstruction> listOfPIs);
/** /**
* Adds a new <code>Element</code> node with the given name to this branch * Adds a new <code>Element</code> node with the given name to this branch
* and returns a reference to the new node. * and returns a reference to the new node.
* *
* @param name * @param name is the name for the <code>Element</code> node.
* is the name for the <code>Element</code> node.
*
* @return the newly added <code>Element</code> node. * @return the newly added <code>Element</code> node.
*/ */
Element addElement(String name); Element addElement(String name);
@ -171,9 +147,7 @@ public interface Branch extends Node {
* Adds a new <code>Element</code> node with the given {@link QName}to * Adds a new <code>Element</code> node with the given {@link QName}to
* this branch and returns a reference to the new node. * this branch and returns a reference to the new node.
* *
* @param qname * @param qname is the qualified name for the <code>Element</code> node.
* is the qualified name for the <code>Element</code> node.
*
* @return the newly added <code>Element</code> node. * @return the newly added <code>Element</code> node.
*/ */
Element addElement(QName qname); Element addElement(QName qname);
@ -182,11 +156,8 @@ public interface Branch extends Node {
* Adds a new <code>Element</code> node with the given qualified name and * Adds a new <code>Element</code> node with the given qualified name and
* namespace URI to this branch and returns a reference to the new node. * namespace URI to this branch and returns a reference to the new node.
* *
* @param qualifiedName * @param qualifiedName is the fully qualified name of the Element
* is the fully qualified name of the Element * @param namespaceURI is the URI of the namespace to use
* @param namespaceURI
* is the URI of the namespace to use
*
* @return the newly added <code>Element</code> node. * @return the newly added <code>Element</code> node.
*/ */
Element addElement(String qualifiedName, String namespaceURI); Element addElement(String qualifiedName, String namespaceURI);
@ -194,9 +165,7 @@ public interface Branch extends Node {
/** /**
* Removes the processing instruction for the given target if it exists * Removes the processing instruction for the given target if it exists
* *
* @param target * @param target DOCUMENT ME!
* DOCUMENT ME!
*
* @return true if a processing instruction was removed else false * @return true if a processing instruction was removed else false
*/ */
boolean removeProcessingInstruction(String target); boolean removeProcessingInstruction(String target);
@ -207,8 +176,7 @@ public interface Branch extends Node {
* which will call the typesafe method for the node type such as * which will call the typesafe method for the node type such as
* add(Element) or add(Comment). * add(Element) or add(Comment).
* *
* @param node * @param node is the given node to add
* is the given node to add
*/ */
void add(Node node); void add(Node node);
@ -217,8 +185,7 @@ public interface Branch extends Node {
* already has a parent defined then an <code>IllegalAddException</code> * already has a parent defined then an <code>IllegalAddException</code>
* will be thrown. * will be thrown.
* *
* @param comment * @param comment is the comment to be added
* is the comment to be added
*/ */
void add(Comment comment); void add(Comment comment);
@ -227,8 +194,7 @@ public interface Branch extends Node {
* already has a parent defined then an <code>IllegalAddException</code> * already has a parent defined then an <code>IllegalAddException</code>
* will be thrown. * will be thrown.
* *
* @param element * @param element is the element to be added
* is the element to be added
*/ */
void add(Element element); void add(Element element);
@ -237,8 +203,7 @@ public interface Branch extends Node {
* the given node already has a parent defined then an * the given node already has a parent defined then an
* <code>IllegalAddException</code> will be thrown. * <code>IllegalAddException</code> will be thrown.
* *
* @param pi * @param pi is the processing instruction to be added
* is the processing instruction to be added
*/ */
void add(ProcessingInstruction pi); void add(ProcessingInstruction pi);
@ -249,9 +214,7 @@ public interface Branch extends Node {
* is a polymorphic method which will call the typesafe method for the node * is a polymorphic method which will call the typesafe method for the node
* type such as remove(Element) or remove(Comment). * type such as remove(Element) or remove(Comment).
* *
* @param node * @param node is the given node to be removed
* is the given node to be removed
*
* @return true if the node was removed * @return true if the node was removed
*/ */
boolean remove(Node node); boolean remove(Node node);
@ -261,9 +224,7 @@ public interface Branch extends Node {
* child of this branch. If the given node is not an immediate child of this * child of this branch. If the given node is not an immediate child of this
* branch then the {@link Node#detach()}method should be used instead. * branch then the {@link Node#detach()}method should be used instead.
* *
* @param comment * @param comment is the comment to be removed
* is the comment to be removed
*
* @return true if the comment was removed * @return true if the comment was removed
*/ */
boolean remove(Comment comment); boolean remove(Comment comment);
@ -273,9 +234,7 @@ public interface Branch extends Node {
* child of this branch. If the given node is not an immediate child of this * child of this branch. If the given node is not an immediate child of this
* branch then the {@link Node#detach()}method should be used instead. * branch then the {@link Node#detach()}method should be used instead.
* *
* @param element * @param element is the element to be removed
* is the element to be removed
*
* @return true if the element was removed * @return true if the element was removed
*/ */
boolean remove(Element element); boolean remove(Element element);
@ -286,9 +245,7 @@ public interface Branch extends Node {
* child of this branch then the {@link Node#detach()}method should be used * child of this branch then the {@link Node#detach()}method should be used
* instead. * instead.
* *
* @param pi * @param pi is the processing instruction to be removed
* is the processing instruction to be removed
*
* @return true if the processing instruction was removed * @return true if the processing instruction was removed
*/ */
boolean remove(ProcessingInstruction pi); boolean remove(ProcessingInstruction pi);

5
fine-org-dom4j/src/main/java/org/dom4j/CDATA.java

@ -8,13 +8,12 @@
package org.dom4j; package org.dom4j;
/** /**
* <p>
* <code>CDATA</code> defines an XML CDATA section. * <code>CDATA</code> defines an XML CDATA section.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.7 $
*/ */
@SuppressWarnings("unused")
public interface CDATA extends CharacterData { public interface CDATA extends CharacterData {
} }

5
fine-org-dom4j/src/main/java/org/dom4j/CharacterData.java

@ -8,15 +8,14 @@
package org.dom4j; package org.dom4j;
/** /**
* <p>
* <code>CharacterData</code> is a marker interface for character based nodes * <code>CharacterData</code> is a marker interface for character based nodes
* such as the <code>CDATA</code>,<code>Comment</code> and * such as the <code>CDATA</code>,<code>Comment</code> and
* <code>Text</code> nodes. * <code>Text</code> nodes.
* </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.9 $
*/ */
@SuppressWarnings("unused")
public interface CharacterData extends Node { public interface CharacterData extends Node {
/** /**
* Appends the given text to this nodes text value. Calling this method is * Appends the given text to this nodes text value. Calling this method is

5
fine-org-dom4j/src/main/java/org/dom4j/Comment.java

@ -8,13 +8,12 @@
package org.dom4j; package org.dom4j;
/** /**
* <p>
* <code>Comment</code> defines the behavior of an XML comment. * <code>Comment</code> defines the behavior of an XML comment.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.7 $
*/ */
@SuppressWarnings("unused")
public interface Comment extends CharacterData { public interface Comment extends CharacterData {
} }

13
fine-org-dom4j/src/main/java/org/dom4j/Document.java

@ -7,18 +7,17 @@
package org.dom4j; package org.dom4j;
import java.util.Map;
import org.xml.sax.EntityResolver; import org.xml.sax.EntityResolver;
import java.util.Map;
/** /**
* <p>
* <code>Document</code> defines an XML Document. * <code>Document</code> defines an XML Document.
* </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.14 $
*/ */
@SuppressWarnings("unused")
public interface Document extends Branch { public interface Document extends Branch {
/** /**
* Returns the root {@link Element}for this document. * Returns the root {@link Element}for this document.
@ -70,7 +69,7 @@ public interface Document extends Branch {
* *
* @return this <code>Document</code> instance. * @return this <code>Document</code> instance.
*/ */
Document addProcessingInstruction(String target, Map data); Document addProcessingInstruction(String target, Map<String, String> data);
/** /**
* Adds a DOCTYPE declaration to this document * Adds a DOCTYPE declaration to this document
@ -124,14 +123,12 @@ public interface Document extends Branch {
* when the Document was created in memory) or when the implementation does * when the Document was created in memory) or when the implementation does
* not support this operation. * not support this operation.
* *
* <p>
* The way this encoding is retrieved also depends on the way the XML source * The way this encoding is retrieved also depends on the way the XML source
* is parsed. For instance, if the SAXReader is used and if the underlying * is parsed. For instance, if the SAXReader is used and if the underlying
* XMLReader implementation support the * XMLReader implementation support the
* <code>org.xml.sax.ext.Locator2</code> interface, the result returned by * <code>org.xml.sax.ext.Locator2</code> interface, the result returned by
* this method is specified by the <code>getEncoding()</code> method of * this method is specified by the <code>getEncoding()</code> method of
* that interface. * that interface.
* </p>
* *
* @return The encoding of this document, as stated in the XML declaration, * @return The encoding of this document, as stated in the XML declaration,
* or <code>null</code> if unknown. * or <code>null</code> if unknown.

62
fine-org-dom4j/src/main/java/org/dom4j/DocumentException.java

@ -7,78 +7,32 @@
package org.dom4j; package org.dom4j;
import java.io.PrintStream;
import java.io.PrintWriter;
/** /**
* <p> * <code>DocumentException</code> is a nested Exception which may be thrown during the processing of a DOM4J document.
* <code>DocumentException</code> is a nested Exception which may be thrown
* during the processing of a DOM4J document.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @author Filip Jirsák
*/ */
public class DocumentException extends Exception { public class DocumentException extends Exception {
/** A wrapped <code>Throwable</code> */
private Throwable nestedException;
public DocumentException() { public DocumentException() {
super("Error occurred in DOM4J application.");
} }
public DocumentException(String message) { public DocumentException(String message) {
super(message); super(message);
} }
public DocumentException(Throwable nestedException) { public DocumentException(String message, Throwable cause) {
super(nestedException.getMessage()); super(message, cause);
this.nestedException = nestedException;
} }
public DocumentException(String message, Throwable nestedException) { public DocumentException(Throwable cause) {
super(message); super(cause);
this.nestedException = nestedException;
} }
@Deprecated
public Throwable getNestedException() { public Throwable getNestedException() {
return nestedException; return null;
}
public String getMessage() {
if (nestedException != null) {
return super.getMessage() + " Nested exception: "
+ nestedException.getMessage();
} else {
return super.getMessage();
}
}
public void printStackTrace() {
super.printStackTrace();
if (nestedException != null) {
System.err.print("Nested exception: ");
nestedException.printStackTrace();
}
}
public void printStackTrace(PrintStream out) {
super.printStackTrace(out);
if (nestedException != null) {
out.println("Nested exception: ");
nestedException.printStackTrace(out);
}
}
public void printStackTrace(PrintWriter writer) {
super.printStackTrace(writer);
if (nestedException != null) {
writer.println("Nested exception: ");
nestedException.printStackTrace(writer);
}
} }
} }

42
fine-org-dom4j/src/main/java/org/dom4j/DocumentFactory.java

@ -32,28 +32,25 @@ import org.dom4j.xpath.XPathPattern;
import org.jaxen.VariableContext; import org.jaxen.VariableContext;
/** /**
* <p>
* <code>DocumentFactory</code> is a collection of factory methods to allow * <code>DocumentFactory</code> is a collection of factory methods to allow
* easy custom building of DOM4J trees. The default tree that is built uses a * easy custom building of DOM4J trees. The default tree that is built uses a
* doubly linked tree. * doubly linked tree.
* </p>
* *
* <p>
* The tree built allows full XPath expressions from anywhere on the tree. * The tree built allows full XPath expressions from anywhere on the tree.
* </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
*/ */
@SuppressWarnings("unused")
public class DocumentFactory implements Serializable { public class DocumentFactory implements Serializable {
private static SingletonStrategy singleton = null; private static SingletonStrategy<DocumentFactory> singleton = null;
protected transient QNameCache cache; protected transient QNameCache cache;
/** Default namespace prefix -> URI mappings for XPath expressions to use */ /** Default namespace prefix URI mappings for XPath expressions to use */
private Map xpathNamespaceURIs; private Map<String, String> xpathNamespaceURIs;
private static SingletonStrategy createSingleton() { private static SingletonStrategy<DocumentFactory> createSingleton() {
SingletonStrategy result = null; SingletonStrategy<DocumentFactory> result;
String documentFactoryClassName; String documentFactoryClassName;
try { try {
@ -67,10 +64,10 @@ public class DocumentFactory implements Serializable {
String singletonClass = System.getProperty( String singletonClass = System.getProperty(
"org.dom4j.DocumentFactory.singleton.strategy", "org.dom4j.DocumentFactory.singleton.strategy",
"org.dom4j.util.SimpleSingleton"); "org.dom4j.util.SimpleSingleton");
Class clazz = Class.forName(singletonClass); Class<SingletonStrategy> clazz = (Class<SingletonStrategy>) Class.forName(singletonClass);
result = (SingletonStrategy) clazz.newInstance(); result = clazz.newInstance();
} catch (Exception e) { } catch (Exception e) {
result = new SimpleSingleton(); result = new SimpleSingleton<DocumentFactory>();
} }
result.setSingletonClassName(documentFactoryClassName); result.setSingletonClassName(documentFactoryClassName);
@ -83,10 +80,8 @@ public class DocumentFactory implements Serializable {
} }
/** /**
* <p>
* Access to singleton implementation of DocumentFactory which is used if no * Access to singleton implementation of DocumentFactory which is used if no
* DocumentFactory is specified when building using the standard builders. * DocumentFactory is specified when building using the standard builders.
* </p>
* *
* @return the default singleon instance * @return the default singleon instance
*/ */
@ -94,7 +89,7 @@ public class DocumentFactory implements Serializable {
if (singleton == null) { if (singleton == null) {
singleton = createSingleton(); singleton = createSingleton();
} }
return (DocumentFactory) singleton.instance(); return singleton.instance();
} }
// Factory methods // Factory methods
@ -121,10 +116,7 @@ public class DocumentFactory implements Serializable {
// createDocument() method. // createDocument() method.
Document answer = createDocument(); Document answer = createDocument();
if (answer instanceof AbstractDocument) { answer.setXMLEncoding(encoding);
((AbstractDocument) answer).setXMLEncoding(encoding);
}
return answer; return answer;
} }
@ -191,7 +183,7 @@ public class DocumentFactory implements Serializable {
} }
public ProcessingInstruction createProcessingInstruction(String target, public ProcessingInstruction createProcessingInstruction(String target,
Map data) { Map<String, String> data) {
return new DefaultProcessingInstruction(target, data); return new DefaultProcessingInstruction(target, data);
} }
@ -324,7 +316,7 @@ public class DocumentFactory implements Serializable {
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
public List getQNames() { public List<QName> getQNames() {
return cache.getQNames(); return cache.getQNames();
} }
@ -337,7 +329,7 @@ public class DocumentFactory implements Serializable {
* namespace URI. This value could well be null to indicate no * namespace URI. This value could well be null to indicate no
* namespace URIs are being mapped. * namespace URIs are being mapped.
*/ */
public Map getXPathNamespaceURIs() { public Map<String, String> getXPathNamespaceURIs() {
return xpathNamespaceURIs; return xpathNamespaceURIs;
} }
@ -349,7 +341,7 @@ public class DocumentFactory implements Serializable {
* @param namespaceURIs * @param namespaceURIs
* DOCUMENT ME! * DOCUMENT ME!
*/ */
public void setXPathNamespaceURIs(Map namespaceURIs) { public void setXPathNamespaceURIs(Map<String, String> namespaceURIs) {
this.xpathNamespaceURIs = namespaceURIs; this.xpathNamespaceURIs = namespaceURIs;
} }
@ -372,10 +364,10 @@ public class DocumentFactory implements Serializable {
try { try {
// I'll use the current class loader // I'll use the current class loader
// that loaded me to avoid problems in J2EE and web apps // that loaded me to avoid problems in J2EE and web apps
Class theClass = Class.forName(className, true, Class<DocumentFactory> theClass = (Class<DocumentFactory>) Class.forName(className, true,
DocumentFactory.class.getClassLoader()); DocumentFactory.class.getClassLoader());
return (DocumentFactory) theClass.newInstance(); return theClass.newInstance();
} catch (Throwable e) { } catch (Throwable e) {
System.out.println("WARNING: Cannot load DocumentFactory: " System.out.println("WARNING: Cannot load DocumentFactory: "
+ className); + className);

23
fine-org-dom4j/src/main/java/org/dom4j/DocumentHelper.java

@ -18,16 +18,16 @@ import org.dom4j.rule.Pattern;
import org.jaxen.VariableContext; import org.jaxen.VariableContext;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/** /**
* <p>
* <code>DocumentHelper</code> is a collection of helper methods for using * <code>DocumentHelper</code> is a collection of helper methods for using
* DOM4J. * DOM4J.
* </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.26 $
*/ */
@SuppressWarnings("unused")
public final class DocumentHelper { public final class DocumentHelper {
private DocumentHelper() { private DocumentHelper() {
} }
@ -89,7 +89,7 @@ public final class DocumentHelper {
} }
public static ProcessingInstruction createProcessingInstruction(String pi, public static ProcessingInstruction createProcessingInstruction(String pi,
Map data) { Map<String, String> data) {
return getDocumentFactory().createProcessingInstruction(pi, data); return getDocumentFactory().createProcessingInstruction(pi, data);
} }
@ -190,7 +190,7 @@ public final class DocumentHelper {
* *
* @return the results of all the XPath evaluations as a single list * @return the results of all the XPath evaluations as a single list
*/ */
public static List selectNodes(String xpathFilterExpression, List nodes) { public static List<Node> selectNodes(String xpathFilterExpression, List<Node> nodes) {
XPath xpath = createXPath(xpathFilterExpression); XPath xpath = createXPath(xpathFilterExpression);
return xpath.selectNodes(nodes); return xpath.selectNodes(nodes);
@ -210,7 +210,7 @@ public final class DocumentHelper {
* *
* @return the results of all the XPath evaluations as a single list * @return the results of all the XPath evaluations as a single list
*/ */
public static List selectNodes(String xpathFilterExpression, Node node) { public static List<Node> selectNodes(String xpathFilterExpression, Node node) {
XPath xpath = createXPath(xpathFilterExpression); XPath xpath = createXPath(xpathFilterExpression);
return xpath.selectNodes(node); return xpath.selectNodes(node);
@ -227,7 +227,7 @@ public final class DocumentHelper {
* @param xpathExpression * @param xpathExpression
* is the XPath expression used for comparison * is the XPath expression used for comparison
*/ */
public static void sort(List list, String xpathExpression) { public static void sort(List<Node> list, String xpathExpression) {
XPath xpath = createXPath(xpathExpression); XPath xpath = createXPath(xpathExpression);
xpath.sort(list); xpath.sort(list);
} }
@ -247,7 +247,7 @@ public final class DocumentHelper {
* if true then duplicate values (using the sortXPath for * if true then duplicate values (using the sortXPath for
* comparisions) will be removed from the List * comparisions) will be removed from the List
*/ */
public static void sort(List list, String expression, boolean distinct) { public static void sort(List<Node> list, String expression, boolean distinct) {
XPath xpath = createXPath(expression); XPath xpath = createXPath(expression);
xpath.sort(list, distinct); xpath.sort(list, distinct);
} }
@ -258,6 +258,8 @@ public final class DocumentHelper {
* returns the newly created Document. * returns the newly created Document.
* </p> * </p>
* *
* Loading external DTD and entities is disabled (if it is possible) for security reasons.
*
* @param text * @param text
* the XML text to be parsed * the XML text to be parsed
* *
@ -267,15 +269,14 @@ public final class DocumentHelper {
* if the document could not be parsed * if the document could not be parsed
*/ */
public static Document parseText(String text) throws DocumentException { public static Document parseText(String text) throws DocumentException {
Document result = null; SAXReader reader = SAXReader.createDefault();
SAXReader reader = new SAXReader();
String encoding = getEncoding(text); String encoding = getEncoding(text);
InputSource source = new InputSource(new StringReader(text)); InputSource source = new InputSource(new StringReader(text));
source.setEncoding(encoding); 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, // if the XML parser doesn't provide a way to retrieve the encoding,
// specify it manually // specify it manually

15
fine-org-dom4j/src/main/java/org/dom4j/DocumentType.java

@ -7,16 +7,17 @@
package org.dom4j; package org.dom4j;
import org.dom4j.dtd.Decl;
import java.util.List; import java.util.List;
/** /**
* <p>
* <code>DocumentType</code> defines an XML DOCTYPE declaration. * <code>DocumentType</code> defines an XML DOCTYPE declaration.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.10 $
*/ */
@SuppressWarnings("unused")
public interface DocumentType extends Node { public interface DocumentType extends Node {
/** /**
* This method is the equivalent to the {@link #getName}method. It is added * 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! * @return DOCUMENT ME!
*/ */
List getInternalDeclarations(); List<Decl> getInternalDeclarations();
/** /**
* Sets the list of internal DTD declaration objects, defined in the * Sets the list of internal DTD declaration objects, defined in the
@ -58,7 +59,7 @@ public interface DocumentType extends Node {
* @param declarations * @param declarations
* DOCUMENT ME! * DOCUMENT ME!
*/ */
void setInternalDeclarations(List declarations); void setInternalDeclarations(List<Decl> declarations);
/** /**
* Returns a list of internal DTD declaration objects, defined in the * Returns a list of internal DTD declaration objects, defined in the
@ -66,7 +67,7 @@ public interface DocumentType extends Node {
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
List getExternalDeclarations(); List<Decl> getExternalDeclarations();
/** /**
* Sets the list of internal DTD declaration objects, defined in the * Sets the list of internal DTD declaration objects, defined in the
@ -75,7 +76,7 @@ public interface DocumentType extends Node {
* @param declarations * @param declarations
* DOCUMENT ME! * DOCUMENT ME!
*/ */
void setExternalDeclarations(List declarations); void setExternalDeclarations(List<Decl> declarations);
} }
/* /*

303
fine-org-dom4j/src/main/java/org/dom4j/Element.java

@ -12,117 +12,88 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* <p>
* <code>Element</code> interface defines an XML element. An element can have * <code>Element</code> interface defines an XML element. An element can have
* declared namespaces, attributes, child nodes and textual content. * declared namespaces, attributes, child nodes and textual content.
* </p>
*
* <p> * <p>
* Some of this interface is optional. Some implementations may be read-only and * Some of this interface is optional. Some implementations may be read-only and
* not support being modified. Some implementations may not support the parent * 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}.
* </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.47 $
*/ */
@SuppressWarnings("unused")
public interface Element extends Branch { public interface Element extends Branch {
// Name and namespace related methods // Name and namespace related methods
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
/** /**
* <p>
* Returns the <code>QName</code> of this element which represents the * Returns the <code>QName</code> of this element which represents the
* local name, the qualified name and the <code>Namespace</code>. * local name, the qualified name and the <code>Namespace</code>.
* </p>
* *
* @return the <code>QName</code> associated with this element * @return the <code>QName</code> associated with this element
*/ */
QName getQName(); QName getQName();
/** /**
* <p>
* Sets the <code>QName</code> of this element which represents the local * Sets the <code>QName</code> of this element which represents the local
* name, the qualified name and the <code>Namespace</code>. * name, the qualified name and the <code>Namespace</code>.
* </p>
* *
* @param qname * @param qname is the <code>QName</code> to be associated with this element
* is the <code>QName</code> to be associated with this element
*/ */
void setQName(QName qname); void setQName(QName qname);
/** /**
* <p>
* Returns the <code>Namespace</code> of this element if one exists * Returns the <code>Namespace</code> of this element if one exists
* otherwise <code>Namespace.NO_NAMESPACE</code> is returned. * otherwise <code>Namespace.NO_NAMESPACE</code> is returned.
* </p>
* *
* @return the <code>Namespace</code> associated with this element * @return the <code>Namespace</code> associated with this element
*/ */
Namespace getNamespace(); Namespace getNamespace();
/** /**
* <p>
* Returns the <code>QName</code> for the given qualified name, using the * Returns the <code>QName</code> for the given qualified name, using the
* namespace URI in scope for the given prefix of the qualified name or the * namespace URI in scope for the given prefix of the qualified name or the
* default namespace if the qualified name has no prefix. * default namespace if the qualified name has no prefix.
* </p>
*
* @param qualifiedName
* DOCUMENT ME!
* *
* @param qualifiedName DOCUMENT ME!
* @return the <code>QName</code> for the given qualified name * @return the <code>QName</code> for the given qualified name
*/ */
QName getQName(String qualifiedName); QName getQName(String qualifiedName);
/** /**
* <p>
* Returns the <code>Namespace</code> which is mapped to the given prefix * Returns the <code>Namespace</code> which is mapped to the given prefix
* or null if it could not be found. * or null if it could not be found.
* </p>
*
* @param prefix
* DOCUMENT ME!
* *
* @param prefix DOCUMENT ME!
* @return the <code>Namespace</code> associated with the given prefix * @return the <code>Namespace</code> associated with the given prefix
*/ */
Namespace getNamespaceForPrefix(String prefix); Namespace getNamespaceForPrefix(String prefix);
/** /**
* <p>
* Returns the <code>Namespace</code> which is mapped to the given URI or * Returns the <code>Namespace</code> which is mapped to the given URI or
* null if it could not be found. If there is more than one * null if it could not be found. If there is more than one
* <code>Namespace</code> mapped to the URI, which of them will be * <code>Namespace</code> mapped to the URI, which of them will be
* returned is undetermined. * returned is undetermined.
* </p>
*
* @param uri
* DOCUMENT ME!
* *
* @param uri DOCUMENT ME!
* @return the <code>Namespace</code> associated with the given URI * @return the <code>Namespace</code> associated with the given URI
*/ */
Namespace getNamespaceForURI(String uri); Namespace getNamespaceForURI(String uri);
/** /**
* <p>
* Returns the all namespaces which are mapped to the given URI or an empty * Returns the all namespaces which are mapped to the given URI or an empty
* list if no such namespaces could be found. * list if no such namespaces could be found.
* </p>
*
* @param uri
* DOCUMENT ME!
* *
* @param uri DOCUMENT ME!
* @return the namespaces associated with the given URI * @return the namespaces associated with the given URI
*
* @since 1.5 * @since 1.5
*/ */
List getNamespacesForURI(String uri); List<Namespace> getNamespacesForURI(String uri);
/** /**
* <p>
* Returns the namespace prefix of this element if one exists otherwise an * Returns the namespace prefix of this element if one exists otherwise an
* empty <code>String</code> is returned. * empty <code>String</code> is returned.
* </p>
* *
* @return the prefix of the <code>Namespace</code> of this element or an * @return the prefix of the <code>Namespace</code> of this element or an
* empty <code>String</code> * empty <code>String</code>
@ -130,10 +101,8 @@ public interface Element extends Branch {
String getNamespacePrefix(); String getNamespacePrefix();
/** /**
* <p>
* Returns the URI mapped to the namespace of this element if one exists * Returns the URI mapped to the namespace of this element if one exists
* otherwise an empty <code>String</code> is returned. * otherwise an empty <code>String</code> is returned.
* </p>
* *
* @return the URI for the <code>Namespace</code> of this element or an * @return the URI for the <code>Namespace</code> of this element or an
* empty <code>String</code> * empty <code>String</code>
@ -141,84 +110,66 @@ public interface Element extends Branch {
String getNamespaceURI(); String getNamespaceURI();
/** /**
* <p>
* Returns the fully qualified name of this element. This will be the same * 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 * as the value returned from {@link #getName}if this element has no
* namespace attached to this element or an expression of the form * namespace attached to this element or an expression of the form
*
* <pre> * <pre>
* getNamespacePrefix() + &quot;:&quot; + getName() * getNamespacePrefix() + &quot;:&quot; + getName()
* </pre> * </pre>
*
* will be returned. * will be returned.
* </p>
* *
* @return the fully qualified name of the element. * @return the fully qualified name of the element.
*/ */
String getQualifiedName(); String getQualifiedName();
/** /**
* <p>
* Returns any additional namespaces declarations for this element other * Returns any additional namespaces declarations for this element other
* than namespace returned via the {@link #getNamespace()}method. If no * than namespace returned via the {@link #getNamespace()}method. If no
* additional namespace declarations are present for this element then an * additional namespace declarations are present for this element then an
* empty list will be returned. The list is backed by the element such that * 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 * changes to the list will be reflected in the element though the reverse
* is not the case. * is not the case.
* </p>
* *
* @return a list of any additional namespace declarations. * @return a list of any additional namespace declarations.
*/ */
List additionalNamespaces(); List<Namespace> additionalNamespaces();
/** /**
* <p>
* Returns all the namespaces declared by this element. If no namespaces are * 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 * 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 * is backed by the element such that changes to the list will be reflected
* in the element though the reverse is not the case. * in the element though the reverse is not the case.
* </p>
* *
* @return a list of namespaces declared for this element. * @return a list of namespaces declared for this element.
*/ */
List declaredNamespaces(); List<Namespace> declaredNamespaces();
// Builder methods // Builder methods
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
/** /**
* <p>
* Adds the attribute value of the given local name. If an attribute already * 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 * 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 * values are silently ignored. If the value of the attribute is null then
* this method call will remove any attributes with the given name. * this method call will remove any attributes with the given name.
* </p>
* *
* @param name * @param name is the name of the attribute whose value is to be added or
* is the name of the attribute whose value is to be added or
* updated * updated
* @param value * @param value is the attribute's value
* is the attribute's value
*
* @return this <code>Element</code> instance. * @return this <code>Element</code> instance.
*/ */
Element addAttribute(String name, String value); Element addAttribute(String name, String value);
/** /**
* <p>
* Adds the attribute value of the given fully qualified name. If an * Adds the attribute value of the given fully qualified name. If an
* attribute already exists for the given name it will be replaced. * attribute already exists for the given name it will be replaced.
* Attributes with null values are silently ignored. If the value of the * Attributes with null values are silently ignored. If the value of the
* attribute is null then this method call will remove any attributes with * attribute is null then this method call will remove any attributes with
* the given name. * the given name.
* </p>
* *
* @param qName * @param qName is the fully qualified name of the attribute whose value is to
* is the fully qualified name of the attribute whose value is to
* be added or updated * be added or updated
* @param value * @param value is the attribute's value
* is the attribute's value
*
* @return this <code>Element</code> instance. * @return this <code>Element</code> instance.
*/ */
Element addAttribute(QName qName, String value); Element addAttribute(QName qName, String value);
@ -227,9 +178,7 @@ public interface Element extends Branch {
* Adds a new <code>Comment</code> node with the given text to this * Adds a new <code>Comment</code> node with the given text to this
* element. * element.
* *
* @param comment * @param comment is the text for the <code>Comment</code> node.
* is the text for the <code>Comment</code> node.
*
* @return this <code>Element</code> instance. * @return this <code>Element</code> instance.
*/ */
Element addComment(String comment); Element addComment(String comment);
@ -237,9 +186,7 @@ public interface Element extends Branch {
/** /**
* Adds a new <code>CDATA</code> node with the given text to this element. * Adds a new <code>CDATA</code> node with the given text to this element.
* *
* @param cdata * @param cdata is the text for the <code>CDATA</code> node.
* is the text for the <code>CDATA</code> node.
*
* @return this <code>Element</code> instance. * @return this <code>Element</code> instance.
*/ */
Element addCDATA(String cdata); Element addCDATA(String cdata);
@ -248,11 +195,8 @@ public interface Element extends Branch {
* Adds a new <code>Entity</code> node with the given name and text to * Adds a new <code>Entity</code> node with the given name and text to
* this element and returns a reference to the new node. * this element and returns a reference to the new node.
* *
* @param name * @param name is the name for the <code>Entity</code> node.
* is the name for the <code>Entity</code> node. * @param text is the text for the <code>Entity</code> node.
* @param text
* is the text for the <code>Entity</code> node.
*
* @return this <code>Element</code> instance. * @return this <code>Element</code> instance.
*/ */
Element addEntity(String name, String text); Element addEntity(String name, String text);
@ -260,11 +204,8 @@ public interface Element extends Branch {
/** /**
* Adds a namespace to this element for use by its child content * Adds a namespace to this element for use by its child content
* *
* @param prefix * @param prefix is the prefix to use, which should not be null or blank
* is the prefix to use, which should not be null or blank * @param uri is the namespace URI
* @param uri
* is the namespace URI
*
* @return this <code>Element</code> instance. * @return this <code>Element</code> instance.
*/ */
Element addNamespace(String prefix, String uri); Element addNamespace(String prefix, String uri);
@ -272,12 +213,9 @@ public interface Element extends Branch {
/** /**
* Adds a processing instruction for the given target * Adds a processing instruction for the given target
* *
* @param target * @param target is the target of the processing instruction
* is the target of the processing instruction * @param text is the textual data (key/value pairs) of the processing
* @param text
* is the textual data (key/value pairs) of the processing
* instruction * instruction
*
* @return this <code>Element</code> instance. * @return this <code>Element</code> instance.
*/ */
Element addProcessingInstruction(String target, String text); Element addProcessingInstruction(String target, String text);
@ -285,22 +223,17 @@ public interface Element extends Branch {
/** /**
* Adds a processing instruction for the given target * Adds a processing instruction for the given target
* *
* @param target * @param target is the target of the processing instruction
* is the target of the processing instruction * @param data is a Map of the key / value pairs of the processing
* @param data
* is a Map of the key / value pairs of the processing
* instruction * instruction
*
* @return this <code>Element</code> instance. * @return this <code>Element</code> instance.
*/ */
Element addProcessingInstruction(String target, Map data); Element addProcessingInstruction(String target, Map<String, String> data);
/** /**
* Adds a new <code>Text</code> node with the given text to this element. * Adds a new <code>Text</code> node with the given text to this element.
* *
* @param text * @param text is the text for the <code>Text</code> node.
* is the text for the <code>Text</code> node.
*
* @return this <code>Element</code> instance. * @return this <code>Element</code> instance.
*/ */
Element addText(String text); Element addText(String text);
@ -314,13 +247,10 @@ public interface Element extends Branch {
* <code>IllegalAddException</code> will be thrown. Attributes with null * <code>IllegalAddException</code> will be thrown. Attributes with null
* values are silently ignored. * values are silently ignored.
* *
* <p>
* If the value of the attribute is null then this method call will remove * If the value of the attribute is null then this method call will remove
* any attributes with the QName of this attribute. * any attributes with the QName of this attribute.
* </p>
* *
* @param attribute * @param attribute is the attribute to be added
* is the attribute to be added
*/ */
void add(Attribute attribute); void add(Attribute attribute);
@ -329,8 +259,7 @@ public interface Element extends Branch {
* already has a parent defined then an <code>IllegalAddException</code> * already has a parent defined then an <code>IllegalAddException</code>
* will be thrown. * will be thrown.
* *
* @param cdata * @param cdata is the CDATA to be added
* is the CDATA to be added
*/ */
void add(CDATA cdata); void add(CDATA cdata);
@ -339,8 +268,7 @@ public interface Element extends Branch {
* already has a parent defined then an <code>IllegalAddException</code> * already has a parent defined then an <code>IllegalAddException</code>
* will be thrown. * will be thrown.
* *
* @param entity * @param entity is the entity to be added
* is the entity to be added
*/ */
void add(Entity entity); void add(Entity entity);
@ -349,8 +277,7 @@ public interface Element extends Branch {
* already has a parent defined then an <code>IllegalAddException</code> * already has a parent defined then an <code>IllegalAddException</code>
* will be thrown. * will be thrown.
* *
* @param text * @param text is the text to be added
* is the text to be added
*/ */
void add(Text text); void add(Text text);
@ -359,17 +286,14 @@ public interface Element extends Branch {
* node already has a parent defined then an * node already has a parent defined then an
* <code>IllegalAddException</code> will be thrown. * <code>IllegalAddException</code> will be thrown.
* *
* @param namespace * @param namespace is the namespace to be added
* is the namespace to be added
*/ */
void add(Namespace namespace); void add(Namespace namespace);
/** /**
* Removes the given <code>Attribute</code> from this element. * Removes the given <code>Attribute</code> from this element.
* *
* @param attribute * @param attribute is the attribute to be removed
* is the attribute to be removed
*
* @return true if the attribute was removed * @return true if the attribute was removed
*/ */
boolean remove(Attribute attribute); boolean remove(Attribute attribute);
@ -379,9 +303,7 @@ public interface Element extends Branch {
* of this element. If the given node is not an immediate child of this * 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. * element then the {@link Node#detach()}method should be used instead.
* *
* @param cdata * @param cdata is the CDATA to be removed
* is the CDATA to be removed
*
* @return true if the cdata was removed * @return true if the cdata was removed
*/ */
boolean remove(CDATA cdata); boolean remove(CDATA cdata);
@ -391,9 +313,7 @@ public interface Element extends Branch {
* of this element. If the given node is not an immediate child of this * 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. * element then the {@link Node#detach()}method should be used instead.
* *
* @param entity * @param entity is the entity to be removed
* is the entity to be removed
*
* @return true if the entity was removed * @return true if the entity was removed
*/ */
boolean remove(Entity entity); boolean remove(Entity entity);
@ -404,9 +324,7 @@ public interface Element extends Branch {
* this element then the {@link Node#detach()}method should be used * this element then the {@link Node#detach()}method should be used
* instead. * instead.
* *
* @param namespace * @param namespace is the namespace to be removed
* is the namespace to be removed
*
* @return true if the namespace was removed * @return true if the namespace was removed
*/ */
boolean remove(Namespace namespace); boolean remove(Namespace namespace);
@ -416,9 +334,7 @@ public interface Element extends Branch {
* of this element. If the given node is not an immediate child of this * 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. * element then the {@link Node#detach()}method should be used instead.
* *
* @param text * @param text is the text to be removed
* is the text to be removed
*
* @return true if the text was removed * @return true if the text was removed
*/ */
boolean remove(Text text); boolean remove(Text text);
@ -470,8 +386,7 @@ public interface Element extends Branch {
* Sets the data value of this element if this element supports data binding * Sets the data value of this element if this element supports data binding
* or calls {@link #setText}if it doesn't * or calls {@link #setText}if it doesn't
* *
* @param data * @param data DOCUMENT ME!
* DOCUMENT ME!
*/ */
void setData(Object data); void setData(Object data);
@ -479,25 +394,22 @@ public interface Element extends Branch {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
/** /**
* <p>
* Returns the {@link Attribute}instances this element contains as a backed * 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}so that the attributes may be modified directly using the
* {@link List}interface. The <code>List</code> is backed by the * {@link List}interface. The <code>List</code> is backed by the
* <code>Element</code> so that changes to the list are reflected in the * <code>Element</code> so that changes to the list are reflected in the
* element and vice versa. * element and vice versa.
* </p>
* *
* @return the attributes that this element contains as a <code>List</code> * @return the attributes that this element contains as a <code>List</code>
*/ */
List attributes(); List<Attribute> attributes();
/** /**
* Sets the attributes that this element contains * Sets the attributes that this element contains
* *
* @param attributes * @param attributes DOCUMENT ME!
* DOCUMENT ME!
*/ */
void setAttributes(List attributes); void setAttributes(List<Attribute> attributes);
/** /**
* DOCUMENT ME! * DOCUMENT ME!
@ -511,14 +423,12 @@ public interface Element extends Branch {
* *
* @return an iterator over the attributes of this element * @return an iterator over the attributes of this element
*/ */
Iterator attributeIterator(); Iterator<Attribute> attributeIterator();
/** /**
* Returns the attribute at the specified indexGets the * Returns the attribute at the specified indexGets the
* *
* @param index * @param index DOCUMENT ME!
* DOCUMENT ME!
*
* @return the attribute at the specified index where index &gt;= 0 and * @return the attribute at the specified index where index &gt;= 0 and
* index &lt; number of attributes or throws an * index &lt; number of attributes or throws an
* IndexOutOfBoundsException if the index is not within the * IndexOutOfBoundsException if the index is not within the
@ -529,9 +439,7 @@ public interface Element extends Branch {
/** /**
* Returns the attribute with the given name * Returns the attribute with the given name
* *
* @param name * @param name DOCUMENT ME!
* DOCUMENT ME!
*
* @return the attribute for the given local name in any namespace. If there * @return the attribute for the given local name in any namespace. If there
* are more than one attributes with the given local name in * are more than one attributes with the given local name in
* different namespaces then the first one is returned. * different namespaces then the first one is returned.
@ -541,109 +449,79 @@ public interface Element extends Branch {
/** /**
* DOCUMENT ME! * DOCUMENT ME!
* *
* @param qName * @param qName is the fully qualified name
* is the fully qualified name
*
* @return the attribute for the given fully qualified name or null if it * @return the attribute for the given fully qualified name or null if it
* could not be found. * could not be found.
*/ */
Attribute attribute(QName qName); Attribute attribute(QName qName);
/** /**
* <p>
* This returns the attribute value for the attribute with the given name * 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 * and any namespace or null if there is no such attribute or the empty
* string if the attribute value is empty. * string if the attribute value is empty.
* </p>
*
* @param name
* is the name of the attribute value to be returnd
* *
* @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 * @return the value of the attribute, null if the attribute does not exist
* or the empty string * or the empty string
*/ */
String attributeValue(String name); String attributeValue(String name);
/** /**
* <p>
* This returns the attribute value for the attribute with the given 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 * and any namespace or the default value if there is no such attribute
* value. * value.
* </p>
* *
* @param name * @param name is the name of the attribute value to be returned
* is the name of the attribute value to be returnd * @param defaultValue is the default value to be returned if the attribute has no
* @param defaultValue
* is the default value to be returned if the attribute has no
* value defined. * value defined.
*
* @return the value of the attribute or the defaultValue if the attribute * @return the value of the attribute or the defaultValue if the attribute
* has no value defined. * has no value defined.
*/ */
String attributeValue(String name, String defaultValue); String attributeValue(String name, String defaultValue);
/** /**
* <p>
* This returns the attribute value for the attribute with the given fully * 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 * qualified name or null if there is no such attribute or the empty string
* if the attribute value is empty. * if the attribute value is empty.
* </p>
*
* @param qName
* is the fully qualified name
* *
* @param qName is the fully qualified name
* @return the value of the attribute, null if the attribute does not exist * @return the value of the attribute, null if the attribute does not exist
* or the empty string * or the empty string
*/ */
String attributeValue(QName qName); String attributeValue(QName qName);
/** /**
* <p>
* This returns the attribute value for the attribute with the given fully * 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. * qualified name or the default value if there is no such attribute value.
* </p>
* *
* @param qName * @param qName is the fully qualified name
* is the fully qualified name * @param defaultValue is the default value to be returned if the attribute has no
* @param defaultValue
* is the default value to be returned if the attribute has no
* value defined. * value defined.
*
* @return the value of the attribute or the defaultValue if the attribute * @return the value of the attribute or the defaultValue if the attribute
* has no value defined. * has no value defined.
*/ */
String attributeValue(QName qName, String defaultValue); String attributeValue(QName qName, String defaultValue);
/** /**
* <p>
* Sets the attribute value of the given local name. * Sets the attribute value of the given local name.
* </p>
* *
* @param name * @param name is the name of the attribute whose value is to be added or
* is the name of the attribute whose value is to be added or
* updated * updated
* @param value * @param value is the attribute's value
* is the attribute's value
*
* @deprecated As of version 0.5. Please use {@link * @deprecated As of version 0.5. Please use {@link
* #addAttribute(String,String)} instead. WILL BE REMOVED IN * #addAttribute(String, String)} instead. WILL BE REMOVED IN
* dom4j-1.6 !! * dom4j-1.6 !!
*/ */
void setAttributeValue(String name, String value); void setAttributeValue(String name, String value);
/** /**
* <p>
* Sets the attribute value of the given fully qualified name. * Sets the attribute value of the given fully qualified name.
* </p>
* *
* @param qName * @param qName is the fully qualified name of the attribute whose value is to
* is the fully qualified name of the attribute whose value is to
* be added or updated * be added or updated
* @param value * @param value is the attribute's value
* is the attribute's value
*
* @deprecated As of version 0.5. Please use {@link * @deprecated As of version 0.5. Please use {@link
* #addAttribute(QName,String)} instead. WILL BE REMOVED IN * #addAttribute(QName, String)} instead. WILL BE REMOVED IN
* dom4j-1.6 !! * dom4j-1.6 !!
*/ */
void setAttributeValue(QName qName, String value); void setAttributeValue(QName qName, String value);
@ -654,9 +532,7 @@ public interface Element extends Branch {
/** /**
* Returns the first element for the given local name and any namespace. * Returns the first element for the given local name and any namespace.
* *
* @param name * @param name DOCUMENT ME!
* DOCUMENT ME!
*
* @return the first element with the given local name * @return the first element with the given local name
*/ */
Element element(String name); Element element(String name);
@ -664,87 +540,71 @@ public interface Element extends Branch {
/** /**
* Returns the first element for the given fully qualified name. * Returns the first element for the given fully qualified name.
* *
* @param qName * @param qName is the fully qualified name to search for
* is the fully qualified name to search for
*
* @return the first element with the given fully qualified name * @return the first element with the given fully qualified name
*/ */
Element element(QName qName); Element element(QName qName);
/** /**
* <p>
* Returns the elements contained in this element. If this element does not * 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 * 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 * backed by the element such that changes to the list will be reflected in
* the element though the reverse is not the case. * the element though the reverse is not the case.
* </p>
* *
* @return a list of all the elements in this element. * @return a list of all the elements in this element.
*/ */
List elements(); List<Element> elements();
/** /**
* <p>
* Returns the elements contained in this element with the given local name * 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 * 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 * 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. * list will be reflected in the element though the reverse is not the case.
* </p>
*
* @param name
* DOCUMENT ME!
* *
* @param name DOCUMENT ME!
* @return a list of all the elements in this element for the given local * @return a list of all the elements in this element for the given local
* name * name
*/ */
List elements(String name); List<Element> elements(String name);
/** /**
* <p>
* Returns the elements contained in this element with the given fully * Returns the elements contained in this element with the given fully
* qualified name. If no elements are found then this method returns an * 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 * 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. * list will be reflected in the element though the reverse is not the case.
* </p>
*
* @param qName
* is the fully qualified name to search for
* *
* @param qName is the fully qualified name to search for
* @return a list of all the elements in this element for the given fully * @return a list of all the elements in this element for the given fully
* qualified name. * qualified name.
*/ */
List elements(QName qName); List<Element> elements(QName qName);
/** /**
* Returns an iterator over all this elements child elements. * Returns an iterator over all this elements child elements.
* *
* @return an iterator over the contained elements * @return an iterator over the contained elements
*/ */
Iterator elementIterator(); Iterator<Element> elementIterator();
/** /**
* Returns an iterator over the elements contained in this element which * Returns an iterator over the elements contained in this element which
* match the given local name and any namespace. * match the given local name and any namespace.
* *
* @param name * @param name DOCUMENT ME!
* DOCUMENT ME!
*
* @return an iterator over the contained elements matching the given local * @return an iterator over the contained elements matching the given local
* name * name
*/ */
Iterator elementIterator(String name); Iterator<Element> elementIterator(String name);
/** /**
* Returns an iterator over the elements contained in this element which * Returns an iterator over the elements contained in this element which
* match the given fully qualified name. * match the given fully qualified name.
* *
* @param qName * @param qName is the fully qualified name to search for
* is the fully qualified name to search for
*
* @return an iterator over the contained elements matching the given fully * @return an iterator over the contained elements matching the given fully
* qualified name * qualified name
*/ */
Iterator elementIterator(QName qName); Iterator<Element> elementIterator(QName qName);
// Helper methods // Helper methods
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
@ -758,20 +618,16 @@ public interface Element extends Branch {
boolean isRootElement(); boolean isRootElement();
/** /**
* <p>
* Returns true if this <code>Element</code> has mixed content. Mixed * Returns true if this <code>Element</code> has mixed content. Mixed
* content means that an element contains both textual data and child * content means that an element contains both textual data and child
* elements. * elements.
* </p>
* *
* @return true if this element contains mixed content. * @return true if this element contains mixed content.
*/ */
boolean hasMixedContent(); boolean hasMixedContent();
/** /**
* <p>
* Returns true if this <code>Element</code> has text only content. * Returns true if this <code>Element</code> has text only content.
* </p>
* *
* @return true if this element is empty or only contains text content. * @return true if this element is empty or only contains text content.
*/ */
@ -782,45 +638,34 @@ public interface Element extends Branch {
* like the {@link java.util.Collection#addAll(java.util.Collection)} * like the {@link java.util.Collection#addAll(java.util.Collection)}
* method. * method.
* *
* @param element * @param element is the element whose attributes will be added to me.
* is the element whose attributes will be added to me.
*/ */
void appendAttributes(Element element); void appendAttributes(Element element);
/** /**
* <p>
* Creates a deep copy of this element The new element is detached from its * Creates a deep copy of this element The new element is detached from its
* parent, and getParent() on the clone will return null. * parent, and getParent() on the clone will return null.
* </p>
* *
* @return a new deep copy Element * @return a new deep copy Element
*/ */
Element createCopy(); Element createCopy();
/** /**
* <p>
* Creates a deep copy of this element with the given local name The new * 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 * element is detached from its parent, and getParent() on the clone will
* return null. * return null.
* </p>
*
* @param name
* DOCUMENT ME!
* *
* @param name DOCUMENT ME!
* @return a new deep copy Element * @return a new deep copy Element
*/ */
Element createCopy(String name); Element createCopy(String name);
/** /**
* <p>
* Creates a deep copy of this element with the given fully qualified 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 * The new element is detached from its parent, and getParent() on the clone
* will return null. * will return null.
* </p>
*
* @param qName
* DOCUMENT ME!
* *
* @param qName DOCUMENT ME!
* @return a new deep copy Element * @return a new deep copy Element
*/ */
Element createCopy(QName qName); Element createCopy(QName qName);
@ -838,9 +683,7 @@ public interface Element extends Branch {
* means the resulting Node will either be null or it will support the * means the resulting Node will either be null or it will support the
* parent relationship. * parent relationship.
* *
* @param index * @param index DOCUMENT ME!
* DOCUMENT ME!
*
* @return the Node for the given index which will support the parent * @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. * relationship or null if there is not a node at the given index.
*/ */

5
fine-org-dom4j/src/main/java/org/dom4j/ElementHandler.java

@ -8,16 +8,15 @@
package org.dom4j; package org.dom4j;
/** /**
* <p>
* <code>ElementHandler</code> interface defines a handler of * <code>ElementHandler</code> interface defines a handler of
* <code>Element</code> objects. It is used primarily in event based * <code>Element</code> objects. It is used primarily in event based
* processing models such as for processing large XML documents as they are * processing models such as for processing large XML documents as they are
* being parsed rather than waiting until the whole document is parsed. * being parsed rather than waiting until the whole document is parsed.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.8 $
*/ */
@SuppressWarnings("unused")
public interface ElementHandler { public interface ElementHandler {
/** /**
* Called by an event based processor when an elements openning tag is * Called by an event based processor when an elements openning tag is

3
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. * primary use is to retrieve the current {@link Element}being processed.
* *
* @author <a href="mailto:dwhite@equipecom.com">Dave White </a> * @author <a href="mailto:dwhite@equipecom.com">Dave White </a>
* @version $Revision$ * @version $Revision: 1.6 $
*/ */
@SuppressWarnings("unused")
public interface ElementPath { public interface ElementPath {
/** /**
* DOCUMENT ME! * DOCUMENT ME!

5
fine-org-dom4j/src/main/java/org/dom4j/Entity.java

@ -8,13 +8,12 @@
package org.dom4j; package org.dom4j;
/** /**
* <p>
* <code>Entity</code> defines an XML entity. * <code>Entity</code> defines an XML entity.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.7 $
*/ */
@SuppressWarnings("unused")
public interface Entity extends Node { public interface Entity extends Node {
} }

4
fine-org-dom4j/src/main/java/org/dom4j/IllegalAddException.java

@ -8,12 +8,10 @@
package org.dom4j; package org.dom4j;
/** /**
* <p>
* <code>IllegalAddException</code> is thrown when a node is added incorrectly * <code>IllegalAddException</code> is thrown when a node is added incorrectly
* to an <code>{@link Element}</code> * to an <code>{@link Element}</code>
* </p>
* *
* @version $Revision$ * @version $Revision: 1.6 $
*/ */
public class IllegalAddException extends IllegalArgumentException { public class IllegalAddException extends IllegalArgumentException {
public IllegalAddException(String reason) { public IllegalAddException(String reason) {

12
fine-org-dom4j/src/main/java/org/dom4j/InvalidXPathException.java

@ -8,17 +8,12 @@
package org.dom4j; package org.dom4j;
/** /**
* <p>
* <code>InvalidXPathException</code> is thrown when an invalid XPath * <code>InvalidXPathException</code> is thrown when an invalid XPath
* expression is used to traverse an XML document * expression is used to traverse an XML document
* </p>
* *
* @version $Revision$ * @version $Revision: 1.6 $
*/ */
public class InvalidXPathException extends IllegalArgumentException { public class InvalidXPathException extends IllegalArgumentException {
/** The <code>serialVersionUID</code>. */
private static final long serialVersionUID = 3257009869058881592L;
public InvalidXPathException(String xpath) { public InvalidXPathException(String xpath) {
super("Invalid XPath expression: " + xpath); super("Invalid XPath expression: " + xpath);
} }
@ -26,11 +21,6 @@ public class InvalidXPathException extends IllegalArgumentException {
public InvalidXPathException(String xpath, String reason) { public InvalidXPathException(String xpath, String reason) {
super("Invalid XPath expression: " + xpath + " " + reason); super("Invalid XPath expression: " + xpath + " " + reason);
} }
public InvalidXPathException(String xpath, Throwable t) {
super("Invalid XPath expression: '" + xpath
+ "'. Caused by: " + t.getMessage());
}
} }
/* /*

8
fine-org-dom4j/src/main/java/org/dom4j/Namespace.java

@ -12,13 +12,11 @@ import org.dom4j.tree.DefaultNamespace;
import org.dom4j.tree.NamespaceCache; import org.dom4j.tree.NamespaceCache;
/** /**
* <p>
* <code>Namespace</code> is a Flyweight Namespace that can be shared amongst * <code>Namespace</code> is a Flyweight Namespace that can be shared amongst
* nodes. * nodes.
* </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.22 $
*/ */
public class Namespace extends AbstractNode { public class Namespace extends AbstractNode {
/** Cache of Namespace instances */ /** Cache of Namespace instances */
@ -51,6 +49,10 @@ public class Namespace extends AbstractNode {
public Namespace(String prefix, String uri) { public Namespace(String prefix, String uri) {
this.prefix = (prefix != null) ? prefix : ""; this.prefix = (prefix != null) ? prefix : "";
this.uri = (uri != null) ? uri : ""; this.uri = (uri != null) ? uri : "";
if (!this.prefix.isEmpty()) {
QName.validateNCName(this.prefix);
}
} }
/** /**

15
fine-org-dom4j/src/main/java/org/dom4j/Node.java

@ -12,26 +12,21 @@ import java.io.Writer;
import java.util.List; import java.util.List;
/** /**
* <p>
* <code>Node</code> defines the polymorphic behavior for all XML nodes in a * <code>Node</code> defines the polymorphic behavior for all XML nodes in a
* dom4j tree. * dom4j tree.
* </p>
* *
* <p>
* A node can be output as its XML format, can be detached from its position in * 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 document and can have XPath expressions evaluated on itself.
* </p>
* *
* <p>
* A node may optionally support the parent relationship and may be read only. * A node may optionally support the parent relationship and may be read only.
* </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.31 $
* *
* @see #supportsParent * @see #supportsParent
* @see #isReadOnly * @see #isReadOnly
*/ */
@SuppressWarnings("unused")
public interface Node extends Cloneable { public interface Node extends Cloneable {
// W3C DOM complient node type codes // W3C DOM complient node type codes
@ -381,7 +376,7 @@ public interface Node extends Cloneable {
* @return the list of <code>Node</code> or <code>String</code> * @return the list of <code>Node</code> or <code>String</code>
* instances depending on the XPath expression * instances depending on the XPath expression
*/ */
List selectNodes(String xpathExpression); List<Node> selectNodes(String xpathExpression);
/** /**
* <p> * <p>
@ -417,7 +412,7 @@ public interface Node extends Cloneable {
* @return the list of <code>Node</code> instances sorted by the * @return the list of <code>Node</code> instances sorted by the
* comparisonXPathExpression * comparisonXPathExpression
*/ */
List selectNodes(String xpathExpression, String comparisonXPathExpression); List<Node> selectNodes(String xpathExpression, String comparisonXPathExpression);
/** /**
* <p> * <p>
@ -438,7 +433,7 @@ public interface Node extends Cloneable {
* @return the list of <code>Node</code> instances sorted by the * @return the list of <code>Node</code> instances sorted by the
* comparisonXPathExpression * comparisonXPathExpression
*/ */
List selectNodes(String xpathExpression, String comparisonXPathExpression, List<Node> selectNodes(String xpathExpression, String comparisonXPathExpression,
boolean removeDuplicates); boolean removeDuplicates);
/** /**

5
fine-org-dom4j/src/main/java/org/dom4j/NodeFilter.java

@ -8,15 +8,14 @@
package org.dom4j; package org.dom4j;
/** /**
* <p>
* <code>NodeFilter</code> defines the behavior for a filter or predicate * <code>NodeFilter</code> defines the behavior for a filter or predicate
* which acts on a DOM4J Node. Instances can be generated from an {@link * which acts on a DOM4J Node. Instances can be generated from an {@link
* DocumentFactory}. * DocumentFactory}.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.7 $
*/ */
@SuppressWarnings("unused")
public interface NodeFilter { public interface NodeFilter {
/** /**
* <p> * <p>

9
fine-org-dom4j/src/main/java/org/dom4j/ProcessingInstruction.java

@ -10,16 +10,15 @@ package org.dom4j;
import java.util.Map; import java.util.Map;
/** /**
* <p>
* <code>ProcessingInstruction</code> defines an XML processing instruction. * <code>ProcessingInstruction</code> defines an XML processing instruction.
* The {@link Node#getName}method will return the target of the PI and the * 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 * {@link Node#getText}method will return the data from all of the
* instructions. * instructions.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.10 $
*/ */
@SuppressWarnings("unused")
public interface ProcessingInstruction extends Node { public interface ProcessingInstruction extends Node {
/** /**
* This method is the equivalent to the {@link #getName}method. It is added * 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 * @return the values for this processing instruction as a Map
*/ */
Map getValues(); Map<String, String> getValues();
void setValue(String name, String value); void setValue(String name, String value);
void setValues(Map data); void setValues(Map<String, String> data);
boolean removeValue(String name); boolean removeValue(String name);
} }

123
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.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.regex.Pattern;
import org.dom4j.tree.QNameCache; import org.dom4j.tree.QNameCache;
import org.dom4j.util.SingletonStrategy; import org.dom4j.util.SingletonStrategy;
/** /**
* <p>
* <code>QName</code> represents a qualified name value of an XML element or * <code>QName</code> represents a qualified name value of an XML element or
* attribute. It consists of a local name and a {@link Namespace}instance. This * attribute. It consists of a local name and a {@link Namespace}instance. This
* object is immutable. * object is immutable.
* </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @author Filip Jirsák
*/ */
public class QName implements Serializable { public class QName implements Serializable {
/** The Singleton instance */ /** The Singleton instance */
private static SingletonStrategy singleton = null; private static SingletonStrategy<QNameCache> singleton = null;
/**
* {@code NameStartChar} without colon.
*
* <pre>NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]</pre>
*
* @see <a href="https://www.w3.org/TR/xml/#sec-common-syn">XML 1.0 2.3 Common Syntactic Constructs</a>
* @see <a href="https://www.w3.org/TR/2006/REC-xml11-20060816/#sec-common-syn">XML 1.1 2.3 Common Syntactic Constructs</a>
*/
private static final String NAME_START_CHAR = "_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD";
/**
* {@code NameChar} without colon.
*
* <pre>NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]</pre>
*
* @see <a href="https://www.w3.org/TR/xml/#sec-common-syn">XML 1.0 2.3 Common Syntactic Constructs</a>
* @see <a href="https://www.w3.org/TR/2006/REC-xml11-20060816/#sec-common-syn">XML 1.1 2.3 Common Syntactic Constructs</a>
*/
private static final String NAME_CHAR = NAME_START_CHAR + "-.0-9\u00B7\u0300-\u036F\u203F-\u2040";
/**
* {@code NCName}
*
* <pre>
* NCName ::= NCNameStartChar NCNameChar* (An XML Name, minus the ":")
* NCNameChar ::= NameChar -':'
* NCNameStartChar ::= NameStartChar -':'
* </pre>
*
* @see <a href="https://www.w3.org/TR/xml-names/#ns-qualnames">Namespaces in XML 1.0 4 Qualified Names</a>
* @see <a href="https://www.w3.org/TR/2006/REC-xml-names11-20060816/#ns-qualnames">Namespaces in XML 1.1 4 Qualified Names</a>
*/
private static final String NCNAME = "["+NAME_START_CHAR+"]["+NAME_CHAR+"]*";
/**
* Regular expression for {@code Name} (with colon).
*
* <pre>Name ::= NameStartChar (NameChar)*</pre>
*
* @see <a href="https://www.w3.org/TR/xml/#sec-common-syn">XML 1.0 2.3 Common Syntactic Constructs</a>
* @see <a href="https://www.w3.org/TR/2006/REC-xml11-20060816/#sec-common-syn">XML 1.1 2.3 Common Syntactic Constructs</a>
*/
private static final Pattern RE_NAME = Pattern.compile("[:"+NAME_START_CHAR+"][:"+NAME_CHAR+"]*");
/**
* Regular expression for {@code NCName}.
*
* <pre>
* NCName ::= NCNameStartChar NCNameChar* (An XML Name, minus the ":")
* NCNameChar ::= NameChar -':'
* NCNameStartChar ::= NameStartChar -':'
* </pre>
*
* @see <a href="https://www.w3.org/TR/xml-names/#ns-qualnames">Namespaces in XML 1.0 4 Qualified Names</a>
* @see <a href="https://www.w3.org/TR/2006/REC-xml-names11-20060816/#ns-qualnames">Namespaces in XML 1.1 4 Qualified Names</a>
*/
private static final Pattern RE_NCNAME = Pattern.compile(NCNAME);
/**
* Regular expression for {@code QName}.
*
* <pre>
* QName ::= PrefixedName | UnprefixedName
* PrefixedName ::= Prefix ':' LocalPart
* UnprefixedName ::= LocalPart
* Prefix ::= NCName
* LocalPart ::= NCName
* </pre>
*
* @see <a href="https://www.w3.org/TR/xml-names/#ns-qualnames">Namespaces in XML 1.0 4 Qualified Names</a>
* @see <a href="https://www.w3.org/TR/2006/REC-xml-names11-20060816/#ns-qualnames">Namespaces in XML 1.1 4 Qualified Names</a>
*/
private static final Pattern RE_QNAME = Pattern.compile("(?:"+NCNAME+":)?"+NCNAME);
static { static {
try { try {
String defaultSingletonClass = "org.dom4j.util.SimpleSingleton"; String defaultSingletonClass = "org.dom4j.util.SimpleSingleton";
Class clazz = null; Class<SingletonStrategy> clazz = null;
try { try {
String singletonClass = defaultSingletonClass; String singletonClass = defaultSingletonClass;
singletonClass = System.getProperty( singletonClass = System.getProperty(
"org.dom4j.QName.singleton.strategy", singletonClass); "org.dom4j.QName.singleton.strategy", singletonClass);
clazz = Class.forName(singletonClass); clazz = (Class<SingletonStrategy>) Class.forName(singletonClass);
} catch (Exception exc1) { } catch (Exception exc1) {
try { try {
String singletonClass = defaultSingletonClass; String singletonClass = defaultSingletonClass;
clazz = Class.forName(singletonClass); clazz = (Class<SingletonStrategy>) Class.forName(singletonClass);
} catch (Exception exc2) { } catch (Exception exc2) {
} }
} }
singleton = (SingletonStrategy) clazz.newInstance(); singleton = clazz.newInstance();
singleton.setSingletonClassName(QNameCache.class.getName()); singleton.setSingletonClassName(QNameCache.class.getName());
} catch (Exception exc3) { } catch (Exception exc3) {
} }
@ -73,6 +147,11 @@ public class QName implements Serializable {
this.name = (name == null) ? "" : name; this.name = (name == null) ? "" : name;
this.namespace = (namespace == null) ? Namespace.NO_NAMESPACE this.namespace = (namespace == null) ? Namespace.NO_NAMESPACE
: namespace; : namespace;
if (this.namespace.equals(Namespace.NO_NAMESPACE)) {
validateName(this.name);
} else {
validateNCName(this.name);
}
} }
public QName(String name, Namespace namespace, String qualifiedName) { public QName(String name, Namespace namespace, String qualifiedName) {
@ -80,6 +159,8 @@ public class QName implements Serializable {
this.qualifiedName = qualifiedName; this.qualifiedName = qualifiedName;
this.namespace = (namespace == null) ? Namespace.NO_NAMESPACE this.namespace = (namespace == null) ? Namespace.NO_NAMESPACE
: namespace; : namespace;
validateNCName(this.name);
validateQName(this.qualifiedName);
} }
public static QName get(String name) { public static QName get(String name) {
@ -231,28 +312,46 @@ public class QName implements Serializable {
} }
private void writeObject(ObjectOutputStream out) throws IOException { private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
// We use writeObject() and not writeUTF() to minimize space // We use writeObject() and not writeUTF() to minimize space
// This allows for writing pointers to already written strings // This allows for writing pointers to already written strings
out.writeObject(namespace.getPrefix()); out.writeObject(namespace.getPrefix());
out.writeObject(namespace.getURI()); out.writeObject(namespace.getURI());
out.defaultWriteObject();
} }
private void readObject(ObjectInputStream in) throws IOException, private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException { ClassNotFoundException {
in.defaultReadObject();
String prefix = (String) in.readObject(); String prefix = (String) in.readObject();
String uri = (String) in.readObject(); String uri = (String) in.readObject();
in.defaultReadObject();
namespace = Namespace.get(prefix, uri); namespace = Namespace.get(prefix, uri);
} }
private static QNameCache getCache() { private static QNameCache getCache() {
QNameCache cache = (QNameCache) singleton.instance(); QNameCache cache = singleton.instance();
return cache; return cache;
} }
private static void validateName(String name) {
if (!RE_NAME.matcher(name).matches()) {
throw new IllegalArgumentException(String.format("Illegal character in name: '%s'.", name));
}
}
protected static void validateNCName(String ncname) {
if (!RE_NCNAME.matcher(ncname).matches()) {
throw new IllegalArgumentException(String.format("Illegal character in local name: '%s'.", ncname));
}
}
private static void validateQName(String qname) {
if (!RE_QNAME.matcher(qname).matches()) {
throw new IllegalArgumentException(String.format("Illegal character in qualified name: '%s'.", qname));
}
}
} }

5
fine-org-dom4j/src/main/java/org/dom4j/Text.java

@ -8,13 +8,12 @@
package org.dom4j; package org.dom4j;
/** /**
* <p>
* <code>Text</code> defines an XML Text node. * <code>Text</code> defines an XML Text node.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.7 $
*/ */
@SuppressWarnings("unused")
public interface Text extends CharacterData { public interface Text extends CharacterData {
} }

7
fine-org-dom4j/src/main/java/org/dom4j/Visitor.java

@ -8,24 +8,21 @@
package org.dom4j; package org.dom4j;
/** /**
* <p>
* <code>Visitor</code> is used to implement the <code>Visitor</code> * <code>Visitor</code> is used to implement the <code>Visitor</code>
* pattern in DOM4J. An object of this interface can be passed to a * pattern in DOM4J. An object of this interface can be passed to a
* <code>Node</code> which will then call its typesafe methods. Please refer * <code>Node</code> which will then call its typesafe methods. Please refer
* to the <i>Gang of Four </i> book of Design Patterns for more details on the * to the <i>Gang of Four </i> book of Design Patterns for more details on the
* <code>Visitor</code> pattern. * <code>Visitor</code> pattern.
* </p>
* *
* <p>
* This <a href="http://www.patterndepot.com/put/8/JavaPatterns.htm">site </a> * This <a href="http://www.patterndepot.com/put/8/JavaPatterns.htm">site </a>
* has further discussion on design patterns and links to the GOF book. This <a * has further discussion on design patterns and links to the GOF book. This <a
* href="http://www.patterndepot.com/put/8/visitor.pdf">link </a> describes the * href="http://www.patterndepot.com/put/8/visitor.pdf">link </a> describes the
* Visitor pattern in detail. * Visitor pattern in detail.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.8 $
*/ */
@SuppressWarnings("unused")
public interface Visitor { public interface Visitor {
/** /**
* <p> * <p>

4
fine-org-dom4j/src/main/java/org/dom4j/VisitorSupport.java

@ -8,14 +8,12 @@
package org.dom4j; package org.dom4j;
/** /**
* <p>
* <code>VisitorSupport</code> is an abstract base class which is useful for * <code>VisitorSupport</code> is an abstract base class which is useful for
* implementation inheritence or when using anonymous inner classes to create * implementation inheritence or when using anonymous inner classes to create
* simple <code>Visitor</code> implementations. * simple <code>Visitor</code> implementations.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.6 $
*/ */
public abstract class VisitorSupport implements Visitor { public abstract class VisitorSupport implements Visitor {
public VisitorSupport() { public VisitorSupport() {

127
fine-org-dom4j/src/main/java/org/dom4j/XPath.java

@ -7,59 +7,48 @@
package org.dom4j; package org.dom4j;
import java.util.List;
import java.util.Map;
import org.jaxen.FunctionContext; import org.jaxen.FunctionContext;
import org.jaxen.NamespaceContext; import org.jaxen.NamespaceContext;
import org.jaxen.VariableContext; import org.jaxen.VariableContext;
import java.util.List;
import java.util.Map;
/** /**
* <p>
* <code>XPath</code> represents an XPath expression after it has been parsed * <code>XPath</code> represents an XPath expression after it has been parsed
* from a String. * from a String.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.20 $
*/ */
@SuppressWarnings("unused")
public interface XPath extends NodeFilter { public interface XPath extends NodeFilter {
/** /**
* <p>
* <code>getText</code> will return the textual version of the XPath * <code>getText</code> will return the textual version of the XPath
* expression. * expression.
* </p>
* *
* @return the textual format of the XPath expression. * @return the textual format of the XPath expression.
*/ */
String getText(); String getText();
/** /**
* <p>
* <code>matches</code> returns true if the given node matches the XPath * <code>matches</code> returns true if the given node matches the XPath
* expression. To be more precise when evaluating this XPath expression on * expression. To be more precise when evaluating this XPath expression on
* the given node the result set must include the node. * the given node the result set must include the node.
* </p>
*
* @param node
* DOCUMENT ME!
* *
* @param node DOCUMENT ME!
* @return true if the given node matches this XPath expression * @return true if the given node matches this XPath expression
*/ */
boolean matches(Node node); boolean matches(Node node);
/** /**
* <p>
* <code>evaluate</code> evaluates an XPath expression and returns the * <code>evaluate</code> evaluates an XPath expression and returns the
* result as an {@link Object}. The object returned can either be a {@link * result as an {@link Object}. The object returned can either be a {@link
* List} of {@link Node}instances, a {@link Node}instance, a {@link * List} of {@link Node}instances, a {@link Node}instance, a {@link
* String} or a {@link Number}instance depending on the XPath expression. * String} or a {@link Number}instance depending on the XPath expression.
* </p>
* *
* @param context * @param context is either a node or a list of nodes on which to evalute the
* is either a node or a list of nodes on which to evalute the
* XPath * XPath
*
* @return the value of the XPath expression as a {@link List}of {@link * @return the value of the XPath expression as a {@link List}of {@link
* Node} instances, a {@link Node}instance, a {@link String}or a * Node} instances, a {@link Node}instance, a {@link String}or a
* {@link Number}instance depending on the XPath expression. * {@link Number}instance depending on the XPath expression.
@ -67,121 +56,89 @@ public interface XPath extends NodeFilter {
Object evaluate(Object context); Object evaluate(Object context);
/** /**
* <p>
* <code>selectObject</code> evaluates an XPath expression and returns the * <code>selectObject</code> evaluates an XPath expression and returns the
* result as an {@link Object}. The object returned can either be a {@link * result as an {@link Object}. The object returned can either be a {@link
* List} of {@link Node}instances, a {@link Node}instance, a {@link * List} of {@link Node}instances, a {@link Node}instance, a {@link
* String} or a {@link Number}instance depending on the XPath expression. * String} or a {@link Number}instance depending on the XPath expression.
* </p>
* *
* @param context * @param context is either a node or a list of nodes on which to evalute the
* is either a node or a list of nodes on which to evalute the
* XPath * XPath
*
* @return the value of the XPath expression as a {@link List}of {@link * @return the value of the XPath expression as a {@link List}of {@link
* Node} instances, a {@link Node}instance, a {@link String}or a * Node} instances, a {@link Node}instance, a {@link String}or a
* {@link Number}instance depending on the XPath expression. * {@link Number}instance depending on the XPath expression.
*
* @deprecated please use evaluate(Object) instead. WILL BE REMOVED IN * @deprecated please use evaluate(Object) instead. WILL BE REMOVED IN
* dom4j-1.6 !! * dom4j-1.6 !!
*/ */
Object selectObject(Object context); Object selectObject(Object context);
/** /**
* <p>
* <code>selectNodes</code> performs this XPath expression on the given * <code>selectNodes</code> performs this XPath expression on the given
* {@link Node}or {@link List}of {@link Node}s instances appending all * {@link Node}or {@link List}of {@link Node}s instances appending all
* the results together into a single list. * the results together into a single list.
* </p>
* *
* @param context * @param context is either a node or a list of nodes on which to evalute the
* is either a node or a list of nodes on which to evalute the
* XPath * XPath
*
* @return the results of all the XPath evaluations as a single list * @return the results of all the XPath evaluations as a single list
*/ */
List selectNodes(Object context); List<Node> selectNodes(Object context);
/** /**
* <p>
* <code>selectNodes</code> evaluates the XPath expression on the given * <code>selectNodes</code> evaluates the XPath expression on the given
* {@link Node}or {@link List}of {@link Node}s and returns the result as * {@link Node}or {@link List}of {@link Node}s and returns the result as
* a <code>List</code> of <code>Node</code> s sorted by the sort XPath * a <code>List</code> of <code>Node</code> s sorted by the sort XPath
* expression. * expression.
* </p>
* *
* @param context * @param context is either a node or a list of nodes on which to evalute the
* is either a node or a list of nodes on which to evalute the
* XPath * XPath
* @param sortXPath * @param sortXPath is the XPath expression to sort by
* is the XPath expression to sort by
*
* @return a list of <code>Node</code> instances * @return a list of <code>Node</code> instances
*/ */
List selectNodes(Object context, XPath sortXPath); List<Node> selectNodes(Object context, XPath sortXPath);
/** /**
* <p>
* <code>selectNodes</code> evaluates the XPath expression on the given * <code>selectNodes</code> evaluates the XPath expression on the given
* {@link Node}or {@link List}of {@link Node}s and returns the result as * {@link Node}or {@link List}of {@link Node}s and returns the result as
* a <code>List</code> of <code>Node</code> s sorted by the sort XPath * a <code>List</code> of <code>Node</code> s sorted by the sort XPath
* expression. * expression.
* </p>
* *
* @param context * @param context is either a node or a list of nodes on which to evalute the
* is either a node or a list of nodes on which to evalute the
* XPath * XPath
* @param sortXPath * @param sortXPath is the XPath expression to sort by
* is the XPath expression to sort by * @param distinct specifies whether or not duplicate values of the sort
* @param distinct
* specifies whether or not duplicate values of the sort
* expression are allowed. If this parameter is true then only * expression are allowed. If this parameter is true then only
* distinct sort expressions values are included in the result * distinct sort expressions values are included in the result
*
* @return a list of <code>Node</code> instances * @return a list of <code>Node</code> instances
*/ */
List selectNodes(Object context, XPath sortXPath, boolean distinct); List<Node> selectNodes(Object context, XPath sortXPath, boolean distinct);
/** /**
* <p>
* <code>selectSingleNode</code> evaluates this XPath expression on the * <code>selectSingleNode</code> evaluates this XPath expression on the
* given {@link Node}or {@link List}of {@link Node}s and returns the * given {@link Node}or {@link List}of {@link Node}s and returns the
* result as a single <code>Node</code> instance. * result as a single <code>Node</code> instance.
* </p>
* *
* @param context * @param context is either a node or a list of nodes on which to evalute the
* is either a node or a list of nodes on which to evalute the
* XPath * XPath
*
* @return a single matching <code>Node</code> instance * @return a single matching <code>Node</code> instance
*/ */
Node selectSingleNode(Object context); Node selectSingleNode(Object context);
/** /**
* <p>
* <code>valueOf</code> evaluates this XPath expression and returns the * <code>valueOf</code> evaluates this XPath expression and returns the
* textual representation of the results using the XPath string() function. * textual representation of the results using the XPath string() function.
* </p>
* *
* @param context * @param context is either a node or a list of nodes on which to evalute the
* is either a node or a list of nodes on which to evalute the
* XPath * XPath
*
* @return the string representation of the results of the XPath expression * @return the string representation of the results of the XPath expression
*/ */
String valueOf(Object context); String valueOf(Object context);
/** /**
* <p>
* <code>numberValueOf</code> evaluates an XPath expression and returns * <code>numberValueOf</code> evaluates an XPath expression and returns
* the numeric value of the XPath expression if the XPath expression results * the numeric value of the XPath expression if the XPath expression results
* is a number, or null if the result is not a number. * is a number, or null if the result is not a number.
* </p>
* *
* @param context * @param context is either a node or a list of nodes on which to evalute the
* is either a node or a list of nodes on which to evalute the
* XPath * XPath
*
* @return the numeric result of the XPath expression or null if the result * @return the numeric result of the XPath expression or null if the result
* is not a number. * is not a number.
*/ */
@ -191,49 +148,37 @@ public interface XPath extends NodeFilter {
* Retrieve a boolean-value interpretation of this XPath expression when * Retrieve a boolean-value interpretation of this XPath expression when
* evaluated against a given context. * evaluated against a given context.
* *
* <p>
* The boolean-value of the expression is determined per the * The boolean-value of the expression is determined per the
* <code>boolean(..)</code> core function as defined in the XPath * <code>boolean(..)</code> core function as defined in the XPath
* specification. This means that an expression that selects zero nodes will * specification. This means that an expression that selects zero nodes will
* return <code>false</code>, while an expression that selects * return <code>false</code>, while an expression that selects
* one-or-more nodes will return <code>true</code>. * one-or-more nodes will return <code>true</code>.
* </p>
* *
* @param context * @param context The node, nodeset or Context object for evaluation. This value
* The node, nodeset or Context object for evaluation. This value
* can be null * can be null
*
* @return The boolean-value interpretation of this expression. * @return The boolean-value interpretation of this expression.
*
* @since 1.5 * @since 1.5
*/ */
boolean booleanValueOf(Object context); boolean booleanValueOf(Object context);
/** /**
* <p>
* <code>sort</code> sorts the given List of Nodes using this XPath * <code>sort</code> sorts the given List of Nodes using this XPath
* expression as a {@link java.util.Comparator}. * expression as a {@link java.util.Comparator}.
* </p>
* *
* @param list * @param list is the list of Nodes to sort
* is the list of Nodes to sort
*/ */
void sort(List list); void sort(List<Node> list);
/** /**
* <p>
* <code>sort</code> sorts the given List of Nodes using this XPath * <code>sort</code> sorts the given List of Nodes using this XPath
* expression as a {@link java.util.Comparator}and optionally removing * expression as a {@link java.util.Comparator}and optionally removing
* duplicates. * duplicates.
* </p>
* *
* @param list * @param list is the list of Nodes to sort
* is the list of Nodes to sort * @param distinct if true then duplicate values (using the sortXPath for
* @param distinct
* if true then duplicate values (using the sortXPath for
* comparisions) will be removed from the List * comparisions) will be removed from the List
*/ */
void sort(List list, boolean distinct); void sort(List<Node> list, boolean distinct);
/** /**
* DOCUMENT ME! * DOCUMENT ME!
@ -245,8 +190,7 @@ public interface XPath extends NodeFilter {
/** /**
* Sets the function context to be used when evaluating XPath expressions * Sets the function context to be used when evaluating XPath expressions
* *
* @param functionContext * @param functionContext DOCUMENT ME!
* DOCUMENT ME!
*/ */
void setFunctionContext(FunctionContext functionContext); void setFunctionContext(FunctionContext functionContext);
@ -260,20 +204,15 @@ public interface XPath extends NodeFilter {
/** /**
* Sets the namespace context to be used when evaluating XPath expressions * Sets the namespace context to be used when evaluating XPath expressions
* *
* @param namespaceContext * @param namespaceContext DOCUMENT ME!
* DOCUMENT ME!
*/ */
void setNamespaceContext(NamespaceContext namespaceContext); void setNamespaceContext(NamespaceContext namespaceContext);
/** /**
* <p>
* Sets the current NamespaceContext from a Map where the keys are the * Sets the current NamespaceContext from a Map where the keys are the
* String namespace prefixes and the values are the namespace URIs. * String namespace prefixes and the values are the namespace URIs.
* </p>
* *
* <p>
* For example: * For example:
*
* <pre> * <pre>
* Map uris = new HashMap(); * Map uris = new HashMap();
* uris.put("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/"); * uris.put("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/");
@ -284,12 +223,9 @@ public interface XPath extends NodeFilter {
* Node babelfish = xpath.selectSingleNode(document); * Node babelfish = xpath.selectSingleNode(document);
* </pre> * </pre>
* *
* </p> * @param map the map containing the namespace mappings
*
* @param map
* the map containing the namespace mappings
*/ */
void setNamespaceURIs(Map map); void setNamespaceURIs(Map<String, String> map);
/** /**
* DOCUMENT ME! * DOCUMENT ME!
@ -301,8 +237,7 @@ public interface XPath extends NodeFilter {
/** /**
* Sets the variable context to be used when evaluating XPath expressions * Sets the variable context to be used when evaluating XPath expressions
* *
* @param variableContext * @param variableContext DOCUMENT ME!
* DOCUMENT ME!
*/ */
void setVariableContext(VariableContext variableContext); void setVariableContext(VariableContext variableContext);
} }

4
fine-org-dom4j/src/main/java/org/dom4j/XPathException.java

@ -8,13 +8,11 @@
package org.dom4j; package org.dom4j;
/** /**
* <p>
* <code>XPathException</code> is thrown when an exception occurs while * <code>XPathException</code> is thrown when an exception occurs while
* evaluating an XPath expression, usually due to some function throwing an * evaluating an XPath expression, usually due to some function throwing an
* exception. * exception.
* </p>
* *
* @version $Revision$ * @version $Revision: 1.6 $
*/ */
public class XPathException extends RuntimeException { public class XPathException extends RuntimeException {
/** The XPath expression that caused the exception */ /** The XPath expression that caused the exception */

2
fine-org-dom4j/src/main/java/org/dom4j/bean/BeanAttribute.java

@ -18,7 +18,7 @@ import org.dom4j.tree.AbstractAttribute;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.7 $
*/ */
public class BeanAttribute extends AbstractAttribute { public class BeanAttribute extends AbstractAttribute {
/** The list of Bean attributes */ /** The list of Bean attributes */

30
fine-org-dom4j/src/main/java/org/dom4j/bean/BeanAttributeList.java

@ -19,9 +19,9 @@ import org.dom4j.QName;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.9 $
*/ */
public class BeanAttributeList extends AbstractList { public class BeanAttributeList extends AbstractList<Attribute> {
/** The BeanElement that this */ /** The BeanElement that this */
private BeanElement parent; private BeanElement parent;
@ -41,18 +41,18 @@ public class BeanAttributeList extends AbstractList {
this.parent = parent; this.parent = parent;
Object data = parent.getData(); Object data = parent.getData();
Class beanClass = (data != null) ? data.getClass() : null; Class<?> beanClass = (data != null) ? data.getClass() : null;
this.beanMetaData = BeanMetaData.get(beanClass); this.beanMetaData = BeanMetaData.get(beanClass);
this.attributes = new BeanAttribute[beanMetaData.attributeCount()]; this.attributes = new BeanAttribute[beanMetaData.attributeCount()];
} }
public Attribute attribute(String name) { public BeanAttribute attribute(String name) {
int index = beanMetaData.getIndex(name); int index = beanMetaData.getIndex(name);
return attribute(index); return attribute(index);
} }
public Attribute attribute(QName qname) { public BeanAttribute attribute(QName qname) {
int index = beanMetaData.getIndex(qname); int index = beanMetaData.getIndex(qname);
return attribute(index); return attribute(index);
@ -91,11 +91,12 @@ public class BeanAttributeList extends AbstractList {
// List interface // List interface
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
@Override
public int size() { public int size() {
return attributes.length; return attributes.length;
} }
public Object get(int index) { public BeanAttribute get(int index) {
BeanAttribute attribute = attributes[index]; BeanAttribute attribute = attributes[index];
if (attribute == null) { if (attribute == null) {
@ -106,15 +107,15 @@ public class BeanAttributeList extends AbstractList {
return attribute; return attribute;
} }
public boolean add(Object object) { public boolean add(BeanAttribute object) {
throw new UnsupportedOperationException("add(Object) unsupported"); throw new UnsupportedOperationException("add(Object) unsupported");
} }
public void add(int index, Object object) { public void add(int index, BeanAttribute object) {
throw new UnsupportedOperationException("add(int,Object) unsupported"); throw new UnsupportedOperationException("add(int,Object) unsupported");
} }
public Object set(int index, Object object) { public BeanAttribute set(int index, BeanAttribute object) {
throw new UnsupportedOperationException("set(int,Object) unsupported"); throw new UnsupportedOperationException("set(int,Object) unsupported");
} }
@ -122,18 +123,15 @@ public class BeanAttributeList extends AbstractList {
return false; return false;
} }
public Object remove(int index) { public BeanAttribute remove(int index) {
BeanAttribute attribute = (BeanAttribute) get(index); BeanAttribute attribute = get(index);
Object oldValue = attribute.getValue();
attribute.setValue(null); attribute.setValue(null);
return oldValue; return attribute;
} }
public void clear() { public void clear() {
for (int i = 0, size = attributes.length; i < size; i++) { for (BeanAttribute attribute : attributes) {
BeanAttribute attribute = attributes[i];
if (attribute != null) { if (attribute != null) {
attribute.setValue(null); attribute.setValue(null);
} }

4
fine-org-dom4j/src/main/java/org/dom4j/bean/BeanDocumentFactory.java

@ -26,7 +26,7 @@ import org.xml.sax.Attributes;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.14 $
*/ */
public class BeanDocumentFactory extends DocumentFactory { public class BeanDocumentFactory extends DocumentFactory {
/** The Singleton instance */ /** The Singleton instance */
@ -78,7 +78,7 @@ public class BeanDocumentFactory extends DocumentFactory {
if (value != null) { if (value != null) {
try { try {
Class beanClass = Class.forName(value, true, Class<?> beanClass = Class.forName(value, true,
BeanDocumentFactory.class.getClassLoader()); BeanDocumentFactory.class.getClassLoader());
return beanClass.newInstance(); return beanClass.newInstance();

14
fine-org-dom4j/src/main/java/org/dom4j/bean/BeanElement.java

@ -25,7 +25,7 @@ import org.xml.sax.Attributes;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.15 $
*/ */
public class BeanElement extends DefaultElement { public class BeanElement extends DefaultElement {
/** The <code>DocumentFactory</code> instance used by default */ /** The <code>DocumentFactory</code> instance used by default */
@ -70,11 +70,11 @@ public class BeanElement extends DefaultElement {
setAttributeList(null); setAttributeList(null);
} }
public Attribute attribute(String name) { public BeanAttribute attribute(String name) {
return getBeanAttributeList().attribute(name); return getBeanAttributeList().attribute(name);
} }
public Attribute attribute(QName qname) { public BeanAttribute attribute(QName qname) {
return getBeanAttributeList().attribute(qname); return getBeanAttributeList().attribute(qname);
} }
@ -98,7 +98,7 @@ public class BeanElement extends DefaultElement {
return this; return this;
} }
public void setAttributes(List attributes) { public void setAttributes(List<Attribute> attributes) {
throw new UnsupportedOperationException("Not implemented yet."); throw new UnsupportedOperationException("Not implemented yet.");
} }
@ -109,7 +109,7 @@ public class BeanElement extends DefaultElement {
if (className != null) { if (className != null) {
try { try {
Class beanClass = Class.forName(className, true, Class<?> beanClass = Class.forName(className, true,
BeanElement.class.getClassLoader()); BeanElement.class.getClassLoader());
this.setData(beanClass.newInstance()); this.setData(beanClass.newInstance());
@ -147,11 +147,11 @@ public class BeanElement extends DefaultElement {
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
protected List createAttributeList() { protected List<Attribute> createAttributeList() {
return new BeanAttributeList(this); return new BeanAttributeList(this);
} }
protected List createAttributeList(int size) { protected List<Attribute> createAttributeList(int size) {
return new BeanAttributeList(this); return new BeanAttributeList(this);
} }
} }

31
fine-org-dom4j/src/main/java/org/dom4j/bean/BeanMetaData.java

@ -24,20 +24,20 @@ import org.dom4j.QName;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.10 $
*/ */
public class BeanMetaData { public class BeanMetaData {
/** Empty arguments for reflection calls */ /** Empty arguments for reflection calls */
protected static final Object[] NULL_ARGS = {}; protected static final Object[] NULL_ARGS = {};
/** Singleton cache */ /** Singleton cache */
private static Map singletonCache = new HashMap(); private static Map<Class<?>, BeanMetaData> singletonCache = new HashMap<Class<?>, BeanMetaData>();
private static final DocumentFactory DOCUMENT_FACTORY = BeanDocumentFactory private static final DocumentFactory DOCUMENT_FACTORY = BeanDocumentFactory
.getInstance(); .getInstance();
/** The class of the bean */ /** The class of the bean */
private Class beanClass; private Class<?> beanClass;
/** Property descriptors for the bean */ /** Property descriptors for the bean */
private PropertyDescriptor[] propertyDescriptors; private PropertyDescriptor[] propertyDescriptors;
@ -51,10 +51,12 @@ public class BeanMetaData {
/** Write methods used for setting properties */ /** Write methods used for setting properties */
private Method[] writeMethods; private Method[] writeMethods;
/** Index of names and QNames to indices */ /** Index of names and QNames to indices
private Map nameMap = new HashMap(); * Keys are type of QName and String
*/
private Map<Object, Integer> nameMap = new HashMap<Object, Integer>();
public BeanMetaData(Class beanClass) { public BeanMetaData(Class<?> beanClass) {
this.beanClass = beanClass; this.beanClass = beanClass;
if (beanClass != null) { if (beanClass != null) {
@ -83,9 +85,8 @@ public class BeanMetaData {
readMethods[i] = propertyDescriptor.getReadMethod(); readMethods[i] = propertyDescriptor.getReadMethod();
writeMethods[i] = propertyDescriptor.getWriteMethod(); writeMethods[i] = propertyDescriptor.getWriteMethod();
Integer index = new Integer(i); nameMap.put(name, i);
nameMap.put(name, index); nameMap.put(qName, i);
nameMap.put(qName, index);
} }
} }
@ -97,8 +98,8 @@ public class BeanMetaData {
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
public static BeanMetaData get(Class beanClass) { public static BeanMetaData get(Class<?> beanClass) {
BeanMetaData answer = (BeanMetaData) singletonCache.get(beanClass); BeanMetaData answer = singletonCache.get(beanClass);
if (answer == null) { if (answer == null) {
answer = new BeanMetaData(beanClass); answer = new BeanMetaData(beanClass);
@ -126,15 +127,15 @@ public class BeanMetaData {
} }
public int getIndex(String name) { public int getIndex(String name) {
Integer index = (Integer) nameMap.get(name); Integer index = nameMap.get(name);
return (index != null) ? index.intValue() : (-1); return (index != null) ? index : (-1);
} }
public int getIndex(QName qName) { public int getIndex(QName qName) {
Integer index = (Integer) nameMap.get(qName); Integer index = nameMap.get(qName);
return (index != null) ? index.intValue() : (-1); return (index != null) ? index : (-1);
} }
public Object getData(int index, Object bean) { public Object getData(int index, Object bean) {

10
fine-org-dom4j/src/main/java/org/dom4j/bean/package.html

@ -1,10 +0,0 @@
<html>
<head>
</head>
<body>
<p>An implementation of the <i>dom4j</i> API which allows JavaBeans to be used to
store and retrieve attribute values from Element.</p>
</body>
</html>

2
fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeAttribute.java

@ -27,7 +27,7 @@ import org.relaxng.datatype.ValidationContext;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.9 $
*/ */
public class DatatypeAttribute extends AbstractAttribute implements public class DatatypeAttribute extends AbstractAttribute implements
SerializationContext, ValidationContext { SerializationContext, ValidationContext {

2
fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeDocumentFactory.java

@ -26,7 +26,7 @@ import org.xml.sax.InputSource;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.9 $
*/ */
public class DatatypeDocumentFactory extends DocumentFactory { public class DatatypeDocumentFactory extends DocumentFactory {
// XXXX: I don't think interning of QNames is necessary // XXXX: I don't think interning of QNames is necessary

2
fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeElement.java

@ -28,7 +28,7 @@ import org.relaxng.datatype.ValidationContext;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.9 $
*/ */
public class DatatypeElement extends DefaultElement implements public class DatatypeElement extends DefaultElement implements
SerializationContext, ValidationContext { SerializationContext, ValidationContext {

10
fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeElementFactory.java

@ -25,7 +25,7 @@ import org.dom4j.QName;
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @author Yuxin Ruan * @author Yuxin Ruan
* @version $Revision$ * @version $Revision: 1.9 $
*/ */
public class DatatypeElementFactory extends DocumentFactory { public class DatatypeElementFactory extends DocumentFactory {
private QName elementQName; private QName elementQName;
@ -34,13 +34,13 @@ public class DatatypeElementFactory extends DocumentFactory {
* Cache of <code>XSDatatype</code> instances per Attribute * Cache of <code>XSDatatype</code> instances per Attribute
* <code>QName</code> * <code>QName</code>
*/ */
private Map attributeXSDatatypes = new HashMap(); private Map<QName, XSDatatype> attributeXSDatatypes = new HashMap<QName, XSDatatype>();
/** /**
* Cache of <code>XSDatatype</code> instances per child Element * Cache of <code>XSDatatype</code> instances per child Element
* <code>QName</code> * <code>QName</code>
*/ */
private Map childrenXSDatatypes = new HashMap(); private Map<QName, XSDatatype> childrenXSDatatypes = new HashMap<QName, XSDatatype>();
public DatatypeElementFactory(QName elementQName) { public DatatypeElementFactory(QName elementQName) {
this.elementQName = elementQName; this.elementQName = elementQName;
@ -65,7 +65,7 @@ public class DatatypeElementFactory extends DocumentFactory {
* QName * QName
*/ */
public XSDatatype getAttributeXSDatatype(QName attributeQName) { public XSDatatype getAttributeXSDatatype(QName attributeQName) {
return (XSDatatype) attributeXSDatatypes.get(attributeQName); return attributeXSDatatypes.get(attributeQName);
} }
/** /**
@ -91,7 +91,7 @@ public class DatatypeElementFactory extends DocumentFactory {
* Element QName * Element QName
*/ */
public XSDatatype getChildElementXSDatatype(QName qname) { public XSDatatype getChildElementXSDatatype(QName qname) {
return (XSDatatype) childrenXSDatatypes.get(qname); return childrenXSDatatypes.get(qname);
} }
public void setChildElementXSDatatype(QName qname, XSDatatype dataType) { public void setChildElementXSDatatype(QName qname, XSDatatype dataType) {

2
fine-org-dom4j/src/main/java/org/dom4j/datatype/InvalidSchemaException.java

@ -13,7 +13,7 @@ package org.dom4j.datatype;
* document is used * document is used
* </p> * </p>
* *
* @version $Revision$ * @version $Revision: 1.6 $
*/ */
public class InvalidSchemaException extends IllegalArgumentException { public class InvalidSchemaException extends IllegalArgumentException {
public InvalidSchemaException(String reason) { public InvalidSchemaException(String reason) {

15
fine-org-dom4j/src/main/java/org/dom4j/datatype/NamedTypeResolver.java

@ -23,16 +23,16 @@ import org.dom4j.QName;
* </p> * </p>
* *
* @author Yuxin Ruan * @author Yuxin Ruan
* @version $Revision$ * @version $Revision: 1.8 $
*/ */
class NamedTypeResolver { class NamedTypeResolver {
protected Map complexTypeMap = new HashMap(); protected Map<QName, DocumentFactory> complexTypeMap = new HashMap<QName, DocumentFactory>();
protected Map simpleTypeMap = new HashMap(); protected Map<QName, XSDatatype> simpleTypeMap = new HashMap<QName, XSDatatype>();
protected Map typedElementMap = new HashMap(); protected Map<Element, QName> typedElementMap = new HashMap<Element, QName>();
protected Map elementFactoryMap = new HashMap(); protected Map<Element, DocumentFactory> elementFactoryMap = new HashMap<Element, DocumentFactory>();
protected DocumentFactory documentFactory; protected DocumentFactory documentFactory;
@ -55,10 +55,7 @@ class NamedTypeResolver {
} }
void resolveElementTypes() { void resolveElementTypes() {
Iterator iterator = typedElementMap.keySet().iterator(); for (Element element : typedElementMap.keySet()) {
while (iterator.hasNext()) {
Element element = (Element) iterator.next();
QName elementQName = getQNameOfSchemaElement(element); QName elementQName = getQNameOfSchemaElement(element);
QName type = (QName) typedElementMap.get(element); QName type = (QName) typedElementMap.get(element);

67
fine-org-dom4j/src/main/java/org/dom4j/datatype/SchemaParser.java

@ -37,7 +37,7 @@ import org.xml.sax.InputSource;
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @author Yuxin Ruan * @author Yuxin Ruan
* @version $Revision$ * @version $Revision: 1.19 $
*/ */
public class SchemaParser { public class SchemaParser {
private static final Namespace XSD_NAMESPACE = Namespace.get("xsd", private static final Namespace XSD_NAMESPACE = Namespace.get("xsd",
@ -76,7 +76,7 @@ public class SchemaParser {
* Cache of <code>XSDatatype</code> instances loaded or created during * Cache of <code>XSDatatype</code> instances loaded or created during
* this build * this build
*/ */
private Map dataTypeCache = new HashMap(); private Map<String, XSDatatype> dataTypeCache = new HashMap<String, XSDatatype>();
/** NamedTypeResolver */ /** NamedTypeResolver */
private NamedTypeResolver namedTypeResolver; private NamedTypeResolver namedTypeResolver;
@ -113,11 +113,7 @@ public class SchemaParser {
Element root = schemaDocument.getRootElement(); Element root = schemaDocument.getRootElement();
if (root != null) { if (root != null) {
// handle schema includes for (Element includeElement : root.elements(XSD_INCLUDE)) {
Iterator includeIter = root.elementIterator(XSD_INCLUDE);
while (includeIter.hasNext()) {
Element includeElement = (Element) includeIter.next();
String inclSchemaInstanceURI = includeElement String inclSchemaInstanceURI = includeElement
.attributeValue("schemaLocation"); .attributeValue("schemaLocation");
EntityResolver resolver = schemaDocument.getEntityResolver(); EntityResolver resolver = schemaDocument.getEntityResolver();
@ -151,24 +147,18 @@ public class SchemaParser {
} }
// handle elements // handle elements
Iterator iter = root.elementIterator(XSD_ELEMENT); for (Element element : root.elements(XSD_ELEMENT)) {
onDatatypeElement(element, documentFactory);
while (iter.hasNext()) {
onDatatypeElement((Element) iter.next(), documentFactory);
} }
// handle named simple types // handle named simple types
iter = root.elementIterator(XSD_SIMPLETYPE); for (Element element : root.elements(XSD_SIMPLETYPE)) {
onNamedSchemaSimpleType(element);
while (iter.hasNext()) {
onNamedSchemaSimpleType((Element) iter.next());
} }
// hanlde named complex types // hanlde named complex types
iter = root.elementIterator(XSD_COMPLEXTYPE); for (Element element : root.elements(XSD_COMPLEXTYPE)) {
onNamedSchemaComplexType(element);
while (iter.hasNext()) {
onNamedSchemaComplexType((Element) iter.next());
} }
namedTypeResolver.resolveNamedTypes(); namedTypeResolver.resolveNamedTypes();
@ -190,15 +180,19 @@ public class SchemaParser {
DocumentFactory parentFactory) { DocumentFactory parentFactory) {
String name = xsdElement.attributeValue("name"); String name = xsdElement.attributeValue("name");
String type = xsdElement.attributeValue("type"); String type = xsdElement.attributeValue("type");
QName qname = getQName(name);
DatatypeElementFactory factory = getDatatypeElementFactory(qname); QName qname = null;
DatatypeElementFactory factory = null;
if (name != null) {
qname = getQName(name);
factory = getDatatypeElementFactory(qname);
}
if (type != null) { if (type != null) {
// register type with this element name // register type with this element name
XSDatatype dataType = getTypeByName(type); XSDatatype dataType = getTypeByName(type);
if (dataType != null) { if (dataType != null && factory != null) {
factory.setChildElementXSDatatype(qname, dataType); factory.setChildElementXSDatatype(qname, dataType);
} else { } else {
QName typeQName = getQName(type); QName typeQName = getQName(type);
@ -215,26 +209,27 @@ public class SchemaParser {
if (xsdSimpleType != null) { if (xsdSimpleType != null) {
XSDatatype dataType = loadXSDatatypeFromSimpleType(xsdSimpleType); XSDatatype dataType = loadXSDatatypeFromSimpleType(xsdSimpleType);
if (dataType != null) { if (dataType != null && factory != null) {
factory.setChildElementXSDatatype(qname, dataType); factory.setChildElementXSDatatype(qname, dataType);
} }
} }
Element schemaComplexType = xsdElement.element(XSD_COMPLEXTYPE); Element schemaComplexType = xsdElement.element(XSD_COMPLEXTYPE);
if (schemaComplexType != null) { if (schemaComplexType != null && factory != null) {
onSchemaComplexType(schemaComplexType, factory); onSchemaComplexType(schemaComplexType, factory);
} }
Iterator iter = xsdElement.elementIterator(XSD_ATTRIBUTE); if (factory != null) {
Iterator<Element> iter = xsdElement.elementIterator(XSD_ATTRIBUTE);
if (iter.hasNext()) { if (iter.hasNext()) {
do { do {
onDatatypeAttribute(xsdElement, factory, (Element) iter onDatatypeAttribute(xsdElement, factory, iter
.next()); .next());
} while (iter.hasNext()); } while (iter.hasNext());
} }
} }
}
/** /**
* processes an named XML Schema &lt;complexTypegt; tag * processes an named XML Schema &lt;complexTypegt; tag
@ -268,10 +263,10 @@ public class SchemaParser {
*/ */
private void onSchemaComplexType(Element schemaComplexType, private void onSchemaComplexType(Element schemaComplexType,
DatatypeElementFactory elementFactory) { DatatypeElementFactory elementFactory) {
Iterator iter = schemaComplexType.elementIterator(XSD_ATTRIBUTE); Iterator<Element> iter = schemaComplexType.elementIterator(XSD_ATTRIBUTE);
while (iter.hasNext()) { while (iter.hasNext()) {
Element xsdAttribute = (Element) iter.next(); Element xsdAttribute = iter.next();
String name = xsdAttribute.attributeValue("name"); String name = xsdAttribute.attributeValue("name");
QName qname = getQName(name); QName qname = getQName(name);
@ -308,10 +303,10 @@ public class SchemaParser {
} }
private void onChildElements(Element element, DatatypeElementFactory fact) { private void onChildElements(Element element, DatatypeElementFactory fact) {
Iterator iter = element.elementIterator(XSD_ELEMENT); Iterator<Element> iter = element.elementIterator(XSD_ELEMENT);
while (iter.hasNext()) { while (iter.hasNext()) {
Element xsdElement = (Element) iter.next(); Element xsdElement = iter.next();
onDatatypeElement(xsdElement, fact); onDatatypeElement(xsdElement, fact);
} }
} }
@ -355,7 +350,7 @@ public class SchemaParser {
*/ */
private XSDatatype dataTypeForXsdAttribute(Element xsdAttribute) { private XSDatatype dataTypeForXsdAttribute(Element xsdAttribute) {
String type = xsdAttribute.attributeValue("type"); String type = xsdAttribute.attributeValue("type");
XSDatatype dataType = null; XSDatatype dataType;
if (type != null) { if (type != null) {
dataType = getTypeByName(type); dataType = getTypeByName(type);
@ -459,9 +454,9 @@ public class SchemaParser {
ValidationContext context = null; ValidationContext context = null;
try { try {
for (Iterator iter = xsdRestriction.elementIterator(); iter for (Iterator<Element> iter = xsdRestriction.elementIterator(); iter
.hasNext();) { .hasNext();) {
Element element = (Element) iter.next(); Element element = iter.next();
String name = element.getName(); String name = element.getName();
String value = element.attributeValue("value"); String value = element.attributeValue("value");
boolean fixed = AttributeHelper.booleanValue(element, "fixed"); boolean fixed = AttributeHelper.booleanValue(element, "fixed");
@ -504,7 +499,7 @@ public class SchemaParser {
} }
private XSDatatype getTypeByName(String type) { private XSDatatype getTypeByName(String type) {
XSDatatype dataType = (XSDatatype) dataTypeCache.get(type); XSDatatype dataType = dataTypeCache.get(type);
if (dataType == null) { if (dataType == null) {
// first check to see if it is a built-in type // first check to see if it is a built-in type
@ -530,7 +525,7 @@ public class SchemaParser {
if (dataType == null) { if (dataType == null) {
// it's no built-in type, maybe it's a type we defined ourself // it's no built-in type, maybe it's a type we defined ourself
QName typeQName = getQName(type); QName typeQName = getQName(type);
dataType = (XSDatatype) namedTypeResolver.simpleTypeMap dataType = namedTypeResolver.simpleTypeMap
.get(typeQName); .get(typeQName);
} }

10
fine-org-dom4j/src/main/java/org/dom4j/datatype/package.html

@ -1,10 +0,0 @@
<html>
<head>
</head>
<body>
<p>An implementation of the <i>dom4j</i> API which supports the
<a href="http://www.w3.org/TR/xmlschema-2/">XML Schema Data Types</a> specification.</p>
</body>
</html>

10
fine-org-dom4j/src/main/java/org/dom4j/dom/DOMAttribute.java

@ -10,13 +10,7 @@ package org.dom4j.dom;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.QName; import org.dom4j.QName;
import org.dom4j.tree.DefaultAttribute; import org.dom4j.tree.DefaultAttribute;
import org.w3c.dom.DOMException; import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.TypeInfo;
import org.w3c.dom.UserDataHandler;
/** /**
* <p> * <p>
@ -25,7 +19,7 @@ import org.w3c.dom.UserDataHandler;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.14 $
*/ */
public class DOMAttribute extends DefaultAttribute implements org.w3c.dom.Attr { public class DOMAttribute extends DefaultAttribute implements org.w3c.dom.Attr {
public DOMAttribute(QName qname) { public DOMAttribute(QName qname) {

2
fine-org-dom4j/src/main/java/org/dom4j/dom/DOMAttributeNodeMap.java

@ -18,7 +18,7 @@ import org.w3c.dom.Node;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.8 $
*/ */
public class DOMAttributeNodeMap implements org.w3c.dom.NamedNodeMap { public class DOMAttributeNodeMap implements org.w3c.dom.NamedNodeMap {
private DOMElement element; private DOMElement element;

10
fine-org-dom4j/src/main/java/org/dom4j/dom/DOMCDATA.java

@ -10,13 +10,7 @@ package org.dom4j.dom;
import org.dom4j.CDATA; import org.dom4j.CDATA;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.tree.DefaultCDATA; import org.dom4j.tree.DefaultCDATA;
import org.w3c.dom.DOMException; import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.w3c.dom.UserDataHandler;
/** /**
* <p> * <p>
@ -25,7 +19,7 @@ import org.w3c.dom.UserDataHandler;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.12 $
*/ */
public class DOMCDATA extends DefaultCDATA implements org.w3c.dom.CDATASection { public class DOMCDATA extends DefaultCDATA implements org.w3c.dom.CDATASection {
public DOMCDATA(String text) { public DOMCDATA(String text) {

9
fine-org-dom4j/src/main/java/org/dom4j/dom/DOMComment.java

@ -9,12 +9,7 @@ package org.dom4j.dom;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.tree.DefaultComment; import org.dom4j.tree.DefaultComment;
import org.w3c.dom.DOMException; import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.UserDataHandler;
/** /**
* <p> * <p>
@ -22,7 +17,7 @@ import org.w3c.dom.UserDataHandler;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.12 $
*/ */
public class DOMComment extends DefaultComment implements org.w3c.dom.Comment { public class DOMComment extends DefaultComment implements org.w3c.dom.Comment {
public DOMComment(String text) { public DOMComment(String text) {

18
fine-org-dom4j/src/main/java/org/dom4j/dom/DOMDocument.java

@ -7,20 +7,16 @@
package org.dom4j.dom; package org.dom4j.dom;
import org.dom4j.DocumentFactory; import org.dom4j.*;
import org.dom4j.QName;
import org.dom4j.tree.DefaultDocument; import org.dom4j.tree.DefaultDocument;
import org.w3c.dom.Attr; import org.w3c.dom.*;
import org.w3c.dom.CDATASection; import org.w3c.dom.Comment;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.EntityReference; import org.w3c.dom.DocumentType;
import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.ProcessingInstruction; import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.UserDataHandler; import org.w3c.dom.Text;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,7 +27,7 @@ import java.util.ArrayList;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.17 $
*/ */
public class DOMDocument extends DefaultDocument implements Document { public class DOMDocument extends DefaultDocument implements Document {
/** The <code>DocumentFactory</code> instance used by default */ /** The <code>DocumentFactory</code> instance used by default */

30
fine-org-dom4j/src/main/java/org/dom4j/dom/DOMDocumentFactory.java

@ -7,18 +7,7 @@
package org.dom4j.dom; package org.dom4j.dom;
import org.dom4j.Attribute; import org.dom4j.*;
import org.dom4j.CDATA;
import org.dom4j.Comment;
import org.dom4j.Document;
import org.dom4j.DocumentFactory;
import org.dom4j.DocumentType;
import org.dom4j.Element;
import org.dom4j.Entity;
import org.dom4j.Namespace;
import org.dom4j.ProcessingInstruction;
import org.dom4j.QName;
import org.dom4j.Text;
import org.dom4j.util.SingletonStrategy; import org.dom4j.util.SingletonStrategy;
import org.w3c.dom.DOMException; import org.w3c.dom.DOMException;
@ -31,32 +20,32 @@ import java.util.Map;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.21 $
*/ */
public class DOMDocumentFactory extends DocumentFactory implements public class DOMDocumentFactory extends DocumentFactory implements
org.w3c.dom.DOMImplementation { org.w3c.dom.DOMImplementation {
/** The Singleton instance */ /** The Singleton instance */
private static SingletonStrategy singleton = null; private static SingletonStrategy<DOMDocumentFactory> singleton = null;
static { static {
try { try {
String defaultSingletonClass = "org.dom4j.util.SimpleSingleton"; String defaultSingletonClass = "org.dom4j.util.SimpleSingleton";
Class clazz = null; Class<SingletonStrategy> clazz = null;
try { try {
String singletonClass = defaultSingletonClass; String singletonClass = defaultSingletonClass;
singletonClass = System.getProperty( singletonClass = System.getProperty(
"org.dom4j.dom.DOMDocumentFactory.singleton.strategy", "org.dom4j.dom.DOMDocumentFactory.singleton.strategy",
singletonClass); singletonClass);
clazz = Class.forName(singletonClass); clazz = (Class<SingletonStrategy>) Class.forName(singletonClass);
} catch (Exception exc1) { } catch (Exception exc1) {
try { try {
String singletonClass = defaultSingletonClass; String singletonClass = defaultSingletonClass;
clazz = Class.forName(singletonClass); clazz = (Class<SingletonStrategy>) Class.forName(singletonClass);
} catch (Exception exc2) { } catch (Exception exc2) {
} }
} }
singleton = (SingletonStrategy) clazz.newInstance(); singleton = clazz.newInstance();
singleton.setSingletonClassName(DOMDocumentFactory.class.getName()); singleton.setSingletonClassName(DOMDocumentFactory.class.getName());
} catch (Exception exc3) { } catch (Exception exc3) {
} }
@ -70,8 +59,7 @@ public class DOMDocumentFactory extends DocumentFactory implements
* @return the default singleon instance * @return the default singleon instance
*/ */
public static DocumentFactory getInstance() { public static DocumentFactory getInstance() {
DOMDocumentFactory fact = (DOMDocumentFactory) singleton.instance(); return singleton.instance();
return fact;
} }
// Factory methods // Factory methods
@ -129,7 +117,7 @@ public class DOMDocumentFactory extends DocumentFactory implements
} }
public ProcessingInstruction createProcessingInstruction(String target, public ProcessingInstruction createProcessingInstruction(String target,
Map data) { Map<String, String> data) {
return new DOMProcessingInstruction(target, data); return new DOMProcessingInstruction(target, data);
} }

9
fine-org-dom4j/src/main/java/org/dom4j/dom/DOMDocumentType.java

@ -8,12 +8,7 @@
package org.dom4j.dom; package org.dom4j.dom;
import org.dom4j.tree.DefaultDocumentType; import org.dom4j.tree.DefaultDocumentType;
import org.w3c.dom.DOMException; import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.UserDataHandler;
/** /**
* <p> * <p>
@ -22,7 +17,7 @@ import org.w3c.dom.UserDataHandler;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.11 $
*/ */
public class DOMDocumentType extends DefaultDocumentType implements public class DOMDocumentType extends DefaultDocumentType implements
org.w3c.dom.DocumentType { org.w3c.dom.DocumentType {

15
fine-org-dom4j/src/main/java/org/dom4j/dom/DOMElement.java

@ -7,19 +7,12 @@
package org.dom4j.dom; package org.dom4j.dom;
import org.dom4j.Attribute; import org.dom4j.*;
import org.dom4j.DocumentFactory;
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.tree.DefaultElement; import org.dom4j.tree.DefaultElement;
import org.w3c.dom.Attr; import org.w3c.dom.*;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.TypeInfo;
import org.w3c.dom.UserDataHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -31,7 +24,7 @@ import java.util.List;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.23 $
*/ */
public class DOMElement extends DefaultElement implements org.w3c.dom.Element { public class DOMElement extends DefaultElement implements org.w3c.dom.Element {
/** The <code>DocumentFactory</code> instance used by default */ /** The <code>DocumentFactory</code> instance used by default */

9
fine-org-dom4j/src/main/java/org/dom4j/dom/DOMEntityReference.java

@ -9,12 +9,7 @@ package org.dom4j.dom;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.tree.DefaultEntity; import org.dom4j.tree.DefaultEntity;
import org.w3c.dom.DOMException; import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.UserDataHandler;
/** /**
* <p> * <p>
@ -23,7 +18,7 @@ import org.w3c.dom.UserDataHandler;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.12 $
*/ */
public class DOMEntityReference extends DefaultEntity implements public class DOMEntityReference extends DefaultEntity implements
org.w3c.dom.EntityReference { org.w3c.dom.EntityReference {

9
fine-org-dom4j/src/main/java/org/dom4j/dom/DOMNamespace.java

@ -9,12 +9,7 @@ package org.dom4j.dom;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.tree.DefaultNamespace; import org.dom4j.tree.DefaultNamespace;
import org.w3c.dom.DOMException; import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.UserDataHandler;
/** /**
* <p> * <p>
@ -23,7 +18,7 @@ import org.w3c.dom.UserDataHandler;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.10 $
*/ */
public class DOMNamespace extends DefaultNamespace implements org.w3c.dom.Node { public class DOMNamespace extends DefaultNamespace implements org.w3c.dom.Node {
public DOMNamespace(String prefix, String uri) { public DOMNamespace(String prefix, String uri) {

35
fine-org-dom4j/src/main/java/org/dom4j/dom/DOMNodeHelper.java

@ -7,12 +7,7 @@
package org.dom4j.dom; package org.dom4j.dom;
import org.dom4j.Branch; import org.dom4j.*;
import org.dom4j.CharacterData;
import org.dom4j.Document;
import org.dom4j.DocumentType;
import org.dom4j.Element;
import org.dom4j.Node;
import org.w3c.dom.DOMException; import org.w3c.dom.DOMException;
import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
@ -26,7 +21,7 @@ import java.util.List;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.20 $
*/ */
public class DOMNodeHelper { public class DOMNodeHelper {
public static final NodeList EMPTY_NODE_LIST = new EmptyNodeList(); public static final NodeList EMPTY_NODE_LIST = new EmptyNodeList();
@ -127,14 +122,15 @@ public class DOMNodeHelper {
org.w3c.dom.Node newChild, org.w3c.dom.Node refChild) org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
throws DOMException { throws DOMException {
if (node instanceof Branch) { if (node instanceof Branch) {
assert newChild instanceof Node;
Branch branch = (Branch) node; Branch branch = (Branch) node;
List list = branch.content(); List<Node> list = branch.content();
int index = list.indexOf(refChild); int index = list.indexOf(refChild);
if (index < 0) { if (index < 0) {
branch.add((Node) newChild); branch.add((Node) newChild);
} else { } else {
list.add(index, newChild); list.add(index, (Node) newChild);
} }
return newChild; return newChild;
@ -149,7 +145,8 @@ public class DOMNodeHelper {
throws DOMException { throws DOMException {
if (node instanceof Branch) { if (node instanceof Branch) {
Branch branch = (Branch) node; Branch branch = (Branch) node;
List list = branch.content(); List<Node> list = branch.content();
assert newChild instanceof Node;
int index = list.indexOf(oldChild); int index = list.indexOf(oldChild);
if (index < 0) { if (index < 0) {
@ -158,7 +155,7 @@ public class DOMNodeHelper {
+ node); + node);
} }
list.set(index, newChild); list.set(index, (Node) newChild);
return oldChild; return oldChild;
} else { } else {
@ -271,7 +268,7 @@ public class DOMNodeHelper {
String text = charData.getText(); String text = charData.getText();
if (text == null) { if (text == null) {
charData.setText(text); charData.setText(arg);
} else { } else {
charData.setText(text + arg); charData.setText(text + arg);
} }
@ -295,7 +292,7 @@ public class DOMNodeHelper {
throw new DOMException(DOMException.INDEX_SIZE_ERR, throw new DOMException(DOMException.INDEX_SIZE_ERR,
"No text at offset: " + offset); "No text at offset: " + offset);
} else { } else {
StringBuffer buffer = new StringBuffer(text); StringBuilder buffer = new StringBuilder(text);
buffer.insert(offset, arg); buffer.insert(offset, arg);
data.setText(buffer.toString()); data.setText(buffer.toString());
} }
@ -323,7 +320,7 @@ public class DOMNodeHelper {
throw new DOMException(DOMException.INDEX_SIZE_ERR, throw new DOMException(DOMException.INDEX_SIZE_ERR,
"No text at offset: " + offset); "No text at offset: " + offset);
} else { } else {
StringBuffer buffer = new StringBuffer(text); StringBuilder buffer = new StringBuilder(text);
buffer.delete(offset, offset + count); buffer.delete(offset, offset + count);
charData.setText(buffer.toString()); charData.setText(buffer.toString());
} }
@ -351,7 +348,7 @@ public class DOMNodeHelper {
throw new DOMException(DOMException.INDEX_SIZE_ERR, throw new DOMException(DOMException.INDEX_SIZE_ERR,
"No text at offset: " + offset); "No text at offset: " + offset);
} else { } else {
StringBuffer buffer = new StringBuffer(text); StringBuilder buffer = new StringBuilder(text);
buffer.replace(offset, offset + count, arg); buffer.replace(offset, offset + count, arg);
charData.setText(buffer.toString()); charData.setText(buffer.toString());
} }
@ -361,7 +358,7 @@ public class DOMNodeHelper {
// Branch API // Branch API
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
public static void appendElementsByTagName(List list, Branch parent, public static void appendElementsByTagName(List<? super Element> list, Branch parent,
String name) { String name) {
final boolean isStar = "*".equals(name); final boolean isStar = "*".equals(name);
@ -380,7 +377,7 @@ public class DOMNodeHelper {
} }
} }
public static void appendElementsByTagNameNS(List list, Branch parent, public static void appendElementsByTagNameNS(List<? super Element> list, Branch parent,
String namespace, String localName) { String namespace, String localName) {
final boolean isStarNS = "*".equals(namespace); final boolean isStarNS = "*".equals(namespace);
final boolean isStar = "*".equals(localName); final boolean isStar = "*".equals(localName);
@ -409,7 +406,7 @@ public class DOMNodeHelper {
// Helper methods // Helper methods
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
public static NodeList createNodeList(final List list) { public static NodeList createNodeList(final List<Node> list) {
return new NodeList() { return new NodeList() {
public org.w3c.dom.Node item(int index) { public org.w3c.dom.Node item(int index) {
if (index >= getLength()) { if (index >= getLength()) {
@ -420,7 +417,7 @@ public class DOMNodeHelper {
*/ */
return null; return null;
} else { } else {
return DOMNodeHelper.asDOMNode((Node) list.get(index)); return DOMNodeHelper.asDOMNode(list.get(index));
} }
} }

11
fine-org-dom4j/src/main/java/org/dom4j/dom/DOMProcessingInstruction.java

@ -9,12 +9,7 @@ package org.dom4j.dom;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.tree.DefaultProcessingInstruction; import org.dom4j.tree.DefaultProcessingInstruction;
import org.w3c.dom.DOMException; import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.UserDataHandler;
import java.util.Map; import java.util.Map;
@ -25,11 +20,11 @@ import java.util.Map;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.12 $
*/ */
public class DOMProcessingInstruction extends DefaultProcessingInstruction public class DOMProcessingInstruction extends DefaultProcessingInstruction
implements org.w3c.dom.ProcessingInstruction { implements org.w3c.dom.ProcessingInstruction {
public DOMProcessingInstruction(String target, Map values) { public DOMProcessingInstruction(String target, Map<String, String> values) {
super(target, values); super(target, values);
} }

9
fine-org-dom4j/src/main/java/org/dom4j/dom/DOMText.java

@ -10,12 +10,7 @@ package org.dom4j.dom;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.Text; import org.dom4j.Text;
import org.dom4j.tree.DefaultText; import org.dom4j.tree.DefaultText;
import org.w3c.dom.DOMException; import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.UserDataHandler;
/** /**
* <p> * <p>
@ -23,7 +18,7 @@ import org.w3c.dom.UserDataHandler;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.12 $
*/ */
public class DOMText extends DefaultText implements org.w3c.dom.Text { public class DOMText extends DefaultText implements org.w3c.dom.Text {
public DOMText(String text) { public DOMText(String text) {

10
fine-org-dom4j/src/main/java/org/dom4j/dom/package.html

@ -1,10 +0,0 @@
<html>
<head>
</head>
<body>
<p>An implementation of the <i>dom4j</i> API which also supports the
W3C object model.</p>
</body>
</html>

4
fine-org-dom4j/src/main/java/org/dom4j/dtd/AttributeDecl.java

@ -13,9 +13,9 @@ package org.dom4j.dtd;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.7 $
*/ */
public class AttributeDecl { public class AttributeDecl implements Decl {
/** Holds value of property elementName. */ /** Holds value of property elementName. */
private String elementName; private String elementName;

4
fine-org-dom4j/src/main/java/org/dom4j/dtd/ElementDecl.java

@ -13,9 +13,9 @@ package org.dom4j.dtd;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.6 $
*/ */
public class ElementDecl { public class ElementDecl implements Decl {
/** Holds value of property name. */ /** Holds value of property name. */
private String name; private String name;

4
fine-org-dom4j/src/main/java/org/dom4j/dtd/ExternalEntityDecl.java

@ -14,9 +14,9 @@ package org.dom4j.dtd;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.9 $
*/ */
public class ExternalEntityDecl { public class ExternalEntityDecl implements Decl {
/** Holds value of property name. */ /** Holds value of property name. */
private String name; private String name;

4
fine-org-dom4j/src/main/java/org/dom4j/dtd/InternalEntityDecl.java

@ -14,9 +14,9 @@ package org.dom4j.dtd;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.9 $
*/ */
public class InternalEntityDecl { public class InternalEntityDecl implements Decl {
/** Holds value of property name. */ /** Holds value of property name. */
private String name; private String name;

9
fine-org-dom4j/src/main/java/org/dom4j/dtd/package.html

@ -1,9 +0,0 @@
<html>
<head>
</head>
<body>
<p>Classes to represent the DTD declarations. They are used inside the {@link org.dom4j.DocumentType} interface.</p>
</body>
</html>

13
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.ArrayList;
import java.util.List; import java.util.List;
import org.dom4j.Branch; import org.dom4j.*;
import org.dom4j.Document; import org.dom4j.dom.DOMAttribute;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.tree.NamespaceStack; import org.dom4j.tree.NamespaceStack;
/** /**
@ -25,7 +21,7 @@ import org.dom4j.tree.NamespaceStack;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.17 $
*/ */
public class DOMReader { public class DOMReader {
/** <code>DocumentFactory</code> used to create new document objects */ /** <code>DocumentFactory</code> used to create new document objects */
@ -201,11 +197,10 @@ public class DOMReader {
if (attributeList != null) { if (attributeList != null) {
int size = attributeList.getLength(); int size = attributeList.getLength();
List attributes = new ArrayList(size); List<org.w3c.dom.Node> attributes = new ArrayList<org.w3c.dom.Node>(size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
org.w3c.dom.Node attribute = attributeList.item(i); org.w3c.dom.Node attribute = attributeList.item(i);
// Define all namespaces first then process attributes later // Define all namespaces first then process attributes later
String name = attribute.getNodeName(); String name = attribute.getNodeName();

72
fine-org-dom4j/src/main/java/org/dom4j/io/DOMWriter.java

@ -9,28 +9,18 @@ package org.dom4j.io;
import java.util.List; import java.util.List;
import org.dom4j.Attribute; import org.dom4j.*;
import org.dom4j.CDATA; import org.dom4j.dtd.Decl;
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.tree.NamespaceStack; import org.dom4j.tree.NamespaceStack;
import org.w3c.dom.DOMImplementation; import org.w3c.dom.DOMImplementation;
/** /**
* <p>
* <code>DOMWriter</code> takes a DOM4J tree and outputs it as a W3C DOM * <code>DOMWriter</code> takes a DOM4J tree and outputs it as a W3C DOM
* object * object
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.17 $
*/ */
public class DOMWriter { public class DOMWriter {
private static boolean loggedWarning = false; private static boolean loggedWarning = false;
@ -46,7 +36,7 @@ public class DOMWriter {
}; };
// the Class used to create new DOM Document instances // the Class used to create new DOM Document instances
private Class domDocumentClass; private Class<?> domDocumentClass;
/** stack of <code>Namespace</code> objects */ /** stack of <code>Namespace</code> objects */
private NamespaceStack namespaceStack = new NamespaceStack(); private NamespaceStack namespaceStack = new NamespaceStack();
@ -54,20 +44,19 @@ public class DOMWriter {
public DOMWriter() { public DOMWriter() {
} }
public DOMWriter(Class domDocumentClass) { public DOMWriter(Class<?> domDocumentClass) {
this.domDocumentClass = domDocumentClass; this.domDocumentClass = domDocumentClass;
} }
public Class getDomDocumentClass() throws DocumentException { public Class<?> getDomDocumentClass() throws DocumentException {
Class result = domDocumentClass; Class<?> result = domDocumentClass;
if (result == null) { if (result == null) {
// lets try and find one in the classpath // lets try and find one in the classpath
int size = DEFAULT_DOM_DOCUMENT_CLASSES.length; int size = DEFAULT_DOM_DOCUMENT_CLASSES.length;
for (int i = 0; i < size; i++) { for (String name : DEFAULT_DOM_DOCUMENT_CLASSES) {
try { try {
String name = DEFAULT_DOM_DOCUMENT_CLASSES[i];
result = Class.forName(name, true, DOMWriter.class result = Class.forName(name, true, DOMWriter.class
.getClassLoader()); .getClassLoader());
@ -89,10 +78,10 @@ public class DOMWriter {
* the writer when creating DOM documents. * the writer when creating DOM documents.
* *
* @param domDocumentClass * @param domDocumentClass
* is the Class implementing the {@linkorg.w3c.dom.Document} * is the Class implementing the {@link org.w3c.dom.Document}
* interface * interface
*/ */
public void setDomDocumentClass(Class domDocumentClass) { public void setDomDocumentClass(Class<?> domDocumentClass) {
this.domDocumentClass = domDocumentClass; this.domDocumentClass = domDocumentClass;
} }
@ -148,28 +137,22 @@ public class DOMWriter {
} }
protected void appendDOMTree(org.w3c.dom.Document domDocument, protected void appendDOMTree(org.w3c.dom.Document domDocument,
org.w3c.dom.Node domCurrent, List content) { org.w3c.dom.Node domCurrent, List<Node> content) {
int size = content.size(); for (Node node : content) {
if (node instanceof Element) {
for (int i = 0; i < size; i++) { appendDOMTree(domDocument, domCurrent, (Element) node);
Object object = content.get(i); } else if (node instanceof Text) {
Text text = (Text) node;
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;
appendDOMTree(domDocument, domCurrent, text.getText()); appendDOMTree(domDocument, domCurrent, text.getText());
} else if (object instanceof CDATA) { } else if (node instanceof CDATA) {
appendDOMTree(domDocument, domCurrent, (CDATA) object); appendDOMTree(domDocument, domCurrent, (CDATA) node);
} else if (object instanceof Comment) { } else if (node instanceof Comment) {
appendDOMTree(domDocument, domCurrent, (Comment) object); appendDOMTree(domDocument, domCurrent, (Comment) node);
} else if (object instanceof Entity) { } else if (node instanceof Entity) {
appendDOMTree(domDocument, domCurrent, (Entity) object); appendDOMTree(domDocument, domCurrent, (Entity) node);
} else if (object instanceof ProcessingInstruction) { } else if (node instanceof ProcessingInstruction) {
appendDOMTree(domDocument, domCurrent, appendDOMTree(domDocument, domCurrent,
(ProcessingInstruction) object); (ProcessingInstruction) node);
} }
} }
} }
@ -192,7 +175,7 @@ public class DOMWriter {
} }
// add the additional declared namespaces // add the additional declared namespaces
List declaredNamespaces = element.declaredNamespaces(); List<Namespace> declaredNamespaces = element.declaredNamespaces();
for (int i = 0, size = declaredNamespaces.size(); i < size; i++) { for (int i = 0, size = declaredNamespaces.size(); i < size; i++) {
Namespace namespace = (Namespace) declaredNamespaces.get(i); Namespace namespace = (Namespace) declaredNamespaces.get(i);
@ -204,8 +187,7 @@ public class DOMWriter {
} }
// add the attributes // add the attributes
for (int i = 0, size = element.attributeCount(); i < size; i++) { for (Attribute attribute : element.attributes()) {
Attribute attribute = (Attribute) element.attribute(i);
String attUri = attribute.getNamespaceURI(); String attUri = attribute.getNamespaceURI();
String attName = attribute.getQualifiedName(); String attName = attribute.getQualifiedName();
String value = attribute.getValue(); String value = attribute.getValue();
@ -294,7 +276,7 @@ public class DOMWriter {
result = createDomDocumentViaJAXP(); result = createDomDocumentViaJAXP();
if (result == null) { if (result == null) {
Class theClass = getDomDocumentClass(); Class<?> theClass = getDomDocumentClass();
try { try {
result = (org.w3c.dom.Document) theClass.newInstance(); result = (org.w3c.dom.Document) theClass.newInstance();

24
fine-org-dom4j/src/main/java/org/dom4j/io/DispatchHandler.java

@ -27,7 +27,7 @@ import org.dom4j.ElementPath;
* </p> * </p>
* *
* @author <a href="mailto:dwhite@equipecom.com">Dave White </a> * @author <a href="mailto:dwhite@equipecom.com">Dave White </a>
* @version $Revision$ * @version $Revision: 1.11 $
*/ */
class DispatchHandler implements ElementHandler { class DispatchHandler implements ElementHandler {
/** Whether the parser is at the root element or not */ /** Whether the parser is at the root element or not */
@ -37,16 +37,16 @@ class DispatchHandler implements ElementHandler {
private String path; private String path;
/** maintains a stack of previously encountered paths */ /** maintains a stack of previously encountered paths */
private ArrayList pathStack; private ArrayList<String> pathStack;
/** maintains a stack of previously encountered handlers */ /** maintains a stack of previously encountered handlers */
private ArrayList handlerStack; private ArrayList<ElementHandler> handlerStack;
/** /**
* <code>HashMap</code> maintains the mapping between element paths and * <code>HashMap</code> maintains the mapping between element paths and
* handlers * handlers
*/ */
private HashMap handlers; private HashMap<String, ElementHandler> handlers;
/** /**
* <code>ElementHandler</code> to use by default for element paths with no * <code>ElementHandler</code> to use by default for element paths with no
@ -57,9 +57,9 @@ class DispatchHandler implements ElementHandler {
public DispatchHandler() { public DispatchHandler() {
atRoot = true; atRoot = true;
path = "/"; path = "/";
pathStack = new ArrayList(); pathStack = new ArrayList<String>();
handlerStack = new ArrayList(); handlerStack = new ArrayList<ElementHandler>();
handlers = new HashMap(); handlers = new HashMap<String, ElementHandler>();
} }
/** /**
@ -86,7 +86,7 @@ class DispatchHandler implements ElementHandler {
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
public ElementHandler removeHandler(String handlerPath) { 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 * @return the registered handler
*/ */
public ElementHandler getHandler(String handlerPath) { 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))) { if ((handlers != null) && (handlers.containsKey(path))) {
// The current node has a handler associated with it. // The current node has a handler associated with it.
// Find the handler and save it on the handler stack. // Find the handler and save it on the handler stack.
ElementHandler handler = (ElementHandler) handlers.get(path); ElementHandler handler = handlers.get(path);
handlerStack.add(handler); handlerStack.add(handler);
// Call the handlers onStart method. // Call the handlers onStart method.
@ -195,7 +195,7 @@ class DispatchHandler implements ElementHandler {
if ((handlers != null) && (handlers.containsKey(path))) { if ((handlers != null) && (handlers.containsKey(path))) {
// This node has a handler associated with it. // This node has a handler associated with it.
// Find the handler and pop it from the handler stack. // 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); handlerStack.remove(handlerStack.size() - 1);
// Call the handlers onEnd method // Call the handlers onEnd method
@ -209,7 +209,7 @@ class DispatchHandler implements ElementHandler {
} }
// Set path back to its parent // Set path back to its parent
path = (String) pathStack.remove(pathStack.size() - 1); path = pathStack.remove(pathStack.size() - 1);
if (pathStack.size() == 0) { if (pathStack.size() == 0) {
atRoot = true; atRoot = true;

2
fine-org-dom4j/src/main/java/org/dom4j/io/DocumentInputSource.java

@ -23,7 +23,7 @@ import org.xml.sax.InputSource;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.8 $
*/ */
class DocumentInputSource extends InputSource { class DocumentInputSource extends InputSource {
/** The document source */ /** The document source */

2
fine-org-dom4j/src/main/java/org/dom4j/io/DocumentResult.java

@ -21,7 +21,7 @@ import org.xml.sax.ext.LexicalHandler;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.8 $
*/ */
public class DocumentResult extends SAXResult { public class DocumentResult extends SAXResult {
private SAXContentHandler contentHandler; private SAXContentHandler contentHandler;

8
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; import org.xml.sax.XMLReader;
/** /**
* <p>
* <code>DocumentSource</code> implements a JAXP {@link SAXSource}for a * <code>DocumentSource</code> implements a JAXP {@link SAXSource}for a
* {@linkDocument}. * {@link Document}.
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.10 $
*/ */
public class DocumentSource extends SAXSource { 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. * instance.
* *
* @param inputSource * @param inputSource

2
fine-org-dom4j/src/main/java/org/dom4j/io/ElementStack.java

@ -20,7 +20,7 @@ import org.dom4j.ElementPath;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.14 $
*/ */
class ElementStack implements ElementPath { class ElementStack implements ElementPath {
/** stack of <code>Element</code> objects */ /** stack of <code>Element</code> objects */

154
fine-org-dom4j/src/main/java/org/dom4j/io/HTMLWriter.java

@ -26,25 +26,21 @@ import org.dom4j.Node;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
* <p>
* <code>HTMLWriter</code> takes a DOM4J tree and formats it to a stream as * <code>HTMLWriter</code> 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 * 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 * and Entity sections rather than the serialised format as in XML, it has an
* XHTML mode, it retains whitespace in certain elements such as &lt;PRE&gt;, * XHTML mode, it retains whitespace in certain elements such as &lt;PRE&gt;,
* and it supports certain elements which have no corresponding close tag such * and it supports certain elements which have no corresponding close tag such
* as for &lt;BR&gt; and &lt;P&gt;. * as for &lt;BR&gt; and &lt;P&gt;.
* </p>
* *
* <p>
* The OutputFormat passed in to the constructor is checked for isXHTML() and * The OutputFormat passed in to the constructor is checked for isXHTML() and
* isExpandEmptyElements(). See {@link OutputFormat OutputFormat}for details. * isExpandEmptyElements(). See {@link OutputFormat OutputFormat}for details.
* Here are the rules for <b>this class </b> based on an OutputFormat, "format", * Here are the rules for <b>this class </b> based on an OutputFormat, "format",
* passed in to the constructor: <br/><br/> * passed in to the constructor:
* *
* <ul> * <ul>
* <li>If an element is in {@link #getOmitElementCloseSet() * <li>If an element is in {@link #getOmitElementCloseSet()
* getOmitElementCloseSet}, then it is treated specially: * getOmitElementCloseSet}, then it is treated specially:
*
* <ul> * <ul>
* <li>It never expands, since some browsers treat this as two separate * <li>It never expands, since some browsers treat this as two separate
* Horizontal Rules: &lt;HR&gt;&lt;/HR&gt;</li> * Horizontal Rules: &lt;HR&gt;&lt;/HR&gt;</li>
@ -54,7 +50,6 @@ import org.xml.sax.SAXException;
* "/", but that's better than when it refuses to recognize this: &lt;hr/&gt; * "/", but that's better than when it refuses to recognize this: &lt;hr/&gt;
* which it thinks is an element named "HR/".</li> * which it thinks is an element named "HR/".</li>
* </ul> * </ul>
*
* </li> * </li>
* <li>If {@link org.dom4j.io.OutputFormat#isXHTML() format.isXHTML()}, all * <li>If {@link org.dom4j.io.OutputFormat#isXHTML() format.isXHTML()}, all
* elements must have either a close element, or be a closed single tag.</li> * elements must have either a close element, or be a closed single tag.</li>
@ -62,41 +57,21 @@ import org.xml.sax.SAXException;
* format.isExpandEmptyElements()}() is true, all elements are expanded except * format.isExpandEmptyElements()}() is true, all elements are expanded except
* as above.</li> * as above.</li>
* </ul> * </ul>
*
* <b>Examples </b> * <b>Examples </b>
* </p>
*
* <p>
* </p>
*
* <p>
* If isXHTML == true, CDATA sections look like this: * If isXHTML == true, CDATA sections look like this:
* * <pre>
* <PRE>
*
* <b>&lt;myelement&gt;&lt;![CDATA[My data]]&gt;&lt;/myelement&gt; </b> * <b>&lt;myelement&gt;&lt;![CDATA[My data]]&gt;&lt;/myelement&gt; </b>
* * </pre>
* </PRE>
*
* Otherwise, they look like this: * Otherwise, they look like this:
* * <pre>
* <PRE>
*
* <b>&lt;myelement&gt;My data&lt;/myelement&gt; </b> * <b>&lt;myelement&gt;My data&lt;/myelement&gt; </b>
* * </pre>
* </PRE>
* * Basically, {@link OutputFormat#isXHTML()} ==
* </p>
*
* <p>
* Basically, {@link OutputFormat.isXHTML() OutputFormat.isXHTML()} ==
* <code>true</code> will produce valid XML, while {@link * <code>true</code> will produce valid XML, while {@link
* org.dom4j.io.OutputFormat#isExpandEmptyElements() * OutputFormat#isExpandEmptyElements()} determines whether empty elements are
* format.isExpandEmptyElements()} determines whether empty elements are
* expanded if isXHTML is true, excepting the special HTML single tags. * expanded if isXHTML is true, excepting the special HTML single tags.
* </p>
* *
* <p>
* Also, HTMLWriter handles tags whose contents should be preformatted, that is, * Also, HTMLWriter handles tags whose contents should be preformatted, that is,
* whitespace-preserved. By default, this set includes the tags &lt;PRE&gt;, * whitespace-preserved. By default, this set includes the tags &lt;PRE&gt;,
* &lt;SCRIPT&gt;, &lt;STYLE&gt;, and &lt;TEXTAREA&gt;, case insensitively. It * &lt;SCRIPT&gt;, &lt;STYLE&gt;, and &lt;TEXTAREA&gt;, case insensitively. It
@ -107,28 +82,14 @@ import org.xml.sax.SAXException;
* However, the parser you use may store comments with linefeed-only text nodes * However, the parser you use may store comments with linefeed-only text nodes
* (\n) even if your platform uses another line.separator character, and * (\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. * HTMLWriter outputs Comment nodes exactly as the DOM is set up by the parser.
* See examples and discussion here: {@link#setPreformattedTags(java.util.Set) * See examples and discussion here: {@link #setPreformattedTags(java.util.Set)}
* setPreformattedTags}
* </p>
* *
* <p>
* <b>Examples </b> * <b>Examples </b>
* </p>
* <blockquote>
* <p>
* <b>Pretty Printing </b> * <b>Pretty Printing </b>
* </p>
*
* <p>
* This example shows how to pretty print a string containing a valid HTML * 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 * document to a string. You can also just call the static methods of this
* class: <br> * class: {@link #prettyPrintHTML(String)}or {@link #prettyPrintHTML(String,boolean,boolean,boolean,boolean)}
* {@link #prettyPrintHTML(String) prettyPrintHTML(String)}or <br> * or {@link #prettyPrintXHTML(String)} for XHTML (note the X)
* {@link #prettyPrintHTML(String,boolean,boolean,boolean,boolean)
* prettyPrintHTML(String,boolean,boolean,boolean,boolean)} or, <br>
* {@link #prettyPrintXHTML(String) prettyPrintXHTML(String)}for XHTML (note
* the X)
* </p>
* *
* <pre> * <pre>
* String testPrettyPrint(String html) { * String testPrettyPrint(String html) {
@ -147,12 +108,10 @@ import org.xml.sax.SAXException;
* } * }
* </pre> * </pre>
* *
* <p>
* This example shows how to create a "squeezed" document, but one that will * 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 * 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 * included, no extra whitespace at all, except where it it required by
* {@link #setPreformattedTags(java.util.Set) setPreformattedTags}. * {@link #setPreformattedTags(java.util.Set) setPreformattedTags}.
* </p>
* *
* <pre> * <pre>
* String testCrunch(String html) { * String testCrunch(String html) {
@ -172,21 +131,19 @@ import org.xml.sax.SAXException;
* } * }
* </pre> * </pre>
* *
* </blockquote>
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @author Laramie Crocker * @author Laramie Crocker
* @version $Revision$ * @version $Revision: 1.21 $
*/ */
public class HTMLWriter extends XMLWriter { public class HTMLWriter extends XMLWriter {
private static String lineSeparator = System.getProperty("line.separator"); private static String lineSeparator = System.getProperty("line.separator");
protected static final HashSet DEFAULT_PREFORMATTED_TAGS; protected static final HashSet<String> DEFAULT_PREFORMATTED_TAGS;
static { static {
// If you change this list, update the javadoc examples, above in the // If you change this list, update the javadoc examples, above in the
// class javadoc, in writeElement, and in setPreformattedTags(). // class javadoc, in writeElement, and in setPreformattedTags().
DEFAULT_PREFORMATTED_TAGS = new HashSet(); DEFAULT_PREFORMATTED_TAGS = new HashSet<String>();
DEFAULT_PREFORMATTED_TAGS.add("PRE"); DEFAULT_PREFORMATTED_TAGS.add("PRE");
DEFAULT_PREFORMATTED_TAGS.add("SCRIPT"); DEFAULT_PREFORMATTED_TAGS.add("SCRIPT");
DEFAULT_PREFORMATTED_TAGS.add("STYLE"); DEFAULT_PREFORMATTED_TAGS.add("STYLE");
@ -201,7 +158,7 @@ public class HTMLWriter extends XMLWriter {
DEFAULT_HTML_FORMAT.setSuppressDeclaration(true); DEFAULT_HTML_FORMAT.setSuppressDeclaration(true);
} }
private Stack formatStack = new Stack(); private Stack<FormatState> formatStack = new Stack<FormatState>();
private String lastText = ""; private String lastText = "";
@ -210,13 +167,13 @@ public class HTMLWriter extends XMLWriter {
// legal values are 0+, but -1 signifies lazy initialization. // legal values are 0+, but -1 signifies lazy initialization.
private int newLineAfterNTags = -1; private int newLineAfterNTags = -1;
private HashSet preformattedTags = DEFAULT_PREFORMATTED_TAGS; private HashSet<String> preformattedTags = DEFAULT_PREFORMATTED_TAGS;
/** /**
* Used to store the qualified element names which should have no close * Used to store the qualified element names which should have no close
* element tag * element tag
*/ */
private HashSet omitElementCloseSet; private HashSet<String> omitElementCloseSet;
public HTMLWriter(Writer writer) { public HTMLWriter(Writer writer) {
super(writer, DEFAULT_HTML_FORMAT); super(writer, DEFAULT_HTML_FORMAT);
@ -349,9 +306,9 @@ public class HTMLWriter extends XMLWriter {
qualifiedName.toUpperCase()); qualifiedName.toUpperCase());
} }
private HashSet internalGetOmitElementCloseSet() { private HashSet<String> internalGetOmitElementCloseSet() {
if (omitElementCloseSet == null) { if (omitElementCloseSet == null) {
omitElementCloseSet = new HashSet(); omitElementCloseSet = new HashSet<String>();
loadOmitElementCloseSet(omitElementCloseSet); loadOmitElementCloseSet(omitElementCloseSet);
} }
@ -359,7 +316,7 @@ public class HTMLWriter extends XMLWriter {
} }
// If you change this, change the javadoc for getOmitElementCloseSet. // If you change this, change the javadoc for getOmitElementCloseSet.
protected void loadOmitElementCloseSet(Set set) { protected void loadOmitElementCloseSet(Set<String> set) {
set.add("AREA"); set.add("AREA");
set.add("BASE"); set.add("BASE");
set.add("BR"); set.add("BR");
@ -382,8 +339,8 @@ public class HTMLWriter extends XMLWriter {
* *
* @return A clone of the Set. * @return A clone of the Set.
*/ */
public Set getOmitElementCloseSet() { public Set<String> getOmitElementCloseSet() {
return (Set) (internalGetOmitElementCloseSet().clone()); return (Set<String>) (internalGetOmitElementCloseSet().clone());
} }
/** /**
@ -402,21 +359,17 @@ public class HTMLWriter extends XMLWriter {
* @param newSet * @param newSet
* DOCUMENT ME! * DOCUMENT ME!
*/ */
public void setOmitElementCloseSet(Set newSet) { public void setOmitElementCloseSet(Set<String> newSet) {
// resets, and safely empties it out if newSet is null. // resets, and safely empties it out if newSet is null.
omitElementCloseSet = new HashSet(); omitElementCloseSet = new HashSet<String>();
if (newSet != null) { if (newSet != null) {
omitElementCloseSet = new HashSet(); omitElementCloseSet = new HashSet<String>();
Object aTag; for (String aTag : newSet) {
Iterator iter = newSet.iterator();
while (iter.hasNext()) {
aTag = iter.next();
if (aTag != null) { 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 * @see #setPreformattedTags(java.util.Set) setPreformattedTags
*
* @return DOCUMENT ME!
*/ */
public Set getPreformattedTags() { public Set<String> getPreformattedTags() {
return (Set) (preformattedTags.clone()); return (Set<String>) (preformattedTags.clone());
} }
/** /**
* <p>
* Override the default set, which includes PRE, SCRIPT, STYLE, and * Override the default set, which includes PRE, SCRIPT, STYLE, and
* TEXTAREA, case insensitively. * TEXTAREA, case insensitively.
* </p>
* *
* <p>
* <b>Setting Preformatted Tags </b> * <b>Setting Preformatted Tags </b>
* </p>
*
* <p>
* Pass in a Set of Strings, one for each tag name that should be treated * 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 * 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 * 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. * 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, * 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. * but it preserves the intention of the whitespace within the tag.
* </p>
* *
* <p>
* The browser considers leading whitespace before the close tag to be * The browser considers leading whitespace before the close tag to be
* significant, but leading whitespace before the open 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 * 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 * 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 * flushed left close PRE tag as different from a close tag with leading
* whitespace. Again, this must be left up to the HTML author. * whitespace. Again, this must be left up to the HTML author.
* </p>
* *
* <p>
* <b>Examples </b> * <b>Examples </b>
* </p>
* <blockquote>
* <p>
* Here is an example of how you can set the PreformattedTags list using * 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 * setPreformattedTags to include IFRAME, as well as the default set, if you
* have an instance of this class named myHTMLWriter: * have an instance of this class named myHTMLWriter:
@ -520,28 +462,20 @@ public class HTMLWriter extends XMLWriter {
* *
* </pre> * </pre>
* *
* </p>
* </blockquote>
*
* @param newSet * @param newSet
* DOCUMENT ME! * DOCUMENT ME!
*/ */
public void setPreformattedTags(Set newSet) { public void setPreformattedTags(Set<String> newSet) {
// no fancy merging, just set it, assuming they did a // no fancy merging, just set it, assuming they did a
// getExcludeTrimTags() first if they wanted to preserve the default // getExcludeTrimTags() first if they wanted to preserve the default
// set. // set.
// resets, and safely empties it out if newSet is null. // resets, and safely empties it out if newSet is null.
preformattedTags = new HashSet(); preformattedTags = new HashSet<String>();
if (newSet != null) { if (newSet != null) {
Object aTag; for (String aTag : newSet) {
Iterator iter = newSet.iterator();
while (iter.hasNext()) {
aTag = iter.next();
if (aTag != null) { 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 * close tags off of the default omitElementCloseSet set. Use one of
* the write methods if you want stream output. * the write methods if you want stream output.
* *
* @throws java.io.IOException * @throws java.io.IOException DOCUMENT ME!
* @throws java.io.UnsupportedEncodingException * @throws java.io.UnsupportedEncodingException DOCUMENT ME!
* @throws org.dom4j.DocumentException * @throws org.dom4j.DocumentException DOCUMENT ME!
*/ */
public static String prettyPrintHTML(String html) public static String prettyPrintHTML(String html)
throws java.io.IOException, java.io.UnsupportedEncodingException, throws java.io.IOException, java.io.UnsupportedEncodingException,
@ -709,9 +643,9 @@ public class HTMLWriter extends XMLWriter {
* converted to XHTML empty tags: &lt;HR/&gt; Use one of the write * converted to XHTML empty tags: &lt;HR/&gt; Use one of the write
* methods if you want stream output. * methods if you want stream output.
* *
* @throws java.io.IOException * @throws java.io.IOException DOCUMENT ME!
* @throws java.io.UnsupportedEncodingException * @throws java.io.UnsupportedEncodingException DOCUMENT ME!
* @throws org.dom4j.DocumentException * @throws org.dom4j.DocumentException DOCUMENT ME!
*/ */
public static String prettyPrintXHTML(String html) public static String prettyPrintXHTML(String html)
throws java.io.IOException, java.io.UnsupportedEncodingException, 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 * override allows you to specify various formatter options. Use one
* of the write methods if you want stream output. * of the write methods if you want stream output.
* *
* @throws java.io.IOException * @throws java.io.IOException DOCUMENT ME!
* @throws java.io.UnsupportedEncodingException * @throws java.io.UnsupportedEncodingException DOCUMENT ME!
* @throws org.dom4j.DocumentException * @throws org.dom4j.DocumentException DOCUMENT ME!
*/ */
public static String prettyPrintHTML(String html, boolean newlines, public static String prettyPrintHTML(String html, boolean newlines,
boolean trim, boolean isXHTML, boolean expandEmpty) boolean trim, boolean isXHTML, boolean expandEmpty)

2
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 * such that dom4j can work without JAXP on the CLASSPATH
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.7 $
*/ */
class JAXPHelper { class JAXPHelper {
protected JAXPHelper() { protected JAXPHelper() {

36
fine-org-dom4j/src/main/java/org/dom4j/io/OutputFormat.java

@ -8,13 +8,11 @@
package org.dom4j.io; package org.dom4j.io;
/** /**
* <p>
* <code>OutputFormat</code> represents the format configuration used by * <code>OutputFormat</code> 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
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.17 $
*/ */
public class OutputFormat implements Cloneable { public class OutputFormat implements Cloneable {
/** standard value to indent by, if we are indenting */ /** standard value to indent by, if we are indenting */
@ -279,21 +277,14 @@ public class OutputFormat implements Cloneable {
} }
/** /**
* <p>
* This will set whether the text is output verbatim (false) or with * This will set whether the text is output verbatim (false) or with
* whitespace stripped as per <code>{@link * whitespace stripped as per <code>{@link
* org.dom4j.Element#getTextTrim()}</code>. * org.dom4j.Element#getTextTrim()}</code>.
* </p>
*
* <p>
* </p>
* *
* <p>
* Default: false * Default: false
* </p>
* *
* @param trimText * @param trimText
* <code>boolean</code> true=>trim the whitespace, false=>use * <code>boolean</code> true trim the whitespace, false use
* text verbatim * text verbatim
*/ */
public void setTrimText(boolean trimText) { public void setTrimText(boolean trimText) {
@ -305,7 +296,6 @@ public class OutputFormat implements Cloneable {
} }
/** /**
* <p>
* Ensure that text immediately preceded by or followed by an element will * Ensure that text immediately preceded by or followed by an element will
* be "padded" with a single space. This is used to allow make * be "padded" with a single space. This is used to allow make
* browser-friendly HTML, avoiding trimText's transformation of, e.g., * browser-friendly HTML, avoiding trimText's transformation of, e.g.,
@ -314,16 +304,11 @@ public class OutputFormat implements Cloneable {
* (the latter will run the three separate words together into a single * (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 * word). This setting is not too useful if you haven't also called
* {@link #setTrimText}. * {@link #setTrimText}.
* </p>
* *
* <p>
* The padding string will only be added if the text itself starts or ends * The padding string will only be added if the text itself starts or ends
* with some whitespace characters. * with some whitespace characters.
* </p>
* *
* <p>
* Default: false * Default: false
* </p>
* *
* @param padText * @param padText
* <code>boolean</code> if true, pad string-element boundaries * <code>boolean</code> if true, pad string-element boundaries
@ -337,11 +322,10 @@ public class OutputFormat implements Cloneable {
} }
/** /**
* <p>
* This will set the indent <code>String</code> to use; this is usually a * This will set the indent <code>String</code> to use; this is usually a
* <code>String</code> of empty spaces. If you pass null, or the empty * <code>String</code> of empty spaces. If you pass null, or the empty
* string (""), then no indentation will happen. * string (""), then no indentation will happen.
* </p> *
* Default: none (null) * Default: none (null)
* *
* @param indent * @param indent
@ -372,11 +356,9 @@ public class OutputFormat implements Cloneable {
} }
/** /**
* <p>
* This will set the indent <code>String</code>'s size; an indentSize of * This will set the indent <code>String</code>'s size; an indentSize of
* 4 would result in the indention being equivalent to the * 4 would result in the indention being equivalent to the
* <code>String</code> "&nbsp;&nbsp;&nbsp;&nbsp;" (four space characters). * <code>String</code> "&nbsp;&nbsp;&nbsp;&nbsp;" (four space characters).
* </p>
* *
* @param indentSize * @param indentSize
* <code>int</code> number of spaces in indentation. * <code>int</code> number of spaces in indentation.
@ -392,17 +374,13 @@ public class OutputFormat implements Cloneable {
} }
/** /**
* <p>
* Whether or not to use the XHTML standard: like HTML but passes an XML * 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 * parser with real, closed tags. Also, XHTML CDATA sections will be output
* with the CDATA delimiters: ( &quot; <b>&lt;![CDATA[ </b>&quot; and &quot; * with the CDATA delimiters: ( &quot; <b>&lt;![CDATA[ </b>&quot; and &quot;
* <b>]]&gt; </b>&quot; ) otherwise, the class HTMLWriter will output the * <b>]]&gt; </b>&quot; ) otherwise, the class HTMLWriter will output the
* CDATA text, but not the delimiters. * CDATA text, but not the delimiters.
* </p>
* *
* <p>
* Default is <code>false</code> * Default is <code>false</code>
* </p>
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
@ -411,20 +389,16 @@ public class OutputFormat implements Cloneable {
} }
/** /**
* <p>
* This will set whether or not to use the XHTML standard: like HTML but * 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 * passes an XML parser with real, closed tags. Also, XHTML CDATA sections
* will be output with the CDATA delimiters: ( &quot; <b>&lt;[CDATA[ * will be output with the CDATA delimiters: ( &quot; <b>&lt;[CDATA[
* </b>&quot; and &quot; <b>]]&lt; </b>) otherwise, the class HTMLWriter * </b>&quot; and &quot; <b>]]&lt; </b>) otherwise, the class HTMLWriter
* will output the CDATA text, but not the delimiters. * will output the CDATA text, but not the delimiters.
* </p>
* *
* <p>
* Default: false * Default: false
* </p>
* *
* @param xhtml * @param xhtml
* <code>boolean</code> true=>conform to XHTML, false=>conform * <code>boolean</code> true conform to XHTML, false conform
* to HTML, can have unclosed tags, etc. * to HTML, can have unclosed tags, etc.
*/ */
public void setXHTML(boolean xhtml) { public void setXHTML(boolean xhtml) {

2
fine-org-dom4j/src/main/java/org/dom4j/io/PruningElementStack.java

@ -20,7 +20,7 @@ import org.dom4j.ElementHandler;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.11 $
*/ */
class PruningElementStack extends ElementStack { class PruningElementStack extends ElementStack {
/** ElementHandler to call when pruning occurs */ /** ElementHandler to call when pruning occurs */

39
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.ElementHandler;
import org.dom4j.Namespace; import org.dom4j.Namespace;
import org.dom4j.QName; import org.dom4j.QName;
import org.dom4j.dtd.AttributeDecl; import org.dom4j.dtd.*;
import org.dom4j.dtd.ElementDecl;
import org.dom4j.dtd.ExternalEntityDecl;
import org.dom4j.dtd.InternalEntityDecl;
import org.dom4j.tree.AbstractElement; import org.dom4j.tree.AbstractElement;
import org.dom4j.tree.NamespaceStack; import org.dom4j.tree.NamespaceStack;
@ -37,6 +34,7 @@ import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException; import org.xml.sax.SAXParseException;
import org.xml.sax.ext.DeclHandler; import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ext.LexicalHandler; import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.ext.Locator2;
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
/** /**
@ -45,7 +43,7 @@ import org.xml.sax.helpers.DefaultHandler;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.61 $
*/ */
public class SAXContentHandler extends DefaultHandler implements public class SAXContentHandler extends DefaultHandler implements
LexicalHandler, DeclHandler, DTDHandler { LexicalHandler, DeclHandler, DTDHandler {
@ -82,17 +80,11 @@ public class SAXContentHandler extends DefaultHandler implements
*/ */
private StringBuffer cdataText; 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 */ /** internal DTD declarations */
private List internalDTDDeclarations; private List<Decl> internalDTDDeclarations;
/** external DTD declarations */ /** external DTD declarations */
private List externalDTDDeclarations; private List<Decl> externalDTDDeclarations;
/** The number of namespaces that are declared in the current scope */ /** The number of namespaces that are declared in the current scope */
private int declaredNamespaceIndex; private int declaredNamespaceIndex;
@ -844,17 +836,8 @@ public class SAXContentHandler extends DefaultHandler implements
return null; return null;
} }
// use reflection to avoid dependency on Locator2 if (locator instanceof Locator2) {
// or other locator implemenations. return ((Locator2) locator).getEncoding();
try {
Method m = locator.getClass().getMethod("getEncoding",
new Class[] {});
if (m != null) {
return (String) m.invoke(locator, null);
}
} catch (Exception e) {
// do nothing
} }
// couldn't determine encoding, returning null... // couldn't determine encoding, returning null...
@ -941,9 +924,9 @@ public class SAXContentHandler extends DefaultHandler implements
* @param declaration * @param declaration
* DOCUMENT ME! * DOCUMENT ME!
*/ */
protected void addDTDDeclaration(Object declaration) { protected void addDTDDeclaration(Decl declaration) {
if (internalDTDDeclarations == null) { if (internalDTDDeclarations == null) {
internalDTDDeclarations = new ArrayList(); internalDTDDeclarations = new ArrayList<Decl>();
} }
internalDTDDeclarations.add(declaration); internalDTDDeclarations.add(declaration);
@ -955,9 +938,9 @@ public class SAXContentHandler extends DefaultHandler implements
* @param declaration * @param declaration
* DOCUMENT ME! * DOCUMENT ME!
*/ */
protected void addExternalDTDDeclaration(Object declaration) { protected void addExternalDTDDeclaration(Decl declaration) {
if (externalDTDDeclarations == null) { if (externalDTDDeclarations == null) {
externalDTDDeclarations = new ArrayList(); externalDTDDeclarations = new ArrayList<Decl>();
} }
externalDTDDeclarations.add(declaration); externalDTDDeclarations.add(declaration);

62
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 static final byte NULL = 2;
private List events = new ArrayList(); private List<SAXEvent> events = new ArrayList<SAXEvent>();
private Map prefixMappings = new HashMap(); private Map<QName, List<String>> prefixMappings = new HashMap<QName, List<String>>();
private static final String XMLNS = "xmlns"; private static final String XMLNS = "xmlns";
@ -79,11 +79,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
} }
public void replay(ContentHandler handler) throws SAXException { public void replay(ContentHandler handler) throws SAXException {
SAXEvent saxEvent; for (SAXEvent saxEvent : events) {
Iterator itr = events.iterator();
while (itr.hasNext()) {
saxEvent = (SAXEvent) itr.next();
switch (saxEvent.event) { switch (saxEvent.event) {
// replay to ContentHandler // replay to ContentHandler
@ -117,13 +113,10 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
case SAXEvent.START_ELEMENT: case SAXEvent.START_ELEMENT:
AttributesImpl attributes = new AttributesImpl(); AttributesImpl attributes = new AttributesImpl();
List attParmList = (List) saxEvent.getParm(3); List<String[]> attParmList = (List<String[]>) saxEvent.getParm(3);
if (attParmList != null) { if (attParmList != null) {
Iterator attsItr = attParmList.iterator(); for (String[] attParms : attParmList) {
while (attsItr.hasNext()) {
String[] attParms = (String[]) attsItr.next();
attributes.addAttribute(attParms[0], attParms[1], attributes.addAttribute(attParms[0], attParms[1],
attParms[2], attParms[3], attParms[4]); attParms[2], attParms[3], attParms[4]);
} }
@ -145,8 +138,8 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
case SAXEvent.CHARACTERS: case SAXEvent.CHARACTERS:
char[] chars = (char[]) saxEvent.getParm(0); char[] chars = (char[]) saxEvent.getParm(0);
int start = ((Integer) saxEvent.getParm(1)).intValue(); int start = (Integer) saxEvent.getParm(1);
int end = ((Integer) saxEvent.getParm(2)).intValue(); int end = (Integer) saxEvent.getParm(2);
handler.characters(chars, start, end); handler.characters(chars, start, end);
break; break;
@ -189,8 +182,8 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
case SAXEvent.COMMENT: case SAXEvent.COMMENT:
char[] cchars = (char[]) saxEvent.getParm(0); char[] cchars = (char[]) saxEvent.getParm(0);
int cstart = ((Integer) saxEvent.getParm(1)).intValue(); int cstart = (Integer) saxEvent.getParm(1);
int cend = ((Integer) saxEvent.getParm(2)).intValue(); int cend = (Integer) saxEvent.getParm(2);
((LexicalHandler) handler).comment(cchars, cstart, cend); ((LexicalHandler) handler).comment(cchars, cstart, cend);
break; break;
@ -272,7 +265,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
saxEvent.addParm(localName); saxEvent.addParm(localName);
saxEvent.addParm(qualifiedName); saxEvent.addParm(qualifiedName);
QName qName = null; QName qName;
if (namespaceURI != null) { if (namespaceURI != null) {
qName = new QName(localName, Namespace.get(namespaceURI)); qName = new QName(localName, Namespace.get(namespaceURI));
} else { } else {
@ -280,8 +273,8 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
} }
if ((attributes != null) && (attributes.getLength() > 0)) { if ((attributes != null) && (attributes.getLength() > 0)) {
List attParmList = new ArrayList(attributes.getLength()); List<String[]> attParmList = new ArrayList<String[]>(attributes.getLength());
String[] attParms = null; String[] attParms;
for (int i = 0; i < attributes.getLength(); i++) { 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 // if SAXWriter is writing a DOMDocument, namespace
// decls are treated as attributes. record a start // decls are treated as attributes. record a start
// prefix mapping event // prefix mapping event
String prefix = null; String prefix;
if (attLocalName.length() > 5) { if (attLocalName.length() > 5) {
prefix = attLocalName.substring(6); prefix = attLocalName.substring(6);
} else { } else {
@ -307,9 +300,9 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
// 'register' the prefix so that we can generate // 'register' the prefix so that we can generate
// an end prefix mapping event within endElement // an end prefix mapping event within endElement
List prefixes = (List) prefixMappings.get(qName); List<String> prefixes = prefixMappings.get(qName);
if (prefixes == null) { if (prefixes == null) {
prefixes = new ArrayList(); prefixes = new ArrayList<String>();
prefixMappings.put(qName, prefixes); prefixMappings.put(qName, prefixes);
} }
prefixes.add(prefix); 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 // check to see if a we issued a start prefix mapping event
// for DOMDocument namespace decls // for DOMDocument namespace decls
QName elementName = null; QName elementName;
if (namespaceURI != null) { if (namespaceURI != null) {
elementName = new QName(localName, Namespace.get(namespaceURI)); elementName = new QName(localName, Namespace.get(namespaceURI));
} else { } else {
elementName = new QName(localName); elementName = new QName(localName);
} }
List prefixes = (List) prefixMappings.get(elementName); List<String> prefixes = prefixMappings.get(elementName);
if (prefixes != null) { if (prefixes != null) {
Iterator itr = prefixes.iterator(); for (String prefixe : prefixes) {
while (itr.hasNext()) {
SAXEvent prefixEvent = SAXEvent prefixEvent =
new SAXEvent(SAXEvent.END_PREFIX_MAPPING); new SAXEvent(SAXEvent.END_PREFIX_MAPPING);
prefixEvent.addParm(itr.next()); prefixEvent.addParm(prefixe);
events.add(prefixEvent); 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 { public void characters(char[] ch, int start, int end) throws SAXException {
SAXEvent saxEvent = new SAXEvent(SAXEvent.CHARACTERS); SAXEvent saxEvent = new SAXEvent(SAXEvent.CHARACTERS);
saxEvent.addParm(ch); saxEvent.addParm(ch);
saxEvent.addParm(new Integer(start)); saxEvent.addParm(start);
saxEvent.addParm(new Integer(end)); saxEvent.addParm(end);
events.add(saxEvent); 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 { public void comment(char[] ch, int start, int end) throws SAXException {
SAXEvent saxEvent = new SAXEvent(SAXEvent.COMMENT); SAXEvent saxEvent = new SAXEvent(SAXEvent.COMMENT);
saxEvent.addParm(ch); saxEvent.addParm(ch);
saxEvent.addParm(new Integer(start)); saxEvent.addParm(start);
saxEvent.addParm(new Integer(end)); saxEvent.addParm(end);
events.add(saxEvent); events.add(saxEvent);
} }
@ -469,7 +461,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
public void readExternal(ObjectInput in) throws ClassNotFoundException, public void readExternal(ObjectInput in) throws ClassNotFoundException,
IOException { IOException {
if (in.readByte() != NULL) { if (in.readByte() != NULL) {
events = (List) in.readObject(); events = (List<SAXEvent>) in.readObject();
} }
} }
@ -518,7 +510,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
protected byte event; protected byte event;
protected List parms; protected List<Object> parms;
public SAXEvent() { public SAXEvent() {
} }
@ -529,7 +521,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
void addParm(Object parm) { void addParm(Object parm) {
if (parms == null) { if (parms == null) {
parms = new ArrayList(3); parms = new ArrayList<Object>(3);
} }
parms.add(parm); parms.add(parm);
@ -559,7 +551,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
event = in.readByte(); event = in.readByte();
if (in.readByte() != NULL) { if (in.readByte() != NULL) {
parms = (List) in.readObject(); parms = (List<Object>) in.readObject();
} }
} }
} }

28
fine-org-dom4j/src/main/java/org/dom4j/io/SAXHelper.java

@ -13,6 +13,8 @@ import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory; import org.xml.sax.helpers.XMLReaderFactory;
import javax.xml.parsers.SAXParserFactory;
/** /**
* <p> * <p>
* <code>SAXHelper</code> contains some helper methods for working with SAX * <code>SAXHelper</code> contains some helper methods for working with SAX
@ -20,7 +22,7 @@ import org.xml.sax.helpers.XMLReaderFactory;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.18 $
*/ */
class SAXHelper { class SAXHelper {
private static boolean loggedWarning = true; private static boolean loggedWarning = true;
@ -62,6 +64,15 @@ class SAXHelper {
* Creats a default XMLReader via the org.xml.sax.driver system property or * Creats a default XMLReader via the org.xml.sax.driver system property or
* JAXP if the system property is not set. * 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:
*
* <pre>
* reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
* reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
* reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
* </pre>
*
* @param validating * @param validating
* DOCUMENT ME! * DOCUMENT ME!
* *
@ -103,6 +114,21 @@ class SAXHelper {
throw new SAXException("Couldn't create SAX reader"); 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; return reader;
} }

18
fine-org-dom4j/src/main/java/org/dom4j/io/SAXModifier.java

@ -50,7 +50,7 @@ public class SAXModifier {
private SAXModifyReader modifyReader; private SAXModifyReader modifyReader;
private HashMap modifiers = new HashMap(); private HashMap<String, ElementModifier> modifiers = new HashMap<String, ElementModifier>();
/** /**
* Creates a new modifier. <br> * Creates a new modifier. <br>
@ -102,7 +102,7 @@ public class SAXModifier {
/** /**
* Reads a Document from the given {@link java.io.File}and writes it to the * 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. * objects are invoked on the fly.
* *
* @param source * @param source
@ -246,7 +246,7 @@ public class SAXModifier {
/** /**
* Reads a Document from the given {@link java.net.URL}and writes it to the * 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. * objects are invoked on the fly.
* *
* @param source * @param source
@ -269,7 +269,7 @@ public class SAXModifier {
/** /**
* Reads a Document from the given URL or filename and writes it to the * 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. * objects are invoked on the fly.
* *
* @param source * @param source
@ -385,14 +385,10 @@ public class SAXModifier {
reader.resetHandlers(); reader.resetHandlers();
Iterator modifierIt = this.modifiers.entrySet().iterator(); for (Map.Entry<String, ElementModifier> entry : this.modifiers.entrySet()) {
while (modifierIt.hasNext()) {
Map.Entry entry = (Map.Entry) modifierIt.next();
SAXModifyElementHandler handler = new SAXModifyElementHandler( SAXModifyElementHandler handler = new SAXModifyElementHandler(
(ElementModifier) entry.getValue()); entry.getValue());
reader.addHandler((String) entry.getKey(), handler); reader.addHandler(entry.getKey(), handler);
} }
reader.setXMLWriter(getXMLWriter()); reader.setXMLWriter(getXMLWriter());

337
fine-org-dom4j/src/main/java/org/dom4j/io/SAXReader.java

@ -30,59 +30,43 @@ import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory; import org.xml.sax.helpers.XMLReaderFactory;
import javax.xml.parsers.SAXParserFactory;
/** /**
* <p>
* <code>SAXReader</code> creates a DOM4J tree from SAX parsing events. * <code>SAXReader</code> creates a DOM4J tree from SAX parsing events.
* </p>
*
* <p> * <p>
* The actual SAX parser that is used by this class is configurable so you can * 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 * 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. * own SAX parser so you do not need to worry about configuring the SAX parser.
* </p>
*
* <p> * <p>
* To explicitly configure the SAX parser that is used via Java code you can use * 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 * a constructor or use the {@link #setXMLReader(XMLReader)}or {@link
* #setXMLReaderClassName(String)} methods. * #setXMLReaderClassName(String)} methods.
* </p>
*
* <p> * <p>
* If the parser is not specified explicitly then the standard SAX policy of * If the parser is not specified explicitly then the standard SAX policy of
* using the <code>org.xml.sax.driver</code> system property is used to * using the <code>org.xml.sax.driver</code> system property is used to
* determine the implementation class of {@link XMLReader}. * determine the implementation class of {@link XMLReader}.
* </p>
*
* <p> * <p>
* If the <code>org.xml.sax.driver</code> system property is not defined then * If the <code>org.xml.sax.driver</code> system property is not defined then
* JAXP is used via reflection (so that DOM4J is not explicitly dependent on the * 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 * 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 * creating a JAXP SAXParser an informational message is output and then the
* default (Aelfred) SAX parser is used instead. * default (Aelfred) SAX parser is used instead.
* </p>
*
* <p> * <p>
* If you are trying to use JAXP to explicitly set your SAX parser and are * 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 * experiencing problems, you can turn on verbose error reporting by defining
* the system property <code>org.dom4j.verbose</code> to be "true" which will * the system property <code>org.dom4j.verbose</code> to be "true" which will
* output a more detailed description of why JAXP could not find a SAX parser * output a more detailed description of why JAXP could not find a SAX parser
* </p>
*
* <p> * <p>
* For more information on JAXP please go to <a * For more information on JAXP please go to <a
* href="http://java.sun.com/xml/">Sun's Java &amp; XML site </a> * href="http://java.sun.com/xml/">Sun's Java &amp; XML site </a>
* </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.58 $
*/ */
public class SAXReader { public class SAXReader {
private static final String SAX_STRING_INTERNING = private static final String SAX_STRING_INTERNING =
"http://xml.org/sax/features/string-interning"; "http://xml.org/sax/features/string-interning";
private static final String SAX_NAMESPACE_PREFIXES =
"http://xml.org/sax/features/namespace-prefixes";
private static final String SAX_NAMESPACES =
"http://xml.org/sax/features/namespaces";
private static final String SAX_DECL_HANDLER = private static final String SAX_DECL_HANDLER =
"http://xml.org/sax/properties/declaration-handler"; "http://xml.org/sax/properties/declaration-handler";
private static final String SAX_LEXICAL_HANDLER = private static final String SAX_LEXICAL_HANDLER =
@ -90,62 +74,151 @@ public class SAXReader {
private static final String SAX_LEXICALHANDLER = private static final String SAX_LEXICALHANDLER =
"http://xml.org/sax/handlers/LexicalHandler"; "http://xml.org/sax/handlers/LexicalHandler";
/** <code>DocumentFactory</code> used to create new document objects */ /**
* <code>DocumentFactory</code> used to create new document objects
*/
private DocumentFactory factory; private DocumentFactory factory;
/** <code>XMLReader</code> used to parse the SAX events */ /**
* <code>XMLReader</code> used to parse the SAX events
*/
private XMLReader xmlReader; private XMLReader xmlReader;
/** Whether validation should occur */ /**
* Whether validation should occur
*/
private boolean validating; private boolean validating;
/** DispatchHandler to call when each <code>Element</code> is encountered */ /**
* DispatchHandler to call when each <code>Element</code> is encountered
*/
private DispatchHandler dispatchHandler; private DispatchHandler dispatchHandler;
/** ErrorHandler class to use */ /**
* ErrorHandler class to use
*/
private ErrorHandler errorHandler; private ErrorHandler errorHandler;
/** The entity resolver */ /**
* The entity resolver
*/
private EntityResolver entityResolver; private EntityResolver entityResolver;
/** Should element & attribute names and namespace URIs be interned? */ /**
* Should element & attribute names and namespace URIs be interned?
*/
private boolean stringInternEnabled = true; private boolean stringInternEnabled = true;
/** Should internal DTD declarations be expanded into a List in the DTD */ /**
* Should internal DTD declarations be expanded into a List in the DTD
*/
private boolean includeInternalDTDDeclarations = false; private boolean includeInternalDTDDeclarations = false;
/** Should external DTD declarations be expanded into a List in the DTD */ /**
* Should external DTD declarations be expanded into a List in the DTD
*/
private boolean includeExternalDTDDeclarations = false; private boolean includeExternalDTDDeclarations = false;
/** Whether adjacent text nodes should be merged */ /**
* Whether adjacent text nodes should be merged
*/
private boolean mergeAdjacentText = false; private boolean mergeAdjacentText = false;
/** Holds value of property stripWhitespaceText. */ /**
* Holds value of property stripWhitespaceText.
*/
private boolean stripWhitespaceText = false; private boolean stripWhitespaceText = false;
/** Should we ignore comments */ /**
* Should we ignore comments
*/
private boolean ignoreComments = false; private boolean ignoreComments = false;
/** Encoding of InputSource - null means system default encoding */ /**
* Encoding of InputSource - null means system default encoding
*/
private String encoding = null; private String encoding = null;
// private boolean includeExternalGeneralEntities = false; // private boolean includeExternalGeneralEntities = false;
// private boolean includeExternalParameterEntities = false; // private boolean includeExternalParameterEntities = false;
/** The SAX filter used to filter SAX events */ /**
* The SAX filter used to filter SAX events
*
* @since 2.1.2
*/
private XMLFilter xmlFilter; private XMLFilter xmlFilter;
public static SAXReader createDefault() {
SAXReader reader = new SAXReader();
try {
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
} catch (SAXException e) {
// nothing to do, incompatible reader
}
return reader;
}
/**
* 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:
*
* <pre>
* reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
* reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
* reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
* </pre>
*/
public SAXReader() { 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:
*
* <pre>
* reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
* reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
* reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
* </pre>
*
* @param validating
*/
public SAXReader(boolean validating) { public SAXReader(boolean validating) {
this.validating = 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:
*
* <pre>
* reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
* reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
* reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
* </pre>
*
* @param factory
*/
public SAXReader(DocumentFactory factory) { public SAXReader(DocumentFactory factory) {
this.factory = 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:
*
* <pre>
* reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
* reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
* reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
* </pre>
*
* @param factory
* @param validating
*/
public SAXReader(DocumentFactory factory, boolean validating) { public SAXReader(DocumentFactory factory, boolean validating) {
this.factory = factory; this.factory = factory;
this.validating = validating; this.validating = validating;
@ -185,13 +258,9 @@ public class SAXReader {
* this method is to correctly configure an XMLReader object instance and * this method is to correctly configure an XMLReader object instance and
* call the {@link #setXMLReader(XMLReader)}method * call the {@link #setXMLReader(XMLReader)}method
* *
* @param name * @param name is the SAX property name
* is the SAX property name * @param value is the value of the SAX property
* @param value * @throws SAXException if the XMLReader could not be created or the property could
* is the value of the SAX property
*
* @throws SAXException
* if the XMLReader could not be created or the property could
* not be changed. * not be changed.
*/ */
public void setProperty(String name, Object value) throws SAXException { public void setProperty(String name, Object value) throws SAXException {
@ -205,13 +274,9 @@ public class SAXReader {
* calling this method is to correctly configure an XMLReader object * calling this method is to correctly configure an XMLReader object
* instance and call the {@link #setXMLReader(XMLReader)}method * instance and call the {@link #setXMLReader(XMLReader)}method
* *
* @param name * @param name is the SAX feature name
* is the SAX feature name * @param value is the value of the SAX feature
* @param value * @throws SAXException if the XMLReader could not be created or the feature could
* is the value of the SAX feature
*
* @throws SAXException
* if the XMLReader could not be created or the feature could
* not be changed. * not be changed.
*/ */
public void setFeature(String name, boolean value) throws SAXException { public void setFeature(String name, boolean value) throws SAXException {
@ -223,13 +288,9 @@ public class SAXReader {
* Reads a Document from the given <code>File</code> * Reads a Document from the given <code>File</code>
* </p> * </p>
* *
* @param file * @param file is the <code>File</code> to read from.
* is the <code>File</code> to read from.
*
* @return the newly created Document instance * @return the newly created Document instance
* * @throws DocumentException if an error occurs during parsing.
* @throws DocumentException
* if an error occurs during parsing.
*/ */
public Document read(File file) throws DocumentException { public Document read(File file) throws DocumentException {
try { try {
@ -272,13 +333,9 @@ public class SAXReader {
* Reads a Document from the given <code>URL</code> using SAX * Reads a Document from the given <code>URL</code> using SAX
* </p> * </p>
* *
* @param url * @param url <code>URL</code> to read from.
* <code>URL</code> to read from.
*
* @return the newly created Document instance * @return the newly created Document instance
* * @throws DocumentException if an error occurs during parsing.
* @throws DocumentException
* if an error occurs during parsing.
*/ */
public Document read(URL url) throws DocumentException { public Document read(URL url) throws DocumentException {
String systemID = url.toExternalForm(); String systemID = url.toExternalForm();
@ -304,13 +361,9 @@ public class SAXReader {
* String} to denote the source of the document. * String} to denote the source of the document.
* </p> * </p>
* *
* @param systemId * @param systemId is a URL for a document or a file name.
* is a URL for a document or a file name.
*
* @return the newly created Document instance * @return the newly created Document instance
* * @throws DocumentException if an error occurs during parsing.
* @throws DocumentException
* if an error occurs during parsing.
*/ */
public Document read(String systemId) throws DocumentException { public Document read(String systemId) throws DocumentException {
InputSource source = new InputSource(systemId); InputSource source = new InputSource(systemId);
@ -326,13 +379,9 @@ public class SAXReader {
* Reads a Document from the given stream using SAX * Reads a Document from the given stream using SAX
* </p> * </p>
* *
* @param in * @param in <code>InputStream</code> to read from.
* <code>InputStream</code> to read from.
*
* @return the newly created Document instance * @return the newly created Document instance
* * @throws DocumentException if an error occurs during parsing.
* @throws DocumentException
* if an error occurs during parsing.
*/ */
public Document read(InputStream in) throws DocumentException { public Document read(InputStream in) throws DocumentException {
InputSource source = new InputSource(in); InputSource source = new InputSource(in);
@ -344,17 +393,11 @@ public class SAXReader {
} }
/** /**
* <p>
* Reads a Document from the given <code>Reader</code> using SAX * Reads a Document from the given <code>Reader</code> using SAX
* </p>
*
* @param reader
* is the reader for the input
* *
* @param reader is the reader for the input
* @return the newly created Document instance * @return the newly created Document instance
* * @throws DocumentException if an error occurs during parsing.
* @throws DocumentException
* if an error occurs during parsing.
*/ */
public Document read(Reader reader) throws DocumentException { public Document read(Reader reader) throws DocumentException {
InputSource source = new InputSource(reader); InputSource source = new InputSource(reader);
@ -370,15 +413,10 @@ public class SAXReader {
* Reads a Document from the given stream using SAX * Reads a Document from the given stream using SAX
* </p> * </p>
* *
* @param in * @param in <code>InputStream</code> to read from.
* <code>InputStream</code> to read from. * @param systemId is the URI for the input
* @param systemId
* is the URI for the input
*
* @return the newly created Document instance * @return the newly created Document instance
* * @throws DocumentException if an error occurs during parsing.
* @throws DocumentException
* if an error occurs during parsing.
*/ */
public Document read(InputStream in, String systemId) public Document read(InputStream in, String systemId)
throws DocumentException { throws DocumentException {
@ -396,15 +434,10 @@ public class SAXReader {
* Reads a Document from the given <code>Reader</code> using SAX * Reads a Document from the given <code>Reader</code> using SAX
* </p> * </p>
* *
* @param reader * @param reader is the reader for the input
* is the reader for the input * @param systemId is the URI for the input
* @param systemId
* is the URI for the input
*
* @return the newly created Document instance * @return the newly created Document instance
* * @throws DocumentException if an error occurs during parsing.
* @throws DocumentException
* if an error occurs during parsing.
*/ */
public Document read(Reader reader, String systemId) public Document read(Reader reader, String systemId)
throws DocumentException { throws DocumentException {
@ -422,13 +455,9 @@ public class SAXReader {
* Reads a Document from the given <code>InputSource</code> using SAX * Reads a Document from the given <code>InputSource</code> using SAX
* </p> * </p>
* *
* @param in * @param in <code>InputSource</code> to read from.
* <code>InputSource</code> to read from.
*
* @return the newly created Document instance * @return the newly created Document instance
* * @throws DocumentException if an error occurs during parsing.
* @throws DocumentException
* if an error occurs during parsing.
*/ */
public Document read(InputSource in) throws DocumentException { public Document read(InputSource in) throws DocumentException {
try { try {
@ -502,8 +531,7 @@ public class SAXReader {
/** /**
* Sets the validation mode. * Sets the validation mode.
* *
* @param validation * @param validation indicates whether or not validation should occur.
* indicates whether or not validation should occur.
*/ */
public void setValidation(boolean validation) { public void setValidation(boolean validation) {
this.validating = validation; this.validating = validation;
@ -523,8 +551,7 @@ public class SAXReader {
* Sets whether internal DTD declarations should be expanded into the * Sets whether internal DTD declarations should be expanded into the
* DocumentType object or not. * DocumentType object or not.
* *
* @param include * @param include whether or not DTD declarations should be expanded and
* whether or not DTD declarations should be expanded and
* included into the DocumentType object. * included into the DocumentType object.
*/ */
public void setIncludeInternalDTDDeclarations(boolean include) { public void setIncludeInternalDTDDeclarations(boolean include) {
@ -545,8 +572,7 @@ public class SAXReader {
* Sets whether DTD external declarations should be expanded into the * Sets whether DTD external declarations should be expanded into the
* DocumentType object or not. * DocumentType object or not.
* *
* @param include * @param include whether or not DTD declarations should be expanded and
* whether or not DTD declarations should be expanded and
* included into the DocumentType object. * included into the DocumentType object.
*/ */
public void setIncludeExternalDTDDeclarations(boolean include) { public void setIncludeExternalDTDDeclarations(boolean include) {
@ -554,7 +580,7 @@ public class SAXReader {
} }
/** /**
* Sets whether String interning is enabled or disabled for element & * Sets whether String interning is enabled or disabled for element &amp;
* attribute names and namespace URIs. This proprety is enabled by default. * attribute names and namespace URIs. This proprety is enabled by default.
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
@ -564,11 +590,10 @@ public class SAXReader {
} }
/** /**
* Sets whether String interning is enabled or disabled for element & * Sets whether String interning is enabled or disabled for element &amp;
* attribute names and namespace URIs * attribute names and namespace URIs
* *
* @param stringInternEnabled * @param stringInternEnabled DOCUMENT ME!
* DOCUMENT ME!
*/ */
public void setStringInternEnabled(boolean stringInternEnabled) { public void setStringInternEnabled(boolean stringInternEnabled) {
this.stringInternEnabled = stringInternEnabled; this.stringInternEnabled = stringInternEnabled;
@ -587,8 +612,7 @@ public class SAXReader {
* Sets whether or not adjacent text nodes should be merged together when * Sets whether or not adjacent text nodes should be merged together when
* parsing. * parsing.
* *
* @param mergeAdjacentText * @param mergeAdjacentText New value of property mergeAdjacentText.
* New value of property mergeAdjacentText.
*/ */
public void setMergeAdjacentText(boolean mergeAdjacentText) { public void setMergeAdjacentText(boolean mergeAdjacentText) {
this.mergeAdjacentText = mergeAdjacentText; this.mergeAdjacentText = mergeAdjacentText;
@ -608,8 +632,7 @@ public class SAXReader {
* Sets whether whitespace between element start and end tags should be * Sets whether whitespace between element start and end tags should be
* ignored. * ignored.
* *
* @param stripWhitespaceText * @param stripWhitespaceText New value of property stripWhitespaceText.
* New value of property stripWhitespaceText.
*/ */
public void setStripWhitespaceText(boolean stripWhitespaceText) { public void setStripWhitespaceText(boolean stripWhitespaceText) {
this.stripWhitespaceText = stripWhitespaceText; this.stripWhitespaceText = stripWhitespaceText;
@ -627,8 +650,7 @@ public class SAXReader {
/** /**
* Sets whether we should ignore comments or not. * Sets whether we should ignore comments or not.
* *
* @param ignoreComments * @param ignoreComments whether we should ignore comments or not.
* whether we should ignore comments or not.
*/ */
public void setIgnoreComments(boolean ignoreComments) { public void setIgnoreComments(boolean ignoreComments) {
this.ignoreComments = ignoreComments; this.ignoreComments = ignoreComments;
@ -656,8 +678,7 @@ public class SAXReader {
* {@link DocumentFactory} * {@link DocumentFactory}
* </p> * </p>
* *
* @param documentFactory * @param documentFactory <code>DocumentFactory</code> used to create DOM4J objects
* <code>DocumentFactory</code> used to create DOM4J objects
*/ */
public void setDocumentFactory(DocumentFactory documentFactory) { public void setDocumentFactory(DocumentFactory documentFactory) {
this.factory = documentFactory; this.factory = documentFactory;
@ -676,8 +697,7 @@ public class SAXReader {
* Sets the <code>ErrorHandler</code> used by the SAX * Sets the <code>ErrorHandler</code> used by the SAX
* <code>XMLReader</code>. * <code>XMLReader</code>.
* *
* @param errorHandler * @param errorHandler is the <code>ErrorHandler</code> used by SAX
* is the <code>ErrorHandler</code> used by SAX
*/ */
public void setErrorHandler(ErrorHandler errorHandler) { public void setErrorHandler(ErrorHandler errorHandler) {
this.errorHandler = errorHandler; this.errorHandler = errorHandler;
@ -695,8 +715,7 @@ public class SAXReader {
/** /**
* Sets the entity resolver used to resolve entities. * Sets the entity resolver used to resolve entities.
* *
* @param entityResolver * @param entityResolver DOCUMENT ME!
* DOCUMENT ME!
*/ */
public void setEntityResolver(EntityResolver entityResolver) { public void setEntityResolver(EntityResolver entityResolver) {
this.entityResolver = entityResolver; this.entityResolver = entityResolver;
@ -706,9 +725,7 @@ public class SAXReader {
* DOCUMENT ME! * DOCUMENT ME!
* *
* @return the <code>XMLReader</code> used to parse SAX events * @return the <code>XMLReader</code> used to parse SAX events
* * @throws SAXException DOCUMENT ME!
* @throws SAXException
* DOCUMENT ME!
*/ */
public XMLReader getXMLReader() throws SAXException { public XMLReader getXMLReader() throws SAXException {
if (xmlReader == null) { if (xmlReader == null) {
@ -721,8 +738,7 @@ public class SAXReader {
/** /**
* Sets the <code>XMLReader</code> used to parse SAX events * Sets the <code>XMLReader</code> used to parse SAX events
* *
* @param reader * @param reader is the <code>XMLReader</code> to parse SAX events
* is the <code>XMLReader</code> to parse SAX events
*/ */
public void setXMLReader(XMLReader reader) { public void setXMLReader(XMLReader reader) {
this.xmlReader = reader; this.xmlReader = reader;
@ -733,7 +749,6 @@ public class SAXReader {
* encoding) * encoding)
* *
* @return encoding used for InputSource * @return encoding used for InputSource
*
*/ */
public String getEncoding() { public String getEncoding() {
return encoding; return encoding;
@ -742,8 +757,7 @@ public class SAXReader {
/** /**
* Sets encoding used for InputSource (null means system default encoding) * Sets encoding used for InputSource (null means system default encoding)
* *
* @param encoding * @param encoding is encoding used for InputSource
* is encoding used for InputSource
*/ */
public void setEncoding(String encoding) { public void setEncoding(String encoding) {
this.encoding = encoding; this.encoding = encoding;
@ -753,12 +767,9 @@ public class SAXReader {
* Sets the class name of the <code>XMLReader</code> to be used to parse * Sets the class name of the <code>XMLReader</code> to be used to parse
* SAX events. * SAX events.
* *
* @param xmlReaderClassName * @param xmlReaderClassName is the class name of the <code>XMLReader</code> to parse SAX
* is the class name of the <code>XMLReader</code> to parse SAX
* events * events
* * @throws SAXException DOCUMENT ME!
* @throws SAXException
* DOCUMENT ME!
*/ */
public void setXMLReaderClassName(String xmlReaderClassName) public void setXMLReaderClassName(String xmlReaderClassName)
throws SAXException { throws SAXException {
@ -769,10 +780,8 @@ public class SAXReader {
* Adds the <code>ElementHandler</code> to be called when the specified * Adds the <code>ElementHandler</code> to be called when the specified
* path is encounted. * path is encounted.
* *
* @param path * @param path is the path to be handled
* is the path to be handled * @param handler is the <code>ElementHandler</code> to be called by the event
* @param handler
* is the <code>ElementHandler</code> to be called by the event
* based processor. * based processor.
*/ */
public void addHandler(String path, ElementHandler handler) { public void addHandler(String path, ElementHandler handler) {
@ -783,8 +792,7 @@ public class SAXReader {
* Removes the <code>ElementHandler</code> from the event based processor, * Removes the <code>ElementHandler</code> from the event based processor,
* for the specified path. * for the specified path.
* *
* @param path * @param path is the path to remove the <code>ElementHandler</code> for.
* is the path to remove the <code>ElementHandler</code> for.
*/ */
public void removeHandler(String path) { public void removeHandler(String path) {
getDispatchHandler().removeHandler(path); getDispatchHandler().removeHandler(path);
@ -795,8 +803,7 @@ public class SAXReader {
* registered, this will set a default <code>ElementHandler</code> to be * registered, this will set a default <code>ElementHandler</code> to be
* called for any path which does <b>NOT </b> have a handler registered. * called for any path which does <b>NOT </b> have a handler registered.
* *
* @param handler * @param handler is the <code>ElementHandler</code> to be called by the event
* is the <code>ElementHandler</code> to be called by the event
* based processor. * based processor.
*/ */
public void setDefaultHandler(ElementHandler handler) { public void setDefaultHandler(ElementHandler handler) {
@ -824,8 +831,7 @@ public class SAXReader {
/** /**
* Sets the SAX filter to be used when filtering SAX events * Sets the SAX filter to be used when filtering SAX events
* *
* @param filter * @param filter is the SAX filter to use or null to disable filtering
* is the SAX filter to use or null to disable filtering
*/ */
public void setXMLFilter(XMLFilter filter) { public void setXMLFilter(XMLFilter filter) {
this.xmlFilter = filter; this.xmlFilter = filter;
@ -838,9 +844,7 @@ public class SAXReader {
* Installs any XMLFilter objects required to allow the SAX event stream to * Installs any XMLFilter objects required to allow the SAX event stream to
* be filtered and preprocessed before it gets to dom4j. * be filtered and preprocessed before it gets to dom4j.
* *
* @param reader * @param reader DOCUMENT ME!
* DOCUMENT ME!
*
* @return the new XMLFilter if applicable or the original XMLReader if no * @return the new XMLFilter if applicable or the original XMLReader if no
* filter is being used. * filter is being used.
*/ */
@ -886,9 +890,7 @@ public class SAXReader {
* XMLReader objects * XMLReader objects
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
* * @throws SAXException DOCUMENT ME!
* @throws SAXException
* DOCUMENT ME!
*/ */
protected XMLReader createXMLReader() throws SAXException { protected XMLReader createXMLReader() throws SAXException {
return SAXHelper.createXMLReader(isValidating()); return SAXHelper.createXMLReader(isValidating());
@ -897,13 +899,9 @@ public class SAXReader {
/** /**
* Configures the XMLReader before use * Configures the XMLReader before use
* *
* @param reader * @param reader DOCUMENT ME!
* DOCUMENT ME! * @param handler DOCUMENT ME!
* @param handler * @throws DocumentException DOCUMENT ME!
* DOCUMENT ME!
*
* @throws DocumentException
* DOCUMENT ME!
*/ */
protected void configureReader(XMLReader reader, DefaultHandler handler) protected void configureReader(XMLReader reader, DefaultHandler handler)
throws DocumentException { throws DocumentException {
@ -918,27 +916,10 @@ public class SAXReader {
SAXHelper.setParserProperty(reader, SAX_DECL_HANDLER, handler); 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 // string interning
SAXHelper.setParserFeature(reader, SAX_STRING_INTERNING, SAXHelper.setParserFeature(reader, SAX_STRING_INTERNING,
isStringInternEnabled()); 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 { try {
// configure validation support // configure validation support
reader.setFeature("http://xml.org/sax/features/validation", reader.setFeature("http://xml.org/sax/features/validation",
@ -960,9 +941,7 @@ public class SAXReader {
/** /**
* Factory Method to allow user derived SAXContentHandler objects to be used * Factory Method to allow user derived SAXContentHandler objects to be used
* *
* @param reader * @param reader DOCUMENT ME!
* DOCUMENT ME!
*
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
protected SAXContentHandler createContentHandler(XMLReader reader) { protected SAXContentHandler createContentHandler(XMLReader reader) {

2
fine-org-dom4j/src/main/java/org/dom4j/io/SAXValidator.java

@ -27,7 +27,7 @@ import org.xml.sax.helpers.DefaultHandler;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.10 $
*/ */
public class SAXValidator { public class SAXValidator {
/** <code>XMLReader</code> used to parse the SAX events */ /** <code>XMLReader</code> used to parse the SAX events */

72
fine-org-dom4j/src/main/java/org/dom4j/io/SAXWriter.java

@ -48,7 +48,7 @@ import org.xml.sax.helpers.LocatorImpl;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.24 $
*/ */
public class SAXWriter implements XMLReader { public class SAXWriter implements XMLReader {
protected static final String[] LEXICAL_HANDLER_NAMES = { protected static final String[] LEXICAL_HANDLER_NAMES = {
@ -79,10 +79,10 @@ public class SAXWriter implements XMLReader {
private AttributesImpl attributes = new AttributesImpl(); private AttributesImpl attributes = new AttributesImpl();
/** Stores the features */ /** Stores the features */
private Map features = new HashMap(); private Map<String, Boolean> features = new HashMap();
/** Stores the properties */ /** Stores the properties */
private Map properties = new HashMap(); private Map<String, Object> properties = new HashMap();
/** Whether namespace declarations are exported as attributes or not */ /** Whether namespace declarations are exported as attributes or not */
private boolean declareNamespaceAttributes; private boolean declareNamespaceAttributes;
@ -493,9 +493,9 @@ public class SAXWriter implements XMLReader {
*/ */
public boolean getFeature(String name) throws SAXNotRecognizedException, public boolean getFeature(String name) throws SAXNotRecognizedException,
SAXNotSupportedException { 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! * DOCUMENT ME!
*/ */
public void setProperty(String name, Object value) { public void setProperty(String name, Object value) {
for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) { for (String lexicalHandlerName : LEXICAL_HANDLER_NAMES) {
if (LEXICAL_HANDLER_NAMES[i].equals(name)) { if (lexicalHandlerName.equals(name)) {
setLexicalHandler((LexicalHandler) value); setLexicalHandler((LexicalHandler) value);
return; return;
@ -561,8 +561,8 @@ public class SAXWriter implements XMLReader {
*/ */
public Object getProperty(String name) throws SAXNotRecognizedException, public Object getProperty(String name) throws SAXNotRecognizedException,
SAXNotSupportedException { SAXNotSupportedException {
for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) { for (String lexicalHandlerName : LEXICAL_HANDLER_NAMES) {
if (LEXICAL_HANDLER_NAMES[i].equals(name)) { if (lexicalHandlerName.equals(name)) {
return getLexicalHandler(); return getLexicalHandler();
} }
} }
@ -612,34 +612,32 @@ public class SAXWriter implements XMLReader {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
protected void writeContent(Branch branch, NamespaceStack namespaceStack) protected void writeContent(Branch branch, NamespaceStack namespaceStack)
throws SAXException { throws SAXException {
for (Iterator iter = branch.nodeIterator(); iter.hasNext();) { for (Iterator<Node> iter = branch.nodeIterator(); iter.hasNext();) {
Object object = iter.next(); Node node = iter.next();
if (object instanceof Element) { if (node instanceof Element) {
write((Element) object, namespaceStack); write((Element) node, namespaceStack);
} else if (object instanceof CharacterData) { } else if (node instanceof CharacterData) {
if (object instanceof Text) { if (node instanceof Text) {
Text text = (Text) object; Text text = (Text) node;
write(text.getText()); write(text.getText());
} else if (object instanceof CDATA) { } else if (node instanceof CDATA) {
write((CDATA) object); write((CDATA) node);
} else if (object instanceof Comment) { } else if (node instanceof Comment) {
write((Comment) object); write((Comment) node);
} else { } else {
throw new SAXException("Invalid Node in DOM4J content: " throw new SAXException("Invalid Node in DOM4J content: "
+ object + " of type: " + object.getClass()); + node + " of type: " + node.getClass());
} }
} else if (object instanceof String) { } else if (node instanceof Entity) {
write((String) object); write((Entity) node);
} else if (object instanceof Entity) { } else if (node instanceof ProcessingInstruction) {
write((Entity) object); write((ProcessingInstruction) node);
} else if (object instanceof ProcessingInstruction) { } else if (node instanceof Namespace) {
write((ProcessingInstruction) object); write((Namespace) node);
} else if (object instanceof Namespace) {
write((Namespace) object);
} else { } else {
throw new SAXException("Invalid Node in DOM4J content: " throw new SAXException("Invalid Node in DOM4J content: "
+ object); + node);
} }
} }
} }
@ -765,11 +763,9 @@ public class SAXWriter implements XMLReader {
elementNamespace); elementNamespace);
} }
List declaredNamespaces = element.declaredNamespaces(); List<Namespace> declaredNamespaces = element.declaredNamespaces();
for (int i = 0, size = declaredNamespaces.size(); i < size; i++) {
Namespace namespace = (Namespace) declaredNamespaces.get(i);
for (Namespace namespace : declaredNamespaces) {
if (!isIgnoreableNamespace(namespace, namespaceStack)) { if (!isIgnoreableNamespace(namespace, namespaceStack)) {
namespaceStack.push(namespace); namespaceStack.push(namespace);
contentHandler.startPrefixMapping(namespace.getPrefix(), contentHandler.startPrefixMapping(namespace.getPrefix(),
@ -825,8 +821,8 @@ public class SAXWriter implements XMLReader {
attributes.setAttributes(namespaceAttributes); attributes.setAttributes(namespaceAttributes);
} }
for (Iterator iter = element.attributeIterator(); iter.hasNext();) { for (Iterator<Attribute> iter = element.attributeIterator(); iter.hasNext();) {
Attribute attribute = (Attribute) iter.next(); Attribute attribute = iter.next();
attributes.addAttribute(attribute.getNamespaceURI(), attribute attributes.addAttribute(attribute.getNamespaceURI(), attribute
.getName(), attribute.getQualifiedName(), "CDATA", .getName(), attribute.getQualifiedName(), "CDATA",
attribute.getValue()); attribute.getValue());

20
fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventReader.java

@ -293,7 +293,7 @@ public class STAXEventReader {
* *
* @throws XMLStreamException * @throws XMLStreamException
* If an error occured reading events from the stream, or the * 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) public Element readElement(XMLEventReader eventReader)
throws XMLStreamException { throws XMLStreamException {
@ -348,7 +348,7 @@ public class STAXEventReader {
* *
* @throws XMLStreamException * @throws XMLStreamException
* If an error occured reading events from the stream, or the * 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) public org.dom4j.Attribute readAttribute(XMLEventReader reader)
throws XMLStreamException { throws XMLStreamException {
@ -375,7 +375,7 @@ public class STAXEventReader {
* *
* @throws XMLStreamException * @throws XMLStreamException
* If an error occured reading events from the stream, or the * 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) public org.dom4j.Namespace readNamespace(XMLEventReader reader)
throws XMLStreamException { throws XMLStreamException {
@ -402,7 +402,7 @@ public class STAXEventReader {
* *
* @throws XMLStreamException * @throws XMLStreamException
* If an error occured reading events from the stream, or the * 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) public CharacterData readCharacters(XMLEventReader reader)
throws XMLStreamException { throws XMLStreamException {
@ -429,7 +429,7 @@ public class STAXEventReader {
* *
* @throws XMLStreamException * @throws XMLStreamException
* If an error occured reading events from the stream, or the * 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) public org.dom4j.Comment readComment(XMLEventReader reader)
throws XMLStreamException { throws XMLStreamException {
@ -455,7 +455,7 @@ public class STAXEventReader {
* *
* @throws XMLStreamException * @throws XMLStreamException
* If an error occured reading events from the stream, or the * 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. * event.
*/ */
public Entity readEntityReference(XMLEventReader reader) public Entity readEntityReference(XMLEventReader reader)
@ -518,14 +518,14 @@ public class STAXEventReader {
Element elem = factory.createElement(elemName); Element elem = factory.createElement(elemName);
// create attributes // create attributes
for (Iterator i = startEvent.getAttributes(); i.hasNext();) { for (Iterator<Attribute> i = startEvent.getAttributes(); i.hasNext();) {
Attribute attr = (Attribute) i.next(); Attribute attr = i.next();
elem.addAttribute(createQName(attr.getName()), attr.getValue()); elem.addAttribute(createQName(attr.getName()), attr.getValue());
} }
// create namespaces // create namespaces
for (Iterator i = startEvent.getNamespaces(); i.hasNext();) { for (Iterator<Namespace> i = startEvent.getNamespaces(); i.hasNext();) {
Namespace ns = (Namespace) i.next(); Namespace ns = i.next();
elem.addNamespace(ns.getPrefix(), ns.getNamespaceURI()); elem.addNamespace(ns.getPrefix(), ns.getNamespaceURI());
} }

26
fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventWriter.java

@ -270,8 +270,8 @@ public class STAXEventWriter {
QName tagName = createQName(elem.getQName()); QName tagName = createQName(elem.getQName());
// create attribute & namespace iterators // create attribute & namespace iterators
Iterator attrIter = new AttributeIterator(elem.attributeIterator()); Iterator<javax.xml.stream.events.Attribute> attrIter = new AttributeIterator(elem.attributeIterator());
Iterator nsIter = new NamespaceIterator(elem.declaredNamespaces() Iterator<javax.xml.stream.events.Namespace> nsIter = new NamespaceIterator(elem.declaredNamespaces()
.iterator()); .iterator());
// create start event // create start event
@ -288,7 +288,7 @@ public class STAXEventWriter {
*/ */
public EndElement createEndElement(Element elem) { public EndElement createEndElement(Element elem) {
QName tagName = createQName(elem.getQName()); QName tagName = createQName(elem.getQName());
Iterator nsIter = new NamespaceIterator(elem.declaredNamespaces() Iterator<javax.xml.stream.events.Namespace> nsIter = new NamespaceIterator(elem.declaredNamespaces()
.iterator()); .iterator());
return factory.createEndElement(tagName, nsIter); return factory.createEndElement(tagName, nsIter);
@ -593,11 +593,11 @@ public class STAXEventWriter {
* Internal {@link Iterator}implementation used to pass DOM4J {@link * Internal {@link Iterator}implementation used to pass DOM4J {@link
* Attribute}s to the stream. * Attribute}s to the stream.
*/ */
private class AttributeIterator implements Iterator { private class AttributeIterator implements Iterator<javax.xml.stream.events.Attribute> {
/** The underlying DOm4J attribute iterator. */ /** The underlying DOm4J attribute iterator. */
private Iterator iter; private Iterator<Attribute> iter;
public AttributeIterator(Iterator iter) { public AttributeIterator(Iterator<Attribute> iter) {
this.iter = iter; this.iter = iter;
} }
@ -605,8 +605,8 @@ public class STAXEventWriter {
return iter.hasNext(); return iter.hasNext();
} }
public Object next() { public javax.xml.stream.events.Attribute next() {
Attribute attr = (Attribute) iter.next(); Attribute attr = iter.next();
QName attrName = createQName(attr.getQName()); QName attrName = createQName(attr.getQName());
String value = attr.getValue(); String value = attr.getValue();
@ -622,10 +622,10 @@ public class STAXEventWriter {
* Internal {@link Iterator}implementation used to pass DOM4J {@link * Internal {@link Iterator}implementation used to pass DOM4J {@link
* Namespace}s to the stream. * Namespace}s to the stream.
*/ */
private class NamespaceIterator implements Iterator { private class NamespaceIterator implements Iterator<javax.xml.stream.events.Namespace> {
private Iterator iter; private Iterator<Namespace> iter;
public NamespaceIterator(Iterator iter) { public NamespaceIterator(Iterator<Namespace> iter) {
this.iter = iter; this.iter = iter;
} }
@ -633,8 +633,8 @@ public class STAXEventWriter {
return iter.hasNext(); return iter.hasNext();
} }
public Object next() { public javax.xml.stream.events.Namespace next() {
Namespace ns = (Namespace) iter.next(); Namespace ns = iter.next();
String prefix = ns.getPrefix(); String prefix = ns.getPrefix();
String nsURI = ns.getURI(); String nsURI = ns.getURI();

2
fine-org-dom4j/src/main/java/org/dom4j/io/XMLResult.java

@ -24,7 +24,7 @@ import org.xml.sax.ext.LexicalHandler;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.9 $
*/ */
public class XMLResult extends SAXResult { public class XMLResult extends SAXResult {
private XMLWriter xmlWriter; private XMLWriter xmlWriter;

189
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.ext.LexicalHandler;
import org.xml.sax.helpers.XMLFilterImpl; import org.xml.sax.helpers.XMLFilterImpl;
import static org.dom4j.util.StringUtils.endsWithWhitespace;
import static org.dom4j.util.StringUtils.startsWithWhitespace;
/** /**
* <p> * <p>
* <code>XMLWriter</code> takes a DOM4J tree and formats it to a stream as * <code>XMLWriter</code> takes a DOM4J tree and formats it to a stream as
@ -66,7 +69,7 @@ import org.xml.sax.helpers.XMLFilterImpl;
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @author Joseph Bowbeer * @author Joseph Bowbeer
* @version $Revision$ * @version $Revision: 1.83 $
*/ */
public class XMLWriter extends XMLFilterImpl implements LexicalHandler { public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
private static final String PAD_TEXT = " "; private static final String PAD_TEXT = " ";
@ -139,7 +142,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
private boolean inDTD; private boolean inDTD;
/** The namespaces used for the current element when consuming SAX events */ /** The namespaces used for the current element when consuming SAX events */
private Map namespacesMap; private Map<String, String> namespacesMap;
/** /**
* what is the maximum allowed character code such as 127 in US-ASCII (7 * what is the maximum allowed character code such as 127 in US-ASCII (7
@ -546,10 +549,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
} else if (object instanceof String) { } else if (object instanceof String) {
write((String) object); write((String) object);
} else if (object instanceof List) { } else if (object instanceof List) {
List list = (List) object; List<?> list = (List<?>) object;
for (int i = 0, size = list.size(); i < size; i++) { for (Object aList : list) {
write(list.get(i)); write(aList);
} }
} else if (object != null) { } else if (object != null) {
throw new IOException("Invalid object: " + object); throw new IOException("Invalid object: " + object);
@ -571,6 +574,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
public void writeOpen(Element element) throws IOException { public void writeOpen(Element element) throws IOException {
writer.write("<"); writer.write("<");
writer.write(element.getQualifiedName()); writer.write(element.getQualifiedName());
writeNamespaces(element);
writeAttributes(element); writeAttributes(element);
writer.write(">"); writer.write(">");
} }
@ -599,8 +603,8 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
public void setProperty(String name, Object value) public void setProperty(String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException { throws SAXNotRecognizedException, SAXNotSupportedException {
for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) { for (String lexicalHandlerName : LEXICAL_HANDLER_NAMES) {
if (LEXICAL_HANDLER_NAMES[i].equals(name)) { if (lexicalHandlerName.equals(name)) {
setLexicalHandler((LexicalHandler) value); setLexicalHandler((LexicalHandler) value);
return; return;
@ -612,8 +616,8 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
public Object getProperty(String name) throws SAXNotRecognizedException, public Object getProperty(String name) throws SAXNotRecognizedException,
SAXNotSupportedException { SAXNotSupportedException {
for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) { for (String lexicalHandlerName : LEXICAL_HANDLER_NAMES) {
if (LEXICAL_HANDLER_NAMES[i].equals(name)) { if (lexicalHandlerName.equals(name)) {
return getLexicalHandler(); return getLexicalHandler();
} }
} }
@ -662,7 +666,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
public void startPrefixMapping(String prefix, String uri) public void startPrefixMapping(String prefix, String uri)
throws SAXException { throws SAXException {
if (namespacesMap == null) { if (namespacesMap == null) {
namespacesMap = new HashMap(); namespacesMap = new HashMap<String, String>();
} }
namespacesMap.put(prefix, uri); namespacesMap.put(prefix, uri);
@ -986,12 +990,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
boolean preserveFound = preserve; // default to global state boolean preserveFound = preserve; // default to global state
if (attr != null) { if (attr != null) {
if ("xml".equals(attr.getNamespacePrefix()) preserveFound = "xml".equals(attr.getNamespacePrefix()) && "preserve".equals(attr.getText());
&& "preserve".equals(attr.getText())) {
preserveFound = true;
} else {
preserveFound = false;
}
} }
return preserveFound; return preserveFound;
@ -1023,34 +1022,34 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
// concatenate adjacent text nodes together // concatenate adjacent text nodes together
// so that whitespace trimming works properly // so that whitespace trimming works properly
Text lastTextNode = null; Text lastTextNode = null;
StringBuffer buff = null; StringBuilder buff = null;
boolean textOnly = true; boolean textOnly = true;
for (int i = 0, size = element.nodeCount(); i < size; i++) { for (Node node : element.content()) {
Node node = element.node(i);
if (node instanceof Text) { if (node instanceof Text) {
if (lastTextNode == null) { if (lastTextNode == null) {
lastTextNode = (Text) node; lastTextNode = (Text) node;
} else { } else {
if (buff == null) { if (buff == null) {
buff = new StringBuffer(lastTextNode.getText()); buff = new StringBuilder(lastTextNode.getText());
} }
buff.append(((Text) node).getText()); buff.append((node).getText());
} }
} else { } else {
if (!textOnly && format.isPadText()) { if (!textOnly && format.isPadText()) {
// only add the PAD_TEXT if the text itself starts with // only add the PAD_TEXT if the text itself starts with
// whitespace // whitespace
char firstChar = 'a'; final boolean startsWithWhitespace;
if (buff != null) { if (buff != null) {
firstChar = buff.charAt(0); startsWithWhitespace = startsWithWhitespace(buff);
} else if (lastTextNode != null) { } 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); writer.write(PAD_TEXT);
} }
} }
@ -1066,15 +1065,14 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
if (format.isPadText()) { if (format.isPadText()) {
// only add the PAD_TEXT if the text itself ends // only add the PAD_TEXT if the text itself ends
// with whitespace // with whitespace
char lastTextChar = 'a'; final boolean endsWithWhitespace;
if (buff != null) { if (buff != null) {
lastTextChar = buff.charAt(buff.length() - 1); endsWithWhitespace = endsWithWhitespace(buff);
} else if (lastTextNode != null) { } else {
String txt = lastTextNode.getText(); endsWithWhitespace = endsWithWhitespace(lastTextNode.getText());
lastTextChar = txt.charAt(txt.length() - 1);
} }
if (Character.isWhitespace(lastTextChar)) { if (endsWithWhitespace) {
writer.write(PAD_TEXT); writer.write(PAD_TEXT);
} }
} }
@ -1091,14 +1089,14 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
if (!textOnly && format.isPadText()) { if (!textOnly && format.isPadText()) {
// only add the PAD_TEXT if the text itself starts with // only add the PAD_TEXT if the text itself starts with
// whitespace // whitespace
char firstChar = 'a'; final boolean startsWithWhitespace;
if (buff != null) { if (buff != null) {
firstChar = buff.charAt(0); startsWithWhitespace = startsWithWhitespace(buff);
} else { } else {
firstChar = lastTextNode.getText().charAt(0); startsWithWhitespace = startsWithWhitespace(lastTextNode.getText());
} }
if (Character.isWhitespace(firstChar)) { if (startsWithWhitespace) {
writer.write(PAD_TEXT); writer.write(PAD_TEXT);
} }
} }
@ -1115,9 +1113,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
} else { } else {
Node lastTextNode = null; Node lastTextNode = null;
for (int i = 0, size = element.nodeCount(); i < size; i++) { for (Node node : element.content()) {
Node node = element.node(i);
if (node instanceof Text) { if (node instanceof Text) {
writeNode(node); writeNode(node);
lastTextNode = node; lastTextNode = node;
@ -1125,10 +1121,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
if ((lastTextNode != null) && format.isPadText()) { if ((lastTextNode != null) && format.isPadText()) {
// only add the PAD_TEXT if the text itself ends with // only add the PAD_TEXT if the text itself ends with
// whitespace // whitespace
String txt = lastTextNode.getText(); if (endsWithWhitespace(lastTextNode.getText())) {
char lastTextChar = txt.charAt(txt.length() - 1);
if (Character.isWhitespace(lastTextChar)) {
writer.write(PAD_TEXT); writer.write(PAD_TEXT);
} }
} }
@ -1180,11 +1173,9 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
*/ */
protected void writeNamespaces() throws IOException { protected void writeNamespaces() throws IOException {
if (namespacesMap != null) { if (namespacesMap != null) {
for (Iterator iter = namespacesMap.entrySet().iterator(); iter for (Map.Entry<String, String> entry : namespacesMap.entrySet()) {
.hasNext();) { String prefix = entry.getKey();
Map.Entry entry = (Map.Entry) iter.next(); String uri = entry.getValue();
String prefix = (String) entry.getKey();
String uri = (String) entry.getValue();
writeNamespace(prefix, uri); writeNamespace(prefix, uri);
} }
@ -1200,7 +1191,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* @param uri * @param uri
* the namespace 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 { throws IOException {
@ -1216,6 +1207,19 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
writer.write("\""); 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) protected void writeProcessingInstruction(ProcessingInstruction pi)
throws IOException { throws IOException {
// indent(); // indent();
@ -1259,12 +1263,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
writer.write(token); writer.write(token);
lastOutputNodeType = Node.TEXT_NODE; lastOutputNodeType = Node.TEXT_NODE;
lastChar = token.charAt(token.length() - 1);
} }
} else { } else {
lastOutputNodeType = Node.TEXT_NODE; lastOutputNodeType = Node.TEXT_NODE;
writer.write(text); writer.write(text);
lastChar = text.charAt(text.length() - 1);
} }
} }
} }
@ -1289,7 +1291,6 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
lastOutputNodeType = Node.TEXT_NODE; lastOutputNodeType = Node.TEXT_NODE;
writer.write(text); 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 // try to register for lexical events
for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) { for (String lexicalHandlerName : LEXICAL_HANDLER_NAMES) {
try { try {
parent.setProperty(LEXICAL_HANDLER_NAMES[i], this); parent.setProperty(lexicalHandlerName, this);
break; break;
} catch (SAXNotRecognizedException ex) { } catch (SAXNotRecognizedException ex) {
@ -1481,26 +1482,24 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
writeNamespace(null, uri); writeNamespace(null, uri);
} }
} else { } else {
char quote = format.getAttributeQuoteCharacter(); writeAttribute(attribute);
writer.write(" ");
writer.write(attribute.getQualifiedName());
writer.write("=");
writer.write(quote);
writeEscapeAttributeEntities(attribute.getValue());
writer.write(quote);
} }
} }
} }
protected void writeAttribute(Attribute attribute) throws IOException { 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(" ");
writer.write(attribute.getQualifiedName()); writer.write(qualifiedName);
writer.write("="); writer.write("=");
char quote = format.getAttributeQuoteCharacter(); char quote = format.getAttributeQuoteCharacter();
writer.write(quote); writer.write(quote);
writeEscapeAttributeEntities(attribute.getValue()); writeEscapeAttributeEntities(value);
writer.write(quote); writer.write(quote);
lastOutputNodeType = Node.ATTRIBUTE_NODE; lastOutputNodeType = Node.ATTRIBUTE_NODE;
@ -1514,13 +1513,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
protected void writeAttribute(Attributes attributes, int index) protected void writeAttribute(Attributes attributes, int index)
throws IOException { throws IOException {
char quote = format.getAttributeQuoteCharacter(); writeAttribute(attributes.getQName(index), attributes.getValue(index));
writer.write(" ");
writer.write(attributes.getQName(index));
writer.write("=");
writer.write(quote);
writeEscapeAttributeEntities(attributes.getValue(index));
writer.write(quote);
} }
protected void indent() throws IOException { protected void indent() throws IOException {
@ -1543,12 +1536,9 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
*/ */
protected void writePrintln() throws IOException { protected void writePrintln() throws IOException {
if (format.isNewlines()) { 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. * Get an OutputStreamWriter, use preferred encoding.
@ -1647,44 +1637,37 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
String entity = null; String entity = null;
char c = text.charAt(i);
int c = text.codePointAt(i);
switch (c) { switch (c) {
case '<': case '<':
entity = "&lt;"; entity = "&lt;";
break; break;
case '>': case '>':
entity = "&gt;"; entity = "&gt;";
break; break;
case '&': case '&':
entity = "&amp;"; entity = "&amp;";
break; break;
case '\t': case '\t':
case '\n': case '\n':
case '\r': case '\r':
// don't encode standard whitespace characters // don't encode standard whitespace characters
if (preserve) { if (preserve) {
entity = String.valueOf(c); entity = String.valueOf((char) c);
} }
break; break;
default: default:
if ((c < 32) || shouldEncodeChar(c)) { if ((c < 32) || shouldEncodeChar(c)) {
entity = "&#" + (int) c + ";"; entity = "&#" + c + ";";
} }
break; break;
} }
if (entity != null) { if (entity != null) {
if (block == null) { if (block == null) {
block = text.toCharArray(); block = text.toCharArray();
@ -1693,6 +1676,12 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
buffer.append(block, last, i - last); buffer.append(block, last, i - last);
buffer.append(entity); buffer.append(entity);
last = i + 1; last = i + 1;
if (Character.isSupplementaryCodePoint(c)) {
last++;
}
}
if (Character.isSupplementaryCodePoint(c)) {
i++;
} }
} }
@ -1741,53 +1730,37 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
String entity = null; String entity = null;
char c = text.charAt(i); int c = text.codePointAt(i);
switch (c) { switch (c) {
case '<': case '<':
entity = "&lt;"; entity = "&lt;";
break; break;
case '>': case '>':
entity = "&gt;"; entity = "&gt;";
break; break;
case '\'': case '\'':
if (quote == '\'') { if (quote == '\'') {
entity = "&apos;"; entity = "&apos;";
} }
break; break;
case '\"': case '\"':
if (quote == '\"') { if (quote == '\"') {
entity = "&quot;"; entity = "&quot;";
} }
break; break;
case '&': case '&':
entity = "&amp;"; entity = "&amp;";
break; break;
case '\t': case '\t':
case '\n': case '\n':
case '\r': case '\r':
// don't encode standard whitespace characters // don't encode standard whitespace characters
break; break;
default: default:
if ((c < 32) || shouldEncodeChar(c)) { if ((c < 32) || shouldEncodeChar(c)) {
entity = "&#" + (int) c + ";"; entity = "&#" + c + ";";
} }
break; break;
} }
@ -1799,6 +1772,12 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
buffer.append(block, last, i - last); buffer.append(block, last, i - last);
buffer.append(entity); buffer.append(entity);
last = i + 1; last = i + 1;
if(Character.isSupplementaryCodePoint(c)) {
last++;
}
}
if(Character.isSupplementaryCodePoint(c)) {
i++;
} }
} }
@ -1824,15 +1803,15 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Should the given character be escaped. This depends on the encoding of * Should the given character be escaped. This depends on the encoding of
* the document. * the document.
* *
* @param c * @param codepoint Unicode codepoint.
* DOCUMENT ME! * DOCUMENT ME!
* *
* @return boolean * @return boolean
*/ */
protected boolean shouldEncodeChar(char c) { protected boolean shouldEncodeChar(int codepoint) {
int max = getMaximumAllowedCharacter(); int max = getMaximumAllowedCharacter();
return (max > 0) && (c > max); return (max > 0) && (codepoint > max);
} }
/** /**

2
fine-org-dom4j/src/main/java/org/dom4j/io/XPP3Reader.java

@ -37,7 +37,7 @@ import org.xmlpull.v1.XmlPullParserFactory;
* *
* @author <a href="mailto:pelle@neubia.com">Pelle Braendgaard </a> * @author <a href="mailto:pelle@neubia.com">Pelle Braendgaard </a>
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.3 $
*/ */
public class XPP3Reader { public class XPP3Reader {
/** <code>DocumentFactory</code> used to create new document objects */ /** <code>DocumentFactory</code> used to create new document objects */

2
fine-org-dom4j/src/main/java/org/dom4j/io/XPPReader.java

@ -37,7 +37,7 @@ import org.gjt.xpp.XmlPullParserFactory;
* </p> * </p>
* *
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a> * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.7 $
*/ */
public class XPPReader { public class XPPReader {
/** <code>DocumentFactory</code> used to create new document objects */ /** <code>DocumentFactory</code> used to create new document objects */

10
fine-org-dom4j/src/main/java/org/dom4j/io/package.html

@ -1,10 +0,0 @@
<html>
<head>
</head>
<body>
<p>Provides input and output via SAX and DOM together with writing <i>dom4j</i>
objects to streams as XML text.</p>
</body>
</html>

12
fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBModifier.java

@ -51,7 +51,7 @@ public class JAXBModifier extends JAXBSupport {
private OutputFormat outputFormat; private OutputFormat outputFormat;
private HashMap modifiers = new HashMap(); private HashMap<String, JAXBObjectModifier> modifiers = new HashMap<String, JAXBObjectModifier>();
/** /**
* Creates a new JAXBModifier for the given JAXB context path. This is the * 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 * 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. * org.dom4j.io.OutputFormat} will be used while writing the XML stream.
* *
* @param contextPath * @param contextPath
@ -441,13 +441,13 @@ public class JAXBModifier extends JAXBSupport {
modifier.resetModifiers(); modifier.resetModifiers();
Iterator modifierIt = modifiers.entrySet().iterator(); Iterator<Map.Entry<String, JAXBObjectModifier>> modifierIt = modifiers.entrySet().iterator();
while (modifierIt.hasNext()) { while (modifierIt.hasNext()) {
Map.Entry entry = (Map.Entry) modifierIt.next(); Map.Entry<String, JAXBObjectModifier> entry = modifierIt.next();
ElementModifier mod = new JAXBElementModifier(this, ElementModifier mod = new JAXBElementModifier(this,
(JAXBObjectModifier) entry.getValue()); entry.getValue());
getModifier().addModifier((String) entry.getKey(), mod); getModifier().addModifier(entry.getKey(), mod);
} }
modifier.setXMLWriter(getXMLWriter()); modifier.setXMLWriter(getXMLWriter());

6
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. * Reads an XML document and creates a DOM4J tree from SAX parsing events.
* {@link JAXBObjectHandler}objects can be registered to automatically receive * {@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 * implementations are notified when a certain element path is encountered
* *
* @author Wonne Keysers (Realsoftware.be) * @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 * 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 can find the generated XML classes. This package MUST contain
* jaxb.properties! * jaxb.properties!
* *
@ -333,7 +333,7 @@ public class JAXBReader extends JAXBSupport {
* Set to true when DOM4J elements must immediately be pruned from the tree. * Set to true when DOM4J elements must immediately be pruned from the tree.
* The {@link Document}will not be available afterwards! * The {@link Document}will not be available afterwards!
* *
* @param pruneElements * @param pruneElements DOCUMENT ME!
*/ */
public void setPruneElements(boolean pruneElements) { public void setPruneElements(boolean pruneElements) {
this.pruneElements = pruneElements; this.pruneElements = pruneElements;

8
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 * 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 can find the generated XML classes. This package MUST contain
* jaxb.properties!) * jaxb.properties!)
* *
@ -87,7 +87,7 @@ public class JAXBWriter extends JAXBSupport {
/** /**
* Creates a new JAXBWriter for the given JAXB context path, using the * 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. * org.dom4j.io.OutputFormat} will be used while writing the XML stream.
* *
* @param contextPath * @param contextPath
@ -148,7 +148,7 @@ public class JAXBWriter extends JAXBSupport {
* @param writer * @param writer
* writer to write to * writer to write to
* *
* @throws IOException * @throws IOException DOCUMENT ME!
*/ */
public void setOutput(Writer writer) throws IOException { public void setOutput(Writer writer) throws IOException {
getWriter().setWriter(writer); getWriter().setWriter(writer);
@ -185,7 +185,7 @@ public class JAXBWriter extends JAXBSupport {
* {@link javax.xml.bind.Element}instances can be created using the * {@link javax.xml.bind.Element}instances can be created using the
* ObjectFactory that is generated by the JAXB compiler. * ObjectFactory that is generated by the JAXB compiler.
* *
* @param jaxbObject * @param jaxbObject DOCUMENT ME!
* *
* @throws IOException * @throws IOException
* if an error occured while writing the output * if an error occured while writing the output

10
fine-org-dom4j/src/main/java/org/dom4j/package.html

@ -1,10 +0,0 @@
<html>
<head>
</head>
<body>
<p>Defines the XML Document Object Model in Java interfaces together
with some helper classes.</p>
</body>
</html>

2
fine-org-dom4j/src/main/java/org/dom4j/rule/Action.java

@ -16,7 +16,7 @@ import org.dom4j.Node;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.7 $
*/ */
public interface Action { public interface Action {
void run(Node node) throws Exception; void run(Node node) throws Exception;

16
fine-org-dom4j/src/main/java/org/dom4j/rule/Mode.java

@ -24,16 +24,16 @@ import org.dom4j.Node;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.9 $
*/ */
public class Mode { public class Mode {
private RuleSet[] ruleSets = new RuleSet[Pattern.NUMBER_OF_TYPES]; private RuleSet[] ruleSets = new RuleSet[Pattern.NUMBER_OF_TYPES];
/** Map of exact (local) element names to RuleSet instances */ /** Map of exact (local) element names to RuleSet instances */
private Map elementNameRuleSets; private Map<String, RuleSet> elementNameRuleSets;
/** Map of exact (local) attribute names to RuleSet instances */ /** Map of exact (local) attribute names to RuleSet instances */
private Map attributeNameRuleSets; private Map<String, RuleSet> attributeNameRuleSets;
public Mode() { public Mode() {
} }
@ -240,12 +240,12 @@ public class Mode {
* *
* @return the Map (which will be created if the given map was null * @return the Map (which will be created if the given map was null
*/ */
protected Map addToNameMap(Map map, String name, Rule rule) { protected Map<String, RuleSet> addToNameMap(Map<String, RuleSet> map, String name, Rule rule) {
if (map == null) { if (map == null) {
map = new HashMap(); map = new HashMap<String, RuleSet>();
} }
RuleSet ruleSet = (RuleSet) map.get(name); RuleSet ruleSet = map.get(name);
if (ruleSet == null) { if (ruleSet == null) {
ruleSet = new RuleSet(); ruleSet = new RuleSet();
@ -257,9 +257,9 @@ public class Mode {
return map; return map;
} }
protected void removeFromNameMap(Map map, String name, Rule rule) { protected void removeFromNameMap(Map<String, RuleSet> map, String name, Rule rule) {
if (map != null) { if (map != null) {
RuleSet ruleSet = (RuleSet) map.get(name); RuleSet ruleSet = map.get(name);
if (ruleSet != null) { if (ruleSet != null) {
ruleSet.removeRule(rule); ruleSet.removeRule(rule);

2
fine-org-dom4j/src/main/java/org/dom4j/rule/NullAction.java

@ -15,7 +15,7 @@ import org.dom4j.Node;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.7 $
*/ */
public class NullAction implements Action { public class NullAction implements Action {
/** Singleton instance */ /** Singleton instance */

2
fine-org-dom4j/src/main/java/org/dom4j/rule/Pattern.java

@ -17,7 +17,7 @@ import org.dom4j.NodeFilter;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.6 $
*/ */
public interface Pattern extends NodeFilter { public interface Pattern extends NodeFilter {
// These node numbers are compatable with DOM4J's Node types // These node numbers are compatable with DOM4J's Node types

79
fine-org-dom4j/src/main/java/org/dom4j/rule/Rule.java

@ -16,25 +16,37 @@ import org.dom4j.Node;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.7 $
*/
public class Rule implements Comparable<Rule> {
/**
* Holds value of property mode.
*/ */
public class Rule implements Comparable {
/** Holds value of property mode. */
private String mode; private String mode;
/** Holds value of property importPrecedence. */ /**
* Holds value of property importPrecedence.
*/
private int importPrecedence; private int importPrecedence;
/** Holds value of property priority. */ /**
* Holds value of property priority.
*/
private double priority; private double priority;
/** Holds value of property appearenceCount. */ /**
* Holds value of property appearenceCount.
*/
private int appearenceCount; private int appearenceCount;
/** Holds value of property pattern. */ /**
* Holds value of property pattern.
*/
private Pattern pattern; private Pattern pattern;
/** Holds value of property action. */ /**
* Holds value of property action.
*/
private Action action; private Action action;
public Rule() { public Rule() {
@ -55,10 +67,8 @@ public class Rule implements Comparable {
* Constructs a new Rule with the same instance data as the given rule but a * Constructs a new Rule with the same instance data as the given rule but a
* different pattern. * different pattern.
* *
* @param that * @param that DOCUMENT ME!
* DOCUMENT ME! * @param pattern DOCUMENT ME!
* @param pattern
* DOCUMENT ME!
*/ */
public Rule(Rule that, Pattern pattern) { public Rule(Rule that, Pattern pattern) {
this.mode = that.mode; this.mode = that.mode;
@ -81,31 +91,21 @@ public class Rule implements Comparable {
return importPrecedence + appearenceCount; 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 * Compares two rules in XSLT processing model order assuming that the modes
* are equal. * are equal.
* *
* @param that * @param that DOCUMENT ME!
* DOCUMENT ME!
*
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
public int compareTo(Rule that) { public int compareTo(Rule that) {
int answer = this.importPrecedence - that.importPrecedence; int answer = compareInt(this.importPrecedence, that.importPrecedence);
if (answer == 0) { if (answer == 0) {
answer = (int) Math.round(this.priority - that.priority); answer = Double.compare(this.priority, that.priority);
if (answer == 0) { if (answer == 0) {
answer = this.appearenceCount - that.appearenceCount; answer = compareInt(this.appearenceCount, that.appearenceCount);
} }
} }
@ -120,9 +120,7 @@ public class Rule implements Comparable {
/** /**
* DOCUMENT ME! * DOCUMENT ME!
* *
* @param node * @param node DOCUMENT ME!
* DOCUMENT ME!
*
* @return true if the pattern matches the given DOM4J node. * @return true if the pattern matches the given DOM4J node.
*/ */
public final boolean matches(Node node) { public final boolean matches(Node node) {
@ -190,8 +188,7 @@ public class Rule implements Comparable {
/** /**
* Setter for property mode. * Setter for property mode.
* *
* @param mode * @param mode New value of property mode.
* New value of property mode.
*/ */
public void setMode(String mode) { public void setMode(String mode) {
this.mode = mode; this.mode = mode;
@ -209,8 +206,7 @@ public class Rule implements Comparable {
/** /**
* Setter for property importPrecedence. * Setter for property importPrecedence.
* *
* @param importPrecedence * @param importPrecedence New value of property importPrecedence.
* New value of property importPrecedence.
*/ */
public void setImportPrecedence(int importPrecedence) { public void setImportPrecedence(int importPrecedence) {
this.importPrecedence = importPrecedence; this.importPrecedence = importPrecedence;
@ -228,8 +224,7 @@ public class Rule implements Comparable {
/** /**
* Setter for property priority. * Setter for property priority.
* *
* @param priority * @param priority New value of property priority.
* New value of property priority.
*/ */
public void setPriority(double priority) { public void setPriority(double priority) {
this.priority = priority; this.priority = priority;
@ -247,8 +242,7 @@ public class Rule implements Comparable {
/** /**
* Setter for property appearenceCount. * Setter for property appearenceCount.
* *
* @param appearenceCount * @param appearenceCount New value of property appearenceCount.
* New value of property appearenceCount.
*/ */
public void setAppearenceCount(int appearenceCount) { public void setAppearenceCount(int appearenceCount) {
this.appearenceCount = appearenceCount; this.appearenceCount = appearenceCount;
@ -266,8 +260,7 @@ public class Rule implements Comparable {
/** /**
* Setter for property pattern. * Setter for property pattern.
* *
* @param pattern * @param pattern New value of property pattern.
* New value of property pattern.
*/ */
public void setPattern(Pattern pattern) { public void setPattern(Pattern pattern) {
this.pattern = pattern; this.pattern = pattern;
@ -285,12 +278,16 @@ public class Rule implements Comparable {
/** /**
* Setter for property action. * Setter for property action.
* *
* @param action * @param action New value of property action.
* New value of property action.
*/ */
public void setAction(Action action) { public void setAction(Action action) {
this.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);
}
} }
/* /*

16
fine-org-dom4j/src/main/java/org/dom4j/rule/RuleManager.java

@ -21,11 +21,11 @@ import org.dom4j.rule.pattern.NodeTypePattern;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.9 $
*/ */
public class RuleManager { public class RuleManager {
/** Map of modes indexed by mode */ /** Map of modes indexed by mode */
private HashMap modes = new HashMap(); private HashMap<String, Mode> modes = new HashMap<String, Mode>();
/** /**
* A counter so that rules can be ordered by the order in which they were * 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. * then it will be created.
*/ */
public Mode getMode(String modeName) { public Mode getMode(String modeName) {
Mode mode = (Mode) modes.get(modeName); Mode mode = modes.get(modeName);
if (mode == null) { if (mode == null) {
mode = createMode(); mode = createMode();
@ -66,8 +66,8 @@ public class RuleManager {
Rule[] childRules = rule.getUnionRules(); Rule[] childRules = rule.getUnionRules();
if (childRules != null) { if (childRules != null) {
for (int i = 0, size = childRules.length; i < size; i++) { for (Rule childRule : childRules) {
mode.addRule(childRules[i]); mode.addRule(childRule);
} }
} else { } else {
mode.addRule(rule); mode.addRule(rule);
@ -79,8 +79,8 @@ public class RuleManager {
Rule[] childRules = rule.getUnionRules(); Rule[] childRules = rule.getUnionRules();
if (childRules != null) { if (childRules != null) {
for (int i = 0, size = childRules.length; i < size; i++) { for (Rule childRule : childRules) {
mode.removeRule(childRules[i]); mode.removeRule(childRule);
} }
} else { } else {
mode.removeRule(rule); mode.removeRule(rule);
@ -99,7 +99,7 @@ public class RuleManager {
* @return the matching Rule or no rule if none matched * @return the matching Rule or no rule if none matched
*/ */
public Rule getMatchingRule(String modeName, Node node) { public Rule getMatchingRule(String modeName, Node node) {
Mode mode = (Mode) modes.get(modeName); Mode mode = modes.get(modeName);
if (mode != null) { if (mode != null) {
return mode.getMatchingRule(node); return mode.getMatchingRule(node);

4
fine-org-dom4j/src/main/java/org/dom4j/rule/RuleSet.java

@ -21,11 +21,11 @@ import org.dom4j.Node;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.10 $
*/ */
public class RuleSet { public class RuleSet {
/** An unordered list of Rule objects */ /** An unordered list of Rule objects */
private ArrayList rules = new ArrayList(); private ArrayList<Rule> rules = new ArrayList<Rule>();
/** A lazily evaluated and cached array of rules sorted */ /** A lazily evaluated and cached array of rules sorted */
private Rule[] ruleArray; private Rule[] ruleArray;

188
fine-org-dom4j/src/main/java/org/dom4j/rule/Stylesheet.java

@ -7,13 +7,9 @@
package org.dom4j.rule; package org.dom4j.rule;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.dom4j.Document; import org.dom4j.*;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.XPath;
/** /**
* <p> * <p>
@ -23,7 +19,7 @@ import org.dom4j.XPath;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.14 $
*/ */
public class Stylesheet { public class Stylesheet {
private RuleManager ruleManager = new RuleManager(); private RuleManager ruleManager = new RuleManager();
@ -57,39 +53,13 @@ public class Stylesheet {
ruleManager.removeRule(rule); ruleManager.removeRule(rule);
} }
/** public void run(List<Node> list) throws Exception {
* 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 {
run(list, this.modeName); run(list, this.modeName);
} }
public void run(List list, String mode) throws Exception { public void run(List<Node> list, String mode) throws Exception {
for (int i = 0, size = list.size(); i < size; i++) { for (Node node : list) {
Object object = list.get(i); run(node, mode);
if (object instanceof Node) {
run((Node) object, mode);
}
} }
} }
@ -134,56 +104,52 @@ public class Stylesheet {
throws Exception { throws Exception {
Mode mod = ruleManager.getMode(mode); Mode mod = ruleManager.getMode(mode);
List list = xpath.selectNodes(input); List<Node> list = xpath.selectNodes(input);
Iterator it = list.iterator(); for (Node current : list) {
while (it.hasNext()) {
Node current = (Node) it.next();
mod.fireRule(current); mod.fireRule(current);
} }
} }
/** /**
* Processes the result of the xpath expression. The xpath expression is * If input is a <code>Node</code>, this will processes all of the
* evaluated against the provided input object. * children of that node. If input is a <code>List</code> of
* <code>Nodes</code>s, these nodes will be iterated and all children of
* each node will be processed.
* *
* @param input * @param node the input object
* the input object
* @param xpath
* the xpath expression
* @throws Exception * @throws Exception
* if something goes wrong * if something goes wrong
* @deprecated Use {@link Stylesheet#applyTemplates(Object, XPath)}instead.
*/ */
public void applyTemplates(Object input, org.jaxen.XPath xpath) public void applyTemplates(Node node) throws Exception {
throws Exception { applyTemplates(node, this.modeName);
applyTemplates(input, xpath, this.modeName);
} }
/** /**
* Processes the result of the xpath expression in the given mode. The xpath * If input is a <code>Node</code>, this will processes all of the
* expression is evaluated against the provided input object. * children of that node. If input is a <code>List</code> of
* <code>Nodes</code>s, these nodes will be iterated and all children of
* each node will be processed.
* *
* @param input * @param element the input object
* the input object
* @param xpath
* the xpath expression
* @param mode
* the mode
* @throws Exception * @throws Exception
* if something goes wrong * if something goes wrong
* @deprecated Use {@link Stylesheet#applyTemplates(Object, XPath, String)}
* instead.
*/ */
public void applyTemplates(Object input, org.jaxen.XPath xpath, String mode) public void applyTemplates(Element element) throws Exception {
throws Exception { applyTemplates(element, this.modeName);
Mode mod = ruleManager.getMode(mode);
List list = xpath.selectNodes(input);
Iterator it = list.iterator();
while (it.hasNext()) {
Node current = (Node) it.next();
mod.fireRule(current);
} }
/**
* If input is a <code>Node</code>, this will processes all of the
* children of that node. If input is a <code>List</code> of
* <code>Nodes</code>s, 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);
} }
/** /**
@ -192,14 +158,12 @@ public class Stylesheet {
* <code>Nodes</code>s, these nodes will be iterated and all children of * <code>Nodes</code>s, these nodes will be iterated and all children of
* each node will be processed. * each node will be processed.
* *
* @param input * @param list the input object
* the input object, this can either be a <code>Node</code> or
* a <code>List</code>
* @throws Exception * @throws Exception
* if something goes wrong * if something goes wrong
*/ */
public void applyTemplates(Object input) throws Exception { public void applyTemplates(List<Node> list) throws Exception {
applyTemplates(input, this.modeName); applyTemplates(list, this.modeName);
} }
/** /**
@ -208,42 +172,82 @@ public class Stylesheet {
* node. If input is a <code>List</code> of <code>Nodes</code>s, these * node. If input is a <code>List</code> of <code>Nodes</code>s, these
* nodes will be iterated and all children of each node will be processed. * nodes will be iterated and all children of each node will be processed.
* *
* @param input * @param node the input object
* the input object, this can either be a <code>Node</code> or * @param mode
* a <code>List</code> * 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
* <code>Node</code>, this will processes all of the children of that
* node. If input is a <code>List</code> of <code>Nodes</code>s, these
* nodes will be iterated and all children of each node will be processed.
*
* @param element the input object
* @param mode * @param mode
* the mode * the mode
* @throws Exception * @throws Exception
* if something goes wrong * 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); Mode mod = ruleManager.getMode(mode);
if (input instanceof Element) {
// iterate through all children // iterate through all children
Element element = (Element) input;
for (int i = 0, size = element.nodeCount(); i < size; i++) { for (int i = 0, size = element.nodeCount(); i < size; i++) {
Node node = element.node(i); Node node = element.node(i);
mod.fireRule(node); mod.fireRule(node);
} }
} else if (input instanceof Document) { }
/**
* Processes the input object in the given mode. If input is a
* <code>Node</code>, this will processes all of the children of that
* node. If input is a <code>List</code> of <code>Nodes</code>s, 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 // iterate through all children
Document document = (Document) input;
for (int i = 0, size = document.nodeCount(); i < size; i++) { for (int i = 0, size = document.nodeCount(); i < size; i++) {
Node node = document.node(i); Node node = document.node(i);
mod.fireRule(node); mod.fireRule(node);
} }
} else if (input instanceof List) {
List list = (List) input;
for (int i = 0, size = list.size(); i < size; i++) {
Object object = list.get(i);
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
* <code>Node</code>, this will processes all of the children of that
* node. If input is a <code>List</code> of <code>Nodes</code>s, 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);
} }
} }
} }

14
fine-org-dom4j/src/main/java/org/dom4j/rule/package.html

@ -1,14 +0,0 @@
<html>
<head>
</head>
<body>
<p>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.
</p>
</body>
</html>

2
fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/DefaultPattern.java

@ -22,7 +22,7 @@ import org.dom4j.rule.Pattern;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.6 $
*/ */
public class DefaultPattern implements Pattern { public class DefaultPattern implements Pattern {
private NodeFilter filter; private NodeFilter filter;

2
fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/NodeTypePattern.java

@ -17,7 +17,7 @@ import org.dom4j.rule.Pattern;
* </p> * </p>
* *
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$ * @version $Revision: 1.7 $
*/ */
public class NodeTypePattern implements Pattern { public class NodeTypePattern implements Pattern {
/** A pattern which matches any Attribute node */ /** A pattern which matches any Attribute node */

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save