Browse Source

REPORT-95578 dom4j升级

release/10.0
Yuan.Wang 1 year ago
parent
commit
e83f5d8167
  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. 10
      fine-org-dom4j/src/main/java/org/dom4j/bean/package.html
  34. 2
      fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeAttribute.java
  35. 2
      fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeDocumentFactory.java
  36. 2
      fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeElement.java
  37. 10
      fine-org-dom4j/src/main/java/org/dom4j/datatype/DatatypeElementFactory.java
  38. 2
      fine-org-dom4j/src/main/java/org/dom4j/datatype/InvalidSchemaException.java
  39. 15
      fine-org-dom4j/src/main/java/org/dom4j/datatype/NamedTypeResolver.java
  40. 75
      fine-org-dom4j/src/main/java/org/dom4j/datatype/SchemaParser.java
  41. 10
      fine-org-dom4j/src/main/java/org/dom4j/datatype/package.html
  42. 10
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMAttribute.java
  43. 2
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMAttributeNodeMap.java
  44. 10
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMCDATA.java
  45. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMComment.java
  46. 18
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMDocument.java
  47. 36
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMDocumentFactory.java
  48. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMDocumentType.java
  49. 15
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMElement.java
  50. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMEntityReference.java
  51. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMNamespace.java
  52. 35
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMNodeHelper.java
  53. 11
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMProcessingInstruction.java
  54. 9
      fine-org-dom4j/src/main/java/org/dom4j/dom/DOMText.java
  55. 10
      fine-org-dom4j/src/main/java/org/dom4j/dom/package.html
  56. 4
      fine-org-dom4j/src/main/java/org/dom4j/dtd/AttributeDecl.java
  57. 4
      fine-org-dom4j/src/main/java/org/dom4j/dtd/ElementDecl.java
  58. 4
      fine-org-dom4j/src/main/java/org/dom4j/dtd/ExternalEntityDecl.java
  59. 4
      fine-org-dom4j/src/main/java/org/dom4j/dtd/InternalEntityDecl.java
  60. 9
      fine-org-dom4j/src/main/java/org/dom4j/dtd/package.html
  61. 13
      fine-org-dom4j/src/main/java/org/dom4j/io/DOMReader.java
  62. 74
      fine-org-dom4j/src/main/java/org/dom4j/io/DOMWriter.java
  63. 24
      fine-org-dom4j/src/main/java/org/dom4j/io/DispatchHandler.java
  64. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/DocumentInputSource.java
  65. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/DocumentResult.java
  66. 10
      fine-org-dom4j/src/main/java/org/dom4j/io/DocumentSource.java
  67. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/ElementStack.java
  68. 174
      fine-org-dom4j/src/main/java/org/dom4j/io/HTMLWriter.java
  69. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/JAXPHelper.java
  70. 58
      fine-org-dom4j/src/main/java/org/dom4j/io/OutputFormat.java
  71. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/PruningElementStack.java
  72. 39
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXContentHandler.java
  73. 68
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXEventRecorder.java
  74. 54
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXHelper.java
  75. 18
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXModifier.java
  76. 1853
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXReader.java
  77. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXValidator.java
  78. 70
      fine-org-dom4j/src/main/java/org/dom4j/io/SAXWriter.java
  79. 20
      fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventReader.java
  80. 26
      fine-org-dom4j/src/main/java/org/dom4j/io/STAXEventWriter.java
  81. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/XMLResult.java
  82. 339
      fine-org-dom4j/src/main/java/org/dom4j/io/XMLWriter.java
  83. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/XPP3Reader.java
  84. 2
      fine-org-dom4j/src/main/java/org/dom4j/io/XPPReader.java
  85. 10
      fine-org-dom4j/src/main/java/org/dom4j/io/package.html
  86. 12
      fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBModifier.java
  87. 6
      fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBReader.java
  88. 8
      fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBWriter.java
  89. 10
      fine-org-dom4j/src/main/java/org/dom4j/package.html
  90. 2
      fine-org-dom4j/src/main/java/org/dom4j/rule/Action.java
  91. 16
      fine-org-dom4j/src/main/java/org/dom4j/rule/Mode.java
  92. 2
      fine-org-dom4j/src/main/java/org/dom4j/rule/NullAction.java
  93. 2
      fine-org-dom4j/src/main/java/org/dom4j/rule/Pattern.java
  94. 547
      fine-org-dom4j/src/main/java/org/dom4j/rule/Rule.java
  95. 16
      fine-org-dom4j/src/main/java/org/dom4j/rule/RuleManager.java
  96. 4
      fine-org-dom4j/src/main/java/org/dom4j/rule/RuleSet.java
  97. 210
      fine-org-dom4j/src/main/java/org/dom4j/rule/Stylesheet.java
  98. 14
      fine-org-dom4j/src/main/java/org/dom4j/rule/package.html
  99. 2
      fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/DefaultPattern.java
  100. 2
      fine-org-dom4j/src/main/java/org/dom4j/rule/pattern/NodeTypePattern.java
  101. Some files were not shown because too many files have changed in this diff Show More

2
fine-org-dom4j/README.md

