00001 /* 00002 * The Apache Software License, Version 1.1 00003 * 00004 * 00005 * Copyright (c) 1999 The Apache Software Foundation. All rights 00006 * reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in 00017 * the documentation and/or other materials provided with the 00018 * distribution. 00019 * 00020 * 3. The end-user documentation included with the redistribution, 00021 * if any, must include the following acknowledgment: 00022 * "This product includes software developed by the 00023 * Apache Software Foundation (http://www.apache.org/)." 00024 * Alternately, this acknowledgment may appear in the software itself, 00025 * if and wherever such third-party acknowledgments normally appear. 00026 * 00027 * 4. The names "Xalan" and "Apache Software Foundation" must 00028 * not be used to endorse or promote products derived from this 00029 * software without prior written permission. For written 00030 * permission, please contact apache@apache.org. 00031 * 00032 * 5. Products derived from this software may not be called "Apache", 00033 * nor may "Apache" appear in their name, without prior written 00034 * permission of the Apache Software Foundation. 00035 * 00036 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00037 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00038 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00039 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 00040 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00041 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00042 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00043 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00044 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00045 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00046 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00047 * SUCH DAMAGE. 00048 * ==================================================================== 00049 * 00050 * This software consists of voluntary contributions made by many 00051 * individuals on behalf of the Apache Software Foundation and was 00052 * originally based on software copyright (c) 1999, International 00053 * Business Machines, Inc., http://www.ibm.com. For more 00054 * information on the Apache Software Foundation, please see 00055 * <http://www.apache.org/>. 00056 * 00057 * @author <a href="mailto:david_n_bertoni@lotus.com">David N. Bertoni</a> 00058 */ 00059 #if !defined(FUNCTIONID_HEADER_GUARD_1357924680) 00060 #define FUNCTIONID_HEADER_GUARD_1357924680 00061 00062 00063 00064 // Base header file. Must be first. 00065 #include <XPath/XPathDefinitions.hpp> 00066 00067 00068 00069 #include <set> 00070 00071 00072 00073 #include <XalanDOM/XalanElement.hpp> 00074 #include <XalanDOM/XalanNode.hpp> 00075 #include <XalanDOM/XalanDocument.hpp> 00076 00077 00078 00079 // Base class header files... 00080 #include <XPath/Function.hpp> 00081 #include <XPath/XObjectTypeCallback.hpp> 00082 00083 00084 00085 #include <PlatformSupport/DOMStringHelper.hpp> 00086 #include <PlatformSupport/StringTokenizer.hpp> 00087 00088 00089 00090 #include <XPath/MutableNodeRefList.hpp> 00091 #include <XPath/NodeRefListBase.hpp> 00092 #include <XPath/XObject.hpp> 00093 #include <XPath/XObjectFactory.hpp> 00094 #include <XPath/XPathExecutionContext.hpp> 00095 00096 00097 00101 // 00102 // These are all inline, even though 00103 // there are virtual functions, because we expect that they will only be 00104 // needed by the XPath class. 00105 class XALAN_XPATH_EXPORT FunctionID : public Function 00106 { 00107 public: 00108 00109 FunctionID() : 00110 Function() 00111 { 00112 } 00113 00114 // These methods are inherited from Function ... 00115 00116 virtual XObject* 00117 execute( 00118 XPathExecutionContext& executionContext, 00119 XalanNode* context, 00120 int /* opPos */, 00121 const XObjectArgVectorType& args) 00122 { 00123 if (args.size() != 1) 00124 { 00125 executionContext.error("The id() function takes one argument!", 00126 context); 00127 } 00128 else if (context == 0) 00129 { 00130 executionContext.error("The id() function requires a non-null context node!", 00131 context); 00132 } 00133 00134 assert(args[0] != 0); 00135 00136 // Do the callback to get the data. 00137 FunctionIDXObjectTypeCallback theCallback(executionContext); 00138 00139 const XalanDOMString theResultString = 00140 theCallback.processCallback(*args[0]); 00141 00142 // Get the context document, so we can search for nodes. 00143 const XalanDocument* const theDocContext = context->getNodeType() == XalanNode::DOCUMENT_NODE ? 00144 #if defined(XALAN_OLD_STYLE_CASTS) 00145 (const XalanDocument*)context : 00146 #else 00147 static_cast<const XalanDocument*>(context) : 00148 #endif 00149 context->getOwnerDocument(); 00150 assert(theDocContext != 0); 00151 00152 typedef XPathExecutionContext::BorrowReturnMutableNodeRefList BorrowReturnMutableNodeRefList; 00153 00154 // This list will hold the nodes we find. 00155 00156 BorrowReturnMutableNodeRefList theNodeList(executionContext); 00157 00158 // If there is no context, we cannot continue. 00159 if(0 == theDocContext) 00160 { 00161 executionContext.error("The context node does not have an owner document!", 00162 context); 00163 } 00164 else if (length(theResultString) > 0) 00165 { 00166 #if defined(XALAN_NO_NAMESPACES) 00167 typedef set<XalanDOMString, less<XalanDOMString> > TokenSetType; 00168 #else 00169 typedef std::set<XalanDOMString> TokenSetType; 00170 #endif 00171 00172 // This set will hold tokens that we've previously found, so 00173 // we can avoid looking more than once. 00174 TokenSetType thePreviousTokens; 00175 00176 StringTokenizer theTokenizer(theResultString); 00177 00178 // Parse the result string... 00179 while(theTokenizer.hasMoreTokens() == true) 00180 { 00181 const XalanDOMString theToken = theTokenizer.nextToken(); 00182 00183 if (length(theToken) > 0) 00184 { 00185 // See if we've already seen this one... 00186 TokenSetType::const_iterator i = 00187 thePreviousTokens.find(theToken); 00188 00189 if (i == thePreviousTokens.end()) 00190 { 00191 thePreviousTokens.insert(theToken); 00192 00193 XalanNode* const theNode = 00194 executionContext.getElementByID(theToken, *theDocContext); 00195 00196 if (theNode != 0) 00197 { 00198 theNodeList->addNodeInDocOrder(theNode, executionContext); 00199 } 00200 } 00201 } 00202 } 00203 } 00204 00205 return executionContext.getXObjectFactory().createNodeSet(theNodeList); 00206 } 00207 00208 #if defined(XALAN_NO_COVARIANT_RETURN_TYPE) 00209 virtual Function* 00210 #else 00211 virtual FunctionID* 00212 #endif 00213 clone() const 00214 { 00215 return new FunctionID(*this); 00216 } 00217 00218 00219 private: 00220 00221 class FunctionIDXObjectTypeCallback : public XObjectTypeCallback 00222 { 00223 public: 00224 00225 FunctionIDXObjectTypeCallback(XPathExecutionContext& theExecutionContext) : 00226 XObjectTypeCallback(), 00227 m_executionContext(theExecutionContext), 00228 m_resultString() 00229 { 00230 } 00231 00232 const XalanDOMString& 00233 processCallback(const XObject& theXObject) 00234 { 00235 theXObject.ProcessXObjectTypeCallback(*this); 00236 00237 return m_resultString; 00238 } 00239 00240 // These methods are inherited from XObjectTypeCallback ... 00241 00242 virtual void 00243 Number(const XObject& theXObject, 00244 double /* theValue */) 00245 { 00246 m_resultString = theXObject.str(); 00247 } 00248 00249 virtual void 00250 Boolean(const XObject& theXObject, 00251 bool /* theValue */) 00252 { 00253 m_resultString = theXObject.str(); 00254 } 00255 00256 virtual void 00257 String(const XObject& theXObject, 00258 const XalanDOMString& /* theValue */) 00259 { 00260 m_resultString = theXObject.str(); 00261 } 00262 00263 virtual void 00264 ResultTreeFragment(const XObject& theXObject, 00265 const ResultTreeFragBase& /* theValue */) 00266 { 00267 m_resultString = theXObject.str(); 00268 } 00269 00270 virtual void 00271 ResultTreeFragment(const XObject& theXObject, 00272 ResultTreeFragBase& /* theValue */) 00273 { 00274 m_resultString = theXObject.str(); 00275 } 00276 00277 virtual void 00278 NodeSet(const XObject& /* theXObject */, 00279 const NodeRefListBase& theValue) 00280 { 00281 const unsigned int theNodeCount = theValue.getLength(); 00282 00283 for (unsigned int i = 0 ; i < theNodeCount; i++) 00284 { 00285 m_resultString += m_executionContext.getNodeData(*theValue.item(i)); 00286 00287 m_resultString += " "; 00288 } 00289 } 00290 00291 virtual void 00292 Unknown(const XObject& /* theObject */, 00293 const XalanDOMString& /* theName */) 00294 { 00295 } 00296 00297 virtual void 00298 Null(const XObject& /* theObject */) 00299 { 00300 } 00301 00302 private: 00303 00304 XalanDOMString m_resultString; 00305 00306 XPathExecutionContext& m_executionContext; 00307 }; 00308 00309 // Not implemented... 00310 FunctionID& 00311 operator=(const FunctionID&); 00312 00313 bool 00314 operator==(const FunctionID&) const; 00315 }; 00316 00317 00318 00319 #endif // FUNCTIONID_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSL Transformer Version 1.0 |
|