123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- /* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ==================================================================== */
-
- package org.apache.poi.xwpf.usermodel;
-
- import java.util.HashMap;
- import java.util.Map;
-
- import org.apache.poi.common.usermodel.PictureType;
- import org.apache.poi.ooxml.POIXMLDocument;
- import org.apache.poi.ooxml.POIXMLRelation;
- import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
- import org.apache.poi.xssf.usermodel.XSSFRelation;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-
- import static org.apache.poi.openxml4j.opc.PackageRelationshipTypes.HDPHOTO_PART;
- import static org.apache.poi.openxml4j.opc.PackageRelationshipTypes.IMAGE_PART;
-
- public final class XWPFRelation extends POIXMLRelation {
-
- /* package */ static final String NS_DRAWINGML = XSSFRelation.NS_DRAWINGML;
-
- /**
- * A map to lookup POIXMLRelation by its relation type
- */
- private static final Map<String, XWPFRelation> _table = new HashMap<>();
-
- public static final XWPFRelation DOCUMENT = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
- PackageRelationshipTypes.CORE_DOCUMENT,
- "/word/document.xml"
- );
-
- public static final XWPFRelation TEMPLATE = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml",
- PackageRelationshipTypes.CORE_DOCUMENT,
- "/word/document.xml"
- );
-
- public static final XWPFRelation MACRO_DOCUMENT = new XWPFRelation(
- "application/vnd.ms-word.document.macroEnabled.main+xml",
- PackageRelationshipTypes.CORE_DOCUMENT,
- "/word/document.xml"
- );
-
- public static final XWPFRelation MACRO_TEMPLATE_DOCUMENT = new XWPFRelation(
- "application/vnd.ms-word.template.macroEnabledTemplate.main+xml",
- PackageRelationshipTypes.CORE_DOCUMENT,
- "/word/document.xml"
- );
-
- public static final XWPFRelation GLOSSARY_DOCUMENT = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument",
- "/word/glossary/document.xml"
- );
-
- public static final XWPFRelation NUMBERING = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",
- "/word/numbering.xml",
- XWPFNumbering::new, XWPFNumbering::new
- );
-
- public static final XWPFRelation FONT_TABLE = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",
- "/word/fontTable.xml"
- );
-
- public static final XWPFRelation SETTINGS = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings",
- "/word/settings.xml",
- XWPFSettings::new, XWPFSettings::new
- );
-
- public static final XWPFRelation STYLES = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
- "/word/styles.xml",
- XWPFStyles::new, XWPFStyles::new
- );
-
- public static final XWPFRelation WEB_SETTINGS = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings",
- "/word/webSettings.xml"
- );
-
- public static final XWPFRelation HEADER = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
- "/word/header#.xml",
- XWPFHeader::new, XWPFHeader::new
- );
-
- public static final XWPFRelation FOOTER = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
- "/word/footer#.xml",
- XWPFFooter::new, XWPFFooter::new
- );
-
- public static final XWPFRelation THEME = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.theme+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
- "/word/theme/theme#.xml",
- XWPFTheme::new, XWPFTheme::new
- );
-
- public static final XWPFRelation WORKBOOK = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
- POIXMLDocument.PACK_OBJECT_REL_TYPE,
- "/word/embeddings/Microsoft_Excel_Worksheet#.xlsx",
- XSSFWorkbook::new, (PackagePartConstructor)XSSFWorkbook::new
- );
-
- public static final XWPFRelation CHART = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.drawingml.chart+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
- "/word/charts/chart#.xml",
- XWPFChart::new, XWPFChart::new
- );
- public static final XWPFRelation HYPERLINK = new XWPFRelation(
- null,
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
- null
- );
- public static final XWPFRelation COMMENT = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
- "/word/comments.xml",
- XWPFComments::new, XWPFComments::new
- );
- public static final XWPFRelation FOOTNOTE = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes",
- "/word/footnotes.xml",
- XWPFFootnotes::new, XWPFFootnotes::new
- );
- public static final XWPFRelation ENDNOTE = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes",
- "/word/endnotes.xml",
- XWPFEndnotes::new, XWPFEndnotes::new
- );
- /**
- * Supported image formats
- */
- public static final XWPFRelation IMAGE_EMF = new XWPFRelation(
- PictureType.EMF.contentType,
- IMAGE_PART,
- "/word/media/image#.emf",
- XWPFPictureData::new, XWPFPictureData::new
- );
- public static final XWPFRelation IMAGE_WMF = new XWPFRelation(
- PictureType.WMF.contentType,
- IMAGE_PART,
- "/word/media/image#.wmf",
- XWPFPictureData::new, XWPFPictureData::new
- );
- public static final XWPFRelation IMAGE_PICT = new XWPFRelation(
- PictureType.PICT.contentType,
- IMAGE_PART,
- "/word/media/image#.pict",
- XWPFPictureData::new, XWPFPictureData::new
- );
- public static final XWPFRelation IMAGE_JPEG = new XWPFRelation(
- PictureType.JPEG.contentType,
- IMAGE_PART,
- "/word/media/image#.jpeg",
- XWPFPictureData::new, XWPFPictureData::new
- );
- public static final XWPFRelation IMAGE_PNG = new XWPFRelation(
- PictureType.PNG.contentType,
- IMAGE_PART,
- "/word/media/image#.png",
- XWPFPictureData::new, XWPFPictureData::new
- );
- public static final XWPFRelation IMAGE_DIB = new XWPFRelation(
- PictureType.DIB.contentType,
- IMAGE_PART,
- "/word/media/image#.dib",
- XWPFPictureData::new, XWPFPictureData::new
- );
- public static final XWPFRelation IMAGE_GIF = new XWPFRelation(
- PictureType.GIF.contentType,
- IMAGE_PART,
- "/word/media/image#.gif",
- XWPFPictureData::new, XWPFPictureData::new
- );
- public static final XWPFRelation IMAGE_TIFF = new XWPFRelation(
- PictureType.TIFF.contentType,
- IMAGE_PART,
- "/word/media/image#.tiff",
- XWPFPictureData::new, XWPFPictureData::new
- );
- public static final XWPFRelation IMAGE_EPS = new XWPFRelation(
- PictureType.EPS.contentType,
- IMAGE_PART,
- "/word/media/image#.eps",
- XWPFPictureData::new, XWPFPictureData::new
- );
- public static final XWPFRelation IMAGE_BMP = new XWPFRelation(
- PictureType.BMP.contentType,
- IMAGE_PART,
- "/word/media/image#.bmp",
- XWPFPictureData::new, XWPFPictureData::new
- );
- public static final XWPFRelation IMAGE_WPG = new XWPFRelation(
- PictureType.WPG.contentType,
- IMAGE_PART,
- "/word/media/image#.wpg",
- XWPFPictureData::new, XWPFPictureData::new
- );
- public static final XWPFRelation HDPHOTO_WDP = new XWPFRelation(
- PictureType.WDP.contentType,
- HDPHOTO_PART,
- "/ppt/media/hdphoto#.wdp",
- XWPFPictureData::new, XWPFPictureData::new
- );
- public static final XWPFRelation IMAGE_SVG = new XWPFRelation(
- PictureType.SVG.contentType,
- IMAGE_PART,
- "/word/media/image#.svg",
- XWPFPictureData::new, XWPFPictureData::new
- );
- public static final XWPFRelation IMAGES = new XWPFRelation(
- null,
- IMAGE_PART,
- null,
- XWPFPictureData::new, XWPFPictureData::new
- );
-
- private XWPFRelation(String type, String rel, String defaultName) {
- super(type, rel, defaultName);
- _table.put(rel, this);
- }
-
- private XWPFRelation(String type, String rel, String defaultName,
- NoArgConstructor noArgConstructor,
- PackagePartConstructor packagePartConstructor) {
- super(type, rel, defaultName, noArgConstructor, packagePartConstructor, null);
- _table.put(rel, this);
- }
-
- private XWPFRelation(String type, String rel, String defaultName,
- NoArgConstructor noArgConstructor,
- ParentPartConstructor parentPartConstructor) {
- super(type, rel, defaultName, noArgConstructor, null, parentPartConstructor);
- _table.put(rel, this);
- }
-
- /**
- * Get POIXMLRelation by relation type
- *
- * @param rel relation type, for example,
- * <code>http://schemas.openxmlformats.org/officeDocument/2006/relationships/image</code>
- * @return registered POIXMLRelation or null if not found
- */
- public static XWPFRelation getInstance(String rel) {
- return _table.get(rel);
- }
-
- @Override
- public String toString() {
- return "XWPFRelation{" +
- //getRelation() + "/" +
- getContentType() + "/" +
- getDefaultFileName() +
- "}";
- }
- }
|