You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Jason Lea <ja...@kumachan.net.nz> on 2004/07/29 07:22:29 UTC

[Jelly] Using without a file or url

I am new to Jelly.  I just started looking for something to allow me to 
make some templates for HTML email, and Jelly looks great.

I have an idea to store some template fragments in a database, pull them 
out, combine them into the completed script then execute Jelly over it.  
However Jelly seems to only have the facilities to open files or URLs.  
It doesn't look like I can pass it a string containing my jelly template 
and execute the script.

Is this the case?  or is there a way to do it?

I imagine I could write my template to a temp file, execute the script 
on that, then delete the file - but that seems clumsy.

-- 
Jason Lea



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


Re: [Jelly] Using without a file or url (SOLVED)

Posted by Jason Lea <ja...@kumachan.net.nz>.
Well, the code was already in there :)  Hidden away, and not mentioned 
in the tutorials etc

But in the java docs there is
*
*org.apache.commons.jelly.impl.Embedded

With this example:

|Embedded| provides easy means to embed JellyEngine
and use Jelly scripts within an application

A typical usage:
|
Embedded embedded = new Embedded();
embedded.setOutputStream(new ByteArrayOutputStream());
embedded.setVariable("some-var","some-object");
.....
embedded.setScript(scriptAsString);
//or one can do.
//embedded.setScript(scriptAsInputStream);

boolean bStatus=embedded.execute();
if(!bStatus) //if error
{
String errorMsg=embedded.getErrorMsg();
}|

This is exactly what I was looking for
  - takes a string or input stream
  - executes it
  - returns result as output stream

Tested it and it works.  Another satisfied customer ;)



Jason Lea wrote:

>Dion Gillard wrote:
>
>  
>
>>There was a patch for this functionality posted to the list recently.
>>
>> 
>>
>>    
>>
>Oh cool.  I'll have a hunt for it :)
>
>  
>
>>On Thu, 29 Jul 2004 17:22:29 +1200, Jason Lea <ja...@kumachan.net.nz> wrote:
>> 
>>
>>    
>>
>>>I am new to Jelly.  I just started looking for something to allow me to
>>>make some templates for HTML email, and Jelly looks great.
>>>
>>>I have an idea to store some template fragments in a database, pull them
>>>out, combine them into the completed script then execute Jelly over it.
>>>However Jelly seems to only have the facilities to open files or URLs.
>>>It doesn't look like I can pass it a string containing my jelly template
>>>and execute the script.
>>>
>>>Is this the case?  or is there a way to do it?
>>>
>>>I imagine I could write my template to a temp file, execute the script
>>>on that, then delete the file - but that seems clumsy.
>>>
>>>--
>>>Jason Lea
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>>
>>>   
>>>
>>>      
>>>
>> 
>>
>>    
>>
>
>
>  
>


-- 
Jason Lea



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


Re: [Commons FileUpload]understanding the source code

Posted by Rommel Sharma <ro...@mahindrabt.com>.
Big thanks Jason! You are right...
I am reading each line and appending to the previous one without taking care
of the linebreaks and had fully ignored this possibility. This solves it all
for me.
Thanks again,
Rommel Sharma.

----- Original Message ----- 
From: "Jason Lea" <ja...@kumachan.net.nz>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Thursday, July 29, 2004 2:36 PM
Subject: Re: [Commons FileUpload]understanding the source code


> You seem to missing the line terminators, the request sent would have
> looked like this:
>
> -----------------------------7d433743032e
> Content-Disposition: form-data;
> name="file1";
> filename="C:\abc.txt"
> Content-Type: text/plain
>
> XYZ
>
> -----------------------------7d433743032e--
>
>
> They just have to process each line.  The blank line between
> Content-type: and XYZ is important, that separates the headers from the
> content.
>
>
> Rommel Sharma wrote:
>
> >Hi,
> >
> >This question is about the Commons FileUpload package. I hope I am
posting
> >to the right users list.
> >
> >I am trying to understand the source code, and understand the logic
through
> >which the data is extracted.
> >
> >>From my understanding: when we use the file input tag to upload a file
to
> >the server using the POST method, then the data transferred looks like
this:
> >
> >-----------------------------7d433743032eContent-Disposition: form-data;
> >name="file1"; filename="C:\abc.txt"Content-Type:
> >text/plainXYZ-----------------------------7d433743032e--
> >
> >where the content in my file is XYZ.
> >
> >We can write a code that  extracts the filename by parsing the
inputstream.
> >Now my question is that how can we extract the content XYZ as the
> >Content-Type could be anything: text/plain, or text/html, or
> >application/octet-stream or something else? We know that the content ends
> >with the boundary (-----------------------------7d433743032e-- in this
case
> >in case of single file uplaod) so we know upto where the content will be,
> >but how do we know the exact starting index of the content as the content
> >type could vary.
> >
> >Also, the content length that I may extract, will give me size including
> >that of the boundary and associated information also, but all I want is
of
> >only of the file uplaoded by the client.
> >
> >How did the Commons FileUpload team get across these problem? The source
> >code, although very well written, looks a bit confusing to me.
> >
> >Thanks and Regards,
> >Rommel Sharma.
> >
> >
> >
> >
> >*********************************************************
> >Disclaimer:
> >
> >This message (including any attachments) contains
> >confidential information intended for a specific
> >individual and purpose, and is protected by law.
> >If you are not the intended recipient, you should
> >delete this message and are hereby notified that
> >any disclosure, copying, or distribution of this
> >message, or the taking of any action based on it,
> >is strictly prohibited.
> >
> >*********************************************************
> >Visit us at http://www.mahindrabt.com
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
> >
> >
>
>
> -- 
> Jason Lea
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


