Search in sources :

Example 11 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 12 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 13 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 14 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 15 with Attribute

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

the class SplitTextEditorProvider method readState.

@NotNull
@Override
public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
    Element child = sourceElement.getChild(FIRST_EDITOR);
    FileEditorState firstState = null;
    if (child != null) {
        firstState = myFirstProvider.readState(child, project, file);
    }
    child = sourceElement.getChild(SECOND_EDITOR);
    FileEditorState secondState = null;
    if (child != null) {
        secondState = mySecondProvider.readState(child, project, file);
    }
    final Attribute attribute = sourceElement.getAttribute(SPLIT_LAYOUT);
    final String layoutName;
    if (attribute != null) {
        layoutName = attribute.getValue();
    } else {
        layoutName = null;
    }
    return new SplitFileEditor.MyFileEditorState(layoutName, firstState, secondState);
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Attribute (org.jdom.Attribute)57 Element (org.jdom.Element)40 ArrayList (java.util.ArrayList)10 DataConversionException (org.jdom.DataConversionException)7 Iterator (java.util.Iterator)4 List (java.util.List)4 Document (org.jdom.Document)4 Namespace (org.jdom.Namespace)3 SAXBuilder (org.jdom.input.SAXBuilder)3 NotNull (org.jetbrains.annotations.NotNull)3 MacroscopicRateConstant (cbit.vcell.math.MacroscopicRateConstant)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 PathMacrosImpl (com.intellij.application.options.PathMacrosImpl)2 PathMacroFilter (com.intellij.openapi.application.PathMacroFilter)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Content (org.jdom.Content)2 Text (org.jdom.Text)2 BioPaxObject (org.vcell.pathway.BioPaxObject)2 RdfObjectProxy (org.vcell.pathway.persistence.BiopaxProxy.RdfObjectProxy)2 JDOMTreeWalker (cbit.util.xml.JDOMTreeWalker)1