thxmlwrite.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "jiface.hpp"
  14. #include "jtime.hpp"
  15. #include "dadfs.hpp"
  16. #include "thexception.hpp"
  17. #include "thmfilemanager.hpp"
  18. #include "eclhelper.hpp"
  19. #include "deftype.hpp"
  20. #include "thxmlwrite.ipp"
  21. class CXmlWriteActivityMaster : public CWriteMasterBase
  22. {
  23. IHThorXmlWriteArg *helper;
  24. ThorActivityKind kind;
  25. unsigned headerLength;
  26. unsigned footerLength;
  27. public:
  28. CXmlWriteActivityMaster(CMasterGraphElement *info, ThorActivityKind _kind) : CWriteMasterBase(info), kind(_kind), headerLength(0), footerLength(0)
  29. {
  30. helper = (IHThorXmlWriteArg *)queryHelper();
  31. }
  32. virtual void init()
  33. {
  34. CWriteMasterBase::init();
  35. assertex(!(helper->getFlags() & TDWextend));
  36. IPropertyTree &props = fileDesc->queryProperties();
  37. StringBuffer rowTag;
  38. OwnedRoxieString xmlpath(helper->getXmlIteratorPath());
  39. if (!xmlpath)
  40. rowTag.append("Row");
  41. else
  42. {
  43. const char *path = xmlpath;
  44. if (*path == '/') path++;
  45. if (strchr(path, '/')) UNIMPLEMENTED;
  46. rowTag.append(path);
  47. }
  48. props.setProp("@rowTag", rowTag.str());
  49. props.setProp("@format", "utf8n");
  50. props.setProp("@kind", (kind==TAKjsonwrite) ? "json" : "xml");
  51. if (kind==TAKjsonwrite)
  52. {
  53. StringBuffer s;
  54. OwnedRoxieString supplied(helper->getHeader());
  55. props.setPropInt("@headerLength", buildJsonHeader(s, supplied, rowTag).length());
  56. supplied.set(helper->getFooter());
  57. props.setPropInt("@footerLength", buildJsonFooter(s.clear(), supplied, rowTag).length());
  58. }
  59. }
  60. };
  61. CActivityBase *createXmlWriteActivityMaster(CMasterGraphElement *container, ThorActivityKind kind)
  62. {
  63. return new CXmlWriteActivityMaster(container, kind);
  64. }