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
This commit is contained in:
parent
6fc404c4a6
commit
87099af3cb
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.9-beta1" date="2012-??-??">
|
<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 > 255</action>
|
<action dev="poi-developers" type="fix">53101 - fixed evaluation of SUM over cell range > 255</action>
|
||||||
<action dev="poi-developers" type="fix">49529 - avoid exception when cloning sheets with no drawing records and initialized drawing patriarch</action>
|
<action dev="poi-developers" type="fix">49529 - avoid exception when cloning sheets with no drawing records and initialized drawing patriarch</action>
|
||||||
</release>
|
</release>
|
||||||
|
@ -111,7 +111,7 @@ public class XSSFHyperlink implements Hyperlink {
|
|||||||
* Generates the relation if required
|
* Generates the relation if required
|
||||||
*/
|
*/
|
||||||
protected void generateRelationIfNeeded(PackagePart sheetPart) {
|
protected void generateRelationIfNeeded(PackagePart sheetPart) {
|
||||||
if (needsRelationToo()) {
|
if (_externalRel == null && needsRelationToo()) {
|
||||||
// Generate the relation
|
// Generate the relation
|
||||||
PackageRelationship rel =
|
PackageRelationship rel =
|
||||||
sheetPart.addExternalRelationship(_location, XSSFRelation.SHEET_HYPERLINKS.getRelation());
|
sheetPart.addExternalRelationship(_location, XSSFRelation.SHEET_HYPERLINKS.getRelation());
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
package org.apache.poi.xssf.usermodel;
|
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.BaseTestHyperlink;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.ss.usermodel.CreationHelper;
|
import org.apache.poi.ss.usermodel.CreationHelper;
|
||||||
@ -50,19 +52,51 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
|
|||||||
doTestHyperlinkContents(sheet);
|
doTestHyperlinkContents(sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreate() {
|
public void testCreate() throws Exception {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
|
XSSFSheet sheet = workbook.createSheet();
|
||||||
|
XSSFRow row = sheet.createRow(0);
|
||||||
XSSFCreationHelper createHelper = workbook.getCreationHelper();
|
XSSFCreationHelper createHelper = workbook.getCreationHelper();
|
||||||
|
|
||||||
String[] validURLs = {
|
String[] urls = {
|
||||||
"http://apache.org",
|
"http://apache.org",
|
||||||
"www.apache.org",
|
"www.apache.org",
|
||||||
"/temp",
|
"/temp",
|
||||||
"c:/temp",
|
"c:/temp",
|
||||||
"http://apache.org/default.php?s=isTramsformed&submit=Search&la=*&li=*"};
|
"http://apache.org/default.php?s=isTramsformed&submit=Search&la=*&li=*"};
|
||||||
for(String s : validURLs){
|
for(int i = 0; i < urls.length; i++){
|
||||||
createHelper.createHyperlink(Hyperlink.LINK_URL).setAddress(s);
|
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 = {
|
String[] invalidURLs = {
|
||||||
"http:\\apache.org",
|
"http:\\apache.org",
|
||||||
@ -74,12 +108,12 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
|
|||||||
createHelper.createHyperlink(Hyperlink.LINK_URL).setAddress(s);
|
createHelper.createHyperlink(Hyperlink.LINK_URL).setAddress(s);
|
||||||
fail("expected IllegalArgumentException: " + s);
|
fail("expected IllegalArgumentException: " + s);
|
||||||
} catch (IllegalArgumentException e){
|
} catch (IllegalArgumentException e){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLoadSave() {
|
public void testLoadSave() {
|
||||||
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
|
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
|
||||||
CreationHelper createHelper = workbook.getCreationHelper();
|
CreationHelper createHelper = workbook.getCreationHelper();
|
||||||
assertEquals(3, workbook.getNumberOfSheets());
|
assertEquals(3, workbook.getNumberOfSheets());
|
||||||
|
Loading…
Reference in New Issue
Block a user