@ -1,2 +1,2 @@
dom4j的源码地址:https://github.com/dom4j/dom4j <br>
版本: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;
/**
* <p>
* <code>Attribute</code> defines an XML attribute. An attribute may have a
* name, an optional namespace and a value.
* </p>
*
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.9 $
*/
@SuppressWarnings("unused")
public interface Attribute extends Node {
/**
* <p>
* Returns the <code>QName</code> of this attribute which represents the
* local name, the qualified name and the <code>Namespace</code>.
* </p>
*
* @return the <code>QName</code> associated with this attribute
*/
QName getQName();
/**
* Returns the <code>QName</code> of this attribute which represents the
* local name, the qualified name and the <code>Namespace</code>.
*
* @return the <code>QName</code> associated with this attribute
*/
QName getQName();
/**
* <p>
* Returns the <code>Namespace</code> of this element if one exists
* otherwise null is returned returned.
* </p>
*
* @return the <code>Namespace</code> associated with this node
*/
Namespace getNamespace();
/**
* Returns the <code>Namespace</code> of this element if one exists
* otherwise null is returned returned.
*
* @return the <code>Namespace</code> associated with this node
*/
Namespace getNamespace();
/**
* <p>
* Sets the <code>Namespace</code> of this element or if this element is
* read only then an <code>UnsupportedOperationException</code> is thrown.
* </p>
*
* @param namespace
* is the <code>Namespace</code> to associate with this element
*/
void setNamespace(Namespace namespace);
/**
* Sets the <code>Namespace</code> of this element or if this element is
* read only then an <code>UnsupportedOperationException</code> is thrown.
*
* @param 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
* empty <code>String</code> is returned.
* </p>
*
* @return the prefix of the <code>Namespace</code> of this element or an
* empty <code>String</code>
*/
String getNamespacePrefix();
/**
* Returns the namespace prefix of this element if one exists otherwise an
* empty <code>String</code> is returned.
*
* @return the prefix of the <code>Namespace</code> of this element or an
* empty <code>String</code>
*/
String getNamespacePrefix();
/**
* <p>
* Returns the URI mapped to the namespace of this element if one exists
* 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>
*/
String getNamespaceURI();
/**
* Returns the URI mapped to the namespace of this element if one exists
* otherwise an empty <code>String</code> is returned.
*
* @return the URI for the <code>Namespace</code> of this element or an
* empty <code>String</code>
*/
String getNamespaceURI();
/**
* <p>
* Returns the fully qualified name of this element.
* </p>
*
* <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
* expression of the form
*
* <pre>
* getNamespacePrefix() + &quot;:&quot; + getName()
* </pre>
*
* will be returned.
* </p>
*
* @return the fully qualified name of the element
*/
String getQualifiedName();
/**
* Returns the fully qualified name of this element.
*
* 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
* expression of the form
* <pre>
* getNamespacePrefix() + &quot;:&quot; + getName()
* </pre>
* will be returned.
*
* @return the fully qualified name of the element
*/
String getQualifiedName();
/**
* <p>
* Returns the value of the attribute. This method returns the same value as
* the {@link Node#getText()}method.
* </p>
*
* @return the value of the attribute
*/
String getValue();
/**
* Returns the value of the attribute. This method returns the same value as
* the {@link Node#getText()}method.
*
* @return the value of the attribute
*/
String getValue();
/**
* <p>
* Sets the value of this attribute or this method will throw an
* <code>UnsupportedOperationException</code> if it is read-only.
* </p>
*
* @param value
* is the new value of this attribute
*/
void setValue(String value);
/**
* Sets the value of this attribute or this method will throw an
* <code>UnsupportedOperationException</code> if it is read-only.
*
* @param value is the new value of this attribute
*/
void setValue(String value);
/**
* <p>
* Accesses the data of this attribute which may implement data typing
* bindings such as <code>XML Schema</code> or <code>Java Bean</code>
* bindings or will return the same value as {@link Node#getText()}.
* </p>
*
* @return the attribute data
*/
Object getData();
/**
* Accesses the data of this attribute which may implement data typing
* bindings such as <code>XML Schema</code> or <code>Java Bean</code>
* bindings or will return the same value as {@link Node#getText()}.
*
* @return the attribute data
*/
Object getData();
/**
* <p>
* Sets the data value of this attribute if this element supports data
* binding or calls {@link Node#setText(String)}if it doesn't.
* </p>
*
* @param data
* the attribute data
*/
void setData(Object data);
/**
* Sets the data value of this attribute if this element supports data
* binding or calls {@link Node#setText(String)}if it doesn't.
*
* @param 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;
/**
* <p>
* <code>Branch</code> interface defines the common behaviour for Nodes which
* can contain child nodes (content) such as XML elements and documents. This
* interface allows both elements and documents to be treated in a polymorphic
* manner when changing or navigating child nodes (content).
* </p>
*
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.32 $
*/
@SuppressWarnings("unused")
public interface Branch extends Node {
/**
* Returns the <code>Node</code> at the specified index position.
*
* @param index
* 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;=
* {@link Branch#nodeCount()}).
*/
Node node(int index) throws IndexOutOfBoundsException;
/**
* Returns the <code>Node</code> at the specified index position.
*
* @param index 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;=
* {@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
* or -1 if the given node is not a child node.
*
* @param node
* 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
*/
int indexOf(Node node);
/**
* 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.
*
* @param node 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
*/
int indexOf(Node node);
/**
* Returns the number of <code>Node</code> instances that this branch
* contains.
*
* @return the number of nodes this branch contains
*/
int nodeCount();
/**
* Returns the number of <code>Node</code> instances that this branch
* contains.
*
* @return the number of nodes this branch contains
*/
int nodeCount();
/**
* 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
* then it should be used, otherwise this method should return null.
*
* @param elementID
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
Element elementByID(String elementID);
/**
* 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
* then it should be used, otherwise this method should return null.
*
* @param elementID DOCUMENT ME!
* @return DOCUMENT ME!
*/
Element elementByID(String elementID);
/**
* <p>
* 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
* {@link List}interface. The <code>List</code> is backed by the
* <code>Branch</code> so that changes to the list are reflected in the
* branch and vice versa.
* </p>
*
* @return the nodes that this branch contains as a <code>List</code>
*/
List content();
/**
* 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
* {@link List}interface. The <code>List</code> is backed by the
* <code>Branch</code> so that changes to the list are reflected in the
* branch and vice versa.
*
* @return the nodes that this branch contains as a <code>List</code>
*/
List<Node> content();
/**
* Returns an iterator through the content nodes of this branch
*
* @return an iterator through the content nodes of this branch
*/
Iterator nodeIterator();
/**
* Returns an iterator through the content nodes of this branch
*
* @return an iterator through the content nodes of this branch
*/
Iterator<Node> nodeIterator();
/**
* Sets the contents of this branch as a <code>List</code> of
* <code>Node</code> instances.
*
* @param content
* is the list of nodes to use as the content for this branch.
*/
void setContent(List content);
/**
* Sets the contents of this branch as a <code>List</code> of
* <code>Node</code> instances.
*
* @param content is the list of nodes to use as the content for this branch.
*/
void setContent(List<Node> content);
/**
* Appends the content of the given branch to this branch instance. This
* method behaves like the {@link
* java.util.Collection#addAll(java.util.Collection)} method.
*
* @param branch
* is the branch whose content will be added to me.
*/
void appendContent(Branch branch);
/**
* Appends the content of the given branch to this branch instance. This
* method behaves like the {@link
* java.util.Collection#addAll(java.util.Collection)} method.
*
* @param branch is the branch whose content will be added to me.
*/
void appendContent(Branch branch);
/**
* Clears the content for this branch, removing any <code>Node</code>
* instances this branch may contain.
*/
void clearContent();
/**
* Clears the content for this branch, removing any <code>Node</code>
* instances this branch may contain.
*/
void clearContent();
/**
* <p>
* 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
* reflected in the branch but the reverse is not the case.
* </p>
*
* @return a backed list of the processing instructions
*/
List processingInstructions();
/**
* 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
* reflected in the branch but the reverse is not the case.
*
* @return a backed list of the processing instructions
*/
List<ProcessingInstruction> processingInstructions();
/**
* <p>
* 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
* reflected in the branch but the reverse is not the case.
* </p>
*
* @param target
* DOCUMENT ME!
*
* @return a backed list of the processing instructions
*/
List processingInstructions(String target);
/**
* 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
* reflected in the branch but the reverse is not the case.
*
* @param target DOCUMENT ME!
* @return a backed list of the processing instructions
*/
List<ProcessingInstruction> processingInstructions(String target);
/**
* DOCUMENT ME!
*
* @param target
* DOCUMENT ME!
*
* @return the processing instruction for the given target
*/
ProcessingInstruction processingInstruction(String target);
/**
* DOCUMENT ME!
*
* @param target DOCUMENT ME!
* @return the processing instruction for the given target
*/
ProcessingInstruction processingInstruction(String target);
/**
* Sets all the processing instructions for this branch
*
* @param listOfPIs
* DOCUMENT ME!
*/
void setProcessingInstructions(List listOfPIs);
/**
* Sets all the processing instructions for this branch
*
* @param listOfPIs DOCUMENT ME!
*/
void setProcessingInstructions(List<ProcessingInstruction> listOfPIs);
/**
* Adds a new <code>Element</code> node with the given name to this branch
* and returns a reference to the new node.
*
* @param name
* is the name for the <code>Element</code> node.
*
* @return the newly added <code>Element</code> node.
*/
Element addElement(String name);
/**
* Adds a new <code>Element</code> node with the given name to this branch
* and returns a reference to the new node.
*
* @param name is the name for the <code>Element</code> node.
* @return the newly added <code>Element</code> node.
*/
Element addElement(String name);
/**
* Adds a new <code>Element</code> node with the given {@link QName}to
* this branch and returns a reference to the new node.
*
* @param qname
* is the qualified name for the <code>Element</code> node.
*
* @return the newly added <code>Element</code> node.
*/
Element addElement(QName qname);
/**
* Adds a new <code>Element</code> node with the given {@link QName}to
* this branch and returns a reference to the new node.
*
* @param qname is the qualified name for the <code>Element</code> node.
* @return the newly added <code>Element</code> node.
*/
Element addElement(QName qname);
/**
* 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.
*
* @param qualifiedName
* is the fully qualified name of the Element
* @param namespaceURI
* is the URI of the namespace to use
*
* @return the newly added <code>Element</code> node.
*/
Element addElement(String qualifiedName, String namespaceURI);
/**
* 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.
*
* @param qualifiedName is the fully qualified name of the Element
* @param namespaceURI is the URI of the namespace to use
* @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
*
* @param target
* DOCUMENT ME!
*
* @return true if a processing instruction was removed else false
*/
boolean removeProcessingInstruction(String target);
/**
* Removes the processing instruction for the given target if it exists
*
* @param target DOCUMENT ME!
* @return true if a processing instruction was removed else false
*/
boolean removeProcessingInstruction(String target);
/**
* 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
* which will call the typesafe method for the node type such as
* add(Element) or add(Comment).
*
* @param node
* is the given node to add
*/
void add(Node node);
/**
* 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
* which will call the typesafe method for the node type such as
* add(Element) or add(Comment).
*
* @param node is the given node to add
*/
void add(Node node);
/**
* Adds the given <code>Comment</code> to this branch. If the given node
* already has a parent defined then an <code>IllegalAddException</code>
* will be thrown.
*
* @param comment
* is the comment to be added
*/
void add(Comment comment);
/**
* Adds the given <code>Comment</code> to this branch. If the given node
* already has a parent defined then an <code>IllegalAddException</code>
* will be thrown.
*
* @param comment is the comment to be added
*/
void add(Comment comment);
/**
* Adds the given <code>Element</code> to this branch. If the given node
* already has a parent defined then an <code>IllegalAddException</code>
* will be thrown.
*
* @param element
* is the element to be added
*/
void add(Element element);
/**
* Adds the given <code>Element</code> to this branch. If the given node
* already has a parent defined then an <code>IllegalAddException</code>
* will be thrown.
*
* @param element is the element to be added
*/
void add(Element element);
/**
* Adds the given <code>ProcessingInstruction</code> to this branch. If
* the given node already has a parent defined then an
* <code>IllegalAddException</code> will be thrown.
*
* @param pi
* is the processing instruction to be added
*/
void add(ProcessingInstruction pi);
/**
* Adds the given <code>ProcessingInstruction</code> to this branch. If
* the given node already has a parent defined then an
* <code>IllegalAddException</code> will be thrown.
*
* @param pi is the processing instruction to be added
*/
void add(ProcessingInstruction pi);
/**
* 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
* 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
* type such as remove(Element) or remove(Comment).
*
* @param node
* is the given node to be removed
*
* @return true if the node was removed
*/
boolean remove(Node node);
/**
* 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
* 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
* type such as remove(Element) or remove(Comment).
*
* @param node is the given node to be removed
* @return true if the node was removed
*/
boolean remove(Node node);
/**
* 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
* branch then the {@link Node#detach()}method should be used instead.
*
* @param comment
* is the comment to be removed
*
* @return true if the comment was removed
*/
boolean remove(Comment comment);
/**
* 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
* branch then the {@link Node#detach()}method should be used instead.
*
* @param comment is the comment to be removed
* @return true if the comment was removed
*/
boolean remove(Comment comment);
/**
* 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
* branch then the {@link Node#detach()}method should be used instead.
*
* @param element
* is the element to be removed
*
* @return true if the element was removed
*/
boolean remove(Element element);
/**
* 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
* branch then the {@link Node#detach()}method should be used instead.
*
* @param element is the element to be removed
* @return true if the element was removed
*/
boolean remove(Element element);
/**
* Removes the given <code>ProcessingInstruction</code> if the node is an
* 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
* instead.
*
* @param pi
* is the processing instruction to be removed
*
* @return true if the processing instruction was removed
*/
boolean remove(ProcessingInstruction pi);
/**
* Removes the given <code>ProcessingInstruction</code> if the node is an
* 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
* instead.
*
* @param pi is the processing instruction to be removed
* @return true if the processing instruction was removed
*/
boolean remove(ProcessingInstruction pi);
/**
* Puts all <code>Text</code> nodes in the full depth of the sub-tree
* underneath this <code>Node</code>, including attribute nodes, into a
* "normal" form where only structure (e.g., elements, comments, processing
* instructions, CDATA sections, and entity references) separates
* <code>Text</code> nodes, i.e., there are neither adjacent
* <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
* were saved and re-loaded, and is useful when operations (such as XPointer
* lookups) that depend on a particular document tree structure are to be
* used.In cases where the document contains <code>CDATASections</code>,
* the normalize operation alone may not be sufficient, since XPointers do
* not differentiate between <code>Text</code> nodes and
* <code>CDATASection</code> nodes.
*
* @since DOM Level 2
*/
void normalize();
/**
* Puts all <code>Text</code> nodes in the full depth of the sub-tree
* underneath this <code>Node</code>, including attribute nodes, into a
* "normal" form where only structure (e.g., elements, comments, processing
* instructions, CDATA sections, and entity references) separates
* <code>Text</code> nodes, i.e., there are neither adjacent
* <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
* were saved and re-loaded, and is useful when operations (such as XPointer
* lookups) that depend on a particular document tree structure are to be
* used.In cases where the document contains <code>CDATASections</code>,
* the normalize operation alone may not be sufficient, since XPointers do
* not differentiate between <code>Text</code> nodes and
* <code>CDATASection</code> nodes.
*
* @since DOM Level 2
*/
void normalize();
}
/*

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

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

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

@ -8,15 +8,14 @@
package org.dom4j;
/**
* <p>
* <code>CharacterData</code> is a marker interface for character based nodes
* such as the <code>CDATA</code>,<code>Comment</code> and
* <code>Text</code> nodes.
* </p>
*
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.9 $
*/
@SuppressWarnings("unused")
public interface CharacterData extends Node {
/**
* 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;
/**
* <p>
* <code>Comment</code> defines the behavior of an XML comment.
* </p>
*
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.7 $
*/
@SuppressWarnings("unused")
public interface Comment extends CharacterData {
}

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

@ -7,18 +7,17 @@
package org.dom4j;
import java.util.Map;
import org.xml.sax.EntityResolver;
import java.util.Map;
/**
* <p>
* <code>Document</code> defines an XML Document.
* </p>
*
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.14 $
*/
@SuppressWarnings("unused")
public interface Document extends Branch {
/**
* Returns the root {@link Element}for this document.
@ -70,7 +69,7 @@ public interface Document extends Branch {
*
* @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
@ -124,15 +123,13 @@ public interface Document extends Branch {
* when the Document was created in memory) or when the implementation does
* not support this operation.
*
* <p>
* 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
* XMLReader implementation support the
* <code>org.xml.sax.ext.Locator2</code> interface, the result returned by
* this method is specified by the <code>getEncoding()</code> method of
* that interface.
* </p>
*
*
* @return The encoding of this document, as stated in the XML declaration,
* or <code>null</code> if unknown.
*

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

@ -7,78 +7,32 @@
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.
* </p>
*
* <code>DocumentException</code> is a nested Exception which may be thrown during the processing of a DOM4J document.
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @author Filip Jirsák
*/
public class DocumentException extends Exception {
/** A wrapped <code>Throwable</code> */
private Throwable nestedException;
public DocumentException() {
super("Error occurred in DOM4J application.");
}
public DocumentException(String message) {
super(message);
}
public DocumentException(Throwable nestedException) {
super(nestedException.getMessage());
this.nestedException = nestedException;
public DocumentException(String message, Throwable cause) {
super(message, cause);
}
public DocumentException(String message, Throwable nestedException) {
super(message);
this.nestedException = nestedException;
public DocumentException(Throwable cause) {
super(cause);
}
@Deprecated
public Throwable getNestedException() {
return nestedException;
}
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);
}
return null;
}
}

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

@ -32,28 +32,25 @@ import org.dom4j.xpath.XPathPattern;
import org.jaxen.VariableContext;
/**
* <p>
* <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
* doubly linked tree.
* </p>
*
* <p>
*
* The tree built allows full XPath expressions from anywhere on the tree.
* </p>
*
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
*/
@SuppressWarnings("unused")
public class DocumentFactory implements Serializable {
private static SingletonStrategy singleton = null;
private static SingletonStrategy<DocumentFactory> singleton = null;
protected transient QNameCache cache;
/** Default namespace prefix -> URI mappings for XPath expressions to use */
private Map xpathNamespaceURIs;
/** Default namespace prefix URI mappings for XPath expressions to use */
private Map<String, String> xpathNamespaceURIs;
private static SingletonStrategy createSingleton() {
SingletonStrategy result = null;
private static SingletonStrategy<DocumentFactory> createSingleton() {
SingletonStrategy<DocumentFactory> result;
String documentFactoryClassName;
try {
@ -67,10 +64,10 @@ public class DocumentFactory implements Serializable {
String singletonClass = System.getProperty(
"org.dom4j.DocumentFactory.singleton.strategy",
"org.dom4j.util.SimpleSingleton");
Class clazz = Class.forName(singletonClass);
result = (SingletonStrategy) clazz.newInstance();
Class<SingletonStrategy> clazz = (Class<SingletonStrategy>) Class.forName(singletonClass);
result = clazz.newInstance();
} catch (Exception e) {
result = new SimpleSingleton();
result = new SimpleSingleton<DocumentFactory>();
}
result.setSingletonClassName(documentFactoryClassName);
@ -83,18 +80,16 @@ public class DocumentFactory implements Serializable {
}
/**
* <p>
* Access to singleton implementation of DocumentFactory which is used if no
* DocumentFactory is specified when building using the standard builders.
* </p>
*
*
* @return the default singleon instance
*/
public static synchronized DocumentFactory getInstance() {
if (singleton == null) {
singleton = createSingleton();
}
return (DocumentFactory) singleton.instance();
return singleton.instance();
}
// Factory methods
@ -121,10 +116,7 @@ public class DocumentFactory implements Serializable {
// createDocument() method.
Document answer = createDocument();
if (answer instanceof AbstractDocument) {
((AbstractDocument) answer).setXMLEncoding(encoding);
}
answer.setXMLEncoding(encoding);
return answer;
}
@ -191,7 +183,7 @@ public class DocumentFactory implements Serializable {
}
public ProcessingInstruction createProcessingInstruction(String target,
Map data) {
Map<String, String> data) {
return new DefaultProcessingInstruction(target, data);
}
@ -324,7 +316,7 @@ public class DocumentFactory implements Serializable {
*
* @return DOCUMENT ME!
*/
public List getQNames() {
public List<QName> 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 URIs are being mapped.
*/
public Map getXPathNamespaceURIs() {
public Map<String, String> getXPathNamespaceURIs() {
return xpathNamespaceURIs;
}
@ -349,7 +341,7 @@ public class DocumentFactory implements Serializable {
* @param namespaceURIs
* DOCUMENT ME!
*/
public void setXPathNamespaceURIs(Map namespaceURIs) {
public void setXPathNamespaceURIs(Map<String, String> namespaceURIs) {
this.xpathNamespaceURIs = namespaceURIs;
}
@ -372,10 +364,10 @@ public class DocumentFactory implements Serializable {
try {
// I'll use the current class loader
// 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());
return (DocumentFactory) theClass.newInstance();
return theClass.newInstance();
} catch (Throwable e) {
System.out.println("WARNING: Cannot load DocumentFactory: "
+ 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.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* <p>
* <code>DocumentHelper</code> is a collection of helper methods for using
* DOM4J.
* </p>
*
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.26 $
*/
@SuppressWarnings("unused")
public final class DocumentHelper {
private DocumentHelper() {
}
@ -89,7 +89,7 @@ public final class DocumentHelper {
}
public static ProcessingInstruction createProcessingInstruction(String pi,
Map data) {
Map<String, String> data) {
return getDocumentFactory().createProcessingInstruction(pi, data);
}
@ -107,12 +107,12 @@ public final class DocumentHelper {
* XPath <code>XPath</code> instance using the singleton {@link
* DocumentFactory}.
* </p>
*
*
* @param xpathExpression
* is the XPath expression to create
*
*
* @return a new <code>XPath</code> instance
*
*
* @throws InvalidXPathException
* if the XPath expression is invalid
*/
@ -127,14 +127,14 @@ public final class DocumentHelper {
* XPath <code>XPath</code> instance using the singleton {@link
* DocumentFactory}.
* </p>
*
*
* @param xpathExpression
* is the XPath expression to create
* @param context
* is the variable context to use when evaluating the XPath
*
*
* @return a new <code>XPath</code> instance
*
*
* @throws InvalidXPathException
* if the XPath expression is invalid
*/
@ -150,10 +150,10 @@ public final class DocumentHelper {
* filter expressions occur within XPath expressions such as
* <code>self::node()[ filterExpression ]</code>
* </p>
*
*
* @param xpathFilterExpression
* is the XPath filter expression to create
*
*
* @return a new <code>NodeFilter</code> instance
*/
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
* processing model.
* </p>
*
*
* @param xpathPattern
* is the XPath pattern expression to create
*
*
* @return a new <code>Pattern</code> instance
*/
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
* into a single list.
* </p>
*
*
* @param xpathFilterExpression
* is the XPath filter expression to evaluate
* @param nodes
* is the list of nodes on which to evalute the XPath
*
*
* @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);
return xpath.selectNodes(nodes);
@ -202,15 +202,15 @@ public final class DocumentHelper {
* {@link List}of {@link Node}instances appending all the results together
* into a single list.
* </p>
*
*
* @param xpathFilterExpression
* is the XPath filter expression to evaluate
* @param node
* is the Node on which to evalute the XPath
*
*
* @return the results of all the XPath evaluations as a single list
*/
public static List selectNodes(String xpathFilterExpression, Node node) {
public static List<Node> selectNodes(String xpathFilterExpression, Node node) {
XPath xpath = createXPath(xpathFilterExpression);
return xpath.selectNodes(node);
@ -221,13 +221,13 @@ public final class DocumentHelper {
* <code>sort</code> sorts the given List of Nodes using an XPath
* expression as a {@link java.util.Comparator}.
* </p>
*
*
* @param list
* is the list of Nodes to sort
* @param xpathExpression
* is the XPath expression used for comparison
*/
public static void sort(List list, String xpathExpression) {
public static void sort(List<Node> list, String xpathExpression) {
XPath xpath = createXPath(xpathExpression);
xpath.sort(list);
}
@ -238,7 +238,7 @@ public final class DocumentHelper {
* expression as a {@link java.util.Comparator}and optionally removing
* duplicates.
* </p>
*
*
* @param list
* is the list of Nodes to sort
* @param expression
@ -247,7 +247,7 @@ public final class DocumentHelper {
* if true then duplicate values (using the sortXPath for
* comparisions) will be removed from the List
*/
public static void sort(List list, String expression, boolean distinct) {
public static void sort(List<Node> list, String expression, boolean distinct) {
XPath xpath = createXPath(expression);
xpath.sort(list, distinct);
}
@ -257,25 +257,26 @@ public final class DocumentHelper {
* <code>parseText</code> parses the given text as an XML document and
* returns the newly created Document.
* </p>
*
*
* Loading external DTD and entities is disabled (if it is possible) for security reasons.
*
* @param text
* the XML text to be parsed
*
*
* @return a newly parsed Document
*
*
* @throws DocumentException
* if the document could not be parsed
*/
public static Document parseText(String text) throws DocumentException {
Document result = null;
SAXReader reader = SAXReader.createDefault();
SAXReader reader = new SAXReader();
String encoding = getEncoding(text);
InputSource source = new InputSource(new StringReader(text));
source.setEncoding(encoding);
result = reader.read(source);
Document result = reader.read(source);
// if the XML parser doesn't provide a way to retrieve the encoding,
// specify it manually
@ -322,14 +323,14 @@ public final class DocumentHelper {
* get the first child &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
* &lt;c&gt; element is returned.
*
*
* @param source
* is the Element or Document to start navigating from
* @param path
* is a simple path expression, seperated by '/' which denotes
* the path from the source to the resulting element such as
* a/b/c
*
*
* @return the first Element on the given path which either already existed
* on the path or were created by this method.
*/
@ -378,24 +379,24 @@ public final class DocumentHelper {
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the
* following conditions are met:
*
*
* 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*
* 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com.
*
*
* 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
*
*
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
*
*
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -407,6 +408,6 @@ public final class DocumentHelper {
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/

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

@ -7,16 +7,17 @@
package org.dom4j;
import org.dom4j.dtd.Decl;
import java.util.List;
/**
* <p>
* <code>DocumentType</code> defines an XML DOCTYPE declaration.
* </p>
*
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.10 $
*/
@SuppressWarnings("unused")
public interface DocumentType extends Node {
/**
* This method is the equivalent to the {@link #getName}method. It is added
@ -49,7 +50,7 @@ public interface DocumentType extends Node {
*
* @return DOCUMENT ME!
*/
List getInternalDeclarations();
List<Decl> getInternalDeclarations();
/**
* Sets the list of internal DTD declaration objects, defined in the
@ -58,7 +59,7 @@ public interface DocumentType extends Node {
* @param declarations
* DOCUMENT ME!
*/
void setInternalDeclarations(List declarations);
void setInternalDeclarations(List<Decl> declarations);
/**
* Returns a list of internal DTD declaration objects, defined in the
@ -66,7 +67,7 @@ public interface DocumentType extends Node {
*
* @return DOCUMENT ME!
*/
List getExternalDeclarations();
List<Decl> getExternalDeclarations();
/**
* Sets the list of internal DTD declaration objects, defined in the
@ -75,7 +76,7 @@ public interface DocumentType extends Node {
* @param declarations
* DOCUMENT ME!
*/
void setExternalDeclarations(List declarations);
void setExternalDeclarations(List<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;
/**
* <p>
* <code>ElementHandler</code> interface defines a handler of
* <code>Element</code> objects. It is used primarily in event based
* processing models such as for processing large XML documents as they are
* being parsed rather than waiting until the whole document is parsed.
* </p>
*
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.8 $
*/
@SuppressWarnings("unused")
public interface ElementHandler {
/**
* 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.
*
* @author <a href="mailto:dwhite@equipecom.com">Dave White </a>
* @version $Revision$
* @version $Revision: 1.6 $
*/
@SuppressWarnings("unused")
public interface ElementPath {
/**
* DOCUMENT ME!

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

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

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

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

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

@ -8,29 +8,19 @@
package org.dom4j;
/**
* <p>
* <code>InvalidXPathException</code> is thrown when an invalid XPath
* expression is used to traverse an XML document
* </p>
*
* @version $Revision$
*
* @version $Revision: 1.6 $
*/
public class InvalidXPathException extends IllegalArgumentException {
/** The <code>serialVersionUID</code>. */
private static final long serialVersionUID = 3257009869058881592L;
public InvalidXPathException(String xpath) {
public InvalidXPathException(String xpath) {
super("Invalid XPath expression: " + xpath);
}
public InvalidXPathException(String xpath, String 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;
/**
* <p>
* <code>Namespace</code> is a Flyweight Namespace that can be shared amongst
* nodes.
* </p>
*
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.22 $
*/
public class Namespace extends AbstractNode {
/** Cache of Namespace instances */
@ -51,6 +49,10 @@ public class Namespace extends AbstractNode {
public Namespace(String prefix, String uri) {
this.prefix = (prefix != null) ? prefix : "";
this.uri = (uri != null) ? uri : "";
if (!this.prefix.isEmpty()) {
QName.validateNCName(this.prefix);
}
}
/**

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

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

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

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

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

@ -10,16 +10,15 @@ package org.dom4j;
import java.util.Map;
/**
* <p>
* <code>ProcessingInstruction</code> defines an XML processing instruction.
* The {@link Node#getName}method will return the target of the PI and the
* {@link Node#getText}method will return the data from all of the
* instructions.
* </p>
*
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.10 $
*/
@SuppressWarnings("unused")
public interface ProcessingInstruction extends Node {
/**
* This method is the equivalent to the {@link #getName}method. It is added
@ -63,11 +62,11 @@ public interface ProcessingInstruction extends Node {
*
* @return the values for this processing instruction as a Map
*/
Map getValues();
Map<String, String> getValues();
void setValue(String name, String value);
void setValues(Map data);
void setValues(Map<String, String> data);
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.ObjectOutputStream;
import java.io.Serializable;
import java.util.regex.Pattern;
import org.dom4j.tree.QNameCache;
import org.dom4j.util.SingletonStrategy;
/**
* <p>
* <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
* object is immutable.
* </p>
*
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @author Filip Jirsák
*/
public class QName implements Serializable {
/** 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 {
try {
String defaultSingletonClass = "org.dom4j.util.SimpleSingleton";
Class clazz = null;
Class<SingletonStrategy> clazz = null;
try {
String singletonClass = defaultSingletonClass;
singletonClass = System.getProperty(
"org.dom4j.QName.singleton.strategy", singletonClass);
clazz = Class.forName(singletonClass);
clazz = (Class<SingletonStrategy>) Class.forName(singletonClass);
} catch (Exception exc1) {
try {
String singletonClass = defaultSingletonClass;
clazz = Class.forName(singletonClass);
clazz = (Class<SingletonStrategy>) Class.forName(singletonClass);
} catch (Exception exc2) {
}
}
singleton = (SingletonStrategy) clazz.newInstance();
singleton = clazz.newInstance();
singleton.setSingletonClassName(QNameCache.class.getName());
} catch (Exception exc3) {
}
@ -73,6 +147,11 @@ public class QName implements Serializable {
this.name = (name == null) ? "" : name;
this.namespace = (namespace == null) ? Namespace.NO_NAMESPACE
: namespace;
if (this.namespace.equals(Namespace.NO_NAMESPACE)) {
validateName(this.name);
} else {
validateNCName(this.name);
}
}
public QName(String name, Namespace namespace, String qualifiedName) {
@ -80,6 +159,8 @@ public class QName implements Serializable {
this.qualifiedName = qualifiedName;
this.namespace = (namespace == null) ? Namespace.NO_NAMESPACE
: namespace;
validateNCName(this.name);
validateQName(this.qualifiedName);
}
public static QName get(String name) {
@ -231,28 +312,46 @@ public class QName implements Serializable {
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
// We use writeObject() and not writeUTF() to minimize space
// This allows for writing pointers to already written strings
out.writeObject(namespace.getPrefix());
out.writeObject(namespace.getURI());
out.defaultWriteObject();
}
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
in.defaultReadObject();
String prefix = (String) in.readObject();
String uri = (String) in.readObject();
in.defaultReadObject();
namespace = Namespace.get(prefix, uri);
}
private static QNameCache getCache() {
QNameCache cache = (QNameCache) singleton.instance();
QNameCache cache = singleton.instance();
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.
*
* 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;
/**
* <p>
* <code>Text</code> defines an XML Text node.
* </p>
*
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.7 $
*/
@SuppressWarnings("unused")
public interface Text extends CharacterData {
}

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

@ -8,24 +8,21 @@
package org.dom4j;
/**
* <p>
* <code>Visitor</code> is used to implement the <code>Visitor</code>
* 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
* to the <i>Gang of Four </i> book of Design Patterns for more details on the
* <code>Visitor</code> pattern.
* </p>
*
* <p>
*
* 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
* href="http://www.patterndepot.com/put/8/visitor.pdf">link </a> describes the
* Visitor pattern in detail.
* </p>
*
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.8 $
*/
@SuppressWarnings("unused")
public interface Visitor {
/**
* <p>

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

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

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

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

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

@ -8,13 +8,11 @@
package org.dom4j;
/**
* <p>
* <code>XPathException</code> is thrown when an exception occurs while
* evaluating an XPath expression, usually due to some function throwing an
* exception.
* </p>
*
* @version $Revision$
*
* @version $Revision: 1.6 $
*/
public class XPathException extends RuntimeException {
/** 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>
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.7 $
*/
public class BeanAttribute extends AbstractAttribute {
/** 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>
*
* @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 */
private BeanElement parent;
@ -41,18 +41,18 @@ public class BeanAttributeList extends AbstractList {
this.parent = parent;
Object data = parent.getData();
Class beanClass = (data != null) ? data.getClass() : null;
Class<?> beanClass = (data != null) ? data.getClass() : null;
this.beanMetaData = BeanMetaData.get(beanClass);
this.attributes = new BeanAttribute[beanMetaData.attributeCount()];
}
public Attribute attribute(String name) {
public BeanAttribute attribute(String name) {
int index = beanMetaData.getIndex(name);
return attribute(index);
}
public Attribute attribute(QName qname) {
public BeanAttribute attribute(QName qname) {
int index = beanMetaData.getIndex(qname);
return attribute(index);
@ -91,11 +91,12 @@ public class BeanAttributeList extends AbstractList {
// List interface
// -------------------------------------------------------------------------
@Override
public int size() {
return attributes.length;
}
public Object get(int index) {
public BeanAttribute get(int index) {
BeanAttribute attribute = attributes[index];
if (attribute == null) {
@ -106,15 +107,15 @@ public class BeanAttributeList extends AbstractList {
return attribute;
}
public boolean add(Object object) {
public boolean add(BeanAttribute object) {
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");
}
public Object set(int index, Object object) {
public BeanAttribute set(int index, BeanAttribute object) {
throw new UnsupportedOperationException("set(int,Object) unsupported");
}
@ -122,18 +123,15 @@ public class BeanAttributeList extends AbstractList {
return false;
}
public Object remove(int index) {
BeanAttribute attribute = (BeanAttribute) get(index);
Object oldValue = attribute.getValue();
public BeanAttribute remove(int index) {
BeanAttribute attribute = get(index);
attribute.setValue(null);
return oldValue;
return attribute;
}
public void clear() {
for (int i = 0, size = attributes.length; i < size; i++) {
BeanAttribute attribute = attributes[i];
for (BeanAttribute attribute : attributes) {
if (attribute != 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>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.14 $
*/
public class BeanDocumentFactory extends DocumentFactory {
/** The Singleton instance */
@ -78,7 +78,7 @@ public class BeanDocumentFactory extends DocumentFactory {
if (value != null) {
try {
Class beanClass = Class.forName(value, true,
Class<?> beanClass = Class.forName(value, true,
BeanDocumentFactory.class.getClassLoader());
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>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.15 $
*/
public class BeanElement extends DefaultElement {
/** The <code>DocumentFactory</code> instance used by default */
@ -70,11 +70,11 @@ public class BeanElement extends DefaultElement {
setAttributeList(null);
}
public Attribute attribute(String name) {
public BeanAttribute attribute(String name) {
return getBeanAttributeList().attribute(name);
}
public Attribute attribute(QName qname) {
public BeanAttribute attribute(QName qname) {
return getBeanAttributeList().attribute(qname);
}
@ -98,7 +98,7 @@ public class BeanElement extends DefaultElement {
return this;
}
public void setAttributes(List attributes) {
public void setAttributes(List<Attribute> attributes) {
throw new UnsupportedOperationException("Not implemented yet.");
}
@ -109,7 +109,7 @@ public class BeanElement extends DefaultElement {
if (className != null) {
try {
Class beanClass = Class.forName(className, true,
Class<?> beanClass = Class.forName(className, true,
BeanElement.class.getClassLoader());
this.setData(beanClass.newInstance());
@ -147,11 +147,11 @@ public class BeanElement extends DefaultElement {
*
* @return DOCUMENT ME!
*/
protected List createAttributeList() {
protected List<Attribute> createAttributeList() {
return new BeanAttributeList(this);
}
protected List createAttributeList(int size) {
protected List<Attribute> createAttributeList(int size) {
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>
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.10 $
*/
public class BeanMetaData {
/** Empty arguments for reflection calls */
protected static final Object[] NULL_ARGS = {};
/** 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
.getInstance();
/** The class of the bean */
private Class beanClass;
private Class<?> beanClass;
/** Property descriptors for the bean */
private PropertyDescriptor[] propertyDescriptors;
@ -51,10 +51,12 @@ public class BeanMetaData {
/** Write methods used for setting properties */
private Method[] writeMethods;
/** Index of names and QNames to indices */
private Map nameMap = new HashMap();
/** Index of names and QNames to indices
* 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;
if (beanClass != null) {
@ -83,9 +85,8 @@ public class BeanMetaData {
readMethods[i] = propertyDescriptor.getReadMethod();
writeMethods[i] = propertyDescriptor.getWriteMethod();
Integer index = new Integer(i);
nameMap.put(name, index);
nameMap.put(qName, index);
nameMap.put(name, i);
nameMap.put(qName, i);
}
}
@ -97,8 +98,8 @@ public class BeanMetaData {
*
* @return DOCUMENT ME!
*/
public static BeanMetaData get(Class beanClass) {
BeanMetaData answer = (BeanMetaData) singletonCache.get(beanClass);
public static BeanMetaData get(Class<?> beanClass) {
BeanMetaData answer = singletonCache.get(beanClass);
if (answer == null) {
answer = new BeanMetaData(beanClass);
@ -126,15 +127,15 @@ public class BeanMetaData {
}
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) {
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) {

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>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.9 $
*/
public class DatatypeAttribute extends AbstractAttribute implements
SerializationContext, ValidationContext {

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

@ -26,7 +26,7 @@ import org.xml.sax.InputSource;
* </p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.9 $
*/
public class DatatypeDocumentFactory extends DocumentFactory {
// 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>
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.9 $
*/
public class DatatypeElement extends DefaultElement implements
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 Yuxin Ruan
* @version $Revision$
* @version $Revision: 1.9 $
*/
public class DatatypeElementFactory extends DocumentFactory {
private QName elementQName;
@ -34,13 +34,13 @@ public class DatatypeElementFactory extends DocumentFactory {
* Cache of <code>XSDatatype</code> instances per Attribute
* <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
* <code>QName</code>
*/
private Map childrenXSDatatypes = new HashMap();
private Map<QName, XSDatatype> childrenXSDatatypes = new HashMap<QName, XSDatatype>();
public DatatypeElementFactory(QName elementQName) {
this.elementQName = elementQName;
@ -65,7 +65,7 @@ public class DatatypeElementFactory extends DocumentFactory {
* QName
*/
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
*/
public XSDatatype getChildElementXSDatatype(QName qname) {
return (XSDatatype) childrenXSDatatypes.get(qname);
return childrenXSDatatypes.get(qname);
}
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
* </p>
*
* @version $Revision$
* @version $Revision: 1.6 $
*/
public class InvalidSchemaException extends IllegalArgumentException {
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>
*
* @author Yuxin Ruan
* @version $Revision$
* @version $Revision: 1.8 $
*/
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;
@ -55,10 +55,7 @@ class NamedTypeResolver {
}
void resolveElementTypes() {
Iterator iterator = typedElementMap.keySet().iterator();
while (iterator.hasNext()) {
Element element = (Element) iterator.next();
for (Element element : typedElementMap.keySet()) {
QName elementQName = getQNameOfSchemaElement(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 Yuxin Ruan
* @version $Revision$
* @version $Revision: 1.19 $
*/
public class SchemaParser {
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
* this build
*/
private Map dataTypeCache = new HashMap();
private Map<String, XSDatatype> dataTypeCache = new HashMap<String, XSDatatype>();
/** NamedTypeResolver */
private NamedTypeResolver namedTypeResolver;
@ -113,11 +113,7 @@ public class SchemaParser {
Element root = schemaDocument.getRootElement();
if (root != null) {
// handle schema includes
Iterator includeIter = root.elementIterator(XSD_INCLUDE);
while (includeIter.hasNext()) {
Element includeElement = (Element) includeIter.next();
for (Element includeElement : root.elements(XSD_INCLUDE)) {
String inclSchemaInstanceURI = includeElement
.attributeValue("schemaLocation");
EntityResolver resolver = schemaDocument.getEntityResolver();
@ -151,24 +147,18 @@ public class SchemaParser {
}
// handle elements
Iterator iter = root.elementIterator(XSD_ELEMENT);
while (iter.hasNext()) {
onDatatypeElement((Element) iter.next(), documentFactory);
for (Element element : root.elements(XSD_ELEMENT)) {
onDatatypeElement(element, documentFactory);
}
// handle named simple types
iter = root.elementIterator(XSD_SIMPLETYPE);
while (iter.hasNext()) {
onNamedSchemaSimpleType((Element) iter.next());
for (Element element : root.elements(XSD_SIMPLETYPE)) {
onNamedSchemaSimpleType(element);
}
// hanlde named complex types
iter = root.elementIterator(XSD_COMPLEXTYPE);
while (iter.hasNext()) {
onNamedSchemaComplexType((Element) iter.next());
for (Element element : root.elements(XSD_COMPLEXTYPE)) {
onNamedSchemaComplexType(element);
}
namedTypeResolver.resolveNamedTypes();
@ -190,15 +180,19 @@ public class SchemaParser {
DocumentFactory parentFactory) {
String name = xsdElement.attributeValue("name");
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) {
// register type with this element name
XSDatatype dataType = getTypeByName(type);
if (dataType != null) {
if (dataType != null && factory != null) {
factory.setChildElementXSDatatype(qname, dataType);
} else {
QName typeQName = getQName(type);
@ -215,24 +209,25 @@ public class SchemaParser {
if (xsdSimpleType != null) {
XSDatatype dataType = loadXSDatatypeFromSimpleType(xsdSimpleType);
if (dataType != null) {
if (dataType != null && factory != null) {
factory.setChildElementXSDatatype(qname, dataType);
}
}
Element schemaComplexType = xsdElement.element(XSD_COMPLEXTYPE);
if (schemaComplexType != null) {
if (schemaComplexType != null && factory != null) {
onSchemaComplexType(schemaComplexType, factory);
}
Iterator iter = xsdElement.elementIterator(XSD_ATTRIBUTE);
if (iter.hasNext()) {
do {
onDatatypeAttribute(xsdElement, factory, (Element) iter
.next());
} while (iter.hasNext());
if (factory != null) {
Iterator<Element> iter = xsdElement.elementIterator(XSD_ATTRIBUTE);
if (iter.hasNext()) {
do {
onDatatypeAttribute(xsdElement, factory, iter
.next());
} while (iter.hasNext());
}
}
}
@ -268,10 +263,10 @@ public class SchemaParser {
*/
private void onSchemaComplexType(Element schemaComplexType,
DatatypeElementFactory elementFactory) {
Iterator iter = schemaComplexType.elementIterator(XSD_ATTRIBUTE);
Iterator<Element> iter = schemaComplexType.elementIterator(XSD_ATTRIBUTE);
while (iter.hasNext()) {
Element xsdAttribute = (Element) iter.next();
Element xsdAttribute = iter.next();
String name = xsdAttribute.attributeValue("name");
QName qname = getQName(name);
@ -308,10 +303,10 @@ public class SchemaParser {
}
private void onChildElements(Element element, DatatypeElementFactory fact) {
Iterator iter = element.elementIterator(XSD_ELEMENT);
Iterator<Element> iter = element.elementIterator(XSD_ELEMENT);
while (iter.hasNext()) {
Element xsdElement = (Element) iter.next();
Element xsdElement = iter.next();
onDatatypeElement(xsdElement, fact);
}
}
@ -355,7 +350,7 @@ public class SchemaParser {
*/
private XSDatatype dataTypeForXsdAttribute(Element xsdAttribute) {
String type = xsdAttribute.attributeValue("type");
XSDatatype dataType = null;
XSDatatype dataType;
if (type != null) {
dataType = getTypeByName(type);
@ -459,9 +454,9 @@ public class SchemaParser {
ValidationContext context = null;
try {
for (Iterator iter = xsdRestriction.elementIterator(); iter
for (Iterator<Element> iter = xsdRestriction.elementIterator(); iter
.hasNext();) {
Element element = (Element) iter.next();
Element element = iter.next();
String name = element.getName();
String value = element.attributeValue("value");
boolean fixed = AttributeHelper.booleanValue(element, "fixed");
@ -504,7 +499,7 @@ public class SchemaParser {
}
private XSDatatype getTypeByName(String type) {
XSDatatype dataType = (XSDatatype) dataTypeCache.get(type);
XSDatatype dataType = dataTypeCache.get(type);
if (dataType == null) {
// first check to see if it is a built-in type
@ -530,7 +525,7 @@ public class SchemaParser {
if (dataType == null) {
// it's no built-in type, maybe it's a type we defined ourself
QName typeQName = getQName(type);
dataType = (XSDatatype) namedTypeResolver.simpleTypeMap
dataType = namedTypeResolver.simpleTypeMap
.get(typeQName);
}

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

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

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

@ -10,13 +10,7 @@ package org.dom4j.dom;
import org.dom4j.Element;
import org.dom4j.QName;
import org.dom4j.tree.DefaultAttribute;
import org.w3c.dom.DOMException;
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;
import org.w3c.dom.*;
/**
* <p>
@ -25,7 +19,7 @@ import org.w3c.dom.UserDataHandler;
* </p>
*
* @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 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>
*
* @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 {
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.Element;
import org.dom4j.tree.DefaultCDATA;
import org.w3c.dom.DOMException;
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;
import org.w3c.dom.*;
/**
* <p>
@ -25,7 +19,7 @@ import org.w3c.dom.UserDataHandler;
* </p>
*
* @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 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.tree.DefaultComment;
import org.w3c.dom.DOMException;
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 org.w3c.dom.*;
/**
* <p>
@ -22,7 +17,7 @@ import org.w3c.dom.UserDataHandler;
* </p>
*
* @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 DOMComment(String text) {

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

@ -7,20 +7,16 @@
package org.dom4j.dom;
import org.dom4j.DocumentFactory;
import org.dom4j.QName;
import org.dom4j.*;
import org.dom4j.tree.DefaultDocument;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.DOMException;
import org.w3c.dom.*;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.EntityReference;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.UserDataHandler;
import org.w3c.dom.Text;
import java.util.ArrayList;
@ -31,7 +27,7 @@ import java.util.ArrayList;
* </p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.17 $
*/
public class DOMDocument extends DefaultDocument implements Document {
/** 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;
import org.dom4j.Attribute;
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.*;
import org.dom4j.util.SingletonStrategy;
import org.w3c.dom.DOMException;
@ -31,32 +20,32 @@ import java.util.Map;
* </p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.21 $
*/
public class DOMDocumentFactory extends DocumentFactory implements
org.w3c.dom.DOMImplementation {
/** The Singleton instance */
private static SingletonStrategy singleton = null;
private static SingletonStrategy<DOMDocumentFactory> singleton = null;
static {
try {
String defaultSingletonClass = "org.dom4j.util.SimpleSingleton";
Class clazz = null;
Class<SingletonStrategy> clazz = null;
try {
String singletonClass = defaultSingletonClass;
singletonClass = System.getProperty(
"org.dom4j.dom.DOMDocumentFactory.singleton.strategy",
singletonClass);
clazz = Class.forName(singletonClass);
clazz = (Class<SingletonStrategy>) Class.forName(singletonClass);
} catch (Exception exc1) {
try {
String singletonClass = defaultSingletonClass;
clazz = Class.forName(singletonClass);
clazz = (Class<SingletonStrategy>) Class.forName(singletonClass);
} catch (Exception exc2) {
}
}
singleton = (SingletonStrategy) clazz.newInstance();
singleton = clazz.newInstance();
singleton.setSingletonClassName(DOMDocumentFactory.class.getName());
} catch (Exception exc3) {
}
@ -66,12 +55,11 @@ public class DOMDocumentFactory extends DocumentFactory implements
* <p>
* Access to the singleton instance of this factory.
* </p>
*
*
* @return the default singleon instance
*/
public static DocumentFactory getInstance() {
DOMDocumentFactory fact = (DOMDocumentFactory) singleton.instance();
return fact;
return singleton.instance();
}
// Factory methods
@ -83,7 +71,7 @@ public class DOMDocumentFactory extends DocumentFactory implements
}
public DocumentType createDocType(String name, String publicId,
String systemId) {
String systemId) {
return new DOMDocumentType(name, publicId, systemId);
}
@ -124,12 +112,12 @@ public class DOMDocumentFactory extends DocumentFactory implements
}
public ProcessingInstruction createProcessingInstruction(String target,
String data) {
String data) {
return new DOMProcessingInstruction(target, data);
}
public ProcessingInstruction createProcessingInstruction(String target,
Map data) {
Map<String, String> 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;
import org.dom4j.tree.DefaultDocumentType;
import org.w3c.dom.DOMException;
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 org.w3c.dom.*;
/**
* <p>
@ -22,7 +17,7 @@ import org.w3c.dom.UserDataHandler;
* </p>
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.11 $
*/
public class DOMDocumentType extends DefaultDocumentType implements
org.w3c.dom.DocumentType {

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

@ -7,19 +7,12 @@
package org.dom4j.dom;
import org.dom4j.Attribute;
import org.dom4j.DocumentFactory;
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.*;
import org.dom4j.tree.DefaultElement;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Element;
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.List;
@ -31,7 +24,7 @@ import java.util.List;
* </p>
*
* @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 {
/** 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.tree.DefaultEntity;
import org.w3c.dom.DOMException;
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 org.w3c.dom.*;
/**
* <p>
@ -23,7 +18,7 @@ import org.w3c.dom.UserDataHandler;
* </p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.12 $
*/
public class DOMEntityReference extends DefaultEntity implements
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.tree.DefaultNamespace;
import org.w3c.dom.DOMException;
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 org.w3c.dom.*;
/**
* <p>
@ -23,7 +18,7 @@ import org.w3c.dom.UserDataHandler;
* </p>
*
* @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 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;
import org.dom4j.Branch;
import org.dom4j.CharacterData;
import org.dom4j.Document;
import org.dom4j.DocumentType;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.*;
import org.w3c.dom.DOMException;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
@ -26,7 +21,7 @@ import java.util.List;
* </p>
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.20 $
*/
public class DOMNodeHelper {
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)
throws DOMException {
if (node instanceof Branch) {
assert newChild instanceof Node;
Branch branch = (Branch) node;
List list = branch.content();
List<Node> list = branch.content();
int index = list.indexOf(refChild);
if (index < 0) {
branch.add((Node) newChild);
} else {
list.add(index, newChild);
list.add(index, (Node) newChild);
}
return newChild;
@ -149,7 +145,8 @@ public class DOMNodeHelper {
throws DOMException {
if (node instanceof Branch) {
Branch branch = (Branch) node;
List list = branch.content();
List<Node> list = branch.content();
assert newChild instanceof Node;
int index = list.indexOf(oldChild);
if (index < 0) {
@ -158,7 +155,7 @@ public class DOMNodeHelper {
+ node);
}
list.set(index, newChild);
list.set(index, (Node) newChild);
return oldChild;
} else {
@ -271,7 +268,7 @@ public class DOMNodeHelper {
String text = charData.getText();
if (text == null) {
charData.setText(text);
charData.setText(arg);
} else {
charData.setText(text + arg);
}
@ -295,7 +292,7 @@ public class DOMNodeHelper {
throw new DOMException(DOMException.INDEX_SIZE_ERR,
"No text at offset: " + offset);
} else {
StringBuffer buffer = new StringBuffer(text);
StringBuilder buffer = new StringBuilder(text);
buffer.insert(offset, arg);
data.setText(buffer.toString());
}
@ -323,7 +320,7 @@ public class DOMNodeHelper {
throw new DOMException(DOMException.INDEX_SIZE_ERR,
"No text at offset: " + offset);
} else {
StringBuffer buffer = new StringBuffer(text);
StringBuilder buffer = new StringBuilder(text);
buffer.delete(offset, offset + count);
charData.setText(buffer.toString());
}
@ -351,7 +348,7 @@ public class DOMNodeHelper {
throw new DOMException(DOMException.INDEX_SIZE_ERR,
"No text at offset: " + offset);
} else {
StringBuffer buffer = new StringBuffer(text);
StringBuilder buffer = new StringBuilder(text);
buffer.replace(offset, offset + count, arg);
charData.setText(buffer.toString());
}
@ -361,7 +358,7 @@ public class DOMNodeHelper {
// Branch API
// -------------------------------------------------------------------------
public static void appendElementsByTagName(List list, Branch parent,
public static void appendElementsByTagName(List<? super Element> list, Branch parent,
String 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) {
final boolean isStarNS = "*".equals(namespace);
final boolean isStar = "*".equals(localName);
@ -409,7 +406,7 @@ public class DOMNodeHelper {
// Helper methods
// -------------------------------------------------------------------------
public static NodeList createNodeList(final List list) {
public static NodeList createNodeList(final List<Node> list) {
return new NodeList() {
public org.w3c.dom.Node item(int index) {
if (index >= getLength()) {
@ -420,7 +417,7 @@ public class DOMNodeHelper {
*/
return null;
} 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.tree.DefaultProcessingInstruction;
import org.w3c.dom.DOMException;
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 org.w3c.dom.*;
import java.util.Map;
@ -25,11 +20,11 @@ import java.util.Map;
* </p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.12 $
*/
public class DOMProcessingInstruction extends DefaultProcessingInstruction
implements org.w3c.dom.ProcessingInstruction {
public DOMProcessingInstruction(String target, Map values) {
public DOMProcessingInstruction(String target, Map<String, String> 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.Text;
import org.dom4j.tree.DefaultText;
import org.w3c.dom.DOMException;
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 org.w3c.dom.*;
/**
* <p>
@ -23,7 +18,7 @@ import org.w3c.dom.UserDataHandler;
* </p>
*
* @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 DOMText(String text) {

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

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

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

@ -13,9 +13,9 @@ package org.dom4j.dtd;
* </p>
*
* @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. */
private String elementName;

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

@ -13,9 +13,9 @@ package org.dom4j.dtd;
* </p>
*
* @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. */
private String name;

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

@ -14,9 +14,9 @@ package org.dom4j.dtd;
* </p>
*
* @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. */
private String name;

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

@ -14,9 +14,9 @@ package org.dom4j.dtd;
* </p>
*
* @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. */
private String name;

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

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

13
fine-org-dom4j/src/main/java/org/dom4j/io/DOMReader.java

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

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

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

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

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

@ -23,7 +23,7 @@ import org.xml.sax.InputSource;
* </p>
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.8 $
*/
class DocumentInputSource extends InputSource {
/** 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>
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.8 $
*/
public class DocumentResult extends SAXResult {
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;
/**
* <p>
* <code>DocumentSource</code> implements a JAXP {@link SAXSource}for a
* {@linkDocument}.
* </p>
*
* {@link Document}.
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.10 $
*/
public class DocumentSource extends SAXSource {
/**
@ -93,7 +91,7 @@ public class DocumentSource extends SAXSource {
}
/**
* This method is not supported as this source is always a {@linkDocument}
* This method is not supported as this source is always a {@link Document}
* instance.
*
* @param inputSource

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

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

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
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.7 $
*/
class JAXPHelper {
protected JAXPHelper() {

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

@ -8,13 +8,11 @@
package org.dom4j.io;
/**
* <p>
* <code>OutputFormat</code> represents the format configuration used by
* {@linkXMLWriter}and its base classes to format the XML output
* </p>
*
* {@link XMLWriter}and its base classes to format the XML output
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.17 $
*/
public class OutputFormat implements Cloneable {
/** standard value to indent by, if we are indenting */
@ -279,21 +277,14 @@ public class OutputFormat implements Cloneable {
}
/**
* <p>
* This will set whether the text is output verbatim (false) or with
* whitespace stripped as per <code>{@link
* org.dom4j.Element#getTextTrim()}</code>.
* </p>
*
* <p>
* </p>
*
* <p>
*
* Default: false
* </p>
*
*
* @param trimText
* <code>boolean</code> true=>trim the whitespace, false=>use
* <code>boolean</code> true trim the whitespace, false use
* text verbatim
*/
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
* be "padded" with a single space. This is used to allow make
* browser-friendly HTML, avoiding trimText's transformation of, e.g.,
@ -314,17 +304,12 @@ public class OutputFormat implements Cloneable {
* (the latter will run the three separate words together into a single
* word). This setting is not too useful if you haven't also called
* {@link #setTrimText}.
* </p>
*
* <p>
*
* The padding string will only be added if the text itself starts or ends
* with some whitespace characters.
* </p>
*
* <p>
*
* Default: false
* </p>
*
*
* @param padText
* <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
* <code>String</code> of empty spaces. If you pass null, or the empty
* string (""), then no indentation will happen.
* </p>
*
* Default: none (null)
*
* @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
* 4 would result in the indention being equivalent to the
* <code>String</code> "&nbsp;&nbsp;&nbsp;&nbsp;" (four space characters).
* </p>
*
*
* @param indentSize
* <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
* parser with real, closed tags. Also, XHTML CDATA sections will be output
* with the CDATA delimiters: ( &quot; <b>&lt;![CDATA[ </b>&quot; and &quot;
* <b>]]&gt; </b>&quot; ) otherwise, the class HTMLWriter will output the
* CDATA text, but not the delimiters.
* </p>
*
* <p>
*
* Default is <code>false</code>
* </p>
*
*
* @return DOCUMENT ME!
*/
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
* passes an XML parser with real, closed tags. Also, XHTML CDATA sections
* will be output with the CDATA delimiters: ( &quot; <b>&lt;[CDATA[
* </b>&quot; and &quot; <b>]]&lt; </b>) otherwise, the class HTMLWriter
* will output the CDATA text, but not the delimiters.
* </p>
*
* <p>
*
* Default: false
* </p>
*
*
* @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.
*/
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>
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.11 $
*/
class PruningElementStack extends ElementStack {
/** 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.Namespace;
import org.dom4j.QName;
import org.dom4j.dtd.AttributeDecl;
import org.dom4j.dtd.ElementDecl;
import org.dom4j.dtd.ExternalEntityDecl;
import org.dom4j.dtd.InternalEntityDecl;
import org.dom4j.dtd.*;
import org.dom4j.tree.AbstractElement;
import org.dom4j.tree.NamespaceStack;
@ -37,6 +34,7 @@ import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.ext.Locator2;
import org.xml.sax.helpers.DefaultHandler;
/**
@ -45,7 +43,7 @@ import org.xml.sax.helpers.DefaultHandler;
* </p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.61 $
*/
public class SAXContentHandler extends DefaultHandler implements
LexicalHandler, DeclHandler, DTDHandler {
@ -82,17 +80,11 @@ public class SAXContentHandler extends DefaultHandler implements
*/
private StringBuffer cdataText;
/** namespaces that are available for use */
private Map availableNamespaceMap = new HashMap();
/** declared namespaces that are not yet available for use */
private List declaredNamespaceList = new ArrayList();
/** internal DTD declarations */
private List internalDTDDeclarations;
private List<Decl> internalDTDDeclarations;
/** external DTD declarations */
private List externalDTDDeclarations;
private List<Decl> externalDTDDeclarations;
/** The number of namespaces that are declared in the current scope */
private int declaredNamespaceIndex;
@ -844,17 +836,8 @@ public class SAXContentHandler extends DefaultHandler implements
return null;
}
// use reflection to avoid dependency on Locator2
// or other locator implemenations.
try {
Method m = locator.getClass().getMethod("getEncoding",
new Class[] {});
if (m != null) {
return (String) m.invoke(locator, null);
}
} catch (Exception e) {
// do nothing
if (locator instanceof Locator2) {
return ((Locator2) locator).getEncoding();
}
// couldn't determine encoding, returning null...
@ -941,9 +924,9 @@ public class SAXContentHandler extends DefaultHandler implements
* @param declaration
* DOCUMENT ME!
*/
protected void addDTDDeclaration(Object declaration) {
protected void addDTDDeclaration(Decl declaration) {
if (internalDTDDeclarations == null) {
internalDTDDeclarations = new ArrayList();
internalDTDDeclarations = new ArrayList<Decl>();
}
internalDTDDeclarations.add(declaration);
@ -955,9 +938,9 @@ public class SAXContentHandler extends DefaultHandler implements
* @param declaration
* DOCUMENT ME!
*/
protected void addExternalDTDDeclaration(Object declaration) {
protected void addExternalDTDDeclaration(Decl declaration) {
if (externalDTDDeclarations == null) {
externalDTDDeclarations = new ArrayList();
externalDTDDeclarations = new ArrayList<Decl>();
}
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 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";
@ -79,11 +79,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
}
public void replay(ContentHandler handler) throws SAXException {
SAXEvent saxEvent;
Iterator itr = events.iterator();
while (itr.hasNext()) {
saxEvent = (SAXEvent) itr.next();
for (SAXEvent saxEvent : events) {
switch (saxEvent.event) {
// replay to ContentHandler
@ -117,13 +113,10 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
case SAXEvent.START_ELEMENT:
AttributesImpl attributes = new AttributesImpl();
List attParmList = (List) saxEvent.getParm(3);
List<String[]> attParmList = (List<String[]>) saxEvent.getParm(3);
if (attParmList != null) {
Iterator attsItr = attParmList.iterator();
while (attsItr.hasNext()) {
String[] attParms = (String[]) attsItr.next();
for (String[] attParms : attParmList) {
attributes.addAttribute(attParms[0], attParms[1],
attParms[2], attParms[3], attParms[4]);
}
@ -145,8 +138,8 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
case SAXEvent.CHARACTERS:
char[] chars = (char[]) saxEvent.getParm(0);
int start = ((Integer) saxEvent.getParm(1)).intValue();
int end = ((Integer) saxEvent.getParm(2)).intValue();
int start = (Integer) saxEvent.getParm(1);
int end = (Integer) saxEvent.getParm(2);
handler.characters(chars, start, end);
break;
@ -154,7 +147,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
// replay to LexicalHandler
case SAXEvent.START_DTD:
((LexicalHandler) handler).startDTD((String) saxEvent
.getParm(0), (String) saxEvent.getParm(1),
.getParm(0), (String) saxEvent.getParm(1),
(String) saxEvent.getParm(2));
break;
@ -189,8 +182,8 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
case SAXEvent.COMMENT:
char[] cchars = (char[]) saxEvent.getParm(0);
int cstart = ((Integer) saxEvent.getParm(1)).intValue();
int cend = ((Integer) saxEvent.getParm(2)).intValue();
int cstart = (Integer) saxEvent.getParm(1);
int cend = (Integer) saxEvent.getParm(2);
((LexicalHandler) handler).comment(cchars, cstart, cend);
break;
@ -204,7 +197,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
case SAXEvent.ATTRIBUTE_DECL:
((DeclHandler) handler).attributeDecl((String) saxEvent
.getParm(0), (String) saxEvent.getParm(1),
.getParm(0), (String) saxEvent.getParm(1),
(String) saxEvent.getParm(2), (String) saxEvent
.getParm(3), (String) saxEvent.getParm(4));
@ -272,7 +265,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
saxEvent.addParm(localName);
saxEvent.addParm(qualifiedName);
QName qName = null;
QName qName;
if (namespaceURI != null) {
qName = new QName(localName, Namespace.get(namespaceURI));
} else {
@ -280,8 +273,8 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
}
if ((attributes != null) && (attributes.getLength() > 0)) {
List attParmList = new ArrayList(attributes.getLength());
String[] attParms = null;
List<String[]> attParmList = new ArrayList<String[]>(attributes.getLength());
String[] attParms;
for (int i = 0; i < attributes.getLength(); i++) {
@ -292,7 +285,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
// if SAXWriter is writing a DOMDocument, namespace
// decls are treated as attributes. record a start
// prefix mapping event
String prefix = null;
String prefix;
if (attLocalName.length() > 5) {
prefix = attLocalName.substring(6);
} else {
@ -307,9 +300,9 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
// 'register' the prefix so that we can generate
// an end prefix mapping event within endElement
List prefixes = (List) prefixMappings.get(qName);
List<String> prefixes = prefixMappings.get(qName);
if (prefixes == null) {
prefixes = new ArrayList();
prefixes = new ArrayList<String>();
prefixMappings.put(qName, prefixes);
}
prefixes.add(prefix);
@ -346,20 +339,19 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
// check to see if a we issued a start prefix mapping event
// for DOMDocument namespace decls
QName elementName = null;
QName elementName;
if (namespaceURI != null) {
elementName = new QName(localName, Namespace.get(namespaceURI));
} else {
elementName = new QName(localName);
}
List prefixes = (List) prefixMappings.get(elementName);
List<String> prefixes = prefixMappings.get(elementName);
if (prefixes != null) {
Iterator itr = prefixes.iterator();
while (itr.hasNext()) {
SAXEvent prefixEvent =
for (String prefixe : prefixes) {
SAXEvent prefixEvent =
new SAXEvent(SAXEvent.END_PREFIX_MAPPING);
prefixEvent.addParm(itr.next());
prefixEvent.addParm(prefixe);
events.add(prefixEvent);
}
}
@ -369,8 +361,8 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
public void characters(char[] ch, int start, int end) throws SAXException {
SAXEvent saxEvent = new SAXEvent(SAXEvent.CHARACTERS);
saxEvent.addParm(ch);
saxEvent.addParm(new Integer(start));
saxEvent.addParm(new Integer(end));
saxEvent.addParm(start);
saxEvent.addParm(end);
events.add(saxEvent);
}
@ -415,8 +407,8 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
public void comment(char[] ch, int start, int end) throws SAXException {
SAXEvent saxEvent = new SAXEvent(SAXEvent.COMMENT);
saxEvent.addParm(ch);
saxEvent.addParm(new Integer(start));
saxEvent.addParm(new Integer(end));
saxEvent.addParm(start);
saxEvent.addParm(end);
events.add(saxEvent);
}
@ -469,7 +461,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
public void readExternal(ObjectInput in) throws ClassNotFoundException,
IOException {
if (in.readByte() != NULL) {
events = (List) in.readObject();
events = (List<SAXEvent>) in.readObject();
}
}
@ -518,7 +510,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
protected byte event;
protected List parms;
protected List<Object> parms;
public SAXEvent() {
}
@ -529,7 +521,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
void addParm(Object parm) {
if (parms == null) {
parms = new ArrayList(3);
parms = new ArrayList<Object>(3);
}
parms.add(parm);
@ -559,7 +551,7 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
event = in.readByte();
if (in.readByte() != NULL) {
parms = (List) in.readObject();
parms = (List<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.helpers.XMLReaderFactory;
import javax.xml.parsers.SAXParserFactory;
/**
* <p>
* <code>SAXHelper</code> contains some helper methods for working with SAX
* and XMLReader objects.
* </p>
*
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.18 $
*/
class SAXHelper {
private static boolean loggedWarning = true;
@ -61,12 +63,21 @@ class SAXHelper {
/**
* Creats a default XMLReader via the org.xml.sax.driver system property or
* JAXP if the system property is not set.
*
*
* This method internally calls {@link SAXParserFactory}{@code .newInstance().newSAXParser().getXMLReader()} or {@link XMLReaderFactory#createXMLReader()}.
* Be sure to configure returned reader if the default configuration does not suit you. Consider setting the following properties:
*
* <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
* DOCUMENT ME!
*
*
* @return DOCUMENT ME!
*
*
* @throws SAXException
* DOCUMENT ME!
*/
@ -103,6 +114,21 @@ class SAXHelper {
throw new SAXException("Couldn't create SAX reader");
}
// configure namespace support
SAXHelper.setParserFeature(reader, "http://xml.org/sax/features/namespaces", true);
SAXHelper.setParserFeature(reader, "http://xml.org/sax/features/namespace-prefixes", false);
// external entites
SAXHelper.setParserFeature(reader, "http://xml.org/sax/properties/external-general-entities", false);
SAXHelper.setParserFeature(reader, "http://xml.org/sax/properties/external-parameter-entities", false);
// external DTD
SAXHelper.setParserFeature(reader,"http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
// use Locator2 if possible
SAXHelper.setParserFeature(reader,"http://xml.org/sax/features/use-locator2", true);
return reader;
}
@ -110,12 +136,12 @@ class SAXHelper {
* This method attempts to use JAXP to locate the SAX2 XMLReader
* implementation. This method uses reflection to avoid being dependent
* directly on the JAXP classes.
*
*
* @param validating
* DOCUMENT ME!
* @param namespaceAware
* DOCUMENT ME!
*
*
* @return DOCUMENT ME!
*/
protected static XMLReader createXMLReaderViaJAXP(boolean validating,
@ -161,24 +187,24 @@ class SAXHelper {
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the
* following conditions are met:
*
*
* 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*
* 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com.
*
*
* 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
*
*
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
*
*
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -190,6 +216,6 @@ class SAXHelper {
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/

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

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

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

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

@ -293,7 +293,7 @@ public class STAXEventReader {
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
* stream was not positioned before a {@linkStartElement}event.
* stream was not positioned before a {@link StartElement}event.
*/
public Element readElement(XMLEventReader eventReader)
throws XMLStreamException {
@ -348,7 +348,7 @@ public class STAXEventReader {
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
* stream was not positioned before an {@linkAttribute}event.
* stream was not positioned before an {@link Attribute}event.
*/
public org.dom4j.Attribute readAttribute(XMLEventReader reader)
throws XMLStreamException {
@ -375,7 +375,7 @@ public class STAXEventReader {
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
* stream was not positioned before a {@linkNamespace}event.
* stream was not positioned before a {@link Namespace}event.
*/
public org.dom4j.Namespace readNamespace(XMLEventReader reader)
throws XMLStreamException {
@ -402,7 +402,7 @@ public class STAXEventReader {
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
* stream was not positioned before a {@linkCharacters}event.
* stream was not positioned before a {@link Characters}event.
*/
public CharacterData readCharacters(XMLEventReader reader)
throws XMLStreamException {
@ -429,7 +429,7 @@ public class STAXEventReader {
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
* stream was not positioned before a {@linkComment}event.
* stream was not positioned before a {@link Comment}event.
*/
public org.dom4j.Comment readComment(XMLEventReader reader)
throws XMLStreamException {
@ -455,7 +455,7 @@ public class STAXEventReader {
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
* stream was not positioned before an {@linkEntityReference}
* stream was not positioned before an {@link EntityReference}
* event.
*/
public Entity readEntityReference(XMLEventReader reader)
@ -518,14 +518,14 @@ public class STAXEventReader {
Element elem = factory.createElement(elemName);
// create attributes
for (Iterator i = startEvent.getAttributes(); i.hasNext();) {
Attribute attr = (Attribute) i.next();
for (Iterator<Attribute> i = startEvent.getAttributes(); i.hasNext();) {
Attribute attr = i.next();
elem.addAttribute(createQName(attr.getName()), attr.getValue());
}
// create namespaces
for (Iterator i = startEvent.getNamespaces(); i.hasNext();) {
Namespace ns = (Namespace) i.next();
for (Iterator<Namespace> i = startEvent.getNamespaces(); i.hasNext();) {
Namespace ns = i.next();
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());
// create attribute & namespace iterators
Iterator attrIter = new AttributeIterator(elem.attributeIterator());
Iterator nsIter = new NamespaceIterator(elem.declaredNamespaces()
Iterator<javax.xml.stream.events.Attribute> attrIter = new AttributeIterator(elem.attributeIterator());
Iterator<javax.xml.stream.events.Namespace> nsIter = new NamespaceIterator(elem.declaredNamespaces()
.iterator());
// create start event
@ -288,7 +288,7 @@ public class STAXEventWriter {
*/
public EndElement createEndElement(Element elem) {
QName tagName = createQName(elem.getQName());
Iterator nsIter = new NamespaceIterator(elem.declaredNamespaces()
Iterator<javax.xml.stream.events.Namespace> nsIter = new NamespaceIterator(elem.declaredNamespaces()
.iterator());
return factory.createEndElement(tagName, nsIter);
@ -593,11 +593,11 @@ public class STAXEventWriter {
* Internal {@link Iterator}implementation used to pass DOM4J {@link
* Attribute}s to the stream.
*/
private class AttributeIterator implements Iterator {
private class AttributeIterator implements Iterator<javax.xml.stream.events.Attribute> {
/** The underlying DOm4J attribute iterator. */
private Iterator iter;
private Iterator<Attribute> iter;
public AttributeIterator(Iterator iter) {
public AttributeIterator(Iterator<Attribute> iter) {
this.iter = iter;
}
@ -605,8 +605,8 @@ public class STAXEventWriter {
return iter.hasNext();
}
public Object next() {
Attribute attr = (Attribute) iter.next();
public javax.xml.stream.events.Attribute next() {
Attribute attr = iter.next();
QName attrName = createQName(attr.getQName());
String value = attr.getValue();
@ -622,10 +622,10 @@ public class STAXEventWriter {
* Internal {@link Iterator}implementation used to pass DOM4J {@link
* Namespace}s to the stream.
*/
private class NamespaceIterator implements Iterator {
private Iterator iter;
private class NamespaceIterator implements Iterator<javax.xml.stream.events.Namespace> {
private Iterator<Namespace> iter;
public NamespaceIterator(Iterator iter) {
public NamespaceIterator(Iterator<Namespace> iter) {
this.iter = iter;
}
@ -633,8 +633,8 @@ public class STAXEventWriter {
return iter.hasNext();
}
public Object next() {
Namespace ns = (Namespace) iter.next();
public javax.xml.stream.events.Namespace next() {
Namespace ns = iter.next();
String prefix = ns.getPrefix();
String nsURI = ns.getURI();

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

@ -24,7 +24,7 @@ import org.xml.sax.ext.LexicalHandler;
* </p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.9 $
*/
public class XMLResult extends SAXResult {
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.helpers.XMLFilterImpl;
import static org.dom4j.util.StringUtils.endsWithWhitespace;
import static org.dom4j.util.StringUtils.startsWithWhitespace;
/**
* <p>
* <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
* or whether empty documents are collapsed.
* </p>
*
*
* <p>
* There are <code>write(...)</code> methods to print any of the standard
* 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
* UTF8, we recommend using the method that takes an OutputStream instead.
* </p>
*
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @author Joseph Bowbeer
* @version $Revision$
* @version $Revision: 1.83 $
*/
public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
private static final String PAD_TEXT = " ";
@ -139,7 +142,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
private boolean inDTD;
/** The namespaces used for the current element when consuming SAX events */
private Map namespacesMap;
private Map<String, String> namespacesMap;
/**
* what is the maximum allowed character code such as 127 in US-ASCII (7
@ -200,7 +203,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* DOCUMENT ME!
*
*
* @return true if text thats output should be escaped. This is enabled by
* default. It could be disabled if the output format is textual,
* like in XSLT where we can have xml, html or text output.
@ -213,7 +216,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Sets whether text output should be escaped or not. This is enabled by
* default. It could be disabled if the output format is textual, like in
* XSLT where we can have xml, html or text output.
*
*
* @param escapeText
* DOCUMENT ME!
*/
@ -225,7 +228,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Set the initial indentation level. This can be used to output a document
* (or, more likely, an element) starting at a given indent level, so it's
* not always flush against the left margin. Default: 0
*
*
* @param indentLevel
* the number of indents to start with
*/
@ -237,7 +240,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Returns the maximum allowed character code that should be allowed
* unescaped which defaults to 127 in US-ASCII (7 bit) or 255 in ISO- (8
* bit).
*
*
* @return DOCUMENT ME!
*/
public int getMaximumAllowedCharacter() {
@ -254,7 +257,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* escape any characters (other than the special XML characters like &lt;
* &gt; &amp;) If this is not explicitly set then it is defaulted from the
* encoding.
*
*
* @param maximumAllowedCharacter
* The maximumAllowedCharacter to set
*/
@ -264,7 +267,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Flushes the underlying Writer
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -274,7 +277,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Closes the underlying Writer
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -284,7 +287,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the new line text to the underlying Writer
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -294,10 +297,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link Attribute}.
*
*
* @param attribute
* <code>Attribute</code> to output.
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -313,21 +316,21 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* <p>
* This will print the <code>Document</code> to the current Writer.
* </p>
*
*
* <p>
* Warning: using your own Writer may cause the writer's preferred character
* encoding to be ignored. If you use encodings other than UTF8, we
* recommend using the method that takes an OutputStream instead.
* </p>
*
*
* <p>
* Note: as with all Writers, you may need to flush() yours after this
* method returns.
* </p>
*
*
* @param doc
* <code>Document</code> to format.
*
*
* @throws IOException
* if there's any problem writing.
*/
@ -358,10 +361,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* s, and its value, and all its content (child nodes) to the current
* Writer.
* </p>
*
*
* @param element
* <code>Element</code> to output.
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -375,10 +378,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link CDATA}.
*
*
* @param cdata
* <code>CDATA</code> to output.
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -392,10 +395,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link Comment}.
*
*
* @param comment
* <code>Comment</code> to output.
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -409,10 +412,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link DocumentType}.
*
*
* @param docType
* <code>DocumentType</code> to output.
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -426,10 +429,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link Entity}.
*
*
* @param entity
* <code>Entity</code> to output.
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -443,10 +446,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link Namespace}.
*
*
* @param namespace
* <code>Namespace</code> to output.
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -460,10 +463,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link ProcessingInstruction}.
*
*
* @param processingInstruction
* <code>ProcessingInstruction</code> to output.
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -481,10 +484,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Print out a {@link String}, Perfoms the necessary entity escaping and
* whitespace stripping.
* </p>
*
*
* @param text
* is the text to output
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -498,10 +501,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link Text}.
*
*
* @param text
* <code>Text</code> to output.
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -515,10 +518,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given {@link Node}.
*
*
* @param node
* <code>Node</code> to output.
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -533,10 +536,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the given object which should be a String, a Node or a List of
* Nodes.
*
*
* @param object
* is the object to output.
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -546,10 +549,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
} else if (object instanceof String) {
write((String) object);
} else if (object instanceof List) {
List list = (List) object;
List<?> list = (List<?>) object;
for (int i = 0, size = list.size(); i < size; i++) {
write(list.get(i));
for (Object aList : list) {
write(aList);
}
} else if (object != null) {
throw new IOException("Invalid object: " + object);
@ -561,16 +564,17 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Writes the opening tag of an {@link Element}, including its {@link
* Attribute}s but without its content.
* </p>
*
*
* @param element
* <code>Element</code> to output.
*
*
* @throws IOException
* DOCUMENT ME!
*/
public void writeOpen(Element element) throws IOException {
writer.write("<");
writer.write(element.getQualifiedName());
writeNamespaces(element);
writeAttributes(element);
writer.write(">");
}
@ -579,10 +583,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* <p>
* Writes the closing tag of an {@link Element}
* </p>
*
*
* @param element
* <code>Element</code> to output.
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -599,8 +603,8 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
public void setProperty(String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) {
if (LEXICAL_HANDLER_NAMES[i].equals(name)) {
for (String lexicalHandlerName : LEXICAL_HANDLER_NAMES) {
if (lexicalHandlerName.equals(name)) {
setLexicalHandler((LexicalHandler) value);
return;
@ -612,8 +616,8 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
public Object getProperty(String name) throws SAXNotRecognizedException,
SAXNotSupportedException {
for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) {
if (LEXICAL_HANDLER_NAMES[i].equals(name)) {
for (String lexicalHandlerName : LEXICAL_HANDLER_NAMES) {
if (lexicalHandlerName.equals(name)) {
return getLexicalHandler();
}
}
@ -662,7 +666,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
if (namespacesMap == null) {
namespacesMap = new HashMap();
namespacesMap = new HashMap<String, String>();
}
namespacesMap.put(prefix, uri);
@ -975,10 +979,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Determines if element is a special case of XML elements where it contains
* an xml:space attribute of "preserve". If it does, then retain whitespace.
*
*
* @param element
* DOCUMENT ME!
*
*
* @return DOCUMENT ME!
*/
protected final boolean isElementSpacePreserved(Element element) {
@ -986,12 +990,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
boolean preserveFound = preserve; // default to global state
if (attr != null) {
if ("xml".equals(attr.getNamespacePrefix())
&& "preserve".equals(attr.getText())) {
preserveFound = true;
} else {
preserveFound = false;
}
preserveFound = "xml".equals(attr.getNamespacePrefix()) && "preserve".equals(attr.getText());
}
return preserveFound;
@ -1003,10 +1002,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* whitespace trimming occurs to avoid problems with multiple text nodes
* being created due to text content that spans parser buffers in a SAX
* parser.
*
*
* @param element
* DOCUMENT ME!
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -1023,34 +1022,34 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
// concatenate adjacent text nodes together
// so that whitespace trimming works properly
Text lastTextNode = null;
StringBuffer buff = null;
StringBuilder buff = null;
boolean textOnly = true;
for (int i = 0, size = element.nodeCount(); i < size; i++) {
Node node = element.node(i);
for (Node node : element.content()) {
if (node instanceof Text) {
if (lastTextNode == null) {
lastTextNode = (Text) node;
} else {
if (buff == null) {
buff = new StringBuffer(lastTextNode.getText());
buff = new StringBuilder(lastTextNode.getText());
}
buff.append(((Text) node).getText());
buff.append((node).getText());
}
} else {
if (!textOnly && format.isPadText()) {
// only add the PAD_TEXT if the text itself starts with
// whitespace
char firstChar = 'a';
final boolean startsWithWhitespace;
if (buff != null) {
firstChar = buff.charAt(0);
startsWithWhitespace = startsWithWhitespace(buff);
} else if (lastTextNode != null) {
firstChar = lastTextNode.getText().charAt(0);
startsWithWhitespace = startsWithWhitespace(lastTextNode.getText());
} else {
startsWithWhitespace = false;
}
if (Character.isWhitespace(firstChar)) {
if (startsWithWhitespace) {
writer.write(PAD_TEXT);
}
}
@ -1066,15 +1065,14 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
if (format.isPadText()) {
// only add the PAD_TEXT if the text itself ends
// with whitespace
char lastTextChar = 'a';
final boolean endsWithWhitespace;
if (buff != null) {
lastTextChar = buff.charAt(buff.length() - 1);
} else if (lastTextNode != null) {
String txt = lastTextNode.getText();
lastTextChar = txt.charAt(txt.length() - 1);
endsWithWhitespace = endsWithWhitespace(buff);
} else {
endsWithWhitespace = endsWithWhitespace(lastTextNode.getText());
}
if (Character.isWhitespace(lastTextChar)) {
if (endsWithWhitespace) {
writer.write(PAD_TEXT);
}
}
@ -1091,14 +1089,14 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
if (!textOnly && format.isPadText()) {
// only add the PAD_TEXT if the text itself starts with
// whitespace
char firstChar = 'a';
final boolean startsWithWhitespace;
if (buff != null) {
firstChar = buff.charAt(0);
startsWithWhitespace = startsWithWhitespace(buff);
} else {
firstChar = lastTextNode.getText().charAt(0);
startsWithWhitespace = startsWithWhitespace(lastTextNode.getText());
}
if (Character.isWhitespace(firstChar)) {
if (startsWithWhitespace) {
writer.write(PAD_TEXT);
}
}
@ -1115,9 +1113,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
} else {
Node lastTextNode = null;
for (int i = 0, size = element.nodeCount(); i < size; i++) {
Node node = element.node(i);
for (Node node : element.content()) {
if (node instanceof Text) {
writeNode(node);
lastTextNode = node;
@ -1125,10 +1121,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
if ((lastTextNode != null) && format.isPadText()) {
// only add the PAD_TEXT if the text itself ends with
// whitespace
String txt = lastTextNode.getText();
char lastTextChar = txt.charAt(txt.length() - 1);
if (Character.isWhitespace(lastTextChar)) {
if (endsWithWhitespace(lastTextNode.getText())) {
writer.write(PAD_TEXT);
}
}
@ -1174,17 +1167,15 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the SAX namepsaces
*
*
* @throws IOException
* DOCUMENT ME!
*/
protected void writeNamespaces() throws IOException {
if (namespacesMap != null) {
for (Iterator iter = namespacesMap.entrySet().iterator(); iter
.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
String prefix = (String) entry.getKey();
String uri = (String) entry.getValue();
for (Map.Entry<String, String> entry : namespacesMap.entrySet()) {
String prefix = entry.getKey();
String uri = entry.getValue();
writeNamespace(prefix, uri);
}
@ -1194,15 +1185,15 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the SAX namepsaces
*
*
* @param prefix
* the prefix
* @param uri
* the namespace uri
*
* @throws IOException
*
* @throws IOException DOCUMENT ME!
*/
protected void writeNamespace(String prefix, String uri)
protected void writeNamespace(String prefix, String uri)
throws IOException {
if ((prefix != null) && (prefix.length() > 0)) {
writer.write(" xmlns:");
@ -1216,6 +1207,19 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
writer.write("\"");
}
/**
* Writes all namespaces declared directly on element.
*
* @throws IOException
*/
protected void writeNamespaces(Element element) throws IOException {
assert element != null;
for (Namespace ns : element.declaredNamespaces()) {
writeNamespace(ns);
namespaceStack.push(ns);
}
}
protected void writeProcessingInstruction(ProcessingInstruction pi)
throws IOException {
// indent();
@ -1259,12 +1263,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
writer.write(token);
lastOutputNodeType = Node.TEXT_NODE;
lastChar = token.charAt(token.length() - 1);
}
} else {
lastOutputNodeType = Node.TEXT_NODE;
writer.write(text);
lastChar = text.charAt(text.length() - 1);
}
}
}
@ -1272,10 +1274,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* This method is used to write out Nodes that contain text and still allow
* for xml:space to be handled properly.
*
*
* @param node
* DOCUMENT ME!
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -1289,7 +1291,6 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
lastOutputNodeType = Node.TEXT_NODE;
writer.write(text);
lastChar = text.charAt(text.length() - 1);
}
}
@ -1362,9 +1363,9 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
}
// try to register for lexical events
for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) {
for (String lexicalHandlerName : LEXICAL_HANDLER_NAMES) {
try {
parent.setProperty(LEXICAL_HANDLER_NAMES[i], this);
parent.setProperty(lexicalHandlerName, this);
break;
} catch (SAXNotRecognizedException ex) {
@ -1434,10 +1435,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Writes the attributes of the given element
*
*
* @param element
* DOCUMENT ME!
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -1481,26 +1482,24 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
writeNamespace(null, uri);
}
} else {
char quote = format.getAttributeQuoteCharacter();
writer.write(" ");
writer.write(attribute.getQualifiedName());
writer.write("=");
writer.write(quote);
writeEscapeAttributeEntities(attribute.getValue());
writer.write(quote);
writeAttribute(attribute);
}
}
}
protected void writeAttribute(Attribute attribute) throws IOException {
writeAttribute(attribute.getQualifiedName(), attribute.getValue());
}
protected void writeAttribute(String qualifiedName, String value) throws IOException {
writer.write(" ");
writer.write(attribute.getQualifiedName());
writer.write(qualifiedName);
writer.write("=");
char quote = format.getAttributeQuoteCharacter();
writer.write(quote);
writeEscapeAttributeEntities(attribute.getValue());
writeEscapeAttributeEntities(value);
writer.write(quote);
lastOutputNodeType = Node.ATTRIBUTE_NODE;
@ -1514,13 +1513,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
protected void writeAttribute(Attributes attributes, int index)
throws IOException {
char quote = format.getAttributeQuoteCharacter();
writer.write(" ");
writer.write(attributes.getQName(index));
writer.write("=");
writer.write(quote);
writeEscapeAttributeEntities(attributes.getValue(index));
writer.write(quote);
writeAttribute(attributes.getQName(index), attributes.getValue(index));
}
protected void indent() throws IOException {
@ -1537,29 +1530,26 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* <p>
* This will print a new line only if the newlines flag was set to true
* </p>
*
*
* @throws IOException
* DOCUMENT ME!
*/
protected void writePrintln() throws IOException {
if (format.isNewlines()) {
String seperator = format.getLineSeparator();
if (lastChar != seperator.charAt(seperator.length() - 1)) {
writer.write(format.getLineSeparator());
}
writer.write(format.getLineSeparator());
}
}
/**
* Get an OutputStreamWriter, use preferred encoding.
*
*
* @param outStream
* DOCUMENT ME!
* @param encoding
* DOCUMENT ME!
*
*
* @return DOCUMENT ME!
*
*
* @throws UnsupportedEncodingException
* DOCUMENT ME!
*/
@ -1573,7 +1563,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* This will write the declaration to the given Writer. Assumes XML version
* 1.0 since we don't directly know.
* </p>
*
*
* @throws IOException
* DOCUMENT ME!
*/
@ -1633,10 +1623,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* This will take the pre-defined entities in XML 1.0 and convert their
* character representation to the appropriate entity reference, suitable
* for XML attributes.
*
*
* @param text
* DOCUMENT ME!
*
*
* @return DOCUMENT ME!
*/
protected String escapeElementEntities(String text) {
@ -1647,44 +1637,37 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
for (i = 0; i < size; i++) {
String entity = null;
char c = text.charAt(i);
int c = text.codePointAt(i);
switch (c) {
case '<':
entity = "&lt;";
break;
case '>':
entity = "&gt;";
break;
case '&':
entity = "&amp;";
break;
case '\t':
case '\n':
case '\r':
// don't encode standard whitespace characters
if (preserve) {
entity = String.valueOf(c);
entity = String.valueOf((char) c);
}
break;
default:
if ((c < 32) || shouldEncodeChar(c)) {
entity = "&#" + (int) c + ";";
entity = "&#" + c + ";";
}
break;
}
if (entity != null) {
if (block == null) {
block = text.toCharArray();
@ -1693,6 +1676,12 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
buffer.append(block, last, i - last);
buffer.append(entity);
last = i + 1;
if (Character.isSupplementaryCodePoint(c)) {
last++;
}
}
if (Character.isSupplementaryCodePoint(c)) {
i++;
}
}
@ -1725,10 +1714,10 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* This will take the pre-defined entities in XML 1.0 and convert their
* character representation to the appropriate entity reference, suitable
* for XML attributes.
*
*
* @param text
* DOCUMENT ME!
*
*
* @return DOCUMENT ME!
*/
protected String escapeAttributeEntities(String text) {
@ -1741,53 +1730,37 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
for (i = 0; i < size; i++) {
String entity = null;
char c = text.charAt(i);
int c = text.codePointAt(i);
switch (c) {
case '<':
entity = "&lt;";
break;
case '>':
entity = "&gt;";
break;
case '\'':
if (quote == '\'') {
entity = "&apos;";
}
break;
case '\"':
if (quote == '\"') {
entity = "&quot;";
}
break;
case '&':
entity = "&amp;";
break;
case '\t':
case '\n':
case '\r':
// don't encode standard whitespace characters
break;
default:
if ((c < 32) || shouldEncodeChar(c)) {
entity = "&#" + (int) c + ";";
entity = "&#" + c + ";";
}
break;
}
@ -1799,6 +1772,12 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
buffer.append(block, last, i - last);
buffer.append(entity);
last = i + 1;
if(Character.isSupplementaryCodePoint(c)) {
last++;
}
}
if(Character.isSupplementaryCodePoint(c)) {
i++;
}
}
@ -1823,23 +1802,23 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
/**
* Should the given character be escaped. This depends on the encoding of
* the document.
*
* @param c
*
* @param codepoint Unicode codepoint.
* DOCUMENT ME!
*
*
* @return boolean
*/
protected boolean shouldEncodeChar(char c) {
protected boolean shouldEncodeChar(int codepoint) {
int max = getMaximumAllowedCharacter();
return (max > 0) && (c > max);
return (max > 0) && (codepoint > max);
}
/**
* Returns the maximum allowed character code that should be allowed
* unescaped which defaults to 127 in US-ASCII (7 bit) or 255 in ISO- (8
* bit).
*
*
* @return DOCUMENT ME!
*/
protected int defaultMaximumAllowedCharacter() {
@ -1880,7 +1859,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* setTrimText, setNewLines, etc. Put in to support the HTMLWriter, in the
* way that it pushes the current newline/trim state onto a stack and
* overrides the state within preformatted tags.
*
*
* @return DOCUMENT ME!
*/
protected OutputFormat getOutputFormat() {
@ -1900,24 +1879,24 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the
* following conditions are met:
*
*
* 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*
* 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com.
*
*
* 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
*
*
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
*
*
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -1929,6 +1908,6 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/

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:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.3 $
*/
public class XPP3Reader {
/** <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>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.7 $
*/
public class XPPReader {
/** <code>DocumentFactory</code> used to create new document objects */

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

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

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

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

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.
* {@link JAXBObjectHandler}objects can be registered to automatically receive
* unmarshalled XML fragments. Registered {@linkorg.dom4j.ElementHandler}
* unmarshalled XML fragments. Registered {@link org.dom4j.ElementHandler}
* implementations are notified when a certain element path is encountered
*
* @author Wonne Keysers (Realsoftware.be)
@ -57,7 +57,7 @@ public class JAXBReader extends JAXBSupport {
/**
* Creates a new JAXBReader for the given JAXB context path, using the
* specified {@link java.lang.Classloader}. This is the Java package where
* specified {@link java.lang.ClassLoader}. This is the Java package where
* JAXB can find the generated XML classes. This package MUST contain
* jaxb.properties!
*
@ -333,7 +333,7 @@ public class JAXBReader extends JAXBSupport {
* Set to true when DOM4J elements must immediately be pruned from the tree.
* The {@link Document}will not be available afterwards!
*
* @param pruneElements
* @param pruneElements DOCUMENT ME!
*/
public void setPruneElements(boolean pruneElements) {
this.pruneElements = pruneElements;

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

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

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

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

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

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

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

@ -14,283 +14,280 @@ import org.dom4j.Node;
* <code>Rule</code> matches against DOM4J Node so that some action can be
* performed such as in the XSLT processing model.
* </p>
*
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.7 $
*/
public class Rule implements Comparable {
/** Holds value of property mode. */
private String mode;
/** Holds value of property importPrecedence. */
private int importPrecedence;
/** Holds value of property priority. */
private double priority;
/** Holds value of property appearenceCount. */
private int appearenceCount;
/** Holds value of property pattern. */
private Pattern pattern;
/** Holds value of property action. */
private Action action;
public Rule() {
this.priority = Pattern.DEFAULT_PRIORITY;
}
public Rule(Pattern pattern) {
this.pattern = pattern;
this.priority = pattern.getPriority();
}
public Rule(Pattern pattern, Action action) {
this(pattern);
this.action = action;
}
/**
* Constructs a new Rule with the same instance data as the given rule but a
* different pattern.
*
* @param that
* DOCUMENT ME!
* @param pattern
* DOCUMENT ME!
*/
public Rule(Rule that, Pattern pattern) {
this.mode = that.mode;
this.importPrecedence = that.importPrecedence;
this.priority = that.priority;
this.appearenceCount = that.appearenceCount;
this.action = that.action;
this.pattern = pattern;
}
public boolean equals(Object that) {
if (that instanceof Rule) {
return compareTo((Rule) that) == 0;
}
return false;
}
public int hashCode() {
return importPrecedence + appearenceCount;
}
public int compareTo(Object that) {
if (that instanceof Rule) {
return compareTo((Rule) that);
}
return getClass().getName().compareTo(that.getClass().getName());
}
/**
* Compares two rules in XSLT processing model order assuming that the modes
* are equal.
*
* @param that
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public int compareTo(Rule that) {
int answer = this.importPrecedence - that.importPrecedence;
if (answer == 0) {
answer = (int) Math.round(this.priority - that.priority);
if (answer == 0) {
answer = this.appearenceCount - that.appearenceCount;
}
}
return answer;
}
public String toString() {
return super.toString() + "[ pattern: " + getPattern() + " action: "
+ getAction() + " ]";
}
/**
* DOCUMENT ME!
*
* @param node
* DOCUMENT ME!
*
* @return true if the pattern matches the given DOM4J node.
*/
public final boolean matches(Node node) {
return pattern.matches(node);
}
/**
* If this rule contains a union pattern then this method should return an
* array of Rules which describe the union rule, which should contain more
* than one rule. Otherwise this method should return null.
*
* @return an array of the rules which make up this union rule or null if
* this rule is not a union rule
*/
public Rule[] getUnionRules() {
Pattern[] patterns = pattern.getUnionPatterns();
if (patterns == null) {
return null;
}
int size = patterns.length;
Rule[] answer = new Rule[size];
for (int i = 0; i < size; i++) {
answer[i] = new Rule(this, patterns[i]);
}
return answer;
}
/**
* DOCUMENT ME!
*
* @return the type of node the pattern matches which by default should
* return ANY_NODE if it can match any kind of node.
*/
public final short getMatchType() {
return pattern.getMatchType();
}
/**
* For patterns which only match an ATTRIBUTE_NODE or an ELEMENT_NODE then
* this pattern may return the name of the element or attribute it matches.
* This allows a more efficient rule matching algorithm to be performed,
* rather than a brute force approach of evaluating every pattern for a
* given Node.
*
* @return the name of the element or attribute this pattern matches or null
* if this pattern matches any or more than one name.
*/
public final String getMatchesNodeName() {
return pattern.getMatchesNodeName();
}
/**
* Getter for property mode.
*
* @return Value of property mode.
*/
public String getMode() {
return mode;
}
/**
* Setter for property mode.
*
* @param mode
* New value of property mode.
*/
public void setMode(String mode) {
this.mode = mode;
}
/**
* Getter for property importPrecedence.
*
* @return Value of property importPrecedence.
*/
public int getImportPrecedence() {
return importPrecedence;
}
/**
* Setter for property importPrecedence.
*
* @param importPrecedence
* New value of property importPrecedence.
*/
public void setImportPrecedence(int importPrecedence) {
this.importPrecedence = importPrecedence;
}
/**
* Getter for property priority.
*
* @return Value of property priority.
*/
public double getPriority() {
return priority;
}
/**
* Setter for property priority.
*
* @param priority
* New value of property priority.
*/
public void setPriority(double priority) {
this.priority = priority;
}
/**
* Getter for property appearenceCount.
*
* @return Value of property appearenceCount.
*/
public int getAppearenceCount() {
return appearenceCount;
}
/**
* Setter for property appearenceCount.
*
* @param appearenceCount
* New value of property appearenceCount.
*/
public void setAppearenceCount(int appearenceCount) {
this.appearenceCount = appearenceCount;
}
/**
* Getter for property pattern.
*
* @return Value of property pattern.
*/
public Pattern getPattern() {
return pattern;
}
/**
* Setter for property pattern.
*
* @param pattern
* New value of property pattern.
*/
public void setPattern(Pattern pattern) {
this.pattern = pattern;
}
/**
* Getter for property action.
*
* @return Value of property action.
*/
public Action getAction() {
return action;
}
/**
* Setter for property action.
*
* @param action
* New value of property action.
*/
public void setAction(Action action) {
this.action = action;
}
public class Rule implements Comparable<Rule> {
/**
* Holds value of property mode.
*/
private String mode;
/**
* Holds value of property importPrecedence.
*/
private int importPrecedence;
/**
* Holds value of property priority.
*/
private double priority;
/**
* Holds value of property appearenceCount.
*/
private int appearenceCount;
/**
* Holds value of property pattern.
*/
private Pattern pattern;
/**
* Holds value of property action.
*/
private Action action;
public Rule() {
this.priority = Pattern.DEFAULT_PRIORITY;
}
public Rule(Pattern pattern) {
this.pattern = pattern;
this.priority = pattern.getPriority();
}
public Rule(Pattern pattern, Action action) {
this(pattern);
this.action = action;
}
/**
* Constructs a new Rule with the same instance data as the given rule but a
* different pattern.
*
* @param that DOCUMENT ME!
* @param pattern DOCUMENT ME!
*/
public Rule(Rule that, Pattern pattern) {
this.mode = that.mode;
this.importPrecedence = that.importPrecedence;
this.priority = that.priority;
this.appearenceCount = that.appearenceCount;
this.action = that.action;
this.pattern = pattern;
}
public boolean equals(Object that) {
if (that instanceof Rule) {
return compareTo((Rule) that) == 0;
}
return false;
}
public int hashCode() {
return importPrecedence + appearenceCount;
}
/**
* Compares two rules in XSLT processing model order assuming that the modes
* are equal.
*
* @param that DOCUMENT ME!
* @return DOCUMENT ME!
*/
public int compareTo(Rule that) {
int answer = compareInt(this.importPrecedence, that.importPrecedence);
if (answer == 0) {
answer = Double.compare(this.priority, that.priority);
if (answer == 0) {
answer = compareInt(this.appearenceCount, that.appearenceCount);
}
}
return answer;
}
public String toString() {
return super.toString() + "[ pattern: " + getPattern() + " action: "
+ getAction() + " ]";
}
/**
* DOCUMENT ME!
*
* @param node DOCUMENT ME!
* @return true if the pattern matches the given DOM4J node.
*/
public final boolean matches(Node node) {
return pattern.matches(node);
}
/**
* If this rule contains a union pattern then this method should return an
* array of Rules which describe the union rule, which should contain more
* than one rule. Otherwise this method should return null.
*
* @return an array of the rules which make up this union rule or null if
* this rule is not a union rule
*/
public Rule[] getUnionRules() {
Pattern[] patterns = pattern.getUnionPatterns();
if (patterns == null) {
return null;
}
int size = patterns.length;
Rule[] answer = new Rule[size];
for (int i = 0; i < size; i++) {
answer[i] = new Rule(this, patterns[i]);
}
return answer;
}
/**
* DOCUMENT ME!
*
* @return the type of node the pattern matches which by default should
* return ANY_NODE if it can match any kind of node.
*/
public final short getMatchType() {
return pattern.getMatchType();
}
/**
* For patterns which only match an ATTRIBUTE_NODE or an ELEMENT_NODE then
* this pattern may return the name of the element or attribute it matches.
* This allows a more efficient rule matching algorithm to be performed,
* rather than a brute force approach of evaluating every pattern for a
* given Node.
*
* @return the name of the element or attribute this pattern matches or null
* if this pattern matches any or more than one name.
*/
public final String getMatchesNodeName() {
return pattern.getMatchesNodeName();
}
/**
* Getter for property mode.
*
* @return Value of property mode.
*/
public String getMode() {
return mode;
}
/**
* Setter for property mode.
*
* @param mode New value of property mode.
*/
public void setMode(String mode) {
this.mode = mode;
}
/**
* Getter for property importPrecedence.
*
* @return Value of property importPrecedence.
*/
public int getImportPrecedence() {
return importPrecedence;
}
/**
* Setter for property importPrecedence.
*
* @param importPrecedence New value of property importPrecedence.
*/
public void setImportPrecedence(int importPrecedence) {
this.importPrecedence = importPrecedence;
}
/**
* Getter for property priority.
*
* @return Value of property priority.
*/
public double getPriority() {
return priority;
}
/**
* Setter for property priority.
*
* @param priority New value of property priority.
*/
public void setPriority(double priority) {
this.priority = priority;
}
/**
* Getter for property appearenceCount.
*
* @return Value of property appearenceCount.
*/
public int getAppearenceCount() {
return appearenceCount;
}
/**
* Setter for property appearenceCount.
*
* @param appearenceCount New value of property appearenceCount.
*/
public void setAppearenceCount(int appearenceCount) {
this.appearenceCount = appearenceCount;
}
/**
* Getter for property pattern.
*
* @return Value of property pattern.
*/
public Pattern getPattern() {
return pattern;
}
/**
* Setter for property pattern.
*
* @param pattern New value of property pattern.
*/
public void setPattern(Pattern pattern) {
this.pattern = pattern;
}
/**
* Getter for property action.
*
* @return Value of property action.
*/
public Action getAction() {
return action;
}
/**
* Setter for property action.
*
* @param action New value of property action.
*/
public void setAction(Action action) {
this.action = action;
}
private static int compareInt(int value1, int value2) {
//return Integer.compare(value1, value2);
return (value1 < value2) ? -1 : ((value1 == value2) ? 0 : 1);
}
}
/*

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

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

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

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

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

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

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

@ -1,14 +0,0 @@
<html>
<head>
</head>
<body>
<p>A {@link org.dom4j.rule.Pattern} based XML rule engine which implements
the full XSLT processing model while allowing any {@link org.dom4j.rule.Action}
to be fired if a pattern matches.
This package can be used as a the base for a full XSLT implementation
or alternatives, such as a JSP custom tag implementation of XSLT.
</p>
</body>
</html>

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

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

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

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

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

Loading…
Cancel
Save