List of usage examples for javax.xml.stream XMLStreamReader next
public int next() throws XMLStreamException;
From source file:com.pocketsoap.salesforce.soap.ChatterClient.java
private RuntimeException handleSoapFault(XMLStreamReader rdr) throws XMLStreamException { String fc = null, fs = null;//from w w w. j a v a 2 s. c o m while (rdr.next() != XMLStreamReader.END_DOCUMENT) { if (rdr.getEventType() == XMLStreamReader.START_ELEMENT) { String ln = rdr.getLocalName(); if (ln.equals("faultcode")) fc = rdr.getElementText(); else if (ln.equals("faultstring")) fs = rdr.getElementText(); } } return new SoapFaultException(fc, fs); }
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 w w w. ja v a 2s .co 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:edu.indiana.d2i.htrc.io.index.solr.SolrClient.java
private Vector createVector(XMLStreamReader parser) throws XMLStreamException { Vector vector = new RandomAccessSparseVector(dictionary.size()); while (parser.hasNext()) { int event = parser.next(); if (event == XMLStreamConstants.START_ELEMENT) { String attributeValue = parser.getAttributeValue(null, "name"); if (attributeValue != null) { // if (dictionary.containsKey(attributeValue)) { // parser.next(); // int tf = Integer.valueOf(parser.getElementText()); // vector.setQuick(dictionary.get(attributeValue), tf); // } parser.next();//from ww w .j av a2 s .co m int freq = Integer.valueOf(parser.getElementText()); if (filter.accept(attributeValue, freq)) { vector.setQuick(dictionary.get(attributeValue), freq); } } } } return vector; }
From source file:ar.com.zauber.commons.spring.test.impl.TamperdataHttpServletRequestFactory.java
/** hace el trabajo sucio * @throws UnsupportedEncodingException */ private HttpServletRequest parse(final XMLStreamReader reader) throws XMLStreamException, UnsupportedEncodingException { final MockHttpServletRequest ret = new MockHttpServletRequest(); ret.setMethod("POST"); String header = null;// w w w .j a v a2 s .c o m String postHeader = null; int event; while ((event = reader.next()) != XMLStreamConstants.END_DOCUMENT) { if (event == XMLStreamConstants.START_ELEMENT) { final String name = reader.getLocalName(); if (name.equals("tdRequestHeader") || name.equals("tdPostHeader")) { header = reader.getAttributeValue(0); } else if (name.equals("tdPostElements")) { ret.setMethod("POST"); } else if (name.equals("tdPostElement")) { postHeader = reader.getAttributeValue(0); } } else if (event == XMLStreamConstants.CHARACTERS) { String text = reader.getText(); if (text.length() > 1 && Character.isWhitespace(text.charAt(0))) { text = text.substring(1); } if (text.length() > 1 && Character.isWhitespace(text.charAt(text.length() - 1))) { text = text.substring(0, text.length() - 1); } final String value = URLDecoder.decode(URLDecoder.decode(text, encoding), encoding); if (header != null) { ret.addHeader(header, value); } else if (postHeader != null) { ret.addParameter(postHeader, value); } header = null; postHeader = null; } else { header = null; postHeader = null; } } reader.close(); return ret; }
From source file:com.microsoft.windowsazure.storage.table.TableParser.java
/** * Reserved for internal use. Parses the operation response as an entity. Reads entity data from the specified * <code>XMLStreamReader</code> using the specified class type and optionally projects the entity result with the * specified resolver into a {@link TableResult} object. * /* w ww . jav a2s .co m*/ * @param xmlr * The <code>XMLStreamReader</code> to read the data to parse from. * @param httpStatusCode * The HTTP status code returned with the operation response. * @param clazzType * The class type <code>T</code> implementing {@link TableEntity} for the entity returned. Set to * <code>null</code> to ignore the returned entity and copy only response properties into the * {@link TableResult} object. * @param resolver * An {@link EntityResolver} instance to project the entity into an instance of type <code>R</code>. Set * to <code>null</code> to return the entitys as instance of the class type <code>T</code>. * @param opContext * An {@link OperationContext} object used to track the execution of the operation. * @return * A {@link TableResult} object with the parsed operation response. * * @throws XMLStreamException * if an error occurs while accessing the stream. * @throws ParseException * if an error occurs while parsing the stream. * @throws InstantiationException * if an error occurs while constructing the result. * @throws IllegalAccessException * if an error occurs in reflection while parsing the result. * @throws StorageException * if a storage service error occurs. */ private static <T extends TableEntity, R> TableResult parseSingleOpAtomResponse(final InputStream inStream, final int httpStatusCode, final Class<T> clazzType, final EntityResolver<R> resolver, final OperationContext opContext) throws XMLStreamException, ParseException, InstantiationException, IllegalAccessException, StorageException { XMLStreamReader xmlr = Utility.createXMLStreamReaderFromStream(inStream); try { xmlr.require(XMLStreamConstants.START_DOCUMENT, null, null); xmlr.next(); final TableResult res = parseAtomEntity(xmlr, clazzType, resolver, opContext); res.setHttpStatusCode(httpStatusCode); return res; } finally { xmlr.close(); } }
From source file:davmail.exchange.dav.ExchangeDavMethod.java
protected void handleProperty(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "prop")) { reader.next(); if (XMLStreamUtil.isStartTag(reader)) { Namespace namespace = Namespace.getNamespace(reader.getNamespaceURI()); String tagLocalName = reader.getLocalName(); if (reader.getAttributeCount() > 0 && "mv.string".equals(reader.getAttributeValue(0))) { handleMultiValuedProperty(reader, multiStatusResponse); } else { String tagContent = getTagContent(reader); if (tagContent != null) { multiStatusResponse.add(new DefaultDavProperty(tagLocalName, tagContent, namespace)); }/*www. j ava2 s . c om*/ } } } }
From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessor.java
/** * Move the cursor forward through the XML stream to the next start element. * @param xmlStreamReader The XML stream to use * @throws XMLStreamException If there was an error using the stream *///from w w w. j a va 2 s . c o m protected void forwardToNextStartElement(final XMLStreamReader xmlStreamReader) throws XMLStreamException { while (xmlStreamReader.hasNext()) { final int eventType = xmlStreamReader.next(); if (XMLEvent.START_ELEMENT == eventType) { return; } } throw new XMLStreamException("No more START_ELEMENT events found"); }
From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessor.java
/** * Move the cursor forward through the XML stream to the next start or end element, which ever comes first. * @param xmlStreamReader The XML stream to use * @return The type of event forwarded to, i.e. <tt>XMLEvent.START_ELEMENT</tt> or <tt>XMLEvent.END_ELEMENT</tt>. * @throws XMLStreamException If there was an error using the stream *//* w ww.j a v a 2 s . co m*/ protected int forwardToNextStartOrEndElement(final XMLStreamReader xmlStreamReader) throws XMLStreamException { while (xmlStreamReader.hasNext()) { final int eventType = xmlStreamReader.next(); if ((XMLEvent.START_ELEMENT == eventType) || (XMLEvent.END_ELEMENT == eventType)) { return eventType; } } throw new XMLStreamException("No more START_ELEMENT or END_ELEMENT events found"); }
From source file:de.tuebingen.uni.sfs.germanet.api.WiktionaryLoader.java
/** * Loads <code>WiktionaryParaphrases</code> from the specified file into this * <code>WiktionaryLoader</code>'s <code>GermaNet</code> object. * @param wiktionaryFile the file containing <code>WiktionaryParaphrases</code> data * @throws java.io.FileNotFoundException * @throws javax.xml.stream.XMLStreamException *//*from w w w . j av a 2s.c o m*/ protected void loadWiktionary(File wiktionaryFile) throws FileNotFoundException, XMLStreamException { wikiDir = wiktionaryFile; FilenameFilter filter = new WikiFilter(); //get only wiktionary files File[] wikiFiles = wikiDir.listFiles(filter); if (wikiFiles == null || wikiFiles.length == 0) { throw new FileNotFoundException( "Unable to load Wiktionary Paraphrases from \"" + this.wikiDir.getPath() + "\""); } for (File wikiFile : wikiFiles) { logger.debug("Loading " + wikiFile.getName() + "..."); InputStream in = new FileInputStream(wikiFile); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader parser = factory.createXMLStreamReader(in); int event; String nodeName; //Parse entire file, looking for Wiktionary paraphrase start elements while (parser.hasNext()) { event = parser.next(); switch (event) { case XMLStreamConstants.START_DOCUMENT: namespace = parser.getNamespaceURI(); break; case XMLStreamConstants.START_ELEMENT: nodeName = parser.getLocalName(); if (nodeName.equals(GermaNet.XML_WIKTIONARY_PARAPHRASE)) { WiktionaryParaphrase wiki = processWiktionaryParaphrase(parser); germaNet.addWiktionaryParaphrase(wiki); } break; } } parser.close(); } logger.debug("Done."); }
From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessor.java
/** * Forwards through the stream looking for the an element with <tt>elementName</tt> * @param elementName The name of the element to find. * @param xmlStreamReader The stream to forward through * @throws XMLStreamException If there was an error using the stream, or if no element with <tt>elementName</tt> * could be found *///ww w. ja v a 2s .c o m protected void forwardToNamedStartElement(final String elementName, final XMLStreamReader xmlStreamReader) throws XMLStreamException { while (xmlStreamReader.hasNext()) { final int eventType = xmlStreamReader.next(); if ((eventType == XMLEvent.START_ELEMENT) && (elementName.equals(xmlStreamReader.getLocalName()))) { return; } } throw new XMLStreamException("Unable to find a start element for, " + elementName); }