diff options
author | Yegor Kozlov <yegor@apache.org> | 2009-06-19 10:37:24 +0000 |
---|---|---|
committer | Yegor Kozlov <yegor@apache.org> | 2009-06-19 10:37:24 +0000 |
commit | 234735a4144b7ae26fb064551d16d41dbecf5fe0 (patch) | |
tree | c573487d529bdf263914b31b9bce5cc0a6903c56 /src/java | |
parent | 84a6e0a03d56f26ffa2f1829f1e506fc09739f6e (diff) | |
download | poi-234735a4144b7ae26fb064551d16d41dbecf5fe0.tar.gz poi-234735a4144b7ae26fb064551d16d41dbecf5fe0.zip |
fixed a regression issue where HSSFHyperlink failed to set inter-sheet and file links, see Bugzilla #47375
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@786442 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/org/apache/poi/hssf/record/HyperlinkRecord.java | 22 | ||||
-rwxr-xr-x | src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java | 13 |
2 files changed, 29 insertions, 6 deletions
diff --git a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java index 190613294f..f94605432d 100644 --- a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java +++ b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java @@ -81,7 +81,9 @@ public final class HyperlinkRecord extends StandardRecord { @Override public boolean equals(Object obj) { GUID other = (GUID) obj; - return _d1 == other._d1 && _d2 == other._d2 + if (obj == null || !(obj instanceof GUID)) + return false; + return _d1 == other._d1 && _d2 == other._d2 && _d3 == other._d3 && _d4 == other._d4; } @@ -360,21 +362,31 @@ public final class HyperlinkRecord extends StandardRecord { } /** - * Hyperlink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc. + * Hyperlink address. Depending on the hyperlink type it can be URL, e-mail, path to a file, etc. * * @return the address of this hyperlink */ public String getAddress() { - return cleanString(_address); + if ((_linkOpts & HLINK_URL) != 0 && FILE_MONIKER.equals(_moniker)) + return cleanString(_address != null ? _address : _shortFilename); + else if((_linkOpts & HLINK_PLACE) != 0) + return cleanString(_textMark); + else + return cleanString(_address); } /** - * Hyperlink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc. + * Hyperlink address. Depending on the hyperlink type it can be URL, e-mail, path to a file, etc. * * @param address the address of this hyperlink */ public void setAddress(String address) { - _address = appendNullTerm(address); + if ((_linkOpts & HLINK_URL) != 0 && FILE_MONIKER.equals(_moniker)) + _shortFilename = appendNullTerm(address); + else if((_linkOpts & HLINK_PLACE) != 0) + _textMark = appendNullTerm(address); + else + _address = appendNullTerm(address); } public String getShortFilename() { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java b/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java index 9a812914d5..669f52f065 100755 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java @@ -162,7 +162,7 @@ public class HSSFHyperlink implements Hyperlink { } /** - * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc. + * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, path to a file, etc. * * @return the address of this hyperlink */ @@ -172,12 +172,23 @@ public class HSSFHyperlink implements Hyperlink { public String getTextMark(){ return record.getTextMark(); } + + /** + * Convenience method equivalent to {@link #setAddress(String)} + * + * @param textMark the place in worksheet this hypelrink referes to, e.g. 'Target Sheet'!A1' + */ public void setTextMark(String textMark) { record.setTextMark(textMark); } public String getShortFilename(){ return record.getShortFilename(); } + /** + * Convenience method equivalent to {@link #setAddress(String)} + * + * @param shortFilename the path to a file this hypelrink points to, e.g. 'readme.txt' + */ public void setShortFilename(String shortFilename) { record.setShortFilename(shortFilename); } |