]> source.dussan.org Git - poi.git/commitdiff
Initialise the link type of HSSFHyperLink, so that getType() on it works
authorNick Burch <nick@apache.org>
Tue, 5 Jan 2010 14:08:51 +0000 (14:08 +0000)
committerNick Burch <nick@apache.org>
Tue, 5 Jan 2010 14:08:51 +0000 (14:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@896049 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/HyperlinkRecord.java
src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java

index b7720e9e867c0c20ad240ba5fe222542a72fa718..1cc2227775b25688d354bb71348153a57ac08d15 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-SNAPSHOT" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">Initialise the link type of HSSFHyperLink, so that getType() on it works</action>
            <action dev="POI-DEVELOPERS" type="fix">48425 - improved performance of DateUtil.isCellDateFormatted()  </action>
            <action dev="POI-DEVELOPERS" type="fix">47215 - fixed InterfaceEndRecord to tolerate unexpected record contents </action>
            <action dev="POI-DEVELOPERS" type="fix">48415 - improved javadoc on HSSPicture.resize() </action>
index 94be338f07ec5b2d0f64e553326ecd3550122169..ed7fee1fd2cf0176ca17e34b1b290f54219fc002 100644 (file)
@@ -674,6 +674,27 @@ public final class HyperlinkRecord extends StandardRecord {
         return buffer.toString();
     }
 
+    /**
+     * Based on the link options, is this a url?
+     */
+    public boolean isUrlLink() {
+       return (_linkOpts & HLINK_URL) > 0 
+           && (_linkOpts & HLINK_ABS) > 0;
+    }
+    /**
+     * Based on the link options, is this a file?
+     */
+    public boolean isFileLink() {
+       return (_linkOpts & HLINK_URL) > 0 
+           && (_linkOpts & HLINK_ABS) == 0;
+    }
+    /**
+     * Based on the link options, is this a document?
+     */
+    public boolean isDocumentLink() {
+       return (_linkOpts & HLINK_PLACE) > 0; 
+    }
+    
     /**
      * Initialize a new url link
      */
index 669f52f06514724d9c346cb5ffb039ff65cdb608..711c6d145e152f86f4edd1aa8b91a5c3b5356beb 100644 (file)
@@ -87,6 +87,20 @@ public class HSSFHyperlink implements Hyperlink {
     protected HSSFHyperlink( HyperlinkRecord record )
     {
         this.record = record;
+        
+        // Figure out the type
+        if(record.isFileLink()) {
+           link_type = LINK_FILE;
+        } else if(record.isDocumentLink()) {
+           link_type = LINK_DOCUMENT;
+        } else {
+           if(record.getAddress() != null &&
+                 record.getAddress().startsWith("mailto:")) {
+              link_type = LINK_EMAIL;
+           } else {
+              link_type = LINK_URL;
+           }
+        }
     }
 
     /**
index 8a5d601369c8705a812bae1770faccf771814ac6..0188e8b270204420060df7264185e9eea66f572f 100644 (file)
@@ -49,6 +49,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
         assertEquals("POI", link.getLabel());
         assertEquals("POI", cell.getRichStringCellValue().getString());
         assertEquals("http://poi.apache.org/", link.getAddress());
+        assertEquals(HSSFHyperlink.LINK_URL, link.getType());
 
         cell = sheet.getRow(8).getCell(0);
         link = cell.getHyperlink();
@@ -56,6 +57,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
         assertEquals("HSSF", link.getLabel());
         assertEquals("HSSF", cell.getRichStringCellValue().getString());
         assertEquals("http://poi.apache.org/hssf/", link.getAddress());
+        assertEquals(HSSFHyperlink.LINK_URL, link.getType());
 
         sheet = wb.getSheet("Emails");
         cell = sheet.getRow(4).getCell(0);
@@ -64,6 +66,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
         assertEquals("dev", link.getLabel());
         assertEquals("dev", cell.getRichStringCellValue().getString());
         assertEquals("mailto:dev@poi.apache.org", link.getAddress());
+        assertEquals(HSSFHyperlink.LINK_EMAIL, link.getType());
 
         sheet = wb.getSheet("Internal");
         cell = sheet.getRow(4).getCell(0);
@@ -73,6 +76,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
         assertEquals("Link To First Sheet", cell.getRichStringCellValue().getString());
         assertEquals("WebLinks!A1", link.getTextMark());
         assertEquals("WebLinks!A1", link.getAddress());
+        assertEquals(HSSFHyperlink.LINK_DOCUMENT, link.getType());
     }
 
     public void testModify() {