r119 - in trunk: . src/main/java/org/nuiton/scmwebeditor src/main/java/org/nuiton/scmwebeditor/actions src/main/resources src/main/webapp src/main/webapp/WEB-INF
Author: kcardineaud Date: 2011-06-16 10:20:00 +0200 (Thu, 16 Jun 2011) New Revision: 119 Url: http://nuiton.org/repositories/revision/scmwebeditor/119 Log: First commit to prepare conversion to struts2 Added: trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java trunk/src/main/java/org/nuiton/scmwebeditor/interceptors/ trunk/src/main/resources/struts.xml trunk/src/main/webapp/accueil.jsp trunk/src/main/webapp/index.jsp Removed: trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditorServlet.java Modified: trunk/pom.xml trunk/src/main/java/org/nuiton/scmwebeditor/PreviewServlet.java trunk/src/main/java/org/nuiton/scmwebeditor/PrivateSvnServlet.java trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorMainServlet.java trunk/src/main/java/org/nuiton/scmwebeditor/SearchServlet.java trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java trunk/src/main/webapp/BadFileRedirect.jsp trunk/src/main/webapp/ModificationViewer.jsp trunk/src/main/webapp/OutConnection.jsp trunk/src/main/webapp/WEB-INF/web.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2011-06-07 20:09:55 UTC (rev 118) +++ trunk/pom.xml 2011-06-16 08:20:00 UTC (rev 119) @@ -52,6 +52,12 @@ <artifactId>jrst</artifactId> <version>${jrstPluginVersion}</version> <scope>compile</scope> + <exclusions> + <exclusion> + <groupId>net.sourceforge.saxon</groupId> + <artifactId>saxon</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> @@ -67,6 +73,35 @@ <version>1.2.1</version> </dependency> + + <!-- Struts --> + + <dependency> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-core</artifactId> + <version>${struts2Version}</version> + </dependency> + + <dependency> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-sitemesh-plugin</artifactId> + <version>${struts2Version}</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>com.jgeppert.struts2.jquery</groupId> + <artifactId>struts2-jquery-plugin</artifactId> + <version>${struts2jqueryVersion}</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.struts.xwork</groupId> + <artifactId>xwork-core</artifactId> + <version>${strutsxworksVersion}</version> + </dependency> + </dependencies> <!-- ************************************************************* --> @@ -130,12 +165,18 @@ <!--Multilanguage maven-site --> <siteLocales>fr,en</siteLocales> + <struts2Version>2.2.3</struts2Version> + <struts2jqueryVersion>3.0.2</struts2jqueryVersion> + <strutsxworksVersion>2.2.3</strutsxworksVersion> <!-- extra files to include in release --> <redmine.releaseFiles>${redmine.libReleaseFiles}</redmine.releaseFiles> </properties> + + + <build> <pluginManagement> <plugins> Added: trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java (rev 0) +++ trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java 2011-06-16 08:20:00 UTC (rev 119) @@ -0,0 +1,211 @@ +/* + * #%L + * Nuiton-ScmWebEditor + * + * $Id: AbstractScmWebEditorServlet.java 89 2010-04-21 12:12:20Z ymartel $ + * $HeadURL: http://svn.nuiton.org/svn/scmwebeditor/trunk/src/main/java/org/nuiton/scmweb... $ + * %% + * Copyright (C) 2009 - 2010 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% + */ +package org.nuiton.scmwebeditor; + +import info.monitorenter.cpdetector.io.*; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.*; +import java.net.MalformedURLException; +import java.nio.charset.Charset; + +/** + * User: chemit + * Date: 24 nov. 2009 + * Time: 21:24:39 + */ +public class AbstractScmWebEditor { + + private static final long serialVersionUID = 1L; + + private static final Log log = LogFactory.getLog(AbstractScmWebEditor.class); + + //TODO-TC200924 : uniformize all this different parameter and attribute, this is a bit messy... + protected static final String PARAMETER_ADRESSE = "adresse"; + protected static final String PARAMETER_SCM_EDITOR_URL = "scmEditorUrl"; + protected static final String PARAMETER_PROJECT_URL = "project_url"; + 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_PROJECT_URL = "Project_url"; + 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 CodepageDetectorProxy detector; + + protected CodepageDetectorProxy getCodepageDetector() { + + if (detector == null) { + detector = CodepageDetectorProxy.getInstance(); // A singleton. + + // Add the implementations of info.monitorenter.cpdetector.io.ICodepageDetector: + // This one is quick if we deal with unicode codepages: + detector.add(new ByteOrderMarkDetector()); + // The first instance delegated to tries to detect the meta charset attribut in html pages. + detector.add(new ParsingDetector(true)); // be verbose about parsing. + // This one does the tricks of exclusion and frequency detection, if first implementation is + // unsuccessful: + detector.add(JChardetFacade.getInstance()); // Another singleton. + detector.add(ASCIIDetector.getInstance()); // Fallback, see javadoc. + } + return detector; + } + + + /** + * Convert all files to UTF-8. + * + * @param files fiels to convert + */ + protected void convertToUnicode(File... files) { + + CodepageDetectorProxy myDetector = getCodepageDetector(); + + for (File file : files) { + try { + Charset charset = myDetector.detectCodepage(file.toURI().toURL()); + + if (log.isDebugEnabled()) { + log.debug("Charset for " + file.getAbsolutePath() + " is " + charset); + } + + if (charset != null && !charset.name().equalsIgnoreCase("UTF-8")) { + + if (log.isDebugEnabled()) { + log.debug("Convert " + file.getAbsolutePath() + " to unicode"); + } + + File tmpFile = File.createTempFile(file.getName(), ".copy"); + tmpFile.deleteOnExit(); + + // direct copy + InputStream is = new FileInputStream(file); + OutputStream os = new FileOutputStream(tmpFile); + try { + IOUtils.copy(is, os); + } + finally { + is.close(); + os.close(); + } + + // copy using cp transaltion + is = new FileInputStream(tmpFile); + os = new FileOutputStream(file); + Reader ir = new InputStreamReader(is, charset); + Writer ow = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); + try { + IOUtils.copy(ir, ow); + } + finally { + ir.close(); + ow.close(); + is.close(); + os.close(); + } + + } else { + if (log.isDebugEnabled()) { + log.debug("File " + file.getAbsolutePath() + " already in unicode : skip"); + } + } + } catch (MalformedURLException e) { + if (log.isErrorEnabled()) { + log.error("Can't convert file in unicode", e); + } + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Can't convert file in unicode", e); + } + } + } + } + + protected SvnSession getSvnSession(HttpSession httpSession) { + SvnSession svnSess = (SvnSession) httpSession.getAttribute(ATTRIBUTE_SVN_SESSION); + return svnSess; + } + + protected void setSvnSession(HttpSession httpSession, SvnSession svnSess) { + httpSession.setAttribute(ATTRIBUTE_SVN_SESSION, svnSess); + } + + protected File getTempDir(HttpSession httpSession) { + File tmp_dir = getSvnSession(httpSession).getCheckoutdir(); + return tmp_dir; + } + +/* + protected void redirect(HttpServletRequest request, HttpServletResponse response, String path) throws IOException, ServletException { + RequestDispatcher requestDispacher = getServletContext().getRequestDispatcher(path); + requestDispacher.forward(request, response); + } +*/ + protected String getRedirectUrl(SvnSession svnSess) { + StringBuilder buffer = new StringBuilder(); + buffer.append(svnSess.getScmEditorUrl()); + buffer.append('?').append(PARAMETER_ADRESSE).append('=').append(svnSess.getSvnPath()); + buffer.append("&").append(PARAMETER_FILE_NAME).append('=').append(svnSess.getFileName()); + buffer.append("&").append(PARAMETER_PROJECT_URL).append('=').append(svnSess.getProjectUrl()); + buffer.append("&").append(PARAMETER_LANG).append('=').append(svnSess.getLang()); + buffer.append("&").append(PARAMETER_DEFAULT_LANG).append('=').append(svnSess.getDefaultLang()); + buffer.append("&").append(PARAMETER_FORMAT).append('=').append(svnSess.getFormat()); + + String url = buffer.toString(); + return url; + } + +} Deleted: trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditorServlet.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditorServlet.java 2011-06-07 20:09:55 UTC (rev 118) +++ trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditorServlet.java 2011-06-16 08:20:00 UTC (rev 119) @@ -1,210 +0,0 @@ -/* - * #%L - * Nuiton-ScmWebEditor - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2010 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% - */ -package org.nuiton.scmwebeditor; - -import info.monitorenter.cpdetector.io.*; -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import java.io.*; -import java.net.MalformedURLException; -import java.nio.charset.Charset; - -/** - * User: chemit - * Date: 24 nov. 2009 - * Time: 21:24:39 - */ -public class AbstractScmWebEditorServlet extends HttpServlet { - - private static final long serialVersionUID = 1L; - - private static final Log log = LogFactory.getLog(AbstractScmWebEditorServlet.class); - - //TODO-TC200924 : uniformize all this different parameter and attribute, this is a bit messy... - protected static final String PARAMETER_ADRESSE = "adresse"; - protected static final String PARAMETER_SCM_EDITOR_URL = "scmEditorUrl"; - protected static final String PARAMETER_PROJECT_URL = "project_url"; - 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_PROJECT_URL = "Project_url"; - 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 CodepageDetectorProxy detector; - - protected CodepageDetectorProxy getCodepageDetector() { - - if (detector == null) { - detector = CodepageDetectorProxy.getInstance(); // A singleton. - - // Add the implementations of info.monitorenter.cpdetector.io.ICodepageDetector: - // This one is quick if we deal with unicode codepages: - detector.add(new ByteOrderMarkDetector()); - // The first instance delegated to tries to detect the meta charset attribut in html pages. - detector.add(new ParsingDetector(true)); // be verbose about parsing. - // This one does the tricks of exclusion and frequency detection, if first implementation is - // unsuccessful: - detector.add(JChardetFacade.getInstance()); // Another singleton. - detector.add(ASCIIDetector.getInstance()); // Fallback, see javadoc. - } - return detector; - } - - - /** - * Convert all files to UTF-8. - * - * @param files fiels to convert - */ - protected void convertToUnicode(File... files) { - - CodepageDetectorProxy myDetector = getCodepageDetector(); - - for (File file : files) { - try { - Charset charset = myDetector.detectCodepage(file.toURI().toURL()); - - if (log.isDebugEnabled()) { - log.debug("Charset for " + file.getAbsolutePath() + " is " + charset); - } - - if (charset != null && !charset.name().equalsIgnoreCase("UTF-8")) { - - if (log.isDebugEnabled()) { - log.debug("Convert " + file.getAbsolutePath() + " to unicode"); - } - - File tmpFile = File.createTempFile(file.getName(), ".copy"); - tmpFile.deleteOnExit(); - - // direct copy - InputStream is = new FileInputStream(file); - OutputStream os = new FileOutputStream(tmpFile); - try { - IOUtils.copy(is, os); - } - finally { - is.close(); - os.close(); - } - - // copy using cp transaltion - is = new FileInputStream(tmpFile); - os = new FileOutputStream(file); - Reader ir = new InputStreamReader(is, charset); - Writer ow = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); - try { - IOUtils.copy(ir, ow); - } - finally { - ir.close(); - ow.close(); - is.close(); - os.close(); - } - - } else { - if (log.isDebugEnabled()) { - log.debug("File " + file.getAbsolutePath() + " already in unicode : skip"); - } - } - } catch (MalformedURLException e) { - if (log.isErrorEnabled()) { - log.error("Can't convert file in unicode", e); - } - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Can't convert file in unicode", e); - } - } - } - } - - protected SvnSession getSvnSession(HttpSession httpSession) { - SvnSession svnSess = (SvnSession) httpSession.getAttribute(ATTRIBUTE_SVN_SESSION); - return svnSess; - } - - protected void setSvnSession(HttpSession httpSession, SvnSession svnSess) { - httpSession.setAttribute(ATTRIBUTE_SVN_SESSION, svnSess); - } - - protected File getTempDir() { - File tmp_dir = (File) getServletContext().getAttribute("javax.servlet.context.tempdir"); - return tmp_dir; - } - - protected void redirect(HttpServletRequest request, HttpServletResponse response, String path) throws IOException, ServletException { - RequestDispatcher requestDispacher = getServletContext().getRequestDispatcher(path); - requestDispacher.forward(request, response); - } - - protected String getRedirectUrl(SvnSession svnSess) { - StringBuilder buffer = new StringBuilder(); - buffer.append(svnSess.getScmEditorUrl()); - buffer.append('?').append(PARAMETER_ADRESSE).append('=').append(svnSess.getSvnPath()); - buffer.append("&").append(PARAMETER_FILE_NAME).append('=').append(svnSess.getFileName()); - buffer.append("&").append(PARAMETER_PROJECT_URL).append('=').append(svnSess.getProjectUrl()); - buffer.append("&").append(PARAMETER_LANG).append('=').append(svnSess.getLang()); - buffer.append("&").append(PARAMETER_DEFAULT_LANG).append('=').append(svnSess.getDefaultLang()); - buffer.append("&").append(PARAMETER_FORMAT).append('=').append(svnSess.getFormat()); - - String url = buffer.toString(); - return url; - } - -} Modified: trunk/src/main/java/org/nuiton/scmwebeditor/PreviewServlet.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/PreviewServlet.java 2011-06-07 20:09:55 UTC (rev 118) +++ trunk/src/main/java/org/nuiton/scmwebeditor/PreviewServlet.java 2011-06-16 08:20:00 UTC (rev 119) @@ -40,7 +40,7 @@ /** * @author geoffroy lorieux */ -public class PreviewServlet extends AbstractScmWebEditorServlet { +public class PreviewServlet extends AbstractScmWebEditor { private static final long serialVersionUID = 1L; @@ -54,12 +54,11 @@ * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ - @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("je suis dans la previewservlet"); HttpSession httpSession = request.getSession(true); - File tmp_dir = getTempDir(); + File tmp_dir = getTempDir(httpSession); log.debug("Le tmp dir est :" + tmp_dir); log.debug("Le content type est : " + request.getContentType()); // Text recuperation Modified: trunk/src/main/java/org/nuiton/scmwebeditor/PrivateSvnServlet.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/PrivateSvnServlet.java 2011-06-07 20:09:55 UTC (rev 118) +++ trunk/src/main/java/org/nuiton/scmwebeditor/PrivateSvnServlet.java 2011-06-16 08:20:00 UTC (rev 119) @@ -37,13 +37,13 @@ /** * @author geoffroy lorieux */ -public class PrivateSvnServlet extends AbstractScmWebEditorServlet { +public class PrivateSvnServlet extends AbstractScmWebEditor { private static final long serialVersionUID = 1L; private static final Log log = LogFactory.getLog(PrivateSvnServlet.class); - @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (log.isDebugEnabled()) { log.debug("New Log setting"); @@ -64,7 +64,7 @@ log.debug("redirect url = " + url); } request.setAttribute(ATTRIBUTE_REDIRECT_URL, url); - redirect(request, response, "/Recall.jsp"); + //redirect(request, response, "/Recall.jsp"); out.close(); } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorMainServlet.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorMainServlet.java 2011-06-07 20:09:55 UTC (rev 118) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorMainServlet.java 2011-06-16 08:20:00 UTC (rev 119) @@ -49,7 +49,7 @@ /** * @author geoffroy lorieux */ -public class ScmWebEditorMainServlet extends AbstractScmWebEditorServlet { +public class ScmWebEditorMainServlet extends AbstractScmWebEditor { private static final long serialVersionUID = 1L; @@ -75,7 +75,7 @@ } HttpSession httpSession = request.getSession(true); try { - + // First Part Svn checkout and JSP call //FIXME-TC20091124 why doing this at each request ?, this is weird :) System.setProperty("file.encoding", "UTF-8"); Modified: trunk/src/main/java/org/nuiton/scmwebeditor/SearchServlet.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/SearchServlet.java 2011-06-07 20:09:55 UTC (rev 118) +++ trunk/src/main/java/org/nuiton/scmwebeditor/SearchServlet.java 2011-06-16 08:20:00 UTC (rev 119) @@ -43,7 +43,7 @@ import org.tmatesoft.svn.core.wc.SVNRevision; import org.tmatesoft.svn.core.wc.SVNWCUtil; -public class SearchServlet extends AbstractScmWebEditorServlet { +public class SearchServlet extends AbstractScmWebEditor { private static final Log log = LogFactory.getLog(SearchServlet.class); @@ -55,7 +55,7 @@ * @param response servlet response * @throws ServletException if a servlet-specific error occurs */ - @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException { try { String adresse = request.getParameter(PARAMETER_ADRESSE); Modified: trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java 2011-06-07 20:09:55 UTC (rev 118) +++ trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java 2011-06-16 08:20:00 UTC (rev 119) @@ -25,6 +25,10 @@ package org.nuiton.scmwebeditor; import org.apache.commons.io.FileUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.scmwebeditor.actions.ScmWebEditorMainAction; +import org.nuiton.util.FileUtil; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.SVNProperty; import org.tmatesoft.svn.core.SVNURL; @@ -38,6 +42,8 @@ public class SvnSession { + + private static final Log log = LogFactory.getLog(SvnSession.class); /** * Url of scm editor */ @@ -79,10 +85,6 @@ */ protected String password; /** - * Temp directory path - */ - protected File tmpDir; - /** * Temp directory for checkout */ protected File checkoutdir; @@ -112,12 +114,11 @@ String projectUrl, String login, String password, - File tmpDir, String id, String lang, String defaultLang, String format, - StringBuffer scmEditorUrl) throws SVNException { + StringBuffer scmEditorUrl) { this.scmEditorUrl = scmEditorUrl; this.id = id; this.format = format; @@ -128,9 +129,16 @@ this.projectUrl = projectUrl; this.login = login; this.password = password; - this.tmpDir = tmpDir; - this.checkoutdir = new File(this.tmpDir, "temp_rst" + id); - this.remoteUrl = SVNURL.parseURIEncoded(svnPath); + try { + this.checkoutdir = FileUtil.createTempDirectory("", ""); + } catch (IOException e) { + e.printStackTrace(); + } + try { + this.remoteUrl = SVNURL.parseURIEncoded(svnPath); + } catch (SVNException e) { + log.debug("SVNSESS NULL"); + } this.authManager = SVNWCUtil.createDefaultAuthenticationManager(this.checkoutdir, this.login, this.password, false); this.svnOption = SVNWCUtil.createDefaultOptions(this.checkoutdir, false); this.svnOption.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); @@ -233,14 +241,6 @@ this.svnPath = svnPath; } - public File getTmpDir() { - return tmpDir; - } - - public void setTmpDir(File tmpDir) { - this.tmpDir = tmpDir; - } - public String getLang() { return lang; } Added: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java (rev 0) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-16 08:20:00 UTC (rev 119) @@ -0,0 +1,218 @@ +package org.nuiton.scmwebeditor.actions; + +import java.io.File; +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts2.interceptor.ServletRequestAware; +import org.nuiton.scmwebeditor.AbstractScmWebEditor; +import org.nuiton.scmwebeditor.ScmWebEditorMainServlet; +import org.nuiton.scmwebeditor.SvnSession; +import org.tmatesoft.svn.core.SVNAuthenticationException; +import org.tmatesoft.svn.core.SVNDepth; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; +import org.tmatesoft.svn.core.wc.ISVNRepositoryPool; +import org.tmatesoft.svn.core.wc.SVNRevision; +import org.tmatesoft.svn.core.wc.SVNUpdateClient; + +public class ScmWebEditorMainAction extends AbstractScmWebEditor implements ServletRequestAware { + + private static final Log log = LogFactory.getLog(ScmWebEditorMainAction.class); + + protected String address; + protected String projectUrl; + protected String fileName; + protected String format; + protected String lang; + protected String defaultLang; + + protected HttpServletRequest request; + + + public String getAddress() { + return address; + } + + + public void setAddress(String address) { + this.address = address; + } + + + public String getProjectUrl() { + return projectUrl; + } + + + public void setProjectUrl(String projectUrl) { + this.projectUrl = projectUrl; + } + + + public String getFileName() { + return fileName; + } + + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + + public String getFormat() { + return format; + } + + + public void setFormat(String format) { + this.format = format; + } + + + public String getLang() { + return lang; + } + + + public void setLang(String lang) { + this.lang = lang; + } + + + public String getDefaultLang() { + return defaultLang; + } + + + public void setDefaultLang(String defaultLang) { + this.defaultLang = defaultLang; + } + + + /** + * On test si les parametres ne sont pas vide + * @return + */ + private boolean testParameters() { + if (address == null || address.length() == 0 + || fileName == null || fileName.length() == 0) { + return true; + } + else { + return false; + } + } + + + public String execute() { + + + + log.debug("--------------------------"); + log.debug("Connection to SCMWebEditor"); + log.debug("--------------------------"); + + /* Si il n'y a pas de parametre, l'utilisateur est renvoyé + * vers la page de configuration (OutConnection) + */ + if(testParameters()) { + return "noParameter"; + } + + HttpSession httpSession = request.getSession(true); + System.setProperty("file.encoding", "UTF-8"); + + //SvnSession object creation if doesn't already exist + SvnSession svnSess = getSvnSession(httpSession); + String scmUrl = address.startsWith("scm:svn:") ? address.replace("scm:svn:", "") : address; + + format = request.getParameter(PARAMETER_FORMAT) != null ? request.getParameter(PARAMETER_FORMAT) : ""; + + String relativePath = "/src/site/" + lang + "/" +( format.equals("") ? "" : format+"/"); + if (lang.equals(defaultLang)) { + // on a maven site, default locale is on root + relativePath = "/src/site/" +( format.equals("") ? "" : format+"/"); + projectUrl = projectUrl.replace("/"+defaultLang+"/", "/"); + } + + String scmPath = address.endsWith(relativePath) ? "" : relativePath; + + String scmFilename = fileName.endsWith(".html") ? fileName.replace(".html", "." + format) : fileName; + + String tmp_log = null; + String tmp_pass = null; + if (svnSess != null) { + tmp_log = svnSess.getLogin(); + tmp_pass = svnSess.getPassword(); + } + + svnSess = new SvnSession( + scmUrl + scmPath, + scmFilename, + projectUrl, + tmp_log, + tmp_pass, + httpSession.getId(), + lang, + defaultLang, + format, + request.getRequestURL()); + + log.debug("VALEUR SVNSESS 1: "+svnSess); + + setSvnSession(httpSession, svnSess); +// Tempdir creation on servlet default temporary directory + + + DAVRepositoryFactory.setup(); + SVNUpdateClient upclient = new SVNUpdateClient(svnSess.getManager(), svnSess.getSvnOption()); + + + log.debug("VALEUR SVNSESS 2: "+svnSess); +// Checkout svn and file organisation + try { + if (log.isDebugEnabled()) { + log.debug("Do Checkout of " + svnSess.getRemoteUrl()); + } + upclient.doCheckout(svnSess.getRemoteUrl(), svnSess.getCheckoutdir(), + SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false); + } catch (SVNAuthenticationException authexep) { + // if svn authentication failed user is redirected on login page + log.debug("Private SCM on reading " + svnSess.getRemoteUrl()); + try { + svnSess.cleanCheckoutDir(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return "private"; + } catch (SVNException e) { + + return "erreurPath"; + } + + + File file_in_dir = new File(svnSess.getCheckoutdir(), svnSess.getFileName()); + + + return "editPage"; + + + } + + + @Override + public void setServletRequest(HttpServletRequest request) { + this.request = request; + + } + + + +} Added: trunk/src/main/resources/struts.xml =================================================================== --- trunk/src/main/resources/struts.xml (rev 0) +++ trunk/src/main/resources/struts.xml 2011-06-16 08:20:00 UTC (rev 119) @@ -0,0 +1,15 @@ +<!DOCTYPE struts PUBLIC +"-//Apache Software Foundation//DTD Struts Configuration +2.0//EN" +"http://struts.apache.org/dtds/struts-2.0.dtd"> +<struts> + <package name="action" extends="struts-default"> + + <action name="main" class="org.nuiton.scmwebeditor.actions.ScmWebEditorMainAction" method="execute"> + <result name="noParameter" >/OutConnection.jsp</result> + <result name="private" >/PrivateSvnRedirect.jsp</result> + <result name="erreurPath" >/BadFileRedirect.jsp?scmEditorUrl=index.jsp</result> + <result name="editPage" >/accueil.jsp</result> + </action> + </package> +</struts> \ No newline at end of file Modified: trunk/src/main/webapp/BadFileRedirect.jsp =================================================================== --- trunk/src/main/webapp/BadFileRedirect.jsp 2011-06-07 20:09:55 UTC (rev 118) +++ trunk/src/main/webapp/BadFileRedirect.jsp 2011-06-16 08:20:00 UTC (rev 119) @@ -11,13 +11,13 @@ <link rel="icon" href="img/ScmWebEditor_little.png" type="image/png"> <link rel="stylesheet" type="text/css" href="css/main.css"> <meta http-equiv="Refresh" content="3; url= -<%=request.getAttribute("scmEditorUrl")%>"> +<%=request.getParameter("scmEditorUrl")%>"> </head> <body> <a target="_blank" href="http://maven-site.nuiton.org/scmwebeditor/"><img src="img/ScmWebEditor_main.png" alt="$alt" /></a> <p>Bad SCM path or file name! Please correct it.</p> <p>You should be transferred automatically to the form page. If not -please <a href="<%=request.getAttribute("scmEditorUrl")%>">click +please <a href="<%=request.getParameter("scmEditorUrl")%>">click this link</a>.</p> <p>©2004-2009 CodeLutin</p> </body> Modified: trunk/src/main/webapp/ModificationViewer.jsp =================================================================== --- trunk/src/main/webapp/ModificationViewer.jsp 2011-06-07 20:09:55 UTC (rev 118) +++ trunk/src/main/webapp/ModificationViewer.jsp 2011-06-16 08:20:00 UTC (rev 119) @@ -41,7 +41,7 @@ <input title="Save your work and continue editing this file." type="button" value="Save and Continue Editing" name="SaveandC" onclick="javascript:saver(this.form.Mytext, this.form.username, this.form.pw, this.form.Commit_message, this.form.Orig_text, this.form.scmEditorUrl);"/> <input title="Save this file and go back to previous page." type="submit" value="Save and Quit" name="Save"/> <%if (request.getAttribute("format").equals("rst") == true){ - %><input title="html preview of the curretn rst file state." type="button" value="Preview" name="Preview" onclick="javascript:preview(this.form.Mytext, this.form.previewServletUrl);"/><%}%> + %><input title="html preview of the current rst file state." type="button" value="Preview" name="Preview" onclick="javascript:preview(this.form.Mytext, this.form.previewServletUrl);"/><%}%> <input title="Reset text as current repository HEAD revision." type="reset" value="Reset" name="Reset" alt="Test plop plop plop"/> <input type="hidden" value="<%=request.getAttribute("Project_url")%>" name="Project_url"> <input title="Exit ScmWebEditor without saving." type="button" value="Exit" name="Cancel" onclick="javascript:cancelRedirectDelete(this.form.Orig_text, this.form.username, this.form.pw, this.form.Commit_message, this.form.Project_url, this.form.scmEditorUrl);"/> Modified: trunk/src/main/webapp/OutConnection.jsp =================================================================== --- trunk/src/main/webapp/OutConnection.jsp 2011-06-07 20:09:55 UTC (rev 118) +++ trunk/src/main/webapp/OutConnection.jsp 2011-06-16 08:20:00 UTC (rev 119) @@ -21,9 +21,9 @@ </h4> </center> <center> -<form method="get" action=<%=request.getAttribute("scmEditorUri")%>> - <p><label>SCM path: <input TYPE=text name="adresse" SIZE=100></label><input type="button" value="Search Files" name="search" onclick="javascript:fileSearch(this.form.adresse, this.form.searchServletUrl);"/></p> - <p><label>File name: <input TYPE=text NAME=file_name SIZE=20></label> +<form method="get" action="main.action"> + <p><label>SCM path: <input TYPE=text name="address" SIZE=100></label><input type="button" value="Search Files" name="search" onclick="javascript:fileSearch(this.form.adresse, this.form.searchServletUrl);"/></p> + <p><label>File name: <input TYPE=text NAME=fileName SIZE=20></label> <label>File type: <select name=format> <option value="rst">Rst <option value="apt">Apt @@ -37,6 +37,7 @@ <option value="en">En </select></label></p> +<input type="hidden" name="projectUrl" value="<%=request.getRequestURL()%>" /> <input type="hidden" name="searchServletUrl" value="<%=request.getAttribute("searchServletUrl")%>"/> <input type="submit" name="Save" /></form> </center> Modified: trunk/src/main/webapp/WEB-INF/web.xml =================================================================== --- trunk/src/main/webapp/WEB-INF/web.xml 2011-06-07 20:09:55 UTC (rev 118) +++ trunk/src/main/webapp/WEB-INF/web.xml 2011-06-16 08:20:00 UTC (rev 119) @@ -1,44 +1,69 @@ <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd"> - <servlet> - <servlet-name>ScmWebEditorMainServlet</servlet-name> - <servlet-class>org.nuiton.scmwebeditor.ScmWebEditorMainServlet</servlet-class> - </servlet> - <servlet> - <servlet-name>PreviewServlet</servlet-name> - <servlet-class>org.nuiton.scmwebeditor.PreviewServlet</servlet-class> - </servlet> - <servlet> - <servlet-name>PrivateSvnServlet</servlet-name> - <servlet-class>org.nuiton.scmwebeditor.PrivateSvnServlet</servlet-class> - </servlet> -<!-- <servlet>--> -<!-- <servlet-name>PictureUpload</servlet-name>--> -<!-- <servlet-class>org.nuiton.scmwebeditor.PictureUpload</servlet-class>--> -<!-- </servlet>--> + + + <filter> + <filter-name>struts2</filter-name> + <filter-class> + org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter + </filter-class> + </filter> + <filter-mapping> + <filter-name>struts2</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + + <welcome-file-list> + <welcome-file>index.jsp</welcome-file> + </welcome-file-list> + + <!-- <servlet> + <servlet-name>ScmWebEditorMainServlet</servlet-name> + <servlet-class>org.nuiton.scmwebeditor.ScmWebEditorMainServlet</servlet-class> + </servlet> + <servlet> + <servlet-name>PreviewServlet</servlet-name> + <servlet-class>org.nuiton.scmwebeditor.PreviewServlet</servlet-class> + </servlet> + <servlet> + <servlet-name>PrivateSvnServlet</servlet-name> + <servlet-class>org.nuiton.scmwebeditor.PrivateSvnServlet</servlet-class> + </servlet> + --> + +<!-- <servlet>--> +<!-- <servlet-name>PictureUpload</servlet-name>--> +<!-- <servlet-class>org.nuiton.scmwebeditor.PictureUpload</servlet-class>--> +<!-- </servlet>--> +<!-- + <servlet> <servlet-name>SearchServlet</servlet-name> <servlet-class>org.nuiton.scmwebeditor.SearchServlet</servlet-class> </servlet> <servlet-mapping> - <servlet-name>ScmWebEditorMainServlet</servlet-name> - <url-pattern>/scmwebeditor</url-pattern> - </servlet-mapping> - <servlet-mapping> - <servlet-name>PreviewServlet</servlet-name> - <url-pattern>/previewservlet</url-pattern> - </servlet-mapping> - <servlet-mapping> - <servlet-name>PrivateSvnServlet</servlet-name> - <url-pattern>/privatesvnservlet</url-pattern> - </servlet-mapping> -<!-- <servlet-mapping>--> -<!-- <servlet-name>PictureUpload</servlet-name>--> -<!-- <url-pattern>/pictureUpload</url-pattern>--> -<!-- </servlet-mapping>--> - + <servlet-name>ScmWebEditorMainServlet</servlet-name> + <url-pattern>/scmwebeditor</url-pattern> + </servlet-mapping> <servlet-mapping> + <servlet-name>PreviewServlet</servlet-name> + <url-pattern>/previewservlet</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>PrivateSvnServlet</servlet-name> + <url-pattern>/privatesvnservlet</url-pattern> + </servlet-mapping> +--> +<!-- <servlet-mapping>--> +<!-- <servlet-name>PictureUpload</servlet-name>--> +<!-- <url-pattern>/pictureUpload</url-pattern>--> +<!-- </servlet-mapping>--> +<!-- + <servlet-mapping> <servlet-name>SearchServlet</servlet-name> <url-pattern>/searchservlet</url-pattern> </servlet-mapping> - </web-app> + --> + +</web-app> Added: trunk/src/main/webapp/accueil.jsp =================================================================== --- trunk/src/main/webapp/accueil.jsp (rev 0) +++ trunk/src/main/webapp/accueil.jsp 2011-06-16 08:20:00 UTC (rev 119) @@ -0,0 +1,9 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<html> + <head> + </head> + + <body> + <p>Parametres detectés</p> + </body> +</html> \ No newline at end of file Added: trunk/src/main/webapp/index.jsp =================================================================== --- trunk/src/main/webapp/index.jsp (rev 0) +++ trunk/src/main/webapp/index.jsp 2011-06-16 08:20:00 UTC (rev 119) @@ -0,0 +1,3 @@ +<% +response.sendRedirect("main.action"); +%> \ No newline at end of file
participants (1)
-
kcardineaud@users.nuiton.org