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 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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.POIXMLDocumentPart;
  20. import org.apache.poi.ooxml.POIXMLRelation;
  21. import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
  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. null
  44. );
  45. public static final XSSFRelation MACROS_WORKBOOK = new XSSFRelation(
  46. "application/vnd.ms-excel.sheet.macroEnabled.main+xml",
  47. PackageRelationshipTypes.CORE_DOCUMENT,
  48. "/xl/workbook.xml",
  49. null
  50. );
  51. public static final XSSFRelation TEMPLATE_WORKBOOK = new XSSFRelation(
  52. "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml",
  53. PackageRelationshipTypes.CORE_DOCUMENT,
  54. "/xl/workbook.xml",
  55. null
  56. );
  57. public static final XSSFRelation MACRO_TEMPLATE_WORKBOOK = new XSSFRelation(
  58. "application/vnd.ms-excel.template.macroEnabled.main+xml",
  59. PackageRelationshipTypes.CORE_DOCUMENT,
  60. "/xl/workbook.xml",
  61. null
  62. );
  63. public static final XSSFRelation MACRO_ADDIN_WORKBOOK = new XSSFRelation(
  64. "application/vnd.ms-excel.addin.macroEnabled.main+xml",
  65. PackageRelationshipTypes.CORE_DOCUMENT,
  66. "/xl/workbook.xml",
  67. null
  68. );
  69. public static final XSSFRelation XLSB_BINARY_WORKBOOK = new XSSFRelation(
  70. "application/vnd.ms-excel.sheet.binary.macroEnabled.main",
  71. PackageRelationshipTypes.CORE_DOCUMENT,
  72. "/xl/workbook.bin",
  73. null
  74. );
  75. public static final XSSFRelation WORKSHEET = new XSSFRelation(
  76. "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",
  77. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",
  78. "/xl/worksheets/sheet#.xml",
  79. XSSFSheet.class
  80. );
  81. public static final XSSFRelation CHARTSHEET = new XSSFRelation(
  82. "application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml",
  83. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet",
  84. "/xl/chartsheets/sheet#.xml",
  85. XSSFChartSheet.class
  86. );
  87. public static final XSSFRelation SHARED_STRINGS = new XSSFRelation(
  88. "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",
  89. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",
  90. "/xl/sharedStrings.xml",
  91. SharedStringsTable.class
  92. );
  93. public static final XSSFRelation STYLES = new XSSFRelation(
  94. "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",
  95. PackageRelationshipTypes.STYLE_PART,
  96. "/xl/styles.xml",
  97. StylesTable.class
  98. );
  99. public static final XSSFRelation DRAWINGS = new XSSFRelation(
  100. "application/vnd.openxmlformats-officedocument.drawing+xml",
  101. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",
  102. "/xl/drawings/drawing#.xml",
  103. XSSFDrawing.class
  104. );
  105. public static final XSSFRelation VML_DRAWINGS = new XSSFRelation(
  106. "application/vnd.openxmlformats-officedocument.vmlDrawing",
  107. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing",
  108. "/xl/drawings/vmlDrawing#.vml",
  109. XSSFVMLDrawing.class
  110. );
  111. public static final XSSFRelation CHART = new XSSFRelation(
  112. "application/vnd.openxmlformats-officedocument.drawingml.chart+xml",
  113. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
  114. "/xl/charts/chart#.xml",
  115. XSSFChart.class
  116. );
  117. public static final XSSFRelation CUSTOM_XML_MAPPINGS = new XSSFRelation(
  118. "application/xml",
  119. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/xmlMaps",
  120. "/xl/xmlMaps.xml",
  121. MapInfo.class
  122. );
  123. public static final XSSFRelation SINGLE_XML_CELLS = new XSSFRelation(
  124. "application/vnd.openxmlformats-officedocument.spreadsheetml.tableSingleCells+xml",
  125. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableSingleCells",
  126. "/xl/tables/tableSingleCells#.xml",
  127. SingleXmlCells.class
  128. );
  129. public static final XSSFRelation TABLE = new XSSFRelation(
  130. "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",
  131. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",
  132. "/xl/tables/table#.xml",
  133. XSSFTable.class
  134. );
  135. public static final XSSFRelation IMAGES = new XSSFRelation(
  136. null,
  137. PackageRelationshipTypes.IMAGE_PART,
  138. null,
  139. XSSFPictureData.class
  140. );
  141. public static final XSSFRelation IMAGE_EMF = new XSSFRelation(
  142. "image/x-emf",
  143. PackageRelationshipTypes.IMAGE_PART,
  144. "/xl/media/image#.emf",
  145. XSSFPictureData.class
  146. );
  147. public static final XSSFRelation IMAGE_WMF = new XSSFRelation(
  148. "image/x-wmf",
  149. PackageRelationshipTypes.IMAGE_PART,
  150. "/xl/media/image#.wmf",
  151. XSSFPictureData.class
  152. );
  153. public static final XSSFRelation IMAGE_PICT = new XSSFRelation(
  154. "image/pict",
  155. PackageRelationshipTypes.IMAGE_PART,
  156. "/xl/media/image#.pict",
  157. XSSFPictureData.class
  158. );
  159. public static final XSSFRelation IMAGE_JPEG = new XSSFRelation(
  160. "image/jpeg",
  161. PackageRelationshipTypes.IMAGE_PART,
  162. "/xl/media/image#.jpeg",
  163. XSSFPictureData.class
  164. );
  165. public static final XSSFRelation IMAGE_PNG = new XSSFRelation(
  166. "image/png",
  167. PackageRelationshipTypes.IMAGE_PART,
  168. "/xl/media/image#.png",
  169. XSSFPictureData.class
  170. );
  171. public static final XSSFRelation IMAGE_DIB = new XSSFRelation(
  172. "image/dib",
  173. PackageRelationshipTypes.IMAGE_PART,
  174. "/xl/media/image#.dib",
  175. XSSFPictureData.class
  176. );
  177. public static final XSSFRelation IMAGE_GIF = new XSSFRelation(
  178. "image/gif",
  179. PackageRelationshipTypes.IMAGE_PART,
  180. "/xl/media/image#.gif",
  181. XSSFPictureData.class
  182. );
  183. public static final XSSFRelation IMAGE_TIFF = new XSSFRelation(
  184. "image/tiff",
  185. PackageRelationshipTypes.IMAGE_PART,
  186. "/xl/media/image#.tiff",
  187. XSSFPictureData.class
  188. );
  189. public static final XSSFRelation IMAGE_EPS = new XSSFRelation(
  190. "image/x-eps",
  191. PackageRelationshipTypes.IMAGE_PART,
  192. "/xl/media/image#.eps",
  193. XSSFPictureData.class
  194. );
  195. public static final XSSFRelation IMAGE_BMP = new XSSFRelation(
  196. "image/x-ms-bmp",
  197. PackageRelationshipTypes.IMAGE_PART,
  198. "/xl/media/image#.bmp",
  199. XSSFPictureData.class
  200. );
  201. public static final XSSFRelation IMAGE_WPG = new XSSFRelation(
  202. "image/x-wpg",
  203. PackageRelationshipTypes.IMAGE_PART,
  204. "/xl/media/image#.wpg",
  205. XSSFPictureData.class
  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.class
  212. );
  213. public static final XSSFRelation SHEET_HYPERLINKS = new XSSFRelation(
  214. null,
  215. PackageRelationshipTypes.HYPERLINK_PART,
  216. null,
  217. null
  218. );
  219. public static final XSSFRelation OLEEMBEDDINGS = new XSSFRelation(
  220. null,
  221. POIXMLDocument.OLE_OBJECT_REL_TYPE,
  222. null,
  223. null
  224. );
  225. public static final XSSFRelation PACKEMBEDDINGS = new XSSFRelation(
  226. null,
  227. POIXMLDocument.PACK_OBJECT_REL_TYPE,
  228. null,
  229. null
  230. );
  231. public static final XSSFRelation VBA_MACROS = new XSSFRelation(
  232. "application/vnd.ms-office.vbaProject",
  233. "http://schemas.microsoft.com/office/2006/relationships/vbaProject",
  234. "/xl/vbaProject.bin",
  235. XSSFVBAPart.class
  236. );
  237. public static final XSSFRelation ACTIVEX_CONTROLS = new XSSFRelation(
  238. "application/vnd.ms-office.activeX+xml",
  239. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/control",
  240. "/xl/activeX/activeX#.xml",
  241. null
  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. null
  248. );
  249. public static final XSSFRelation MACRO_SHEET_BIN = new XSSFRelation(
  250. null,//TODO: figure out what this should be?
  251. "http://schemas.microsoft.com/office/2006/relationships/xlMacrosheet",
  252. "/xl/macroSheets/sheet#.bin",
  253. null
  254. );
  255. public static final XSSFRelation INTL_MACRO_SHEET_BIN = new XSSFRelation(
  256. null,//TODO: figure out what this should be?
  257. "http://schemas.microsoft.com/office/2006/relationships/xlIntlMacrosheet",
  258. "/xl/macroSheets/sheet#.bin",
  259. null
  260. );
  261. public static final XSSFRelation DIALOG_SHEET_BIN = new XSSFRelation(
  262. null,//TODO: figure out what this should be?
  263. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/dialogsheet",
  264. "/xl/dialogSheets/sheet#.bin",
  265. null
  266. );
  267. public static final XSSFRelation THEME = new XSSFRelation(
  268. "application/vnd.openxmlformats-officedocument.theme+xml",
  269. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
  270. "/xl/theme/theme#.xml",
  271. ThemesTable.class
  272. );
  273. public static final XSSFRelation CALC_CHAIN = new XSSFRelation(
  274. "application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml",
  275. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain",
  276. "/xl/calcChain.xml",
  277. CalculationChain.class
  278. );
  279. public static final XSSFRelation EXTERNAL_LINKS = new XSSFRelation(
  280. "application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml",
  281. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink",
  282. "/xl/externalLinks/externalLink#.xmll",
  283. ExternalLinksTable.class
  284. );
  285. public static final XSSFRelation PRINTER_SETTINGS = new XSSFRelation(
  286. "application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings",
  287. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings",
  288. "/xl/printerSettings/printerSettings#.bin",
  289. null
  290. );
  291. public static final XSSFRelation PIVOT_TABLE = new XSSFRelation(
  292. "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",
  293. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable",
  294. "/xl/pivotTables/pivotTable#.xml",
  295. XSSFPivotTable.class
  296. );
  297. public static final XSSFRelation PIVOT_CACHE_DEFINITION = new XSSFRelation(
  298. "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml",
  299. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition",
  300. "/xl/pivotCache/pivotCacheDefinition#.xml",
  301. XSSFPivotCacheDefinition.class
  302. );
  303. public static final XSSFRelation PIVOT_CACHE_RECORDS = new XSSFRelation(
  304. "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml",
  305. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords",
  306. "/xl/pivotCache/pivotCacheRecords#.xml",
  307. XSSFPivotCacheRecords.class
  308. );
  309. public static final XSSFRelation CTRL_PROP_RECORDS = new XSSFRelation(
  310. null,
  311. "http://schemas.openxmlformats.org/officeDocument/2006/relationships/ctrlProp",
  312. "/xl/ctrlProps/ctrlProp#.xml",
  313. null
  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. null
  320. );
  321. public static final String NS_SPREADSHEETML = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
  322. public static final String NS_DRAWINGML = "http://schemas.openxmlformats.org/drawingml/2006/main";
  323. public static final String NS_CHART = "http://schemas.openxmlformats.org/drawingml/2006/chart";
  324. private XSSFRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) {
  325. super(type, rel, defaultName, cls);
  326. _table.put(rel, this);
  327. }
  328. /**
  329. * Get POIXMLRelation by relation type
  330. *
  331. * @param rel relation type, for example,
  332. * <code>http://schemas.openxmlformats.org/officeDocument/2006/relationships/image</code>
  333. * @return registered POIXMLRelation or null if not found
  334. */
  335. public static XSSFRelation getInstance(String rel) {
  336. return _table.get(rel);
  337. }
  338. }