List of usage examples for javax.xml.stream XMLStreamReader next
public int next() throws XMLStreamException;
From source file:org.jasig.schedassist.impl.caldav.xml.ReportResponseHandlerImpl.java
/** * Extracts a {@link List} of {@link Calendar}s from the {@link InputStream}, if present. * /* www .j av a 2 s.co m*/ * @param inputStream * @return a never null, but possibly empty {@link List} of {@link Calendar}s from the {@link InputStream} * @throws XmlParsingException in the event the stream could not be properly parsed */ public List<CalendarWithURI> extractCalendars(InputStream inputStream) { List<CalendarWithURI> results = new ArrayList<CalendarWithURI>(); ByteArrayOutputStream capturedContent = null; XMLInputFactory factory = XMLInputFactory.newInstance(); try { InputStream localReference = inputStream; if (log.isDebugEnabled()) { capturedContent = new ByteArrayOutputStream(); localReference = new TeeInputStream(inputStream, capturedContent); } BufferedInputStream buffered = new BufferedInputStream(localReference); buffered.mark(1); int firstbyte = buffered.read(); if (-1 == firstbyte) { // short circuit on empty stream return results; } buffered.reset(); XMLStreamReader parser = factory.createXMLStreamReader(buffered); String currentUri = null; String currentEtag = null; for (int eventType = parser.next(); eventType != XMLStreamConstants.END_DOCUMENT; eventType = parser .next()) { switch (eventType) { case XMLStreamConstants.START_ELEMENT: QName name = parser.getName(); if (isWebdavHrefElement(name)) { currentUri = parser.getElementText(); } else if (isWebdavEtagElement(name)) { currentEtag = parser.getElementText(); } else if (isCalendarDataElement(name)) { Calendar cal = extractCalendar(parser.getElementText()); if (cal != null) { CalendarWithURI withUri = new CalendarWithURI(cal, currentUri, currentEtag); results.add(withUri); } else if (log.isDebugEnabled()) { log.debug("extractCalendar returned null for " + currentUri + ", skipping"); } } break; } } if (log.isDebugEnabled()) { log.debug("extracted " + results.size() + " calendar from " + capturedContent.toString()); } } catch (XMLStreamException e) { if (capturedContent != null) { log.error("caught XMLStreamException in extractCalendars, captured content: " + capturedContent.toString(), e); } else { log.error("caught XMLStreamException in extractCalendars, no captured content available", e); } throw new XmlParsingException("caught XMLStreamException in extractCalendars", e); } catch (IOException e) { log.error("caught IOException in extractCalendars", e); throw new XmlParsingException("caught IOException in extractCalendars", e); } return results; }
From source file:org.jbpm.designer.web.profile.impl.JbpmProfileImpl.java
private void initializeLocalPlugins(ServletContext context) { Map<String, IDiagramPlugin> registry = PluginServiceImpl.getLocalPluginsRegistry(context); FileInputStream fileStream = null; try {/*from www. ja v a 2 s . c om*/ try { fileStream = new FileInputStream(new StringBuilder(context.getRealPath("/")).append("/") .append(ConfigurationProvider.getInstance().getDesignerContext()).append("profiles") .append("/").append("jbpm.xml").toString()); } catch (FileNotFoundException e) { throw new RuntimeException(e); } XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader(fileStream, "UTF-8"); while (reader.hasNext()) { if (reader.next() == XMLStreamReader.START_ELEMENT) { if ("profile".equals(reader.getLocalName())) { for (int i = 0; i < reader.getAttributeCount(); i++) { if ("stencilset".equals(reader.getAttributeLocalName(i))) { _stencilSet = reader.getAttributeValue(i); } } } else if ("plugin".equals(reader.getLocalName())) { String name = null; for (int i = 0; i < reader.getAttributeCount(); i++) { if ("name".equals(reader.getAttributeLocalName(i))) { name = reader.getAttributeValue(i); } } _plugins.put(name, registry.get(name)); } else if ("localhistory".equals(reader.getLocalName())) { for (int i = 0; i < reader.getAttributeCount(); i++) { if ("enabled".equals(reader.getAttributeLocalName(i))) { String localhistoryenabled = reader.getAttributeValue(i); if (!isEmpty(localhistoryenabled)) { _localHistoryEnabled = localhistoryenabled; } else { _logger.info("Invalid local history enabled"); } } if ("timeout".equals(reader.getAttributeLocalName(i))) { String localhistorytimeout = reader.getAttributeValue(i); if (!isEmpty(localhistorytimeout)) { _localHistoryTimeout = localhistorytimeout; } else { _logger.info("Invalid local history timeout"); } } } } else if ("storesvgonsave".equals(reader.getLocalName())) { for (int i = 0; i < reader.getAttributeCount(); i++) { if ("enabled".equals(reader.getAttributeLocalName(i))) { String storesvgonsaveenabled = reader.getAttributeValue(i); if (!isEmpty(storesvgonsaveenabled)) { _storeSVGonSaveOption = storesvgonsaveenabled; } else { _logger.info("Invalid store svg on save enabled"); } } } } } } } catch (XMLStreamException e) { _logger.error(e.getMessage(), e); throw new RuntimeException(e); // stop initialization } finally { if (fileStream != null) { try { fileStream.close(); } catch (IOException e) { } } ; } }
From source file:org.jbpm.designer.web.server.ProcessDiffServiceServlet.java
private List<String> getAssetVersions(String packageName, String assetName, String uuid, IDiagramProfile profile) {//from ww w . j a v a 2s .c om try { String assetVersionURL = RepositoryInfo.getRepositoryProtocol(profile) + "://" + RepositoryInfo.getRepositoryHost(profile) + "/" + RepositoryInfo.getRepositorySubdomain(profile).substring(0, RepositoryInfo.getRepositorySubdomain(profile).indexOf("/")) + "/rest/packages/" + URLEncoder.encode(packageName, "UTF-8") + "/assets/" + assetName + "/versions/"; List<String> versionList = new ArrayList<String>(); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader( ServletUtil.getInputStreamForURL(assetVersionURL, "GET", profile), "UTF-8"); boolean isFirstTitle = true; String title = ""; while (reader.hasNext()) { int next = reader.next(); if (next == XMLStreamReader.START_ELEMENT) { if ("title".equals(reader.getLocalName())) { if (isFirstTitle) { isFirstTitle = false; } else { versionList.add(reader.getElementText()); } } } } return versionList; } catch (Exception e) { _logger.error(e.getMessage()); return null; } }
From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java
/** * {@inheritDoc}//from ww w.j ava 2 s .c o m */ @Override public Config processConfig(XMLStreamReader aStreamReader) { JWebSocketConfig.Builder lConfigBuilder = new JWebSocketConfig.Builder(); try { while (aStreamReader.hasNext()) { aStreamReader.next(); if (aStreamReader.isStartElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_PROTOCOL)) { aStreamReader.next(); lConfigBuilder.setProtocol(aStreamReader.getText()); } else if (lElementName.equals(ELEMENT_NODE_ID)) { aStreamReader.next(); lConfigBuilder.setNodeId(aStreamReader.getText()); } else if (lElementName.equals(ELEMENT_LIBRARY_FOLDER)) { aStreamReader.next(); lConfigBuilder.setLibraryFolder(aStreamReader.getText()); } else if (lElementName.equals(ELEMENT_LIBRARIES)) { List<LibraryConfig> lLibraries = handleLibraries(aStreamReader); lConfigBuilder = lConfigBuilder.setLibraries(lLibraries); } else if (lElementName.equals(ELEMENT_ENGINES)) { List<EngineConfig> lEngines = handleEngines(aStreamReader); lConfigBuilder = lConfigBuilder.setEngines(lEngines); } else if (lElementName.equals(ELEMENT_SERVERS)) { List<ServerConfig> lServers = handleServers(aStreamReader); lConfigBuilder = lConfigBuilder.setServers(lServers); } else if (lElementName.equals(ELEMENT_PLUGINS)) { List<PluginConfig> lPlugins = handlePlugins(aStreamReader); lConfigBuilder = lConfigBuilder.setPlugins(lPlugins); } else if (lElementName.equals(ELEMENT_FILTERS)) { List<FilterConfig> lFilters = handleFilters(aStreamReader); lConfigBuilder = lConfigBuilder.setFilters(lFilters); } else if (lElementName.equals(ELEMENT_LOGGING)) { List<LoggingConfig> loggingConfigs = handleLoggingConfigs(aStreamReader); lConfigBuilder = lConfigBuilder.setLoggingConfig(loggingConfigs); } else if (lElementName.equals(ELEMENT_RIGHTS)) { List<RightConfig> lGlobalRights = handleRights(aStreamReader); lConfigBuilder = lConfigBuilder.setGlobalRights(lGlobalRights); } else if (lElementName.equals(ELEMENT_ROLES)) { List<RoleConfig> lRoles = handleRoles(aStreamReader); lConfigBuilder = lConfigBuilder.setGlobalRoles(lRoles); } else if (lElementName.equals(ELEMENT_USERS)) { List<UserConfig> lUsers = handleUsers(aStreamReader); lConfigBuilder = lConfigBuilder.setUsers(lUsers); } else { // ignore } } if (aStreamReader.isEndElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(JWEBSOCKET)) { break; } } } } catch (XMLStreamException lEx) { throw new WebSocketRuntimeException("Error parsing jWebSocket.xml configuration file", lEx); } // if no filters where given in the .xml file // initialize empty filter list here if (lConfigBuilder.getFilters() == null) { lConfigBuilder.setFilters(new FastList<FilterConfig>()); } // now return the config object, this is the only one config object that // should exists // in the system return lConfigBuilder.buildConfig(); }
From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java
/** * private method to handle the user config. * * @param aStreamReader/*from w w w . j a v a 2 s. c o m*/ * the stream reader object * @return the list of user config * @throws XMLStreamException * if there's any exception reading configuration */ private List<UserConfig> handleUsers(XMLStreamReader aStreamReader) throws XMLStreamException { List<UserConfig> lUsers = new FastList<UserConfig>(); while (aStreamReader.hasNext()) { aStreamReader.next(); if (aStreamReader.isStartElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_USER)) { UserConfig lUser = (UserConfig) handlerContext.get(lElementName).processConfig(aStreamReader); lUsers.add(lUser); } } if (aStreamReader.isEndElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_USERS)) { break; } } } return lUsers; }
From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java
/** * method that reads the roles configuration * * @param aStreamReader/*from ww w . jav a 2 s.c om*/ * the stream reader object * @return the list of roles config * @throws XMLStreamException * if there's any exception reading configuration */ private List<RoleConfig> handleRoles(XMLStreamReader aStreamReader) throws XMLStreamException { List<RoleConfig> lRoles = new FastList<RoleConfig>(); while (aStreamReader.hasNext()) { aStreamReader.next(); if (aStreamReader.isStartElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_ROLE)) { RoleConfig lRole = (RoleConfig) handlerContext.get(lElementName).processConfig(aStreamReader); lRoles.add(lRole); } } if (aStreamReader.isEndElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_ROLES)) { break; } } } return lRoles; }
From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java
/** * private method to read the list of rights configuration * * @param aStreamReader/*from w ww .j av a2 s.c om*/ * the stream reader object * @return the list of rights configuration * @throws XMLStreamException * if there's any exception reading configuration */ private List<RightConfig> handleRights(XMLStreamReader aStreamReader) throws XMLStreamException { List<RightConfig> lRights = new FastList<RightConfig>(); while (aStreamReader.hasNext()) { aStreamReader.next(); if (aStreamReader.isStartElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_RIGHT)) { RightConfig lRight = (RightConfig) handlerContext.get(lElementName) .processConfig(aStreamReader); lRights.add(lRight); } } if (aStreamReader.isEndElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_RIGHTS)) { break; } } } return lRights; }
From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java
/** * private method that reads the config for plugins * * @param aStreamReader/*w w w .j av a 2 s .c om*/ * the stream reader object * @return the list of plugin configs * @throws XMLStreamException * if exception occurs while reading */ protected List<PluginConfig> handlePlugins(XMLStreamReader aStreamReader) throws XMLStreamException { List<PluginConfig> lPlugins = new FastList<PluginConfig>(); while (aStreamReader.hasNext()) { aStreamReader.next(); if (aStreamReader.isStartElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_PLUGIN)) { PluginConfig lPlugin = (PluginConfig) handlerContext.get(lElementName) .processConfig(aStreamReader); lPlugins.add(lPlugin); } } if (aStreamReader.isEndElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_PLUGINS)) { break; } } } return lPlugins; }
From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java
/** * private method that reads the config for filters * * @param aStreamReader/*from w ww . j a v a 2s . c o m*/ * the stream reader object * @return the list of filter configs * @throws XMLStreamException * if exception occurs while reading */ protected List<FilterConfig> handleFilters(XMLStreamReader aStreamReader) throws XMLStreamException { List<FilterConfig> lFilters = new FastList<FilterConfig>(); while (aStreamReader.hasNext()) { aStreamReader.next(); if (aStreamReader.isStartElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_FILTER)) { FilterConfig lFilter = (FilterConfig) handlerContext.get(lElementName) .processConfig(aStreamReader); lFilters.add(lFilter); } } if (aStreamReader.isEndElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_FILTERS)) { break; } } } return lFilters; }
From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java
/** * private method that reads the config for logging * * @param aStreamReader// w w w . j a v a 2 s . c om * the stream reader object * @return the list of logging configs * @throws XMLStreamException * if exception occurs while reading */ private List<LoggingConfig> handleLoggingConfigs(XMLStreamReader aStreamReader) throws XMLStreamException { List<LoggingConfig> loggingConfigs = new FastList<LoggingConfig>(); while (aStreamReader.hasNext()) { aStreamReader.next(); if (aStreamReader.isStartElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_LOG4J)) { LoggingConfig loggingConfig = (LoggingConfig) handlerContext.get(lElementName) .processConfig(aStreamReader); loggingConfigs.add(loggingConfig); } } if (aStreamReader.isEndElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(ELEMENT_LOGGING)) { break; } } } return loggingConfigs; }