Search in sources :

Example 81 with Document

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

the class JabberFacadeImpl method getServers.

public String[] getServers() {
    SAXBuilder saxBuilder = new SAXBuilder();
    try {
        Document document = saxBuilder.build(getClass().getResource("servers.xml"));
        Element rootElement = document.getRootElement();
        List children = rootElement.getChildren("item", rootElement.getNamespace());
        List<String> result = new ArrayList<>();
        for (Object aChildren : children) {
            Element element = (Element) aChildren;
            result.add(element.getAttributeValue("jid"));
        }
        return ArrayUtil.toStringArray(result);
    } catch (JDOMException e) {
        LOG.error(e.getMessage(), e);
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    }
    return new String[] { "jabber.org" };
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Example 82 with Document

use of org.jdom.Document in project android by JetBrains.

the class CompatibilityChecksMetadataTest method loadMetadata.

@Test
public void loadMetadata() throws Exception {
    @Language("XML") String metadataText = "<compatibility version='1'>\n" + "  <check failureType='error'>\n" + "    <component name='gradle' version='[2.4, +)'>\n" + "      <requires name='android-gradle-plugin' version='[1.5.0, +]'>\n" + "        <failureMsg>\n" + "           <![CDATA[\n" + "Please use Android Gradle plugin 1.5.0 or newer.\n" + "]]>\n" + "        </failureMsg>\n" + "      </requires>\n" + "    </component>\n" + "  </check>\n" + "</compatibility>";
    Document document = loadDocument(metadataText);
    CompatibilityChecksMetadata metadata = CompatibilityChecksMetadata.load(document.getRootElement());
    List<CompatibilityCheck> compatibilityChecks = metadata.getCompatibilityChecks();
    assertThat(compatibilityChecks).hasSize(1);
    CompatibilityCheck compatibilityCheck = compatibilityChecks.get(0);
    assertSame(ERROR, compatibilityCheck.getType());
    Component component = compatibilityCheck.getComponent();
    assertEquals("gradle", component.getName());
    // @formatter:off
    assertAbout(versionRange()).that(component.getVersionRange()).hasMinVersion("2.4").hasMaxVersion(null).isMinVersionInclusive(true).isMaxVersionInclusive(false);
    // @formatter:on
    List<Component> requirements = component.getRequirements();
    assertThat(requirements).hasSize(1);
    Component requirement = requirements.get(0);
    assertEquals("android-gradle-plugin", requirement.getName());
    // @formatter:off
    assertAbout(versionRange()).that(requirement.getVersionRange()).hasMinVersion("1.5.0").hasMaxVersion(null).isMinVersionInclusive(true).isMaxVersionInclusive(true);
    // @formatter:on
    assertEquals("Please use Android Gradle plugin 1.5.0 or newer.", requirement.getFailureMessage());
    Map<String, ComponentVersionReader> readers = metadata.getReadersByComponentName();
    assertSame(GRADLE, readers.get("gradle"));
    assertSame(ANDROID_GRADLE_PLUGIN, readers.get("android-gradle-plugin"));
}
Also used : Language(org.intellij.lang.annotations.Language) Document(org.jdom.Document) JDOMUtil.loadDocument(com.intellij.openapi.util.JDOMUtil.loadDocument) ComponentVersionReader(com.android.tools.idea.gradle.project.sync.compatibility.version.ComponentVersionReader) Test(org.junit.Test)

Example 83 with Document

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

the class FlexCompilationUtils method fixInitialContent.

private static String fixInitialContent(final VirtualFile descriptorFile, final String swfName) throws FlexCompilerException {
    try {
        final Document document;
        try {
            document = JDOMUtil.loadDocument(descriptorFile.getInputStream());
        } catch (IOException e) {
            throw new FlexCompilerException("Failed to read AIR descriptor content: " + e.getMessage(), descriptorFile.getUrl(), -1, -1);
        }
        final Element rootElement = document.getRootElement();
        if (!"application".equals(rootElement.getName())) {
            throw new FlexCompilerException("AIR descriptor file has incorrect root tag", descriptorFile.getUrl(), -1, -1);
        }
        Element initialWindowElement = rootElement.getChild("initialWindow", rootElement.getNamespace());
        if (initialWindowElement == null) {
            initialWindowElement = new Element("initialWindow", rootElement.getNamespace());
            rootElement.addContent(initialWindowElement);
        }
        Element contentElement = initialWindowElement.getChild("content", rootElement.getNamespace());
        if (contentElement == null) {
            contentElement = new Element("content", rootElement.getNamespace());
            initialWindowElement.addContent(contentElement);
        }
        contentElement.setText(swfName);
        return JDOMUtil.writeDocument(document, SystemProperties.getLineSeparator());
    } catch (JDOMException e) {
        throw new FlexCompilerException("AIR descriptor file has incorrect format: " + e.getMessage(), descriptorFile.getUrl(), -1, -1);
    }
}
Also used : PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Example 84 with Document

use of org.jdom.Document in project android by JetBrains.

the class MessagesFixture method getHtmlBody.

@Nullable
private static String getHtmlBody(@NotNull String html) {
    try {
        Document document = loadDocument(html);
        Element rootElement = document.getRootElement();
        String sheetTitle = rootElement.getChild("body").getText();
        return sheetTitle.replace("\n", "").trim();
    } catch (Throwable e) {
        Logger.getInstance(MessagesFixture.class).info("Failed to parse HTML '" + html + "'", e);
    }
    return null;
}
Also used : Element(org.jdom.Element) Document(org.jdom.Document) JDOMUtil.loadDocument(com.intellij.openapi.util.JDOMUtil.loadDocument) Nullable(org.jetbrains.annotations.Nullable)

Example 85 with Document

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

the class ConversionServiceImpl method saveConversionResult.

private static void saveConversionResult(ConversionContextImpl context) {
    final CachedConversionResult conversionResult = new CachedConversionResult();
    for (ConverterProvider provider : ConverterProvider.EP_NAME.getExtensions()) {
        conversionResult.myAppliedConverters.add(provider.getId());
    }
    conversionResult.myProjectFilesTimestamps = getProjectFilesMap(context);
    final File infoFile = getConversionInfoFile(context.getProjectFile());
    FileUtil.createParentDirs(infoFile);
    try {
        JDOMUtil.writeDocument(new Document(XmlSerializer.serialize(conversionResult)), infoFile, SystemProperties.getLineSeparator());
    } catch (IOException e) {
        LOG.info(e);
    }
}
Also used : IOException(java.io.IOException) Document(org.jdom.Document) File(java.io.File)

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