nokogiri 1.11.0.rc3-java → 1.11.4-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/LICENSE-DEPENDENCIES.md +1015 -947
- data/LICENSE.md +1 -1
- data/README.md +168 -91
- data/dependencies.yml +12 -12
- data/ext/java/nokogiri/EncodingHandler.java +76 -89
- data/ext/java/nokogiri/HtmlDocument.java +135 -144
- data/ext/java/nokogiri/HtmlElementDescription.java +102 -117
- data/ext/java/nokogiri/HtmlEntityLookup.java +33 -60
- data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -222
- data/ext/java/nokogiri/HtmlSaxPushParser.java +162 -169
- data/ext/java/nokogiri/NokogiriService.java +595 -556
- data/ext/java/nokogiri/XmlAttr.java +118 -126
- data/ext/java/nokogiri/XmlAttributeDecl.java +95 -106
- data/ext/java/nokogiri/XmlCdata.java +35 -58
- data/ext/java/nokogiri/XmlComment.java +46 -67
- data/ext/java/nokogiri/XmlDocument.java +645 -572
- data/ext/java/nokogiri/XmlDocumentFragment.java +125 -137
- data/ext/java/nokogiri/XmlDtd.java +448 -414
- data/ext/java/nokogiri/XmlElement.java +23 -48
- data/ext/java/nokogiri/XmlElementContent.java +343 -316
- data/ext/java/nokogiri/XmlElementDecl.java +124 -125
- data/ext/java/nokogiri/XmlEntityDecl.java +119 -127
- data/ext/java/nokogiri/XmlEntityReference.java +49 -72
- data/ext/java/nokogiri/XmlNamespace.java +175 -175
- data/ext/java/nokogiri/XmlNode.java +1843 -1622
- data/ext/java/nokogiri/XmlNodeSet.java +361 -331
- data/ext/java/nokogiri/XmlProcessingInstruction.java +47 -69
- data/ext/java/nokogiri/XmlReader.java +513 -450
- data/ext/java/nokogiri/XmlRelaxng.java +89 -101
- data/ext/java/nokogiri/XmlSaxParserContext.java +328 -310
- data/ext/java/nokogiri/XmlSaxPushParser.java +227 -220
- data/ext/java/nokogiri/XmlSchema.java +335 -242
- data/ext/java/nokogiri/XmlSyntaxError.java +113 -119
- data/ext/java/nokogiri/XmlText.java +55 -76
- data/ext/java/nokogiri/XmlXpathContext.java +242 -210
- data/ext/java/nokogiri/XsltStylesheet.java +280 -269
- data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +201 -190
- data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
- data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
- data/ext/java/nokogiri/internals/NokogiriDomParser.java +63 -80
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +27 -52
- data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -286
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +736 -652
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +184 -173
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +79 -89
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +64 -79
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +84 -99
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +48 -65
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +119 -78
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -54
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +23 -46
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +55 -72
- data/ext/java/nokogiri/internals/ParserContext.java +206 -211
- data/ext/java/nokogiri/internals/ReaderNode.java +478 -403
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -739
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +31 -54
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +3 -34
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +206 -207
- data/ext/java/nokogiri/internals/XmlSaxParser.java +22 -47
- data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
- data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
- data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
- data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
- data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
- data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
- data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
- data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
- data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
- data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
- data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
- data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -574
- data/ext/nokogiri/depend +37 -358
- data/ext/nokogiri/extconf.rb +581 -374
- data/ext/nokogiri/html_document.c +78 -82
- data/ext/nokogiri/html_element_description.c +84 -71
- data/ext/nokogiri/html_entity_lookup.c +21 -16
- data/ext/nokogiri/html_sax_parser_context.c +69 -66
- data/ext/nokogiri/html_sax_push_parser.c +42 -34
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +192 -93
- data/ext/nokogiri/test_global_handlers.c +40 -0
- data/ext/nokogiri/xml_attr.c +15 -15
- data/ext/nokogiri/xml_attribute_decl.c +18 -18
- data/ext/nokogiri/xml_cdata.c +13 -18
- data/ext/nokogiri/xml_comment.c +19 -26
- data/ext/nokogiri/xml_document.c +246 -188
- data/ext/nokogiri/xml_document_fragment.c +13 -15
- data/ext/nokogiri/xml_dtd.c +54 -48
- data/ext/nokogiri/xml_element_content.c +30 -27
- data/ext/nokogiri/xml_element_decl.c +22 -22
- data/ext/nokogiri/xml_encoding_handler.c +17 -11
- data/ext/nokogiri/xml_entity_decl.c +32 -30
- data/ext/nokogiri/xml_entity_reference.c +16 -18
- data/ext/nokogiri/xml_namespace.c +56 -49
- data/ext/nokogiri/xml_node.c +371 -320
- data/ext/nokogiri/xml_node_set.c +168 -156
- data/ext/nokogiri/xml_processing_instruction.c +17 -19
- data/ext/nokogiri/xml_reader.c +191 -157
- data/ext/nokogiri/xml_relax_ng.c +52 -28
- data/ext/nokogiri/xml_sax_parser.c +118 -118
- data/ext/nokogiri/xml_sax_parser_context.c +103 -86
- data/ext/nokogiri/xml_sax_push_parser.c +36 -27
- data/ext/nokogiri/xml_schema.c +95 -47
- data/ext/nokogiri/xml_syntax_error.c +42 -21
- data/ext/nokogiri/xml_text.c +13 -17
- data/ext/nokogiri/xml_xpath_context.c +206 -123
- data/ext/nokogiri/xslt_stylesheet.c +158 -161
- data/lib/nokogiri.rb +3 -7
- data/lib/nokogiri/css/parser.rb +3 -3
- data/lib/nokogiri/css/parser.y +2 -2
- data/lib/nokogiri/css/xpath_visitor.rb +70 -42
- data/lib/nokogiri/extension.rb +26 -0
- data/lib/nokogiri/html/document.rb +12 -26
- data/lib/nokogiri/html/document_fragment.rb +15 -15
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +2 -149
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +205 -0
- data/lib/nokogiri/xml/document.rb +91 -35
- data/lib/nokogiri/xml/document_fragment.rb +4 -6
- data/lib/nokogiri/xml/node.rb +89 -69
- data/lib/nokogiri/xml/parse_options.rb +6 -0
- data/lib/nokogiri/xml/reader.rb +2 -9
- data/lib/nokogiri/xml/relax_ng.rb +6 -2
- data/lib/nokogiri/xml/schema.rb +12 -4
- data/lib/nokogiri/xml/searchable.rb +3 -1
- data/lib/nokogiri/xml/xpath.rb +1 -3
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
- metadata +86 -177
- data/ext/nokogiri/html_document.h +0 -10
- data/ext/nokogiri/html_element_description.h +0 -10
- data/ext/nokogiri/html_entity_lookup.h +0 -8
- data/ext/nokogiri/html_sax_parser_context.h +0 -11
- data/ext/nokogiri/html_sax_push_parser.h +0 -9
- data/ext/nokogiri/nokogiri.h +0 -134
- data/ext/nokogiri/xml_attr.h +0 -9
- data/ext/nokogiri/xml_attribute_decl.h +0 -9
- data/ext/nokogiri/xml_cdata.h +0 -9
- data/ext/nokogiri/xml_comment.h +0 -9
- data/ext/nokogiri/xml_document.h +0 -23
- data/ext/nokogiri/xml_document_fragment.h +0 -10
- data/ext/nokogiri/xml_dtd.h +0 -10
- data/ext/nokogiri/xml_element_content.h +0 -10
- data/ext/nokogiri/xml_element_decl.h +0 -9
- data/ext/nokogiri/xml_encoding_handler.h +0 -8
- data/ext/nokogiri/xml_entity_decl.h +0 -10
- data/ext/nokogiri/xml_entity_reference.h +0 -9
- data/ext/nokogiri/xml_io.c +0 -63
- data/ext/nokogiri/xml_io.h +0 -11
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
- data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
- data/ext/nokogiri/xml_namespace.h +0 -14
- data/ext/nokogiri/xml_node.h +0 -13
- data/ext/nokogiri/xml_node_set.h +0 -12
- data/ext/nokogiri/xml_processing_instruction.h +0 -9
- data/ext/nokogiri/xml_reader.h +0 -10
- data/ext/nokogiri/xml_relax_ng.h +0 -9
- data/ext/nokogiri/xml_sax_parser.h +0 -39
- data/ext/nokogiri/xml_sax_parser_context.h +0 -10
- data/ext/nokogiri/xml_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_schema.h +0 -9
- data/ext/nokogiri/xml_syntax_error.h +0 -13
- data/ext/nokogiri/xml_text.h +0 -9
- data/ext/nokogiri/xml_xpath_context.h +0 -10
- data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -19,22 +19,29 @@
|
|
19
19
|
package nokogiri.internals.c14n;
|
20
20
|
|
21
21
|
|
22
|
-
public class Canonicalizer20010315ExclOmitComments extends Canonicalizer20010315Excl
|
22
|
+
public class Canonicalizer20010315ExclOmitComments extends Canonicalizer20010315Excl
|
23
|
+
{
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
/**
|
26
|
+
*
|
27
|
+
*/
|
28
|
+
public
|
29
|
+
Canonicalizer20010315ExclOmitComments()
|
30
|
+
{
|
31
|
+
super(false);
|
32
|
+
}
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
/** @inheritDoc */
|
35
|
+
public final String
|
36
|
+
engineGetURI()
|
37
|
+
{
|
38
|
+
return Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS;
|
39
|
+
}
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
41
|
+
/** @inheritDoc */
|
42
|
+
public final boolean
|
43
|
+
engineGetIncludeComments()
|
44
|
+
{
|
45
|
+
return false;
|
46
|
+
}
|
40
47
|
}
|
@@ -22,23 +22,30 @@ package nokogiri.internals.c14n;
|
|
22
22
|
/**
|
23
23
|
* Class Canonicalizer20010315ExclWithComments
|
24
24
|
*/
|
25
|
-
public class Canonicalizer20010315ExclWithComments extends Canonicalizer20010315Excl
|
25
|
+
public class Canonicalizer20010315ExclWithComments extends Canonicalizer20010315Excl
|
26
|
+
{
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
/**
|
29
|
+
* Constructor Canonicalizer20010315ExclWithComments
|
30
|
+
*
|
31
|
+
*/
|
32
|
+
public
|
33
|
+
Canonicalizer20010315ExclWithComments()
|
34
|
+
{
|
35
|
+
super(true);
|
36
|
+
}
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
/** @inheritDoc */
|
39
|
+
public final String
|
40
|
+
engineGetURI()
|
41
|
+
{
|
42
|
+
return Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS;
|
43
|
+
}
|
39
44
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
45
|
+
/** @inheritDoc */
|
46
|
+
public final boolean
|
47
|
+
engineGetIncludeComments()
|
48
|
+
{
|
49
|
+
return true;
|
50
|
+
}
|
44
51
|
}
|
@@ -22,23 +22,30 @@ package nokogiri.internals.c14n;
|
|
22
22
|
/**
|
23
23
|
* @author Christian Geuer-Pollmann
|
24
24
|
*/
|
25
|
-
public class Canonicalizer20010315OmitComments extends Canonicalizer20010315
|
25
|
+
public class Canonicalizer20010315OmitComments extends Canonicalizer20010315
|
26
|
+
{
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
/**
|
29
|
+
* Constructor Canonicalizer20010315WithXPathOmitComments
|
30
|
+
*
|
31
|
+
*/
|
32
|
+
public
|
33
|
+
Canonicalizer20010315OmitComments()
|
34
|
+
{
|
35
|
+
super(false);
|
36
|
+
}
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
/** @inheritDoc */
|
39
|
+
public final String
|
40
|
+
engineGetURI()
|
41
|
+
{
|
42
|
+
return Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
|
43
|
+
}
|
39
44
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
45
|
+
/** @inheritDoc */
|
46
|
+
public final boolean
|
47
|
+
engineGetIncludeComments()
|
48
|
+
{
|
49
|
+
return false;
|
50
|
+
}
|
44
51
|
}
|
@@ -22,22 +22,29 @@ package nokogiri.internals.c14n;
|
|
22
22
|
/**
|
23
23
|
* @author Christian Geuer-Pollmann
|
24
24
|
*/
|
25
|
-
public class Canonicalizer20010315WithComments extends Canonicalizer20010315
|
25
|
+
public class Canonicalizer20010315WithComments extends Canonicalizer20010315
|
26
|
+
{
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
/**
|
29
|
+
* Constructor Canonicalizer20010315WithXPathWithComments
|
30
|
+
*/
|
31
|
+
public
|
32
|
+
Canonicalizer20010315WithComments()
|
33
|
+
{
|
34
|
+
super(true);
|
35
|
+
}
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
/** @inheritDoc */
|
38
|
+
public final String
|
39
|
+
engineGetURI()
|
40
|
+
{
|
41
|
+
return Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS;
|
42
|
+
}
|
38
43
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
/** @inheritDoc */
|
45
|
+
public final boolean
|
46
|
+
engineGetIncludeComments()
|
47
|
+
{
|
48
|
+
return true;
|
49
|
+
}
|
43
50
|
}
|
@@ -46,585 +46,615 @@ import org.w3c.dom.ProcessingInstruction;
|
|
46
46
|
*
|
47
47
|
* @author Christian Geuer-Pollmann <geuerp@apache.org>
|
48
48
|
*/
|
49
|
-
public abstract class CanonicalizerBase extends CanonicalizerSpi
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
private List<NodeFilter> nodeFilter;
|
86
|
-
|
87
|
-
private final boolean includeComments;
|
88
|
-
//private Set<Node> xpathNodeSet;
|
89
|
-
/**
|
90
|
-
* The node to be skipped/excluded from the DOM tree
|
91
|
-
* in subtree canonicalizations.
|
92
|
-
*/
|
93
|
-
private Node excludeNode;
|
94
|
-
private OutputStream writer = new ByteArrayOutputStream();
|
95
|
-
|
96
|
-
/**
|
97
|
-
* Constructor CanonicalizerBase
|
98
|
-
*
|
99
|
-
* @param includeComments
|
100
|
-
*/
|
101
|
-
public CanonicalizerBase(boolean includeComments) {
|
102
|
-
this.includeComments = includeComments;
|
49
|
+
public abstract class CanonicalizerBase extends CanonicalizerSpi
|
50
|
+
{
|
51
|
+
public static final String XML = "xml";
|
52
|
+
public static final String XMLNS = "xmlns";
|
53
|
+
|
54
|
+
protected static final AttrCompare COMPARE = new AttrCompare();
|
55
|
+
protected static final Attr nullNode;
|
56
|
+
|
57
|
+
private static final byte[] END_PI = {'?', '>'};
|
58
|
+
private static final byte[] BEGIN_PI = {'<', '?'};
|
59
|
+
private static final byte[] END_COMM = {'-', '-', '>'};
|
60
|
+
private static final byte[] BEGIN_COMM = {'<', '!', '-', '-'};
|
61
|
+
private static final byte[] XA = {'&', '#', 'x', 'A', ';'};
|
62
|
+
private static final byte[] X9 = {'&', '#', 'x', '9', ';'};
|
63
|
+
private static final byte[] QUOT = {'&', 'q', 'u', 'o', 't', ';'};
|
64
|
+
private static final byte[] XD = {'&', '#', 'x', 'D', ';'};
|
65
|
+
private static final byte[] GT = {'&', 'g', 't', ';'};
|
66
|
+
private static final byte[] LT = {'&', 'l', 't', ';'};
|
67
|
+
private static final byte[] END_TAG = {'<', '/'};
|
68
|
+
private static final byte[] AMP = {'&', 'a', 'm', 'p', ';'};
|
69
|
+
private static final byte[] equalsStr = {'=', '\"'};
|
70
|
+
|
71
|
+
protected static final int NODE_BEFORE_DOCUMENT_ELEMENT = -1;
|
72
|
+
protected static final int NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT = 0;
|
73
|
+
protected static final int NODE_AFTER_DOCUMENT_ELEMENT = 1;
|
74
|
+
|
75
|
+
static
|
76
|
+
{
|
77
|
+
// The null xmlns definition.
|
78
|
+
try {
|
79
|
+
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
80
|
+
nullNode = documentBuilder.newDocument().createAttributeNS(Constants.NamespaceSpecNS, XMLNS);
|
81
|
+
nullNode.setValue("");
|
82
|
+
} catch (Exception e) {
|
83
|
+
throw new RuntimeException("Unable to create nullNode: " + e);
|
103
84
|
}
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
85
|
+
}
|
86
|
+
|
87
|
+
private List<NodeFilter> nodeFilter;
|
88
|
+
|
89
|
+
private final boolean includeComments;
|
90
|
+
//private Set<Node> xpathNodeSet;
|
91
|
+
/**
|
92
|
+
* The node to be skipped/excluded from the DOM tree
|
93
|
+
* in subtree canonicalizations.
|
94
|
+
*/
|
95
|
+
private Node excludeNode;
|
96
|
+
private OutputStream writer = new ByteArrayOutputStream();
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Constructor CanonicalizerBase
|
100
|
+
*
|
101
|
+
* @param includeComments
|
102
|
+
*/
|
103
|
+
public
|
104
|
+
CanonicalizerBase(boolean includeComments)
|
105
|
+
{
|
106
|
+
this.includeComments = includeComments;
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Method engineCanonicalizeSubTree
|
111
|
+
* @inheritDoc
|
112
|
+
* @param rootNode
|
113
|
+
* @throws CanonicalizationException
|
114
|
+
*/
|
115
|
+
@Override
|
116
|
+
public byte[]
|
117
|
+
engineCanonicalizeSubTree(Node rootNode, CanonicalFilter filter)
|
118
|
+
throws CanonicalizationException
|
119
|
+
{
|
120
|
+
return engineCanonicalizeSubTree(rootNode, (Node)null, filter);
|
121
|
+
}
|
122
|
+
|
123
|
+
/**
|
124
|
+
* @param writer The writer to set.
|
125
|
+
*/
|
126
|
+
@Override
|
127
|
+
public void
|
128
|
+
setWriter(OutputStream writer)
|
129
|
+
{
|
130
|
+
this.writer = writer;
|
131
|
+
}
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Canonicalizes a Subtree node.
|
135
|
+
*
|
136
|
+
* @param rootNode
|
137
|
+
* the root of the subtree to canonicalize
|
138
|
+
* @param excludeNode
|
139
|
+
* a node to be excluded from the canonicalize operation
|
140
|
+
* @return The canonicalize stream.
|
141
|
+
* @throws CanonicalizationException
|
142
|
+
*/
|
143
|
+
protected byte[]
|
144
|
+
engineCanonicalizeSubTree(Node rootNode, Node excludeNode, CanonicalFilter filter)
|
145
|
+
throws CanonicalizationException
|
146
|
+
{
|
147
|
+
this.excludeNode = excludeNode;
|
148
|
+
try {
|
149
|
+
NameSpaceSymbTable ns = new NameSpaceSymbTable();
|
150
|
+
int nodeLevel = NODE_BEFORE_DOCUMENT_ELEMENT;
|
151
|
+
if (rootNode != null && Node.ELEMENT_NODE == rootNode.getNodeType()) {
|
152
|
+
//Fills the nssymbtable with the definitions of the parent of the root subnode
|
153
|
+
getParentNameSpaces((Element)rootNode, ns);
|
154
|
+
nodeLevel = NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
|
155
|
+
}
|
156
|
+
this.canonicalizeSubTree(rootNode, ns, rootNode, nodeLevel, filter);
|
157
|
+
this.writer.flush();
|
158
|
+
if (this.writer instanceof ByteArrayOutputStream) {
|
159
|
+
byte[] result = ((ByteArrayOutputStream)this.writer).toByteArray();
|
160
|
+
if (reset) {
|
161
|
+
((ByteArrayOutputStream)this.writer).reset();
|
162
|
+
} else {
|
163
|
+
this.writer.close();
|
164
|
+
}
|
165
|
+
return result;
|
166
|
+
} else {
|
167
|
+
this.writer.close();
|
168
|
+
}
|
169
|
+
return null;
|
170
|
+
|
171
|
+
} catch (UnsupportedEncodingException ex) {
|
172
|
+
throw new CanonicalizationException("empty", ex);
|
173
|
+
} catch (IOException ex) {
|
174
|
+
throw new CanonicalizationException("empty", ex);
|
115
175
|
}
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
176
|
+
}
|
177
|
+
|
178
|
+
|
179
|
+
/**
|
180
|
+
* Method canonicalizeSubTree, this function is a recursive one.
|
181
|
+
*
|
182
|
+
* @param currentNode
|
183
|
+
* @param ns
|
184
|
+
* @param endnode
|
185
|
+
* @throws CanonicalizationException
|
186
|
+
* @throws IOException
|
187
|
+
*/
|
188
|
+
protected final void
|
189
|
+
canonicalizeSubTree(
|
190
|
+
Node currentNode, NameSpaceSymbTable ns, Node endnode, int documentLevel, CanonicalFilter filter
|
191
|
+
) throws CanonicalizationException, IOException
|
192
|
+
{
|
193
|
+
if (isVisibleInt(currentNode) == -1) {
|
194
|
+
return;
|
123
195
|
}
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
if (this.writer instanceof ByteArrayOutputStream) {
|
149
|
-
byte[] result = ((ByteArrayOutputStream)this.writer).toByteArray();
|
150
|
-
if (reset) {
|
151
|
-
((ByteArrayOutputStream)this.writer).reset();
|
152
|
-
} else {
|
153
|
-
this.writer.close();
|
154
|
-
}
|
155
|
-
return result;
|
156
|
-
} else {
|
157
|
-
this.writer.close();
|
158
|
-
}
|
159
|
-
return null;
|
160
|
-
|
161
|
-
} catch (UnsupportedEncodingException ex) {
|
162
|
-
throw new CanonicalizationException("empty", ex);
|
163
|
-
} catch (IOException ex) {
|
164
|
-
throw new CanonicalizationException("empty", ex);
|
196
|
+
Node sibling = null;
|
197
|
+
Node parentNode = null;
|
198
|
+
final OutputStream writer = this.writer;
|
199
|
+
final Node excludeNode = this.excludeNode;
|
200
|
+
final boolean includeComments = this.includeComments;
|
201
|
+
Map<String, byte[]> cache = new HashMap<String, byte[]>();
|
202
|
+
do {
|
203
|
+
switch (currentNode.getNodeType()) {
|
204
|
+
|
205
|
+
case Node.ENTITY_NODE :
|
206
|
+
case Node.NOTATION_NODE :
|
207
|
+
case Node.ATTRIBUTE_NODE :
|
208
|
+
// illegal node type during traversal
|
209
|
+
throw new CanonicalizationException("empty");
|
210
|
+
|
211
|
+
case Node.DOCUMENT_FRAGMENT_NODE :
|
212
|
+
case Node.DOCUMENT_NODE :
|
213
|
+
ns.outputNodePush();
|
214
|
+
sibling = currentNode.getFirstChild();
|
215
|
+
break;
|
216
|
+
|
217
|
+
case Node.COMMENT_NODE :
|
218
|
+
if (includeComments) {
|
219
|
+
outputCommentToWriter((Comment) currentNode, writer, documentLevel);
|
165
220
|
}
|
166
|
-
|
221
|
+
break;
|
167
222
|
|
223
|
+
case Node.PROCESSING_INSTRUCTION_NODE :
|
224
|
+
outputPItoWriter((ProcessingInstruction) currentNode, writer, documentLevel);
|
225
|
+
break;
|
168
226
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
* @param ns
|
174
|
-
* @param endnode
|
175
|
-
* @throws CanonicalizationException
|
176
|
-
* @throws IOException
|
177
|
-
*/
|
178
|
-
protected final void canonicalizeSubTree(
|
179
|
-
Node currentNode, NameSpaceSymbTable ns, Node endnode, int documentLevel, CanonicalFilter filter
|
180
|
-
) throws CanonicalizationException, IOException {
|
181
|
-
if (isVisibleInt(currentNode) == -1) {
|
182
|
-
return;
|
183
|
-
}
|
184
|
-
Node sibling = null;
|
185
|
-
Node parentNode = null;
|
186
|
-
final OutputStream writer = this.writer;
|
187
|
-
final Node excludeNode = this.excludeNode;
|
188
|
-
final boolean includeComments = this.includeComments;
|
189
|
-
Map<String, byte[]> cache = new HashMap<String, byte[]>();
|
190
|
-
do {
|
191
|
-
switch (currentNode.getNodeType()) {
|
192
|
-
|
193
|
-
case Node.ENTITY_NODE :
|
194
|
-
case Node.NOTATION_NODE :
|
195
|
-
case Node.ATTRIBUTE_NODE :
|
196
|
-
// illegal node type during traversal
|
197
|
-
throw new CanonicalizationException("empty");
|
198
|
-
|
199
|
-
case Node.DOCUMENT_FRAGMENT_NODE :
|
200
|
-
case Node.DOCUMENT_NODE :
|
201
|
-
ns.outputNodePush();
|
202
|
-
sibling = currentNode.getFirstChild();
|
203
|
-
break;
|
204
|
-
|
205
|
-
case Node.COMMENT_NODE :
|
206
|
-
if (includeComments) {
|
207
|
-
outputCommentToWriter((Comment) currentNode, writer, documentLevel);
|
208
|
-
}
|
209
|
-
break;
|
210
|
-
|
211
|
-
case Node.PROCESSING_INSTRUCTION_NODE :
|
212
|
-
outputPItoWriter((ProcessingInstruction) currentNode, writer, documentLevel);
|
213
|
-
break;
|
214
|
-
|
215
|
-
case Node.TEXT_NODE :
|
216
|
-
case Node.CDATA_SECTION_NODE :
|
217
|
-
outputTextToWriter(currentNode.getNodeValue(), writer);
|
218
|
-
break;
|
219
|
-
|
220
|
-
case Node.ELEMENT_NODE :
|
221
|
-
documentLevel = NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
|
222
|
-
if (currentNode == excludeNode) {
|
223
|
-
break;
|
224
|
-
}
|
225
|
-
if (filter != null && !filter.includeNodes(currentNode, parentNode)) {
|
226
|
-
break;
|
227
|
-
}
|
228
|
-
|
229
|
-
Element currentElement = (Element)currentNode;
|
230
|
-
//Add a level to the nssymbtable. So latter can be pop-back.
|
231
|
-
ns.outputNodePush();
|
232
|
-
writer.write('<');
|
233
|
-
String name = currentElement.getTagName();
|
234
|
-
UtfHelpper.writeByte(name, writer, cache);
|
235
|
-
|
236
|
-
Iterator<Attr> attrs = this.handleAttributesSubtree(currentElement, ns);
|
237
|
-
if (attrs != null) {
|
238
|
-
//we output all Attrs which are available
|
239
|
-
while (attrs.hasNext()) {
|
240
|
-
Attr attr = attrs.next();
|
241
|
-
outputAttrToWriter(attr.getNodeName(), attr.getNodeValue(), writer, cache);
|
242
|
-
}
|
243
|
-
}
|
244
|
-
writer.write('>');
|
245
|
-
sibling = currentNode.getFirstChild();
|
246
|
-
if (sibling == null) {
|
247
|
-
writer.write(END_TAG);
|
248
|
-
UtfHelpper.writeStringToUtf8(name, writer);
|
249
|
-
writer.write('>');
|
250
|
-
//We finished with this level, pop to the previous definitions.
|
251
|
-
ns.outputNodePop();
|
252
|
-
if (parentNode != null) {
|
253
|
-
sibling = currentNode.getNextSibling();
|
254
|
-
}
|
255
|
-
} else {
|
256
|
-
parentNode = currentElement;
|
257
|
-
}
|
258
|
-
break;
|
259
|
-
case Node.DOCUMENT_TYPE_NODE :
|
260
|
-
default :
|
261
|
-
break;
|
262
|
-
}
|
263
|
-
while (sibling == null && parentNode != null) {
|
264
|
-
writer.write(END_TAG);
|
265
|
-
UtfHelpper.writeByte(((Element)parentNode).getTagName(), writer, cache);
|
266
|
-
writer.write('>');
|
267
|
-
//We finished with this level, pop to the previous definitions.
|
268
|
-
ns.outputNodePop();
|
269
|
-
if (parentNode == endnode) {
|
270
|
-
return;
|
271
|
-
}
|
272
|
-
sibling = parentNode.getNextSibling();
|
273
|
-
parentNode = parentNode.getParentNode();
|
274
|
-
if (parentNode == null || Node.ELEMENT_NODE != parentNode.getNodeType()) {
|
275
|
-
documentLevel = NODE_AFTER_DOCUMENT_ELEMENT;
|
276
|
-
parentNode = null;
|
277
|
-
}
|
278
|
-
}
|
279
|
-
if (sibling == null) {
|
280
|
-
return;
|
281
|
-
}
|
282
|
-
currentNode = sibling;
|
283
|
-
sibling = currentNode.getNextSibling();
|
284
|
-
} while(true);
|
285
|
-
}
|
227
|
+
case Node.TEXT_NODE :
|
228
|
+
case Node.CDATA_SECTION_NODE :
|
229
|
+
outputTextToWriter(currentNode.getNodeValue(), writer);
|
230
|
+
break;
|
286
231
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
int i = (it.next()).isNodeIncludeDO(currentNode, level);
|
292
|
-
if (i != 1) {
|
293
|
-
return i;
|
294
|
-
}
|
295
|
-
}
|
232
|
+
case Node.ELEMENT_NODE :
|
233
|
+
documentLevel = NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
|
234
|
+
if (currentNode == excludeNode) {
|
235
|
+
break;
|
296
236
|
}
|
297
|
-
|
298
|
-
|
299
|
-
//}
|
300
|
-
return 1;
|
301
|
-
}
|
302
|
-
|
303
|
-
protected int isVisibleInt(Node currentNode) {
|
304
|
-
if (nodeFilter != null) {
|
305
|
-
Iterator<NodeFilter> it = nodeFilter.iterator();
|
306
|
-
while (it.hasNext()) {
|
307
|
-
int i = (it.next()).isNodeInclude(currentNode);
|
308
|
-
if (i != 1) {
|
309
|
-
return i;
|
310
|
-
}
|
311
|
-
}
|
237
|
+
if (filter != null && !filter.includeNodes(currentNode, parentNode)) {
|
238
|
+
break;
|
312
239
|
}
|
313
|
-
//if ((this.xpathNodeSet != null) && !this.xpathNodeSet.contains(currentNode)) {
|
314
|
-
// return 0;
|
315
|
-
//}
|
316
|
-
return 1;
|
317
|
-
}
|
318
240
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
}
|
326
|
-
}
|
327
|
-
}
|
328
|
-
//if ((this.xpathNodeSet != null) && !this.xpathNodeSet.contains(currentNode)) {
|
329
|
-
// return false;
|
330
|
-
//}
|
331
|
-
return true;
|
332
|
-
}
|
241
|
+
Element currentElement = (Element)currentNode;
|
242
|
+
//Add a level to the nssymbtable. So latter can be pop-back.
|
243
|
+
ns.outputNodePush();
|
244
|
+
writer.write('<');
|
245
|
+
String name = currentElement.getTagName();
|
246
|
+
UtfHelpper.writeByte(name, writer, cache);
|
333
247
|
|
334
|
-
|
335
|
-
if (
|
336
|
-
|
248
|
+
Iterator<Attr> attrs = this.handleAttributesSubtree(currentElement, ns);
|
249
|
+
if (attrs != null) {
|
250
|
+
//we output all Attrs which are available
|
251
|
+
while (attrs.hasNext()) {
|
252
|
+
Attr attr = attrs.next();
|
253
|
+
outputAttrToWriter(attr.getNodeName(), attr.getNodeValue(), writer, cache);
|
254
|
+
}
|
337
255
|
}
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
256
|
+
writer.write('>');
|
257
|
+
sibling = currentNode.getFirstChild();
|
258
|
+
if (sibling == null) {
|
259
|
+
writer.write(END_TAG);
|
260
|
+
UtfHelpper.writeStringToUtf8(name, writer);
|
261
|
+
writer.write('>');
|
262
|
+
//We finished with this level, pop to the previous definitions.
|
263
|
+
ns.outputNodePop();
|
264
|
+
if (parentNode != null) {
|
265
|
+
sibling = currentNode.getNextSibling();
|
266
|
+
}
|
267
|
+
} else {
|
268
|
+
parentNode = currentElement;
|
349
269
|
}
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
270
|
+
break;
|
271
|
+
case Node.DOCUMENT_TYPE_NODE :
|
272
|
+
default :
|
273
|
+
break;
|
274
|
+
}
|
275
|
+
while (sibling == null && parentNode != null) {
|
276
|
+
writer.write(END_TAG);
|
277
|
+
UtfHelpper.writeByte(((Element)parentNode).getTagName(), writer, cache);
|
278
|
+
writer.write('>');
|
279
|
+
//We finished with this level, pop to the previous definitions.
|
280
|
+
ns.outputNodePop();
|
281
|
+
if (parentNode == endnode) {
|
282
|
+
return;
|
363
283
|
}
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
* @param ns
|
370
|
-
*/
|
371
|
-
protected final void getParentNameSpaces(Element el, NameSpaceSymbTable ns) {
|
372
|
-
Node n1 = el.getParentNode();
|
373
|
-
if (n1 == null || Node.ELEMENT_NODE != n1.getNodeType()) {
|
374
|
-
return;
|
284
|
+
sibling = parentNode.getNextSibling();
|
285
|
+
parentNode = parentNode.getParentNode();
|
286
|
+
if (parentNode == null || Node.ELEMENT_NODE != parentNode.getNodeType()) {
|
287
|
+
documentLevel = NODE_AFTER_DOCUMENT_ELEMENT;
|
288
|
+
parentNode = null;
|
375
289
|
}
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
290
|
+
}
|
291
|
+
if (sibling == null) {
|
292
|
+
return;
|
293
|
+
}
|
294
|
+
currentNode = sibling;
|
295
|
+
sibling = currentNode.getNextSibling();
|
296
|
+
} while (true);
|
297
|
+
}
|
298
|
+
|
299
|
+
protected int
|
300
|
+
isVisibleDO(Node currentNode, int level)
|
301
|
+
{
|
302
|
+
if (nodeFilter != null) {
|
303
|
+
Iterator<NodeFilter> it = nodeFilter.iterator();
|
304
|
+
while (it.hasNext()) {
|
305
|
+
int i = (it.next()).isNodeIncludeDO(currentNode, level);
|
306
|
+
if (i != 1) {
|
307
|
+
return i;
|
382
308
|
}
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
309
|
+
}
|
310
|
+
}
|
311
|
+
//if ((this.xpathNodeSet != null) && !this.xpathNodeSet.contains(currentNode)) {
|
312
|
+
// return 0;
|
313
|
+
//}
|
314
|
+
return 1;
|
315
|
+
}
|
316
|
+
|
317
|
+
protected int
|
318
|
+
isVisibleInt(Node currentNode)
|
319
|
+
{
|
320
|
+
if (nodeFilter != null) {
|
321
|
+
Iterator<NodeFilter> it = nodeFilter.iterator();
|
322
|
+
while (it.hasNext()) {
|
323
|
+
int i = (it.next()).isNodeInclude(currentNode);
|
324
|
+
if (i != 1) {
|
325
|
+
return i;
|
388
326
|
}
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
327
|
+
}
|
328
|
+
}
|
329
|
+
//if ((this.xpathNodeSet != null) && !this.xpathNodeSet.contains(currentNode)) {
|
330
|
+
// return 0;
|
331
|
+
//}
|
332
|
+
return 1;
|
333
|
+
}
|
334
|
+
|
335
|
+
protected boolean
|
336
|
+
isVisible(Node currentNode)
|
337
|
+
{
|
338
|
+
if (nodeFilter != null) {
|
339
|
+
Iterator<NodeFilter> it = nodeFilter.iterator();
|
340
|
+
while (it.hasNext()) {
|
341
|
+
if (it.next().isNodeInclude(currentNode) != 1) {
|
342
|
+
return false;
|
394
343
|
}
|
344
|
+
}
|
395
345
|
}
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
346
|
+
//if ((this.xpathNodeSet != null) && !this.xpathNodeSet.contains(currentNode)) {
|
347
|
+
// return false;
|
348
|
+
//}
|
349
|
+
return true;
|
350
|
+
}
|
351
|
+
|
352
|
+
protected void
|
353
|
+
handleParent(Element e, NameSpaceSymbTable ns)
|
354
|
+
{
|
355
|
+
if (!e.hasAttributes() && e.getNamespaceURI() == null) {
|
356
|
+
return;
|
357
|
+
}
|
358
|
+
NamedNodeMap attrs = e.getAttributes();
|
359
|
+
int attrsLength = attrs.getLength();
|
360
|
+
for (int i = 0; i < attrsLength; i++) {
|
361
|
+
Attr attribute = (Attr) attrs.item(i);
|
362
|
+
String NName = attribute.getLocalName();
|
363
|
+
String NValue = attribute.getNodeValue();
|
364
|
+
|
365
|
+
if (Constants.NamespaceSpecNS.equals(attribute.getNamespaceURI())
|
366
|
+
&& (!XML.equals(NName) || !Constants.XML_LANG_SPACE_SpecNS.equals(NValue))) {
|
367
|
+
ns.addMapping(NName, NValue, attribute);
|
368
|
+
}
|
369
|
+
}
|
370
|
+
if (e.getNamespaceURI() != null) {
|
371
|
+
String NName = e.getPrefix();
|
372
|
+
String NValue = e.getNamespaceURI();
|
373
|
+
String Name;
|
374
|
+
if (NName == null || NName.equals("")) {
|
375
|
+
NName = XMLNS;
|
376
|
+
Name = XMLNS;
|
377
|
+
} else {
|
378
|
+
Name = XMLNS + ":" + NName;
|
379
|
+
}
|
380
|
+
Attr n = e.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", Name);
|
381
|
+
n.setValue(NValue);
|
382
|
+
ns.addMapping(NName, NValue, n);
|
383
|
+
}
|
384
|
+
}
|
385
|
+
|
386
|
+
/**
|
387
|
+
* Adds to ns the definitions from the parent elements of el
|
388
|
+
* @param el
|
389
|
+
* @param ns
|
390
|
+
*/
|
391
|
+
protected final void
|
392
|
+
getParentNameSpaces(Element el, NameSpaceSymbTable ns)
|
393
|
+
{
|
394
|
+
Node n1 = el.getParentNode();
|
395
|
+
if (n1 == null || Node.ELEMENT_NODE != n1.getNodeType()) {
|
396
|
+
return;
|
397
|
+
}
|
398
|
+
//Obtain all the parents of the element
|
399
|
+
List<Element> parents = new ArrayList<Element>();
|
400
|
+
Node parent = n1;
|
401
|
+
while (parent != null && Node.ELEMENT_NODE == parent.getNodeType()) {
|
402
|
+
parents.add((Element)parent);
|
403
|
+
parent = parent.getParentNode();
|
404
|
+
}
|
405
|
+
//Visit them in reverse order.
|
406
|
+
ListIterator<Element> it = parents.listIterator(parents.size());
|
407
|
+
while (it.hasPrevious()) {
|
408
|
+
Element ele = it.previous();
|
409
|
+
handleParent(ele, ns);
|
410
|
+
}
|
411
|
+
parents.clear();
|
412
|
+
Attr nsprefix;
|
413
|
+
if (((nsprefix = ns.getMappingWithoutRendered(XMLNS)) != null)
|
414
|
+
&& "".equals(nsprefix.getValue())) {
|
415
|
+
ns.addMappingAndRender(XMLNS, "", nullNode);
|
416
|
+
}
|
417
|
+
}
|
418
|
+
|
419
|
+
/**
|
420
|
+
* Obtain the attributes to output for this node in XPathNodeSet c14n.
|
421
|
+
*
|
422
|
+
* @param element
|
423
|
+
* @param ns
|
424
|
+
* @return the attributes nodes to output.
|
425
|
+
* @throws CanonicalizationException
|
426
|
+
*/
|
427
|
+
abstract Iterator<Attr> handleAttributes(Element element, NameSpaceSymbTable ns)
|
428
|
+
throws CanonicalizationException;
|
429
|
+
|
430
|
+
/**
|
431
|
+
* Obtain the attributes to output for this node in a Subtree c14n.
|
432
|
+
*
|
433
|
+
* @param element
|
434
|
+
* @param ns
|
435
|
+
* @return the attributes nodes to output.
|
436
|
+
* @throws CanonicalizationException
|
437
|
+
*/
|
438
|
+
abstract Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
|
439
|
+
throws CanonicalizationException;
|
440
|
+
|
441
|
+
//abstract void circumventBugIfNeeded(XMLSignatureInput input)
|
442
|
+
// throws CanonicalizationException, ParserConfigurationException, IOException, SAXException;
|
443
|
+
|
444
|
+
/**
|
445
|
+
* Outputs an Attribute to the internal Writer.
|
446
|
+
*
|
447
|
+
* The string value of the node is modified by replacing
|
448
|
+
* <UL>
|
449
|
+
* <LI>all ampersands (&) with <CODE>&amp;</CODE></LI>
|
450
|
+
* <LI>all open angle brackets (<) with <CODE>&lt;</CODE></LI>
|
451
|
+
* <LI>all quotation mark characters with <CODE>&quot;</CODE></LI>
|
452
|
+
* <LI>and the whitespace characters <CODE>#x9</CODE>, #xA, and #xD, with character
|
453
|
+
* references. The character references are written in uppercase
|
454
|
+
* hexadecimal with no leading zeroes (for example, <CODE>#xD</CODE> is represented
|
455
|
+
* by the character reference <CODE>&#xD;</CODE>)</LI>
|
456
|
+
* </UL>
|
457
|
+
*
|
458
|
+
* @param name
|
459
|
+
* @param value
|
460
|
+
* @param writer
|
461
|
+
* @throws IOException
|
462
|
+
*/
|
463
|
+
protected static final void
|
464
|
+
outputAttrToWriter(
|
465
|
+
final String name, final String value,
|
466
|
+
final OutputStream writer, final Map<String, byte[]> cache
|
467
|
+
) throws IOException
|
468
|
+
{
|
469
|
+
writer.write(' ');
|
470
|
+
UtfHelpper.writeByte(name, writer, cache);
|
471
|
+
writer.write(equalsStr);
|
472
|
+
byte[] toWrite;
|
473
|
+
final int length = value.length();
|
474
|
+
int i = 0;
|
475
|
+
while (i < length) {
|
476
|
+
char c = value.charAt(i++);
|
477
|
+
|
478
|
+
switch (c) {
|
479
|
+
|
480
|
+
case '&' :
|
481
|
+
toWrite = AMP;
|
482
|
+
break;
|
483
|
+
|
484
|
+
case '<' :
|
485
|
+
toWrite = LT;
|
486
|
+
break;
|
487
|
+
|
488
|
+
case '"' :
|
489
|
+
toWrite = QUOT;
|
490
|
+
break;
|
491
|
+
|
492
|
+
case 0x09 : // '\t'
|
493
|
+
toWrite = X9;
|
494
|
+
break;
|
495
|
+
|
496
|
+
case 0x0A : // '\n'
|
497
|
+
toWrite = XA;
|
498
|
+
break;
|
499
|
+
|
500
|
+
case 0x0D : // '\r'
|
501
|
+
toWrite = XD;
|
502
|
+
break;
|
503
|
+
|
504
|
+
default :
|
505
|
+
if (c < 0x80) {
|
506
|
+
writer.write(c);
|
507
|
+
} else {
|
508
|
+
UtfHelpper.writeCharToUtf8(c, writer);
|
489
509
|
}
|
490
|
-
|
491
|
-
|
510
|
+
continue;
|
511
|
+
}
|
512
|
+
writer.write(toWrite);
|
492
513
|
}
|
493
514
|
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
515
|
+
writer.write('\"');
|
516
|
+
}
|
517
|
+
|
518
|
+
/**
|
519
|
+
* Outputs a PI to the internal Writer.
|
520
|
+
*
|
521
|
+
* @param currentPI
|
522
|
+
* @param writer where to write the things
|
523
|
+
* @throws IOException
|
524
|
+
*/
|
525
|
+
protected void
|
526
|
+
outputPItoWriter(
|
527
|
+
ProcessingInstruction currentPI, OutputStream writer, int position
|
528
|
+
) throws IOException
|
529
|
+
{
|
530
|
+
if (position == NODE_AFTER_DOCUMENT_ELEMENT) {
|
531
|
+
writer.write('\n');
|
532
|
+
}
|
533
|
+
writer.write(BEGIN_PI);
|
534
|
+
|
535
|
+
final String target = currentPI.getTarget();
|
536
|
+
int length = target.length();
|
537
|
+
|
538
|
+
for (int i = 0; i < length; i++) {
|
539
|
+
char c = target.charAt(i);
|
540
|
+
if (c == 0x0D) {
|
541
|
+
writer.write(XD);
|
542
|
+
} else {
|
543
|
+
if (c < 0x80) {
|
544
|
+
writer.write(c);
|
545
|
+
} else {
|
546
|
+
UtfHelpper.writeCharToUtf8(c, writer);
|
523
547
|
}
|
548
|
+
}
|
549
|
+
}
|
524
550
|
|
525
|
-
|
551
|
+
final String data = currentPI.getData();
|
526
552
|
|
527
|
-
|
553
|
+
length = data.length();
|
528
554
|
|
529
|
-
|
530
|
-
|
555
|
+
if (length > 0) {
|
556
|
+
writer.write(' ');
|
531
557
|
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
}
|
539
|
-
}
|
540
|
-
}
|
541
|
-
|
542
|
-
writer.write(END_PI);
|
543
|
-
if (position == NODE_BEFORE_DOCUMENT_ELEMENT) {
|
544
|
-
writer.write('\n');
|
558
|
+
for (int i = 0; i < length; i++) {
|
559
|
+
char c = data.charAt(i);
|
560
|
+
if (c == 0x0D) {
|
561
|
+
writer.write(XD);
|
562
|
+
} else {
|
563
|
+
UtfHelpper.writeCharToUtf8(c, writer);
|
545
564
|
}
|
565
|
+
}
|
546
566
|
}
|
547
567
|
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
568
|
+
writer.write(END_PI);
|
569
|
+
if (position == NODE_BEFORE_DOCUMENT_ELEMENT) {
|
570
|
+
writer.write('\n');
|
571
|
+
}
|
572
|
+
}
|
573
|
+
|
574
|
+
/**
|
575
|
+
* Method outputCommentToWriter
|
576
|
+
*
|
577
|
+
* @param currentComment
|
578
|
+
* @param writer writer where to write the things
|
579
|
+
* @throws IOException
|
580
|
+
*/
|
581
|
+
protected void
|
582
|
+
outputCommentToWriter(
|
583
|
+
Comment currentComment, OutputStream writer, int position
|
584
|
+
) throws IOException
|
585
|
+
{
|
586
|
+
if (position == NODE_AFTER_DOCUMENT_ELEMENT) {
|
587
|
+
writer.write('\n');
|
588
|
+
}
|
589
|
+
writer.write(BEGIN_COMM);
|
590
|
+
|
591
|
+
final String data = currentComment.getData();
|
592
|
+
final int length = data.length();
|
593
|
+
|
594
|
+
for (int i = 0; i < length; i++) {
|
595
|
+
char c = data.charAt(i);
|
596
|
+
if (c == 0x0D) {
|
597
|
+
writer.write(XD);
|
598
|
+
} else {
|
599
|
+
if (c < 0x80) {
|
600
|
+
writer.write(c);
|
601
|
+
} else {
|
602
|
+
UtfHelpper.writeCharToUtf8(c, writer);
|
582
603
|
}
|
604
|
+
}
|
583
605
|
}
|
584
606
|
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
607
|
+
writer.write(END_COMM);
|
608
|
+
if (position == NODE_BEFORE_DOCUMENT_ELEMENT) {
|
609
|
+
writer.write('\n');
|
610
|
+
}
|
611
|
+
}
|
612
|
+
|
613
|
+
/**
|
614
|
+
* Outputs a Text of CDATA section to the internal Writer.
|
615
|
+
*
|
616
|
+
* @param text
|
617
|
+
* @param writer writer where to write the things
|
618
|
+
* @throws IOException
|
619
|
+
*/
|
620
|
+
protected static final void
|
621
|
+
outputTextToWriter(
|
622
|
+
final String text, final OutputStream writer
|
623
|
+
) throws IOException
|
624
|
+
{
|
625
|
+
final int length = text.length();
|
626
|
+
byte[] toWrite;
|
627
|
+
for (int i = 0; i < length; i++) {
|
628
|
+
char c = text.charAt(i);
|
629
|
+
|
630
|
+
switch (c) {
|
631
|
+
|
632
|
+
case '&' :
|
633
|
+
toWrite = AMP;
|
634
|
+
break;
|
635
|
+
|
636
|
+
case '<' :
|
637
|
+
toWrite = LT;
|
638
|
+
break;
|
639
|
+
|
640
|
+
case '>' :
|
641
|
+
toWrite = GT;
|
642
|
+
break;
|
643
|
+
|
644
|
+
case 0xD :
|
645
|
+
toWrite = XD;
|
646
|
+
break;
|
647
|
+
|
648
|
+
default :
|
649
|
+
if (c < 0x80) {
|
650
|
+
writer.write(c);
|
651
|
+
} else {
|
652
|
+
UtfHelpper.writeCharToUtf8(c, writer);
|
627
653
|
}
|
654
|
+
continue;
|
655
|
+
}
|
656
|
+
writer.write(toWrite);
|
628
657
|
}
|
658
|
+
}
|
629
659
|
|
630
660
|
}
|