List of usage examples for javax.xml.stream XMLStreamReader getLocalName
public String getLocalName();
From source file:org.flowable.dmn.converter.child.OutputValuesParser.java
@Override public void parseChildElement(XMLStreamReader xtr, DmnElement parentElement, DecisionTable decisionTable) throws Exception { if (!(parentElement instanceof OutputClause)) return;//from w ww . ja v a 2s . co m OutputClause clause = (OutputClause) parentElement; UnaryTests outputValues = new UnaryTests(); boolean readyWithOutputValues = false; try { while (!readyWithOutputValues && xtr.hasNext()) { xtr.next(); if (xtr.isStartElement() && ELEMENT_TEXT.equalsIgnoreCase(xtr.getLocalName())) { String outputValuesText = xtr.getElementText(); if (StringUtils.isNotEmpty(outputValuesText)) { String[] outputValuesSplit = outputValuesText.replaceAll("^\"", "") .split("\"?(,|$)(?=(([^\"]*\"){2})*[^\"]*$) *\"?"); outputValues.setTextValues(new ArrayList<Object>(Arrays.asList(outputValuesSplit))); } } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) { readyWithOutputValues = true; } } } catch (Exception e) { LOGGER.warn("Error parsing output values", e); } clause.setOutputValues(outputValues); }
From source file:org.gephi.statistics.StatisticsModelImpl.java
public void readXML(XMLStreamReader reader) throws XMLStreamException { Collection<? extends StatisticsUI> uis = Lookup.getDefault().lookupAll(StatisticsUI.class); Collection<? extends StatisticsBuilder> builders = Lookup.getDefault().lookupAll(StatisticsBuilder.class); boolean end = false; while (reader.hasNext() && !end) { int type = reader.next(); switch (type) { case XMLStreamReader.START_ELEMENT: String name = reader.getLocalName(); if ("report".equalsIgnoreCase(name)) { String classStr = reader.getAttributeValue(null, "class"); Class reportClass = null; for (StatisticsBuilder builder : builders) { if (builder.getStatisticsClass().getName().equals(classStr)) { reportClass = builder.getStatisticsClass(); }// w w w . j a v a 2 s. c o m } if (reportClass != null) { String report = reader.getAttributeValue(null, "value"); report = unembedImages(report); reportMap.put(reportClass, report); } } break; case XMLStreamReader.END_ELEMENT: if ("statisticsmodel".equalsIgnoreCase(reader.getLocalName())) { end = true; } break; } } }
From source file:org.gtdfree.model.GTDDataXMLTools.java
static private boolean checkTagStart(XMLStreamReader r, String tag) throws XMLStreamException { return tag.equals(r.getLocalName()) && r.getEventType() == XMLStreamReader.START_ELEMENT; }
From source file:org.gtdfree.model.GTDDataXMLTools.java
private static void findTagEnd(XMLStreamReader r, String tag) throws XMLStreamException { while (!r.getLocalName().equals(tag) || XMLStreamReader.END_ELEMENT != r.getEventType()) { if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; }/*from www. j a v a2 s .co m*/ r.nextTag(); } }
From source file:org.gtdfree.model.GTDDataXMLTools.java
static public DataHeader load(GTDModel model, InputStream in) throws XMLStreamException, IOException { model.setSuspendedForMultipleChanges(true); model.getDataRepository().suspend(true); XMLStreamReader r; try {//from w w w.j av a2 s . c o m // buffer size is same as default in 1.6, we explicitly request it so, not to brake if defaut changes. BufferedInputStream bin = new BufferedInputStream(in, 8192); bin.mark(8191); Reader rr = new InputStreamReader(bin); CharBuffer b = CharBuffer.allocate(96); rr.read(b); b.position(0); //System.out.println(b); Pattern pattern = Pattern.compile("<\\?.*?encoding\\s*?=.*?\\?>", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$ Matcher matcher = pattern.matcher(b); // reset back to start of file bin.reset(); // we check if encoding is defined in xml, by the book encoding on r should be null if not defined in xml, // but in reality it can be arbitrary if not defined in xml. So we have to check ourselves. if (matcher.find()) { //System.out.println(matcher); // if defined, then XML parser will pick it up and use it r = XMLInputFactory.newInstance().createXMLStreamReader(bin); Logger.getLogger(GTDDataXMLTools.class).info("XML declared encoding: " + r.getEncoding() //$NON-NLS-1$ + ", system default encoding: " + Charset.defaultCharset()); //$NON-NLS-1$ } else { //System.out.println(matcher); // if not defined, then we assume it is generated by gtd-free version 0.4 or some local editor, // so we assume system default encoding. r = XMLInputFactory.newInstance().createXMLStreamReader(new InputStreamReader(bin)); Logger.getLogger(GTDDataXMLTools.class) .info("XML assumed system default encoding: " + Charset.defaultCharset()); //$NON-NLS-1$ } r.nextTag(); if ("gtd-data".equals(r.getLocalName())) { //$NON-NLS-1$ DataHeader dh = new DataHeader(null, r.getAttributeValue(null, "version"), //$NON-NLS-1$ r.getAttributeValue(null, "modified")); //$NON-NLS-1$ if (dh.version != null) { if (dh.version.equals("2.0")) { //$NON-NLS-1$ r.nextTag(); _load_2_0(model, r); return dh; } } String s = r.getAttributeValue(null, "lastActionID"); //$NON-NLS-1$ if (s != null) { try { model.setLastActionID(Integer.parseInt(s)); } catch (Exception e) { Logger.getLogger(GTDDataXMLTools.class).debug("Internal error.", e); //$NON-NLS-1$ } } if (dh.version != null) { if (dh.version.equals("2.1")) { //$NON-NLS-1$ r.nextTag(); _load_2_1(model, r); return dh; } if (dh.version.startsWith("2.2")) { //$NON-NLS-1$ r.nextTag(); _load_2_2(model, r); return dh; } } throw new IOException("XML gtd-free data with version number " + dh.version //$NON-NLS-1$ + " can not be imported. Data version is newer then supported versions. Update your GTD-Free application to latest version."); //$NON-NLS-1$ } _load_1_0(model, r); return null; } catch (XMLStreamException e) { if (e.getNestedException() != null) { Logger.getLogger(GTDDataXMLTools.class).debug("Parse error.", e.getNestedException()); //$NON-NLS-1$ } else { Logger.getLogger(GTDDataXMLTools.class).debug("Parse error.", e); //$NON-NLS-1$ } throw e; } catch (IOException e) { throw e; } finally { model.setSuspendedForMultipleChanges(false); model.getDataRepository().suspend(false); } }
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 w w w . j ava 2 s . c o m*/ 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 w w w. j a v a 2 s . 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 www . j ava 2 s . co 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// w w w.j av 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 w ww.java2 s . c o m*/ * 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; }