Search in sources :

Example 96 with SAXBuilder

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)));
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) IPath(org.eclipse.core.runtime.IPath) InputStream(java.io.InputStream) Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 97 with SAXBuilder

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;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) URL(java.net.URL)

Example 98 with SAXBuilder

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();
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Document(org.jdom.Document)

Example 99 with SAXBuilder

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);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.jdom.Document)

Example 100 with SAXBuilder

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();
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

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