19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one 39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file 49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information 59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file 69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the "License"); 79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License. 89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at 99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software 139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and 169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License. 179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: FuncDocument.java 468643 2006-10-28 06:56:03Z minchau $ 209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xalan.templates; 229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.io.IOException; 249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.io.PrintWriter; 259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.io.StringWriter; 269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.ErrorListener; 289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.Source; 299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.SourceLocator; 309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.TransformerException; 319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLMessages; 339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLTErrorResources; 349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.DTM; 359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.DTMIterator; 369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.XMLString; 379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.Expression; 389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.NodeSetDTM; 399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.SourceTreeManager; 409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.XPathContext; 419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.functions.Function2Args; 429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.functions.WrongNumberArgsException; 439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XNodeSet; 449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XObject; 459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** 479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Execute the Doc() function. 489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * When the document function has exactly one argument and the argument 509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is a node-set, then the result is the union, for each node in the 519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * argument node-set, of the result of calling the document function with 529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the first argument being the string-value of the node, and the second 539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * argument being a node-set with the node as its only member. When the 549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * document function has two arguments and the first argument is a node-set, 559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * then the result is the union, for each node in the argument node-set, 569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * of the result of calling the document function with the first argument 579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * being the string-value of the node, and with the second argument being 589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the second argument passed to the document function. 599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage advanced 609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class FuncDocument extends Function2Args 629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{ 639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson static final long serialVersionUID = 2483304325971281424L; 649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Execute the function. The function must return 679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a valid object. 689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The current execution context. 699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return A valid XObject. 709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException 749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int context = xctxt.getCurrentNode(); 769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson DTM dtm = xctxt.getDTM(context); 779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int docContext = dtm.getDocumentRoot(context); 799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XObject arg = (XObject) this.getArg0().execute(xctxt); 809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String base = ""; 829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Expression arg1Expr = this.getArg1(); 839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != arg1Expr) 859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // The URI reference may be relative. The base URI (see [3.2 Base URI]) 889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // of the node in the second argument node-set that is first in document 899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // order is used as the base URI for resolving the 909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // relative URI into an absolute URI. 919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XObject arg2 = arg1Expr.execute(xctxt); 929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (XObject.CLASS_NODESET == arg2.getType()) 949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int baseNode = arg2.iter().nextNode(); 969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (baseNode == DTM.NULL) 989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // See http://www.w3.org/1999/11/REC-xslt-19991116-errata#E14. 1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // If the second argument is an empty nodeset, this is an error. 1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // The processor can recover by returning an empty nodeset. 1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson warn(xctxt, XSLTErrorResources.WG_EMPTY_SECOND_ARG, null); 1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XNodeSet nodes = new XNodeSet(xctxt.getDTMManager()); 1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return nodes; 1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } else{ 1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson DTM baseDTM = xctxt.getDTM(baseNode); 1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson base = baseDTM.getDocumentBaseURI(); 1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // %REVIEW% This doesn't seem to be a problem with the conformance 1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // suite, but maybe it's just not doing a good test? 1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// int baseDoc = baseDTM.getDocument(); 1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// 1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// if (baseDoc == DTM.NULL /* || baseDoc instanceof Stylesheet -->What to do?? */) 1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// { 1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// 1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// // base = ((Stylesheet)baseDoc).getBaseIdentifier(); 1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// base = xctxt.getNamespaceContext().getBaseIdentifier(); 1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// } 1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// else 1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson// base = xctxt.getSourceTreeManager().findURIFromDoc(baseDoc); 1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //Can not convert other type to a node-set!; 1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson arg2.iter(); 1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // If the second argument is omitted, then it defaults to 1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // the node in the stylesheet that contains the expression that 1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // includes the call to the document function. Note that a 1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // zero-length URI reference is a reference to the document 1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // relative to which the URI reference is being resolved; thus 1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // document("") refers to the root node of the stylesheet; 1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // the tree representation of the stylesheet is exactly 1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // the same as if the XML document containing the stylesheet 1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // was the initial source document. 1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson assertion(null != xctxt.getNamespaceContext(), "Namespace context can not be null!"); 1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson base = xctxt.getNamespaceContext().getBaseIdentifier(); 1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XNodeSet nodes = new XNodeSet(xctxt.getDTMManager()); 1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson NodeSetDTM mnl = nodes.mutableNodeset(); 1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson DTMIterator iterator = (XObject.CLASS_NODESET == arg.getType()) 1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ? arg.iter() : null; 1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int pos = DTM.NULL; 1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson while ((null == iterator) || (DTM.NULL != (pos = iterator.nextNode()))) 1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XMLString ref = (null != iterator) 1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ? xctxt.getDTM(pos).getStringValue(pos) : arg.xstr(); 1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // The first and only argument was a nodeset, the base in that 1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // case is the base URI of the node from the first argument nodeset. 1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Remember, when the document function has exactly one argument and 1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // the argument is a node-set, then the result is the union, for each 1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // node in the argument node-set, of the result of calling the document 1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // function with the first argument being the string-value of the node, 1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // and the second argument being a node-set with the node as its only 1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // member. 1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null == arg1Expr && DTM.NULL != pos) 1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson DTM baseDTM = xctxt.getDTM(pos); 1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson base = baseDTM.getDocumentBaseURI(); 1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null == ref) 1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson continue; 1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (DTM.NULL == docContext) 1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson error(xctxt, XSLTErrorResources.ER_NO_CONTEXT_OWNERDOC, null); //"context does not have an owner document!"); 1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // From http://www.ics.uci.edu/pub/ietf/uri/rfc1630.txt 1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // A partial form can be distinguished from an absolute form in that the 1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // latter must have a colon and that colon must occur before any slash 1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // characters. Systems not requiring partial forms should not use any 1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // unencoded slashes in their naming schemes. If they do, absolute URIs 1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // will still work, but confusion may result. 1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int indexOfColon = ref.indexOf(':'); 1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int indexOfSlash = ref.indexOf('/'); 1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ((indexOfColon != -1) && (indexOfSlash != -1) 1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson && (indexOfColon < indexOfSlash)) 1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // The url (or filename, for that matter) is absolute. 1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson base = null; 1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int newDoc = getDoc(xctxt, context, ref.toString(), base); 1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // nodes.mutableNodeset().addNode(newDoc); 1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (DTM.NULL != newDoc) 1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // TODO: mnl.addNodeInDocOrder(newDoc, true, xctxt); ?? 2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (!mnl.contains(newDoc)) 2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson mnl.addElement(newDoc); 2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null == iterator || newDoc == DTM.NULL) 2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson break; 2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return nodes; 2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the document from the given URI and base 2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime state. 2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param context The current context node 2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param uri Relative(?) URI of the document 2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param base Base to resolve relative URI from. 2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The document Node pointing to the document at the given URI 2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or null 2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int getDoc(XPathContext xctxt, int context, String uri, String base) 2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.out.println("base: "+base+", uri: "+uri); 2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson SourceTreeManager treeMgr = xctxt.getSourceTreeManager(); 2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Source source; 2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int newDoc; 2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson source = treeMgr.resolveURI(base, uri, xctxt.getSAXLocator()); 2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson newDoc = treeMgr.getNode(source); 2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (IOException ioe) 2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new TransformerException(ioe.getMessage(), 2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson (SourceLocator)xctxt.getSAXLocator(), ioe); 2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch(TransformerException te) 2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new TransformerException(te); 2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (DTM.NULL != newDoc) 2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return newDoc; 2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // If the uri length is zero, get the uri of the stylesheet. 2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (uri.length() == 0) 2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Hmmm... this seems pretty bogus to me... -sb 2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson uri = xctxt.getNamespaceContext().getBaseIdentifier(); 2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson source = treeMgr.resolveURI(base, uri, xctxt.getSAXLocator()); 2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (IOException ioe) 2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new TransformerException(ioe.getMessage(), 2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson (SourceLocator)xctxt.getSAXLocator(), ioe); 2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String diagnosticsString = null; 2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson try 2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ((null != uri) && (uri.length() > 0)) 2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson newDoc = treeMgr.getSourceTree(source, xctxt.getSAXLocator(), xctxt); 2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.out.println("newDoc: "+((Document)newDoc).getDocumentElement().getNodeName()); 2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson warn(xctxt, XSLTErrorResources.WG_CANNOT_MAKE_URL_FROM, 2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson new Object[]{ ((base == null) ? "" : base) + uri }); //"Can not make URL from: "+((base == null) ? "" : base )+uri); 2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson catch (Throwable throwable) 2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // throwable.printStackTrace(); 2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson newDoc = DTM.NULL; 2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // path.warn(XSLTErrorResources.WG_ENCODING_NOT_SUPPORTED_USING_JAVA, new Object[]{((base == null) ? "" : base )+uri}); //"Can not load requested doc: "+((base == null) ? "" : base )+uri); 2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson while (throwable 2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson instanceof org.apache.xml.utils.WrappedRuntimeException) 2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throwable = 2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ((org.apache.xml.utils.WrappedRuntimeException) throwable).getException(); 2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ((throwable instanceof NullPointerException) 2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson || (throwable instanceof ClassCastException)) 2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new org.apache.xml.utils.WrappedRuntimeException( 3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson (Exception) throwable); 3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson StringWriter sw = new StringWriter(); 3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson PrintWriter diagnosticsWriter = new PrintWriter(sw); 3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (throwable instanceof TransformerException) 3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson TransformerException spe = (TransformerException) throwable; 3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Throwable e = spe; 3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson while (null != e) 3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != e.getMessage()) 3179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson diagnosticsWriter.println(" (" + e.getClass().getName() + "): " 3199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson + e.getMessage()); 3209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (e instanceof TransformerException) 3239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson TransformerException spe2 = (TransformerException) e; 3259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson SourceLocator locator = spe2.getLocator(); 3279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ((null != locator) && (null != locator.getSystemId())) 3289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson diagnosticsWriter.println(" ID: " + locator.getSystemId() 3299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson + " Line #" + locator.getLineNumber() 3309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson + " Column #" 3319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson + locator.getColumnNumber()); 3329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson e = spe2.getException(); 3349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (e instanceof org.apache.xml.utils.WrappedRuntimeException) 3369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson e = ((org.apache.xml.utils.WrappedRuntimeException) e).getException(); 3379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 3399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson e = null; 3409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 3449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson diagnosticsWriter.println(" (" + throwable.getClass().getName() 3469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson + "): " + throwable.getMessage()); 3479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson diagnosticsString = throwable.getMessage(); //sw.toString(); 3509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (DTM.NULL == newDoc) 3539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // System.out.println("what?: "+base+", uri: "+uri); 3569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != diagnosticsString) 3579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson warn(xctxt, XSLTErrorResources.WG_CANNOT_LOAD_REQUESTED_DOC, 3599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson new Object[]{ diagnosticsString }); //"Can not load requested doc: "+((base == null) ? "" : base )+uri); 3609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 3629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson warn(xctxt, XSLTErrorResources.WG_CANNOT_LOAD_REQUESTED_DOC, 3639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson new Object[]{ 3649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson uri == null 3659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ? ((base == null) ? "" : base) + uri : uri.toString() }); //"Can not load requested doc: "+((base == null) ? "" : base )+uri); 3669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 3689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // %REVIEW% 3709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // TBD: What to do about XLocator? 3719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // xctxt.getSourceTreeManager().associateXLocatorToNode(newDoc, url, null); 3729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return newDoc; 3759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tell the user of an error, and probably throw an 3799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * exception. 3809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime state. 3829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param msg The error message key 3839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param args Arguments to be used in the error message 3849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide 3859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the error condition is severe enough to halt processing. 3869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 3889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void error(XPathContext xctxt, String msg, Object args[]) 3909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 3919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 3929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String formattedMsg = XSLMessages.createMessage(msg, args); 3949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorListener errHandler = xctxt.getErrorListener(); 3959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson TransformerException spe = new TransformerException(formattedMsg, 3969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson (SourceLocator)xctxt.getSAXLocator()); 3979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != errHandler) 3999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson errHandler.error(spe); 4009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 4019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson System.out.println(formattedMsg); 4029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Warn the user of a problem. 4069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param xctxt The XPath runtime state. 4089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param msg Warning message key 4099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param args Arguments to be used in the warning message 4109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide 4119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the error condition is severe enough to halt processing. 4129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws javax.xml.transform.TransformerException 4149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void warn(XPathContext xctxt, String msg, Object args[]) 4169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws javax.xml.transform.TransformerException 4179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String formattedMsg = XSLMessages.createWarning(msg, args); 4209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorListener errHandler = xctxt.getErrorListener(); 4219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson TransformerException spe = new TransformerException(formattedMsg, 4229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson (SourceLocator)xctxt.getSAXLocator()); 4239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (null != errHandler) 4259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson errHandler.warning(spe); 4269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 4279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson System.out.println(formattedMsg); 4289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Overide the superclass method to allow one or two arguments. 4329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param argNum Number of arguments passed in to this function 4359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws WrongNumberArgsException 4379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void checkNumberArgs(int argNum) throws WrongNumberArgsException 4399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ((argNum < 1) || (argNum > 2)) 4419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson reportWrongNumberArgs(); 4429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Constructs and throws a WrongNumberArgException with the appropriate 4469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * message for this function object. 4479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws WrongNumberArgsException 4499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected void reportWrongNumberArgs() throws WrongNumberArgsException { 4519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new WrongNumberArgsException(XSLMessages.createMessage(XSLTErrorResources.ER_ONE_OR_TWO, null)); //"1 or 2"); 4529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tell if the expression is a nodeset expression. 4569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true if the expression can be represented as a nodeset. 4579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isNodesetExpr() 4599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 4609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return true; 4619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson} 464