Index: lams_central/src/java/org/lamsfoundation/lams/web/PortraitSaveAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/PortraitSaveAction.java,v diff -u -r1.9 -r1.10 --- lams_central/src/java/org/lamsfoundation/lams/web/PortraitSaveAction.java 10 Nov 2008 13:59:14 -0000 1.9 +++ lams_central/src/java/org/lamsfoundation/lams/web/PortraitSaveAction.java 11 Apr 2011 12:36:26 -0000 1.10 @@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -41,30 +42,39 @@ import org.lamsfoundation.lams.contentrepository.NodeKey; import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.exception.UserAccessDeniedException; import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.CentralToolContentHandler; +import org.lamsfoundation.lams.util.FileUtilException; +import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.PortraitUtils; +import org.lamsfoundation.lams.web.action.LamsDispatchAction; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; /** * @author jliew * @author Andrey Balan * - * @struts:action path="/saveportrait" name="PortraitActionForm" input=".portrait" scope="request" validate="false" + * @struts:action path="/saveportrait" parameter="method" name="PortraitActionForm" input=".portrait" scope="request" validate="false" * * @struts:action-forward name="profile" path="/index.do?state=active&tab=profile" * @struts:action-forward name="errors" path="/index.do?state=active&tab=portrait" */ -public class PortraitSaveAction extends Action { +public class PortraitSaveAction extends LamsDispatchAction { private static Logger log = Logger.getLogger(PortraitSaveAction.class); private static IUserManagementService service; private static CentralToolContentHandler centralToolContentHandler; private static int LARGEST_DIMENSION = 120; - @Override - public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, + /** + * Upload portrait image. + */ + public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (isCancelled(request)) { @@ -73,11 +83,6 @@ ActionMessages errors = new ActionMessages(); - WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() - .getServletContext()); - PortraitSaveAction.centralToolContentHandler = (CentralToolContentHandler) wac - .getBean("centralToolContentHandler"); - PortraitActionForm portraitForm = (PortraitActionForm) form; FormFile file = portraitForm.getFile(); String fileName = file.getFileName(); @@ -107,7 +112,7 @@ if ((file != null) && !StringUtils.isEmpty(fileName)) { try { fileName = fileName.substring(0, fileName.indexOf('.')) + ".jpg"; - node = PortraitSaveAction.centralToolContentHandler.uploadFile(is, fileName, file.getContentType(), + node = getCentralToolContentHandler().uploadFile(is, fileName, file.getContentType(), IToolContentHandler.TYPE_ONLINE); is.close(); } catch (Exception e) { @@ -120,21 +125,74 @@ // delete old portrait file (we only want to keep the user's current portrait) if (user.getPortraitUuid() != null) { - PortraitSaveAction.centralToolContentHandler.deleteFile(user.getPortraitUuid()); + getCentralToolContentHandler().deleteFile(user.getPortraitUuid()); } user.setPortraitUuid(node.getUuid()); getService().save(user); return mapping.findForward("profile"); } + + + /** + * Save portrait taken from web camera. + */ + public ActionForward saveWebcamPortrait(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + // check if there is a session with logged in user + HttpSession ss = SessionManager.getSession(); + UserDTO userDTO = (UserDTO) ss.getAttribute(AttributeNames.USER); + User user = getService().getUserByLogin(request.getRemoteUser()); + if ((userDTO == null) || (user == null)) { + throw new UserAccessDeniedException("User hasn't been logged in"); + } + + // check if the file is an image using the MIME content type + String mediaType = request.getContentType().split("/", 2)[0]; + if (!mediaType.equals("image")) { + throw new FileUtilException("The file is not an image."); + } + + // check if there is an input stream + InputStream is = request.getInputStream(); + if (is == null) { + throw new FileUtilException("Sorry, there has been an error."); + } + + // write to content repository + String fileName = user.getFullName() + " portrait.jpg"; + NodeKey node = getCentralToolContentHandler().uploadFile(is, fileName, "image/jpeg", IToolContentHandler.TYPE_ONLINE); + is.close(); + + log.debug("saved file with uuid: " + node.getUuid() + " and version: " + node.getVersion()); + + // delete old portrait file (we only want to keep the user's current portrait) + if (user.getPortraitUuid() != null) { + getCentralToolContentHandler().deleteFile(user.getPortraitUuid()); + } + user.setPortraitUuid(node.getUuid()); + getService().save(user); + + return null; + } + + private CentralToolContentHandler getCentralToolContentHandler() { + if (centralToolContentHandler == null) { + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() + .getServletContext()); + centralToolContentHandler = (CentralToolContentHandler) wac.getBean("centralToolContentHandler"); + } + return centralToolContentHandler; + } + private IUserManagementService getService() { if (PortraitSaveAction.service == null) { WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() .getServletContext()); PortraitSaveAction.service = (IUserManagementService) ctx.getBean("userManagementService"); } - return PortraitSaveAction.service; + return service; } } Index: lams_central/web/portrait.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/portrait.jsp,v diff -u -r1.6 -r1.7 --- lams_central/web/portrait.jsp 28 Jan 2009 00:12:15 -0000 1.6 +++ lams_central/web/portrait.jsp 11 Apr 2011 12:36:26 -0000 1.7 @@ -5,54 +5,165 @@ <%@ taglib uri="tags-core" prefix="c"%> <%@ taglib uri="tags-lams" prefix="lams"%> - - + + + + + + + + +
-

+

+ +

-
-

-
+
+ +

+
- - + + + + + + + + + - - - - - +
: - &preferDownload=false" /> - - - - - + + : + + + &preferDownload=false" /> + -
:
  + + - - - - +
+

+
+
+ + +
+ + +
+ +
+ +

+
+ +

+ + + +

+ +

+
+
-

+ Fisheye: Tag 1.1 refers to a dead (removed) revision in file `lams_central/web/css/jquery-ui-1.8.11.redmont-theme.css'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-bg_flat_0_aaaaaa_40x100.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-bg_flat_0_aaaaaa_40x100.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-bg_flat_55_fbec88_40x100.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-bg_flat_55_fbec88_40x100.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-bg_glass_75_d0e5f5_1x400.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-bg_glass_75_d0e5f5_1x400.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-bg_glass_85_dfeffc_1x400.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-bg_glass_85_dfeffc_1x400.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-bg_glass_95_fef1ec_1x400.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-bg_glass_95_fef1ec_1x400.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-bg_gloss-wave_55_5c9ccc_500x100.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-bg_gloss-wave_55_5c9ccc_500x100.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-bg_inset-hard_100_f5f8f9_1x100.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-bg_inset-hard_100_f5f8f9_1x100.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-bg_inset-hard_100_fcfdfd_1x100.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-bg_inset-hard_100_fcfdfd_1x100.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-icons_217bc0_256x240.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-icons_217bc0_256x240.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-icons_2e83ff_256x240.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-icons_2e83ff_256x240.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-icons_469bdd_256x240.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-icons_469bdd_256x240.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-icons_6da8d5_256x240.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-icons_6da8d5_256x240.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-icons_cd0a0a_256x240.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-icons_cd0a0a_256x240.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-icons_d8e7f3_256x240.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-icons_d8e7f3_256x240.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/images/css/jquery-ui.redmond-theme/ui-icons_f9bd01_256x240.png =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/images/css/jquery-ui.redmond-theme/Attic/ui-icons_f9bd01_256x240.png,v diff -u -r1.1 -r1.2 Binary files differ Index: lams_central/web/includes/flash/webcam.swf =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/includes/flash/webcam.swf,v diff -u -r1.1 -r1.2 Binary files differ Fisheye: Tag 1.1 refers to a dead (removed) revision in file `lams_central/web/includes/javascript/jquery-ui-1.8.11.custom.min.js'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.1 refers to a dead (removed) revision in file `lams_central/web/includes/javascript/jquery.blockUI.js'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.1 refers to a dead (removed) revision in file `lams_central/web/includes/javascript/webcam.js'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/web/includes/sounds/shutter.mp3 =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/includes/sounds/shutter.mp3,v diff -u -r1.1 -r1.2 Binary files differ