use of org.w3c.dom.Comment in project webservices-axiom by apache.
the class TestInsertBeforeForbidden method runTest.
@Override
protected void runTest() throws Throwable {
OMDocument omDocument = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<!--test--><test/>")).getDocument();
if (build) {
omDocument.build();
}
Document document = (Document) omDocument;
Comment comment = (Comment) document.getFirstChild();
try {
document.insertBefore(document.createElementNS(null, "test"), comment);
fail("Expected DOMException");
} catch (DOMException ex) {
assertThat(ex.code).isEqualTo(DOMException.HIERARCHY_REQUEST_ERR);
}
}
use of org.w3c.dom.Comment in project cdap by caskdata.
the class Configuration method asXmlDocument.
/**
* Return the XML DOM corresponding to this Configuration.
*/
private synchronized Document asXmlDocument() throws IOException {
Document doc;
try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
} catch (ParserConfigurationException pe) {
throw new IOException(pe);
}
Element conf = doc.createElement("configuration");
doc.appendChild(conf);
conf.appendChild(doc.createTextNode("\n"));
//ensure properties is set and deprecation is handled
handleDeprecation();
for (Enumeration e = properties.keys(); e.hasMoreElements(); ) {
String name = (String) e.nextElement();
Object object = properties.get(name);
String value = null;
if (object instanceof String) {
value = (String) object;
} else {
continue;
}
Element propNode = doc.createElement("property");
conf.appendChild(propNode);
if (updatingResource != null) {
Comment commentNode = doc.createComment("Loaded from " + updatingResource.get(name));
propNode.appendChild(commentNode);
}
Element nameNode = doc.createElement("name");
nameNode.appendChild(doc.createTextNode(name));
propNode.appendChild(nameNode);
Element valueNode = doc.createElement("value");
valueNode.appendChild(doc.createTextNode(value));
propNode.appendChild(valueNode);
conf.appendChild(doc.createTextNode("\n"));
}
return doc;
}
use of org.w3c.dom.Comment in project che by eclipse.
the class BuildFileGenerator method createClean.
/**
* Create clean target tag.
* <target description="Remove all temporary files" name="clean">
* ...
* </target>
*/
private void createClean() {
//Insert comment
Comment cleanUpComment = doc.createComment("Clean up");
root.appendChild(cleanUpComment);
//Create main target tag
Element target = doc.createElement("target");
target.setAttribute("name", "clean");
target.setAttribute("description", "Remove all temporary files");
//Insert comment
Comment deleteFileComment = doc.createComment("Delete files");
target.appendChild(deleteFileComment);
//Create delete tag inside target tag
Element delete = doc.createElement("delete");
delete.setAttribute("dir", "${build.classes}");
target.appendChild(delete);
root.appendChild(target);
}
use of org.w3c.dom.Comment in project che by eclipse.
the class BuildFileGenerator method createBuild.
// /**
// * Create classpath tag.
// * <path id="libs.dir">
// * <fileset dir="lib" includes="**\/*\.jar"/>
// * </path>
// */
// private void createClassPath() {
// Element path = doc.createElement("path");
// path.setAttribute("id", "libs.dir");
//
// Element fieldSet = doc.createElement("fileset");
// fieldSet.setAttribute("dir", "lib");
// fieldSet.setAttribute("includes", "**/*.jar");
//
// path.appendChild(fieldSet);
//
// root.appendChild(path);
// }
/**
* Create build target tag.
* <target depends="clean" description="Builds the application" name="build">
* ...
* </target>
*/
private void createBuild() {
//Insert comment
Comment buildComment = doc.createComment("Application build");
root.appendChild(buildComment);
//Create main target tag
Element target = doc.createElement("target");
target.setAttribute("name", "build");
target.setAttribute("depends", "clean");
target.setAttribute("description", "Builds the application");
//Insert comment
Comment createDirectoryComment = doc.createComment("Create directory");
target.appendChild(createDirectoryComment);
//Create mkdir tag inside target
Element mkdir = doc.createElement("mkdir");
mkdir.setAttribute("dir", "${build.classes}");
target.appendChild(mkdir);
//Insert comment
Comment compileSourcesComment = doc.createComment("Compile source code");
target.appendChild(compileSourcesComment);
//Create javac tag inside target
Element javac = doc.createElement("javac");
javac.setAttribute("srcdir", "${src.dir}");
javac.setAttribute("destdir", "${build.classes}");
javac.setAttribute("debug", "false");
javac.setAttribute("deprecation", "true");
javac.setAttribute("optimize", "true");
javac.setAttribute("includeantruntime", "true");
// //Create classpath tag inside javac
// Element classpath = doc.createElement("classpath");
// classpath.setAttribute("refid", "libs.dir");
// javac.appendChild(classpath);
target.appendChild(javac);
//Insert comment
Comment copyNecessaryFiles = doc.createComment("Copy necessary files");
target.appendChild(copyNecessaryFiles);
//Create copy tag inside target
Element copy = doc.createElement("copy");
copy.setAttribute("todir", "${build.classes}");
//Create fileset tag inside copy
Element copyFileset = doc.createElement("fileset");
copyFileset.setAttribute("dir", "${src.dir}");
copyFileset.setAttribute("includes", "**/*.*");
copyFileset.setAttribute("excludes", "**/*.java");
copy.appendChild(copyFileset);
target.appendChild(copy);
//Insert comment
Comment createJarComment = doc.createComment("Create JAR-file");
target.appendChild(createJarComment);
//Create jar tag inside target
Element jar = doc.createElement("jar");
jar.setAttribute("jarfile", "${build}/${name}.jar");
//Create fileset tag inside jar
Element jarFileset = doc.createElement("fileset");
jarFileset.setAttribute("dir", "${build.classes}");
jar.appendChild(jarFileset);
target.appendChild(jar);
root.appendChild(target);
}
use of org.w3c.dom.Comment in project robovm by robovm.
the class SimpleBuilderTest method testGoodFile1.
public void testGoodFile1() throws Exception {
Document document = builder.parse(getClass().getResourceAsStream("/SimpleBuilderTest.xml"));
Element root = document.getDocumentElement();
assertNotNull(root);
assertEquals("http://www.foo.bar", root.getNamespaceURI());
assertEquals("t", root.getPrefix());
assertEquals("stuff", root.getLocalName());
NodeList list = root.getElementsByTagName("nestedStuff");
assertNotNull(list);
assertEquals(list.getLength(), 4);
Element one = (Element) list.item(0);
Element two = (Element) list.item(1);
Element three = (Element) list.item(2);
Element four = (Element) list.item(3);
assertEquals("This space intentionally left blank.", getTextContent(one));
assertEquals("Nothing to see here - please get along!", getTextContent(two));
assertEquals("Rent this space!", getTextContent(three));
assertEquals("", getTextContent(four));
assertEquals("eins", one.getAttribute("one"));
assertEquals("zwei", two.getAttribute("two"));
assertEquals("drei", three.getAttribute("three"));
assertEquals("vier", four.getAttribute("t:four"));
assertEquals("vier", four.getAttributeNS("http://www.foo.bar", "four"));
list = document.getChildNodes();
assertNotNull(list);
String proinst = "";
String comment = "";
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if (node instanceof ProcessingInstruction) {
proinst = proinst + node.getNodeValue();
} else if (node instanceof Comment) {
comment = comment + node.getNodeValue();
}
}
assertEquals("The quick brown fox jumps over the lazy dog.", proinst);
assertEquals(" Fragile! Handle me with care! ", comment);
}
Aggregations