Author: kcardineaud Date: 2011-07-27 14:55:22 +0200 (Wed, 27 Jul 2011) New Revision: 189 Url: http://nuiton.org/repositories/revision/scmwebeditor/189 Log: Add close() to a stream and remove some useless instructions Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-07-27 08:11:22 UTC (rev 188) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-07-27 12:55:22 UTC (rev 189) @@ -182,80 +182,80 @@ SVNRepository repository = null; try { - repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( url ) ); - ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( login , pw ); - repository.setAuthenticationManager( authManager ); + repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( url ) ); + ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( login , pw ); + repository.setAuthenticationManager( authManager ); + + SVNNodeKind nodeKind = repository.checkPath( file , -1 ); + + + + + if ( nodeKind == SVNNodeKind.NONE ) { + if(log.isErrorEnabled()) { + log.error( "There is no entry at '" + url + "'." ); + } + request.setAttribute("projectUrl", projectUrl); + return "errorPath"; + + } else if ( nodeKind == SVNNodeKind.DIR ) { + if(log.isErrorEnabled()) { + log.error( "The entry at '" + url + "' is a file while a directory was expected." ); + } + request.setAttribute("projectUrl", projectUrl); + if(log.isErrorEnabled()) { + log.error("Error with svn path or file "); + } + return "errorPath"; + } + + + ByteArrayOutputStream baos = new ByteArrayOutputStream( ); + + //On récupere le contenu du fichier, et on le met dans un outputStream + repository.getFile( file , -1 , null , baos ); + + originalText=baos.toString(); + baos.close(); - SVNNodeKind nodeKind = repository.checkPath( file , -1 ); - - - - - if ( nodeKind == SVNNodeKind.NONE ) { - if(log.isErrorEnabled()) { - log.error( "There is no entry at '" + url + "'." ); + } 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()); } + //redirect to a login page + return Action.LOGIN; + + } catch (SVNException e) { request.setAttribute("projectUrl", projectUrl); - //Suppression du repertoire temporaire - delTempDirectory(svnSess); - return "errorPath"; - } else if ( nodeKind == SVNNodeKind.DIR ) { + if(log.isErrorEnabled()) { - log.error( "The entry at '" + url + "' is a file while a directory was expected." ); + log.error("SVN error ",e); } - request.setAttribute("projectUrl", projectUrl); - //Suppression du repertoire temporaire - delTempDirectory(svnSess); + return "errorPath"; + } catch (IOException e) { if(log.isErrorEnabled()) { - log.error("Error with svn path or file "); + log.error("IO error ",e); } return "errorPath"; - } - + } - ByteArrayOutputStream baos = new ByteArrayOutputStream( ); - - repository.getFile( file , -1 , null , baos ); - - originalText=baos.toString(); - - - } 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 Action.LOGIN; - - } catch (SVNException e) { - request.setAttribute("projectUrl", projectUrl); - //Suppression du repertoire temporaire - delTempDirectory(svnSess); - if(log.isErrorEnabled()) { - log.error("SVN error ",e); - } - return "errorPath"; - } - String mimeType =null; - try { - mimeType = getMimeType(originalText, svnSess.getFileName()); - } catch (IOException e) { - if(log.isErrorEnabled()) { - log.error("Can't get MimeType, problem when reading file",e); - } - } + try { + mimeType = getMimeType(originalText, svnSess.getFileName()); + } catch (IOException e) { + if(log.isErrorEnabled()) { + log.error("Can't get MimeType, problem when reading file",e); + } + } /* @@ -309,8 +309,6 @@ // Si le fichier n'est pas de type texte, on ne peut pas l'éditer if(mimeType==null || editable==false ) { request.setAttribute("projectUrl", projectUrl); - //On supprime le repertoire temporaire - delTempDirectory(svnSess); if(log.isErrorEnabled()) { log.error("Can't edit this file, mimetype : "+mimeType);