com.sun.org.apache.xalan.internal.xsltc.DOM Java Examples

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.DOM. 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: BasisLibrary.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean compareStrings(String lstring, String rstring,
                                      int op, DOM dom) {
    switch (op) {
case Operators.EQ:
        return lstring.equals(rstring);

case Operators.NE:
        return !lstring.equals(rstring);

case Operators.GT:
        return numberF(lstring, dom) > numberF(rstring, dom);

case Operators.LT:
        return numberF(lstring, dom) < numberF(rstring, dom);

case Operators.GE:
        return numberF(lstring, dom) >= numberF(rstring, dom);

case Operators.LE:
        return numberF(lstring, dom) <= numberF(rstring, dom);

    default:
        runTimeError(RUN_TIME_INTERNAL_ERR, "compare()");
        return false;
    }
}
 
Example #2
Source File: BasisLibrary.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Implements the nodeset() extension function.
 */
public static DTMAxisIterator nodesetF(Object obj) {
    if (obj instanceof DOM) {
       //final DOMAdapter adapter = (DOMAdapter) obj;
       final DOM dom = (DOM)obj;
       return new SingletonIterator(dom.getDocument(), true);
    }
    else if (obj instanceof DTMAxisIterator) {
       return (DTMAxisIterator) obj;
    }
    else {
        final String className = obj.getClass().getName();
        runTimeError(DATA_CONVERSION_ERR, "node-set", className);
        return null;
    }
}
 
Example #3
Source File: BasisLibrary.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Utility function: used to test context node's language
 */
public static boolean testLanguage(String testLang, DOM dom, int node) {
    // language for context node (if any)
    String nodeLang = dom.getLanguage(node);
    if (nodeLang == null)
        return(false);
    else
        nodeLang = nodeLang.toLowerCase();

    // compare context node's language agains test language
    testLang = testLang.toLowerCase();
    if (testLang.length() == 2) {
        return(nodeLang.startsWith(testLang));
    }
    else {
        return(nodeLang.equals(testLang));
    }
}
 
Example #4
Source File: BasisLibrary.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Utility function: used to test context node's language
 */
public static boolean testLanguage(String testLang, DOM dom, int node) {
    // language for context node (if any)
    String nodeLang = dom.getLanguage(node);
    if (nodeLang == null)
        return(false);
    else
        nodeLang = nodeLang.toLowerCase();

    // compare context node's language agains test language
    testLang = testLang.toLowerCase();
    if (testLang.length() == 2) {
        return(nodeLang.startsWith(testLang));
    }
    else {
        return(nodeLang.equals(testLang));
    }
}
 
Example #5
Source File: LoadDocument.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private static DTMAxisIterator document(DTMAxisIterator arg1,
                                        String baseURI,
                                        AbstractTranslet translet, DOM dom)
throws Exception
{
    UnionIterator union = new UnionIterator(dom);
    int node = DTM.NULL;

    while ((node = arg1.next()) != DTM.NULL) {
        String uri = dom.getStringValueX(node);
        //document(node-set) if true;  document(node-set,node-set) if false
        if (baseURI  == null) {
           baseURI = dom.getDocumentURI(node);
           if (!SystemIDResolver.isAbsoluteURI(baseURI))
                baseURI = SystemIDResolver.getAbsoluteURIFromRelative(baseURI);
        }
        union.addIterator(document(uri, baseURI, translet, dom));
    }
    return(union);
}
 
Example #6
Source File: BasisLibrary.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Utility function: used to test context node's language
 */
public static boolean testLanguage(String testLang, DOM dom, int node) {
    // language for context node (if any)
    String nodeLang = dom.getLanguage(node);
    if (nodeLang == null)
        return(false);
    else
        nodeLang = nodeLang.toLowerCase();

    // compare context node's language agains test language
    testLang = testLang.toLowerCase();
    if (testLang.length() == 2) {
        return(nodeLang.startsWith(testLang));
    }
    else {
        return(nodeLang.equals(testLang));
    }
}
 
