You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Filip Defoort <fi...@cirquedigital.com> on 2009/12/16 22:57:45 UTC

HyperLink.LINK_URL not working for XSSF (works for HSSF) ?

Hi,

I'm inserting a hyperlink with a non standard protocol into a XSSF
Worksheet like so

						Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
						link.setAddress("my-proto://" + someURL);
						cell.setHyperlink(link);

This is working fine with HSSF but with XSSF it ignores the fact that
this is a URL and not a File link, and generates a
file://localhost/my-proto//... link.

Quickly browsing the source it seems to be related to XSSFHyperlink.java:

            // Try to figure out the type
            if (_location.startsWith("http://") ||
_location.startsWith("https://")
                    || _location.startsWith("ftp://")) {
                _type = Hyperlink.LINK_URL;
            } else if (_location.startsWith("mailto:")) {
                _type = Hyperlink.LINK_EMAIL;
            } else {
                _type = Hyperlink.LINK_FILE;
            }

That doesn't look right. It ought to use LINK_FILE only for "file"
URLs, LINK_EMAIL for "mailto" and LINK_URL for the rest.

Does anybody know of any workarounds in the mean time ? Any chance one
of the developers could address this ?

Thanks much in advance,
- Filip

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: HyperLink.LINK_URL not working for XSSF (works for HSSF) ?

Posted by David Fisher <df...@jmlafferty.com>.
Hi Filip,

> Hi,
>
> I'm inserting a hyperlink with a non standard protocol into a XSSF
> Worksheet like so
>
> 						Hyperlink link =  
> createHelper.createHyperlink(Hyperlink.LINK_URL);
> 						link.setAddress("my-proto://" + someURL);
> 						cell.setHyperlink(link);
>
> This is working fine with HSSF but with XSSF it ignores the fact that
> this is a URL and not a File link, and generates a
> file://localhost/my-proto//... link.
>
> Quickly browsing the source it seems to be related to  
> XSSFHyperlink.java:
>
>            // Try to figure out the type
>            if (_location.startsWith("http://") ||
> _location.startsWith("https://")
>                    || _location.startsWith("ftp://")) {
>                _type = Hyperlink.LINK_URL;
>            } else if (_location.startsWith("mailto:")) {
>                _type = Hyperlink.LINK_EMAIL;
>            } else {
>                _type = Hyperlink.LINK_FILE;
>            }

>
> That doesn't look right. It ought to use LINK_FILE only for "file"
> URLs, LINK_EMAIL for "mailto" and LINK_URL for the rest.

I think the correct pattern is more like this:
            if (_location.contains("://") ) {
                _type = Hyperlink.LINK_URL;
            } else if (_location.startsWith("mailto:")) {
                _type = Hyperlink.LINK_EMAIL;
            } else {
                _type = Hyperlink.LINK_FILE;
            }

Although the URL rule needs to be a pattern match, I am pretty certain  
that <protocol>:// signifies a URL and the other stuff can only be  
EMAIL or a FILE.

> Does anybody know of any workarounds in the mean time ? Any chance one
> of the developers could address this ?

You could do whatever you want if you build from source. Give it a day  
for the developers on the other side of the world to respond.

Regards,
Dave


>
> Thanks much in advance,
> - Filip
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org