List of usage examples for javax.xml.stream Location getLineNumber
int getLineNumber();
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()); }
From source file:org.flowable.cmmn.converter.util.CmmnXmlUtil.java
public static void addXMLLocation(GraphicInfo graphicInfo, XMLStreamReader xtr) { Location location = xtr.getLocation(); graphicInfo.setXmlRowNumber(location.getLineNumber()); graphicInfo.setXmlColumnNumber(location.getColumnNumber()); }
From source file:org.modeldriven.fuml.assembly.ElementAssembler.java
public void assemleFeatures() { try {/* ww w . j a v a 2s . c om*/ NamespaceDomain domain = null; // only lookup as needed StreamNode eventNode = (StreamNode) source; Location loc = eventNode.getLocation(); if (log.isDebugEnabled()) log.debug("element line/column: " + loc.getLineNumber() + ":" + loc.getColumnNumber()); // look at XML attributes Iterator<Attribute> attributes = eventNode.getAttributes(); while (attributes != null && attributes.hasNext()) { Attribute xmlAttrib = attributes.next(); QName name = xmlAttrib.getName(); String prefix = name.getPrefix(); if (prefix != null && prefix.length() > 0) continue; // not applicable to current // element/association-end. if ("href".equals(name.getLocalPart())) continue; // FIXME: find/write URI resolver Property property = this.prototype.findProperty(name.getLocalPart()); if (property == null) { if (domain == null) domain = FumlConfiguration.getInstance().findNamespaceDomain(source.getNamespaceURI()); ValidationExemption exemption = FumlConfiguration.getInstance() .findValidationExemptionByProperty(ValidationExemptionType.UNDEFINED_PROPERTY, this.prototype, name.getLocalPart(), source.getNamespaceURI(), domain); if (exemption == null) { throw new ValidationException(new ValidationError(eventNode, name.getLocalPart(), ErrorCode.UNDEFINED_PROPERTY, ErrorSeverity.FATAL)); } else { if (log.isDebugEnabled()) log.debug("undefined property exemption found within domain '" + exemption.getDomain().toString() + "' for property '" + this.prototype.getName() + "." + name.getLocalPart() + "' - ignoring error"); continue; // ignore attrib } } Classifier type = property.getType(); if (this.modelSupport.isReferenceAttribute(property)) { XmiReferenceAttribute reference = new XmiReferenceAttribute(source, xmlAttrib, this.getPrototype()); this.addReference(reference); continue; } String value = xmlAttrib.getValue(); if (value == null || value.length() == 0) { String defaultValue = property.findPropertyDefault(); if (defaultValue != null) { value = defaultValue; if (log.isDebugEnabled()) log.debug("using default '" + String.valueOf(value) + "' for enumeration feature <" + type.getName() + "> " + this.getPrototype().getName() + "." + property.getName()); } } this.assembleNonReferenceFeature(property, value, type); } // look at model properties not found in above attribute set List<Property> properties = this.prototype.getNamedProperties(); for (Property property : properties) { QName name = new QName(property.getName()); String value = eventNode.getAttributeValue(name); if (value != null && value.trim().length() > 0) continue; // handled above String defaultValue = property.findPropertyDefault(); if (defaultValue != null) { Classifier type = property.getType(); if (log.isDebugEnabled()) log.debug("using default: '" + String.valueOf(defaultValue) + "' for enumeration feature <" + type.getName() + "> " + this.getPrototype().getName() + "." + property.getName()); this.assembleNonReferenceFeature(property, defaultValue, type); continue; } if (!property.isRequired()) continue; // don't bother digging further for a value if (eventNode.findChildByName(property.getName()) != null) continue; // it has such a child, let if (this.modelSupport.isReferenceAttribute(property) && FumlConfiguration.getInstance().hasReferenceMapping(this.prototype, property)) { ReferenceMappingType mappingType = FumlConfiguration.getInstance() .getReferenceMappingType(this.prototype, property); if (mappingType == ReferenceMappingType.PARENT) { if (parent != null && parent.getXmiId() != null && parent.getXmiId().length() > 0) { XmiMappedReference reference = new XmiMappedReference(source, property.getName(), new String[] { parent.getXmiId() }, this.prototype); this.addReference(reference); continue; } else log.warn("no parent XMI id found, ignoring mapping for, " + this.prototype.getName() + "." + property.getName()); } else log.warn("unrecognized mapping type, " + mappingType.value() + " ignoring mapping for, " + this.prototype.getName() + "." + property.getName()); } if (!property.isDerived()) { if (domain == null) domain = FumlConfiguration.getInstance().findNamespaceDomain(source.getNamespaceURI()); ValidationExemption exemption = FumlConfiguration.getInstance() .findValidationExemptionByProperty(ValidationExemptionType.REQUIRED_PROPERTY, this.prototype, name.getLocalPart(), source.getNamespaceURI(), domain); if (exemption == null) { if (log.isDebugEnabled()) log.debug("throwing " + ErrorCode.PROPERTY_REQUIRED.toString() + " error for " + this.prototype.getName() + "." + property.getName()); throw new ValidationException(new ValidationError(eventNode, property.getName(), ErrorCode.PROPERTY_REQUIRED, ErrorSeverity.FATAL)); } else { if (log.isDebugEnabled()) log.debug("required property exemption found within domain '" + exemption.getDomain().toString() + "' for property '" + this.prototype.getName() + "." + name.getLocalPart() + "' - ignoring error"); continue; // ignore property } } } } catch (ClassNotFoundException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (NoSuchMethodException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InvocationTargetException e) { log.error(e.getCause().getMessage(), e.getCause()); throw new AssemblyException(e.getCause()); } catch (IllegalAccessException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InstantiationException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (NoSuchFieldException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } }
From source file:org.modeldriven.fuml.xmi.stream.StreamReader.java
@SuppressWarnings("unchecked") public Collection read(InputStream stream) { List<Object> results = new ArrayList<Object>(); InputStream source = stream;/*w w w .j a v a 2s . com*/ StreamContext context = null; try { XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setXMLResolver(new XMLResolver() { @Override public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) throws XMLStreamException { // TODO Auto-generated method stub return null; } }); /* XStream xstream = new XStream(new StaxDriver() { protected XMLStreamReader createParser(Reader xml) throws XMLStreamException { return getInputFactory().createXMLStreamReader(xml); } protected XMLStreamReader createParser(InputStream xml) throws XMLStreamException { return getInputFactory().createXMLStreamReader(xml); } }); */ //factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES,Boolean.FALSE); //factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,Boolean.TRUE); //set the IS_COALESCING property to true , if application desires to //get whole text data as one event. //factory.setProperty(XMLInputFactory.IS_COALESCING , Boolean.TRUE); factory.setEventAllocator(new EventAllocator()); allocator = factory.getEventAllocator(); XMLStreamReader streamReader = factory.createXMLStreamReader(stream); int eventType = streamReader.getEventType(); StreamNode node = null; StreamNode parent = null; int level = 0; int ignoredNodeLevel = -1; while (streamReader.hasNext()) { eventType = streamReader.next(); //if (log.isDebugEnabled()) // log.debug(this.getEventTypeString(eventType)); switch (eventType) { case XMLEvent.START_ELEMENT: level++; if (ignoredNodeLevel >= 0) break; XMLEvent event = allocateXMLEvent(streamReader); if (level == 1) { if (context != null) throw new XmiException("existing context unexpected"); context = new StreamContext(event); } // debugging if (event.toString().contains("plasma:PlasmaType")) { int foo = 1; foo++; } node = new StreamNode(event, context); if (node.isIgnored()) { if (log.isDebugEnabled()) { Location loc = event.getLocation(); String msg = "start ignoring elements - level: " + String.valueOf(level) + " - line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "] - "; log.debug(msg); } ignoredNodeLevel = level; break; } logEventInfo(event); parent = null; if (nodes.size() > 0) { parent = nodes.peek(); parent.add(node); node.setParent(parent); if (isRootNode(node, context)) results.add(node); } else { if (isRootNode(node, context)) results.add(node); } nodes.push(node); fireStreamNodeCreated(node, parent); break; case XMLEvent.END_ELEMENT: if (ignoredNodeLevel >= 0) { if (ignoredNodeLevel == level) { if (log.isDebugEnabled()) { event = allocateXMLEvent(streamReader); Location loc = event.getLocation(); String msg = "end ignoring elements - level: " + String.valueOf(level) + " - line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "] - "; log.debug(msg); } ignoredNodeLevel = -1; } level--; break; } level--; node = nodes.pop(); parent = null; if (nodes.size() > 0) parent = nodes.peek(); fireStreamNodeCompleted(node, parent); break; case XMLEvent.CHARACTERS: if (ignoredNodeLevel >= 0) break; node = nodes.peek(); event = allocateXMLEvent(streamReader); String data = event.asCharacters().getData(); if (data != null) { data = data.trim(); if (data.length() > 0) { if (log.isDebugEnabled()) log.debug("CHARACTERS: '" + data + "'"); if (data.length() > 0) { node = nodes.peek(); node.addCharactersEvent(event); } } } break; default: if (log.isDebugEnabled()) { event = allocateXMLEvent(streamReader); logEventInfo(event); } break; } } if (results.size() > 1) throw new XmiException("found multiple root nodes (" + results.size() + ")"); } catch (XMLStreamException e) { throw new XmiException(e); } finally { try { source.close(); } catch (IOException e) { } } return results; }
From source file:org.modeldriven.fuml.xmi.stream.StreamReader.java
private void logEventInfo(XMLEvent event) { if (log.isDebugEnabled()) { Location loc = event.getLocation(); String msg = getEventTypeString(event.getEventType()); msg += " line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "] - "; msg += event.toString();/*from w w w. j a v a 2s.co m*/ log.debug(msg); } }
From source file:org.omegat.util.TMXReader2.java
public TMXReader2() { factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false); factory.setXMLReporter(new XMLReporter() { public void report(String message, String error_type, Object info, Location location) throws XMLStreamException { Log.logWarningRB("TMXR_WARNING_WHILE_PARSING", location.getLineNumber(), location.getColumnNumber()); Log.log(message + ": " + info); warningsCount++;/*from w w w . ja va 2s . co m*/ } }); factory.setXMLResolver(TMX_DTD_RESOLVER_2); dateFormat1 = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH); dateFormat1.setTimeZone(TimeZone.getTimeZone("UTC")); dateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH); dateFormat2.setTimeZone(TimeZone.getTimeZone("UTC")); dateFormatOut = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH); dateFormatOut.setTimeZone(TimeZone.getTimeZone("UTC")); }
From source file:org.onehippo.repository.scxml.RepositorySCXMLRegistry.java
private String naturalizeXMLStreamExceptionMessage(final XMLStreamException xse) { String naturalized = xse.getLocalizedMessage(); final Matcher m = XML_STREAM_EXCEPTION_MESSAGE_PATTERN.matcher(naturalized); if (m.find()) { final String errorInfo = m.group(2); if (StringUtils.isNotEmpty(errorInfo)) { final String[] tokens = StringUtils.split(errorInfo, "#?&"); if (!ArrayUtils.isEmpty(tokens)) { final Location location = xse.getLocation(); final StringBuilder sbTemp = new StringBuilder().append("XML Stream Error at (L") .append(location.getLineNumber()).append(":C").append(location.getColumnNumber()) .append("). Cause: ") .append(StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(tokens[0]), " ")); if (tokens.length > 1) { sbTemp.append(" (").append(StringUtils.join(tokens, ", ", 1, tokens.length)).append(")"); }//from w w w . java 2 s .com naturalized = sbTemp.toString(); } } } return naturalized; }
From source file:org.openvpms.tools.data.loader.DataLoader.java
/** * Starts a data element, pushing it on the stack. * * @param reader the reader/*from w w w.j av a 2 s . com*/ * @param stack the stack of load states * @param path a path representing the stream source, for logging purposes */ private void startData(XMLStreamReader reader, Stack<LoadState> stack, String path) { LoadState current; Data data = new Data(reader); if (verbose) { String archetypeId = stack.isEmpty() ? "none" : stack.peek().getArchetypeId().toString(); log.info("[START PROCESSING element, parent=" + archetypeId + "]" + data); } try { if (!stack.isEmpty()) { current = processData(stack.peek(), data, path); } else { current = processData(null, data, path); } stack.push(current); } catch (Exception exception) { Location location = reader.getLocation(); log.error("Error in start element, line " + location.getLineNumber() + ", column " + location.getColumnNumber() + "" + data + "", exception); } }
From source file:org.openvpms.tools.data.loader.DataLoader.java
/** * Process the specified data. If the parent object is specified then the * specified element is in a parent-child relationship. * * @param parent the parent object. May be <tt>null</tt> * @param data the data to process// www .j a v a 2 s . c o m * @param path a path representing the data source, for logging purposes * @return the load state corresponding to the data */ private LoadState processData(LoadState parent, Data data, String path) { LoadState result; Location location = data.getLocation(); String collectionNode = data.getCollection(); // if a childId node is defined then we can skip the create object // process since the object already exists String childId = data.getChildId(); if (StringUtils.isEmpty(childId)) { result = create(data, parent, path); for (Map.Entry<String, String> attribute : data.getAttributes().entrySet()) { String name = attribute.getKey(); String value = attribute.getValue(); result.setValue(name, value, context); } if (collectionNode != null) { if (parent == null) { throw new ArchetypeDataLoaderException(NoParentForChild, location.getLineNumber(), location.getColumnNumber()); } parent.addChild(collectionNode, result); } } else { // A childId has been specified. Must have a collection node, and // a non-null parent. if (parent == null) { throw new ArchetypeDataLoaderException(NoParentForChild, location.getLineNumber(), location.getColumnNumber()); } result = parent; if (StringUtils.isEmpty(collectionNode)) { throw new ArchetypeDataLoaderException(NoCollectionAttribute, location.getLineNumber(), location.getColumnNumber()); } parent.addChild(collectionNode, childId, context); } return result; }