Author: kcardineaud Date: 2011-07-07 11:25:04 +0200 (Thu, 07 Jul 2011) New Revision: 163 Url: http://nuiton.org/repositories/revision/scmwebeditor/163 Log: Add a method to checkout a file with a SvnSession 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/resources/struts.xml Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-07-06 15:58:11 UTC (rev 162) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-07-07 09:25:04 UTC (rev 163) @@ -34,6 +34,10 @@ import org.apache.tika.metadata.Metadata; import org.apache.tika.parser.AutoDetectParser; import org.apache.tika.sax.BodyContentHandler; +import org.tmatesoft.svn.core.SVNDepth; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.wc.SVNRevision; +import org.tmatesoft.svn.core.wc.SVNUpdateClient; import org.xml.sax.SAXException; import com.opensymphony.xwork2.ActionSupport; @@ -180,6 +184,20 @@ } } + + public void checkout(SvnSession svnSess) throws SVNException { + + SVNUpdateClient upclient = new SVNUpdateClient(svnSess.getManager(), svnSess.getSvnOption()); + + if (log.isDebugEnabled()) { + log.debug("Do Checkout of " + svnSess.getRemoteUrl()); + } + upclient.doCheckout(svnSess.getRemoteUrl(), svnSess.getCheckoutdir(), + SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); + + } + + public void delTempDirectory(SvnSession svnSess) { try { FileUtils.deleteDirectory(svnSess.getCheckoutdir()); @@ -205,12 +223,7 @@ return tmp_dir; } -/* - protected void redirect(HttpServletRequest request, HttpServletResponse response, String path) throws IOException, ServletException { - RequestDispatcher requestDispacher = getServletContext().getRequestDispatcher(path); - requestDispacher.forward(request, response); - } -*/ + protected String getRedirectUrl(SvnSession svnSess) { StringBuilder buffer = new StringBuilder(); buffer.append(svnSess.getScmEditorUrl()); Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-07-06 15:58:11 UTC (rev 162) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-07-07 09:25:04 UTC (rev 163) @@ -18,11 +18,12 @@ 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; +import com.opensymphony.xwork2.Action; + + public class ScmWebEditorCommitAction extends ScmWebEditorBaseAction implements ServletRequestAware { /** * @@ -110,41 +111,34 @@ 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); + checkout(svnSess); } 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"; - + 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 Action.LOGIN; + } catch (SVNException e) { - //Suppression du repertoire temporaire - delTempDirectory(svnSess); - return "error"; + //Suppression du repertoire temporaire + delTempDirectory(svnSess); + return "errorPath"; } + + + File checkOutFile = new File(svnSess.getCheckoutdir(), svnSess.getFileName()); + + lastText=newText; - File CheckOutFile = new File(svnSess.getCheckoutdir(), svnSess.getFileName()); try { - String originalText = FileUtils.readFileToString(CheckOutFile); + String originalText = FileUtils.readFileToString(checkOutFile); request.setAttribute(PARAMETER_FORMAT, svnSess.getFormat()); request.setAttribute("lastText", lastText); request.setAttribute(ATTRIBUTE_ORIG_TEXT, StringEscapeUtils.escapeHtml(originalText)); @@ -223,7 +217,7 @@ request.setAttribute(ATTRIBUTE_BAD_LOGIN, true); //Suppression du repertoire temporaire delTempDirectory(svnSess); - return "authError"; + return Action.LOGIN; } catch (SVNException e) { if(log.isErrorEnabled()) { log.error("SVN FAIL",e); Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-07-06 15:58:11 UTC (rev 162) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-07-07 09:25:04 UTC (rev 163) @@ -15,11 +15,8 @@ import org.nuiton.scmwebeditor.ScmWebEditorBaseAction; 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.internal.io.dav.DAVRepositoryFactory; -import org.tmatesoft.svn.core.wc.SVNRevision; -import org.tmatesoft.svn.core.wc.SVNUpdateClient; import com.opensymphony.xwork2.Action; @@ -34,11 +31,9 @@ protected String projectUrl; protected String format; - protected String username; protected String pw; - - + protected HttpServletRequest request; @@ -165,17 +160,11 @@ DAVRepositoryFactory.setup(); - SVNUpdateClient upclient = new SVNUpdateClient(svnSess.getManager(), svnSess.getSvnOption()); + - - // Checkout svn and file organisation try { - if (log.isDebugEnabled()) { - log.debug("Do Checkout of " + svnSess.getRemoteUrl()); - } - upclient.doCheckout(svnSess.getRemoteUrl(), svnSess.getCheckoutdir(), - SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); + checkout(svnSess); } catch (SVNAuthenticationException authexep) { request.setAttribute(PARAMETER_ADDRESS, address); Modified: trunk/src/main/resources/struts.xml =================================================================== --- trunk/src/main/resources/struts.xml 2011-07-06 15:58:11 UTC (rev 162) +++ trunk/src/main/resources/struts.xml 2011-07-07 09:25:04 UTC (rev 163) @@ -17,8 +17,9 @@ <action name="commit" class="org.nuiton.scmwebeditor.actions.ScmWebEditorCommitAction" method="execute"> <result name="success" >/Redirect.jsp</result> - <result name="authError" >/ModificationViewer.jsp</result> + <result name="login" >/ModificationViewer.jsp</result> <result name="error">/BadFileRedirect.jsp</result> + <result name="errorPath">/BadFileRedirect.jsp</result> </action> <action name="save" class="org.nuiton.scmwebeditor.actions.SaveAction" method="save">