Re: How to add a link to a file stored in directory?

2013-06-05 Thread Lance Java
Tapestry has built in support for serving classpath assets.
http://tapestry.apache.org/assets.html

Option1
TML
   a
href=${asset:classpath:regoznapp/enterprise/src/main/resources/return.txt}
/

Option2
Java
@Inject AssetSource assetSource;

   public String getAssetUrl() {
  return
assetSource.getClasspathAsset(regoznapp/enterprise/src/main/resources/return.txt,
null).toClientURL();
   }

TML
   a href=${assetUrl}  /


How to add a link to a file stored in directory?

2013-06-04 Thread Petr Janata
Hi,

thanks for links with ideas. I am new in Tapestry I use Example
Apphttp://jumpstart.doublenegative.com.au/jumpstart/theapp/login
from
Jumpstart tutorial . I added File
Uploadhttp://jumpstart.doublenegative.com.au/jumpstart/examples/javascript/fileupload
to
Example App and HSQL table for uploaded file names. In Example App is
used Protecting
Pageshttp://jumpstart.doublenegative.com.au/jumpstart/examples/infrastructure/protectingpages
and
I can not download uploaded file by simple href even if I am logged in as a
admin user.

How to allow to download file from upload-path?

I use simple link in  tml file

a t:type=eventlink t:event=returnstreamresponse href=#download/a

and I also added  onReturnStreamResponse into java file from jumpstart
tutorial from this link.

StreamResponse onReturnStreamResponse() {
return new StreamResponse() {
InputStream inputStream;

@Override
public void prepareResponse(Response response) {
ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
inputStream =
classLoader.getResourceAsStream(regoznapp/enterprise/src/main/resources/return.txt);

// Set content length to prevent chunking - see
//
http://tapestry-users.832.n2.nabble.com/Disable-Transfer-Encoding-chunked-from-StreamResponse-td5269662.html#a5269662

try {
response.setHeader(Content-Length,  +
inputStream.available());
}
catch (IOException e) {
// Ignore the exception in this simple example.
}
}

@Override
public String getContentType() {
return text/plain;
}

@Override
public InputStream getStream() throws IOException {
return inputStream;
}
};
}

Petr


Re: How to add a link to a file stored in directory?

2013-06-04 Thread Geoff Callender
1. What happens? Is an exception thrown?

2. If you upload to the file system, like the jumpstart example does; then you 
should download from the file system - but your example, below, is downloading 
from a path relative to the classpath of the web app. Try this instead:

inputStream = new FileInputStream(myFilePath);

Geoff

On 05/06/2013, at 8:01 AM, Petr Janata wrote:

 Hi,
 
 thanks for links with ideas. I am new in Tapestry I use Example
 Apphttp://jumpstart.doublenegative.com.au/jumpstart/theapp/login
 from
 Jumpstart tutorial . I added File
 Uploadhttp://jumpstart.doublenegative.com.au/jumpstart/examples/javascript/fileupload
 to
 Example App and HSQL table for uploaded file names. In Example App is
 used Protecting
 Pageshttp://jumpstart.doublenegative.com.au/jumpstart/examples/infrastructure/protectingpages
 and
 I can not download uploaded file by simple href even if I am logged in as a
 admin user.
 
 How to allow to download file from upload-path?
 
 I use simple link in  tml file
 
 a t:type=eventlink t:event=returnstreamresponse href=#download/a
 
 and I also added  onReturnStreamResponse into java file from jumpstart
 tutorial from this link.
 
 StreamResponse onReturnStreamResponse() {
return new StreamResponse() {
InputStream inputStream;
 
@Override
public void prepareResponse(Response response) {
ClassLoader classLoader =
 Thread.currentThread().getContextClassLoader();
inputStream =
 classLoader.getResourceAsStream(regoznapp/enterprise/src/main/resources/return.txt);
 
// Set content length to prevent chunking - see
//
 http://tapestry-users.832.n2.nabble.com/Disable-Transfer-Encoding-chunked-from-StreamResponse-td5269662.html#a5269662
 
try {
response.setHeader(Content-Length,  +
 inputStream.available());
}
catch (IOException e) {
// Ignore the exception in this simple example.
}
}
 
@Override
public String getContentType() {
return text/plain;
}
 
@Override
public InputStream getStream() throws IOException {
return inputStream;
}
};
 }
 
 Petr



