use of de.pdark.decentxml.Document in project sling by apache.
the class JcrNode method createVaultFileWithContent.
private void createVaultFileWithContent(IFolder parent, String filename, String childNodeType, Element content) {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<jcr:root \n xmlns:sling=\"http://sling.apache.org/jcr/sling/1.0\"\n xmlns:jcr=\"http://www.jcp.org/jcr/1.0\"\n jcr:primaryType=\"" + childNodeType + "\"/>";
final IFile file = parent.getFile(filename);
try {
if (content != null) {
Document document = TolerantXMLParser.parse(xml, file.getFullPath().toOSString());
// add the attributes of content
List<Attribute> attributes = content.getAttributes();
for (Attribute attribute : attributes) {
if (attribute.getName().equals("jcr:primaryType")) {
// skip this
continue;
}
document.getRootElement().addAttribute(attribute);
}
// then copy all the children
document.getRootElement().addNodes(content.getChildren());
// then save the document
xml = document.toXML();
}
if (file.exists()) {
file.setContents(new ByteArrayInputStream(xml.getBytes()), true, true, new NullProgressMonitor());
} else {
file.create(new ByteArrayInputStream(xml.getBytes()), true, new NullProgressMonitor());
}
} catch (Exception e) {
//TODO proper logging
e.printStackTrace();
MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Cannot create JCR node on a File", "Following Exception encountered: " + e);
}
}
use of de.pdark.decentxml.Document in project tycho by eclipse.
the class EclipseModelTest method testDefaultXmlEncoding.
public void testDefaultXmlEncoding() throws Exception {
// Run the test with -Dfile.encoding=Cp1252 to be sure
Feature feature = Feature.read(new File("src/test/resources/modelio/feature-default-encoding.xml"));
Feature.write(feature, new File("target/feature-default-encoding.xml"));
Document document = XMLParser.parse(new File("target/feature-default-encoding.xml"));
Element child = document.getChild("/feature/license");
assertEquals("\u201cI AGREE\u201d", child.getText().trim());
}
use of de.pdark.decentxml.Document in project tycho by eclipse.
the class Category method write.
public static void write(Category category, File file) throws IOException {
OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
Document document = category.document;
try {
String enc = document.getEncoding() != null ? document.getEncoding() : "UTF-8";
Writer w = new OutputStreamWriter(os, enc);
XMLWriter xw = new XMLWriter(w);
try {
document.toXML(xw);
} finally {
xw.flush();
}
} finally {
IOUtil.close(os);
}
}
use of de.pdark.decentxml.Document in project tycho by eclipse.
the class IU method read.
public static IU read(File file) throws IOException {
FileInputStream is = new FileInputStream(file);
try {
Document iuDocument = parser.parse(new XMLIOSource(is));
Element root = iuDocument.getChild(UNIT);
if (root == null)
throw new RuntimeException("No iu found.");
IU result = new IU(iuDocument, root);
if (result.getId() == null)
throw new RuntimeException(String.format("The IU defined in %s is missing an id.", file.getAbsolutePath()));
if (result.getVersion() == null)
throw new RuntimeException(String.format("The IU defined in %s is missing a version.", file.getAbsolutePath()));
return result;
} finally {
IOUtil.close(is);
}
}
use of de.pdark.decentxml.Document in project tycho by eclipse.
the class Tycho465RootFilesTest method testProductBuild.
@Test
public void testProductBuild() throws Exception {
Verifier verifier = getVerifier("product.rootFiles", false);
verifier.getSystemProperties().setProperty("forceContextQualifier", Tycho465RootFilesTest.QUALIFIER.toString());
verifier.getSystemProperties().setProperty("p2.repo", P2Repositories.ECLIPSE_342.toString());
verifier.executeGoal("install");
verifier.verifyErrorFreeLog();
File targetDir = new File(verifier.getBasedir(), Tycho465RootFilesTest.MODULE + "/target");
File repositoryTargetDirectory = new File(targetDir, "repository");
Document contentXml = openMetadataRepositoryDocument(repositoryTargetDirectory);
assertBuildProductAndRepository(targetDir, repositoryTargetDirectory, contentXml);
// clean the local build results
verifier.executeGoal("clean");
verifier.verifyErrorFreeLog();
// re-build the repository project only (incl. products) to ensure that the created root file zips were attached
// to the project and are available from the local repository
final boolean ignoreLocallyInstalledArtifacts = false;
Verifier eclipseRepoProjectVerifier = getVerifier("product.rootFiles/eclipse-repository", false, ignoreLocallyInstalledArtifacts);
eclipseRepoProjectVerifier.getSystemProperties().setProperty("forceContextQualifier", Tycho465RootFilesTest.QUALIFIER.toString());
eclipseRepoProjectVerifier.getSystemProperties().setProperty("p2.repo", P2Repositories.ECLIPSE_342.toString());
eclipseRepoProjectVerifier.executeGoal("verify");
eclipseRepoProjectVerifier.verifyErrorFreeLog();
Document updatedContentXml = openMetadataRepositoryDocument(repositoryTargetDirectory);
assertBuildProductAndRepository(targetDir, repositoryTargetDirectory, updatedContentXml);
}
Aggregations