Skip to content

Commit

Permalink
refactor some code
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1917136 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pjfanning committed Apr 19, 2024
1 parent 5955dd7 commit 1899bee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more

import org.apache.poi.ooxml.POIXMLDocument;
import org.apache.poi.ooxml.POIXMLRelation;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.util.Beta;
import org.apache.poi.xssf.usermodel.XSSFRelation;
Expand Down Expand Up @@ -118,7 +119,7 @@ public final class XSLFRelation extends POIXMLRelation {

public static final XSLFRelation HYPERLINK = new XSLFRelation(
null,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
PackageRelationshipTypes.HYPERLINK_PART,
null
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public final class XWPFRelation extends POIXMLRelation {
);
public static final XWPFRelation HYPERLINK = new XWPFRelation(
null,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
PackageRelationshipTypes.HYPERLINK_PART,
null
);
public static final XWPFRelation COMMENT = new XWPFRelation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFRelation;
import org.junit.jupiter.api.Test;


class TestRelationships {
private static final String HYPERLINK_REL_TYPE =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
PackageRelationshipTypes.HYPERLINK_PART;
private static final String COMMENTS_REL_TYPE =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
XSSFRelation.SHEET_COMMENTS.getRelation();
private static final String SHEET_WITH_COMMENTS =
"/xl/worksheets/sheet1.xml";

private static final Logger LOG = LogManager.getLogger(TestRelationships.class);

/**
* Test relationships are correctly loaded. This at the moment fails (as of r499)
* whenever a document is loaded before its correspondig .rels file has been found.
* whenever a document is loaded before its corresponding .rels file has been found.
* The code in this case assumes there are no relationships defined, but it should
* really look also for not yet loaded parts.
*/
Expand Down Expand Up @@ -319,9 +320,10 @@ private void assert_50154(OPCPackage pkg) throws Exception {
// expected one image
assertEquals(1, drawingPart.getRelationshipsByType(IMAGE_PART).size());
// and three hyperlinks
assertEquals(5, drawingPart.getRelationshipsByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink").size());
assertEquals(5, drawingPart.getRelationshipsByType(HYPERLINK_REL_TYPE).size());

PackageRelationship rId1 = drawingPart.getRelationship("rId1");
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more

import org.apache.poi.ooxml.ReferenceRelationship;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.ss.usermodel.BaseTestCloneSheet;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
Expand Down Expand Up @@ -143,10 +144,10 @@ void test64759() throws IOException {
void testBug63189() throws IOException {
try (XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("bug63189.xlsx")) {
// given
String linkRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
String linkTargetUrl = "#Sheet3!A1";
String imageRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
String imageTargetUrl = "/xl/media/image1.png";
final String linkRelationType = PackageRelationshipTypes.HYPERLINK_PART;
final String linkTargetUrl = "#Sheet3!A1";
final String imageRelationType = PackageRelationshipTypes.IMAGE_PART;
final String imageTargetUrl = "/xl/media/image1.png";

XSSFSheet srcSheet = workbook.getSheetAt(0);
assertEquals("CloneMe", srcSheet.getSheetName());
Expand Down

0 comments on commit 1899bee

Please sign in to comment.