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.

XSSFRelation.java 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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.xssf.usermodel;
  16. import java.util.HashMap;
  17. import java.util.Map;
  18. import org.apache.poi.ooxml.POIXMLDocument;
  19. import org.apache.poi.ooxml.POIXMLRelation;
  20. import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
  21. import org.apache.poi.sl.usermodel.PictureData;
  22. import org.apache.poi.xssf.model.CalculationChain;
  23. import org.apache.poi.xssf.model.CommentsTable;
  24. import org.apache.poi.xssf.model.ExternalLinksTable;
  25. import org.apache.poi.xssf.model.MapInfo;
  26. import org.apache.poi.xssf.model.SharedStringsTable;
  27. import org.apache.poi.xssf.model.SingleXmlCells;
  28. import org.apache.poi.xssf.model.StylesTable;
  29. import org.apache.poi.xssf.model.ThemesTable;
  30. /**
  31. * Defines namespaces, content types and normal file names / naming
  32. * patterns, for the well-known XSSF format parts.
  33. */
  34. public final class XSSFRelation extends POIXMLRelation {
  35. /**
  36. * A map to lookup POIXMLRelation by its relation type
  37. */
  38. private static final Map<String, XSSFRelation> _table = new HashMap<>();
  39. public static final XSSFRelation WORKBOOK = new XSSFRelation(
  40. "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
  41. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/workbook",
  42. "/xl/workbook.xml"
  43. );
  44. public static final XSSFRelation MACROS_WORKBOOK = new XSSFRelation(
  45. "application/vnd.ms-excel.sheet.macroEnabled.main+xml",
  46. PackageRelationshipTypes.CORE_DOCUMENT,
  47. "/xl/workbook.xml"
  48. );
  49. public static final XSSFRelation TEMPLATE_WORKBOOK = new XSSFRelation(
  50. "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml",
  51. PackageRelationshipTypes.CORE_DOCUMENT,
  52. "/xl/workbook.xml"
  53. );
  54. public static final XSSFRelation MACRO_TEMPLATE_WORKBOOK = new XSSFRelation(
  55. "application/vnd.ms-excel.template.macroEnabled.main+xml",
  56. PackageRelationshipTypes.CORE_DOCUMENT,
  57. "/xl/workbook.xml"
  58. );
  59. public static final XSSFRelation MACRO_ADDIN_WORKBOOK = new XSSFRelation(
  60. "application/vnd.ms-excel.addin.macroEnabled.main+xml",
  61. PackageRelationshipTypes.CORE_DOCUMENT,
  62. "/xl/workbook.xml"
  63. );
  64. public static final XSSFRelation XLSB_BINARY_WORKBOOK = new XSSFRelation(
  65. "application/vnd.ms-excel.sheet.binary.macroEnabled.main",
  66. PackageRelationshipTypes.CORE_DOCUMENT,
  67. "/xl/workbook.bin"
  68. );
  69. public static final XSSFRelation WORKSHEET = new XSSFRelation(
  70. "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",
  71. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",
  72. "/xl/worksheets/sheet#.xml",
  73. XSSFSheet::new, XSSFSheet::new
  74. );
  75. public static final XSSFRelation CHARTSHEET = new XSSFRelation(
  76. "application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml",
  77. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet",
  78. "/xl/chartsheets/sheet#.xml",
  79. null, XSSFChartSheet::new
  80. );
  81. public static final XSSFRelation CHART_EX = new XSSFRelation(
  82. "application/vnd.ms-office.chartex+xml",
  83. "http://schemas.microsoft.com/office/2014/relationships/chartEx",
  84. "/xl/charts/chartEx#.xml");
  85. public static final XSSFRelation SHARED_STRINGS = new XSSFRelation(
  86. "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",
  87. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",
  88. "/xl/sharedStrings.xml",
  89. SharedStringsTable::new, SharedStringsTable::new
  90. );
  91. public static final XSSFRelation STYLES = new XSSFRelation(
  92. "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",
  93. PackageRelationshipTypes.STYLE_PART,
  94. "/xl/styles.xml",
  95. StylesTable::new, StylesTable::new
  96. );
  97. public static final XSSFRelation DRAWINGS = new XSSFRelation(
  98. "application/vnd.openxmlformats-officedocument.drawing+xml",
  99. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",
  100. "/xl/drawings/drawing#.xml",
  101. XSSFDrawing::new, XSSFDrawing::new
  102. );
  103. public static final XSSFRelation VML_DRAWINGS = new XSSFRelation(
  104. "application/vnd.openxmlformats-officedocument.vmlDrawing",
  105. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing",
  106. "/xl/drawings/vmlDrawing#.vml",
  107. XSSFVMLDrawing::new, XSSFVMLDrawing::new
  108. );
  109. public static final XSSFRelation CHART = new XSSFRelation(
  110. "application/vnd.openxmlformats-officedocument.drawingml.chart+xml",
  111. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
  112. "/xl/charts/chart#.xml",
  113. XSSFChart::new, XSSFChart::new
  114. );
  115. public static final XSSFRelation CUSTOM_XML_MAPPINGS = new XSSFRelation(
  116. "application/xml",
  117. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/xmlMaps",
  118. "/xl/xmlMaps.xml",
  119. MapInfo::new, MapInfo::new
  120. );
  121. public static final XSSFRelation SINGLE_XML_CELLS = new XSSFRelation(
  122. "application/vnd.openxmlformats-officedocument.spreadsheetml.tableSingleCells+xml",
  123. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableSingleCells",
  124. "/xl/tables/tableSingleCells#.xml",
  125. SingleXmlCells::new, SingleXmlCells::new
  126. );
  127. public static final XSSFRelation TABLE = new XSSFRelation(
  128. "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",
  129. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",
  130. "/xl/tables/table#.xml",
  131. XSSFTable::new, XSSFTable::new
  132. );
  133. public static final XSSFRelation IMAGES = new XSSFRelation(
  134. null,
  135. PackageRelationshipTypes.IMAGE_PART,
  136. null,
  137. XSSFPictureData::new, XSSFPictureData::new
  138. );
  139. public static final XSSFRelation IMAGE_EMF = new XSSFRelation(
  140. PictureData.PictureType.EMF.contentType,
  141. PackageRelationshipTypes.IMAGE_PART,
  142. "/xl/media/image#.emf",
  143. XSSFPictureData::new, XSSFPictureData::new
  144. );
  145. public static final XSSFRelation IMAGE_WMF = new XSSFRelation(
  146. PictureData.PictureType.WMF.contentType,
  147. PackageRelationshipTypes.IMAGE_PART,
  148. "/xl/media/image#.wmf",
  149. XSSFPictureData::new, XSSFPictureData::new
  150. );
  151. public static final XSSFRelation IMAGE_PICT = new XSSFRelation(
  152. PictureData.PictureType.PICT.contentType,
  153. PackageRelationshipTypes.IMAGE_PART,
  154. "/xl/media/image#.pict",
  155. XSSFPictureData::new, XSSFPictureData::new
  156. );
  157. public static final XSSFRelation IMAGE_JPEG = new XSSFRelation(
  158. PictureData.PictureType.JPEG.contentType,
  159. PackageRelationshipTypes.IMAGE_PART,
  160. "/xl/media/image#.jpeg",
  161. XSSFPictureData::new, XSSFPictureData::new
  162. );
  163. public static final XSSFRelation IMAGE_PNG = new XSSFRelation(
  164. PictureData.PictureType.PNG.contentType,
  165. PackageRelationshipTypes.IMAGE_PART,
  166. "/xl/media/image#.png",
  167. XSSFPictureData::new, XSSFPictureData::new
  168. );
  169. public static final XSSFRelation IMAGE_DIB = new XSSFRelation(
  170. PictureData.PictureType.DIB.contentType,
  171. PackageRelationshipTypes.IMAGE_PART,
  172. "/xl/media/image#.dib",
  173. XSSFPictureData::new, XSSFPictureData::new
  174. );
  175. public static final XSSFRelation IMAGE_GIF = new XSSFRelation(
  176. PictureData.PictureType.GIF.contentType,
  177. PackageRelationshipTypes.IMAGE_PART,
  178. "/xl/media/image#.gif",
  179. XSSFPictureData::new, XSSFPictureData::new
  180. );
  181. public static final XSSFRelation IMAGE_TIFF = new XSSFRelation(
  182. PictureData.PictureType.TIFF.contentType,
  183. PackageRelationshipTypes.IMAGE_PART,
  184. "/xl/media/image#.tiff",
  185. XSSFPictureData::new, XSSFPictureData::new
  186. );
  187. public static final XSSFRelation IMAGE_EPS = new XSSFRelation(
  188. PictureData.PictureType.EPS.contentType,
  189. PackageRelationshipTypes.IMAGE_PART,
  190. "/xl/media/image#.eps",
  191. XSSFPictureData::new, XSSFPictureData::new
  192. );
  193. public static final XSSFRelation IMAGE_BMP = new XSSFRelation(
  194. PictureData.PictureType.BMP.contentType,
  195. PackageRelationshipTypes.IMAGE_PART,
  196. "/xl/media/image#.bmp",
  197. XSSFPictureData::new, XSSFPictureData::new
  198. );
  199. public static final XSSFRelation IMAGE_WPG = new XSSFRelation(
  200. PictureData.PictureType.WPG.contentType,
  201. PackageRelationshipTypes.IMAGE_PART,
  202. "/xl/media/image#.wpg",
  203. XSSFPictureData::new, XSSFPictureData::new
  204. );
  205. public static final XSSFRelation HDPHOTO_WDP = new XSSFRelation(
  206. PictureData.PictureType.WDP.contentType,
  207. PackageRelationshipTypes.HDPHOTO_PART,
  208. "/xl/media/hdphoto#.wdp",
  209. XSSFPictureData::new, XSSFPictureData::new
  210. );
  211. public static final XSSFRelation SHEET_COMMENTS = new XSSFRelation(
  212. "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",
  213. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
  214. "/xl/comments#.xml",
  215. CommentsTable::new, CommentsTable::new
  216. );
  217. public static final XSSFRelation SHEET_HYPERLINKS = new XSSFRelation(
  218. null,
  219. PackageRelationshipTypes.HYPERLINK_PART,
  220. null
  221. );
  222. public static final XSSFRelation OLEEMBEDDINGS = new XSSFRelation(
  223. "application/vnd.openxmlformats-officedocument.oleObject",
  224. POIXMLDocument.OLE_OBJECT_REL_TYPE,
  225. "/xl/embeddings/oleObject#.bin"
  226. );
  227. public static final XSSFRelation PACKEMBEDDINGS = new XSSFRelation(
  228. null,
  229. POIXMLDocument.PACK_OBJECT_REL_TYPE,
  230. null
  231. );
  232. public static final XSSFRelation VBA_MACROS = new XSSFRelation(
  233. "application/vnd.ms-office.vbaProject",
  234. "http://schemas.microsoft.com/office/2006/relationships/vbaProject",
  235. "/xl/vbaProject.bin",
  236. XSSFVBAPart::new, XSSFVBAPart::new
  237. );
  238. public static final XSSFRelation ACTIVEX_CONTROLS = new XSSFRelation(
  239. "application/vnd.ms-office.activeX+xml",
  240. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/control",
  241. "/xl/activeX/activeX#.xml"
  242. );
  243. public static final XSSFRelation ACTIVEX_BINS = new XSSFRelation(
  244. "application/vnd.ms-office.activeX",
  245. "http://schemas.microsoft.com/office/2006/relationships/activeXControlBinary",
  246. "/xl/activeX/activeX#.bin"
  247. );
  248. public static final XSSFRelation MACRO_SHEET_BIN = new XSSFRelation(
  249. "application/vnd.ms-excel.macrosheet",
  250. "http://schemas.microsoft.com/office/2006/relationships/xlMacrosheet",
  251. "/xl/macroSheets/sheet#.bin"
  252. );
  253. public static final XSSFRelation MACRO_SHEET_XML = new XSSFRelation(
  254. "application/vnd.ms-excel.macrosheet+xml",
  255. "http://schemas.microsoft.com/office/2006/relationships/xlMacrosheet",
  256. "/xl/macroSheets/sheet#.xml"
  257. );
  258. public static final XSSFRelation INTL_MACRO_SHEET_BIN = new XSSFRelation(
  259. "application/vnd.ms-excel.intlmacrosheet",
  260. "http://schemas.microsoft.com/office/2006/relationships/xlIntlMacrosheet",
  261. "/xl/macroSheets/sheet#.bin"
  262. );
  263. public static final XSSFRelation INTL_MACRO_SHEET_XML = new XSSFRelation(
  264. "application/vnd.ms-excel.intlmacrosheet+xml",
  265. "http://schemas.microsoft.com/office/2006/relationships/xlIntlMacrosheet",
  266. "/xl/macroSheets/sheet#.xml"
  267. );
  268. public static final XSSFRelation DIALOG_SHEET_BIN = new XSSFRelation(
  269. null,//TODO: figure out what this should be?
  270. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/dialogsheet",
  271. "/xl/dialogSheets/sheet#.bin"
  272. );
  273. public static final XSSFRelation THEME = new XSSFRelation(
  274. "application/vnd.openxmlformats-officedocument.theme+xml",
  275. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
  276. "/xl/theme/theme#.xml",
  277. ThemesTable::new, ThemesTable::new
  278. );
  279. public static final XSSFRelation CALC_CHAIN = new XSSFRelation(
  280. "application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml",
  281. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain",
  282. "/xl/calcChain.xml",
  283. CalculationChain::new, CalculationChain::new
  284. );
  285. public static final XSSFRelation EXTERNAL_LINKS = new XSSFRelation(
  286. "application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml",
  287. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink",
  288. "/xl/externalLinks/externalLink#.xml",
  289. ExternalLinksTable::new, ExternalLinksTable::new
  290. );
  291. public static final XSSFRelation PRINTER_SETTINGS = new XSSFRelation(
  292. "application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings",
  293. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings",
  294. "/xl/printerSettings/printerSettings#.bin"
  295. );
  296. public static final XSSFRelation PIVOT_TABLE = new XSSFRelation(
  297. "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",
  298. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable",
  299. "/xl/pivotTables/pivotTable#.xml",
  300. XSSFPivotTable::new, XSSFPivotTable::new
  301. );
  302. public static final XSSFRelation PIVOT_CACHE_DEFINITION = new XSSFRelation(
  303. "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml",
  304. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition",
  305. "/xl/pivotCache/pivotCacheDefinition#.xml",
  306. XSSFPivotCacheDefinition::new, XSSFPivotCacheDefinition::new
  307. );
  308. public static final XSSFRelation PIVOT_CACHE_RECORDS = new XSSFRelation(
  309. "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml",
  310. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords",
  311. "/xl/pivotCache/pivotCacheRecords#.xml",
  312. XSSFPivotCacheRecords::new, XSSFPivotCacheRecords::new
  313. );
  314. public static final XSSFRelation CTRL_PROP_RECORDS = new XSSFRelation(
  315. null,
  316. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/ctrlProp",
  317. "/xl/ctrlProps/ctrlProp#.xml"
  318. );
  319. public static final XSSFRelation CUSTOM_PROPERTIES = new XSSFRelation(
  320. "application/vnd.openxmlformats-officedocument.spreadsheetml.customProperty",
  321. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customProperty",
  322. "/xl/customProperty#.bin"
  323. );
  324. public static final String NS_PRESENTATIONML = "http://schemas.openxmlformats.org/presentationml/2006/main";
  325. public static final String NS_WORDPROCESSINGML = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
  326. public static final String NS_SPREADSHEETML = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
  327. public static final String NS_DRAWINGML = "http://schemas.openxmlformats.org/drawingml/2006/main";
  328. public static final String NS_CHART = "http://schemas.openxmlformats.org/drawingml/2006/chart";
  329. private XSSFRelation(String type, String rel, String defaultName) {
  330. this(type,rel, defaultName, null, null);
  331. }
  332. private XSSFRelation(String type, String rel, String defaultName,
  333. NoArgConstructor noArgConstructor,
  334. PackagePartConstructor packagePartConstructor) {
  335. super(type, rel, defaultName, noArgConstructor, packagePartConstructor, null);
  336. _table.put(rel, this);
  337. }
  338. /**
  339. * Get POIXMLRelation by relation type
  340. *
  341. * @param rel relation type, for example,
  342. * <code>http://schemas.openxmlformats.org/officeDocument/2006/relationships/image</code>
  343. * @return registered POIXMLRelation or null if not found
  344. */
  345. public static XSSFRelation getInstance(String rel) {
  346. return _table.get(rel);
  347. }
  348. }