Author: kcardineaud Date: 2011-06-16 10:31:07 +0200 (Thu, 16 Jun 2011) New Revision: 120 Url: http://nuiton.org/repositories/revision/scmwebeditor/120 Log: Delete the useless file ScmWebEditorMainServlet Removed: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorMainServlet.java Deleted: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorMainServlet.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorMainServlet.java 2011-06-16 08:20:00 UTC (rev 119) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorMainServlet.java 2011-06-16 08:31:07 UTC (rev 120) @@ -1,287 +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 org.apache.commons.io.FileUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -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.SVNCommitClient; -import org.tmatesoft.svn.core.wc.SVNRevision; -import org.tmatesoft.svn.core.wc.SVNUpdateClient; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.apache.commons.lang.StringEscapeUtils; - -/** - * @author geoffroy lorieux - */ -public class ScmWebEditorMainServlet extends AbstractScmWebEditor { - - private static final long serialVersionUID = 1L; - - private static final Log log = LogFactory.getLog(ScmWebEditorMainServlet.class); - - /** - * Handles the HTTP <code>GET</code> method. - * Do checkout on a private or not scm and call modification jsp page - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs - */ - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - - if (log.isDebugEnabled()) { - log.debug("--------------------------"); - log.debug("Connection to SCMWebEditor"); - log.debug("--------------------------"); - } - 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"); - -// Redirect if the SCMWebEditor is not call from an other website - String paramAdresse = request.getParameter(PARAMETER_ADRESSE); - String paramFileName = request.getParameter(PARAMETER_FILE_NAME); - String paramProjectUrl = request.getParameter(PARAMETER_PROJECT_URL); - - if (paramAdresse == null || paramFileName == null || paramProjectUrl == null) { - // il manque des paramètres pour editer une ressource - - SvnSession svnSess = getSvnSession(httpSession); - if (svnSess != null) { - // on nettoye le répertoire de checkout - svnSess.cleanCheckoutDir(); - } - // on redirige vers la page OutConnection.jsp - request.setAttribute(ATTRIBUTE_SCM_EDITOR_URI, request.getRequestURI()); - request.setAttribute(ATTRIBUTE_FILESEARCH_SERVLET_URL, request.getContextPath() + "/searchservlet"); - log.debug("l'uri est: " + request.getRequestURI()); - redirect(request, response, "/OutConnection.jsp"); - return; - } - - if (paramAdresse.equals("") || paramFileName.equals("") || paramProjectUrl.equals("")) { - // les paramètres sont invalides, impossible d'éditer la ressource - // on redirige sur la page BadFileRedirect.jsp - request.setAttribute(PARAMETER_SCM_EDITOR_URL, paramProjectUrl); - redirect(request, response, "/BadFileRedirect.jsp"); - return; - } - -// SvnSession object creation if doesn't already exist - SvnSession svnSess = getSvnSession(httpSession); - - String scmUrl = paramAdresse.startsWith("scm:svn:") ? paramAdresse.replace("scm:svn:", "") : paramAdresse; - - String paramLang = request.getParameter(PARAMETER_LANG); - String paramDefaultLang = request.getParameter(PARAMETER_DEFAULT_LANG); - String paramFormat = request.getParameter(PARAMETER_FORMAT) != null ? request.getParameter(PARAMETER_FORMAT) : ""; - - String relativePath = "/src/site/" + paramLang + "/" +( paramFormat.equals("") ? "" : paramFormat+"/"); - if (paramLang.equals(paramDefaultLang)) { - // on a maven site, default locale is on root - relativePath = "/src/site/" +( paramFormat.equals("") ? "" : paramFormat+"/"); - paramProjectUrl = paramProjectUrl.replace("/"+paramDefaultLang+"/", "/"); - } - - String scmPath = paramAdresse.endsWith(relativePath) ? "" : relativePath; - - String scmFilename = paramFileName.endsWith(".html") ? paramFileName.replace(".html", "." + paramFormat) : paramFileName; - File tempDir = getTempDir(); - 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, - paramProjectUrl, - tmp_log, - tmp_pass, - tempDir, - httpSession.getId(), - paramLang, - paramDefaultLang, - paramFormat, - request.getRequestURL()); - - setSvnSession(httpSession, svnSess); -// Tempdir creation on servlet default temporary directory - - svnSess.getCheckoutdir().mkdir(); -// update client initialisation - - DAVRepositoryFactory.setup(); - SVNUpdateClient upclient = new SVNUpdateClient(svnSess.getManager(), svnSess.getSvnOption()); - -// 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()); - svnSess.cleanCheckoutDir(); - - request.setAttribute(ATTRIBUTE_PRIVATE_SERVLET_URI, request.getContextPath() + "/privatesvnservlet"); - redirect(request, response, "/PrivateSvnRedirect.jsp"); - - return; - } - - File file_in_dir = new File(svnSess.getCheckoutdir(), svnSess.getFileName()); - try { - String original_text = FileUtils.readFileToString(file_in_dir); - request.setAttribute(PARAMETER_FORMAT, svnSess.getFormat()); - request.setAttribute(ATTRIBUTE_ORIG_TEXT, StringEscapeUtils.escapeHtml(original_text)); - request.setAttribute(ATTRIBUTE_INVALIDATE_MAX_TIME, (httpSession.getMaxInactiveInterval() / 60)); - request.setAttribute(ATTRIBUTE_LOGIN, (svnSess.getLogin() != null && !svnSess.getLogin().equalsIgnoreCase("") ? svnSess.getLogin() : null)); - request.setAttribute(ATTRIBUTE_IS_LOGIN, (svnSess.getLogin() != null && svnSess.getPassword() != null && !svnSess.getLogin().equalsIgnoreCase("") && !svnSess.getPassword().equalsIgnoreCase(""))); - request.setAttribute(ATTRIBUTE_PROJECT_URL, svnSess.getProjectUrl()); - request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getScmEditorUrl()); - if (log.isDebugEnabled()) { - log.debug("l'url est:" + svnSess.getScmEditorUrl()); - } - request.setAttribute(ATTRIBUTE_SCM_EDITOR_URI, request.getRequestURI()); - request.setAttribute(ATTRIBUTE_PREVIEW_SERVLET_URL, request.getContextPath() + "/previewservlet"); - redirect(request, response, "/ModificationViewer.jsp"); - // End on first part - - } catch (FileNotFoundException ee) { - // fichier non trouve, on redirige vers BadFileRedirect.jsp - FileUtils.deleteDirectory(svnSess.getCheckoutdir()); - request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getProjectUrl()); - redirect(request, response, "/BadFileRedirect.jsp"); - } -// JSP data transfert - - } catch (SVNException ex) { - // probleme svn, on redirige vers BadUseRedirect.jsp - if (log.isErrorEnabled()) { - log.error(ex); - } - SvnSession svnSess = getSvnSession(httpSession); - FileUtils.deleteDirectory(svnSess.getCheckoutdir()); - request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getProjectUrl()); - redirect(request, response, "/BadUseRedirect.jsp"); - } - } - - /** - * Handles the HTTP <code>POST</code> method. - * Receve the new text and commit it to scm - * - * @param request servlet request - * @param response servlet response - * @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 { - try { - -// Second Part Client response and SVN commit - //FIXME-TC20091124 why doing this at each request ?, this is weird :) - System.setProperty("file.encoding", "UTF-8"); - HttpSession httpSession = request.getSession(true); - SvnSession svnSess = getSvnSession(httpSession); - -// Resetting authentification information and manager - svnSess.updateAuthentication( - svnSess.getLogin() != null && !svnSess.getLogin().equalsIgnoreCase("") ? svnSess.getLogin() : request.getParameter(PARAMETER_USERNAME), - svnSess.getPassword() != null && !svnSess.getPassword().equalsIgnoreCase("") ? svnSess.getPassword() : request.getParameter(PARAMETER_PW)); - - String originalText = StringEscapeUtils.unescapeHtml(request.getParameter(PARAMETER_ORIG_TEXT)); - String myText = StringEscapeUtils.unescapeHtml(request.getParameter(PARAMETER_MYTEXT)); - - File pathToFile = new File(svnSess.getCheckoutdir(), svnSess.getFileName()); - - SVNCommitClient commitClient = new SVNCommitClient(svnSess.getManager(), svnSess.getSvnOption()); - FileUtils.writeStringToFile(pathToFile, request.getParameter(PARAMETER_MYTEXT)); - - convertToUnicode(pathToFile); - - File[] tabFile = new File[1]; - tabFile[0] = pathToFile; -// Sending Data to SVN - - if (!myText.equals(originalText)) { - try { - log.debug("Je commit"); - //TODO-TC20091124 Should add a prefix to the commit file ? something like from scmwebeditor -- - commitClient.doCommit(tabFile, false, request.getParameter(PARAMETER_COMMIT_MESSAGE), null, null, false, true, SVNDepth.FILES); - } catch (SVNAuthenticationException authexep) { - // if authentication failed edition page is reload form user's relogin - response.setStatus(401); - String url = getRedirectUrl(svnSess); - request.setAttribute(ATTRIBUTE_REDIRECT_URL, url); - redirect(request, response, "/Error.jsp"); - return; - } - } - - if (svnSess.getCheckoutdir() != null) { - log.debug("Je delete le tempdir"); - FileUtils.deleteDirectory(svnSess.getCheckoutdir()); - } -// if commit success user is redirect on the project page - request.setAttribute(ATTRIBUTE_REDIRECTION_URL, svnSess.getProjectUrl()); - redirect(request, response, "/Redirect.jsp"); - -// End of Second part - - log.debug("Exit RSTEditor"); - - } catch (SVNException ex) { - Logger.getLogger(ScmWebEditorMainServlet.class.getName()).log(Level.SEVERE, null, ex); - } - } - -}
participants (1)
-
kcardineaud@users.nuiton.org