Search in sources :

Example 91 with SAXBuilder

use of org.jdom.input.SAXBuilder in project gora by apache.

the class DynamoDBStore method readMapping.

/** 
   * Reads the schema file and converts it into a data structure to be used
   *
   * @return DynamoDBMapping Object containing all necessary information to
   *         create tables
   * @throws IOException
   */
@SuppressWarnings("unchecked")
private DynamoDBMapping readMapping() throws IOException {
    DynamoDBMappingBuilder mappingBuilder = new DynamoDBMappingBuilder();
    try {
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(getClass().getClassLoader().getResourceAsStream(MAPPING_FILE));
        if (doc == null || doc.getRootElement() == null)
            throw new GoraException("Unable to load " + MAPPING_FILE + ". Please check its existance!");
        Element root = doc.getRootElement();
        List<Element> tableElements = root.getChildren("table");
        boolean keys = false;
        for (Element tableElement : tableElements) {
            String tableName = tableElement.getAttributeValue("name");
            long readCapacUnits = Long.parseLong(tableElement.getAttributeValue("readcunit"));
            long writeCapacUnits = Long.parseLong(tableElement.getAttributeValue("writecunit"));
            mappingBuilder.setProvisionedThroughput(tableName, readCapacUnits, writeCapacUnits);
            LOG.debug("Basic table properties have been set: Name, and Provisioned throughput.");
            // Retrieving attributes
            List<Element> fieldElements = tableElement.getChildren("attribute");
            for (Element fieldElement : fieldElements) {
                String key = fieldElement.getAttributeValue("key");
                String attributeName = fieldElement.getAttributeValue("name");
                String attributeType = fieldElement.getAttributeValue("type");
                mappingBuilder.addAttribute(tableName, attributeName, attributeType);
                // Retrieving key's features
                if (key != null) {
                    mappingBuilder.setKeySchema(tableName, attributeName, key);
                    keys = true;
                }
            }
            LOG.debug("Attributes for table '" + tableName + "' have been read.");
            if (!keys)
                LOG.warn("Keys for table '" + tableName + "' have NOT been set.");
        }
    } catch (IOException ex) {
        LOG.error("Error while performing xml mapping.", ex.getMessage());
        throw new IOException(ex);
    } catch (Exception ex) {
        LOG.error("Error while performing xml mapping.", ex.getMessage());
        throw new RuntimeException(ex);
    }
    return mappingBuilder.build();
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) GoraException(org.apache.gora.util.GoraException) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) Element(org.jdom.Element) DynamoDBMappingBuilder(org.apache.gora.dynamodb.store.DynamoDBMapping.DynamoDBMappingBuilder) IOException(java.io.IOException) Document(org.jdom.Document) GoraException(org.apache.gora.util.GoraException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 92 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-plugins by JetBrains.

the class BridgeSupportReader method read.

public static Framework read(final String name, final String version, final InputStream text, final boolean osx) {
    final Framework framework = new Framework(name, version, osx);
    try {
        final Element root = new SAXBuilder().build(text).getRootElement();
        readFramework(root, framework);
        framework.mergeClasses();
    } catch (Exception e) {
        LOG.error("Can't load framework", e, name, version, osx ? "osx" : "");
    } finally {
        StreamUtil.closeStream(text);
    }
    framework.seal();
    return framework;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element)

Example 93 with SAXBuilder

use of org.jdom.input.SAXBuilder in project flutter-intellij by flutter.

the class FlutterGuiTestRule 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 94 with SAXBuilder

use of org.jdom.input.SAXBuilder in project aliyun-oss-java-sdk by aliyun.

the class PerftestRunner method buildScenario.

public void buildScenario(final String scenarioTypeString) {
    File confFile = new File(System.getProperty("user.dir") + File.separator + "runner_conf.xml");
    InputStream input = null;
    try {
        input = new FileInputStream(confFile);
    } catch (FileNotFoundException e) {
        log.error(e);
        Assert.fail(e.getMessage());
    }
    SAXBuilder builder = new SAXBuilder();
    try {
        Document doc = builder.build(input);
        Element root = doc.getRootElement();
        scenario = new TestScenario();
        scenario.setHost(root.getChildText("host"));
        scenario.setAccessId(root.getChildText("accessid"));
        scenario.setAccessKey(root.getChildText("accesskey"));
        scenario.setBucketName(root.getChildText("bucket"));
        scenario.setType(determineScenarioType(scenarioTypeString));
        Element target = root.getChild(scenarioTypeString);
        if (target != null) {
            scenario.setContentLength(Long.parseLong(target.getChildText("size")));
            scenario.setPutThreadNumber(Integer.parseInt(target.getChildText("putthread")));
            scenario.setGetThreadNumber(Integer.parseInt(target.getChildText("getthread")));
            scenario.setDurationInSeconds(Integer.parseInt(target.getChildText("time")));
            scenario.setGetQPS(Integer.parseInt(target.getChildText("getqps")));
            scenario.setPutQPS(Integer.parseInt(target.getChildText("putqps")));
        } else {
            log.error("Unable to locate XML element " + scenarioTypeString);
            Assert.fail("Unable to locate XML element " + scenarioTypeString);
        }
    } catch (JDOMException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.jdom.Element) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 95 with SAXBuilder

use of org.jdom.input.SAXBuilder in project checkstyle-idea by jshiell.

the class ConfigurationLocation method extractProperties.

/**
 * Extract all settable properties from the given configuration file.
 *
 * @param inputStream the configuration file.
 * @return the property names.
 */
private List<String> extractProperties(final InputStream inputStream) {
    if (inputStream != null) {
        try {
            final SAXBuilder saxBuilder = new SAXBuilder();
            saxBuilder.setEntityResolver(new CheckStyleEntityResolver(this));
            final Document configDoc = saxBuilder.build(inputStream);
            return extractProperties(configDoc.getRootElement());
        } catch (Exception e) {
            LOG.warn("CheckStyle file could not be parsed for properties.", e);
        }
    }
    return new ArrayList<>();
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) CheckStyleEntityResolver(org.infernus.idea.checkstyle.util.CheckStyleEntityResolver) Document(org.jdom.Document) IOException(java.io.IOException)

Aggregations

SAXBuilder (org.jdom.input.SAXBuilder)146 Document (org.jdom.Document)110 Element (org.jdom.Element)84 IOException (java.io.IOException)61 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