*********************************************************
Disclaimer:          

This message (including any attachments) contains 
confidential information intended for a specific 
individual and purpose, and is protected by law. 
If you are not the intended recipient, you should 
delete this message and are hereby notified that 
any disclosure, copying, or distribution of this
message, or the taking of any action based on it, 
is strictly prohibited.

*********************************************************
Visit us at http://www.mahindrabt.com


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


Re: [Commons FileUpload]understanding the source code

Posted by Jason Lea <ja...@kumachan.net.nz>.
You seem to missing the line terminators, the request sent would have 
looked like this:

-----------------------------7d433743032e
Content-Disposition: form-data;
	name="file1";
	filename="C:\abc.txt"
Content-Type: text/plain

XYZ

-----------------------------7d433743032e--


They just have to process each line.  The blank line between 
Content-type: and XYZ is important, that separates the headers from the 
content.


Rommel Sharma wrote:

>Hi,
>
>This question is about the Commons FileUpload package. I hope I am posting
>to the right users list.
>
>I am trying to understand the source code, and understand the logic through
>which the data is extracted.
>
>>>From my understanding: when we use the file input tag to upload a file to
>the server using the POST method, then the data transferred looks like this:
>
>-----------------------------7d433743032eContent-Disposition: form-data;
>name="file1"; filename="C:\abc.txt"Content-Type:
>text/plainXYZ-----------------------------7d433743032e--
>
>where the content in my file is XYZ.
>
>We can write a code that  extracts the filename by parsing the inputstream.
>Now my question is that how can we extract the content XYZ as the
>Content-Type could be anything: text/plain, or text/html, or
>application/octet-stream or something else? We know that the content ends
>with the boundary (-----------------------------7d433743032e-- in this case
>in case of single file uplaod) so we know upto where the content will be,
>but how do we know the exact starting index of the content as the content
>type could vary.
>
>Also, the content length that I may extract, will give me size including
>that of the boundary and associated information also, but all I want is of
>only of the file uplaoded by the client.
>
>How did the Commons FileUpload team get across these problem? The source
>code, although very well written, looks a bit confusing to me.
>
>Thanks and Regards,
>Rommel Sharma.
>
>
>
>
>*********************************************************
>Disclaimer:          
>
>This message (including any attachments) contains 
>confidential information intended for a specific 
>individual and purpose, and is protected by law. 
>If you are not the intended recipient, you should 
>delete this message and are hereby notified that 
>any disclosure, copying, or distribution of this
>message, or the taking of any action based on it, 
>is strictly prohibited.
>
>*********************************************************
>Visit us at http://www.mahindrabt.com
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>  
>


-- 
Jason Lea



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


[Commons FileUpload]understanding the source code

Posted by Rommel Sharma <ro...@mahindrabt.com>.
Hi,

This question is about the Commons FileUpload package. I hope I am posting
to the right users list.

I am trying to understand the source code, and understand the logic through
which the data is extracted.

>From my understanding: when we use the file input tag to upload a file to
the server using the POST method, then the data transferred looks like this:

-----------------------------7d433743032eContent-Disposition: form-data;
name="file1"; filename="C:\abc.txt"Content-Type:
text/plainXYZ-----------------------------7d433743032e--

where the content in my file is XYZ.

We can write a code that  extracts the filename by parsing the inputstream.
Now my question is that how can we extract the content XYZ as the
Content-Type could be anything: text/plain, or text/html, or
application/octet-stream or something else? We know that the content ends
with the boundary (-----------------------------7d433743032e-- in this case
in case of single file uplaod) so we know upto where the content will be,
but how do we know the exact starting index of the content as the content
type could vary.

Also, the content length that I may extract, will give me size including
that of the boundary and associated information also, but all I want is of
only of the file uplaoded by the client.

How did the Commons FileUpload team get across these problem? The source
code, although very well written, looks a bit confusing to me.

Thanks and Regards,
Rommel Sharma.




*********************************************************
Disclaimer:          

This message (including any attachments) contains 
confidential information intended for a specific 
individual and purpose, and is protected by law. 
If you are not the intended recipient, you should 
delete this message and are hereby notified that 
any disclosure, copying, or distribution of this
message, or the taking of any action based on it, 
is strictly prohibited.

