cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Dumon <br...@outerthought.org>
Subject Re: String to bytestream?
Date Mon, 08 Sep 2003 15:54:16 GMT
On Mon, 2003-09-08 at 16:09, Timothy Larson wrote:
> --- Bruno Dumon <bruno@outerthought.org> wrote:
> ...
> > I don't know what you've attempted so far, but I think the following
> > will work (warning: pseudo code):
> > 
> > XMLByteStreamCompiler comp = new XMLByteStreamCompiler();
> > String mytext = "piet snot";
> > comp.characters(mytext.toCharArray(), 0, mytext.length());
> > Object compiledSAX = comp.getSAXFragment();
> ...
> 
> Thanks for the help.  I now have two working solutions:
> 
> function setLabel1 (widgetDefinition, labelString) {
>   var comp = new Packages.org.apache.cocoon.components.sax.XMLByteStreamCompiler();
>   var text = new java.lang.String(labelString);
>   comp.characters(text.toCharArray(), 0, text.length());
>   var compiledSAX = comp.getSAXFragment();
>   widgetDefinition.setLabel(compiledSAX);
> }
> 
> function setLabel2 (widgetDefinition, labelString) {
>   var doc  = new Packages.org.apache.xerces.dom.DocumentImpl();
>   var elem = doc.createElementNS("http://apache.org/cocoon/woody/definition/1.0", "label");
>   var text = doc.createTextNode(labelString);
>   elem.appendChild(text);
>   var label = Packages.org.apache.cocoon.woody.util.DomHelper.compileElementContent(elem);
>   widgetDefinition.setLabel(label);
> }
> 

the first one should be way faster.

> BTW: What do XMLByteStreamCompiler.writeString and friends do?

That method shouldn't be used directly (and shouldn't be public
probably). It's used everwhere where a string needs to be written as
part of the compiled SAX events.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


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


Mime
View raw message