<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>
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
*/
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;
+ }
+ }
}
/**
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();
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);
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);
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() {