List of usage examples for javax.xml.stream XMLStreamReader getName
public QName getName();
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads unique index column elements from the XML stream reader and adds them to the given * index object./*from w w w. j av a2 s. co m*/ * * @param xmlReader The reader * @param index The index object */ private void readUniqueColumnElements(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_UNIQUE_COLUMN)) { index.addColumn(readIndexColumnElement(xmlReader)); } else { readOverElement(xmlReader); } } } }
From source file:org.apache.ddlutils.io.DataReader.java
/** * Reads a bean from the given xml stream reader. * /*from ww w. java2 s.c o m*/ * @param xmlReader The reader */ private void readBean(XMLStreamReader xmlReader) throws XMLStreamException, DdlUtilsXMLException { QName elemQName = xmlReader.getName(); Location location = xmlReader.getLocation(); Map attributes = new HashMap(); String tableName = null; for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++) { QName attrQName = xmlReader.getAttributeName(idx); attributes.put(isCaseSensitive() ? attrQName.getLocalPart() : attrQName.getLocalPart().toLowerCase(), xmlReader.getAttributeValue(idx)); } readColumnSubElements(xmlReader, attributes); if ("table".equals(elemQName.getLocalPart())) { tableName = (String) attributes.get("table-name"); } else { tableName = elemQName.getLocalPart(); } Table table = _model.findTable(tableName, isCaseSensitive()); if (table == null) { _log.warn("Data XML contains an element " + elemQName + " at location " + location + " but there is no table defined with this name. This element will be ignored."); } else { DynaBean bean = _model.createDynaBeanFor(table); for (int idx = 0; idx < table.getColumnCount(); idx++) { Column column = table.getColumn(idx); String value = (String) attributes .get(isCaseSensitive() ? column.getName() : column.getName().toLowerCase()); if (value != null) { setColumnValue(bean, table, column, value); } } getSink().addBean(bean); consumeRestOfElement(xmlReader); } }
From source file:org.apache.ddlutils.io.DataReader.java
/** * Reads the next column sub element that matches a column specified by the given table object from the xml reader into the given bean. * /*from w ww. j av a 2s . c o m*/ * @param xmlReader The reader * @param data Where to store the values */ private void readColumnSubElement(XMLStreamReader xmlReader, Map data) throws XMLStreamException, DdlUtilsXMLException { QName elemQName = xmlReader.getName(); Map attributes = new HashMap(); boolean usesBase64 = false; for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++) { QName attrQName = xmlReader.getAttributeName(idx); String value = xmlReader.getAttributeValue(idx); if (DatabaseIO.BASE64_ATTR_NAME.equals(attrQName.getLocalPart())) { if ("true".equalsIgnoreCase(value)) { usesBase64 = true; } } else { attributes.put(attrQName.getLocalPart(), value); } } int eventType = XMLStreamReader.START_ELEMENT; StringBuffer content = new StringBuffer(); while (eventType != XMLStreamReader.END_ELEMENT) { eventType = xmlReader.next(); if (eventType == XMLStreamReader.START_ELEMENT) { readColumnDataSubElement(xmlReader, attributes); } else if ((eventType == XMLStreamReader.CHARACTERS) || (eventType == XMLStreamReader.CDATA) || (eventType == XMLStreamReader.SPACE) || (eventType == XMLStreamReader.ENTITY_REFERENCE)) { content.append(xmlReader.getText()); } } String value = content.toString().trim(); if (usesBase64) { value = new String(Base64.decodeBase64(value.getBytes())); } String name = elemQName.getLocalPart(); if ("table-name".equals(name)) { data.put("table-name", value); } else { if ("column".equals(name)) { name = (String) attributes.get("column-name"); } if (attributes.containsKey("column-value")) { value = (String) attributes.get("column-value"); } data.put(name, value); } consumeRestOfElement(xmlReader); }
From source file:org.apache.ddlutils.io.DataReader.java
/** * Reads the next column-name or column-value sub element. * /*from w w w . j a va 2 s. co m*/ * @param xmlReader The reader * @param data Where to store the values */ private void readColumnDataSubElement(XMLStreamReader xmlReader, Map data) throws XMLStreamException, DdlUtilsXMLException { QName elemQName = xmlReader.getName(); boolean usesBase64 = false; for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++) { QName attrQName = xmlReader.getAttributeName(idx); String value = xmlReader.getAttributeValue(idx); if (DatabaseIO.BASE64_ATTR_NAME.equals(attrQName.getLocalPart())) { if ("true".equalsIgnoreCase(value)) { usesBase64 = true; } break; } } String value = xmlReader.getElementText(); if (value != null) { value = value.toString().trim(); if (usesBase64) { value = new String(Base64.decodeBase64(value.getBytes())); } } String name = elemQName.getLocalPart(); if ("column-name".equals(name)) { data.put("column-name", value); } else if ("column-value".equals(name)) { data.put("column-value", value); } consumeRestOfElement(xmlReader); }
From source file:org.apache.ddlutils.io.DataReaderKeys.java
private Identity readBean(XMLStreamReader xmlReader) throws XMLStreamException, DdlUtilsXMLException { QName elemQName = xmlReader.getName(); Table table = _model.findTable(elemQName.getLocalPart(), isCaseSensitive()); if (table == null) { readOverElement(xmlReader);/*from ww w . j a v a 2 s . co m*/ return null; } DynaBean bean = _model.createDynaBeanFor(table); for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++) { QName attrQName = xmlReader.getAttributeName(idx); Column column = table.findColumn(attrQName.getLocalPart(), isCaseSensitive()); if (column != null) { setColumnValue(bean, table, column, xmlReader.getAttributeValue(idx)); } } readColumnSubElements(xmlReader, bean, table); //getSink().addBean(bean); //--get keys here Identity id = buildIdentityFromPKs(table, bean); //Hashmap keyval = new Hashmap(); //keyval.put(id.,id); consumeRestOfElement(xmlReader); return id; }
From source file:org.apache.ddlutils.io.DataReaderKeys.java
private void readColumnSubElement(XMLStreamReader xmlReader, DynaBean bean, Table table) throws XMLStreamException, DdlUtilsXMLException { QName elemQName = xmlReader.getName(); boolean usesBase64 = false; for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++) { QName attrQName = xmlReader.getAttributeName(idx); if (DatabaseIO.BASE64_ATTR_NAME.equals(attrQName.getLocalPart()) && "true".equalsIgnoreCase(xmlReader.getAttributeValue(idx))) { usesBase64 = true;//from w ww. j a v a 2 s .com break; } } Column column = table.findColumn(elemQName.getLocalPart(), isCaseSensitive()); if (column == null) { _log.warn("Data XML contains an element " + elemQName + " at location " + xmlReader.getLocation() + " but there is no column defined in table " + table.getName() + " with this name. This element will be ignored."); } else { String value = xmlReader.getElementText(); if (value != null) { value = value.trim(); if (usesBase64) { value = new String(Base64.decodeBase64(value.getBytes())); } setColumnValue(bean, table, column, value); } } consumeRestOfElement(xmlReader); }
From source file:org.apache.xml.security.stax.impl.processor.input.AbstractDecryptInputProcessor.java
private void forwardToWrapperElement(XMLStreamReader xmlStreamReader) throws XMLStreamException { do {/*from w ww . j ava2 s. c o m*/ if (xmlStreamReader.getEventType() == XMLStreamConstants.START_ELEMENT && xmlStreamReader.getName().equals(wrapperElementName)) { xmlStreamReader.next(); break; } xmlStreamReader.next(); } while (xmlStreamReader.hasNext()); }
From source file:org.auraframework.impl.factory.SVGParser.java
@Override public SVGDef getDefinition(DefDescriptor<SVGDef> descriptor, TextSource<SVGDef> source) throws SVGParserException, QuickFixException { if (descriptor.getDefType() == DefType.SVG) { XMLStreamReader reader = null; String contents = source.getContents(); //If the file is too big throw before we parse the whole thing. SVGDef ret = new SVGDefHandler<>(descriptor, source).createDefinition(); try (StringReader stringReader = new StringReader(contents)) { reader = xmlInputFactory.createXMLStreamReader(stringReader); if (reader != null) { LOOP: while (reader.hasNext()) { int type = reader.next(); switch (type) { case XMLStreamConstants.END_DOCUMENT: break LOOP; //This is plain text inside the file case XMLStreamConstants.CHARACTERS: if (DISSALOWED_LIST.matcher(reader.getText()).matches()) { throw new InvalidDefinitionException( String.format("Text contains disallowed symbols: %s", reader.getText()), XMLParser.getLocation(reader, source)); }/*w w w .j a va 2 s .c o m*/ break; case XMLStreamConstants.START_ELEMENT: String name = reader.getName().toString().toLowerCase(); if (!SVG_TAG_WHITELIST.contains(name)) { throw new InvalidDefinitionException( String.format("Invalid SVG tag specified: %s", name), XMLParser.getLocation(reader, source)); } for (int i = 0; i < reader.getAttributeCount(); i++) { QName qAttr = reader.getAttributeName(i); String attr = qAttr.getLocalPart(); if (SVG_ATTR_BLACKLIST.contains(attr)) { throw new InvalidDefinitionException( String.format("Invalid SVG attribute specified: %s", attr), XMLParser.getLocation(reader, source)); } } break; case XMLStreamConstants.END_ELEMENT: case XMLStreamConstants.COMMENT: case XMLStreamConstants.DTD: case XMLStreamConstants.SPACE: continue; default: throw new InvalidDefinitionException(String.format("Found unexpected element in xml."), XMLParser.getLocation(reader, source)); } } } } catch (XMLStreamException e) { throw new SVGParserException(StringEscapeUtils.escapeHtml4(e.getMessage())); } finally { if (reader != null) { try { reader.close(); } catch (XMLStreamException e) { //Well I tried to play nicely } } } return ret; } return null; }
From source file:org.auraframework.impl.svg.parser.SVGParser.java
@Override public SVGDef parse(DefDescriptor<SVGDef> descriptor, Source<SVGDef> source) throws SVGParserException, QuickFixException { if (descriptor.getDefType() == DefType.SVG) { XMLStreamReader reader = null; String contents = source.getContents(); //If the file is too big throw before we parse the whole thing. SVGDef ret = new SVGDefHandler<>(descriptor, source).createDefinition(); try (StringReader stringReader = new StringReader(contents)) { reader = xmlInputFactory.createXMLStreamReader(stringReader); if (reader != null) { LOOP: while (reader.hasNext()) { int type = reader.next(); switch (type) { case XMLStreamConstants.END_DOCUMENT: break LOOP; //This is plain text inside the file case XMLStreamConstants.CHARACTERS: if (DISSALOWED_LIST.matcher(reader.getText()).matches()) { throw new InvalidDefinitionException( String.format("Text contains disallowed symbols: %s", reader.getText()), XMLParser.getLocation(reader, source)); }/* w ww. jav a 2s .c o m*/ break; case XMLStreamConstants.START_ELEMENT: String name = reader.getName().toString().toLowerCase(); if (!SVG_TAG_WHITELIST.contains(name)) { throw new InvalidDefinitionException( String.format("Invalid SVG tag specified: %s", name), XMLParser.getLocation(reader, source)); } for (int i = 0; i < reader.getAttributeCount(); i++) { QName qAttr = reader.getAttributeName(i); String attr = qAttr.getLocalPart(); if (SVG_ATTR_BLACKLIST.contains(attr)) { throw new InvalidDefinitionException( String.format("Invalid SVG attribute specified: %s", attr), XMLParser.getLocation(reader, source)); } } break; case XMLStreamConstants.END_ELEMENT: case XMLStreamConstants.COMMENT: case XMLStreamConstants.DTD: case XMLStreamConstants.SPACE: continue; default: throw new InvalidDefinitionException(String.format("Found unexpected element in xml."), XMLParser.getLocation(reader, source)); } } } } catch (XMLStreamException e) { throw new SVGParserException(StringEscapeUtils.escapeHtml4(e.getMessage())); } finally { if (reader != null) { try { reader.close(); } catch (XMLStreamException e) { //Well I tried to play nicely } } } return ret; } return null; }
From source file:org.deegree.gml.geometry.GML3GeometryWriterTest.java
private Geometry readAIXMGeometry(String fileName) throws ClassCastException, ClassNotFoundException, InstantiationException, IllegalAccessException, XMLStreamException, FactoryConfigurationError, IOException, XMLParsingException, UnknownCRSException { String schemaUrl = this.getClass().getResource("../aixm/schema/message/AIXM_BasicMessage.xsd").toString(); GMLAppSchemaReader adapter = new GMLAppSchemaReader(null, null, schemaUrl); AppSchema schema = adapter.extractAppSchema(); GMLStreamReader gmlStream = createGMLStreamReader(GML_32, this.getClass().getResource("../aixm/geometry/" + fileName)); gmlStream.setApplicationSchema(schema); XMLStreamReader xmlReader = gmlStream.getXMLReader(); Assert.assertEquals(START_ELEMENT, xmlReader.getEventType()); QName elName = xmlReader.getName(); Assert.assertTrue(gmlStream.isGeometryElement()); Geometry geom = gmlStream.readGeometry(); Assert.assertEquals(END_ELEMENT, xmlReader.getEventType()); Assert.assertEquals(elName, xmlReader.getName()); return geom;//ww w.j av a2 s .c o m }