Author: kcardineaud Date: 2011-07-01 17:27:37 +0200 (Fri, 01 Jul 2011) New Revision: 156 Url: http://nuiton.org/repositories/revision/scmwebeditor/156 Log: Use taglib to display upload result Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/SaveAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java trunk/src/main/resources/struts.xml trunk/src/main/webapp/Search.jsp trunk/src/main/webapp/upload.jsp trunk/src/main/webapp/uploadForm.jsp Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/SaveAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/SaveAction.java 2011-07-01 14:34:00 UTC (rev 155) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/SaveAction.java 2011-07-01 15:27:37 UTC (rev 156) @@ -1,7 +1,6 @@ package org.nuiton.scmwebeditor.actions; import java.util.Date; -import java.util.GregorianCalendar; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -55,7 +54,7 @@ result = execute(); date = new Date(); - log.info("Date : "+date.getTime()); + return Action.SUCCESS; } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java 2011-07-01 14:34:00 UTC (rev 155) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java 2011-07-01 15:27:37 UTC (rev 156) @@ -35,6 +35,9 @@ protected String username; protected String pw; protected String svnPath; + + protected boolean badLogin; + protected boolean error; protected HttpServletRequest request; @@ -76,28 +79,31 @@ this.pw = pw; } + public boolean isBadLogin() { + return badLogin; + } + public boolean isError() { + return error; + } public String execute() { + badLogin=false; + error=false; + if(log.isInfoEnabled()) { log.info("PictureName : "+uploadFileName); log.info("ContentType : "+uploadContentType); } - - - + HttpSession httpSession = request.getSession(true); SvnSession svnSess = getSvnSession(httpSession); - - // Resetting authentification information and manager - svnSess.updateAuthentication( - svnSess.getLogin() != null && !svnSess.getLogin().equalsIgnoreCase("") ? svnSess.getLogin() : username, - svnSess.getPassword() != null && !svnSess.getPassword().equalsIgnoreCase("") ? svnSess.getPassword() : pw); + svnSess.updateAuthentication(username,pw); /* @@ -121,20 +127,20 @@ //On supprime le repertoire temporaire delTempDirectory(svnSess); //redirect to a login page + error=true; return "error"; } catch (SVNException e) { //Suppression du repertoire temporaire delTempDirectory(svnSess); + error=true; return "error"; } File checkoutDir = svnSess.getCheckoutdir(); - - //On test si le chemin commence par un / si non, on l'ajoute if(!svnPath.startsWith("/")) { svnPath="/"+svnPath; @@ -153,7 +159,9 @@ try { FileUtils.copyFile(upload, file); } catch (IOException e) { + error=true; log.error("Can't copy the file to the checkout directory",e); + return "error"; } @@ -180,7 +188,7 @@ } catch (SVNException e) { log.error("Erreur SVN Add",e); - request.setAttribute("error", true); + error=true; //Suppression du repertoire temporaire delTempDirectory(svnSess); return Action.ERROR; @@ -200,14 +208,14 @@ } catch (SVNAuthenticationException authexep) { log.error("authentification fail"); - request.setAttribute(ATTRIBUTE_BAD_LOGIN, true); + badLogin=true; //Suppression du repertoire temporaire delTempDirectory(svnSess); return Action.LOGIN; } catch (SVNException e) { log.error("Erreur SVN commit",e); - request.setAttribute("error", true); + error=true; //Suppression du repertoire temporaire delTempDirectory(svnSess); return Action.ERROR; Modified: trunk/src/main/resources/struts.xml =================================================================== --- trunk/src/main/resources/struts.xml 2011-07-01 14:34:00 UTC (rev 155) +++ trunk/src/main/resources/struts.xml 2011-07-01 15:27:37 UTC (rev 156) @@ -22,19 +22,19 @@ <result>/Save.jsp</result> </action> - <action name="doUpload" class="org.nuiton.scmwebeditor.actions.UploadAction" method="execute"> + <action name="doUpload" class="org.nuiton.scmwebeditor.actions.UploadAction" > <result>/uploadSuccess.jsp</result> <result name="login" >/uploadForm.jsp</result> <result name="error" >/uploadForm.jsp</result> </action> - <action name="uploadFile" class="org.nuiton.scmwebeditor.actions.UploadAction" method="execute"> + <action name="uploadFile" class="org.nuiton.scmwebeditor.actions.UploadAction" > <result>/upload.jsp</result> <result name="login" >/upload.jsp</result> <result name="error" >/upload.jsp</result> </action> - <action name="preview" class="org.nuiton.scmwebeditor.actions.PreviewAction" method="execute"> + <action name="preview" class="org.nuiton.scmwebeditor.actions.PreviewAction" > <result>/Preview.jsp</result> </action> Modified: trunk/src/main/webapp/Search.jsp =================================================================== --- trunk/src/main/webapp/Search.jsp 2011-07-01 14:34:00 UTC (rev 155) +++ trunk/src/main/webapp/Search.jsp 2011-07-01 15:27:37 UTC (rev 156) @@ -8,14 +8,14 @@ <s:form action="search"> - <s:if test="!files.empty"> - <p>Files on the repository : </p> - <table> - <s:iterator value="files"> - <tr><td><a href="checkout.action?address=<s:property/>"><s:property/> <s:property value="level"/></a></td></tr> - </s:iterator> + <s:if test="!files.empty"> + <p>Files on the repository : </p> + <table> + <s:iterator value="files"> + <tr><td><a href="checkout.action?address=<s:property/>"><s:property/> <s:property value="level"/></a></td></tr> + </s:iterator> </table> - </s:if> + </s:if> <s:label name="error"></s:label> </s:form> Modified: trunk/src/main/webapp/upload.jsp =================================================================== --- trunk/src/main/webapp/upload.jsp 2011-07-01 14:34:00 UTC (rev 155) +++ trunk/src/main/webapp/upload.jsp 2011-07-01 15:27:37 UTC (rev 156) @@ -1,16 +1,14 @@ +<%@ taglib prefix="s" uri="/struts-tags"%> + <p>Result : </p> - <%if (request.getAttribute("badLogin")!=null && request.getAttribute("badLogin").equals(true)) { %> - <p> - <font color="red"> - Bad username or password - </font> - </p> - <% } else if (request.getAttribute("error")!=null && request.getAttribute("error").equals(true)) { %> - <p> - <font color="red"> - Erreur SVN - </font> - </p> - <% } else {%> - <p>File upload successful</p> - <% } %> \ No newline at end of file + + + <s:if test="badLogin"> + <p><font color="red">Bad username or password</font></p> + </s:if> + <s:elseif test="error"> + <p><font color="red">Erreur SVN</font></p> + </s:elseif> + <s:else> + <p>File upload successful</p> + </s:else> \ No newline at end of file Modified: trunk/src/main/webapp/uploadForm.jsp =================================================================== --- trunk/src/main/webapp/uploadForm.jsp 2011-07-01 14:34:00 UTC (rev 155) +++ trunk/src/main/webapp/uploadForm.jsp 2011-07-01 15:27:37 UTC (rev 156) @@ -1,5 +1,6 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> + <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> @@ -13,20 +14,13 @@ <label>Path on svn : <input type="text" name="svnPath" /></label><br/> <label>username : <input type="text" name="username" /></label><br/> <label>password : <input type="password" name="pw" /></label><br/> - <%if (request.getAttribute("badLogin")!=null && request.getAttribute("badLogin").equals(true)) { %> - <p> - <font color="red"> - Bad username or password - </font> - </p> - <% } %> - <%if (request.getAttribute("error")!=null && request.getAttribute("error").equals(true)) { %> - <p> - <font color="red"> - Erreur SVN - </font> - </p> - <% } %> + + <s:if test="badLogin"> + <p><font color="red">Bad username or password</font></p> + </s:if> + <s:elseif test="error"> + <p><font color="red">Erreur SVN</font></p> + </s:elseif> <input type="submit"/> </form>