Browse Source

Pull request #8922: REPORT-95578 dom4j升级

Merge in CORE/base-third from ~YUAN.WANG/base-third:feature/x to feature/x

* commit '77897381bdf10e912ba7610c840a1f820a5673c1':
  REPORT-95578 dom4j升级
feature/x
Yuan.Wang-王垣 1 year ago
parent
commit
f504e9f1fa
  1. 2
      fine-org-dom4j/README.md
  2. 194
      fine-org-dom4j/src/main/java/org/dom4j/Attribute.java
  3. 493
      fine-org-dom4j/src/main/java/org/dom4j/Branch.java
  4. 7
      fine-org-dom4j/src/main/java/org/dom4j/CDATA.java
  5. 7
      fine-org-dom4j/src/main/java/org/dom4j/CharacterData.java
  6. 7
      fine-org-dom4j/src/main/java/org/dom4j/Comment.java
  7. 17
      fine-org-dom4j/src/main/java/org/dom4j/Document.java
  8. 64
      fine-org-dom4j/src/main/java/org/dom4j/DocumentException.java
  9. 48
      fine-org-dom4j/src/main/java/org/dom4j/DocumentFactory.java
  10. 81
      fine-org-dom4j/src/main/java/org/dom4j/DocumentHelper.java
  11. 17
      fine-org-dom4j/src/main/java/org/dom4j/DocumentType.java
  12. 1493
      fine-org-dom4j/src/main/java/org/dom4j/Element.java
  13. 7
      fine-org-dom4j/src/main/java/org/dom4j/ElementHandler.java
  14. 3
      fine-org-dom4j/src/main/java/org/dom4j/ElementPath.java
  15. 7
      fine-org-dom4j/src/main/java/org/dom4j/Entity.java
  16. 6
      fine-org-dom4j/src/main/java/org/dom4j/IllegalAddException.java
  17. 16
      fine-org-dom4j/src/main/java/org/dom4j/InvalidXPathException.java
  18. 10
      fine-org-dom4j/src/main/java/org/dom4j/Namespace.java
  19. 21
      fine-org-dom4j/src/main/java/org/dom4j/Node.java
  20. 7
      fine-org-dom4j/src/main/java/org/dom4j/NodeFilter.java
  21. 11
      fine-org-dom4j/src/main/java/org/dom4j/ProcessingInstruction.java
  22. 127
      fine-org-dom4j/src/main/java/org/dom4j/QName.java
  23. 7
      fine-org-dom4j/src/main/java/org/dom4j/Text.java
  24. 11
      fine-org-dom4j/src/main/java/org/dom4j/Visitor.java
  25. 6
      fine-org-dom4j/src/main/java/org/dom4j/VisitorSupport.java
  26. 473
      fine-org-dom4j/src/main/java/org/dom4j/XPath.java
  27. 6
      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. 4
      fine-org-dom4j/src/main/java/org/dom4j/bean/package-info.java
  34. 10
      fine-org-dom4j/src/main/java/org/dom4j/bean/package.html
  35. 2
      fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeAttribute.java
  36. 2
      fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeDocumentFactory.java
  37. 2
      fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeElement.java
  38. 10
      fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeElementFactory.java
  39. 2
      fine-org-dom4j/src/main/java/org/dom4j/datatype/InvalidSchemaException.java
  40. 15
      fine-org-dom4j/src/main/java/org/dom4j/datatype/NamedTypeResolver.java
  41. 75
      fine-org-dom4j/src/main/java/org/dom4j/datatype/SchemaParser.java
  42. 4
      fine-org-dom4j/src/main/java/org/dom4j/datatype/package-info.java
  43. 10
      fine-org-dom4j/src/main/java/org/dom4j/datatype/package.html
  44. 10
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMAttribute.java
  45. 2
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMAttributeNodeMap.java
  46. 10
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMCDATA.java
  47. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMComment.java
  48. 18
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMDocument.java
  49. 36
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMDocumentFactory.java
  50. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMDocumentType.java
  51. 15
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMElement.java
  52. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMEntityReference.java
  53. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMNamespace.java
  54. 35
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMNodeHelper.java
  55. 11
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMProcessingInstruction.java
  56. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMText.java
  57. 4
      fine-org-dom4j/src/main/java/org/dom4j/dom/package-info.java
  58. 10
      fine-org-dom4j/src/main/java/org/dom4j/dom/package.html
  59. 4
      fine-org-dom4j/src/main/java/org/dom4j/dtd/AttributeDecl.java
  60. 7
      fine-org-dom4j/src/main/java/org/dom4j/dtd/Decl.java
  61. 4
      fine-org-dom4j/src/main/java/org/dom4j/dtd/ElementDecl.java
  62. 4
      fine-org-dom4j/src/main/java/org/dom4j/dtd/ExternalEntityDecl.java
  63. 4
      fine-org-dom4j/src/main/java/org/dom4j/dtd/InternalEntityDecl.java
  64. 4
      fine-org-dom4j/src/main/java/org/dom4j/dtd/package-info.java
  65. 9
      fine-org-dom4j/src/main/java/org/dom4j/dtd/package.html
  66. 102
      fine-org-dom4j/src/main/java/org/dom4j/io/DOMDocumentResult.java
  67. 13
      fine-org-dom4j/src/main/java/org/dom4j/io/DOMReader.java
  68. 548
      fine-org-dom4j/src/main/java/org/dom4j/io/DOMSAXContentHandler.java
  69. 74
      fine-org-dom4j/src/main/java/org/dom4j/io/DOMWriter.java
  70. 24
      fine-org-dom4j/src/main/java/org/dom4j/io/DispatchHandler.java
  71. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/DocumentInputSource.java
  72. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/DocumentResult.java
  73. 10
      fine-org-dom4j/src/main/java/org/dom4j/io/DocumentSource.java
  74. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/ElementStack.java
  75. 174
      fine-org-dom4j/src/main/java/org/dom4j/io/HTMLWriter.java
  76. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/JAXPHelper.java
  77. 58
      fine-org-dom4j/src/main/java/org/dom4j/io/OutputFormat.java
  78. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/PruningElementStack.java
  79. 39
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXContentHandler.java
  80. 68
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXEventRecorder.java
  81. 54
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXHelper.java
  82. 18
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXModifier.java
  83. 1853
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXReader.java
  84. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXValidator.java
  85. 70
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXWriter.java
  86. 20
      fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventReader.java
  87. 26
      fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventWriter.java
  88. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/XMLResult.java
  89. 339
      fine-org-dom4j/src/main/java/org/dom4j/io/XMLWriter.java
  90. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/XPP3Reader.java
  91. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/XPPReader.java
  92. 4
      fine-org-dom4j/src/main/java/org/dom4j/io/package-info.java
  93. 10
      fine-org-dom4j/src/main/java/org/dom4j/io/package.html
  94. 12
      fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBModifier.java
  95. 6
      fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBReader.java
  96. 8
      fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBWriter.java
  97. 4
      fine-org-dom4j/src/main/java/org/dom4j/package-info.java
  98. 10
      fine-org-dom4j/src/main/java/org/dom4j/package.html
  99. 2
      fine-org-dom4j/src/main/java/org/dom4j/rule/Action.java
  100. 16
      fine-org-dom4j/src/main/java/org/dom4j/rule/Mode.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>

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

