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);
}
}
}
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;
}
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;
}
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);
}
}
}
}
}
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"));
}
Aggregations