diff options
author | Yegor Kozlov <yegor@apache.org> | 2012-02-22 14:04:17 +0000 |
---|---|---|
committer | Yegor Kozlov <yegor@apache.org> | 2012-02-22 14:04:17 +0000 |
commit | 37149e9d6b8daed7d8820a8e3d01ee7da376566e (patch) | |
tree | 7a86278691dae5e818be5106428a86f87fd33f17 | |
parent | e94b5e52f1969378e5b55659c2ebc15a047f6457 (diff) | |
download | poi-37149e9d6b8daed7d8820a8e3d01ee7da376566e.tar.gz poi-37149e9d6b8daed7d8820a8e3d01ee7da376566e.zip |
Bugzilla 52716 - tolerate hyperlinks that have neither location nor relation
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1292295 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/documentation/content/xdocs/status.xml | 1 | ||||
-rw-r--r-- | src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java | 44 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java | 20 | ||||
-rw-r--r-- | test-data/spreadsheet/52716.xlsx | bin | 0 -> 14009 bytes |
4 files changed, 52 insertions, 13 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index d2367da522..d2d7aebf85 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ <changes> <release version="3.8-beta6" date="2012-??-??"> + <action dev="poi-developers" type="fix">52716 - tolerate hyperlinks that have neither location nor relation </action> <action dev="poi-developers" type="fix">52599 - avoid duplicate text when rendering slides in HSLF</action> <action dev="poi-developers" type="fix">52598 - respect slide background when rendering slides in HSLF</action> <action dev="poi-developers" type="fix">51731 - fixed painting shape outlines in HSLF</action> 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 2fd47d9d42..84a9ea51d8 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java @@ -68,23 +68,27 @@ public class XSSFHyperlink implements Hyperlink { // the relation to see how if (_externalRel == null) { if (ctHyperlink.getId() != null) { - throw new IllegalStateException("The hyperlink for cell " + ctHyperlink.getRef() + " references relation " + ctHyperlink.getId() + ", but that didn't exist!"); + throw new IllegalStateException("The hyperlink for cell " + ctHyperlink.getRef() + + " references relation " + ctHyperlink.getId() + ", but that didn't exist!"); + } + // hyperlink is internal and is not related to other parts + _type = Hyperlink.LINK_DOCUMENT; + } else { + URI target = _externalRel.getTargetURI(); + _location = target.toString(); + + // Try to figure out the type + if (_location.startsWith("http://") || _location.startsWith("https://") + || _location.startsWith("ftp://")) { + _type = Hyperlink.LINK_URL; + } else if (_location.startsWith("mailto:")) { + _type = Hyperlink.LINK_EMAIL; + } else { + _type = Hyperlink.LINK_FILE; } - throw new IllegalStateException("A sheet hyperlink must either have a location, or a relationship. Found:\n" + ctHyperlink); } - URI target = _externalRel.getTargetURI(); - _location = target.toString(); - // Try to figure out the type - if (_location.startsWith("http://") || _location.startsWith("https://") - || _location.startsWith("ftp://")) { - _type = Hyperlink.LINK_URL; - } else if (_location.startsWith("mailto:")) { - _type = Hyperlink.LINK_EMAIL; - } else { - _type = Hyperlink.LINK_FILE; - } } } @@ -306,4 +310,18 @@ public class XSSFHyperlink implements Hyperlink { public void setLastRow(int row) { setFirstRow(row); } + + /** + * @return additional text to help the user understand more about the hyperlink + */ + public String getTooltip() { + return _ctHyperlink.getTooltip(); + } + + /** + * @param text additional text to help the user understand more about the hyperlink + */ + public void setTooltip(String text) { + _ctHyperlink.setTooltip(text); + } } 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 49f79365f3..0358133a23 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java @@ -189,4 +189,24 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink { assertEquals("mailto:dev@poi.apache.org?subject=XSSF%20Hyperlinks", sheet.getRow(16).getCell(2).getHyperlink().getAddress()); } + + public void test52716() { + XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("52716.xlsx"); + XSSFSheet sh1 = wb1.getSheetAt(0); + + XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1); + XSSFSheet sh2 = wb2.getSheetAt(0); + + assertEquals(sh1.getNumberOfComments(), sh2.getNumberOfComments()); + XSSFHyperlink l1 = sh1.getHyperlink(0, 1); + assertEquals(XSSFHyperlink.LINK_DOCUMENT, l1.getType()); + assertEquals("B1", l1.getCellRef()); + assertEquals("Sort on Titel", l1.getTooltip()); + + XSSFHyperlink l2 = sh2.getHyperlink(0, 1); + assertEquals(l1.getTooltip(), l2.getTooltip()); + assertEquals(XSSFHyperlink.LINK_DOCUMENT, l2.getType()); + assertEquals("B1", l2.getCellRef()); + } + } diff --git a/test-data/spreadsheet/52716.xlsx b/test-data/spreadsheet/52716.xlsx Binary files differnew file mode 100644 index 0000000000..ba4f120c70 --- /dev/null +++ b/test-data/spreadsheet/52716.xlsx |