List of usage examples for javax.xml.stream XMLStreamConstants START_ELEMENT
int START_ELEMENT
To view the source code for javax.xml.stream XMLStreamConstants START_ELEMENT.
Click Source Link
From source file:org.springmodules.remoting.xmlrpc.stax.AbstractStaxXmlRpcParser.java
/** * Creates a new Object from the current element being read in the specified * <code>StreamReader</code>. * /* w w w .j av a 2 s . com*/ * @param reader * the <code>StreamReader</code>. * @return the created Object. * @throws XmlRpcInvalidPayloadException * if the element contains an unknown child. * @see #parseArrayElement(XMLStreamReader) * @see #parseStructElement(XMLStreamReader) */ protected final XmlRpcElement parseValueElement(XMLStreamReader reader) throws XMLStreamException { while (reader.hasNext()) { int event = reader.next(); String localName = null; switch (event) { case XMLStreamConstants.START_ELEMENT: localName = reader.getLocalName(); if (XmlRpcElementNames.ARRAY.equals(localName)) { return parseArrayElement(reader); } else if (XmlRpcElementNames.BASE_64.equals(localName)) { String source = reader.getElementText(); return new XmlRpcBase64(source); } else if (XmlRpcElementNames.BOOLEAN.equals(localName)) { String source = reader.getElementText(); return new XmlRpcBoolean(source); } else if (XmlRpcElementNames.DATE_TIME.equals(localName)) { String source = reader.getElementText(); return new XmlRpcDateTime(source); } else if (XmlRpcElementNames.DOUBLE.equals(localName)) { String source = reader.getElementText(); return new XmlRpcDouble(source); } else if (XmlRpcElementNames.I4.equals(localName) || XmlRpcElementNames.INT.equals(localName)) { String source = reader.getElementText(); return new XmlRpcInteger(source); } else if (XmlRpcElementNames.STRING.equals(localName) || XmlRpcElementNames.INT.equals(localName)) { String source = reader.getElementText(); return new XmlRpcString(source); } else if (XmlRpcElementNames.STRUCT.equals(localName)) { return parseStructElement(reader); } else { XmlRpcParsingUtils.handleUnexpectedElementFound(localName); } case XMLStreamConstants.CHARACTERS: String source = reader.getText(); return new XmlRpcString(source); } } // we should not reach this point. return null; }
From source file:org.talend.dataprep.schema.xls.streaming.StreamingSheetReader.java
/** * Handles a Stream event./* w w w. j a v a 2s . c o m*/ * * @param event * @throws SAXException */ private void handleEvent(XMLEvent event) throws SAXException { if (event.getEventType() == XMLStreamConstants.CHARACTERS) { Characters c = event.asCharacters(); lastContents += c.getData(); } else if (event.getEventType() == XMLStreamConstants.START_ELEMENT) { StartElement startElement = event.asStartElement(); String tagLocalName = startElement.getName().getLocalPart(); if ("row".equals(tagLocalName)) { Attribute rowIndex = startElement.getAttributeByName(new QName("r")); if (firstRowIndex == -1) { firstRowIndex = Integer.parseInt(rowIndex.getValue()); } currentRow = new StreamingRow(Integer.parseInt(rowIndex.getValue()) - 1); } else if ("cols".equals(tagLocalName)) { parsingCols = true; } else if ("col".equals(tagLocalName) && parsingCols) { colNumber = colNumber + 1; } else if ("c".equals(tagLocalName)) { Attribute ref = startElement.getAttributeByName(new QName("r")); String[] coord = ref.getValue().split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)"); currentCell = new StreamingCell(CellReference.convertColStringToIndex(coord[0]), Integer.parseInt(coord[1]) - 1); setFormatString(startElement, currentCell); Attribute type = startElement.getAttributeByName(new QName("t")); if (type != null) { currentCell.setType(type.getValue()); } else { currentCell.setType("n"); } Attribute style = startElement.getAttributeByName(new QName("s")); if (style != null) { String indexStr = style.getValue(); try { int index = Integer.parseInt(indexStr); currentCell.setCellStyle(stylesTable.getStyleAt(index)); } catch (NumberFormatException nfe) { LOGGER.warn("Ignoring invalid style index {}", indexStr); } } // we store the dimension as well to revert with this method when cols not found // can happen see xlsx attached here https://jira.talendforge.org/browse/TDP-1957 // <dimension ref="A1:B60"/> } else if ("dimension".equals(tagLocalName)) { Attribute attribute = startElement.getAttributeByName(new QName("ref")); if (attribute != null) { this.dimension = attribute.getValue(); } } // Clear contents cache lastContents = ""; } else if (event.getEventType() == XMLStreamConstants.END_ELEMENT) { EndElement endElement = event.asEndElement(); String tagLocalName = endElement.getName().getLocalPart(); if ("v".equals(tagLocalName) || "t".equals(tagLocalName)) { currentCell.setRawContents(unformattedContents()); currentCell.setContents(formattedContents()); } else if ("row".equals(tagLocalName) && currentRow != null) { rowCache.add(currentRow); } else if ("c".equals(tagLocalName)) { currentRow.getCellMap().put(currentCell.getColumnIndex(), currentCell); } else if ("cols".equals(tagLocalName)) { parsingCols = false; } } }
From source file:org.tobarsegais.webapp.data.Index.java
public static Index read(String bundle, XMLStreamReader reader) throws XMLStreamException { while (reader.hasNext() && !reader.isStartElement()) { reader.next();// ww w . ja v a 2 s . co m } if (reader.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new IllegalStateException("Expecting a start element"); } if (!"index".equals(reader.getLocalName())) { throw new IllegalStateException("Expecting a <index> element, found a <" + reader.getLocalName() + ">"); } List<IndexEntry> entries = new ArrayList<IndexEntry>(); int depth = 0; while (reader.hasNext() && depth >= 0) { switch (reader.next()) { case XMLStreamConstants.START_ELEMENT: if (depth == 0 && "entry".equals(reader.getLocalName())) { entries.add(IndexEntry.read(bundle, Collections.<String>emptyList(), reader)); } else { depth++; } break; case XMLStreamConstants.END_ELEMENT: depth--; break; } } return new Index(entries); }
From source file:org.tobarsegais.webapp.data.Plugin.java
public static Plugin read(XMLStreamReader reader) throws XMLStreamException { while (reader.hasNext() && !reader.isStartElement()) { reader.next();//w w w . j a va 2 s . c om } if (reader.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new IllegalStateException("Expecting a start element"); } if (!"plugin".equals(reader.getLocalName())) { throw new IllegalStateException("Expecting a <plugin> element"); } String name = reader.getAttributeValue(null, "name"); String id = reader.getAttributeValue(null, "id"); String version = reader.getAttributeValue(null, "version"); String providerName = reader.getAttributeValue(null, "provider-name"); List<Extension> extensions = new ArrayList<Extension>(); int depth = 0; while (reader.hasNext() && depth >= 0) { switch (reader.next()) { case XMLStreamConstants.START_ELEMENT: if (depth == 0 && "extension".equals(reader.getLocalName())) { extensions.add(Extension.read(reader)); } else { depth++; } break; case XMLStreamConstants.END_ELEMENT: depth--; break; } } return new Plugin(name, id, version, providerName, extensions); }
From source file:org.tobarsegais.webapp.data.Toc.java
public static Toc read(XMLStreamReader reader) throws XMLStreamException { while (reader.hasNext() && !reader.isStartElement()) { reader.next();// w ww . jav a2 s. co m } if (reader.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new IllegalStateException("Expecting a start element"); } if (!"toc".equals(reader.getLocalName())) { throw new IllegalStateException("Expecting a <toc> element"); } String label = reader.getAttributeValue(null, "label"); String topic = reader.getAttributeValue(null, "topic"); List<Topic> topics = new ArrayList<Topic>(); int depth = 0; while (reader.hasNext() && depth >= 0) { switch (reader.next()) { case XMLStreamConstants.START_ELEMENT: if (depth == 0 && "topic".equals(reader.getLocalName())) { topics.add(Topic.read(reader)); } else { depth++; } break; case XMLStreamConstants.END_ELEMENT: depth--; break; } } return new Toc(label, topic, topics); }
From source file:org.ut.biolab.medsavant.client.plugin.AppController.java
public AppDescriptor getDescriptorFromFile(File f) throws PluginVersionException { XMLStreamReader reader;//w w w . j a v a 2 s . c om try { JarFile jar = new JarFile(f); ZipEntry entry = jar.getEntry("plugin.xml"); if (entry != null) { InputStream entryStream = jar.getInputStream(entry); reader = XMLInputFactory.newInstance().createXMLStreamReader(entryStream); String className = null; String id = null; String version = null; String sdkVersion = null; String name = null; String category = AppDescriptor.Category.UTILITY.toString(); String currentElement = null; String currentText = ""; do { switch (reader.next()) { case XMLStreamConstants.START_ELEMENT: switch (readElement(reader)) { case PLUGIN: className = readAttribute(reader, AppDescriptor.PluginXMLAttribute.CLASS); //category can be specified as an attribute or <property>. category = readAttribute(reader, AppDescriptor.PluginXMLAttribute.CATEGORY); break; case ATTRIBUTE: if ("sdk-version".equals(readAttribute(reader, AppDescriptor.PluginXMLAttribute.ID))) { sdkVersion = readAttribute(reader, AppDescriptor.PluginXMLAttribute.VALUE); } break; case PARAMETER: if ("name".equals(readAttribute(reader, AppDescriptor.PluginXMLAttribute.ID))) { name = readAttribute(reader, AppDescriptor.PluginXMLAttribute.VALUE); } break; case PROPERTY: if ("name".equals(readAttribute(reader, AppDescriptor.PluginXMLAttribute.NAME))) { name = readAttribute(reader, AppDescriptor.PluginXMLAttribute.VALUE); if (name == null) { currentElement = "name"; } } if ("version".equals(readAttribute(reader, AppDescriptor.PluginXMLAttribute.NAME))) { version = readAttribute(reader, AppDescriptor.PluginXMLAttribute.VALUE); if (version == null) { currentElement = "version"; } } if ("sdk-version" .equals(readAttribute(reader, AppDescriptor.PluginXMLAttribute.NAME))) { sdkVersion = readAttribute(reader, AppDescriptor.PluginXMLAttribute.VALUE); if (sdkVersion == null) { currentElement = "sdk-version"; } } if ("category".equals(readAttribute(reader, AppDescriptor.PluginXMLAttribute.NAME))) { category = readAttribute(reader, AppDescriptor.PluginXMLAttribute.VALUE); if (category == null) { currentElement = "category"; } } break; } break; case XMLStreamConstants.CHARACTERS: if (reader.isWhiteSpace()) { break; } else if (currentElement != null) { currentText += reader.getText().trim().replace("\t", ""); } break; case XMLStreamConstants.END_ELEMENT: if (readElement(reader) == AppDescriptor.PluginXMLElement.PROPERTY) { if (currentElement != null && currentText.length() > 0) { if (currentElement.equals("name")) { name = currentText; } else if (currentElement.equals("sdk-version")) { sdkVersion = currentText; } else if (currentElement.equals("category")) { category = currentText; } else if (currentElement.equals("version")) { version = currentText; } } currentText = ""; currentElement = null; } break; case XMLStreamConstants.END_DOCUMENT: reader.close(); reader = null; break; } } while (reader != null); System.out.println(className + " " + name + " " + version); if (className != null && name != null && version != null) { return new AppDescriptor(className, version, name, sdkVersion, category, f); } } } catch (Exception x) { LOG.error("Error parsing plugin.xml from " + f.getAbsolutePath() + ": " + x); } throw new PluginVersionException(f.getName() + " did not contain a valid plugin"); }
From source file:org.ut.biolab.medsavant.client.plugin.PluginIndex.java
public PluginIndex(URL url) throws IOException { urls = new HashMap<String, URL>(); try {//from w ww . java 2 s . c om XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader( ClientNetworkUtils.openStream(url, ClientNetworkUtils.NONCRITICAL_CONNECT_TIMEOUT, ClientNetworkUtils.NONCRITICAL_READ_TIMEOUT)); if (reader.getVersion() == null) { throw new XMLStreamException("Invalid XML at URL " + url); } boolean done = false; String id = null; do { if (reader.hasNext()) { int t = reader.next(); switch (t) { case XMLStreamConstants.START_ELEMENT: String elemName = reader.getLocalName(); if (elemName.equals("leaf")) { id = reader.getAttributeValue(null, "id"); } else if (elemName.equals("url")) { if (id != null) { try { urls.put(id, new URL(reader.getElementText())); } catch (MalformedURLException x) { LOG.warn(String.format("Unable to parse \"%s\" as a plugin URL.", reader.getElementText())); } id = null; } } break; case XMLStreamConstants.END_DOCUMENT: reader.close(); done = true; break; } } else { throw new XMLStreamException("Malformed XML at " + url); } } while (!done); } catch (XMLStreamException x) { throw new IOException("Unable to get version number from web-site.", x); } }
From source file:savant.file.Project.java
private void createFromXML(InputStream input) throws XMLStreamException, ParseException, IOException { trackPaths = new ArrayList<String>(); trackModes = new ArrayList<DrawingMode>(); bookmarks = new ArrayList<Bookmark>(); controls = new ArrayList<String>(); String genomeName = null;/*from ww w. j av a 2s . com*/ String genomeDesc = null; String cytobandPath = null; List<ReferenceInfo> references = new ArrayList<ReferenceInfo>(); reader = XMLInputFactory.newInstance().createXMLStreamReader(input); int version = -1; boolean done = false; do { switch (reader.next()) { case XMLStreamConstants.START_ELEMENT: switch (readElement()) { case savant: version = Integer.valueOf(readAttribute(XMLAttribute.version)); Bookmark r = new Bookmark(readAttribute(XMLAttribute.range)); range = (Range) r.getRange(); reference = r.getReference(); LOG.info("Reading project version " + version); break; case genome: genomeName = readAttribute(XMLAttribute.name); genomeDesc = readAttribute(XMLAttribute.description); genomePath = readAttribute(XMLAttribute.uri); cytobandPath = readAttribute(XMLAttribute.cytoband); break; case reference: references.add(new ReferenceInfo(readAttribute(XMLAttribute.name), Integer.valueOf(readAttribute(XMLAttribute.length)))); break; case track: trackPaths.add(readAttribute(XMLAttribute.uri)); try { trackModes.add(DrawingMode.valueOf(readAttribute(XMLAttribute.mode))); } catch (Exception x) { // Mode attribute is invalid or missing. trackModes.add(null); } break; case bookmark: Bookmark b = new Bookmark(readAttribute(XMLAttribute.range)); b.setAnnotation(reader.getElementText()); bookmarks.add(b); break; case control: controls.add(reader.getElementText()); break; } break; case XMLStreamConstants.END_DOCUMENT: reader.close(); done = true; break; } } while (!done); if (cytobandPath != null) { genome = new Genome(genomeName, genomeDesc, URI.create(cytobandPath), null); } else if (references.size() > 0) { genome = new Genome(genomeName, genomeDesc, references.toArray(new ReferenceInfo[0])); } }
From source file:savant.plugin.PluginIndex.java
public PluginIndex(URL url) throws IOException { urls = new HashMap<String, URL>(); try {/*w ww . java 2 s .c o m*/ XMLStreamReader reader = XMLInputFactory.newInstance() .createXMLStreamReader(NetworkUtils.openStream(url)); boolean done = false; String id = null; do { switch (reader.next()) { case XMLStreamConstants.START_ELEMENT: String elemName = reader.getLocalName(); if (elemName.equals("leaf")) { id = reader.getAttributeValue(null, "id"); } else if (elemName.equals("url")) { if (id != null) { try { urls.put(id, new URL(reader.getElementText())); } catch (MalformedURLException x) { LOG.info("Unable to parse \"" + reader.getElementText() + "\" as a plugin URL."); } id = null; } } break; case XMLStreamConstants.END_DOCUMENT: reader.close(); done = true; break; } } while (!done); } catch (XMLStreamException x) { throw new IOException("Unable to get version number from web-site.", x); } }
From source file:savant.plugin.Tool.java
/** * The tool's arguments are contained in the associated plugin.xml file. *//*from w w w . j ava2 s . c o m*/ void parseDescriptor() throws XMLStreamException, FileNotFoundException { XMLStreamReader reader = XMLInputFactory.newInstance() .createXMLStreamReader(new FileInputStream(getDescriptor().getFile())); do { switch (reader.next()) { case XMLStreamConstants.START_ELEMENT: String elemName = reader.getLocalName().toLowerCase(); if (elemName.equals("tool")) { baseCommand = reader.getElementText(); } else if (elemName.equals("arg")) { // There's lots of crud in the XML file; we're just interested in the <arg> elements. arguments.add(new ToolArgument(reader)); } else if (elemName.equals("progress")) { progressRegex = Pattern.compile(reader.getElementText()); } else if (elemName.equals("error")) { errorRegex = Pattern.compile(reader.getElementText()); } break; case XMLStreamConstants.END_DOCUMENT: reader.close(); reader = null; break; } } while (reader != null); }