Author: dkulp
Date: Mon Oct 24 18:36:36 2011
New Revision: 1188280
URL: http://svn.apache.org/viewvc?rev=1188280&view=rev
Log:
Merged revisions 1187040 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1187040 | dkulp | 2011-10-20 16:38:58 -0400 (Thu, 20 Oct 2011) | 1 line
Add lexical handler to SAXSource's to get comments
........
Modified:
cxf/branches/2.4.x-fixes/ (props changed)
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
Propchange: cxf/branches/2.4.x-fixes/
('svn:mergeinfo' removed)
Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java?rev=1188280&r1=1188279&r2=1188280&view=diff
==============================================================================
---
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java
(original)
+++
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java
Mon Oct 24 18:36:36 2011
@@ -103,7 +103,7 @@ public class StaxSource extends SAXSourc
int start = streamReader.getTextStart();
char[] chars = streamReader.getTextCharacters();
lexicalHandler.comment(chars, start, length);
- }
+ }
break;
case XMLStreamConstants.DTD:
break;
@@ -253,6 +253,10 @@ public class StaxSource extends SAXSourc
public void setContentHandler(ContentHandler handler) {
this.contentHandler = handler;
+ if (handler instanceof LexicalHandler
+ && lexicalHandler == null) {
+ lexicalHandler = (LexicalHandler)handler;
+ }
}
public ContentHandler getContentHandler() {
Modified:
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=1188280&r1=1188279&r2=1188280&view=diff
==============================================================================
---
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
(original)
+++
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
Mon Oct 24 18:36:36 2011
@@ -427,6 +427,11 @@ public final class StaxUtils {
} catch (Throwable t) {
//ignore
}
+ try {
+
reader.setProperty("http://xml.org/sax/properties/lexical-handler", ch);
+ } catch (Throwable t) {
+ //ignore
+ }
reader.parse(((SAXSource)source).getInputSource());
return;
} catch (Exception e) {
Modified:
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java?rev=1188280&r1=1188279&r2=1188280&view=diff
==============================================================================
---
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
(original)
+++
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
Mon Oct 24 18:36:36 2011
@@ -29,16 +29,18 @@ import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
import org.apache.cxf.common.util.StringUtils;
/**
*
*/
-public class StreamWriterContentHandler implements ContentHandler {
+public class StreamWriterContentHandler implements ContentHandler,
LexicalHandler {
XMLStreamWriter writer;
Map<String, String> mapping = new LinkedHashMap<String, String>();
+ boolean inCDATA;
public StreamWriterContentHandler(XMLStreamWriter w) {
writer = w;
@@ -72,7 +74,11 @@ public class StreamWriterContentHandler
*/
public void characters(char ch[], int start, int length) throws
SAXException {
try {
- writer.writeCharacters(ch, start, length);
+ if (inCDATA) {
+ writer.writeCData(new String(ch, start, length));
+ } else {
+ writer.writeCharacters(ch, start, length);
+ }
} catch (XMLStreamException e) {
throw new SAXException(e);
}
@@ -87,6 +93,11 @@ public class StreamWriterContentHandler
* @throws SAXException
*/
public void ignorableWhitespace(char ch[], int start, int length) throws
SAXException {
+ try {
+ writer.writeCharacters(ch, start, length);
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ }
}
/**
@@ -242,7 +253,27 @@ public class StreamWriterContentHandler
throw new SAXException(e);
}
}
-
-
+ public void startDTD(String name, String publicId, String systemId) throws
SAXException {
+ }
+ public void endDTD() throws SAXException {
+ }
+ public void startEntity(String name) throws SAXException {
+ }
+ public void endEntity(String name) throws SAXException {
+ }
+ public void startCDATA() throws SAXException {
+ inCDATA = true;
+ }
+ public void endCDATA() throws SAXException {
+ inCDATA = false;
+ }
+
+ public void comment(char[] ch, int start, int length) throws SAXException {
+ try {
+ writer.writeComment(new String(ch, start, length));
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ }
+ }
}