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:org.pentaho.platform.dataaccess.datasource.api.AnalysisService.java
private String getSchemaName(String encoding, InputStream inputStream) throws XMLStreamException, IOException { String domainId = null;/*from w w w. j av a 2 s.c o m*/ XMLStreamReader reader = null; try { XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); if (StringUtils.isEmpty(encoding)) { reader = factory.createXMLStreamReader(inputStream); } else { reader = factory.createXMLStreamReader(inputStream, encoding); } while (reader.next() != XMLStreamReader.END_DOCUMENT) { if (reader.getEventType() == XMLStreamReader.START_ELEMENT && reader.getLocalName().equalsIgnoreCase("Schema")) { domainId = reader.getAttributeValue("", "name"); return domainId; } } } finally { if (reader != null) { reader.close(); } inputStream.reset(); } return domainId; }
From source file:org.sakaiproject.nakamura.auth.cas.CasAuthenticationHandler.java
private String retrieveCredentials(String responseBody) { String username = null;//from www .ja v a 2 s . c om String pgtIou = null; String failureCode = null; String failureMessage = null; try { XMLInputFactory xmlInputFactory = new WstxInputFactory(); xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true); xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false); xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(new StringReader(responseBody)); while (eventReader.hasNext()) { XMLEvent event = eventReader.nextEvent(); // process the event if we're starting an element if (event.isStartElement()) { StartElement startEl = event.asStartElement(); QName startElName = startEl.getName(); String startElLocalName = startElName.getLocalPart(); LOGGER.debug(responseBody); /* * Example of failure XML <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> <cas:authenticationFailure code='INVALID_REQUEST'> 'service' and 'ticket' parameters are both required </cas:authenticationFailure> </cas:serviceResponse> */ if ("authenticationFailure".equalsIgnoreCase(startElLocalName)) { // get code of the failure Attribute code = startEl.getAttributeByName(QName.valueOf("code")); failureCode = code.getValue(); // get the message of the failure event = eventReader.nextEvent(); assert event.isCharacters(); Characters chars = event.asCharacters(); failureMessage = chars.getData(); break; } /* * Example of success XML <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> <cas:authenticationSuccess> <cas:user>NetID</cas:user> </cas:authenticationSuccess> </cas:serviceResponse> */ if ("authenticationSuccess".equalsIgnoreCase(startElLocalName)) { // skip to the user tag start while (eventReader.hasNext()) { event = eventReader.nextTag(); if (event.isEndElement()) { if (eventReader.hasNext()) { event = eventReader.nextTag(); } else { break; } } assert event.isStartElement(); startEl = event.asStartElement(); startElName = startEl.getName(); startElLocalName = startElName.getLocalPart(); if (proxy && "proxyGrantingTicket".equals(startElLocalName)) { event = eventReader.nextEvent(); assert event.isCharacters(); Characters chars = event.asCharacters(); pgtIou = chars.getData(); LOGGER.debug("XML parser found pgt: {}", pgtIou); } else if ("user".equals(startElLocalName)) { // move on to the body of the user tag event = eventReader.nextEvent(); assert event.isCharacters(); Characters chars = event.asCharacters(); username = chars.getData(); LOGGER.debug("XML parser found user: {}", username); } else { LOGGER.error("Found unexpected element [{}] while inside 'authenticationSuccess'", startElName); break; } if (username != null && (!proxy || pgtIou != null)) { break; } } } } } } catch (XMLStreamException e) { LOGGER.error(e.getMessage(), e); } if (failureCode != null || failureMessage != null) { LOGGER.error("Error response from server code={} message={}", failureCode, failureMessage); } String pgt = pgts.get(pgtIou); if (pgt != null) { savePgt(username, pgt, pgtIou); } else { LOGGER.debug("Caching '{}' as the IOU for '{}'", pgtIou, username); pgtIOUs.put(pgtIou, username); } return username; }
From source file:org.sakaiproject.nakamura.auth.cas.CasAuthenticationHandler.java
private String getProxyTicketFromXml(String responseBody) { String ticket = null;//from w w w . j a v a2 s.co m try { XMLInputFactory xmlInputFactory = new WstxInputFactory(); xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true); xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false); xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(new StringReader(responseBody)); LOGGER.debug(responseBody); while (eventReader.hasNext()) { XMLEvent event = eventReader.nextEvent(); // process the event if we're starting an element if (event.isStartElement()) { StartElement startEl = event.asStartElement(); QName startElName = startEl.getName(); String startElLocalName = startElName.getLocalPart(); // Example XML // <cas:serviceResponse> // <cas:proxySuccess> // <cas:proxyTicket>PT-957-ZuucXqTZ1YcJw81T3dxf</cas:proxyTicket> // </cas:proxySuccess> // </cas:serviceResponse> if ("proxySuccess".equalsIgnoreCase(startElLocalName)) { event = eventReader.nextTag(); assert event.isStartElement(); startEl = event.asStartElement(); startElName = startEl.getName(); startElLocalName = startElName.getLocalPart(); if ("proxyTicket".equalsIgnoreCase(startElLocalName)) { event = eventReader.nextEvent(); assert event.isCharacters(); Characters chars = event.asCharacters(); ticket = chars.getData(); } else { LOGGER.error("Found unexpected element [{}] while inside 'proxySuccess'", startElName); break; } } } } } catch (XMLStreamException e) { LOGGER.error(e.getMessage(), e); } return ticket; }
From source file:org.sakaiproject.nakamura.docproxy.url.UrlRepositoryProcessor.java
@Activate protected void activate(ComponentContext context) { xmlInputFactory = new WstxInputFactory(); xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true); xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false); xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); // process properties into http methods Dictionary<?, ?> props = context.getProperties(); hmacHeader = PropertiesUtil.toString(props.get(HMAC_HEADER), DEFAULT_HMAC_HEADER); searchUrl = PropertiesUtil.toString(props.get(SEARCH_URL), DEFAULT_SEARCH_URL); documentUrl = PropertiesUtil.toString(props.get(DOCUMENT_URL), DEFAULT_DOCUMENT_URL); updateUrl = PropertiesUtil.toString(props.get(UPDATE_URL), DEFAULT_UPDATE_URL); metadataUrl = PropertiesUtil.toString(props.get(METADATA_URL), DEFAULT_METADATA_URL); removeUrl = PropertiesUtil.toString(props.get(REMOVE_URL), DEFAULT_REMOVE_URL); hmacHeader = PropertiesUtil.toString(props.get(HMAC_HEADER), DEFAULT_HMAC_HEADER); sharedKey = PropertiesUtil.toString(props.get(SHARED_KEY), null); }
From source file:org.sakaiproject.nakamura.importer.ImportSiteArchiveServlet.java
/** * {@inheritDoc}//www . j a va2s. c o m * * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig) */ @Override public void init(ServletConfig config) throws ServletException { super.init(config); xmlInputFactory = new WstxInputFactory(); xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true); xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false); xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false); sdf.setTimeZone(TimeZone.getTimeZone("GMT+0")); }
From source file:org.sakaiproject.nakamura.proxy.RSSProxyPostProcessor.java
@Activate protected void activate(Map<?, ?> props) { eventsThreshold = PropertiesUtil.toInteger(props.get(EVENTS_THRESHOLD), DEFAULT_EVENTS_THRESHOLD); maxLength = PropertiesUtil.toInteger(props.get(MAX_LENGTH), DEFAULT_MAX_LENGTH); xmlInputFactory = new WstxInputFactory(); xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true); xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false); contentTypes = new ArrayList<String>(); contentTypes.add("application/rss+xml"); contentTypes.add("application/rdf+xml"); contentTypes.add("application/atom+xml"); contentTypes.add("text/xml"); contentTypes.add("application/xhtml+xml"); contentTypes.add("application/xml"); contentTypes.add("text/plain"); // Formats are stored as: // key = First tag after prologue. Include version if pertinent. // value = Set of required tags. formats = new HashMap<String, Set<String>>(); // RSS 0.91/*from www. j av a 2s . c om*/ HashSet<String> rss091 = new HashSet<String>(); rss091.add("channel"); rss091.add("title"); rss091.add("description"); rss091.add("link"); rss091.add("language"); formats.put("rss-0.91", rss091); // RSS 1.0 HashSet<String> rss10 = new HashSet<String>(); rss10.add("channel"); rss10.add("title"); rss10.add("description"); rss10.add("link"); formats.put("rdf", rss10); // RSS 2.0 HashSet<String> rss20 = new HashSet<String>(); rss20.add("channel"); rss20.add("title"); rss20.add("description"); rss20.add("link"); formats.put("rss-2.0", rss20); // ATOM 1.0 HashSet<String> atom10 = new HashSet<String>(); atom10.add("id"); atom10.add("title"); atom10.add("updated"); formats.put("feed", atom10); }
From source file:org.sonar.api.profiles.XMLProfileParser.java
private SMInputFactory initStax() { XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // just so it won't try to load DTD in if there's DOCTYPE xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); return new SMInputFactory(xmlFactory); }
From source file:org.sonar.api.rules.XMLRuleParser.java
public List<Rule> parse(Reader reader) { XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // just so it won't try to load DTD in if there's DOCTYPE xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); SMInputFactory inputFactory = new SMInputFactory(xmlFactory); try {/*from w ww . jav a 2 s .c o m*/ SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <rules> List<Rule> rules = new ArrayList<Rule>(); SMInputCursor rulesC = rootC.childElementCursor("rule"); while (rulesC.getNext() != null) { // <rule> Rule rule = Rule.create(); rules.add(rule); processRule(rule, rulesC); } return rules; } catch (XMLStreamException e) { throw new SonarException("XML is not valid", e); } }
From source file:org.sonar.api.server.rule.RulesDefinitionXmlLoader.java
/** * Loads rules by reading the XML input stream. The reader is not closed by the method, so it * should be handled by the caller./*w w w. java2 s .c o m*/ * @since 4.3 */ public void load(RulesDefinition.NewRepository repo, Reader reader) { XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // just so it won't try to load DTD in if there's DOCTYPE xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); SMInputFactory inputFactory = new SMInputFactory(xmlFactory); try { SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <rules> SMInputCursor rulesC = rootC.childElementCursor("rule"); while (rulesC.getNext() != null) { // <rule> processRule(repo, rulesC); } } catch (XMLStreamException e) { throw new IllegalStateException("XML is not valid", e); } }
From source file:org.sonar.core.technicaldebt.TechnicalDebtXMLImporter.java
private SMInputFactory initStax() { XMLInputFactory xmlFactory = XMLInputFactory2.newInstance(); xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); return new SMInputFactory(xmlFactory); }