List of usage examples for javax.xml.stream.events Attribute getName
QName getName();
From source file:com.logiware.accounting.domain.EdiInvoice.java
private void setCharacterType(StartElement startElement) { if (isHeader) { if ("Sender".equals(elementType) && "Code".equalsIgnoreCase(startElement.getName().toString())) { characterType = "Code"; elements.add("Code"); }/*from w ww .j a v a 2 s. c o m*/ } else if (isBody) { if (isInformation) { if ("Invoice".equals(elementType)) { characterType = startElement.getName().toString(); } else if ("RelatedReferences".equalsIgnoreCase(elementType)) { if ("Reference".equalsIgnoreCase(startElement.getName().toString())) { Iterator attributes = startElement.getAttributes(); if (attributes.hasNext()) { Attribute attribute = (Attribute) (attributes.next()); if ("Qualifier".equals(attribute.getName().toString())) { if ("EFR".equals(attribute.getValue())) { characterType = "EFR"; } else if ("BLR".equals(attribute.getValue())) { characterType = "BLR"; } else if ("CR".equals(attribute.getValue())) { characterType = "CR"; } else if ("TID".equals(attribute.getValue())) { characterType = "TID"; } } } } } else if ("Company".equalsIgnoreCase(elementType)) { if (!"NAD".equalsIgnoreCase(startElement.getName().toString()) && !"Location".equalsIgnoreCase(startElement.getName().toString())) { characterType = startElement.getName().toString(); } } else if ("Vendor".equalsIgnoreCase(elementType)) { if ("Bank".equalsIgnoreCase(startElement.getName().toString())) { isBank = true; } else if (!"NAD".equalsIgnoreCase(startElement.getName().toString()) && !"Location".equalsIgnoreCase(startElement.getName().toString())) { characterType = startElement.getName().toString(); } } else if ("PaymentTerms".equalsIgnoreCase(elementType)) { characterType = startElement.getName().toString(); } else if ("ShipmentInformation".equalsIgnoreCase(elementType)) { if (!"VoyageInformation".equalsIgnoreCase(startElement.getName().toString()) && !"Details".equalsIgnoreCase(startElement.getName().toString()) && !"Package".equalsIgnoreCase(startElement.getName().toString())) { characterType = startElement.getName().toString(); } } } else if (isDetails) { if ("Detail".equalsIgnoreCase(elementType)) { characterType = startElement.getName().toString(); } } else if (isSummary) { if ("TotalMonetaryAmount".equalsIgnoreCase(elementType)) { if ("TotalVATIncl".equalsIgnoreCase(startElement.getName().toString())) { characterType = "TotalVATIncl"; } } else if ("TotalMonetaryAmountGroupByVAT".equalsIgnoreCase(elementType)) { if ("TotalVAT".equalsIgnoreCase(startElement.getName().toString())) { characterType = "TotalVAT"; } else if ("VATPercentage".equalsIgnoreCase(startElement.getName().toString())) { characterType = "VATPercentage"; } } } } }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void encodeXhtml(XhtmlDt theDt, XMLStreamWriter theEventWriter) throws XMLStreamException { if (theDt == null || theDt.getValue() == null) { return;/*from ww w . j a va 2 s .c o m*/ } boolean firstElement = true; for (XMLEvent event : theDt.getValue()) { switch (event.getEventType()) { case XMLStreamConstants.ATTRIBUTE: Attribute attr = (Attribute) event; if (isBlank(attr.getName().getPrefix())) { if (isBlank(attr.getName().getNamespaceURI())) { theEventWriter.writeAttribute(attr.getName().getLocalPart(), attr.getValue()); } else { theEventWriter.writeAttribute(attr.getName().getNamespaceURI(), attr.getName().getLocalPart(), attr.getValue()); } } else { theEventWriter.writeAttribute(attr.getName().getPrefix(), attr.getName().getNamespaceURI(), attr.getName().getLocalPart(), attr.getValue()); } break; case XMLStreamConstants.CDATA: theEventWriter.writeCData(((Characters) event).getData()); break; case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: String data = ((Characters) event).getData(); theEventWriter.writeCharacters(data); break; case XMLStreamConstants.COMMENT: theEventWriter.writeComment(((Comment) event).getText()); break; case XMLStreamConstants.END_ELEMENT: theEventWriter.writeEndElement(); break; case XMLStreamConstants.ENTITY_REFERENCE: EntityReference er = (EntityReference) event; theEventWriter.writeEntityRef(er.getName()); break; case XMLStreamConstants.NAMESPACE: Namespace ns = (Namespace) event; theEventWriter.writeNamespace(ns.getPrefix(), ns.getNamespaceURI()); break; case XMLStreamConstants.START_ELEMENT: StartElement se = event.asStartElement(); if (firstElement) { if (StringUtils.isBlank(se.getName().getPrefix())) { String namespaceURI = se.getName().getNamespaceURI(); if (StringUtils.isBlank(namespaceURI)) { namespaceURI = "http://www.w3.org/1999/xhtml"; } theEventWriter.writeStartElement(se.getName().getLocalPart()); theEventWriter.writeDefaultNamespace(namespaceURI); } else { String prefix = se.getName().getPrefix(); String namespaceURI = se.getName().getNamespaceURI(); theEventWriter.writeStartElement(prefix, se.getName().getLocalPart(), namespaceURI); theEventWriter.writeNamespace(prefix, namespaceURI); } firstElement = false; } else { if (isBlank(se.getName().getPrefix())) { if (isBlank(se.getName().getNamespaceURI())) { theEventWriter.writeStartElement(se.getName().getLocalPart()); } else { if (StringUtils.isBlank(se.getName().getPrefix())) { theEventWriter.writeStartElement(se.getName().getLocalPart()); // theEventWriter.writeDefaultNamespace(se.getName().getNamespaceURI()); } else { theEventWriter.writeStartElement(se.getName().getNamespaceURI(), se.getName().getLocalPart()); } } } else { theEventWriter.writeStartElement(se.getName().getPrefix(), se.getName().getLocalPart(), se.getName().getNamespaceURI()); } for (Iterator<?> attrIter = se.getAttributes(); attrIter.hasNext();) { Attribute next = (Attribute) attrIter.next(); theEventWriter.writeAttribute(next.getName().getLocalPart(), next.getValue()); } } break; case XMLStreamConstants.DTD: case XMLStreamConstants.END_DOCUMENT: case XMLStreamConstants.ENTITY_DECLARATION: case XMLStreamConstants.NOTATION_DECLARATION: case XMLStreamConstants.PROCESSING_INSTRUCTION: case XMLStreamConstants.START_DOCUMENT: break; } } }
From source file:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlFilterReader.java
private Attr bufferAttribute(Element element, Attribute attribute) { QName name = attribute.getName(); String prefix = name.getPrefix(); String uri = name.getNamespaceURI(); Attr node;/* w ww. j a v a2 s .c o m*/ if (uri == null || uri.isEmpty()) { node = document.createAttribute(name.getLocalPart()); element.setAttributeNode(node); } else { node = document.createAttributeNS(uri, name.getLocalPart()); if (prefix != null && !prefix.isEmpty()) { node.setPrefix(prefix); } element.setAttributeNodeNS(node); } node.setTextContent(attribute.getValue()); return node; }
From source file:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlFilterReader.java
private void streamAttribute(Element element, Attribute attribute) throws XPathExpressionException { Attr node;/*w w w . ja va 2 s . c om*/ QName name = attribute.getName(); String prefix = name.getPrefix(); String uri = name.getNamespaceURI(); if (uri == null || uri.isEmpty()) { node = document.createAttribute(name.getLocalPart()); element.setAttributeNode(node); } else { node = document.createAttributeNS(uri, name.getLocalPart()); if (prefix != null && !prefix.isEmpty()) { node.setPrefix(prefix); } element.setAttributeNodeNS(node); } String value = attribute.getValue(); Level level = stack.peek(); if ((level.scopeConfig) == null || (level.scopeConfig.getSelectors().isEmpty())) { value = filterAttribute(null, attribute.getName(), value, null); node.setValue(value); } else { UrlRewriteFilterPathDescriptor path = pickFirstMatchingPath(level); if (path instanceof UrlRewriteFilterApplyDescriptor) { String rule = ((UrlRewriteFilterApplyDescriptor) path).rule(); value = filterAttribute(null, attribute.getName(), value, rule); node.setValue(value); } } //dump( document ); if (prefix == null || prefix.isEmpty()) { writer.write(" "); writer.write(name.getLocalPart()); } else { writer.write(" "); writer.write(prefix); writer.write(":"); writer.write(name.getLocalPart()); } writer.write("=\""); writer.write(value); writer.write("\""); element.removeAttributeNode(node); }
From source file:org.apache.hadoop.util.ConfTest.java
public void addAttribute(Attribute attribute) { attributes.add(attribute); addQNameXMLEvent(attribute.getName(), attribute); }
From source file:org.modeldriven.fuml.assembly.ElementAssembler.java
public void assemleFeatures() { try {// www. ja v a2s. 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.validation.ValidationErrorCollector.java
private void validateAttributes(StreamNode target, XmiNode source, Class_ classifier, Iterator<Attribute> attributes) { NamespaceDomain domain = null; // only lookup as needed // look at XML attributes while (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: why is this "special" ? Property property = classifier.findProperty(name.getLocalPart()); if (property == null) { if (domain == null) domain = FumlConfiguration.getInstance().findNamespaceDomain(target.getNamespaceURI()); ValidationExemption exemption = FumlConfiguration.getInstance().findValidationExemptionByProperty( ValidationExemptionType.UNDEFINED_PROPERTY, classifier, name.getLocalPart(), target.getNamespaceURI(), domain); if (exemption == null) { addError(ErrorCode.UNDEFINED_PROPERTY, ErrorSeverity.FATAL, target, name.getLocalPart()); } else { if (log.isDebugEnabled()) log.debug("undefined property exemption found within domain '" + exemption.getDomain().toString() + "' for property '" + classifier.getName() + "." + name.getLocalPart() + "' - ignoring error"); }// w w w . j a va 2 s . c o m continue; } if (isReferenceAttribute(property)) { XmiReferenceAttribute reference = new XmiReferenceAttribute(target, xmlAttrib, classifier); this.references.add(reference); } // TODO: when this error is commented out, an erroneous 'invalid internal reference' validation // error was seen to be thrown during assembly. This seems to be a bug if (property.isDerived()) if (checkDerivedPropertyInstantiationError(target, source, classifier, property)) { addError(ErrorCode.DERIVED_PROPERTY_INSTANTIATION, ErrorSeverity.FATAL, target, property.getName()); } } }
From source file:org.odftoolkit.odfdom.pkg.rdfa.URIExtractorImpl.java
public String getURI(StartElement element, Attribute attr, EvalContext context) { QName attrName = attr.getName(); if (Util.qNameEquals(attrName, Constants.about)) // Safe CURIE or URI {//from w w w . j av a2 s .c o m return expandSafeCURIE(element, attr.getValue(), context); } if (Util.qNameEquals(attrName, Constants.datatype)) // A CURIE { return expandCURIE(element, attr.getValue(), context); } throw new RuntimeException("Unexpected attribute: " + attr); }
From source file:org.odftoolkit.odfdom.pkg.rdfa.URIExtractorImpl.java
public List<String> getURIs(StartElement element, Attribute attr, EvalContext context) { List<String> uris = new LinkedList<String>(); String[] curies = attr.getValue().split("\\s+"); boolean permitReserved = Util.qNameEquals(Constants.rel, attr.getName()) || Util.qNameEquals(Constants.rev, attr.getName()); for (String curie : curies) { if (Constants.SpecialRels.contains(curie.toLowerCase())) { if (permitReserved) uris.add("http://www.w3.org/1999/xhtml/vocab#" + curie.toLowerCase()); } else {/*from w w w .ja v a2s. co m*/ String uri = expandCURIE(element, curie, context); if (uri != null) { uris.add(uri); } } } return uris; }
From source file:org.omegat.util.TMXReader2.java
protected void parseTuv(StartElement element) throws Exception { ParsedTuv tuv = new ParsedTuv(); currentTu.tuvs.add(tuv);//from w w w . j a v a2 s. co m tuv.changeid = getAttributeValue(element, "changeid"); tuv.changedate = parseISO8601date(getAttributeValue(element, "changedate")); tuv.creationid = getAttributeValue(element, "creationid"); tuv.creationdate = parseISO8601date(getAttributeValue(element, "creationdate")); // find 'lang' or 'xml:lang' attribute for (Iterator<?> it = element.getAttributes(); it.hasNext();) { Attribute a = (Attribute) it.next(); if ("lang".equals(a.getName().getLocalPart())) { tuv.lang = a.getValue(); break; } } while (true) { XMLEvent e = xml.nextEvent(); switch (e.getEventType()) { case XMLEvent.START_ELEMENT: StartElement eStart = (StartElement) e; if ("seg".equals(eStart.getName().getLocalPart())) { if (isOmegaT) { parseSegOmegaT(); } else if (extTmxLevel2) { parseSegExtLevel2(); } else { parseSegExtLevel1(); } tuv.text = StringUtil.normalizeUnicode(segContent); } break; case XMLEvent.END_ELEMENT: EndElement eEnd = (EndElement) e; if ("tuv".equals(eEnd.getName().getLocalPart())) { return; } break; } } }