aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/ooxml/java/org')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java
index 21fd54b844..2fd47d9d42 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java
@@ -17,6 +17,7 @@
package org.apache.poi.xssf.usermodel;
import java.net.URI;
+import java.net.URISyntaxException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
@@ -181,18 +182,37 @@ public class XSSFHyperlink implements Hyperlink {
}
/**
- * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, path to a file
+ * Hyperlink address. Depending on the hyperlink type it can be URL, e-mail, path to a file
*
* @param address - the address of this hyperlink
*/
public void setAddress(String address) {
- _location = address;
+ validate(address);
+
+ _location = address;
//we must set location for internal hyperlinks
if (_type == Hyperlink.LINK_DOCUMENT) {
setLocation(address);
}
}
+ private void validate(String address) {
+ switch (_type){
+ // email, path to file and url must be valid URIs
+ case Hyperlink.LINK_EMAIL:
+ case Hyperlink.LINK_FILE:
+ case Hyperlink.LINK_URL:
+ try {
+ new URI(address);
+ } catch (URISyntaxException x) {
+ IllegalArgumentException y = new IllegalArgumentException("Address of hyperlink must be a valid URI");
+ y.initCause(x);
+ throw y;
+ }
+ break;
+ }
+ }
+
/**
* Assigns this hyperlink to the given cell reference
*/