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.

POIXMLRelation.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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;
  16. /**
  17. * Represents a descriptor of a OOXML relation.
  18. *
  19. * @author Yegor Kozlov
  20. */
  21. public abstract class POIXMLRelation {
  22. /**
  23. * Describes the content stored in a part.
  24. */
  25. protected String _type;
  26. /**
  27. * The kind of connection between a source part and a target part in a package.
  28. */
  29. protected String _relation;
  30. /**
  31. * The path component of a pack URI.
  32. */
  33. protected String _defaultName;
  34. /**
  35. * Defines what object is used to construct instances of this relationship
  36. */
  37. private Class<? extends POIXMLDocumentPart> _cls;
  38. /**
  39. * Instantiates a POIXMLRelation.
  40. *
  41. * @param type content type
  42. * @param rel relationship
  43. * @param defaultName default item name
  44. * @param cls defines what object is used to construct instances of this relationship
  45. */
  46. public POIXMLRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) {
  47. _type = type;
  48. _relation = rel;
  49. _defaultName = defaultName;
  50. _cls = cls;
  51. }
  52. /**
  53. * Instantiates a POIXMLRelation.
  54. *
  55. * @param type content type
  56. * @param rel relationship
  57. * @param defaultName default item name
  58. */
  59. public POIXMLRelation(String type, String rel, String defaultName) {
  60. this(type, rel, defaultName, null);
  61. }
  62. /**
  63. * Return the content type. Content types define a media type, a subtype, and an
  64. * optional set of parameters, as defined in RFC 2616.
  65. *
  66. * @return the content type
  67. */
  68. public String getContentType() {
  69. return _type;
  70. }
  71. /**
  72. * Return the relationship, the kind of connection between a source part and a target part in a package.
  73. * Relationships make the connections between parts directly discoverable without looking at the content
  74. * in the parts, and without altering the parts themselves.
  75. *
  76. * @return the relationship
  77. */
  78. public String getRelation() {
  79. return _relation;
  80. }
  81. /**
  82. * Return the default part name. Part names are used to refer to a part in the context of a
  83. * package, typically as part of a URI.
  84. *
  85. * @return the default part name
  86. */
  87. public String getDefaultFileName() {
  88. return _defaultName;
  89. }
  90. /**
  91. * Returns the filename for the nth one of these,
  92. * e.g. /xl/comments4.xml
  93. */
  94. public String getFileName(int index) {
  95. if(_defaultName.indexOf("#") == -1) {
  96. // Generic filename in all cases
  97. return getDefaultFileName();
  98. }
  99. return _defaultName.replace("#", Integer.toString(index));
  100. }
  101. /**
  102. * Return type of the obejct used to construct instances of this relationship
  103. *
  104. * @return the class of the object used to construct instances of this relation
  105. */
  106. public Class<? extends POIXMLDocumentPart> getRelationClass(){
  107. return _cls;
  108. }
  109. }