001package org.nuxeo.ecm.webengine.samples; 002 003import javax.ws.rs.DELETE; 004import javax.ws.rs.GET; 005import javax.ws.rs.PUT; 006import javax.ws.rs.PathParam; 007import javax.ws.rs.Produces; 008 009import org.nuxeo.ecm.webengine.model.WebObject; 010import org.nuxeo.ecm.webengine.model.impl.DefaultObject; 011 012/** 013 * User object. You can see the @WebObject annotation that is defining a WebObject of type "User" 014 * 015 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 016 */ 017@WebObject(type = "User") 018@Produces("text/html;charset=UTF-8") 019public class UserObject extends DefaultObject { 020 021 String displayName; 022 023 /** 024 * Initialize the object. args values are the one passed to the method newObject(String type, Object ... args) 025 */ 026 protected void initialize(Object... args) { 027 displayName = (String) args[0]; 028 } 029 030 /** 031 * Getter the variable displayName. Would be accessible from views with ${This.displayName} 032 */ 033 public String getDisplayName() { 034 return displayName; 035 } 036 037 /** 038 * Get the index view of the User object. The view file is located in {@code skin/views/User} so that it can be 039 * easily extended by a derived module. See extensibility sample. 040 */ 041 @GET 042 public Object doGet() { 043 return getView("index"); 044 } 045 046 /** 047 * This method is not implemented but demonstrates how DELETE requests can be used 048 */ 049 @DELETE 050 public Object doRemove(@PathParam("name") String name) { 051 // TODO ... remove user here ... 052 // redirect to the UserManager (the previous object in the request chain) 053 return redirect(getPrevious().getPath()); 054 } 055 056 /** 057 * This method is not implemented but demonstrates how PUT requests can be used 058 */ 059 @PUT 060 public Object doPut(@PathParam("name") String name) { 061 // TODO ... update user here ... 062 // redirect to myself 063 return redirect(getPath()); 064 } 065 066}