Search in sources :

Example 1 with DOMReader

use of org.dom4j.io.DOMReader in project Openfire by igniterealtime.

the class Xep227Exporter method importUsers.

/* (non-Javadoc)
   * @see org.jivesoftware.openfire.plugin.InExporter#importUsers(java.io.InputStream, java.lang.String, boolean)
   */
@Override
public List<String> importUsers(InputStream inputStream, String previousDomain, boolean isUserProviderReadOnly) {
    Log.debug("importUsers");
    DOMReader xmlReader = new DOMReader();
    Document doc = xmlReader.read(new UserSchemaValidator(inputStream).validateAndParse());
    return importUsers(doc, previousDomain, isUserProviderReadOnly);
}
Also used : DOMReader(org.dom4j.io.DOMReader) Document(org.dom4j.Document)

Example 2 with DOMReader

use of org.dom4j.io.DOMReader in project Openfire by igniterealtime.

the class OpenfireExporter method importUsers.

/* (non-Javadoc)
   * @see org.jivesoftware.openfire.plugin.InExporter#importUsers(java.io.InputStream, java.lang.String, boolean)
   */
@Override
public List<String> importUsers(InputStream inputStream, String previousDomain, boolean isUserProviderReadOnly) {
    Log.debug("importUsers");
    DOMReader xmlReader = new DOMReader();
    Document doc = xmlReader.read(new UserSchemaValidator(inputStream).validateAndParse());
    return importUsers(doc, previousDomain, isUserProviderReadOnly);
}
Also used : DOMReader(org.dom4j.io.DOMReader) Document(org.dom4j.Document)

Example 3 with DOMReader

use of org.dom4j.io.DOMReader in project zm-mailbox by Zimbra.

the class W3cDomUtil method parseXMLToDom4jDocUsingSecureProcessing.

/**
 * Note: DOCTYPE is disallowed for reasons of security and protection against denial of service
 * @throws XmlParseException
 */
public static org.dom4j.Document parseXMLToDom4jDocUsingSecureProcessing(InputStream is) throws XmlParseException {
    org.w3c.dom.Document w3cDoc = W3cDomUtil.parseXMLToDoc(is);
    DOMReader reader = new DOMReader();
    return reader.read(w3cDoc);
}
Also used : DOMReader(org.dom4j.io.DOMReader) Document(org.w3c.dom.Document)

Example 4 with DOMReader

use of org.dom4j.io.DOMReader in project hudson-2.x by hudson.

the class JDKInstaller method locateStage1.

