Search in sources :

Example 46 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.

the class XsltDocumentationProvider method getDocumentationDocument.

private Document getDocumentationDocument() throws IOException, JDOMException {
    Document d = com.intellij.reference.SoftReference.dereference(myDocument);
    if (d == null) {
        d = new SAXBuilder().build(XsltSupport.class.getResource("resources/documentation.xml"));
        myDocument = new SoftReference<>(d);
    }
    return d;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Document(org.jdom.Document)

Example 47 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.

the class ModelLoader method load.

protected final void load(String name) {
    try {
        InputStream stream = getClass().getResourceAsStream(name);
        Document document = new SAXBuilder().build(stream);
        stream.close();
        loadDocument(document.getRootElement());
    } catch (Throwable e) {
        LOG.error(e);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) InputStream(java.io.InputStream) Document(org.jdom.Document)

Example 48 with SAXBuilder

use of org.jdom.input.SAXBuilder in project zaproxy by zaproxy.

the class ContentMatcher method loadXMLPatternDefinitions.

/**
     * Load a pattern list from an XML formatted file.
     * Pattern should be enclosed around a {@code <Patterns>} tag and should be
     * defined as {@code <Pattern type="xxx"></Pattern>}. Use "regex" to define
     * a Regex formatted pattern or "string" for an exact matching pattern.
     * @param xmlInputStream the {@code InputStream} used to read the patterns
     * @throws JDOMException if an error occurred while parsing
     * @throws IOException if an I/O error occurred while reading the {@code InputStream}
     */
protected void loadXMLPatternDefinitions(InputStream xmlInputStream) throws JDOMException, IOException {
    strings = new ArrayList<BoyerMooreMatcher>();
    patterns = new ArrayList<Pattern>();
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(xmlInputStream);
    Element el = doc.getRootElement();
    String value;
    // go ahead for boundaries and tests
    for (Object obj : el.getChildren(TAG_PATTERN)) {
        el = (Element) obj;
        value = el.getText();
        // Check if the pattern has been set to null
        if (value != null && !value.isEmpty()) {
            // Check if a regex expression has been set
            if (el.getAttributeValue(TAG_PATTERN_TYPE).equalsIgnoreCase(TAG_PATTERN_TYPE_REGEX)) {
                patterns.add(Pattern.compile(el.getText()));
            // Otherwise it's by default an exact match model
            } else {
                strings.add(new BoyerMooreMatcher(el.getText()));
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) Document(org.jdom.Document)

Example 49 with SAXBuilder

use of org.jdom.input.SAXBuilder in project ACS by ACS-Community.

the class TestHighLevelNodes method testXmlMACI.

public void testXmlMACI() throws Exception {
    logger.info("MACI XML string -- Classic: " + xmlXml);
    SAXBuilder sb = new SAXBuilder();
    InputStream is = new ByteArrayInputStream(rdbXml.getBytes("UTF-8"));
    Document doc = sb.build(is);
    XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    xout.output(doc, out);
    logger.info("MACI XML string -- RDB: " + out.toString());
    // This fails at the moment because XML returns namespace info, TMCDB doesn't
    assertXMLEqual("MACI XML pieces are similar ", xmlXml, rdbXml);
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.jdom.Document)

Example 50 with SAXBuilder

use of org.jdom.input.SAXBuilder in project Asqatasun by Asqatasun.

the class KbCsvMojo method getUrls.

private List<String> getUrls(String url) throws JDOMException, JaxenException, IOException {
    SAXBuilder builder = new SAXBuilder();
    EntityResolver resolver = new XhtmlEntityResolver();
    builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
    builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    builder.setEntityResolver(resolver);
    Document document = builder.build(new URL(url));
    XPath xpath = new JDOMXPath("//*[@id='resultat']//*[@href]/@href");
    List<Attribute> results = xpath.selectNodes(document);
    List<String> urls = new ArrayList<String>();
    for (Attribute attr : results) {
        urls.add(attr.getValue());
    }
    return urls;
}
Also used : XPath(org.jaxen.XPath) JDOMXPath(org.jaxen.jdom.JDOMXPath) SAXBuilder(org.jdom.input.SAXBuilder) JDOMXPath(org.jaxen.jdom.JDOMXPath) Attribute(org.jdom.Attribute) ArrayList(java.util.ArrayList) EntityResolver(org.xml.sax.EntityResolver) Document(org.jdom.Document) URL(java.net.URL)

Aggregations

SAXBuilder (org.jdom.input.SAXBuilder)68 Document (org.jdom.Document)51 Element (org.jdom.Element)47 IOException (java.io.IOException)27 JDOMException (org.jdom.JDOMException)24 InputStream (java.io.InputStream)18 StringReader (java.io.StringReader)13 HttpMethod (org.apache.commons.httpclient.HttpMethod)10 XPath (org.jdom.xpath.XPath)9 File (java.io.File)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 XMLOutputter (org.jdom.output.XMLOutputter)5 Nullable (org.jetbrains.annotations.Nullable)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 PostMethod (org.apache.commons.httpclient.methods.PostMethod)4 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)4 Format (org.jdom.output.Format)4 NotNull (org.jetbrains.annotations.NotNull)4 Logger (com.intellij.openapi.diagnostic.Logger)3