You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by skydiverx <ma...@tapestryforums.com> on 2006/01/30 00:43:15 UTC

Images from DB

Apologies all around if I have missed the obvious. 

What would be best practise if I have images stored as BLOBs in a DB and want to display those through a  tag?

This has to be a fairly common problem and yet we have failed to find some mention of this in the docs.

I dont know if it's relevant but we use Hibernate on top of MySQL.

Thank you in advance for your advice.

Tom.


-------------------- m2f --------------------

Sent from www.TapestryForums.com

Read this topic online here: <<topic_link>>

http://www.tapestryforums.com/viewtopic.php?p=13981#13981

-------------------- m2f --------------------



Re: Images from DB

Posted by "Jason L. Buberel" <ja...@buberel.org>.
Skydiver-

Lemme put together a quite blog entry on this - I just put the finishing
touches on such a system - based on generated images (jfreechart),
hibernate + postgres - that uses a customer IEngineService to do it.

See the output here:

http://www.altosresearch.com/altos/app?s=median&ra=c&q=a&st=CA&c=SUNNYVALE&z=94086&sz=l&ts=e&service=chart

For example...

More to follow.

-jason


On Mon, January 30, 2006 8:06 am, Raul Raja Martinez said:
> Is there a repository for the sources or not yet?
>
> Ron Piterman wrote:
>> By the end of februar we are planning to release (opensource, apache
>> license) a tapestry library for handling files, both up- and downloads),
>> which takes care of many things, and even enables some (basic) image
>> manipulation on both up- and downloaded images, so if you can bare the
>> wait...
>>
>> Cheers,
>> Ron
>>
>> skydiverx wrote:
>>> Apologies all around if I have missed the obvious.
>>> What would be best practise if I have images stored as BLOBs in a DB
>>> and want to display those through a  tag?
>>>
>>> This has to be a fairly common problem and yet we have failed to find
>>> some mention of this in the docs.
>>>
>>> I dont know if it's relevant but we use Hibernate on top of MySQL.
>>>
>>> Thank you in advance for your advice.
>>>
>>> Tom.
>>>
>>>
>>> -------------------- m2f --------------------
>>>
>>> Sent from www.TapestryForums.com
>>>
>>> Read this topic online here: <<topic_link>>
>>>
>>> http://www.tapestryforums.com/viewtopic.php?p=13981#13981
>>>
>>> -------------------- m2f --------------------
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
>
>


-- 
Jason L. Buberel - www.buberel.org - skype:jbuberel
im:jason@im.buberel.org - +1.650.483.1989

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


Re: Images from DB

Posted by Raul Raja Martinez <do...@estudiowebs.com>.
Is there a repository for the sources or not yet?

Ron Piterman wrote:
> By the end of februar we are planning to release (opensource, apache 
> license) a tapestry library for handling files, both up- and downloads), 
> which takes care of many things, and even enables some (basic) image 
> manipulation on both up- and downloaded images, so if you can bare the 
> wait...
> 
> Cheers,
> Ron
> 
> skydiverx wrote:
>> Apologies all around if I have missed the obvious.
>> What would be best practise if I have images stored as BLOBs in a DB 
>> and want to display those through a  tag?
>>
>> This has to be a fairly common problem and yet we have failed to find 
>> some mention of this in the docs.
>>
>> I dont know if it's relevant but we use Hibernate on top of MySQL.
>>
>> Thank you in advance for your advice.
>>
>> Tom.
>>
>>
>> -------------------- m2f --------------------
>>
>> Sent from www.TapestryForums.com
>>
>> Read this topic online here: <<topic_link>>
>>
>> http://www.tapestryforums.com/viewtopic.php?p=13981#13981
>>
>> -------------------- m2f --------------------
>>
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 


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


Re: Images from DB

Posted by Ron Piterman <rp...@gmx.net>.
By the end of februar we are planning to release (opensource, apache 
license) a tapestry library for handling files, both up- and downloads), 
which takes care of many things, and even enables some (basic) image 
manipulation on both up- and downloaded images, so if you can bare the 
wait...

Cheers,
Ron

skydiverx wrote:
> Apologies all around if I have missed the obvious. 
> 
> What would be best practise if I have images stored as BLOBs in a DB and want to display those through a  tag?
> 
> This has to be a fairly common problem and yet we have failed to find some mention of this in the docs.
> 
> I dont know if it's relevant but we use Hibernate on top of MySQL.
> 
> Thank you in advance for your advice.
> 
> Tom.
> 
> 
> -------------------- m2f --------------------
> 
> Sent from www.TapestryForums.com
> 
> Read this topic online here: <<topic_link>>
> 
> http://www.tapestryforums.com/viewtopic.php?p=13981#13981
> 
> -------------------- m2f --------------------
> 
> 
> 


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


