Initialise the link type of HSSFHyperLink, so that getType() on it works
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@896049 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e4531ab0fd
commit
62e8d43b5b
@ -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>
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user