Browse Source

Merge pull request #9027 in CORE/base-third from release/11.0 to final/11.0

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

2
fine-org-dom4j/README.md

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

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

@ -8,51 +8,41 @@
package org.dom4j;
/**
* <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();
/**
* <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();
/**
* <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
* @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>
@ -60,10 +50,8 @@ public interface Attribute extends Node {
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>
@ -71,66 +59,50 @@ public interface Attribute extends Node {
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();
/**
* <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();
/**
* <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
* @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();
/**
* <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
* @param data the attribute data
*/
void setData(Object data);
}

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

@ -11,27 +11,22 @@ import java.util.Iterator;
import java.util.List;
/**
* <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.
*
* @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;=
* @throws IndexOutOfBoundsException if the index is out of range (index &lt; 0 || index &gt;=
* {@link Branch#nodeCount()}).
*/
Node node(int index) throws IndexOutOfBoundsException;
@ -40,9 +35,7 @@ public interface Branch extends Node {
* Returns the index of the given node if it is a child node of this branch
* or -1 if the given node is not a child node.
*
* @param node
* the content child node to find.
*
* @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
*/
@ -61,49 +54,43 @@ public interface Branch extends Node {
* 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!
*
* @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();
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();
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.
* @param content is the list of nodes to use as the content for this branch.
*/
void setContent(List content);
void setContent(List<Node> content);
/**
* Appends the content of the given branch to this branch instance. This
* 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.
* @param branch is the branch whose content will be added to me.
*/
void appendContent(Branch branch);
@ -114,36 +101,28 @@ public interface Branch extends Node {
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();
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!
*
* @param target DOCUMENT ME!
* @return a backed list of the processing instructions
*/
List processingInstructions(String target);
List<ProcessingInstruction> processingInstructions(String target);
/**
* DOCUMENT ME!
*
* @param target
* DOCUMENT ME!
*
* @param target DOCUMENT ME!
* @return the processing instruction for the given target
*/
ProcessingInstruction processingInstruction(String target);
@ -151,18 +130,15 @@ public interface Branch extends Node {
/**
* Sets all the processing instructions for this branch
*
* @param listOfPIs
* DOCUMENT ME!
* @param listOfPIs DOCUMENT ME!
*/
void setProcessingInstructions(List listOfPIs);
void setProcessingInstructions(List<ProcessingInstruction> listOfPIs);
/**
* Adds a new <code>Element</code> node with the given name to this branch
* and returns a reference to the new node.
*
* @param name
* is the name for the <code>Element</code> node.
*
* @param name is the name for the <code>Element</code> node.
* @return the newly added <code>Element</code> node.
*/
Element addElement(String name);
@ -171,9 +147,7 @@ public interface Branch extends Node {
* Adds a new <code>Element</code> node with the given {@link QName}to
* this branch and returns a reference to the new node.
*
* @param qname
* is the qualified name for the <code>Element</code> 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);
@ -182,11 +156,8 @@ public interface Branch extends Node {
* 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
*
* @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);
@ -194,9 +165,7 @@ public interface Branch extends Node {
/**
* Removes the processing instruction for the given target if it exists
*
* @param target
* DOCUMENT ME!
*
* @param target DOCUMENT ME!
* @return true if a processing instruction was removed else false
*/
boolean removeProcessingInstruction(String target);
@ -207,8 +176,7 @@ public interface Branch extends Node {
* which will call the typesafe method for the node type such as
* add(Element) or add(Comment).
*
* @param node
* is the given node to add
* @param node is the given node to add
*/
void add(Node node);
@ -217,8 +185,7 @@ public interface Branch extends Node {
* already has a parent defined then an <code>IllegalAddException</code>
* will be thrown.
*
* @param comment
* is the comment to be added
* @param comment is the comment to be added
*/
void add(Comment comment);
@ -227,8 +194,7 @@ public interface Branch extends Node {
* already has a parent defined then an <code>IllegalAddException</code>
* will be thrown.
*
* @param element
* is the element to be added
* @param element is the element to be added
*/
void add(Element element);
@ -237,8 +203,7 @@ public interface Branch extends Node {
* 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
* @param pi is the processing instruction to be added
*/
void add(ProcessingInstruction pi);
@ -249,9 +214,7 @@ public interface Branch extends Node {
* is a polymorphic method which will call the typesafe method for the node
* type such as remove(Element) or remove(Comment).
*
* @param node
* is the given node to be removed
*
* @param node is the given node to be removed
* @return true if the node was removed
*/
boolean remove(Node node);
@ -261,9 +224,7 @@ public interface Branch extends Node {
* child of this branch. If the given node is not an immediate child of this
* branch then the {@link Node#detach()}method should be used instead.
*
* @param comment
* is the comment to be removed
*
* @param comment is the comment to be removed
* @return true if the comment was removed
*/
boolean remove(Comment comment);
@ -273,9 +234,7 @@ public interface Branch extends Node {
* child of this branch. If the given node is not an immediate child of this
* branch then the {@link Node#detach()}method should be used instead.
*
* @param element
* is the element to be removed
*
* @param element is the element to be removed
* @return true if the element was removed
*/
boolean remove(Element element);
@ -286,9 +245,7 @@ public interface Branch extends Node {
* child of this branch then the {@link Node#detach()}method should be used
* instead.
*
* @param pi
* is the processing instruction to be removed
*
* @param pi is the processing instruction to be removed
* @return true if the processing instruction was removed
*/
boolean remove(ProcessingInstruction pi);

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

5
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

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

13
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,14 +123,12 @@ 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.

62
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;
}
}

42
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,10 +80,8 @@ 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
*/
@ -94,7 +89,7 @@ public class DocumentFactory implements Serializable {
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);

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

@ -18,16 +18,16 @@ import org.dom4j.rule.Pattern;
import org.jaxen.VariableContext;
import org.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);
}
@ -190,7 +190,7 @@ public final class DocumentHelper {
*
* @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);
@ -210,7 +210,7 @@ public final class DocumentHelper {
*
* @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);
@ -227,7 +227,7 @@ public final class DocumentHelper {
* @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);
}
@ -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);
}
@ -258,6 +258,8 @@ public final class DocumentHelper {
* 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
*
@ -267,15 +269,14 @@ public final class DocumentHelper {
* 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

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

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

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

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

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

4
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) {

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

@ -8,17 +8,12 @@
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) {
super("Invalid XPath expression: " + xpath);
}
@ -26,11 +21,6 @@ public class InvalidXPathException extends IllegalArgumentException {
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());
}
}
/*

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

@ -12,13 +12,11 @@ import org.dom4j.tree.DefaultNamespace;
import org.dom4j.tree.NamespaceCache;
/**
* <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);
}
}
/**

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

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

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

123
fine-org-dom4j/src/main/java/org/dom4j/QName.java

@ -11,40 +11,114 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.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));
}
}
}

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

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

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

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

@ -7,59 +7,48 @@
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();
/**
* <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!
*
* @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
* @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.
@ -67,121 +56,89 @@ public interface XPath extends NodeFilter {
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
* @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
* @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);
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
* @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 sortXPath is the XPath expression to sort by
* @return a list of <code>Node</code> instances
*/
List selectNodes(Object context, XPath sortXPath);
List<Node> selectNodes(Object context, XPath sortXPath);
/**
* <p>
* <code>selectNodes</code> evaluates the XPath expression on the given
* {@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
* @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
* @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);
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
* @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
* @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
* @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.
*/
@ -191,49 +148,37 @@ public interface XPath extends NodeFilter {
* 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
* @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
* @param list is the list of Nodes to sort
*/
void sort(List list);
void sort(List<Node> list);
/**
* <p>
* <code>sort</code> sorts the given List of Nodes using this XPath
* 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
* @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);
void sort(List<Node> list, boolean distinct);
/**
* DOCUMENT ME!
@ -245,8 +190,7 @@ public interface XPath extends NodeFilter {
/**
* Sets the function context to be used when evaluating XPath expressions
*
* @param functionContext
* DOCUMENT ME!
* @param functionContext DOCUMENT ME!
*/
void setFunctionContext(FunctionContext functionContext);
@ -260,20 +204,15 @@ public interface XPath extends NodeFilter {
/**
* Sets the namespace context to be used when evaluating XPath expressions
*
* @param namespaceContext
* DOCUMENT ME!
* @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/");
@ -284,12 +223,9 @@ public interface XPath extends NodeFilter {
* Node babelfish = xpath.selectSingleNode(document);
* </pre>
*
* </p>
*
* @param map
* the map containing the namespace mappings
* @param map the map containing the namespace mappings
*/
void setNamespaceURIs(Map map);
void setNamespaceURIs(Map<String, String> map);
/**
* DOCUMENT ME!
@ -301,8 +237,7 @@ public interface XPath extends NodeFilter {
/**
* Sets the variable context to be used when evaluating XPath expressions
*
* @param variableContext
* DOCUMENT ME!
* @param variableContext DOCUMENT ME!
*/
void setVariableContext(VariableContext variableContext);
}

4
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) {

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

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

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

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

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

@ -27,7 +27,7 @@ import org.relaxng.datatype.ValidationContext;
* </p>
*
* @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);

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

@ -37,7 +37,7 @@ import org.xml.sax.InputSource;
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
* @author 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,26 +209,27 @@ 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 (factory != null) {
Iterator<Element> iter = xsdElement.elementIterator(XSD_ATTRIBUTE);
if (iter.hasNext()) {
do {
onDatatypeAttribute(xsdElement, factory, (Element) iter
onDatatypeAttribute(xsdElement, factory, iter
.next());
} while (iter.hasNext());
}
}
}
/**
* processes an named XML Schema &lt;complexTypegt; tag
@ -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);
}

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

@ -0,0 +1,4 @@
/**
* An implementation of the <i>dom4j</i> API which supports the <a href="http://www.w3.org/TR/xmlschema-2/">XML Schema Data Types</a> specification.
*/
package org.dom4j.datatype;

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

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

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

@ -10,13 +10,7 @@ package org.dom4j.dom;
import org.dom4j.Element;
import org.dom4j.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 */

30
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) {
}
@ -70,8 +59,7 @@ public class DOMDocumentFactory extends DocumentFactory implements
* @return the default singleon instance
*/
public static DocumentFactory getInstance() {
DOMDocumentFactory fact = (DOMDocumentFactory) singleton.instance();
return fact;
return singleton.instance();
}
// Factory methods
@ -129,7 +117,7 @@ public class DOMDocumentFactory extends DocumentFactory implements
}
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) {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -10,12 +10,8 @@ package org.dom4j.io;
import java.util.ArrayList;
import java.util.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();

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

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

70
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());
@ -92,7 +81,7 @@ public class DOMWriter {
* 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;

4
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
* {@link Document}.
* </p>
*
* @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
* @version $Revision$
* @version $Revision: 1.10 $
*/
public class DocumentSource extends SAXSource {
/**

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

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

@ -26,25 +26,21 @@ import org.dom4j.Node;
import org.xml.sax.SAXException;
/**
* <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,28 +82,14 @@ 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>
* See examples and discussion here: {@link #setPreformattedTags(java.util.Set)}
*
* <p>
* <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) {
@ -147,12 +108,10 @@ 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) {
@ -172,21 +131,19 @@ import org.xml.sax.SAXException;
* }
* </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();
omitElementCloseSet = new HashSet<String>();
Object aTag;
Iterator iter = newSet.iterator();
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:
@ -520,28 +462,20 @@ 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() {

34
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
* {@link XMLWriter}and its base classes to format the XML output
* </p>
*
* @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,16 +304,11 @@ 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,11 +356,9 @@ 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,17 +374,13 @@ 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!
*/
@ -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);

62
fine-org-dom4j/src/main/java/org/dom4j/io/SAXEventRecorder.java

@ -67,9 +67,9 @@ public class SAXEventRecorder extends DefaultHandler implements LexicalHandler,
private static final byte NULL = 2;
private 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;
@ -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;
@ -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()) {
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();
}
}
}

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

@ -13,6 +13,8 @@ import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import javax.xml.parsers.SAXParserFactory;
/**
* <p>
* <code>SAXHelper</code> contains some helper methods for working with SAX
@ -20,7 +22,7 @@ import org.xml.sax.helpers.XMLReaderFactory;
* </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;
@ -62,6 +64,15 @@ 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!
*
@ -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;
}

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

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

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

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

@ -27,7 +27,7 @@ import org.xml.sax.helpers.DefaultHandler;
* </p>
*
* @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 */

72
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());
}
} 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);
+ node + " of type: " + node.getClass());
}
} 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());

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

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

