You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@apache.org on 2002/10/31 08:10:26 UTC

cvs commit: xml-xalan/c/src/XalanExtensions FunctionEvaluate.cpp

dbertoni    2002/10/30 23:10:26

  Modified:    c/src/XalanExtensions FunctionEvaluate.cpp
  Log:
  Factored out common code.
  
  Revision  Changes    Path
  1.7       +70 -41    xml-xalan/c/src/XalanExtensions/FunctionEvaluate.cpp
  
  Index: FunctionEvaluate.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanExtensions/FunctionEvaluate.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FunctionEvaluate.cpp	17 Apr 2002 05:34:20 -0000	1.6
  +++ FunctionEvaluate.cpp	31 Oct 2002 07:10:25 -0000	1.7
  @@ -62,6 +62,10 @@
   
   
   
  +#include <DOMSupport/DOMServices.hpp>
  +
  +
  +
   #include <XalanDOM/XalanElement.hpp>
   
   
  @@ -69,6 +73,7 @@
   #include <XPath/ElementPrefixResolverProxy.hpp>
   #include <XPath/XObjectFactory.hpp>
   #include <XPath/XPath.hpp>
  +#include <XPath/XPathConstructionContextDefault.hpp>
   #include <XPath/XPathProcessorImpl.hpp>
   
   
  @@ -85,6 +90,52 @@
   
   
   
  +inline XObjectPtr
  +doExecute(
  +			XPathExecutionContext&	executionContext,
  +			XalanNode*				context,
  +			const XalanDOMString&	expression,
  +			const PrefixResolver&	resolver)
  +{
  +	// $$$ ToDo: Consider moving all of this into a member function of
  +	// XPathExecutionContext.
  +	XPathProcessorImpl					theProcessor;
  +
  +	XPathConstructionContextDefault		theConstructionContext;
  +
  +	XPath								theXPath;
  +
  +	theProcessor.initXPath(
  +			theXPath,
  +			theConstructionContext,
  +			expression,
  +			resolver);
  +
  +	return theXPath.execute(context, resolver, executionContext);
  +}
  +
  +
  +
  +inline XObjectPtr
  +doExecute(
  +			XPathExecutionContext&	executionContext,
  +			XalanNode*				context,
  +			const XalanDOMString&	expression,
  +			const XalanNode*		resolver)
  +{
  +	assert(resolver == 0 || resolver->getNodeType() == XalanNode::ELEMENT_NODE);
  +
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +	ElementPrefixResolverProxy	theProxy((const XalanElement*)resolver);
  +#else
  +	ElementPrefixResolverProxy	theProxy(static_cast<const XalanElement*>(resolver));
  +#endif
  +
  +	return doExecute(executionContext, context, expression, theProxy);
  +}
  +
  +
  +
   XObjectPtr
   FunctionEvaluate::execute(
   			XPathExecutionContext&			executionContext,
  @@ -99,57 +150,35 @@
   
   	assert(args[0].null() == false);
   
  +	const XalanDOMString&	theExpression = args[0]->str();
  +
   	const PrefixResolver* const	theResolver =
   		executionContext.getPrefixResolver();
   
  -	if (theResolver == 0)
  +	if (theResolver != 0)
   	{
  -		if (context->getNodeType() != XalanNode::ELEMENT_NODE)
  -		{
  -			executionContext.warn(
  -				"No prefix resolver is available in evaluate().  The expression cannot be evaluated.",
  -				context,
  -				locator);
  -
  -			return args[0];
  -		}
  -		else
  -		{
  -			executionContext.warn(
  -				"No prefix resolver is available in evaluate().  evalute() will use the context node for prefix resolution.",
  -				context,
  -				locator);
  -
  -#if defined(XALAN_OLD_STYLE_CASTS)
  -			ElementPrefixResolverProxy	theProxy((const XalanElement*)context);
  -#else
  -			ElementPrefixResolverProxy	theProxy(static_cast<const XalanElement*>(context));
  -#endif
  -
  -			XPathProcessorImpl	theProcessor;
  -
  -			XPath				theXPath;
  -
  -			theProcessor.initXPath(
  -					theXPath,
  -					args[0]->str(),
  -					theProxy);
  -
  -			return theXPath.execute(context, *theResolver, executionContext);
  -		}
  +		return doExecute(executionContext, context, theExpression, *theResolver);
   	}
   	else
   	{
  -		XPathProcessorImpl	theProcessor;
  +		const XalanNode*	resolverNode = context;
  +
  +		if (resolverNode->getNodeType() != XalanNode::ELEMENT_NODE)
  +		{
  +			resolverNode = DOMServices::getParentOfNode(*resolverNode);
   
  -		XPath				theXPath;
  +			if (context->getNodeType() != XalanNode::ELEMENT_NODE)
  +			{
  +				executionContext.warn(
  +					"No prefix resolver is available in evaluate().",
  +					context,
  +					locator);
   
  -		theProcessor.initXPath(
  -				theXPath,
  -				args[0]->str(),
  -				*theResolver);
  +				resolverNode = 0;
  +			}
  +		}
   
  -		return theXPath.execute(context, *theResolver, executionContext);
  +		return doExecute(executionContext, context, theExpression, resolverNode);
   	}
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org