@ -8,131 +8,103 @@
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 is the <code>Namespace</code> to associate with this element
* */
* @param namespace void setNamespace(Namespace namespace);
* is the <code>Namespace</code> to associate with this element
*/
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
* * empty <code>String</code>
* @return the prefix of the <code>Namespace</code> of this element or an */
* empty <code>String</code> 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
* * empty <code>String</code>
* @return the URI for the <code>Namespace</code> of this element or an */
* empty <code>String</code> String getNamespaceURI();
*/
String getNamespaceURI();
/** /**
* <p> * Returns the fully qualified name of this element.
* Returns the fully qualified name of this element. *
* </p> * 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
* <p> * expression of the form
* This will be the same as the value returned from {@link Node#getName()} * <pre>
* if this element has no namespace attached to this element or an * getNamespacePrefix() + &quot;:&quot; + getName()
* expression of the form * </pre>
* * will be returned.
* <pre> *
* getNamespacePrefix() + &quot;:&quot; + getName() * @return the fully qualified name of the element
* </pre> */
* String getQualifiedName();
* will be returned.
* </p>
*
* @return the fully qualified name of the element
*/
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 is the new value of this attribute
* */
* @param value void setValue(String value);
* is the new value of this attribute
*/
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 the attribute data
* */
* @param data void setData(Object data);
* the attribute data
*/
void setData(Object data);
} }
/* /*

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

@ -11,306 +11,263 @@ 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.
* * @throws IndexOutOfBoundsException if the index is out of range (index &lt; 0 || index &gt;=
* @return the <code>Node</code> at the specified position. * {@link Branch#nodeCount()}).
* */
* @throws IndexOutOfBoundsException Node node(int index) throws IndexOutOfBoundsException;
* if the index is out of range (index &lt; 0 || index &gt;=
* {@link Branch#nodeCount()}).
*/
Node node(int index) throws IndexOutOfBoundsException;
/** /**
* 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
* * not a child node of this branch
* @return the index of the given node starting at 0 or -1 if the node is */
* not a child node of this branch int indexOf(Node node);
*/
int indexOf(Node node);
/** /**
* Returns the number of <code>Node</code> instances that this branch * Returns the number of <code>Node</code> instances that this branch
* contains. * contains.
* *
* @return the number of nodes this branch contains * @return the number of nodes this branch contains
*/ */
int nodeCount(); int nodeCount();
/** /**
* Returns the element of the given ID attribute value. If this tree is * Returns the element of the given ID attribute value. If this tree is
* 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<Node> content();
*/
List 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<Node> content);
void setContent(List 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);
/** /**
* Clears the content for this branch, removing any <code>Node</code> * Clears the content for this branch, removing any <code>Node</code>
* instances this branch may contain. * instances this branch may contain.
*/ */
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<ProcessingInstruction> processingInstructions();
*/
List 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!
* * @return a backed list of the processing instructions
* @param target */
* DOCUMENT ME! List<ProcessingInstruction> processingInstructions(String target);
*
* @return a backed list of the processing instructions
*/
List 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);
/** /**
* 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<ProcessingInstruction> listOfPIs);
void setProcessingInstructions(List 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);
/** /**
* 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);
/** /**
* 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 * @return the newly added <code>Element</code> node.
* is the URI of the namespace to use */
* Element addElement(String qualifiedName, String namespaceURI);
* @return the newly added <code>Element</code> node.
*/
Element addElement(String qualifiedName, String namespaceURI);
/** /**
* 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);
/** /**
* Adds the given <code>Node</code> or throws {@link IllegalAddException} * Adds the given <code>Node</code> or throws {@link IllegalAddException}
* if the given node is not of a valid type. This is a polymorphic method * if the given node is not of a valid type. This is a polymorphic method
* 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);
/** /**
* Adds the given <code>Comment</code> to this branch. If the given node * Adds the given <code>Comment</code> to this branch. If the given 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);
/** /**
* Adds the given <code>Element</code> to this branch. If the given node * Adds the given <code>Element</code> to this branch. If the given 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);
/** /**
* Adds the given <code>ProcessingInstruction</code> to this branch. If * Adds the given <code>ProcessingInstruction</code> to this branch. If
* 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);
/** /**
* Removes the given <code>Node</code> if the node is an immediate child * Removes the given <code>Node</code> if the node is an immediate child
* of this branch. If the given node is not an immediate child of this * 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. This * branch then the {@link Node#detach()}method should be used instead. This
* 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);
/** /**
* Removes the given <code>Comment</code> if the node is an immediate * Removes the given <code>Comment</code> if the node is an immediate
* 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);
/** /**
* Removes the given <code>Element</code> if the node is an immediate * Removes the given <code>Element</code> if the node is an immediate
* 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);
/** /**
* Removes the given <code>ProcessingInstruction</code> if the node is an * Removes the given <code>ProcessingInstruction</code> if the node is an
* immediate child of this branch. If the given node is not an immediate * immediate 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 * 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);
/** /**
* Puts all <code>Text</code> nodes in the full depth of the sub-tree * Puts all <code>Text</code> nodes in the full depth of the sub-tree
* underneath this <code>Node</code>, including attribute nodes, into a * underneath this <code>Node</code>, including attribute nodes, into a
* "normal" form where only structure (e.g., elements, comments, processing * "normal" form where only structure (e.g., elements, comments, processing
* instructions, CDATA sections, and entity references) separates * instructions, CDATA sections, and entity references) separates
* <code>Text</code> nodes, i.e., there are neither adjacent * <code>Text</code> nodes, i.e., there are neither adjacent
* <code>Text</code> nodes nor empty <code>Text</code> nodes. This can * <code>Text</code> nodes nor empty <code>Text</code> nodes. This can
* be used to ensure that the DOM view of a document is the same as if it * be used to ensure that the DOM view of a document is the same as if it
* were saved and re-loaded, and is useful when operations (such as XPointer * were saved and re-loaded, and is useful when operations (such as XPointer
* lookups) that depend on a particular document tree structure are to be * lookups) that depend on a particular document tree structure are to be
* used.In cases where the document contains <code>CDATASections</code>, * used.In cases where the document contains <code>CDATASections</code>,
* the normalize operation alone may not be sufficient, since XPointers do * the normalize operation alone may not be sufficient, since XPointers do
* not differentiate between <code>Text</code> nodes and * not differentiate between <code>Text</code> nodes and
* <code>CDATASection</code> nodes. * <code>CDATASection</code> nodes.
* *
* @since DOM Level 2 * @since DOM Level 2
*/ */
void normalize(); void normalize();
} }
/* /*

7
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 {
} }

7
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

7
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 {
} }

17
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,15 +123,13 @@ 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.
* *

64
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);
}
} }
} }

48
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,18 +80,16 @@ 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
*/ */
public static synchronized DocumentFactory getInstance() { public static synchronized DocumentFactory getInstance() {
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);

81
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);
} }
@ -107,12 +107,12 @@ public final class DocumentHelper {
* XPath <code>XPath</code> instance using the singleton {@link * XPath <code>XPath</code> instance using the singleton {@link
* DocumentFactory}. * DocumentFactory}.
* </p> * </p>
* *
* @param xpathExpression * @param xpathExpression
* is the XPath expression to create * is the XPath expression to create
* *
* @return a new <code>XPath</code> instance * @return a new <code>XPath</code> instance
* *
* @throws InvalidXPathException * @throws InvalidXPathException
* if the XPath expression is invalid * if the XPath expression is invalid
*/ */
@ -127,14 +127,14 @@ public final class DocumentHelper {
* XPath <code>XPath</code> instance using the singleton {@link * XPath <code>XPath</code> instance using the singleton {@link
* DocumentFactory}. * DocumentFactory}.
* </p> * </p>
* *
* @param xpathExpression * @param xpathExpression
* is the XPath expression to create * is the XPath expression to create
* @param context * @param context
* is the variable context to use when evaluating the XPath * is the variable context to use when evaluating the XPath
* *
* @return a new <code>XPath</code> instance * @return a new <code>XPath</code> instance
* *
* @throws InvalidXPathException * @throws InvalidXPathException
* if the XPath expression is invalid * if the XPath expression is invalid
*/ */
@ -150,10 +150,10 @@ public final class DocumentHelper {
* filter expressions occur within XPath expressions such as * filter expressions occur within XPath expressions such as
* <code>self::node()[ filterExpression ]</code> * <code>self::node()[ filterExpression ]</code>
* </p> * </p>
* *
* @param xpathFilterExpression * @param xpathFilterExpression
* is the XPath filter expression to create * is the XPath filter expression to create
* *
* @return a new <code>NodeFilter</code> instance * @return a new <code>NodeFilter</code> instance
*/ */
public static NodeFilter createXPathFilter(String xpathFilterExpression) { public static NodeFilter createXPathFilter(String xpathFilterExpression) {
@ -166,10 +166,10 @@ public final class DocumentHelper {
* an XSLT style {@link Pattern}instance which can then be used in an XSLT * an XSLT style {@link Pattern}instance which can then be used in an XSLT
* processing model. * processing model.
* </p> * </p>
* *
* @param xpathPattern * @param xpathPattern
* is the XPath pattern expression to create * is the XPath pattern expression to create
* *
* @return a new <code>Pattern</code> instance * @return a new <code>Pattern</code> instance
*/ */
public static Pattern createPattern(String xpathPattern) { public static Pattern createPattern(String xpathPattern) {
@ -182,15 +182,15 @@ public final class DocumentHelper {
* {@link List}of {@link Node}instances appending all the results together * {@link List}of {@link Node}instances appending all the results together
* into a single list. * into a single list.
* </p> * </p>
* *
* @param xpathFilterExpression * @param xpathFilterExpression
* is the XPath filter expression to evaluate * is the XPath filter expression to evaluate
* @param nodes * @param nodes
* is the list of nodes on which to evalute the XPath * is the list of nodes on which to evalute the 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
*/ */
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);
@ -202,15 +202,15 @@ public final class DocumentHelper {
* {@link List}of {@link Node}instances appending all the results together * {@link List}of {@link Node}instances appending all the results together
* into a single list. * into a single list.
* </p> * </p>
* *
* @param xpathFilterExpression * @param xpathFilterExpression
* is the XPath filter expression to evaluate * is the XPath filter expression to evaluate
* @param node * @param node
* is the Node on which to evalute the XPath * is the Node on which to evalute the 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
*/ */
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);
@ -221,13 +221,13 @@ public final class DocumentHelper {
* <code>sort</code> sorts the given List of Nodes using an XPath * <code>sort</code> sorts the given List of Nodes using an XPath
* expression as a {@link java.util.Comparator}. * expression as a {@link java.util.Comparator}.
* </p> * </p>
* *
* @param list * @param list
* is the list of Nodes to sort * is the list of Nodes to sort
* @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);
} }
@ -238,7 +238,7 @@ public final class DocumentHelper {
* expression as a {@link java.util.Comparator}and optionally removing * expression as a {@link java.util.Comparator}and optionally removing
* duplicates. * duplicates.
* </p> * </p>
* *
* @param list * @param list
* is the list of Nodes to sort * is the list of Nodes to sort
* @param expression * @param expression
@ -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);
} }
@ -257,25 +257,26 @@ public final class DocumentHelper {
* <code>parseText</code> parses the given text as an XML document and * <code>parseText</code> parses the given text as an XML document and
* 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
* *
* @return a newly parsed Document * @return a newly parsed Document
* *
* @throws DocumentException * @throws DocumentException
* 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
@ -322,14 +323,14 @@ public final class DocumentHelper {
* get the first child &lt;a&gt; element, which would be created if it did * get the first child &lt;a&gt; element, which would be created if it did
* not exist, then the next child &lt;b&gt; and so on until finally a * not exist, then the next child &lt;b&gt; and so on until finally a
* &lt;c&gt; element is returned. * &lt;c&gt; element is returned.
* *
* @param source * @param source
* is the Element or Document to start navigating from * is the Element or Document to start navigating from
* @param path * @param path
* is a simple path expression, seperated by '/' which denotes * is a simple path expression, seperated by '/' which denotes
* the path from the source to the resulting element such as * the path from the source to the resulting element such as
* a/b/c * a/b/c
* *
* @return the first Element on the given path which either already existed * @return the first Element on the given path which either already existed
* on the path or were created by this method. * on the path or were created by this method.
*/ */
@ -378,24 +379,24 @@ public final class DocumentHelper {
* Redistribution and use of this software and associated documentation * Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the * ("Software"), with or without modification, are permitted provided that the
* following conditions are met: * following conditions are met:
* *
* 1. Redistributions of source code must retain copyright statements and * 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document. * notices. Redistributions must also contain a copy of this document.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* 3. The name "DOM4J" must not be used to endorse or promote products derived * 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For * from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com. * written permission, please contact dom4j-info@metastuff.com.
* *
* 4. Products derived from this Software may not be called "DOM4J" nor may * 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff, * "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd. * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
* *
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
* *
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -407,6 +408,6 @@ public final class DocumentHelper {
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved. * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/ */

17
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);
} }
/* /*

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

File diff suppressed because it is too large Load Diff

7
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!

7
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 {
} }

6
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: 1.6 $
* @version $Revision$
*/ */
public class IllegalAddException extends IllegalArgumentException { public class IllegalAddException extends IllegalArgumentException {
public IllegalAddException(String reason) { public IllegalAddException(String reason) {

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

@ -8,29 +8,19 @@
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: 1.6 $
* @version $Revision$
*/ */
public class InvalidXPathException extends IllegalArgumentException { public class InvalidXPathException extends IllegalArgumentException {
/** The <code>serialVersionUID</code>. */ public InvalidXPathException(String xpath) {
private static final long serialVersionUID = 3257009869058881592L;
public InvalidXPathException(String xpath) {
super("Invalid XPath expression: " + xpath); super("Invalid XPath expression: " + xpath);
} }
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());
}
} }
/* /*

10
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);
}
} }
/** /**

21
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);
/** /**

7
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>

11
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);
} }

127
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));
}
}
} }
@ -292,4 +391,4 @@ public class QName implements Serializable {
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved. * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/ */

7
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 {
} }

11
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>

6
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() {

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

@ -7,304 +7,239 @@
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!
* * @return true if the given node matches this XPath expression
* @param node */
* DOCUMENT ME! boolean matches(Node node);
*
* @return true if the given node matches this XPath expression
*/
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 is either a node or a list of nodes on which to evalute the
* * XPath
* @param context * @return the value of the XPath expression as a {@link List}of {@link
* is either a node or a list of nodes on which to evalute the * Node} instances, a {@link Node}instance, a {@link String}or a
* XPath * {@link Number}instance depending on the XPath expression.
* */
* @return the value of the XPath expression as a {@link List}of {@link Object evaluate(Object context);
* Node} instances, a {@link Node}instance, a {@link String}or a
* {@link Number}instance depending on the XPath expression.
*/
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 is either a node or a list of nodes on which to evalute the
* * XPath
* @param context * @return the value of the XPath expression as a {@link List}of {@link
* is either a node or a list of nodes on which to evalute the * Node} instances, a {@link Node}instance, a {@link String}or a
* XPath * {@link Number}instance depending on the XPath expression.
* * @deprecated please use evaluate(Object) instead. WILL BE REMOVED IN
* @return the value of the XPath expression as a {@link List}of {@link * dom4j-1.6 !!
* Node} instances, a {@link Node}instance, a {@link String}or a */
* {@link Number}instance depending on the XPath expression. Object selectObject(Object context);
*
* @deprecated please use evaluate(Object) instead. WILL BE REMOVED IN
* dom4j-1.6 !!
*/
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 is either a node or a list of nodes on which to evalute the
* * XPath
* @param context * @return the results of all the XPath evaluations as a single list
* is either a node or a list of nodes on which to evalute the */
* XPath List<Node> selectNodes(Object context);
*
* @return the results of all the XPath evaluations as a single list
*/
List 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 is either a node or a list of nodes on which to evalute the
* * XPath
* @param context * @param sortXPath is the XPath expression to sort by
* is either a node or a list of nodes on which to evalute the * @return a list of <code>Node</code> instances
* XPath */
* @param sortXPath List<Node> selectNodes(Object context, XPath sortXPath);
* is the XPath expression to sort by
*
* @return a list of <code>Node</code> instances
*/
List 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 is either a node or a list of nodes on which to evalute the
* * XPath
* @param context * @param sortXPath is the XPath expression to sort by
* is either a node or a list of nodes on which to evalute the * @param distinct specifies whether or not duplicate values of the sort
* XPath * expression are allowed. If this parameter is true then only
* @param sortXPath * distinct sort expressions values are included in the result
* is the XPath expression to sort by * @return a list of <code>Node</code> instances
* @param distinct */
* specifies whether or not duplicate values of the sort List<Node> selectNodes(Object context, XPath sortXPath, boolean distinct);
* expression are allowed. If this parameter is true then only
* distinct sort expressions values are included in the result
*
* @return a list of <code>Node</code> instances
*/
List 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 is either a node or a list of nodes on which to evalute the
* * XPath
* @param context * @return a single matching <code>Node</code> instance
* is either a node or a list of nodes on which to evalute the */
* XPath Node selectSingleNode(Object context);
*
* @return a single matching <code>Node</code> instance
*/
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 is either a node or a list of nodes on which to evalute the
* * XPath
* @param context * @return the string representation of the results of the XPath expression
* is either a node or a list of nodes on which to evalute the */
* XPath String valueOf(Object context);
*
* @return the string representation of the results of the XPath expression
*/
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 is either a node or a list of nodes on which to evalute the
* * XPath
* @param context * @return the numeric result of the XPath expression or null if the result
* is either a node or a list of nodes on which to evalute the * is not a number.
* XPath */
* Number numberValueOf(Object context);
* @return the numeric result of the XPath expression or null if the result
* is not a number.
*/
Number numberValueOf(Object context);
/** /**
* Retrieve a boolean-value interpretation of this XPath expression when * 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 The node, nodeset or Context object for evaluation. This value
* * can be null
* @param context * @return The boolean-value interpretation of this expression.
* The node, nodeset or Context object for evaluation. This value * @since 1.5
* can be null */
* boolean booleanValueOf(Object context);
* @return The boolean-value interpretation of this expression.
*
* @since 1.5
*/
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 is the list of Nodes to sort
* */
* @param list void sort(List<Node> list);
* is the list of Nodes to sort
*/
void sort(List 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 is the list of Nodes to sort
* * @param distinct if true then duplicate values (using the sortXPath for
* @param list * comparisions) will be removed from the List
* is the list of Nodes to sort */
* @param distinct void sort(List<Node> list, boolean distinct);
* if true then duplicate values (using the sortXPath for
* comparisions) will be removed from the List
*/
void sort(List list, boolean distinct);
/** /**
* DOCUMENT ME! * DOCUMENT ME!
* *
* @return the current function context * @return the current function context
*/ */
FunctionContext getFunctionContext(); FunctionContext getFunctionContext();
/** /**
* 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);
/** /**
* DOCUMENT ME! * DOCUMENT ME!
* *
* @return the current namespace context * @return the current namespace context
*/ */
NamespaceContext getNamespaceContext(); NamespaceContext getNamespaceContext();
/** /**
* 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> * For example:
* * <pre>
* <p> * Map uris = new HashMap();
* For example: * uris.put("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/");
* * uris.put("m", "urn:xmethodsBabelFish");
* <pre> * XPath xpath = document
* Map uris = new HashMap(); * .createXPath("SOAP-ENV:Envelope/SOAP-ENV:Body/m:BabelFish");
* uris.put("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/"); * xpath.setNamespaceURIs(uris);
* uris.put("m", "urn:xmethodsBabelFish"); * Node babelfish = xpath.selectSingleNode(document);
* XPath xpath = document * </pre>
* .createXPath("SOAP-ENV:Envelope/SOAP-ENV:Body/m:BabelFish"); *
* xpath.setNamespaceURIs(uris); * @param map the map containing the namespace mappings
* Node babelfish = xpath.selectSingleNode(document); */
* </pre> void setNamespaceURIs(Map<String, String> map);
*
* </p>
*
* @param map
* the map containing the namespace mappings
*/
void setNamespaceURIs(Map map);
/** /**
* DOCUMENT ME! * DOCUMENT ME!
* *
* @return the current variable context * @return the current variable context
*/ */
VariableContext getVariableContext(); VariableContext getVariableContext();
/** /**
* 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);
} }
/* /*

6
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: 1.6 $
* @version $Revision$
*/ */
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) {

4
fine-org-dom4j/src/main/java/org/dom4j/bean/package-info.java

@ -0,0 +1,4 @@
/**
* An implementation of the <i>dom4j</i> API which allows JavaBeans to be used to store and retrieve attribute values from Element.
*/
package org.dom4j.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);

75
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,24 +209,25 @@ 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());
}
} }
} }
@ -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);
} }

