001package org.nuxeo.ecm.webengine.samples;
002
003import javax.ws.rs.GET;
004import javax.ws.rs.Path;
005import javax.ws.rs.PathParam;
006import javax.ws.rs.Produces;
007import javax.ws.rs.QueryParam;
008
009import org.nuxeo.ecm.webengine.model.WebObject;
010import org.nuxeo.ecm.webengine.model.impl.DefaultObject;
011
012/**
013 * UserManager object. You can see the @WebObject annotation that defines a WebObject of type "UserManager"
014 *
015 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
016 */
017@WebObject(type = "UserManager")
018@Produces("text/html;charset=UTF-8")
019public class UserManagerObject extends DefaultObject {
020
021    /**
022     * Get the index view. The view file name is computed as follows: index[-media_type_id].ftl First the
023     * skin/views/UserManager is searched for that file then the current directory. (The type of a module is the same as
024     * its name)
025     */
026    @GET
027    public Object doGet() {
028        return getView("index");
029    }
030
031    /**
032     * A hack to accept users as user?name=xxx query parameters
033     */
034    @GET
035    @Path("user")
036    public Object getUserByQueryString(@QueryParam("name") String name) {
037        if (name == null) {
038            return doGet();
039        } else {
040            return redirect(getPath() + "/user/" + name);
041        }
042    }
043
044    /**
045     * Get the user JAX-RS resource given the user name
046     */
047    @Path("user/{name}")
048    public Object getUser(@PathParam("name") String name) {
049        // create a new instance of a WebObject which type is "User" and push this object on the request chain
050        // the User object is initialized with the String "Username: name"
051        return newObject("User", "Username: " + name);
052    }
053
054}