[Lift] Re: Dynamic Image generation / HttpServletResponse

2009-03-30 Thread Thomas Rynne

On Mar 26, 12:14 am, David Pollak feeder.of.the.be...@gmail.com
wrote:
 Here's some code to serve an image out of the database.
 ...
 Does this help?

Yes it does. I've got it working now.

Thanks, Thomas

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Dynamic Image generation / HttpServletResponse

2009-03-26 Thread Viktor Klang
For Graphs I'd recommend Flot :)



On Thu, Mar 26, 2009 at 12:14 AM, David Pollak 
feeder.of.the.be...@gmail.com wrote:

 Here's some code to serve an image out of the database.  Here's the Mapper
 definition:

 class Image extends LongKeyedMapper[Image] with IdPK {
   def getSingleton = Image

   object image extends MappedBinary(this)
   object lookup extends MappedUniqueId(this, 32) {
 override def dbIndexed_? = true
   }
   object saveTime extends MappedLong(this) {
 override def defaultValue = millis
   }
   object mimeType extends MappedString(this, 256)
 }

 object Image extends Image with LongKeyedMetaMapper[Image]

 And here's the code that serves the image:

 object ImageLogic {
   object TestImage {
 def unapply(in: String): Option[Image] =
 Image.find(By(Image.lookup, in.trim))
   }

   def matcher: LiftRules.DispatchPF = {
 case r @ Req(image_logic :: TestImage(img) ::
  Nil, _, GetRequest) = () = servImage(img, r)
   }

   def servImage(img: Image, r: Req): Box[LiftResponse] = {
 if (r.testIfModifiedSince(img.saveTime))
 Full(InMemoryResponse(new Array[Byte](0),
   List(Last-Modified -
toInternetDate(img.saveTime.is)), Nil,
 304))
 else Full(InMemoryResponse(img.image.is,
List(Last-Modified -
 toInternetDate(img.saveTime.is),
 Content-Type - img.mimeType.is,
 Content-Length -
 img.image.is.length.toString), Nil,
 200))
   }
 }

 In Boot:

  LiftRules.dispatch.append(ImageLogic.matcher)

 Does this help?

 Thanks,

 David

 On Wed, Mar 25, 2009 at 2:38 PM, Thomas Rynne thomas.ry...@gmail.comwrote:


 Hi,
  I want to dynamically generate images (actually a graph). I could
 write a seperate servlet for this but I'd like easy access to the
 Mapper classes and the logged in User etc so would prefer to write it
 as a method in lift.

 Is there a hook for this? I suppose I essentially want direct acccess
 to the httpresponse.

 I found some discussion of this here:

 http://groups.google.com/group/liftweb/browse_thread/thread/9d6f61f69a20765/d98a32e89e87d317

 but I don't know if it was ever implemented, and need some pointers/
 documentation if it has been.

 thanks for any advice,
 Thomas





 --
 Lift, the simply functional web framework http://liftweb.net
 Beginning Scala http://www.apress.com/book/view/1430219890
 Follow me: http://twitter.com/dpp
 Git some: http://github.com/dpp

 



-- 
Viktor Klang
Senior Systems Analyst

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Dynamic Image generation / HttpServletResponse

2009-03-25 Thread David Pollak
Oddly enough, I'm working on code like this right now... I'll post what I
can.

On Wed, Mar 25, 2009 at 2:38 PM, Thomas Rynne thomas.ry...@gmail.comwrote:


 Hi,
  I want to dynamically generate images (actually a graph). I could
 write a seperate servlet for this but I'd like easy access to the
 Mapper classes and the logged in User etc so would prefer to write it
 as a method in lift.

 Is there a hook for this? I suppose I essentially want direct acccess
 to the httpresponse.

 I found some discussion of this here:

 http://groups.google.com/group/liftweb/browse_thread/thread/9d6f61f69a20765/d98a32e89e87d317

 but I don't know if it was ever implemented, and need some pointers/
 documentation if it has been.

 thanks for any advice,
 Thomas

 



-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Dynamic Image generation / HttpServletResponse

2009-03-25 Thread Derek Chen-Becker
Check out our JFreeChart graphing class in PocketChange:

http://github.com/tjweir/pocketchangeapp/blob/903ae91ab2787aebd9a94a5439a7e39a9386bcdb/PocketChange/src/main/scala/com/pocketchangeapp/util/Charting.scala

And how it hooks into the request cycle in Boot:

