Hi,

a little bit more information (read: code)...

I know the code is imperfect but this was just a quick and dirty setup to try 
inline document viewing.

My Viewer component:

public class Viewer {
        
        @Parameter(required=true)
        @Property
        String documentUrl;
        
        @Inject
        Logger logger;
        
        public StreamResponse showDocument() {
                if ("".equals(documentUrl)) {
                        return null;
                }
                File pdf = new File(documentUrl);
                return new InlineViewingStreamResponse (pdf);
        }

My StreamResponse implementation:

public class InlineViewingStreamResponse implements StreamResponse {    

        File file;
        
        public FileAttachment(File file) throws FileNotFoundException {
                if (file != null && file.exists() && file.isFile()) {
                        this.file = file;
                } else {
                        throw new FileNotFoundException();
                }
        }

        @Override
        public String getContentType() {
                try {
                        return Files.probeContentType(file.toPath());
                } catch (IOException e) {
                        e.printStackTrace();
                        return null;
                }
        }

        @Override
        public InputStream getStream() throws IOException {
                return new BufferedInputStream(new FileInputStream(file));
        }

        @Override
        public void prepareResponse(Response response) {
                response.setHeader("Content-Disposition", "inline; filename=" + 
file.getName());
        } 

Regards,
Daniel P.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to