r123 - in trunk/src/main: java/org/nuiton/scmwebeditor java/org/nuiton/scmwebeditor/actions resources webapp
Author: kcardineaud Date: 2011-06-17 14:56:21 +0200 (Fri, 17 Jun 2011) New Revision: 123 Url: http://nuiton.org/repositories/revision/scmwebeditor/123 Log: File commit is now in struts Added: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java Modified: trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java trunk/src/main/resources/struts.xml trunk/src/main/webapp/ModificationViewer.jsp trunk/src/main/webapp/OutConnection.jsp trunk/src/main/webapp/fileSearch.js trunk/src/main/webapp/index.jsp Modified: trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java 2011-06-17 07:43:45 UTC (rev 122) +++ trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java 2011-06-17 12:56:21 UTC (rev 123) @@ -118,7 +118,7 @@ this.login = login; this.password = password; try { - this.checkoutdir = FileUtil.createTempDirectory("", ""); + this.checkoutdir = FileUtil.createTempDirectory("scm_", ""); } catch (IOException e) { e.printStackTrace(); } Added: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java (rev 0) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-17 12:56:21 UTC (rev 123) @@ -0,0 +1,154 @@ +package org.nuiton.scmwebeditor.actions; + +import java.io.File; +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts2.interceptor.ServletRequestAware; +import org.nuiton.scmwebeditor.AbstractScmWebEditor; +import org.nuiton.scmwebeditor.SvnSession; +import org.tmatesoft.svn.core.SVNAuthenticationException; +import org.tmatesoft.svn.core.SVNDepth; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.wc.SVNCommitClient; + +public class ScmWebEditorCommitAction extends AbstractScmWebEditor implements ServletRequestAware { + private static final Log log = LogFactory.getLog(ScmWebEditorCommitAction.class); + + protected String newText; + protected String commitMessage; + protected String origText; + protected String username; + protected String pw; + + + protected HttpServletRequest request; + + public String getCommitMessage() { + return commitMessage; + } + + public void setCommitMessage(String commitMessage) { + this.commitMessage = commitMessage; + } + + + public String getNewText() { + return newText; + } + + public void setNewText(String newText) { + this.newText = newText; + } + + public String getOrigText() { + return origText; + } + + public void setOrigText(String origText) { + this.origText = origText; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPw() { + return pw; + } + + public void setPw(String pw) { + this.pw = pw; + } + + public String execute() { + System.setProperty("file.encoding", "UTF-8"); + 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); + + String originalText = StringEscapeUtils.unescapeHtml(origText); + String myText = StringEscapeUtils.unescapeHtml(newText); + + File pathToFile = new File(svnSess.getCheckoutdir(), svnSess.getFileName()); + + SVNCommitClient commitClient = new SVNCommitClient(svnSess.getManager(), svnSess.getSvnOption()); + try { + FileUtils.writeStringToFile(pathToFile, newText); + } catch (IOException e) { + if(log.isErrorEnabled()) { + log.error("Can't write in file " , e); + } + return "ko"; + } + + + convertToUnicode(pathToFile); + + File[] tabFile = new File[1]; + 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); + } + // if authentication failed edition page is reload form user's relogin + request.setAttribute(ATTRIBUTE_REDIRECT_URL, getRedirectUrl(svnSess)); + return "ko"; + } catch (SVNException e) { + if(log.isErrorEnabled()) { + log.error("SVN FAIL",e); + } + request.setAttribute(ATTRIBUTE_REDIRECT_URL, getRedirectUrl(svnSess)); + return "ko"; + } + } + + if (svnSess.getCheckoutdir() != null) { + log.debug("Delete tempdir"); + try { + FileUtils.deleteDirectory(svnSess.getCheckoutdir()); + } catch (IOException e) { + if(log.isErrorEnabled()) { + log.error("Can't delete the temp dir",e); + } + } + } + //if commit success user is redirect on the project page + request.setAttribute(ATTRIBUTE_REDIRECTION_URL, svnSess.getProjectUrl()); + + if(log.isDebugEnabled()) { + log.debug("End of commit"); + } + return "ok"; + } + + + + @Override + public void setServletRequest(HttpServletRequest request) { + this.request = request; + } + +} Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-17 07:43:45 UTC (rev 122) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-17 12:56:21 UTC (rev 123) @@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; +import javax.swing.Action; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringEscapeUtils; @@ -18,7 +19,6 @@ import org.tmatesoft.svn.core.SVNDepth; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; -import org.tmatesoft.svn.core.wc.ISVNRepositoryPool; import org.tmatesoft.svn.core.wc.SVNRevision; import org.tmatesoft.svn.core.wc.SVNUpdateClient; @@ -95,21 +95,12 @@ //SvnSession object creation if doesn't already exist SvnSession svnSess = getSvnSession(httpSession); - String relativePath = address.substring(0,address.lastIndexOf("/")); - - log.debug("RELATIVEPATH : "+relativePath); - //String scmPath = address.endsWith(relativePath) ? "" : relativePath; - String scmFileName = address.substring(address.lastIndexOf("/")+1); - - log.debug("SCMFILENAME : "+scmFileName); format = scmFileName.substring(scmFileName.lastIndexOf(".")+1); - log.debug("FORMAT : "+scmFileName); - String tmp_log = null; String tmp_pass = null; if (svnSess != null) { @@ -147,21 +138,28 @@ SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); } catch (SVNAuthenticationException authexep) { // if svn authentication failed user is redirected on login page - log.debug("Private SCM on reading " + svnSess.getRemoteUrl()); + if(log.isDebugEnabled()) { + log.debug("Private SCM on reading " + svnSess.getRemoteUrl()); + } //Suppression du repertoire temporaire try { svnSess.cleanCheckoutDir(); } catch (IOException e) { - e.printStackTrace(); + if (log.isErrorEnabled()) { + log.error("Can't delete temp directory",e); + } } - - return "private"; + //redirect to a login page + return "login"; + } catch (SVNException e) { //Suppression du repertoire temporaire try { svnSess.cleanCheckoutDir(); } catch (IOException ee) { - e.printStackTrace(); + if(log.isErrorEnabled()) { + log.error("Can't delete temp directory"); + } } return "erreurPath"; } @@ -186,16 +184,20 @@ // End on first part } catch (FileNotFoundException ee) { - // fichier non trouve, on redirige vers BadFileRedirect.jsp + /* fichier non trouve, on redirige vers BadFileRedirect.jsp + * après avoir supprimé le repertoire temporaire + */ try { FileUtils.deleteDirectory(svnSess.getCheckoutdir()); } catch (IOException e) { - e.printStackTrace(); + if(log.isErrorEnabled()) { + log.error("Can't delete temp directory"); + } } request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getProjectUrl()); return "erreurPath"; } catch (IOException e) { - e.printStackTrace(); + log.error("Can't find the checkout file",e); } return "editPage"; Modified: trunk/src/main/resources/struts.xml =================================================================== --- trunk/src/main/resources/struts.xml 2011-06-17 07:43:45 UTC (rev 122) +++ trunk/src/main/resources/struts.xml 2011-06-17 12:56:21 UTC (rev 123) @@ -5,11 +5,15 @@ <struts> <package name="action" extends="struts-default"> - <action name="main" class="org.nuiton.scmwebeditor.actions.ScmWebEditorMainAction" method="execute"> + <action name="checkout" class="org.nuiton.scmwebeditor.actions.ScmWebEditorMainAction" method="execute"> <result name="noParameter" >/OutConnection.jsp</result> - <result name="private" >/PrivateSvnRedirect.jsp</result> + <result name="login" >/PrivateSvnRedirect.jsp</result> <result name="erreurPath" >/BadFileRedirect.jsp</result> <result name="editPage" >/ModificationViewer.jsp</result> </action> + <action name="commit" class="org.nuiton.scmwebeditor.actions.ScmWebEditorCommitAction" method="execute"> + <result name="ok" >/accueil.jsp</result> + <result name="ko">/BadFileRedirect.jsp</result> + </action> </package> </struts> \ No newline at end of file Modified: trunk/src/main/webapp/ModificationViewer.jsp =================================================================== --- trunk/src/main/webapp/ModificationViewer.jsp 2011-06-17 07:43:45 UTC (rev 122) +++ trunk/src/main/webapp/ModificationViewer.jsp 2011-06-17 12:56:21 UTC (rev 123) @@ -15,9 +15,10 @@ <center><h2>Welcome on SCMWebEditor</h2> <%if (request.getAttribute("format").equals("rst") == true){ %><h4>For any Problem with RestruturedText visit <a href="http://docutils.sourceforge.net/rst.html">RST documentation website</a>.</h4></center><%}%> - <center><form method="post" action=<%=request.getAttribute("scmEditorUri")%>> + <center> + <form method="post" action=commit.action> <script src="GereFormSize.js" type="text/javascript"></script> - <textarea name="Mytext" id="Mytext" rows="20" cols="150"><%=request.getAttribute("OrigText")%></textarea> + <textarea name="newText" id="newText" rows="20" cols="150"><%=request.getAttribute("OrigText")%></textarea> <script src="Preview.js" type="text/javascript"></script> <script src="Saver.js" type="text/javascript"></script> <script src="GereSession.js" type="text/javascript"></script> @@ -25,7 +26,7 @@ <script src="pictureUpload.js" type="text/javascript"></script> <noscript><h4>Javascript is not activated. You can't only use Save and Quit or Reset button.</h4></noscript> <noscript><h4>For a better use of SCMWebEditor please activate JavaScript.</h4></noscript> - <p>Commit Message: <input type="text" name="Commit_message" title="Let a commit message with this file."/></p> + <p>Commit Message: <input type="text" name="commitMessage" title="Let a commit message with this file."/></p> <%if (request.getAttribute("IsLogin").equals(false) == true){ %><p><label ACCESSKEY=U>User name: <input TYPE=text NAME=username SIZE=12 title="Commit Username."/></label> @@ -35,16 +36,16 @@ <input type="hidden" NAME=username /> <input type="hidden" NAME=pw /><% }%> - <input type="hidden" name="Orig_text" value=<%=request.getAttribute("OrigText")%>/> + <input type="hidden" name="origText" value=<%=request.getAttribute("OrigText")%>/> <input type="hidden" name="scmEditorUrl" value="<%=request.getAttribute("scmEditorUrl")%>"/> <input type="hidden" name="previewServletUrl" value="<%=request.getAttribute("previewServletUrl")%>"/> - <input title="Save your work and continue editing this file." type="button" value="Save and Continue Editing" name="SaveandC" onclick="javascript:saver(this.form.Mytext, this.form.username, this.form.pw, this.form.Commit_message, this.form.Orig_text, this.form.scmEditorUrl);"/> + <input title="Save your work and continue editing this file." type="button" value="Save and Continue Editing" name="SaveandC" onclick="javascript:saver(this.form.newText, this.form.username, this.form.pw, this.form.commitMessage, this.form.Orig_text, this.form.scmEditorUrl);"/> <input title="Save this file and go back to previous page." type="submit" value="Save and Quit" name="Save"/> <%if (request.getAttribute("format").equals("rst") == true){ - %><input title="html preview of the current rst file state." type="button" value="Preview" name="Preview" onclick="javascript:preview(this.form.Mytext, this.form.previewServletUrl);"/><%}%> + %><input title="html preview of the current rst file state." type="button" value="Preview" name="Preview" onclick="javascript:preview(this.form.newText, this.form.previewServletUrl);"/><%}%> <input title="Reset text as current repository HEAD revision." type="reset" value="Reset" name="Reset" alt="Test plop plop plop"/> <input type="hidden" value="<%=request.getAttribute("Project_url")%>" name="Project_url"> - <input title="Exit ScmWebEditor without saving." type="button" value="Exit" name="Cancel" onclick="javascript:cancelRedirectDelete(this.form.Orig_text, this.form.username, this.form.pw, this.form.Commit_message, this.form.Project_url, this.form.scmEditorUrl);"/> + <input title="Exit ScmWebEditor without saving." type="button" value="Exit" name="Cancel" onclick="javascript:cancelRedirectDelete(this.form.Orig_text, this.form.username, this.form.pw, this.form.commitMessage, this.form.Project_url, this.form.scmEditorUrl);"/> </form></center> <%--Title and div for rst preview--%> <h4 id="prevtitle" ></h4> Modified: trunk/src/main/webapp/OutConnection.jsp =================================================================== --- trunk/src/main/webapp/OutConnection.jsp 2011-06-17 07:43:45 UTC (rev 122) +++ trunk/src/main/webapp/OutConnection.jsp 2011-06-17 12:56:21 UTC (rev 123) @@ -21,8 +21,8 @@ </h4> </center> <center> -<form method="get" action="main.action"> - <p><label>SCM path: <input TYPE=text name="address" SIZE=100></label><input type="button" value="Search Files" name="search" onclick="javascript:fileSearch(this.form.address, this.form.searchServletUrl);"/></p> +<form method="get" action="checkout.action"> + <p><label>SCM path: <input TYPE=text name="address" SIZE=100></label><input disabled="disabled" type="button" value="Search Files" name="search" onclick="javascript:fileSearch(this.form.address, 'SearchServlet');"/></p> <input type="hidden" name="projectUrl" value="<%=request.getRequestURL()%>" /> Modified: trunk/src/main/webapp/fileSearch.js =================================================================== --- trunk/src/main/webapp/fileSearch.js 2011-06-17 07:43:45 UTC (rev 122) +++ trunk/src/main/webapp/fileSearch.js 2011-06-17 12:56:21 UTC (rev 123) @@ -24,7 +24,7 @@ function sendRequestToFileSearchServlet(scmPath, scmEditorUrl) { - http.open("POST", scmEditorUrl.value, true); + http.open("POST", scmEditorUrl, true); http.onreadystatechange = handleResponseFromFileSearchServlet; http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.send("adresse="+scmPath.value); @@ -42,6 +42,6 @@ function fileSearch(scmPath, scmEditorUrl) { alert(scmPath.value); - alert(scmEditorUrl.value); + alert(scmEditorUrl); sendRequestToFileSearchServlet(scmPath, scmEditorUrl); } Modified: trunk/src/main/webapp/index.jsp =================================================================== --- trunk/src/main/webapp/index.jsp 2011-06-17 07:43:45 UTC (rev 122) +++ trunk/src/main/webapp/index.jsp 2011-06-17 12:56:21 UTC (rev 123) @@ -1,3 +1,3 @@ <% -response.sendRedirect("main.action"); +response.sendRedirect("checkout.action"); %> \ No newline at end of file
participants (1)
-
kcardineaud@users.nuiton.org