当前位置: 首页>>代码示例>>Java>>正文


Java NamespaceSupport.getPrefixes方法代码示例

本文整理汇总了Java中org.xml.sax.helpers.NamespaceSupport.getPrefixes方法的典型用法代码示例。如果您正苦于以下问题:Java NamespaceSupport.getPrefixes方法的具体用法?Java NamespaceSupport.getPrefixes怎么用?Java NamespaceSupport.getPrefixes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.xml.sax.helpers.NamespaceSupport的用法示例。


在下文中一共展示了NamespaceSupport.getPrefixes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getInscopeNamespaces

import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
/**
 * 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()]);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:StreamMessage.java

示例2: patchDOMFragment

import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
/**
 * 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));
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:AbstractSchemaValidationTube.java

示例3: testPrefixAndUri2

import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
@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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:NSSupportTest.java

示例4: testPrefixAndUri3

import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
@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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:NSSupportTest.java

示例5: patchDOMFragment

import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
/**
 * 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)) {
                LOGGER.fine("Patching with xmlns:"+prefix+"="+nss.getURI(prefix));
                elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:"+prefix, nss.getURI(prefix));
            }
        }
    }
}
 
开发者ID:alexkasko,项目名称:openjdk-icedtea7,代码行数:21,代码来源:AbstractSchemaValidationTube.java


注:本文中的org.xml.sax.helpers.NamespaceSupport.getPrefixes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。