List of usage examples for javax.xml.stream Location getColumnNumber
int 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 {//from ww w. j a va2s. co m 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 . ja va 2 s .co m 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();/*w w w . ja v a 2 s. c o 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++;/*w ww .j ava2 s .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 . j a va 2 s . c o m 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 ww .j a v a2 s .c o m*/ * @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/*from w ww. j ava2s.c om*/ * @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; }
From source file:org.openvpms.tools.data.loader.DataLoader.java
/** * Creates a new load state for the specified data. * * @param data the data//from w ww . j av a 2 s . c o m * @param parent the parent state. May be <tt>null</tt> * @param path a path representing the data source, for logging purposes * @return a new load state */ private LoadState create(Data data, LoadState parent, String path) { String shortName = data.getShortName(); ArchetypeDescriptor descriptor = service.getArchetypeDescriptor(shortName); Location location = data.getLocation(); if (descriptor == null) { throw new ArchetypeDataLoaderException(InvalidArchetype, location.getLineNumber(), location.getColumnNumber(), shortName); } IMObject object = service.create(descriptor.getType()); if (object == null) { throw new ArchetypeDataLoaderException(InvalidArchetype, location.getLineNumber(), location.getColumnNumber(), shortName); } cache.add(object, data.getId()); return new LoadState(parent, object, descriptor, path, data.getLocation().getLineNumber()); }
From source file:org.plasma.sdo.xml.StreamUnmarshaller.java
private StreamObject read(XMLStreamReader streamReader) throws XMLStreamException, UnmarshallerException { int eventType; StreamObject root = null;//from www.ja v a 2 s . co m while (streamReader.hasNext()) { eventType = streamReader.next(); XMLEvent event = allocateXMLEvent(streamReader); switch (eventType) { case XMLEvent.START_ELEMENT: QName name = event.asStartElement().getName(); String uri = name.getNamespaceURI(); if (uri != null && uri.trim().length() > 0) this.currentNamespaceUri = uri.trim(); if (stack.size() == 0) { String typeName = name.getLocalPart(); PlasmaType type = (PlasmaType) PlasmaTypeHelper.INSTANCE.getType(currentNamespaceUri, typeName); if (log.isDebugEnabled()) log.debug("unmarshaling root: " + type.getURI() + "#" + type.getName()); root = new StreamObject(type, name, event.getLocation()); stack.push(root); } else { StreamObject sreamObject = (StreamObject) stack.peek(); PlasmaType type = sreamObject.getType(); QName elemName = event.asStartElement().getName(); PlasmaProperty property = getPropertyByLocalName(event, type, elemName.getLocalPart()); if (property.getType().isDataType()) { // still need characters event to populate this property. We expect to // pop this back off the stack after its characters event is processed below stack.push(new StreamProperty((PlasmaType) property.getType(), property, name, event.getLocation())); break; // we expect no attributes !! } else { if (log.isDebugEnabled()) log.debug("unmarshaling: " + property.getType().getURI() + "#" + property.getType().getName()); // The source is a reference property but we don't know at this point // whether its a reference object. // Push the new DO so we can value its contents on subsequent events stack.push(new StreamObject((PlasmaType) property.getType(), property, name, event.getLocation())); } } StreamObject streamObject = (StreamObject) stack.peek(); readAttributes(event, streamObject); break; case XMLEvent.END_ELEMENT: StreamNode node = stack.pop(); if (stack.size() == 0) break; // link stream objects creating an initial graph StreamObject other = (StreamObject) stack.peek(); if (node instanceof StreamProperty) { StreamProperty streamProp = (StreamProperty) node; if (this.charbuf.length() > 0) { readCharacters(streamProp, this.charbuf.toString(), event); this.charbuf.setLength(0); } link((StreamProperty) node, other); } else { link((StreamObject) node, other); } break; case XMLEvent.CHARACTERS: if (stack.size() == 0) break; String data = event.asCharacters().getData(); if (log.isDebugEnabled()) log.debug("unmarshaling characters: " + String.valueOf(data)); if (data == null) { break; // ignore null } if (data.contains(">")) { //Note: we even get escaped '>' char here so // can't accurately determine well-formedness Location loc = event.getLocation(); String msg = "line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "]"; msg += " - document may not be well-formed"; log.warn(msg); } StreamNode streamNode = stack.peek(); if (streamNode instanceof StreamProperty) { this.charbuf.append(data); } else { if (log.isDebugEnabled()) { StreamObject streamObj = (StreamObject) streamNode; Location loc = event.getLocation(); String msg = "line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "]"; msg += " - ignoring character(s) data '" + data + "' for complex type " + streamObj.getType().getURI() + "#" + streamObj.getType().getName(); log.debug(msg); } } break; default: logEventInfo(event); } } return root; }