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 2006/10/03 05:20:06 UTC
svn commit: r452304 - in
/xerces/java/branches/stax-dev/src/org/apache/xerces/stax:
SAXXMLStreamReaderImpl.java StAXSAXHandler.java
Author: mrglavas
Date: Mon Oct 2 20:20:05 2006
New Revision: 452304
URL: http://svn.apache.org/viewvc?view=rev&rev=452304
Log:
JIRA Issue #1199:
http://issues.apache.org/jira/browse/XERCESJ-1199
Attempt to set the StAXSAXHandler on the XMLReader as a LexicalHandler and as a
DeclHandler. It is now able to handle comments and CDATA sections. Still needs
a bit of work to support DTD events.
Modified:
xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXXMLStreamReaderImpl.java
xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXSAXHandler.java
Modified: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXXMLStreamReaderImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXXMLStreamReaderImpl.java?view=diff&rev=452304&r1=452303&r2=452304
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXXMLStreamReaderImpl.java (original)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXXMLStreamReaderImpl.java Mon Oct 2 20:20:05 2006
@@ -28,8 +28,10 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+import org.apache.xerces.impl.Constants;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
/**
@@ -41,6 +43,24 @@
*/
public class SAXXMLStreamReaderImpl implements XMLStreamReader {
+ //
+ // Constants
+ //
+
+ // properties
+
+ /** Property id: lexical handler. */
+ private static final String LEXICAL_HANDLER =
+ Constants.SAX_PROPERTY_PREFIX + Constants.LEXICAL_HANDLER_PROPERTY;
+
+ /** Property id: declaration handler. */
+ private static final String DECLARATION_HANDLER =
+ Constants.SAX_PROPERTY_PREFIX + Constants.DECLARATION_HANDLER_PROPERTY;
+
+ //
+ // Data
+ //
+
// The XMLInputFactory instance which creates the SAXXMLStreamReader
private XMLInputFactory xif;
@@ -110,6 +130,22 @@
xr.setEntityResolver(handler);
xr.setErrorHandler(handler);
+ // Try to set a lexical handler.
+ try {
+ xr.setProperty(LEXICAL_HANDLER, handler);
+ }
+ // If the XMLReader doesn't support this property ignore the exception.
+ catch (SAXException e) {}
+
+ // Try to set a declaration handler.
+ try {
+ xr.setProperty(DECLARATION_HANDLER, handler);
+ }
+ // If the XMLReader doesn't support this property ignore the exception.
+ catch (SAXException e) {
+ e.printStackTrace();
+ }
+
dc = new NamespaceContextImpl();
synchronized (asp) {
@@ -136,9 +172,10 @@
* @return The value of the property
* @throws IllegalArgumentException if name is null
*/
- public Object getProperty(java.lang.String name) throws java.lang.IllegalArgumentException {
- if (name == null)
- throw new IllegalArgumentException("The feature name should not be null");
+ public Object getProperty(String name) throws java.lang.IllegalArgumentException {
+ if (name == null) {
+ throw new IllegalArgumentException("The feature name must not be null");
+ }
return xif.getProperty(name);
}
Modified: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXSAXHandler.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXSAXHandler.java?view=diff&rev=452304&r1=452303&r2=452304
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXSAXHandler.java (original)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXSAXHandler.java Mon Oct 2 20:20:05 2006
@@ -22,34 +22,32 @@
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.ext.DefaultHandler2;
/**
* @author Hua Lei
*
* @version $Id$
*/
-final class StAXSAXHandler extends DefaultHandler {
+final class StAXSAXHandler extends DefaultHandler2 {
private final AsyncSAXParser asp;
private final SAXXMLStreamReaderImpl reader;
private final SAXLocation loc;
private StringBuffer buf;
+ private boolean inCDATA;
public StAXSAXHandler(AsyncSAXParser asp, SAXXMLStreamReaderImpl reader, SAXLocation loc) {
this.asp = asp;
this.reader = reader;
this.loc = loc;
- if (reader.isCoalescing) {
- buf = new StringBuffer();
- }
+ this.buf = new StringBuffer();
}
public void characters(char[] ch, int start, int length) throws SAXException {
try {
- reader.setCurType(XMLStreamConstants.CHARACTERS);
-
- if (reader.isCoalescing) {
+ reader.setCurType(!inCDATA ? XMLStreamConstants.CHARACTERS : XMLStreamConstants.CDATA);
+ if (reader.isCoalescing || inCDATA) {
buf.append(ch, start, length);
return;
}
@@ -210,11 +208,52 @@
loc.setLocator(locator);
}
- public synchronized void skippedEntity(String name) throws SAXException{
+ public synchronized void skippedEntity(String name) throws SAXException {
try {
reader.setCurType(XMLStreamConstants.ENTITY_REFERENCE);
asp.setEntityName(name);
asp.setCharacters(null, 0, 0);
+ synchronized (asp) {
+ asp.notify();
+ asp.wait();
+ }
+ }
+ catch (Exception e) {
+ throw new SAXException(e.getMessage(), e);
+ }
+ }
+
+ public synchronized void comment(char[] ch, int start, int length) throws SAXException {
+ try {
+ checkCoalescing();
+ reader.setCurType(XMLStreamConstants.COMMENT);
+ asp.setCharacters(ch, start, length);
+ synchronized (asp) {
+ asp.notify();
+ asp.wait();
+ }
+ }
+ catch (Exception e) {
+ throw new SAXException(e.getMessage(), e);
+ }
+ }
+
+ public synchronized void startCDATA() throws SAXException {
+ try {
+ checkCoalescing();
+ inCDATA = true;
+ }
+ catch (Exception e) {
+ throw new SAXException(e.getMessage(), e);
+ }
+ }
+
+ public synchronized void endCDATA() throws SAXException {
+ try {
+ inCDATA = false;
+ char[] chs = buf.toString().toCharArray();
+ asp.setCharacters(chs, 0, chs.length);
+ buf.setLength(0);
synchronized (asp) {
asp.notify();
asp.wait();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org