use of org.jdom.input.SAXBuilder in project liferay-ide by liferay.
the class InitConfigureProjectPage method _removeIvyPrivateSetting.
@SuppressWarnings("unchecked")
private void _removeIvyPrivateSetting(IPath sdkLocation) throws CoreException {
IPath ivySettingPath = sdkLocation.append("ivy-settings.xml");
File ivySettingFile = ivySettingPath.toFile();
SAXBuilder builder = new SAXBuilder(false);
builder.setValidation(false);
builder.setFeature("http://xml.org/sax/features/validation", false);
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
try (InputStream ivyInput = Files.newInputStream(ivySettingFile.toPath())) {
if (ivySettingFile.exists()) {
Document doc = builder.build(ivyInput);
Element itemRem = null;
Element elementRoot = doc.getRootElement();
List<Element> resolversElements = elementRoot.getChildren("resolvers");
for (Iterator<Element> resolversIterator = resolversElements.iterator(); resolversIterator.hasNext(); ) {
Element resolversElement = resolversIterator.next();
List<Element> chainElements = resolversElement.getChildren("chain");
for (Iterator<Element> chainIterator = chainElements.iterator(); chainIterator.hasNext(); ) {
Element chainElement = chainIterator.next();
List<Element> resolverElements = chainElement.getChildren("resolver");
for (Iterator<Element> resolverIterator = resolverElements.iterator(); resolverIterator.hasNext(); ) {
Element resolverItem = resolverIterator.next();
String resolverRefItem = resolverItem.getAttributeValue("ref");
if (resolverRefItem.equals("liferay-private")) {
resolverIterator.remove();
itemRem = resolverItem;
}
}
}
elementRoot.removeContent(itemRem);
List<Element> ibiblioElements = resolversElement.getChildren("ibiblio");
for (Iterator<Element> ibiblioIterator = ibiblioElements.iterator(); ibiblioIterator.hasNext(); ) {
Element ibiblioElement = ibiblioIterator.next();
String liferayPrivateName = ibiblioElement.getAttributeValue("name");
if (liferayPrivateName.equals("liferay-private")) {
ibiblioIterator.remove();
itemRem = ibiblioElement;
}
}
elementRoot.removeContent(itemRem);
}
_saveXML(ivySettingFile, doc);
}
} catch (CoreException | IOException | JDOMException e) {
ProjectUI.logError(e);
throw new CoreException(StatusBridge.create(Status.createErrorStatus("Failed to remove Liferay private url configuration of ivy-settings.xml.", e)));
}
}
use of org.jdom.input.SAXBuilder in project core by jcryptool.
the class FlexiProviderPlugin method getAlgorithmsXML.
/**
* Reads the algorithms.xml file and creates a document object.
*
* @return A jdom document
*/
public static Document getAlgorithmsXML() {
URL xmlFile = FlexiProviderPlugin.getDefault().getBundle().getEntry("/xml/algorithms.xml");
SAXBuilder builder = new SAXBuilder();
try {
return builder.build(xmlFile);
} catch (JDOMException e) {
LogUtil.logError(PLUGIN_ID, e);
} catch (IOException e) {
LogUtil.logError(PLUGIN_ID, e);
}
return null;
}
use of org.jdom.input.SAXBuilder in project oozie by apache.
the class XmlUtils method parseXml.
/**
* Parse a inputstream assuming it is a valid XML document and return an JDOM Element for it.
*
* @param is inputstream to parse.
* @return JDOM element for the parsed XML string.
* @throws JDOMException thrown if an error happend while XML parsing.
* @throws IOException thrown if an IO error occurred.
*/
public static Element parseXml(InputStream is) throws JDOMException, IOException {
ParamChecker.notNull(is, "is");
SAXBuilder saxBuilder = createSAXBuilder();
Document document = saxBuilder.build(is);
return document.getRootElement();
}
use of org.jdom.input.SAXBuilder in project oozie by apache.
the class XmlUtils method removeComments.
/**
* Remove comments from any Xml String.
*
* @param xmlStr XML string to remove comments.
* @return String after removing comments.
* @throws JDOMException thrown if an error happend while XML parsing.
*/
public static String removeComments(String xmlStr) throws JDOMException {
if (xmlStr == null) {
return null;
}
try {
SAXBuilder saxBuilder = createSAXBuilder();
Document document = saxBuilder.build(new StringReader(xmlStr));
removeComments(document);
return prettyPrint(document.getRootElement()).toString();
} catch (IOException ex) {
throw new RuntimeException("It should not happen, " + ex.getMessage(), ex);
}
}
use of org.jdom.input.SAXBuilder in project oozie by apache.
the class XmlUtils method getRootAttribute.
/**
* //TODO move this to action registry method Return the value of an attribute from the root element of an XML
* document.
*
* @param filePath path of the XML document.
* @param attributeName attribute to retrieve value for.
* @return value of the specified attribute.
*/
public static String getRootAttribute(String filePath, String attributeName) {
ParamChecker.notNull(filePath, "filePath");
ParamChecker.notNull(attributeName, "attributeName");
SAXBuilder saxBuilder = createSAXBuilder();
try {
Document doc = saxBuilder.build(Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath));
return doc.getRootElement().getAttributeValue(attributeName);
} catch (JDOMException e) {
throw new RuntimeException();
} catch (IOException e) {
throw new RuntimeException();
}
}
Aggregations