use of org.jdom.Document 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);
}
}
use of org.jdom.Document in project gora by apache.
the class HBaseStore method readMapping.
@SuppressWarnings("unchecked")
private HBaseMapping readMapping(String filename) throws IOException {
HBaseMappingBuilder mappingBuilder = new HBaseMappingBuilder();
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(getClass().getClassLoader().getResourceAsStream(filename));
Element root = doc.getRootElement();
List<Element> tableElements = root.getChildren("table");
for (Element tableElement : tableElements) {
String tableName = tableElement.getAttributeValue("name");
List<Element> fieldElements = tableElement.getChildren("family");
for (Element fieldElement : fieldElements) {
String familyName = fieldElement.getAttributeValue("name");
String compression = fieldElement.getAttributeValue("compression");
String blockCache = fieldElement.getAttributeValue("blockCache");
String blockSize = fieldElement.getAttributeValue("blockSize");
String bloomFilter = fieldElement.getAttributeValue("bloomFilter");
String maxVersions = fieldElement.getAttributeValue("maxVersions");
String timeToLive = fieldElement.getAttributeValue("timeToLive");
String inMemory = fieldElement.getAttributeValue("inMemory");
mappingBuilder.addFamilyProps(tableName, familyName, compression, blockCache, blockSize, bloomFilter, maxVersions, timeToLive, inMemory);
}
}
List<Element> classElements = root.getChildren("class");
boolean keyClassMatches = false;
for (Element classElement : classElements) {
if (classElement.getAttributeValue("keyClass").equals(keyClass.getCanonicalName()) && classElement.getAttributeValue("name").equals(persistentClass.getCanonicalName())) {
LOG.debug("Keyclass and nameclass match.");
keyClassMatches = true;
String tableNameFromMapping = classElement.getAttributeValue("table");
String tableName = getSchemaName(tableNameFromMapping, persistentClass);
//tableNameFromMapping could be null here
if (!tableName.equals(tableNameFromMapping)) {
//TODO this might not be the desired behavior as the user might have actually made a mistake.
LOG.warn("Mismatching schema's names. Mappingfile schema: '{}'. PersistentClass schema's name: '{}'. Assuming they are the same.", tableNameFromMapping, tableName);
if (tableNameFromMapping != null) {
mappingBuilder.renameTable(tableNameFromMapping, tableName);
}
}
mappingBuilder.setTableName(tableName);
List<Element> fields = classElement.getChildren("field");
for (Element field : fields) {
String fieldName = field.getAttributeValue("name");
String family = field.getAttributeValue("family");
String qualifier = field.getAttributeValue("qualifier");
mappingBuilder.addField(fieldName, family, qualifier);
mappingBuilder.addColumnFamily(tableName, family);
}
//do not continue on other class definitions
break;
}
}
if (!keyClassMatches)
LOG.error("KeyClass in gora-hbase-mapping is not the same as the one in the databean.");
} catch (MalformedURLException ex) {
LOG.error("Error while trying to read the mapping file {}. " + "Expected to be in the classpath " + "(ClassLoader#getResource(java.lang.String)).", filename);
LOG.error("Actual classpath = {}", Arrays.asList(((URLClassLoader) getClass().getClassLoader()).getURLs()));
throw ex;
} catch (IOException ex) {
LOG.error(ex.getMessage(), ex);
throw ex;
} catch (Exception ex) {
LOG.error(ex.getMessage(), ex);
throw new IOException(ex);
}
return mappingBuilder.build();
}
use of org.jdom.Document in project gora by apache.
the class GoraDynamoDBCompiler method readMapping.
/**
* Reads the schema file and converts it into a data structure to be used
* @param pMapFile
* schema file to be mapped into a table
* @return
* @throws IOException
*/
@SuppressWarnings("unchecked")
private DynamoDBMapping readMapping(File pMapFile) throws IOException {
DynamoDBMappingBuilder mappingBuilder = new DynamoDBMappingBuilder();
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(pMapFile);
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"));
this.packageName = tableElement.getAttributeValue("package");
mappingBuilder.setProvisionedThroughput(tableName, readCapacUnits, writeCapacUnits);
log.debug("Table properties have been set for name, package 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 '{}' have been read.", tableName);
if (!keys)
log.warn("Keys for table '{}' have NOT been set.", tableName);
}
} catch (IOException ex) {
log.error("Error while performing xml mapping.", ex.getMessage());
throw new RuntimeException(ex);
} catch (Exception ex) {
log.error("An error occured whilst reading the xml mapping file!", ex.getMessage());
throw new IOException(ex);
}
return mappingBuilder.build();
}
use of org.jdom.Document in project intellij-community by JetBrains.
the class ExportHTMLAction method dump2xml.
private void dump2xml(final String outputDirectoryName) {
try {
final File outputDir = new File(outputDirectoryName);
if (!outputDir.exists() && !outputDir.mkdirs()) {
throw new IOException("Cannot create \'" + outputDir + "\'");
}
final InspectionTreeNode root = myView.getTree().getRoot();
final IOException[] ex = new IOException[1];
final Set<InspectionToolWrapper> visitedWrappers = new THashSet<>();
TreeUtil.traverse(root, node -> {
if (node instanceof InspectionNode) {
InspectionNode toolNode = (InspectionNode) node;
Element problems = new Element(PROBLEMS);
InspectionToolWrapper toolWrapper = toolNode.getToolWrapper();
if (!visitedWrappers.add(toolWrapper))
return true;
final Set<InspectionToolWrapper> toolWrappers = getWorkedTools(toolNode);
for (InspectionToolWrapper wrapper : toolWrappers) {
InspectionToolPresentation presentation = myView.getGlobalInspectionContext().getPresentation(wrapper);
final ExcludedInspectionTreeNodesManager excludedManager = myView.getExcludedManager();
if (!toolNode.isExcluded(excludedManager)) {
presentation.exportResults(problems, e -> excludedManager.containsRefEntity(e, toolWrapper), excludedManager::containsProblemDescriptor);
}
}
PathMacroManager.getInstance(myView.getProject()).collapsePaths(problems);
try {
if (problems.getContentSize() != 0) {
JDOMUtil.writeDocument(new Document(problems), outputDirectoryName + File.separator + toolWrapper.getShortName() + InspectionApplication.XML_EXTENSION, CodeStyleSettingsManager.getSettings(null).getLineSeparator());
}
} catch (IOException e) {
ex[0] = e;
}
}
return true;
});
if (ex[0] != null) {
throw ex[0];
}
final Element element = new Element(InspectionApplication.INSPECTIONS_NODE);
final String profileName = myView.getCurrentProfileName();
if (profileName != null) {
element.setAttribute(InspectionApplication.PROFILE, profileName);
}
JDOMUtil.write(element, new File(outputDirectoryName, InspectionApplication.DESCRIPTIONS + InspectionApplication.XML_EXTENSION), CodeStyleSettingsManager.getSettings(null).getLineSeparator());
} catch (IOException e) {
ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(myView, e.getMessage()));
}
}
use of org.jdom.Document in project intellij-community by JetBrains.
the class TraverseUIStarter method startup.
public static void startup(String outputPath) throws IOException {
Map<SearchableConfigurable, Set<OptionDescription>> options = new LinkedHashMap<>();
try {
SearchUtil.processProjectConfigurables(ProjectManager.getInstance().getDefaultProject(), options);
Element root = new Element(OPTIONS);
for (SearchableConfigurable option : options.keySet()) {
SearchableConfigurable configurable = option;
Element configurableElement = new Element(CONFIGURABLE);
String id = configurable.getId();
configurableElement.setAttribute(ID, id);
configurableElement.setAttribute(CONFIGURABLE_NAME, configurable.getDisplayName());
Set<OptionDescription> sortedOptions = options.get(configurable);
writeOptions(configurableElement, sortedOptions);
if (configurable instanceof ConfigurableWrapper) {
UnnamedConfigurable wrapped = ((ConfigurableWrapper) configurable).getConfigurable();
if (wrapped instanceof SearchableConfigurable) {
configurable = (SearchableConfigurable) wrapped;
}
}
if (configurable instanceof KeymapPanel) {
processKeymap(configurableElement);
} else if (configurable instanceof OptionsContainingConfigurable) {
processOptionsContainingConfigurable((OptionsContainingConfigurable) configurable, configurableElement);
} else if (configurable instanceof PluginManagerConfigurable) {
for (OptionDescription description : wordsToOptionDescriptors(Collections.singleton(AvailablePluginsManagerMain.MANAGE_REPOSITORIES))) {
append(null, AvailablePluginsManagerMain.MANAGE_REPOSITORIES, description.getOption(), configurableElement);
}
} else if (configurable instanceof AllFileTemplatesConfigurable) {
processFileTemplates(configurableElement);
}
root.addContent(configurableElement);
}
FileUtil.ensureCanCreateFile(new File(outputPath));
JDOMUtil.writeDocument(new Document(root), outputPath, "\n");
System.out.println("Searchable options index builder completed");
} finally {
for (SearchableConfigurable configurable : options.keySet()) {
configurable.disposeUIResources();
}
}
}
Aggregations