aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2012-04-21 12:50:57 +0000
committerYegor Kozlov <yegor@apache.org>2012-04-21 12:50:57 +0000
commit306579455bfd260adfb33b0b02dc262696a744fc (patch)
tree78221a77ba067c91578adcd40d262396d1b31f06 /src
parent8ae072fc85dcbc61e4ccaabc68b841da2e609514 (diff)
downloadpoi-306579455bfd260adfb33b0b02dc262696a744fc.tar.gz
poi-306579455bfd260adfb33b0b02dc262696a744fc.zip
Bugzilla 53043 - don't duplicate hyperlink relationships when saving XSSF file
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1328653 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java2
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java46
3 files changed, 42 insertions, 7 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index d2a6d64e3b..d96617f5c0 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
<changes>
<release version="3.9-beta1" date="2012-??-??">
+ <action dev="poi-developers" type="fix">53043 - don't duplicate hyperlink relationships when saving XSSF file</action>
<action dev="poi-developers" type="fix">53101 - fixed evaluation of SUM over cell range &gt; 255</action>
<action dev="poi-developers" type="fix">49529 - avoid exception when cloning sheets with no drawing records and initialized drawing patriarch</action>
</release>
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java
index 84a9ea51d8..dfe3423254 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java
@@ -111,7 +111,7 @@ public class XSSFHyperlink implements Hyperlink {
* Generates the relation if required
*/
protected void generateRelationIfNeeded(PackagePart sheetPart) {
- if (needsRelationToo()) {
+ if (_externalRel == null && needsRelationToo()) {
// Generate the relation
PackageRelationship rel =
sheetPart.addExternalRelationship(_location, XSSFRelation.SHEET_HYPERLINKS.getRelation());
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java
index 0358133a23..cf51b40d86 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java
@@ -17,6 +17,8 @@
package org.apache.poi.xssf.usermodel;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
import org.apache.poi.ss.usermodel.BaseTestHyperlink;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CreationHelper;
@@ -50,20 +52,52 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
doTestHyperlinkContents(sheet);
}
- public void testCreate() {
+ public void testCreate() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook();
+ XSSFSheet sheet = workbook.createSheet();
+ XSSFRow row = sheet.createRow(0);
XSSFCreationHelper createHelper = workbook.getCreationHelper();
- String[] validURLs = {
+ String[] urls = {
"http://apache.org",
"www.apache.org",
"/temp",
"c:/temp",
"http://apache.org/default.php?s=isTramsformed&submit=Search&la=*&li=*"};
- for(String s : validURLs){
- createHelper.createHyperlink(Hyperlink.LINK_URL).setAddress(s);
+ for(int i = 0; i < urls.length; i++){
+ String s = urls[i];
+ XSSFHyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
+ link.setAddress(s);
+
+ XSSFCell cell = row.createCell(i);
+ cell.setHyperlink(link);
+ }
+ workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
+ sheet = workbook.getSheetAt(0);
+ PackageRelationshipCollection rels = sheet.getPackagePart().getRelationships();
+ assertEquals(urls.length, rels.size());
+ for(int i = 0; i < rels.size(); i++){
+ PackageRelationship rel = rels.getRelationship(i);
+ // there should be a relationship for each URL
+ assertEquals(urls[i], rel.getTargetURI().toString());
}
+ // Bugzilla 53041: Hyperlink relations are duplicated when saving XSSF file
+ workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
+ sheet = workbook.getSheetAt(0);
+ rels = sheet.getPackagePart().getRelationships();
+ assertEquals(urls.length, rels.size());
+ for(int i = 0; i < rels.size(); i++){
+ PackageRelationship rel = rels.getRelationship(i);
+ // there should be a relationship for each URL
+ assertEquals(urls[i], rel.getTargetURI().toString());
+ }
+ }
+
+ public void testInvalidURLs() {
+ XSSFWorkbook workbook = new XSSFWorkbook();
+ XSSFCreationHelper createHelper = workbook.getCreationHelper();
+
String[] invalidURLs = {
"http:\\apache.org",
"www.apache .org",
@@ -74,12 +108,12 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
createHelper.createHyperlink(Hyperlink.LINK_URL).setAddress(s);
fail("expected IllegalArgumentException: " + s);
} catch (IllegalArgumentException e){
-
+
}
}
}
- public void testLoadSave() {
+ public void testLoadSave() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
CreationHelper createHelper = workbook.getCreationHelper();
assertEquals(3, workbook.getNumberOfSheets());