You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Sebastian Klamar <se...@tux.wh17.tu-dresden.de> on 2003/11/24 22:47:12 UTC

Flow's processePipelineTo inside a Transformer?

I want to add some information to <img> links inside a document.  In my
special case this information is the size of the image.  The difficult
thing is that it's not the current (static) file size of the image.
Instead of the image has to be processed by a Reader (transforms JPEGs
into WBMPs, makes resizing etc.), so the image size is varying.  So the
image has to be processed by Cocoon before you can calculate the size.

Now my question to you.  How can I aquire the information in question
inside the transformer?  With Flow's processPipelineTo() you can process
a dummy request, but only inside a flow script :-(  How can I combine
SAX processing of a transformer with the control flow processing like
Flow's processPipelineTo()?


TIA -- Sebastian

-- 
Dinge, die man nicht hören will, wenn man operiert wird:
                        »Nimm' dieses Opfer an, oh Herr der Finsternis.«
************************************************************************
PGP Key: 0x1E727CE6 / 9085 48BD 8332 4BFC D80C  A6CF D162 20BB 1E72 7CE6

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


Re: Flow's processePipelineTo inside a Transformer?

Posted by Upayavira <uv...@upaya.co.uk>.
Bruno Dumon wrote:

>On Tue, 2003-11-25 at 19:53, Upayavira wrote:
>  
>
>>Bruno Dumon wrote:
>>
>>    
>>
>>>On Mon, 2003-11-24 at 22:47, Sebastian Klamar wrote:
>>> 
>>>
>>>      
>>>
>>>>I want to add some information to <img> links inside a document.  In my
>>>>special case this information is the size of the image.  The difficult
>>>>thing is that it's not the current (static) file size of the image.
>>>>Instead of the image has to be processed by a Reader (transforms JPEGs
>>>>into WBMPs, makes resizing etc.), so the image size is varying.  So the
>>>>image has to be processed by Cocoon before you can calculate the size.
>>>>
>>>>Now my question to you.  How can I aquire the information in question
>>>>inside the transformer?  With Flow's processPipelineTo() you can process
>>>>a dummy request, but only inside a flow script :-(  How can I combine
>>>>SAX processing of a transformer with the control flow processing like
>>>>Flow's processPipelineTo()?
>>>>   
>>>>
>>>>        
>>>>
>>>If you're writing a custom transformer, you can use the SourceResolver
>>>to resolve a cocoon: URL, which is similar to the processPipelineTo in
>>>flowscript.
>>> 
>>>
>>>      
>>>
>>Yup. That's good. But a question of mine - what if you want this 
>>pipeline, within your custom transformer, to feed SAX events into your 
>>own content handler, so that you don't have to reparse the XML? Is that 
>>possile?
>>    
>>
>
>yes, check if the Source implements the XMLizable interface, and if so,
>use the XMLizable.toSAX method. The SourceUtil class has a convenience
>method for that: SourceUtil.toSAX(Source, ContentHandler).
>  
>
Yabadabadooo! That's great. Thanks!

Upayavira




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


Re: Flow's processePipelineTo inside a Transformer?

Posted by Bruno Dumon <br...@outerthought.org>.
On Tue, 2003-11-25 at 19:53, Upayavira wrote:
> Bruno Dumon wrote:
> 
> >On Mon, 2003-11-24 at 22:47, Sebastian Klamar wrote:
> >  
> >
> >>I want to add some information to <img> links inside a document.  In my
> >>special case this information is the size of the image.  The difficult
> >>thing is that it's not the current (static) file size of the image.
> >>Instead of the image has to be processed by a Reader (transforms JPEGs
> >>into WBMPs, makes resizing etc.), so the image size is varying.  So the
> >>image has to be processed by Cocoon before you can calculate the size.
> >>
> >>Now my question to you.  How can I aquire the information in question
> >>inside the transformer?  With Flow's processPipelineTo() you can process
> >>a dummy request, but only inside a flow script :-(  How can I combine
> >>SAX processing of a transformer with the control flow processing like
> >>Flow's processPipelineTo()?
> >>    
> >>
> >
> >If you're writing a custom transformer, you can use the SourceResolver
> >to resolve a cocoon: URL, which is similar to the processPipelineTo in
> >flowscript.
> >  
> >
> Yup. That's good. But a question of mine - what if you want this 
> pipeline, within your custom transformer, to feed SAX events into your 
> own content handler, so that you don't have to reparse the XML? Is that 
> possile?

yes, check if the Source implements the XMLizable interface, and if so,
use the XMLizable.toSAX method. The SourceUtil class has a convenience
method for that: SourceUtil.toSAX(Source, ContentHandler).

-- 
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


Re: Flow's processePipelineTo inside a Transformer?

Posted by Upayavira <uv...@upaya.co.uk>.
Bruno Dumon wrote:

>On Mon, 2003-11-24 at 22:47, Sebastian Klamar wrote:
>  
>
>>I want to add some information to <img> links inside a document.  In my
>>special case this information is the size of the image.  The difficult
>>thing is that it's not the current (static) file size of the image.
>>Instead of the image has to be processed by a Reader (transforms JPEGs
>>into WBMPs, makes resizing etc.), so the image size is varying.  So the
>>image has to be processed by Cocoon before you can calculate the size.
>>
>>Now my question to you.  How can I aquire the information in question
>>inside the transformer?  With Flow's processPipelineTo() you can process
>>a dummy request, but only inside a flow script :-(  How can I combine
>>SAX processing of a transformer with the control flow processing like
>>Flow's processPipelineTo()?
>>    
>>
>
>If you're writing a custom transformer, you can use the SourceResolver
>to resolve a cocoon: URL, which is similar to the processPipelineTo in
>flowscript.
>  
>
Yup. That's good. But a question of mine - what if you want this 
pipeline, within your custom transformer, to feed SAX events into your 
own content handler, so that you don't have to reparse the XML? Is that 
possile?

Regards, Upayavira


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


Re: cocoon:/ does not work with SourceResolver (was: Re: Flow's processePipelineTo inside a Transformer?)

Posted by Bruno Dumon <br...@outerthought.org>.
On Wed, 2003-11-26 at 21:32, Sebastian Klamar wrote:
> * Bruno Dumon [2003-11-26 14:29 +0100] wrote:
> > On Wed, 2003-11-26 at 14:04, Sebastian Klamar wrote:
> > > But for cocoon:/ and cocoon:// prefixed URLs (like
> > > »cocoon://samples/«) I get no response.  The response has always
> > > mime type text/xml and content length -1.
> >
> > Can you do source.getInputStream() and read data from the inputstream?
> 
> I can call source.getInputStream().available() that returns the same
> size as source.getContentLength() with http:// URI.  But I can't make
> reading from the InputStream.  I've tried the read() methods from
> InputStream interface
> 
>   byte[] bytes;
>   source.getInputStream().read(bytes);

is this a literal cut and paste from your code? You need to create the
byte array yourself:

byte[] bytes = new byte[10000];

though you should have gotten a NullPointerException in case you didn't
do that. See the javadoc of the InputStream.read  method for more info.

> 
> and
> 
>   source.getInputStream().read(bytes, int, ...getInputStream().length)

this obviously won't work, since getLength() returns -1.

> but both are blocking the whole process and no data gets read.  I've
> also tried to call close() on the InputStream.
> 
> Do you easily see what I'm doing wrong?  If not I can provide more
> information about IOExceptions that were thrown when trying various
> methods tomorrow (no read() but close(), only available() w/ and wo
> close() ...).

If you think you found a bug, best of all would be a full example (full
Java class + pipelines etc. to reproduce the problem) that illustrates
the problem, so that we can reproduce it (submit it to bugzilla in that
case).

-- 
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


Re: cocoon:/ does not work with SourceResolver (was: Re: Flow's processePipelineTo inside a Transformer?)

Posted by Sebastian Klamar <se...@tux.wh17.tu-dresden.de>.
* Bruno Dumon [2003-11-26 14:29 +0100] wrote:
> On Wed, 2003-11-26 at 14:04, Sebastian Klamar wrote:
> > But for cocoon:/ and cocoon:// prefixed URLs (like
> > »cocoon://samples/«) I get no response.  The response has always
> > mime type text/xml and content length -1.
>
> Can you do source.getInputStream() and read data from the inputstream?

I can call source.getInputStream().available() that returns the same
size as source.getContentLength() with http:// URI.  But I can't make
reading from the InputStream.  I've tried the read() methods from
InputStream interface

  byte[] bytes;
  source.getInputStream().read(bytes);

and

  source.getInputStream().read(bytes, int, ...getInputStream().length)

but both are blocking the whole process and no data gets read.  I've
also tried to call close() on the InputStream.

Do you easily see what I'm doing wrong?  If not I can provide more
information about IOExceptions that were thrown when trying various
methods tomorrow (no read() but close(), only available() w/ and wo
close() ...).


TIA -- Sebastian

-- 
Dinge, die man nicht hören will, wenn man operiert wird:
                          »Und nun noch ein Bild aus der Richtung; Mann,
                                          das ist wirklich ein Monster.«
************************************************************************
PGP Key: 0x1E727CE6 / 9085 48BD 8332 4BFC D80C  A6CF D162 20BB 1E72 7CE6

Re: cocoon:/ does not work with SourceResolver (was: Re: Flow's processePipelineTo inside a Transformer?)

Posted by Bruno Dumon <br...@outerthought.org>.
On Wed, 2003-11-26 at 14:04, Sebastian Klamar wrote:
> Bruno,
> 
> thank you for your reply.
> 
> * Bruno Dumon [2003-11-25 19:28 +0100] wrote:
> > If you're writing a custom transformer, you can use the SourceResolver
> > to resolve a cocoon: URL, which is similar to the processPipelineTo in
> > flowscript.
> 
> I've tried this.  But for cocoon:/ and cocoon:// prefixed URLs (like
> »cocoon://samples/«) I get no response.  The response has always mime
> type text/xml and content length -1.

Can you do source.getInputStream() and read data from the inputstream?

The content length being -1 is normal behaviour. The javadoc for the
Source interface (part of Avalon Excalibur) states that -1 is returned
when the content length is unknown.

The fact that the mime type is always text/xml might be a bug, don't
know.

-- 
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


cocoon:/ does not work with SourceResolver (was: Re: Flow's processePipelineTo inside a Transformer?)

Posted by Sebastian Klamar <se...@tux.wh17.tu-dresden.de>.
Bruno,

thank you for your reply.

* Bruno Dumon [2003-11-25 19:28 +0100] wrote:
> If you're writing a custom transformer, you can use the SourceResolver
> to resolve a cocoon: URL, which is similar to the processPipelineTo in
> flowscript.

I've tried this.  But for cocoon:/ and cocoon:// prefixed URLs (like
»cocoon://samples/«) I get no response.  The response has always mime
type text/xml and content length -1.  For http:// prefixed URLs (like
»http://localhost:8888/samples/«) resolveURI() works.  So what I'm doing
wrong?


TIA -- Sebastian

<mycodesnippet>

//  String uri = this.fragmentURIPrefix + fragmentID + this.fragmentURISuffix;
    String uri = "cocoon://samples/";
    Source source = null;
    source = this.sourceResolver.resolveURI(uri);
    try {
      source = this.sourceResolver.resolveURI(uri);
    } catch (MalformedURLException e) {
      getLogger().error(e);
    } catch (IOException e) {
      getLogger().error(e);
    }

</mycodesnippet>

-- 
Dinge, die man nicht hören will, wenn man operiert wird:
    »Alle bleiben ruhig stehen.  Ich hab' meine Kontaktlinsen verloren.«
************************************************************************
PGP Key: 0x1E727CE6 / 9085 48BD 8332 4BFC D80C  A6CF D162 20BB 1E72 7CE6

Re: Flow's processePipelineTo inside a Transformer?

Posted by Bruno Dumon <br...@outerthought.org>.
On Mon, 2003-11-24 at 22:47, Sebastian Klamar wrote:
> I want to add some information to <img> links inside a document.  In my
> special case this information is the size of the image.  The difficult
> thing is that it's not the current (static) file size of the image.
> Instead of the image has to be processed by a Reader (transforms JPEGs
> into WBMPs, makes resizing etc.), so the image size is varying.  So the
> image has to be processed by Cocoon before you can calculate the size.
> 
> Now my question to you.  How can I aquire the information in question
> inside the transformer?  With Flow's processPipelineTo() you can process
> a dummy request, but only inside a flow script :-(  How can I combine
> SAX processing of a transformer with the control flow processing like
> Flow's processPipelineTo()?

If you're writing a custom transformer, you can use the SourceResolver
to resolve a cocoon: URL, which is similar to the processPipelineTo in
flowscript.

-- 
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