]> source.dussan.org Git - poi.git/commitdiff
refactor some code
authorPJ Fanning <fanningpj@apache.org>
Fri, 19 Apr 2024 09:56:05 +0000 (09:56 +0000)
committerPJ Fanning <fanningpj@apache.org>
Fri, 19 Apr 2024 09:56:05 +0000 (09:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1917136 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFRelation.java
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java
poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java
poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFCloneSheet.java

index cec0e475e142a456b3316cab58965d191f7f5b7c..61e79686e0f370303a6a3a49050d8d6b3178aaec 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Map;
 
 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;
@@ -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
     );
 
index 4566e6113a36b03e1592aec44196a05365fc50ec..f8d1f3e236bdccb7e7e6dca876d02f4e068f662c 100644 (file)
@@ -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(
index fe370a6fe51d7a1c82c7176d635fc9aefa6e0f76..7bbbea564b8f92c52afb5403b541ed428e71e40f 100644 (file)
@@ -33,14 +33,15 @@ import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 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";
 
@@ -48,7 +49,7 @@ class TestRelationships {
 
     /**
      * 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.
      */
@@ -319,9 +320,10 @@ class TestRelationships {
         // 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());
index e966520bedd3eb60fcacf712583fb5749b80cfd0..bf6499d6cea5bb82efbb40555beee84443c309a6 100644 (file)
@@ -26,6 +26,7 @@ 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 org.apache.poi.ss.usermodel.BaseTestCloneSheet;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
@@ -143,10 +144,10 @@ class TestXSSFCloneSheet  extends BaseTestCloneSheet {
     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());