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