RE: Images from DB

Posted by Patrick Casey <pa...@adelphia.net>.
	This will probably help (3.0.3):

	1: The Service:

package services;

import java.io.IOException;

import javax.servlet.ServletException;

import org.apache.tapestry.IComponent;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.AbstractService;
import org.apache.tapestry.engine.IEngineServiceView;
import org.apache.tapestry.engine.ILink;
import org.apache.tapestry.request.ResponseOutputStream;

import survey.InternalImage;
import data.HibHelper;

public class InternalImageServer extends AbstractService {
	public static final String SERVICE_NAME = "InternalImageServer";

	public ILink getLink(IRequestCycle cycle, IComponent component,
			Object[] parms) {
		String[] context;
		String pageName = component.getPage().getPageName();
		String idPath = component.getIdPath();

		if (idPath != null) {
			context = new String[2];
			context[1] = idPath;
		} else
			context = new String[1];

		context[0] = pageName;
		return constructLink(cycle, SERVICE_NAME, context, parms,
true);
	}

	public void service(IEngineServiceView acrg0, IRequestCycle cycle,
			ResponseOutputStream response) throws
ServletException, IOException {
		Object[] parms = this.getParameters(cycle);
		
		String id = (String) parms[0];
		InternalImage ii = (InternalImage)
HibHelper.getSession().get(InternalImage.class, id);		
		response.setContentType(ii.getType());
		response.write(ii.getData());		
	}

	public String getName() {

		return SERVICE_NAME;
	}

}

	Step 2: The ImageLink java file

package components;

import org.apache.tapestry.BaseComponent;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.IEngineService;
import org.apache.tapestry.engine.ILink;

import services.InternalImageServer;

public abstract class ImageLink extends BaseComponent {	
	private String fImageId;
	private String fAlt = null;
	private String fTitleText = null;

	public String getAlt() {
		if (fAlt == null)
			fAlt = "Alt";
		return fAlt;
	}

	public void setAlt(String alt) {
		fAlt = alt;
	}

	public String getTitleText() {
		if (fTitleText == null)
			fTitleText = "Title";
		return fTitleText;
	}

	public void setTitleText(String titleText) {
		fTitleText = titleText;
	}

	public String getImageId() {
		return fImageId;
	}

	public void setImageId(String imageId) {
		fImageId = imageId;
	}
	
	public String getLink() {
		IRequestCycle cycle = getPage().getRequestCycle();
		IEngineService service =
cycle.getEngine().getService(InternalImageServer.SERVICE_NAME);

		Object[] parms = new Object[1];
		parms[0] = fImageId;
		ILink link = service.getLink(cycle, this, parms);
		return link.getAbsoluteURL();
	}

}
	Part 3: The ImageLink .jwc 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE component-specification PUBLIC
  "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
  "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
<!-- generated by Spindle, http://spindle.sourceforge.net -->

<component-specification class="components.ImageLink"
    allow-body="yes"
    allow-informal-parameters="yes">
    
    <description>add a description</description>
    <parameter name="imageId" required="yes" type="java.lang.String"
direction="in"/>
    <parameter name="alt" required="no" type="java.lang.String"
direction="in" />
    <parameter name="titleText" required="no" type="java.lang.String"
direction="in" />
</component-specification>

	Part 4: The Imagelink html
<span jwcid="@Any" element="img" src="ognl:getLink()" alt="ognl:alt"
title="ognl:titleText"/>

	

> -----Original Message-----
> From: skydiverx [mailto:maillist@tapestryforums.com]
> Sent: Sunday, January 29, 2006 3:43 PM
> To: tapestry-user@jakarta.apache.org
> Subject: Images from DB
> 
> Apologies all around if I have missed the obvious.
> 
> What would be best practise if I have images stored as BLOBs in a DB and
> want to display those through a  tag?
> 
> This has to be a fairly common problem and yet we have failed to find some
> mention of this in the docs.
> 
> I dont know if it's relevant but we use Hibernate on top of MySQL.
> 
> Thank you in advance for your advice.
> 
> Tom.
> 
> 
> -------------------- m2f --------------------
> 
> Sent from www.TapestryForums.com
> 
> Read this topic online here: <<topic_link>>
> 
> http://www.tapestryforums.com/viewtopic.php?p=13981#13981
> 
> -------------------- m2f --------------------
> 




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