You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Ojares Rami EINT <Ra...@elisa.fi> on 2003/11/11 14:07:55 UTC

[Jelly] Converting JSP taglib to Jelly taglib

Hi,

I am new to Jelly.
I was thinking about converting a JSP taglib to Jelly tags.
But I have some concerns.
One very handy thing about JSP parsing
is that jsp does not have to be a well formed XML document.
How about Jelly?
Could I use some jelly tags inside a html document
that is filled with javascript, ampersands and
unfinished tags?

- rami

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


Re: [Jelly] XML Declaration

Posted by "Christopher W. Farnham" <ch...@wrycan.com>.
Paul,

I have an architecture where some of my objects have associated jelly 
scripts which are an XML representation of the object,
I call a method |'writeAsXML(File)'| and it gets written as XML to the 
file.  Essentially, the jelly logic that's embedded in my
java code borrows heavily from the core:file code, but I resisted using 
the core:file tag for a couple of reasons.

1) By not using the core:file tag, my jelly scripts end up looking more 
like the XML they produce.
2) My own java code can have hooks into logging and reporting etc.
3) I have some custom tags which allow for the above actions to happen 
recursively (when jellified objects contain other jellified objects)
    and having that code together makes it easier to maintain.
4) This does pretty much the same thing as castor's marshall behavior 
except I have a lot more control of the final output and it's more
    WYSIWYG like.

I've looked closely at the source for core:file and can't see what I 
might have done differently.  But in reading the explanation above,
perhaps I've answered my own question because I have a little more going 
on behind the scenes than core:file, but I don't modify XMLOutput
in any way after creating it, other than simply passing it around.

Here's an example of one of my 'root' jelly scripts.  The wr:embed 
object calls a similar script for each composed object in a 
Component-like pattern.
<?xml version="1.0" encoding="UTF-8"?>
<j:jelly trim="true" xmlns:j="jelly:core" xmlns:x="jelly:xml"
    xmlns:wr="jelly:com.wrycan.common.jelly.tags.wrycan.WrycanTagLibrary">
    <x:element name="book">
        <x:attribute name="xmlns">http://xml.classwell.com/clg</x:attribute>
        <x:attribute 
name="xmlns:clg">http://xml.classwell.com/clg</x:attribute>
        <x:attribute 
name="xmlns:xsi">http://www.w3.org/2001/XMLSchema-instance</x:attribute>
        <x:attribute 
name="xsi:schemaLocation">${this.getSchemaLocation()}</x:attribute>
        <x:attribute name="id">${this.getId()}</x:attribute>
        <meta>
            <wr:embed object="${this.getMetaSystem()}" />
            <wr:embed object="${this.getMetaContent()}" />
            <wr:embed object="${this.getMetaEducation()}" />
        </meta>
        <bookName>${this.getBookName()}</bookName>
        <j:forEach items="${this.getSectionsList()}" var="section">
            <wr:embed object="${section}" />
        </j:forEach>
    </x:element>
</j:jelly>

Christopher Farnham
Senior Consultant at Wrycan, Inc.

chris.farnham@wrycan.com
http://www.wrycan.com



Paul Libbrecht wrote:

> Christopher,
>
>
> Doesn't the core:file tag do this already ?
>
> Paul
>
>
> Christopher W. Farnham wrote:
>
>> Is there an elegant way to make sure the XML declaration is included 
>> when writing to XMOutput?
>>
>> I have a factory method a la the core FileTag where I was calling 
>> |outputFormat.setSuppressDeclaration(false);
>>
>> |This didn't work (there was no declaration at the top of my XML 
>> files).  Finally I ended up hacking
>> my factory method to do this:
>> |        OutputFormat format = new OutputFormat();
>>        //we can use this line if we want results pretty printed
>>        //format = OutputFormat.createPrettyPrint();
>>        if (xmlDeclaration) {
>>            writer.write("<?xml version=\"1.0\" 
>> encoding=\"UTF-8\"?>".toCharArray());
>>        }
>>        format.setEncoding( "UTF8" );
>>        format.setSuppressDeclaration(true);
>>        final XMLWriter xmlWriter = new XMLWriter(writer, format);
>>        xmlWriter.setEscapeText(false);
>>
>>        XMLOutput returnOutput = new XMLOutput() {
>>            public void close() throws IOException {
>>                xmlWriter.close();
>>            }
>>        };
>>        returnOutput.setContentHandler(xmlWriter);
>>        returnOutput.setLexicalHandler(xmlWriter);
>>        return returnOutput;
>>
>> |This, of course, is not the best way to do things, but it works.  
>> Did I miss something?
>>
>> Thanks,
>>
>> Christopher Farnham
>> Senior Consultant at Wrycan, Inc.
>>
>> chris.farnham@wrycan.com
>> http://www.wrycan.com
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>

