Author: kcardineaud Date: 2011-06-24 10:07:02 +0200 (Fri, 24 Jun 2011) New Revision: 134 Url: http://nuiton.org/repositories/revision/scmwebeditor/134 Log: ScmWebEditor delete the checkout temp dir after each action Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java trunk/src/main/webapp/ModificationViewer.jsp trunk/src/main/webapp/OutConnection.jsp Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-06-23 14:15:20 UTC (rev 133) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-06-24 08:07:02 UTC (rev 134) @@ -210,7 +210,7 @@ StringBuilder buffer = new StringBuilder(); buffer.append(svnSess.getScmEditorUrl()); buffer.append('?').append(PARAMETER_ADDRESS).append('=').append(svnSess.getSvnPath()+svnSess.getFileName()); - buffer.append("&").append(PARAMETER_PROJECT_URL).append('=').append(svnSess.getProjectUrl()); + String url = buffer.toString(); return url; Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-23 14:15:20 UTC (rev 133) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-24 08:07:02 UTC (rev 134) @@ -1,6 +1,7 @@ package org.nuiton.scmwebeditor.actions; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import javax.servlet.http.HttpServletRequest; @@ -17,7 +18,11 @@ import org.tmatesoft.svn.core.SVNDepth; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.wc.SVNCommitClient; +import org.tmatesoft.svn.core.wc.SVNRevision; +import org.tmatesoft.svn.core.wc.SVNUpdateClient; + + public class ScmWebEditorCommitAction extends ScmWebEditorBaseAction implements ServletRequestAware { /** * @@ -31,6 +36,8 @@ protected String origText; protected String username; protected String pw; + protected String address; + protected String lastText; protected HttpServletRequest request; @@ -43,7 +50,6 @@ this.commitMessage = commitMessage; } - public String getNewText() { return newText; } @@ -75,7 +81,24 @@ public void setPw(String pw) { this.pw = pw; } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + public String getLastText() { + return lastText; + } + + public void setLastText(String lastText) { + this.lastText = lastText; + } + + public String execute() { System.setProperty("file.encoding", "UTF-8"); HttpSession httpSession = request.getSession(true); @@ -86,6 +109,75 @@ svnSess.getLogin() != null && !svnSess.getLogin().equalsIgnoreCase("") ? svnSess.getLogin() : username, svnSess.getPassword() != null && !svnSess.getPassword().equalsIgnoreCase("") ? svnSess.getPassword() : pw); + + + /* + * Checkout process + */ + SVNUpdateClient upclient = new SVNUpdateClient(svnSess.getManager(), svnSess.getSvnOption()); + + + try { + if (log.isDebugEnabled()) { + log.debug("Do Checkout of " + svnSess.getRemoteUrl()); + } + upclient.doCheckout(svnSess.getRemoteUrl(), svnSess.getCheckoutdir(), + SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); + } catch (SVNAuthenticationException authexep) { + request.setAttribute(PARAMETER_ADDRESS, address); + + // if svn authentication failed user is redirected on login page + if(log.isDebugEnabled()) { + log.debug("Private SCM on reading " + svnSess.getRemoteUrl()); + } + //On supprime le repertoire temporaire + delTempDirectory(svnSess); + //redirect to a login page + return "authError"; + + } catch (SVNException e) { + //Suppression du repertoire temporaire + delTempDirectory(svnSess); + return "error"; + } + lastText=newText; + + File CheckOutFile = new File(svnSess.getCheckoutdir(), svnSess.getFileName()); + try { + String originalText = FileUtils.readFileToString(CheckOutFile); + request.setAttribute(PARAMETER_FORMAT, svnSess.getFormat()); + request.setAttribute("lastText", lastText); + request.setAttribute(ATTRIBUTE_ORIG_TEXT, StringEscapeUtils.escapeHtml(originalText)); + request.setAttribute(ATTRIBUTE_INVALIDATE_MAX_TIME, (httpSession.getMaxInactiveInterval() / 60)); + request.setAttribute(ATTRIBUTE_LOGIN, (svnSess.getLogin() != null && !svnSess.getLogin().equalsIgnoreCase("") ? svnSess.getLogin() : null)); + request.setAttribute(ATTRIBUTE_IS_LOGIN, (svnSess.getLogin() != null && svnSess.getPassword() != null && !svnSess.getLogin().equalsIgnoreCase("") && !svnSess.getPassword().equalsIgnoreCase(""))); + request.setAttribute(ATTRIBUTE_PROJECT_URL, svnSess.getProjectUrl()); + request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getScmEditorUrl()); + if (log.isDebugEnabled()) { + log.debug("l'url est : " + svnSess.getScmEditorUrl()); + } + request.setAttribute(ATTRIBUTE_SCM_EDITOR_URI, request.getRequestURI()); + request.setAttribute(ATTRIBUTE_PREVIEW_SERVLET_URL, request.getContextPath() + "/previewservlet"); + + // End on first part + + } catch (FileNotFoundException ee) { + /* fichier non trouve, on redirige vers BadFileRedirect.jsp + * après avoir supprimé le repertoire temporaire + */ + delTempDirectory(svnSess); + request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getProjectUrl()); + return "error"; + } catch (IOException e) { + log.error("Can't find the checkout file",e); + } + + + + /* + * Commit process + */ + String originalText = StringEscapeUtils.unescapeHtml(origText); String myText = StringEscapeUtils.unescapeHtml(newText); @@ -98,7 +190,7 @@ if(log.isErrorEnabled()) { log.error("Can't write in file " , e); } - return "ko"; + return "erreur"; } @@ -108,45 +200,48 @@ tabFile[0] = pathToFile; // Sending Data to SVN - if (!myText.equals(originalText)) { - try { - if(log.isDebugEnabled()) { - log.debug("Try to commit"); - } - commitClient.doCommit(tabFile, false, "From scmwebeditor -- "+commitMessage, null, null, false, true, SVNDepth.FILES); - } catch (SVNAuthenticationException authexep) { - if(log.isErrorEnabled()) { - log.error("AUTH FAIL",authexep); - } - svnSess.setLogin(null); - svnSess.setPassword(null); - // if authentication failed edition page is reload form user's relogin - request.setAttribute(PARAMETER_FORMAT, svnSess.getFormat()); - request.setAttribute(ATTRIBUTE_ORIG_TEXT, StringEscapeUtils.escapeHtml(newText)); - request.setAttribute(ATTRIBUTE_INVALIDATE_MAX_TIME, (httpSession.getMaxInactiveInterval() / 60)); - request.setAttribute(ATTRIBUTE_LOGIN, (svnSess.getLogin() != null && !svnSess.getLogin().equalsIgnoreCase("") ? svnSess.getLogin() : null)); - request.setAttribute(ATTRIBUTE_IS_LOGIN, false); - request.setAttribute(ATTRIBUTE_PROJECT_URL, svnSess.getProjectUrl()); - request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getScmEditorUrl()); - request.setAttribute(ATTRIBUTE_SCM_EDITOR_URI, request.getRequestURI()); - request.setAttribute(ATTRIBUTE_PREVIEW_SERVLET_URL, request.getContextPath() + "/previewservlet"); - - request.setAttribute(ATTRIBUTE_BAD_LOGIN, true); - return "authError"; - } catch (SVNException e) { - if(log.isErrorEnabled()) { - log.error("SVN FAIL",e); - } - //Suppression du repertoire temporaire - //delTempDirectory(svnSess); - request.setAttribute(ATTRIBUTE_REDIRECT_URL, getRedirectUrl(svnSess)); - return "erreur"; + + try { + if(log.isDebugEnabled()) { + log.debug("Try to commit"); } + commitClient.doCommit(tabFile, false, "From scmwebeditor -- "+commitMessage, null, null, false, true, SVNDepth.FILES); + } catch (SVNAuthenticationException authexep) { + if(log.isErrorEnabled()) { + log.error("AUTH FAIL"); + } + svnSess.setLogin(null); + svnSess.setPassword(null); + // if authentication failed edition page is reload form user's relogin + request.setAttribute("address", address); + request.setAttribute(PARAMETER_FORMAT, svnSess.getFormat()); + request.setAttribute(ATTRIBUTE_ORIG_TEXT, StringEscapeUtils.escapeHtml(newText)); + request.setAttribute(ATTRIBUTE_INVALIDATE_MAX_TIME, (httpSession.getMaxInactiveInterval() / 60)); + request.setAttribute(ATTRIBUTE_LOGIN, (svnSess.getLogin() != null && !svnSess.getLogin().equalsIgnoreCase("") ? svnSess.getLogin() : null)); + request.setAttribute(ATTRIBUTE_IS_LOGIN, false); + request.setAttribute(ATTRIBUTE_PROJECT_URL, svnSess.getProjectUrl()); + request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getScmEditorUrl()); + request.setAttribute(ATTRIBUTE_SCM_EDITOR_URI, request.getRequestURI()); + request.setAttribute(ATTRIBUTE_PREVIEW_SERVLET_URL, request.getContextPath() + "/previewservlet"); + + request.setAttribute(ATTRIBUTE_BAD_LOGIN, true); + //Suppression du repertoire temporaire + delTempDirectory(svnSess); + return "authError"; + } catch (SVNException e) { + if(log.isErrorEnabled()) { + log.error("SVN FAIL",e); + } + //Suppression du repertoire temporaire + delTempDirectory(svnSess); + request.setAttribute(ATTRIBUTE_REDIRECT_URL, getRedirectUrl(svnSess)); + return "erreur"; } + if (svnSess.getCheckoutdir() != null) { //Suppression du repertoire temporaire - //delTempDirectory(svnSess); + delTempDirectory(svnSess); } //if commit success user is redirect on the project page request.setAttribute(ATTRIBUTE_REDIRECTION_URL, svnSess.getProjectUrl()); @@ -155,7 +250,7 @@ log.debug("End of commit"); } //Suppression du repertoire temporaire - //delTempDirectory(svnSess); + delTempDirectory(svnSess); return "success"; } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-23 14:15:20 UTC (rev 133) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-24 08:07:02 UTC (rev 134) @@ -21,6 +21,8 @@ import org.tmatesoft.svn.core.wc.SVNRevision; import org.tmatesoft.svn.core.wc.SVNUpdateClient; +import com.opensymphony.xwork2.Action; + public class ScmWebEditorMainAction extends ScmWebEditorBaseAction implements ServletRequestAware { /** @@ -178,9 +180,10 @@ if(log.isDebugEnabled()) { log.debug("Private SCM on reading " + svnSess.getRemoteUrl()); } - + //On supprime le repertoire temporaire + delTempDirectory(svnSess); //redirect to a login page - return "login"; + return Action.LOGIN; } catch (SVNException e) { //Suppression du repertoire temporaire @@ -218,6 +221,8 @@ log.error("Can't find the checkout file",e); } + //On supprime le repertoire temporaire + delTempDirectory(svnSess); return "editPage"; Modified: trunk/src/main/webapp/ModificationViewer.jsp =================================================================== --- trunk/src/main/webapp/ModificationViewer.jsp 2011-06-23 14:15:20 UTC (rev 133) +++ trunk/src/main/webapp/ModificationViewer.jsp 2011-06-24 08:07:02 UTC (rev 134) @@ -21,7 +21,11 @@ <center> <form method="post" action=commit.action id="editForm"> <script src="GereFormSize.js" type="text/javascript"></script> - <textarea name="newText" id="newText"><%=request.getAttribute("OrigText")%></textarea> + <% if(request.getAttribute("lastText")!=null) { %> + <textarea name="newText" id="newText"><%=request.getAttribute("lastText")%></textarea> + <% } else { %> + <textarea name="newText" id="newText"><%=request.getAttribute("OrigText")%></textarea> + <% } %> <script src="GereSession.js" type="text/javascript"></script> <script src="cancelRedirectDelete.js" type="text/javascript"></script> <script src="pictureUpload.js" type="text/javascript"></script> @@ -50,10 +54,13 @@ <input type="hidden" NAME=username /> <input type="hidden" NAME=pw /><% }%> + <input type="hidden" name="address" value="<%=request.getAttribute("address")%>"/> <input type="hidden" name="origText" value="<%=request.getAttribute("OrigText")%>"/> + <% if(request.getAttribute("lastText")!=null) { %> + <input type="hidden" name="lastText" value="<%=request.getAttribute("lastText")%>" /> + <% } %> <input type="hidden" name="scmEditorUrl" value="<%=request.getAttribute("scmEditorUrl")%>"/> - <input type="hidden" name="previewServletUrl" value="<%=request.getAttribute("previewServletUrl")%>"/> - + <s:url id="ajaxCommit" value="save.action" /> <sj:submit Modified: trunk/src/main/webapp/OutConnection.jsp =================================================================== --- trunk/src/main/webapp/OutConnection.jsp 2011-06-23 14:15:20 UTC (rev 133) +++ trunk/src/main/webapp/OutConnection.jsp 2011-06-24 08:07:02 UTC (rev 134) @@ -45,10 +45,6 @@ <input type="submit" name="Save" /> </p> - - - - <div id="htmlcontentSearch" ></div> </form> </center>