http://github.com/tjweir/pocketchangeapp/blob/04adab6ab126f617d25e5f8222545a9a06e51e06/PocketChange/src/main/scala/bootstrap/liftweb/Boot.scala

There's also an Image class under the util directory that serves up a
MappedBinary image directly based on an Expense ID:

http://github.com/tjweir/pocketchangeapp/blob/903ae91ab2787aebd9a94a5439a7e39a9386bcdb/PocketChange/src/main/scala/com/pocketchangeapp/util/Image.scala

Derek

On Wed, Mar 25, 2009 at 4:38 PM, Thomas Rynne thomas.ry...@gmail.comwrote:


 Hi,
  I want to dynamically generate images (actually a graph). I could
 write a seperate servlet for this but I'd like easy access to the
 Mapper classes and the logged in User etc so would prefer to write it
 as a method in lift.

 Is there a hook for this? I suppose I essentially want direct acccess
 to the httpresponse.

 I found some discussion of this here:

 http://groups.google.com/group/liftweb/browse_thread/thread/9d6f61f69a20765/d98a32e89e87d317

 but I don't know if it was ever implemented, and need some pointers/
 documentation if it has been.

 thanks for any advice,
 Thomas

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Dynamic Image generation / HttpServletResponse

2009-03-25 Thread Timothy Perrett

If you'd like graphing, depending on your use case perhaps check out  
the flot graph widget in lift-widgets

Sent from my iPhone

On 25 Mar 2009, at 21:38, Thomas Rynne thomas.ry...@gmail.com wrote:


 Hi,
 I want to dynamically generate images (actually a graph). I could
 write a seperate servlet for this but I'd like easy access to the
 Mapper classes and the logged in User etc so would prefer to write it
 as a method in lift.

 Is there a hook for this? I suppose I essentially want direct acccess
 to the httpresponse.

 I found some discussion of this here:
 http://groups.google.com/group/liftweb/browse_thread/thread/9d6f61f69a20765/d98a32e89e87d317

 but I don't know if it was ever implemented, and need some pointers/
 documentation if it has been.

 thanks for any advice,
 Thomas

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Dynamic Image generation / HttpServletResponse

2009-03-25 Thread David Pollak
Here's some code to serve an image out of the database.  Here's the Mapper
definition:

class Image extends LongKeyedMapper[Image] with IdPK {
  def getSingleton = Image

  object image extends MappedBinary(this)
  object lookup extends MappedUniqueId(this, 32) {
override def dbIndexed_? = true
  }
  object saveTime extends MappedLong(this) {
override def defaultValue = millis
  }
  object mimeType extends MappedString(this, 256)
}

object Image extends Image with LongKeyedMetaMapper[Image]

And here's the code that serves the image:

object ImageLogic {
  object TestImage {
def unapply(in: String): Option[Image] =
Image.find(By(Image.lookup, in.trim))
  }

  def matcher: LiftRules.DispatchPF = {
case r @ Req(image_logic :: TestImage(img) ::
 Nil, _, GetRequest) = () = servImage(img, r)
  }

  def servImage(img: Image, r: Req): Box[LiftResponse] = {
if (r.testIfModifiedSince(img.saveTime))
Full(InMemoryResponse(new Array[Byte](0),
  List(Last-Modified -
   toInternetDate(img.saveTime.is)), Nil, 304))
else Full(InMemoryResponse(img.image.is,
   List(Last-Modified -
toInternetDate(img.saveTime.is),
Content-Type - img.mimeType.is,
Content-Length -
img.image.is.length.toString), Nil,
200))
  }
}

In Boot:

 LiftRules.dispatch.append(ImageLogic.matcher)

Does this help?

Thanks,

David

On Wed, Mar 25, 2009 at 2:38 PM, Thomas Rynne thomas.ry...@gmail.comwrote:


 Hi,
  I want to dynamically generate images (actually a graph). I could
 write a seperate servlet for this but I'd like easy access to the
 Mapper classes and the logged in User etc so would prefer to write it
 as a method in lift.

 Is there a hook for this? I suppose I essentially want direct acccess
 to the httpresponse.

 I found some discussion of this here:

 http://groups.google.com/group/liftweb/browse_thread/thread/9d6f61f69a20765/d98a32e89e87d317

 but I don't know if it was ever implemented, and need some pointers/
 documentation if it has been.

 thanks for any advice,
 Thomas

 



-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---