Example #7
Source File: BasisLibrary.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Implements the nodeset() extension function.
 */
public static DTMAxisIterator nodesetF(Object obj) {
    if (obj instanceof DOM) {
       //final DOMAdapter adapter = (DOMAdapter) obj;
       final DOM dom = (DOM)obj;
       return new SingletonIterator(dom.getDocument(), true);
    }
    else if (obj instanceof DTMAxisIterator) {
       return (DTMAxisIterator) obj;
    }
    else {
        final String className = obj.getClass().getName();
        runTimeError(DATA_CONVERSION_ERR, "node-set", className);
        return null;
    }
}
 
Example #8
Source File: BasisLibrary.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Implements the nodeset() extension function.
 */
public static DTMAxisIterator nodesetF(Object obj) {
    if (obj instanceof DOM) {
       //final DOMAdapter adapter = (DOMAdapter) obj;
       final DOM dom = (DOM)obj;
       return new SingletonIterator(dom.getDocument(), true);
    }
    else if (obj instanceof DTMAxisIterator) {
       return (DTMAxisIterator) obj;
    }
    else {
        final String className = obj.getClass().getName();
        runTimeError(DATA_CONVERSION_ERR, "node-set", className);
        return null;
    }
}
 
Example #9
Source File: BasisLibrary.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static boolean compareStrings(String lstring, String rstring,
                                      int op, DOM dom) {
    switch (op) {
case Operators.EQ:
        return lstring.equals(rstring);

case Operators.NE:
        return !lstring.equals(rstring);

case Operators.GT:
        return numberF(lstring, dom) > numberF(rstring, dom);

case Operators.LT:
        return numberF(lstring, dom) < numberF(rstring, dom);

case Operators.GE:
        return numberF(lstring, dom) >= numberF(rstring, dom);

case Operators.LE:
        return numberF(lstring, dom) <= numberF(rstring, dom);

    default:
        runTimeError(RUN_TIME_INTERNAL_ERR, "compare()");
        return false;
    }
}
 
