You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2011/03/21 11:55:11 UTC
svn commit: r1083729 - in
/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security:
keys/keyresolver/implementations/ signature/
Author: coheigea
Date: Mon Mar 21 10:55:11 2011
New Revision: 1083729
URL: http://svn.apache.org/viewvc?rev=1083729&view=rev
Log:
[SANTUARIO-259] - Finished with signature refactoring.
Modified:
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/RetrievalMethodResolver.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/Manifest.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInput.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInputDebugger.java
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/RetrievalMethodResolver.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/RetrievalMethodResolver.java?rev=1083729&r1=1083728&r2=1083729&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/RetrievalMethodResolver.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/RetrievalMethodResolver.java Mon Mar 21 10:55:11 2011
@@ -305,11 +305,11 @@ public class RetrievalMethodResolver ext
return null;
}
- private static Element getDocumentElement(Set set) {
- Iterator it = set.iterator();
+ private static Element getDocumentElement(Set<Node> set) {
+ Iterator<Node> it = set.iterator();
Element e = null;
while (it.hasNext()) {
- Node currentNode = (Node) it.next();
+ Node currentNode = it.next();
if (currentNode != null && Node.ELEMENT_NODE == currentNode.getNodeType()) {
e = (Element) currentNode;
break;
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/Manifest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/Manifest.java?rev=1083729&r1=1083728&r2=1083729&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/Manifest.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/Manifest.java Mon Mar 21 10:55:11 2011
@@ -307,12 +307,12 @@ public class Manifest extends SignatureE
try {
XMLSignatureInput signedManifestNodes =
currentRef.dereferenceURIandPerformTransforms(null);
- Set nl = signedManifestNodes.getNodeSet();
+ Set<Node> nl = signedManifestNodes.getNodeSet();
Manifest referencedManifest = null;
- Iterator nlIterator = nl.iterator();
+ Iterator<Node> nlIterator = nl.iterator();
findManifest: while (nlIterator.hasNext()) {
- Node n = (Node) nlIterator.next();
+ Node n = nlIterator.next();
if ((n.getNodeType() == Node.ELEMENT_NODE)
&& ((Element) n).getNamespaceURI().equals(Constants.SignatureSpecNS)
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInput.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInput.java?rev=1083729&r1=1083728&r2=1083729&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInput.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInput.java Mon Mar 21 10:55:11 2011
@@ -22,7 +22,6 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -50,9 +49,8 @@ import org.xml.sax.SAXException;
* $todo$ check whether an XMLSignatureInput can be _both_, octet stream _and_ node set?
*/
public class XMLSignatureInput implements Cloneable {
- static org.apache.commons.logging.Log log =
- org.apache.commons.logging.LogFactory.getLog
- (XMLSignatureInput.class.getName());
+ private static org.apache.commons.logging.Log log =
+ org.apache.commons.logging.LogFactory.getLog(XMLSignatureInput.class.getName());
/*
* The XMLSignature Input can be either:
@@ -67,29 +65,29 @@ public class XMLSignatureInput implement
* Some InputStreams do not support the {@link java.io.InputStream#reset}
* method, so we read it in completely and work on our Proxy.
*/
- InputStream _inputOctetStreamProxy = null;
+ private InputStream inputOctetStreamProxy = null;
/**
* The original NodeSet for this XMLSignatureInput
*/
- Set _inputNodeSet = null;
+ private Set<Node> inputNodeSet = null;
/**
* The original Element
*/
- Node _subNode = null;
+ private Node subNode = null;
/**
* Exclude Node *for enveloped transformations*
*/
- Node excludeNode = null;
+ private Node excludeNode = null;
/**
*
*/
- boolean excludeComments = false;
+ private boolean excludeComments = false;
- boolean isNodeSet = false;
+ private boolean isNodeSet = false;
/**
* A cached bytes
*/
- byte[] bytes = null;
+ private byte[] bytes = null;
/**
* Some Transforms may require explicit MIME type, charset (IANA registered
@@ -100,20 +98,20 @@ public class XMLSignatureInput implement
* Transform algorithm and should be described in the specification for the
* algorithm.
*/
- private String _MIMEType = null;
+ private String MIMEType = null;
/**
- * Field _SourceURI
+ * Field sourceURI
*/
- private String _SourceURI = null;
+ private String sourceURI = null;
/**
* Node Filter list.
*/
- List nodeFilters = new ArrayList();
+ private List<NodeFilter> nodeFilters = new ArrayList<NodeFilter>();
- boolean needsToBeExpanded = false;
- OutputStream outputStream = null;
+ private boolean needsToBeExpanded = false;
+ private OutputStream outputStream = null;
/**
* Construct a XMLSignatureInput from an octet array.
@@ -135,35 +133,7 @@ public class XMLSignatureInput implement
* @param inputOctetStream
*/
public XMLSignatureInput(InputStream inputOctetStream) {
- this._inputOctetStreamProxy=inputOctetStream;
- }
-
- /**
- * Construct a XMLSignatureInput from a String.
- * <p>
- * This is a comfort method, which internally converts the String into a byte
- * [] array using the {@link java.lang.String#getBytes()} method.
- * @deprecated
- * @param inputStr the input String which including XML document or node
- */
- public XMLSignatureInput(String inputStr) {
- this(inputStr.getBytes());
- }
-
- /**
- * Construct a XMLSignatureInput from a String with a given encoding.
- * <p>
- * This is a comfort method, which internally converts the String into a byte
- * [] array using the {@link java.lang.String#getBytes()} method.
- *
- * @deprecated
- * @param inputStr the input String with encoding <code>encoding</code>
- * @param encoding the encoding of <code>inputStr</code>
- * @throws UnsupportedEncodingException
- */
- public XMLSignatureInput(String inputStr, String encoding)
- throws UnsupportedEncodingException {
- this(inputStr.getBytes(encoding));
+ this.inputOctetStreamProxy = inputOctetStream;
}
/**
@@ -173,17 +143,16 @@ public class XMLSignatureInput implement
* @param rootNode
*/
public XMLSignatureInput(Node rootNode) {
- this._subNode = rootNode;
+ this.subNode = rootNode;
}
/**
* Constructor XMLSignatureInput
*
* @param inputNodeSet
- * @param usedXPathAPI
*/
- public XMLSignatureInput(Set inputNodeSet) {
- this._inputNodeSet = inputNodeSet;
+ public XMLSignatureInput(Set<Node> inputNodeSet) {
+ this.inputNodeSet = inputNodeSet;
}
/**
@@ -212,10 +181,18 @@ public class XMLSignatureInput implement
* @throws ParserConfigurationException
* @throws CanonicalizationException
*/
- public Set getNodeSet() throws CanonicalizationException,
- ParserConfigurationException, IOException, SAXException {
+ public Set<Node> getNodeSet() throws CanonicalizationException, ParserConfigurationException,
+ IOException, SAXException {
return getNodeSet(false);
}
+
+ /**
+ * Get the Input NodeSet.
+ * @return the Input NodeSet.
+ */
+ public Set<Node> getInputNodeSet() {
+ return inputNodeSet;
+ }
/**
* Returns the node set from input which was specified as the parameter of
@@ -228,52 +205,49 @@ public class XMLSignatureInput implement
* @throws ParserConfigurationException
* @throws CanonicalizationException
*/
- public Set getNodeSet(boolean circumvent)
- throws ParserConfigurationException, IOException, SAXException,
- CanonicalizationException {
- if (_inputNodeSet != null) {
- return _inputNodeSet;
+ public Set<Node> getNodeSet(boolean circumvent) throws ParserConfigurationException,
+ IOException, SAXException, CanonicalizationException {
+ if (inputNodeSet != null) {
+ return inputNodeSet;
}
- if (_inputOctetStreamProxy == null && _subNode != null) {
+ if (inputOctetStreamProxy == null && subNode != null) {
if (circumvent) {
- XMLUtils.circumventBug2650(XMLUtils.getOwnerDocument(_subNode));
+ XMLUtils.circumventBug2650(XMLUtils.getOwnerDocument(subNode));
}
- _inputNodeSet = new HashSet();
- XMLUtils.getSet
- (_subNode, _inputNodeSet, excludeNode, excludeComments);
- return _inputNodeSet;
+ inputNodeSet = new HashSet<Node>();
+ XMLUtils.getSet(subNode, inputNodeSet, excludeNode, excludeComments);
+ return inputNodeSet;
} else if (this.isOctetStream()) {
convertToNodes();
- HashSet result = new HashSet();
- XMLUtils.getSet(_subNode, result, null, false);
+ Set<Node> result = new HashSet<Node>();
+ XMLUtils.getSet(subNode, result, null, false);
return result;
}
- throw new RuntimeException(
- "getNodeSet() called but no input data present");
+ throw new RuntimeException("getNodeSet() called but no input data present");
}
/**
- * Returns the Octect stream(byte Stream) from input which was specified as
+ * Returns the Octet stream(byte Stream) from input which was specified as
* the parameter of {@link XMLSignatureInput} constructor
*
- * @return the Octect stream(byte Stream) from input which was specified as
+ * @return the Octet stream(byte Stream) from input which was specified as
* the parameter of {@link XMLSignatureInput} constructor
* @throws IOException
*/
public InputStream getOctetStream() throws IOException {
- if (_inputOctetStreamProxy instanceof FileInputStream) {
- return _inputOctetStreamProxy;
+ if (inputOctetStreamProxy instanceof FileInputStream) {
+ return inputOctetStreamProxy;
} else {
return getResetableInputStream();
}
}
/**
- * @return real octect stream
+ * @return real octet stream
*/
public InputStream getOctetStreamReal () {
- return this._inputOctetStreamProxy;
+ return this.inputOctetStreamProxy;
}
/**
@@ -295,12 +269,11 @@ public class XMLSignatureInput implement
// resetable can read again bytes.
if (bytes == null) {
is.reset();
- bytes=JavaUtils.getBytesFromStream(is);
+ bytes = JavaUtils.getBytesFromStream(is);
}
return bytes;
}
- Canonicalizer20010315OmitComments c14nizer =
- new Canonicalizer20010315OmitComments();
+ Canonicalizer20010315OmitComments c14nizer = new Canonicalizer20010315OmitComments();
bytes = c14nizer.engineCanonicalize(this);
return bytes;
}
@@ -311,8 +284,8 @@ public class XMLSignatureInput implement
* @return true if the object has been set up with a Node set
*/
public boolean isNodeSet() {
- return ((this._inputOctetStreamProxy == null
- && this._inputNodeSet != null) || isNodeSet);
+ return ((this.inputOctetStreamProxy == null
+ && this.inputNodeSet != null) || isNodeSet);
}
/**
@@ -321,8 +294,8 @@ public class XMLSignatureInput implement
* @return true if the object has been set up with a Node set
*/
public boolean isElement() {
- return (this._inputOctetStreamProxy == null && this._subNode != null
- && this._inputNodeSet == null && !isNodeSet);
+ return (this.inputOctetStreamProxy == null && this.subNode != null
+ && this.inputNodeSet == null && !isNodeSet);
}
/**
@@ -331,8 +304,8 @@ public class XMLSignatureInput implement
* @return true if the object has been set up with an octet stream
*/
public boolean isOctetStream() {
- return ((this._inputOctetStreamProxy != null || bytes != null)
- && (this._inputNodeSet == null && _subNode == null));
+ return ((this.inputOctetStreamProxy != null || bytes != null)
+ && (this.inputNodeSet == null && subNode == null));
}
/**
@@ -352,8 +325,7 @@ public class XMLSignatureInput implement
* @return true is the object has been set up with an octet stream
*/
public boolean isByteArray() {
- return (bytes != null
- && (this._inputNodeSet == null && _subNode == null));
+ return (bytes != null && (this.inputNodeSet == null && subNode == null));
}
/**
@@ -371,7 +343,7 @@ public class XMLSignatureInput implement
* @return MIMEType
*/
public String getMIMEType() {
- return this._MIMEType;
+ return this.MIMEType;
}
/**
@@ -379,8 +351,8 @@ public class XMLSignatureInput implement
*
* @param MIMEType
*/
- public void setMIMEType(String MIMEType) {
- this._MIMEType = MIMEType;
+ public void setMIMEType(String mimeType) {
+ this.MIMEType = mimeType;
}
/**
@@ -389,7 +361,7 @@ public class XMLSignatureInput implement
* @return SourceURI
*/
public String getSourceURI() {
- return this._SourceURI;
+ return this.sourceURI;
}
/**
@@ -397,8 +369,8 @@ public class XMLSignatureInput implement
*
* @param SourceURI
*/
- public void setSourceURI(String SourceURI) {
- this._SourceURI = SourceURI;
+ public void setSourceURI(String sourceURI) {
+ this.sourceURI = sourceURI;
}
/**
@@ -407,13 +379,13 @@ public class XMLSignatureInput implement
*/
public String toString() {
if (this.isNodeSet()) {
- return "XMLSignatureInput/NodeSet/" + this._inputNodeSet.size()
+ return "XMLSignatureInput/NodeSet/" + this.inputNodeSet.size()
+ " nodes/" + this.getSourceURI();
}
if (this.isElement()) {
- return "XMLSignatureInput/Element/" + this._subNode
- + " exclude "+ this.excludeNode + " comments:" +
- this.excludeComments +"/" + this.getSourceURI();
+ return "XMLSignatureInput/Element/" + this.subNode
+ + " exclude "+ this.excludeNode + " comments:"
+ + this.excludeComments +"/" + this.getSourceURI();
}
try {
return "XMLSignatureInput/OctetStream/" + this.getBytes().length
@@ -443,11 +415,10 @@ public class XMLSignatureInput implement
* @throws XMLSignatureException
* @return The HTML representation for this XMLSignature
*/
- public String getHTMLRepresentation(Set inclusiveNamespaces)
- throws XMLSignatureException {
-
- XMLSignatureInputDebugger db = new XMLSignatureInputDebugger(this,
- inclusiveNamespaces);
+ public String getHTMLRepresentation(Set<String> inclusiveNamespaces)
+ throws XMLSignatureException {
+ XMLSignatureInputDebugger db =
+ new XMLSignatureInputDebugger(this, inclusiveNamespaces);
return db.getHTMLRepresentation();
}
@@ -472,7 +443,7 @@ public class XMLSignatureInput implement
* @return The excludeNode set.
*/
public Node getSubNode() {
- return _subNode;
+ return subNode;
}
/**
@@ -494,19 +465,19 @@ public class XMLSignatureInput implement
* @throws IOException
* @throws CanonicalizationException
*/
- public void updateOutputStream(OutputStream diOs)
- throws CanonicalizationException, IOException {
+ public void updateOutputStream(OutputStream diOs)
+ throws CanonicalizationException, IOException {
updateOutputStream(diOs, false);
}
public void updateOutputStream(OutputStream diOs, boolean c14n11)
- throws CanonicalizationException, IOException {
+ throws CanonicalizationException, IOException {
if (diOs == outputStream) {
return;
}
if (bytes != null) {
diOs.write(bytes);
- } else if (_inputOctetStreamProxy == null) {
+ } else if (inputOctetStreamProxy == null) {
CanonicalizerBase c14nizer = null;
if (c14n11) {
c14nizer = new Canonicalizer11_OmitComments();
@@ -516,10 +487,10 @@ public class XMLSignatureInput implement
c14nizer.setWriter(diOs);
c14nizer.engineCanonicalize(this);
} else {
- if (_inputOctetStreamProxy instanceof FileInputStream) {
+ if (inputOctetStreamProxy instanceof FileInputStream) {
byte[] buffer = new byte[4 * 1024];
int bytesread = 0;
- while ((bytesread = _inputOctetStreamProxy.read(buffer)) != -1 ) {
+ while ((bytesread = inputOctetStreamProxy.read(buffer)) != -1) {
diOs.write(buffer, 0, bytesread);
}
} else {
@@ -547,25 +518,30 @@ public class XMLSignatureInput implement
}
protected InputStream getResetableInputStream() throws IOException {
- if (_inputOctetStreamProxy instanceof ByteArrayInputStream) {
- if (!_inputOctetStreamProxy.markSupported()) {
- throw new RuntimeException("Accepted as Markable but not truly been"+_inputOctetStreamProxy);
+ if (inputOctetStreamProxy instanceof ByteArrayInputStream) {
+ if (!inputOctetStreamProxy.markSupported()) {
+ throw new RuntimeException(
+ "Accepted as Markable but not truly been" + inputOctetStreamProxy
+ );
}
- return _inputOctetStreamProxy;
+ return inputOctetStreamProxy;
}
if (bytes != null) {
- _inputOctetStreamProxy = new ByteArrayInputStream(bytes);
- return _inputOctetStreamProxy;
+ inputOctetStreamProxy = new ByteArrayInputStream(bytes);
+ return inputOctetStreamProxy;
}
- if (_inputOctetStreamProxy == null)
+ if (inputOctetStreamProxy == null) {
return null;
- if (_inputOctetStreamProxy.markSupported()) {
- log.info("Mark Suported but not used as reset");
}
- bytes = JavaUtils.getBytesFromStream(_inputOctetStreamProxy);
- _inputOctetStreamProxy.close();
- _inputOctetStreamProxy = new ByteArrayInputStream(bytes);
- return _inputOctetStreamProxy;
+ if (inputOctetStreamProxy.markSupported()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Mark Suported but not used as reset");
+ }
+ }
+ bytes = JavaUtils.getBytesFromStream(inputOctetStreamProxy);
+ inputOctetStreamProxy.close();
+ inputOctetStreamProxy = new ByteArrayInputStream(bytes);
+ return inputOctetStreamProxy;
}
/**
@@ -576,7 +552,9 @@ public class XMLSignatureInput implement
try {
convertToNodes();
} catch (Exception e) {
- throw new XMLSecurityRuntimeException("signature.XMLSignatureInput.nodesetReference",e);
+ throw new XMLSecurityRuntimeException(
+ "signature.XMLSignatureInput.nodesetReference", e
+ );
}
}
nodeFilters.add(filter);
@@ -585,8 +563,7 @@ public class XMLSignatureInput implement
/**
* @return the node filters
*/
- public List getNodeFilters() {
- // TODO Auto-generated method stub
+ public List<NodeFilter> getNodeFilters() {
return nodeFilters;
}
@@ -605,11 +582,10 @@ public class XMLSignatureInput implement
DocumentBuilder db = dfactory.newDocumentBuilder();
// select all nodes, also the comments.
try {
- db.setErrorHandler(new org.apache.xml.security.utils
- .IgnoreAllErrorHandler());
+ db.setErrorHandler(new org.apache.xml.security.utils.IgnoreAllErrorHandler());
Document doc = db.parse(this.getOctetStream());
- this._subNode = doc;
+ this.subNode = doc;
} catch (SAXException ex) {
// if a not-wellformed nodeset exists, put a container around it...
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -620,9 +596,9 @@ public class XMLSignatureInput implement
byte result[] = baos.toByteArray();
Document document = db.parse(new ByteArrayInputStream(result));
- this._subNode = document.getDocumentElement().getFirstChild().getFirstChild();
+ this.subNode = document.getDocumentElement().getFirstChild().getFirstChild();
}
- this._inputOctetStreamProxy = null;
+ this.inputOctetStreamProxy = null;
this.bytes = null;
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInputDebugger.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInputDebugger.java?rev=1083729&r1=1083728&r2=1083729&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInputDebugger.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInputDebugger.java Mon Mar 21 10:55:11 2011
@@ -34,629 +34,590 @@ import org.w3c.dom.ProcessingInstruction
/**
* Class XMLSignatureInputDebugger
- *
- * @author $Author$
- * @version $Revision$
*/
public class XMLSignatureInputDebugger {
+ /** Field _xmlSignatureInput */
+ private Set<Node> xpathNodeSet;
+ private Set<String> inclusiveNamespaces;
- /** Field _xmlSignatureInput */
- private Set _xpathNodeSet;
+ /** Field doc */
+ private Document doc = null;
- private Set _inclusiveNamespaces;
-
- /** Field doc */
- private Document doc = null;
-
- /** Field _writer */
- private Writer _writer = null;
-
- // J-
- // public static final String HTMLPrefix = "<!DOCTYPE HTML PUBLIC
- // \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><style
- // type=\"text/css\"><!-- .INCLUDED { color: #000000; background-color:
- // #FFFFFF; font-weight: bold; } .EXCLUDED { color: #666666;
- // background-color: #999999; } .INCLUDEDINCLUSIVENAMESPACE { color:
- // #0000FF; background-color: #FFFFFF; font-weight: bold; font-style:
- // italic; } .EXCLUDEDINCLUSIVENAMESPACE { color: #0000FF; background-color:
- // #999999; font-style: italic; } --> </style> </head><body
- // bgcolor=\"#999999\"><pre>";
- /** The HTML Prefix* */
- static final String HTMLPrefix = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
- + "<html>\n"
- + "<head>\n"
- + "<title>Caninical XML node set</title>\n"
- + "<style type=\"text/css\">\n"
- + "<!-- \n"
- + ".INCLUDED { \n"
- + " color: #000000; \n"
- + " background-color: \n"
- + " #FFFFFF; \n"
- + " font-weight: bold; } \n"
- + ".EXCLUDED { \n"
- + " color: #666666; \n"
- + " background-color: \n"
- + " #999999; } \n"
- + ".INCLUDEDINCLUSIVENAMESPACE { \n"
- + " color: #0000FF; \n"
- + " background-color: #FFFFFF; \n"
- + " font-weight: bold; \n"
- + " font-style: italic; } \n"
- + ".EXCLUDEDINCLUSIVENAMESPACE { \n"
- + " color: #0000FF; \n"
- + " background-color: #999999; \n"
- + " font-style: italic; } \n"
- + "--> \n"
- + "</style> \n"
- + "</head>\n"
- + "<body bgcolor=\"#999999\">\n"
- + "<h1>Explanation of the output</h1>\n"
- + "<p>The following text contains the nodeset of the given Reference before it is canonicalized. There exist four different styles to indicate how a given node is treated.</p>\n"
- + "<ul>\n"
- + "<li class=\"INCLUDED\">A node which is in the node set is labeled using the INCLUDED style.</li>\n"
- + "<li class=\"EXCLUDED\">A node which is <em>NOT</em> in the node set is labeled EXCLUDED style.</li>\n"
- + "<li class=\"INCLUDEDINCLUSIVENAMESPACE\">A namespace which is in the node set AND in the InclusiveNamespaces PrefixList is labeled using the INCLUDEDINCLUSIVENAMESPACE style.</li>\n"
- + "<li class=\"EXCLUDEDINCLUSIVENAMESPACE\">A namespace which is in NOT the node set AND in the InclusiveNamespaces PrefixList is labeled using the INCLUDEDINCLUSIVENAMESPACE style.</li>\n"
- + "</ul>\n" + "<h1>Output</h1>\n" + "<pre>\n";
-
- /** HTML Suffix * */
- static final String HTMLSuffix = "</pre></body></html>";
-
- static final String HTMLExcludePrefix = "<span class=\"EXCLUDED\">";
-
- static final String HTMLIncludePrefix = "<span class=\"INCLUDED\">";
-
- static final String HTMLIncludeOrExcludeSuffix = "</span>";
-
- static final String HTMLIncludedInclusiveNamespacePrefix = "<span class=\"INCLUDEDINCLUSIVENAMESPACE\">";
-
- static final String HTMLExcludedInclusiveNamespacePrefix = "<span class=\"EXCLUDEDINCLUSIVENAMESPACE\">";
-
- private static final int NODE_BEFORE_DOCUMENT_ELEMENT = -1;
-
- private static final int NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT = 0;
-
- private static final int NODE_AFTER_DOCUMENT_ELEMENT = 1;
-
- static final AttrCompare ATTR_COMPARE = new AttrCompare();
-
- // J+
- private XMLSignatureInputDebugger() {
- // do nothing
- }
-
- /**
- * Constructor XMLSignatureInputDebugger
- *
- * @param xmlSignatureInput the signatur to pretty print
- */
- public XMLSignatureInputDebugger(
- XMLSignatureInput xmlSignatureInput) {
-
- if (!xmlSignatureInput.isNodeSet()) {
- this._xpathNodeSet = null;
- } else {
- this._xpathNodeSet = xmlSignatureInput._inputNodeSet;
- }
+ /** Field writer */
+ private Writer writer = null;
+
+ /** The HTML Prefix* */
+ static final String HTMLPrefix =
+ "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
+ + "<html>\n"
+ + "<head>\n"
+ + "<title>Caninical XML node set</title>\n"
+ + "<style type=\"text/css\">\n"
+ + "<!-- \n"
+ + ".INCLUDED { \n"
+ + " color: #000000; \n"
+ + " background-color: \n"
+ + " #FFFFFF; \n"
+ + " font-weight: bold; } \n"
+ + ".EXCLUDED { \n"
+ + " color: #666666; \n"
+ + " background-color: \n"
+ + " #999999; } \n"
+ + ".INCLUDEDINCLUSIVENAMESPACE { \n"
+ + " color: #0000FF; \n"
+ + " background-color: #FFFFFF; \n"
+ + " font-weight: bold; \n"
+ + " font-style: italic; } \n"
+ + ".EXCLUDEDINCLUSIVENAMESPACE { \n"
+ + " color: #0000FF; \n"
+ + " background-color: #999999; \n"
+ + " font-style: italic; } \n"
+ + "--> \n"
+ + "</style> \n"
+ + "</head>\n"
+ + "<body bgcolor=\"#999999\">\n"
+ + "<h1>Explanation of the output</h1>\n"
+ + "<p>The following text contains the nodeset of the given Reference before it is canonicalized. There exist four different styles to indicate how a given node is treated.</p>\n"
+ + "<ul>\n"
+ + "<li class=\"INCLUDED\">A node which is in the node set is labeled using the INCLUDED style.</li>\n"
+ + "<li class=\"EXCLUDED\">A node which is <em>NOT</em> in the node set is labeled EXCLUDED style.</li>\n"
+ + "<li class=\"INCLUDEDINCLUSIVENAMESPACE\">A namespace which is in the node set AND in the InclusiveNamespaces PrefixList is labeled using the INCLUDEDINCLUSIVENAMESPACE style.</li>\n"
+ + "<li class=\"EXCLUDEDINCLUSIVENAMESPACE\">A namespace which is in NOT the node set AND in the InclusiveNamespaces PrefixList is labeled using the INCLUDEDINCLUSIVENAMESPACE style.</li>\n"
+ + "</ul>\n" + "<h1>Output</h1>\n" + "<pre>\n";
+
+ /** HTML Suffix * */
+ static final String HTMLSuffix = "</pre></body></html>";
+
+ static final String HTMLExcludePrefix = "<span class=\"EXCLUDED\">";
+
+ static final String HTMLIncludePrefix = "<span class=\"INCLUDED\">";
+
+ static final String HTMLIncludeOrExcludeSuffix = "</span>";
+
+ static final String HTMLIncludedInclusiveNamespacePrefix = "<span class=\"INCLUDEDINCLUSIVENAMESPACE\">";
+
+ static final String HTMLExcludedInclusiveNamespacePrefix = "<span class=\"EXCLUDEDINCLUSIVENAMESPACE\">";
+
+ private static final int NODE_BEFORE_DOCUMENT_ELEMENT = -1;
+
+ private static final int NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT = 0;
+
+ private static final int NODE_AFTER_DOCUMENT_ELEMENT = 1;
+
+ static final AttrCompare ATTR_COMPARE = new AttrCompare();
+
+ /**
+ * Constructor XMLSignatureInputDebugger
+ *
+ * @param xmlSignatureInput the signature to pretty print
+ */
+ public XMLSignatureInputDebugger(XMLSignatureInput xmlSignatureInput) {
+ if (!xmlSignatureInput.isNodeSet()) {
+ this.xpathNodeSet = null;
+ } else {
+ this.xpathNodeSet = xmlSignatureInput.getInputNodeSet();
}
+ }
- /**
- * Constructor XMLSignatureInputDebugger
- *
- * @param xmlSignatureInput the signatur to pretty print
- * @param inclusiveNamespace
- */
- public XMLSignatureInputDebugger(
- XMLSignatureInput xmlSignatureInput, Set inclusiveNamespace) {
-
- this(xmlSignatureInput);
-
- this._inclusiveNamespaces = inclusiveNamespace;
- }
-
- /**
- * Method getHTMLRepresentation
- *
- * @return The HTML Representation.
- * @throws XMLSignatureException
- */
- public String getHTMLRepresentation() throws XMLSignatureException {
-
- if ((this._xpathNodeSet == null) || (this._xpathNodeSet.size() == 0)) {
- return HTMLPrefix + "<blink>no node set, sorry</blink>"
- + HTMLSuffix;
- }
-
- {
-
- // get only a single node as anchor to fetch the owner document
- Node n = (Node) this._xpathNodeSet.iterator().next();
+ /**
+ * Constructor XMLSignatureInputDebugger
+ *
+ * @param xmlSignatureInput the signatur to pretty print
+ * @param inclusiveNamespace
+ */
+ public XMLSignatureInputDebugger(
+ XMLSignatureInput xmlSignatureInput,
+ Set<String> inclusiveNamespace
+ ) {
+ this(xmlSignatureInput);
+ this.inclusiveNamespaces = inclusiveNamespace;
+ }
+
+ /**
+ * Method getHTMLRepresentation
+ *
+ * @return The HTML Representation.
+ * @throws XMLSignatureException
+ */
+ public String getHTMLRepresentation() throws XMLSignatureException {
+ if ((this.xpathNodeSet == null) || (this.xpathNodeSet.size() == 0)) {
+ return HTMLPrefix + "<blink>no node set, sorry</blink>" + HTMLSuffix;
+ }
- this.doc = XMLUtils.getOwnerDocument(n);
- }
+ // get only a single node as anchor to fetch the owner document
+ Node n = (Node) this.xpathNodeSet.iterator().next();
- try {
- this._writer = new StringWriter();
+ this.doc = XMLUtils.getOwnerDocument(n);
- this.canonicalizeXPathNodeSet(this.doc);
- this._writer.close();
+ try {
+ this.writer = new StringWriter();
- return this._writer.toString();
- } catch (IOException ex) {
- throw new XMLSignatureException("empty", ex);
- } finally {
- this._xpathNodeSet = null;
- this.doc = null;
- this._writer = null;
- }
+ this.canonicalizeXPathNodeSet(this.doc);
+ this.writer.close();
+
+ return this.writer.toString();
+ } catch (IOException ex) {
+ throw new XMLSignatureException("empty", ex);
+ } finally {
+ this.xpathNodeSet = null;
+ this.doc = null;
+ this.writer = null;
}
+ }
- /**
- * Method canonicalizeXPathNodeSet
- *
- * @param currentNode
- * @throws XMLSignatureException
- * @throws IOException
- */
- private void canonicalizeXPathNodeSet(Node currentNode)
- throws XMLSignatureException, IOException {
-
- int currentNodeType = currentNode.getNodeType();
- switch (currentNodeType) {
-
- case Node.DOCUMENT_TYPE_NODE:
- default:
- break;
+ /**
+ * Method canonicalizeXPathNodeSet
+ *
+ * @param currentNode
+ * @throws XMLSignatureException
+ * @throws IOException
+ */
+ private void canonicalizeXPathNodeSet(Node currentNode)
+ throws XMLSignatureException, IOException {
+
+ int currentNodeType = currentNode.getNodeType();
+ switch (currentNodeType) {
+
+ case Node.DOCUMENT_TYPE_NODE:
+ default:
+ break;
+
+ case Node.ENTITY_NODE:
+ case Node.NOTATION_NODE:
+ case Node.DOCUMENT_FRAGMENT_NODE:
+ case Node.ATTRIBUTE_NODE:
+ throw new XMLSignatureException("empty");
+ case Node.DOCUMENT_NODE:
+ this.writer.write(HTMLPrefix);
+
+ for (Node currentChild = currentNode.getFirstChild();
+ currentChild != null; currentChild = currentChild.getNextSibling()) {
+ this.canonicalizeXPathNodeSet(currentChild);
+ }
+
+ this.writer.write(HTMLSuffix);
+ break;
+
+ case Node.COMMENT_NODE:
+ if (this.xpathNodeSet.contains(currentNode)) {
+ this.writer.write(HTMLIncludePrefix);
+ } else {
+ this.writer.write(HTMLExcludePrefix);
+ }
+
+ int position = getPositionRelativeToDocumentElement(currentNode);
+
+ if (position == NODE_AFTER_DOCUMENT_ELEMENT) {
+ this.writer.write("\n");
+ }
+
+ this.outputCommentToWriter((Comment) currentNode);
+
+ if (position == NODE_BEFORE_DOCUMENT_ELEMENT) {
+ this.writer.write("\n");
+ }
+
+ this.writer.write(HTMLIncludeOrExcludeSuffix);
+ break;
+
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ if (this.xpathNodeSet.contains(currentNode)) {
+ this.writer.write(HTMLIncludePrefix);
+ } else {
+ this.writer.write(HTMLExcludePrefix);
+ }
+
+ position = getPositionRelativeToDocumentElement(currentNode);
+
+ if (position == NODE_AFTER_DOCUMENT_ELEMENT) {
+ this.writer.write("\n");
+ }
+
+ this.outputPItoWriter((ProcessingInstruction) currentNode);
+
+ if (position == NODE_BEFORE_DOCUMENT_ELEMENT) {
+ this.writer.write("\n");
+ }
+
+ this.writer.write(HTMLIncludeOrExcludeSuffix);
+ break;
+
+ case Node.TEXT_NODE:
+ case Node.CDATA_SECTION_NODE:
+ if (this.xpathNodeSet.contains(currentNode)) {
+ this.writer.write(HTMLIncludePrefix);
+ } else {
+ this.writer.write(HTMLExcludePrefix);
+ }
+
+ outputTextToWriter(currentNode.getNodeValue());
+
+ for (Node nextSibling = currentNode.getNextSibling();
+ (nextSibling != null)
+ && ((nextSibling.getNodeType() == Node.TEXT_NODE)
+ || (nextSibling.getNodeType() == Node.CDATA_SECTION_NODE));
+ nextSibling = nextSibling.getNextSibling()) {
+ /*
+ * The XPath data model allows to select only the first of a
+ * sequence of mixed text and CDATA nodes. But we must output
+ * them all, so we must search:
+ *
+ * @see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6329
+ */
+ this.outputTextToWriter(nextSibling.getNodeValue());
+ }
+
+ this.writer.write(HTMLIncludeOrExcludeSuffix);
+ break;
+
+ case Node.ELEMENT_NODE:
+ Element currentElement = (Element) currentNode;
+
+ if (this.xpathNodeSet.contains(currentNode)) {
+ this.writer.write(HTMLIncludePrefix);
+ } else {
+ this.writer.write(HTMLExcludePrefix);
+ }
+
+ this.writer.write("<");
+ this.writer.write(currentElement.getTagName());
+
+ this.writer.write(HTMLIncludeOrExcludeSuffix);
+
+ // we output all Attrs which are available
+ NamedNodeMap attrs = currentElement.getAttributes();
+ int attrsLength = attrs.getLength();
+ Attr attrs2[] = new Attr[attrsLength];
+
+ for (int i = 0; i < attrsLength; i++) {
+ attrs2[i] = (Attr)attrs.item(i);
+ }
+
+ Arrays.sort(attrs2, ATTR_COMPARE);
+ Object attrs3[] = attrs2;
+
+ for (int i = 0; i < attrsLength; i++) {
+ Attr a = (Attr) attrs3[i];
+ boolean included = this.xpathNodeSet.contains(a);
+ boolean inclusive = this.inclusiveNamespaces.contains(a.getName());
+
+ if (included) {
+ if (inclusive) {
+ // included and inclusive
+ this.writer.write(HTMLIncludedInclusiveNamespacePrefix);
+ } else {
+ // included and not inclusive
+ this.writer.write(HTMLIncludePrefix);
+ }
+ } else {
+ if (inclusive) {
+ // excluded and inclusive
+ this.writer.write(HTMLExcludedInclusiveNamespacePrefix);
+ } else {
+ // excluded and not inclusive
+ this.writer.write(HTMLExcludePrefix);
+ }
+ }
- case Node.ENTITY_NODE:
- case Node.NOTATION_NODE:
- case Node.DOCUMENT_FRAGMENT_NODE:
- case Node.ATTRIBUTE_NODE:
- throw new XMLSignatureException("empty");
- case Node.DOCUMENT_NODE:
- this._writer.write(HTMLPrefix);
-
- for (Node currentChild = currentNode.getFirstChild(); currentChild != null; currentChild = currentChild
- .getNextSibling()) {
- this.canonicalizeXPathNodeSet(currentChild);
- }
-
- this._writer.write(HTMLSuffix);
- break;
-
- case Node.COMMENT_NODE:
- if (this._xpathNodeSet.contains(currentNode)) {
- this._writer.write(HTMLIncludePrefix);
- } else {
- this._writer.write(HTMLExcludePrefix);
- }
-
- int position = getPositionRelativeToDocumentElement(currentNode);
-
- if (position == NODE_AFTER_DOCUMENT_ELEMENT) {
- this._writer.write("\n");
- }
-
- this.outputCommentToWriter((Comment) currentNode);
-
- if (position == NODE_BEFORE_DOCUMENT_ELEMENT) {
- this._writer.write("\n");
- }
-
- this._writer.write(HTMLIncludeOrExcludeSuffix);
- break;
-
- case Node.PROCESSING_INSTRUCTION_NODE:
- if (this._xpathNodeSet.contains(currentNode)) {
- this._writer.write(HTMLIncludePrefix);
- } else {
- this._writer.write(HTMLExcludePrefix);
- }
-
- position = getPositionRelativeToDocumentElement(currentNode);
-
- if (position == NODE_AFTER_DOCUMENT_ELEMENT) {
- this._writer.write("\n");
- }
-
- this.outputPItoWriter((ProcessingInstruction) currentNode);
-
- if (position == NODE_BEFORE_DOCUMENT_ELEMENT) {
- this._writer.write("\n");
- }
-
- this._writer.write(HTMLIncludeOrExcludeSuffix);
- break;
-
- case Node.TEXT_NODE:
- case Node.CDATA_SECTION_NODE:
- if (this._xpathNodeSet.contains(currentNode)) {
- this._writer.write(HTMLIncludePrefix);
- } else {
- this._writer.write(HTMLExcludePrefix);
- }
-
- outputTextToWriter(currentNode.getNodeValue());
-
- for (Node nextSibling = currentNode.getNextSibling(); (nextSibling != null)
- && ((nextSibling.getNodeType() == Node.TEXT_NODE) || (nextSibling
- .getNodeType() == Node.CDATA_SECTION_NODE)); nextSibling = nextSibling
- .getNextSibling()) {
-
- /*
- * The XPath data model allows to select only the first of a
- * sequence of mixed text and CDATA nodes. But we must output
- * them all, so we must search:
- *
- * @see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6329
- */
- this.outputTextToWriter(nextSibling.getNodeValue());
- }
-
- this._writer.write(HTMLIncludeOrExcludeSuffix);
- break;
-
- case Node.ELEMENT_NODE:
- Element currentElement = (Element) currentNode;
-
- if (this._xpathNodeSet.contains(currentNode)) {
- this._writer.write(HTMLIncludePrefix);
- } else {
- this._writer.write(HTMLExcludePrefix);
- }
-
- this._writer.write("<");
- this._writer.write(currentElement.getTagName());
-
- this._writer.write(HTMLIncludeOrExcludeSuffix);
-
- // we output all Attrs which are available
- NamedNodeMap attrs = currentElement.getAttributes();
- int attrsLength = attrs.getLength();
- Attr attrs2[] = new Attr[attrsLength];
-
- for (int i = 0; i < attrsLength; i++) {
- attrs2[i] = (Attr)attrs.item(i);
- }
-
- Arrays.sort(attrs2, ATTR_COMPARE);
- Object attrs3[] = attrs2;
-
- for (int i = 0; i < attrsLength; i++) {
- Attr a = (Attr) attrs3[i];
- boolean included = this._xpathNodeSet.contains(a);
- boolean inclusive = this._inclusiveNamespaces.contains(a
- .getName());
-
- if (included) {
- if (inclusive) {
-
- // included and inclusive
- this._writer
- .write(HTMLIncludedInclusiveNamespacePrefix);
- } else {
-
- // included and not inclusive
- this._writer.write(HTMLIncludePrefix);
- }
- } else {
- if (inclusive) {
-
- // excluded and inclusive
- this._writer
- .write(HTMLExcludedInclusiveNamespacePrefix);
- } else {
-
- // excluded and not inclusive
- this._writer.write(HTMLExcludePrefix);
- }
- }
-
- this.outputAttrToWriter(a.getNodeName(), a.getNodeValue());
-
- this._writer.write(HTMLIncludeOrExcludeSuffix);
- }
-
- if (this._xpathNodeSet.contains(currentNode)) {
- this._writer.write(HTMLIncludePrefix);
- } else {
- this._writer.write(HTMLExcludePrefix);
- }
-
- this._writer.write(">");
-
- this._writer.write(HTMLIncludeOrExcludeSuffix);
-
- // traversal
- for (Node currentChild = currentNode.getFirstChild(); currentChild != null; currentChild = currentChild
- .getNextSibling()) {
- this.canonicalizeXPathNodeSet(currentChild);
- }
-
- if (this._xpathNodeSet.contains(currentNode)) {
- this._writer.write(HTMLIncludePrefix);
- } else {
- this._writer.write(HTMLExcludePrefix);
- }
-
- this._writer.write("</");
- this._writer.write(currentElement.getTagName());
- this._writer.write(">");
+ this.outputAttrToWriter(a.getNodeName(), a.getNodeValue());
+ this.writer.write(HTMLIncludeOrExcludeSuffix);
+ }
+
+ if (this.xpathNodeSet.contains(currentNode)) {
+ this.writer.write(HTMLIncludePrefix);
+ } else {
+ this.writer.write(HTMLExcludePrefix);
+ }
+
+ this.writer.write(">");
+
+ this.writer.write(HTMLIncludeOrExcludeSuffix);
+
+ // traversal
+ for (Node currentChild = currentNode.getFirstChild();
+ currentChild != null;
+ currentChild = currentChild.getNextSibling()) {
+ this.canonicalizeXPathNodeSet(currentChild);
+ }
+
+ if (this.xpathNodeSet.contains(currentNode)) {
+ this.writer.write(HTMLIncludePrefix);
+ } else {
+ this.writer.write(HTMLExcludePrefix);
+ }
+
+ this.writer.write("</");
+ this.writer.write(currentElement.getTagName());
+ this.writer.write(">");
- this._writer.write(HTMLIncludeOrExcludeSuffix);
- break;
- }
+ this.writer.write(HTMLIncludeOrExcludeSuffix);
+ break;
}
+ }
- /**
- * Checks whether a Comment or ProcessingInstruction is before or after the
- * document element. This is needed for prepending or appending "\n"s.
- *
- * @param currentNode
- * comment or pi to check
- * @return NODE_BEFORE_DOCUMENT_ELEMENT,
- * NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT or
- * NODE_AFTER_DOCUMENT_ELEMENT
- * @see #NODE_BEFORE_DOCUMENT_ELEMENT
- * @see #NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT
- * @see #NODE_AFTER_DOCUMENT_ELEMENT
- */
- private int getPositionRelativeToDocumentElement(Node currentNode) {
-
- if (currentNode == null) {
- return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
- }
+ /**
+ * Checks whether a Comment or ProcessingInstruction is before or after the
+ * document element. This is needed for prepending or appending "\n"s.
+ *
+ * @param currentNode
+ * comment or pi to check
+ * @return NODE_BEFORE_DOCUMENT_ELEMENT,
+ * NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT or
+ * NODE_AFTER_DOCUMENT_ELEMENT
+ * @see #NODE_BEFORE_DOCUMENT_ELEMENT
+ * @see #NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT
+ * @see #NODE_AFTER_DOCUMENT_ELEMENT
+ */
+ private int getPositionRelativeToDocumentElement(Node currentNode) {
+ if (currentNode == null) {
+ return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
+ }
- Document doc = currentNode.getOwnerDocument();
+ Document doc = currentNode.getOwnerDocument();
- if (currentNode.getParentNode() != doc) {
- return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
- }
-
- Element documentElement = doc.getDocumentElement();
+ if (currentNode.getParentNode() != doc) {
+ return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
+ }
- if (documentElement == null) {
- return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
- }
+ Element documentElement = doc.getDocumentElement();
- if (documentElement == currentNode) {
- return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
- }
+ if (documentElement == null) {
+ return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
+ }
- for (Node x = currentNode; x != null; x = x.getNextSibling()) {
- if (x == documentElement) {
- return NODE_BEFORE_DOCUMENT_ELEMENT;
- }
- }
+ if (documentElement == currentNode) {
+ return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
+ }
- return NODE_AFTER_DOCUMENT_ELEMENT;
+ for (Node x = currentNode; x != null; x = x.getNextSibling()) {
+ if (x == documentElement) {
+ return NODE_BEFORE_DOCUMENT_ELEMENT;
+ }
}
- /**
- * Normalizes an {@link Attr}ibute value
- *
- * The string value of the node is modified by replacing
- * <UL>
- * <LI>all ampersands (&) with <CODE>&amp;</CODE></LI>
- * <LI>all open angle brackets (<) with <CODE>&lt;</CODE></LI>
- * <LI>all quotation mark characters with <CODE>&quot;</CODE></LI>
- * <LI>and the whitespace characters <CODE>#x9</CODE>, #xA, and #xD,
- * with character references. The character references are written in
- * uppercase hexadecimal with no leading zeroes (for example, <CODE>#xD</CODE>
- * is represented by the character reference <CODE>&#xD;</CODE>)</LI>
- * </UL>
- *
- * @param name
- * @param value
- * @throws IOException
- */
- private void outputAttrToWriter(String name, String value)
- throws IOException {
-
- this._writer.write(" ");
- this._writer.write(name);
- this._writer.write("=\"");
-
- int length = value.length();
-
- for (int i = 0; i < length; i++) {
- char c = value.charAt(i);
-
- switch (c) {
-
- case '&':
- this._writer.write("&amp;");
- break;
-
- case '<':
- this._writer.write("&lt;");
- break;
-
- case '"':
- this._writer.write("&quot;");
- break;
-
- case 0x09: // '\t'
- this._writer.write("&#x9;");
- break;
-
- case 0x0A: // '\n'
- this._writer.write("&#xA;");
- break;
-
- case 0x0D: // '\r'
- this._writer.write("&#xD;");
- break;
-
- default:
- this._writer.write(c);
- break;
- }
- }
+ return NODE_AFTER_DOCUMENT_ELEMENT;
+ }
- this._writer.write("\"");
+ /**
+ * Normalizes an {@link Attr}ibute value
+ *
+ * The string value of the node is modified by replacing
+ * <UL>
+ * <LI>all ampersands (&) with <CODE>&amp;</CODE></LI>
+ * <LI>all open angle brackets (<) with <CODE>&lt;</CODE></LI>
+ * <LI>all quotation mark characters with <CODE>&quot;</CODE></LI>
+ * <LI>and the whitespace characters <CODE>#x9</CODE>, #xA, and #xD,
+ * with character references. The character references are written in
+ * uppercase hexadecimal with no leading zeroes (for example, <CODE>#xD</CODE>
+ * is represented by the character reference <CODE>&#xD;</CODE>)</LI>
+ * </UL>
+ *
+ * @param name
+ * @param value
+ * @throws IOException
+ */
+ private void outputAttrToWriter(String name, String value) throws IOException {
+ this.writer.write(" ");
+ this.writer.write(name);
+ this.writer.write("=\"");
+
+ int length = value.length();
+
+ for (int i = 0; i < length; i++) {
+ char c = value.charAt(i);
+
+ switch (c) {
+
+ case '&':
+ this.writer.write("&amp;");
+ break;
+
+ case '<':
+ this.writer.write("&lt;");
+ break;
+
+ case '"':
+ this.writer.write("&quot;");
+ break;
+
+ case 0x09: // '\t'
+ this.writer.write("&#x9;");
+ break;
+
+ case 0x0A: // '\n'
+ this.writer.write("&#xA;");
+ break;
+
+ case 0x0D: // '\r'
+ this.writer.write("&#xD;");
+ break;
+
+ default:
+ this.writer.write(c);
+ break;
+ }
}
- /**
- * Normalizes a {@link org.w3c.dom.Comment} value
- *
- * @param currentPI
- * @throws IOException
- */
- private void outputPItoWriter(ProcessingInstruction currentPI)
- throws IOException {
+ this.writer.write("\"");
+ }
- if (currentPI == null) {
- return;
- }
+ /**
+ * Normalizes a {@link org.w3c.dom.Comment} value
+ *
+ * @param currentPI
+ * @throws IOException
+ */
+ private void outputPItoWriter(ProcessingInstruction currentPI) throws IOException {
- this._writer.write("<?");
+ if (currentPI == null) {
+ return;
+ }
- String target = currentPI.getTarget();
- int length = target.length();
+ this.writer.write("<?");
- for (int i = 0; i < length; i++) {
- char c = target.charAt(i);
+ String target = currentPI.getTarget();
+ int length = target.length();
- switch (c) {
+ for (int i = 0; i < length; i++) {
+ char c = target.charAt(i);
- case 0x0D:
- this._writer.write("&#xD;");
- break;
+ switch (c) {
- case ' ':
- this._writer.write("·");
- break;
+ case 0x0D:
+ this.writer.write("&#xD;");
+ break;
- case '\n':
- this._writer.write("¶\n");
- break;
+ case ' ':
+ this.writer.write("·");
+ break;
- default:
- this._writer.write(c);
- break;
- }
- }
+ case '\n':
+ this.writer.write("¶\n");
+ break;
- String data = currentPI.getData();
+ default:
+ this.writer.write(c);
+ break;
+ }
+ }
- length = data.length();
+ String data = currentPI.getData();
- if (length > 0) {
- this._writer.write(" ");
+ length = data.length();
- for (int i = 0; i < length; i++) {
- char c = data.charAt(i);
+ if (length > 0) {
+ this.writer.write(" ");
- switch (c) {
+ for (int i = 0; i < length; i++) {
+ char c = data.charAt(i);
- case 0x0D:
- this._writer.write("&#xD;");
- break;
+ switch (c) {
- default:
- this._writer.write(c);
- break;
- }
- }
- }
+ case 0x0D:
+ this.writer.write("&#xD;");
+ break;
- this._writer.write("?>");
+ default:
+ this.writer.write(c);
+ break;
+ }
+ }
}
- /**
- * Method outputCommentToWriter
- *
- * @param currentComment
- * @throws IOException
- */
- private void outputCommentToWriter(Comment currentComment)
- throws IOException {
+ this.writer.write("?>");
+ }
- if (currentComment == null) {
- return;
- }
+ /**
+ * Method outputCommentToWriter
+ *
+ * @param currentComment
+ * @throws IOException
+ */
+ private void outputCommentToWriter(Comment currentComment) throws IOException {
- this._writer.write("<!--");
+ if (currentComment == null) {
+ return;
+ }
- String data = currentComment.getData();
- int length = data.length();
+ this.writer.write("<!--");
- for (int i = 0; i < length; i++) {
- char c = data.charAt(i);
+ String data = currentComment.getData();
+ int length = data.length();
- switch (c) {
+ for (int i = 0; i < length; i++) {
+ char c = data.charAt(i);
- case 0x0D:
- this._writer.write("&#xD;");
- break;
+ switch (c) {
- case ' ':
- this._writer.write("·");
- break;
+ case 0x0D:
+ this.writer.write("&#xD;");
+ break;
- case '\n':
- this._writer.write("¶\n");
- break;
+ case ' ':
+ this.writer.write("·");
+ break;
- default:
- this._writer.write(c);
- break;
- }
- }
+ case '\n':
+ this.writer.write("¶\n");
+ break;
- this._writer.write("-->");
+ default:
+ this.writer.write(c);
+ break;
+ }
}
- /**
- * Method outputTextToWriter
- *
- * @param text
- * @throws IOException
- */
- private void outputTextToWriter(String text) throws IOException {
+ this.writer.write("-->");
+ }
- if (text == null) {
- return;
- }
+ /**
+ * Method outputTextToWriter
+ *
+ * @param text
+ * @throws IOException
+ */
+ private void outputTextToWriter(String text) throws IOException {
+ if (text == null) {
+ return;
+ }
- int length = text.length();
+ int length = text.length();
- for (int i = 0; i < length; i++) {
- char c = text.charAt(i);
+ for (int i = 0; i < length; i++) {
+ char c = text.charAt(i);
- switch (c) {
+ switch (c) {
- case '&':
- this._writer.write("&amp;");
- break;
+ case '&':
+ this.writer.write("&amp;");
+ break;
- case '<':
- this._writer.write("&lt;");
- break;
+ case '<':
+ this.writer.write("&lt;");
+ break;
- case '>':
- this._writer.write("&gt;");
- break;
+ case '>':
+ this.writer.write("&gt;");
+ break;
- case 0xD:
- this._writer.write("&#xD;");
- break;
+ case 0xD:
+ this.writer.write("&#xD;");
+ break;
- case ' ':
- this._writer.write("·");
- break;
+ case ' ':
+ this.writer.write("·");
+ break;
- case '\n':
- this._writer.write("¶\n");
- break;
+ case '\n':
+ this.writer.write("¶\n");
+ break;
- default:
- this._writer.write(c);
- break;
- }
- }
+ default:
+ this.writer.write(c);
+ break;
+ }
}
+ }
}