XslFunctions.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #if 0 //this is just a sample Xalan (XSLT) external function
  15. #include "XslFunctions.hpp"
  16. #include "XPath/XObjectFactory.hpp"
  17. FunctionSample::FunctionSample()
  18. {
  19. }
  20. FunctionSample::~FunctionSample()
  21. {
  22. }
  23. XObjectPtr
  24. FunctionSample::execute(
  25. XPathExecutionContext& executionContext,
  26. XalanNode* /* context */,
  27. const XObjectPtr arg1,
  28. const XObjectPtr arg2,
  29. const Locator* /* locator */) const
  30. {
  31. assert(arg1.null() == false);
  32. assert(arg2.null() == false);
  33. XalanDOMString path;
  34. arg1->str(path);
  35. const bool bLinux = arg2->boolean();
  36. XalanDOMChar dchOld;
  37. XalanDOMChar dchNew;
  38. if (bLinux)
  39. {
  40. dchOld = '\\';
  41. dchNew = '/';
  42. }
  43. else
  44. {
  45. dchOld = '/';
  46. dchOld = '\\';
  47. }
  48. int len = path.length();
  49. for (int i=0; i<len; i++)
  50. if (path[i] == dchOld)
  51. path[i] = dchNew;
  52. return executionContext.getXObjectFactory().createString(path);
  53. }
  54. #if defined(XALAN_NO_COVARIANT_RETURN_TYPE)
  55. Function*
  56. #else
  57. FunctionSample*
  58. #endif
  59. FunctionSample::clone() const
  60. {
  61. return new FunctionSample(*this);
  62. }
  63. const XalanDOMString
  64. FunctionSample::getError() const
  65. {
  66. return StaticStringToDOMString(XALAN_STATIC_UCODE_STRING("The boolean() function takes one argument!"));
  67. }
  68. #endif //0