use of org.jdom.Document in project intellij-plugins by JetBrains.
the class SendXmlMessageP2PCommand method incomingMessage.
public String incomingMessage(String remoteUser, String messageText) {
String xml = StringUtil.fromXMLSafeString(messageText);
SAXBuilder builder = new SAXBuilder();
try {
Document document = builder.build(new StringReader(xml));
Element rootElement = document.getRootElement();
Element response = createResponse(rootElement, StringUtil.fromXMLSafeString(remoteUser));
if (response == null)
return "";
return new XMLOutputter().outputString(response);
} catch (Throwable e) {
LOG.info(e.getMessage(), e);
return StringUtil.toXML(e);
}
}
use of org.jdom.Document in project android by JetBrains.
the class CompatibilityChecksMetadataUpdater method fetchMetadata.
@NotNull
private static ActionCallback fetchMetadata() {
ActionCallback callback = new ActionCallback();
ApplicationManager.getApplication().executeOnPooledThread(() -> {
String url = "https://dl.google.com/android/studio/metadata/android-component-compatibility.xml";
try {
Document metadata = HttpRequests.request(url).connect(request -> {
try {
return loadDocument(request.getInputStream());
} catch (JDOMException e) {
LOG.info("Failed to parse XML metadata", e);
return null;
} catch (Throwable e) {
LOG.info("Failed to parse XML metadata", e);
return null;
}
});
if (metadata != null) {
VersionCompatibilityChecker.getInstance().updateMetadata(metadata);
callback.setDone();
}
} catch (IOException e) {
LOG.info(String.format("Failed to connect to '%1$s'", url), e);
}
callback.setRejected();
});
return callback;
}
use of org.jdom.Document 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.Document in project maven-plugins by apache.
the class PomWriter method write.
public static void write(Writer w, Model newModel, boolean namespaceDeclaration) throws IOException {
Element root = new Element("project");
if (namespaceDeclaration) {
String modelVersion = newModel.getModelVersion();
Namespace pomNamespace = Namespace.getNamespace("", "http://maven.apache.org/POM/" + modelVersion);
root.setNamespace(pomNamespace);
Namespace xsiNamespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
root.addNamespaceDeclaration(xsiNamespace);
if (root.getAttribute("schemaLocation", xsiNamespace) == null) {
root.setAttribute("schemaLocation", "http://maven.apache.org/POM/" + modelVersion + " http://maven.apache.org/maven-v" + modelVersion.replace('.', '_') + ".xsd", xsiNamespace);
}
}
Document doc = new Document(root);
MavenJDOMWriter writer = new MavenJDOMWriter();
String encoding = newModel.getModelEncoding() != null ? newModel.getModelEncoding() : "UTF-8";
Format format = Format.getPrettyFormat().setEncoding(encoding);
writer.write(newModel, doc, w, format);
}
use of org.jdom.Document in project gora by apache.
the class CassandraMappingManager method loadConfiguration.
/**
* Primary class for loading Cassandra configuration from the 'MAPPING_FILE'.
*
* @throws JDOMException
* @throws IOException
*/
@SuppressWarnings("unchecked")
public void loadConfiguration() throws JDOMException, IOException {
SAXBuilder saxBuilder = new SAXBuilder();
// get mapping file
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(MAPPING_FILE);
if (inputStream == null) {
LOG.warn("Mapping file '" + MAPPING_FILE + "' could not be found!");
throw new IOException("Mapping file '" + MAPPING_FILE + "' could not be found!");
}
Document document = saxBuilder.build(inputStream);
if (document == null) {
LOG.warn("Mapping file '" + MAPPING_FILE + "' could not be found!");
throw new IOException("Mapping file '" + MAPPING_FILE + "' could not be found!");
}
Element root = document.getRootElement();
// find cassandra keyspace element
List<Element> keyspaces = root.getChildren(KEYSPACE_ELEMENT);
if (keyspaces == null || keyspaces.size() == 0) {
LOG.error("Error locating Cassandra Keyspace element!");
} else {
for (Element keyspace : keyspaces) {
// log name, cluster and host for given keyspace(s)
String keyspaceName = keyspace.getAttributeValue(NAME_ATTRIBUTE);
String clusterName = keyspace.getAttributeValue(CLUSTER_ATTRIBUTE);
String hostName = keyspace.getAttributeValue(HOST_ATTRIBUTE);
if (LOG.isDebugEnabled()) {
LOG.debug("Located Cassandra Keyspace: '" + keyspaceName + "' in cluster '" + clusterName + "' on host '" + hostName + "'.");
}
if (keyspaceName == null) {
LOG.error("Error locating Cassandra Keyspace name attribute!");
continue;
}
keyspaceMap.put(keyspaceName, keyspace);
}
}
// load column definitions
List<Element> mappings = root.getChildren(MAPPING_ELEMENT);
if (mappings == null || mappings.size() == 0) {
LOG.error("Error locating Cassandra Mapping class element!");
} else {
for (Element mapping : mappings) {
// associate persistent and class names for keyspace(s)
String className = mapping.getAttributeValue(NAME_ATTRIBUTE);
String keyClassName = mapping.getAttributeValue(KEYCLASS_ATTRIBUTE);
String keyspaceName = mapping.getAttributeValue(KEYSPACE_ELEMENT);
if (LOG.isDebugEnabled()) {
LOG.debug("Located Cassandra Mapping: keyClass: '" + keyClassName + "' in storage class '" + className + "' for Keyspace '" + keyspaceName + "'.");
}
if (className == null) {
LOG.error("Error locating Cassandra Mapping class name attribute!");
continue;
}
mappingMap.put(className, mapping);
}
}
}
Aggregations