Search in sources :

Example 1 with JDOMSource

use of org.jdom.transform.JDOMSource in project intellij-community by JetBrains.

the class XsltDocumentationProvider method getDocumentation.

@Nullable
private String getDocumentation(String name, String type) {
    try {
        final Transformer transformer = getTemplate().newTransformer();
        transformer.setParameter("element", name);
        transformer.setParameter("type", type);
        final StringWriter writer = new StringWriter();
        transformer.transform(new JDOMSource(getDocumentationDocument()), new StreamResult(writer));
        final String s = writer.toString();
        final Matcher matcher = check.matcher(s);
        if (matcher.find()) {
            if (matcher.group(1).equals("true")) {
                return s.replaceFirst("<META.+?>", "");
            }
        }
    } catch (Exception e) {
        Logger.getInstance(getClass().getName()).error(e);
    }
    return null;
}
Also used : Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) Matcher(java.util.regex.Matcher) JDOMSource(org.jdom.transform.JDOMSource) JDOMException(org.jdom.JDOMException) IncorrectOperationException(com.intellij.util.IncorrectOperationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with JDOMSource

use of org.jdom.transform.JDOMSource 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 3 with JDOMSource

use of org.jdom.transform.JDOMSource in project voldemort by voldemort.

the class StoreDefinitionsMapper method readStoreList.

public List<StoreDefinition> readStoreList(Reader input, boolean verifySchema) {
    try {
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(input);
        if (verifySchema) {
            Validator validator = schema.newValidator();
            validator.validate(new JDOMSource(doc));
        }
        Element root = doc.getRootElement();
        if (!root.getName().equals(STORES_ELMT))
            throw new MappingException("Invalid root element: " + doc.getRootElement().getName());
        List<StoreDefinition> stores = new ArrayList<StoreDefinition>();
        for (Object store : root.getChildren(STORE_ELMT)) stores.add(readStore((Element) store));
        for (Object view : root.getChildren(VIEW_ELMT)) stores.add(readView((Element) view, stores));
        return stores;
    } 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) Element(org.jdom.Element) ArrayList(java.util.ArrayList) JDOMSource(org.jdom.transform.JDOMSource) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) SAXException(org.xml.sax.SAXException) StoreDefinition(voldemort.store.StoreDefinition) Validator(javax.xml.validation.Validator)

Aggregations

IOException (java.io.IOException)3 JDOMException (org.jdom.JDOMException)3 JDOMSource (org.jdom.transform.JDOMSource)3 ArrayList (java.util.ArrayList)2 Validator (javax.xml.validation.Validator)2 Document (org.jdom.Document)2 Element (org.jdom.Element)2 SAXBuilder (org.jdom.input.SAXBuilder)2 SAXException (org.xml.sax.SAXException)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 StringWriter (java.io.StringWriter)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Transformer (javax.xml.transform.Transformer)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 StreamResult (javax.xml.transform.stream.StreamResult)1 Nullable (org.jetbrains.annotations.Nullable)1 Cluster (voldemort.cluster.Cluster)1 Node (voldemort.cluster.Node)1 Zone (voldemort.cluster.Zone)1