poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1292295 - in /poi/trunk: src/documentation/content/xdocs/status.xml src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java test-data/spreadsheet/52716.xlsx
Date Wed, 22 Feb 2012 14:04:17 GMT
Author: yegor
Date: Wed Feb 22 14:04:17 2012
New Revision: 1292295

URL: http://svn.apache.org/viewvc?rev=1292295&view=rev
Log:
Bugzilla 52716 - tolerate hyperlinks that have neither location nor relation

Added:
    poi/trunk/test-data/spreadsheet/52716.xlsx   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1292295&r1=1292294&r2=1292295&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Wed Feb 22 14:04:17 2012
@@ -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>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java?rev=1292295&r1=1292294&r2=1292295&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java Wed Feb 22 14:04:17
2012
@@ -68,23 +68,27 @@ public class XSSFHyperlink implements Hy
             //  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 Hy
     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);
+    }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java?rev=1292295&r1=1292294&r2=1292295&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java Wed
Feb 22 14:04:17 2012
@@ -189,4 +189,24 @@ public final class TestXSSFHyperlink ext
 		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());
+    }
+
 }

Added: poi/trunk/test-data/spreadsheet/52716.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/52716.xlsx?rev=1292295&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/52716.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/vnd.ms-excel



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message