PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/AODL/Document/TextDocuments/TextDocumentHelper.cs

https://bitbucket.org/chrisc/aodl
C# | 161 lines | 86 code | 5 blank | 70 comment | 0 complexity | fbf723dbc215268da4d0c1f96660b542 MD5 | raw file
  1. /*************************************************************************
  2. *
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
  4. *
  5. * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
  6. *
  7. * Use is subject to license terms.
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  10. * use this file except in compliance with the License. You may obtain a copy
  11. * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
  12. * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. *
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. *
  21. ************************************************************************/
  22. using System.Xml;
  23. namespace AODL.Document.TextDocuments
  24. {
  25. /// <summary>
  26. /// Class with static helper methods for the TextDocument class.
  27. /// </summary>
  28. public class TextDocumentHelper
  29. {
  30. /// <summary>
  31. /// Getting a blank OpenDocument textdocument.
  32. /// </summary>
  33. /// <returns>The blank document. Which should be loaded for the TextDocument.</returns>
  34. public static string GetBlankDocument()
  35. {
  36. const string header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> <office:document-content"
  37. + " xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\""
  38. + " xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\""
  39. + " xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\""
  40. + " xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\""
  41. + " xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\""
  42. + " xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\""
  43. + " xmlns:xlink=\"http://www.w3.org/1999/xlink\""
  44. + " xmlns:dc=\"http://purl.org/dc/elements/1.1/\""
  45. + " xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\""
  46. + " xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\""
  47. + " xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\""
  48. + " xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\""
  49. + " xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\""
  50. + " xmlns:math=\"http://www.w3.org/1998/Math/MathML\""
  51. + " xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\""
  52. + " xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\""
  53. + " xmlns:ooo=\"http://openoffice.org/2004/office\""
  54. + " xmlns:ooow=\"http://openoffice.org/2004/writer\""
  55. + " xmlns:oooc=\"http://openoffice.org/2004/calc\""
  56. + " xmlns:dom=\"http://www.w3.org/2001/xml-events\""
  57. + " xmlns:xforms=\"http://www.w3.org/2002/xforms\""
  58. + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
  59. + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
  60. + " office:version=\"1.0\">"
  61. + "<office:scripts />"
  62. + "<office:font-face-decls>"
  63. + "<style:font-face style:name=\"StarSymbol\" svg:font-family=\"StarSymbol\" style:font-charset=\"x-symbol\" />"
  64. + "<style:font-face style:name=\"Tahoma1\" svg:font-family=\"Tahoma\" /> "
  65. + "<style:font-face style:name=\"Lucida Sans Unicode\" svg:font-family=\"'Lucida Sans Unicode'\" style:font-pitch=\"variable\" />"
  66. + "<style:font-face style:name=\"Tahoma\" svg:font-family=\"Tahoma\" style:font-pitch=\"variable\" />"
  67. + "<style:font-face style:name=\"Times New Roman\" svg:font-family=\"'Times New Roman'\" style:font-family-generic=\"roman\" style:font-pitch=\"variable\" />"
  68. + "</office:font-face-decls>"
  69. + "<office:automatic-styles>"
  70. + "</office:automatic-styles>"
  71. + "<office:body>"
  72. + "<office:text>"
  73. // + "<office:forms form:automatic-focus=\"false\" form:apply-design-mode=\"false\" /> "
  74. + "<text:sequence-decls>"
  75. + "<text:sequence-decl text:display-outline-level=\"0\" text:name=\"Illustration\" />"
  76. + "<text:sequence-decl text:display-outline-level=\"0\" text:name=\"Table\" /> "
  77. + "<text:sequence-decl text:display-outline-level=\"0\" text:name=\"Text\" />"
  78. + "<text:sequence-decl text:display-outline-level=\"0\" text:name=\"Drawing\" />"
  79. + "</text:sequence-decls>"
  80. + "</office:text>"
  81. + "</office:body>"
  82. + "</office:document-content>";
  83. return header;
  84. }
  85. /// <summary>
  86. /// Create a new XmlNamespaceManager and fill it with all necessary namespaces and prefixes.
  87. /// </summary>
  88. /// <param name="nametable">The XmlNameTable of the TextDocument object XDocument.</param>
  89. /// <returns>The XmlNamespaceManager object.</returns>
  90. public static XmlNamespaceManager NameSpace(XmlNameTable nametable)
  91. {
  92. XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(nametable);
  93. xmlnsManager.AddNamespace("office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0");
  94. xmlnsManager.AddNamespace("style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
  95. xmlnsManager.AddNamespace("text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0");
  96. xmlnsManager.AddNamespace("table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0");
  97. xmlnsManager.AddNamespace("draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0");
  98. xmlnsManager.AddNamespace("fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
  99. xmlnsManager.AddNamespace("xlink", "http://www.w3.org/1999/xlink");
  100. xmlnsManager.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
  101. xmlnsManager.AddNamespace("meta", "urn:oasis:names:tc:opendocument:xmlns:meta:1.0");
  102. xmlnsManager.AddNamespace("number", "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0");
  103. xmlnsManager.AddNamespace("svg", "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0");
  104. xmlnsManager.AddNamespace("dr3d", "urn:oasis:names:tc:opendocument:xmlns:chart:1.0");
  105. xmlnsManager.AddNamespace("math", "http://www.w3.org/1998/Math/MathML");
  106. xmlnsManager.AddNamespace("form", "urn:oasis:names:tc:opendocument:xmlns:form:1.0");
  107. xmlnsManager.AddNamespace("script", "urn:oasis:names:tc:opendocument:xmlns:script:1.0");
  108. xmlnsManager.AddNamespace("ooo", "http://openoffice.org/2004/office");
  109. xmlnsManager.AddNamespace("ooow", "http://openoffice.org/2004/writer");
  110. xmlnsManager.AddNamespace("oooc", "http://openoffice.org/2004/calc");
  111. xmlnsManager.AddNamespace("dom", "http://www.w3.org/2001/xml-events");
  112. xmlnsManager.AddNamespace("xforms", "http://www.w3.org/2002/xforms");
  113. xmlnsManager.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
  114. xmlnsManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
  115. xmlnsManager.AddNamespace ("manifest", "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0");
  116. xmlnsManager.AddNamespace ("chart", "urn:oasis:names:tc:opendocument:xmlns:chart:1.0");
  117. return xmlnsManager;
  118. }
  119. }
  120. }
  121. /*
  122. * $Log: TextDocumentHelper.cs,v $
  123. * Revision 1.6 2008/04/29 15:39:57 mt
  124. * new copyright header
  125. *
  126. * Revision 1.5 2008/02/08 07:12:21 larsbehr
  127. * - added initial chart support
  128. * - several bug fixes
  129. *
  130. * Revision 1.4 2007/06/20 17:37:19 yegorov
  131. * Issue number:
  132. * Submitted by:
  133. * Reviewed by:
  134. *
  135. * Revision 1.1 2007/02/25 08:58:59 larsbehr
  136. * initial checkin, import from Sourceforge.net to OpenOffice.org
  137. *
  138. * Revision 1.2 2006/02/21 19:34:56 larsbm
  139. * - Fixed Bug text that contains a xml tag will be imported as UnknowText and not correct displayed if document is exported as HTML.
  140. * - Fixed Bug [ 1436080 ] Common styles
  141. *
  142. * Revision 1.1 2006/01/29 11:28:30 larsbm
  143. * - Changes for the new version. 1.2. see next changelog for details
  144. *
  145. * Revision 1.4 2005/10/22 15:52:10 larsbm
  146. * - Changed some styles from Enum to Class with statics
  147. * - Add full support for available OpenOffice fonts
  148. *
  149. * Revision 1.3 2005/10/09 15:52:47 larsbm
  150. * - Changed some design at the paragraph usage
  151. * - add list support
  152. *
  153. * Revision 1.2 2005/10/08 07:50:15 larsbm
  154. * - added cvs tags
  155. *
  156. */