List of usage examples for javax.xml.stream XMLStreamReader getNamespaceURI
public String getNamespaceURI();
From source file:de.tuebingen.uni.sfs.germanet.api.WiktionaryLoader.java
/** * Loads <code>WiktionaryParaphrases</code> from the given streams into this * <code>WiktionaryLoader</code>'s <code>GermaNet</code> object. * @param inputStreams the list of streams containing <code>WiktionaryParaphrases</code> data * @param xmlNames the names of the streams * @throws javax.xml.stream.XMLStreamException *//*from w w w . j av a2s . c o m*/ protected void loadWiktionary(List<InputStream> inputStreams, List<String> xmlNames) throws XMLStreamException { for (int i = 0; i < inputStreams.size(); i++) { if (xmlNames.get(i).startsWith("wiktionary")) { logger.debug("Loading input stream " + xmlNames.get(i) + "..."); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader parser = factory.createXMLStreamReader(inputStreams.get(i)); 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:davmail.exchange.dav.ExchangePropPatchMethod.java
protected void handleProperty(XMLStreamReader reader, MultiStatusResponse multiStatusResponse) throws XMLStreamException { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "prop")) { reader.next();// w ww . j a v a2 s.co m if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); Namespace namespace = Namespace.getNamespace(reader.getNamespaceURI()); multiStatusResponse.add(new DefaultDavProperty(tagLocalName, reader.getElementText(), namespace)); } } }
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())); }//www . j av a2s. c om // New start element ProcessedStartElement startElement = new ProcessedStartElement(reader.getNamespaceURI(), reader.getLocalName(), reader.getName().getLocalPart(), attributes); processedElements.add(startElement); }
From source file:lux.search.highlight.XmlHighlighter.java
@Override public void handleEvent(XMLStreamReader reader, int eventType) throws XMLStreamException { switch (eventType) { case XMLStreamConstants.START_DOCUMENT: xmlStreamReader = reader; // cache the reader so we can pull events super.handleEvent(reader, eventType); break;//from w w w .ja va 2s . c o m case XMLStreamConstants.START_ELEMENT: super.handleEvent(reader, eventType); xmlStreamTokens .pushElement(new QName(reader.getNamespaceURI(), reader.getLocalName(), reader.getPrefix())); break; case XMLStreamConstants.END_ELEMENT: super.handleEvent(reader, eventType); xmlStreamTokens.popElement(); break; case XMLStreamConstants.COMMENT: case XMLStreamConstants.PROCESSING_INSTRUCTION: super.handleEvent(reader, eventType); break; case XMLStreamConstants.CDATA: throw new XMLStreamException("unexpected CDATA event"); case XMLStreamConstants.SPACE: super.handleEvent(reader, eventType); break; case XMLStreamConstants.CHARACTERS: textReader.text(); try { highlightTextNode(); } catch (IOException e) { throw new XMLStreamException(e); } break; case XMLStreamConstants.ENTITY_REFERENCE: throw new XMLStreamException("unexpected entity reference event"); default: super.handleEvent(reader, eventType); } }
From source file:com.microsoft.windowsazure.storage.table.TableParser.java
/** * Reserved for internal use. Reads the properties of an entity from the stream into a map of property names to * typed values. Reads the entity data as an AtomPub Entry Resource from the specified {@link XMLStreamReader} into * a map of <code>String</code> property names to {@link EntityProperty} data typed values. * /*from w ww . j av a 2s. co m*/ * @param xmlr * The <code>XMLStreamReader</code> to read the data from. * @param opContext * An {@link OperationContext} object used to track the execution of the operation. * * @return * A <code>java.util.HashMap</code> containing a map of <code>String</code> property names to * {@link EntityProperty} data typed values found in the entity data. * @throws XMLStreamException * if an error occurs accessing the stream. * @throws ParseException * if an error occurs converting the input to a particular data type. */ private static HashMap<String, EntityProperty> readAtomProperties(final XMLStreamReader xmlr, final OperationContext opContext) throws XMLStreamException, ParseException { int eventType = xmlr.getEventType(); xmlr.require(XMLStreamConstants.START_ELEMENT, null, ODataConstants.PROPERTIES); final HashMap<String, EntityProperty> properties = new HashMap<String, EntityProperty>(); while (xmlr.hasNext()) { eventType = xmlr.next(); if (eventType == XMLStreamConstants.CHARACTERS) { xmlr.getText(); continue; } if (eventType == XMLStreamConstants.START_ELEMENT && xmlr.getNamespaceURI().equals(ODataConstants.DATA_SERVICES_NS)) { final String key = xmlr.getLocalName(); String val = Constants.EMPTY_STRING; String edmType = null; if (xmlr.getAttributeCount() > 0) { edmType = xmlr.getAttributeValue(ODataConstants.DATA_SERVICES_METADATA_NS, ODataConstants.TYPE); } // move to chars eventType = xmlr.next(); if (eventType == XMLStreamConstants.CHARACTERS) { val = xmlr.getText(); // end element eventType = xmlr.next(); } xmlr.require(XMLStreamConstants.END_ELEMENT, null, key); final EntityProperty newProp = new EntityProperty(val, EdmType.parse(edmType)); properties.put(key, newProp); } else if (eventType == XMLStreamConstants.END_ELEMENT && xmlr.getName().toString() .equals(ODataConstants.BRACKETED_DATA_SERVICES_METADATA_NS + ODataConstants.PROPERTIES)) { // End read properties break; } } xmlr.require(XMLStreamConstants.END_ELEMENT, null, ODataConstants.PROPERTIES); return properties; }
From source file:ddf.catalog.source.opensearch.OpenSearchSource.java
private InputTransformer getInputTransformer(InputStream inputStream) { XMLStreamReader xmlStreamReader = null; try {//from w w w . ja v a 2 s . c o m xmlStreamReader = xmlInputFactory.createXMLStreamReader(inputStream); while (xmlStreamReader.hasNext()) { int next = xmlStreamReader.next(); if (next == XMLStreamConstants.START_ELEMENT) { String namespaceUri = xmlStreamReader.getNamespaceURI(); InputTransformer transformerReference = lookupTransformerReference(namespaceUri); if (transformerReference != null) { return transformerReference; } } } } catch (XMLStreamException | InvalidSyntaxException e) { LOGGER.error("Failed to parse transformer namespace", e); } finally { try { if (xmlStreamReader != null) { xmlStreamReader.close(); } } catch (XMLStreamException e) { LOGGER.error("failed to close namespace reader", e); } } return null; }
From source file:ddf.catalog.source.opensearch.impl.OpenSearchSource.java
private InputTransformer getInputTransformer(InputStream inputStream) { XMLStreamReader xmlStreamReader = null; try {//from w w w.ja v a 2 s . c o m xmlStreamReader = xmlInputFactory.createXMLStreamReader(inputStream); while (xmlStreamReader.hasNext()) { int next = xmlStreamReader.next(); if (next == XMLStreamConstants.START_ELEMENT) { String namespaceUri = xmlStreamReader.getNamespaceURI(); InputTransformer transformerReference = lookupTransformerReference(namespaceUri); if (transformerReference != null) { return transformerReference; } } } } catch (XMLStreamException | InvalidSyntaxException e) { LOGGER.debug("Failed to parse transformer namespace", e); } finally { try { if (xmlStreamReader != null) { xmlStreamReader.close(); } } catch (XMLStreamException e) { LOGGER.debug("failed to close namespace reader", e); } } return null; }
From source file:de.uzk.hki.da.model.ObjectPremisXmlWriter.java
/** * Integrate jhove data.//from w w w. j a va 2 s. c o m * * @param jhoveFilePath the jhove file path * @param tab the tab * @throws XMLStreamException the xML stream exception * @author Thomas Kleinke * @throws FileNotFoundException */ private void integrateJhoveData(String jhoveFilePath, int tab) throws XMLStreamException, FileNotFoundException { File jhoveFile = new File(jhoveFilePath); if (!jhoveFile.exists()) throw new FileNotFoundException("file does not exist. " + jhoveFile); FileInputStream inputStream = null; inputStream = new FileInputStream(jhoveFile); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(inputStream); boolean textElement = false; while (streamReader.hasNext()) { int event = streamReader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: writer.writeDTD("\n"); indent(tab); tab++; String prefix = streamReader.getPrefix(); if (prefix != null && !prefix.equals("")) { writer.setPrefix(prefix, streamReader.getNamespaceURI()); writer.writeStartElement(streamReader.getNamespaceURI(), streamReader.getLocalName()); } else writer.writeStartElement(streamReader.getLocalName()); for (int i = 0; i < streamReader.getNamespaceCount(); i++) writer.writeNamespace(streamReader.getNamespacePrefix(i), streamReader.getNamespaceURI(i)); for (int i = 0; i < streamReader.getAttributeCount(); i++) { QName qname = streamReader.getAttributeName(i); String attributeName = qname.getLocalPart(); String attributePrefix = qname.getPrefix(); if (attributePrefix != null && !attributePrefix.equals("")) attributeName = attributePrefix + ":" + attributeName; writer.writeAttribute(attributeName, streamReader.getAttributeValue(i)); } break; case XMLStreamConstants.CHARACTERS: if (!streamReader.isWhiteSpace()) { writer.writeCharacters(streamReader.getText()); textElement = true; } break; case XMLStreamConstants.END_ELEMENT: tab--; if (!textElement) { writer.writeDTD("\n"); indent(tab); } writer.writeEndElement(); textElement = false; break; default: break; } } streamReader.close(); try { inputStream.close(); } catch (IOException e) { throw new RuntimeException("Failed to close input stream", e); } }
From source file:de.uzk.hki.da.cb.CreatePremisAction.java
/** * Accepts a premis.xml file and creates a new xml file for each jhove section * /* w ww . j av a2s. c om*/ * @author Thomas Kleinke * Extract jhove data. * * @param premisFilePath the premis file path * @param outputFolder the output folder * @throws XMLStreamException the xML stream exception */ public void extractJhoveData(String premisFilePath, String outputFolder) throws XMLStreamException { outputFolder += "/premis_output/"; FileInputStream inputStream = null; try { inputStream = new FileInputStream(premisFilePath); } catch (FileNotFoundException e) { throw new RuntimeException("Couldn't find file " + premisFilePath, e); } XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(inputStream); boolean textElement = false; boolean jhoveSection = false; boolean objectIdentifierValue = false; int tab = 0; String fileId = ""; while (streamReader.hasNext()) { int event = streamReader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: if (streamReader.getLocalName().equals("jhove")) { jhoveSection = true; String outputFilePath = outputFolder + fileId.replace('/', '_').replace('.', '_') + ".xml"; if (!new File(outputFolder).exists()) new File(outputFolder).mkdirs(); writer = startNewDocument(outputFilePath); } if (streamReader.getLocalName().equals("objectIdentifierValue")) objectIdentifierValue = true; if (jhoveSection) { writer.writeDTD("\n"); indent(tab); tab++; String prefix = streamReader.getPrefix(); if (prefix != null && !prefix.equals("")) { writer.setPrefix(prefix, streamReader.getNamespaceURI()); writer.writeStartElement(streamReader.getNamespaceURI(), streamReader.getLocalName()); } else writer.writeStartElement(streamReader.getLocalName()); for (int i = 0; i < streamReader.getNamespaceCount(); i++) writer.writeNamespace(streamReader.getNamespacePrefix(i), streamReader.getNamespaceURI(i)); for (int i = 0; i < streamReader.getAttributeCount(); i++) { QName qname = streamReader.getAttributeName(i); String attributeName = qname.getLocalPart(); String attributePrefix = qname.getPrefix(); if (attributePrefix != null && !attributePrefix.equals("")) attributeName = attributePrefix + ":" + attributeName; writer.writeAttribute(attributeName, streamReader.getAttributeValue(i)); } } break; case XMLStreamConstants.CHARACTERS: if (objectIdentifierValue) { fileId = streamReader.getText(); objectIdentifierValue = false; } if (jhoveSection && !streamReader.isWhiteSpace()) { writer.writeCharacters(streamReader.getText()); textElement = true; } break; case XMLStreamConstants.END_ELEMENT: if (jhoveSection) { tab--; if (!textElement) { writer.writeDTD("\n"); indent(tab); } writer.writeEndElement(); textElement = false; if (streamReader.getLocalName().equals("jhove")) { jhoveSection = false; finalizeDocument(); } } break; case XMLStreamConstants.END_DOCUMENT: streamReader.close(); try { inputStream.close(); } catch (IOException e) { throw new RuntimeException("Failed to close input stream", e); } break; default: break; } } }
From source file:org.activiti.bpmn.converter.BaseBpmnXMLConverter.java
@SuppressWarnings("unchecked") protected ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception { ExtensionElement extensionElement = new ExtensionElement(); extensionElement.setName(xtr.getLocalName()); if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) { extensionElement.setNamespace(xtr.getNamespaceURI()); }//from ww w .j a v a2s.c o m if (StringUtils.isNotEmpty(xtr.getPrefix())) { extensionElement.setNamespacePrefix(xtr.getPrefix()); } BpmnXMLUtil.addCustomAttributes(xtr, extensionElement, defaultElementAttributes); boolean readyWithExtensionElement = false; while (readyWithExtensionElement == false && xtr.hasNext()) { xtr.next(); if (xtr.isCharacters()) { if (StringUtils.isNotEmpty(xtr.getText().trim())) { extensionElement.setElementText(xtr.getText().trim()); } } else if (xtr.isStartElement()) { ExtensionElement childExtensionElement = parseExtensionElement(xtr); extensionElement.addChildElement(childExtensionElement); } else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) { readyWithExtensionElement = true; } } return extensionElement; }