You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XWPFRelation.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xwpf.usermodel;
  16. import java.util.HashMap;
  17. import java.util.Map;
  18. import org.apache.poi.common.usermodel.PictureType;
  19. import org.apache.poi.ooxml.POIXMLDocument;
  20. import org.apache.poi.ooxml.POIXMLRelation;
  21. import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
  22. import org.apache.poi.xssf.usermodel.XSSFRelation;
  23. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  24. import static org.apache.poi.openxml4j.opc.PackageRelationshipTypes.HDPHOTO_PART;
  25. import static org.apache.poi.openxml4j.opc.PackageRelationshipTypes.IMAGE_PART;
  26. public final class XWPFRelation extends POIXMLRelation {
  27. /* package */ static final String NS_DRAWINGML = XSSFRelation.NS_DRAWINGML;
  28. /**
  29. * A map to lookup POIXMLRelation by its relation type
  30. */
  31. private static final Map<String, XWPFRelation> _table = new HashMap<>();
  32. public static final XWPFRelation DOCUMENT = new XWPFRelation(
  33. "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
  34. PackageRelationshipTypes.CORE_DOCUMENT,
  35. "/word/document.xml"
  36. );
  37. public static final XWPFRelation TEMPLATE = new XWPFRelation(
  38. "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml",
  39. PackageRelationshipTypes.CORE_DOCUMENT,
  40. "/word/document.xml"
  41. );
  42. public static final XWPFRelation MACRO_DOCUMENT = new XWPFRelation(
  43. "application/vnd.ms-word.document.macroEnabled.main+xml",
  44. PackageRelationshipTypes.CORE_DOCUMENT,
  45. "/word/document.xml"
  46. );
  47. public static final XWPFRelation MACRO_TEMPLATE_DOCUMENT = new XWPFRelation(
  48. "application/vnd.ms-word.template.macroEnabledTemplate.main+xml",
  49. PackageRelationshipTypes.CORE_DOCUMENT,
  50. "/word/document.xml"
  51. );
  52. public static final XWPFRelation GLOSSARY_DOCUMENT = new XWPFRelation(
  53. "application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml",
  54. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument",
  55. "/word/glossary/document.xml"
  56. );
  57. public static final XWPFRelation NUMBERING = new XWPFRelation(
  58. "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",
  59. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",
  60. "/word/numbering.xml",
  61. XWPFNumbering::new, XWPFNumbering::new
  62. );
  63. public static final XWPFRelation FONT_TABLE = new XWPFRelation(
  64. "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml",
  65. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",
  66. "/word/fontTable.xml"
  67. );
  68. public static final XWPFRelation SETTINGS = new XWPFRelation(
  69. "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml",
  70. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings",
  71. "/word/settings.xml",
  72. XWPFSettings::new, XWPFSettings::new
  73. );
  74. public static final XWPFRelation STYLES = new XWPFRelation(
  75. "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml",
  76. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
  77. "/word/styles.xml",
  78. XWPFStyles::new, XWPFStyles::new
  79. );
  80. public static final XWPFRelation WEB_SETTINGS = new XWPFRelation(
  81. "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml",
  82. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings",
  83. "/word/webSettings.xml"
  84. );
  85. public static final XWPFRelation HEADER = new XWPFRelation(
  86. "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml",
  87. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
  88. "/word/header#.xml",
  89. XWPFHeader::new, XWPFHeader::new
  90. );
  91. public static final XWPFRelation FOOTER = new XWPFRelation(
  92. "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml",
  93. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
  94. "/word/footer#.xml",
  95. XWPFFooter::new, XWPFFooter::new
  96. );
  97. public static final XWPFRelation THEME = new XWPFRelation(
  98. "application/vnd.openxmlformats-officedocument.theme+xml",
  99. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
  100. "/word/theme/theme#.xml",
  101. XWPFTheme::new, XWPFTheme::new
  102. );
  103. public static final XWPFRelation WORKBOOK = new XWPFRelation(
  104. "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  105. POIXMLDocument.PACK_OBJECT_REL_TYPE,
  106. "/word/embeddings/Microsoft_Excel_Worksheet#.xlsx",
  107. XSSFWorkbook::new, (PackagePartConstructor)XSSFWorkbook::new
  108. );
  109. public static final XWPFRelation CHART = new XWPFRelation(
  110. "application/vnd.openxmlformats-officedocument.drawingml.chart+xml",
  111. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
  112. "/word/charts/chart#.xml",
  113. XWPFChart::new, XWPFChart::new
  114. );
  115. public static final XWPFRelation HYPERLINK = new XWPFRelation(
  116. null,
  117. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
  118. null
  119. );
  120. public static final XWPFRelation COMMENT = new XWPFRelation(
  121. "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
  122. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
  123. "/word/comments.xml",
  124. XWPFComments::new, XWPFComments::new
  125. );
  126. public static final XWPFRelation FOOTNOTE = new XWPFRelation(
  127. "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml",
  128. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes",
  129. "/word/footnotes.xml",
  130. XWPFFootnotes::new, XWPFFootnotes::new
  131. );
  132. public static final XWPFRelation ENDNOTE = new XWPFRelation(
  133. "application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml",
  134. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes",
  135. "/word/endnotes.xml",
  136. XWPFEndnotes::new, XWPFEndnotes::new
  137. );
  138. /**
  139. * Supported image formats
  140. */
  141. public static final XWPFRelation IMAGE_EMF = new XWPFRelation(
  142. PictureType.EMF.contentType,
  143. IMAGE_PART,
  144. "/word/media/image#.emf",
  145. XWPFPictureData::new, XWPFPictureData::new
  146. );
  147. public static final XWPFRelation IMAGE_WMF = new XWPFRelation(
  148. PictureType.WMF.contentType,
  149. IMAGE_PART,
  150. "/word/media/image#.wmf",
  151. XWPFPictureData::new, XWPFPictureData::new
  152. );
  153. public static final XWPFRelation IMAGE_PICT = new XWPFRelation(
  154. PictureType.PICT.contentType,
  155. IMAGE_PART,
  156. "/word/media/image#.pict",
  157. XWPFPictureData::new, XWPFPictureData::new
  158. );
  159. public static final XWPFRelation IMAGE_JPEG = new XWPFRelation(
  160. PictureType.JPEG.contentType,
  161. IMAGE_PART,
  162. "/word/media/image#.jpeg",
  163. XWPFPictureData::new, XWPFPictureData::new
  164. );
  165. public static final XWPFRelation IMAGE_PNG = new XWPFRelation(
  166. PictureType.PNG.contentType,
  167. IMAGE_PART,
  168. "/word/media/image#.png",
  169. XWPFPictureData::new, XWPFPictureData::new
  170. );
  171. public static final XWPFRelation IMAGE_DIB = new XWPFRelation(
  172. PictureType.DIB.contentType,
  173. IMAGE_PART,
  174. "/word/media/image#.dib",
  175. XWPFPictureData::new, XWPFPictureData::new
  176. );
  177. public static final XWPFRelation IMAGE_GIF = new XWPFRelation(
  178. PictureType.GIF.contentType,
  179. IMAGE_PART,
  180. "/word/media/image#.gif",
  181. XWPFPictureData::new, XWPFPictureData::new
  182. );
  183. public static final XWPFRelation IMAGE_TIFF = new XWPFRelation(
  184. PictureType.TIFF.contentType,
  185. IMAGE_PART,
  186. "/word/media/image#.tiff",
  187. XWPFPictureData::new, XWPFPictureData::new
  188. );
  189. public static final XWPFRelation IMAGE_EPS = new XWPFRelation(
  190. PictureType.EPS.contentType,
  191. IMAGE_PART,
  192. "/word/media/image#.eps",
  193. XWPFPictureData::new, XWPFPictureData::new
  194. );
  195. public static final XWPFRelation IMAGE_BMP = new XWPFRelation(
  196. PictureType.BMP.contentType,
  197. IMAGE_PART,
  198. "/word/media/image#.bmp",
  199. XWPFPictureData::new, XWPFPictureData::new
  200. );
  201. public static final XWPFRelation IMAGE_WPG = new XWPFRelation(
  202. PictureType.WPG.contentType,
  203. IMAGE_PART,
  204. "/word/media/image#.wpg",
  205. XWPFPictureData::new, XWPFPictureData::new
  206. );
  207. public static final XWPFRelation HDPHOTO_WDP = new XWPFRelation(
  208. PictureType.WDP.contentType,
  209. HDPHOTO_PART,
  210. "/ppt/media/hdphoto#.wdp",
  211. XWPFPictureData::new, XWPFPictureData::new
  212. );
  213. public static final XWPFRelation IMAGE_SVG = new XWPFRelation(
  214. PictureType.SVG.contentType,
  215. IMAGE_PART,
  216. "/word/media/image#.svg",
  217. XWPFPictureData::new, XWPFPictureData::new
  218. );
  219. public static final XWPFRelation IMAGES = new XWPFRelation(
  220. null,
  221. IMAGE_PART,
  222. null,
  223. XWPFPictureData::new, XWPFPictureData::new
  224. );
  225. private XWPFRelation(String type, String rel, String defaultName) {
  226. super(type, rel, defaultName);
  227. _table.put(rel, this);
  228. }
  229. private XWPFRelation(String type, String rel, String defaultName,
  230. NoArgConstructor noArgConstructor,
  231. PackagePartConstructor packagePartConstructor) {
  232. super(type, rel, defaultName, noArgConstructor, packagePartConstructor, null);
  233. _table.put(rel, this);
  234. }
  235. private XWPFRelation(String type, String rel, String defaultName,
  236. NoArgConstructor noArgConstructor,
  237. ParentPartConstructor parentPartConstructor) {
  238. super(type, rel, defaultName, noArgConstructor, null, parentPartConstructor);
  239. _table.put(rel, this);
  240. }
  241. /**
  242. * Get POIXMLRelation by relation type
  243. *
  244. * @param rel relation type, for example,
  245. * <code>http://schemas.openxmlformats.org/officeDocument/2006/relationships/image</code>
  246. * @return registered POIXMLRelation or null if not found
  247. */
  248. public static XWPFRelation getInstance(String rel) {
  249. return _table.get(rel);
  250. }
  251. @Override
  252. public String toString() {
  253. return "XWPFRelation{" +
  254. //getRelation() + "/" +
  255. getContentType() + "/" +
  256. getDefaultFileName() +
  257. "}";
  258. }
  259. }