List of usage examples for javax.xml.stream XMLStreamReader getName
public QName getName();
From source file:net.xy.jcms.controller.configurations.parser.TranslationParser.java
/** * parses an single file translation/* w w w. java 2 s. co m*/ * * @param in * @param loader * @return value * @throws XMLStreamException * @throws ClassNotFoundException * in case there are problems with an params type converter */ public static TranslationRule parseSingle(final InputStream in, final ClassLoader loader) throws XMLStreamException, ClassNotFoundException { @SuppressWarnings("deprecation") final XMLInputFactory factory = XMLInputFactory.newInstance( "com.sun.xml.internal.stream.XMLInputFactoryImpl", TranslationParser.class.getClassLoader()); LOG.info("XMLInputFactory loaded: " + factory.getClass().getName()); factory.setProperty("javax.xml.stream.isCoalescing", true); final XMLStreamReader parser = factory.createXMLStreamReader(in); while (parser.hasNext()) { final int event = parser.next(); if (event == XMLStreamConstants.START_ELEMENT && parser.getName().getLocalPart().equals("rule")) { return parseRule(parser, loader); } } throw new IllegalArgumentException("No rules section found."); }
From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java
/** * parses usecases out from an xml file//from w w w .j a v a2 s . c o m * * @param in * @param loader * used for retrieving configuration included resources and also * for retrieving the controllers * @return value * @throws XMLStreamException * @throws ClassNotFoundException */ public static Usecase[] parse(final InputStream in, final ClassLoader loader) throws XMLStreamException, ClassNotFoundException { final XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty("javax.xml.stream.isCoalescing", true); // not supported by the reference implementation // factory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.TRUE); final XMLStreamReader parser = factory.createXMLStreamReader(in); while (parser.hasNext()) { final int event = parser.next(); if (event == XMLStreamConstants.START_ELEMENT && parser.getName().getLocalPart().equals("usecases")) { return parseUsecases(parser, loader); } } throw new IllegalArgumentException("No usecases section found. [" + parser.getLocation() + "]"); }
From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java
/** * method for parsing single usecase xml files. one per file. * // w ww .j a v a 2 s. c o m * @param in * @param loader * @return parsed usecase * @throws XMLStreamException * @throws ClassNotFoundException */ public static Usecase parseSingle(final InputStream in, final ClassLoader loader) throws XMLStreamException, ClassNotFoundException { final XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty("javax.xml.stream.isCoalescing", true); // not supported by the reference implementation // factory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.TRUE); final XMLStreamReader parser = factory.createXMLStreamReader(in); while (parser.hasNext()) { final int event = parser.next(); if (event == XMLStreamConstants.START_ELEMENT && parser.getName().getLocalPart().equals("usecase")) { return parseUsecase(parser, loader); } } throw new IllegalArgumentException("No usecases section found. [" + parser.getLocation() + "]"); }
From source file:nl.knaw.huygens.tei.xpath.XPathUtil.java
public static Map<String, String> getNamespaceInfo(String xml) { Map<String, String> namespaces = Maps.newIdentityHashMap(); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); try {/*from ww w .j a v a2 s. co m*/ XMLStreamReader xreader = inputFactory.createXMLStreamReader(IOUtils.toInputStream(xml, "UTF-8")); while (xreader.hasNext()) { if (xreader.next() == XMLStreamConstants.START_ELEMENT) { QName qName = xreader.getName(); if (qName != null) { addNamespace(namespaces, qName.getPrefix(), qName.getNamespaceURI()); for (int i = 0; i < xreader.getAttributeCount(); i++) { addNamespace(namespaces, xreader.getAttributePrefix(i), xreader.getAttributeNamespace(i)); } } } } } catch (XMLStreamException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return namespaces; }
From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java
/** * Create SOAPElement from the current tag data * * @param nc NameCreator//from w w w .ja v a 2 s. co m * @param parent SOAPElement for the new SOAPElement * @param reader XMLStreamReader whose cursor is at the START_ELEMENT * @return */ protected SOAPElement createElementFromTag(NameCreator nc, SOAPElement parent, XMLStreamReader reader) throws SOAPException { // Unfortunately, the SAAJ object is a product of both the // QName of the element and the parent object. For example, // All element children of a SOAPBody must be object's that are SOAPBodyElements. // createElement creates the proper child element. QName qName = reader.getName(); SOAPElement child = createElement(parent, qName); // Update the tag data on the child updateTagData(nc, child, reader, true); return child; }
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads the database model from the given XML stream reader. * //from w w w . ja va 2 s.co m * @param xmlReader The reader * @return The database model */ private Database read(XMLStreamReader xmlReader) throws DdlUtilsXMLException { Database model = null; try { while (xmlReader.getEventType() != XMLStreamReader.START_ELEMENT) { if (xmlReader.next() == XMLStreamReader.END_DOCUMENT) { return null; } } if (isSameAs(xmlReader.getName(), QNAME_ELEMENT_DATABASE)) { model = readDatabaseElement(xmlReader); } } catch (IOException ex) { throw new DdlUtilsXMLException(ex); } catch (XMLStreamException ex) { throw new DdlUtilsXMLException(ex); } if (model != null) { model.initialize(); } return model; }
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads table elements from the XML stream reader and adds them to the given * database model./*from w ww .j ava 2s . c om*/ * * @param xmlReader The reader * @param model The database model to add the table objects to */ private void readTableElements(XMLStreamReader xmlReader, Database model) throws XMLStreamException, IOException { int eventType = XMLStreamReader.START_ELEMENT; while (eventType != XMLStreamReader.END_ELEMENT) { eventType = xmlReader.next(); if (eventType == XMLStreamReader.START_ELEMENT) { if (isSameAs(xmlReader.getName(), QNAME_ELEMENT_TABLE)) { model.addTable(readTableElement(xmlReader)); } else { readOverElement(xmlReader); } } } }
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads table sub elements (column, foreign key, index) from the XML stream reader and adds * them to the given table./*from w ww . j a v a 2 s.c om*/ * * @param xmlReader The reader * @param table The table */ private void readTableSubElements(XMLStreamReader xmlReader, Table table) throws XMLStreamException, IOException { int eventType = XMLStreamReader.START_ELEMENT; while (eventType != XMLStreamReader.END_ELEMENT) { eventType = xmlReader.next(); if (eventType == XMLStreamReader.START_ELEMENT) { QName elemQName = xmlReader.getName(); if (isSameAs(elemQName, QNAME_ELEMENT_COLUMN)) { table.addColumn(readColumnElement(xmlReader)); } else if (isSameAs(elemQName, QNAME_ELEMENT_FOREIGN_KEY)) { table.addForeignKey(readForeignKeyElement(xmlReader)); } else if (isSameAs(elemQName, QNAME_ELEMENT_INDEX)) { table.addIndex(readIndexElement(xmlReader)); } else if (isSameAs(elemQName, QNAME_ELEMENT_UNIQUE)) { table.addIndex(readUniqueElement(xmlReader)); } else { readOverElement(xmlReader); } } } }
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads reference elements from the XML stream reader and adds them to the given * foreign key./*from ww w . j av a 2 s .co m*/ * * @param xmlReader The reader * @param foreignKey The foreign key */ private void readReferenceElements(XMLStreamReader xmlReader, ForeignKey foreignKey) throws XMLStreamException, IOException { int eventType = XMLStreamReader.START_ELEMENT; while (eventType != XMLStreamReader.END_ELEMENT) { eventType = xmlReader.next(); if (eventType == XMLStreamReader.START_ELEMENT) { QName elemQName = xmlReader.getName(); if (isSameAs(elemQName, QNAME_ELEMENT_REFERENCE)) { foreignKey.addReference(readReferenceElement(xmlReader)); } else { readOverElement(xmlReader); } } } }
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads index column elements from the XML stream reader and adds them to the given * index object./* w ww. j a v a 2 s .c om*/ * * @param xmlReader The reader * @param index The index object */ private void readIndexColumnElements(XMLStreamReader xmlReader, Index index) throws XMLStreamException, IOException { int eventType = XMLStreamReader.START_ELEMENT; while (eventType != XMLStreamReader.END_ELEMENT) { eventType = xmlReader.next(); if (eventType == XMLStreamReader.START_ELEMENT) { QName elemQName = xmlReader.getName(); if (isSameAs(elemQName, QNAME_ELEMENT_INDEX_COLUMN)) { index.addColumn(readIndexColumnElement(xmlReader)); } else { readOverElement(xmlReader); } } } }