📄 basislibrary.java
字号:
* constructs, and never really tries to call it if it doesn't exist. * But simple stylesheets may result in a call to this method. * The compiler should generate a warning if it encounters a call to * an unresolved external function. */ public static void unresolved_externalF(String name) { runTimeError(EXTERNAL_FUNC_ERR, name); } /** * Utility function to throw a runtime error on the use of an extension * function when the secure processing feature is set to true. */ public static void unallowed_extension_functionF(String name) { runTimeError(UNALLOWED_EXTENSION_FUNCTION_ERR, name); } /** * Utility function to throw a runtime error on the use of an extension * element when the secure processing feature is set to true. */ public static void unallowed_extension_elementF(String name) { runTimeError(UNALLOWED_EXTENSION_ELEMENT_ERR, name); } /** * Utility function to throw a runtime error for an unsupported element. * * This is only used in forward-compatibility mode, when the control flow * cannot be determined. In 1.0 mode, the error message is emitted at * compile time. */ public static void unsupported_ElementF(String qname, boolean isExtension) { if (isExtension) runTimeError(UNSUPPORTED_EXT_ERR, qname); else runTimeError(UNSUPPORTED_XSL_ERR, qname); } /** * XSLT Standard function namespace-uri(node-set). */ public static String namespace_uriF(DTMAxisIterator iter, DOM dom) { return namespace_uriF(iter.next(), dom); } /** * XSLT Standard function system-property(name) */ public static String system_propertyF(String name) { if (name.equals("xsl:version")) return("1.0"); if (name.equals("xsl:vendor")) return("Apache Software Foundation (Xalan XSLTC)"); if (name.equals("xsl:vendor-url")) return("http://xml.apache.org/xalan-j"); runTimeError(INVALID_ARGUMENT_ERR, name, "system-property()"); return(EMPTYSTRING); } /** * 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; } /** * Implements the object-type() extension function. * * @see <a href="http://www.exslt.org/">EXSLT</a> */ public static String objectTypeF(Object obj) { if (obj instanceof String) return "string"; else if (obj instanceof Boolean) return "boolean"; else if (obj instanceof Number) return "number"; else if (obj instanceof DOM) return "RTF"; else if (obj instanceof DTMAxisIterator) return "node-set"; else return "unknown"; } /** * 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; } } //-- Begin utility functions private static boolean isWhiteSpace(char ch) { return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'; } 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; } } /** * 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; } public static boolean compare(int node, DTMAxisIterator iterator, int op, DOM dom) { //iterator.reset(); int rnode; String value; switch(op) { case Operators.EQ: rnode = iterator.next(); if (rnode != DTMAxisIterator.END) { value = dom.getStringValueX(node); do { if (node == rnode || value.equals(dom.getStringValueX(rnode))) { return true; } } while ((rnode = iterator.next()) != DTMAxisIterator.END); } break; case Operators.NE: rnode = iterator.next(); if (rnode != DTMAxisIterator.END) { value = dom.getStringValueX(node); do { if (node != rnode && !value.equals(dom.getStringValueX(rnode))) { return true; } } while ((rnode = iterator.next()) != DTMAxisIterator.END); } break; case Operators.LT: // Assume we're comparing document order here while ((rnode = iterator.next()) != DTMAxisIterator.END) { if (rnode > node) return true; } break; case Operators.GT: // Assume we're comparing document order here while ((rnode = iterator.next()) != DTMAxisIterator.END) { if (rnode < node) return true; } break; } return(false); } /** * Utility function: node-set/number compare. */ public static boolean compare(DTMAxisIterator left, final double rnumber, final int op, DOM dom) { int node; //left.reset(); switch (op) { case Operators.EQ: while ((node = left.next()) != DTMAxisIterator.END) { if (numberF(dom.getStringValueX(node), dom) == rnumber) return true; } break; case Operators.NE: while ((node = left.next()) != DTMAxisIterator.END) { if (numberF(dom.getStringValueX(node), dom) != rnumber) return true; } break; case Operators.GT: while ((node = left.next()) != DTMAxisIterator.END) { if (numberF(dom.getStringValueX(node), dom) > rnumber) return true; } break; case Operators.LT: while ((node = left.next()) != DTMAxisIterator.END) { if (numberF(dom.getStringValueX(node), dom) < rnumber) return true; } break; case Operators.GE: while ((node = left.next()) != DTMAxisIterator.END) { if (numberF(dom.getStringValueX(node), dom) >= rnumber) return true; } break; case Operators.LE: while ((node = left.next()) != DTMAxisIterator.END) { if (numberF(dom.getStringValueX(node), dom) <= rnumber) return true; } break; default: runTimeError(RUN_TIME_INTERNAL_ERR, "compare()"); } return false; } /** * Utility function: node-set/string comparison. */ public static boolean compare(DTMAxisIterator left, final String rstring, int op, DOM dom) { int node; //left.reset(); while ((node = left.next()) != DTMAxisIterator.END) { if (compareStrings(dom.getStringValueX(node), rstring, op, dom)) { return true; } } return false; } public static boolean compare(Object left, Object right, int op, DOM dom) { boolean result = false; boolean hasSimpleArgs = hasSimpleType(left) && hasSimpleType(right); if (op != Operators.EQ && op != Operators.NE) { // If node-boolean comparison -> convert node to boolean if (left instanceof Node || right instanceof Node) { if (left instanceof Boolean) { right = new Boolean(booleanF(right)); hasSimpleArgs = true; } if (right instanceof Boolean) { left = new Boolean(booleanF(left)); hasSimpleArgs = true; } } if (hasSimpleArgs) { switch (op) { case Operators.GT: return numberF(left, dom) > numberF(right, dom); case Operators.LT: return numberF(left, dom) < numberF(right, dom); case Operators.GE: return numberF(left, dom) >= numberF(right, dom); case Operators.LE: return numberF(left, dom) <= numberF(right, dom); default: runTimeError(RUN_TIME_INTERNAL_ERR, "compare()"); } } // falls through } if (hasSimpleArgs) { if (left instanceof Boolean || right instanceof Boolean) { result = booleanF(left) == booleanF(right); } else if (left instanceof Double || right instanceof Double || left instanceof Integer || right instanceof Integer) { result = numberF(left, dom) == numberF(right, dom); } else { // compare them as strings result = stringF(left, dom).equals(stringF(right, dom)); } if (op == Operators.NE) { result = !result; } } else { if (left instanceof Node) { left = new SingletonIterator(((Node)left).node); } if (right instanceof Node) { right = new SingletonIterator(((Node)right).node); } if (hasSimpleType(left) || left instanceof DOM && right instanceof DTMAxisIterator) { // swap operands and operator final Object temp = right; right = left; left = temp; op = Operators.swapOp(op); } if (left instanceof DOM) { if (right instanceof Boolean) { result = ((Boolean)right).booleanValue(); return result == (op == Operators.EQ); } final String sleft = ((DOM)left).getStringValue(); if (right instanceof Number) { result = ((Number)right).doubleValue() == stringToReal(sleft); } else if (right instanceof String) { result = sleft.equals((String)right); } else if (right instanceof DOM) { result = sleft.equals(((DOM)right).getStringValue()); } if (op == Operators.NE) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -