Package org.pdf4j.saxon.sort

Examples of org.pdf4j.saxon.sort.IntSet


        // in a DOM created programmatically, this is not necessarily the case. So we need to add
        // namespace bindings for the namespace of the element and any attributes
        if (node.get_NodeType().Value == XmlNodeType.Element) {
            XmlElement elem = (XmlElement)node;
            XmlNamedNodeMap atts = elem.get_Attributes();
            IntSet codes = new IntHashSet();
            NamePool pool = getNamePool();
            for (int i = 0; i < atts.get_Count(); i++) {
                XmlAttribute att = (XmlAttribute)atts.Item(i);
                String attName = att.get_Name();
                if (attName.equals("xmlns")) {
                    String prefix = "";
                    String uri = att.get_Value();
                    codes.add(pool.allocateNamespaceCode(prefix, uri));
                } else if (attName.startsWith("xmlns:")) {
                    String prefix = attName.substring(6);
                    String uri = att.get_Value();
                    codes.add(pool.allocateNamespaceCode(prefix, uri));
                } else if (att.get_NamespaceURI().length() != 0) {
                    codes.add(pool.allocateNamespaceCode(att.get_Prefix(), att.get_NamespaceURI()));
                }
            }

            if (elem.get_NamespaceURI().length() != 0) {
                codes.add(pool.allocateNamespaceCode(elem.get_Prefix(), elem.get_NamespaceURI()));
            }
            int count = codes.size();
            int[] result = new int[count];
            int p = 0;
            for (IntIterator ii = codes.iterator(); ii.hasNext();) {
                 result[p++] = ii.next();
            }
            return result;
        } else {
            return null;
View Full Code Here


    protected void fixupInsertedNamespaces(boolean inherit) {
        if (parent.getNodeKind() == Type.DOCUMENT) {
            return;
        }

        IntSet childNamespaces = new IntHashSet();
        if (namespaceList != null) {
            for (int i=0; i<namespaceList.length; i++) {
                childNamespaces.add(namespaceList[i]);
            }
        }

        NamespaceResolver inscope = new InscopeNamespaceResolver(parent);
        NamePool pool = getNamePool();

        // If the child is in the null namespace but the parent has a default namespace, xmlns="" should be added.

        if (getURI().length()==0 && inscope.getURIForPrefix("", true).length()!=0) {
            childNamespaces.add(0);
        }

        // Namespaces present on the parent but not on the child should be undeclared (if requested)

        if (!inherit) {
            Iterator it = inscope.iteratePrefixes();
            while (it.hasNext()) {
                String prefix = (String)it.next();
                int prefixCode = pool.getCodeForPrefix(prefix)<<16;
                boolean found = false;
                if (namespaceList != null) {
                    for (int i=0; i<namespaceList.length; i++) {
                        if ((namespaceList[i] & 0xffff) == prefixCode) {
                            found = true;
                            break;
                        }
                    }
                }
                if (!found) {
                    childNamespaces.add(prefixCode);
                }
            }
        }

        // Redundant namespaces should be removed

        if (namespaceList != null) {
            for (int i=0; i<namespaceList.length; i++) {
                int nscode = namespaceList[i];
                String prefix = pool.getPrefixFromNamespaceCode(nscode);
                String uri = pool.getURIFromNamespaceCode(nscode);
                String parentUri = inscope.getURIForPrefix(prefix, true);
                if (parentUri != null && parentUri.equals(uri)) {
                    // the namespace declaration is redundant
                    childNamespaces.remove(nscode);
                }
            }
        }
        int[] n2 = new int[childNamespaces.size()];
        int j = 0;
        IntIterator ii = childNamespaces.iterator();
        while (ii.hasNext()) {
            n2[j++] = ii.next();
        }
        namespaceList = n2;
    }
View Full Code Here

TOP

Related Classes of org.pdf4j.saxon.sort.IntSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.