Search in sources :

Example 76 with Document

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

Example 77 with Document

use of org.jdom.Document in project freud by LMAX-Exchange.

the class CssJdomParser method parseCssRules.

@SuppressWarnings("unchecked")
static Iterable<CssRule> parseCssRules(final Reader reader) throws RecognitionException, IOException {
    List<CssRule> cssRuleList = new ArrayList<CssRule>();
    Document root = parseCssToDocument(reader);
    JXPathContext context = JXPathContext.newContext(root.getRootElement());
    List<Element> cssRuleElementList = (List<Element>) context.selectNodes("/RULE");
    for (Element element : cssRuleElementList) {
        final CssRuleJdom cssRuleJdom = new CssRuleJdom(element, 0);
        cssRuleList.add(cssRuleJdom);
        for (int i = 1; i < cssRuleJdom.getNumberOfCommaSeparatedSelectorLists(); i++) {
            cssRuleList.add(new CssRuleJdom(element, i));
        }
    }
    return cssRuleList;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) CssRule(org.freud.analysed.css.rule.CssRule) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.jdom.Document)

Example 78 with Document

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

the class LocalMavenRepository method isMatch.

@Nullable
private static Match isMatch(@NotNull File mavenMetadataFile, @NotNull SearchRequest request) {
    String groupId = request.getGroupId();
    String artifactName = request.getArtifactName();
    try {
        Document document = loadDocument(mavenMetadataFile);
        Element rootElement = document.getRootElement();
        if (rootElement != null) {
            Element groupIdElement = rootElement.getChild("groupId");
            if (groupId != null && groupIdElement == null) {
                return null;
            }
            groupId = nullToEmpty(groupId);
            String currentGroupId = nullToEmpty(groupIdElement.getValue());
            if (!currentGroupId.contains(groupId)) {
                return null;
            }
            Element artifactIdElement = rootElement.getChild("artifactId");
            if (artifactIdElement == null) {
                return null;
            }
            String currentArtifactName = artifactIdElement.getValue();
            if (currentArtifactName.contains(artifactName)) {
                return new Match(currentArtifactName, nullToEmpty(currentGroupId));
            }
        }
    } catch (Throwable e) {
        String msg = String.format("Failed to parse '%1$s'", mavenMetadataFile.getPath());
        Logger.getInstance(LocalMavenRepository.class).warn(msg, 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 79 with Document

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

the class MavenPoms method findDependenciesInPomFile.

@NotNull
public static List<PsArtifactDependencySpec> findDependenciesInPomFile(@NotNull File libraryPath) {
    File pomFilePath = LibraryFilePaths.getInstance().findPomPathForLibrary(libraryPath);
    if (pomFilePath == null) {
        return Collections.emptyList();
    }
    List<PsArtifactDependencySpec> dependencies = Lists.newArrayList();
    try {
        Document document = loadDocument(pomFilePath);
        Element rootElement = document.getRootElement();
        if (rootElement != null) {
            Element dependenciesElement = null;
            for (Element childElement : rootElement.getChildren()) {
                if ("dependencies".equals(childElement.getName())) {
                    dependenciesElement = childElement;
                    break;
                }
            }
            if (dependenciesElement != null) {
                for (Element childElement : dependenciesElement.getChildren()) {
                    if ("dependency".equals(childElement.getName())) {
                        PsArtifactDependencySpec spec = createSpec(childElement);
                        if (spec != null) {
                            dependencies.add(spec);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        String msg = String.format("Failed to obtain dependencies in POM file for library '%1$s", libraryPath.getName());
        LOG.warn(msg, e);
    }
    return dependencies;
}
Also used : PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) Element(org.jdom.Element) Document(org.jdom.Document) JDOMUtil.loadDocument(com.intellij.openapi.util.JDOMUtil.loadDocument) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 80 with Document

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

the class ExternalRepository method doRefreshFor.

private void doRefreshFor(@NotNull final String groupId, @NotNull final String artifactId) {
    String url = String.format(URL_TEMPLATE, groupId.replaceAll("\\.", "/"), artifactId);
    Document document;
    try {
        document = JDOMUtil.loadDocument(URI.create(url).toURL());
    } catch (JDOMException e) {
        LOG.warn(String.format("Unexpected exception occurred on attempt to parse document from %s (checking the latest version " + "for artifact '%s:%s')", url, groupId, artifactId));
        return;
    } catch (IOException e) {
        LOG.warn(String.format("Unexpected I/O exception occurred on attempt to check the latest version for artifact '%s:%s' at " + "external repository (url %s)", groupId, artifactId, url));
        return;
    }
    Element versioning = document.getRootElement().getChild(MAVEN_METADATA_VERSIONING);
    if (versioning == null) {
        LOG.warn(String.format("Can't check the latest version for artifact '%s:%s'. Reason: artifact metadata info downloaded from " + "%s has unknown format - expected to find a <%s> element under a root element but it's not there", groupId, artifactId, url, MAVEN_METADATA_VERSIONING));
        return;
    }
    Element latest = versioning.getChild(MAVEN_METADATA_LATEST);
    if (latest == null) {
        LOG.warn(String.format("Can't check the latest version for artifact '%s:%s'. Reason: artifact metadata info downloaded from " + "%s has unknown format - expected to find a <%s> element under a <%s> element but it's not there", groupId, artifactId, url, MAVEN_METADATA_LATEST, MAVEN_METADATA_VERSIONING));
        return;
    }
    try {
        GradleVersion version = GradleVersion.parse(latest.getText());
        myLatestVersionCache.put(Pair.create(groupId, artifactId), version);
    } catch (NumberFormatException e) {
        LOG.warn(String.format("Can't check the latest version for artifact '%s:%s'. Reason: artifact metadata info downloaded from " + "%s has unknown version format - '%s'", groupId, artifactId, url, latest.getText()));
    }
}
Also used : Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) GradleVersion(com.android.ide.common.repository.GradleVersion)

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