Back to index

lightning-sunbird  0.9+nobinonly
ElementAvailableFnCall.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is TransforMiiX XSLT processor code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Peter Van der Beken <peterv@propagandism.org>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "txIXPathContext.h"
00040 #include "txAtoms.h"
00041 #include "txError.h"
00042 #include "XMLUtils.h"
00043 #include "XSLTFunctions.h"
00044 #include "ExprResult.h"
00045 #include "txNamespaceMap.h"
00046 
00047 /*
00048   Implementation of XSLT 1.0 extension function: element-available
00049 */
00050 
00056 ElementAvailableFunctionCall::ElementAvailableFunctionCall(txNamespaceMap* aMappings)
00057     : mMappings(aMappings)
00058 {
00059 }
00060 
00069 nsresult
00070 ElementAvailableFunctionCall::evaluate(txIEvalContext* aContext,
00071                                        txAExprResult** aResult)
00072 {
00073     *aResult = nsnull;
00074     if (!requireParams(1, 1, aContext)) {
00075         return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
00076     }
00077 
00078     txListIterator iter(&params);
00079     Expr* param = (Expr*) iter.next();
00080 
00081     nsRefPtr<txAExprResult> exprResult;
00082     nsresult rv = param->evaluate(aContext, getter_AddRefs(exprResult));
00083     NS_ENSURE_SUCCESS(rv, rv);
00084 
00085     nsAutoString property;
00086     exprResult->stringValue(property);
00087     txExpandedName qname;
00088     rv = qname.init(property, mMappings, MB_TRUE);
00089     NS_ENSURE_SUCCESS(rv, rv);
00090 
00091     PRBool val = qname.mNamespaceID == kNameSpaceID_XSLT &&
00092                  (qname.mLocalName == txXSLTAtoms::applyImports ||
00093                   qname.mLocalName == txXSLTAtoms::applyTemplates ||
00094                   qname.mLocalName == txXSLTAtoms::attribute ||
00095                   qname.mLocalName == txXSLTAtoms::attributeSet ||
00096                   qname.mLocalName == txXSLTAtoms::callTemplate ||
00097                   qname.mLocalName == txXSLTAtoms::choose ||
00098                   qname.mLocalName == txXSLTAtoms::comment ||
00099                   qname.mLocalName == txXSLTAtoms::copy ||
00100                   qname.mLocalName == txXSLTAtoms::copyOf ||
00101                   qname.mLocalName == txXSLTAtoms::decimalFormat ||
00102                   qname.mLocalName == txXSLTAtoms::element ||
00103                   qname.mLocalName == txXSLTAtoms::fallback ||
00104                   qname.mLocalName == txXSLTAtoms::forEach ||
00105                   qname.mLocalName == txXSLTAtoms::_if ||
00106                   qname.mLocalName == txXSLTAtoms::import ||
00107                   qname.mLocalName == txXSLTAtoms::include ||
00108                   qname.mLocalName == txXSLTAtoms::key ||
00109                   qname.mLocalName == txXSLTAtoms::message ||
00110                   //qname.mLocalName == txXSLTAtoms::namespaceAlias ||
00111                   qname.mLocalName == txXSLTAtoms::number ||
00112                   qname.mLocalName == txXSLTAtoms::otherwise ||
00113                   qname.mLocalName == txXSLTAtoms::output ||
00114                   qname.mLocalName == txXSLTAtoms::param ||
00115                   qname.mLocalName == txXSLTAtoms::preserveSpace ||
00116                   qname.mLocalName == txXSLTAtoms::processingInstruction ||
00117                   qname.mLocalName == txXSLTAtoms::sort ||
00118                   qname.mLocalName == txXSLTAtoms::stripSpace ||
00119                   qname.mLocalName == txXSLTAtoms::stylesheet ||
00120                   qname.mLocalName == txXSLTAtoms::_template ||
00121                   qname.mLocalName == txXSLTAtoms::text ||
00122                   qname.mLocalName == txXSLTAtoms::transform ||
00123                   qname.mLocalName == txXSLTAtoms::valueOf ||
00124                   qname.mLocalName == txXSLTAtoms::variable ||
00125                   qname.mLocalName == txXSLTAtoms::when ||
00126                   qname.mLocalName == txXSLTAtoms::withParam);
00127 
00128     aContext->recycler()->getBoolResult(val, aResult);
00129 
00130     return NS_OK;
00131 }
00132 
00133 #ifdef TX_TO_STRING
00134 nsresult
00135 ElementAvailableFunctionCall::getNameAtom(nsIAtom** aAtom)
00136 {
00137     *aAtom = txXSLTAtoms::elementAvailable;
00138     NS_ADDREF(*aAtom);
00139     return NS_OK;
00140 }
00141 #endif