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
@@ -43,131 +43,152 @@ import org.w3c.dom.ProcessingInstruction;
|
|
43
43
|
* because the decrypted XML content will share the same physical representation
|
44
44
|
* as the original XML content that was encrypted.
|
45
45
|
*/
|
46
|
-
public class CanonicalizerPhysical extends CanonicalizerBase
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
46
|
+
public class CanonicalizerPhysical extends CanonicalizerBase
|
47
|
+
{
|
48
|
+
|
49
|
+
private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Constructor Canonicalizer20010315
|
53
|
+
*/
|
54
|
+
public
|
55
|
+
CanonicalizerPhysical()
|
56
|
+
{
|
57
|
+
super(true);
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Always throws a CanonicalizationException.
|
62
|
+
*
|
63
|
+
* @param xpathNodeSet
|
64
|
+
* @param inclusiveNamespaces
|
65
|
+
* @return none it always fails
|
66
|
+
* @throws CanonicalizationException always
|
67
|
+
*/
|
68
|
+
public byte[]
|
69
|
+
engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces, CanonicalFilter filter)
|
70
|
+
throws CanonicalizationException
|
71
|
+
{
|
72
|
+
|
73
|
+
/** $todo$ well, should we throw UnsupportedOperationException ? */
|
74
|
+
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
|
75
|
+
}
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Always throws a CanonicalizationException.
|
79
|
+
*
|
80
|
+
* @param rootNode
|
81
|
+
* @param inclusiveNamespaces
|
82
|
+
* @return none it always fails
|
83
|
+
* @throws CanonicalizationException
|
84
|
+
*/
|
85
|
+
@Override
|
86
|
+
public byte[]
|
87
|
+
engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces, CanonicalFilter filter)
|
88
|
+
throws CanonicalizationException
|
89
|
+
{
|
90
|
+
|
91
|
+
/** $todo$ well, should we throw UnsupportedOperationException ? */
|
92
|
+
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Returns the Attr[]s to be output for the given element.
|
97
|
+
* <br>
|
98
|
+
* The code of this method is a copy of {@link #handleAttributes(Element,
|
99
|
+
* NameSpaceSymbTable)},
|
100
|
+
* whereas it takes into account that subtree-c14n is -- well -- subtree-based.
|
101
|
+
* So if the element in question isRoot of c14n, it's parent is not in the
|
102
|
+
* node set, as well as all other ancestors.
|
103
|
+
*
|
104
|
+
* @param element
|
105
|
+
* @param ns
|
106
|
+
* @return the Attr[]s to be output
|
107
|
+
* @throws CanonicalizationException
|
108
|
+
*/
|
109
|
+
@Override
|
110
|
+
protected Iterator<Attr>
|
111
|
+
handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
|
112
|
+
throws CanonicalizationException
|
113
|
+
{
|
114
|
+
if (!element.hasAttributes()) {
|
115
|
+
return null;
|
70
116
|
}
|
71
117
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
* @param rootNode
|
76
|
-
* @param inclusiveNamespaces
|
77
|
-
* @return none it always fails
|
78
|
-
* @throws CanonicalizationException
|
79
|
-
*/
|
80
|
-
@Override
|
81
|
-
public byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces, CanonicalFilter filter)
|
82
|
-
throws CanonicalizationException {
|
83
|
-
|
84
|
-
/** $todo$ well, should we throw UnsupportedOperationException ? */
|
85
|
-
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
|
86
|
-
}
|
87
|
-
|
88
|
-
/**
|
89
|
-
* Returns the Attr[]s to be output for the given element.
|
90
|
-
* <br>
|
91
|
-
* The code of this method is a copy of {@link #handleAttributes(Element,
|
92
|
-
* NameSpaceSymbTable)},
|
93
|
-
* whereas it takes into account that subtree-c14n is -- well -- subtree-based.
|
94
|
-
* So if the element in question isRoot of c14n, it's parent is not in the
|
95
|
-
* node set, as well as all other ancestors.
|
96
|
-
*
|
97
|
-
* @param element
|
98
|
-
* @param ns
|
99
|
-
* @return the Attr[]s to be output
|
100
|
-
* @throws CanonicalizationException
|
101
|
-
*/
|
102
|
-
@Override
|
103
|
-
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
|
104
|
-
throws CanonicalizationException {
|
105
|
-
if (!element.hasAttributes()) {
|
106
|
-
return null;
|
107
|
-
}
|
108
|
-
|
109
|
-
// result will contain all the attrs declared directly on that element
|
110
|
-
final SortedSet<Attr> result = this.result;
|
111
|
-
result.clear();
|
112
|
-
|
113
|
-
if (element.hasAttributes()) {
|
114
|
-
NamedNodeMap attrs = element.getAttributes();
|
115
|
-
int attrsLength = attrs.getLength();
|
116
|
-
|
117
|
-
for (int i = 0; i < attrsLength; i++) {
|
118
|
-
Attr attribute = (Attr) attrs.item(i);
|
119
|
-
result.add(attribute);
|
120
|
-
}
|
121
|
-
}
|
122
|
-
|
123
|
-
return result.iterator();
|
124
|
-
}
|
118
|
+
// result will contain all the attrs declared directly on that element
|
119
|
+
final SortedSet<Attr> result = this.result;
|
120
|
+
result.clear();
|
125
121
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
* @param element
|
130
|
-
* @param ns
|
131
|
-
* @return the Attr[]s to be output
|
132
|
-
* @throws CanonicalizationException
|
133
|
-
*/
|
134
|
-
@Override
|
135
|
-
protected Iterator<Attr> handleAttributes(Element element, NameSpaceSymbTable ns)
|
136
|
-
throws CanonicalizationException {
|
137
|
-
|
138
|
-
/** $todo$ well, should we throw UnsupportedOperationException ? */
|
139
|
-
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
|
140
|
-
}
|
122
|
+
if (element.hasAttributes()) {
|
123
|
+
NamedNodeMap attrs = element.getAttributes();
|
124
|
+
int attrsLength = attrs.getLength();
|
141
125
|
|
142
|
-
|
143
|
-
|
144
|
-
|
126
|
+
for (int i = 0; i < attrsLength; i++) {
|
127
|
+
Attr attribute = (Attr) attrs.item(i);
|
128
|
+
result.add(attribute);
|
129
|
+
}
|
145
130
|
}
|
146
131
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
132
|
+
return result.iterator();
|
133
|
+
}
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Returns the Attr[]s to be output for the given element.
|
137
|
+
*
|
138
|
+
* @param element
|
139
|
+
* @param ns
|
140
|
+
* @return the Attr[]s to be output
|
141
|
+
* @throws CanonicalizationException
|
142
|
+
*/
|
143
|
+
@Override
|
144
|
+
protected Iterator<Attr>
|
145
|
+
handleAttributes(Element element, NameSpaceSymbTable ns)
|
146
|
+
throws CanonicalizationException
|
147
|
+
{
|
148
|
+
|
149
|
+
/** $todo$ well, should we throw UnsupportedOperationException ? */
|
150
|
+
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
|
151
|
+
}
|
152
|
+
|
153
|
+
@Override
|
154
|
+
protected void
|
155
|
+
handleParent(Element e, NameSpaceSymbTable ns)
|
156
|
+
{
|
157
|
+
// nothing to do
|
158
|
+
}
|
159
|
+
|
160
|
+
/** @inheritDoc */
|
161
|
+
@Override
|
162
|
+
public final String
|
163
|
+
engineGetURI()
|
164
|
+
{
|
165
|
+
return Canonicalizer.ALGO_ID_C14N_PHYSICAL;
|
166
|
+
}
|
167
|
+
|
168
|
+
/** @inheritDoc */
|
169
|
+
@Override
|
170
|
+
public final boolean
|
171
|
+
engineGetIncludeComments()
|
172
|
+
{
|
173
|
+
return true;
|
174
|
+
}
|
175
|
+
|
176
|
+
@Override
|
177
|
+
protected void
|
178
|
+
outputPItoWriter(ProcessingInstruction currentPI,
|
179
|
+
OutputStream writer, int position) throws IOException
|
180
|
+
{
|
181
|
+
// Processing Instructions before or after the document element are not treated specially
|
182
|
+
super.outputPItoWriter(currentPI, writer, NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT);
|
183
|
+
}
|
184
|
+
|
185
|
+
@Override
|
186
|
+
protected void
|
187
|
+
outputCommentToWriter(Comment currentComment,
|
188
|
+
OutputStream writer, int position) throws IOException
|
189
|
+
{
|
190
|
+
// Comments before or after the document element are not treated specially
|
191
|
+
super.outputCommentToWriter(currentComment, writer, NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT);
|
192
|
+
}
|
172
193
|
|
173
194
|
}
|
@@ -28,49 +28,50 @@ import org.w3c.dom.Node;
|
|
28
28
|
*
|
29
29
|
* @author Christian Geuer-Pollmann
|
30
30
|
*/
|
31
|
-
public abstract class CanonicalizerSpi
|
31
|
+
public abstract class CanonicalizerSpi
|
32
|
+
{
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
/** Reset the writer after a c14n */
|
35
|
+
protected boolean reset = false;
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
/**
|
38
|
+
* Returns the URI of this engine.
|
39
|
+
* @return the URI
|
40
|
+
*/
|
41
|
+
public abstract String engineGetURI();
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
/**
|
44
|
+
* Returns true if comments are included
|
45
|
+
* @return true if comments are included
|
46
|
+
*/
|
47
|
+
public abstract boolean engineGetIncludeComments();
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
49
|
+
/**
|
50
|
+
* C14n a node tree.
|
51
|
+
*
|
52
|
+
* @param rootNode
|
53
|
+
* @return the c14n bytes
|
54
|
+
* @throws CanonicalizationException
|
55
|
+
*/
|
56
|
+
public abstract byte[] engineCanonicalizeSubTree(Node rootNode, CanonicalFilter filter)
|
57
|
+
throws CanonicalizationException;
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
59
|
+
/**
|
60
|
+
* C14n a node tree.
|
61
|
+
*
|
62
|
+
* @param rootNode
|
63
|
+
* @param inclusiveNamespaces
|
64
|
+
* @return the c14n bytes
|
65
|
+
* @throws CanonicalizationException
|
66
|
+
*/
|
67
|
+
public abstract byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces, CanonicalFilter filter)
|
68
|
+
throws CanonicalizationException;
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
/**
|
71
|
+
* Sets the writer where the canonicalization ends. ByteArrayOutputStream if
|
72
|
+
* none is set.
|
73
|
+
* @param os
|
74
|
+
*/
|
75
|
+
public abstract void setWriter(OutputStream os);
|
75
76
|
|
76
77
|
}
|
@@ -27,16 +27,19 @@ package nokogiri.internals.c14n;
|
|
27
27
|
*
|
28
28
|
* @author $Author: coheigea $
|
29
29
|
*/
|
30
|
-
public class Constants
|
31
|
-
|
32
|
-
/** The URI for XML spec*/
|
33
|
-
public static final String XML_LANG_SPACE_SpecNS = "http://www.w3.org/XML/1998/namespace";
|
34
|
-
|
35
|
-
/** The URI for XMLNS spec*/
|
36
|
-
public static final String NamespaceSpecNS = "http://www.w3.org/2000/xmlns/";
|
30
|
+
public class Constants
|
31
|
+
{
|
37
32
|
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
/** The URI for XML spec*/
|
34
|
+
public static final String XML_LANG_SPACE_SpecNS = "http://www.w3.org/XML/1998/namespace";
|
35
|
+
|
36
|
+
/** The URI for XMLNS spec*/
|
37
|
+
public static final String NamespaceSpecNS = "http://www.w3.org/2000/xmlns/";
|
38
|
+
|
39
|
+
private
|
40
|
+
Constants()
|
41
|
+
{
|
42
|
+
// we don't allow instantiation
|
43
|
+
}
|
41
44
|
|
42
45
|
}
|
@@ -32,262 +32,294 @@ import org.w3c.dom.Text;
|
|
32
32
|
* This is the base class to all Objects which have a direct 1:1 mapping to an
|
33
33
|
* Element in a particular namespace.
|
34
34
|
*/
|
35
|
-
public abstract class ElementProxy
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
35
|
+
public abstract class ElementProxy
|
36
|
+
{
|
37
|
+
|
38
|
+
/** Field constructionElement */
|
39
|
+
protected Element constructionElement = null;
|
40
|
+
|
41
|
+
/** Field baseURI */
|
42
|
+
protected String baseURI = null;
|
43
|
+
|
44
|
+
/** Field doc */
|
45
|
+
protected Document doc = null;
|
46
|
+
|
47
|
+
/** Field prefixMappings */
|
48
|
+
private static Map<String, String> prefixMappings = new ConcurrentHashMap<String, String>();
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Constructor ElementProxy
|
52
|
+
*
|
53
|
+
*/
|
54
|
+
public
|
55
|
+
ElementProxy()
|
56
|
+
{
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Constructor ElementProxy
|
61
|
+
*
|
62
|
+
* @param doc
|
63
|
+
*/
|
64
|
+
public
|
65
|
+
ElementProxy(Document doc)
|
66
|
+
{
|
67
|
+
if (doc == null) {
|
68
|
+
throw new RuntimeException("Document is null");
|
54
69
|
}
|
55
70
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
71
|
+
this.doc = doc;
|
72
|
+
this.constructionElement =
|
73
|
+
createElementForFamilyLocal(this.doc, this.getBaseNamespace(), this.getBaseLocalName());
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Constructor ElementProxy
|
78
|
+
*
|
79
|
+
* @param element
|
80
|
+
* @param BaseURI
|
81
|
+
* @throws XMLSecurityException
|
82
|
+
*/
|
83
|
+
public
|
84
|
+
ElementProxy(Element element, String BaseURI) throws CanonicalizationException
|
85
|
+
{
|
86
|
+
if (element == null) {
|
87
|
+
throw new CanonicalizationException("ElementProxy.nullElement");
|
69
88
|
}
|
70
|
-
|
71
|
-
/**
|
72
|
-
* Constructor ElementProxy
|
73
|
-
*
|
74
|
-
* @param element
|
75
|
-
* @param BaseURI
|
76
|
-
* @throws XMLSecurityException
|
77
|
-
*/
|
78
|
-
public ElementProxy(Element element, String BaseURI) throws CanonicalizationException {
|
79
|
-
if (element == null) {
|
80
|
-
throw new CanonicalizationException("ElementProxy.nullElement");
|
81
|
-
}
|
82
|
-
|
83
|
-
//if (System.getProperty("nokogiri.c14.debug") == "on") {
|
84
|
-
// System.out.println("setElement(\"" + element.getTagName() + "\", \"" + BaseURI + "\")");
|
85
|
-
//}
|
86
|
-
|
87
|
-
this.doc = element.getOwnerDocument();
|
88
|
-
this.constructionElement = element;
|
89
|
-
this.baseURI = BaseURI;
|
90
|
-
|
91
|
-
this.guaranteeThatElementInCorrectSpace();
|
92
|
-
}
|
93
|
-
|
94
|
-
/**
|
95
|
-
* Returns the namespace of the Elements of the sub-class.
|
96
|
-
*
|
97
|
-
* @return the namespace of the Elements of the sub-class.
|
98
|
-
*/
|
99
|
-
public abstract String getBaseNamespace();
|
100
|
-
|
101
|
-
/**
|
102
|
-
* Returns the localname of the Elements of the sub-class.
|
103
|
-
*
|
104
|
-
* @return the localname of the Elements of the sub-class.
|
105
|
-
*/
|
106
|
-
public abstract String getBaseLocalName();
|
107
|
-
|
108
|
-
|
109
|
-
protected Element createElementForFamilyLocal(
|
110
|
-
Document doc, String namespace, String localName
|
111
|
-
) {
|
112
|
-
Element result;
|
113
|
-
if (namespace == null) {
|
114
|
-
result = doc.createElementNS(null, localName);
|
115
|
-
} else {
|
116
|
-
String baseName = this.getBaseNamespace();
|
117
|
-
String prefix = ElementProxy.getDefaultPrefix(baseName);
|
118
|
-
if ((prefix == null) || (prefix.length() == 0)) {
|
119
|
-
result = doc.createElementNS(namespace, localName);
|
120
|
-
result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", namespace);
|
121
|
-
} else {
|
122
|
-
result = doc.createElementNS(namespace, prefix + ":" + localName);
|
123
|
-
result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, namespace);
|
124
|
-
}
|
125
|
-
}
|
126
|
-
return result;
|
127
|
-
}
|
128
|
-
|
129
89
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
90
|
+
//if (System.getProperty("nokogiri.c14.debug") == "on") {
|
91
|
+
// System.out.println("setElement(\"" + element.getTagName() + "\", \"" + BaseURI + "\")");
|
92
|
+
//}
|
93
|
+
|
94
|
+
this.doc = element.getOwnerDocument();
|
95
|
+
this.constructionElement = element;
|
96
|
+
this.baseURI = BaseURI;
|
97
|
+
|
98
|
+
this.guaranteeThatElementInCorrectSpace();
|
99
|
+
}
|
100
|
+
|
101
|
+
/**
|
102
|
+
* Returns the namespace of the Elements of the sub-class.
|
103
|
+
*
|
104
|
+
* @return the namespace of the Elements of the sub-class.
|
105
|
+
*/
|
106
|
+
public abstract String getBaseNamespace();
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Returns the localname of the Elements of the sub-class.
|
110
|
+
*
|
111
|
+
* @return the localname of the Elements of the sub-class.
|
112
|
+
*/
|
113
|
+
public abstract String getBaseLocalName();
|
114
|
+
|
115
|
+
|
116
|
+
protected Element
|
117
|
+
createElementForFamilyLocal(
|
118
|
+
Document doc, String namespace, String localName
|
119
|
+
)
|
120
|
+
{
|
121
|
+
Element result;
|
122
|
+
if (namespace == null) {
|
123
|
+
result = doc.createElementNS(null, localName);
|
124
|
+
} else {
|
125
|
+
String baseName = this.getBaseNamespace();
|
126
|
+
String prefix = ElementProxy.getDefaultPrefix(baseName);
|
127
|
+
if ((prefix == null) || (prefix.length() == 0)) {
|
128
|
+
result = doc.createElementNS(namespace, localName);
|
129
|
+
result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", namespace);
|
130
|
+
} else {
|
131
|
+
result = doc.createElementNS(namespace, prefix + ":" + localName);
|
132
|
+
result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, namespace);
|
133
|
+
}
|
159
134
|
}
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
135
|
+
return result;
|
136
|
+
}
|
137
|
+
|
138
|
+
|
139
|
+
/**
|
140
|
+
* This method creates an Element in a given namespace with a given localname.
|
141
|
+
* It uses the {@link ElementProxy#getDefaultPrefix} method to decide whether
|
142
|
+
* a particular prefix is bound to that namespace.
|
143
|
+
* <BR />
|
144
|
+
* This method was refactored out of the constructor.
|
145
|
+
*
|
146
|
+
* @param doc
|
147
|
+
* @param namespace
|
148
|
+
* @param localName
|
149
|
+
* @return The element created.
|
150
|
+
*/
|
151
|
+
public static Element
|
152
|
+
createElementForFamily(Document doc, String namespace, String localName)
|
153
|
+
{
|
154
|
+
Element result;
|
155
|
+
String prefix = ElementProxy.getDefaultPrefix(namespace);
|
156
|
+
|
157
|
+
if (namespace == null) {
|
158
|
+
result = doc.createElementNS(null, localName);
|
159
|
+
} else {
|
160
|
+
if ((prefix == null) || (prefix.length() == 0)) {
|
161
|
+
result = doc.createElementNS(namespace, localName);
|
162
|
+
result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", namespace);
|
163
|
+
} else {
|
164
|
+
result = doc.createElementNS(namespace, prefix + ":" + localName);
|
165
|
+
result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, namespace);
|
166
|
+
}
|
168
167
|
}
|
169
168
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
169
|
+
return result;
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* Returns the Element which was constructed by the Object.
|
174
|
+
*
|
175
|
+
* @return the Element which was constructed by the Object.
|
176
|
+
*/
|
177
|
+
public final Element
|
178
|
+
getElement()
|
179
|
+
{
|
180
|
+
return this.constructionElement;
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Returns the Element plus a leading and a trailing CarriageReturn Text node.
|
185
|
+
*
|
186
|
+
* @return the Element which was constructed by the Object.
|
187
|
+
*/
|
188
|
+
public final NodeList
|
189
|
+
getElementPlusReturns()
|
190
|
+
{
|
191
|
+
|
192
|
+
HelperNodeList nl = new HelperNodeList();
|
193
|
+
|
194
|
+
nl.appendChild(this.doc.createTextNode("\n"));
|
195
|
+
nl.appendChild(this.getElement());
|
196
|
+
nl.appendChild(this.doc.createTextNode("\n"));
|
197
|
+
|
198
|
+
return nl;
|
199
|
+
}
|
200
|
+
|
201
|
+
/**
|
202
|
+
* Method getDocument
|
203
|
+
*
|
204
|
+
* @return the Document where this element is contained.
|
205
|
+
*/
|
206
|
+
public Document
|
207
|
+
getDocument()
|
208
|
+
{
|
209
|
+
return this.doc;
|
210
|
+
}
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Method getBaseURI
|
214
|
+
*
|
215
|
+
* @return the base uri of the namespace of this element
|
216
|
+
*/
|
217
|
+
public String
|
218
|
+
getBaseURI()
|
219
|
+
{
|
220
|
+
return this.baseURI;
|
221
|
+
}
|
222
|
+
|
223
|
+
/**
|
224
|
+
* Method guaranteeThatElementInCorrectSpace
|
225
|
+
*
|
226
|
+
* @throws XMLSecurityException
|
227
|
+
*/
|
228
|
+
void
|
229
|
+
guaranteeThatElementInCorrectSpace() throws CanonicalizationException
|
230
|
+
{
|
231
|
+
|
232
|
+
String expectedLocalName = this.getBaseLocalName();
|
233
|
+
String expectedNamespaceUri = this.getBaseNamespace();
|
234
|
+
|
235
|
+
String actualLocalName = this.constructionElement.getLocalName();
|
236
|
+
String actualNamespaceUri = this.constructionElement.getNamespaceURI();
|
237
|
+
|
238
|
+
if (!expectedNamespaceUri.equals(actualNamespaceUri)
|
239
|
+
&& !expectedLocalName.equals(actualLocalName)) {
|
240
|
+
Object exArgs[] = { actualNamespaceUri + ":" + actualLocalName,
|
241
|
+
expectedNamespaceUri + ":" + expectedLocalName
|
242
|
+
};
|
243
|
+
throw new CanonicalizationException("xml.WrongElement", exArgs);
|
184
244
|
}
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
245
|
+
}
|
246
|
+
|
247
|
+
/**
|
248
|
+
* Method addText
|
249
|
+
*
|
250
|
+
* @param text
|
251
|
+
*/
|
252
|
+
public void
|
253
|
+
addText(String text)
|
254
|
+
{
|
255
|
+
if (text != null) {
|
256
|
+
Text t = this.doc.createTextNode(text);
|
257
|
+
|
258
|
+
this.constructionElement.appendChild(t);
|
193
259
|
}
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
* @return the Text of the textNode
|
244
|
-
*/
|
245
|
-
public String getTextFromChildElement(String localname, String namespace) {
|
246
|
-
return XMLUtils.selectNode(
|
247
|
-
this.constructionElement.getFirstChild(),
|
248
|
-
namespace,
|
249
|
-
localname,
|
250
|
-
0).getTextContent();
|
251
|
-
}
|
252
|
-
|
253
|
-
/**
|
254
|
-
* Method getTextFromTextChild
|
255
|
-
*
|
256
|
-
* @return the Text obtained by concatenating all the text nodes of this
|
257
|
-
* element
|
258
|
-
*/
|
259
|
-
public String getTextFromTextChild() {
|
260
|
-
return XMLUtils.getFullTextChildrenFromElement(this.constructionElement);
|
261
|
-
}
|
262
|
-
|
263
|
-
/**
|
264
|
-
* Method length
|
265
|
-
*
|
266
|
-
* @param namespace
|
267
|
-
* @param localname
|
268
|
-
* @return the number of elements {namespace}:localname under this element
|
269
|
-
*/
|
270
|
-
public int length(String namespace, String localname) {
|
271
|
-
int number = 0;
|
272
|
-
Node sibling = this.constructionElement.getFirstChild();
|
273
|
-
while (sibling != null) {
|
274
|
-
if (localname.equals(sibling.getLocalName())
|
275
|
-
&& namespace.equals(sibling.getNamespaceURI())) {
|
276
|
-
number++;
|
277
|
-
}
|
278
|
-
sibling = sibling.getNextSibling();
|
279
|
-
}
|
280
|
-
return number;
|
281
|
-
}
|
282
|
-
|
283
|
-
/**
|
284
|
-
* Method getDefaultPrefix
|
285
|
-
*
|
286
|
-
* @param namespace
|
287
|
-
* @return the default prefix bind to this element.
|
288
|
-
*/
|
289
|
-
public static String getDefaultPrefix(String namespace) {
|
290
|
-
return prefixMappings.get(namespace);
|
260
|
+
}
|
261
|
+
|
262
|
+
/**
|
263
|
+
* Method getTextFromChildElement
|
264
|
+
*
|
265
|
+
* @param localname
|
266
|
+
* @param namespace
|
267
|
+
* @return the Text of the textNode
|
268
|
+
*/
|
269
|
+
public String
|
270
|
+
getTextFromChildElement(String localname, String namespace)
|
271
|
+
{
|
272
|
+
return XMLUtils.selectNode(
|
273
|
+
this.constructionElement.getFirstChild(),
|
274
|
+
namespace,
|
275
|
+
localname,
|
276
|
+
0).getTextContent();
|
277
|
+
}
|
278
|
+
|
279
|
+
/**
|
280
|
+
* Method getTextFromTextChild
|
281
|
+
*
|
282
|
+
* @return the Text obtained by concatenating all the text nodes of this
|
283
|
+
* element
|
284
|
+
*/
|
285
|
+
public String
|
286
|
+
getTextFromTextChild()
|
287
|
+
{
|
288
|
+
return XMLUtils.getFullTextChildrenFromElement(this.constructionElement);
|
289
|
+
}
|
290
|
+
|
291
|
+
/**
|
292
|
+
* Method length
|
293
|
+
*
|
294
|
+
* @param namespace
|
295
|
+
* @param localname
|
296
|
+
* @return the number of elements {namespace}:localname under this element
|
297
|
+
*/
|
298
|
+
public int
|
299
|
+
length(String namespace, String localname)
|
300
|
+
{
|
301
|
+
int number = 0;
|
302
|
+
Node sibling = this.constructionElement.getFirstChild();
|
303
|
+
while (sibling != null) {
|
304
|
+
if (localname.equals(sibling.getLocalName())
|
305
|
+
&& namespace.equals(sibling.getNamespaceURI())) {
|
306
|
+
number++;
|
307
|
+
}
|
308
|
+
sibling = sibling.getNextSibling();
|
291
309
|
}
|
310
|
+
return number;
|
311
|
+
}
|
312
|
+
|
313
|
+
/**
|
314
|
+
* Method getDefaultPrefix
|
315
|
+
*
|
316
|
+
* @param namespace
|
317
|
+
* @return the default prefix bind to this element.
|
318
|
+
*/
|
319
|
+
public static String
|
320
|
+
getDefaultPrefix(String namespace)
|
321
|
+
{
|
322
|
+
return prefixMappings.get(namespace);
|
323
|
+
}
|
292
324
|
|
293
325
|
}
|