java类org.xml.sax.helpers.NamespaceSupport的实例源码

StreamMessage.java 文件源码 项目:OpenJSharp 阅读 45 收藏 0 点赞 0 评论 0
/**
 * 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()]);
}
AbstractSchemaValidationTube.java 文件源码 项目:OpenJSharp 阅读 32 收藏 0 点赞 0 评论 0
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
    if (node==null || node.getNodeType()!=Node.ELEMENT_NODE) {
        return;
    }

    buildNamespaceSupport( nss, node.getParentNode() );

    nss.pushContext();
    NamedNodeMap atts = node.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( "xmlns".equals(a.getPrefix()) ) {
            nss.declarePrefix( a.getLocalName(), a.getValue() );
            continue;
        }
        if( "xmlns".equals(a.getName()) ) {
            nss.declarePrefix( "", a.getValue() );
            //continue;
        }
    }
}
AbstractSchemaValidationTube.java 文件源码 项目:OpenJSharp 阅读 37 收藏 0 点赞 0 评论 0
/**
 * 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));
            }
        }
    }
}
DOMScanner.java 文件源码 项目:OpenJSharp 阅读 43 收藏 0 点赞 0 评论 0
/**
 * Recursively visit ancestors and build up {@link NamespaceSupport} oject.
 */
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
    if(node==null || node.getNodeType()!=Node.ELEMENT_NODE)
        return;

    buildNamespaceSupport( nss, node.getParentNode() );

    nss.pushContext();
    NamedNodeMap atts = node.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( "xmlns".equals(a.getPrefix()) ) {
            nss.declarePrefix( a.getLocalName(), a.getValue() );
            continue;
        }
        if( "xmlns".equals(a.getName()) ) {
            nss.declarePrefix( "", a.getValue() );
            continue;
        }
    }
}
XMLDOMWriterImpl.java 文件源码 项目:OpenJSharp 阅读 41 收藏 0 点赞 0 评论 0
/**
 * Creates a new instance of XMLDOMwriterImpl
 * @param result DOMResult object @javax.xml.transform.dom.DOMResult
 */
