Fields Summary |
---|
private Set | _xpathNodeSetField _xmlSignatureInput |
private Set | _inclusiveNamespaces |
private Document | _docField _doc |
private Writer | _writerField _writer |
static final String | HTMLPrefixThe HTML Prefix* |
static final String | HTMLSuffixHTML Suffix * |
static final String | HTMLExcludePrefix |
static final String | HTMLExcludeSuffix |
static final String | HTMLIncludePrefix |
static final String | HTMLIncludeSuffix |
static final String | HTMLIncludedInclusiveNamespacePrefix |
static final String | HTMLIncludedInclusiveNamespaceSuffix |
static final String | HTMLExcludedInclusiveNamespacePrefix |
static final String | HTMLExcludedInclusiveNamespaceSuffix |
private static final int | NODE_BEFORE_DOCUMENT_ELEMENT |
private static final int | NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT |
private static final int | NODE_AFTER_DOCUMENT_ELEMENT |
static final AttrCompare | ATTR_COMPARE |
Methods Summary |
---|
private void | canonicalizeXPathNodeSet(org.w3c.dom.Node currentNode)Method canonicalizeXPathNodeSet
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");
}
if (this._xpathNodeSet.contains(currentNode)) {
this._writer.write(HTMLIncludeSuffix);
} else {
this._writer.write(HTMLExcludeSuffix);
}
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");
}
if (this._xpathNodeSet.contains(currentNode)) {
this._writer.write(HTMLIncludeSuffix);
} else {
this._writer.write(HTMLExcludeSuffix);
}
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());
}
if (this._xpathNodeSet.contains(currentNode)) {
this._writer.write(HTMLIncludeSuffix);
} else {
this._writer.write(HTMLExcludeSuffix);
}
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());
if (this._xpathNodeSet.contains(currentNode)) {
this._writer.write(HTMLIncludeSuffix);
} else {
this._writer.write(HTMLExcludeSuffix);
}
// we output all Attrs which are available
NamedNodeMap attrs = currentElement.getAttributes();
int attrsLength = attrs.getLength();
Object attrs2[] = new Object[attrsLength];
for (int i = 0; i < attrsLength; i++) {
attrs2[i] = 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());
if (included) {
if (inclusive) {
// included and inclusive
this._writer
.write(HTMLIncludedInclusiveNamespaceSuffix);
} else {
// included and not inclusive
this._writer.write(HTMLIncludeSuffix);
}
} else {
if (inclusive) {
// excluded and inclusive
this._writer
.write(HTMLExcludedInclusiveNamespaceSuffix);
} else {
// excluded and not inclusive
this._writer.write(HTMLExcludeSuffix);
}
}
}
if (this._xpathNodeSet.contains(currentNode)) {
this._writer.write(HTMLIncludePrefix);
} else {
this._writer.write(HTMLExcludePrefix);
}
this._writer.write(">");
if (this._xpathNodeSet.contains(currentNode)) {
this._writer.write(HTMLIncludeSuffix);
} else {
this._writer.write(HTMLExcludeSuffix);
}
// 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(">");
if (this._xpathNodeSet.contains(currentNode)) {
this._writer.write(HTMLIncludeSuffix);
} else {
this._writer.write(HTMLExcludeSuffix);
}
break;
}
|
public java.lang.String | getHTMLRepresentation()Method getHTMLRepresentation
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();
this._doc = XMLUtils.getOwnerDocument(n);
}
try {
this._writer = new StringWriter();
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;
}
|
private int | getPositionRelativeToDocumentElement(org.w3c.dom.Node currentNode)Checks whether a Comment or ProcessingInstruction is before or after the
document element. This is needed for prepending or appending "\n"s.
if (currentNode == null) {
return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
}
Document doc = currentNode.getOwnerDocument();
if (currentNode.getParentNode() != doc) {
return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
}
Element documentElement = doc.getDocumentElement();
if (documentElement == null) {
return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
}
if (documentElement == currentNode) {
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;
}
}
return NODE_AFTER_DOCUMENT_ELEMENT;
|
private void | outputAttrToWriter(java.lang.String name, java.lang.String value)Normalizes an {@link Attr}ibute value
The string value of the node is modified by replacing
- all ampersands (&) with
&
- all open angle brackets (<) with
<
- all quotation mark characters with
"
- and the whitespace characters
#x9 , #xA, and #xD,
with character references. The character references are written in
uppercase hexadecimal with no leading zeroes (for example, #xD
is represented by the character reference 
 )
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("&");
break;
case '<":
this._writer.write("<");
break;
case '"":
this._writer.write(""");
break;
case 0x09: // '\t'
this._writer.write("	");
break;
case 0x0A: // '\n'
this._writer.write("
");
break;
case 0x0D: // '\r'
this._writer.write("
");
break;
default:
this._writer.write(c);
break;
}
}
this._writer.write("\"");
|
private void | outputCommentToWriter(org.w3c.dom.Comment currentComment)Method outputCommentToWriter
if (currentComment == null) {
return;
}
this._writer.write("<!--");
String data = currentComment.getData();
int length = data.length();
for (int i = 0; i < length; i++) {
char c = data.charAt(i);
switch (c) {
case 0x0D:
this._writer.write("
");
break;
case ' ":
this._writer.write("·");
break;
case '\n":
this._writer.write("¶\n");
break;
default:
this._writer.write(c);
break;
}
}
this._writer.write("-->");
|
private void | outputPItoWriter(org.w3c.dom.ProcessingInstruction currentPI)Normalizes a {@link org.w3c.dom.Comment} value
if (currentPI == null) {
return;
}
this._writer.write("<?");
String target = currentPI.getTarget();
int length = target.length();
for (int i = 0; i < length; i++) {
char c = target.charAt(i);
switch (c) {
case 0x0D:
this._writer.write("
");
break;
case ' ":
this._writer.write("·");
break;
case '\n":
this._writer.write("¶\n");
break;
default:
this._writer.write(c);
break;
}
}
String data = currentPI.getData();
length = data.length();
if ((data != null) && (length > 0)) {
this._writer.write(" ");
for (int i = 0; i < length; i++) {
char c = data.charAt(i);
switch (c) {
case 0x0D:
this._writer.write("
");
break;
default:
this._writer.write(c);
break;
}
}
}
this._writer.write("?>");
|
private void | outputTextToWriter(java.lang.String text)Method outputTextToWriter
if (text == null) {
return;
}
int length = text.length();
for (int i = 0; i < length; i++) {
char c = text.charAt(i);
switch (c) {
case '&":
this._writer.write("&");
break;
case '<":
this._writer.write("<");
break;
case '>":
this._writer.write(">");
break;
case 0xD:
this._writer.write("
");
break;
case ' ":
this._writer.write("·");
break;
case '\n":
this._writer.write("¶\n");
break;
default:
this._writer.write(c);
break;
}
}
|