public static String _printQName(QName val, NamespaceContext nsc) { // Double-check String qname; String prefix = nsc.getPrefix(val.getNamespaceURI()); String localPart = val.getLocalPart(); if (prefix == null || prefix.length() == 0) { // be defensive qname = localPart; } else { qname = prefix + ':' + localPart; } return qname; }
public static String _printQName(QName val, NamespaceContext nsc) { // Double-check String qname; String prefix = nsc.getPrefix(val.getNamespaceURI()); String localPart = val.getLocalPart(); if (prefix == null || prefix.length() == 0) { // be defensive qname = localPart; } else { qname = prefix + ':' + localPart; } return qname; }
@Override public String getPrefix(String uri) { if( uri==null ) throw new IllegalArgumentException(); if( uri.equals(XMLConstants.XML_NS_URI) ) return XMLConstants.XML_NS_PREFIX; if( uri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI) ) return XMLConstants.XMLNS_ATTRIBUTE; for( int i=nsLen-2; i>=0; i-=2 ) if(uri.equals(nsBind[i+1])) if( getNamespaceURI(nsBind[i]).equals(nsBind[i+1]) ) // make sure that this prefix is still effective. return nsBind[i]; if(environmentNamespaceContext!=null) return environmentNamespaceContext.getPrefix(uri); return null; }
public void run() { NamespaceContext ns = nsc; if(xsw!=null) ns = xsw.getNamespaceContext(); if(xew!=null) ns = xew.getNamespaceContext(); // StAX javadoc isn't very clear on the behavior, // so work defensively in anticipation of broken implementations. if(ns==null) return; // we can't enumerate all the in-scope namespace bindings in StAX, // so we only look for the known static namespace URIs. // this is less than ideal, but better than nothing. for( String nsUri : serializer.grammar.nameList.namespaceURIs ) { String p = ns.getPrefix(nsUri); if(p!=null) serializer.addInscopeBinding(nsUri,p); } } }
public static String _printQName(QName val, NamespaceContext nsc) { // Double-check String qname; String prefix = nsc.getPrefix(val.getNamespaceURI()); String localPart = val.getLocalPart(); if (prefix == null || prefix.length() == 0) { // be defensive qname = localPart; } else { qname = prefix + ':' + localPart; } return qname; }
public String printQName(QName arg0, NamespaceContext arg1) { String prefix = arg1.getPrefix(arg0.getNamespaceURI()); if (prefix == null) { throw new IllegalArgumentException( "The namespace URI " + arg0.getNamespaceURI() + " is not bound."); } else if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) { return arg0.getLocalPart(); } else { return prefix + ":" + arg0.getLocalPart(); } }
@Override public String getPrefix(String uri) throws XMLStreamException { return getNamespaceContext().getPrefix(uri); }
public String getPrefix(String uri) { if (!mNsAware) { return null; } if (mNsContext != null) { String prefix = mNsContext.getPrefix(uri); if (prefix != null) { return prefix; } } return mCurrElem.getPrefix(uri); }
public String getPrefix(String ns) throws XMLStreamException { return getNamespaceContext().getPrefix(ns); }
public final String getPrefix(String uri) { if (mDefaultNsURI.equals(uri)) { return ""; } if (mNsMapping != null) { String prefix = mNsMapping.findPrefixByUri(uri); if (prefix != null) { return prefix; } } return (mRootNsContext != null) ? mRootNsContext.getPrefix(uri) : null; }
@Override public String getPrefix(String uri) { if( uri==null ) throw new IllegalArgumentException(); if( uri.equals(XMLConstants.XML_NS_URI) ) return XMLConstants.XML_NS_PREFIX; if( uri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI) ) return XMLConstants.XMLNS_ATTRIBUTE; for( int i=nsLen-2; i>=0; i-=2 ) if(uri.equals(nsBind[i+1])) if( getNamespaceURI(nsBind[i]).equals(nsBind[i+1]) ) // make sure that this prefix is still effective. return nsBind[i]; if(environmentNamespaceContext!=null) return environmentNamespaceContext.getPrefix(uri); return null; }
public String doGetPrefix(String nsURI) { // Note: base class checks for 'known' problems and prefixes: if (mNsByURI == null) { mNsByURI = buildByNsURIMap(); } Namespace ns = (Namespace) mNsByURI.get(nsURI); if (ns == null && mParentCtxt != null) { return mParentCtxt.getPrefix(nsURI); } return (ns == null) ? null : ns.getPrefix(); }
/** * Method similar to {@link #getPrefix}, but one that will not accept * the default namespace, only an explicit one. Usually used when * trying to find a prefix for attributes. */ public final String getExplicitPrefix(String uri) { if (mNsMapping != null) { String prefix = mNsMapping.findPrefixByUri(uri); if (prefix != null) { return prefix; } } if (mRootNsContext != null) { String prefix = mRootNsContext.getPrefix(uri); if (prefix != null) { // Hmmh... still can't use the default NS: if (prefix.length() > 0) { return prefix; } // ... should we try to find an explicit one? } } return null; }
public static String printQName(QName qname, NamespaceContext nsContext, Collection errors) { final String uri = qname.getNamespaceURI(); assert uri != null; //qname is not allowed to have null uri values final String prefix; if (uri.length() > 0) { prefix = nsContext.getPrefix(uri); if (prefix == null) { String msg = "NamespaceContext does not provide" + " prefix for namespaceURI " + uri; errors.add(XmlError.forMessage(msg)); } } else { prefix = null; } return getQNameString(uri, qname.getLocalPart(), prefix); }
private static String qnameToString(QName qname, NamespaceContext ctx) throws XPathGenerationException { String localName = qname.getLocalPart(); String uri = qname.getNamespaceURI(); if (uri.length() == 0) return localName; String prefix = qname.getPrefix(); if (prefix != null && prefix.length() > 0) { // Try to use the same prefix if it maps to the right URI String mappedUri = ctx.getNamespaceURI(prefix); if (uri.equals(mappedUri)) return prefix + ':' + localName; } // The prefix is not specified, or it is not mapped to the right URI prefix = ctx.getPrefix(uri); if (prefix == null) throw new XPathGenerationException("Could not obtain a prefix for URI: " + uri); if (prefix.length() == 0) throw new XPathGenerationException("Can not use default prefix in XPath for URI: " + uri); return prefix + ':' + localName; }
public void run() { NamespaceContext ns = nsc; if(xsw!=null) ns = xsw.getNamespaceContext(); if(xew!=null) ns = xew.getNamespaceContext(); // StAX javadoc isn't very clear on the behavior, // so work defensively in anticipation of broken implementations. if(ns==null) return; // we can't enumerate all the in-scope namespace bindings in StAX, // so we only look for the known static namespace URIs. // this is less than ideal, but better than nothing. for( String nsUri : serializer.grammar.nameList.namespaceURIs ) { String p = ns.getPrefix(nsUri); if(p!=null) serializer.addInscopeBinding(nsUri,p); } } }
String prefix = namespaceContext.getPrefix(qName.getNamespaceURI()); if (prefix != null && !"".equals(prefix)) { qName = new QName(qName.getNamespaceURI(), qName.getLocalPart(), prefix);
public String getPrefix(String namespaceURI) { for (Map.Entry<String, String> entry : bindings.entrySet()) { if (entry.getValue().equals(namespaceURI)) { return entry.getKey(); } } return rootNamespaceContext.getPrefix(namespaceURI); }
public String getPrefix(String namespaceURI) { for (Map.Entry<String, String> e : map.entrySet()) { if (e.getValue().equals(namespaceURI)) { return e.getKey(); } } if (parent != null) { return parent.getPrefix(namespaceURI); } return null; }
public String getAttributeValue(int index) { if (first && index == 0) { String pfx = this.getNamespaceContext().getPrefix(typeQName.getNamespaceURI()); if (StringUtils.isEmpty(pfx)) { return typeQName.getLocalPart(); } return pfx + ":" + typeQName.getLocalPart(); } return super.getAttributeValue(index - offset); }