4
fine-org-dom4j/src/main/java/org/dom4j/datatype/package-info.java

@ -0,0 +1,4 @@
/**
* 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.
*/
package org.dom4j.datatype;

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 */

36
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) {
} }
@ -66,12 +55,11 @@ public class DOMDocumentFactory extends DocumentFactory implements
* <p> * <p>
* Access to the singleton instance of this factory. * Access to the singleton instance of this factory.
* </p> * </p>
* *
* @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
@ -83,7 +71,7 @@ public class DOMDocumentFactory extends DocumentFactory implements
} }
public DocumentType createDocType(String name, String publicId, public DocumentType createDocType(String name, String publicId,
String systemId) { String systemId) {
return new DOMDocumentType(name, publicId, systemId); return new DOMDocumentType(name, publicId, systemId);
} }
@ -124,12 +112,12 @@ public class DOMDocumentFactory extends DocumentFactory implements
} }
public ProcessingInstruction createProcessingInstruction(String target, public ProcessingInstruction createProcessingInstruction(String target,
String data) { String data) {
return new DOMProcessingInstruction(target, data); return new DOMProcessingInstruction(target, data);
} }
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) {

4
fine-org-dom4j/src/main/java/org/dom4j/dom/package-info.java

@ -0,0 +1,4 @@
/**
* An implementation of the <i>dom4j</i> API which also supports the W3C object model.
*/
package org.dom4j.dom;

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;

7
fine-org-dom4j/src/main/java/org/dom4j/dtd/Decl.java

@ -0,0 +1,7 @@
package org.dom4j.dtd;
/**
* Created by filip on 5.7.15.
*/
public interface Decl {
}

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;

4
fine-org-dom4j/src/main/java/org/dom4j/dtd/package-info.java

@ -0,0 +1,4 @@
/**
* Classes to represent the DTD declarations. They are used inside the {@link org.dom4j.DocumentType} interface.
*/
package org.dom4j.dtd;

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>

102
fine-org-dom4j/src/main/java/org/dom4j/io/DOMDocumentResult.java

@ -0,0 +1,102 @@
/*
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*
* This software is open source.
* See the bottom of this file for the licence.
*/
package org.dom4j.io;
import javax.xml.transform.sax.SAXResult;
import org.w3c.dom.Document;
import org.xml.sax.ContentHandler;
import org.xml.sax.ext.LexicalHandler;
/**
* <p>
* <code>DOMDocumentResult</code> implements a JAXP {@link SAXResult} for a
* {@link org.w3c.dom.Document}.
* </p>
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @author Todd Wolff
* @version $Revision: 1.1 $
*/
public class DOMDocumentResult extends SAXResult {
private DOMSAXContentHandler contentHandler;
public DOMDocumentResult() {
this(new DOMSAXContentHandler());
}
public DOMDocumentResult(DOMSAXContentHandler contentHandler) {
this.contentHandler = contentHandler;
super.setHandler(this.contentHandler);
super.setLexicalHandler(this.contentHandler);
}
/**
* Retrieves w3c dom object generated via transformation
*
* @return the Document created by the transformation
*/
public Document getDocument() {
return contentHandler.getDocument();
}
// Overloaded methods
// -------------------------------------------------------------------------
public void setHandler(ContentHandler handler) {
if (handler instanceof DOMSAXContentHandler) {
this.contentHandler = (DOMSAXContentHandler) handler;
super.setHandler(this.contentHandler);
}
}
public void setLexicalHandler(LexicalHandler handler) {
if (handler instanceof DOMSAXContentHandler) {
this.contentHandler = (DOMSAXContentHandler) handler;
super.setLexicalHandler(this.contentHandler);
}
}
}
/*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com.
*
* 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
*
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
*
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/

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();

548
fine-org-dom4j/src/main/java/org/dom4j/io/DOMSAXContentHandler.java

@ -0,0 +1,548 @@
/*
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*
* This software is open source.
* See the bottom of this file for the licence.
*/
package org.dom4j.io;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.dom4j.Branch;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.dom.DOMAttribute;
import org.dom4j.dom.DOMCDATA;
import org.dom4j.dom.DOMComment;
import org.dom4j.dom.DOMDocumentFactory;
import org.dom4j.dom.DOMElement;
import org.dom4j.dom.DOMText;
import org.dom4j.tree.NamespaceStack;
import org.w3c.dom.ProcessingInstruction;
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.ext.Locator2;
import org.xml.sax.helpers.DefaultHandler;
/**
* <p>
* <code>SAXContentHandler</code> builds W3C DOM object via SAX events.
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @author Todd Wolff
*
* </p>
*/
public class DOMSAXContentHandler extends DefaultHandler implements LexicalHandler {
/** The factory used to create new <code>Document</code> instances */
private DOMDocumentFactory documentFactory;
/** The document that is being built */
private Document document;
/** stack of <code>Element</code> objects */
private ElementStack elementStack;
/** stack of <code>Namespace</code> and <code>QName</code> objects */
private NamespaceStack namespaceStack;
/** the Locator */
private Locator locator;
/** Flag used to indicate that we are inside a CDATA section */
private boolean insideCDATASection;
/**
* buffer to hold contents of cdata section across multiple characters
* events
*/
private StringBuffer cdataText;
/** The number of namespaces that are declared in the current scope */
private int declaredNamespaceIndex;
private InputSource inputSource;
/** The current element we are on */
private Element currentElement;
/** The entity resolver */
private EntityResolver entityResolver;
/** Whether adjacent text nodes should be merged */
private boolean mergeAdjacentText = false;
/** Have we added text to the buffer */
private boolean textInTextBuffer = false;
/** Should we ignore comments */
private boolean ignoreComments = false;
/** Buffer used to concatenate text together */
private StringBuffer textBuffer;
/** Holds value of property stripWhitespaceText. */
private boolean stripWhitespaceText = false;
public DOMSAXContentHandler() {
this((DOMDocumentFactory)DOMDocumentFactory.getInstance());
}
public DOMSAXContentHandler(DOMDocumentFactory documentFactory) {
this.documentFactory = documentFactory;
this.elementStack = createElementStack();
this.namespaceStack = new NamespaceStack(documentFactory);
}
/**
* Retrieves w3c document object built via generated sax events.
*
* @return the document that has been or is being built
*/
public org.w3c.dom.Document getDocument() {
if (document == null) {
document = createDocument();
}
return (org.w3c.dom.Document)document;
}
// ContentHandler interface
// -------------------------------------------------------------------------
public void setDocumentLocator(Locator documentLocator) {
this.locator = documentLocator;
}
public void processingInstruction(String target, String data)
throws SAXException {
if (mergeAdjacentText && textInTextBuffer) {
completeCurrentTextNode();
}
ProcessingInstruction pi = (ProcessingInstruction)documentFactory.createProcessingInstruction(target, data);
if (currentElement != null) {
((org.w3c.dom.Element)currentElement).appendChild(pi);
} else {
getDocument().appendChild(pi);
}
}
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
namespaceStack.push(prefix, uri);
}
public void endPrefixMapping(String prefix) throws SAXException {
namespaceStack.pop(prefix);
declaredNamespaceIndex = namespaceStack.size();
}
public void startDocument() throws SAXException {
document = null;
currentElement = null;
elementStack.clear();
namespaceStack.clear();
declaredNamespaceIndex = 0;
if (mergeAdjacentText && (textBuffer == null)) {
textBuffer = new StringBuffer();
}
textInTextBuffer = false;
}
public void endDocument() throws SAXException {
namespaceStack.clear();
elementStack.clear();
currentElement = null;
textBuffer = null;
}
public void startElement(String namespaceURI, String localName,
String qualifiedName, Attributes attributes) throws SAXException {
if (mergeAdjacentText && textInTextBuffer) {
completeCurrentTextNode();
}
QName qName = namespaceStack.getQName(namespaceURI, localName,
qualifiedName);
Branch branch = currentElement;
if (branch == null) {
branch = (org.dom4j.Document)getDocument();
}
Element element = new DOMElement(qName);
branch.add(element);
// add all declared namespaces
addDeclaredNamespaces(element);
// now lets add all attribute values
addAttributes(element, attributes);
elementStack.pushElement(element);
currentElement = element;
}
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
if (mergeAdjacentText && textInTextBuffer) {
completeCurrentTextNode();
}
elementStack.popElement();
currentElement = elementStack.peekElement();
}
public void characters(char[] ch, int start, int end) throws SAXException {
if (end == 0) {
return;
}
if (currentElement != null) {
if (insideCDATASection) {
if (mergeAdjacentText && textInTextBuffer) {
completeCurrentTextNode();
}
cdataText.append(new String(ch, start, end));
} else {
if (mergeAdjacentText) {
textBuffer.append(ch, start, end);
textInTextBuffer = true;
} else {
DOMText text = new DOMText(new String(ch, start, end));
((DOMElement)currentElement).add(text);
}
}
}
}
// ErrorHandler interface
// -------------------------------------------------------------------------
/**
* This method is called when a warning occurs during the parsing of the
* document. This method does nothing.
*
* @param exception
* DOCUMENT ME!
*
* @throws SAXException
* DOCUMENT ME!
*/
public void warning(SAXParseException exception) throws SAXException {
// ignore warnings by default
}
/**
* This method is called when an error is detected during parsing such as a
* validation error. This method rethrows the exception
*
* @param exception
* DOCUMENT ME!
*
* @throws SAXException
* DOCUMENT ME!
*/
public void error(SAXParseException exception) throws SAXException {
throw exception;
}
/**
* This method is called when a fatal error occurs during parsing. This
* method rethrows the exception
*
* @param exception
* DOCUMENT ME!
*
* @throws SAXException
* DOCUMENT ME!
*/
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
// LexicalHandler interface
// -------------------------------------------------------------------------
public void startDTD(String name, String publicId, String systemId)
throws SAXException {
// not supported
}
public void endDTD() throws SAXException {
// not supported
}
public void startEntity(String name) throws SAXException {
// not supported
}
public void endEntity(String name) throws SAXException {
// not supported
}
public void startCDATA() throws SAXException {
insideCDATASection = true;
cdataText = new StringBuffer();
}
public void endCDATA() throws SAXException {
insideCDATASection = false;
DOMCDATA cdata = new DOMCDATA(cdataText.toString());
((DOMElement)currentElement).add(cdata);
}
public void comment(char[] ch, int start, int end) throws SAXException {
if (!ignoreComments) {
if (mergeAdjacentText && textInTextBuffer) {
completeCurrentTextNode();
}
String text = new String(ch, start, end);
if (text.length() > 0) {
DOMComment domComment = new DOMComment(text);
if (currentElement != null) {
((DOMElement)currentElement).add(domComment);
} else {
getDocument().appendChild(domComment);
}
}
}
}
// Properties
// -------------------------------------------------------------------------
public ElementStack getElementStack() {
return elementStack;
}
public void setElementStack(ElementStack elementStack) {
this.elementStack = elementStack;
}
public EntityResolver getEntityResolver() {
return entityResolver;
}
public void setEntityResolver(EntityResolver entityResolver) {
this.entityResolver = entityResolver;
}
public InputSource getInputSource() {
return inputSource;
}
public void setInputSource(InputSource inputSource) {
this.inputSource = inputSource;
}
/**
* Returns whether adjacent text nodes should be merged together.
*
* @return Value of property mergeAdjacentText.
*/
public boolean isMergeAdjacentText() {
return mergeAdjacentText;
}
/**
* Sets whether or not adjacent text nodes should be merged together when
* parsing.
*
* @param mergeAdjacentText
* New value of property mergeAdjacentText.
*/
public void setMergeAdjacentText(boolean mergeAdjacentText) {
this.mergeAdjacentText = mergeAdjacentText;
}
/**
* Sets whether whitespace between element start and end tags should be
* ignored
*
* @return Value of property stripWhitespaceText.
*/
public boolean isStripWhitespaceText() {
return stripWhitespaceText;
}
/**
* Sets whether whitespace between element start and end tags should be
* ignored.
*
* @param stripWhitespaceText
* New value of property stripWhitespaceText.
*/
public void setStripWhitespaceText(boolean stripWhitespaceText) {
this.stripWhitespaceText = stripWhitespaceText;
}
/**
* Returns whether we should ignore comments or not.
*
* @return boolean
*/
public boolean isIgnoreComments() {
return ignoreComments;
}
/**
* Sets whether we should ignore comments or not.
*
* @param ignoreComments
* whether we should ignore comments or not.
*/
public void setIgnoreComments(boolean ignoreComments) {
this.ignoreComments = ignoreComments;
}
// Implementation methods
// -------------------------------------------------------------------------
protected void completeCurrentTextNode() {
if (stripWhitespaceText) {
boolean whitespace = true;
for (int i = 0, size = textBuffer.length(); i < size; i++) {
if (!Character.isWhitespace(textBuffer.charAt(i))) {
whitespace = false;
break;
}
}
if (!whitespace) {
DOMText domText = new DOMText(textBuffer.toString());
((DOMElement)currentElement).add(domText);
}
} else {
DOMText domText = new DOMText(textBuffer.toString());
((DOMElement)currentElement).add(domText);
}
textBuffer.setLength(0);
textInTextBuffer = false;
}
protected Document createDocument() {
String encoding = getEncoding();
Document doc = documentFactory.createDocument(encoding);
// set the EntityResolver
doc.setEntityResolver(entityResolver);
if (inputSource != null) {
doc.setName(inputSource.getSystemId());
}
return doc;
}
private String getEncoding() {
if (locator == null) {
return null;
}
if (locator instanceof Locator2) {
return ((Locator2) locator).getEncoding();
}
// couldn't determine encoding, returning null...
return null;
}
protected void addDeclaredNamespaces(Element element) {
for (int size = namespaceStack.size(); declaredNamespaceIndex < size;
declaredNamespaceIndex++) {
Namespace namespace = namespaceStack
.getNamespace(declaredNamespaceIndex);
String attributeName = attributeNameForNamespace(namespace);
((DOMElement)element).setAttribute(attributeName, namespace.getURI());
}
}
protected void addAttributes(Element element, Attributes attributes) {
int size = attributes.getLength();
for (int i = 0; i < size; i++) {
String attributeQName = attributes.getQName(i);
if (!attributeQName.startsWith("xmlns")) {
String attributeURI = attributes.getURI(i);
String attributeLocalName = attributes.getLocalName(i);
String attributeValue = attributes.getValue(i);
QName qName = namespaceStack.getAttributeQName(
attributeURI, attributeLocalName, attributeQName);
DOMAttribute domAttribute = new DOMAttribute(qName, attributeValue);
((DOMElement)element).setAttributeNode(domAttribute);
}
}
}
protected ElementStack createElementStack() {
return new ElementStack();
}
protected String attributeNameForNamespace(Namespace namespace) {
String xmlns = "xmlns";
String prefix = namespace.getPrefix();
if (prefix.length() > 0) {
return xmlns + ":" + prefix;
}
return xmlns;
}
}
/*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com.
*
* 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
*
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
*
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/

74
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;

10
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 */

