You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2007/07/15 21:28:23 UTC
svn commit: r556437 - in
/xerces/java/branches/stax-dev/src/org/apache/xerces/stax:
AbstractStAXParser.java StAXFilterParser.java StAXParser.java
XMLInputFactoryImpl.java
Author: mrglavas
Date: Sun Jul 15 12:28:22 2007
New Revision: 556437
URL: http://svn.apache.org/viewvc?view=rev&rev=556437
Log:
JIRA Issue #1259:
http://issues.apache.org/jira/browse/XERCESJ-1259
Updates to the implementation from Wei Duan:
1. Add StreamFilter support.
2. Add full support for Entity Reference, and add support for DTD and CDATA.
3. Implement the close() method on the XMLStreamReader implementation.
Added:
xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXFilterParser.java (with props)
Modified:
xerces/java/branches/stax-dev/src/org/apache/xerces/stax/AbstractStAXParser.java
xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXParser.java
xerces/java/branches/stax-dev/src/org/apache/xerces/stax/XMLInputFactoryImpl.java
Modified: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/AbstractStAXParser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/AbstractStAXParser.java?view=diff&rev=556437&r1=556436&r2=556437
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/AbstractStAXParser.java (original)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/AbstractStAXParser.java Sun Jul 15 12:28:22 2007
@@ -55,6 +55,9 @@
// Process Instruction target
protected String piTarget = null;
+
+ // Name of entity referrence
+ protected String entityReferrenceName = null;
// Character content
protected XMLString characters = null;
@@ -107,6 +110,7 @@
characters = null;
piTarget = null;
piData = null;
+ entityReferrenceName = null;
elementName = null;
curElementAttr = null;
namespaceContext = null;
@@ -193,7 +197,7 @@
*/
public void doctypeDecl(String rootElement, String publicId,
String systemId, Augmentations augs) throws XNIException {
-
+ this.eventType = XMLStreamConstants.DTD;
} // doctypeDecl(String,String,String)
/**
@@ -259,7 +263,6 @@
throws XNIException {
eventType = XMLStreamConstants.CHARACTERS;
this.characters = text;
-
} // characters(XMLString)
/**
@@ -367,6 +370,8 @@
public void startGeneralEntity(String name,
XMLResourceIdentifier identifier, String encoding,
Augmentations augs) throws XNIException {
+ eventType = XMLStreamConstants.ENTITY_REFERENCE;
+ this.entityReferrenceName = name;
} // startGeneralEntity(String,XMLResourceIdentifier,String,Augmentations)
/**
@@ -410,6 +415,7 @@
*/
public void endGeneralEntity(String name, Augmentations augs)
throws XNIException {
+ eventType = XMLStreamConstants.ENTITY_REFERENCE;
} // endGeneralEntity(String,Augmentations)
/**
@@ -531,6 +537,7 @@
public void startParameterEntity(String name,
XMLResourceIdentifier identifier, String encoding,
Augmentations augs) throws XNIException {
+ eventType = XMLStreamConstants.ENTITY_DECLARATION;
} // startParameterEntity(String,XMLResourceIdentifier,String,Augmentations)
/**
@@ -549,6 +556,7 @@
*/
public void endParameterEntity(String name, Augmentations augs)
throws XNIException {
+ eventType = XMLStreamConstants.ENTITY_DECLARATION;
} // endParameterEntity(String,Augmentations)
/**
@@ -596,7 +604,7 @@
* Thrown by handler to signal an error.
*/
public void startAttlist(String elementName, Augmentations augs)
- throws XNIException {
+ throws XNIException {
} // startAttlist(String)
/**
@@ -670,6 +678,7 @@
public void internalEntityDecl(String name, XMLString text,
XMLString nonNormalizedText, Augmentations augs)
throws XNIException {
+ eventType = XMLStreamConstants.ENTITY_DECLARATION;
} // internalEntityDecl(String,XMLString,XMLString)
/**
@@ -690,6 +699,7 @@
public void externalEntityDecl(String name,
XMLResourceIdentifier identifier, Augmentations augs)
throws XNIException {
+ eventType = XMLStreamConstants.ENTITY_DECLARATION;
} // externalEntityDecl(String,XMLResourceIdentifier, Augmentations)
/**
@@ -711,6 +721,7 @@
public void unparsedEntityDecl(String name,
XMLResourceIdentifier identifier, String notation,
Augmentations augs) throws XNIException {
+ eventType = XMLStreamConstants.ENTITY_DECLARATION;
} // unparsedEntityDecl(String,XMLResourceIdentifier, String,
// Augmentations)
@@ -730,6 +741,7 @@
*/
public void notationDecl(String name, XMLResourceIdentifier identifier,
Augmentations augs) throws XNIException {
+ eventType = XMLStreamConstants.NOTATION_DECLARATION;
} // notationDecl(String,XMLResourceIdentifier, Augmentations)
/**
Added: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXFilterParser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXFilterParser.java?view=auto&rev=556437
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXFilterParser.java (added)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXFilterParser.java Sun Jul 15 12:28:22 2007
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * 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.
+ */
+
+package org.apache.xerces.stax;
+
+import javax.xml.stream.StreamFilter;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.util.StreamReaderDelegate;
+
+/**
+ * @author Wei Duan
+ *
+ * @version $Id$
+ */
+public class StAXFilterParser extends StreamReaderDelegate {
+
+ // The stream fileter used to test whether current state is part of this stream
+ private StreamFilter streamFilter = null;
+
+ /**
+ * The constructor for StAXFilterParser
+ *
+ * @param streamReader
+ * @param streamFilter
+ */
+ public StAXFilterParser(XMLStreamReader streamReader, StreamFilter streamFilter)
+ throws XMLStreamException {
+ super(streamReader);
+
+ if (streamReader == null)
+ {
+ throw new XMLStreamException("The StreamReader parameter can't be null for StAXFilterParser");
+ }
+ this.streamFilter = streamFilter;
+ }
+
+ /**
+ * Get next parsing event - a processor may return all contiguous character
+ * data in a single chunk, or it may split it into several chunks. If the
+ * property javax.xml.stream.isCoalescing is set to true element content
+ * must be coalesced and only one CHARACTERS event must be returned for
+ * contiguous element content or CDATA Sections. By default entity
+ * references must be expanded and reported transparently to the
+ * application. An exception will be thrown if an entity reference cannot be
+ * expanded. If element content is empty (i.e. content is "") then no
+ * CHARACTERS event will be reported.
+ *
+ * @return the integer code corresponding to the current parse event
+ * @throws java.lang.IllegalStateException -
+ * if this is called when hasNext() returns false
+ * @throws XMLStreamException
+ * if there is an error processing the underlying XML source
+ */
+ public int next() throws XMLStreamException {
+ while (streamFilter != null && !streamFilter.accept(this))
+ {
+ next();
+ }
+
+ return next();
+ }
+
+ /**
+ * Returns true if there are more parsing events and false if there are no
+ * more events. This method will return false if the current state of the
+ * XMLStreamReader is END_DOCUMENT
+ *
+ * @return true if there are more events, false otherwise
+ * @throws XMLStreamException
+ * if there is a fatal error detecting the next state
+ */
+ public boolean hasNext() throws XMLStreamException {
+ boolean hasNext = hasNext();
+
+ while (streamFilter != null && !streamFilter.accept(this))
+ {
+ next();
+ hasNext = hasNext();
+ }
+
+ return hasNext;
+ }
+}
Propchange: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXFilterParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXFilterParser.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXParser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXParser.java?view=diff&rev=556437&r1=556436&r2=556437
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXParser.java (original)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXParser.java Sun Jul 15 12:28:22 2007
@@ -54,6 +54,10 @@
// The stax location
private StAXLocation location = null;
+
+ // Define property string
+ private final String notationProperty = "javax.xml.stream.notations";
+ private final String entityProperty = "javax.xml.stream.entities";
/**
* The constructor for StAXParser
@@ -73,7 +77,7 @@
throw new XMLStreamException("Fail to create StAXParser instance");
}
}
-
+
/**
* Get the value of a feature/property from the underlying implementation
*
@@ -90,7 +94,16 @@
"The feature name should not be null");
}
- return inputFactory.getProperty(name);
+ if (name == notationProperty)
+ {
+ // TODO : Add notation property support when current enent is DTD
+ }
+ else if (name == entityProperty)
+ {
+ // TODO : Add notation property support when current enent is DTD
+ }
+
+ return null;
}
/**
@@ -144,12 +157,13 @@
curStAXEventType = staxParser.eventType;
+ // Initialize the location information
if (curStAXEventType == XMLStreamConstants.START_DOCUMENT) {
this.namespaceContext = new StAXNamespaceContext(
staxParser.namespaceContext);
this.location = new StAXLocation(staxParser.locator);
}
-
+
return curStAXEventType;
}
@@ -296,6 +310,11 @@
* if there are errors freeing associated resources
*/
public void close() throws XMLStreamException {
+ if (curStAXEventType == XMLStreamConstants.END_DOCUMENT) {
+ configuration.cleanup();
+ }
+ throw new IllegalStateException(
+ "Current state is not START_ELEMENT or ATTRIBUTE");
}
/**
@@ -880,8 +899,7 @@
|| curStAXEventType == XMLStreamConstants.END_ELEMENT) {
return staxParser.elementName.localpart;
} else if (curStAXEventType == XMLStreamConstants.ENTITY_REFERENCE) {
- // TODO
- return "";
+ return staxParser.entityReferrenceName;
} else {
throw new IllegalStateException(
"Current state is not START_ELEMENT, END_ELEMENT or ENTITY_REFERENCE");
Modified: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/XMLInputFactoryImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/XMLInputFactoryImpl.java?view=diff&rev=556437&r1=556436&r2=556437
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/XMLInputFactoryImpl.java (original)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/XMLInputFactoryImpl.java Sun Jul 15 12:28:22 2007
@@ -141,11 +141,10 @@
return new XMLEventReaderImpl(createEventAllocator(), createXMLStreamReader(systemId, stream));
}
-
-
+
public XMLStreamReader createFilteredReader(XMLStreamReader reader,
- StreamFilter filter) throws XMLStreamException {
- return null;
+ StreamFilter filter) throws XMLStreamException {
+ return new StAXFilterParser(reader, filter);
}
public XMLEventReader createFilteredReader(XMLEventReader reader,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org