📄 runxqts.java
字号:
i2++; } else if (c1 == c2) { if (c1 == '<' && isXML) { intag = true; start_attr1 = 0; start_attr2 = 0; inAttr = 0; } else if (intag && c1 == '>') { intag = false; } else if (intag && Character.isWhitespace((char) c1) && inAttr == 0) { start_attr1 = i1+1; start_attr2 = i2+1;; } else if (intag && inAttr == 0 && (c1 == '"' || c1 == '\'')) { inAttr = (char) c1; } else if (intag && inAttr == c1) { start_attr1 = 0; start_attr2 = 0; inAttr = 0; } i1++; i2++; } else if (intag && start_attr1 > 0) { i1 = start_attr1; i2 = start_attr2; /* #ifdef JAVA5 */ // Stack<String> attrs1 = new Stack<String>(); // Stack<String> attrs2 = new Stack<String>(); /* #else */ Stack attrs1 = new Stack(); Stack attrs2 = new Stack(); /* #endif */ for (;;) { int end1 = grabAttribute(arg1, i1); int end2 = grabAttribute(arg2, i2); if (end1 < 0 || end2 < 0) return false; String attr1 = arg1.substring(i1, end1); attrs1.push(attr1); String attr2 = arg2.substring(i2, end2); attrs2.push(attr2); i1 = end1; i2 = end2; for (;;) { if (i1 >= len1) return false; c1 = arg1.charAt(i1++); if (! Character.isWhitespace((char) c1)) break; } for (;;) { if (i2 >= len2) return false; c2 = arg2.charAt(i2++); if (! Character.isWhitespace((char) c2)) break; } boolean done1 = c1 == '/' || c1 == '>'; boolean done2 = c2 == '/' || c2 == '>'; if (done1 && done2) break; if (done1 || done2) return false; i1--; i2--; } // Same number of attributes. // Do an O(n^2) search to make sure the sets are equal. for (int i = attrs1.size(); --i >= 0; ) { String attr1 = (String) attrs1.elementAt(i); for (int j = attrs2.size(); ; ) { if (--j < 0) return false; String attr2 = (String) attrs2.elementAt(j); if (attr1.equals(attr2)) break; } } start_attr1 = 0; start_attr2 = 0; intag = false; } else if (isFloatChar(c1) ? (isFloatChar(c2) || (i2 > 0 && isFloatChar(arg2.charAt(i2-1)))) : (isFloatChar(c2) && (i1 > 0 && isFloatChar(arg1.charAt(i1-1))))) { int start1 = i1, start2 = i2; while (start1 > 0 && isFloatChar(arg1.charAt(start1-1))) start1--; while (start2 > 0 && isFloatChar(arg2.charAt(start2-1))) start2--; int end1 = i1, end2 = i2; while (end1 < len1 && isFloatChar(arg1.charAt(end1))) end1++; while (end2 < len2 && isFloatChar(arg2.charAt(end2))) end2++; if (end1 <= start1 || end2 <= start2) return false; String word1 = arg1.substring(start1, end1); String word2 = arg2.substring(start2, end2); try { float f1 = Float.parseFloat(word1); float f2 = Float.parseFloat(word2); if (Float.floatToIntBits(f1) != Float.floatToIntBits(f2)) return false; } catch (Throwable ex) { return false; } i1 = end1; i2 = end2; } else if (isXML && (c1 == ' ' || c1 == '\n' || c1 == '\t' || c1 == '\r')) { i1++; } else if (isXML && (c2 == ' ' || c2 == '\n' || c2 == '\t' || c2 == '\r')) { i2++; } // If isXML, then "/>" matches "></ANYNAME>". else if (isXML && c1 == '/' && c2 == '>' && i1 + 1 < len1 && i2 + 2 < len2 && arg1.charAt(i1+1) == '>' && arg2.charAt(i2+1) == '<' && arg2.charAt(i2+2) == '/') { for (i2 = i2 + 3; ; i2++) { if (i2 >= len2) return false; char c = arg2.charAt(i2); if (c == '>') break; if (! XName.isNamePart(c)) return false; } i1 = i1 + 2; i2 = i2 + 1; } else return false; } } static boolean isFloatChar (int c) { return (c >= '0' && c <= '9') || c == '.' || c == '-' || c == '+' || c == 'E'; } String selectedTest; public String getElementValue () { return cout.toSubString(elementStartIndex[nesting]); } public void endElement() { if (inStartTag) handleStartTag(); if (tagMatches("test-case")) { if (--maxTests == 0) System.exit(0); // FIXME if (selectedTest == null || selectedTest.equals(testName)) { xqlog.startElement(testCaseElementType); writeAttribute("name", testName); try { // Other attributes and <test-case> body written by evalTest. evalTest(testName); } catch (Throwable ex) { System.err.println("test-case name:"+testName); System.err.println("caught "+ex); ex.printStackTrace(); } xqlog.endElement(); } //xqlog.flush(); testName = null; contextItem = null; Environment env = Environment.getCurrent(); while (! externalVariablesSet.empty()) env.remove((Symbol) externalVariablesSet.pop()); } else if (tagMatches("expected-error")) { expectedErrorsBuf.append(getElementValue()); expectedErrorsBuf.append('|'); } else if (tagMatches("input-query")) { String variable = attributes.getValue("variable"); Symbol symbol = Symbol.parse(variable); String name = attributes.getValue("name"); String filename = directory + '/' + XQueryQueryOffsetPath + testFilePath + name + XQueryFileExtension; InPort in; try { in = InPort.openFile(filename); Object value = XQuery.getInstance().eval(in); in.close(); Environment current = Environment.getCurrent(); current.put(symbol, null, value); externalVariablesSet.push(symbol); } catch (Throwable ex) { System.err.println("input-query: cannot open "+filename); System.err.println("caught "+ex); ex.printStackTrace(); System.exit(-1); } } else if (tagMatches("input-file") || tagMatches("contextItem")) { String inputFile = getElementValue(); // KLUDGE around testsuite bug! if ("userdefined".equals(inputFile)) inputFile = "emptydoc"; String path = directory + '/' + sources.get(inputFile); String variable; Symbol symbol; if (tagMatches("input-file")) { variable = attributes.getValue("variable"); symbol = Symbol.parse(variable); externalVariablesSet.push(symbol); } else // tagMatches("contextItem") { variable = null; symbol = null; } try { Object value = gnu.kawa.xml.Document.parseCached(path); if (symbol != null) Environment.getCurrent().put(symbol, null, value); else contextItem = value; } catch (Throwable ex) { System.err.println("caught "+ex); System.err.println("reading data file "+path); System.err.println("inputFile:"+inputFile+" variable:"+variable+" path:"+path); ex.printStackTrace(); System.exit(-1); } } else if (tagMatches("input-URI")) { String inputFile = getElementValue(); String variable = attributes.getValue("variable"); Object inputValue = sources.get(inputFile); String path = inputValue instanceof Values ? "collection:"+inputFile : "file://" + directory + '/' + inputValue; Symbol symbol = Symbol.parse(variable); externalVariablesSet.push(symbol); Environment.getCurrent().put(symbol, null, Path.valueOf(path)); } else if (tagMatches("defaultCollection")) { String inputFile = getElementValue(); Object inputValue = sources.get(inputFile); Object val = NodeUtils.getSavedCollection("collection:"+inputFile); NodeUtils.setSavedCollection("#default", val); } else if (tagMatches("collection")) { NodeUtils.setSavedCollection("collection:"+collectionID, collectionDocuments.canonicalize()); collectionID = null; collectionDocuments = null; } else if (tagMatches("input-document")) { String inputName = getElementValue(); String path = "file://" + directory + '/' + sources.get(inputName); if (collectionID == null) throw new Error("<input-document> not in <collection>"); try { KDocument value = (KDocument) Document.parseCached(path); collectionDocuments.writeObject(value); } catch (Throwable ex) { System.err.println("caught "+ex); System.err.println("reading data file "+path); System.err.println("for collection "+collectionID); ex.printStackTrace(); System.exit(-1); } } else if (tagMatches("output-file")) { outputFileAlts.push(getElementValue()); outputCompareAlts.push(attributes.getValue("compare")); } else if (tagMatches("test-suite")) { xqlog.endElement(); } else if (testName != null && tagMatches("module")) { String uri = attributes.getValue("namespace"); String module = getElementValue(); String mfile = (String) modules.get(module); String mpath = directory + '/' + mfile + XQueryFileExtension; String mclass = Compilation.mangleURI(uri) + '.' + XQuery.makeClassName(mpath); ModuleInfo minfo = manager.findWithClassName(mclass); minfo.sourcePath = mfile + XQueryFileExtension; minfo.setSourceAbsPath(Path.valueOf(mpath)); minfo.setNamespaceUri(uri); } /* else if ("test".equals(typeName) && (nesting == 0 || (inTestSuite && nesting == 1))) { inTest = false; TestMisc.evalTest(query, expect); } else if (inTestSuite ? nesting == 2 : nesting == 1) { if ("query".equals(typeName)) query = sout.toString(); else if ("expect".equals(typeName)) expect = sout.toString(); currentTag = null; } else base.endElement(); */ cout.setLength(elementStartIndex[nesting]); nesting--; Object type = elementTypeStack.pop(); currentElementType = type; currentElementSymbol = type instanceof Symbol ? (Symbol) type : null; } public void startAttribute(Object attrType) { super.startAttribute(attrType); attrValueStart = cout.length(); } public void endAttribute() { super.endAttribute(); String attrValue = cout.toSubString(attrValueStart, cout.length()-1); Symbol sym = (Symbol) attributeType; String uri = sym.getNamespaceURI(); String local = sym.getLocalPart(); String prefix = sym.getPrefix(); String qname = (prefix == null || prefix.length() == 0 ? local : prefix+":"+local); cout.setLength(attrValueStart); attributes.addAttribute(uri, local, qname, "CDATA", attrValue); } public void beforeContent () { if (! inAttribute && inStartTag) handleStartTag(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -