Java Code Examples for org.xml.sax.helpers.NamespaceSupport#getPrefixes()
The following examples show how to use
org.xml.sax.helpers.NamespaceSupport#getPrefixes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSchemaValidationTube.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Adds inscope namespaces as attributes to <xsd:schema> fragment nodes. * * @param nss namespace context info * @param elem that is patched with inscope namespaces */ private @Nullable void patchDOMFragment(NamespaceSupport nss, Element elem) { NamedNodeMap atts = elem.getAttributes(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); for( int i=0; i<atts.getLength(); i++ ) { Attr a = (Attr)atts.item(i); if (!"xmlns".equals(a.getPrefix()) || !a.getLocalName().equals(prefix)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Patching with xmlns:{0}={1}", new Object[]{prefix, nss.getURI(prefix)}); } elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:"+prefix, nss.getURI(prefix)); } } } }
Example 2
Source File: AbstractSchemaValidationTube.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Adds inscope namespaces as attributes to <xsd:schema> fragment nodes. * * @param nss namespace context info * @param elem that is patched with inscope namespaces */ private @Nullable void patchDOMFragment(NamespaceSupport nss, Element elem) { NamedNodeMap atts = elem.getAttributes(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); for( int i=0; i<atts.getLength(); i++ ) { Attr a = (Attr)atts.item(i); if (!"xmlns".equals(a.getPrefix()) || !a.getLocalName().equals(prefix)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Patching with xmlns:{0}={1}", new Object[]{prefix, nss.getURI(prefix)}); } elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:"+prefix, nss.getURI(prefix)); } } } }
Example 3
Source File: StreamMessage.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * There is no way to enumerate inscope namespaces for XMLStreamReader. That means * namespaces declared in envelope, and body tags need to be computed using their * {@link TagInfoset}s. * * @return array of the even length of the form { prefix0, uri0, prefix1, uri1, ... } */ private String[] getInscopeNamespaces() { NamespaceSupport nss = new NamespaceSupport(); nss.pushContext(); for(int i=0; i < envelopeTag.ns.length; i+=2) { nss.declarePrefix(envelopeTag.ns[i], envelopeTag.ns[i+1]); } nss.pushContext(); for(int i=0; i < bodyTag.ns.length; i+=2) { nss.declarePrefix(bodyTag.ns[i], bodyTag.ns[i+1]); } List<String> inscope = new ArrayList<String>(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); inscope.add(prefix); inscope.add(nss.getURI(prefix)); } return inscope.toArray(new String[inscope.size()]); }
Example 4
Source File: AbstractSchemaValidationTube.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Adds inscope namespaces as attributes to <xsd:schema> fragment nodes. * * @param nss namespace context info * @param elem that is patched with inscope namespaces */ private @Nullable void patchDOMFragment(NamespaceSupport nss, Element elem) { NamedNodeMap atts = elem.getAttributes(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); for( int i=0; i<atts.getLength(); i++ ) { Attr a = (Attr)atts.item(i); if (!"xmlns".equals(a.getPrefix()) || !a.getLocalName().equals(prefix)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Patching with xmlns:{0}={1}", new Object[]{prefix, nss.getURI(prefix)}); } elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:"+prefix, nss.getURI(prefix)); } } } }
Example 5
Source File: StreamMessage.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * There is no way to enumerate inscope namespaces for XMLStreamReader. That means * namespaces declared in envelope, and body tags need to be computed using their * {@link TagInfoset}s. * * @return array of the even length of the form { prefix0, uri0, prefix1, uri1, ... } */ private String[] getInscopeNamespaces() { NamespaceSupport nss = new NamespaceSupport(); nss.pushContext(); for(int i=0; i < envelopeTag.ns.length; i+=2) { nss.declarePrefix(envelopeTag.ns[i], envelopeTag.ns[i+1]); } nss.pushContext(); for(int i=0; i < bodyTag.ns.length; i+=2) { nss.declarePrefix(bodyTag.ns[i], bodyTag.ns[i+1]); } List<String> inscope = new ArrayList<String>(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); inscope.add(prefix); inscope.add(nss.getURI(prefix)); } return inscope.toArray(new String[inscope.size()]); }
Example 6
Source File: AbstractSchemaValidationTube.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Adds inscope namespaces as attributes to <xsd:schema> fragment nodes. * * @param nss namespace context info * @param elem that is patched with inscope namespaces */ private @Nullable void patchDOMFragment(NamespaceSupport nss, Element elem) { NamedNodeMap atts = elem.getAttributes(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); for( int i=0; i<atts.getLength(); i++ ) { Attr a = (Attr)atts.item(i); if (!"xmlns".equals(a.getPrefix()) || !a.getLocalName().equals(prefix)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Patching with xmlns:{0}={1}", new Object[]{prefix, nss.getURI(prefix)}); } elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:"+prefix, nss.getURI(prefix)); } } } }
Example 7
Source File: StreamMessage.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * There is no way to enumerate inscope namespaces for XMLStreamReader. That means * namespaces declared in envelope, and body tags need to be computed using their * {@link TagInfoset}s. * * @return array of the even length of the form { prefix0, uri0, prefix1, uri1, ... } */ private String[] getInscopeNamespaces() { NamespaceSupport nss = new NamespaceSupport(); nss.pushContext(); for(int i=0; i < envelopeTag.ns.length; i+=2) { nss.declarePrefix(envelopeTag.ns[i], envelopeTag.ns[i+1]); } nss.pushContext(); for(int i=0; i < bodyTag.ns.length; i+=2) { nss.declarePrefix(bodyTag.ns[i], bodyTag.ns[i+1]); } List<String> inscope = new ArrayList<String>(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); inscope.add(prefix); inscope.add(nss.getURI(prefix)); } return inscope.toArray(new String[inscope.size()]); }
Example 8
Source File: StreamMessage.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * There is no way to enumerate inscope namespaces for XMLStreamReader. That means * namespaces declared in envelope, and body tags need to be computed using their * {@link TagInfoset}s. * * @return array of the even length of the form { prefix0, uri0, prefix1, uri1, ... } */ private String[] getInscopeNamespaces() { NamespaceSupport nss = new NamespaceSupport(); nss.pushContext(); for(int i=0; i < envelopeTag.ns.length; i+=2) { nss.declarePrefix(envelopeTag.ns[i], envelopeTag.ns[i+1]); } nss.pushContext(); for(int i=0; i < bodyTag.ns.length; i+=2) { nss.declarePrefix(bodyTag.ns[i], bodyTag.ns[i+1]); } List<String> inscope = new ArrayList<String>(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); inscope.add(prefix); inscope.add(nss.getURI(prefix)); } return inscope.toArray(new String[inscope.size()]); }
Example 9
Source File: StreamMessage.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * There is no way to enumerate inscope namespaces for XMLStreamReader. That means * namespaces declared in envelope, and body tags need to be computed using their * {@link TagInfoset}s. * * @return array of the even length of the form { prefix0, uri0, prefix1, uri1, ... } */ private String[] getInscopeNamespaces() { NamespaceSupport nss = new NamespaceSupport(); nss.pushContext(); for(int i=0; i < envelopeTag.ns.length; i+=2) { nss.declarePrefix(envelopeTag.ns[i], envelopeTag.ns[i+1]); } nss.pushContext(); for(int i=0; i < bodyTag.ns.length; i+=2) { nss.declarePrefix(bodyTag.ns[i], bodyTag.ns[i+1]); } List<String> inscope = new ArrayList<String>(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); inscope.add(prefix); inscope.add(nss.getURI(prefix)); } return inscope.toArray(new String[inscope.size()]); }
Example 10
Source File: AbstractSchemaValidationTube.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Adds inscope namespaces as attributes to <xsd:schema> fragment nodes. * * @param nss namespace context info * @param elem that is patched with inscope namespaces */ private @Nullable void patchDOMFragment(NamespaceSupport nss, Element elem) { NamedNodeMap atts = elem.getAttributes(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); for( int i=0; i<atts.getLength(); i++ ) { Attr a = (Attr)atts.item(i); if (!"xmlns".equals(a.getPrefix()) || !a.getLocalName().equals(prefix)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Patching with xmlns:{0}={1}", new Object[]{prefix, nss.getURI(prefix)}); } elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:"+prefix, nss.getURI(prefix)); } } } }
Example 11
Source File: StreamMessage.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * There is no way to enumerate inscope namespaces for XMLStreamReader. That means * namespaces declared in envelope, and body tags need to be computed using their * {@link TagInfoset}s. * * @return array of the even length of the form { prefix0, uri0, prefix1, uri1, ... } */ private String[] getInscopeNamespaces() { NamespaceSupport nss = new NamespaceSupport(); nss.pushContext(); for(int i=0; i < envelopeTag.ns.length; i+=2) { nss.declarePrefix(envelopeTag.ns[i], envelopeTag.ns[i+1]); } nss.pushContext(); for(int i=0; i < bodyTag.ns.length; i+=2) { nss.declarePrefix(bodyTag.ns[i], bodyTag.ns[i+1]); } List<String> inscope = new ArrayList<String>(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); inscope.add(prefix); inscope.add(nss.getURI(prefix)); } return inscope.toArray(new String[inscope.size()]); }
Example 12
Source File: AbstractSchemaValidationTube.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Adds inscope namespaces as attributes to <xsd:schema> fragment nodes. * * @param nss namespace context info * @param elem that is patched with inscope namespaces */ private @Nullable void patchDOMFragment(NamespaceSupport nss, Element elem) { NamedNodeMap atts = elem.getAttributes(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); for( int i=0; i<atts.getLength(); i++ ) { Attr a = (Attr)atts.item(i); if (!"xmlns".equals(a.getPrefix()) || !a.getLocalName().equals(prefix)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Patching with xmlns:{0}={1}", new Object[]{prefix, nss.getURI(prefix)}); } elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:"+prefix, nss.getURI(prefix)); } } } }
Example 13
Source File: StreamMessage.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * There is no way to enumerate inscope namespaces for XMLStreamReader. That means * namespaces declared in envelope, and body tags need to be computed using their * {@link TagInfoset}s. * * @return array of the even length of the form { prefix0, uri0, prefix1, uri1, ... } */ private String[] getInscopeNamespaces() { NamespaceSupport nss = new NamespaceSupport(); nss.pushContext(); for(int i=0; i < envelopeTag.ns.length; i+=2) { nss.declarePrefix(envelopeTag.ns[i], envelopeTag.ns[i+1]); } nss.pushContext(); for(int i=0; i < bodyTag.ns.length; i+=2) { nss.declarePrefix(bodyTag.ns[i], bodyTag.ns[i+1]); } List<String> inscope = new ArrayList<String>(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); inscope.add(prefix); inscope.add(nss.getURI(prefix)); } return inscope.toArray(new String[inscope.size()]); }
Example 14
Source File: AbstractSchemaValidationTube.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Adds inscope namespaces as attributes to <xsd:schema> fragment nodes. * * @param nss namespace context info * @param elem that is patched with inscope namespaces */ private @Nullable void patchDOMFragment(NamespaceSupport nss, Element elem) { NamedNodeMap atts = elem.getAttributes(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); for( int i=0; i<atts.getLength(); i++ ) { Attr a = (Attr)atts.item(i); if (!"xmlns".equals(a.getPrefix()) || !a.getLocalName().equals(prefix)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Patching with xmlns:{0}={1}", new Object[]{prefix, nss.getURI(prefix)}); } elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:"+prefix, nss.getURI(prefix)); } } } }
Example 15
Source File: StreamMessage.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * There is no way to enumerate inscope namespaces for XMLStreamReader. That means * namespaces declared in envelope, and body tags need to be computed using their * {@link TagInfoset}s. * * @return array of the even length of the form { prefix0, uri0, prefix1, uri1, ... } */ private String[] getInscopeNamespaces() { NamespaceSupport nss = new NamespaceSupport(); nss.pushContext(); for(int i=0; i < envelopeTag.ns.length; i+=2) { nss.declarePrefix(envelopeTag.ns[i], envelopeTag.ns[i+1]); } nss.pushContext(); for(int i=0; i < bodyTag.ns.length; i+=2) { nss.declarePrefix(bodyTag.ns[i], bodyTag.ns[i+1]); } List<String> inscope = new ArrayList<String>(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); inscope.add(prefix); inscope.add(nss.getURI(prefix)); } return inscope.toArray(new String[inscope.size()]); }
Example 16
Source File: AbstractSchemaValidationTube.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Adds inscope namespaces as attributes to <xsd:schema> fragment nodes. * * @param nss namespace context info * @param elem that is patched with inscope namespaces */ private @Nullable void patchDOMFragment(NamespaceSupport nss, Element elem) { NamedNodeMap atts = elem.getAttributes(); for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) { String prefix = (String)en.nextElement(); for( int i=0; i<atts.getLength(); i++ ) { Attr a = (Attr)atts.item(i); if (!"xmlns".equals(a.getPrefix()) || !a.getLocalName().equals(prefix)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Patching with xmlns:{0}={1}", new Object[]{prefix, nss.getURI(prefix)}); } elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:"+prefix, nss.getURI(prefix)); } } } }
Example 17
Source File: NSSupportTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test public void testPrefixAndUri2() { boolean hasdc = false; boolean hasdc1 = false; boolean hasdc2 = false; boolean hasdcnew = false; NamespaceSupport nssupport = new NamespaceSupport(); nssupport.pushContext(); nssupport.declarePrefix("dc", "http://www.purl.org/dc"); nssupport.pushContext(); nssupport.declarePrefix("dc1", "http://www.purl.org/dc"); nssupport.declarePrefix("dc2", "http://www.purl.org/dc2"); nssupport.declarePrefix("dcnew", "http://www.purl.org/dcnew"); Enumeration enu1 = nssupport.getPrefixes(); while (enu1.hasMoreElements()) { String str = (String) enu1.nextElement(); if (str.equals("dc")) { hasdc = true; } else if (str.equals("dc1")) { hasdc1 = true; } else if (str.equals("dc2")) { hasdc2 = true; } else if (str.equals("dcnew")) { hasdcnew = true; } } AssertJUnit.assertTrue(hasdcnew && hasdc1 && hasdc2 && hasdc); }
Example 18
Source File: NSSupportTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test public void testPrefixAndUri3() { boolean hasdc = false; boolean hasdc1 = false; boolean hasdc2 = false; boolean hasdcnew = false; NamespaceSupport nssupport = new NamespaceSupport(); nssupport.pushContext(); nssupport.declarePrefix("dc", "http://www.purl.org/dc"); nssupport.pushContext(); nssupport.declarePrefix("dc1", "http://www.purl.org/dc"); nssupport.declarePrefix("dc2", "http://www.purl.org/dc2"); nssupport.declarePrefix("dcnew", "http://www.purl.org/dcnew"); Enumeration enu1 = nssupport.getPrefixes("http://www.purl.org/dc"); while (enu1.hasMoreElements()) { String str = (String) enu1.nextElement(); if (str.equals("dc")) { hasdc = true; } else if (str.equals("dc1")) { hasdc1 = true; } else if (str.equals("dc2")) { hasdc2 = true; } else if (str.equals("dcnew")) { hasdcnew = true; } } AssertJUnit.assertTrue(hasdc1 && hasdc); AssertJUnit.assertFalse(hasdc2); AssertJUnit.assertFalse(hasdcnew); }