View | Details | Raw Unified | Return to bug 59775
Collapse All | Expand All

(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java (-36 / +36 lines)
Lines 55-98 public class XSSFHyperlink implements Hyperlink { Link Here
55
     * @param hyperlinkRel the relationship in the underlying OPC package which stores the actual link's address
55
     * @param hyperlinkRel the relationship in the underlying OPC package which stores the actual link's address
56
     */
56
     */
57
    protected XSSFHyperlink(CTHyperlink ctHyperlink, PackageRelationship hyperlinkRel) {
57
    protected XSSFHyperlink(CTHyperlink ctHyperlink, PackageRelationship hyperlinkRel) {
58
        _ctHyperlink = ctHyperlink;
58
         _ctHyperlink = ctHyperlink;
59
        _externalRel = hyperlinkRel;
59
         _externalRel = hyperlinkRel;
60
60
61
        // Figure out the Hyperlink type and distination
61
         // Figure out the Hyperlink type and distination
62
62
63
        // If it has a location, it's internal
63
         if (_externalRel == null) {
64
        if (ctHyperlink.getLocation() != null) {
64
             // If it has a location, it's internal
65
            _type = Hyperlink.LINK_DOCUMENT;
65
             if (ctHyperlink.getLocation() != null) {
66
            _location = ctHyperlink.getLocation();
66
                 _type = Hyperlink.LINK_DOCUMENT;
67
        } else {
67
                 _location = ctHyperlink.getLocation();
68
            // Otherwise it's somehow external, check
68
             } else if (ctHyperlink.getId() != null) {
69
            //  the relation to see how
69
                 throw new IllegalStateException("The hyperlink for cell "
70
            if (_externalRel == null) {
70
                         + ctHyperlink.getRef() + " references relation "
71
                if (ctHyperlink.getId() != null) {
71
                         + ctHyperlink.getId() + ", but that didn't exist!");
72
                    throw new IllegalStateException("The hyperlink for cell " + ctHyperlink.getRef() +
72
             } else {
73
                            " references relation " + ctHyperlink.getId() + ", but that didn't exist!");
73
                 // hyperlink is internal and is not related to other parts
74
                }
74
                 _type = Hyperlink.LINK_DOCUMENT;
75
                // hyperlink is internal and is not related to other parts
75
             }
76
                _type = Hyperlink.LINK_DOCUMENT;
76
         } else {
77
            } else {
77
             URI target = _externalRel.getTargetURI();
78
                URI target = _externalRel.getTargetURI();
78
             _location = target.toString();
79
                _location = target.toString();
79
             if (ctHyperlink.getLocation() != null) {
80
80
                 // URI fragment
81
                // Try to figure out the type
81
                 _location += "#" + ctHyperlink.getLocation();
82
             }
83
84
             // Try to figure out the type
82
                if (_location.startsWith("http://") || _location.startsWith("https://")
85
                if (_location.startsWith("http://") || _location.startsWith("https://")
83
                        || _location.startsWith("ftp://")) {
86
                     || _location.startsWith("ftp://")) {
84
                    _type = Hyperlink.LINK_URL;
87
                 _type = Hyperlink.LINK_URL;
85
                } else if (_location.startsWith("mailto:")) {
88
             } else if (_location.startsWith("mailto:")) {
86
                    _type = Hyperlink.LINK_EMAIL;
89
                 _type = Hyperlink.LINK_EMAIL;
87
                } else {
90
             } else {
88
                    _type = Hyperlink.LINK_FILE;
91
                 _type = Hyperlink.LINK_FILE;
89
                }
92
             }
90
            }
93
         }
91
94
95
     }
92
96
93
        }
94
    }
95
    
96
    /**
97
    /**
97
     * Create a new XSSFHyperlink. This method is for Internal use only.
98
     * Create a new XSSFHyperlink. This method is for Internal use only.
98
     * XSSFHyperlinks can be created by XSSFCreationHelper.
99
     * XSSFHyperlinks can be created by XSSFCreationHelper.
99
- 

Return to bug 59775