001/*
002 * (C) Copyright 2006 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Bogdan Stefanescu
018 */
019package org.nuxeo.ecm.webengine.samples;
020
021import javax.ws.rs.DELETE;
022import javax.ws.rs.GET;
023import javax.ws.rs.PUT;
024import javax.ws.rs.PathParam;
025import javax.ws.rs.Produces;
026
027import org.nuxeo.ecm.webengine.model.WebObject;
028import org.nuxeo.ecm.webengine.model.impl.DefaultObject;
029
030/**
031 * User object. You can see the @WebObject annotation that is defining a WebObject of type "User"
032 *
033 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
034 */
035@WebObject(type = "User")
036@Produces("text/html;charset=UTF-8")
037public class UserObject extends DefaultObject {
038
039    String displayName;
040
041    /**
042     * Initialize the object. args values are the one passed to the method newObject(String type, Object ... args)
043     */
044    protected void initialize(Object... args) {
045        displayName = (String) args[0];
046    }
047
048    /**
049     * Getter the variable displayName. Would be accessible from views with ${This.displayName}
050     */
051    public String getDisplayName() {
052        return displayName;
053    }
054
055    /**
056     * Get the index view of the User object. The view file is located in {@code skin/views/User} so that it can be
057     * easily extended by a derived module. See extensibility sample.
058     */
059    @GET
060    public Object doGet() {
061        return getView("index");
062    }
063
064    /**
065     * This method is not implemented but demonstrates how DELETE requests can be used
066     */
067    @DELETE
068    public Object doRemove(@PathParam("name") String name) {
069        // TODO ... remove user here ...
070        // redirect to the UserManager (the previous object in the request chain)
071        return redirect(getPrevious().getPath());
072    }
073
074    /**
075     * This method is not implemented but demonstrates how PUT requests can be used
076     */
077    @PUT
078    public Object doPut(@PathParam("name") String name) {
079        // TODO ... update user here ...
080        // redirect to myself
081        return redirect(getPath());
082    }
083
084}