public XMLDOMWriterImpl(DOMResult result) {

    node = result.getNode();
    if( node.getNodeType() == Node.DOCUMENT_NODE){
        ownerDoc = (Document)node;
        currentNode = ownerDoc;
    }else{
        ownerDoc = node.getOwnerDocument();
        currentNode = node;
    }
    getDLThreeMethods();
    stringBuffer = new StringBuffer();
    needContextPop = new boolean[resizeValue];
    namespaceContext = new NamespaceSupport();
}
StreamMessage.java 文件源码 项目:openjdk-jdk10 阅读 41 收藏 0 点赞 0 评论 0
/**
 * 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()]);
}
AbstractSchemaValidationTube.java 文件源码 项目:openjdk-jdk10 阅读 41 收藏 0 点赞 0 评论 0
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
    if (node==null || node.getNodeType()!=Node.ELEMENT_NODE) {
        return;
    }

    buildNamespaceSupport( nss, node.getParentNode() );

    nss.pushContext();
    NamedNodeMap atts = node.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( "xmlns".equals(a.getPrefix()) ) {
            nss.declarePrefix( a.getLocalName(), a.getValue() );
            continue;
        }
        if( "xmlns".equals(a.getName()) ) {
            nss.declarePrefix( "", a.getValue() );
            //continue;
        }
    }
}
AbstractSchemaValidationTube.java 文件源码 项目:openjdk-jdk10 阅读 40 收藏 0 点赞 0 评论 0
/**
 * 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));
            }
        }
    }
}
DOMScanner.java 文件源码 项目:openjdk-jdk10 阅读 37 收藏 0 点赞 0 评论 0
/**
 * Recursively visit ancestors and build up {@link NamespaceSupport} oject.
 */
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
    if(node==null || node.getNodeType()!=Node.ELEMENT_NODE)
        return;

    buildNamespaceSupport( nss, node.getParentNode() );

    nss.pushContext();
    NamedNodeMap atts = node.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( "xmlns".equals(a.getPrefix()) ) {
            nss.declarePrefix( a.getLocalName(), a.getValue() );
            continue;
        }
        if( "xmlns".equals(a.getName()) ) {
            nss.declarePrefix( "", a.getValue() );
            continue;
        }
    }
}
NSSupportTest.java 文件源码 项目:openjdk-jdk10 阅读 32 收藏 0 点赞 0 评论 0
@Test
public void testProcessName() {
    NamespaceSupport nssupport = new NamespaceSupport();

    nssupport.pushContext();
    nssupport.declarePrefix("", "http://www.java.com");
    nssupport.declarePrefix("dc", "http://www.purl.org/dc");

    String[] parts = new String[3];
    nssupport.processName("dc:name1", parts, false);
    Assert.assertTrue(parts[0].equals("http://www.purl.org/dc"));
    Assert.assertTrue(parts[1].equals("name1"));
    Assert.assertTrue(parts[2].equals("dc:name1"));

    nssupport.processName("name2", parts, false);
    Assert.assertTrue(parts[0].equals("http://www.java.com"));
    Assert.assertTrue(parts[1].equals("name2"));
    Assert.assertTrue(parts[2].equals("name2"));
}
NSSupportTest.java 文件源码 项目:openjdk-jdk10 阅读 37 收藏 0 点赞 0 评论 0
@Test
public void testPopContext() {
    String[] parts = new String[3];
    NamespaceSupport nssupport = new NamespaceSupport();

    nssupport.pushContext();
    nssupport.declarePrefix("dc", "http://www.purl.org/dc");
    Assert.assertEquals(nssupport.getPrefix("http://www.purl.org/dc"), "dc");

    nssupport.popContext();
    Assert.assertNull(nssupport.getPrefix("http://www.purl.org/dc"));
    nssupport.processName("dc:name1", parts, false);
    Assert.assertNull(parts[0]);
    Assert.assertNull(parts[1]);
    Assert.assertNull(parts[2]);
}
NSSupportTest.java 文件源码 项目:openjdk-jdk10 阅读 24 收藏 0 点赞 0 评论 0
@Test
public void testPrefixAndUri4() {
    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");

    AssertJUnit.assertTrue(nssupport.getURI("dc").equals("http://www.purl.org/dc"));
    AssertJUnit.assertTrue(nssupport.getURI("dc1").equals("http://www.purl.org/dc"));
    AssertJUnit.assertTrue(nssupport.getURI("dc2").equals("http://www.purl.org/dc2"));
    AssertJUnit.assertTrue(nssupport.getURI("dcnew").equals("http://www.purl.org/dcnew"));

    // Negative test
    Assert.assertNull(nssupport.getURI("wrong_prefix"));
    Assert.assertNull(nssupport.getURI(""));
}
NSSupportTest.java 文件源码 项目:openjdk-jdk10 阅读 35 收藏 0 点赞 0 评论 0
/**
 * Test for NamespaceSupport.getDeclaredPrefixes().
 */