174
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,29 +82,15 @@ 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) {
* StringWriter sw = new StringWriter(); * StringWriter sw = new StringWriter();
@ -147,13 +108,11 @@ 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) {
* StringWriter sw = new StringWriter(); * StringWriter sw = new StringWriter();
@ -171,22 +130,20 @@ import org.xml.sax.SAXException;
* return sw.toString(); * return sw.toString();
* } * }
* </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;
Iterator iter = newSet.iterator();
while (iter.hasNext()) { for (String aTag : newSet) {
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:
@ -519,29 +461,21 @@ 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() {

58
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,17 +304,12 @@ 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,12 +356,10 @@ 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,18 +374,14 @@ 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!
*/ */
public boolean isXHTML() { public boolean isXHTML() {
@ -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);

68
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;
@ -154,7 +147,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
// replay to LexicalHandler // replay to LexicalHandler
case SAXEvent.START_DTD: case SAXEvent.START_DTD:
((LexicalHandler) handler).startDTD((String) saxEvent ((LexicalHandler) handler).startDTD((String) saxEvent
.getParm(0), (String) saxEvent.getParm(1), .getParm(0), (String) saxEvent.getParm(1),
(String) saxEvent.getParm(2)); (String) saxEvent.getParm(2));
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;
@ -204,7 +197,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
case SAXEvent.ATTRIBUTE_DECL: case SAXEvent.ATTRIBUTE_DECL:
((DeclHandler) handler).attributeDecl((String) saxEvent ((DeclHandler) handler).attributeDecl((String) saxEvent
.getParm(0), (String) saxEvent.getParm(1), .getParm(0), (String) saxEvent.getParm(1),
(String) saxEvent.getParm(2), (String) saxEvent (String) saxEvent.getParm(2), (String) saxEvent
.getParm(3), (String) saxEvent.getParm(4)); .getParm(3), (String) saxEvent.getParm(4));
@ -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();
} }
} }
} }

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

