Search in sources :

Example 6 with Attribute

use of org.jdom.Attribute in project maven-plugins by apache.

the class XmlAppendingTransformer method processResource.

public void processResource(String resource, InputStream is, List<Relocator> relocators) throws IOException {
    Document r;
    try {
        SAXBuilder builder = new SAXBuilder(false);
        builder.setExpandEntities(false);
        if (ignoreDtd) {
            builder.setEntityResolver(new EntityResolver() {

                public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
                    return new InputSource(new StringReader(""));
                }
            });
        }
        r = builder.build(is);
    } catch (JDOMException e) {
        throw new RuntimeException("Error processing resource " + resource + ": " + e.getMessage(), e);
    }
    if (doc == null) {
        doc = r;
    } else {
        Element root = r.getRootElement();
        for (@SuppressWarnings("unchecked") Iterator<Attribute> itr = root.getAttributes().iterator(); itr.hasNext(); ) {
            Attribute a = itr.next();
            itr.remove();
            Element mergedEl = doc.getRootElement();
            Attribute mergedAtt = mergedEl.getAttribute(a.getName(), a.getNamespace());
            if (mergedAtt == null) {
                mergedEl.setAttribute(a);
            }
        }
        for (@SuppressWarnings("unchecked") Iterator<Content> itr = root.getChildren().iterator(); itr.hasNext(); ) {
            Content n = itr.next();
            itr.remove();
            doc.getRootElement().addContent(n);
        }
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) InputSource(org.xml.sax.InputSource) Attribute(org.jdom.Attribute) Element(org.jdom.Element) EntityResolver(org.xml.sax.EntityResolver) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) SAXException(org.xml.sax.SAXException) Content(org.jdom.Content) StringReader(java.io.StringReader)

Example 7 with Attribute

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

the class DefaultArrangementSettingsSerializer method deserializeTokensDefinition.

@Nullable
private Set<StdArrangementRuleAliasToken> deserializeTokensDefinition(@NotNull Element element, @NotNull ArrangementSettings defaultSettings) {
    if (!(defaultSettings instanceof ArrangementExtendableSettings)) {
        return null;
    }
    final Element tokensRoot = element.getChild(TOKENS_ELEMENT_NAME);
    if (tokensRoot == null) {
        return ((ArrangementExtendableSettings) myDefaultSettings).getRuleAliases();
    }
    final Set<StdArrangementRuleAliasToken> tokenDefinitions = new THashSet<>();
    final List<Element> tokens = tokensRoot.getChildren(TOKEN_ELEMENT_NAME);
    for (Element token : tokens) {
        final Attribute id = token.getAttribute(TOKEN_ID);
        final Attribute name = token.getAttribute(TOKEN_NAME);
        assert id != null && name != null : "Can not find id for token: " + token;
        final Element rules = token.getChild(RULES_ELEMENT_NAME);
        final List<StdArrangementMatchRule> tokenRules = rules == null ? ContainerUtil.<StdArrangementMatchRule>emptyList() : deserializeRules(rules, null);
        tokenDefinitions.add(new StdArrangementRuleAliasToken(id.getValue(), name.getValue(), tokenRules));
    }
    return tokenDefinitions;
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element) THashSet(gnu.trove.THashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with Attribute

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

the class DefaultArrangementSettingsSerializer method deserializeSectionRules.

@NotNull
private List<ArrangementSectionRule> deserializeSectionRules(@NotNull Element rulesElement, @Nullable Set<StdArrangementRuleAliasToken> tokens) {
    final List<ArrangementSectionRule> sectionRules = new ArrayList<>();
    for (Object o : rulesElement.getChildren(SECTION_ELEMENT_NAME)) {
        final Element sectionElement = (Element) o;
        final List<StdArrangementMatchRule> rules = deserializeRules(sectionElement, tokens);
        final Attribute start = sectionElement.getAttribute(SECTION_START_ATTRIBUTE);
        final String startComment = start != null ? start.getValue().trim() : null;
        final Attribute end = sectionElement.getAttribute(SECTION_END_ATTRIBUTE);
        final String endComment = end != null ? end.getValue().trim() : null;
        sectionRules.add(ArrangementSectionRule.create(startComment, endComment, rules));
    }
    return sectionRules;
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with Attribute

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

the class PersistentFileSetManager method loadState.

@Override
public void loadState(Element state) {
    final VirtualFileManager vfManager = VirtualFileManager.getInstance();
    for (Object child : state.getChildren(FILE_ELEMENT)) {
        if (child instanceof Element) {
            final Element fileElement = (Element) child;
            final Attribute filePathAttr = fileElement.getAttribute(PATH_ATTR);
            if (filePathAttr != null) {
                final String filePath = filePathAttr.getValue();
                VirtualFile vf = vfManager.findFileByUrl(filePath);
                if (vf != null) {
                    myFiles.add(vf);
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) Attribute(org.jdom.Attribute) Element(org.jdom.Element)

Example 10 with Attribute

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

the class PathMacrosCollectorTest method testWithFilter.

public void testWithFilter() throws Exception {
    Element root = new Element("root");
    final Element testTag = new Element("test");
    testTag.setAttribute("path", "$MACRO$");
    testTag.setAttribute("ignore", "$PATH$");
    root.addContent(testTag);
    final Set<String> macros = PathMacrosCollector.getMacroNames(root, null, new PathMacrosImpl());
    assertEquals(2, macros.size());
    assertTrue(macros.contains("MACRO"));
    assertTrue(macros.contains("PATH"));
    final Set<String> filtered = PathMacrosCollector.getMacroNames(root, new PathMacroFilter() {

        @Override
        public boolean skipPathMacros(Attribute attribute) {
            return "ignore".equals(attribute.getName());
        }
    }, new PathMacrosImpl());
    assertEquals(1, filtered.size());
    assertTrue(macros.contains("MACRO"));
}
Also used : PathMacrosImpl(com.intellij.application.options.PathMacrosImpl) Attribute(org.jdom.Attribute) Element(org.jdom.Element) PathMacroFilter(com.intellij.openapi.application.PathMacroFilter)

Aggregations

Attribute (org.jdom.Attribute)40 Element (org.jdom.Element)30 DataConversionException (org.jdom.DataConversionException)6 ArrayList (java.util.ArrayList)4 Document (org.jdom.Document)3 SAXBuilder (org.jdom.input.SAXBuilder)3 NotNull (org.jetbrains.annotations.NotNull)3 PathMacrosImpl (com.intellij.application.options.PathMacrosImpl)2 PathMacroFilter (com.intellij.openapi.application.PathMacroFilter)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 EntityResolver (org.xml.sax.EntityResolver)2 AbstractColorsScheme (com.intellij.openapi.editor.colors.impl.AbstractColorsScheme)1 DefaultColorsScheme (com.intellij.openapi.editor.colors.impl.DefaultColorsScheme)1 SchemeImportException (com.intellij.openapi.options.SchemeImportException)1 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)1 ReplacementVariableDefinition (com.intellij.structuralsearch.ReplacementVariableDefinition)1 LwRootContainer (com.intellij.uiDesigner.lw.LwRootContainer)1 THashSet (gnu.trove.THashSet)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1