Nokogiri_precompiled_aarch64_dedshit 1.14.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +44 -0
- data/LICENSE-DEPENDENCIES.md +2224 -0
- data/LICENSE.md +9 -0
- data/README.md +287 -0
- data/bin/nokogiri +131 -0
- data/dependencies.yml +41 -0
- data/ext/java/nokogiri/Html4Document.java +157 -0
- data/ext/java/nokogiri/Html4ElementDescription.java +133 -0
- data/ext/java/nokogiri/Html4EntityLookup.java +63 -0
- data/ext/java/nokogiri/Html4SaxParserContext.java +289 -0
- data/ext/java/nokogiri/Html4SaxPushParser.java +213 -0
- data/ext/java/nokogiri/NokogiriService.java +613 -0
- data/ext/java/nokogiri/XmlAttr.java +154 -0
- data/ext/java/nokogiri/XmlAttributeDecl.java +119 -0
- data/ext/java/nokogiri/XmlCdata.java +60 -0
- data/ext/java/nokogiri/XmlComment.java +77 -0
- data/ext/java/nokogiri/XmlDocument.java +705 -0
- data/ext/java/nokogiri/XmlDocumentFragment.java +163 -0
- data/ext/java/nokogiri/XmlDtd.java +516 -0
- data/ext/java/nokogiri/XmlElement.java +44 -0
- data/ext/java/nokogiri/XmlElementContent.java +412 -0
- data/ext/java/nokogiri/XmlElementDecl.java +148 -0
- data/ext/java/nokogiri/XmlEntityDecl.java +151 -0
- data/ext/java/nokogiri/XmlEntityReference.java +79 -0
- data/ext/java/nokogiri/XmlNamespace.java +193 -0
- data/ext/java/nokogiri/XmlNode.java +1938 -0
- data/ext/java/nokogiri/XmlNodeSet.java +463 -0
- data/ext/java/nokogiri/XmlProcessingInstruction.java +79 -0
- data/ext/java/nokogiri/XmlReader.java +615 -0
- data/ext/java/nokogiri/XmlRelaxng.java +133 -0
- data/ext/java/nokogiri/XmlSaxParserContext.java +329 -0
- data/ext/java/nokogiri/XmlSaxPushParser.java +288 -0
- data/ext/java/nokogiri/XmlSchema.java +423 -0
- data/ext/java/nokogiri/XmlSyntaxError.java +137 -0
- data/ext/java/nokogiri/XmlText.java +90 -0
- data/ext/java/nokogiri/XmlXpathContext.java +305 -0
- data/ext/java/nokogiri/XsltStylesheet.java +368 -0
- data/ext/java/nokogiri/internals/ClosedStreamException.java +13 -0
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +252 -0
- data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +27 -0
- data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +178 -0
- data/ext/java/nokogiri/internals/NokogiriDomParser.java +99 -0
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +140 -0
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +65 -0
- data/ext/java/nokogiri/internals/NokogiriHandler.java +339 -0
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +817 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +228 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +110 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +86 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +107 -0
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +62 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +165 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +50 -0
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +37 -0
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +70 -0
- data/ext/java/nokogiri/internals/ParserContext.java +262 -0
- data/ext/java/nokogiri/internals/ReaderNode.java +564 -0
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +865 -0
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +50 -0
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +174 -0
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +11 -0
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +265 -0
- data/ext/java/nokogiri/internals/XmlSaxParser.java +40 -0
- data/ext/java/nokogiri/internals/c14n/AttrCompare.java +122 -0
- data/ext/java/nokogiri/internals/c14n/C14nHelper.java +178 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +43 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +106 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +278 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +664 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +45 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +45 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +388 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +308 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +47 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +51 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +51 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +50 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +660 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +194 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +77 -0
- data/ext/java/nokogiri/internals/c14n/Constants.java +45 -0
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +325 -0
- data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +106 -0
- data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +86 -0
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +181 -0
- data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +87 -0
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +452 -0
- data/ext/java/nokogiri/internals/c14n/NodeFilter.java +52 -0
- data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +190 -0
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +540 -0
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1712 -0
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +737 -0
- data/ext/nokogiri/depend +38 -0
- data/ext/nokogiri/extconf.rb +1086 -0
- data/ext/nokogiri/gumbo.c +594 -0
- data/ext/nokogiri/html4_document.c +167 -0
- data/ext/nokogiri/html4_element_description.c +294 -0
- data/ext/nokogiri/html4_entity_lookup.c +37 -0
- data/ext/nokogiri/html4_sax_parser_context.c +116 -0
- data/ext/nokogiri/html4_sax_push_parser.c +95 -0
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +265 -0
- data/ext/nokogiri/nokogiri.h +235 -0
- data/ext/nokogiri/test_global_handlers.c +42 -0
- data/ext/nokogiri/xml_attr.c +103 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_cdata.c +57 -0
- data/ext/nokogiri/xml_comment.c +62 -0
- data/ext/nokogiri/xml_document.c +689 -0
- data/ext/nokogiri/xml_document_fragment.c +44 -0
- data/ext/nokogiri/xml_dtd.c +210 -0
- data/ext/nokogiri/xml_element_content.c +128 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_encoding_handler.c +104 -0
- data/ext/nokogiri/xml_entity_decl.c +112 -0
- data/ext/nokogiri/xml_entity_reference.c +50 -0
- data/ext/nokogiri/xml_namespace.c +186 -0
- data/ext/nokogiri/xml_node.c +2426 -0
- data/ext/nokogiri/xml_node_set.c +496 -0
- data/ext/nokogiri/xml_processing_instruction.c +54 -0
- data/ext/nokogiri/xml_reader.c +794 -0
- data/ext/nokogiri/xml_relax_ng.c +164 -0
- data/ext/nokogiri/xml_sax_parser.c +316 -0
- data/ext/nokogiri/xml_sax_parser_context.c +283 -0
- data/ext/nokogiri/xml_sax_push_parser.c +166 -0
- data/ext/nokogiri/xml_schema.c +260 -0
- data/ext/nokogiri/xml_syntax_error.c +85 -0
- data/ext/nokogiri/xml_text.c +48 -0
- data/ext/nokogiri/xml_xpath_context.c +415 -0
- data/ext/nokogiri/xslt_stylesheet.c +363 -0
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +111 -0
- data/gumbo-parser/THANKS +27 -0
- data/gumbo-parser/src/Makefile +34 -0
- data/gumbo-parser/src/README.md +41 -0
- data/gumbo-parser/src/ascii.c +75 -0
- data/gumbo-parser/src/ascii.h +115 -0
- data/gumbo-parser/src/attribute.c +42 -0
- data/gumbo-parser/src/attribute.h +17 -0
- data/gumbo-parser/src/char_ref.c +22225 -0
- data/gumbo-parser/src/char_ref.h +29 -0
- data/gumbo-parser/src/char_ref.rl +2154 -0
- data/gumbo-parser/src/error.c +626 -0
- data/gumbo-parser/src/error.h +148 -0
- data/gumbo-parser/src/foreign_attrs.c +104 -0
- data/gumbo-parser/src/foreign_attrs.gperf +27 -0
- data/gumbo-parser/src/insertion_mode.h +33 -0
- data/gumbo-parser/src/macros.h +91 -0
- data/gumbo-parser/src/nokogiri_gumbo.h +944 -0
- data/gumbo-parser/src/parser.c +4878 -0
- data/gumbo-parser/src/parser.h +41 -0
- data/gumbo-parser/src/replacement.h +33 -0
- data/gumbo-parser/src/string_buffer.c +103 -0
- data/gumbo-parser/src/string_buffer.h +68 -0
- data/gumbo-parser/src/string_piece.c +48 -0
- data/gumbo-parser/src/svg_attrs.c +174 -0
- data/gumbo-parser/src/svg_attrs.gperf +77 -0
- data/gumbo-parser/src/svg_tags.c +137 -0
- data/gumbo-parser/src/svg_tags.gperf +55 -0
- data/gumbo-parser/src/tag.c +223 -0
- data/gumbo-parser/src/tag_lookup.c +382 -0
- data/gumbo-parser/src/tag_lookup.gperf +170 -0
- data/gumbo-parser/src/tag_lookup.h +13 -0
- data/gumbo-parser/src/token_buffer.c +79 -0
- data/gumbo-parser/src/token_buffer.h +71 -0
- data/gumbo-parser/src/token_type.h +17 -0
- data/gumbo-parser/src/tokenizer.c +3463 -0
- data/gumbo-parser/src/tokenizer.h +112 -0
- data/gumbo-parser/src/tokenizer_states.h +339 -0
- data/gumbo-parser/src/utf8.c +245 -0
- data/gumbo-parser/src/utf8.h +164 -0
- data/gumbo-parser/src/util.c +66 -0
- data/gumbo-parser/src/util.h +34 -0
- data/gumbo-parser/src/vector.c +111 -0
- data/gumbo-parser/src/vector.h +45 -0
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +54 -0
- data/lib/nokogiri/css/parser.rb +770 -0
- data/lib/nokogiri/css/parser.y +277 -0
- data/lib/nokogiri/css/parser_extras.rb +96 -0
- data/lib/nokogiri/css/syntax_error.rb +9 -0
- data/lib/nokogiri/css/tokenizer.rb +155 -0
- data/lib/nokogiri/css/tokenizer.rex +56 -0
- data/lib/nokogiri/css/xpath_visitor.rb +359 -0
- data/lib/nokogiri/css.rb +66 -0
- data/lib/nokogiri/decorators/slop.rb +44 -0
- data/lib/nokogiri/encoding_handler.rb +57 -0
- data/lib/nokogiri/extension.rb +32 -0
- data/lib/nokogiri/gumbo.rb +15 -0
- data/lib/nokogiri/html.rb +48 -0
- data/lib/nokogiri/html4/builder.rb +37 -0
- data/lib/nokogiri/html4/document.rb +214 -0
- data/lib/nokogiri/html4/document_fragment.rb +54 -0
- data/lib/nokogiri/html4/element_description.rb +25 -0
- data/lib/nokogiri/html4/element_description_defaults.rb +572 -0
- data/lib/nokogiri/html4/encoding_reader.rb +121 -0
- data/lib/nokogiri/html4/entity_lookup.rb +15 -0
- data/lib/nokogiri/html4/sax/parser.rb +63 -0
- data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
- data/lib/nokogiri/html4.rb +47 -0
- data/lib/nokogiri/html5/document.rb +168 -0
- data/lib/nokogiri/html5/document_fragment.rb +90 -0
- data/lib/nokogiri/html5/node.rb +98 -0
- data/lib/nokogiri/html5.rb +389 -0
- data/lib/nokogiri/jruby/dependencies.rb +3 -0
- data/lib/nokogiri/jruby/isorelax/isorelax/20030108/isorelax-20030108.jar +0 -0
- data/lib/nokogiri/jruby/net/sf/saxon/Saxon-HE/9.6.0-4/Saxon-HE-9.6.0-4.jar +0 -0
- data/lib/nokogiri/jruby/net/sourceforge/htmlunit/neko-htmlunit/2.63.0/neko-htmlunit-2.63.0.jar +0 -0
- data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
- data/lib/nokogiri/jruby/nu/validator/jing/20200702VNU/jing-20200702VNU.jar +0 -0
- data/lib/nokogiri/jruby/org/nokogiri/nekodtd/0.1.11.noko2/nekodtd-0.1.11.noko2.jar +0 -0
- data/lib/nokogiri/jruby/xalan/serializer/2.7.3/serializer-2.7.3.jar +0 -0
- data/lib/nokogiri/jruby/xalan/xalan/2.7.3/xalan-2.7.3.jar +0 -0
- data/lib/nokogiri/jruby/xerces/xercesImpl/2.12.2/xercesImpl-2.12.2.jar +0 -0
- data/lib/nokogiri/jruby/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar +0 -0
- data/lib/nokogiri/syntax_error.rb +6 -0
- data/lib/nokogiri/version/constant.rb +6 -0
- data/lib/nokogiri/version/info.rb +223 -0
- data/lib/nokogiri/version.rb +4 -0
- data/lib/nokogiri/xml/attr.rb +66 -0
- data/lib/nokogiri/xml/attribute_decl.rb +20 -0
- data/lib/nokogiri/xml/builder.rb +487 -0
- data/lib/nokogiri/xml/cdata.rb +13 -0
- data/lib/nokogiri/xml/character_data.rb +9 -0
- data/lib/nokogiri/xml/document.rb +471 -0
- data/lib/nokogiri/xml/document_fragment.rb +205 -0
- data/lib/nokogiri/xml/dtd.rb +34 -0
- data/lib/nokogiri/xml/element_content.rb +38 -0
- data/lib/nokogiri/xml/element_decl.rb +15 -0
- data/lib/nokogiri/xml/entity_decl.rb +21 -0
- data/lib/nokogiri/xml/entity_reference.rb +20 -0
- data/lib/nokogiri/xml/namespace.rb +58 -0
- data/lib/nokogiri/xml/node/save_options.rb +68 -0
- data/lib/nokogiri/xml/node.rb +1563 -0
- data/lib/nokogiri/xml/node_set.rb +447 -0
- data/lib/nokogiri/xml/notation.rb +19 -0
- data/lib/nokogiri/xml/parse_options.rb +213 -0
- data/lib/nokogiri/xml/pp/character_data.rb +21 -0
- data/lib/nokogiri/xml/pp/node.rb +57 -0
- data/lib/nokogiri/xml/pp.rb +4 -0
- data/lib/nokogiri/xml/processing_instruction.rb +11 -0
- data/lib/nokogiri/xml/reader.rb +105 -0
- data/lib/nokogiri/xml/relax_ng.rb +38 -0
- data/lib/nokogiri/xml/sax/document.rb +167 -0
- data/lib/nokogiri/xml/sax/parser.rb +125 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +21 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
- data/lib/nokogiri/xml/sax.rb +6 -0
- data/lib/nokogiri/xml/schema.rb +73 -0
- data/lib/nokogiri/xml/searchable.rb +270 -0
- data/lib/nokogiri/xml/syntax_error.rb +72 -0
- data/lib/nokogiri/xml/text.rb +11 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +13 -0
- data/lib/nokogiri/xml/xpath.rb +21 -0
- data/lib/nokogiri/xml/xpath_context.rb +16 -0
- data/lib/nokogiri/xml.rb +76 -0
- data/lib/nokogiri/xslt/stylesheet.rb +27 -0
- data/lib/nokogiri/xslt.rb +65 -0
- data/lib/nokogiri.rb +120 -0
- data/lib/xsd/xmlparser/nokogiri.rb +106 -0
- metadata +391 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
package nokogiri.internals;
|
2
|
+
|
3
|
+
import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
|
4
|
+
import nokogiri.NokogiriService;
|
5
|
+
import nokogiri.XmlSyntaxError;
|
6
|
+
|
7
|
+
import org.jruby.Ruby;
|
8
|
+
import org.jruby.RubyArray;
|
9
|
+
import org.xml.sax.ErrorHandler;
|
10
|
+
import org.xml.sax.SAXException;
|
11
|
+
import org.xml.sax.SAXParseException;
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Error handler for Relax and W3C XML Schema.
|
15
|
+
*
|
16
|
+
* @author sergio
|
17
|
+
* @author Yoko Harada <yokolet@gmail.com>
|
18
|
+
*/
|
19
|
+
public class SchemaErrorHandler implements ErrorHandler
|
20
|
+
{
|
21
|
+
|
22
|
+
private final Ruby runtime;
|
23
|
+
final RubyArray<?> errors;
|
24
|
+
|
25
|
+
public
|
26
|
+
SchemaErrorHandler(Ruby ruby, RubyArray<?> array)
|
27
|
+
{
|
28
|
+
this.runtime = ruby;
|
29
|
+
this.errors = array;
|
30
|
+
}
|
31
|
+
|
32
|
+
public void
|
33
|
+
warning(SAXParseException ex) throws SAXException
|
34
|
+
{
|
35
|
+
errors.append(XmlSyntaxError.createWarning(runtime, ex));
|
36
|
+
}
|
37
|
+
|
38
|
+
public void
|
39
|
+
error(SAXParseException ex) throws SAXException
|
40
|
+
{
|
41
|
+
errors.append(XmlSyntaxError.createError(runtime, ex));
|
42
|
+
}
|
43
|
+
|
44
|
+
public void
|
45
|
+
fatalError(SAXParseException ex) throws SAXException
|
46
|
+
{
|
47
|
+
throw ex;
|
48
|
+
}
|
49
|
+
|
50
|
+
}
|
@@ -0,0 +1,174 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2017 [Karol Bucek](http://kares.org/)
|
3
|
+
*
|
4
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
5
|
+
* or more contributor license agreements. See the NOTICE file
|
6
|
+
* distributed with this work for additional information
|
7
|
+
* regarding copyright ownership. The ASF licenses this file
|
8
|
+
* to you under the Apache License, Version 2.0 (the "License");
|
9
|
+
* you may not use this file except in compliance with the License.
|
10
|
+
* You may obtain a copy of the License at
|
11
|
+
*
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
*
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
* See the License for the specific language governing permissions and
|
18
|
+
* limitations under the License.
|
19
|
+
*/
|
20
|
+
package nokogiri.internals;
|
21
|
+
|
22
|
+
import javax.xml.transform.dom.DOMSource;
|
23
|
+
|
24
|
+
import org.apache.xml.dtm.DTM;
|
25
|
+
import nokogiri.internals.dom2dtm.DOM2DTM;
|
26
|
+
import nokogiri.internals.dom2dtm.DOM2DTMdefaultNamespaceDeclarationNode;
|
27
|
+
import org.apache.xml.dtm.DTMWSFilter;
|
28
|
+
import org.apache.xml.res.XMLErrorResources;
|
29
|
+
import org.apache.xml.res.XMLMessages;
|
30
|
+
import org.w3c.dom.Node;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* @author kares
|
34
|
+
*/
|
35
|
+
public final class XalanDTMManagerPatch extends org.apache.xml.dtm.ref.DTMManagerDefault
|
36
|
+
{
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Given a W3C DOM node, try and return a DTM handle.
|
40
|
+
* Note: calling this may be non-optimal, and there is no guarantee that
|
41
|
+
* the node will be found in any particular DTM.
|
42
|
+
*
|
43
|
+
* @param node Non-null reference to a DOM node.
|
44
|
+
*
|
45
|
+
* @return a valid DTM handle.
|
46
|
+
*/
|
47
|
+
@Override
|
48
|
+
public /* synchronized */ int
|
49
|
+
getDTMHandleFromNode(org.w3c.dom.Node node)
|
50
|
+
{
|
51
|
+
//if (node == null) // "node must be non-null for getDTMHandleFromNode!");
|
52
|
+
// throw new IllegalArgumentException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NODE_NON_NULL, null));
|
53
|
+
assert node != null;
|
54
|
+
|
55
|
+
if (node instanceof org.apache.xml.dtm.ref.DTMNodeProxy) {
|
56
|
+
return ((org.apache.xml.dtm.ref.DTMNodeProxy) node).getDTMNodeNumber();
|
57
|
+
}
|
58
|
+
|
59
|
+
// Find the DOM2DTMs wrapped around this Document (if any)
|
60
|
+
// and check whether they contain the Node in question.
|
61
|
+
//
|
62
|
+
// NOTE that since a DOM2DTM may represent a subtree rather
|
63
|
+
// than a full document, we have to be prepared to check more
|
64
|
+
// than one -- and there is no guarantee that we will find
|
65
|
+
// one that contains ancestors or siblings of the node we're
|
66
|
+
// seeking.
|
67
|
+
//
|
68
|
+
// %REVIEW% We could search for the one which contains this
|
69
|
+
// node at the deepest level, and thus covers the widest
|
70
|
+
// subtree, but that's going to entail additional work
|
71
|
+
// checking more DTMs... and getHandleOfNode is not a
|
72
|
+
// cheap operation in most implementations.
|
73
|
+
//
|
74
|
+
// TODO: %REVIEW% If overflow addressing, we may recheck a DTM
|
75
|
+
// already examined. Ouch. But with the increased number of DTMs,
|
76
|
+
// scanning back to check this is painful.
|
77
|
+
// POSSIBLE SOLUTIONS:
|
78
|
+
// Generate a list of _unique_ DTM objects?
|
79
|
+
// Have each DTM cache last DOM node search?
|
80
|
+
for (int i = 0; i < m_dtms.length; i++) {
|
81
|
+
DTM thisDTM = m_dtms[i];
|
82
|
+
if (thisDTM instanceof DOM2DTM) {
|
83
|
+
int handle = ((DOM2DTM) thisDTM).getHandleOfNode(node);
|
84
|
+
if (handle != DTM.NULL) {
|
85
|
+
return handle;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
// Not found; generate a new DTM.
|
91
|
+
//
|
92
|
+
// %REVIEW% Is this really desirable, or should we return null
|
93
|
+
// and make folks explicitly instantiate from a DOMSource? The
|
94
|
+
// latter is more work but gives the caller the opportunity to
|
95
|
+
// explicitly add the DTM to a DTMManager... and thus to know when
|
96
|
+
// it can be discarded again, which is something we need to pay much
|
97
|
+
// more attention to. (Especially since only DTMs which are assigned
|
98
|
+
// to a manager can use the overflow addressing scheme.)
|
99
|
+
//
|
100
|
+
// %BUG% If the source node was a DOM2DTM$defaultNamespaceDeclarationNode
|
101
|
+
// and the DTM wasn't registered with this DTMManager, we will create
|
102
|
+
// a new DTM and _still_ not be able to find the node (since it will
|
103
|
+
// be resynthesized). Another reason to push hard on making all DTMs
|
104
|
+
// be managed DTMs.
|
105
|
+
|
106
|
+
// Since the real root of our tree may be a DocumentFragment, we need to
|
107
|
+
// use getParent to find the root, instead of getOwnerDocument. Otherwise
|
108
|
+
// DOM2DTM#getHandleOfNode will be very unhappy.
|
109
|
+
Node root = node;
|
110
|
+
int rootType = root.getNodeType();
|
111
|
+
Node p = (rootType == Node.ATTRIBUTE_NODE) ? ((org.w3c.dom.Attr) root).getOwnerElement() : root.getParentNode();
|
112
|
+
for (; p != null; p = p.getParentNode()) { root = p; }
|
113
|
+
|
114
|
+
// DOM2DTM dtm = (DOM2DTM) getDTM(new DOMSource(root), false, null);
|
115
|
+
DOM2DTM dtm = getDTM(new DOMSource(root), false, null/*, true, true*/);
|
116
|
+
|
117
|
+
int handle;
|
118
|
+
|
119
|
+
if (node instanceof org.apache.xml.dtm.ref.dom2dtm.DOM2DTMdefaultNamespaceDeclarationNode
|
120
|
+
|| node instanceof DOM2DTMdefaultNamespaceDeclarationNode) {
|
121
|
+
// Can't return the same node since it's unique to a specific DTM,
|
122
|
+
// but can return the equivalent node -- find the corresponding
|
123
|
+
// Document Element, then ask it for the xml: namespace decl.
|
124
|
+
handle = dtm.getHandleOfNode(((org.w3c.dom.Attr) node).getOwnerElement());
|
125
|
+
handle = dtm.getAttributeNode(handle, node.getNamespaceURI(), node.getLocalName());
|
126
|
+
} else {
|
127
|
+
handle = dtm.getHandleOfNode(node);
|
128
|
+
|
129
|
+
rootType = root.getNodeType();
|
130
|
+
// Is Node actually within the same document? If not, don't search!
|
131
|
+
// This would be easier if m_root was always the Document node, but
|
132
|
+
// we decided to allow wrapping a DTM around a subtree.
|
133
|
+
if ((root == node) ||
|
134
|
+
(rootType == Node.DOCUMENT_NODE && root == node.getOwnerDocument()) ||
|
135
|
+
(rootType != Node.DOCUMENT_NODE && root.getOwnerDocument() == node.getOwnerDocument())
|
136
|
+
) {
|
137
|
+
// If node _is_ in m_root's tree, find its handle
|
138
|
+
//
|
139
|
+
// %OPT% This check may be improved significantly when DOM
|
140
|
+
// Level 3 nodeKey and relative-order tests become
|
141
|
+
// available!
|
142
|
+
for (Node cursor = node; cursor != null;
|
143
|
+
cursor = (cursor.getNodeType() != Node.ATTRIBUTE_NODE)
|
144
|
+
? cursor.getParentNode()
|
145
|
+
: ((org.w3c.dom.Attr)cursor).getOwnerElement()) {
|
146
|
+
if (cursor == root) {
|
147
|
+
// We know this node; find its handle.
|
148
|
+
return (dtm).getHandleFromNode(node);
|
149
|
+
}
|
150
|
+
} // for ancestors of node
|
151
|
+
} // if node and m_root in same Document
|
152
|
+
}
|
153
|
+
|
154
|
+
if (DTM.NULL == handle) {
|
155
|
+
throw new RuntimeException(XMLMessages.createXMLMessage(XMLErrorResources.ER_COULD_NOT_RESOLVE_NODE,
|
156
|
+
null)); //"Could not resolve the node to a handle!");
|
157
|
+
}
|
158
|
+
|
159
|
+
return handle;
|
160
|
+
}
|
161
|
+
|
162
|
+
private DOM2DTM
|
163
|
+
getDTM(DOMSource source, boolean unique, DTMWSFilter whiteSpaceFilter/*, boolean incremental, boolean doIndexing*/)
|
164
|
+
{
|
165
|
+
int dtmPos = getFirstFreeDTMID();
|
166
|
+
int documentID = dtmPos << IDENT_DTM_NODE_BITS;
|
167
|
+
|
168
|
+
DOM2DTM dtm = new DOM2DTM(this, source, documentID, whiteSpaceFilter, m_xsf, true);
|
169
|
+
|
170
|
+
addDTM(dtm, dtmPos, 0);
|
171
|
+
return dtm;
|
172
|
+
}
|
173
|
+
|
174
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
package nokogiri.internals;
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Interface for receiving xmlDecl information.
|
5
|
+
*
|
6
|
+
* @author Patrick Mahoney <pat@polycrystal.org>
|
7
|
+
*/
|
8
|
+
public interface XmlDeclHandler
|
9
|
+
{
|
10
|
+
public void xmlDecl(String version, String encoding, String standalone);
|
11
|
+
}
|
@@ -0,0 +1,265 @@
|
|
1
|
+
package nokogiri.internals;
|
2
|
+
|
3
|
+
import nokogiri.XmlDocument;
|
4
|
+
import nokogiri.XmlDtd;
|
5
|
+
import nokogiri.XmlSyntaxError;
|
6
|
+
import org.apache.xerces.parsers.DOMParser;
|
7
|
+
import org.jruby.*;
|
8
|
+
import org.jruby.exceptions.RaiseException;
|
9
|
+
import org.jruby.runtime.Helpers;
|
10
|
+
import org.jruby.runtime.ThreadContext;
|
11
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
12
|
+
import org.w3c.dom.Document;
|
13
|
+
import org.w3c.dom.Node;
|
14
|
+
import org.w3c.dom.NodeList;
|
15
|
+
import org.xml.sax.SAXException;
|
16
|
+
|
17
|
+
import java.io.IOException;
|
18
|
+
import java.util.ArrayList;
|
19
|
+
import java.util.List;
|
20
|
+
|
21
|
+
import static nokogiri.internals.NokogiriHelpers.isBlank;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Parser class for XML DOM processing. This class actually parses XML document
|
25
|
+
* and creates DOM tree in Java side. However, DOM tree in Ruby side is not since
|
26
|
+
* we delay creating objects for performance.
|
27
|
+
*
|
28
|
+
* @author sergio
|
29
|
+
* @author Yoko Harada <yokolet@gmail.com>
|
30
|
+
*/
|
31
|
+
public class XmlDomParserContext extends ParserContext
|
32
|
+
{
|
33
|
+
private static final long serialVersionUID = 1L;
|
34
|
+
|
35
|
+
protected static final String FEATURE_LOAD_EXTERNAL_DTD =
|
36
|
+
"http://apache.org/xml/features/nonvalidating/load-external-dtd";
|
37
|
+
protected static final String FEATURE_LOAD_DTD_GRAMMAR =
|
38
|
+
"http://apache.org/xml/features/nonvalidating/load-dtd-grammar";
|
39
|
+
protected static final String FEATURE_INCLUDE_IGNORABLE_WHITESPACE =
|
40
|
+
"http://apache.org/xml/features/dom/include-ignorable-whitespace";
|
41
|
+
protected static final String CONTINUE_AFTER_FATAL_ERROR =
|
42
|
+
"http://apache.org/xml/features/continue-after-fatal-error";
|
43
|
+
protected static final String FEATURE_NOT_EXPAND_ENTITY =
|
44
|
+
"http://apache.org/xml/features/dom/create-entity-ref-nodes";
|
45
|
+
protected static final String FEATURE_VALIDATION = "http://xml.org/sax/features/validation";
|
46
|
+
private static final String SECURITY_MANAGER = "http://apache.org/xml/properties/security-manager";
|
47
|
+
|
48
|
+
protected ParserContext.Options options;
|
49
|
+
protected DOMParser parser;
|
50
|
+
protected NokogiriErrorHandler errorHandler;
|
51
|
+
protected IRubyObject ruby_encoding;
|
52
|
+
|
53
|
+
public
|
54
|
+
XmlDomParserContext(Ruby runtime, IRubyObject options)
|
55
|
+
{
|
56
|
+
this(runtime, runtime.getNil(), options);
|
57
|
+
}
|
58
|
+
|
59
|
+
public
|
60
|
+
XmlDomParserContext(Ruby runtime, IRubyObject encoding, IRubyObject options)
|
61
|
+
{
|
62
|
+
super(runtime);
|
63
|
+
this.options = new ParserContext.Options(RubyFixnum.fix2long(options));
|
64
|
+
java_encoding = NokogiriHelpers.getValidEncodingOrNull(encoding);
|
65
|
+
ruby_encoding = encoding;
|
66
|
+
initErrorHandler(runtime);
|
67
|
+
initParser(runtime);
|
68
|
+
}
|
69
|
+
|
70
|
+
protected void
|
71
|
+
initErrorHandler(Ruby runtime)
|
72
|
+
{
|
73
|
+
if (options.recover) {
|
74
|
+
errorHandler = new NokogiriNonStrictErrorHandler(runtime, options.noError, options.noWarning);
|
75
|
+
} else {
|
76
|
+
errorHandler = new NokogiriStrictErrorHandler(runtime, options.noError, options.noWarning);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
protected void
|
81
|
+
initParser(Ruby runtime)
|
82
|
+
{
|
83
|
+
if (options.xInclude) {
|
84
|
+
System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration",
|
85
|
+
"org.apache.xerces.parsers.XIncludeParserConfiguration");
|
86
|
+
}
|
87
|
+
|
88
|
+
parser = new NokogiriDomParser(options);
|
89
|
+
parser.setErrorHandler(errorHandler);
|
90
|
+
|
91
|
+
// Fix for Issue#586. This limits entity expansion up to 100000 and nodes up to 3000.
|
92
|
+
setProperty(SECURITY_MANAGER, new org.apache.xerces.util.SecurityManager());
|
93
|
+
|
94
|
+
if (options.noBlanks) {
|
95
|
+
setFeature(FEATURE_INCLUDE_IGNORABLE_WHITESPACE, false);
|
96
|
+
}
|
97
|
+
|
98
|
+
if (options.recover) {
|
99
|
+
setFeature(CONTINUE_AFTER_FATAL_ERROR, true);
|
100
|
+
}
|
101
|
+
|
102
|
+
if (options.dtdValid) {
|
103
|
+
setFeature(FEATURE_VALIDATION, true);
|
104
|
+
}
|
105
|
+
|
106
|
+
if (!options.noEnt) {
|
107
|
+
setFeature(FEATURE_NOT_EXPAND_ENTITY, true);
|
108
|
+
}
|
109
|
+
// If we turn off loading of external DTDs complete, we don't
|
110
|
+
// getthe publicID. Instead of turning off completely, we use
|
111
|
+
// an entity resolver that returns empty documents.
|
112
|
+
if (options.dtdLoad) {
|
113
|
+
setFeature(FEATURE_LOAD_EXTERNAL_DTD, true);
|
114
|
+
setFeature(FEATURE_LOAD_DTD_GRAMMAR, true);
|
115
|
+
}
|
116
|
+
parser.setEntityResolver(new NokogiriEntityResolver(runtime, errorHandler, options));
|
117
|
+
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Convenience method that catches and ignores SAXException
|
121
|
+
* (unrecognized and unsupported exceptions).
|
122
|
+
*/
|
123
|
+
protected void
|
124
|
+
setFeature(String feature, boolean value)
|
125
|
+
{
|
126
|
+
try {
|
127
|
+
parser.setFeature(feature, value);
|
128
|
+
} catch (SAXException e) {
|
129
|
+
// ignore
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Convenience method that catches and ignores SAXException
|
135
|
+
* (unrecognized and unsupported exceptions).
|
136
|
+
*/
|
137
|
+
protected void
|
138
|
+
setProperty(String property, Object value)
|
139
|
+
{
|
140
|
+
try {
|
141
|
+
parser.setProperty(property, value);
|
142
|
+
} catch (SAXException e) {
|
143
|
+
// ignore
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
public void
|
148
|
+
addErrorsIfNecessary(ThreadContext context, XmlDocument doc)
|
149
|
+
{
|
150
|
+
doc.setInstanceVariable("@errors", mapErrors(context, errorHandler));
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
public static RubyArray<?>
|
155
|
+
mapErrors(ThreadContext context, NokogiriErrorHandler errorHandler)
|
156
|
+
{
|
157
|
+
final Ruby runtime = context.runtime;
|
158
|
+
final List<RubyException> errors = errorHandler.getErrors();
|
159
|
+
final IRubyObject[] errorsAry = new IRubyObject[errors.size()];
|
160
|
+
for (int i = 0; i < errors.size(); i++) {
|
161
|
+
errorsAry[i] = errors.get(i);
|
162
|
+
}
|
163
|
+
return runtime.newArrayNoCopy(errorsAry);
|
164
|
+
}
|
165
|
+
|
166
|
+
public XmlDocument
|
167
|
+
getDocumentWithErrorsOrRaiseException(ThreadContext context, RubyClass klazz, Exception ex)
|
168
|
+
{
|
169
|
+
if (options.recover) {
|
170
|
+
XmlDocument xmlDocument = getInterruptedOrNewXmlDocument(context, klazz);
|
171
|
+
this.addErrorsIfNecessary(context, xmlDocument);
|
172
|
+
XmlSyntaxError xmlSyntaxError = XmlSyntaxError.createXMLSyntaxError(context.runtime);
|
173
|
+
xmlSyntaxError.setException(ex);
|
174
|
+
((RubyArray) xmlDocument.getInstanceVariable("@errors")).append(xmlSyntaxError);
|
175
|
+
return xmlDocument;
|
176
|
+
} else {
|
177
|
+
XmlSyntaxError xmlSyntaxError = XmlSyntaxError.createXMLSyntaxError(context.runtime);
|
178
|
+
xmlSyntaxError.setException(ex);
|
179
|
+
throw xmlSyntaxError.toThrowable();
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
private XmlDocument
|
184
|
+
getInterruptedOrNewXmlDocument(ThreadContext context, RubyClass klass)
|
185
|
+
{
|
186
|
+
Document document = parser.getDocument();
|
187
|
+
XmlDocument xmlDocument = new XmlDocument(context.runtime, klass, document);
|
188
|
+
xmlDocument.setEncoding(ruby_encoding);
|
189
|
+
return xmlDocument;
|
190
|
+
}
|
191
|
+
|
192
|
+
/**
|
193
|
+
* This method is broken out so that HtmlDomParserContext can
|
194
|
+
* override it.
|
195
|
+
*/
|
196
|
+
protected XmlDocument
|
197
|
+
wrapDocument(ThreadContext context, RubyClass klass, Document doc)
|
198
|
+
{
|
199
|
+
XmlDocument xmlDocument = new XmlDocument(context.runtime, klass, doc);
|
200
|
+
Helpers.invoke(context, xmlDocument, "initialize");
|
201
|
+
xmlDocument.setEncoding(ruby_encoding);
|
202
|
+
|
203
|
+
if (options.dtdLoad) {
|
204
|
+
IRubyObject dtd = XmlDtd.newFromExternalSubset(context.runtime, doc);
|
205
|
+
if (!dtd.isNil()) {
|
206
|
+
doc.setUserData(XmlDocument.DTD_EXTERNAL_SUBSET, (XmlDtd) dtd, null);
|
207
|
+
}
|
208
|
+
}
|
209
|
+
return xmlDocument;
|
210
|
+
}
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Must call setInputSource() before this method.
|
214
|
+
*/
|
215
|
+
public XmlDocument
|
216
|
+
parse(ThreadContext context, RubyClass klass, IRubyObject url)
|
217
|
+
{
|
218
|
+
XmlDocument xmlDoc;
|
219
|
+
try {
|
220
|
+
Document doc = do_parse();
|
221
|
+
xmlDoc = wrapDocument(context, klass, doc);
|
222
|
+
xmlDoc.setUrl(url);
|
223
|
+
addErrorsIfNecessary(context, xmlDoc);
|
224
|
+
return xmlDoc;
|
225
|
+
} catch (SAXException e) {
|
226
|
+
return getDocumentWithErrorsOrRaiseException(context, klass, e);
|
227
|
+
} catch (IOException e) {
|
228
|
+
return getDocumentWithErrorsOrRaiseException(context, klass, e);
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
protected Document
|
233
|
+
do_parse() throws SAXException, IOException
|
234
|
+
{
|
235
|
+
try {
|
236
|
+
parser.parse(getInputSource());
|
237
|
+
} catch (NullPointerException ex) {
|
238
|
+
// FIXME: this is really a hack to fix #838. Xerces will throw a NullPointerException
|
239
|
+
// if we tried to parse '<? ?>'. We should submit a patch to Xerces.
|
240
|
+
}
|
241
|
+
if (options.noBlanks) {
|
242
|
+
List<Node> emptyNodes = new ArrayList<Node>();
|
243
|
+
findEmptyTexts(parser.getDocument(), emptyNodes);
|
244
|
+
if (emptyNodes.size() > 0) {
|
245
|
+
for (Node node : emptyNodes) {
|
246
|
+
node.getParentNode().removeChild(node);
|
247
|
+
}
|
248
|
+
}
|
249
|
+
}
|
250
|
+
return parser.getDocument();
|
251
|
+
}
|
252
|
+
|
253
|
+
private static void
|
254
|
+
findEmptyTexts(Node node, List<Node> emptyNodes)
|
255
|
+
{
|
256
|
+
if (node.getNodeType() == Node.TEXT_NODE && isBlank(node.getTextContent())) {
|
257
|
+
emptyNodes.add(node);
|
258
|
+
} else {
|
259
|
+
NodeList children = node.getChildNodes();
|
260
|
+
for (int i = 0; i < children.getLength(); i++) {
|
261
|
+
findEmptyTexts(children.item(i), emptyNodes);
|
262
|
+
}
|
263
|
+
}
|
264
|
+
}
|
265
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
package nokogiri.internals;
|
2
|
+
|
3
|
+
import org.apache.xerces.parsers.SAXParser;
|
4
|
+
import org.apache.xerces.xni.Augmentations;
|
5
|
+
import org.apache.xerces.xni.XNIException;
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Extends SAXParser in order to receive xmlDecl events and pass them
|
9
|
+
* on to a handler.
|
10
|
+
*
|
11
|
+
* @author Patrick Mahoney <pat@polycrystal.org>
|
12
|
+
*/
|
13
|
+
public class XmlSaxParser extends SAXParser
|
14
|
+
{
|
15
|
+
|
16
|
+
protected XmlDeclHandler xmlDeclHandler = null;
|
17
|
+
|
18
|
+
public
|
19
|
+
XmlSaxParser()
|
20
|
+
{
|
21
|
+
super();
|
22
|
+
}
|
23
|
+
|
24
|
+
public void
|
25
|
+
setXmlDeclHandler(XmlDeclHandler xmlDeclHandler)
|
26
|
+
{
|
27
|
+
this.xmlDeclHandler = xmlDeclHandler;
|
28
|
+
}
|
29
|
+
|
30
|
+
@Override
|
31
|
+
public void
|
32
|
+
xmlDecl(String version, String encoding, String standalone,
|
33
|
+
Augmentations augs) throws XNIException
|
34
|
+
{
|
35
|
+
super.xmlDecl(version, encoding, standalone, augs);
|
36
|
+
if (xmlDeclHandler != null) {
|
37
|
+
xmlDeclHandler.xmlDecl(version, encoding, standalone);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
@@ -0,0 +1,122 @@
|
|
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.io.Serializable;
|
22
|
+
import java.util.Comparator;
|
23
|
+
|
24
|
+
|
25
|
+
import org.w3c.dom.Attr;
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Compares two attributes based on the C14n specification.
|
29
|
+
*
|
30
|
+
* <UL>
|
31
|
+
* <LI>Namespace nodes have a lesser document order position than attribute
|
32
|
+
* nodes.
|
33
|
+
* <LI> An element's namespace nodes are sorted lexicographically by
|
34
|
+
* local name (the default namespace node, if one exists, has no
|
35
|
+
* local name and is therefore lexicographically least).
|
36
|
+
* <LI> An element's attribute nodes are sorted lexicographically with
|
37
|
+
* namespace URI as the primary key and local name as the secondary
|
38
|
+
* key (an empty namespace URI is lexicographically least).
|
39
|
+
* </UL>
|
40
|
+
*
|
41
|
+
* @author Christian Geuer-Pollmann
|
42
|
+
*/
|
43
|
+
public class AttrCompare implements Comparator<Attr>, Serializable
|
44
|
+
{
|
45
|
+
|
46
|
+
private static final long serialVersionUID = -7113259629930576230L;
|
47
|
+
private static final int ATTR0_BEFORE_ATTR1 = -1;
|
48
|
+
private static final int ATTR1_BEFORE_ATTR0 = 1;
|
49
|
+
private static final String XMLNS = Constants.NamespaceSpecNS;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Compares two attributes based on the C14n specification.
|
53
|
+
*
|
54
|
+
* <UL>
|
55
|
+
* <LI>Namespace nodes have a lesser document order position than
|
56
|
+
* attribute nodes.
|
57
|
+
* <LI> An element's namespace nodes are sorted lexicographically by
|
58
|
+
* local name (the default namespace node, if one exists, has no
|
59
|
+
* local name and is therefore lexicographically least).
|
60
|
+
* <LI> An element's attribute nodes are sorted lexicographically with
|
61
|
+
* namespace URI as the primary key and local name as the secondary
|
62
|
+
* key (an empty namespace URI is lexicographically least).
|
63
|
+
* </UL>
|
64
|
+
*
|
65
|
+
* @param attr0
|
66
|
+
* @param attr1
|
67
|
+
* @return returns a negative integer, zero, or a positive integer as
|
68
|
+
* obj0 is less than, equal to, or greater than obj1
|
69
|
+
*
|
70
|
+
*/
|
71
|
+
public int
|
72
|
+
compare(Attr attr0, Attr attr1)
|
73
|
+
{
|
74
|
+
String namespaceURI0 = attr0.getNamespaceURI();
|
75
|
+
String namespaceURI1 = attr1.getNamespaceURI();
|
76
|
+
|
77
|
+
boolean isNamespaceAttr0 = XMLNS.equals(namespaceURI0);
|
78
|
+
boolean isNamespaceAttr1 = XMLNS.equals(namespaceURI1);
|
79
|
+
|
80
|
+
if (isNamespaceAttr0) {
|
81
|
+
if (isNamespaceAttr1) {
|
82
|
+
// both are namespaces
|
83
|
+
String localname0 = attr0.getLocalName();
|
84
|
+
String localname1 = attr1.getLocalName();
|
85
|
+
|
86
|
+
if ("xmlns".equals(localname0)) {
|
87
|
+
localname0 = "";
|
88
|
+
}
|
89
|
+
|
90
|
+
if ("xmlns".equals(localname1)) {
|
91
|
+
localname1 = "";
|
92
|
+
}
|
93
|
+
|
94
|
+
return localname0.compareTo(localname1);
|
95
|
+
}
|
96
|
+
// attr0 is a namespace, attr1 is not
|
97
|
+
return ATTR0_BEFORE_ATTR1;
|
98
|
+
} else if (isNamespaceAttr1) {
|
99
|
+
// attr1 is a namespace, attr0 is not
|
100
|
+
return ATTR1_BEFORE_ATTR0;
|
101
|
+
}
|
102
|
+
|
103
|
+
// none is a namespace
|
104
|
+
if (namespaceURI0 == null) {
|
105
|
+
if (namespaceURI1 == null) {
|
106
|
+
String name0 = attr0.getName();
|
107
|
+
String name1 = attr1.getName();
|
108
|
+
return name0.compareTo(name1);
|
109
|
+
}
|
110
|
+
return ATTR0_BEFORE_ATTR1;
|
111
|
+
} else if (namespaceURI1 == null) {
|
112
|
+
return ATTR1_BEFORE_ATTR0;
|
113
|
+
}
|
114
|
+
|
115
|
+
int a = namespaceURI0.compareTo(namespaceURI1);
|
116
|
+
if (a != 0) {
|
117
|
+
return a;
|
118
|
+
}
|
119
|
+
|
120
|
+
return (attr0.getLocalName()).compareTo(attr1.getLocalName());
|
121
|
+
}
|
122
|
+
}
|