Search in sources :

Example 16 with SAXBuilder

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);
    }
}
Also used : XPath(org.jdom.xpath.XPath) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) Document(org.jdom.Document) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 17 with SAXBuilder

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);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Example 18 with SAXBuilder

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);
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) StringReader(java.io.StringReader) Document(org.jdom.Document)

Example 19 with SAXBuilder

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);
        }
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) InputStream(java.io.InputStream) Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document)

Example 20 with SAXBuilder

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);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Aggregations

SAXBuilder (org.jdom.input.SAXBuilder)145 Document (org.jdom.Document)109 Element (org.jdom.Element)84 IOException (java.io.IOException)60 JDOMException (org.jdom.JDOMException)50 StringReader (java.io.StringReader)35 InputStream (java.io.InputStream)29 File (java.io.File)18 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)13 ArrayList (java.util.ArrayList)12 XPath (org.jdom.xpath.XPath)11 HttpMethod (org.apache.commons.httpclient.HttpMethod)10 XMLOutputter (org.jdom.output.XMLOutputter)10 URL (java.net.URL)9 List (java.util.List)8 GoraException (org.apache.gora.util.GoraException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 Namespace (org.jdom.Namespace)6 StringWriter (java.io.StringWriter)5