List of usage examples for javax.xml.stream XMLInputFactory IS_COALESCING
String IS_COALESCING
To view the source code for javax.xml.stream XMLInputFactory IS_COALESCING.
Click Source Link
From source file:com.norconex.collector.http.sitemap.impl.StandardSitemapResolver.java
private void parseLocation(InputStream is, HttpClient httpClient, SitemapURLAdder sitemapURLAdder, Set<String> resolvedLocations, String location) throws XMLStreamException { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setProperty(XMLInputFactory.IS_COALESCING, true); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is); ParseState parseState = new ParseState(); String locationDir = StringUtils.substringBeforeLast(location, "/"); int event = xmlReader.getEventType(); while (true) { switch (event) { case XMLStreamConstants.START_ELEMENT: String tag = xmlReader.getLocalName(); parseStartElement(parseState, tag); break; case XMLStreamConstants.CHARACTERS: String value = xmlReader.getText(); if (parseState.sitemapIndex && parseState.loc) { resolveLocation(value, httpClient, sitemapURLAdder, resolvedLocations); parseState.loc = false;/*from w ww .java 2 s .c om*/ } else if (parseState.baseURL != null) { parseCharacters(parseState, value); } break; case XMLStreamConstants.END_ELEMENT: tag = xmlReader.getLocalName(); parseEndElement(sitemapURLAdder, parseState, locationDir, tag); break; } if (!xmlReader.hasNext()) { break; } event = xmlReader.next(); } }
From source file:com.streamsets.pipeline.stage.origin.salesforce.ForceSource.java
public ForceSource(ForceSourceConfigBean conf) { this.conf = conf; xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); }
From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessor.java
/** * This method firstly checks that the content type of the response is text based and can be parsed. If so, it * converts the <tt>AciResponseInputStream</tt> into a StAX <tt>XMLStreamReader</tt> and calls the the {@link * #process(javax.xml.stream.XMLStreamReader)} method that should be implemented in a subclass to do all the work. * @param aciResponseInputStream The ACI response to process * @return An object of type <tt>T</tt> * @throws AciErrorException If the ACI response was an error response * @throws ProcessorException If an error occurred during the processing of the IDOL response *///w w w . ja v a 2 s . com public T process(final AciResponseInputStream aciResponseInputStream) { LOGGER.trace("process() called..."); if (!"text/xml".equalsIgnoreCase(aciResponseInputStream.getContentType())) { throw new ProcessorException( "This processor is unable to process non-text ACI responses. The content type for this response is " + aciResponseInputStream.getContentType()); } // Define this here so we can make sure it's closed when the processor is finished... XMLStreamReader xmlStreamReader = null; try { // Update the factory with the various properties as they might have changed since the last run... xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, namespaceAware); xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, validating); xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, coalescing); xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, replacingEntityReferences); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, supportingExternalEntities); xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, supportDtd); // Convert the input stream.. xmlStreamReader = xmlInputFactory.createXMLStreamReader(aciResponseInputStream); return process(xmlStreamReader); } catch (final XMLStreamException xmlse) { throw new ProcessorException("Unable to convert the InputStream to a XMLStreamReader", xmlse); } finally { if (xmlStreamReader != null) { try { // This does NOT close the underlying AciResponseInputStream xmlStreamReader.close(); } catch (final XMLStreamException xmlse) { LOGGER.error("Unable to close the XMLStreamReader.", xmlse); } } } }
From source file:ddf.catalog.source.opensearch.OpenSearchSource.java
private void configureXmlInputFactory() { xmlInputFactory = XMLInputFactory2.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE); }
From source file:com.norconex.collector.http.sitemap.impl.DefaultSitemapResolver.java
private void parseLocation(InputStream is, DefaultHttpClient httpClient, SitemapURLStore sitemapURLStore, Set<String> resolvedLocations, String location) throws XMLStreamException { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setProperty(XMLInputFactory.IS_COALESCING, true); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is); ParseState parseState = new ParseState(); String locationDir = StringUtils.substringBeforeLast(location, "/"); int event = xmlReader.getEventType(); while (true) { switch (event) { case XMLStreamConstants.START_ELEMENT: String tag = xmlReader.getLocalName(); parseStartElement(parseState, tag); break; case XMLStreamConstants.CHARACTERS: String value = xmlReader.getText(); if (parseState.sitemapIndex && parseState.loc) { resolveLocation(value, httpClient, sitemapURLStore, resolvedLocations); parseState.loc = false;//from www.ja va 2 s. c om } else if (parseState.baseURL != null) { parseCharacters(parseState, value); } break; case XMLStreamConstants.END_ELEMENT: tag = xmlReader.getLocalName(); parseEndElement(sitemapURLStore, parseState, locationDir, tag); break; } if (!xmlReader.hasNext()) { break; } event = xmlReader.next(); } }
From source file:ca.efendi.datafeeds.messaging.FtpSubscriptionMessageListener.java
private void parse(FtpSubscription ftpSubscription, final InputStream is) throws XMLStreamException { final XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, true); factory.setProperty(XMLInputFactory.IS_COALESCING, true); final XMLStreamReader reader = factory.createXMLStreamReader(is, "UTF-8"); CJProduct product = null;// w ww. ja v a2s . c o m String tagContent = null; //final ServiceContext serviceContext = new ServiceContext(); //ServiceContext serviceContext = ServiceContextFactory.getInstance( // BlogsEntry.class.getName(), actionRequest); //serviceContext.setScopeGroupId(20159); while (reader.hasNext()) { final int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: //tagContent = ""; if ("product".equals(reader.getLocalName())) { product = _cjProductLocalService.createCJProduct(0); } break; case XMLStreamConstants.CHARACTERS: //tagContent += reader.getText().trim(); tagContent = reader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: switch (reader.getLocalName()) { case "product": try { _log.warn("refreshing document..."); _cjProductLocalService.refresh(ftpSubscription, product); } catch (final SystemException e) { _log.error(e); } catch (final PortalException e) { _log.error(e); } break; case "programname": product.setProgramName(tagContent); break; case "programurl": product.setProgramUrl(tagContent); break; case "catalogname": product.setCatalogName(tagContent); break; case "lastupdated": product.setLastUpdated(tagContent); break; case "name": product.setName(tagContent); break; case "keywords": product.setKeywords(tagContent); break; case "description": product.setDescription(tagContent); break; case "sku": product.setSku(tagContent); break; case "manufacturer": product.setManufacturer(tagContent); break; case "manufacturerid": product.setManufacturerId(tagContent); break; case "currency": product.setCurrency(tagContent); break; case "price": product.setPrice(tagContent); break; case "buyurl": product.setBuyUrl(tagContent); break; case "impressionurl": product.setImpressionUrl(tagContent); break; case "imageurl": product.setImageUrl(tagContent); break; case "instock": product.setInStock(tagContent); break; } break; case XMLStreamConstants.START_DOCUMENT: break; } } }
From source file:ddf.catalog.source.opensearch.impl.OpenSearchSource.java
private void configureXmlInputFactory() { xmlInputFactory = XMLInputFactory2.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); // This disables DTDs entirely for that factory xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE); }
From source file:act.installer.pubchem.PubchemParser.java
/** * Initializes a PubchemParser. Must be called before the PubchemParser can be used. * @throws XPathExpressionException//from w ww .ja va 2s . co m * @throws ParserConfigurationException */ public void init() throws ParserConfigurationException, JaxenException { // Would rather do this in its own block, but have to handle the XPath exception. :( for (PC_XPATHS x : PC_XPATHS.values()) { xpaths.put(x, x.compile()); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); documentBuilder = factory.newDocumentBuilder(); xmlInputFactory = XMLInputFactory.newInstance(); /* Configure the XMLInputFactory to return event streams that coalesce consecutive character events. Without this * we can end up with malformed names and InChIs, as XPath will only fetch the first text node if there are several * text children under one parent. */ xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, ENABLE_XML_STREAM_TEXT_COALESCING); if ((Boolean) xmlInputFactory.getProperty(XMLInputFactory.IS_COALESCING)) { LOGGER.info("Successfully configured XML stream to coalesce character elements."); } else { LOGGER.error("Unable to configure XML stream to coalesce character elements."); } }
From source file:edu.unc.lib.dl.services.TripleStoreManagerMulgaraImpl.java
/** * @param query/*from w w w.ja va 2s . c o m*/ * an ITQL command * @return the message returned by Mulgara * @throws RemoteException * for communication failure */ public String storeCommand(String query) { String result = null; String response = this.sendTQL(query); if (response != null) { StringReader sr = new StringReader(response); XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); XMLEventReader r = null; try { boolean inMessage = false; StringBuffer message = new StringBuffer(); r = factory.createXMLEventReader(sr); while (r.hasNext()) { XMLEvent e = r.nextEvent(); if (e.isStartElement()) { StartElement s = e.asStartElement(); if ("message".equals(s.getName().getLocalPart())) { inMessage = true; } } else if (e.isEndElement()) { EndElement end = e.asEndElement(); if ("message".equals(end.getName().getLocalPart())) { inMessage = false; } } else if (inMessage && e.isCharacters()) { message.append(e.asCharacters().getData()); } } result = message.toString(); } catch (XMLStreamException e) { e.printStackTrace(); } finally { if (r != null) { try { r.close(); } catch (Exception ignored) { log.error(ignored); } } } sr.close(); } return result; }
From source file:com.pocketsoap.salesforce.soap.ChatterClient.java
private <T> T makeSoapRequest(String serverUrl, RequestEntity req, ResponseParser<T> respParser) throws XMLStreamException, IOException { PostMethod post = new PostMethod(serverUrl); post.addRequestHeader("SOAPAction", "\"\""); post.setRequestEntity(req);//from ww w . jav a 2 s . c om HttpClient http = new HttpClient(); int sc = http.executeMethod(post); if (sc != 200 && sc != 500) throw new IOException("request to " + serverUrl + " returned unexpected HTTP status code of " + sc + ", check configuration."); XMLInputFactory f = XMLInputFactory.newInstance(); f.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); XMLStreamReader rdr = f.createXMLStreamReader(post.getResponseBodyAsStream()); rdr.require(XMLStreamReader.START_DOCUMENT, null, null); rdr.nextTag(); rdr.require(XMLStreamReader.START_ELEMENT, SOAP_NS, "Envelope"); rdr.nextTag(); // TODO, should handle a Header appearing in the response. rdr.require(XMLStreamReader.START_ELEMENT, SOAP_NS, "Body"); rdr.nextTag(); if (rdr.getLocalName().equals("Fault")) { throw handleSoapFault(rdr); } try { T response = respParser.parse(rdr); while (rdr.hasNext()) rdr.next(); return response; } finally { try { rdr.close(); } finally { post.releaseConnection(); } } }