Author: dkulp Date: Wed Oct 26 16:05:38 2011 New Revision: 1189283 URL: http://svn.apache.org/viewvc?rev=1189283&view=rev Log: Merged revisions 1188280 via svnmerge from https://svn.us.apache.org/repos/asf/cxf/branches/2.4.x-fixes
................ r1188280 | dkulp | 2011-10-24 14:36:36 -0400 (Mon, 24 Oct 2011) | 9 lines 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.3.x-fixes/ (props changed) cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java Propchange: cxf/branches/2.3.x-fixes/ ('svn:mergeinfo' removed) Propchange: cxf/branches/2.3.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java?rev=1189283&r1=1189282&r2=1189283&view=diff ============================================================================== --- cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java (original) +++ cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java Wed Oct 26 16:05:38 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.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=1189283&r1=1189282&r2=1189283&view=diff ============================================================================== --- cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original) +++ cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Wed Oct 26 16:05:38 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.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java?rev=1189283&r1=1189282&r2=1189283&view=diff ============================================================================== --- cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java (original) +++ cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java Wed Oct 26 16:05:38 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); + } + } }
