r162 - in trunk/src/main: java/org/nuiton/scmwebeditor/actions resources
Author: kcardineaud Date: 2011-07-06 17:58:11 +0200 (Wed, 06 Jul 2011) New Revision: 162 Url: http://nuiton.org/repositories/revision/scmwebeditor/162 Log: ResetAction does not download the file anymore, but use stream (faster) Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ResetAction.java trunk/src/main/resources/struts.xml Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ResetAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ResetAction.java 2011-07-06 14:21:39 UTC (rev 161) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ResetAction.java 2011-07-06 15:58:11 UTC (rev 162) @@ -1,23 +1,22 @@ package org.nuiton.scmwebeditor.actions; -import java.io.File; -import java.io.IOException; +import java.io.ByteArrayOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.interceptor.ServletRequestAware; 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 org.tmatesoft.svn.core.SVNNodeKind; +import org.tmatesoft.svn.core.SVNURL; +import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; +import org.tmatesoft.svn.core.io.SVNRepository; +import org.tmatesoft.svn.core.io.SVNRepositoryFactory; +import org.tmatesoft.svn.core.wc.SVNWCUtil; import com.opensymphony.xwork2.Action; @@ -40,65 +39,67 @@ public String execute() { - try { HttpSession httpSession = request.getSession(true); SvnSession svnSess = getSvnSession(httpSession); - DAVRepositoryFactory.setup(); - SVNUpdateClient upclient = new SVNUpdateClient(svnSess.getManager(), svnSess.getSvnOption()); + String login = svnSess.getLogin(); + String pw = svnSess.getPassword(); + String url = svnSess.getSvnPath(); + String file = svnSess.getFileName(); -// 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); - } catch (SVNAuthenticationException authexep) { - - - // if svn authentication failed user is redirected on login page - - //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 "errorPath"; + if(login==null && pw==null) { + login = "anonymous"; + pw = "anonymous"; } + SVNRepository repository = null; + + try { + repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( url ) ); + ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( login , pw ); + repository.setAuthenticationManager( authManager ); - File checkOutFile = new File(svnSess.getCheckoutdir(), svnSess.getFileName()); + SVNNodeKind nodeKind = repository.checkPath( file , -1 ); + - try { - lastRevision = FileUtils.readFileToString(checkOutFile); - } catch (IOException e) { + if ( nodeKind == SVNNodeKind.NONE ) { if(log.isErrorEnabled()) { - log.error("Can't read this file",e); + log.error( "There is no entry at '" + url + "'." ); } + return Action.SUCCESS; + } else if ( nodeKind == SVNNodeKind.DIR ) { + if(log.isErrorEnabled()) { + log.error( "The entry at '" + url + "' is a file while a directory was expected." ); + } + return Action.SUCCESS; } + - //On supprime le repertoire temporaire - delTempDirectory(svnSess); + ByteArrayOutputStream baos = new ByteArrayOutputStream( ); + + repository.getFile( file , -1 , null , baos ); + + lastRevision=baos.toString(); + + } + catch (SVNException e) { + if(log.isErrorEnabled()) { + log.error("Can't reach the svn repository"); + return "errorPath"; + } + } if(log.isInfoEnabled()) { - log.info("Reset success !"); + } return Action.SUCCESS; - } - catch(Exception e) { - log.error("erreur", e); - return "erreur"; - } + } Modified: trunk/src/main/resources/struts.xml =================================================================== --- trunk/src/main/resources/struts.xml 2011-07-06 14:21:39 UTC (rev 161) +++ trunk/src/main/resources/struts.xml 2011-07-06 15:58:11 UTC (rev 162) @@ -46,8 +46,6 @@ </action> - - <action name="search" class="org.nuiton.scmwebeditor.actions.SearchAction" method="search"> <param name="address"/> <result name="root" >Search.jsp</result>
participants (1)
-
kcardineaud@users.nuiton.org