use of org.jdom.Document in project maven-plugins by apache.
the class EffectivePomMojo method prettyFormat.
/**
* @param effectivePom not null
* @return pretty format of the xml or the original <code>effectivePom</code> if an error occurred.
*/
private static String prettyFormat(String effectivePom) {
SAXBuilder builder = new SAXBuilder();
try {
Document effectiveDocument = builder.build(new StringReader(effectivePom));
StringWriter w = new StringWriter();
Format format = Format.getPrettyFormat();
XMLOutputter out = new XMLOutputter(format);
out.output(effectiveDocument, w);
return w.toString();
} catch (JDOMException e) {
return effectivePom;
} catch (IOException e) {
return effectivePom;
}
}
use of org.jdom.Document in project sling by apache.
the class CreateKarafFeatureDescriptorMojo method executeWithArtifacts.
@Override
protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
Document doc = new Document();
Element features = new Element("features");
doc.setRootElement(features);
features.setAttribute("name", featuresName);
Element feature = new Element("feature");
features.addContent(feature);
feature.setAttribute("name", featureName);
feature.setAttribute("version", featureVersion);
BundleList bundleList = getInitializedBundleList();
for (StartLevel level : bundleList.getStartLevels()) {
for (Bundle bundle : level.getBundles()) {
String bundleRef = String.format("mvn:%s/%s/%s", bundle.getGroupId(), bundle.getArtifactId(), bundle.getVersion());
feature.addContent(new Element("bundle").setText(bundleRef));
}
}
FileOutputStream out = null;
try {
out = new FileOutputStream(outputFile);
new XMLOutputter(Format.getPrettyFormat().setEncoding("UTF-8")).output(doc, out);
projectHelper.attachArtifact(project, TYPE, CLASSIFIER, outputFile);
} catch (IOException e) {
throw new MojoExecutionException("Unable to write features.xml", e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
}
use of org.jdom.Document in project beast-mcmc by beast-dev.
the class TreeStatData method create.
/**
* Read options from a file
*/
public Document create() {
Element root = new Element("treeTracer");
root.setAttribute("version", version);
Element taxonSetsElement = new Element("taxonSets");
Element charactersElement = new Element("characters");
Element statisticsElement = new Element("statistics");
root.addContent(taxonSetsElement);
root.addContent(charactersElement);
root.addContent(statisticsElement);
return new Document(root);
}
use of org.jdom.Document in project beast-mcmc by beast-dev.
the class AbstractPolygon2D method readKMLFile.
public static List<AbstractPolygon2D> readKMLFile(String fileName) {
List<AbstractPolygon2D> polygons = new ArrayList<AbstractPolygon2D>();
try {
SAXBuilder builder = new SAXBuilder();
builder.setValidation(false);
builder.setIgnoringElementContentWhitespace(true);
Document doc = builder.build(new File(fileName));
Element root = doc.getRootElement();
if (!root.getName().equalsIgnoreCase("KML"))
throw new RuntimeException("Not a KML file");
readKMLElement(root, polygons);
} catch (IOException e) {
e.printStackTrace();
} catch (JDOMException e) {
e.printStackTrace();
}
return polygons;
}
use of org.jdom.Document in project beast-mcmc by beast-dev.
the class XMLModelFile method main.
public static void main(String[] args) {
//main method for debugging
SAXBuilder parser = new SAXBuilder();
Document doc;
try {
doc = parser.build(new File("testSimplePathSampling.xml"));
XMLModelFile z = new XMLModelFile(doc.getRootElement());
z.printIdentified();
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("samplingMean", "samplingMean");
z.prefixIdentifiedNames("model1.", hm, false);
z.printIdentified();
} catch (IOException e) {
//
} catch (JDOMException e) {
//
}
}
Aggregations