Browse Source

refactor some code

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1917136 13f79535-47bb-0310-9956-ffa450edef68
pull/256/merge
PJ Fanning 2 weeks ago
parent
commit
1899bee1b9

+ 2
- 1
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFRelation.java View 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
);


+ 1
- 1
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java View 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(

+ 6
- 4
poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java View 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());

+ 5
- 4
poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFCloneSheet.java View 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());

Loading…
Cancel
Save