Example #10
Source File: AbstractTranslet.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an empty KeyIndex in the DOM case
 *   @param name is the name of the index (the key or ##id)
 *   @param dom is the DOM
 */
public void buildKeyIndex(String name, DOM dom) {
    if (_keyIndexes == null) _keyIndexes = new Hashtable();

    KeyIndex index = (KeyIndex)_keyIndexes.get(name);
    if (index == null) {
        _keyIndexes.put(name, index = new KeyIndex(_indexSize));
    }
    index.setDom(dom, dom.getDocument());
}
 
Example #11
Source File: BasisLibrary.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void copy(Object obj,
                        SerializationHandler handler,
                        int node,
                        DOM dom) {
    try {
        if (obj instanceof DTMAxisIterator)
  {
            DTMAxisIterator iter = (DTMAxisIterator) obj;
            dom.copy(iter.reset(), handler);
        }
        else if (obj instanceof Node) {
            dom.copy(((Node) obj).node, handler);
        }
        else if (obj instanceof DOM) {
            //((DOM)obj).copy(((com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase)((DOMAdapter)obj).getDOMImpl()).getDocument(), handler);
            DOM newDom = (DOM)obj;
            newDom.copy(newDom.getDocument(), handler);
        }
        else {
            String string = obj.toString();         // or call stringF()
            final int length = string.length();
            if (length > _characterArray.length)
                _characterArray = new char[length];
            string.getChars(0, length, _characterArray, 0);
            handler.characters(_characterArray, 0, length);
        }
    }
    catch (SAXException e) {
        runTimeError(RUN_TIME_COPY_ERR);
    }
}
 
Example #12
Source File: NodeCounter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected NodeCounter(Translet translet,
          DOM document, DTMAxisIterator iterator, boolean hasFrom) {
    _translet = translet;
    _document = document;
    _iterator = iterator;
    _hasFrom = hasFrom;
}
 
Example #13
Source File: BasisLibrary.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * XSLT Standard function namespace-uri().
 */
public static String namespace_uriF(int node, DOM dom) {
    final String value = dom.getNodeName(node);
    final int colon = value.lastIndexOf(':');
    if (colon >= 0)
        return value.substring(0, colon);
    else
        return EMPTYSTRING;
}
 
Example #14
Source File: BasisLibrary.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * XSLT Standard function namespace-uri().
 */
public static String namespace_uriF(int node, DOM dom) {
    final String value = dom.getNodeName(node);
    final int colon = value.lastIndexOf(':');
    if (colon >= 0)
        return value.substring(0, colon);
    else
        return EMPTYSTRING;
}
 
Example #15
Source File: AbstractTranslet.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an empty KeyIndex in the DOM case
 *   @param name is the name of the index (the key or ##id)
 *   @param dom is the DOM
 */
public void buildKeyIndex(String name, DOM dom) {
    if (_keyIndexes == null) _keyIndexes = new Hashtable();

    KeyIndex index = (KeyIndex)_keyIndexes.get(name);
    if (index == null) {
        _keyIndexes.put(name, index = new KeyIndex(_indexSize));
    }
    index.setDom(dom, dom.getDocument());
}
 
Example #16
Source File: BasisLibrary.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Utility function used to convert references to DOMs.
 */
public static DOM referenceToResultTree(Object obj) {
    try {
        return ((DOM) obj);
    }
    catch (IllegalArgumentException e) {
        final String className = obj.getClass().getName();
        runTimeError(DATA_CONVERSION_ERR, "reference", className);
        return null;
    }
}
 
Example #17
Source File: AdaptiveResultTreeImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public DOM getResultTreeFrag(int initialSize, int rtfType)
{
    if (_dom != null) {
        return _dom.getResultTreeFrag(initialSize, rtfType);
    }
    else {
        return super.getResultTreeFrag(initialSize, rtfType);
    }
}
 
Example #18
Source File: BasisLibrary.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void copy(Object obj,
                        SerializationHandler handler,
                        int node,
                        DOM dom) {
    try {
        if (obj instanceof DTMAxisIterator)
  {
            DTMAxisIterator iter = (DTMAxisIterator) obj;
            dom.copy(iter.reset(), handler);
        }
        else if (obj instanceof Node) {
            dom.copy(((Node) obj).node, handler);
        }
        else if (obj instanceof DOM) {
            //((DOM)obj).copy(((com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase)((DOMAdapter)obj).getDOMImpl()).getDocument(), handler);
            DOM newDom = (DOM)obj;
            newDom.copy(newDom.getDocument(), handler);
        }
        else {
            String string = obj.toString();         // or call stringF()
            final int length = string.length();
            if (length > _characterArray.length)
                _characterArray = new char[length];
            string.getChars(0, length, _characterArray, 0);
            handler.characters(_characterArray, 0, length);
        }
    }
    catch (SAXException e) {
        runTimeError(RUN_TIME_COPY_ERR);
    }
}
 
Example #19
Source File: DOMAdapter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a instance of a DOM class to be used as an RTF
 */
public DOM getResultTreeFrag(int initSize, int rtfType)
{
    if (_enhancedDOM != null) {
        return _enhancedDOM.getResultTreeFrag(initSize, rtfType);
    }
    else {
        return _dom.getResultTreeFrag(initSize, rtfType);
    }
}
 
Example #20
Source File: BasisLibrary.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * XSLT Standard function namespace-uri().
 */
public static String namespace_uriF(int node, DOM dom) {
    final String value = dom.getNodeName(node);
    final int colon = value.lastIndexOf(':');
    if (colon >= 0)
        return value.substring(0, colon);
    else
        return EMPTYSTRING;
}
 
Example #21
Source File: MultiDOM.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public DOM getDOMAdapter(String uri) {
    Integer domIdx = _documents.get(uri);
    if (domIdx == null) {
        return(null);
    } else {
        return(_adapters[domIdx.intValue()]);
    }
}
 
Example #22
Source File: TransformerImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This class should only be used as a DOMCache for the translet if the
 * URIResolver has been set.
 *
 * The method implements XSLTC's DOMCache interface, which is used to
 * plug in an external document loader into a translet. This method acts
 * as an adapter between TrAX's URIResolver interface and XSLTC's
 * DOMCache interface. This approach is simple, but removes the
 * possibility of using external document caches with XSLTC.
 *
 * @param baseURI The base URI used by the document call.
 * @param href The href argument passed to the document function.
 * @param translet A reference to the translet requesting the document
 */
@Override
public DOM retrieveDocument(String baseURI, String href, Translet translet) {
    try {
        // Argument to document function was: document('');
        if (href.length() == 0) {
            href = baseURI;
        }

        /*
         *  Fix for bug 24188
         *  Incase the _uriResolver.resolve(href,base) is null
         *  try to still  retrieve the document before returning null
         *  and throwing the FileNotFoundException in
         *  com.sun.org.apache.xalan.internal.xsltc.dom.LoadDocument
         *
         */
        Source resolvedSource = _uriResolver.resolve(href, baseURI);
        if (resolvedSource == null)  {
            StreamSource streamSource = new StreamSource(
                 SystemIDResolver.getAbsoluteURI(href, baseURI));
            return getDOM(streamSource) ;
        }

        return getDOM(resolvedSource);
    }
    catch (TransformerException e) {
        if (_errorListener != null)
            postErrorToListener("File not found: " + e.getMessage());
        return(null);
    }
}
 
Example #23
Source File: BasisLibrary.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Utility function used to convert references to DOMs.
 */
public static DOM referenceToResultTree(Object obj) {
    try {
        return ((DOM) obj);
    }
    catch (IllegalArgumentException e) {
        final String className = obj.getClass().getName();
        runTimeError(DATA_CONVERSION_ERR, "reference", className);
        return null;
    }
}
 
Example #24
Source File: AbstractTranslet.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Calls transform() with a given output handler
 */
public final void transform(DOM document, SerializationHandler handler)
    throws TransletException {
    try {
        transform(document, document.getIterator(), handler);
    } finally {
        _keyIndexes = null;
    }
}
 
Example #25
Source File: DOMAdapter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a instance of a DOM class to be used as an RTF
 */
public DOM getResultTreeFrag(int initSize, int rtfType,
                             boolean addToManager)
{
    if (_enhancedDOM != null) {
        return _enhancedDOM.getResultTreeFrag(initSize, rtfType,
                                              addToManager);
    }
    else {
        return _dom.getResultTreeFrag(initSize, rtfType, addToManager);
    }
}
 
Example #26
Source File: TransformerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This class should only be used as a DOMCache for the translet if the
 * URIResolver has been set.
 *
 * The method implements XSLTC's DOMCache interface, which is used to
 * plug in an external document loader into a translet. This method acts
 * as an adapter between TrAX's URIResolver interface and XSLTC's
 * DOMCache interface. This approach is simple, but removes the
 * possibility of using external document caches with XSLTC.
 *
 * @param baseURI The base URI used by the document call.
 * @param href The href argument passed to the document function.
 * @param translet A reference to the translet requesting the document
 */
@Override
public DOM retrieveDocument(String baseURI, String href, Translet translet) {
    try {
        // Argument to document function was: document('');
        if (href.length() == 0) {
            href = baseURI;
        }

        /*
         *  Fix for bug 24188
         *  Incase the _uriResolver.resolve(href,base) is null
         *  try to still  retrieve the document before returning null
         *  and throwing the FileNotFoundException in
         *  com.sun.org.apache.xalan.internal.xsltc.dom.LoadDocument
         *
         */
        Source resolvedSource = _uriResolver.resolve(href, baseURI);
        if (resolvedSource == null)  {
            StreamSource streamSource = new StreamSource(
                 SystemIDResolver.getAbsoluteURI(href, baseURI));
            return getDOM(streamSource) ;
        }

        return getDOM(resolvedSource);
    }
    catch (TransformerException e) {
        if (_errorListener != null)
            postErrorToListener("File not found: " + e.getMessage());
        return(null);
    }
}
 
Example #27
Source File: AbstractTranslet.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Leverages the Key Class to implement the XSLT id() function.
 * buildIdIndex creates the index (##id) that Key Class uses.
 * The index contains the element node index (int) and Id value (String).
 */
private final void buildIDIndex(DOM document) {
    setRootForKeys(document.getDocument());

    if (document instanceof DOMEnhancedForDTM) {
        DOMEnhancedForDTM enhancedDOM = (DOMEnhancedForDTM)document;

        // If the input source is DOMSource, the KeyIndex table is not
        // built at this time. It will be built later by the lookupId()
        // and containsId() methods of the KeyIndex class.
        if (enhancedDOM.hasDOMSource()) {
            buildKeyIndex(ID_INDEX_NAME, document);
            return;
        }
        else {
            final Map<String, Integer> elementsByID = enhancedDOM.getElementsWithIDs();

            if (elementsByID == null) {
                return;
            }

            // Given a Map of DTM nodes indexed by ID attribute values,
            // loop through the table copying information to a KeyIndex
            // for the mapping from ID attribute value to DTM node
            boolean hasIDValues = false;
            for (Map.Entry<String, Integer> entry : elementsByID.entrySet()) {
                final int element = document.getNodeHandle(entry.getValue());
                buildKeyIndex(ID_INDEX_NAME, element, entry.getKey());
                hasIDValues = true;
            }

            if (hasIDValues) {
                setKeyIndexDom(ID_INDEX_NAME, document);
            }
        }
    }
}
 
Example #28
Source File: DOMAdapter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a instance of a DOM class to be used as an RTF
 */
public DOM getResultTreeFrag(int initSize, int rtfType)
{
    if (_enhancedDOM != null) {
        return _enhancedDOM.getResultTreeFrag(initSize, rtfType);
    }
    else {
        return _dom.getResultTreeFrag(initSize, rtfType);
    }
}
 
Example #29
Source File: MultiDOM.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private boolean isMatchingAdapterEntry(DOM entry, DOMAdapter adapter) {
    DOM dom = adapter.getDOMImpl();

    return (entry == adapter) || (
        /*
         * Method addDOMAdapter overwrites for AdaptiveResultTreeImpl
         * objects the usual entry with an adapter to the nested
         * DOM, so we must check this here. See last 'if' statement
         * of addDOMAdapter.
         */
        (dom instanceof AdaptiveResultTreeImpl) &&
        (entry instanceof DOMAdapter) &&
        (((AdaptiveResultTreeImpl)dom).getNestedDOM() == ((DOMAdapter)entry).getDOMImpl())
    );
}
 
Example #30
Source File: BasisLibrary.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Utility function: node-set/node-set compare.
 */
public static boolean compare(DTMAxisIterator left, DTMAxisIterator right,
                              int op, DOM dom) {
    int lnode;
    left.reset();

    while ((lnode = left.next()) != DTMAxisIterator.END) {
        final String lvalue = dom.getStringValueX(lnode);

        int rnode;
        right.reset();
        while ((rnode = right.next()) != DTMAxisIterator.END) {
            // String value must be the same if both nodes are the same
            if (lnode == rnode) {
                if (op == Operators.EQ) {
                    return true;
                } else if (op == Operators.NE) {
                    continue;
                }
            }
            if (compareStrings(lvalue, dom.getStringValueX(rnode), op,
                               dom)) {
                return true;
            }
        }
    }
    return false;
}