use of org.jdom.Document in project voldemort by voldemort.
the class StoreDefinitionsMapper method readStoreList.
public List<StoreDefinition> readStoreList(Reader input, boolean verifySchema) {
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(input);
if (verifySchema) {
Validator validator = schema.newValidator();
validator.validate(new JDOMSource(doc));
}
Element root = doc.getRootElement();
if (!root.getName().equals(STORES_ELMT))
throw new MappingException("Invalid root element: " + doc.getRootElement().getName());
List<StoreDefinition> stores = new ArrayList<StoreDefinition>();
for (Object store : root.getChildren(STORE_ELMT)) stores.add(readStore((Element) store));
for (Object view : root.getChildren(VIEW_ELMT)) stores.add(readView((Element) view, stores));
return stores;
} catch (JDOMException e) {
throw new MappingException(e);
} catch (SAXException e) {
throw new MappingException(e);
} catch (IOException e) {
throw new MappingException(e);
}
}
use of org.jdom.Document in project freud by LMAX-Exchange.
the class CssJdomParser method parseCssRules.
@SuppressWarnings("unchecked")
static Iterable<CssRule> parseCssRules(final Reader reader) throws RecognitionException, IOException {
List<CssRule> cssRuleList = new ArrayList<CssRule>();
Document root = parseCssToDocument(reader);
JXPathContext context = JXPathContext.newContext(root.getRootElement());
List<Element> cssRuleElementList = (List<Element>) context.selectNodes("/RULE");
for (Element element : cssRuleElementList) {
final CssRuleJdom cssRuleJdom = new CssRuleJdom(element, 0);
cssRuleList.add(cssRuleJdom);
for (int i = 1; i < cssRuleJdom.getNumberOfCommaSeparatedSelectorLists(); i++) {
cssRuleList.add(new CssRuleJdom(element, i));
}
}
return cssRuleList;
}
use of org.jdom.Document in project android by JetBrains.
the class LocalMavenRepository method isMatch.
@Nullable
private static Match isMatch(@NotNull File mavenMetadataFile, @NotNull SearchRequest request) {
String groupId = request.getGroupId();
String artifactName = request.getArtifactName();
try {
Document document = loadDocument(mavenMetadataFile);
Element rootElement = document.getRootElement();
if (rootElement != null) {
Element groupIdElement = rootElement.getChild("groupId");
if (groupId != null && groupIdElement == null) {
return null;
}
groupId = nullToEmpty(groupId);
String currentGroupId = nullToEmpty(groupIdElement.getValue());
if (!currentGroupId.contains(groupId)) {
return null;
}
Element artifactIdElement = rootElement.getChild("artifactId");
if (artifactIdElement == null) {
return null;
}
String currentArtifactName = artifactIdElement.getValue();
if (currentArtifactName.contains(artifactName)) {
return new Match(currentArtifactName, nullToEmpty(currentGroupId));
}
}
} catch (Throwable e) {
String msg = String.format("Failed to parse '%1$s'", mavenMetadataFile.getPath());
Logger.getInstance(LocalMavenRepository.class).warn(msg, e);
}
return null;
}
use of org.jdom.Document in project android by JetBrains.
the class MavenPoms method findDependenciesInPomFile.
@NotNull
public static List<PsArtifactDependencySpec> findDependenciesInPomFile(@NotNull File libraryPath) {
File pomFilePath = LibraryFilePaths.getInstance().findPomPathForLibrary(libraryPath);
if (pomFilePath == null) {
return Collections.emptyList();
}
List<PsArtifactDependencySpec> dependencies = Lists.newArrayList();
try {
Document document = loadDocument(pomFilePath);
Element rootElement = document.getRootElement();
if (rootElement != null) {
Element dependenciesElement = null;
for (Element childElement : rootElement.getChildren()) {
if ("dependencies".equals(childElement.getName())) {
dependenciesElement = childElement;
break;
}
}
if (dependenciesElement != null) {
for (Element childElement : dependenciesElement.getChildren()) {
if ("dependency".equals(childElement.getName())) {
PsArtifactDependencySpec spec = createSpec(childElement);
if (spec != null) {
dependencies.add(spec);
}
}
}
}
}
} catch (Exception e) {
String msg = String.format("Failed to obtain dependencies in POM file for library '%1$s", libraryPath.getName());
LOG.warn(msg, e);
}
return dependencies;
}
use of org.jdom.Document in project android by JetBrains.
the class ExternalRepository method doRefreshFor.
private void doRefreshFor(@NotNull final String groupId, @NotNull final String artifactId) {
String url = String.format(URL_TEMPLATE, groupId.replaceAll("\\.", "/"), artifactId);
Document document;
try {
document = JDOMUtil.loadDocument(URI.create(url).toURL());
} catch (JDOMException e) {
LOG.warn(String.format("Unexpected exception occurred on attempt to parse document from %s (checking the latest version " + "for artifact '%s:%s')", url, groupId, artifactId));
return;
} catch (IOException e) {
LOG.warn(String.format("Unexpected I/O exception occurred on attempt to check the latest version for artifact '%s:%s' at " + "external repository (url %s)", groupId, artifactId, url));
return;
}
Element versioning = document.getRootElement().getChild(MAVEN_METADATA_VERSIONING);
if (versioning == null) {
LOG.warn(String.format("Can't check the latest version for artifact '%s:%s'. Reason: artifact metadata info downloaded from " + "%s has unknown format - expected to find a <%s> element under a root element but it's not there", groupId, artifactId, url, MAVEN_METADATA_VERSIONING));
return;
}
Element latest = versioning.getChild(MAVEN_METADATA_LATEST);
if (latest == null) {
LOG.warn(String.format("Can't check the latest version for artifact '%s:%s'. Reason: artifact metadata info downloaded from " + "%s has unknown format - expected to find a <%s> element under a <%s> element but it's not there", groupId, artifactId, url, MAVEN_METADATA_LATEST, MAVEN_METADATA_VERSIONING));
return;
}
try {
GradleVersion version = GradleVersion.parse(latest.getText());
myLatestVersionCache.put(Pair.create(groupId, artifactId), version);
} catch (NumberFormatException e) {
LOG.warn(String.format("Can't check the latest version for artifact '%s:%s'. Reason: artifact metadata info downloaded from " + "%s has unknown version format - '%s'", groupId, artifactId, url, latest.getText()));
}
}
Aggregations