Author: tchemit Date: 2011-08-26 17:09:03 +0200 (Fri, 26 Aug 2011) New Revision: 248 Url: http://nuiton.org/repositories/revision/scmwebeditor/248 Log: reformat improve code use constants Removed: trunk/src/main/java/org/nuiton/scmwebeditor/interceptors/ Modified: trunk/pom.xml trunk/src/main/java/org/nuiton/scmwebeditor/ScmSession.java trunk/src/main/java/org/nuiton/scmwebeditor/ScmUser.java trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorApplicationListener.java trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfig.java trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfigOption.java trunk/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/LogoutAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/PreviewAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ResetAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/SaveAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/ScmUrlResolver.java trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/ScmUrlResolverEngine.java trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/impl/ScmUrlResolverDefaultImpl.java trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/impl/ScmUrlResolverMavenDocImpl.java trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/impl/ScmUrlResolverMavenSiteXmlImpl.java trunk/src/test/java/org/nuiton/scmwebeditor/BaseActionTest.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/pom.xml 2011-08-26 15:09:03 UTC (rev 248) @@ -1,5 +1,7 @@ <?xml version="1.0"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> @@ -90,13 +92,12 @@ <artifactId>tika-core</artifactId> <version>0.9</version> </dependency> - + <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <version>1.1.0</version> </dependency> - <dependency> @@ -284,7 +285,7 @@ <version>${nuitonI18nVersion}</version> </plugin> - + </plugins> </pluginManagement> Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmSession.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmSession.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmSession.java 2011-08-26 15:09:03 UTC (rev 248) @@ -31,46 +31,44 @@ protected Map<String, ScmUser> scmUsers; - + public ScmSession() { - scmUsers = new HashMap<String,ScmUser>(); - } + scmUsers = new HashMap<String, ScmUser>(); + } public Map<String, ScmUser> getScmUsers() { return scmUsers; } - - public void addScmUser(String address , String login, String password) { - scmUsers.put(address, new ScmUser(login,password)); + + public void addScmUser(String address, String login, String password) { + scmUsers.put(address, new ScmUser(login, password)); } - + public void delScmUser(String address) { scmUsers.remove(address); } - + public String getUsername(String url) { - if(scmUsers.containsKey(url)) { + if (scmUsers.containsKey(url)) { return scmUsers.get(url).getUsername(); - } - else { + } else { return null; } - + } - + public String getPassword(String url) { - if(scmUsers.containsKey(url)) { + if (scmUsers.containsKey(url)) { return scmUsers.get(url).getPassword(); - } - else { + } else { return null; } } - + public String getUUID(String address) { SvnConnection svnConnection = new SvnConnection(address); return svnConnection.getUUID(); } - - + + } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmUser.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmUser.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmUser.java 2011-08-26 15:09:03 UTC (rev 248) @@ -25,13 +25,14 @@ package org.nuiton.scmwebeditor; public class ScmUser { - + protected String username; + protected String password; - + public ScmUser(String username, String password) { - this.setUsername(username); - this.setPassword(password); + setUsername(username); + setPassword(password); } public void setUsername(String username) { Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorApplicationListener.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorApplicationListener.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorApplicationListener.java 2011-08-26 15:09:03 UTC (rev 248) @@ -51,7 +51,7 @@ @Override public void contextDestroyed(ServletContextEvent sce) { // Nothing - + } } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-08-26 15:09:03 UTC (rev 248) @@ -81,53 +81,81 @@ */ public class ScmWebEditorBaseAction extends BaseAction { - + public static final String AUTH_ERROR = "authError"; + + public static final String ERROR_PATH = "errorPath"; + protected Map<String, Object> session; - + private static final long serialVersionUID = 1L; + final static protected String CONTEXT_ACTION_KEY = "action"; private static final Log log = LogFactory.getLog(ScmWebEditorBaseAction.class); //TODO-TC200924 : uniformize all this different parameter and attribute, this is a bit messy... protected static final String PARAMETER_ADDRESS = "address"; + protected static final String PARAMETER_SCM_EDITOR_URL = "scmEditorUrl"; + protected static final String PARAMETER_PROJECT_URL = "projectUrl"; + protected static final String PARAMETER_FILE_NAME = "file_name"; + protected static final String PARAMETER_LANG = "lang"; + protected static final String PARAMETER_DEFAULT_LANG = "defaultLang"; + protected static final String PARAMETER_FORMAT = "format"; + protected static final String PARAMETER_USERNAME = "username"; + protected static final String PARAMETER_PW = "pw"; + protected static final String PARAMETER_MYTEXT = "Mytext"; + protected static final String PARAMETER_ORIG_TEXT = "Orig_text"; + protected static final String PARAMETER_COMMIT_MESSAGE = "Commit_message"; + protected static final String PARAMETER_TEXT = "text"; //protected static final String ATTRIBUTE_TEMPDIR = "javax.servlet.context.tempdir"; // protected static final String ATTRIBUTE_SVN_PATH_URL = "svnPath_url"; // protected static final String ATTRIBUTE_FILE_NAME_URL = "fileName_url"; protected static final String ATTRIBUTE_REDIRECTION_URL = "Redirection_url"; + // protected static final String ATTRIBUTE_LANG = "Lang"; // protected static final String ATTRIBUTE_FORMAT = "Format"; private static final String ATTRIBUTE_SVN_SESSION = "myInfo"; protected static final String ATTRIBUTE_ORIG_TEXT = "OrigText"; + protected static final String ATTRIBUTE_INVALIDATE_MAX_TIME = "InvalidateMaxTime"; + protected static final String ATTRIBUTE_LOGIN = "Login"; + protected static final String ATTRIBUTE_IS_LOGIN = "IsLogin"; + protected static final String ATTRIBUTE_BAD_LOGIN = "badLogin"; + protected static final String ATTRIBUTE_PROJECT_URL = "projectUrl"; + protected static final String ATTRIBUTE_SCM_EDITOR_URI = "scmEditorUri"; + protected static final String ATTRIBUTE_PREVIEW_SERVLET_URL = "previewServletUrl"; + protected static final String ATTRIBUTE_FILESEARCH_SERVLET_URL = "searchServletUrl"; + protected static final String ATTRIBUTE_REDIRECT_URL = "Redirect_url"; + protected static final String ATTRIBUTE_PRIVATE_SERVLET_URI = "privateServletUri"; - + protected static final String PROPERTIESFILES = "scmwebeditor.properties"; + protected static final String EDITABLESFILES = "editableFiles"; - + protected static CodepageDetectorProxy detector; protected CodepageDetectorProxy getCodepageDetector() { @@ -180,8 +208,7 @@ OutputStream os = new FileOutputStream(tmpFile); try { IOUtils.copy(is, os); - } - finally { + } finally { is.close(); os.close(); } @@ -193,8 +220,7 @@ Writer ow = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); try { IOUtils.copy(ir, ow); - } - finally { + } finally { ir.close(); ow.close(); is.close(); @@ -217,38 +243,35 @@ } } } - + /** - * * @param svnSess * @param checkoutdir * @throws SVNException */ - public void checkout(SvnConnection svnSess, File checkoutdir , String numVersion) throws SVNException { + public void checkout(SvnConnection svnSess, File checkoutdir, String numVersion) throws SVNException { SVNUpdateClient upclient = new SVNUpdateClient(svnSess.getManager(), svnSess.getSvnOption()); - - if (log.isDebugEnabled()) { - log.debug("Do Checkout of " + svnSess.getRemoteUrl()); + + if (log.isDebugEnabled()) { + log.debug("Do Checkout of " + svnSess.getRemoteUrl()); + } + try { + upclient.doCheckout(svnSess.getRemoteUrl(), checkoutdir, + SVNRevision.create(Long.parseLong(numVersion)), SVNRevision.create(Long.parseLong(numVersion)), SVNDepth.FILES, false); + } catch (NumberFormatException e) { + if (log.isErrorEnabled()) { + log.error("The number version is not valid."); } - try { - upclient.doCheckout(svnSess.getRemoteUrl(), checkoutdir, - SVNRevision.create(Long.parseLong(numVersion)), SVNRevision.create(Long.parseLong(numVersion)), SVNDepth.FILES, false); - } - catch (NumberFormatException e) { - if(log.isErrorEnabled()) { - log.error("The number version is not valid."); - } - upclient.doCheckout(svnSess.getRemoteUrl(), checkoutdir, - SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); - - } - - + upclient.doCheckout(svnSess.getRemoteUrl(), checkoutdir, + SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); + + } + + } - + /** - * * @param svnSess * @param checkoutdir * @throws SVNException @@ -256,130 +279,129 @@ public void checkout(SvnConnection svnSess, File checkoutdir) throws SVNException { SVNUpdateClient upclient = new SVNUpdateClient(svnSess.getManager(), svnSess.getSvnOption()); - - if (log.isDebugEnabled()) { - log.debug("Do Checkout of " + svnSess.getRemoteUrl()); - } - upclient.doCheckout(svnSess.getRemoteUrl(), checkoutdir, - SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); + if (log.isDebugEnabled()) { + log.debug("Do Checkout of " + svnSess.getRemoteUrl()); + } + + upclient.doCheckout(svnSess.getRemoteUrl(), checkoutdir, + SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); } - - + + /** - * * @param svnFile * @param username * @param password * @return - * @throws SVNException - * @throws IOException + * @throws SVNException + * @throws IOException */ - public String getHeadRevision(String address, String login, String password) throws SVNException , IllegalArgumentException { - - String lastRevision = ""; - + public String getHeadRevision(String address, String login, String password) throws SVNException, IllegalArgumentException { + + String lastRevision; + SvnConnection svnConn = new SvnConnection(address); - - + + String url = svnConn.getSvnPath(); String file = svnConn.getFileName(); - - SVNRepository repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded( url )); - ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( login , password ); - repository.setAuthenticationManager( authManager ); - - SVNNodeKind nodeKind = repository.checkPath( file , -1 ); - - - if ( nodeKind == SVNNodeKind.NONE ) { - if(log.isErrorEnabled()) { - log.error( "There is no entry at '" + url + "'." ); + + SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url)); + ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(login, password); + repository.setAuthenticationManager(authManager); + + SVNNodeKind nodeKind = repository.checkPath(file, -1); + + + if (nodeKind == SVNNodeKind.NONE) { + if (log.isErrorEnabled()) { + log.error("There is no entry at '" + url + "'."); } throw new IllegalArgumentException("There is no entry at '" + url + "'."); - } else if ( nodeKind == SVNNodeKind.DIR ) { - if(log.isErrorEnabled()) { - log.error( "The entry at '" + url + "' is a file while a directory was expected." ); + } else if (nodeKind == SVNNodeKind.DIR) { + if (log.isErrorEnabled()) { + log.error("The entry at '" + url + "' is a file while a directory was expected."); } throw new IllegalArgumentException("The entry at '" + url + "' is a file while a directory was expected."); } - - ByteArrayOutputStream baos = new ByteArrayOutputStream( ); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + SVNProperties fileProperties = new SVNProperties(); - - repository.getFile( file , -1 , fileProperties , baos ); - + + repository.getFile(file, -1, fileProperties, baos); + fileProperties.getStringValue(SVNProperty.REVISION); - - + + lastRevision = baos.toString(); - + try { baos.close(); } catch (IOException e) { - if(log.isDebugEnabled()) { - log.debug("Can't close stream",e); + if (log.isDebugEnabled()) { + log.debug("Can't close stream", e); } } - + return lastRevision; } - - - + + public String getHeadNumberRevision(String address, String login, String password) throws SVNException { - - ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( login , password ); - + + ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(login, password); + DefaultSVNOptions svnOption = new DefaultSVNOptions(); svnOption.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); - - SVNWCClient wcClient = new SVNWCClient(authManager,svnOption); - + + SVNWCClient wcClient = new SVNWCClient(authManager, svnOption); + SVNInfo info = wcClient.doInfo(SVNURL.parseURIEncoded(address), SVNRevision.HEAD, SVNRevision.HEAD); String headRevision = info.getRevision().toString(); - - + + return headRevision; } - + public String getHeadcommiter(String address, String login, String password) throws SVNException { - - ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( login , password ); - + + ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(login, password); + DefaultSVNOptions svnOption = new DefaultSVNOptions(); svnOption.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); - - SVNWCClient wcClient = new SVNWCClient(authManager,svnOption); - + + SVNWCClient wcClient = new SVNWCClient(authManager, svnOption); + SVNInfo info = wcClient.doInfo(SVNURL.parseURIEncoded(address), SVNRevision.HEAD, SVNRevision.HEAD); String headAuthor = info.getAuthor(); - - + + return headAuthor; } - - + + /** * Use to delete the checkout temp directory + * * @param checkoutdir The dir temp directory */ public void delTempDirectory(File checkoutdir) { try { FileUtils.deleteDirectory(checkoutdir); } catch (IOException e) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("Can't delete temp directory"); } } } - + protected SvnConnection getSvnSession(HttpSession httpSession) { SvnConnection svnSess = (SvnConnection) httpSession.getAttribute(ATTRIBUTE_SVN_SESSION); return svnSess; @@ -393,8 +415,8 @@ File tmp_dir = getSvnSession(httpSession).getCheckoutdir(); return tmp_dir; } - + protected String getMimeType(File file) throws IOException, SAXException, TikaException { InputStream is = new FileInputStream(file); String result = null; @@ -405,25 +427,24 @@ AutoDetectParser parser = new AutoDetectParser(); parser.parse(is, contenthandler, metadata); result = metadata.get(Metadata.CONTENT_TYPE); - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("Mine type of " + file.getName() + " is : " + result); - } - + } + } catch (SAXException e) { - if(log.isErrorEnabled()) { - log.error("Can't get MimeType, parsing error",e); + if (log.isErrorEnabled()) { + log.error("Can't get MimeType, parsing error", e); } } catch (TikaException e) { - if(log.isErrorEnabled()) { - log.error("Can't get MimeType, tika error",e); + if (log.isErrorEnabled()) { + log.error("Can't get MimeType, tika error", e); } - } - finally { + } finally { is.close(); } return result; } - + protected String getMimeType(String content, String filename) throws IOException { InputStream is = new ByteArrayInputStream(content.getBytes()); String result = null; @@ -434,20 +455,19 @@ AutoDetectParser parser = new AutoDetectParser(); parser.parse(is, contenthandler, metadata); result = metadata.get(Metadata.CONTENT_TYPE); - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("Mine type of " + filename + " is : " + result); } - + } catch (SAXException e) { - if(log.isErrorEnabled()) { - log.error("Can't get MimeType, parsing error",e); + if (log.isErrorEnabled()) { + log.error("Can't get MimeType, parsing error", e); } } catch (TikaException e) { - if(log.isErrorEnabled()) { - log.error("Can't get MimeType, tika error",e); + if (log.isErrorEnabled()) { + log.error("Can't get MimeType, tika error", e); } - } - finally { + } finally { is.close(); } return result; @@ -462,18 +482,17 @@ AutoDetectParser parser = new AutoDetectParser(); parser.parse(is, contenthandler, metadata); String[] result = metadata.getValues(Metadata.CONTENT_TYPE); - - if(log.isDebugEnabled()) { + + if (log.isDebugEnabled()) { log.debug("Mine type of " + filename + " is : " + result); } - + return result; - } - finally { + } finally { is.close(); } } - + /** * Recuperation des propriétés dans un fichier properties * @@ -481,63 +500,55 @@ * @return un objet Properties contenant les propriétés du fichier */ public static Properties loadProperties(String file) throws IOException { - Properties properties = new Properties(); + Properties properties = new Properties(); - FileInputStream input = new FileInputStream(file); - try{ - properties.load(input); - return properties; - } + FileInputStream input = new FileInputStream(file); + try { + properties.load(input); + return properties; + } finally { + input.close(); + } - finally{ - input.close(); - } + } - } - /** * Recuperation des propriétés dans un fichier properties * * @param inStream le fichier contenant les propriétés * @return un objet Properties contenant les propriétés du fichier */ - public static Properties loadProperties(InputStream inStream) throws IOException , NullPointerException { - Properties properties = new Properties(); + public static Properties loadProperties(InputStream inStream) throws IOException, NullPointerException { + Properties properties = new Properties(); - properties.load(inStream); - return properties; - + properties.load(inStream); + return properties; + } - - + + public ScmSession getScmSession() { session = ActionContext.getContext().getSession(); Object obj = session.get("ScmSession"); - - ScmSession scmSession = null; - if(obj==null) { + + ScmSession scmSession; + if (obj == null) { scmSession = new ScmSession(); session.put("ScmSession", scmSession); - } - else { + } else { scmSession = (ScmSession) obj; } - return scmSession; + return scmSession; } - + public String getUsername(String url) { return getScmSession().getUsername(url); } - + public String getPassword(String url) { return getScmSession().getPassword(url); } - - - - - } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfig.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfig.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfig.java 2011-08-26 15:09:03 UTC (rev 248) @@ -24,54 +24,54 @@ */ package org.nuiton.scmwebeditor; -import java.util.List; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.ApplicationConfig; import org.nuiton.util.ArgumentsParserException; +import java.util.List; + public class ScmWebEditorConfig { private static final Log log = LogFactory.getLog(ScmWebEditorConfig.class); - + protected static ApplicationConfig config; - - + + public static ApplicationConfig getConfig(String... args) { - if(config==null) { + if (config == null) { synchronized (ScmWebEditorConfig.class) { - if(config==null) { + if (config == null) { config = new ApplicationConfig(ScmWebEditorConfigOption.CONFIG_FILE.getDefaultValue()); try { config.parse(args); } catch (ArgumentsParserException e) { - if(log.isErrorEnabled()) { - log.error("Error when parsing ApplicationConfig",e); + if (log.isErrorEnabled()) { + log.error("Error when parsing ApplicationConfig", e); } } } - } + } } return config; } - + public static List<String> getEditableFiles() { return getEditableFiles(getConfig()); } - + public static List<String> getEditableFiles(ApplicationConfig config) { return config.getOptionAsList(ScmWebEditorConfigOption.EDITABLESFILES.getKey()).getOption(); } - + public static String getKey() { return getKey(getConfig()); } - + public static String getKey(ApplicationConfig config) { return config.getOption(ScmWebEditorConfigOption.COOKIES_PRIVATE_KEY.getKey()); } - - + + } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfigOption.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfigOption.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorConfigOption.java 2011-08-26 15:09:03 UTC (rev 248) @@ -30,20 +30,25 @@ public enum ScmWebEditorConfigOption implements OptionDef { CONFIG_FILE(ApplicationConfig.CONFIG_FILE_NAME, "The file name", "scmwebeditor.properties", String.class, false, false), - EDITABLESFILES("editableFiles", "description" , "Files types that are editable", String.class, true, true), - COOKIES_PRIVATE_KEY("cookiePrivateKey", "Private key for cookies" , null , String.class, true, true); + EDITABLESFILES("editableFiles", "description", "Files types that are editable", String.class, true, true), + COOKIES_PRIVATE_KEY("cookiePrivateKey", "Private key for cookies", null, String.class, true, true); - + private final String key; + private final String description; + private String defaultValue; + private final Class<?> type; + private boolean _transient; + private boolean _final; ScmWebEditorConfigOption(String key, String description, String defaultValue, - Class<?> type, boolean _transient, boolean _final) { + Class<?> type, boolean _transient, boolean _final) { this.key = key; this.description = description; this.defaultValue = defaultValue; @@ -52,8 +57,7 @@ this._transient = _transient; } - - + @Override public String getKey() { return key; @@ -86,22 +90,18 @@ @Override public void setDefaultValue(String defaultValue) { - this.defaultValue = defaultValue ; + this.defaultValue = defaultValue; } @Override public void setTransient(boolean isTransient) { - this._transient=isTransient; + _transient = isTransient; } @Override public void setFinal(boolean isFinal) { - this._final = isFinal; + _final = isFinal; } - - - - } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/SvnConnection.java 2011-08-26 15:09:03 UTC (rev 248) @@ -46,182 +46,164 @@ public class SvnConnection { - + private static final Log log = LogFactory.getLog(SvnConnection.class); - /** - * full svn path - */ + + /** full svn path */ protected String addressSvn; - /** - * svn path without fileName - */ + + /** svn path without fileName */ protected String svnPath; - /** - * fileName of modif file - */ + + /** fileName of modif file */ protected String fileName; - /** - * Temp directory for checkout - */ + + /** Temp directory for checkout */ protected File checkoutdir; - /** - * url of svn path - */ + + /** url of svn path */ protected SVNURL remoteUrl; - /** - * AuthenticationManager with login and password - */ + + /** AuthenticationManager with login and password */ protected ISVNAuthenticationManager authManager; - /** - * svn default option - */ + + /** svn default option */ protected DefaultSVNOptions svnOption; + /** * */ protected SVNClientManager manager; - + protected String repositoryId; - - public SvnConnection ( + public SvnConnection( String address) throws StringIndexOutOfBoundsException { - - this.addressSvn = address; - - this.svnPath = address.substring(0,address.lastIndexOf("/")); - - this.fileName = address.substring(address.lastIndexOf("/")+1); - + + addressSvn = address; + + svnPath = address.substring(0, address.lastIndexOf("/")); + + fileName = address.substring(address.lastIndexOf("/") + 1); + try { - this.remoteUrl = SVNURL.parseURIEncoded(svnPath); + remoteUrl = SVNURL.parseURIEncoded(svnPath); } catch (SVNException e) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("Can't parse svnPath", e); } } - this.authManager = SVNWCUtil.createDefaultAuthenticationManager(); - this.svnOption = SVNWCUtil.createDefaultOptions(false); - this.svnOption.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); - this.manager = SVNClientManager.newInstance(this.svnOption, this.authManager); + authManager = SVNWCUtil.createDefaultAuthenticationManager(); + svnOption = SVNWCUtil.createDefaultOptions(false); + svnOption.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); + manager = SVNClientManager.newInstance(svnOption, authManager); } public void updateAuthentication(String login, String password) { setAuthManager(SVNWCUtil.createDefaultAuthenticationManager(login, password)); setManager(SVNClientManager.newInstance(getSvnOption(), getAuthManager())); } - - /** - * - * @return - */ + + /** @return */ public String getUUID() { - String repositoryUUID = null; + String repositoryUUID; try { SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(addressSvn)); ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(); repository.setAuthenticationManager(authManager); - + repositoryUUID = repository.getRepositoryUUID(true); - } - catch (SVNException e) { - if(log.isDebugEnabled()) { + } catch (SVNException e) { + if (log.isDebugEnabled()) { log.debug("Can't get UUID"); } return null; } - + return repositoryUUID; } - - /** - * - * @return - */ + + /** @return */ public String getSvnRoot() { - String repositoryRoot = null; + String repositoryRoot; try { SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(addressSvn)); ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(); repository.setAuthenticationManager(authManager); - + repositoryRoot = repository.getRepositoryRoot(true).toString(); - } - catch (SVNException e) { - if(log.isDebugEnabled()) { + } catch (SVNException e) { + if (log.isDebugEnabled()) { log.debug("Can't get SvnRoot"); } return null; } - + return repositoryRoot; } - - + + public void testConnection() throws SVNException { SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(addressSvn)); - repository.setAuthenticationManager(this.authManager); - - + repository.setAuthenticationManager(authManager); + + repository.testConnection(); - - + + } - - + + public boolean isDifferent(String text) throws IOException { File pathToFile = new File(checkoutdir, getFileName()); - + SVNDiffClient diffClient = new SVNDiffClient(getManager(), getSvnOption()); - + FileUtil.writeString(pathToFile, text, "UTF-8"); - + ByteArrayOutputStream diff = new ByteArrayOutputStream(); - + try { diffClient.doDiff(pathToFile, SVNRevision.UNDEFINED, SVNRevision.WORKING, SVNRevision.HEAD, SVNDepth.INFINITY, true, diff, null); } catch (SVNException e) { - log.error("Diff fail",e); + log.error("Diff fail", e); return false; } - if(diff.size()>0) { + if (diff.size() > 0) { return true; - } - else { + } else { return false; } - - + + } - + public ByteArrayOutputStream getDiff(String text) throws IOException { File pathToFile = new File(checkoutdir, getFileName()); SVNDiffClient diffClient = new SVNDiffClient(getManager(), getSvnOption()); - + FileUtil.writeString(pathToFile, text, "UTF-8"); - + ByteArrayOutputStream diff = new ByteArrayOutputStream(); - + try { diffClient.doDiff(pathToFile, SVNRevision.UNDEFINED, SVNRevision.WORKING, SVNRevision.HEAD, SVNDepth.INFINITY, true, diff, null); } catch (SVNException e) { - log.error("Diff fail",e); + log.error("Diff fail", e); } - - + + return diff; - - - + + } - - + public ISVNAuthenticationManager getAuthManager() { return authManager; } @@ -235,9 +217,9 @@ } public void createCheckoutdir() throws IOException { - this.checkoutdir = FileUtil.createTempDirectory("scm_", ""); + checkoutdir = FileUtil.createTempDirectory("scm_", ""); } - + public void setCheckoutdir(File checkoutdir) { this.checkoutdir = checkoutdir; } @@ -281,7 +263,7 @@ public void setSvnPath(String svnPath) { this.svnPath = svnPath; } - + public String getRepositoryId() { return repositoryId; } @@ -291,5 +273,4 @@ } - } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/LogoutAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/LogoutAction.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/LogoutAction.java 2011-08-26 15:09:03 UTC (rev 248) @@ -24,10 +24,6 @@ */ package org.nuiton.scmwebeditor.actions; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.interceptor.ServletRequestAware; @@ -35,25 +31,29 @@ import org.nuiton.scmwebeditor.ScmWebEditorBaseAction; import org.nuiton.scmwebeditor.SvnConnection; -import com.opensymphony.xwork2.Action; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; public class LogoutAction extends ScmWebEditorBaseAction implements ServletRequestAware, ServletResponseAware { private static final long serialVersionUID = 6937086747942656369L; private static final Log log = LogFactory.getLog(LogoutAction.class); - + protected String address; + protected String projectUrl; - - protected HttpServletRequest request; - protected HttpServletResponse response; - + protected transient HttpServletRequest request; + + protected transient HttpServletResponse response; + + public void setAddress(String address) { this.address = address; } - + public String getAddress() { return address; } @@ -64,45 +64,44 @@ public void setProjectUrl(String projectUrl) { this.projectUrl = projectUrl; - } + } public String execute() { SvnConnection svnConn = new SvnConnection(address); - + //Si le repo n'est pas protege en ecriture on recupere sont UUID String repositoryUUID = svnConn.getUUID(); - if (repositoryUUID==null) { - repositoryUUID=address; + if (repositoryUUID == null) { + repositoryUUID = address; } - + //suppression des cookies pour ce dépot for (Cookie c : request.getCookies()) { - if(c.getName().equals(repositoryUUID)) { + if (c.getName().equals(repositoryUUID)) { c.setMaxAge(0);//On supprime le cookie response.addCookie(c); - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("Cookie supprimé"); } } - } - + } + //Suppression des identifiants stockés en session getScmSession().delScmUser(repositoryUUID); - - - return Action.SUCCESS; + + return SUCCESS; } - + @Override public void setServletRequest(HttpServletRequest request) { - this.request=request; + this.request = request; } @Override public void setServletResponse(HttpServletResponse response) { - this.response=response; + this.response = response; } - + } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/PreviewAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/PreviewAction.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/PreviewAction.java 2011-08-26 15:09:03 UTC (rev 248) @@ -25,31 +25,29 @@ package org.nuiton.scmwebeditor.actions; -import javax.servlet.http.HttpServletRequest; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.interceptor.ServletRequestAware; import org.nuiton.jrst.JRST; import org.nuiton.scmwebeditor.ScmWebEditorBaseAction; +import javax.servlet.http.HttpServletRequest; -import com.opensymphony.xwork2.Action; -import com.opensymphony.xwork2.ActionContext; - public class PreviewAction extends ScmWebEditorBaseAction implements ServletRequestAware { /** - * + * */ private static final long serialVersionUID = -2388759298175611718L; - HttpServletRequest request; - String XMLResponse; - String newText; - - - + private static final Log log = LogFactory.getLog(PreviewAction.class); + + protected transient HttpServletRequest request; + + protected String XMLResponse; + + protected String newText; + public String getNewText() { return newText; } @@ -62,58 +60,42 @@ return XMLResponse; } + public void setXMLResponse(String XMLResponse) { this.XMLResponse = XMLResponse; } - - - private static final Log log = LogFactory.getLog(PreviewAction.class); - + public String execute() { - setResponse(); - return Action.SUCCESS; - } - - public void setResponse() { - - if(log.isDebugEnabled()) { + + if (log.isDebugEnabled()) { log.debug("Enter in preview action"); } - - if(log.isDebugEnabled()) { - log.debug(newText); + + if (log.isDebugEnabled()) { + log.debug(newText); } - XMLResponse=""; + XMLResponse = ""; //Using jrst to generate html document try { XMLResponse = JRST.generate(JRST.TYPE_HTML, newText); - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("RST generate"); } - + } catch (Exception eee) { - if(log.isWarnEnabled()) { - log.warn("RST generate fail",eee); + if (log.isWarnEnabled()) { + log.warn("RST generate fail", eee); } XMLResponse = "<h4>Parsing error, please read RST specification<h4>"; - return; } - - - } - static public PreviewAction getAction() { - return (PreviewAction) ActionContext.getContext() - .get(CONTEXT_ACTION_KEY); + return SUCCESS; } @Override public void setServletRequest(HttpServletRequest request) { this.request = request; } - - - - - + + } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ResetAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ResetAction.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ResetAction.java 2011-08-26 15:09:03 UTC (rev 248) @@ -31,28 +31,25 @@ import org.tmatesoft.svn.core.SVNAuthenticationException; import org.tmatesoft.svn.core.SVNException; -import com.opensymphony.xwork2.Action; - public class ResetAction extends ScmWebEditorBaseAction { - private static final long serialVersionUID = -1154924826535371319L; private static final Log log = LogFactory.getLog(ResetAction.class); - + protected String lastRevision; - + protected String numRevision; - + protected String address; - + protected String username; - + protected String pw; - + protected String error; - - + + public String getLastRevision() { return lastRevision; } @@ -60,7 +57,7 @@ public String getNumRevision() { return numRevision; } - + public void setAddress(String address) { this.address = address; } @@ -72,73 +69,68 @@ public void setPw(String pw) { this.pw = pw; } - + public String getError() { return error; } - public String execute() { - + SvnConnection svnConn = new SvnConnection(address); - + //Si le repo n'est pas protege en ecriture on recupere sont UUID String repositoryUUID = svnConn.getUUID(); - if (repositoryUUID==null) { - repositoryUUID=address; + if (repositoryUUID == null) { + repositoryUUID = address; } - - if(username==null && pw==null) { - if(getScmSession().getUsername(repositoryUUID)!=null && getScmSession().getPassword(repositoryUUID)!=null) { + + if (username == null && pw == null) { + if (getScmSession().getUsername(repositoryUUID) != null && getScmSession().getPassword(repositoryUUID) != null) { //On recupère les identifiants en session username = getScmSession().getUsername(repositoryUUID); pw = getScmSession().getPassword(repositoryUUID); - } - else { + } else { username = null; pw = null; } } - - + try { - + lastRevision = getHeadRevision(address, username, pw); - - numRevision =getHeadNumberRevision(address, username, pw); - + numRevision = getHeadNumberRevision(address, username, pw); + + } catch (SVNAuthenticationException authexep) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("AUTH FAIL"); } - error = "authError"; - return "authError"; + error = AUTH_ERROR; + return AUTH_ERROR; } catch (SVNException e1) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("Can't reach the svn repository"); } - error = "errorPath"; - numRevision=null; - return "errorPath"; + error = ERROR_PATH; + numRevision = null; + return ERROR_PATH; } catch (StringIndexOutOfBoundsException e) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("Can't reach the svn repository"); } - error = "errorPath"; - return "errorPath"; + error = ERROR_PATH; + return ERROR_PATH; } catch (IllegalArgumentException e) { - if(log.isErrorEnabled()) { - log.error("Problem with file path",e); + if (log.isErrorEnabled()) { + log.error("Problem with file path", e); } - error = "errorPath"; - return "errorPath"; - } - - return Action.SUCCESS; - - + error = ERROR_PATH; + return ERROR_PATH; + } + + return SUCCESS; } - - + + } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/SaveAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/SaveAction.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/SaveAction.java 2011-08-26 15:09:03 UTC (rev 248) @@ -24,71 +24,63 @@ */ package org.nuiton.scmwebeditor.actions; -import java.util.Date; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.opensymphony.xwork2.Action; +import java.util.Date; public class SaveAction extends ScmWebEditorCommitAction { - String result; - Date date; - + private static final Log log = LogFactory.getLog(SaveAction.class); + private static final long serialVersionUID = -115627369699637253L; + protected String result; - private static final Log log = LogFactory.getLog(SaveAction.class); + protected Date date; - public String getResult() { return result; } - public void setResult(String result) { this.result = result; } - + public Date getDate() { return date; } - - private static final long serialVersionUID = -115627369699637253L; - - public String save() { - - if(log.isDebugEnabled()) { - log.debug("originText : "+origText); - log.debug("newText : "+newText); + + if (log.isDebugEnabled()) { + log.debug("originText : " + origText); + log.debug("newText : " + newText); } - - - if(origText.equals(newText)) { + + + if (origText.equals(newText)) { result = "uselessSave"; - return Action.SUCCESS; - } - + return SUCCESS; + } + result = execute(); date = new Date(); - - - return Action.SUCCESS; + + + return SUCCESS; } - - + + /** * Use to display a beautiful date in jsp + * * @return */ public String getFormatDate() { return date.toString(); } - - - + + } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-08-26 15:09:03 UTC (rev 248) @@ -24,15 +24,6 @@ */ package org.nuiton.scmwebeditor.actions; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -50,40 +41,59 @@ import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.wc.SVNCommitClient; -import com.opensymphony.xwork2.Action; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +public class ScmWebEditorCommitAction extends ScmWebEditorBaseAction implements ServletRequestAware, ServletResponseAware { -public class ScmWebEditorCommitAction extends ScmWebEditorBaseAction implements ServletRequestAware, ServletResponseAware { - /** - * - */ private static final long serialVersionUID = 6374273568146287730L; private static final Log log = LogFactory.getLog(ScmWebEditorCommitAction.class); - + + public static final String FILE_MODIFY = "fileModify"; + protected String newText; + protected String commitMessage; + protected String origText; + protected String username; + protected String pw; + protected String address; + protected String lastText; + protected String format; + protected String projectUrl; + protected String diff; + protected String headCommiter; + protected String mimeType; - + protected boolean force; + protected boolean saveCookie; + protected boolean badLogin; - + protected String numRevision; - - protected HttpServletRequest request; - protected HttpServletResponse response; - + + protected transient HttpServletRequest request; + + protected transient HttpServletResponse response; + public String getCommitMessage() { return commitMessage; } @@ -107,7 +117,7 @@ public void setNewText(String newText) { this.newText = newText; } - + public String getOrigText() { return origText; } @@ -115,7 +125,7 @@ public void setOrigText(String origText) { this.origText = origText; } - + public String getUsername() { return username; } @@ -131,7 +141,7 @@ public void setPw(String pw) { this.pw = pw; } - + public String getAddress() { return address; } @@ -139,7 +149,7 @@ public void setAddress(String address) { this.address = address; } - + public String getLastText() { return lastText; } @@ -147,7 +157,7 @@ public void setLastText(String lastText) { this.lastText = lastText; } - + public String getProjectUrl() { return projectUrl; } @@ -155,13 +165,13 @@ public void setProjectUrl(String projectUrl) { this.projectUrl = projectUrl; - } - + } + public void setForce(boolean force) { this.force = force; } - - + + public String getNumRevision() { return numRevision; } @@ -169,15 +179,15 @@ public void setNumRevision(String numRevision) { this.numRevision = numRevision; } - + public String getDiff() { return diff; } - + public String getHeadCommiter() { return headCommiter; } - + public boolean isSaveCookie() { return saveCookie; } @@ -194,7 +204,7 @@ this.mimeType = mimeType; } - + public boolean isBadLogin() { return badLogin; } @@ -202,168 +212,163 @@ protected boolean isRstValid(String newText) { try { JRST.generate(JRST.TYPE_HTML, newText); - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("RST generate success"); } return true; } catch (Exception e) { - if(log.isErrorEnabled()) { - log.error("RST generate fail",e); + if (log.isErrorEnabled()) { + log.error("RST generate fail", e); } return false; } - - + + } - - - + + public String execute() { - + System.setProperty("file.encoding", "UTF-8"); - - if(!force) { - if(format.equals("rst")) { - if(!isRstValid(newText)) { + + if (!force) { + if (format.equals("rst")) { + if (!isRstValid(newText)) { return "errorRst"; } - } + } } - - - SvnConnection svnConn = null; - - + + + SvnConnection svnConn; + + try { svnConn = new SvnConnection(address); } catch (StringIndexOutOfBoundsException e) { - if(log.isDebugEnabled()) { - log.debug("Parameter is not valid ",e); + if (log.isDebugEnabled()) { + log.debug("Parameter is not valid ", e); } - return "error"; + return "error"; } - - - String login = this.getUsername(); - String password = this.getPw(); - + + + String login = getUsername(); + String password = getPw(); + //Si le repo n'est pas protege en ecriture on recupere sont UUID String repositoryUUID = svnConn.getUUID(); - if (repositoryUUID==null) { - repositoryUUID=address; + if (repositoryUUID == null) { + repositoryUUID = address; } - - + + /* - * Lecture du cookie - */ + * Lecture du cookie + */ String usernamepwCookie = null; // lire cookies - BlowfishCipherService bf = new BlowfishCipherService(); - + BlowfishCipherService bf = new BlowfishCipherService(); + byte[] privateKey = Base64.decode(ScmWebEditorConfig.getKey()); - - for(Cookie c : request.getCookies()) { + + for (Cookie c : request.getCookies()) { if (c.getName().equals(repositoryUUID)) - usernamepwCookie= c.getValue(); + usernamepwCookie = c.getValue(); } - - - if(usernamepwCookie!=null) { - - String usernameDecode = new String( bf.decrypt(Base64.decode(usernamepwCookie), privateKey).getBytes() ); + + if (usernamepwCookie != null) { + + String usernameDecode = new String(bf.decrypt(Base64.decode(usernamepwCookie), privateKey).getBytes()); String[] resCookie = usernameDecode.split(","); - if (resCookie.length==2) { - username=resCookie[0]; - pw=resCookie[1]; + if (resCookie.length == 2) { + username = resCookie[0]; + pw = resCookie[1]; } } - - if(saveCookie) { - if(username!=null && pw!=null) { - Cookie authCookie = new Cookie( repositoryUUID , bf.encrypt( (username+","+pw).getBytes() , privateKey ).toBase64() ); - authCookie.setMaxAge(60*60*24*365); + + if (saveCookie) { + if (username != null && pw != null) { + Cookie authCookie = new Cookie(repositoryUUID, bf.encrypt((username + "," + pw).getBytes(), privateKey).toBase64()); + authCookie.setMaxAge(60 * 60 * 24 * 365); response.addCookie(authCookie); } - + } - - + + /* - * Recuperation des informations d'authentification dans la session - */ - if( ( login==null || login.equals("") ) && ( password==null || password.equals("") ) ) { - if(getScmSession().getUsername(repositoryUUID)!=null && getScmSession().getPassword(repositoryUUID)!=null) { + * Recuperation des informations d'authentification dans la session + */ + if ((login == null || login.equals("")) && (password == null || password.equals(""))) { + if (getScmSession().getUsername(repositoryUUID) != null && getScmSession().getPassword(repositoryUUID) != null) { //On recupère les identifiants en session login = getScmSession().getUsername(repositoryUUID); password = getScmSession().getPassword(repositoryUUID); - } - else { + } else { login = null; password = null; } + } else { + getScmSession().addScmUser(repositoryUUID, login, password); } - else { - getScmSession().addScmUser(repositoryUUID, login , password); - } - - svnConn.updateAuthentication( login, password); - File checkoutdir = null; + svnConn.updateAuthentication(login, password); + + File checkoutdir; try { svnConn.createCheckoutdir(); } catch (IOException e1) { - if(log.isErrorEnabled()) { - log.error("Can't create checkoutDir",e1); + if (log.isErrorEnabled()) { + log.error("Can't create checkoutDir", e1); } return "error"; } checkoutdir = svnConn.getCheckoutdir(); - - + + // Avant le commit, il faut checkout le repertoire try { checkout(svnConn, checkoutdir); } 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 " + svnConn.getRemoteUrl()); - } - //On supprime le repertoire temporaire - delTempDirectory(checkoutdir); + request.setAttribute(PARAMETER_ADDRESS, address); - username = null; - pw = null; - getScmSession().delScmUser(repositoryUUID); - - return Action.LOGIN; - + // if svn authentication failed user is redirected on login page + if (log.isDebugEnabled()) { + log.debug("Private SCM on reading " + svnConn.getRemoteUrl()); + } + //On supprime le repertoire temporaire + delTempDirectory(checkoutdir); + + username = null; + pw = null; + getScmSession().delScmUser(repositoryUUID); + + return LOGIN; + } catch (SVNException e) { - if(log.isErrorEnabled()) { - log.error("Can't checkout the file",e); - } - //Suppression du repertoire temporaire - delTempDirectory(checkoutdir); - return "errorPath"; + if (log.isErrorEnabled()) { + log.error("Can't checkout the file", e); + } + //Suppression du repertoire temporaire + delTempDirectory(checkoutdir); + return ERROR_PATH; } File checkOutFile = new File(checkoutdir, svnConn.getFileName()); - - - lastText=newText; - + + + lastText = newText; + try { String originalText = FileUtils.readFileToString(checkOutFile); - + origText = originalText; - } catch (FileNotFoundException ee) { /* fichier non trouve, on redirige vers BadFileRedirect.jsp @@ -371,133 +376,129 @@ */ delTempDirectory(checkoutdir); - return "error"; + return ERROR; } catch (IOException e) { - log.error("Can't find the checkout file",e); + log.error("Can't find the checkout file", e); } - - - - + + /* - * Diff - */ - if(!force) { + * Diff + */ + if (!force) { try { - - if(svnConn.isDifferent(origText)) { + + if (svnConn.isDifferent(origText)) { ByteArrayOutputStream differents = svnConn.getDiff(newText); - - if(differents.size()>0) { - diff=differents.toString(); + + if (differents.size() > 0) { + diff = differents.toString(); diff = diff.substring(diff.indexOf("@@")); delTempDirectory(checkoutdir); try { - headCommiter=getHeadcommiter(address, login, password); + headCommiter = getHeadcommiter(address, login, password); } catch (SVNException e) { - log.error("Can't get head commiter",e); + log.error("Can't get head commiter", e); } - return "fileModify"; + return FILE_MODIFY; } } - + } catch (IOException e) { - if(log.isErrorEnabled()) { - log.error("Can't do diff on file, IO error",e); + if (log.isErrorEnabled()) { + log.error("Can't do diff on file, IO error", e); } } } - - - + + /* - * Commit process - */ + * Commit process + */ // File pathToFile = new File(checkoutdir, svnConn.getFileName()); SVNCommitClient commitClient = new SVNCommitClient(svnConn.getManager(), svnConn.getSvnOption()); - + File pathToFile = new File(checkoutdir, svnConn.getFileName()); - - + + try { FileUtil.writeString(pathToFile, newText, "UTF-8"); } catch (IOException e1) { delTempDirectory(checkoutdir); - return "error"; + return ERROR; } - - + + File[] tabFile = new File[1]; tabFile[0] = pathToFile; try { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("Try to commit"); } - commitClient.doCommit(tabFile, false, "From scmwebeditor -- "+commitMessage, null, null, false, false, SVNDepth.FILES); + commitClient.doCommit(tabFile, false, "From scmwebeditor -- " + commitMessage, null, null, false, false, SVNDepth.FILES); } catch (SVNAuthenticationException authexep) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("AUTH FAIL"); } // if authentication failed edition page is reload form user's relogin - + origText = newText; badLogin = true; - + //Suppression du repertoire temporaire delTempDirectory(checkoutdir); username = null; pw = null; //on supprime la valeur stocke en session getScmSession().delScmUser(repositoryUUID); - return Action.LOGIN; + return LOGIN; } catch (SVNException e) { - if(log.isErrorEnabled()) { - log.error("SVN FAIL",e); + if (log.isErrorEnabled()) { + log.error("SVN FAIL", e); } //Suppression du repertoire temporaire delTempDirectory(checkoutdir); return "error"; } - - + + if (checkoutdir != null) { //Suppression du repertoire temporaire delTempDirectory(checkoutdir); } - - if(log.isDebugEnabled()) { + + if (log.isDebugEnabled()) { log.debug("End of commit"); } //Suppression du repertoire temporaire delTempDirectory(checkoutdir); - - if(log.isInfoEnabled()) { - log.info(login + " with IP "+request.getRemoteAddr()+" commit the file "+address+" with message : "+commitMessage); + + if (log.isInfoEnabled()) { + log.info(login + " with IP " + request.getRemoteAddr() + " commit the file " + address + " with message : " + commitMessage); } - + try { - numRevision=getHeadNumberRevision(address, login, password); + numRevision = getHeadNumberRevision(address, login, password); } catch (SVNException e) { - numRevision=null; + numRevision = null; } - - return "success"; + + return SUCCESS; } - @Override public void setServletRequest(HttpServletRequest request) { - this.request = request; + this.request = request; } @Override public void setServletResponse(HttpServletResponse response) { - this.response = response; + this.response = response; } } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-08-26 15:09:03 UTC (rev 248) @@ -24,13 +24,6 @@ */ package org.nuiton.scmwebeditor.actions; -import java.io.IOException; -import java.util.LinkedList; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.shiro.codec.Base64; @@ -43,54 +36,62 @@ import org.tmatesoft.svn.core.SVNAuthenticationException; import org.tmatesoft.svn.core.SVNException; -import com.opensymphony.xwork2.Action; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.LinkedList; -public class ScmWebEditorMainAction extends ScmWebEditorBaseAction implements ServletRequestAware, ServletResponseAware { +public class ScmWebEditorMainAction extends ScmWebEditorBaseAction implements ServletRequestAware, ServletResponseAware { private static final long serialVersionUID = 8361035067228171624L; private static final Log log = LogFactory.getLog(ScmWebEditorMainAction.class); - + + public static final String NO_PARAMETER = "noParameter"; + + public static final String EDIT_PAGE = "editPage"; + protected String address; + protected String projectUrl; + protected String format; + protected String origText; + protected String mimeType; - - + protected boolean saveCookie = true; - protected boolean badLogin = false; - + + protected boolean badLogin; + protected String numRevision; - protected String addressSvn; - - public String getAddressSvn() { - return addressSvn; - } + protected String username; - public void setAddressSvn(String addressSvn) { - this.addressSvn = addressSvn; - } + protected String pw; + protected transient HttpServletRequest request; - protected String username; - protected String pw; - - protected HttpServletRequest request; - - protected HttpServletResponse response; + protected transient HttpServletResponse response; - protected String repositoryId; protected boolean fromLoginPage; - - + + public String getAddressSvn() { + return addressSvn; + } + + public void setAddressSvn(String addressSvn) { + this.addressSvn = addressSvn; + } + public String getMimeType() { return mimeType; } @@ -99,55 +100,46 @@ return repositoryId; } - public void setRepositoryId(String repositoryId) { this.repositoryId = repositoryId; } - 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 getAddress() { return address; } - public void setAddress(String address) { this.address = address; } - + public String getFormat() { return format; } - public void setFormat(String format) { this.format = format; } - public String getOrigText() { return origText; } - public String getProjectUrl() { return projectUrl; } @@ -158,8 +150,7 @@ public void setProjectUrl(String projectUrl) { this.projectUrl = projectUrl; - } - + } public void setFromLoginPage(boolean fromLoginPage) { this.fromLoginPage = fromLoginPage; @@ -169,62 +160,57 @@ return badLogin; } - /** * On test si les parametres ne sont pas vide + * * @return */ private boolean testParameters() { if (address == null || address.length() == 0) { return true; - } - else { + } else { return false; } } - -// public void prepare() { -// -// } - + /** * Methode principale de la classe + * * @return */ + @Override public String execute() { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("Connection to SCMWebEditor\n"); - } - - - + } + + /* Si il n'y a pas de parametre, l'utilisateur est renvoyé - * vers la page de configuration (OutConnection) - */ + * vers la page de configuration (OutConnection) + */ // if(testParameters()) { // return "noParameter"; // } - - - if(!this.fromLoginPage && projectUrl==null) { - projectUrl=request.getHeader("referer"); + + + if (!fromLoginPage && projectUrl == null) { + projectUrl = request.getHeader("referer"); } - - - if(log.isDebugEnabled()) { - log.debug("ProjectUrl= "+projectUrl); + + + if (log.isDebugEnabled()) { + log.debug("ProjectUrl= " + projectUrl); } - - - + + // Map<?,?> map =(Map<?,?>) request.getParameterMap(); - - if(testParameters()) { - return "noParameter"; + + if (testParameters()) { + return NO_PARAMETER; } - - + + // if(testParameters()) { // // Map<String,String> parameters = new HashMap<String,String>(); @@ -256,208 +242,192 @@ // address=urlSvn.toString(); // // } - - - SvnConnection svnConn = null; - + + SvnConnection svnConn; + + try { svnConn = new SvnConnection(address); - } - catch (StringIndexOutOfBoundsException e) { - if(log.isDebugEnabled()) { - log.debug("Parameter is not valid ",e); + } catch (StringIndexOutOfBoundsException e) { + if (log.isDebugEnabled()) { + log.debug("Parameter is not valid ", e); } - return "errorPath"; + return ERROR_PATH; } - - - format = svnConn.getFileName().substring(svnConn.getFileName().lastIndexOf(".")+1); - - String originalText = ""; - + + + format = svnConn.getFileName().substring(svnConn.getFileName().lastIndexOf(".") + 1); + + String originalText; + //Si le repo n'est pas protege en ecriture on recupere sont UUID String repositoryUUID = svnConn.getUUID(); - if (repositoryUUID==null) { - repositoryUUID=address; + if (repositoryUUID == null) { + repositoryUUID = address; } - - if(log.isDebugEnabled()) { - log.debug("Login : "+username); + + if (log.isDebugEnabled()) { + log.debug("Login : " + username); } - + /* - * Lecture du cookie - */ - - + * Lecture du cookie + */ + + String usernamepwCookie = null; // lire cookies - - BlowfishCipherService bf = new BlowfishCipherService(); - + + BlowfishCipherService bf = new BlowfishCipherService(); + byte[] privateKey = Base64.decode(ScmWebEditorConfig.getKey()); - - for(Cookie c : request.getCookies()) { + + for (Cookie c : request.getCookies()) { if (c.getName().equals(repositoryUUID)) - usernamepwCookie= c.getValue(); + usernamepwCookie = c.getValue(); } - if(usernamepwCookie!=null) { - - String usernameDecode = new String( bf.decrypt(Base64.decode(usernamepwCookie), privateKey).getBytes() ); - + if (usernamepwCookie != null) { + + String usernameDecode = new String(bf.decrypt(Base64.decode(usernamepwCookie), privateKey).getBytes()); + String[] resCookie = usernameDecode.split(","); - if (resCookie.length==2) { - username=resCookie[0]; - pw=resCookie[1]; + if (resCookie.length == 2) { + username = resCookie[0]; + pw = resCookie[1]; } } - - if(saveCookie) { - if(username!=null && pw!=null) { - - Cookie authCookie = new Cookie( repositoryUUID , bf.encrypt( (username+","+pw).getBytes() , privateKey ).toBase64() ); - authCookie.setMaxAge(60*60*24*365); + + if (saveCookie) { + if (username != null && pw != null) { + + Cookie authCookie = new Cookie(repositoryUUID, bf.encrypt((username + "," + pw).getBytes(), privateKey).toBase64()); + authCookie.setMaxAge(60 * 60 * 24 * 365); response.addCookie(authCookie); } - + } - - + + /* - * Récuperation des informations en session - */ - if(username==null && pw==null) { - if(getScmSession().getUsername(repositoryUUID)!=null && getScmSession().getPassword(repositoryUUID)!=null) { + * Récuperation des informations en session + */ + if (username == null && pw == null) { + if (getScmSession().getUsername(repositoryUUID) != null && getScmSession().getPassword(repositoryUUID) != null) { //On recupère les identifiants en session username = getScmSession().getUsername(repositoryUUID); pw = getScmSession().getPassword(repositoryUUID); - } - else { + } else { username = null; pw = null; } + } else { + getScmSession().addScmUser(repositoryUUID, username, pw); } - else { - getScmSession().addScmUser(repositoryUUID, username , pw); - } - - + + svnConn.updateAuthentication(username, pw); - /* - * Recuperation du fichier et de sa revision - */ + * Recuperation du fichier et de sa revision + */ try { originalText = getHeadRevision(address, username, pw); numRevision = getHeadNumberRevision(address, username, pw); - + } catch (SVNAuthenticationException authexep) { - + request.setAttribute(PARAMETER_ADDRESS, address); - + // if svn authentication failed user is redirected on login page - if(log.isDebugEnabled()) { - log.debug("Auth Fail " ,authexep); + if (log.isDebugEnabled()) { + log.debug("Auth Fail ", authexep); } - + //suppression des cookies pour ce dépot for (Cookie c : request.getCookies()) { - if(c.getName().equals(repositoryUUID)) { + if (c.getName().equals(repositoryUUID)) { c.setMaxAge(0);//On supprime le cookie response.addCookie(c); - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("Cookie supprimé"); } } - } - + } + getScmSession().delScmUser(repositoryUUID); //redirect to a login page - return Action.LOGIN; - - } catch (SVNException e) { + return LOGIN; + + } catch (SVNException e) { request.setAttribute("projectUrl", projectUrl); - - if(log.isErrorEnabled()) { - log.error("SVN error ",e); + + if (log.isErrorEnabled()) { + log.error("SVN error ", e); } - return "errorPath"; - } catch (IllegalArgumentException e) { - request.setAttribute("projectUrl", projectUrl); - - if(log.isDebugEnabled()) { - log.debug("SVN error debug",e); - } - return "errorPath"; - } - - - - - - mimeType =null; - + return ERROR_PATH; + } catch (IllegalArgumentException e) { + request.setAttribute("projectUrl", projectUrl); + + if (log.isDebugEnabled()) { + log.debug("SVN error debug", e); + } + return ERROR_PATH; + } + + mimeType = null; + try { mimeType = getMimeType(originalText, svnConn.getFileName()); } catch (IOException e) { - if(log.isErrorEnabled()) { - log.error("Can't get MimeType, problem when reading file",e); + if (log.isErrorEnabled()) { + log.error("Can't get MimeType, problem when reading file", e); } - } + } - LinkedList<String> editableFiles = new LinkedList<String>(); - - editableFiles.add("text"); + + editableFiles.add("text"); editableFiles.add("xml"); editableFiles.add("x-java"); - + editableFiles.addAll(ScmWebEditorConfig.getEditableFiles()); - - - boolean editable =false; - if(mimeType!=null ) { - for (String fileType : editableFiles){ - if (mimeType.matches(".*"+fileType+".*")) { - editable=true; + + boolean editable = false; + if (mimeType != null) { + for (String fileType : editableFiles) { + if (mimeType.matches(".*" + fileType + ".*")) { + editable = true; } } } - - - + + // Si le fichier n'est pas de type texte, on ne peut pas l'éditer - if(mimeType==null || editable==false ) { - - if(log.isErrorEnabled()) { - log.error("Can't edit this file, mimetype : "+mimeType); + if (mimeType == null || !editable) { + + if (log.isErrorEnabled()) { + log.error("Can't edit this file, mimetype : " + mimeType); } - return "errorPath"; + return ERROR_PATH; } - - origText=originalText; + origText = originalText; - - if(log.isInfoEnabled()) { - log.info("IP client : "+request.getRemoteAddr() + " , get file : "+address+ ". File's mimetype : "+mimeType); + + if (log.isInfoEnabled()) { + log.info("IP client : " + request.getRemoteAddr() + " , get file : " + address + ". File's mimetype : " + mimeType); } - - - - return "editPage"; - + return EDIT_PAGE; + } - @Override public void setServletRequest(HttpServletRequest request) { this.request = request; @@ -470,8 +440,4 @@ } - - - - } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java 2011-08-26 15:09:03 UTC (rev 248) @@ -24,17 +24,7 @@ */ package org.nuiton.scmwebeditor.actions; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - import com.jgeppert.struts2.jquery.tree.result.TreeNode; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.scmwebeditor.ScmWebEditorBaseAction; @@ -45,97 +35,92 @@ import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; - 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; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; public class SearchAction extends ScmWebEditorBaseAction { - private static final long serialVersionUID = 4432027215087932750L; - private static final Log log = LogFactory.getLog(SearchAction.class); - - - String address; - LinkedList<String> files; - Map<String,String> directories; - String username; - String pw; - String error; - - - - int numberOfFile; - String info; - String list; - - + protected String address; + + protected List<String> files; + + protected Map<String, String> directories; + + protected String username; + + protected String pw; + + protected String error; + + protected int numberOfFile; + + protected String info; + + protected String list; + protected List<TreeNode> nodes = new ArrayList<TreeNode>(); + protected String id = ""; - - public String getError() { return error; } - - + public String getList() { return list; } - public void setList(String list) { this.list = list; } - - public LinkedList<String> getFiles() { + public List<String> getFiles() { return files; } - - - public Map<String,String> getDirectories() { + + public Map<String, String> getDirectories() { return directories; } - public String getInfo() { return info; } - public String getAddress() { return address; } - + public void setAddress(String address) { this.address = address; } - + 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; } @@ -144,243 +129,223 @@ return numberOfFile; } - public String search() { - - if(log.isDebugEnabled()) { + + if (log.isDebugEnabled()) { log.debug("Enter in search action"); } - - - + + DAVRepositoryFactory.setup(); - String url = ""; - - - + String url; + + String name = "anonymous"; - String password="anonymous"; - - if(username!=null && pw!=null) { + String password = "anonymous"; + + if (username != null && pw != null) { name = username; - password=pw; + password = pw; } - - - - - - if(address.endsWith("/")) { - address = address.substring(0, address.length()-1); + if (address.endsWith("/")) { + address = address.substring(0, address.length() - 1); } - - - SVNRepository repository = null; - ISVNAuthenticationManager authManager = null; - - - if(id.equals("")) { - + + + SVNRepository repository; + ISVNAuthenticationManager authManager; + + + if (id.equals("")) { + try { - if(log.isDebugEnabled()) { - log.debug("Address svn : "+address); + if (log.isDebugEnabled()) { + log.debug("Address svn : " + address); } - repository = SVNRepositoryFactory.create( SVNURL.parseURIDecoded( address ) ); - authManager = SVNWCUtil.createDefaultAuthenticationManager( name , password ); - repository.setAuthenticationManager( authManager ); - + repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(address)); + authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password); + repository.setAuthenticationManager(authManager); + repository.testConnection(); - + } catch (SVNAuthenticationException e) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("Can't access to the repository : Auth Problem"); } return "authError"; } catch (SVNException e) { - if(log.isErrorEnabled()) { - log.error("Can't access to the repository",e); - } - error="Can't access to the repository"; - } + if (log.isErrorEnabled()) { + log.error("Can't access to the repository", e); + } + error = "Can't access to the repository"; + } return "root"; + } else if (id.equals("0")) { + url = address; + } else { + url = id; + address = id; } - else if(id.equals("0")) { - url=address; - } - else { - url=id; - address=id; - } - + try { - repository = SVNRepositoryFactory.create( SVNURL.parseURIDecoded( url ) ); - authManager = SVNWCUtil.createDefaultAuthenticationManager( name , password ); - repository.setAuthenticationManager( authManager ); - - if(log.isDebugEnabled()) { - log.debug( "Repository Root: " + repository.getRepositoryRoot( true ) ); - log.debug( "Repository UUID: " + repository.getRepositoryUUID( true ) ); + repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url)); + authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password); + repository.setAuthenticationManager(authManager); + + if (log.isDebugEnabled()) { + log.debug("Repository Root: " + repository.getRepositoryRoot(true)); + log.debug("Repository UUID: " + repository.getRepositoryUUID(true)); } - - SVNNodeKind nodeKind = repository.checkPath( "" , -1 ); - if ( nodeKind == SVNNodeKind.NONE ) { - if(log.isWarnEnabled()) { - log.warn( "There is no entry at '" + url + "'." ); + + SVNNodeKind nodeKind = repository.checkPath("", -1); + if (nodeKind == SVNNodeKind.NONE) { + if (log.isWarnEnabled()) { + log.warn("There is no entry at '" + url + "'."); } - error="There is no entry at '" + url + "'."; - return Action.SUCCESS; - } else if ( nodeKind == SVNNodeKind.FILE ) { - if(log.isDebugEnabled()) { - log.debug( "The entry at '" + url + "' is a file." ); + error = "There is no entry at '" + url + "'."; + return SUCCESS; + } else if (nodeKind == SVNNodeKind.FILE) { + if (log.isDebugEnabled()) { + log.debug("The entry at '" + url + "' is a file."); } TreeNode node = new TreeNode(); node.setId(url); - node.setTitle(url.substring(url.lastIndexOf("/")+1)); + node.setTitle(url.substring(url.lastIndexOf("/") + 1)); node.setState(TreeNode.NODE_STATE_LEAF); node.setIcon("ui-icon-document"); nodes.add(node); - return Action.SUCCESS; + return SUCCESS; } - numberOfFile=0; - listEntries( repository , "" ); - if(log.isDebugEnabled()) { - log.debug("Number of file : "+files.size()); + numberOfFile = 0; + listEntries(repository, ""); + if (log.isDebugEnabled()) { + log.debug("Number of file : " + files.size()); } - - - for (String file : files ) { + + for (String file : files) { TreeNode node = new TreeNode(); node.setId(file); - node.setTitle(file.substring(file.lastIndexOf("/")+1)); + node.setTitle(file.substring(file.lastIndexOf("/") + 1)); node.setState(TreeNode.NODE_STATE_LEAF); node.setIcon("ui-icon-document"); nodes.add(node); } - - + + Iterator<Entry<String, String>> iter1 = directories.entrySet().iterator(); while (iter1.hasNext()) { - Map.Entry<String,String> ent = (Map.Entry<String,String>) iter1.next(); + Map.Entry<String, String> ent = (Map.Entry<String, String>) iter1.next(); String value = ent.getValue(); - + TreeNode node = new TreeNode(); node.setId(value); node.setTitle(value.substring(value.lastIndexOf("/"))); nodes.add(node); - - + + //Traitement } - - - + + } catch (SVNAuthenticationException authexep) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("Can't access to the repository : Auth Problem"); } return "authError"; - } - catch ( SVNException svne ) { - if(log.isErrorEnabled()) { - log.error("Can't access to the repository"); + } catch (SVNException svne) { + if (log.isErrorEnabled()) { + log.error("Can't access to the repository"); } - error="Can't access to the repository"; + error = "Can't access to the repository"; } - - if(log.isDebugEnabled()) { + + if (log.isDebugEnabled()) { log.debug("Search success"); } - - return Action.SUCCESS; + + return SUCCESS; } - - - public void listEntries( SVNRepository repository, String path ) { - + + + public void listEntries(SVNRepository repository, String path) { + files = new LinkedList<String>(); - directories = new HashMap<String,String>(); - + directories = new HashMap<String, String>(); + Collection<?> entries = null; try { - entries = repository.getDir( path, -1 , null , (Collection<?>) null ); + entries = repository.getDir(path, -1, null, (Collection<?>) null); } catch (SVNException e) { - if(log.isErrorEnabled()) { - log.error("Can not reach the repository",e); + if (log.isErrorEnabled()) { + log.error("Can not reach the repository", e); } } Iterator<?> iterator = entries.iterator(); - - + + while (iterator.hasNext()) { SVNDirEntry entry = (SVNDirEntry) iterator.next(); - if(log.isDebugEnabled()) { - log.debug("/" + (path.equals("") ? "" : path + "/") + entry.getName()+ "\n"); + if (log.isDebugEnabled()) { + log.debug("/" + (path.equals("") ? "" : path + "/") + entry.getName() + "\n"); } - String fichier = address+"/" + (path.equals("") ? "" : path + "/") + entry.getName(); - - - if ( entry.getKind() == SVNNodeKind.DIR ) { - directories.put(getAddressUnique(fichier),fichier); - + String fichier = address + "/" + (path.equals("") ? "" : path + "/") + entry.getName(); + + + if (entry.getKind() == SVNNodeKind.DIR) { + directories.put(getAddressUnique(fichier), fichier); + //listEntries(repository, (path.equals("")) ? entry.getName() : path + "/" + entry.getName()); - } - else { + } else { // On ajoute dans la liste files seulement les fichiers et pas les répertoires files.add(fichier); } } - + } - - - + public String getJSON() { return search(); } - + public List<TreeNode> getNodes() { return nodes; } - + public void setId(String id) { - this.id=id; + this.id = id; } - - - + + public String getAddressUnique(String leFichier) { String result = leFichier.replaceAll("/|:", ""); - if(log.isDebugEnabled()) { - log.debug("Result of getAddressUnique : "+result); + if (log.isDebugEnabled()) { + log.debug("Result of getAddressUnique : " + result); } return result; } - - - + + public static String replaceLast(String string, String toReplace, String replacement) { int pos = string.lastIndexOf(toReplace); if (pos > -1) { return string.substring(0, pos) - + replacement - + string.substring(pos + toReplace.length(), string.length()); + + replacement + + string.substring(pos + toReplace.length(), string.length()); } else { return string; } } - - - + } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java 2011-08-26 15:09:03 UTC (rev 248) @@ -24,12 +24,6 @@ */ package org.nuiton.scmwebeditor.actions; -import java.io.File; - -import java.io.IOException; - -import javax.servlet.http.HttpServletRequest; - import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -44,312 +38,306 @@ import org.tmatesoft.svn.core.wc.SVNRevision; import org.tmatesoft.svn.core.wc.SVNUpdateClient; -import com.opensymphony.xwork2.Action; +import javax.servlet.http.HttpServletRequest; +import java.io.File; +import java.io.IOException; public class UploadAction extends ScmWebEditorBaseAction implements ServletRequestAware { - /** - * - */ private static final long serialVersionUID = 4244339447567114412L; + private static final Log log = LogFactory.getLog(UploadAction.class); + + public static final String REDIRECT = "redirect"; + protected File upload; + protected String uploadFileName; + protected String uploadContentType; + protected String username; + protected String pw; + protected String svnPath; + protected String address; + protected String svnRoot; + protected String fileRoot; - + protected boolean badLogin; + protected boolean error; - - protected HttpServletRequest request; - - + + protected transient HttpServletRequest request; + public String getSvnPath() { return svnPath; } + public void setSvnPath(String svnPath) { this.svnPath = svnPath; } + public File getUpload() { return upload; } + public void setUpload(File upload) { this.upload = upload; } + public String getUploadContentType() { return uploadContentType; } + public void setUploadContentType(String uploadContentType) { this.uploadContentType = uploadContentType; } + public String getUploadFileName() { return uploadFileName; } + public void setUploadFileName(String uploadFileName) { this.uploadFileName = uploadFileName; } + 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 void setAddress(String address) { this.address = address; } - + public String getAddress() { - return this.address; + return address; } public boolean isBadLogin() { return badLogin; } + public boolean isError() { return error; } - + public String getSvnRoot() { return svnRoot; } - + public String getFileRoot() { return fileRoot; } - - -// public void prepare() { -// -// } - - + public String execute() { - + SvnConnection svnConnection = new SvnConnection(address); svnRoot = svnConnection.getSvnRoot(); - + fileRoot = svnConnection.getSvnPath(); - - if(svnRoot==null) { - svnRoot=fileRoot; + + if (svnRoot == null) { + svnRoot = fileRoot; } - - - - SvnConnection svnConn = null; + + SvnConnection svnConn; + try { svnConn = new SvnConnection(address); - } - catch (StringIndexOutOfBoundsException e) { - if(log.isErrorEnabled()) { - log.error("error when creating SvnSession in UploadAction",e); + } catch (StringIndexOutOfBoundsException e) { + if (log.isErrorEnabled()) { + log.error("error when creating SvnSession in UploadAction", e); } - error=true; - return "error"; + error = true; + return ERROR; } - - - + + //Si le repo n'est pas protege en ecriture on recupere sont UUID String repositoryUUID = svnConn.getUUID(); - if (repositoryUUID==null) { - repositoryUUID=address; + if (repositoryUUID == null) { + repositoryUUID = address; } - - - if(username==null && pw==null) { - if(getScmSession().getUsername(repositoryUUID)!=null && getScmSession().getPassword(repositoryUUID)!=null) { + + + if (username == null && pw == null) { + if (getScmSession().getUsername(repositoryUUID) != null && getScmSession().getPassword(repositoryUUID) != null) { //On recupère les identifiants en session username = getScmSession().getUsername(repositoryUUID); pw = getScmSession().getPassword(repositoryUUID); - } - else { + } else { username = null; pw = null; } + } else { + getScmSession().addScmUser(repositoryUUID, username, pw); } - else { - getScmSession().addScmUser(repositoryUUID, username , pw); - } - - svnConn.updateAuthentication( username, pw); - + + svnConn.updateAuthentication(username, pw); + try { svnConn.testConnection(); } catch (SVNException e) { - if(log.isDebugEnabled()) { - log.debug("Test connection fail",e); + if (log.isDebugEnabled()) { + log.debug("Test connection fail", e); } getScmSession().delScmUser(repositoryUUID); username = null; pw = null; } - - - + + //Si il n'y a pas de fichier à uploader on retourne sur le formulaire d'upload - if(upload==null) { - return "redirect"; + if (upload == null) { + return REDIRECT; } - - badLogin=false; - error=false; - - if(log.isDebugEnabled()) { - log.debug("FileName : "+uploadFileName); - log.debug("ContentType : "+uploadContentType); - } + badLogin = false; + error = false; + if (log.isDebugEnabled()) { + log.debug("FileName : " + uploadFileName); + log.debug("ContentType : " + uploadContentType); + } - - - /* - * Checkout process - */ + /* + * Checkout process + */ SVNUpdateClient upclient = new SVNUpdateClient(svnConn.getManager(), svnConn.getSvnOption()); - - File checkoutDir = null; + + File checkoutDir; try { svnConn.createCheckoutdir(); checkoutDir = svnConn.getCheckoutdir(); } catch (IOException e1) { - if(log.isErrorEnabled()) { - log.error("Can't create checkoutDir",e1); + if (log.isErrorEnabled()) { + log.error("Can't create checkoutDir", e1); } - error=true; - return "error"; + error = true; + return ERROR; } - - - - - + + try { if (log.isDebugEnabled()) { log.debug("Do Checkout of " + svnRoot); } upclient.doCheckout(SVNURL.parseURIEncoded(svnRoot), checkoutDir, - SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, false); + SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, false); } catch (SVNAuthenticationException authexep) { - + // if svn authentication failed user is redirected on login page - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("Private SCM on reading " + svnConn.getRemoteUrl()); } //On supprime le repertoire temporaire delTempDirectory(checkoutDir); //redirect to a login page - error=true; - return "error"; - + error = true; + return ERROR; + } catch (SVNException e) { //Suppression du repertoire temporaire delTempDirectory(checkoutDir); - error=true; - return "error"; + error = true; + return ERROR; } - - - - //On test si le chemin se termine par un / si non, on l'ajoute - if(!svnPath.endsWith("/")) { - svnPath+=("/"); + if (!svnPath.endsWith("/")) { + svnPath += "/"; } - - + + //Copy file in checkourdir - + String checkoutPath = checkoutDir.getAbsolutePath(); - - File file = new File(checkoutPath+svnPath.replace(svnRoot, ""),uploadFileName); - + + File file = new File(checkoutPath + svnPath.replace(svnRoot, ""), uploadFileName); + try { FileUtils.copyFile(upload, file); } catch (IOException e) { - error=true; - if(log.isErrorEnabled()) { - log.error("Can't copy the file to the checkout directory",e); + error = true; + if (log.isErrorEnabled()) { + log.error("Can't copy the file to the checkout directory", e); } return ERROR; } - - - + //Commit process SVNClientManager manager = svnConn.getManager(); - + try { - if(log.isDebugEnabled()) { - log.debug("leSvnPath : "+file.toString()); + if (log.isDebugEnabled()) { + log.debug("leSvnPath : " + file.toString()); } - + //On ajoute le repertoire - manager.getWCClient().doAdd( file , false , false , false , SVNDepth.EMPTY, false, true ); - if(log.isDebugEnabled()) { + manager.getWCClient().doAdd(file, false, false, false, SVNDepth.EMPTY, false, true); + if (log.isDebugEnabled()) { log.debug("Add success !"); } //On ajoute le fichier aux fichiers versionnés - - } - catch (SVNException e) { - if(log.isErrorEnabled()){ - log.error("Erreur SVN Add",e); + + } catch (SVNException e) { + if (log.isErrorEnabled()) { + log.error("Erreur SVN Add", e); } - error=true; + error = true; //Suppression du repertoire temporaire delTempDirectory(checkoutDir); - return Action.ERROR; + return ERROR; } - - - File[] checkoutDirTab = new File[1]; - checkoutDirTab[0] = checkoutDir; - + File[] checkoutDirTab = new File[1]; + checkoutDirTab[0] = checkoutDir; + try { - manager.getCommitClient().doCommit(checkoutDirTab, false, "From scmwebeditor -- add the file : "+uploadFileName, null, null, false, true, SVNDepth.INFINITY); - - if(log.isDebugEnabled()) { + manager.getCommitClient().doCommit(checkoutDirTab, false, "From scmwebeditor -- add the file : " + uploadFileName, null, null, false, true, SVNDepth.INFINITY); + + if (log.isDebugEnabled()) { log.debug("Commit success !"); } - + } catch (SVNAuthenticationException authexep) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("authentification fail"); } - badLogin=true; + badLogin = true; //Suppression du repertoire temporaire delTempDirectory(checkoutDir); getScmSession().delScmUser(repositoryUUID); - return Action.LOGIN; - } - catch (SVNException e) { - if(log.isErrorEnabled()) { - log.error("Erreur SVN commit",e); + return LOGIN; + } catch (SVNException e) { + if (log.isErrorEnabled()) { + log.error("Erreur SVN commit", e); } - error=true; + error = true; //Suppression du repertoire temporaire delTempDirectory(checkoutDir); return ERROR; @@ -358,27 +346,19 @@ //Suppression du repertoire temporaire delTempDirectory(checkoutDir); - - if(log.isDebugEnabled()) { + + if (log.isDebugEnabled()) { log.debug("File upload successful"); } - - if(log.isInfoEnabled()) { - log.info(username + " with IP "+request.getRemoteAddr()+" add the file "+this.getUploadFileName()+" on the repository."); - } + + if (log.isInfoEnabled()) { + log.info(username + " with IP " + request.getRemoteAddr() + " add the file " + getUploadFileName() + " on the repository."); + } return SUCCESS; - - } - - - - + @Override public void setServletRequest(HttpServletRequest request) { - this.request=request; + this.request = request; } - - - } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/ScmUrlResolver.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/ScmUrlResolver.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/ScmUrlResolver.java 2011-08-26 15:09:03 UTC (rev 248) @@ -32,6 +32,6 @@ String getLayoutName(); - URL resolv(Map<String, String> parameters) throws IOException; - + URL resolv(Map<String, String> parameters) throws IOException; + } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/ScmUrlResolverEngine.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/ScmUrlResolverEngine.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/ScmUrlResolverEngine.java 2011-08-26 15:09:03 UTC (rev 248) @@ -24,6 +24,9 @@ */ package org.nuiton.scmwebeditor.urlResolver; +import org.apache.commons.lang.StringUtils; +import org.nuiton.scmwebeditor.urlResolver.impl.ScmUrlResolverDefaultImpl; + import java.io.IOException; import java.net.URL; import java.util.ArrayList; @@ -31,13 +34,10 @@ import java.util.Map; import java.util.ServiceLoader; -import org.apache.commons.lang.StringUtils; -import org.nuiton.scmwebeditor.urlResolver.impl.ScmUrlResolverDefaultImpl; - public class ScmUrlResolverEngine { public static final String PARAMETER_SCM_LAYOUT = "scmlayout"; - + static final ThreadLocal<ScmUrlResolverEngine> engine = new ThreadLocal<ScmUrlResolverEngine>() { @Override Modified: trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/impl/ScmUrlResolverDefaultImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/impl/ScmUrlResolverDefaultImpl.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/impl/ScmUrlResolverDefaultImpl.java 2011-08-26 15:09:03 UTC (rev 248) @@ -24,13 +24,13 @@ */ package org.nuiton.scmwebeditor.urlResolver.impl; +import org.apache.commons.lang.StringUtils; +import org.nuiton.scmwebeditor.urlResolver.ScmUrlResolver; + import java.io.IOException; import java.net.URL; import java.util.Map; -import org.apache.commons.lang.StringUtils; -import org.nuiton.scmwebeditor.urlResolver.ScmUrlResolver; - public class ScmUrlResolverDefaultImpl implements ScmUrlResolver { public static final String DEFAULT_NAME = "default"; @@ -52,7 +52,7 @@ } return new URL(result); } - + } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/impl/ScmUrlResolverMavenDocImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/impl/ScmUrlResolverMavenDocImpl.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/impl/ScmUrlResolverMavenDocImpl.java 2011-08-26 15:09:03 UTC (rev 248) @@ -24,24 +24,28 @@ */ package org.nuiton.scmwebeditor.urlResolver.impl; +import org.apache.commons.lang.StringUtils; +import org.nuiton.scmwebeditor.urlResolver.ScmUrlResolver; + import java.io.IOException; import java.net.URL; import java.util.Map; -import org.apache.commons.lang.StringUtils; -import org.nuiton.scmwebeditor.urlResolver.ScmUrlResolver; - public class ScmUrlResolverMavenDocImpl implements ScmUrlResolver { public static final String MAVEN_SITE_DOCUMENT_NAME = "maven-site-document"; - + public static final String PARAMETER_DEFAULT_LOCALE = "svndefaultLocale"; + public static final String PARAMETER_LOCALE = "svnlocale"; + public static final String PARAMETER_SVN_ROOT = "svnroot"; + public static final String PARAMETER_SVN_FILE = "svnfile"; + public static final String PARAMETER_FILE_FORMAT = "svnformat"; - - + + @Override public String getLayoutName() { return MAVEN_SITE_DOCUMENT_NAME; @@ -55,27 +59,25 @@ String svnRoot = parameters.get(PARAMETER_SVN_ROOT); String svnFile = parameters.get(PARAMETER_SVN_FILE); String svnFormat = parameters.get(PARAMETER_FILE_FORMAT); - - if ( StringUtils.isEmpty(defaultLocale) || StringUtils.isEmpty(locale) || StringUtils.isEmpty(svnRoot) - || StringUtils.isEmpty(svnFile) || StringUtils.isEmpty(svnFormat) ) { + + if (StringUtils.isEmpty(defaultLocale) || StringUtils.isEmpty(locale) || StringUtils.isEmpty(svnRoot) + || StringUtils.isEmpty(svnFile) || StringUtils.isEmpty(svnFormat)) { throw new IllegalArgumentException( "Layout " + MAVEN_SITE_DOCUMENT_NAME + " requires five parameters '" + - PARAMETER_DEFAULT_LOCALE + "', '"+PARAMETER_LOCALE+"' , '"+PARAMETER_SVN_ROOT+"' , '"+PARAMETER_SVN_FILE+"' , '"+PARAMETER_FILE_FORMAT+"'"); + PARAMETER_DEFAULT_LOCALE + "', '" + PARAMETER_LOCALE + "' , '" + PARAMETER_SVN_ROOT + "' , '" + PARAMETER_SVN_FILE + "' , '" + PARAMETER_FILE_FORMAT + "'"); } - - String result = ""; - if(locale.equals(defaultLocale)) { - result = svnRoot+"/src/site/"+svnFormat+"/"+svnFile; + String result; + + if (locale.equals(defaultLocale)) { + result = svnRoot + "/src/site/" + svnFormat + "/" + svnFile; + } else { + result = svnRoot + "/src/site/" + locale + "/" + svnFormat + "/" + svnFile; } - else { - result = svnRoot+"/src/site/"+locale+"/"+svnFormat+"/"+svnFile; - } - - - + + return new URL(result); - + } } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/impl/ScmUrlResolverMavenSiteXmlImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/impl/ScmUrlResolverMavenSiteXmlImpl.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/main/java/org/nuiton/scmwebeditor/urlResolver/impl/ScmUrlResolverMavenSiteXmlImpl.java 2011-08-26 15:09:03 UTC (rev 248) @@ -24,22 +24,22 @@ */ package org.nuiton.scmwebeditor.urlResolver.impl; +import org.apache.commons.lang.StringUtils; +import org.nuiton.scmwebeditor.urlResolver.ScmUrlResolver; + import java.io.IOException; import java.net.URL; import java.util.Map; -import org.apache.commons.lang.StringUtils; -import org.nuiton.scmwebeditor.urlResolver.ScmUrlResolver; - public class ScmUrlResolverMavenSiteXmlImpl implements ScmUrlResolver { public static final String MAVEN_SITE_XML_NAME = "maven-site.xml"; - + public static final String PARAMETER_LOCALE = "svnlocale"; + public static final String PARAMETER_SVN_ROOT = "svnroot"; - - - + + @Override public String getLayoutName() { return MAVEN_SITE_XML_NAME; @@ -49,19 +49,18 @@ public URL resolv(Map<String, String> parameters) throws IOException, IllegalArgumentException { String local = parameters.get(PARAMETER_LOCALE); String svnRoot = parameters.get(PARAMETER_SVN_ROOT); - - if (StringUtils.isEmpty(svnRoot) || StringUtils.isEmpty(local) ) { + + if (StringUtils.isEmpty(svnRoot) || StringUtils.isEmpty(local)) { throw new IllegalArgumentException( "Layout " + MAVEN_SITE_XML_NAME + " requires three parameters '" + - PARAMETER_LOCALE + "', '"+PARAMETER_SVN_ROOT+"'"); + PARAMETER_LOCALE + "', '" + PARAMETER_SVN_ROOT + "'"); } - - String result = ""; - result = svnRoot+"/src/site/site_"+local+".xml"; + String result; - - + result = svnRoot + "/src/site/site_" + local + ".xml"; + + return new URL(result); } Modified: trunk/src/test/java/org/nuiton/scmwebeditor/BaseActionTest.java =================================================================== --- trunk/src/test/java/org/nuiton/scmwebeditor/BaseActionTest.java 2011-08-26 14:41:55 UTC (rev 247) +++ trunk/src/test/java/org/nuiton/scmwebeditor/BaseActionTest.java 2011-08-26 15:09:03 UTC (rev 248) @@ -64,31 +64,31 @@ DefaultSVNOptions svnOption; SVNClientManager manager; - SVNURL tgtURL = null; - File tgtPath = null; - File checkoutdir = null; + SVNURL tgtURL; + File tgtPath; + File checkoutdir; @Before public void before() throws Exception { try { FSRepositoryFactory.setup(); + + + authManager = SVNWCUtil.createDefaultAuthenticationManager(); + svnOption = SVNWCUtil.createDefaultOptions(false); + svnOption.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); + manager = SVNClientManager.newInstance(svnOption, authManager); - this.authManager = SVNWCUtil.createDefaultAuthenticationManager(); - this.svnOption = SVNWCUtil.createDefaultOptions(false); - this.svnOption.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); - this.manager = SVNClientManager.newInstance(this.svnOption, this.authManager); + SVNAdminClient adminClient = new SVNAdminClient(authManager, svnOption); - SVNAdminClient adminClient = new SVNAdminClient( this.authManager, this.svnOption); - - tgtPath = FileUtil.createTempDirectory("scmTestSvn_", ""); tgtURL = adminClient.doCreateRepository( tgtPath, null , true , true ); - SVNUpdateClient upclient = new SVNUpdateClient(this.manager, this.svnOption); + SVNUpdateClient upclient = new SVNUpdateClient(manager, svnOption); checkoutdir = FileUtil.createTempDirectory("scmTest_", ""); @@ -103,7 +103,7 @@ File[] tabFile = new File[1]; tabFile[0] = testFile; - SVNCommitClient commitClient = new SVNCommitClient(this.manager, this.svnOption); + SVNCommitClient commitClient = new SVNCommitClient(manager, svnOption); commitClient.doCommit(tabFile, false, "commit Test", null, null, false, true, SVNDepth.FILES); } catch ( SVNException e ) {