Search in sources :

Example 86 with Document

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;
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) Format(org.jdom.output.Format) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Example 87 with Document

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) {
            }
        }
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) Element(org.jdom.Element) FileOutputStream(java.io.FileOutputStream) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel) IOException(java.io.IOException) Document(org.jdom.Document)

Example 88 with Document

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);
}
Also used : Element(org.jdom.Element) Document(org.jdom.Document)

Example 89 with Document

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;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) File(java.io.File)

Example 90 with Document

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) {
    //
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) File(java.io.File)

Aggregations

Document (org.jdom.Document)90 Element (org.jdom.Element)67 IOException (java.io.IOException)40 SAXBuilder (org.jdom.input.SAXBuilder)40 JDOMException (org.jdom.JDOMException)24 File (java.io.File)16 XMLOutputter (org.jdom.output.XMLOutputter)16 ArrayList (java.util.ArrayList)13 List (java.util.List)12 StringReader (java.io.StringReader)10 XPath (org.jdom.xpath.XPath)10 Format (org.jdom.output.Format)9 StringWriter (java.io.StringWriter)8 InputStream (java.io.InputStream)7 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)7 Writer (java.io.Writer)5 URL (java.net.URL)5 JDOMUtil.loadDocument (com.intellij.openapi.util.JDOMUtil.loadDocument)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4