189
fine-org-dom4j/src/main/java/org/dom4j/io/XMLWriter.java

@ -42,6 +42,9 @@ import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.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
@ -66,7 +69,7 @@ import org.xml.sax.helpers.XMLFilterImpl;
*
* @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
@ -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);
@ -571,6 +574,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
public void writeOpen(Element element) throws IOException {
writer.write("<");
writer.write(element.getQualifiedName());
writeNamespaces(element);
writeAttributes(element);
writer.write(">");
}
@ -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);
@ -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;
@ -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);
}
}
@ -1180,11 +1173,9 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
*/
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);
}
@ -1200,7 +1191,7 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
* @param uri
* the namespace uri
*
* @throws IOException
* @throws IOException DOCUMENT ME!
*/
protected void writeNamespace(String prefix, String uri)
throws IOException {
@ -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);
}
}
}
@ -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) {
@ -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 {
@ -1543,12 +1536,9 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
*/
protected void writePrintln() throws IOException {
if (format.isNewlines()) {
String seperator = format.getLineSeparator();
if (lastChar != seperator.charAt(seperator.length() - 1)) {
writer.write(format.getLineSeparator());
}
}
}
/**
* Get an OutputStreamWriter, use preferred encoding.
@ -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++;
}
}
@ -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++;
}
}
@ -1824,15 +1803,15 @@ 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);
}
/**

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

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

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

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

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

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

@ -51,7 +51,7 @@ public class JAXBModifier extends JAXBSupport {
private OutputFormat outputFormat;
private 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());

4
fine-org-dom4j/src/main/java/org/dom4j/jaxb/JAXBReader.java

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

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

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

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

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

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

@ -16,7 +16,7 @@ import org.dom4j.Node;
* </p>
*
* @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);

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

Loading…
Cancel
Save