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

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