@Test
public void testcase01() {
    String[] prefixes = new String[2];
    NamespaceSupport support = new NamespaceSupport();
    support.pushContext();
    support.declarePrefix(EMPTY_PREFIX, W3_URI);
    support.declarePrefix(DC_PREFIX, PURL_URI);

    Enumeration e = support.getDeclaredPrefixes();
    int i = 0;
    while(e.hasMoreElements()) {
        prefixes[i++] = e.nextElement().toString();
    }
    support.popContext();

    assertEquals(prefixes, new String[]{EMPTY_PREFIX, DC_PREFIX});
}
StreamMessage.java 文件源码 项目:openjdk9 阅读 31 收藏 0 点赞 0 评论 0
/**
 * 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()]);
}
AbstractSchemaValidationTube.java 文件源码 项目:openjdk9 阅读 38 收藏 0 点赞 0 评论 0
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
    if (node==null || node.getNodeType()!=Node.ELEMENT_NODE) {
        return;
    }

    buildNamespaceSupport( nss, node.getParentNode() );

    nss.pushContext();
    NamedNodeMap atts = node.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( "xmlns".equals(a.getPrefix()) ) {
            nss.declarePrefix( a.getLocalName(), a.getValue() );
            continue;
        }
        if( "xmlns".equals(a.getName()) ) {
            nss.declarePrefix( "", a.getValue() );
            //continue;
        }
    }
}
AbstractSchemaValidationTube.java 文件源码 项目:openjdk9 阅读 45 收藏 0 点赞 0 评论 0
/**
 * 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));
            }
        }
    }
}
DOMScanner.java 文件源码 项目:openjdk9 阅读 37 收藏 0 点赞 0 评论 0
/**
 * Recursively visit ancestors and build up {@link NamespaceSupport} oject.
 */
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
    if(node==null || node.getNodeType()!=Node.ELEMENT_NODE)
        return;

    buildNamespaceSupport( nss, node.getParentNode() );

    nss.pushContext();
    NamedNodeMap atts = node.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( "xmlns".equals(a.getPrefix()) ) {
            nss.declarePrefix( a.getLocalName(), a.getValue() );
            continue;
        }
        if( "xmlns".equals(a.getName()) ) {
            nss.declarePrefix( "", a.getValue() );
            continue;
        }
    }
}
NSSupportTest.java 文件源码 项目:openjdk9 阅读 36 收藏 0 点赞 0 评论 0
@Test
public void testProcessName() {
    NamespaceSupport nssupport = new NamespaceSupport();

    nssupport.pushContext();
    nssupport.declarePrefix("", "http://www.java.com");
    nssupport.declarePrefix("dc", "http://www.purl.org/dc");

    String[] parts = new String[3];
    nssupport.processName("dc:name1", parts, false);
    Assert.assertTrue(parts[0].equals("http://www.purl.org/dc"));
    Assert.assertTrue(parts[1].equals("name1"));
    Assert.assertTrue(parts[2].equals("dc:name1"));

    nssupport.processName("name2", parts, false);
    Assert.assertTrue(parts[0].equals("http://www.java.com"));
    Assert.assertTrue(parts[1].equals("name2"));
    Assert.assertTrue(parts[2].equals("name2"));
}
NSSupportTest.java 文件源码 项目:openjdk9 阅读 25 收藏 0 点赞 0 评论 0
@Test
public void testPopContext() {
    String[] parts = new String[3];
    NamespaceSupport nssupport = new NamespaceSupport();

    nssupport.pushContext();
    nssupport.declarePrefix("dc", "http://www.purl.org/dc");
    Assert.assertEquals(nssupport.getPrefix("http://www.purl.org/dc"), "dc");

    nssupport.popContext();
    Assert.assertNull(nssupport.getPrefix("http://www.purl.org/dc"));
    nssupport.processName("dc:name1", parts, false);
    Assert.assertNull(parts[0]);
    Assert.assertNull(parts[1]);
    Assert.assertNull(parts[2]);
}
NSSupportTest.java 文件源码 项目:openjdk9 阅读 41 收藏 0 点赞 0 评论 0
@Test
public void testPrefixAndUri4() {
    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");

    AssertJUnit.assertTrue(nssupport.getURI("dc").equals("http://www.purl.org/dc"));
    AssertJUnit.assertTrue(nssupport.getURI("dc1").equals("http://www.purl.org/dc"));
    AssertJUnit.assertTrue(nssupport.getURI("dc2").equals("http://www.purl.org/dc2"));
    AssertJUnit.assertTrue(nssupport.getURI("dcnew").equals("http://www.purl.org/dcnew"));

    // Negative test
    Assert.assertNull(nssupport.getURI("wrong_prefix"));
    Assert.assertNull(nssupport.getURI(""));
}
NSSupportTest.java 文件源码 项目:openjdk9 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Test for NamespaceSupport.getDeclaredPrefixes().
 */
