org.xml.sax.helpers.NamespaceSupport#getPrefixes ( )源码实例Demo

下面列出了org.xml.sax.helpers.NamespaceSupport#getPrefixes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TencentKona-8   文件: StreamMessage.java
/**
 * 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()]);
}
 
/**
 * 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));
            }
        }
    }
}
 
源代码3 项目: jdk8u60   文件: StreamMessage.java
/**
 * 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()]);
}
 
源代码4 项目: jdk8u60   文件: AbstractSchemaValidationTube.java
/**
 * 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));
            }
        }
    }
}
 
源代码5 项目: openjdk-jdk8u   文件: StreamMessage.java
/**
 * 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()]);
}
 
/**
 * 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));
            }
        }
    }
}
 
源代码7 项目: openjdk-jdk8u-backup   文件: StreamMessage.java
/**
 * 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()]);
}
 
/**
 * 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));
            }
        }
    }
}
 
源代码9 项目: openjdk-jdk9   文件: StreamMessage.java
/**
 * 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()]);
}
 
/**
 * 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));
            }
        }
    }
}
 
源代码11 项目: hottub   文件: StreamMessage.java
/**
 * 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()]);
}
 
源代码12 项目: hottub   文件: AbstractSchemaValidationTube.java
/**
 * 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));
            }
        }
    }
}
 
源代码13 项目: openjdk-8-source   文件: StreamMessage.java
/**
 * 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()]);
}
 
/**
 * 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));
            }
        }
    }
}
 
源代码15 项目: openjdk-8   文件: StreamMessage.java
/**
 * 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()]);
}
 
源代码16 项目: openjdk-8   文件: AbstractSchemaValidationTube.java
/**
 * 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));
            }
        }
    }
}
 
源代码17 项目: openjdk-jdk9   文件: NSSupportTest.java
@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);
}
 
源代码18 项目: openjdk-jdk9   文件: NSSupportTest.java
@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);
}