Re: How to add a link to a file stored in directory?

2013-06-04 Thread mailingl...@j-b-s.de
Hi Petr!

You are really refering to a file in your src directory? When you use maven to 
build it the file is copied to target/ and you access it simply by return.txt 
using the classloader because target/resources is stripped when building the 
jar/war.

Set a break point and check if you really got an inputstream. You can also try 
to get the URL first which is null in case nothing found.

Jens

Sent from my iPhone

On 05.06.2013, at 00:01, Petr Janata petrdotjan...@gmail.com wrote:

 Hi,
 
 thanks for links with ideas. I am new in Tapestry I use Example
 Apphttp://jumpstart.doublenegative.com.au/jumpstart/theapp/login
 from
 Jumpstart tutorial . I added File
 Uploadhttp://jumpstart.doublenegative.com.au/jumpstart/examples/javascript/fileupload
 to
 Example App and HSQL table for uploaded file names. In Example App is
 used Protecting
 Pageshttp://jumpstart.doublenegative.com.au/jumpstart/examples/infrastructure/protectingpages
 and
 I can not download uploaded file by simple href even if I am logged in as a
 admin user.
 
 How to allow to download file from upload-path?
 
 I use simple link in  tml file
 
 a t:type=eventlink t:event=returnstreamresponse href=#download/a
 
 and I also added  onReturnStreamResponse into java file from jumpstart
 tutorial from this link.
 
 StreamResponse onReturnStreamResponse() {
return new StreamResponse() {
InputStream inputStream;
 
@Override
public void prepareResponse(Response response) {
ClassLoader classLoader =
 Thread.currentThread().getContextClassLoader();
inputStream =
 classLoader.getResourceAsStream(regoznapp/enterprise/src/main/resources/return.txt);
 
// Set content length to prevent chunking - see
//
 http://tapestry-users.832.n2.nabble.com/Disable-Transfer-Encoding-chunked-from-StreamResponse-td5269662.html#a5269662
 
try {
response.setHeader(Content-Length,  +
 inputStream.available());
}
catch (IOException e) {
// Ignore the exception in this simple example.
}
}
 
@Override
public String getContentType() {
return text/plain;
}
 
@Override
public InputStream getStream() throws IOException {
return inputStream;
}
};
 }
 
 Petr

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



How to add a link to a file stored in directory

2013-05-30 Thread Petr Janata
Hi I have table with file names. I need to add link for files stored in 
directory to download them.


Any idea?

Petr

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



How to add a link to a file stored in directory?

2013-05-30 Thread Petr Janata
Hi I have table with file names. I need to add link for files stored in 
directory to download them.


Any idea?

Petr

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



Re: How to add a link to a file stored in directory?

2013-05-30 Thread mailingl...@j-b-s.de
Hi Petr!

Have a look at:
http://tawus.wordpress.com/2011/07/30/tapestry-jfreechart-integration/

Here you can see how to stream any kind of data.


StreamResponse was discussed here before:
http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/T5-1-Return-a-file-as-response-of-a-ActionLink-event-td2437679.html


And you can find more here:
http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/StreamResponse.html

or on JumpStart which is a great source to start from anyway

http://jumpstart.doublenegative.com.au/jumpstart/examples/navigation/returntypes1



Jens

Sent from my iPhone

On 30.05.2013, at 16:06, Petr Janata petrdotjan...@gmail.com wrote:

 Hi I have table with file names. I need to add link for files stored in 
 directory to download them.
 
 Any idea?
 
 Petr
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org
 

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



Re: How to add a link to a file stored in directory

2013-05-30 Thread Boris Horvat
Put your files in the web app , or some external source (e.g. Amazon S3).
Putting the files in some arbitary folder in the host is not auto suported
by tapestry. You could write a file factory and there was a few topics
around this. For the time I wanted to the same but in the end I decided to
use S3.

Cheer


On Thu, May 30, 2013 at 4:02 PM, Petr Janata petrdotjan...@gmail.comwrote:

 Hi I have table with file names. I need to add link for files stored in
 directory to download them.

 Any idea?

 Petr

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




-- 
Sincerely
*Boris Horvat*