ICEfaces
  1. ICEfaces
  2. ICE-3857

OutputResource: Display correct URL when attachment="false"

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.2
    • Fix Version/s: 1.8DR#2, 1.8
    • Component/s: ICE-Components
    • Labels:
      None
    • Environment:
      All

      Description

      When using the outputResource component to display pdfs, if attachement="true" the filename will be appended to the URL when the user selects save. If attachment="false", the filename is not included in the generated URL.

      i.e:

      http://localhost/testApp/Web/block/resource/LTE4NTk2MjU0MzQ=/filename.pdf

      instead of just

      http://localhost/testApp/Web/block/resource/LTE4NTk2MjU0MzQ=/

       

        Activity

        Hide
        Tyler Johnson added a comment -

        Here is the fix for ResourceDispatcher.java:

        private class FileNameOption implements Resource.Options {
        private String fileName;
        public String getFileName()

        { return fileName; }

        public void setAsAttachement()

        { // TODO Auto-generated method stub }
        public void setExpiresBy(Date date) { // TODO Auto-generated method stub }

        public void setFileName(String fileName)

        { this.fileName = fileName; }

        public void setLastModified(Date date)

        { // TODO Auto-generated method stub }
        public void setMimeType(String mimeType) { // TODO Auto-generated method stub }

        }
        public URI registerResource(Resource resource, ResourceLinker.Handler handler) {
        if( handler == null )
        handler = NOOPHandler;
        final FileNameOption options = new FileNameOption();
        try

        { resource.withOptions(options); }

        catch (IOException e)

        { throw new RuntimeException(e); }

        final String filename = options.getFileName();
        final String name = prefix + encode(resource) + "/" + (filename != null && filename != "" ? filename : "");

        Show
        Tyler Johnson added a comment - Here is the fix for ResourceDispatcher.java: private class FileNameOption implements Resource.Options { private String fileName; public String getFileName() { return fileName; } public void setAsAttachement() { // TODO Auto-generated method stub } public void setExpiresBy(Date date) { // TODO Auto-generated method stub } public void setFileName(String fileName) { this.fileName = fileName; } public void setLastModified(Date date) { // TODO Auto-generated method stub } public void setMimeType(String mimeType) { // TODO Auto-generated method stub } } public URI registerResource(Resource resource, ResourceLinker.Handler handler) { if( handler == null ) handler = NOOPHandler; final FileNameOption options = new FileNameOption(); try { resource.withOptions(options); } catch (IOException e) { throw new RuntimeException(e); } final String filename = options.getFileName(); final String name = prefix + encode(resource) + "/" + (filename != null && filename != "" ? filename : "");
        Hide
        yip.ng added a comment -

        The attachment attribute doesn't affect the generation of the URL. The same URL is generated regardless. The attachment attribute determines whether a save file dialog will pop up right away when a link is left-clicked. If true, a save file dialog will pop up, and the file name will be taken from the filename attribute in the Content-Disposition HTTP header, NOT from the URL. If false, you have to right-click and choose Save Link As to save the file. Then the file name is taken from the generated URL.

        Show
        yip.ng added a comment - The attachment attribute doesn't affect the generation of the URL. The same URL is generated regardless. The attachment attribute determines whether a save file dialog will pop up right away when a link is left-clicked. If true, a save file dialog will pop up, and the file name will be taken from the filename attribute in the Content-Disposition HTTP header, NOT from the URL. If false, you have to right-click and choose Save Link As to save the file. Then the file name is taken from the generated URL.
        Hide
        yip.ng added a comment -

        The problem is not specific to PDF files. It occurs in every type of file.

        Show
        yip.ng added a comment - The problem is not specific to PDF files. It occurs in every type of file.
        Hide
        yip.ng added a comment -

        Suggested fix applied, but note that there is a bug in the supplied code: filename != "" should be !filename.equals(""). This has been changed.

        Show
        yip.ng added a comment - Suggested fix applied, but note that there is a bug in the supplied code: filename != "" should be !filename.equals(""). This has been changed.
        Hide
        Keith Garry Boyce added a comment -

        We encountered another issue with this fix... If there are space's in filename then the URI generates an error as being invalid. Hence the URL has to be urlencoded.. But when urlencoding the filename the pattern matcher complains about + and - characters which need to be escaped in pattern matching algorithm on registering resource..

        Please address this test case as well.. i.e where filename has spaces and dashes... and also think about the other valid characters that may be in a filename

        Show
        Keith Garry Boyce added a comment - We encountered another issue with this fix... If there are space's in filename then the URI generates an error as being invalid. Hence the URL has to be urlencoded.. But when urlencoding the filename the pattern matcher complains about + and - characters which need to be escaped in pattern matching algorithm on registering resource.. Please address this test case as well.. i.e where filename has spaces and dashes... and also think about the other valid characters that may be in a filename
        Hide
        Sam Xiao added a comment -

        test

        Show
        Sam Xiao added a comment - test

          People

          • Assignee:
            Unassigned
            Reporter:
            Tyler Johnson
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: