List of usage examples for javax.xml.stream XMLStreamConstants END_DOCUMENT
int END_DOCUMENT
To view the source code for javax.xml.stream XMLStreamConstants END_DOCUMENT.
Click Source Link
From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java
protected static final Model readDocument(final XMLStreamReader reader) { try {//from w ww.jav a2s. c om if (XMLStreamConstants.START_DOCUMENT == reader.getEventType()) { Model model = null; while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { if ("XMI".equals(reader.getLocalName())) { model = readXMI(reader); if (model == null) { throw new IllegalStateException(); } break; } else { throw new XmiRuntimeException("Expecting Foo element, got: " + reader.getLocalName()); } } case XMLStreamConstants.END_DOCUMENT: { if (model == null) { throw new IllegalStateException(); } return model; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); } else { throw new AssertionError(reader.getLocalName()); } } catch (final XMLStreamException e) { throw new XmiRuntimeException(e); } }
From source file:org.ut.biolab.medsavant.client.plugin.AppController.java
public AppDescriptor getDescriptorFromFile(File f) throws PluginVersionException { XMLStreamReader reader;/*from ww w .ja va 2 s .c o m*/ 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 w w. ja v a 2 s . c o m*/ 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:ru.codeinside.gws.crypto.cryptopro.CryptoProvider.java
private String saxFilter(Node node) { try {// w w w . j a va 2s .c o m final Transformer transformer = TransformerFactory.newInstance().newTransformer(); final StringWriter w1 = new StringWriter(); transformer.transform(new DOMSource(node), new StreamResult(w1)); XMLInputFactory xif = XMLInputFactory.newInstance(); XMLEventReader eventReader = xif .createXMLEventReader(new StreamSource(new StringReader(w1.toString()))); XMLEventReader filteredReader = xif.createFilteredReader(eventReader, new EventFilter() { @Override public boolean accept(XMLEvent event) { int type = event.getEventType(); if (type == XMLStreamConstants.START_DOCUMENT || type == XMLStreamConstants.END_DOCUMENT) { return false; } if (event.isStartElement()) { StartElement startElement = (StartElement) event; QName name = startElement.getName(); if ("".equals(name.getNamespaceURI()) && "root".equals(name.getLocalPart())) { return false; } } if (event.isEndElement()) { EndElement endElement = (EndElement) event; QName name = endElement.getName(); if ("".equals(name.getNamespaceURI()) && "root".equals(name.getLocalPart())) { return false; } } return true; } }); StringWriter sw = new StringWriter(); XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLEventWriter writer = xof.createXMLEventWriter(sw); while (filteredReader.hasNext()) { writer.add(filteredReader.nextEvent()); } return sw.toString(); } catch (Exception e) { throw new RuntimeException(e); } }
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;// w ww . j av a2s .c o m 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 w w . j a v a 2s . 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 ww .j av a2 s. co 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); }
From source file:savant.util.Version.java
/** * Factory method which construct a Version object from a URL pointing to an XML file. * @param url URL of our version.xml file * @return the version number read from the file *//* w w w .j a va 2s . c o m*/ public static Version fromURL(URL url) throws IOException { try { XMLStreamReader reader = XMLInputFactory.newInstance() .createXMLStreamReader(NetworkUtils.openStream(url)); boolean done = false; boolean foundCurrentVersion = false; do { switch (reader.next()) { case XMLStreamConstants.START_ELEMENT: String elemName = reader.getLocalName(); if (elemName.equals("version") && "current_release".equals(reader.getAttributeValue(null, "status"))) { foundCurrentVersion = true; } else if (foundCurrentVersion && elemName.equals("name")) { return new Version(reader.getElementText()); } else { foundCurrentVersion = false; } 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); } return null; }