| 1 | /* |
|---|
| 2 | * Copyright 2007-2008, Plutext Pty Ltd. |
|---|
| 3 | * |
|---|
| 4 | * This file is part of docx4j. |
|---|
| 5 | |
|---|
| 6 | docx4j is licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 7 | you may not use this file except in compliance with the License. |
|---|
| 8 | |
|---|
| 9 | You may obtain a copy of the License at |
|---|
| 10 | |
|---|
| 11 | http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 12 | |
|---|
| 13 | Unless required by applicable law or agreed to in writing, software |
|---|
| 14 | distributed under the License is distributed on an "AS IS" BASIS, |
|---|
| 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|---|
| 16 | See the License for the specific language governing permissions and |
|---|
| 17 | limitations under the License. |
|---|
| 18 | |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | package org.docx4j.openpackaging.parts; |
|---|
| 22 | |
|---|
| 23 | import org.apache.log4j.Logger; |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | /** "When set to External, the target attribute may be a relative |
|---|
| 28 | * reference or a URI. If the target attribute is a relative |
|---|
| 29 | * reference, then that reference is interpreted relative to the |
|---|
| 30 | * location of the package." |
|---|
| 31 | * |
|---|
| 32 | * <rel:Relationship Id="rId5" Target="http://guest%40public0902:guest@alpha.plutext.org/alfresco/plutextwebdav/User%20Homes/tester/evolution.docx/word/media/image1.png" |
|---|
| 33 | * TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" xmlns=""/> |
|---|
| 34 | * |
|---|
| 35 | * Note: this method assumes an absolute location. |
|---|
| 36 | * |
|---|
| 37 | * ECMA 376 is a little bit ambiguous about whether an |
|---|
| 38 | * external resource is a "part" or not. |
|---|
| 39 | * |
|---|
| 40 | * - the definition of part implies that it is; there is no definition of resource |
|---|
| 41 | * |
|---|
| 42 | * - but the definition of part name in 8.1.1 "refers to parts _within_ a package" |
|---|
| 43 | * (but is within logical or physical?) |
|---|
| 44 | * |
|---|
| 45 | * - 8.3 Relationships: "Parts often contain references to other parts |
|---|
| 46 | * in the package and to resources outside the package" |
|---|
| 47 | * |
|---|
| 48 | * (POI has TargetMode and POIXMLRelation; they have PackagePart.addExternalRelationship |
|---|
| 49 | * |
|---|
| 50 | * We'll call them external resources. |
|---|
| 51 | * |
|---|
| 52 | * When we load an external resource, it is loaded as a part. |
|---|
| 53 | * |
|---|
| 54 | * But it is not stored in the package's parts collection; instead it is stored |
|---|
| 55 | * in a collection called ExternalResources. |
|---|
| 56 | * |
|---|
| 57 | * An ExternalTarget is the value of @target, made absolute |
|---|
| 58 | * if necessary. |
|---|
| 59 | * |
|---|
| 60 | * We don't need explicit support in RelationshipsPart for adding an external |
|---|
| 61 | * resource; you can do that by creating a Relationship object, then calling |
|---|
| 62 | * addRelationship (your reference in your @target should be relative, not absolute). |
|---|
| 63 | */ |
|---|
| 64 | public final class ExternalTarget { |
|---|
| 65 | |
|---|
| 66 | private static Logger log = Logger.getLogger(ExternalTarget.class); |
|---|
| 67 | |
|---|
| 68 | String target; |
|---|
| 69 | public String getValue() { |
|---|
| 70 | return target; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | public ExternalTarget(String target) |
|---|
| 74 | { |
|---|
| 75 | this.target = target; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | @Override |
|---|
| 79 | public boolean equals(Object other) { |
|---|
| 80 | |
|---|
| 81 | if (other == null |
|---|
| 82 | || !(other instanceof ExternalTarget)) |
|---|
| 83 | return false; |
|---|
| 84 | return this.target.equals( |
|---|
| 85 | ((ExternalTarget) other).getValue()); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | @Override |
|---|
| 89 | public int hashCode() { |
|---|
| 90 | return this.target.hashCode(); |
|---|
| 91 | } |
|---|
| 92 | } |
|---|