Samuel - GSOC 2012

You're doing good.

It looks like you understand the basics of the XPath function class that needs to be extended
and customizing the appropriate execute() methods.

Here are some comments:: Ref: file OspXpathConvertDate.cpp from zip example.

YourXPathFunction::execute(
  XPathExecutionContext & executionContext,
  XalanNode *           context,  /*may not be needed*/
  const XObjectPtr      arg1,
  const XObjectPtr      arg2,
  const LocatorType *   locator   /*may not be needed*/
) const
{
  CharVectorType  theFirstArg;
  char *          charFirstArg;
  CharVectorType  theSecondArg;
  char *          charSecondArg;

  MemoryManager * theManager = executionContext.getMemoryManager();

  theFirstArg = TranscodeToLocalCodePage(arg1->str());
  charFirstArg = theFirstArg.begin();

  theSecondArg = TranscodeToLocalCodePage(arg2->str());
  charSecondArg = theSecondArg.begin();

/* NOTES
 *
 * TransCodeToLocalCodePage()
 *   creates a new instance of CharVectorType containing
* converted transformed Unicode to the host character set (ASCII/EBCDIC...)
 *
 * The CharVectorType.begin() method returns a pointer to the
* null-terminated character string. This string is owned by the CharVectorType
 * class.  This CharVectorType class is a local variable with local scope.
 * The allocation for CharVectorType will be properly destroyed when the
 * execute() method returns.
 *
 * You should not access the m_data storage variable directly, but instead
 * use the access method begin() to ensure a proper address.
 *
 * Note also that XalanDOMString may not be what you want.  Its native
 * character storage is 16-bit characters (UTF-16) encoding.
 *
 * The above sample I have shown here will give you standard 'C' strings
 * extracted from the XPath function arguments in a safe way.
 *
 * The XalanDOMString class does know how to import data from (char *)
 * strings.
 */

 char * charResult;
 charResult = someFunction(...) // returning a pointer to type (char *);

// The following creates a XalanDOMString and initializes it with charResult.
 // Declaring XalanDOMString as a local instance, it will be destroyed when
 // the execute method exits.

 XalanDOMString theResult(charResult);

 // You may need to free the memory associated with the charResult pointer
 // before you return.  After charResult is saved in a XalanDOMString, you
// should be able to release owhership of the (char *) pointer and free the
 // (char *) allocation.

 free(charResult);  // or program specific equivalent.

 // The execution.GetXObjectFactory() creates a XObjectPtr to data owned
 // by the XObjectFactory.  This content is returned to the XPath
 // interpreter execution context.

 return executionContext.getXObjectFactory().createString(theResult);

}

/*
 * Create an error reporter
 */
const XalanDOMString &
YourXPathFunction::getError(XalanDOMString & theResult) const
{
  return XalanMessageLoader::getMessage(
    theResult,
    XalanMessages::FunctionTakesTwoArguments_1Param,
    "name of you XPath Function");
}

/* NOTE:
 * The example error reporter.
 * The XalanMessageLoader::getMessage(...) prepares a standard message
 * showing theResult, "The function '(0)' requires two arguments."
 * with '(0)' replaced with "name of your XPath Function");
 *
 * If you need messages that are not in the NLS library, we can create
 * new message templates and put them into the NLS library.
 *
 * FunctionTakesTwoArguments_1Param is an address to the NLS string:
 * "The function '(0)' requires two arguments."
 */


Sincerely,
Steven J. Hathaway



---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscr...@xml.apache.org
For additional commands, e-mail: xalan-dev-h...@xml.apache.org

Reply via email to