Search in sources :

Example 96 with Document

use of org.jdom.Document 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 97 with Document

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

the class XmlSerializer method deserialize.

@NotNull
public static <T> T deserialize(@NotNull URL url, Class<T> aClass) throws XmlSerializationException {
    try {
        Document document = JDOMUtil.loadDocument(url);
        document = JDOMXIncluder.resolve(document, url.toExternalForm());
        return deserialize(document.getRootElement(), aClass);
    } catch (IOException e) {
        throw new XmlSerializationException(e);
    } catch (JDOMException e) {
        throw new XmlSerializationException(e);
    }
}
Also used : IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull)

Example 98 with Document

use of org.jdom.Document 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 99 with Document

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

the class PluginManagerCore method loadDescriptorFromJar.

@Nullable
private static IdeaPluginDescriptorImpl loadDescriptorFromJar(@NotNull File file, @NotNull String fileName, @NotNull JDOMXIncluder.PathResolver pathResolver) {
    try {
        URL jarURL = URLUtil.getJarEntryURL(file, META_INF + '/' + fileName);
        ZipFile zipFile = new ZipFile(file);
        try {
            ZipEntry entry = zipFile.getEntry(META_INF + '/' + fileName);
            if (entry != null) {
                Document document = JDOMUtil.loadDocument(zipFile.getInputStream(entry));
                IdeaPluginDescriptorImpl descriptor = new IdeaPluginDescriptorImpl(file);
                descriptor.readExternal(document, jarURL, pathResolver);
                return descriptor;
            }
        } finally {
            zipFile.close();
        }
    } catch (XmlSerializationException e) {
        getLogger().info("Cannot load " + file, e);
        prepareLoadingPluginsErrorMessage(Collections.singletonList("File '" + file.getName() + "' contains invalid plugin descriptor."));
    } catch (Throwable e) {
        getLogger().info("Cannot load " + file, e);
    }
    return null;
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) XmlSerializationException(com.intellij.util.xmlb.XmlSerializationException) Document(org.jdom.Document) URL(java.net.URL) Nullable(org.jetbrains.annotations.Nullable)

Example 100 with Document

use of org.jdom.Document 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)

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