Search in sources :

Example 71 with Document

use of org.jdom.Document in project yamcs-studio by yamcs.

the class XMLUtil method inputStreamToXML.

private static Element inputStreamToXML(InputStream stream) throws JDOMException, IOException {
    SAXBuilder saxBuilder = LineAwareXMLParser.createBuilder();
    Document doc = saxBuilder.build(stream);
    Element root = doc.getRootElement();
    return root;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) LineAwareElement(org.csstudio.opibuilder.persistence.LineAwareXMLParser.LineAwareElement) Element(org.jdom.Element) Document(org.jdom.Document)

Example 72 with Document

use of org.jdom.Document in project che by eclipse.

the class EffectivePomWriter method addMavenNamespace.

/**
     * method from org.apache.maven.plugins.help.AbstractEffectiveMojo
     * Add a Pom/Settings namespaces to the effective XML content.
     *
     * @param effectiveXml not null the effective POM or Settings
     * @param isPom if <code>true</code> add the Pom xsd url, otherwise add the settings xsd url.
     * @return the content of the root element, i.e. &lt;project/&gt; or &lt;settings/&gt; with the Maven namespace or
     *         the original <code>effective</code> if an error occurred.
     * @see #POM_XSD_URL
     * @see #SETTINGS_XSD_URL
     */
protected static String addMavenNamespace(String effectiveXml, boolean isPom) {
    SAXBuilder builder = new SAXBuilder();
    try {
        Document document = builder.build(new StringReader(effectiveXml));
        Element rootElement = document.getRootElement();
        // added namespaces
        Namespace pomNamespace = Namespace.getNamespace("", "http://maven.apache.org/POM/4.0.0");
        rootElement.setNamespace(pomNamespace);
        Namespace xsiNamespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        rootElement.addNamespaceDeclaration(xsiNamespace);
        if (rootElement.getAttribute("schemaLocation", xsiNamespace) == null) {
            rootElement.setAttribute("schemaLocation", "http://maven.apache.org/POM/4.0.0 " + (isPom ? POM_XSD_URL : SETTINGS_XSD_URL), xsiNamespace);
        }
        ElementFilter elementFilter = new ElementFilter(Namespace.getNamespace(""));
        for (Iterator<?> i = rootElement.getDescendants(elementFilter); i.hasNext(); ) {
            Element e = (Element) i.next();
            e.setNamespace(pomNamespace);
        }
        StringWriter w = new StringWriter();
        Format format = Format.getPrettyFormat();
        XMLOutputter out = new XMLOutputter(format);
        out.output(document.getRootElement(), w);
        return w.toString();
    } catch (JDOMException e) {
        return effectiveXml;
    } catch (IOException e) {
        return effectiveXml;
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) Format(org.jdom.output.Format) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) StringWriter(java.io.StringWriter) Element(org.jdom.Element) ElementFilter(org.jdom.filter.ElementFilter) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) Namespace(org.jdom.Namespace)

Example 73 with Document

use of org.jdom.Document in project voldemort by voldemort.

the class RestUtils method parseSerializerDefinition.

private static SerializerDefinition parseSerializerDefinition(String serializerInfoXml, String elementName) {
    SAXBuilder builder = new SAXBuilder();
    try {
        Document doc = builder.build(new StringReader(serializerInfoXml));
        Element root = doc.getRootElement();
        Element serializerElement = root.getChild(elementName);
        return StoreDefinitionsMapper.readSerializer(serializerElement);
    } catch (JDOMException e) {
        throw new MappingException(e);
    } catch (IOException e) {
        throw new MappingException(e);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) MappingException(voldemort.xml.MappingException)

Example 74 with Document

use of org.jdom.Document in project voldemort by voldemort.

the class ClusterMapper method readCluster.

@SuppressWarnings("unchecked")
public Cluster readCluster(Reader input, boolean verifySchema) {
    try {
        SAXBuilder builder = new SAXBuilder(false);
        Document doc = builder.build(input);
        if (verifySchema) {
            Validator validator = this.schema.newValidator();
            validator.validate(new JDOMSource(doc));
        }
        Element root = doc.getRootElement();
        if (!root.getName().equals(CLUSTER_ELMT))
            throw new MappingException("Invalid root element: " + doc.getRootElement().getName());
        String name = root.getChildText(CLUSTER_NAME_ELMT);
        List<Zone> zones = new ArrayList<Zone>();
        for (Element node : (List<Element>) root.getChildren(ZONE_ELMT)) zones.add(readZone(node));
        List<Node> servers = new ArrayList<Node>();
        for (Element node : (List<Element>) root.getChildren(SERVER_ELMT)) servers.add(readServer(node));
        return new Cluster(name, servers, zones);
    } catch (JDOMException e) {
        throw new MappingException(e);
    } catch (SAXException e) {
        throw new MappingException(e);
    } catch (IOException e) {
        throw new MappingException(e);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Zone(voldemort.cluster.Zone) Element(org.jdom.Element) Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) JDOMSource(org.jdom.transform.JDOMSource) Cluster(voldemort.cluster.Cluster) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) SAXException(org.xml.sax.SAXException) ArrayList(java.util.ArrayList) List(java.util.List) Validator(javax.xml.validation.Validator)

Example 75 with Document

use of org.jdom.Document in project voldemort by voldemort.

the class StoreDefinitionsMapper method readStore.

public static StoreDefinition readStore(Reader input) {
    SAXBuilder builder = new SAXBuilder();
    try {
        Document doc = builder.build(input);
        Element root = doc.getRootElement();
        return readStore(root);
    } catch (JDOMException e) {
        throw new MappingException(e);
    } catch (IOException e) {
        throw new MappingException(e);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Aggregations

Document (org.jdom.Document)144 Element (org.jdom.Element)102 SAXBuilder (org.jdom.input.SAXBuilder)51 IOException (java.io.IOException)49 JDOMException (org.jdom.JDOMException)29 File (java.io.File)27 ArrayList (java.util.ArrayList)22 XMLOutputter (org.jdom.output.XMLOutputter)22 List (java.util.List)16 StringReader (java.io.StringReader)15 Format (org.jdom.output.Format)12 VCDocument (org.vcell.util.document.VCDocument)11 XPath (org.jdom.xpath.XPath)10 StringWriter (java.io.StringWriter)9 InputStream (java.io.InputStream)8 URL (java.net.URL)8 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)7 FileNotFoundException (java.io.FileNotFoundException)5 Writer (java.io.Writer)5