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