nokogiri 1.6.1-java → 1.6.2-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/.editorconfig +17 -0
- data/.travis.yml +6 -6
- data/CHANGELOG.ja.rdoc +61 -8
- data/CHANGELOG.rdoc +58 -3
- data/Gemfile +3 -3
- data/Manifest.txt +57 -1
- data/README.ja.rdoc +22 -17
- data/README.rdoc +23 -18
- data/ROADMAP.md +1 -2
- data/Rakefile +162 -58
- data/build_all +56 -31
- data/dependencies.yml +3 -3
- data/ext/java/nokogiri/NokogiriService.java +9 -5
- data/ext/java/nokogiri/XmlDocument.java +95 -54
- data/ext/java/nokogiri/XmlNode.java +93 -42
- data/ext/java/nokogiri/XmlReader.java +1 -1
- data/ext/java/nokogiri/XmlSaxParserContext.java +33 -0
- data/ext/java/nokogiri/XmlSchema.java +4 -2
- data/ext/java/nokogiri/XmlXpathContext.java +118 -76
- data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +20 -0
- data/ext/java/nokogiri/internals/NokogiriHandler.java +3 -10
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +40 -23
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +59 -54
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +1 -1
- data/ext/java/nokogiri/internals/ParserContext.java +1 -4
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +6 -2
- data/ext/java/nokogiri/internals/c14n/AttrCompare.java +119 -0
- data/ext/java/nokogiri/internals/c14n/C14nHelper.java +159 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +37 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +93 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +252 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +639 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +38 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +38 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +368 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +295 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +40 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +44 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +44 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +43 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +630 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +173 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +76 -0
- data/ext/java/nokogiri/internals/c14n/Constants.java +42 -0
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +293 -0
- data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +93 -0
- data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +79 -0
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +165 -0
- data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +76 -0
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +402 -0
- data/ext/java/nokogiri/internals/c14n/NodeFilter.java +51 -0
- data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +179 -0
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +507 -0
- data/ext/nokogiri/extconf.rb +429 -128
- data/ext/nokogiri/html_document.c +2 -2
- data/ext/nokogiri/nokogiri.c +6 -1
- data/ext/nokogiri/xml_document.c +5 -4
- data/ext/nokogiri/xml_node.c +76 -7
- data/ext/nokogiri/xml_reader.c +1 -1
- data/ext/nokogiri/xml_sax_parser_context.c +40 -0
- data/ext/nokogiri/xml_syntax_error.c +10 -5
- data/ext/nokogiri/xml_syntax_error.h +1 -1
- data/ext/nokogiri/xml_xpath_context.c +2 -14
- data/ext/nokogiri/xslt_stylesheet.c +1 -1
- data/lib/nokogiri.rb +31 -22
- data/lib/nokogiri/css/node.rb +0 -50
- data/lib/nokogiri/css/parser.rb +213 -218
- data/lib/nokogiri/css/parser.y +21 -30
- data/lib/nokogiri/css/xpath_visitor.rb +62 -14
- data/lib/nokogiri/html/document.rb +97 -18
- data/lib/nokogiri/html/sax/parser.rb +2 -2
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +1 -1
- data/lib/nokogiri/xml/builder.rb +1 -1
- data/lib/nokogiri/xml/document.rb +2 -2
- data/lib/nokogiri/xml/dtd.rb +10 -0
- data/lib/nokogiri/xml/node.rb +26 -1
- data/lib/nokogiri/xml/sax/parser.rb +1 -1
- data/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch +265 -0
- data/ports/patches/libxml2/0002-Fix-entities-local-buffers-size-problems.patch +102 -0
- data/ports/patches/libxml2/0003-Fix-an-error-in-previous-commit.patch +26 -0
- data/ports/patches/libxml2/0004-Fix-potential-out-of-bound-access.patch +26 -0
- data/ports/patches/libxml2/0005-Detect-excessive-entities-expansion-upon-replacement.patch +158 -0
- data/ports/patches/libxml2/0006-Do-not-fetch-external-parsed-entities.patch +78 -0
- data/ports/patches/libxml2/0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch +480 -0
- data/ports/patches/libxml2/0008-Improve-handling-of-xmlStopParser.patch +315 -0
- data/ports/patches/libxml2/0009-Fix-a-couple-of-return-without-value.patch +37 -0
- data/ports/patches/libxslt/0001-Adding-doc-update-related-to-1.1.28.patch +222 -0
- data/ports/patches/libxslt/0002-Fix-a-couple-of-places-where-f-printf-parameters-wer.patch +53 -0
- data/ports/patches/libxslt/0003-Initialize-pseudo-random-number-generator-with-curre.patch +60 -0
- data/ports/patches/libxslt/0004-EXSLT-function-str-replace-is-broken-as-is.patch +42 -0
- data/ports/patches/libxslt/0006-Fix-str-padding-to-work-with-UTF-8-strings.patch +164 -0
- data/ports/patches/libxslt/0007-Separate-function-for-predicate-matching-in-patterns.patch +587 -0
- data/ports/patches/libxslt/0008-Fix-direct-pattern-matching.patch +80 -0
- data/ports/patches/libxslt/0009-Fix-certain-patterns-with-predicates.patch +185 -0
- data/ports/patches/libxslt/0010-Fix-handling-of-UTF-8-strings-in-EXSLT-crypto-module.patch +126 -0
- data/ports/patches/libxslt/0013-Memory-leak-in-xsltCompileIdKeyPattern-error-path.patch +25 -0
- data/ports/patches/libxslt/0014-Fix-for-bug-436589.patch +43 -0
- data/ports/patches/libxslt/0015-Fix-mkdir-for-mingw.patch +41 -0
- data/suppressions/README.txt +1 -0
- data/suppressions/nokogiri_ree-1.8.7.358.supp +61 -0
- data/suppressions/nokogiri_ruby-1.8.7.370.supp +0 -0
- data/suppressions/nokogiri_ruby-1.9.2.320.supp +28 -0
- data/suppressions/nokogiri_ruby-1.9.3.327.supp +28 -0
- data/test/css/test_nthiness.rb +65 -2
- data/test/css/test_parser.rb +27 -10
- data/test/css/test_tokenizer.rb +1 -1
- data/test/css/test_xpath_visitor.rb +6 -1
- data/test/files/atom.xml +344 -0
- data/test/files/shift_jis_no_charset.html +9 -0
- data/test/helper.rb +10 -0
- data/test/html/test_document.rb +74 -7
- data/test/html/test_document_encoding.rb +10 -0
- data/test/html/test_document_fragment.rb +9 -3
- data/test/namespaces/test_namespaces_aliased_default.rb +24 -0
- data/test/namespaces/test_namespaces_in_cloned_doc.rb +31 -0
- data/test/namespaces/test_namespaces_preservation.rb +31 -0
- data/test/test_nokogiri.rb +6 -0
- data/test/test_reader.rb +7 -4
- data/test/test_xslt_transforms.rb +25 -0
- data/test/xml/sax/test_parser.rb +16 -0
- data/test/xml/sax/test_parser_context.rb +9 -0
- data/test/xml/test_builder.rb +9 -0
- data/test/xml/test_c14n.rb +12 -2
- data/test/xml/test_document.rb +66 -0
- data/test/xml/test_document_fragment.rb +5 -0
- data/test/xml/test_dtd.rb +84 -0
- data/test/xml/test_entity_reference.rb +3 -3
- data/test/xml/test_node.rb +21 -3
- data/test/xml/test_node_attributes.rb +17 -0
- data/test/xml/test_schema.rb +26 -0
- data/test/xml/test_text.rb +15 -0
- data/test/xml/test_xpath.rb +87 -0
- data/test_all +3 -3
- metadata +119 -68
- data/tasks/cross_compile.rb +0 -134
@@ -0,0 +1,93 @@
|
|
1
|
+
/**
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
4
|
+
* distributed with this work for additional information
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
7
|
+
* "License"); you may not use this file except in compliance
|
8
|
+
* with the License. You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
13
|
+
* software distributed under the License is distributed on an
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
* KIND, either express or implied. See the License for the
|
16
|
+
* specific language governing permissions and limitations
|
17
|
+
* under the License.
|
18
|
+
*/
|
19
|
+
package nokogiri.internals.c14n;
|
20
|
+
|
21
|
+
import java.util.ArrayList;
|
22
|
+
import java.util.List;
|
23
|
+
import org.w3c.dom.Document;
|
24
|
+
import org.w3c.dom.Node;
|
25
|
+
import org.w3c.dom.NodeList;
|
26
|
+
|
27
|
+
/**
|
28
|
+
* @author Christian Geuer-Pollmann
|
29
|
+
*/
|
30
|
+
public class HelperNodeList implements NodeList {
|
31
|
+
|
32
|
+
/** Field nodes */
|
33
|
+
List<Node> nodes = new ArrayList<Node>();
|
34
|
+
boolean allNodesMustHaveSameParent = false;
|
35
|
+
|
36
|
+
/**
|
37
|
+
*
|
38
|
+
*/
|
39
|
+
public HelperNodeList() {
|
40
|
+
this(false);
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
/**
|
45
|
+
* @param allNodesMustHaveSameParent
|
46
|
+
*/
|
47
|
+
public HelperNodeList(boolean allNodesMustHaveSameParent) {
|
48
|
+
this.allNodesMustHaveSameParent = allNodesMustHaveSameParent;
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Method item
|
53
|
+
*
|
54
|
+
* @param index
|
55
|
+
* @return node with index i
|
56
|
+
*/
|
57
|
+
public Node item(int index) {
|
58
|
+
return nodes.get(index);
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Method getLength
|
63
|
+
*
|
64
|
+
* @return length of the list
|
65
|
+
*/
|
66
|
+
public int getLength() {
|
67
|
+
return nodes.size();
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Method appendChild
|
72
|
+
*
|
73
|
+
* @param node
|
74
|
+
* @throws IllegalArgumentException
|
75
|
+
*/
|
76
|
+
public void appendChild(Node node) throws IllegalArgumentException {
|
77
|
+
if (this.allNodesMustHaveSameParent && this.getLength() > 0
|
78
|
+
&& this.item(0).getParentNode() != node.getParentNode()) {
|
79
|
+
throw new IllegalArgumentException("Nodes have not the same Parent");
|
80
|
+
}
|
81
|
+
nodes.add(node);
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* @return the document that contains this nodelist
|
86
|
+
*/
|
87
|
+
public Document getOwnerDocument() {
|
88
|
+
if (this.getLength() == 0) {
|
89
|
+
return null;
|
90
|
+
}
|
91
|
+
return XMLUtils.getOwnerDocument(this.item(0));
|
92
|
+
}
|
93
|
+
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
/**
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
4
|
+
* distributed with this work for additional information
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
7
|
+
* "License"); you may not use this file except in compliance
|
8
|
+
* with the License. You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
13
|
+
* software distributed under the License is distributed on an
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
* KIND, either express or implied. See the License for the
|
16
|
+
* specific language governing permissions and limitations
|
17
|
+
* under the License.
|
18
|
+
*/
|
19
|
+
package nokogiri.internals.c14n;
|
20
|
+
|
21
|
+
import org.xml.sax.ErrorHandler;
|
22
|
+
import org.xml.sax.SAXException;
|
23
|
+
import org.xml.sax.SAXParseException;
|
24
|
+
|
25
|
+
/**
|
26
|
+
* This {@link org.xml.sax.ErrorHandler} does absolutely nothing but log
|
27
|
+
* the events.
|
28
|
+
*
|
29
|
+
* @author Christian Geuer-Pollmann
|
30
|
+
*/
|
31
|
+
public class IgnoreAllErrorHandler implements ErrorHandler {
|
32
|
+
|
33
|
+
/** Field throwExceptions */
|
34
|
+
private static final boolean warnOnExceptions =
|
35
|
+
System.getProperty("org.apache.xml.security.test.warn.on.exceptions", "false").equals("true");
|
36
|
+
|
37
|
+
/** Field throwExceptions */
|
38
|
+
private static final boolean throwExceptions =
|
39
|
+
System.getProperty("org.apache.xml.security.test.throw.exceptions", "false").equals("true");
|
40
|
+
|
41
|
+
|
42
|
+
/** @inheritDoc */
|
43
|
+
public void warning(SAXParseException ex) throws SAXException {
|
44
|
+
if (IgnoreAllErrorHandler.warnOnExceptions) {
|
45
|
+
// TODO
|
46
|
+
// get handler from upper layer
|
47
|
+
//log.warn("", ex);
|
48
|
+
}
|
49
|
+
if (IgnoreAllErrorHandler.throwExceptions) {
|
50
|
+
throw ex;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
/** @inheritDoc */
|
56
|
+
public void error(SAXParseException ex) throws SAXException {
|
57
|
+
if (IgnoreAllErrorHandler.warnOnExceptions) {
|
58
|
+
// TODO
|
59
|
+
// get handler from upper layer
|
60
|
+
//log.error("", ex);
|
61
|
+
}
|
62
|
+
if (IgnoreAllErrorHandler.throwExceptions) {
|
63
|
+
throw ex;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
/** @inheritDoc */
|
69
|
+
public void fatalError(SAXParseException ex) throws SAXException {
|
70
|
+
if (IgnoreAllErrorHandler.warnOnExceptions) {
|
71
|
+
// TODO
|
72
|
+
// get handler from upper layer
|
73
|
+
//log.warn("", ex);
|
74
|
+
}
|
75
|
+
if (IgnoreAllErrorHandler.throwExceptions) {
|
76
|
+
throw ex;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
@@ -0,0 +1,165 @@
|
|
1
|
+
/**
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
4
|
+
* distributed with this work for additional information
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
7
|
+
* "License"); you may not use this file except in compliance
|
8
|
+
* with the License. You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
13
|
+
* software distributed under the License is distributed on an
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
* KIND, either express or implied. See the License for the
|
16
|
+
* specific language governing permissions and limitations
|
17
|
+
* under the License.
|
18
|
+
*/
|
19
|
+
package nokogiri.internals.c14n;
|
20
|
+
|
21
|
+
import java.util.Set;
|
22
|
+
import java.util.SortedSet;
|
23
|
+
import java.util.TreeSet;
|
24
|
+
//import nokogiri.internals.org.apache.xml.security.exceptions.XMLSecurityException;
|
25
|
+
//import nokogiri.internals.org.apache.xml.security.transforms.TransformParam;
|
26
|
+
import org.w3c.dom.Document;
|
27
|
+
import org.w3c.dom.Element;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* This Object serves as Content for the ds:Transforms for exclusive
|
31
|
+
* Canonicalization.
|
32
|
+
* <BR />
|
33
|
+
* It implements the {@link Element} interface
|
34
|
+
* and can be used directly in a DOM tree.
|
35
|
+
*
|
36
|
+
* @author Christian Geuer-Pollmann
|
37
|
+
*/
|
38
|
+
//public class InclusiveNamespaces extends ElementProxy implements TransformParam {
|
39
|
+
public class InclusiveNamespaces extends ElementProxy {
|
40
|
+
|
41
|
+
/** Field _TAG_EC_INCLUSIVENAMESPACES */
|
42
|
+
public static final String _TAG_EC_INCLUSIVENAMESPACES =
|
43
|
+
"InclusiveNamespaces";
|
44
|
+
|
45
|
+
/** Field _ATT_EC_PREFIXLIST */
|
46
|
+
public static final String _ATT_EC_PREFIXLIST = "PrefixList";
|
47
|
+
|
48
|
+
/** Field ExclusiveCanonicalizationNamespace */
|
49
|
+
public static final String ExclusiveCanonicalizationNamespace =
|
50
|
+
"http://www.w3.org/2001/10/xml-exc-c14n#";
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Constructor XPathContainer
|
54
|
+
*
|
55
|
+
* @param doc
|
56
|
+
* @param prefixList
|
57
|
+
*/
|
58
|
+
public InclusiveNamespaces(Document doc, String prefixList) {
|
59
|
+
this(doc, InclusiveNamespaces.prefixStr2Set(prefixList));
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Constructor InclusiveNamespaces
|
64
|
+
*
|
65
|
+
* @param doc
|
66
|
+
* @param prefixes
|
67
|
+
*/
|
68
|
+
public InclusiveNamespaces(Document doc, Set<String> prefixes) {
|
69
|
+
super(doc);
|
70
|
+
|
71
|
+
SortedSet<String> prefixList = null;
|
72
|
+
if (prefixes instanceof SortedSet<?>) {
|
73
|
+
prefixList = (SortedSet<String>)prefixes;
|
74
|
+
} else {
|
75
|
+
prefixList = new TreeSet<String>(prefixes);
|
76
|
+
}
|
77
|
+
|
78
|
+
StringBuilder sb = new StringBuilder();
|
79
|
+
for (String prefix : prefixList) {
|
80
|
+
if (prefix.equals("xmlns")) {
|
81
|
+
sb.append("#default ");
|
82
|
+
} else {
|
83
|
+
sb.append(prefix + " ");
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
this.constructionElement.setAttributeNS(
|
88
|
+
null, InclusiveNamespaces._ATT_EC_PREFIXLIST, sb.toString().trim());
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Constructor InclusiveNamespaces
|
93
|
+
*
|
94
|
+
* @param element
|
95
|
+
* @param BaseURI
|
96
|
+
* @throws XMLSecurityException
|
97
|
+
*/
|
98
|
+
public InclusiveNamespaces(Element element, String BaseURI)
|
99
|
+
throws CanonicalizationException {
|
100
|
+
super(element, BaseURI);
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Method getInclusiveNamespaces
|
105
|
+
*
|
106
|
+
* @return The Inclusive Namespace string
|
107
|
+
*/
|
108
|
+
public String getInclusiveNamespaces() {
|
109
|
+
return this.constructionElement.getAttributeNS(null, InclusiveNamespaces._ATT_EC_PREFIXLIST);
|
110
|
+
}
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Decodes the <code>inclusiveNamespaces</code> String and returns all
|
114
|
+
* selected namespace prefixes as a Set. The <code>#default</code>
|
115
|
+
* namespace token is represented as an empty namespace prefix
|
116
|
+
* (<code>"xmlns"</code>).
|
117
|
+
* <BR/>
|
118
|
+
* The String <code>inclusiveNamespaces=" xenc ds #default"</code>
|
119
|
+
* is returned as a Set containing the following Strings:
|
120
|
+
* <UL>
|
121
|
+
* <LI><code>xmlns</code></LI>
|
122
|
+
* <LI><code>xenc</code></LI>
|
123
|
+
* <LI><code>ds</code></LI>
|
124
|
+
* </UL>
|
125
|
+
*
|
126
|
+
* @param inclusiveNamespaces
|
127
|
+
* @return A set to string
|
128
|
+
*/
|
129
|
+
public static SortedSet<String> prefixStr2Set(String inclusiveNamespaces) {
|
130
|
+
SortedSet<String> prefixes = new TreeSet<String>();
|
131
|
+
|
132
|
+
if ((inclusiveNamespaces == null) || (inclusiveNamespaces.length() == 0)) {
|
133
|
+
return prefixes;
|
134
|
+
}
|
135
|
+
|
136
|
+
String[] tokens = inclusiveNamespaces.split("\\s");
|
137
|
+
for (String prefix : tokens) {
|
138
|
+
if (prefix.equals("#default")) {
|
139
|
+
prefixes.add("xmlns");
|
140
|
+
} else {
|
141
|
+
prefixes.add(prefix);
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
return prefixes;
|
146
|
+
}
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Method getBaseNamespace
|
150
|
+
*
|
151
|
+
* @inheritDoc
|
152
|
+
*/
|
153
|
+
public String getBaseNamespace() {
|
154
|
+
return InclusiveNamespaces.ExclusiveCanonicalizationNamespace;
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* Method getBaseLocalName
|
159
|
+
*
|
160
|
+
* @inheritDoc
|
161
|
+
*/
|
162
|
+
public String getBaseLocalName() {
|
163
|
+
return InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES;
|
164
|
+
}
|
165
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
/**
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
4
|
+
* distributed with this work for additional information
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
7
|
+
* "License"); you may not use this file except in compliance
|
8
|
+
* with the License. You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
13
|
+
* software distributed under the License is distributed on an
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
* KIND, either express or implied. See the License for the
|
16
|
+
* specific language governing permissions and limitations
|
17
|
+
* under the License.
|
18
|
+
*/
|
19
|
+
package nokogiri.internals.c14n;
|
20
|
+
|
21
|
+
|
22
|
+
public class InvalidCanonicalizerException extends Exception {
|
23
|
+
|
24
|
+
/**
|
25
|
+
*
|
26
|
+
*/
|
27
|
+
private static final long serialVersionUID = 1L;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Constructor InvalidCanonicalizerException
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
public InvalidCanonicalizerException() {
|
34
|
+
super();
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Constructor InvalidCanonicalizerException
|
39
|
+
*
|
40
|
+
* @param message
|
41
|
+
*/
|
42
|
+
public InvalidCanonicalizerException(String message) {
|
43
|
+
super(message);
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Constructor InvalidCanonicalizerException
|
48
|
+
*
|
49
|
+
* @param message
|
50
|
+
* @param exArgs
|
51
|
+
*/
|
52
|
+
public InvalidCanonicalizerException(String message, Object... exArgs) {
|
53
|
+
super(C14nHelper.getErrorMessage(message, exArgs));
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Constructor InvalidCanonicalizerException
|
58
|
+
*
|
59
|
+
* @param msgID
|
60
|
+
* @param originalException
|
61
|
+
*/
|
62
|
+
public InvalidCanonicalizerException(String message, Exception rootCause) {
|
63
|
+
super(message, rootCause);
|
64
|
+
}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Constructor InvalidCanonicalizerException
|
68
|
+
*
|
69
|
+
* @param msgID
|
70
|
+
* @param exArgs
|
71
|
+
* @param originalException
|
72
|
+
*/
|
73
|
+
public InvalidCanonicalizerException(String message, Exception rootCause, Object... exArgs) {
|
74
|
+
super(C14nHelper.getErrorMessage(message, exArgs), rootCause);
|
75
|
+
}
|
76
|
+
}
|
@@ -0,0 +1,402 @@
|
|
1
|
+
/**
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
4
|
+
* distributed with this work for additional information
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
7
|
+
* "License"); you may not use this file except in compliance
|
8
|
+
* with the License. You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
13
|
+
* software distributed under the License is distributed on an
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
* KIND, either express or implied. See the License for the
|
16
|
+
* specific language governing permissions and limitations
|
17
|
+
* under the License.
|
18
|
+
*/
|
19
|
+
package nokogiri.internals.c14n;
|
20
|
+
|
21
|
+
import java.util.ArrayList;
|
22
|
+
import java.util.Collection;
|
23
|
+
import java.util.Iterator;
|
24
|
+
import java.util.List;
|
25
|
+
import org.w3c.dom.Attr;
|
26
|
+
import org.w3c.dom.Node;
|
27
|
+
|
28
|
+
/**
|
29
|
+
* A stack based Symbol Table.
|
30
|
+
*<br>For speed reasons all the symbols are introduced in the same map,
|
31
|
+
* and at the same time in a list so it can be removed when the frame is pop back.
|
32
|
+
* @author Raul Benito
|
33
|
+
*/
|
34
|
+
public class NameSpaceSymbTable {
|
35
|
+
|
36
|
+
private static final String XMLNS = "xmlns";
|
37
|
+
private static final SymbMap initialMap = new SymbMap();
|
38
|
+
|
39
|
+
static {
|
40
|
+
NameSpaceSymbEntry ne = new NameSpaceSymbEntry("", null, true, XMLNS);
|
41
|
+
ne.lastrendered = "";
|
42
|
+
initialMap.put(XMLNS, ne);
|
43
|
+
}
|
44
|
+
|
45
|
+
/**The map betwen prefix-> entry table. */
|
46
|
+
private SymbMap symb;
|
47
|
+
|
48
|
+
/**The stacks for removing the definitions when doing pop.*/
|
49
|
+
private List<SymbMap> level;
|
50
|
+
private boolean cloned = true;
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Default constractor
|
54
|
+
**/
|
55
|
+
public NameSpaceSymbTable() {
|
56
|
+
level = new ArrayList<SymbMap>();
|
57
|
+
//Insert the default binding for xmlns.
|
58
|
+
symb = (SymbMap) initialMap.clone();
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Get all the unrendered nodes in the name space.
|
63
|
+
* For Inclusive rendering
|
64
|
+
* @param result the list where to fill the unrendered xmlns definitions.
|
65
|
+
**/
|
66
|
+
public void getUnrenderedNodes(Collection<Attr> result) {
|
67
|
+
Iterator<NameSpaceSymbEntry> it = symb.entrySet().iterator();
|
68
|
+
while (it.hasNext()) {
|
69
|
+
NameSpaceSymbEntry n = it.next();
|
70
|
+
//put them rendered?
|
71
|
+
if ((!n.rendered) && (n.n != null)) {
|
72
|
+
n = (NameSpaceSymbEntry) n.clone();
|
73
|
+
needsClone();
|
74
|
+
symb.put(n.prefix, n);
|
75
|
+
n.lastrendered = n.uri;
|
76
|
+
n.rendered = true;
|
77
|
+
|
78
|
+
result.add(n.n);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Push a frame for visible namespace.
|
85
|
+
* For Inclusive rendering.
|
86
|
+
**/
|
87
|
+
public void outputNodePush() {
|
88
|
+
push();
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Pop a frame for visible namespace.
|
93
|
+
**/
|
94
|
+
public void outputNodePop() {
|
95
|
+
pop();
|
96
|
+
}
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Push a frame for a node.
|
100
|
+
* Inclusive or Exclusive.
|
101
|
+
**/
|
102
|
+
public void push() {
|
103
|
+
//Put the number of namespace definitions in the stack.
|
104
|
+
level.add(null);
|
105
|
+
cloned = false;
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Pop a frame.
|
110
|
+
* Inclusive or Exclusive.
|
111
|
+
**/
|
112
|
+
public void pop() {
|
113
|
+
int size = level.size() - 1;
|
114
|
+
Object ob = level.remove(size);
|
115
|
+
if (ob != null) {
|
116
|
+
symb = (SymbMap)ob;
|
117
|
+
if (size == 0) {
|
118
|
+
cloned = false;
|
119
|
+
} else {
|
120
|
+
cloned = (level.get(size - 1) != symb);
|
121
|
+
}
|
122
|
+
} else {
|
123
|
+
cloned = false;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
final void needsClone() {
|
128
|
+
if (!cloned) {
|
129
|
+
level.set(level.size() - 1, symb);
|
130
|
+
symb = (SymbMap) symb.clone();
|
131
|
+
cloned = true;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Gets the attribute node that defines the binding for the prefix.
|
138
|
+
* @param prefix the prefix to obtain the attribute.
|
139
|
+
* @return null if there is no need to render the prefix. Otherwise the node of
|
140
|
+
* definition.
|
141
|
+
**/
|
142
|
+
public Attr getMapping(String prefix) {
|
143
|
+
NameSpaceSymbEntry entry = symb.get(prefix);
|
144
|
+
if (entry == null) {
|
145
|
+
//There is no definition for the prefix(a bug?).
|
146
|
+
return null;
|
147
|
+
}
|
148
|
+
if (entry.rendered) {
|
149
|
+
//No need to render an entry already rendered.
|
150
|
+
return null;
|
151
|
+
}
|
152
|
+
// Mark this entry as render.
|
153
|
+
entry = (NameSpaceSymbEntry) entry.clone();
|
154
|
+
needsClone();
|
155
|
+
symb.put(prefix, entry);
|
156
|
+
entry.rendered = true;
|
157
|
+
entry.lastrendered = entry.uri;
|
158
|
+
// Return the node for outputing.
|
159
|
+
return entry.n;
|
160
|
+
}
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Gets a definition without mark it as render.
|
164
|
+
* For render in exclusive c14n the namespaces in the include prefixes.
|
165
|
+
* @param prefix The prefix whose definition is neaded.
|
166
|
+
* @return the attr to render, null if there is no need to render
|
167
|
+
**/
|
168
|
+
public Attr getMappingWithoutRendered(String prefix) {
|
169
|
+
NameSpaceSymbEntry entry = symb.get(prefix);
|
170
|
+
if (entry == null) {
|
171
|
+
return null;
|
172
|
+
}
|
173
|
+
if (entry.rendered) {
|
174
|
+
return null;
|
175
|
+
}
|
176
|
+
return entry.n;
|
177
|
+
}
|
178
|
+
|
179
|
+
/**
|
180
|
+
* Adds the mapping for a prefix.
|
181
|
+
* @param prefix the prefix of definition
|
182
|
+
* @param uri the Uri of the definition
|
183
|
+
* @param n the attribute that have the definition
|
184
|
+
* @return true if there is already defined.
|
185
|
+
**/
|
186
|
+
public boolean addMapping(String prefix, String uri, Attr n) {
|
187
|
+
NameSpaceSymbEntry ob = symb.get(prefix);
|
188
|
+
if ((ob != null) && uri.equals(ob.uri)) {
|
189
|
+
//If we have it previously defined. Don't keep working.
|
190
|
+
return false;
|
191
|
+
}
|
192
|
+
//Creates and entry in the table for this new definition.
|
193
|
+
NameSpaceSymbEntry ne = new NameSpaceSymbEntry(uri, n, false, prefix);
|
194
|
+
needsClone();
|
195
|
+
symb.put(prefix, ne);
|
196
|
+
if (ob != null) {
|
197
|
+
//We have a previous definition store it for the pop.
|
198
|
+
//Check if a previous definition(not the inmidiatly one) has been rendered.
|
199
|
+
ne.lastrendered = ob.lastrendered;
|
200
|
+
if ((ob.lastrendered != null) && (ob.lastrendered.equals(uri))) {
|
201
|
+
//Yes it is. Mark as rendered.
|
202
|
+
ne.rendered = true;
|
203
|
+
}
|
204
|
+
}
|
205
|
+
return true;
|
206
|
+
}
|
207
|
+
|
208
|
+
/**
|
209
|
+
* Adds a definition and mark it as render.
|
210
|
+
* For inclusive c14n.
|
211
|
+
* @param prefix the prefix of definition
|
212
|
+
* @param uri the Uri of the definition
|
213
|
+
* @param n the attribute that have the definition
|
214
|
+
* @return the attr to render, null if there is no need to render
|
215
|
+
**/
|
216
|
+
public Node addMappingAndRender(String prefix, String uri, Attr n) {
|
217
|
+
NameSpaceSymbEntry ob = symb.get(prefix);
|
218
|
+
|
219
|
+
if ((ob != null) && uri.equals(ob.uri)) {
|
220
|
+
if (!ob.rendered) {
|
221
|
+
ob = (NameSpaceSymbEntry) ob.clone();
|
222
|
+
needsClone();
|
223
|
+
symb.put(prefix, ob);
|
224
|
+
ob.lastrendered = uri;
|
225
|
+
ob.rendered = true;
|
226
|
+
return ob.n;
|
227
|
+
}
|
228
|
+
return null;
|
229
|
+
}
|
230
|
+
|
231
|
+
NameSpaceSymbEntry ne = new NameSpaceSymbEntry(uri,n,true,prefix);
|
232
|
+
ne.lastrendered = uri;
|
233
|
+
needsClone();
|
234
|
+
symb.put(prefix, ne);
|
235
|
+
if ((ob != null) && (ob.lastrendered != null) && (ob.lastrendered.equals(uri))) {
|
236
|
+
ne.rendered = true;
|
237
|
+
return null;
|
238
|
+
}
|
239
|
+
return ne.n;
|
240
|
+
}
|
241
|
+
|
242
|
+
public int getLevel() {
|
243
|
+
return level.size();
|
244
|
+
}
|
245
|
+
|
246
|
+
public void removeMapping(String prefix) {
|
247
|
+
NameSpaceSymbEntry ob = symb.get(prefix);
|
248
|
+
|
249
|
+
if (ob != null) {
|
250
|
+
needsClone();
|
251
|
+
symb.put(prefix, null);
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
public void removeMappingIfNotRender(String prefix) {
|
256
|
+
NameSpaceSymbEntry ob = symb.get(prefix);
|
257
|
+
|
258
|
+
if (ob != null && !ob.rendered) {
|
259
|
+
needsClone();
|
260
|
+
symb.put(prefix, null);
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
public boolean removeMappingIfRender(String prefix) {
|
265
|
+
NameSpaceSymbEntry ob = symb.get(prefix);
|
266
|
+
|
267
|
+
if (ob != null && ob.rendered) {
|
268
|
+
needsClone();
|
269
|
+
symb.put(prefix, null);
|
270
|
+
}
|
271
|
+
return false;
|
272
|
+
}
|
273
|
+
}
|
274
|
+
|
275
|
+
/**
|
276
|
+
* The internal structure of NameSpaceSymbTable.
|
277
|
+
**/
|
278
|
+
class NameSpaceSymbEntry implements Cloneable {
|
279
|
+
|
280
|
+
String prefix;
|
281
|
+
|
282
|
+
/**The URI that the prefix defines */
|
283
|
+
String uri;
|
284
|
+
|
285
|
+
/**The last output in the URI for this prefix (This for speed reason).*/
|
286
|
+
String lastrendered = null;
|
287
|
+
|
288
|
+
/**This prefix-URI has been already render or not.*/
|
289
|
+
boolean rendered = false;
|
290
|
+
|
291
|
+
/**The attribute to include.*/
|
292
|
+
Attr n;
|
293
|
+
|
294
|
+
NameSpaceSymbEntry(String name, Attr n, boolean rendered, String prefix) {
|
295
|
+
this.uri = name;
|
296
|
+
this.rendered = rendered;
|
297
|
+
this.n = n;
|
298
|
+
this.prefix = prefix;
|
299
|
+
}
|
300
|
+
|
301
|
+
/** @inheritDoc */
|
302
|
+
public Object clone() {
|
303
|
+
try {
|
304
|
+
return super.clone();
|
305
|
+
} catch (CloneNotSupportedException e) {
|
306
|
+
return null;
|
307
|
+
}
|
308
|
+
}
|
309
|
+
};
|
310
|
+
|
311
|
+
class SymbMap implements Cloneable {
|
312
|
+
int free = 23;
|
313
|
+
NameSpaceSymbEntry[] entries;
|
314
|
+
String[] keys;
|
315
|
+
|
316
|
+
SymbMap() {
|
317
|
+
entries = new NameSpaceSymbEntry[free];
|
318
|
+
keys = new String[free];
|
319
|
+
}
|
320
|
+
|
321
|
+
void put(String key, NameSpaceSymbEntry value) {
|
322
|
+
int index = index(key);
|
323
|
+
Object oldKey = keys[index];
|
324
|
+
keys[index] = key;
|
325
|
+
entries[index] = value;
|
326
|
+
if ((oldKey == null || !oldKey.equals(key)) && (--free == 0)) {
|
327
|
+
free = entries.length;
|
328
|
+
int newCapacity = free << 2;
|
329
|
+
rehash(newCapacity);
|
330
|
+
}
|
331
|
+
}
|
332
|
+
|
333
|
+
List<NameSpaceSymbEntry> entrySet() {
|
334
|
+
List<NameSpaceSymbEntry> a = new ArrayList<NameSpaceSymbEntry>();
|
335
|
+
for (int i = 0;i < entries.length;i++) {
|
336
|
+
if ((entries[i] != null) && !("".equals(entries[i].uri))) {
|
337
|
+
a.add(entries[i]);
|
338
|
+
}
|
339
|
+
}
|
340
|
+
return a;
|
341
|
+
}
|
342
|
+
|
343
|
+
protected int index(Object obj) {
|
344
|
+
Object[] set = keys;
|
345
|
+
int length = set.length;
|
346
|
+
//abs of index
|
347
|
+
int index = (obj.hashCode() & 0x7fffffff) % length;
|
348
|
+
Object cur = set[index];
|
349
|
+
|
350
|
+
if (cur == null || (cur.equals(obj))) {
|
351
|
+
return index;
|
352
|
+
}
|
353
|
+
length--;
|
354
|
+
do {
|
355
|
+
index = index == length ? 0 : ++index;
|
356
|
+
cur = set[index];
|
357
|
+
} while (cur != null && (!cur.equals(obj)));
|
358
|
+
return index;
|
359
|
+
}
|
360
|
+
|
361
|
+
/**
|
362
|
+
* rehashes the map to the new capacity.
|
363
|
+
*
|
364
|
+
* @param newCapacity an <code>int</code> value
|
365
|
+
*/
|
366
|
+
protected void rehash(int newCapacity) {
|
367
|
+
int oldCapacity = keys.length;
|
368
|
+
String oldKeys[] = keys;
|
369
|
+
NameSpaceSymbEntry oldVals[] = entries;
|
370
|
+
|
371
|
+
keys = new String[newCapacity];
|
372
|
+
entries = new NameSpaceSymbEntry[newCapacity];
|
373
|
+
|
374
|
+
for (int i = oldCapacity; i-- > 0;) {
|
375
|
+
if (oldKeys[i] != null) {
|
376
|
+
String o = oldKeys[i];
|
377
|
+
int index = index(o);
|
378
|
+
keys[index] = o;
|
379
|
+
entries[index] = oldVals[i];
|
380
|
+
}
|
381
|
+
}
|
382
|
+
}
|
383
|
+
|
384
|
+
NameSpaceSymbEntry get(String key) {
|
385
|
+
return entries[index(key)];
|
386
|
+
}
|
387
|
+
|
388
|
+
protected Object clone() {
|
389
|
+
try {
|
390
|
+
SymbMap copy = (SymbMap) super.clone();
|
391
|
+
copy.entries = new NameSpaceSymbEntry[entries.length];
|
392
|
+
System.arraycopy(entries, 0, copy.entries, 0, entries.length);
|
393
|
+
copy.keys = new String[keys.length];
|
394
|
+
System.arraycopy(keys, 0, copy.keys, 0, keys.length);
|
395
|
+
|
396
|
+
return copy;
|
397
|
+
} catch (CloneNotSupportedException e) {
|
398
|
+
e.printStackTrace();
|
399
|
+
}
|
400
|
+
return null;
|
401
|
+
}
|
402
|
+
}
|