This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository scmwebeditor. See http://git.nuiton.org/scmwebeditor.git commit a6a25f3eb48833a2f2672000bdfd5bf43fe93e2f Author: Hugo PIGEON <hpigeon@codelutin.com> Date: Wed Jun 3 10:58:52 2015 +0200 Improve code quality --- .../org/nuiton/scmwebeditor/git/GitConnection.java | 45 +++-- .../nuiton/scmwebeditor/git/GitFileManager.java | 10 +- .../api/dto/result/AbstractResultDto.java | 4 +- .../api/dto/result/BrowseResultDto.java | 2 +- .../api/dto/result/CommitResultDto.java | 4 +- .../api/dto/result/CreateDirectoryResultDto.java | 4 +- .../api/dto/result/MoveFileResultDto.java | 4 +- .../api/dto/result/RemoveDirectoryResultDto.java | 4 +- .../api/dto/result/RemoveFileResultDto.java | 4 +- .../api/dto/result/UploadFileResultDto.java | 4 +- .../org/nuiton/scmwebeditor/svn/SvnConnection.java | 98 ++++----- .../uiweb/actions/AbstractScmWebEditorAction.java | 9 +- .../scmwebeditor/uiweb/actions/BrowseAction.java | 10 +- .../scmwebeditor/uiweb/actions/EditAction.java | 19 +- .../uiweb/actions/ScmWebEditorCommitAction.java | 19 +- .../webapp/codemirror-ui/js/codemirror-ui-find.js | 22 +- .../main/webapp/codemirror-ui/js/codemirror-ui.js | 224 ++++++--------------- swe-ui-web/src/main/webapp/js/autoSave.js | 22 ++ swe-ui-web/src/main/webapp/js/branches.js | 22 ++ swe-ui-web/src/main/webapp/js/editor.js | 22 ++ swe-ui-web/src/main/webapp/js/gereSession.js | 33 ++- swe-ui-web/src/main/webapp/js/preview.js | 36 +++- swe-ui-web/src/main/webapp/js/scmDetector.js | 22 ++ swe-ui-web/src/main/webapp/js/selectLanguage.js | 102 ++++------ 24 files changed, 387 insertions(+), 358 deletions(-) diff --git a/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitConnection.java b/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitConnection.java index aadf497..347a4f8 100644 --- a/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitConnection.java +++ b/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitConnection.java @@ -49,6 +49,7 @@ import javax.naming.AuthenticationException; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; @@ -80,6 +81,8 @@ public class GitConnection implements ScmConnection { /** the default branch to use when the requested one was not found */ protected static final String DEFAULT_BRANCH = "master"; + protected final String REPOSITORY_EXTENSION = ".git"; + public Repository getGitRepo() { return gitRepo; } @@ -91,10 +94,6 @@ public class GitConnection implements ScmConnection { public String getAddressGit() { return addressGit; } - public void setAddressGit(String addressGit) { this.addressGit = addressGit; } - - public void setFileName(String fileName) { this.fileName = fileName; } - public String getPathToLocalRepos() { return pathToLocalRepos; } public void setPathToLocalRepos(String pathToLocalRepos) { this.pathToLocalRepos = pathToLocalRepos; } @@ -111,18 +110,18 @@ public class GitConnection implements ScmConnection { log.debug("Git repository"); } - if (address.equals(".git")) { + if (address.equals(REPOSITORY_EXTENSION)) { throw new IOException("Can not reach Git repository"); - } else if (address.contains(".git")) { - addressGit = address.substring(0, address.indexOf(".git") + 4); - fileName = address.substring(address.indexOf(".git") + 4); + } else if (address.contains(REPOSITORY_EXTENSION)) { + addressGit = address.substring(0, address.indexOf(REPOSITORY_EXTENSION) + 4); + fileName = address.substring(address.indexOf(REPOSITORY_EXTENSION) + 4); } else if (address.startsWith("git://")) { - String lastPart = address.substring(address.lastIndexOf("/") + 1); + String lastPart = address.substring(address.lastIndexOf('/') + 1); if (lastPart.contains(".")) { // if the path is for a file addressGit = address.replace(lastPart, ""); - fileName = address.substring(address.lastIndexOf("/") + 1); + fileName = address.substring(address.lastIndexOf('/') + 1); } else { // if the path is for a directory addressGit = address; @@ -130,7 +129,7 @@ public class GitConnection implements ScmConnection { } } else { addressGit = address; - fileName = address.substring(address.lastIndexOf("/") + 1); + fileName = address.substring(address.lastIndexOf('/') + 1); } this.pathToLocalRepos = pathToLocalRepos; @@ -270,14 +269,14 @@ public class GitConnection implements ScmConnection { treeWalk.setRecursive(false); // the directories we have to open to find the requested url - String path = url.substring(url.indexOf(".git") + 4); + String path = url.substring(url.indexOf(REPOSITORY_EXTENSION) + 4); ArrayList<String> dirs = Lists.newArrayList(path.split("/")); while (treeWalk.next()) { - String fileName = address + File.separator + treeWalk.getPathString(); + String currentFileName = address + File.separator + treeWalk.getPathString(); - String fileNameComplete = fileName + File.separator; + String fileNameComplete = currentFileName + File.separator; String urlComplete = url + File.separator; if (fileNameComplete.startsWith(urlComplete) || urlComplete.startsWith(fileNameComplete)) { @@ -291,10 +290,10 @@ public class GitConnection implements ScmConnection { if (dirs.contains(currentDir)) { treeWalk.enterSubtree(); } else { - resultDto.getDirectories().put(fileName, fileName); + resultDto.getDirectories().put(currentFileName, currentFileName); } } else { - resultDto.getFiles().add(fileName); + resultDto.getFiles().add(currentFileName); } } } @@ -495,7 +494,9 @@ public class GitConnection implements ScmConnection { ObjectId commitId = gitRepo.resolve(Constants.HEAD); headRevision = commitId.getName(); } catch (IOException e) { - e.printStackTrace(); + if (log.isErrorEnabled()) { + log.error("Can not resolve commit " + Constants.HEAD, e); + } } return headRevision; @@ -637,7 +638,7 @@ public class GitConnection implements ScmConnection { } // Connection to the local repository - File gitFile = new File(localDirectory.getAbsolutePath() + File.separator + ".git"); + File gitFile = new File(localDirectory.getAbsolutePath() + File.separator + REPOSITORY_EXTENSION); FileRepositoryBuilder gitRepoBuilder = new FileRepositoryBuilder(); gitRepoBuilder.setGitDir(gitFile); gitRepo = gitRepoBuilder.build(); @@ -716,7 +717,13 @@ public class GitConnection implements ScmConnection { try { MessageDigest md = MessageDigest.getInstance(algorithm); - md.update(toHash.getBytes()); + try { + md.update(toHash.getBytes("UTF-8")); + } catch (UnsupportedEncodingException e) { + if (log.isErrorEnabled()) { + log.error("Can not get bytes from UTF-8 encoding"); + } + } byte byteData[] = md.digest(); StringBuilder sb = new StringBuilder(); diff --git a/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitFileManager.java b/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitFileManager.java index f6b665e..5f320d7 100644 --- a/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitFileManager.java +++ b/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitFileManager.java @@ -188,7 +188,10 @@ public class GitFileManager implements ScmFileManager { push.call(); } catch (GitAPIException e) { - file.delete(); + boolean fileDeleted = file.delete(); + if (!fileDeleted && log.isDebugEnabled()) { + log.debug("Could not delete file " + file.getAbsolutePath()); + } connection.handlePushException(e); @@ -205,7 +208,10 @@ public class GitFileManager implements ScmFileManager { log.error("Can not open git local repository : " + connection.getLocalDirectory().getAbsolutePath(), e); } - file.delete(); + boolean fileDeleted = file.delete(); + if (!fileDeleted && log.isDebugEnabled()) { + log.debug("Could not delete file " + file.getAbsolutePath()); + } resultDto.setError(UploadFileResultDto.ERROR); return resultDto; } diff --git a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/AbstractResultDto.java b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/AbstractResultDto.java index 5b51007..16516f5 100644 --- a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/AbstractResultDto.java +++ b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/AbstractResultDto.java @@ -23,9 +23,9 @@ package org.nuiton.scmwebeditor.api.dto.result; public class AbstractResultDto { - public static String ERROR = "error"; + public static final String ERROR = "error"; - public static String AUTH_ERROR = "auth error"; + public static final String AUTH_ERROR = "auth error"; /** gives a message about the error if one occured */ protected String error; diff --git a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/BrowseResultDto.java b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/BrowseResultDto.java index 4553485..e9a96d9 100644 --- a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/BrowseResultDto.java +++ b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/BrowseResultDto.java @@ -8,7 +8,7 @@ import java.util.Map; public class BrowseResultDto extends AbstractResultDto { - public static String ROOT = "root"; + public static final String ROOT = "root"; /** the name of the head branch on the SCM */ diff --git a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/CommitResultDto.java b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/CommitResultDto.java index 261de67..9431337 100644 --- a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/CommitResultDto.java +++ b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/CommitResultDto.java @@ -2,9 +2,9 @@ package org.nuiton.scmwebeditor.api.dto.result; public class CommitResultDto extends AbstractResultDto { - public static String ERROR_PATH = "error path"; + public static final String ERROR_PATH = "error path"; - public static String FILE_MODIFY = "file modify"; + public static final String FILE_MODIFY = "file modify"; /** the last read text */ protected String lastText; diff --git a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/CreateDirectoryResultDto.java b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/CreateDirectoryResultDto.java index 33fcccb..44113aa 100644 --- a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/CreateDirectoryResultDto.java +++ b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/CreateDirectoryResultDto.java @@ -23,9 +23,9 @@ package org.nuiton.scmwebeditor.api.dto.result; public class CreateDirectoryResultDto extends AbstractResultDto { - public static String REDIRECT = "redirect"; + public static final String REDIRECT = "redirect"; - public static String CONNECTION_FAILED = "connection failed"; + public static final String CONNECTION_FAILED = "connection failed"; /** the directory which contains the file */ protected String fileRoot; diff --git a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/MoveFileResultDto.java b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/MoveFileResultDto.java index 5e216ac..b0a6cbb 100644 --- a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/MoveFileResultDto.java +++ b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/MoveFileResultDto.java @@ -23,9 +23,9 @@ package org.nuiton.scmwebeditor.api.dto.result; public class MoveFileResultDto extends AbstractResultDto { - public static String REDIRECT = "redirect"; + public static final String REDIRECT = "redirect"; - public static String CONNECTION_FAILED = "connection failed"; + public static final String CONNECTION_FAILED = "connection failed"; /** the root directory of the repository */ protected String scmRoot; diff --git a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/RemoveDirectoryResultDto.java b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/RemoveDirectoryResultDto.java index 702529c..56ac863 100644 --- a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/RemoveDirectoryResultDto.java +++ b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/RemoveDirectoryResultDto.java @@ -23,9 +23,9 @@ package org.nuiton.scmwebeditor.api.dto.result; public class RemoveDirectoryResultDto extends AbstractResultDto { - public static String REDIRECT = "redirect"; + public static final String REDIRECT = "redirect"; - public static String CONNECTION_FAILED = "connection failed"; + public static final String CONNECTION_FAILED = "connection failed"; /** the directory which contains the file */ protected String fileRoot; diff --git a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/RemoveFileResultDto.java b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/RemoveFileResultDto.java index df30d81..63761c7 100644 --- a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/RemoveFileResultDto.java +++ b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/RemoveFileResultDto.java @@ -23,9 +23,9 @@ package org.nuiton.scmwebeditor.api.dto.result; public class RemoveFileResultDto extends AbstractResultDto { - public static String REDIRECT = "redirect"; + public static final String REDIRECT = "redirect"; - public static String CONNECTION_FAILED = "connection failed"; + public static final String CONNECTION_FAILED = "connection failed"; /** the root directory of the repository */ protected String scmRoot; diff --git a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/UploadFileResultDto.java b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/UploadFileResultDto.java index e48d397..e11e353 100644 --- a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/UploadFileResultDto.java +++ b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/result/UploadFileResultDto.java @@ -23,9 +23,9 @@ package org.nuiton.scmwebeditor.api.dto.result; public class UploadFileResultDto extends AbstractResultDto { - public static String REDIRECT = "redirect"; + public static final String REDIRECT = "redirect"; - public static String CONNECTION_FAILED = "connection failed"; + public static final String CONNECTION_FAILED = "connection failed"; /** the directory which contains the file */ protected String fileRoot; diff --git a/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnConnection.java b/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnConnection.java index e6cda7e..c9a1e7a 100644 --- a/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnConnection.java +++ b/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnConnection.java @@ -79,41 +79,16 @@ public class SvnConnection implements ScmConnection { protected SVNClientManager manager; - public String getAddressSvn() { return addressSvn; } - - public void setAddressSvn(String addressSvn) { this.addressSvn = addressSvn; } - public String getSvnPath() { return svnPath; } - public void setSvnPath(String svnPath) { this.svnPath = svnPath; } - - public void setFileName(String fileName) { this.fileName = fileName; } - - public File getCheckoutdir() { return checkoutdir; } - - public void setCheckoutdir(File checkoutdir) { this.checkoutdir = checkoutdir; } - - public SVNURL getRemoteUrl() { return remoteUrl; } - - public void setRemoteUrl(SVNURL remoteUrl) { this.remoteUrl = remoteUrl; } - - public ISVNAuthenticationManager getAuthManager() { return authManager; } - - public void setAuthManager( - ISVNAuthenticationManager authManager) { this.authManager = authManager; } - public DefaultSVNOptions getSvnOption() { return svnOption; } - public void setSvnOption(DefaultSVNOptions svnOption) { this.svnOption = svnOption; } - public String getPathToLocalRepos() { return pathToLocalRepos; } public void setPathToLocalRepos(String pathToLocalRepos) { this.pathToLocalRepos = pathToLocalRepos; } public SVNClientManager getManager() { return manager; } - public void setManager(SVNClientManager manager) { this.manager = manager; } - public SvnConnection(String address, String pathToLocalRepos) throws SVNException { @@ -121,7 +96,7 @@ public class SvnConnection implements ScmConnection { log.debug("SVN repository"); } - if (address.lastIndexOf("/") != -1){ + if (address.lastIndexOf('/') != -1){ svnPath = address.substring(0, address.lastIndexOf('/')); fileName = address.substring(address.lastIndexOf('/') + 1); @@ -149,7 +124,7 @@ public class SvnConnection implements ScmConnection { DAVRepositoryFactory.setup(); SVNRepository repository; - ISVNAuthenticationManager authManager; + ISVNAuthenticationManager svnAuthManager; String name = dto.getUsername(); String password = dto.getPassword(); @@ -163,8 +138,8 @@ public class SvnConnection implements ScmConnection { String encodedUrl = SVNEncodingUtil.autoURIEncode(addressSvn); repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(encodedUrl)); - authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password); - repository.setAuthenticationManager(authManager); + svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(name, password); + repository.setAuthenticationManager(svnAuthManager); repository.testConnection(); @@ -196,8 +171,8 @@ public class SvnConnection implements ScmConnection { String encodedUrl = SVNEncodingUtil.autoURIEncode(url); repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(encodedUrl)); - authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password); - repository.setAuthenticationManager(authManager); + svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(name, password); + repository.setAuthenticationManager(svnAuthManager); if (log.isDebugEnabled()) { log.debug("Repository Root: " + repository.getRepositoryRoot(true)); @@ -339,7 +314,7 @@ public class SvnConnection implements ScmConnection { ByteArrayOutputStream differents = getDiff(dto.getNewText()); if (differents.size() > 0) { - resultDto.setDiff(differents.toString()); + resultDto.setDiff(differents.toString("UTF-8")); String diff = resultDto.getDiff(); @@ -453,21 +428,27 @@ public class SvnConnection implements ScmConnection { @Override public File getFileContent(String path, String username, String password) throws AuthenticationException { - String url = path.substring(0, path.lastIndexOf("/")); - String file = path.substring(path.lastIndexOf("/") + 1); + String url = path.substring(0, path.lastIndexOf('/')); + String file = path.substring(path.lastIndexOf('/') + 1); // storing the file content to the user's local directory File localDirectory = new File(pathToLocalRepos); if (!localDirectory.exists()) { - localDirectory.mkdir(); + boolean localDirectoryCreated = localDirectory.mkdir(); + if (!localDirectoryCreated && log.isDebugEnabled()) { + log.debug("Could not create directory " + localDirectory.getAbsolutePath()); + } } String tempFileName = localDirectory.getAbsolutePath() + File.separator + file; File tempFile = new File(tempFileName); - if(tempFile.exists()) { - tempFile.delete(); + if (tempFile.exists()) { + boolean tempFileDeleted = tempFile.delete(); + if (!tempFileDeleted && log.isDebugEnabled()) { + log.debug("Could not delete temp file " + tempFileName); + } } updateAuthentication(username, password); @@ -477,8 +458,8 @@ public class SvnConnection implements ScmConnection { try { repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url)); - ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); - repository.setAuthenticationManager(authManager); + ISVNAuthenticationManager svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); + repository.setAuthenticationManager(svnAuthManager); SVNNodeKind nodeKind = repository.checkPath(file, -1); @@ -543,12 +524,12 @@ public class SvnConnection implements ScmConnection { log.debug("headRevisionNumber expected " + addressSvn + " ; got " + path); } - ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); + ISVNAuthenticationManager svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); - DefaultSVNOptions svnOption = new DefaultSVNOptions(); - svnOption.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); + DefaultSVNOptions svnOptions = new DefaultSVNOptions(); + svnOptions.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); - SVNWCClient wcClient = new SVNWCClient(authManager, svnOption); + SVNWCClient wcClient = new SVNWCClient(svnAuthManager, svnOptions); SVNInfo info = null; @@ -578,8 +559,8 @@ public class SvnConnection implements ScmConnection { try { String encodedUrl = SVNEncodingUtil.autoURIEncode(addressSvn); SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(encodedUrl)); - ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(); - repository.setAuthenticationManager(authManager); + ISVNAuthenticationManager svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(); + repository.setAuthenticationManager(svnAuthManager); repositoryUUID = repository.getRepositoryUUID(true); } catch (SVNException e) { @@ -609,8 +590,8 @@ public class SvnConnection implements ScmConnection { try { String encodedUrl = SVNEncodingUtil.autoURIEncode(addressSvn); SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(encodedUrl)); - ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); - repository.setAuthenticationManager(authManager); + ISVNAuthenticationManager svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); + repository.setAuthenticationManager(svnAuthManager); repositoryRoot = repository.getRepositoryRoot(true).toString(); } catch (SVNException e) { @@ -644,15 +625,9 @@ public class SvnConnection implements ScmConnection { ByteArrayOutputStream diff = getDiff(text); - if (diff == null) { - return false; - } + boolean positiveSize = (diff.size() > 0); - if (diff.size() > 0) { - return true; - } else { - return false; - } + return positiveSize; } public ByteArrayOutputStream getDiff(String text) throws IOException { @@ -695,7 +670,10 @@ public class SvnConnection implements ScmConnection { File localDirectory = new File(pathToLocalRepos); if (!localDirectory.exists()) { - localDirectory.mkdir(); + boolean localDirectoryCreated = localDirectory.mkdir(); + if (!localDirectoryCreated && log.isDebugEnabled()) { + log.debug("Could not create directory " + localDirectory.getAbsolutePath()); + } } checkoutdir = FileUtil.createTempDirectory("scm_", "", localDirectory); @@ -731,12 +709,12 @@ public class SvnConnection implements ScmConnection { */ public String getHeadcommiter(String address, String login, String password) throws SVNException { - ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(login, password); + ISVNAuthenticationManager svnAuthManager = SVNWCUtil.createDefaultAuthenticationManager(login, password); - DefaultSVNOptions svnOption = new DefaultSVNOptions(); - svnOption.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); + DefaultSVNOptions svnOptions = new DefaultSVNOptions(); + svnOptions.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); - SVNWCClient wcClient = new SVNWCClient(authManager, svnOption); + SVNWCClient wcClient = new SVNWCClient(svnAuthManager, svnOptions); SVNInfo info = wcClient.doInfo(SVNURL.parseURIEncoded(address), SVNRevision.HEAD, SVNRevision.HEAD); diff --git a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/AbstractScmWebEditorAction.java b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/AbstractScmWebEditorAction.java index 80e595a..19e14b3 100644 --- a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/AbstractScmWebEditorAction.java +++ b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/AbstractScmWebEditorAction.java @@ -39,6 +39,7 @@ import javax.servlet.http.HttpServletRequest; import java.io.*; import java.net.MalformedURLException; import java.nio.charset.Charset; +import java.util.Arrays; import java.util.Map; import java.util.Properties; @@ -251,7 +252,7 @@ public abstract class AbstractScmWebEditorAction extends BaseAction implements S protected String getMimeType(String content, String filename) throws IOException { - InputStream is = new ByteArrayInputStream(content.getBytes()); + InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8")); String result = null; try { BodyContentHandler contenthandler = new BodyContentHandler(); @@ -261,7 +262,7 @@ public abstract class AbstractScmWebEditorAction extends BaseAction implements S parser.parse(is, contenthandler, metadata); result = metadata.get(Metadata.CONTENT_TYPE); if (log.isDebugEnabled()) { - log.debug("Mine type of " + filename + " is : " + result); + log.debug("Mime type of " + filename + " is : " + result); } } catch (SAXException e) { @@ -279,7 +280,7 @@ public abstract class AbstractScmWebEditorAction extends BaseAction implements S } protected String[] getMimeTypes(String content, String filename) throws IOException, SAXException, TikaException { - InputStream is = new ByteArrayInputStream(content.getBytes()); + InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8")); try { BodyContentHandler contenthandler = new BodyContentHandler(); Metadata metadata = new Metadata(); @@ -289,7 +290,7 @@ public abstract class AbstractScmWebEditorAction extends BaseAction implements S String[] result = metadata.getValues(Metadata.CONTENT_TYPE); if (log.isDebugEnabled()) { - log.debug("Mine type of " + filename + " is : " + result); + log.debug("Mime type of " + filename + " is : " + Arrays.toString(result)); } return result; diff --git a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/BrowseAction.java b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/BrowseAction.java index e37d3a8..9853afe 100644 --- a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/BrowseAction.java +++ b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/BrowseAction.java @@ -37,6 +37,7 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.File; +import java.io.UnsupportedEncodingException; import java.text.Normalizer; import java.util.ArrayList; import java.util.List; @@ -253,7 +254,14 @@ public class BrowseAction extends AbstractScmWebEditorAction implements ServletR BlowfishCipherService bf = new BlowfishCipherService(); byte[] privateKey = Base64.decode(ScmWebEditorConfig.getKey()); - Cookie authCookie = new Cookie(repositoryUUID, bf.encrypt((username + "," + pw).getBytes(), privateKey).toBase64()); + Cookie authCookie = null; + try { + authCookie = new Cookie(repositoryUUID, bf.encrypt((username + "," + pw).getBytes("UTF-8"), privateKey).toBase64()); + } catch (UnsupportedEncodingException e) { + if (log.isErrorEnabled()) { + log.error("Can not get bytes from UTF-8 encoding"); + } + } authCookie.setMaxAge(60 * 60 * 24 * 365); response.addCookie(authCookie); diff --git a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/EditAction.java b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/EditAction.java index 8f1002a..9f50b38 100644 --- a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/EditAction.java +++ b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/EditAction.java @@ -37,6 +37,7 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpSession; import java.io.File; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.text.Normalizer; import java.util.LinkedList; @@ -154,7 +155,14 @@ public class EditAction extends ScmWebEditorMainAction { if (usernamepwCookie != null) { - String usernameDecode = new String(bf.decrypt(Base64.decode(usernamepwCookie), privateKey).getBytes()); + String usernameDecode = null; + try { + usernameDecode = new String(bf.decrypt(Base64.decode(usernamepwCookie), privateKey).getBytes(), "UTF-8"); + } catch (UnsupportedEncodingException e) { + if (log.isErrorEnabled()) { + log.error("Can not create a String with UTF-8 encoding"); + } + } String[] resCookie = usernameDecode.split(","); if (resCookie.length == 2) { @@ -167,7 +175,14 @@ public class EditAction extends ScmWebEditorMainAction { if (username != null && pw != null) { if (!username.equals("") && !pw.equals("")) { - Cookie authCookie = new Cookie(repositoryUUID, bf.encrypt((username + "," + pw).getBytes(), privateKey).toBase64()); + Cookie authCookie = null; + try { + authCookie = new Cookie(repositoryUUID, bf.encrypt((username + "," + pw).getBytes("UTF-8"), privateKey).toBase64()); + } catch (UnsupportedEncodingException e) { + if (log.isErrorEnabled()) { + log.error("Can not get a String from UTF-8 encoding"); + } + } authCookie.setMaxAge(60 * 60 * 24 * 365); response.addCookie(authCookie); } diff --git a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/ScmWebEditorCommitAction.java b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/ScmWebEditorCommitAction.java index ca8e35d..c621120 100644 --- a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/ScmWebEditorCommitAction.java +++ b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/ScmWebEditorCommitAction.java @@ -42,6 +42,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.File; import java.io.StringReader; +import java.io.UnsupportedEncodingException; import java.text.Normalizer; /** @@ -260,7 +261,14 @@ public class ScmWebEditorCommitAction extends AbstractScmWebEditorAction impleme if (usernamepwCookie != null) { - String usernameDecode = new String(bf.decrypt(Base64.decode(usernamepwCookie), privateKey).getBytes()); + String usernameDecode = null; + try { + usernameDecode = new String(bf.decrypt(Base64.decode(usernamepwCookie), privateKey).getBytes(), "UTF-8"); + } catch (UnsupportedEncodingException e) { + if (log.isErrorEnabled()) { + log.error("Can not create a String with UTF-8 encoding"); + } + } String[] resCookie = usernameDecode.split(","); if (resCookie.length == 2) { username = resCookie[0]; @@ -270,7 +278,14 @@ public class ScmWebEditorCommitAction extends AbstractScmWebEditorAction impleme if (saveCookie) { if (username != null && pw != null) { - Cookie authCookie = new Cookie(repositoryUUID, bf.encrypt((username + "," + pw).getBytes(), privateKey).toBase64()); + Cookie authCookie = null; + try { + authCookie = new Cookie(repositoryUUID, bf.encrypt((username + "," + pw).getBytes("UTF-8"), privateKey).toBase64()); + } catch (UnsupportedEncodingException e) { + if (log.isErrorEnabled()) { + log.error("Can not get bytes from UTF-8 encoding"); + } + } authCookie.setMaxAge(60 * 60 * 24 * 365); response.addCookie(authCookie); } diff --git a/swe-ui-web/src/main/webapp/codemirror-ui/js/codemirror-ui-find.js b/swe-ui-web/src/main/webapp/codemirror-ui/js/codemirror-ui-find.js index c1cc8c5..02cac2b 100644 --- a/swe-ui-web/src/main/webapp/codemirror-ui/js/codemirror-ui-find.js +++ b/swe-ui-web/src/main/webapp/codemirror-ui/js/codemirror-ui-find.js @@ -18,35 +18,35 @@ function closeWindow(){ function find(){ var findString = document.getElementById('find').value; - if (findString == null || findString == '') { + if (findString == null || findString === '') { alert('You must enter something to search for.'); return; } - + if(document.getElementById('regex').checked){ findString = new RegExp(findString); } - + cursor = codeMirrorUI.mirror.getSearchCursor(findString, true); var found = moveCursor(cursor); - + //if we didn't find anything, let's check to see if we should start from the top if(!found && document.getElementById('wrap').checked){ cursor = codeMirrorUI.mirror.getSearchCursor(findString, false); found = moveCursor(cursor); } - + if(found){ cursor.select(); }else{ alert("No instances found. (Maybe you need to enable 'Wrap Search'?)"); } - + } function moveCursor(cursor){ var found = false; - if( getFindDirection() == "forward" ){ + if( getFindDirection() === "forward" ){ found = cursor.findNext(); }else{ found = cursor.findPrevious(); @@ -57,7 +57,7 @@ function moveCursor(cursor){ function getFindDirection(){ var dRadio = document.forms[0].elements['direction']; - + for (var i = 0; i < dRadio.length; i++) { if (dRadio[i].checked) { return dRadio[i].value; @@ -65,22 +65,20 @@ function getFindDirection(){ } return 'no-value?'; - } function replaceAll(){ var cursor = codeMirrorUI.mirror.getSearchCursor(document.getElementById('find').value, false); - while (cursor.findNext()) + while (cursor.findNext()) { cursor.replace(document.getElementById('replace').value); + } } function replace(){ cursor.replace(document.getElementById('replace').value); - //codeMirrorUI.replaceSelection(document.getElementById('replace').value); setTimeout(window.focus, 100); - //alert('replaced!'); } function replaceFind(){ diff --git a/swe-ui-web/src/main/webapp/codemirror-ui/js/codemirror-ui.js b/swe-ui-web/src/main/webapp/codemirror-ui/js/codemirror-ui.js index dce9c98..157d811 100644 --- a/swe-ui-web/src/main/webapp/codemirror-ui/js/codemirror-ui.js +++ b/swe-ui-web/src/main/webapp/codemirror-ui/js/codemirror-ui.js @@ -2,7 +2,6 @@ * interface defined here is a mess of prompts and confirms, and * should probably not be used in a real project. */ -//var CodeMirrorUI = Class.create(); function CodeMirrorUI(place, options, mirrorOptions) { this.initialize(place, options, mirrorOptions); @@ -16,9 +15,9 @@ CodeMirrorUI.prototype = { imagePath: 'images/silk', path: 'js', buttons: ['search', 'undo', 'redo', 'jump', 'reindentSelection', 'reindent','about'], - saveCallback: function() {}, - } - this.textarea = textarea + saveCallback: function() {} + }; + this.textarea = textarea; this.options = options; this.setDefaults(this.options, defaultOptions); @@ -39,11 +38,6 @@ CodeMirrorUI.prototype = { this.home = document.createElement("div"); this.textarea.parentNode.insertBefore(this.home, this.textarea); - /*if (place.appendChild) - place.appendChild(this.home); - else - place(this.home); - */ this.self = this; var onChange = this.editorChanged.cmuiBind(this); @@ -53,32 +47,36 @@ CodeMirrorUI.prototype = { mirrorOptions.onChange = function() { mirrorOptions.oldOnChange(); onChange(); - } + }; } else { mirrorOptions.onChange = onChange; } mir = CodeMirror.fromTextArea(this.textarea, mirrorOptions); - //console.log(mir); this.mirror = mir; this.initButtons(); - //this.initWordWrapControl(); // CodeMirror v2 does not support word wrapping - - if (this.options.searchMode == 'inline') { + if (this.options.searchMode === 'inline') { this.initFindControl(); - } else if (this.options.searchMode == 'popup') { + } else if (this.options.searchMode === 'popup') { this.initPopupFindControl(); } - if (this.saveButton) this.addClass(this.saveButton,'inactive'); - if (this.undoButton) this.addClass(this.undoButton,'inactive'); - if (this.redoButton) this.addClass(this.redoButton,'inactive'); + if (this.saveButton) { + this.addClass(this.saveButton,'inactive'); + } + if (this.undoButton) { + this.addClass(this.undoButton,'inactive'); + } + if (this.redoButton) { + this.addClass(this.redoButton,'inactive'); + } }, setDefaults: function(object, defaults) { for (var option in defaults) { - if (!object.hasOwnProperty(option)) + if (!object.hasOwnProperty(option)) { object[option] = defaults[option]; + } } }, toTextArea: function() { @@ -94,29 +92,7 @@ CodeMirrorUI.prototype = { var buttonDef = this.buttonDefs[buttonId]; this.addButton(buttonDef[0], buttonDef[1], buttonDef[2], buttonDef[3], this.buttonFrame); } - - //this.makeButton("Search", "search"); - //this.makeButton("Replace", "replace"); - //this.makeButton("Current line", "line"); - //this.makeButton("Jump to line", "jump"); - //this.makeButton("Insert constructor", "macro"); - //this.makeButton("Indent all", "reindent"); }, - /* - * This is left over from the MirrorFrame demo. - * Get rid of it quick. - */ - /* - makeButton : function(name, action){ - var button = document.createElement("input"); - button.type = "button"; - button.value = name; - this.home.appendChild(button); - button.onclick = function(){ - self[action].call(self); - }; - }, - */ createFindBar: function() { var findBar = document.createElement("div"); findBar.className = "codemirror-ui-find-bar"; @@ -128,34 +104,34 @@ CodeMirrorUI.prototype = { this.findButton = document.createElement("input"); this.findButton.type = "button"; this.findButton.value = "Find"; - this.findButton.onclick = function(){this.find()}.cmuiBind(this); + this.findButton.onclick = function() { this.find(); }.cmuiBind(this); - this.connect(this.findString, "keyup", function(e){ + this.connect(this.findString, "keyup", function(e) { var code = e.keyCode; - if (code == 13){ - this.find(this.mirror.getCursor(false)) - }else{ - if(!this.findString.value == ""){ - this.find(this.mirror.getCursor(true)) - } + if (code === 13) { + this.find(this.mirror.getCursor(false)); + } else { + if(!this.findString.value === "") { + this.find(this.mirror.getCursor(true)); + } } this.findString.focus(); - + }.cmuiBind(this) ); var regLabel = document.createElement("label"); - regLabel.title = "Regular Expressions" + regLabel.title = "Regular Expressions"; this.regex = document.createElement("input"); - this.regex.type = "checkbox" - this.regex.className = "codemirror-ui-checkbox" + this.regex.type = "checkbox"; + this.regex.className = "codemirror-ui-checkbox"; regLabel.appendChild(this.regex); regLabel.appendChild(document.createTextNode("RegEx")); var caseLabel = document.createElement("label"); - caseLabel.title = "Case Sensitive" + caseLabel.title = "Case Sensitive"; this.caseSensitive = document.createElement("input"); - this.caseSensitive.type = "checkbox" - this.caseSensitive.className = "codemirror-ui-checkbox" + this.caseSensitive.type = "checkbox"; + this.caseSensitive.className = "codemirror-ui-checkbox"; caseLabel.appendChild(this.caseSensitive); caseLabel.appendChild(document.createTextNode("A/a")); @@ -163,10 +139,10 @@ CodeMirrorUI.prototype = { this.replaceString.type = "text"; this.replaceString.size = 8; - this.connect(this.replaceString, "keyup", function(e){ + this.connect(this.replaceString, "keyup", function(e) { var code = e.keyCode; - if (code == 13){ - this.replace() + if (code === 13){ + this.replace(); } }.cmuiBind(this) ); @@ -176,10 +152,10 @@ CodeMirrorUI.prototype = { this.replaceButton.onclick = this.replace.cmuiBind(this); var replaceAllLabel = document.createElement("label"); - replaceAllLabel.title = "Replace All" + replaceAllLabel.title = "Replace All"; this.replaceAll = document.createElement("input"); - this.replaceAll.type = "checkbox" - this.replaceAll.className = "codemirror-ui-checkbox" + this.replaceAll.type = "checkbox"; + this.replaceAll.className = "codemirror-ui-checkbox"; replaceAllLabel.appendChild(this.replaceAll); replaceAllLabel.appendChild(document.createTextNode("All")); @@ -217,7 +193,7 @@ CodeMirrorUI.prototype = { start = this.mirror.getCursor(); } var findString = this.findString.value; - if (findString == null || findString == '') { + if (findString == null || findString === '') { alert('You must enter something to search for.'); return; } @@ -228,15 +204,13 @@ CodeMirrorUI.prototype = { this.cursor = this.mirror.getSearchCursor(findString, start, !isCaseSensitive ); var found = this.cursor.findNext(); if (found) { - this.mirror.setSelection(this.cursor.from(),this.cursor.to()) - //this.cursor.select(); + this.mirror.setSelection(this.cursor.from(),this.cursor.to()); } else { if (confirm("No more matches. Should we start from the top?")) { this.cursor = this.mirror.getSearchCursor(findString, 0, !isCaseSensitive); found = this.cursor.findNext(); if (found) { - this.mirror.setSelection(this.cursor.from(),this.cursor.to()) - //this.cursor.select(); + this.mirror.setSelection(this.cursor.from(),this.cursor.to()); } else { alert("No matches found."); } @@ -252,27 +226,26 @@ CodeMirrorUI.prototype = { if (this.replaceAll.checked) { var cursor = this.mirror.getSearchCursor(isRegex ? regFindString : findString, 0, !isCaseSensitive); - while (cursor.findNext()) + while (cursor.findNext()) { this.mirror.replaceRange( isRegex ? cursor.pos.match[0].replace(regFindString, replaceString) : replaceString ,cursor.from(),cursor.to()); - //cursor.replace(this.replaceString.value); + } } else { this.mirror.replaceRange( isRegex ? this.cursor.pos.match[0].replace(regFindString, replaceString) : replaceString - ,this.cursor.from(),this.cursor.to()) - //this.cursor.replace(this.replaceString.value); + ,this.cursor.from(),this.cursor.to()); this.find(); } }, initWordWrapControl: function() { var wrapDiv = document.createElement("div"); - wrapDiv.className = "codemirror-ui-wrap" + wrapDiv.className = "codemirror-ui-wrap"; var label = document.createElement("label"); this.wordWrap = document.createElement("input"); - this.wordWrap.type = "checkbox" + this.wordWrap.type = "checkbox"; this.wordWrap.checked = true; label.appendChild(this.wordWrap); label.appendChild(document.createTextNode("Word Wrap")); @@ -289,24 +262,20 @@ CodeMirrorUI.prototype = { }, addButton: function(name, action, image, func, frame) { var button = document.createElement("a"); - //button.href = "#"; button.className = "codemirror-ui-button " + action; button.title = name; button.func = func.cmuiBind(this); button.onclick = function(event) { - //alert(event.target); - + //normalize for IE event = event ? event : window.event; - if (typeof event.target == 'undefined') { + if (typeof event.target === 'undefined') { var target = event.srcElement; } else { var target = event.target; } target.func(); return false; - //this.self[action].call(this); - //eval("this."+action)(); } .cmuiBind(this, func); var img = document.createElement("img"); @@ -315,13 +284,13 @@ CodeMirrorUI.prototype = { img.func = func.cmuiBind(this); button.appendChild(img); frame.appendChild(button); - if (action == 'save') { + if (action === 'save') { this.saveButton = button; } - if (action == 'undo') { + if (action === 'undo') { this.undoButton = button; } - if (action == 'redo') { + if (action === 'redo') { this.redoButton = button; } }, @@ -336,7 +305,7 @@ CodeMirrorUI.prototype = { }, removeClass: function(element, className) { if (element && element.className) { - var m = element.className.match(this.classNameRegex(className)) + var m = element.className.match(this.classNameRegex(className)); if (m) { element.className = m[1] + " " + m[2]; } @@ -344,7 +313,7 @@ CodeMirrorUI.prototype = { }, editorChanged: function() { if(!this.mirror) { - return + return; } var his = this.mirror.historySize(); if (his['undo'] > 0) { @@ -359,14 +328,13 @@ CodeMirrorUI.prototype = { } else { this.addClass(this.redoButton, 'inactive'); } - //alert("undo size = " + his['undo'] + " and redo size = " + his['redo']); }, save: function() { this.options.saveCallback(); this.addClass(this.saveButton, 'inactive'); }, getValue: function() { - return this.mirror.getValue(); + return this.mirror.getValue(); }, undo: function() { this.mirror.undo(); @@ -379,7 +347,6 @@ CodeMirrorUI.prototype = { this.searchWindow.focus(); }, raise_search_window: function() { - //alert('raising window!'); this.searchWindow.focus(); }, find_replace_window: function() { @@ -390,54 +357,12 @@ CodeMirrorUI.prototype = { this.searchWindow.focus(); }, find_replace_popup: function() { - //alert('Hello!'); this.popupFindWrap.className = "codemirror-ui-popup-find-wrap active"; this.findString.focus(); }, find_replace_popup_close: function() { - //alert('Hello!'); this.popupFindWrap.className = "codemirror-ui-popup-find-wrap"; }, - /* - find_replace: function(){ - this.find_replace = document.createElement("div"); - this.find_replace.className = "codemirror-search-replace"; - this.find_replace.innerHTML = "Just a test!"; - this.home.appendChild(this.find_replace); - }, - - search: function(){ - var text = prompt("Enter search term:", ""); - if (!text) - return; - - var first = true; - do { - var cursor = this.mirror.getSearchCursor(text, first); - first = false; - while (cursor.findNext()) { - cursor.select(); - if (!confirm("Search again?")) - return; - } - } - while (confirm("End of document reached. Start over?")); - }, - - replace: function(){ - // This is a replace-all, but it is possible to implement a - // prompting replace. - var from = prompt("Enter search string:", ""), to; - if (from) - to = prompt("What should it be replaced with?", ""); - if (to == null) - return; - - var cursor = this.mirror.getSearchCursor(from, false); - while (cursor.findNext()) - cursor.replace(to); - }, - */ jump: function() { var line = prompt("Jump to line:", ""); if (line && !isNaN(Number(line))) { @@ -446,18 +371,6 @@ CodeMirrorUI.prototype = { this.mirror.focus(); } }, - /* - line: function(){ - alert("The cursor is currently at line " + this.mirror.currentLine()); - this.mirror.focus(); - }, - - macro: function(){ - var name = prompt("Name your constructor:", ""); - if (name) - this.mirror.replaceSelection("function " + name + "() {\n \n}\n\n" + name + ".prototype = {\n \n};\n"); - }, - */ reindent: function() { var lineCount = this.mirror.lineCount(); for(var line = 0; line < lineCount; line++) { @@ -465,42 +378,39 @@ CodeMirrorUI.prototype = { } }, about : function() { - string = "CodeMirror-UI was written by Jeremy Green (http://www.octolabs.com/) as a light interface around CodeMirror by Marijn Haverbeke (http://codemirror.net)." - string += "\n\n" - string += "Documentation and the code can be found at https://github.com/jagthedrummer/codemirror-ui/." + string = "CodeMirror-UI was written by Jeremy Green (http://www.octolabs.com/) as a light interface around CodeMirror by Marijn Haverbeke (http://codemirror.net)."; + string += "\n\n"; + string += "Documentation and the code can be found at https://github.com/jagthedrummer/codemirror-ui/."; alert(string); }, reindentSelection: function() { - var cur = this.mirror.getCursor() - //console.log(cur) - var start = this.mirror.getCursor(true)["line"] - var end = this.mirror.getCursor(false)["line"] + this.mirror.getCursor() + var start = this.mirror.getCursor(true)["line"]; + var end = this.mirror.getCursor(false)["line"]; for(var line = start; line <= end; line++) { this.mirror.indentLine(line); } - //this.mirror.reindentSelection(); }, // Event handler registration. If disconnect is true, it'll return a // function that unregisters the handler. // Borrowed from CodeMirror + modified connect: function (node, type, handler, disconnect) { - /*function wrapHandler(event) { - handler(new Event(event || window.event)); - }*/ - if (typeof node.addEventListener == "function") { + if (typeof node.addEventListener === "function") { node.addEventListener(type, handler, false); - if (disconnect) + if (disconnect) { return function() { node.removeEventListener(type, handler, false); }; + } } else { node.attachEvent("on" + type, handler); - if (disconnect) + if (disconnect) { return function() { node.detachEvent("on" + type, handler); }; + } } } }; @@ -513,5 +423,5 @@ Function.prototype.cmuiBind = function(scope) { return function() { return _function.apply(scope, arguments); - } -} + }; +}; diff --git a/swe-ui-web/src/main/webapp/js/autoSave.js b/swe-ui-web/src/main/webapp/js/autoSave.js index 0188a45..79ec8e0 100644 --- a/swe-ui-web/src/main/webapp/js/autoSave.js +++ b/swe-ui-web/src/main/webapp/js/autoSave.js @@ -1,3 +1,25 @@ +/* + * #%L + * ScmWebEditor + * %% + * Copyright (C) 2009 - 2015 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + function autoSave() { loadChange(); diff --git a/swe-ui-web/src/main/webapp/js/branches.js b/swe-ui-web/src/main/webapp/js/branches.js index 3ac9df7..cd2fabc 100644 --- a/swe-ui-web/src/main/webapp/js/branches.js +++ b/swe-ui-web/src/main/webapp/js/branches.js @@ -1,3 +1,25 @@ +/* + * #%L + * ScmWebEditor + * %% + * Copyright (C) 2009 - 2015 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + $(document).ready(function() { $("#ajaxSearchButton").on("click", function() { diff --git a/swe-ui-web/src/main/webapp/js/editor.js b/swe-ui-web/src/main/webapp/js/editor.js index 2d9db58..34cd2d5 100644 --- a/swe-ui-web/src/main/webapp/js/editor.js +++ b/swe-ui-web/src/main/webapp/js/editor.js @@ -1,3 +1,25 @@ +/* + * #%L + * ScmWebEditor + * %% + * Copyright (C) 2009 - 2015 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + var exitAfterCommit = false; /* Changes the value of the new text */ diff --git a/swe-ui-web/src/main/webapp/js/gereSession.js b/swe-ui-web/src/main/webapp/js/gereSession.js index bb1dd60..1d6ca25 100644 --- a/swe-ui-web/src/main/webapp/js/gereSession.js +++ b/swe-ui-web/src/main/webapp/js/gereSession.js @@ -2,40 +2,35 @@ * #%L * ScmWebEditor * %% - * Copyright (C) 2009 - 2011 CodeLutin + * Copyright (C) 2009 - 2015 CodeLutin * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. * #L% */ -/** - * @author geoffroy lorieux - */ function rappelSession(minutes) { - var msg='Your session expire on '+minutes+' minute'; - if(minutes>1) - { + var msg='Your session expired on ' + minutes + ' minutes'; + if (minutes > 1) { msg+='s'; - } + } msg+='.\nDo you want to reload this page ?(You will not lose your data)'; - if(confirm(msg)) - { + if(confirm(msg)) { location.reload(); - } + } } /** @@ -43,7 +38,7 @@ function rappelSession(minutes) */ function expirationSession() { - alert("Your session has expire. Please relogin"); + alert("Your session has expired. Please relogin"); window.history.back(-1); } @@ -55,8 +50,8 @@ function expirationSession() function geresession(expiration, rappel) { // affichage du rappel - var chronoRappel=setTimeout('rappelSession('+rappel+')', (expiration-rappel)*60*1000); + setTimeout('rappelSession('+rappel+')', (expiration-rappel)*60*1000); // une fois le rappel affiché, on avertit uniquement de l'expiration - var chronoExpiration=setTimeout('expirationSession()', (expiration)*60*1000); + setTimeout('expirationSession()', (expiration)*60*1000); } diff --git a/swe-ui-web/src/main/webapp/js/preview.js b/swe-ui-web/src/main/webapp/js/preview.js index b809caa..93db99d 100644 --- a/swe-ui-web/src/main/webapp/js/preview.js +++ b/swe-ui-web/src/main/webapp/js/preview.js @@ -1,13 +1,35 @@ +/* + * #%L + * ScmWebEditor + * %% + * Copyright (C) 2009 - 2015 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + $(document).ready(function() { // setting the editor's height relative to the button's bar height var editors = document.getElementsByClassName('CodeMirror'); - if (editors.length == 1) { + if (editors.length === 1) { var edit = editors[0]; - var findBar = document.getElementsByClassName("codemirror-ui-find-bar") + var findBar = document.getElementsByClassName("codemirror-ui-find-bar"); - if (findBar.length == 1) { + if (findBar.length === 1) { var findBarHeight = findBar[0].offsetHeight; edit.style.height = (600 - findBarHeight) + "px"; @@ -20,12 +42,12 @@ $(document).ready(function() { function updatePreview() { - if (lastValue != editor.getValue()) { + if (lastValue !== editor.getValue()) { lastValue = editor.getValue(); loadChange(); - var request = $.post("preview.action", { + $.post("preview.action", { scmType: $("#scmType").val(), username: $("#username").val(), pw: $("#pw").val(), @@ -56,13 +78,13 @@ $(document).ready(function() { var $preview = $("#largeEditorPreview"); var selectedPos = $(this).val(); - if (selectedPos == "none") { + if (selectedPos === "none") { $editor.css("width", "100%"); $preview.hide(); } else { $preview.show(); - if (selectedPos == "side") { + if (selectedPos === "side") { $editor.css("width", "49%"); $preview.css("width", "49%"); $preview.css("margin-top", "0px"); diff --git a/swe-ui-web/src/main/webapp/js/scmDetector.js b/swe-ui-web/src/main/webapp/js/scmDetector.js index aefb2b4..46871a0 100644 --- a/swe-ui-web/src/main/webapp/js/scmDetector.js +++ b/swe-ui-web/src/main/webapp/js/scmDetector.js @@ -1,3 +1,25 @@ +/* + * #%L + * ScmWebEditor + * %% + * Copyright (C) 2009 - 2015 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + $(document).ready(function() { $("#addressInput").on("input", function() { diff --git a/swe-ui-web/src/main/webapp/js/selectLanguage.js b/swe-ui-web/src/main/webapp/js/selectLanguage.js index adb4c4c..19226e0 100644 --- a/swe-ui-web/src/main/webapp/js/selectLanguage.js +++ b/swe-ui-web/src/main/webapp/js/selectLanguage.js @@ -2,34 +2,30 @@ * #%L * ScmWebEditor * %% - * Copyright (C) 2009 - 2011 CodeLutin + * Copyright (C) 2009 - 2015 CodeLutin * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public + * + * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. * #L% */ -/** - * - */ function contains(text, test) { - - if(text.indexOf(test) == -1) { + + if(text.indexOf(test) === -1) { return false; - } - else { + } else { return true; } } @@ -42,83 +38,73 @@ function changeModeBy(CodeMirrorEditor, select){ -function selectLanguage(minetype, format) { +function selectLanguage(mimetype, format) { var typeEditor = null; - if(typeEditor==null && minetype!=null) { + if(typeEditor == null && mimetype != null) { - if(contains(minetype, "rst") ) { + if(contains(mimetype, "rst") ) { typeEditor="rst"; - document.getElementById('language').selectedIndex=1 - } - else if(contains(minetype, "javascript")) { + document.getElementById('language').selectedIndex = 1; + } else if(contains(mimetype, "javascript")) { typeEditor="javascript"; - document.getElementById('language').selectedIndex=2 - } - else if(contains(minetype, "html") ) { + document.getElementById('language').selectedIndex = 2; + } else if(contains(mimetype, "html") ) { typeEditor="text/html"; - document.getElementById('language').selectedIndex=3 - } - else if( contains(minetype, "xml") ) { + document.getElementById('language').selectedIndex = 3; + } else if( contains(mimetype, "xml") ) { typeEditor="xml"; - document.getElementById('language').selectedIndex=4 - } - else if( contains(minetype, "java/application") ) { + document.getElementById('language').selectedIndex = 4; + } else if( contains(mimetype, "java/application") ) { typeEditor="text/x-java"; - document.getElementById('language').selectedIndex=5 - } - else if(contains(minetype, "text/css") ) { + document.getElementById('language').selectedIndex = 5; + } else if(contains(mimetype, "text/css") ) { typeEditor="css"; - document.getElementById('language').selectedIndex=6 - } - else if(contains(minetype, "x-tex") ) { + document.getElementById('language').selectedIndex = 6; + } else if(contains(mimetype, "x-tex") ) { typeEditor="text/stex"; - document.getElementById('language').selectedIndex=7 + document.getElementById('language').selectedIndex = 7; } } - if (typeEditor==null && format!=null){ - - - if (format==("rst")) { + if (typeEditor==null && format!=null) { + + if (format === "rst") { typeEditor="rst"; - document.getElementById('language').selectedIndex=1 + document.getElementById('language').selectedIndex = 1; - } else if(format==("javascript")) { - typeEditor="javascript"; + } else if(format === "javascript") { + typeEditor="javascript"; - document.getElementById('language').selectedIndex=2 + document.getElementById('language').selectedIndex = 2; - } else if(format==("html")) { - typeEditor="text/html"; + } else if(format === "html") { + typeEditor="text/html"; - document.getElementById('language').selectedIndex=3 + document.getElementById('language').selectedIndex = 3; - } else if(format==("xml")) { + } else if(format === "xml") { typeEditor="xml"; - document.getElementById('language').selectedIndex=4 + document.getElementById('language').selectedIndex = 4; - } else if(format==("java")) { + } else if(format === "java") { typeEditor="text/x-java"; - document.getElementById('language').selectedIndex=5 + document.getElementById('language').selectedIndex = 5; - } else if(format==("css")) { + } else if(format === "css") { typeEditor="css"; - document.getElementById('language').selectedIndex=6 + document.getElementById('language').selectedIndex = 6; - } else if(format==("tex")) { + } else if(format === "tex") { typeEditor="text/stex"; - document.getElementById('language').selectedIndex=7 - + document.getElementById('language').selectedIndex = 7; + } - } - - } -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.