// dom4j doesn't do generics, apparently... should probably switch to XOM
@SuppressWarnings("unchecked")
private HttpURLConnection locateStage1(Platform platform, CPU cpu) throws IOException {
    URL url = new URL("https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewProductDetail-Start?ProductRef=" + id);
    String cookie;
    Element form;
    try {
        HttpURLConnection con = (HttpURLConnection) ProxyConfiguration.open(url);
        cookie = con.getHeaderField("Set-Cookie");
        LOGGER.fine("Cookie=" + cookie);
        Tidy tidy = new Tidy();
        tidy.setErrout(new PrintWriter(new NullWriter()));
        DOMReader domReader = new DOMReader();
        Document dom = domReader.read(tidy.parseDOM(con.getInputStream(), null));
        form = null;
        for (Element e : (List<Element>) dom.selectNodes("//form")) {
            String action = e.attributeValue("action");
            LOGGER.fine("Found form:" + action);
            if (action.contains("ViewFilteredProducts")) {
                form = e;
                break;
            }
        }
    } catch (IOException e) {
        throw new IOException2("Failed to access " + url, e);
    }
    url = new URL(form.attributeValue("action"));
    try {
        HttpURLConnection con = (HttpURLConnection) ProxyConfiguration.open(url);
        con.setRequestMethod("POST");
        con.setDoOutput(true);
        con.setRequestProperty("Cookie", cookie);
        con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        PrintStream os = new PrintStream(con.getOutputStream());
        // select platform
        String primary = null, secondary = null;
        Element p = (Element) form.selectSingleNode(".//select[@id='dnld_platform']");
        for (Element opt : (List<Element>) p.elements("option")) {
            String value = opt.attributeValue("value");
            String vcap = value.toUpperCase(Locale.ENGLISH);
            if (!platform.is(vcap))
                continue;
            switch(cpu.accept(vcap)) {
                case PRIMARY:
                    primary = value;
                    break;
                case SECONDARY:
                    secondary = value;
                    break;
                case UNACCEPTABLE:
                    break;
            }
        }
        if (primary == null)
            primary = secondary;
        if (primary == null)
            throw new AbortException("Couldn't find the right download for " + platform + " and " + cpu + " combination");
        os.print(p.attributeValue("name") + '=' + primary);
        LOGGER.fine("Platform choice:" + primary);
        // select language
        Element l = (Element) form.selectSingleNode(".//select[@id='dnld_language']");
        if (l != null) {
            os.print("&" + l.attributeValue("name") + "=" + l.element("option").attributeValue("value"));
        }
        // the rest
        for (Element e : (List<Element>) form.selectNodes(".//input")) {
            os.print('&');
            os.print(e.attributeValue("name"));
            os.print('=');
            String value = e.attributeValue("value");
            if (value == null)
                // assume this is a checkbox
                os.print("on");
            else
                os.print(URLEncoder.encode(value, "UTF-8"));
        }
        os.close();
        return con;
    } catch (IOException e) {
        throw new IOException2("Failed to access " + url, e);
    }
}
Also used : PrintStream(java.io.PrintStream) Element(org.dom4j.Element) IOException(java.io.IOException) Document(org.dom4j.Document) Tidy(org.w3c.tidy.Tidy) URL(java.net.URL) NullWriter(org.apache.commons.io.output.NullWriter) DOMReader(org.dom4j.io.DOMReader) HttpURLConnection(java.net.HttpURLConnection) ArrayList(java.util.ArrayList) List(java.util.List) IOException2(hudson.util.IOException2) PrintWriter(java.io.PrintWriter) AbortException(hudson.AbortException)

Example 5 with DOMReader

use of org.dom4j.io.DOMReader in project uPortal by Jasig.

the class AbstractDom4jImporter method convertToElement.

protected Element convertToElement(Source source) {
    if (source instanceof StAXSource) {
        final StAXSource staxSource = (StAXSource) source;
        final DOMConverter domConverter = new DOMConverter();
        final Document document;
        try {
            XMLStreamReader xmlStreamReader = staxSource.getXMLStreamReader();
            if (xmlStreamReader == null) {
                final XMLEventReader xmlEventReader = staxSource.getXMLEventReader();
                xmlStreamReader = new FixedXMLEventStreamReader(xmlEventReader);
            }
            document = domConverter.buildDocument(xmlStreamReader);
        } catch (XMLStreamException e) {
            throw new RuntimeException("Failed to parse StAX Reader into Dom4J Element", e);
        }
        final DOMReader domReader = new DOMReader();
        final org.dom4j.Document dom4JDocument = domReader.read(document);
        dom4JDocument.setName(source.getSystemId());
        return dom4JDocument.getRootElement();
    }
    throw new IllegalArgumentException("Source of type " + source.getClass() + " is not supported");
}
Also used : DOMReader(org.dom4j.io.DOMReader) XMLStreamReader(javax.xml.stream.XMLStreamReader) FixedXMLEventStreamReader(org.springframework.util.xml.FixedXMLEventStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEventReader(javax.xml.stream.XMLEventReader) StAXSource(javax.xml.transform.stax.StAXSource) Document(org.w3c.dom.Document) DOMConverter(org.codehaus.staxmate.dom.DOMConverter)

Aggregations

DOMReader (org.dom4j.io.DOMReader)5 Document (org.dom4j.Document)3 Document (org.w3c.dom.Document)2 AbortException (hudson.AbortException)1 IOException2 (hudson.util.IOException2)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 PrintWriter (java.io.PrintWriter)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 StAXSource (javax.xml.transform.stax.StAXSource)1 NullWriter (org.apache.commons.io.output.NullWriter)1 DOMConverter (org.codehaus.staxmate.dom.DOMConverter)1 Element (org.dom4j.Element)1 FixedXMLEventStreamReader (org.springframework.util.xml.FixedXMLEventStreamReader)1