Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented SEAMFORGE-179

  • Loading branch information...
commit 6fd1db57a1796459ae5b3c4e7e2175f0d9e4ef86 1 parent 4091b52
@kevinpollet kevinpollet authored lincolnthree committed
View
43 parser-xml/src/main/java/org/jboss/forge/parser/xml/NodeType.java
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.forge.parser.xml;
+
+/**
+ * @author Kevin Pollet
+ */
+public enum NodeType
+{
+ COMMENT("#comment"),
+ CDATA_SECTION("#cdata-section");
+
+ private final String nodeName;
+
+ private NodeType(String nodeName)
+ {
+ this.nodeName = nodeName;
+ }
+
+ public String getNodeName()
+ {
+ return nodeName;
+ }
+}
View
19 parser-xml/src/main/java/org/jboss/forge/parser/xml/XMLParser.java
@@ -42,6 +42,9 @@
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
+import static org.jboss.forge.parser.xml.NodeType.CDATA_SECTION;
+import static org.jboss.forge.parser.xml.NodeType.COMMENT;
+
/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
@@ -153,15 +156,23 @@ private static void writeRecursive(org.w3c.dom.Node target, Node source)
{
owned = (Document) target;
}
- org.w3c.dom.Node targetChild = null;
- if (source.text() != null)
+
+ org.w3c.dom.Node targetChild;
+ if (COMMENT.getNodeName().equals(source.name()))
{
- targetChild = owned.createElement(source.name());
- targetChild.appendChild(owned.createTextNode(source.text()));
+ targetChild = owned.createComment(source.text());
+ }
+ else if (CDATA_SECTION.getNodeName().equals(source.name()))
+ {
+ targetChild = owned.createCDATASection(source.text());
}
else
{
targetChild = owned.createElement(source.name());
+ if (source.text() != null)
+ {
+ targetChild.appendChild(owned.createTextNode(source.text()));
+ }
}
target.appendChild(targetChild);
Please sign in to comment.
Something went wrong with that request. Please try again.