Refine search
/** * Convert a namespace URI and DOM or SAX qualified name to a {@code QName}. The * qualified name can have the form {@code prefix:localname} or {@code localName}. * @param namespaceUri the namespace URI * @param qualifiedName the qualified name * @return a QName */ protected QName toQName(String namespaceUri, String qualifiedName) { int idx = qualifiedName.indexOf(':'); if (idx == -1) { return new QName(namespaceUri, qualifiedName); } else { String prefix = qualifiedName.substring(0, idx); String localPart = qualifiedName.substring(idx + 1); return new QName(namespaceUri, localPart, prefix); } }
@Override @Nullable public String getAttributeValue(@Nullable String namespaceURI, String localName) { for (int i = 0; i < getAttributeCount(); i++) { QName name = getAttributeName(i); if (name.getLocalPart().equals(localName) && (namespaceURI == null || name.getNamespaceURI().equals(namespaceURI))) { return getAttributeValue(i); } } return null; }
private boolean isSupported( QName returnType ) { // XPathConstants.STRING if ( ( returnType.equals( XPathConstants.STRING ) ) || ( returnType.equals( XPathConstants.NUMBER ) ) || ( returnType.equals( XPathConstants.BOOLEAN ) ) || ( returnType.equals( XPathConstants.NODE ) ) || ( returnType.equals( XPathConstants.NODESET ) ) ) { return true; } return false; }
/** * Convert a {@code QName} to a qualified name, as used by DOM and SAX. * The returned string has a format of {@code prefix:localName} if the * prefix is set, or just {@code localName} if not. * @param qName the {@code QName} * @return the qualified name */ protected String toQualifiedName(QName qName) { String prefix = qName.getPrefix(); if (!StringUtils.hasLength(prefix)) { return qName.getLocalPart(); } else { return prefix + ":" + qName.getLocalPart(); } }
static Element of(QName qName) { QName name; if (qName.getNamespaceURI().equals("")) { name = new QName(NAMESPACE_1_0, qName.getLocalPart()); } else { name = qName; } final Element element = elements.get(name); return element == null ? UNKNOWN : element; } }
@Override protected void startElementInternal(QName name, Attributes attributes, Map<String, String> namespaceMapping) throws XMLStreamException { this.streamWriter.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI()); for (Map.Entry<String, String> entry : namespaceMapping.entrySet()) { String prefix = entry.getKey(); String namespaceUri = entry.getValue(); this.streamWriter.writeNamespace(prefix, namespaceUri); if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) { this.streamWriter.setDefaultNamespace(namespaceUri); } else { this.streamWriter.setPrefix(prefix, namespaceUri); } } for (int i = 0; i < attributes.getLength(); i++) { QName attrName = toQName(attributes.getURI(i), attributes.getQName(i)); if (!isNamespaceDeclaration(attrName)) { this.streamWriter.writeAttribute(attrName.getPrefix(), attrName.getNamespaceURI(), attrName.getLocalPart(), attributes.getValue(i)); } } }
public TypeReference(QName tagName, Type type, Annotation... annotations) { if(tagName==null || type==null || annotations==null) { String nullArgs = ""; if(tagName == null) nullArgs = "tagName"; if(type == null) nullArgs += (nullArgs.length() > 0 ? ", type" : "type"); if(annotations == null) nullArgs += (nullArgs.length() > 0 ? ", annotations" : "annotations"); Messages.ARGUMENT_CANT_BE_NULL.format(nullArgs); throw new IllegalArgumentException(Messages.ARGUMENT_CANT_BE_NULL.format(nullArgs)); } this.tagName = new QName(tagName.getNamespaceURI().intern(), tagName.getLocalPart().intern(), tagName.getPrefix()); this.type = type; this.annotations = annotations; }
@Override public String getAttributeLocalName(int index) { return getAttributeName(index).getLocalPart(); }
private StartElement wrap(StartElement startElement) { List<Attribute> newElementAttributeList = mapAttributes( startElement ); List<Namespace> newNamespaceList = mapNamespaces( startElement ); // Transfer the location info from the incoming event to the event factory // so that the event we ask it to generate for us has the same location info xmlEventFactory.setLocation( startElement.getLocation() ); return xmlEventFactory.createStartElement( new QName( MappingXsdSupport.INSTANCE.latestJpaDescriptor().getNamespaceUri(), startElement.getName().getLocalPart() ), newElementAttributeList.iterator(), newNamespaceList.iterator() ); }
@Override public String getAttributeNamespace(int index) { return getAttributeName(index).getNamespaceURI(); }
public void attWildcardAsURIs(Map<QName,String> attributes, String fieldName) { if(attributes==null) return; for( Map.Entry<QName,String> e : attributes.entrySet() ) { QName n = e.getKey(); String nsUri = n.getNamespaceURI(); if(nsUri.length()>0) { String p = n.getPrefix(); if(p.length()==0) p=null; nsContext.declareNsUri(nsUri, p, true); } } }
@Override public String getAttributePrefix(int index) { return getAttributeName(index).getPrefix(); }
/** * Initialize internal instance of XMLCatalog. * Initialize XPath for parameter evaluation. * @throws BuildException on error */ @Override public void init() throws BuildException { super.init(); xmlCatalog.setProject(getProject()); xpathFactory = XPathFactory.newInstance(); xpath = xpathFactory.newXPath(); xpath.setXPathVariableResolver( variableName -> getProject().getProperty(variableName.toString())); }
private void handleStartElement(StartElement startElement) throws SAXException { if (getContentHandler() != null) { QName qName = startElement.getName(); if (hasNamespacesFeature()) { for (Iterator i = startElement.getNamespaces(); i.hasNext();) { Namespace namespace = (Namespace) i.next(); startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceURI()); } for (Iterator i = startElement.getAttributes(); i.hasNext();){ Attribute attribute = (Attribute) i.next(); QName attributeName = attribute.getName(); startPrefixMapping(attributeName.getPrefix(), attributeName.getNamespaceURI()); } getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName), getAttributes(startElement)); } else { getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes(startElement)); } } }
/** Keys for overriding default layer properties */ public static class StyleProperty<T> { T get(Map<StyleProperty, Object> map, T def) { return map != null && map.containsKey(this) ? (T) map.get(this) : def; } public static StyleProperty<String> FORMAT = new StyleProperty<String>(); public static StyleProperty<Version> FORMAT_VERSION = new StyleProperty<Version>(); public static StyleProperty<LegendInfo> LEGEND_INFO = new StyleProperty<LegendInfo>(); }
protected boolean isNamespaceDeclaration(QName qName) { String prefix = qName.getPrefix(); String localPart = qName.getLocalPart(); return (XMLConstants.XMLNS_ATTRIBUTE.equals(localPart) && prefix.isEmpty()) || (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) && !localPart.isEmpty()); }
@Override public String getLocalName() { return getName().getLocalPart(); }
private XMLEvent wrap(EndElement endElement) { final List<Namespace> targetNamespaces = mapNamespaces( existingXmlNamespacesIterator( endElement ) ); // Transfer the location info from the incoming event to the event factory // so that the event we ask it to generate for us has the same location info xmlEventFactory.setLocation( endElement.getLocation() ); return xmlEventFactory.createEndElement( new QName( MappingXsdSupport.INSTANCE.latestJpaDescriptor().getNamespaceUri(), endElement.getName().getLocalPart() ), targetNamespaces.iterator() ); }
protected static boolean hasNamespace(StartElement startElement) { return ! "".equals( startElement.getName().getNamespaceURI() ); }
@Override public void declareNamespace(QName v, XMLSerializer w) { w.getNamespaceContext().declareNamespace(v.getNamespaceURI(),v.getPrefix(),false); } });