List of usage examples for javax.xml.stream XMLStreamReader getLocation
public Location getLocation();
From source file:org.activiti.dmn.converter.util.DmnXMLUtil.java
public static void addXMLLocation(DmnElement element, XMLStreamReader xtr) { Location location = xtr.getLocation(); //element.setXmlRowNumber(location.getLineNumber()); //element.setXmlColumnNumber(location.getColumnNumber()); }
From source file:org.apache.ddlutils.io.DataReader.java
/** * Reads a bean from the given xml stream reader. * /*www . j a v a 2 s . co 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.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 w w. j a v a 2s. co m*/ 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.tajo.catalog.store.XMLCatalogSchemaManager.java
protected StoreObject loadCatalogStore(XMLStreamReader xmlReader) throws XMLStreamException { try {/*www. j ava 2s . c om*/ JAXBElement<StoreObject> elem = unmarshaller.unmarshal(xmlReader, StoreObject.class); return elem.getValue(); } catch (JAXBException e) { throw new XMLStreamException(e.getMessage(), xmlReader.getLocation(), e); } }
From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java
Pair<Graphic, Continuation<Graphic>> parseGraphic(XMLStreamReader in) throws XMLStreamException { in.require(START_ELEMENT, null, "Graphic"); Graphic base = new Graphic(); Continuation<Graphic> contn = null; while (!(in.isEndElement() && in.getLocalName().equals("Graphic"))) { in.nextTag();// w ww . jav a 2s . c o m if (in.getLocalName().equals("Mark")) { final Pair<Mark, Continuation<Mark>> pair = parseMark(in); if (pair != null) { base.mark = pair.first; if (pair.second != null) { contn = new Continuation<Graphic>(contn) { @Override public void updateStep(Graphic base, Feature f, XPathEvaluator<Feature> evaluator) { pair.second.evaluate(base.mark, f, evaluator); } }; } } } else if (in.getLocalName().equals("ExternalGraphic")) { try { final Triple<BufferedImage, String, Continuation<List<BufferedImage>>> p = parseExternalGraphic( in); if (p.third != null) { contn = new Continuation<Graphic>(contn) { @Override public void updateStep(Graphic base, Feature f, XPathEvaluator<Feature> evaluator) { LinkedList<BufferedImage> list = new LinkedList<BufferedImage>(); p.third.evaluate(list, f, evaluator); base.image = list.poll(); } }; } else { base.image = p.first; base.imageURL = p.second; } } catch (IOException e) { LOG.debug("Stack trace", e); LOG.warn("External graphic could not be loaded. Location: line '{}' column '{}' of file '{}'.", new Object[] { in.getLocation().getLineNumber(), in.getLocation().getColumnNumber(), in.getLocation().getSystemId() }); } } else if (in.getLocalName().equals("Opacity")) { contn = context.parser.updateOrContinue(in, "Opacity", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.opacity = Double.parseDouble(val); } }, contn).second; } else if (in.getLocalName().equals("Size")) { contn = context.parser.updateOrContinue(in, "Size", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.size = Double.parseDouble(val); } }, contn).second; } else if (in.getLocalName().equals("Rotation")) { contn = context.parser.updateOrContinue(in, "Rotation", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.rotation = Double.parseDouble(val); } }, contn).second; } else if (in.getLocalName().equals("AnchorPoint")) { while (!(in.isEndElement() && in.getLocalName().equals("AnchorPoint"))) { in.nextTag(); if (in.getLocalName().equals("AnchorPointX")) { contn = context.parser.updateOrContinue(in, "AnchorPointX", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.anchorPointX = Double.parseDouble(val); } }, contn).second; } else if (in.getLocalName().equals("AnchorPointY")) { contn = context.parser.updateOrContinue(in, "AnchorPointY", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.anchorPointY = Double.parseDouble(val); } }, contn).second; } else if (in.isStartElement()) { Location loc = in.getLocation(); LOG.error("Found unknown element '{}' at line {}, column {}, skipping.", new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() }); skipElement(in); } } } else if (in.getLocalName().equals("Displacement")) { while (!(in.isEndElement() && in.getLocalName().equals("Displacement"))) { in.nextTag(); if (in.getLocalName().equals("DisplacementX")) { contn = context.parser.updateOrContinue(in, "DisplacementX", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.displacementX = Double.parseDouble(val); } }, contn).second; } else if (in.getLocalName().equals("DisplacementY")) { contn = context.parser.updateOrContinue(in, "DisplacementY", base, new Updater<Graphic>() { public void update(Graphic obj, String val) { obj.displacementY = Double.parseDouble(val); } }, contn).second; } else if (in.isStartElement()) { Location loc = in.getLocation(); LOG.error("Found unknown element '{}' at line {}, column {}, skipping.", new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() }); skipElement(in); } } } else if (in.isStartElement()) { Location loc = in.getLocation(); LOG.error("Found unknown element '{}' at line {}, column {}, skipping.", new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() }); skipElement(in); } } in.require(END_ELEMENT, null, "Graphic"); return new Pair<Graphic, Continuation<Graphic>>(base, contn); }
From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java
private Pair<Mark, Continuation<Mark>> parseMark(XMLStreamReader in) throws XMLStreamException { in.require(START_ELEMENT, null, "Mark"); Mark base = new Mark(); Continuation<Mark> contn = null; in.nextTag();//from w w w.j av a 2 s. com while (!(in.isEndElement() && in.getLocalName().equals("Mark"))) { if (in.isEndElement()) { in.nextTag(); } if (in.getLocalName().equals("WellKnownName")) { String wkn = in.getElementText(); try { base.wellKnown = SimpleMark.valueOf(wkn.toUpperCase()); } catch (IllegalArgumentException e) { LOG.warn("Specified unsupported WellKnownName of '{}', using square instead.", wkn); base.wellKnown = SimpleMark.SQUARE; } } else sym: if (in.getLocalName().equals("OnlineResource") || in.getLocalName().equals("InlineContent")) { LOG.debug("Loading mark from external file."); Triple<InputStream, String, Continuation<StringBuffer>> pair = getOnlineResourceOrInlineContent( in); if (pair == null) { in.nextTag(); break sym; } InputStream is = pair.first; in.nextTag(); in.require(START_ELEMENT, null, "Format"); String format = in.getElementText(); in.require(END_ELEMENT, null, "Format"); in.nextTag(); if (in.getLocalName().equals("MarkIndex")) { base.markIndex = Integer.parseInt(in.getElementText()); } if (is != null) { try { java.awt.Font font = null; if (format.equalsIgnoreCase("ttf")) { font = createFont(TRUETYPE_FONT, is); } if (format.equalsIgnoreCase("type1")) { font = createFont(TYPE1_FONT, is); } if (format.equalsIgnoreCase("svg")) { base.shape = ShapeHelper.getShapeFromSvg(is, pair.second); } if (font == null && base.shape == null) { LOG.warn("Mark was not loaded, because the format '{}' is not supported.", format); break sym; } if (font != null && base.markIndex >= font.getNumGlyphs() - 1) { LOG.warn("The font only contains {} glyphs, but the index given was {}.", font.getNumGlyphs(), base.markIndex); break sym; } base.font = font; } catch (FontFormatException e) { LOG.debug("Stack trace:", e); LOG.warn("The file was not a valid '{}' file: '{}'", format, e.getLocalizedMessage()); } catch (IOException e) { LOG.debug("Stack trace:", e); LOG.warn("The file could not be read: '{}'.", e.getLocalizedMessage()); } finally { closeQuietly(is); } } } else if (in.getLocalName().equals("Fill")) { final Pair<Fill, Continuation<Fill>> fill = context.fillParser.parseFill(in); base.fill = fill.first; if (fill.second != null) { contn = new Continuation<Mark>(contn) { @Override public void updateStep(Mark base, Feature f, XPathEvaluator<Feature> evaluator) { fill.second.evaluate(base.fill, f, evaluator); } }; } } else if (in.getLocalName().equals("Stroke")) { final Pair<Stroke, Continuation<Stroke>> stroke = context.strokeParser.parseStroke(in); base.stroke = stroke.first; if (stroke.second != null) { contn = new Continuation<Mark>(contn) { @Override public void updateStep(Mark base, Feature f, XPathEvaluator<Feature> evaluator) { stroke.second.evaluate(base.stroke, f, evaluator); } }; } } else if (in.isStartElement()) { Location loc = in.getLocation(); LOG.error("Found unknown element '{}' at line {}, column {}, skipping.", new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() }); skipElement(in); } } in.require(END_ELEMENT, null, "Mark"); return new Pair<Mark, Continuation<Mark>>(base, contn); }
From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java
private Triple<BufferedImage, String, Continuation<List<BufferedImage>>> parseExternalGraphic( final XMLStreamReader in) throws IOException, XMLStreamException { // TODO color replacement in.require(START_ELEMENT, null, "ExternalGraphic"); String format = null;/*w ww . j a va 2s. c o m*/ BufferedImage img = null; String url = null; Triple<InputStream, String, Continuation<StringBuffer>> pair = null; Continuation<List<BufferedImage>> contn = null; // needs to be list to be updateable by reference... while (!(in.isEndElement() && in.getLocalName().equals("ExternalGraphic"))) { in.nextTag(); if (in.getLocalName().equals("Format")) { format = in.getElementText(); } else if (in.getLocalName().equals("OnlineResource") || in.getLocalName().equals("InlineContent")) { pair = getOnlineResourceOrInlineContent(in); } else if (in.isStartElement()) { Location loc = in.getLocation(); LOG.error("Found unknown element '{}' at line {}, column {}, skipping.", new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() }); skipElement(in); } } try { if (pair != null) { if (pair.first != null && format != null && (format.toLowerCase().indexOf("svg") == -1)) { img = ImageIO.read(pair.first); } url = pair.second; final Continuation<StringBuffer> sbcontn = pair.third; if (pair.third != null) { final LinkedHashMap<String, BufferedImage> cache = new LinkedHashMap<String, BufferedImage>( 256) { private static final long serialVersionUID = -6847956873232942891L; @Override protected boolean removeEldestEntry(Map.Entry<String, BufferedImage> eldest) { return size() > 256; // yeah, hardcoded max size... TODO } }; contn = new Continuation<List<BufferedImage>>() { @Override public void updateStep(List<BufferedImage> base, Feature f, XPathEvaluator<Feature> evaluator) { StringBuffer sb = new StringBuffer(); sbcontn.evaluate(sb, f, evaluator); String file = sb.toString(); if (cache.containsKey(file)) { base.add(cache.get(file)); return; } try { BufferedImage i; if (context.location != null) { i = ImageIO.read(context.location.resolve(file)); } else { i = ImageIO.read(resolve(file, in)); } base.add(i); cache.put(file, i); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; } } } finally { if (pair != null) { try { pair.first.close(); } catch (Exception e) { LOG.trace("Stack trace when closing input stream:", e); } } } return new Triple<BufferedImage, String, Continuation<List<BufferedImage>>>(img, url, contn); }
From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java
private Triple<InputStream, String, Continuation<StringBuffer>> getOnlineResourceOrInlineContent( XMLStreamReader in) throws XMLStreamException { if (in.getLocalName().equals("OnlineResource")) { String str = in.getAttributeValue(XLNNS, "href"); if (str == null) { Continuation<StringBuffer> contn = context.parser.updateOrContinue(in, "OnlineResource", new StringBuffer(), SBUPDATER, null).second; return new Triple<InputStream, String, Continuation<StringBuffer>>(null, null, contn); }//from w w w .ja va2 s .co m String strUrl = null; try { URL url; if (context.location != null) { url = context.location.resolveToUrl(str); } else { url = resolve(str, in); } strUrl = url.toExternalForm(); LOG.debug("Loading from URL '{}'", url); in.nextTag(); return new Triple<InputStream, String, Continuation<StringBuffer>>(url.openStream(), strUrl, null); } catch (IOException e) { LOG.debug("Stack trace:", e); LOG.warn("Could not retrieve content at URL '{}'.", str); return null; } } else if (in.getLocalName().equals("InlineContent")) { String format = in.getAttributeValue(null, "encoding"); if (format.equalsIgnoreCase("base64")) { ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decodeBase64(in.getElementText())); return new Triple<InputStream, String, Continuation<StringBuffer>>(bis, null, null); } // if ( format.equalsIgnoreCase( "xml" ) ) { // // TODO // } } else if (in.isStartElement()) { Location loc = in.getLocation(); LOG.error("Found unknown element '{}' at line {}, column {}, skipping.", new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() }); skipElement(in); } return null; }
From source file:org.flowable.cmmn.converter.ExtensionElementsXMLConverter.java
protected void readCommonXmlInfo(BaseElement baseElement, XMLStreamReader xtr) { baseElement.setId(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_ID)); Location location = xtr.getLocation(); baseElement.setXmlRowNumber(location.getLineNumber()); baseElement.setXmlRowNumber(location.getColumnNumber()); }
From source file:org.flowable.cmmn.converter.util.CmmnXmlUtil.java
public static void addXMLLocation(BaseElement element, XMLStreamReader xtr) { Location location = xtr.getLocation(); element.setXmlRowNumber(location.getLineNumber()); element.setXmlColumnNumber(location.getColumnNumber()); }