*********************************************************
Visit us at http://www.mahindrabt.com


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


Re: [Jelly] Using without a file or url

Posted by Jason Lea <ja...@kumachan.net.nz>.
Dion Gillard wrote:

>There was a patch for this functionality posted to the list recently.
>
>  
>
Oh cool.  I'll have a hunt for it :)

>On Thu, 29 Jul 2004 17:22:29 +1200, Jason Lea <ja...@kumachan.net.nz> wrote:
>  
>
>>I am new to Jelly.  I just started looking for something to allow me to
>>make some templates for HTML email, and Jelly looks great.
>>
>>I have an idea to store some template fragments in a database, pull them
>>out, combine them into the completed script then execute Jelly over it.
>>However Jelly seems to only have the facilities to open files or URLs.
>>It doesn't look like I can pass it a string containing my jelly template
>>and execute the script.
>>
>>Is this the case?  or is there a way to do it?
>>
>>I imagine I could write my template to a temp file, execute the script
>>on that, then delete the file - but that seems clumsy.
>>
>>--
>>Jason Lea
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>>    
>>
>
>
>  
>


-- 
Jason Lea



Re: [Jelly] Using without a file or url

Posted by Dion Gillard <di...@gmail.com>.
There was a patch for this functionality posted to the list recently.

On Thu, 29 Jul 2004 17:22:29 +1200, Jason Lea <ja...@kumachan.net.nz> wrote:
> I am new to Jelly.  I just started looking for something to allow me to
> make some templates for HTML email, and Jelly looks great.
> 
> I have an idea to store some template fragments in a database, pull them
> out, combine them into the completed script then execute Jelly over it.
> However Jelly seems to only have the facilities to open files or URLs.
> It doesn't look like I can pass it a string containing my jelly template
> and execute the script.
> 
> Is this the case?  or is there a way to do it?
> 
> I imagine I could write my template to a temp file, execute the script
> on that, then delete the file - but that seems clumsy.
> 
> --
> Jason Lea
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


-- 
http://www.multitask.com.au/people/dion/

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


Re: [Jelly] Using without a file or url

Posted by Jason Lea <ja...@kumachan.net.nz>.
Tim Reilly wrote:

>I don't want to take away from your question;
>
>but I was curious if you considered using Velocity
>http://jakarta.apache.org/velocity/
>http://today.java.net/pub/a/today/2003/12/16/velocity.html
>for your email templating, instead?
>  
>
No, I hadn't.  Having a quick look now though.  I was looking for 
something that did JSTL-style code, and my 30 second glance at velocity 
just now shows it uses a different style.  Keeping it consistent between 
my existing Struts/Tiles/JSP pages and templates would be nice.  I was 
really hoping I could have grabbed some sort of JSP processor from 
Tomcat and passed it the stuff I wanted evaluated.

>
>  
>
>>[Jason Lea wrote:]
>>Sent: Thursday, July 29, 2004 1:22 AM
>>To: Jakarta Commons Users List
>>Subject: [Jelly] Using without a file or url
>>
>>
>>I am new to Jelly.  I just started looking for something to allow me to 
>>make some templates for HTML email, and Jelly looks great.
>>
>>I have an idea to store some template fragments in a database, pull them 
>>out, combine them into the completed script then execute Jelly over it.  
>>However Jelly seems to only have the facilities to open files or URLs.  
>>It doesn't look like I can pass it a string containing my jelly template 
>>and execute the script.
>>
>>Is this the case?  or is there a way to do it?
>>
>>I imagine I could write my template to a temp file, execute the script 
>>on that, then delete the file - but that seems clumsy.
>>
>>-- 
>>Jason Lea
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>  
>


-- 
Jason Lea



RE: [Jelly] Using without a file or url

Posted by Tim Reilly <ti...@consultant.com>.
I don't want to take away from your question;

but I was curious if you considered using Velocity
http://jakarta.apache.org/velocity/
http://today.java.net/pub/a/today/2003/12/16/velocity.html
for your email templating, instead?


> [Jason Lea wrote:]
> Sent: Thursday, July 29, 2004 1:22 AM
> To: Jakarta Commons Users List
> Subject: [Jelly] Using without a file or url
> 
> 
> I am new to Jelly.  I just started looking for something to allow me to 
> make some templates for HTML email, and Jelly looks great.
> 
> I have an idea to store some template fragments in a database, pull them 
> out, combine them into the completed script then execute Jelly over it.  
> However Jelly seems to only have the facilities to open files or URLs.  
> It doesn't look like I can pass it a string containing my jelly template 
> and execute the script.
> 
> Is this the case?  or is there a way to do it?
> 
> I imagine I could write my template to a temp file, execute the script 
> on that, then delete the file - but that seems clumsy.
> 
> -- 
> Jason Lea


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