On Jan 5, 2009, at 1:05 PM, fmancinelli (SVN) wrote:

> Author: fmancinelli
> Date: 2009-01-05 13:05:32 +0100 (Mon, 05 Jan 2009)
> New Revision: 15061
>
> Modified:
>   sandbox/xwiki-core-rest/.classpath
>   sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/ 
> PageResource.java
>   sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/ 
> RestApplication.java
> Log:
> Componentized page representation with plexus components as  
> suggested on the mailing list.
>
> Modified: sandbox/xwiki-core-rest/.classpath
> ===================================================================
> --- sandbox/xwiki-core-rest/.classpath        2009-01-05 12:01:09 UTC (rev  
> 15060)
> +++ sandbox/xwiki-core-rest/.classpath        2009-01-05 12:05:32 UTC (rev  
> 15061)
> @@ -1,6 +1,7 @@
> <?xml version="1.0" encoding="UTF-8"?>
> <classpath>
>       <classpathentry kind="src" output="target/classes" path="src/main/ 
> java"/>
> +     <classpathentry kind="src" path="src/main/resources"/>
>       <classpathentry kind="src" path="src/test/java"/>
>       <classpathentry kind="src" path="src/test/resources"/>
>       <classpathentry kind="con"  
> path="org.eclipse.jdt.launching.JRE_CONTAINER/ 
> org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
>
> Modified: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/ 
> PageResource.java
> ===================================================================
> --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/ 
> PageResource.java     2009-01-05 12:01:09 UTC (rev 15060)
> +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/ 
> PageResource.java     2009-01-05 12:05:32 UTC (rev 15061)
> @@ -1,14 +1,15 @@
> package org.xwiki.rest;
>
> +import java.util.Map;
> +
> import org.restlet.Context;
> import org.restlet.data.MediaType;
> import org.restlet.data.Request;
> import org.restlet.data.Response;
> import org.restlet.data.Status;
> import org.restlet.resource.Representation;
> -import org.restlet.resource.StringRepresentation;
> import org.restlet.resource.Variant;
> -import org.xwiki.rest.model.Page;
> +import org.xwiki.component.manager.ComponentLookupException;
>
> import com.xpn.xwiki.api.Document;
>
> @@ -29,9 +30,19 @@
>     public PageResource(Context context, Request request, Response  
> response)
>     {
>         super(context, request, response);
> -        getVariants().clear();
> -        getVariants().add(new Variant(MediaType.TEXT_XML));
> -        getVariants().add(new Variant(MediaType.TEXT_PLAIN));
> +
> +        /* Configure Media types from registered PageRepresenter  
> components */
> +        try {
> +            getVariants().clear();
> +            Map<String, Object> map = 
> com.xpn.xwiki.web.Utils.getComponentManager 
> ().lookupMap(PageRepresenter.ROLE);
> +            for (String mediaTypeName : map.keySet()) {
> +                MediaType mediaType =  
> MediaType.valueOf(mediaTypeName);
> +                getVariants().add(new Variant(mediaType));
> +            }
> +        } catch (ComponentLookupException e) {
> +            throw new RuntimeException(e);
> +        }

The ideal way would be for PageResource to be a component. You could  
then have a component map directly injected in PageResource using  
Plexus and you wouldn't need to use the xwiki-core dep on web.Utils  
which we need to get rif of.

-Vincent




_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to