Example usage for javax.xml.stream XMLStreamReader getElementText

List of usage examples for javax.xml.stream XMLStreamReader getElementText

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamReader getElementText.

Prototype

public String getElementText() throws XMLStreamException;

Source Link

Document

Reads the content of a text-only element, an exception is thrown if this is not a text-only element.

Usage

From source file:davmail.exchange.dav.ExchangeDavMethod.java

protected void handleResponse(XMLStreamReader reader) throws XMLStreamException {
    MultiStatusResponse multiStatusResponse = null;
    String href = null;// w w  w. j  av a  2s  .c  o  m
    String responseStatus = "";
    while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "response")) {
        reader.next();
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagLocalName = reader.getLocalName();
            if ("href".equals(tagLocalName)) {
                href = reader.getElementText();
            } else if ("status".equals(tagLocalName)) {
                responseStatus = reader.getElementText();
            } else if ("propstat".equals(tagLocalName)) {
                if (multiStatusResponse == null) {
                    multiStatusResponse = new MultiStatusResponse(href, responseStatus);
                }
                handlePropstat(reader, multiStatusResponse);
            }
        }
    }
    if (multiStatusResponse != null) {
        responses.add(multiStatusResponse);
    }
}

From source file:edu.indiana.d2i.htrc.io.index.solr.SolrClient.java

public List<String> getIDList(String queryStr) {
    List<String> idlist = new ArrayList<String>();
    try {//from  www .  j av a  2  s . c o  m
        // get num of hits
        String url = mainURL + QUERY_PREFIX + queryStr;

        System.out.println(url);

        HttpGet getRequest = new HttpGet(url);
        HttpResponse response = httpClient.execute(getRequest);
        InputStream content = response.getEntity().getContent();

        int numFound = 0;
        XMLStreamReader parser = factory.createXMLStreamReader(content);
        while (parser.hasNext()) {
            int event = parser.next();
            if (event == XMLStreamConstants.START_ELEMENT) {
                String attributeValue = parser.getAttributeValue(null, NUM_FOUND);
                if (attributeValue != null) {
                    numFound = Integer.valueOf(attributeValue);
                    break;
                }
            }
        }
        content.close();

        // 
        String idurl = mainURL + QUERY_PREFIX + queryStr + "&start=0&rows=" + numFound;
        //         String idurl = mainURL + QUERY_PREFIX + queryStr + "&start=0&rows=" + 10;
        HttpResponse idresponse = httpClient.execute(new HttpGet(idurl));
        InputStream idcontent = idresponse.getEntity().getContent();

        XMLStreamReader idparser = factory.createXMLStreamReader(idcontent);
        while (idparser.hasNext()) {
            int event = idparser.next();
            if (event == XMLStreamConstants.START_ELEMENT) {
                String attributeValue = idparser.getAttributeValue(null, "name");
                if (attributeValue != null) {
                    if (attributeValue.equals(SOLR_QUERY_ID)) {
                        String volumeId = idparser.getElementText();
                        idlist.add(volumeId);
                    }
                }
            }
        }
        idcontent.close();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (XMLStreamException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return idlist;
}

From source file:davmail.exchange.dav.ExchangePropPatchMethod.java

protected void handleProperty(XMLStreamReader reader, MultiStatusResponse multiStatusResponse)
        throws XMLStreamException {
    while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "prop")) {
        reader.next();/*from   ww  w  .j a  v a2  s  . c om*/
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagLocalName = reader.getLocalName();
            Namespace namespace = Namespace.getNamespace(reader.getNamespaceURI());
            multiStatusResponse.add(new DefaultDavProperty(tagLocalName, reader.getElementText(), namespace));
        }
    }
}

From source file:com.conx.logistics.kernel.bpm.impl.jbpm.core.mock.BPMGuvnorUtil.java

private List<String> getPackageNamesFromGuvnor() {
    List<String> packages = new ArrayList<String>();
    String packagesURL = getGuvnorProtocol() + "://" + getGuvnorHost() + "/" + getGuvnorSubdomain()
            + "/rest/packages/";
    try {//from ww  w .  j  a  v  a2  s.c om
        XMLInputFactory factory = XMLInputFactory.newInstance();
        XMLStreamReader reader = factory.createXMLStreamReader(getInputStreamForURL(packagesURL, "GET"));
        while (reader.hasNext()) {
            if (reader.next() == XMLStreamReader.START_ELEMENT) {
                if ("title".equals(reader.getLocalName())) {
                    String pname = reader.getElementText();
                    if (!pname.equalsIgnoreCase("Packages")) {
                        packages.add(pname);
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.error("Error retriving packages from guvnor: " + e.getMessage());
    }
    return packages;
}

From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessor.java

/**
 * Reads from the XML stream and tries to determine if the ACI response contains an error or not. The stream is left
 * at the end of the body content of the <tt>/autnresponse/response</tt> element, if one could be found.
 * @param xmlStreamReader The response to process
 * @return <tt>true</tt> if the response contains an error, <tt>false</tt> otherwise
 * @throws javax.xml.stream.XMLStreamException If there was a problem reading the IDOL Server response.
 *//*from  ww w .j a va 2s . c  om*/
protected boolean isErrorResponse(final XMLStreamReader xmlStreamReader) throws XMLStreamException {
    LOGGER.trace("isErrorResponse() called...");

    // Get the /autnresponse/response element...
    while (xmlStreamReader.hasNext()) {
        // Get the event type...
        final int eventType = xmlStreamReader.next();

        // Check to see if it's a start event...
        if ((XMLEvent.START_ELEMENT == eventType)
                && ("response".equalsIgnoreCase(xmlStreamReader.getLocalName()))) {
            return "ERROR".equalsIgnoreCase(xmlStreamReader.getElementText());
        }
    }

    // Couldn't find a /autnresponse/response element...
    throw new XMLStreamException("Unable to find /autnresponse/response element.");
}

From source file:edu.indiana.d2i.htrc.portal.HTRCAgentClient.java

private boolean parseJobDeleteResponse(InputStream stream) throws XMLStreamException {
    XMLStreamReader parser = factory.createXMLStreamReader(stream);
    while (parser.hasNext()) {
        int event = parser.next();
        if (event == XMLStreamConstants.START_ELEMENT) {
            if (parser.hasName()) {
                String localName = parser.getLocalName();
                if (localName.equals("success"))
                    return true;
                else {
                    log.error(parser.getElementText());
                    return false;
                }/*from   www .j av  a 2  s .co m*/
            }
        }
    }
    return false;
}

From source file:wiki.link.LinkImporter.java

public boolean readXML(String filename) {

    //System.exit(1);
    //MAKE BLOODY SURE YOU HAVE SOME HOURS.
    DbConnector dbc = new DbConnector("localhost");
    dbc.jdbcTemplate.update("TRUNCATE links;");
    try {/*from  www  . jav a 2s.c o m*/
        XMLInputFactory xif = XMLInputFactory.newInstance();
        XMLStreamReader xsr = xif.createXMLStreamReader(new FileInputStream(filename));

        long n = 0;
        List<Doc> toSave = new ArrayList<>();
        while (xsr.hasNext()) {
            xsr.next();
            if (xsr.getEventType() == XMLStreamReader.START_ELEMENT) {
                if (xsr.getLocalName().equals("page")) {
                    long id = -1;
                    String title = null;
                    String text = null;
                    while (xsr.hasNext()) {
                        xsr.next();
                        if (xsr.getEventType() == XMLStreamReader.START_ELEMENT) {
                            if (xsr.getLocalName().equals("id") && id == -1) {
                                id = Long.parseLong(xsr.getElementText());
                            }
                            if (xsr.getLocalName().equals("title")) {
                                title = xsr.getElementText();
                            }
                            if (xsr.getLocalName().equals("text")) {
                                text = xsr.getElementText();
                            }
                        } else if (xsr.getEventType() == XMLStreamReader.END_ELEMENT
                                && xsr.getLocalName().equals("page")) {
                            break;
                        }
                    }
                    if (id != -1 && title != null && text != null) {
                        Doc wd = new Doc(id, title, text);
                        toSave.add(wd);
                        n++;
                        if (n % 1000 == 0) {
                            insertLinks(toSave, dbc);
                            //                                WikiDoc.insertAll(toSave, dbc);
                            System.out.println(n);
                            toSave.clear();
                        }
                    }
                }
            }
        }
    } catch (IOException | XMLStreamException e) {
        e.printStackTrace();
    }
    return true;
}

From source file:com.conx.logistics.kernel.bpm.impl.jbpm.core.mock.BPMGuvnorUtil.java

public List<String> getAllProcessesInPackage(String pkgName) {
    List<String> processes = new ArrayList<String>();
    String assetsURL = getGuvnorProtocol() + "://" + getGuvnorHost() + "/" + getGuvnorSubdomain()
            + "/rest/packages/" + pkgName + "/assets/";

    try {/* ww  w  . j  av  a 2 s. c  om*/
        XMLInputFactory factory = XMLInputFactory.newInstance();
        XMLStreamReader reader = factory.createXMLStreamReader(getInputStreamForURL(assetsURL, "GET"));

        String format = "";
        String title = "";
        while (reader.hasNext()) {
            int next = reader.next();
            if (next == XMLStreamReader.START_ELEMENT) {
                if ("format".equals(reader.getLocalName())) {
                    format = reader.getElementText();
                }
                if ("title".equals(reader.getLocalName())) {
                    title = reader.getElementText();
                }
                if ("asset".equals(reader.getLocalName())) {
                    if (format.equals(EXT_BPMN) || format.equals(EXT_BPMN2)) {
                        processes.add(title);
                        title = "";
                        format = "";
                    }
                }
            }
        }
        // last one
        if (format.equals(EXT_BPMN) || format.equals(EXT_BPMN2)) {
            processes.add(title);
        }
    } catch (Exception e) {
        logger.error("Error finding processes in package: " + e.getMessage());
    }
    return processes;
}

From source file:de.uzk.hki.da.sb.SIPFactoryTest.java

/**
 * @param premis/*w ww.j a va2  s . c  o m*/
 * @param publicRights 
 */
private boolean checkPremisFilePubStartDate(File premis, ContractRights rights) {

    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader streamReader;
    try {
        streamReader = inputFactory.createXMLStreamReader(new FileInputStream(premis));
        while (streamReader.hasNext()) {
            int event = streamReader.next();
            switch (event) {
            case XMLStreamConstants.START_ELEMENT:
                if (streamReader.getLocalName().equals("startDate")) {

                    String startDate = streamReader.getElementText().substring(0, 10);
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    String publicDate = sdf.format(rights.getPublicRights().getStartDate());
                    if (startDate.trim().equals(publicDate.trim())) {
                        return true;
                    }
                }
            default:
                break;
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (XMLStreamException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:com.conx.logistics.kernel.bpm.impl.jbpm.core.mock.BPMGuvnorUtil.java

public boolean templateExistsInRepo(String templateName) throws Exception {
    List<String> allPackages = getPackageNames();
    try {/*  ww w.  j av  a2s . c  o  m*/
        for (String pkg : allPackages) {
            String templateURL = getGuvnorProtocol() + "://" + getGuvnorHost() + "/" + getGuvnorSubdomain()
                    + "/rest/packages/" + pkg + "/assets/" + URLEncoder.encode(templateName, "UTF-8");

            URL checkURL = new URL(templateURL);
            HttpURLConnection checkConnection = (HttpURLConnection) checkURL.openConnection();
            checkConnection.setRequestMethod("GET");
            checkConnection.setRequestProperty("Accept", "application/atom+xml");
            checkConnection.setConnectTimeout(Integer.parseInt(getGuvnorConnectTimeout()));
            checkConnection.setReadTimeout(Integer.parseInt(getGuvnorReadTimeout()));
            applyAuth(checkConnection);
            checkConnection.connect();
            if (checkConnection.getResponseCode() == 200) {

                XMLInputFactory factory = XMLInputFactory.newInstance();
                XMLStreamReader reader = factory.createXMLStreamReader(checkConnection.getInputStream());

                boolean foundFormFormat = false;
                while (reader.hasNext()) {
                    if (reader.next() == XMLStreamReader.START_ELEMENT) {
                        if ("format".equals(reader.getLocalName())) {
                            reader.next();
                            String pname = reader.getElementText();
                            if ("flt".equalsIgnoreCase(pname)) {
                                foundFormFormat = true;
                                break;
                            }
                        }
                    }
                }
                return foundFormFormat;
            }
        }
    } catch (Exception e) {
        logger.error("Exception checking template url : " + e.getMessage());
        return false;
    }
    logger.info("Could not find process template for: " + templateName);
    return false;
}