Re: [Jelly] XML Declaration

Posted by Paul Libbrecht <pa...@activemath.org>.
Christopher,


Doesn't the core:file tag do this already ?

Paul


Christopher W. Farnham wrote:
> Is there an elegant way to make sure the XML declaration is included 
> when writing to XMOutput?
> 
> I have a factory method a la the core FileTag where I was calling 
> |outputFormat.setSuppressDeclaration(false);
> 
> |This didn't work (there was no declaration at the top of my XML 
> files).  Finally I ended up hacking
> my factory method to do this:
> |        OutputFormat format = new OutputFormat();
>        //we can use this line if we want results pretty printed
>        //format = OutputFormat.createPrettyPrint();
>        if (xmlDeclaration) {
>            writer.write("<?xml version=\"1.0\" 
> encoding=\"UTF-8\"?>".toCharArray());
>        }
>        format.setEncoding( "UTF8" );
>        format.setSuppressDeclaration(true);
>        final XMLWriter xmlWriter = new XMLWriter(writer, format);
>        xmlWriter.setEscapeText(false);
> 
>        XMLOutput returnOutput = new XMLOutput() {
>            public void close() throws IOException {
>                xmlWriter.close();
>            }
>        };
>        returnOutput.setContentHandler(xmlWriter);
>        returnOutput.setLexicalHandler(xmlWriter);
>        return returnOutput;
> 
> |This, of course, is not the best way to do things, but it works.  Did I 
> miss something?
> 
> Thanks,
> 
> Christopher Farnham
> Senior Consultant at Wrycan, Inc.
> 
> chris.farnham@wrycan.com
> http://www.wrycan.com
> 


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


[Jelly] XML Declaration

Posted by "Christopher W. Farnham" <ch...@wrycan.com>.
Is there an elegant way to make sure the XML declaration is included 
when writing to XMOutput?

I have a factory method a la the core FileTag where I was calling 
|outputFormat.setSuppressDeclaration(false);

|This didn't work (there was no declaration at the top of my XML 
files).  Finally I ended up hacking
my factory method to do this:
|        OutputFormat format = new OutputFormat();
        //we can use this line if we want results pretty printed
        //format = OutputFormat.createPrettyPrint();
        if (xmlDeclaration) {
            writer.write("<?xml version=\"1.0\" 
encoding=\"UTF-8\"?>".toCharArray());
        }
        format.setEncoding( "UTF8" );
        format.setSuppressDeclaration(true);
        final XMLWriter xmlWriter = new XMLWriter(writer, format);
        xmlWriter.setEscapeText(false);

        XMLOutput returnOutput = new XMLOutput() {
            public void close() throws IOException {
                xmlWriter.close();
            }
        };
        returnOutput.setContentHandler(xmlWriter);
        returnOutput.setLexicalHandler(xmlWriter);
        return returnOutput;

|This, of course, is not the best way to do things, but it works.  Did I 
miss something?

Thanks,

Christopher Farnham
Senior Consultant at Wrycan, Inc.

chris.farnham@wrycan.com
http://www.wrycan.com



>  
>



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


Re: [Jelly] Converting JSP taglib to Jelly taglib

Posted by di...@multitask.com.au.
A jelly script *must* be a well-formed XML document.
--
dIon Gillard, Multitask Consulting
Blog:      http://blogs.codehaus.org/people/dion/



"Ojares Rami EINT" <Ra...@elisa.fi> wrote on 12/11/2003 12:07:55 AM:

> Hi,
> 
> I am new to Jelly.
> I was thinking about converting a JSP taglib to Jelly tags.
> But I have some concerns.
> One very handy thing about JSP parsing
> is that jsp does not have to be a well formed XML document.
> How about Jelly?
> Could I use some jelly tags inside a html document
> that is filled with javascript, ampersands and
> unfinished tags?
> 
> - rami
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


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