List of usage examples for javax.xml.stream XMLStreamReader getLocalName
public String getLocalName();
From source file:de.tuebingen.uni.sfs.germanet.api.IliLoader.java
/** * Loads <code>IliRecords</code> from the specified file into this * <code>IliLoader</code>'s <code>GermaNet</code> object. * @param iliFile the file containing <code>IliRecords</code> data * @throws java.io.FileNotFoundException * @throws javax.xml.stream.XMLStreamException *//*from w ww .j a v a 2 s .c om*/ protected void loadILI(File iliFile) throws FileNotFoundException, XMLStreamException { InputStream in = new FileInputStream(iliFile); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader parser = factory.createXMLStreamReader(in); int event; String nodeName; logger.debug("Loading " + iliFile.getName() + "..."); //Parse entire file, looking for ili record 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_ILI_RECORD)) { IliRecord ili = processIliRecord(parser); germaNet.addIliRecord(ili); } break; } } parser.close(); logger.debug("Done."); }
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 a v a 2 s. 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.amalto.core.load.context.BufferStateContextWriter.java
public void writeStartElement(XMLStreamReader reader) throws XMLStreamException { // Attribute parsing Attributes attributes = Utils.parseAttributes(reader); // Namespace parsing Map<String, String> prefixToNamespace = Utils.parseNamespace(reader); Set<Map.Entry<String, String>> entries = prefixToNamespace.entrySet(); for (Map.Entry<String, String> entry : entries) { processedElements.add(new ProcessedStartNamespace(entry.getKey(), entry.getValue())); }// ww w .j a v a 2s . c o m // New start element ProcessedStartElement startElement = new ProcessedStartElement(reader.getNamespaceURI(), reader.getLocalName(), reader.getName().getLocalPart(), attributes); processedElements.add(startElement); }
From source file:hudson.plugins.report.jck.parsers.JtregReportParser.java
private List<Test> parseTestsuites(XMLStreamReader in) throws Exception { List<Test> r = new ArrayList<>(); String ignored = "com.google.security.wycheproof.OpenJDKAllTests"; while (in.hasNext()) { int event = in.next(); if (event == START_ELEMENT && TESTSUITE.equals(in.getLocalName())) { JtregBackwardCompatibileSuite suite = parseTestSuite(in); if (ignored.equals(suite.name)) { System.out.println("Skipping ignored suite : " + ignored); } else { r.addAll(suite.getTests()); }//from w w w .ja va2 s . c o m } } return r; }
From source file:edu.indiana.d2i.htrc.portal.HTRCAgentClient.java
private JobDetailsBean parseJobSubmit(InputStream stream) throws XMLStreamException { JobDetailsBean res = new JobDetailsBean(); XMLStreamReader parser = factory.createXMLStreamReader(stream); while (parser.hasNext()) { int event = parser.next(); if (event == XMLStreamConstants.START_ELEMENT) { if (parser.hasName()) { // only parse several attributes if (parser.getLocalName().equals(JobDetailsBean.STATUS)) { res.setJobStatus(parser.getAttributeValue(0)); } else if (parser.getLocalName().equals(JobDetailsBean.JOBID)) { res.setJobId(parser.getElementText()); } else if (parser.getLocalName().equals(JobDetailsBean.JOBNAME)) { res.setJobTitle(parser.getElementText()); } else if (parser.getLocalName().equals(JobDetailsBean.DATE)) { res.setLastUpdatedDate(parser.getElementText()); } else if (parser.getLocalName().equals(JobDetailsBean.USER)) { res.setUserName(parser.getElementText()); }// w ww . j av a2s .c om } } } return res; }
From source file:edu.indiana.d2i.htrc.portal.HTRCAgentClient.java
private Map<String, JobDetailsBean> parseJobDetailBeans(InputStream stream) throws XMLStreamException { Map<String, JobDetailsBean> res = new TreeMap<String, JobDetailsBean>(); XMLStreamReader parser = factory.createXMLStreamReader(stream); while (parser.hasNext()) { int event = parser.next(); if (event == XMLStreamConstants.START_ELEMENT) { if (parser.hasName()) { if (parser.getLocalName().equals("job_status")) { // one job status JobDetailsBean detail = new JobDetailsBean(); Map<String, String> jobParams = new HashMap<String, String>(); Map<String, String> results = new HashMap<String, String>(); int innerEvent = parser.next(); while (true) { if (innerEvent == XMLStreamConstants.END_ELEMENT && parser.getLocalName().equals("job_status")) { break; }// ww w. j av a2 s . c o m if (innerEvent == XMLStreamConstants.START_ELEMENT && parser.hasName()) { // single tag if (parser.getLocalName().equals("job_name")) { detail.setJobTitle(parser.getElementText()); } else if (parser.getLocalName().equals("user")) { detail.setUserName(parser.getElementText()); } else if (parser.getLocalName().equals("algorithm")) { detail.setAlgorithmName(parser.getElementText()); } else if (parser.getLocalName().equals("job_id")) { detail.setJobId(parser.getElementText()); } else if (parser.getLocalName().equals("date")) { detail.setLastUpdatedDate(parser.getElementText()); } // parameters if (parser.hasName() && parser.getLocalName().equals(JobDetailsBean.ONEPARAM)) { String name, value; name = value = ""; for (int i = 0; i < 3; i++) { if (parser.getAttributeName(i).toString().equals("name")) name = parser.getAttributeValue(i); if (parser.getAttributeName(i).toString().equals("value")) value = parser.getAttributeValue(i); } jobParams.put(name, value); } // status if (parser.hasName() && parser.getLocalName().equals(JobDetailsBean.STATUS)) { String status = parser.getAttributeValue(0); detail.setJobStatus(status); } // results if (parser.hasName() && parser.getLocalName().equals(JobDetailsBean.RESULT)) { String name = parser.getAttributeValue(0); String value = parser.getElementText(); results.put(name, value); } // message if (parser.hasName() && parser.getLocalName().equals(JobDetailsBean.MESSAGE)) { detail.setMessage(parser.getElementText()); } // saved or unsaved if (parser.hasName() && parser.getLocalName().equals(JobDetailsBean.SAVEDORNOT)) { detail.setJobSavedStr(parser.getElementText()); } } innerEvent = parser.next(); } detail.setJobParams(jobParams); detail.setResults(results); res.put(detail.getJobId(), detail); } } } } return res; }
From source file:cz.muni.fi.mir.mathmlcanonicalization.MathMLCanonicalizer.java
/** * Loads configuration from XML file, overriding the properties. *///from www . j a va2 s . co m private void loadXMLConfiguration(InputStream xmlConfigurationStream) throws ConfigException, XMLStreamException { assert xmlConfigurationStream != null; final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); final XMLStreamReader reader = inputFactory.createXMLStreamReader(xmlConfigurationStream); boolean config = false; Module module = null; while (reader.hasNext()) { final int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: { String name = reader.getLocalName(); if (name.equals("config")) { config = true; break; } if (config && name.equals("module")) { if (reader.getAttributeCount() == 1) { final String attributeName = reader.getAttributeLocalName(0); final String attributeValue = reader.getAttributeValue(0); if (attributeName.equals("name") && attributeValue != null) { String fullyQualified = Settings.class.getPackage().getName() + ".modules." + attributeValue; try { Class<?> moduleClass = Class.forName(fullyQualified); module = (Module) moduleClass.newInstance(); } catch (InstantiationException ex) { LOGGER.log(Level.SEVERE, ex.getMessage(), ex); throw new ConfigException("cannot instantiate module " + attributeValue, ex); } catch (IllegalAccessException ex) { LOGGER.log(Level.SEVERE, ex.getMessage(), ex); throw new ConfigException("cannot access module " + attributeValue, ex); } catch (ClassNotFoundException ex) { LOGGER.log(Level.SEVERE, ex.getMessage(), ex); throw new ConfigException("cannot load module " + attributeValue, ex); } } } } if (config && name.equals("property")) { if (reader.getAttributeCount() == 1) { final String attributeName = reader.getAttributeLocalName(0); final String attributeValue = reader.getAttributeValue(0); if (attributeName.equals("name") && attributeValue != null) { if (module == null) { if (Settings.isProperty(attributeValue)) { Settings.setProperty(attributeValue, reader.getElementText()); } else { throw new ConfigException("configuration not valid\n" + "Tried to override non-existing global property " + attributeValue); } } else { if (module.isProperty(attributeValue)) { module.setProperty(attributeValue, reader.getElementText()); } else { throw new ConfigException("configuration not valid\n" + "configuration tried to override non-existing property " + attributeValue); } } } } } break; } case XMLStreamConstants.END_ELEMENT: { if (config && reader.getLocalName().equals("module")) { addModule(module); module = null; } if (config && reader.getLocalName().equals("config")) { config = false; } } } } }
From source file:de.tuebingen.uni.sfs.germanet.api.IliLoader.java
/** * Loads <code>IliRecords</code> from the specified stream into this * <code>IliLoader</code>'s <code>GermaNet</code> object. * @param inputStream the stream containing <code>IliRecords</code> data * @throws javax.xml.stream.XMLStreamException *//* www . jav a 2 s. c o m*/ protected void loadILI(InputStream inputStream) throws XMLStreamException { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader parser = factory.createXMLStreamReader(inputStream); int event; String nodeName; logger.debug("Loading input stream interLingualIndex_DE-EN.xml..."); //Parse entire file, looking for ili record 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_ILI_RECORD)) { IliRecord ili = processIliRecord(parser); germaNet.addIliRecord(ili); } break; } } parser.close(); logger.debug("Done."); }
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);// w w w.ja va2s .co m 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(); } } }
From source file:com.conx.logistics.kernel.bpm.impl.jbpm.core.mock.BPMGuvnorUtil.java
private List<String> getPackageNamesFromGuvnor() { List<String> packages = new ArrayList<String>(); String packagesURL = getGuvnorProtocol() + "://" + getGuvnorHost() + "/" + getGuvnorSubdomain() + "/rest/packages/"; try {/*from w w w . j a v a2 s. c o m*/ XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader(getInputStreamForURL(packagesURL, "GET")); while (reader.hasNext()) { if (reader.next() == XMLStreamReader.START_ELEMENT) { if ("title".equals(reader.getLocalName())) { String pname = reader.getElementText(); if (!pname.equalsIgnoreCase("Packages")) { packages.add(pname); } } } } } catch (Exception e) { logger.error("Error retriving packages from guvnor: " + e.getMessage()); } return packages; }