Plugin integration

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Plugin integration

Xavier MOGHRABI
Hi XWiki developers,

I'm preparing a small plugin for thumbnails as explain in my previous mail.
The image is resized by adding a parameter heigth at this end of a download
URL (eg :xwiki/bin/download/Photos/Seychelles1999/DSC04010.JPG?height=550)

To call the plugin I need to add a piece of code in DownloadAction class.

Do you think :
- is it better to add the dependancy to the plugin in the DownloadAction class
such as :
         // Sending the content of the attachment
-        byte[] data = attachment.getContent(context);
+               byte[] data = null;
+
+               // Resize if imageplugin is on
+               ImagePlugin imageplugin = (ImagePlugin)
context.getWiki().getPlugin(
+                               "image", context);
+               if ((request.getParameter("height") != null) &&
(imageplugin != null)) {
+                       try {
+                               int height =
Integer.parseInt(request.getParameter("height"));
+                               data = imageplugin.createThumbnail(attachment,
height, context);
+                               response.setContentType("image/png");
+                       } catch (NumberFormatException e) {
+                       } catch (Exception e) {
+                               e.printStackTrace();
+                       }
+               }
+
+               if (data == null) data = attachment.getContent(context);
+

- or is it better to add a generic method in the plugin Interface class
(XWikiPluginInterface) with a method : startDownloading(byte[] data,
XWikiContext context) and to call it after in DownloadAction ?

Regards

--
Xavier MOGHRABI - Consortium ObjectWeb



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Plugin integration

jeremi joslin
On 2/14/06, Xavier MOGHRABI <[hidden email]> wrote:

> Hi XWiki developers,
>
> I'm preparing a small plugin for thumbnails as explain in my previous mail.
> The image is resized by adding a parameter heigth at this end of a download
> URL (eg :xwiki/bin/download/Photos/Seychelles1999/DSC04010.JPG?height=550)
>
> To call the plugin I need to add a piece of code in DownloadAction class.
>
> Do you think :
> - is it better to add the dependancy to the plugin in the DownloadAction class
> such as :
>          // Sending the content of the attachment
> -        byte[] data = attachment.getContent(context);
> +               byte[] data = null;
> +
> +               // Resize if imageplugin is on
> +               ImagePlugin imageplugin = (ImagePlugin)
> context.getWiki().getPlugin(
> +                               "image", context);
> +               if ((request.getParameter("height") != null) &&
> (imageplugin != null)) {
> +                       try {
> +                               int height =
> Integer.parseInt(request.getParameter("height"));
> +                               data = imageplugin.createThumbnail(attachment,
> height, context);
> +                               response.setContentType("image/png");
> +                       } catch (NumberFormatException e) {
> +                       } catch (Exception e) {
> +                               e.printStackTrace();
> +                       }
> +               }
> +
> +               if (data == null) data = attachment.getContent(context);
> +
>
> - or is it better to add a generic method in the plugin Interface class
> (XWikiPluginInterface) with a method : startDownloading(byte[] data,
> XWikiContext context) and to call it after in DownloadAction ?
>
> Regards
>

Hi,
For me the second method is the best. I don't want the core of xwiki
depends on a plugin.

you can do something like this in the download action manager:
  XWikiPluginManager plugins = xwiki.getPluginManager();
  data = plugins.renderAttachment(byte[] data, XWikiContext context);

We also have to think about other binding points on xwiki for plugins.

Jérémi


--
Blog: http://www.jeremi.info
LinkedIn: https://www.linkedin.com/profile?viewProfile=&key=1437724
http://www.xwiki.org
skype: jeremi23 -- msn et gtalk : [hidden email]


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws