}
/**
- * Returns the list of child relations for this POIXMLDocumentPart
+ * Returns the list of child relations for this POIXMLDocumentPart.
+ *
+ * <p>
+ * Since POI 5.2.6, Reference Relationships are stored separately from other child relations.
+ * </p>
*
* @return child relations
+ * @see #getReferenceRelationships() for reference relationships (e.g. hyperlinks)
*/
public final List<RelationPart> getRelationParts() {
List<RelationPart> l = new ArrayList<>(relations.values());
* @return true, if the relation was removed
* @since POI 5.2.6
*/
- public boolean removeReferenceRelationship(String relId) {
+ public final boolean removeReferenceRelationship(String relId) {
ReferenceRelationship existing = referenceRelationships.remove(relId);
if (existing != null) {
packagePart.removeRelationship(relId);
* @return the reference relationship or {@code null} if not found
* @since POI 5.2.6
*/
- public ReferenceRelationship getReferenceRelationship(String relId) {
+ public final ReferenceRelationship getReferenceRelationship(String relId) {
return referenceRelationships.get(relId);
}
* @return the created reference relationship
* @since POI 5.2.6
*/
- public HyperlinkRelationship createHyperlink(URI uri, boolean isExternal, String relId) {
+ public final HyperlinkRelationship createHyperlink(URI uri, boolean isExternal, String relId) {
PackageRelationship pr = packagePart.addRelationship(uri, isExternal ? TargetMode.EXTERNAL : TargetMode.INTERNAL,
PackageRelationshipTypes.HYPERLINK_PART, relId);
HyperlinkRelationship hyperlink = new HyperlinkRelationship(this, uri, isExternal, relId);
*
* @return reference relationships
* @since POI 5.2.6
+ * @see #getRelationParts() for child relations
*/
- public List<ReferenceRelationship> getReferenceRelationships() {
+ public final List<ReferenceRelationship> getReferenceRelationships() {
List<ReferenceRelationship> list = new ArrayList<>(referenceRelationships.values());
return Collections.unmodifiableList(list);
}
assertNotNull(rId1);
URI parent = drawingPart.getPartName().getURI();
// Hyperlink is not a target of relativize() because it is not resolved based on sourceURI in getTargetURI()
-// URI rel1 = parent.relativize(rId1.getTargetURI());
-// URI rel11 = PackagingURIHelper.relativizeURI(drawingPart.getPartName().getURI(), rId1.getTargetURI());
-// assertEquals("'Another Sheet'!A1", rel1.getFragment());
-// assertEquals("'Another Sheet'!A1", rel11.getFragment());
+ URI rel1 = parent.relativize(rId1.getTargetURI());
+ assertEquals("'Another Sheet'!A1", rel1.getFragment());
+ URI rel11 = PackagingURIHelper.relativizeURI(drawingPart.getPartName().getURI(), rId1.getTargetURI());
+ // the following changed with https://github.com/apache/poi/pull/617
+ //assertEquals("'Another Sheet'!A1", rel11.getFragment());
+ assertNull(rel11.getFragment());
PackageRelationship rId2 = drawingPart.getRelationship("rId2");
URI rel2 = PackagingURIHelper.relativizeURI(drawingPart.getPartName().getURI(), rId2.getTargetURI());
package org.apache.poi.xssf;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
import org.apache.poi.ooxml.ReferenceRelationship;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import java.io.IOException;
+import static org.junit.jupiter.api.Assertions.*;
+
class TestXSSFCloneSheet extends BaseTestCloneSheet {
public TestXSSFCloneSheet() {
super(XSSFITestDataProvider.instance);
PackageRelationship imageRel2 = drawing2.getRelationPartById(imageRelId2).getRelationship();
assertEquals(imageRelationType, imageRel2.getRelationshipType());
assertEquals(imageTargetUrl, imageRel2.getTargetURI().toString());
+
+ assertTrue(drawing2.removeReferenceRelationship(linkRelId2));
+ assertFalse(drawing2.removeReferenceRelationship(linkRelId2));
+ assertNull(drawing2.getReferenceRelationship(linkRelId2));
}
}
}