use of org.jdom.input.SAXBuilder in project android by JetBrains.
the class GuiTestRule method cleanUpProjectForImport.
public void cleanUpProjectForImport(@NotNull File projectPath) {
File dotIdeaFolderPath = new File(projectPath, Project.DIRECTORY_STORE_FOLDER);
if (dotIdeaFolderPath.isDirectory()) {
File modulesXmlFilePath = new File(dotIdeaFolderPath, "modules.xml");
if (modulesXmlFilePath.isFile()) {
SAXBuilder saxBuilder = new SAXBuilder();
try {
Document document = saxBuilder.build(modulesXmlFilePath);
XPath xpath = XPath.newInstance("//*[@fileurl]");
//noinspection unchecked
List<Element> modules = xpath.selectNodes(document);
int urlPrefixSize = "file://$PROJECT_DIR$/".length();
for (Element module : modules) {
String fileUrl = module.getAttributeValue("fileurl");
if (!StringUtil.isEmpty(fileUrl)) {
String relativePath = FileUtil.toSystemDependentName(fileUrl.substring(urlPrefixSize));
File imlFilePath = new File(projectPath, relativePath);
if (imlFilePath.isFile()) {
FileUtilRt.delete(imlFilePath);
}
// It is likely that each module has a "build" folder. Delete it as well.
File buildFilePath = new File(imlFilePath.getParentFile(), "build");
if (buildFilePath.isDirectory()) {
FileUtilRt.delete(buildFilePath);
}
}
}
} catch (Throwable ignored) {
// if something goes wrong, just ignore. Most likely it won't affect project import in any way.
}
}
FileUtilRt.delete(dotIdeaFolderPath);
}
}
use of org.jdom.input.SAXBuilder in project intellij-plugins by JetBrains.
the class P2PNetworkXmlMessage method processResponse.
void processResponse() {
if (myMessage == null || !myMessage.needsResponse())
return;
try {
final String response = getResponse().toString();
if (!com.intellij.openapi.util.text.StringUtil.isEmptyOrSpaces(response)) {
Document document = new SAXBuilder().build(new StringReader(response));
myMessage.processResponse(document.getRootElement());
}
} catch (JDOMException e) {
LOG.error(e.getMessage(), e);
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
}
use of org.jdom.input.SAXBuilder 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.input.SAXBuilder 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);
}
}
}
use of org.jdom.input.SAXBuilder in project gora by apache.
the class MongoMappingBuilder method fromFile.
/**
* Load the {@link org.apache.gora.mongodb.store.MongoMapping} from a file
* passed in parameter.
*
* @param uri
* path to the file holding the mapping
* @throws java.io.IOException
*/
protected void fromFile(String uri) throws IOException {
try {
SAXBuilder saxBuilder = new SAXBuilder();
InputStream is = getClass().getResourceAsStream(uri);
if (is == null) {
String msg = "Unable to load the mapping from resource '" + uri + "' as it does not appear to exist! " + "Trying local file.";
MongoStore.LOG.warn(msg);
is = new FileInputStream(uri);
}
Document doc = saxBuilder.build(is);
Element root = doc.getRootElement();
// No need to use documents descriptions for now...
// Extract class descriptions
@SuppressWarnings("unchecked") List<Element> classElements = root.getChildren(TAG_CLASS);
for (Element classElement : classElements) {
final Class<T> persistentClass = dataStore.getPersistentClass();
final Class<K> keyClass = dataStore.getKeyClass();
if (haveKeyClass(keyClass, classElement) && havePersistentClass(persistentClass, classElement)) {
loadPersistentClass(classElement, persistentClass);
// only need that
break;
}
}
} catch (IOException ex) {
MongoStore.LOG.error(ex.getMessage());
MongoStore.LOG.error(ex.getStackTrace().toString());
throw ex;
} catch (Exception ex) {
MongoStore.LOG.error(ex.getMessage());
MongoStore.LOG.error(ex.getStackTrace().toString());
throw new IOException(ex);
}
}
Aggregations