You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by hese <10...@gmail.com> on 2011/12/15 22:39:26 UTC

How to get resource handle in AppModule.java

Hi,

I want to access a resource file from AppModule.java buildXXX method.  Can
anyone guide me how to go about it?

public EmailTemplate buildEmailTemplate() {
    InputStream is = ?? 
    // I want to get a handle to a text file residing in my context path.
    // obviously FileInputStream("/templates/billing.stg"); throws a file
not found exception
}

Thanks!


--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-get-resource-handle-in-AppModule-java-tp5078761p5078761.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to get resource handle in AppModule.java

Posted by hese <10...@gmail.com>.

Great, that worked, thanks.


public EmailTemplate buildEmailTemplate(@Inject AssetSource assetSource)
throws IOException {
	Asset asset = assetSource.getContextAsset("/templates/billing.stg", new
Locale("en"));
	EmailTemplate emailTemplate = new
EmailTemplate(asset.getResource().openStream());
	return emailTemplate;
}


--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-get-resource-handle-in-AppModule-java-tp5078761p5078787.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to get resource handle in AppModule.java

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
@Inject AssetSource, and go from there.  This should get you started.

On Dec 15, 2011, at 4:39 PM, hese wrote:

> 
> Hi,
> 
> I want to access a resource file from AppModule.java buildXXX method.  Can
> anyone guide me how to go about it?
> 
> public EmailTemplate buildEmailTemplate() {
>    InputStream is = ?? 
>    // I want to get a handle to a text file residing in my context path.
>    // obviously FileInputStream("/templates/billing.stg"); throws a file
> not found exception
> }


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