@Test
public void testcase01() {
    String[] prefixes = new String[2];
    NamespaceSupport support = new NamespaceSupport();
    support.pushContext();
    support.declarePrefix(EMPTY_PREFIX, W3_URI);
    support.declarePrefix(DC_PREFIX, PURL_URI);

    Enumeration e = support.getDeclaredPrefixes();
    int i = 0;
    while(e.hasMoreElements()) {
        prefixes[i++] = e.nextElement().toString();
    }
    support.popContext();

    assertEquals(prefixes, new String[]{EMPTY_PREFIX, DC_PREFIX});
}
StreamMessage.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 36 收藏 0 点赞 0 评论 0
/**
 * 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()]);
}
AbstractSchemaValidationTube.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 59 收藏 0 点赞 0 评论 0
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
    if (node==null || node.getNodeType()!=Node.ELEMENT_NODE) {
        return;
    }

    buildNamespaceSupport( nss, node.getParentNode() );

    nss.pushContext();
    NamedNodeMap atts = node.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( "xmlns".equals(a.getPrefix()) ) {
            nss.declarePrefix( a.getLocalName(), a.getValue() );
            continue;
        }
        if( "xmlns".equals(a.getName()) ) {
            nss.declarePrefix( "", a.getValue() );
            //continue;
        }
    }
}
AbstractSchemaValidationTube.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 32 收藏 0 点赞 0 评论 0
/**
 * 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));
            }
        }
    }
}
DOMScanner.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 44 收藏 0 点赞 0 评论 0
/**
 * Recursively visit ancestors and build up {@link NamespaceSupport} oject.
 */
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
    if(node==null || node.getNodeType()!=Node.ELEMENT_NODE)
        return;

    buildNamespaceSupport( nss, node.getParentNode() );

    nss.pushContext();
    NamedNodeMap atts = node.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( "xmlns".equals(a.getPrefix()) ) {
            nss.declarePrefix( a.getLocalName(), a.getValue() );
            continue;
        }
        if( "xmlns".equals(a.getName()) ) {
            nss.declarePrefix( "", a.getValue() );
            continue;
        }
    }
}
XMLDOMWriterImpl.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 39 收藏 0 点赞 0 评论 0
/**
 * Creates a new instance of XMLDOMwriterImpl
 * @param result DOMResult object @javax.xml.transform.dom.DOMResult
 */
public XMLDOMWriterImpl(DOMResult result) {

    node = result.getNode();
    if( node.getNodeType() == Node.DOCUMENT_NODE){
        ownerDoc = (Document)node;
        currentNode = ownerDoc;
    }else{
        ownerDoc = node.getOwnerDocument();
        currentNode = node;
    }
    getDLThreeMethods();
    stringBuffer = new StringBuffer();
    needContextPop = new boolean[resizeValue];
    namespaceContext = new NamespaceSupport();
}
StreamMessage.java 文件源码 项目:infobip-open-jdk-8 阅读 46 收藏 0 点赞 0 评论 0
/**
 * 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()]);
}
AbstractSchemaValidationTube.java 文件源码 项目:infobip-open-jdk-8 阅读 36 收藏 0 点赞 0 评论 0
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
    if (node==null || node.getNodeType()!=Node.ELEMENT_NODE) {
        return;
    }

    buildNamespaceSupport( nss, node.getParentNode() );

    nss.pushContext();
    NamedNodeMap atts = node.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( "xmlns".equals(a.getPrefix()) ) {
            nss.declarePrefix( a.getLocalName(), a.getValue() );
            continue;
        }
        if( "xmlns".equals(a.getName()) ) {
            nss.declarePrefix( "", a.getValue() );
            //continue;
        }
    }
}
AbstractSchemaValidationTube.java 文件源码 项目:infobip-open-jdk-8 阅读 36 收藏 0 点赞 0 评论 0
/**
 * 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));
            }
        }
    }
}
DOMScanner.java 文件源码 项目:infobip-open-jdk-8 阅读 47 收藏 0 点赞 0 评论 0
/**
 * Recursively visit ancestors and build up {@link NamespaceSupport} oject.
 */
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
    if(node==null || node.getNodeType()!=Node.ELEMENT_NODE)
        return;

    buildNamespaceSupport( nss, node.getParentNode() );

    nss.pushContext();
    NamedNodeMap atts = node.getAttributes();
    for( int i=0; i<atts.getLength(); i++ ) {
        Attr a = (Attr)atts.item(i);
        if( "xmlns".equals(a.getPrefix()) ) {
            nss.declarePrefix( a.getLocalName(), a.getValue() );
            continue;
        }
        if( "xmlns".equals(a.getName()) ) {
            nss.declarePrefix( "", a.getValue() );
            continue;
        }
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号