#ODFTOOLKIT-424# Patch by Nimarukan - PERFORMANCE: Reuse XMLFactories, currently created too frequently during insertNode and setTextContent
git-svn-id: https://svn.apache.org/repos/asf/incubator/odf/trunk@1811308 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/rdfa/DOMRDFaParser.java b/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/rdfa/DOMRDFaParser.java
index 889a3d5..9465c8e 100644
--- a/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/rdfa/DOMRDFaParser.java
+++ b/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/rdfa/DOMRDFaParser.java
@@ -1,20 +1,20 @@
/************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
- *
+ *
* Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
- *
+ *
* Use is subject to license terms.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
* obtain a copy of the License at http://odftoolkit.org/docs/license.txt
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
+ *
* See the License for the specific language governing permissions and
* limitations under the License.
*
@@ -23,20 +23,21 @@
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLOutputFactory;
-
import org.odftoolkit.odfdom.dom.element.text.TextBookmarkStartElement;
import org.w3c.dom.Node;
/**
* A RDFa parser for DOM
- *
+ *
*/
public class DOMRDFaParser extends RDFaParser {
+ private static final XMLOutputFactory DEFAULT_XML_OUTPUT_FACTORY = XMLOutputFactory.newFactory();
+ private static final XMLEventFactory DEFAULT_XML_EVENT_FACTORY = XMLEventFactory.newFactory();
+
public static DOMRDFaParser createInstance(JenaSink sink) {
sink.getExtractor().setForSAX(false);
- return new DOMRDFaParser(sink, XMLOutputFactory.newInstance(),
- XMLEventFactory.newInstance(), sink.getExtractor());
+ return new DOMRDFaParser(sink, sink.getExtractor());
}
public DOMRDFaParser(JenaSink sink, XMLOutputFactory outputFactory,
@@ -45,9 +46,13 @@
}
+ public DOMRDFaParser(JenaSink sink, URIExtractor extractor) {
+ this(sink, DEFAULT_XML_OUTPUT_FACTORY, DEFAULT_XML_EVENT_FACTORY, extractor);
+ }
+
/**
* Parse the RDFa in-content metadata of the node.
- *
+ *
* @param node
*/
public void parse(Node node) {
diff --git a/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/rdfa/RDFaParser.java b/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/rdfa/RDFaParser.java
index d280a1a..b8c6109 100644
--- a/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/rdfa/RDFaParser.java
+++ b/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/rdfa/RDFaParser.java
@@ -1,20 +1,20 @@
/************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
- *
+ *
* Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
- *
+ *
* Use is subject to license terms.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
* obtain a copy of the License at http://odftoolkit.org/docs/license.txt
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
+ *
* See the License for the specific language governing permissions and
* limitations under the License.
*
@@ -26,7 +26,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLOutputFactory;
@@ -34,11 +33,12 @@
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
-
import net.rootdev.javardfa.Constants;
+import net.rootdev.javardfa.ProfileCollector;
import net.rootdev.javardfa.Setting;
import net.rootdev.javardfa.literal.LiteralCollector;
-
+import net.rootdev.javardfa.uri.IRIResolver;
+import net.rootdev.javardfa.uri.URIExtractor10;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
@@ -47,7 +47,7 @@
*
*/
class RDFaParser extends net.rootdev.javardfa.Parser {
-
+
boolean ignore = false;
protected XMLEventFactory eventFactory;
@@ -60,7 +60,7 @@
protected RDFaParser(JenaSink sink, XMLOutputFactory outputFactory,
XMLEventFactory eventFactory, URIExtractor extractor) {
- super(sink);
+ super(sink, outputFactory, eventFactory, new URIExtractor10(new IRIResolver()), ProfileCollector.EMPTY_COLLECTOR);
this.sink = sink;
this.eventFactory = eventFactory;
this.settings = EnumSet.noneOf(Setting.class);
@@ -116,7 +116,7 @@
throw new RuntimeException("Streaming issue", ex);
}
}
-
+
protected void endRDFaElement(String arg0, String localname, String qname) {
if (localname.equals("bookmark-start")) {
ignore = false;
@@ -132,7 +132,7 @@
if (!literalCollector.isCollectingXML())
context = context.parent;
}
-
+
protected void writeCharacters(String value) {
if (!ignore) {
if (literalCollector.isCollecting()) {
@@ -141,11 +141,11 @@
}
}
}
-
- /**
+
+ /**
* Set the base uri of the DOM.
*/
- public void setBase(String base) {
+ public void setBase(String base) {
this.context = new EvalContext(base);
sink.setBase(context.getBase());
}
@@ -202,7 +202,7 @@
}
if (getAttributeByName(element, Constants.rev) == null
&& getAttributeByName(element, Constants.rel) == null) {
- Attribute nSubj = findAttribute(element, Constants.about);
+ Attribute nSubj = findAttribute(element, Constants.about);
if (nSubj != null) {
newSubject = extractor.getURI(element, nSubj, context);
}