@ -13,14 +13,16 @@ import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader; import org.xml.sax.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
* and XMLReader objects. * and XMLReader objects.
* </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;
@ -61,12 +63,21 @@ 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!
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
* *
* @throws SAXException * @throws SAXException
* 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;
} }
@ -110,12 +136,12 @@ class SAXHelper {
* This method attempts to use JAXP to locate the SAX2 XMLReader * This method attempts to use JAXP to locate the SAX2 XMLReader
* implementation. This method uses reflection to avoid being dependent * implementation. This method uses reflection to avoid being dependent
* directly on the JAXP classes. * directly on the JAXP classes.
* *
* @param validating * @param validating
* DOCUMENT ME! * DOCUMENT ME!
* @param namespaceAware * @param namespaceAware
* DOCUMENT ME! * DOCUMENT ME!
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
protected static XMLReader createXMLReaderViaJAXP(boolean validating, protected static XMLReader createXMLReaderViaJAXP(boolean validating,
@ -161,24 +187,24 @@ class SAXHelper {
* Redistribution and use of this software and associated documentation * Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the * ("Software"), with or without modification, are permitted provided that the
* following conditions are met: * following conditions are met:
* *
* 1. Redistributions of source code must retain copyright statements and * 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document. * notices. Redistributions must also contain a copy of this document.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* 3. The name "DOM4J" must not be used to endorse or promote products derived * 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For * from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com. * written permission, please contact dom4j-info@metastuff.com.
* *
* 4. Products derived from this Software may not be called "DOM4J" nor may * 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff, * "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd. * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
* *
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
* *
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -190,6 +216,6 @@ class SAXHelper {
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved. * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/ */

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());

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

File diff suppressed because it is too large Load Diff

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 */

70
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;

339
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
@ -54,7 +57,7 @@ import org.xml.sax.helpers.XMLFilterImpl;
* such as to allow suppression of the XML declaration, the encoding declaration * such as to allow suppression of the XML declaration, the encoding declaration
* or whether empty documents are collapsed. * or whether empty documents are collapsed.
* </p> * </p>
* *
* <p> * <p>
* There are <code>write(...)</code> methods to print any of the standard * There are <code>write(...)</code> methods to print any of the standard
* DOM4J classes, including <code>Document</code> and <code>Element</code>, * DOM4J classes, including <code>Document</code> and <code>Element</code>,
@ -63,10 +66,10 @@ import org.xml.sax.helpers.XMLFilterImpl;
* preferred character encoding to be ignored. If you use encodings other than * preferred character encoding to be ignored. If you use encodings other than
* UTF8, we recommend using the method that takes an OutputStream instead. * UTF8, we recommend using the method that takes an OutputStream instead.
* </p> * </p>
* *
* @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
@ -200,7 +203,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* DOCUMENT ME! * DOCUMENT ME!
* *
* @return true if text thats output should be escaped. This is enabled by * @return true if text thats output should be escaped. This is enabled by
* default. It could be disabled if the output format is textual, * default. It could be disabled if the output format is textual,
* like in XSLT where we can have xml, html or text output. * like in XSLT where we can have xml, html or text output.
@ -213,7 +216,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Sets whether text output should be escaped or not. This is enabled by * Sets whether text output should be escaped or not. This is enabled by
* default. It could be disabled if the output format is textual, like in * default. It could be disabled if the output format is textual, like in
* XSLT where we can have xml, html or text output. * XSLT where we can have xml, html or text output.
* *
* @param escapeText * @param escapeText
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -225,7 +228,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Set the initial indentation level. This can be used to output a document * Set the initial indentation level. This can be used to output a document
* (or, more likely, an element) starting at a given indent level, so it's * (or, more likely, an element) starting at a given indent level, so it's
* not always flush against the left margin. Default: 0 * not always flush against the left margin. Default: 0
* *
* @param indentLevel * @param indentLevel
* the number of indents to start with * the number of indents to start with
*/ */
@ -237,7 +240,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Returns the maximum allowed character code that should be allowed * Returns the maximum allowed character code that should be allowed
* unescaped which defaults to 127 in US-ASCII (7 bit) or 255 in ISO- (8 * unescaped which defaults to 127 in US-ASCII (7 bit) or 255 in ISO- (8
* bit). * bit).
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
public int getMaximumAllowedCharacter() { public int getMaximumAllowedCharacter() {
@ -254,7 +257,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* escape any characters (other than the special XML characters like &lt; * escape any characters (other than the special XML characters like &lt;
* &gt; &amp;) If this is not explicitly set then it is defaulted from the * &gt; &amp;) If this is not explicitly set then it is defaulted from the
* encoding. * encoding.
* *
* @param maximumAllowedCharacter * @param maximumAllowedCharacter
* The maximumAllowedCharacter to set * The maximumAllowedCharacter to set
*/ */
@ -264,7 +267,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Flushes the underlying Writer * Flushes the underlying Writer
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -274,7 +277,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Closes the underlying Writer * Closes the underlying Writer
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -284,7 +287,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the new line text to the underlying Writer * Writes the new line text to the underlying Writer
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -294,10 +297,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the given {@link Attribute}. * Writes the given {@link Attribute}.
* *
* @param attribute * @param attribute
* <code>Attribute</code> to output. * <code>Attribute</code> to output.
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -313,21 +316,21 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* <p> * <p>
* This will print the <code>Document</code> to the current Writer. * This will print the <code>Document</code> to the current Writer.
* </p> * </p>
* *
* <p> * <p>
* Warning: using your own Writer may cause the writer's preferred character * Warning: using your own Writer may cause the writer's preferred character
* encoding to be ignored. If you use encodings other than UTF8, we * encoding to be ignored. If you use encodings other than UTF8, we
* recommend using the method that takes an OutputStream instead. * recommend using the method that takes an OutputStream instead.
* </p> * </p>
* *
* <p> * <p>
* Note: as with all Writers, you may need to flush() yours after this * Note: as with all Writers, you may need to flush() yours after this
* method returns. * method returns.
* </p> * </p>
* *
* @param doc * @param doc
* <code>Document</code> to format. * <code>Document</code> to format.
* *
* @throws IOException * @throws IOException
* if there's any problem writing. * if there's any problem writing.
*/ */
@ -358,10 +361,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* s, and its value, and all its content (child nodes) to the current * s, and its value, and all its content (child nodes) to the current
* Writer. * Writer.
* </p> * </p>
* *
* @param element * @param element
* <code>Element</code> to output. * <code>Element</code> to output.
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -375,10 +378,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the given {@link CDATA}. * Writes the given {@link CDATA}.
* *
* @param cdata * @param cdata
* <code>CDATA</code> to output. * <code>CDATA</code> to output.
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -392,10 +395,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the given {@link Comment}. * Writes the given {@link Comment}.
* *
* @param comment * @param comment
* <code>Comment</code> to output. * <code>Comment</code> to output.
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -409,10 +412,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the given {@link DocumentType}. * Writes the given {@link DocumentType}.
* *
* @param docType * @param docType
* <code>DocumentType</code> to output. * <code>DocumentType</code> to output.
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -426,10 +429,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the given {@link Entity}. * Writes the given {@link Entity}.
* *
* @param entity * @param entity
* <code>Entity</code> to output. * <code>Entity</code> to output.
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -443,10 +446,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the given {@link Namespace}. * Writes the given {@link Namespace}.
* *
* @param namespace * @param namespace
* <code>Namespace</code> to output. * <code>Namespace</code> to output.
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -460,10 +463,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the given {@link ProcessingInstruction}. * Writes the given {@link ProcessingInstruction}.
* *
* @param processingInstruction * @param processingInstruction
* <code>ProcessingInstruction</code> to output. * <code>ProcessingInstruction</code> to output.
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -481,10 +484,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Print out a {@link String}, Perfoms the necessary entity escaping and * Print out a {@link String}, Perfoms the necessary entity escaping and
* whitespace stripping. * whitespace stripping.
* </p> * </p>
* *
* @param text * @param text
* is the text to output * is the text to output
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -498,10 +501,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the given {@link Text}. * Writes the given {@link Text}.
* *
* @param text * @param text
* <code>Text</code> to output. * <code>Text</code> to output.
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -515,10 +518,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the given {@link Node}. * Writes the given {@link Node}.
* *
* @param node * @param node
* <code>Node</code> to output. * <code>Node</code> to output.
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -533,10 +536,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the given object which should be a String, a Node or a List of * Writes the given object which should be a String, a Node or a List of
* Nodes. * Nodes.
* *
* @param object * @param object
* is the object to output. * is the object to output.
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -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);
@ -561,16 +564,17 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Writes the opening tag of an {@link Element}, including its {@link * Writes the opening tag of an {@link Element}, including its {@link
* Attribute}s but without its content. * Attribute}s but without its content.
* </p> * </p>
* *
* @param element * @param element
* <code>Element</code> to output. * <code>Element</code> to output.
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
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(">");
} }
@ -579,10 +583,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* <p> * <p>
* Writes the closing tag of an {@link Element} * Writes the closing tag of an {@link Element}
* </p> * </p>
* *
* @param element * @param element
* <code>Element</code> to output. * <code>Element</code> to output.
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -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);
@ -975,10 +979,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Determines if element is a special case of XML elements where it contains * Determines if element is a special case of XML elements where it contains
* an xml:space attribute of "preserve". If it does, then retain whitespace. * an xml:space attribute of "preserve". If it does, then retain whitespace.
* *
* @param element * @param element
* DOCUMENT ME! * DOCUMENT ME!
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
protected final boolean isElementSpacePreserved(Element element) { protected final boolean isElementSpacePreserved(Element element) {
@ -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;
@ -1003,10 +1002,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* whitespace trimming occurs to avoid problems with multiple text nodes * whitespace trimming occurs to avoid problems with multiple text nodes
* being created due to text content that spans parser buffers in a SAX * being created due to text content that spans parser buffers in a SAX
* parser. * parser.
* *
* @param element * @param element
* DOCUMENT ME! * DOCUMENT ME!
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -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);
} }
} }
@ -1174,17 +1167,15 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the SAX namepsaces * Writes the SAX namepsaces
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
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);
} }
@ -1194,15 +1185,15 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the SAX namepsaces * Writes the SAX namepsaces
* *
* @param prefix * @param prefix
* the prefix * the prefix
* @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 {
if ((prefix != null) && (prefix.length() > 0)) { if ((prefix != null) && (prefix.length() > 0)) {
writer.write(" xmlns:"); writer.write(" xmlns:");
@ -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);
} }
} }
} }
@ -1272,10 +1274,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* This method is used to write out Nodes that contain text and still allow * This method is used to write out Nodes that contain text and still allow
* for xml:space to be handled properly. * for xml:space to be handled properly.
* *
* @param node * @param node
* DOCUMENT ME! * DOCUMENT ME!
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -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) {
@ -1434,10 +1435,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/** /**
* Writes the attributes of the given element * Writes the attributes of the given element
* *
* @param element * @param element
* DOCUMENT ME! * DOCUMENT ME!
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -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 {
@ -1537,29 +1530,26 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* <p> * <p>
* This will print a new line only if the newlines flag was set to true * This will print a new line only if the newlines flag was set to true
* </p> * </p>
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
protected void writePrintln() throws IOException { protected void writePrintln() throws IOException {
if (format.isNewlines()) { if (format.isNewlines()) {
String seperator = format.getLineSeparator(); writer.write(format.getLineSeparator());
if (lastChar != seperator.charAt(seperator.length() - 1)) {
writer.write(format.getLineSeparator());
}
} }
} }
/** /**
* Get an OutputStreamWriter, use preferred encoding. * Get an OutputStreamWriter, use preferred encoding.
* *
* @param outStream * @param outStream
* DOCUMENT ME! * DOCUMENT ME!
* @param encoding * @param encoding
* DOCUMENT ME! * DOCUMENT ME!
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
* *
* @throws UnsupportedEncodingException * @throws UnsupportedEncodingException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -1573,7 +1563,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* This will write the declaration to the given Writer. Assumes XML version * This will write the declaration to the given Writer. Assumes XML version
* 1.0 since we don't directly know. * 1.0 since we don't directly know.
* </p> * </p>
* *
* @throws IOException * @throws IOException
* DOCUMENT ME! * DOCUMENT ME!
*/ */
@ -1633,10 +1623,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* This will take the pre-defined entities in XML 1.0 and convert their * This will take the pre-defined entities in XML 1.0 and convert their
* character representation to the appropriate entity reference, suitable * character representation to the appropriate entity reference, suitable
* for XML attributes. * for XML attributes.
* *
* @param text * @param text
* DOCUMENT ME! * DOCUMENT ME!
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
protected String escapeElementEntities(String text) { protected String escapeElementEntities(String text) {
@ -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++;
} }
} }
@ -1725,10 +1714,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* This will take the pre-defined entities in XML 1.0 and convert their * This will take the pre-defined entities in XML 1.0 and convert their
* character representation to the appropriate entity reference, suitable * character representation to the appropriate entity reference, suitable
* for XML attributes. * for XML attributes.
* *
* @param text * @param text
* DOCUMENT ME! * DOCUMENT ME!
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
protected String escapeAttributeEntities(String text) { protected String escapeAttributeEntities(String text) {
@ -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++;
} }
} }
@ -1823,23 +1802,23 @@ 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);
} }
/** /**
* Returns the maximum allowed character code that should be allowed * Returns the maximum allowed character code that should be allowed
* unescaped which defaults to 127 in US-ASCII (7 bit) or 255 in ISO- (8 * unescaped which defaults to 127 in US-ASCII (7 bit) or 255 in ISO- (8
* bit). * bit).
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
protected int defaultMaximumAllowedCharacter() { protected int defaultMaximumAllowedCharacter() {
@ -1880,7 +1859,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* setTrimText, setNewLines, etc. Put in to support the HTMLWriter, in the * setTrimText, setNewLines, etc. Put in to support the HTMLWriter, in the
* way that it pushes the current newline/trim state onto a stack and * way that it pushes the current newline/trim state onto a stack and
* overrides the state within preformatted tags. * overrides the state within preformatted tags.
* *
* @return DOCUMENT ME! * @return DOCUMENT ME!
*/ */
protected OutputFormat getOutputFormat() { protected OutputFormat getOutputFormat() {
@ -1900,24 +1879,24 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Redistribution and use of this software and associated documentation * Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the * ("Software"), with or without modification, are permitted provided that the
* following conditions are met: * following conditions are met:
* *
* 1. Redistributions of source code must retain copyright statements and * 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document. * notices. Redistributions must also contain a copy of this document.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* 3. The name "DOM4J" must not be used to endorse or promote products derived * 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For * from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com. * written permission, please contact dom4j-info@metastuff.com.
* *
* 4. Products derived from this Software may not be called "DOM4J" nor may * 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff, * "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd. * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
* *
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
* *
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -1929,6 +1908,6 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved. * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/ */

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 */

4
fine-org-dom4j/src/main/java/org/dom4j/io/package-info.java

@ -0,0 +1,4 @@
/**
* Provides input and output via SAX and DOM together with writing <i>dom4j</i> objects to streams as XML text.
*/
package org.dom4j.io;

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

4
fine-org-dom4j/src/main/java/org/dom4j/package-info.java

@ -0,0 +1,4 @@
/**
* Defines the XML Document Object Model in Java interfaces together with some helper classes.
*/
package org.dom4j;

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);

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

Loading…
Cancel
Save