Bug 734627

Summary: CDATAs in TopicXML are converted to <foo> when you export the XML
Product: [Community] PressGang CCMS Reporter: sgilda
Component: Web-UIAssignee: sgilda
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: urgent Docs Contact:
Priority: urgent    
Version: 1.xCC: topic-tool-list
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-10-19 23:08:28 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description sgilda 2011-08-31 00:33:07 UTC
Description of problem:
I enter and save topic XML containing the following:
    <programlisting language="XML">
        <![CDATA[<servlet-mapping>
            <servlet-name>javax.ws.rs.core.Application</servlet-name>
            <url-pattern>/hello/*</url-pattern>
        </servlet-mapping>]]>
    </programlisting>
When I export the TopicXML for that topic, it exports like this:
    <programlisting language="XML">
        &lt;servlet-mapping&gt;
           &lt;servlet-name&gt;javax.ws.rs.core.Application&lt;/servlet-name&gt;
           &lt;url-pattern&gt;/hello/*&lt;/url-pattern&gt;
        &lt;/servlet-mapping&gt;
    </programlisting>


Version-Release number of selected component (if applicable):


How reproducible:
Add the topicXML data as described above. Save the topic. Then export that topicXML.

Steps to Reproduce:
1. Add the topicXML data as described above. 
2. Then export that topicXML.
3.
  
Actual results:


Expected results:


Additional info:

Comment 1 sgilda 2011-08-31 00:48:15 UTC
Many of my topics contain xml snippets. I am not able to edit those topics without messing up all the CDATAs until this bug is fixed. The topic displays fine, but it would be a maintenance nightmare to try to maintain the source code with &lt; instead of CDATAs. Is there an option on the XML API to prevent converting CDATAs?

Comment 2 Matthew Casperson 2011-08-31 23:58:23 UTC
Fixed in 20110901-0957

Turns out this code:

final DOMImplementationLS impl = (DOMImplementationLS)DOMImplementationRegistry.newInstance().getDOMImplementation("LS");
final LSParser builder = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
final LSInput xmlFile = impl.createLSInput();					
xmlFile.setByteStream(new ByteArrayInputStream(xml.getBytes(encoding)));
final Document document = builder.parse(xmlFile);

will coalesce CDATA elements. I couldn't find any way to disable it. Changed to this code:

final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
final DocumentBuilder builder = builderFactory.newDocumentBuilder();
final Document document = builder.parse(new ByteArrayInputStream(xml.getBytes(encoding)));

Comment 3 sgilda 2011-10-19 23:08:28 UTC
works as expected.