cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JeVeoy <jor...@wisloff.org>
Subject Re: Streaming buffered image using Cocoon
Date Tue, 24 May 2011 19:59:19 GMT

Ah...Beautiful! Thank you for providing a working sample! Awesome!

But what if I wanted to perform check against values in cocoon.session,
cocoon.context or perhaps business logic? What I'm thinking of is to
intercept the request in sitemap.xmap like this:

  <map:match pattern="time.jpg">
    <map:call function="intercept"/>
  </map:match>

Then I would have a flowscript function like this:

  function intercept() {
    // Session valid? Using cocoon.session to validate...
    ...
    // Fetch some DB values if session valid...
    var businessLogicObject = cocoon.getComponent("blBean");
    ...
    // Etc..
    
    // I know that user has a valid session, I've fetched values from
context (like language variables),
    // performed a fetch towards DB and now I want to send everything needed
to generate a png-image
    cocoon.sendPage("generate.image", {"background" : backgroundVariable,
"overlay" : overlayVariable});
  }

The idea was to make a sitemap entry like this:

  <map:match pattern="generate.image">
    <map:read type="timeimg"/>
  </map:match>

This utilizes the generator you wrote, but in this case I get an exception:
Pipeline has already been processed for this request. I've omitted
parameters, as you can see, for the time being.

Is there any simple solution to make use of a flowscript function to perform
logic and then use your reader with parameters?

Thomas Markus wrote:
> 
> Hi,
> 
> thats pretty simple. Create a reader like this (creates a png with 
> current timestamp in red):
> 
> public class TestImageReader extends AbstractReader {
> 
>      public String getMimeType() {
>          return "image/png";
>      }
> 
>      public void generate() throws IOException, SAXException, 
> ProcessingException {
>          String date = DateFormat.getDateTimeInstance().format(new
> Date());
>          Font font = Font.decode(Font.SERIF).deriveFont(80.f);
>          TextLayout textLayout = new TextLayout(date, font, new 
> FontRenderContext(null, true, true));
>          Rectangle2D bounds = textLayout.getBounds();
>          BufferedImage image = new BufferedImage((int) 
> bounds.getWidth(), (int) bounds.getHeight(), BufferedImage.TYPE_INT_ARGB);
>          Graphics2D g = image.createGraphics();
>          g.setColor(Color.RED);
>          textLayout.draw(g, (float) -bounds.getX(), (float)
> -bounds.getY());
>          g.dispose();
>          ImageIO.write(image, "png", this.out);
>      }
> 
> }
> 
> in your sitemap define and use this reader:
> <map:components>
> <map:readers>
> <map:reader name="timeimg" src="test.TestImageReader" />
> </map:readers>
> </map:components>
> 
> ...
> 
> <map:match pattern="time.jpg">
>    <map:read type="timeimg" />
> </map:match>
> 
> 
> hth
> Thomas
> 
> 
> Am 21.05.2011 14:00, schrieb JeVeoy:
>>
>> First of all: thank you so much for helping me out, Steven&  Thomas!
>>
>> Then: I've tried my best to see if I could get a working example to run
>> using either javax.imageio.ImageIO.write(RenderedImage, String,
>> OutputStream) or AbstractReader.out, but to no luck. Googling didn't
>> quite
>> help either. I'm very sorry for my lack of knowledge... Hope you can
>> forgive
>> me.
>>
>> Pipeline for an image-reader is, as far as I know, defined in
>> sitemap.xmap
>> like this:
>>
>> <map:match pattern="*.jpg">
>>    <map:read type="image" src="path/{1}.png" mime-type="image/png">
>>    </map:read>
>> </map:match>
>>
>> How can I make use of AbstractReader.out in this definition?
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Streaming-buffered-image-using-Cocoon-tp31655697p31693420.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


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


Mime
View raw message