opc_properties.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. Copyright (c) 2010, Florian Reuter
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. * Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. * Neither the name of Florian Reuter nor the names of its contributors
  14. may be used to endorse or promote products derived from this
  15. software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  19. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  20. COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  22. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  25. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  27. OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. /*
  30. Dump core properties of an OPC container.
  31. Ussage:
  32. opc_properties FILENAME
  33. Sample:
  34. opc_properties OOXMLI1.docx
  35. */
  36. #include <opc/opc.h>
  37. #include <stdio.h>
  38. #include <time.h>
  39. #ifdef WIN32
  40. #include <crtdbg.h>
  41. #endif
  42. static void printValue(opcDCSimpleType_t *v) {
  43. printf("\"%s\"", v->str);
  44. if (NULL!=v->lang)
  45. printf("@%s", v->lang);
  46. }
  47. static void printPair(const char *name, opcDCSimpleType_t *value) {
  48. printf("%s=", name);
  49. printValue(value);
  50. printf("\n");
  51. }
  52. int main( int argc, const char* argv[] )
  53. {
  54. #ifdef WIN32
  55. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  56. #endif
  57. time_t start_time=time(NULL);
  58. opc_error_t err=OPC_ERROR_NONE;
  59. if (OPC_ERROR_NONE==opcInitLibrary() && 2==argc) {
  60. opcContainer *c=NULL;
  61. if (NULL!=(c=opcContainerOpen(_X(argv[1]), OPC_OPEN_READ_WRITE, NULL, NULL))) {
  62. opcProperties_t cp;
  63. opcCorePropertiesInit(&cp);
  64. opcCorePropertiesRead(&cp, c);
  65. // opcCorePropertiesSetString(&cp.category, _X("category"));
  66. // opcCorePropertiesSetString(&cp.contentStatus, _X("contentStatus"));
  67. // opcCorePropertiesSetString(&cp.created, _X("2011-04-13T06:24:00Z"));
  68. if (NULL!=cp.category) printf("category=\"%s\"\n", cp.category);
  69. if (NULL!=cp.contentStatus) printf("contentStatus=\"%s\"\n", cp.contentStatus);
  70. if (NULL!=cp.created) printf("created=\"%s\"\n", cp.created);
  71. if (NULL!=cp.creator.str) printPair("creator", &cp.creator);
  72. if (NULL!=cp.description.str) printPair("description", &cp.description);
  73. if (NULL!=cp.identifier.str) printPair("identifier", &cp.identifier);
  74. if (cp.keyword_items>0) {
  75. printf("keywords={");
  76. for(opc_uint32_t i=0;i<cp.keyword_items;i++) {
  77. printValue(&cp.keyword_array[i]);
  78. if (i+1<cp.keyword_items) printf(", ");
  79. }
  80. printf("}\n");
  81. }
  82. if (NULL!=cp.language.str) printPair("language", &cp.language);
  83. if (NULL!=cp.lastModifiedBy) printf("lastModifiedBy=\"%s\"\n", cp.lastModifiedBy);
  84. if (NULL!=cp.lastPrinted) printf("lastPrinted=\"%s\"\n", cp.lastPrinted);
  85. if (NULL!=cp.modified) printf("modified=\"%s\"\n", cp.modified);
  86. if (NULL!=cp.revision) printf("revision=\"%s\"\n", cp.revision);
  87. if (NULL!=cp.subject.str) printPair("subject", &cp.subject);
  88. if (NULL!=cp.title.str) printPair("title", &cp.title);
  89. if (NULL!=cp.version) printf("version=\"%s\"\n", cp.version);
  90. opcCorePropertiesWrite(&cp, c);
  91. opcCorePropertiesCleanup(&cp);
  92. opcContainerClose(c, OPC_CLOSE_NOW);
  93. } else {
  94. printf("ERROR: \"%s\" could not be opened.\n", argv[1]);
  95. err=OPC_ERROR_STREAM;
  96. }
  97. opcFreeLibrary();
  98. } else if (2==argc) {
  99. printf("ERROR: initialization of libopc failed.\n");
  100. err=OPC_ERROR_STREAM;
  101. } else {
  102. printf("opc_dump FILENAME.\n\n");
  103. printf("Sample: opc_properties test.docx\n");
  104. }
  105. time_t end_time=time(NULL);
  106. fprintf(stderr, "time %.2lfsec\n", difftime(end_time, start_time));
  107. #ifdef WIN32
  108. OPC_ASSERT(!_CrtDumpMemoryLeaks());
  109. #endif
  110. return (OPC_ERROR_NONE==err?0:3);
  111. }