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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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 SHARED_STRINGS = new XSSFRelation(
  82. "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",
  83. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",
  84. "/xl/sharedStrings.xml",
  85. SharedStringsTable::new, SharedStringsTable::new
  86. );
  87. public static final XSSFRelation STYLES = new XSSFRelation(
  88. "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",
  89. PackageRelationshipTypes.STYLE_PART,
  90. "/xl/styles.xml",
  91. StylesTable::new, StylesTable::new
  92. );
  93. public static final XSSFRelation DRAWINGS = new XSSFRelation(
  94. "application/vnd.openxmlformats-officedocument.drawing+xml",
  95. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",
  96. "/xl/drawings/drawing#.xml",
  97. XSSFDrawing::new, XSSFDrawing::new
  98. );
  99. public static final XSSFRelation VML_DRAWINGS = new XSSFRelation(
  100. "application/vnd.openxmlformats-officedocument.vmlDrawing",
  101. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing",
  102. "/xl/drawings/vmlDrawing#.vml",
  103. XSSFVMLDrawing::new, XSSFVMLDrawing::new
  104. );
  105. public static final XSSFRelation CHART = new XSSFRelation(
  106. "application/vnd.openxmlformats-officedocument.drawingml.chart+xml",
  107. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
  108. "/xl/charts/chart#.xml",
  109. XSSFChart::new, XSSFChart::new
  110. );
  111. public static final XSSFRelation CUSTOM_XML_MAPPINGS = new XSSFRelation(
  112. "application/xml",
  113. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/xmlMaps",
  114. "/xl/xmlMaps.xml",
  115. MapInfo::new, MapInfo::new
  116. );
  117. public static final XSSFRelation SINGLE_XML_CELLS = new XSSFRelation(
  118. "application/vnd.openxmlformats-officedocument.spreadsheetml.tableSingleCells+xml",
  119. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableSingleCells",
  120. "/xl/tables/tableSingleCells#.xml",
  121. SingleXmlCells::new, SingleXmlCells::new
  122. );
  123. public static final XSSFRelation TABLE = new XSSFRelation(
  124. "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",
  125. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",
  126. "/xl/tables/table#.xml",
  127. XSSFTable::new, XSSFTable::new
  128. );
  129. public static final XSSFRelation IMAGES = new XSSFRelation(
  130. null,
  131. PackageRelationshipTypes.IMAGE_PART,
  132. null,
  133. XSSFPictureData::new, XSSFPictureData::new
  134. );
  135. public static final XSSFRelation IMAGE_EMF = new XSSFRelation(
  136. PictureData.PictureType.EMF.contentType,
  137. PackageRelationshipTypes.IMAGE_PART,
  138. "/xl/media/image#.emf",
  139. XSSFPictureData::new, XSSFPictureData::new
  140. );
  141. public static final XSSFRelation IMAGE_WMF = new XSSFRelation(
  142. PictureData.PictureType.WMF.contentType,
  143. PackageRelationshipTypes.IMAGE_PART,
  144. "/xl/media/image#.wmf",
  145. XSSFPictureData::new, XSSFPictureData::new
  146. );
  147. public static final XSSFRelation IMAGE_PICT = new XSSFRelation(
  148. PictureData.PictureType.PICT.contentType,
  149. PackageRelationshipTypes.IMAGE_PART,
  150. "/xl/media/image#.pict",
  151. XSSFPictureData::new, XSSFPictureData::new
  152. );
  153. public static final XSSFRelation IMAGE_JPEG = new XSSFRelation(
  154. PictureData.PictureType.JPEG.contentType,
  155. PackageRelationshipTypes.IMAGE_PART,
  156. "/xl/media/image#.jpeg",
  157. XSSFPictureData::new, XSSFPictureData::new
  158. );
  159. public static final XSSFRelation IMAGE_PNG = new XSSFRelation(
  160. PictureData.PictureType.PNG.contentType,
  161. PackageRelationshipTypes.IMAGE_PART,
  162. "/xl/media/image#.png",
  163. XSSFPictureData::new, XSSFPictureData::new
  164. );
  165. public static final XSSFRelation IMAGE_DIB = new XSSFRelation(
  166. PictureData.PictureType.DIB.contentType,
  167. PackageRelationshipTypes.IMAGE_PART,
  168. "/xl/media/image#.dib",
  169. XSSFPictureData::new, XSSFPictureData::new
  170. );
  171. public static final XSSFRelation IMAGE_GIF = new XSSFRelation(
  172. PictureData.PictureType.GIF.contentType,
  173. PackageRelationshipTypes.IMAGE_PART,
  174. "/xl/media/image#.gif",
  175. XSSFPictureData::new, XSSFPictureData::new
  176. );
  177. public static final XSSFRelation IMAGE_TIFF = new XSSFRelation(
  178. PictureData.PictureType.TIFF.contentType,
  179. PackageRelationshipTypes.IMAGE_PART,
  180. "/xl/media/image#.tiff",
  181. XSSFPictureData::new, XSSFPictureData::new
  182. );
  183. public static final XSSFRelation IMAGE_EPS = new XSSFRelation(
  184. PictureData.PictureType.EPS.contentType,
  185. PackageRelationshipTypes.IMAGE_PART,
  186. "/xl/media/image#.eps",
  187. XSSFPictureData::new, XSSFPictureData::new
  188. );
  189. public static final XSSFRelation IMAGE_BMP = new XSSFRelation(
  190. PictureData.PictureType.BMP.contentType,
  191. PackageRelationshipTypes.IMAGE_PART,
  192. "/xl/media/image#.bmp",
  193. XSSFPictureData::new, XSSFPictureData::new
  194. );
  195. public static final XSSFRelation IMAGE_WPG = new XSSFRelation(
  196. PictureData.PictureType.WPG.contentType,
  197. PackageRelationshipTypes.IMAGE_PART,
  198. "/xl/media/image#.wpg",
  199. XSSFPictureData::new, XSSFPictureData::new
  200. );
  201. public static final XSSFRelation HDPHOTO_WDP = new XSSFRelation(
  202. PictureData.PictureType.WDP.contentType,
  203. PackageRelationshipTypes.HDPHOTO_PART,
  204. "/xl/media/hdphoto#.wdp",
  205. XSSFPictureData::new, XSSFPictureData::new
  206. );
  207. public static final XSSFRelation SHEET_COMMENTS = new XSSFRelation(
  208. "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",
  209. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
  210. "/xl/comments#.xml",
  211. CommentsTable::new, CommentsTable::new
  212. );
  213. public static final XSSFRelation SHEET_HYPERLINKS = new XSSFRelation(
  214. null,
  215. PackageRelationshipTypes.HYPERLINK_PART,
  216. null
  217. );
  218. public static final XSSFRelation OLEEMBEDDINGS = new XSSFRelation(
  219. "application/vnd.openxmlformats-officedocument.oleObject",
  220. POIXMLDocument.OLE_OBJECT_REL_TYPE,
  221. "/xl/embeddings/oleObject#.bin"
  222. );
  223. public static final XSSFRelation PACKEMBEDDINGS = new XSSFRelation(
  224. null,
  225. POIXMLDocument.PACK_OBJECT_REL_TYPE,
  226. null
  227. );
  228. public static final XSSFRelation VBA_MACROS = new XSSFRelation(
  229. "application/vnd.ms-office.vbaProject",
  230. "http://schemas.microsoft.com/office/2006/relationships/vbaProject",
  231. "/xl/vbaProject.bin",
  232. XSSFVBAPart::new, XSSFVBAPart::new
  233. );
  234. public static final XSSFRelation ACTIVEX_CONTROLS = new XSSFRelation(
  235. "application/vnd.ms-office.activeX+xml",
  236. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/control",
  237. "/xl/activeX/activeX#.xml"
  238. );
  239. public static final XSSFRelation ACTIVEX_BINS = new XSSFRelation(
  240. "application/vnd.ms-office.activeX",
  241. "http://schemas.microsoft.com/office/2006/relationships/activeXControlBinary",
  242. "/xl/activeX/activeX#.bin"
  243. );
  244. public static final XSSFRelation MACRO_SHEET_BIN = new XSSFRelation(
  245. "application/vnd.ms-excel.macrosheet",
  246. "http://schemas.microsoft.com/office/2006/relationships/xlMacrosheet",
  247. "/xl/macroSheets/sheet#.bin"
  248. );
  249. public static final XSSFRelation MACRO_SHEET_XML = new XSSFRelation(
  250. "application/vnd.ms-excel.macrosheet+xml",
  251. "http://schemas.microsoft.com/office/2006/relationships/xlMacrosheet",
  252. "/xl/macroSheets/sheet#.xml"
  253. );
  254. public static final XSSFRelation INTL_MACRO_SHEET_BIN = new XSSFRelation(
  255. "application/vnd.ms-excel.intlmacrosheet",
  256. "http://schemas.microsoft.com/office/2006/relationships/xlIntlMacrosheet",
  257. "/xl/macroSheets/sheet#.bin"
  258. );
  259. public static final XSSFRelation INTL_MACRO_SHEET_XML = new XSSFRelation(
  260. "application/vnd.ms-excel.intlmacrosheet+xml",
  261. "http://schemas.microsoft.com/office/2006/relationships/xlIntlMacrosheet",
  262. "/xl/macroSheets/sheet#.xml"
  263. );
  264. public static final XSSFRelation DIALOG_SHEET_BIN = new XSSFRelation(
  265. null,//TODO: figure out what this should be?
  266. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/dialogsheet",
  267. "/xl/dialogSheets/sheet#.bin"
  268. );
  269. public static final XSSFRelation THEME = new XSSFRelation(
  270. "application/vnd.openxmlformats-officedocument.theme+xml",
  271. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
  272. "/xl/theme/theme#.xml",
  273. ThemesTable::new, ThemesTable::new
  274. );
  275. public static final XSSFRelation CALC_CHAIN = new XSSFRelation(
  276. "application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml",
  277. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain",
  278. "/xl/calcChain.xml",
  279. CalculationChain::new, CalculationChain::new
  280. );
  281. public static final XSSFRelation EXTERNAL_LINKS = new XSSFRelation(
  282. "application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml",
  283. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink",
  284. "/xl/externalLinks/externalLink#.xml",
  285. ExternalLinksTable::new, ExternalLinksTable::new
  286. );
  287. public static final XSSFRelation PRINTER_SETTINGS = new XSSFRelation(
  288. "application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings",
  289. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings",
  290. "/xl/printerSettings/printerSettings#.bin"
  291. );
  292. public static final XSSFRelation PIVOT_TABLE = new XSSFRelation(
  293. "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",
  294. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable",
  295. "/xl/pivotTables/pivotTable#.xml",
  296. XSSFPivotTable::new, XSSFPivotTable::new
  297. );
  298. public static final XSSFRelation PIVOT_CACHE_DEFINITION = new XSSFRelation(
  299. "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml",
  300. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition",
  301. "/xl/pivotCache/pivotCacheDefinition#.xml",
  302. XSSFPivotCacheDefinition::new, XSSFPivotCacheDefinition::new
  303. );
  304. public static final XSSFRelation PIVOT_CACHE_RECORDS = new XSSFRelation(
  305. "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml",
  306. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords",
  307. "/xl/pivotCache/pivotCacheRecords#.xml",
  308. XSSFPivotCacheRecords::new, XSSFPivotCacheRecords::new
  309. );
  310. public static final XSSFRelation CTRL_PROP_RECORDS = new XSSFRelation(
  311. null,
  312. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/ctrlProp",
  313. "/xl/ctrlProps/ctrlProp#.xml"
  314. );
  315. public static final XSSFRelation CUSTOM_PROPERTIES = new XSSFRelation(
  316. "application/vnd.openxmlformats-officedocument.spreadsheetml.customProperty",
  317. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customProperty",
  318. "/xl/customProperty#.bin"
  319. );
  320. public static final String NS_PRESENTATIONML = "http://schemas.openxmlformats.org/presentationml/2006/main";
  321. public static final String NS_WORDPROCESSINGML = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
  322. public static final String NS_SPREADSHEETML = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
  323. public static final String NS_DRAWINGML = "http://schemas.openxmlformats.org/drawingml/2006/main";
  324. public static final String NS_CHART = "http://schemas.openxmlformats.org/drawingml/2006/chart";
  325. private XSSFRelation(String type, String rel, String defaultName) {
  326. this(type,rel, defaultName, null, null);
  327. }
  328. private XSSFRelation(String type, String rel, String defaultName,
  329. NoArgConstructor noArgConstructor,
  330. PackagePartConstructor packagePartConstructor) {
  331. super(type, rel, defaultName, noArgConstructor, packagePartConstructor, null);
  332. _table.put(rel, this);
  333. }
  334. /**
  335. * Get POIXMLRelation by relation type
  336. *
  337. * @param rel relation type, for example,
  338. * <code>http://schemas.openxmlformats.org/officeDocument/2006/relationships/image</code>
  339. * @return registered POIXMLRelation or null if not found
  340. */
  341. public static XSSFRelation getInstance(String rel) {
  342. return _table.get(rel);
  343. }
  344. }