Scmwebeditor-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- 439 discussions
r129 - in trunk/src/main: java/org/nuiton/scmwebeditor java/org/nuiton/scmwebeditor/actions resources webapp
by kcardineaud@users.nuiton.org 21 Jun '11
by kcardineaud@users.nuiton.org 21 Jun '11
21 Jun '11
Author: kcardineaud
Date: 2011-06-21 11:02:44 +0200 (Tue, 21 Jun 2011)
New Revision: 129
Url: http://nuiton.org/repositories/revision/scmwebeditor/129
Log:
Add JQuery for ajax preview
Added:
trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java
trunk/src/main/webapp/Preview.jsp
Removed:
trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java
Modified:
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/SearchServlet.java
trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java
trunk/src/main/java/org/nuiton/scmwebeditor/actions/PreviewAction.java
trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java
trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java
trunk/src/main/resources/struts.xml
trunk/src/main/webapp/ModificationViewer.jsp
Deleted: trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java 2011-06-20 15:03:57 UTC (rev 128)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java 2011-06-21 09:02:44 UTC (rev 129)
@@ -1,221 +0,0 @@
-/*
- * #%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/scmwe… $
- * %%
- * 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.FileUtils;
-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 = "address";
- protected static final String PARAMETER_SCM_EDITOR_URL = "scmEditorUrl";
- protected static final String PARAMETER_PROJECT_URL = "projectUrl";
- protected static final String PARAMETER_FILE_NAME = "file_name";
- protected static final String PARAMETER_LANG = "lang";
- protected static final String PARAMETER_DEFAULT_LANG = "defaultLang";
- protected static final String PARAMETER_FORMAT = "format";
- protected static final String PARAMETER_USERNAME = "username";
- protected static final String PARAMETER_PW = "pw";
- protected static final String PARAMETER_MYTEXT = "Mytext";
- protected static final String PARAMETER_ORIG_TEXT = "Orig_text";
- protected static final String PARAMETER_COMMIT_MESSAGE = "Commit_message";
- protected static final String PARAMETER_TEXT = "text";
-
- //protected static final String ATTRIBUTE_TEMPDIR = "javax.servlet.context.tempdir";
- // protected static final String ATTRIBUTE_SVN_PATH_URL = "svnPath_url";
-// protected static final String ATTRIBUTE_FILE_NAME_URL = "fileName_url";
- protected static final String ATTRIBUTE_REDIRECTION_URL = "Redirection_url";
- // protected static final String ATTRIBUTE_LANG = "Lang";
- // protected static final String ATTRIBUTE_FORMAT = "Format";
- private static final String ATTRIBUTE_SVN_SESSION = "myInfo";
-
- protected static final String ATTRIBUTE_ORIG_TEXT = "OrigText";
- protected static final String ATTRIBUTE_INVALIDATE_MAX_TIME = "InvalidateMaxTime";
- protected static final String ATTRIBUTE_LOGIN = "Login";
- protected static final String ATTRIBUTE_IS_LOGIN = "IsLogin";
- protected static final String ATTRIBUTE_BAD_LOGIN = "badLogin";
- protected static final String ATTRIBUTE_PROJECT_URL = "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);
- }
- }
- }
- }
-
- public void delTempDirectory(SvnSession svnSess) {
- try {
- FileUtils.deleteDirectory(svnSess.getCheckoutdir());
- } catch (IOException e) {
- if(log.isErrorEnabled()) {
- log.error("Can't delete temp directory");
- }
- }
- }
-
-
- 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()+svnSess.getFileName());
- buffer.append("&").append(PARAMETER_PROJECT_URL).append('=').append(svnSess.getProjectUrl());
-
- 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-20 15:03:57 UTC (rev 128)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/PreviewServlet.java 2011-06-21 09:02:44 UTC (rev 129)
@@ -40,7 +40,7 @@
/**
* @author geoffroy lorieux
*/
-public class PreviewServlet extends AbstractScmWebEditor {
+public class PreviewServlet extends ScmWebEditorBaseAction {
private static final long serialVersionUID = 1L;
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/PrivateSvnServlet.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/PrivateSvnServlet.java 2011-06-20 15:03:57 UTC (rev 128)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/PrivateSvnServlet.java 2011-06-21 09:02:44 UTC (rev 129)
@@ -37,7 +37,7 @@
/**
* @author geoffroy lorieux
*/
-public class PrivateSvnServlet extends AbstractScmWebEditor {
+public class PrivateSvnServlet extends ScmWebEditorBaseAction {
private static final long serialVersionUID = 1L;
Added: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java (rev 0)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-06-21 09:02:44 UTC (rev 129)
@@ -0,0 +1,219 @@
+/*
+ * #%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/scmwe… $
+ * %%
+ * 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.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.opensymphony.xwork2.ActionSupport;
+
+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 ScmWebEditorBaseAction extends ActionSupport {
+
+ private static final long serialVersionUID = 1L;
+ final static protected String CONTEXT_ACTION_KEY = "action";
+
+ private static final Log log = LogFactory.getLog(ScmWebEditorBaseAction.class);
+
+ //TODO-TC200924 : uniformize all this different parameter and attribute, this is a bit messy...
+ protected static final String PARAMETER_ADRESSE = "address";
+ protected static final String PARAMETER_SCM_EDITOR_URL = "scmEditorUrl";
+ protected static final String PARAMETER_PROJECT_URL = "projectUrl";
+ protected static final String PARAMETER_FILE_NAME = "file_name";
+ protected static final String PARAMETER_LANG = "lang";
+ protected static final String PARAMETER_DEFAULT_LANG = "defaultLang";
+ protected static final String PARAMETER_FORMAT = "format";
+ protected static final String PARAMETER_USERNAME = "username";
+ protected static final String PARAMETER_PW = "pw";
+ protected static final String PARAMETER_MYTEXT = "Mytext";
+ protected static final String PARAMETER_ORIG_TEXT = "Orig_text";
+ protected static final String PARAMETER_COMMIT_MESSAGE = "Commit_message";
+ protected static final String PARAMETER_TEXT = "text";
+
+ //protected static final String ATTRIBUTE_TEMPDIR = "javax.servlet.context.tempdir";
+ // protected static final String ATTRIBUTE_SVN_PATH_URL = "svnPath_url";
+// protected static final String ATTRIBUTE_FILE_NAME_URL = "fileName_url";
+ protected static final String ATTRIBUTE_REDIRECTION_URL = "Redirection_url";
+ // protected static final String ATTRIBUTE_LANG = "Lang";
+ // protected static final String ATTRIBUTE_FORMAT = "Format";
+ private static final String ATTRIBUTE_SVN_SESSION = "myInfo";
+
+ protected static final String ATTRIBUTE_ORIG_TEXT = "OrigText";
+ protected static final String ATTRIBUTE_INVALIDATE_MAX_TIME = "InvalidateMaxTime";
+ protected static final String ATTRIBUTE_LOGIN = "Login";
+ protected static final String ATTRIBUTE_IS_LOGIN = "IsLogin";
+ protected static final String ATTRIBUTE_BAD_LOGIN = "badLogin";
+ protected static final String ATTRIBUTE_PROJECT_URL = "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);
+ }
+ }
+ }
+ }
+
+ public void delTempDirectory(SvnSession svnSess) {
+ try {
+ FileUtils.deleteDirectory(svnSess.getCheckoutdir());
+ } catch (IOException e) {
+ if(log.isErrorEnabled()) {
+ log.error("Can't delete temp directory");
+ }
+ }
+ }
+
+
+ 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()+svnSess.getFileName());
+ buffer.append("&").append(PARAMETER_PROJECT_URL).append('=').append(svnSess.getProjectUrl());
+
+ String url = buffer.toString();
+ return url;
+ }
+
+}
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/SearchServlet.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/SearchServlet.java 2011-06-20 15:03:57 UTC (rev 128)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/SearchServlet.java 2011-06-21 09:02:44 UTC (rev 129)
@@ -43,8 +43,12 @@
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
-public class SearchServlet extends AbstractScmWebEditor {
+public class SearchServlet extends ScmWebEditorBaseAction {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8229295563440910960L;
private static final Log log = LogFactory.getLog(SearchServlet.class);
/**
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java 2011-06-20 15:03:57 UTC (rev 128)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java 2011-06-21 09:02:44 UTC (rev 129)
@@ -27,7 +27,6 @@
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;
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/PreviewAction.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/actions/PreviewAction.java 2011-06-20 15:03:57 UTC (rev 128)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/PreviewAction.java 2011-06-21 09:02:44 UTC (rev 129)
@@ -1,9 +1,8 @@
package org.nuiton.scmwebeditor.actions;
-import java.io.ByteArrayInputStream;
+
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import javax.servlet.http.HttpServletRequest;
@@ -14,17 +13,42 @@
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.nuiton.jrst.JRST;
-import org.nuiton.scmwebeditor.AbstractScmWebEditor;
+import org.nuiton.scmwebeditor.ScmWebEditorBaseAction;
import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.ActionContext;
-public class PreviewAction extends AbstractScmWebEditor implements ServletRequestAware {
+public class PreviewAction extends ScmWebEditorBaseAction implements ServletRequestAware {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2388759298175611718L;
HttpServletRequest request;
- InputStream XMLResponse;
+ String XMLResponse;
+ String newText;
+
+
+ public String getNewText() {
+ return newText;
+ }
+
+ public void setNewText(String newText) {
+ this.newText = newText;
+ }
+
+ public String getXMLResponse() {
+ return XMLResponse;
+ }
+
+ public void setXMLResponse(String XMLResponse) {
+ this.XMLResponse = XMLResponse;
+ }
+
+
private static final Log log = LogFactory.getLog(PreviewAction.class);
public String execute() {
@@ -35,13 +59,13 @@
public void setResponse() {
if(log.isDebugEnabled()) {
- log.debug("Enter in Servlet Action");
+ log.debug("Enter in preview action");
}
HttpSession httpSession = request.getSession(true);
File tmpDir = getTempDir(httpSession);
//Text recuperation
- String myData = request.getParameter(PARAMETER_TEXT);
+ String myData = newText;
//Text formating and tempfile creating
String myDataWithoutcrlf = myData.replace("\r", "");
File fileInDirCopy = new File(tmpDir, "copy" + httpSession.getId() + ".rst");
@@ -52,7 +76,7 @@
FileUtils.writeStringToFile(fileInDirCopy, myDataWithoutcrlf);
} catch (IOException e) {
if(log.isErrorEnabled()) {
- log.error("Erreur de lecture/ecriture",e);
+ log.error("read/write error",e);
}
}
@@ -70,14 +94,14 @@
if(log.isWarnEnabled()) {
log.warn("RST generate fail",eee);
}
- XMLResponse = new ByteArrayInputStream("<h4>Parsing error, please read RST specification<h4>".getBytes());
+ XMLResponse = "<h4>Parsing error, please read RST specification<h4>";
return;
}
copy.delete();
try {
- XMLResponse = new ByteArrayInputStream(FileUtils.readFileToString(httpFile).getBytes());
+ XMLResponse = FileUtils.readFileToString(httpFile);
} catch (IOException e) {
e.printStackTrace();
}
@@ -88,14 +112,11 @@
}
- public InputStream getXMLResponse() {
- return XMLResponse;
+ static public PreviewAction getAction() {
+ return (PreviewAction) ActionContext.getContext()
+ .get(CONTEXT_ACTION_KEY);
}
- public void setXMLResponse(InputStream xMLResponse) {
- XMLResponse = xMLResponse;
- }
-
@Override
public void setServletRequest(HttpServletRequest request) {
this.request = request;
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-20 15:03:57 UTC (rev 128)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-21 09:02:44 UTC (rev 129)
@@ -11,14 +11,19 @@
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.ScmWebEditorBaseAction;
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.wc.SVNCommitClient;
-public class ScmWebEditorCommitAction extends AbstractScmWebEditor implements ServletRequestAware {
+public class ScmWebEditorCommitAction extends ScmWebEditorBaseAction implements ServletRequestAware {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6374273568146287730L;
+
private static final Log log = LogFactory.getLog(ScmWebEditorCommitAction.class);
protected String newText;
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-20 15:03:57 UTC (rev 128)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-21 09:02:44 UTC (rev 129)
@@ -6,14 +6,13 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
-import javax.swing.Action;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
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.ScmWebEditorBaseAction;
import org.nuiton.scmwebeditor.SvnSession;
import org.tmatesoft.svn.core.SVNAuthenticationException;
import org.tmatesoft.svn.core.SVNDepth;
@@ -22,8 +21,13 @@
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
-public class ScmWebEditorMainAction extends AbstractScmWebEditor implements ServletRequestAware {
+public class ScmWebEditorMainAction extends ScmWebEditorBaseAction implements ServletRequestAware {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8361035067228171624L;
+
private static final Log log = LogFactory.getLog(ScmWebEditorMainAction.class);
protected String address;
Modified: trunk/src/main/resources/struts.xml
===================================================================
--- trunk/src/main/resources/struts.xml 2011-06-20 15:03:57 UTC (rev 128)
+++ trunk/src/main/resources/struts.xml 2011-06-21 09:02:44 UTC (rev 129)
@@ -17,10 +17,7 @@
<result name="erreur">/BadFileRedirect.jsp</result>
</action>
<action name="preview" class="org.nuiton.scmwebeditor.actions.PreviewAction" method="execute">
- <result type="stream" >
- <param name="contentType">text/xml</param>
- <param name="inputName">XMLResponse</param>
- </result>
+ <result>/Preview.jsp</result>
</action>
<action name="search" class="org.nuiton.scmwebeditor.actions.SearchAction" method="execute">
<result type="stream" >
Modified: trunk/src/main/webapp/ModificationViewer.jsp
===================================================================
--- trunk/src/main/webapp/ModificationViewer.jsp 2011-06-20 15:03:57 UTC (rev 128)
+++ trunk/src/main/webapp/ModificationViewer.jsp 2011-06-21 09:02:44 UTC (rev 129)
@@ -1,5 +1,8 @@
<%-- Document : ModificationViewer Created on : 10 sept. 2009, 13:43:11 Author : glorieux --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
+ <%@ taglib prefix="s" uri="/struts-tags"%>
+ <%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
+ <sj:head jquerytheme="default"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
@@ -16,7 +19,7 @@
<%if (request.getAttribute("format")!=null && request.getAttribute("format").equals("rst") == true){
%><h4>For any Problem with RestruturedText visit <a href="http://docutils.sourceforge.net/rst.html">RST documentation website</a>.</h4></center><%}%>
<center>
- <form method="post" action=commit.action>
+ <form method="post" action=commit.action id="editForm">
<script src="GereFormSize.js" type="text/javascript"></script>
<textarea name="newText" id="newText"><%=request.getAttribute("OrigText")%></textarea>
<script src="Preview.js" type="text/javascript"></script>
@@ -31,11 +34,11 @@
<%if (request.getAttribute("IsLogin").equals(false) == true){
%>
<%if (request.getAttribute("badLogin")!=null && request.getAttribute("badLogin").equals(true)) { %>
- <p>
- <font color="red">
- Bad username or password
- </font>
- </p>
+ <p>
+ <font color="red">
+ Bad username or password
+ </font>
+ </p>
<% } %>
<p>
@@ -52,14 +55,41 @@
<input title="Save your work and continue editing this file." type="button" value="Save and Continue Editing" name="SaveandC" onclick="javascript:saver(this.form.newText, this.form.username, this.form.pw, this.form.commitMessage, this.form.origText, 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")!=null && request.getAttribute("format")!=null && request.getAttribute("format").equals("rst") == true){
- %><input title="html preview of the current rst file state." type="button" value="Preview" name="Preview" onclick="javascript:preview(this.form.newText, this.form.previewServletUrl);"/><%}%>
+ %>
+
+ <s:url id="ajaxPreview" value="preview.action" />
+
+ <sj:submit
+ id="ajaxformlink"
+ formIds="editForm"
+ targets="htmlcontentPreview"
+ href="%{ajaxPreview}"
+ indicator="indicator"
+ button="true"
+ buttonIcon="ui-icon-refresh"
+ value="Preview"
+ >
+ </sj:submit>
+
+
+ <%}%>
<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("ProjectUrl")%>" name="ProjectUrl">
<input title="Exit ScmWebEditor without saving." type="button" value="Exit" name="Cancel" onclick="javascript:cancelRedirectDelete(this.form.origText, this.form.username, this.form.pw, this.form.commitMessage, this.form.ProjectUrl, this.form.scmEditorUrl);"/>
- </form></center>
- <%--Title and div for rst preview--%>
- <h3 id="prevtitle" ></h3>
- <div id="prev" title="Preview"></div>
+
+
+
+
+
+ </form>
+
+
+
+
+
+ </center>
+ <div id="htmlcontentPreview"></div>
+
<p align="right">©2004-2009 CodeLutin</p>
</body>
</html>
Added: trunk/src/main/webapp/Preview.jsp
===================================================================
--- trunk/src/main/webapp/Preview.jsp (rev 0)
+++ trunk/src/main/webapp/Preview.jsp 2011-06-21 09:02:44 UTC (rev 129)
@@ -0,0 +1,17 @@
+<%@page
+ import="org.nuiton.scmwebeditor.actions.PreviewAction"%>
+
+ <%--Title and div for rst preview--%>
+ <h3 id="prevtitle" ></h3>
+ <div id="prev" title="Preview">
+ <div id="preview" >
+ <%
+ PreviewAction action = PreviewAction.getAction();
+
+ String preview = action.getXMLResponse();
+
+ %>
+ <%=preview%>
+
+ </div>
+ </div>
1
0
r128 - in trunk/src/main: java/org/nuiton/scmwebeditor resources webapp
by kcardineaud@users.nuiton.org 20 Jun '11
by kcardineaud@users.nuiton.org 20 Jun '11
20 Jun '11
Author: kcardineaud
Date: 2011-06-20 17:03:57 +0200 (Mon, 20 Jun 2011)
New Revision: 128
Url: http://nuiton.org/repositories/revision/scmwebeditor/128
Log:
Add search file option (but isn't finish)
Modified:
trunk/src/main/java/org/nuiton/scmwebeditor/PrivateSvnServlet.java
trunk/src/main/resources/struts.xml
trunk/src/main/webapp/OutConnection.jsp
trunk/src/main/webapp/PrivateSvnRedirect.jsp
trunk/src/main/webapp/fileSearch.js
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/PrivateSvnServlet.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/PrivateSvnServlet.java 2011-06-20 12:41:21 UTC (rev 127)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/PrivateSvnServlet.java 2011-06-20 15:03:57 UTC (rev 128)
@@ -58,7 +58,7 @@
svnSess.updateAuthentication(request.getParameter(PARAMETER_USERNAME), request.getParameter(PARAMETER_PW));
//FIXME-TC20091124 : why repush the object already in session, I don't see the point...
setSvnSession(httpSession, svnSess);
-// Recalling helloservlet with user information stock on session
+ // Recalling helloservlet with user information stock on session
String url = getRedirectUrl(svnSess);
if (log.isDebugEnabled()) {
log.debug("redirect url = " + url);
Modified: trunk/src/main/resources/struts.xml
===================================================================
--- trunk/src/main/resources/struts.xml 2011-06-20 12:41:21 UTC (rev 127)
+++ trunk/src/main/resources/struts.xml 2011-06-20 15:03:57 UTC (rev 128)
@@ -22,5 +22,11 @@
<param name="inputName">XMLResponse</param>
</result>
</action>
+ <action name="search" class="org.nuiton.scmwebeditor.actions.SearchAction" method="execute">
+ <result type="stream" >
+ <param name="contentType">text/xml</param>
+ <param name="inputName">XMLResponse</param>
+ </result>
+ </action>
</package>
</struts>
\ No newline at end of file
Modified: trunk/src/main/webapp/OutConnection.jsp
===================================================================
--- trunk/src/main/webapp/OutConnection.jsp 2011-06-20 12:41:21 UTC (rev 127)
+++ trunk/src/main/webapp/OutConnection.jsp 2011-06-20 15:03:57 UTC (rev 128)
@@ -22,7 +22,7 @@
</center>
<center>
<form method="get" action="checkout.action">
- <p><label>SCM path: <input TYPE=text name="address" SIZE=100></label><input disabled="disabled" type="button" value="Search Files" name="search" onclick="javascript:fileSearch(this.form.address, 'SearchServlet');"/></p>
+ <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.address);"/></p>
<input type="hidden" name="projectUrl" value="<%=request.getRequestURL()%>" />
Modified: trunk/src/main/webapp/PrivateSvnRedirect.jsp
===================================================================
--- trunk/src/main/webapp/PrivateSvnRedirect.jsp 2011-06-20 12:41:21 UTC (rev 127)
+++ trunk/src/main/webapp/PrivateSvnRedirect.jsp 2011-06-20 15:03:57 UTC (rev 128)
@@ -13,7 +13,7 @@
</head>
<body>
<a target="_blank" href="http://maven-site.nuiton.org/scmwebeditor/"><img src="img/ScmWebEditor_main.png" alt="$alt" /></a>
-<form method="post" action=<%=request.getAttribute("privateServletUri")%>>
+<form method="post" action="checkout.action" >
<script src="cancelRedirect.js"></script>
<p>You try to access a Private SCM. Please login</p>
<p><label ACCESSKEY=U>User name: <input TYPE=text
Modified: trunk/src/main/webapp/fileSearch.js
===================================================================
--- trunk/src/main/webapp/fileSearch.js 2011-06-20 12:41:21 UTC (rev 127)
+++ trunk/src/main/webapp/fileSearch.js 2011-06-20 15:03:57 UTC (rev 128)
@@ -22,26 +22,29 @@
//Make the XMLHttpRequest Object
var http= createRequestObject();
-function sendRequestToFileSearchServlet(scmPath, scmEditorUrl)
+function sendRequestToFileSearchAction(scmPath, searchUrl)
{
- http.open("POST", scmEditorUrl, true);
- http.onreadystatechange = handleResponseFromFileSearchServlet;
+ http.open("POST", searchUrl, true);
+ http.onreadystatechange = handleResponseFromFileSearchAction;
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- http.send("adresse="+scmPath.value);
+ http.send("address="+scmPath.value);
}
-function handleResponseFromFileSearchServlet()
+function handleResponseFromFileSearchAction()
{
if(http.readyState == 4 && http.status != 401){
alert("Can find file Continue");
+ var response = http.responseText;
+ alert(response);
+
+
} else if (http.readyState == 4 && http.status == 401){
alert("Cannot find files please recheck Scm path.");
}
}
-function fileSearch(scmPath, scmEditorUrl)
+function fileSearch(scmPath)
{
alert(scmPath.value);
- alert(scmEditorUrl);
- sendRequestToFileSearchServlet(scmPath, scmEditorUrl);
+ sendRequestToFileSearchAction(scmPath, "search.action");
}
1
0
Author: kcardineaud
Date: 2011-06-20 14:41:21 +0200 (Mon, 20 Jun 2011)
New Revision: 127
Url: http://nuiton.org/repositories/revision/scmwebeditor/127
Log:
Add save and continue option
Modified:
trunk/src/main/webapp/ModificationViewer.jsp
trunk/src/main/webapp/Preview.js
trunk/src/main/webapp/Saver.js
trunk/src/main/webapp/css/main.css
Modified: trunk/src/main/webapp/ModificationViewer.jsp
===================================================================
--- trunk/src/main/webapp/ModificationViewer.jsp 2011-06-20 09:40:04 UTC (rev 126)
+++ trunk/src/main/webapp/ModificationViewer.jsp 2011-06-20 12:41:21 UTC (rev 127)
@@ -46,7 +46,7 @@
<input type="hidden" NAME=username />
<input type="hidden" NAME=pw /><%
}%>
- <input type="hidden" name="origText" value=<%=request.getAttribute("OrigText")%>/>
+ <input type="hidden" name="origText" value="<%=request.getAttribute("OrigText")%>"/>
<input type="hidden" name="scmEditorUrl" value="<%=request.getAttribute("scmEditorUrl")%>"/>
<input type="hidden" name="previewServletUrl" value="<%=request.getAttribute("previewServletUrl")%>"/>
<input title="Save your work and continue editing this file." type="button" value="Save and Continue Editing" name="SaveandC" onclick="javascript:saver(this.form.newText, this.form.username, this.form.pw, this.form.commitMessage, this.form.origText, this.form.scmEditorUrl);"/>
Modified: trunk/src/main/webapp/Preview.js
===================================================================
--- trunk/src/main/webapp/Preview.js 2011-06-20 09:40:04 UTC (rev 126)
+++ trunk/src/main/webapp/Preview.js 2011-06-20 12:41:21 UTC (rev 127)
@@ -41,7 +41,7 @@
{
var response = http.responseText;
document.getElementById("prevtitle").innerHTML = "Preview : ";
- document.getElementById("prev").innerHTML ="<div id=\"preview\" "+response+"</div>";
+ document.getElementById("prev").innerHTML ="<div id=\"preview\" >"+response+"</div>";
}
else if (http.readyState == 4 && http.status == 406)
{
Modified: trunk/src/main/webapp/Saver.js
===================================================================
--- trunk/src/main/webapp/Saver.js 2011-06-20 09:40:04 UTC (rev 126)
+++ trunk/src/main/webapp/Saver.js 2011-06-20 12:41:21 UTC (rev 127)
@@ -28,10 +28,10 @@
function sendReq(method, url, text, login, pass, message, orig_text)
{
- http.open(method, url.value, true);
+ http.open(method, url, true);
http.onreadystatechange = handleResp;
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- http.send("Mytext="+text.value+"&username="+login.value+"&pw="+pass.value+"&Commit_message="+message.value+"&Orig_text="+orig_text.value);
+ http.send("newText="+text.value+"&username="+login.value+"&pw="+pass.value+"&commitMessage="+message.value+"&origText="+orig_text.value);
}
function handleResp()
@@ -46,14 +46,12 @@
function saver(my_text, login, pass, message, orig_text, scmEditorUrl)
{
+
if (my_text.value != orig_text.value){
if (confirm("Do you really want to save?")){
- if (message.value == ""){
- alert("You must enter a Commit message!!!", "");
- }
- else {
- sendReq("POST", scmEditorUrl, my_text, login, pass, message, orig_text);
- }
+
+ sendReq("POST", "commit.action", my_text, login, pass, message, orig_text);
+
}
} else{
alert("File don't need to be save.");
Modified: trunk/src/main/webapp/css/main.css
===================================================================
--- trunk/src/main/webapp/css/main.css 2011-06-20 09:40:04 UTC (rev 126)
+++ trunk/src/main/webapp/css/main.css 2011-06-20 12:41:21 UTC (rev 127)
@@ -12,7 +12,7 @@
}
#prevtitle {
- margin-left:12%;
+ margin-left:13%;
}
#preview {
1
0
r126 - in trunk/src/main: java/org/nuiton/scmwebeditor/actions resources webapp webapp/css
by kcardineaud@users.nuiton.org 20 Jun '11
by kcardineaud@users.nuiton.org 20 Jun '11
20 Jun '11
Author: kcardineaud
Date: 2011-06-20 11:40:04 +0200 (Mon, 20 Jun 2011)
New Revision: 126
Url: http://nuiton.org/repositories/revision/scmwebeditor/126
Log:
Add preview functionality in modification page
Added:
trunk/src/main/java/org/nuiton/scmwebeditor/actions/PreviewAction.java
Modified:
trunk/src/main/resources/struts.xml
trunk/src/main/webapp/ModificationViewer.jsp
trunk/src/main/webapp/Preview.js
trunk/src/main/webapp/css/main.css
Added: trunk/src/main/java/org/nuiton/scmwebeditor/actions/PreviewAction.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/actions/PreviewAction.java (rev 0)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/PreviewAction.java 2011-06-20 09:40:04 UTC (rev 126)
@@ -0,0 +1,108 @@
+package org.nuiton.scmwebeditor.actions;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts2.interceptor.ServletRequestAware;
+import org.nuiton.jrst.JRST;
+import org.nuiton.scmwebeditor.AbstractScmWebEditor;
+
+
+import com.opensymphony.xwork2.Action;
+
+public class PreviewAction extends AbstractScmWebEditor implements ServletRequestAware {
+
+ HttpServletRequest request;
+ InputStream XMLResponse;
+
+
+ private static final Log log = LogFactory.getLog(PreviewAction.class);
+
+ public String execute() {
+ setResponse();
+ return Action.SUCCESS;
+ }
+
+ public void setResponse() {
+
+ if(log.isDebugEnabled()) {
+ log.debug("Enter in Servlet Action");
+ }
+
+ HttpSession httpSession = request.getSession(true);
+ File tmpDir = getTempDir(httpSession);
+ //Text recuperation
+ String myData = request.getParameter(PARAMETER_TEXT);
+ //Text formating and tempfile creating
+ String myDataWithoutcrlf = myData.replace("\r", "");
+ File fileInDirCopy = new File(tmpDir, "copy" + httpSession.getId() + ".rst");
+ File httpFile = new File(tmpDir, "preview" + httpSession.getId() + ".html");
+ try {
+ fileInDirCopy.createNewFile();
+ httpFile.createNewFile();
+ FileUtils.writeStringToFile(fileInDirCopy, myDataWithoutcrlf);
+ } catch (IOException e) {
+ if(log.isErrorEnabled()) {
+ log.error("Erreur de lecture/ecriture",e);
+ }
+ }
+
+ convertToUnicode(fileInDirCopy);
+
+ File copy = new File(tmpDir, "copy" + httpSession.getId() + ".rst");
+
+ //Using jrst for generate html document
+ try {
+ JRST.generate(JRST.TYPE_HTML, copy, httpFile, JRST.Overwrite.ALLTIME);
+ if(log.isDebugEnabled()) {
+ log.debug("RST generate");
+ }
+ } catch (Exception eee) {
+ if(log.isWarnEnabled()) {
+ log.warn("RST generate fail",eee);
+ }
+ XMLResponse = new ByteArrayInputStream("<h4>Parsing error, please read RST specification<h4>".getBytes());
+ return;
+ }
+ copy.delete();
+
+
+ try {
+ XMLResponse = new ByteArrayInputStream(FileUtils.readFileToString(httpFile).getBytes());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ httpFile.delete();
+
+
+
+ }
+
+ public InputStream getXMLResponse() {
+ return XMLResponse;
+ }
+
+ public void setXMLResponse(InputStream xMLResponse) {
+ XMLResponse = xMLResponse;
+ }
+
+ @Override
+ public void setServletRequest(HttpServletRequest request) {
+ this.request = request;
+ }
+
+
+
+
+
+}
Modified: trunk/src/main/resources/struts.xml
===================================================================
--- trunk/src/main/resources/struts.xml 2011-06-17 15:24:35 UTC (rev 125)
+++ trunk/src/main/resources/struts.xml 2011-06-20 09:40:04 UTC (rev 126)
@@ -16,5 +16,11 @@
<result name="authError" >/ModificationViewer.jsp</result>
<result name="erreur">/BadFileRedirect.jsp</result>
</action>
+ <action name="preview" class="org.nuiton.scmwebeditor.actions.PreviewAction" method="execute">
+ <result type="stream" >
+ <param name="contentType">text/xml</param>
+ <param name="inputName">XMLResponse</param>
+ </result>
+ </action>
</package>
</struts>
\ No newline at end of file
Modified: trunk/src/main/webapp/ModificationViewer.jsp
===================================================================
--- trunk/src/main/webapp/ModificationViewer.jsp 2011-06-17 15:24:35 UTC (rev 125)
+++ trunk/src/main/webapp/ModificationViewer.jsp 2011-06-20 09:40:04 UTC (rev 126)
@@ -18,7 +18,7 @@
<center>
<form method="post" action=commit.action>
<script src="GereFormSize.js" type="text/javascript"></script>
- <textarea name="newText" id="newText" rows="20" cols="150"><%=request.getAttribute("OrigText")%></textarea>
+ <textarea name="newText" id="newText"><%=request.getAttribute("OrigText")%></textarea>
<script src="Preview.js" type="text/javascript"></script>
<script src="Saver.js" type="text/javascript"></script>
<script src="GereSession.js" type="text/javascript"></script>
@@ -49,16 +49,16 @@
<input type="hidden" name="origText" value=<%=request.getAttribute("OrigText")%>/>
<input type="hidden" name="scmEditorUrl" value="<%=request.getAttribute("scmEditorUrl")%>"/>
<input type="hidden" name="previewServletUrl" value="<%=request.getAttribute("previewServletUrl")%>"/>
- <input title="Save your work and continue editing this file." type="button" value="Save and Continue Editing" name="SaveandC" onclick="javascript:saver(this.form.newText, this.form.username, this.form.pw, this.form.commitMessage, this.form.Orig_text, this.form.scmEditorUrl);"/>
+ <input title="Save your work and continue editing this file." type="button" value="Save and Continue Editing" name="SaveandC" onclick="javascript:saver(this.form.newText, this.form.username, this.form.pw, this.form.commitMessage, this.form.origText, 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")!=null && request.getAttribute("format")!=null && request.getAttribute("format").equals("rst") == true){
%><input title="html preview of the current rst file state." type="button" value="Preview" name="Preview" onclick="javascript:preview(this.form.newText, 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.commitMessage, this.form.Project_url, this.form.scmEditorUrl);"/>
+ <input type="hidden" value="<%=request.getAttribute("ProjectUrl")%>" name="ProjectUrl">
+ <input title="Exit ScmWebEditor without saving." type="button" value="Exit" name="Cancel" onclick="javascript:cancelRedirectDelete(this.form.origText, this.form.username, this.form.pw, this.form.commitMessage, this.form.ProjectUrl, this.form.scmEditorUrl);"/>
</form></center>
<%--Title and div for rst preview--%>
- <h4 id="prevtitle" ></h4>
+ <h3 id="prevtitle" ></h3>
<div id="prev" title="Preview"></div>
<p align="right">©2004-2009 CodeLutin</p>
</body>
Modified: trunk/src/main/webapp/Preview.js
===================================================================
--- trunk/src/main/webapp/Preview.js 2011-06-17 15:24:35 UTC (rev 125)
+++ trunk/src/main/webapp/Preview.js 2011-06-20 09:40:04 UTC (rev 126)
@@ -29,7 +29,7 @@
function sendRequest(method, url, text)
{
- http.open(method, url.value, true);
+ http.open(method, url, true);
http.onreadystatechange = handleResponse;
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send("text="+text.value);
@@ -41,7 +41,7 @@
{
var response = http.responseText;
document.getElementById("prevtitle").innerHTML = "Preview : ";
- document.getElementById("prev").innerHTML = response;
+ document.getElementById("prev").innerHTML ="<div id=\"preview\" "+response+"</div>";
}
else if (http.readyState == 4 && http.status == 406)
{
@@ -51,6 +51,6 @@
function preview(my_text, url)
{
- sendRequest("POST", url, my_text);
+ sendRequest("POST", "preview.action", my_text);
}
Modified: trunk/src/main/webapp/css/main.css
===================================================================
--- trunk/src/main/webapp/css/main.css 2011-06-17 15:24:35 UTC (rev 125)
+++ trunk/src/main/webapp/css/main.css 2011-06-20 09:40:04 UTC (rev 126)
@@ -4,3 +4,22 @@
background-color: #b8b1b1;
}
+textarea {
+ width:72%;
+ margin:auto;
+ display:block;
+ min-height: 150px;
+}
+
+#prevtitle {
+ margin-left:12%;
+}
+
+#preview {
+ width:70%;
+ margin:auto;
+ display:block;
+ padding:1%;
+ border : solid 3px black;
+}
+
1
0
r125 - in trunk/src/main: java/org/nuiton/scmwebeditor java/org/nuiton/scmwebeditor/actions resources
by kcardineaud@users.nuiton.org 17 Jun '11
by kcardineaud@users.nuiton.org 17 Jun '11
17 Jun '11
Author: kcardineaud
Date: 2011-06-17 17:24:35 +0200 (Fri, 17 Jun 2011)
New Revision: 125
Url: http://nuiton.org/repositories/revision/scmwebeditor/125
Log:
Add a method in AbstractScmWebEditor to delete the temporary directory
Modified:
trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java
trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java
trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java
trunk/src/main/resources/struts.xml
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java 2011-06-17 14:43:57 UTC (rev 124)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java 2011-06-17 15:24:35 UTC (rev 125)
@@ -25,6 +25,8 @@
package org.nuiton.scmwebeditor;
import info.monitorenter.cpdetector.io.*;
+
+import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -77,6 +79,7 @@
protected static final String ATTRIBUTE_INVALIDATE_MAX_TIME = "InvalidateMaxTime";
protected static final String ATTRIBUTE_LOGIN = "Login";
protected static final String ATTRIBUTE_IS_LOGIN = "IsLogin";
+ protected static final String ATTRIBUTE_BAD_LOGIN = "badLogin";
protected static final String ATTRIBUTE_PROJECT_URL = "Project_url";
protected static final String ATTRIBUTE_SCM_EDITOR_URI = "scmEditorUri";
protected static final String ATTRIBUTE_PREVIEW_SERVLET_URL = "previewServletUrl";
@@ -173,6 +176,17 @@
}
}
}
+
+ public void delTempDirectory(SvnSession svnSess) {
+ try {
+ FileUtils.deleteDirectory(svnSess.getCheckoutdir());
+ } catch (IOException e) {
+ if(log.isErrorEnabled()) {
+ log.error("Can't delete temp directory");
+ }
+ }
+ }
+
protected SvnSession getSvnSession(HttpSession httpSession) {
SvnSession svnSess = (SvnSession) httpSession.getAttribute(ATTRIBUTE_SVN_SESSION);
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-17 14:43:57 UTC (rev 124)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-17 15:24:35 UTC (rev 125)
@@ -116,7 +116,6 @@
svnSess.setLogin(null);
svnSess.setPassword(null);
// if authentication failed edition page is reload form user's relogin
- log.debug("AUTH REDIRECT"+getRedirectUrl(svnSess));
request.setAttribute(PARAMETER_FORMAT, svnSess.getFormat());
request.setAttribute(ATTRIBUTE_ORIG_TEXT, StringEscapeUtils.escapeHtml(newText));
request.setAttribute(ATTRIBUTE_INVALIDATE_MAX_TIME, (httpSession.getMaxInactiveInterval() / 60));
@@ -127,28 +126,22 @@
request.setAttribute(ATTRIBUTE_SCM_EDITOR_URI, request.getRequestURI());
request.setAttribute(ATTRIBUTE_PREVIEW_SERVLET_URL, request.getContextPath() + "/previewservlet");
- request.setAttribute("badLogin", true);
+ request.setAttribute(ATTRIBUTE_BAD_LOGIN, true);
return "authError";
} catch (SVNException e) {
if(log.isErrorEnabled()) {
log.error("SVN FAIL",e);
}
+ //Suppression du repertoire temporaire
+ delTempDirectory(svnSess);
request.setAttribute(ATTRIBUTE_REDIRECT_URL, getRedirectUrl(svnSess));
- return "ko";
+ return "erreur";
}
}
if (svnSess.getCheckoutdir() != null) {
- if(log.isDebugEnabled()) {
- log.debug("Delete tempdir");
- }
- try {
- FileUtils.deleteDirectory(svnSess.getCheckoutdir());
- } catch (IOException e) {
- if(log.isErrorEnabled()) {
- log.error("Can't delete the temp dir",e);
- }
- }
+ //Suppression du repertoire temporaire
+ delTempDirectory(svnSess);
}
//if commit success user is redirect on the project page
request.setAttribute(ATTRIBUTE_REDIRECTION_URL, svnSess.getProjectUrl());
@@ -156,6 +149,8 @@
if(log.isDebugEnabled()) {
log.debug("End of commit");
}
+ //Suppression du repertoire temporaire
+ delTempDirectory(svnSess);
return "success";
}
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-17 14:43:57 UTC (rev 124)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-17 15:24:35 UTC (rev 125)
@@ -142,25 +142,13 @@
log.debug("Private SCM on reading " + svnSess.getRemoteUrl());
}
//Suppression du repertoire temporaire
- try {
- svnSess.cleanCheckoutDir();
- } catch (IOException e) {
- if (log.isErrorEnabled()) {
- log.error("Can't delete temp directory",e);
- }
- }
+ delTempDirectory(svnSess);
//redirect to a login page
return "login";
} catch (SVNException e) {
//Suppression du repertoire temporaire
- try {
- svnSess.cleanCheckoutDir();
- } catch (IOException ee) {
- if(log.isErrorEnabled()) {
- log.error("Can't delete temp directory");
- }
- }
+ delTempDirectory(svnSess);
return "erreurPath";
}
@@ -187,13 +175,7 @@
/* fichier non trouve, on redirige vers BadFileRedirect.jsp
* après avoir supprimé le repertoire temporaire
*/
- try {
- FileUtils.deleteDirectory(svnSess.getCheckoutdir());
- } catch (IOException e) {
- if(log.isErrorEnabled()) {
- log.error("Can't delete temp directory");
- }
- }
+ delTempDirectory(svnSess);
request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getProjectUrl());
return "erreurPath";
} catch (IOException e) {
@@ -213,5 +195,6 @@
}
+
}
Modified: trunk/src/main/resources/struts.xml
===================================================================
--- trunk/src/main/resources/struts.xml 2011-06-17 14:43:57 UTC (rev 124)
+++ trunk/src/main/resources/struts.xml 2011-06-17 15:24:35 UTC (rev 125)
@@ -14,7 +14,7 @@
<action name="commit" class="org.nuiton.scmwebeditor.actions.ScmWebEditorCommitAction" method="execute">
<result name="success" >/Redirect.jsp</result>
<result name="authError" >/ModificationViewer.jsp</result>
- <result name="ko">/BadFileRedirect.jsp</result>
+ <result name="erreur">/BadFileRedirect.jsp</result>
</action>
</package>
</struts>
\ No newline at end of file
1
0
r124 - in trunk/src/main: java/org/nuiton/scmwebeditor java/org/nuiton/scmwebeditor/actions resources webapp
by kcardineaud@users.nuiton.org 17 Jun '11
by kcardineaud@users.nuiton.org 17 Jun '11
17 Jun '11
Author: kcardineaud
Date: 2011-06-17 16:43:57 +0200 (Fri, 17 Jun 2011)
New Revision: 124
Url: http://nuiton.org/repositories/revision/scmwebeditor/124
Log:
Modify the login system for commit a file
Modified:
trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java
trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java
trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java
trunk/src/main/resources/struts.xml
trunk/src/main/webapp/ModificationViewer.jsp
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java 2011-06-17 12:56:21 UTC (rev 123)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java 2011-06-17 14:43:57 UTC (rev 124)
@@ -51,9 +51,9 @@
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_ADRESSE = "address";
protected static final String PARAMETER_SCM_EDITOR_URL = "scmEditorUrl";
- protected static final String PARAMETER_PROJECT_URL = "project_url";
+ protected static final String PARAMETER_PROJECT_URL = "projectUrl";
protected static final String PARAMETER_FILE_NAME = "file_name";
protected static final String PARAMETER_LANG = "lang";
protected static final String PARAMETER_DEFAULT_LANG = "defaultLang";
@@ -197,8 +197,7 @@
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_ADRESSE).append('=').append(svnSess.getSvnPath()+svnSess.getFileName());
buffer.append("&").append(PARAMETER_PROJECT_URL).append('=').append(svnSess.getProjectUrl());
String url = buffer.toString();
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-17 12:56:21 UTC (rev 123)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-17 14:43:57 UTC (rev 124)
@@ -113,9 +113,22 @@
if(log.isErrorEnabled()) {
log.error("AUTH FAIL",authexep);
}
+ svnSess.setLogin(null);
+ svnSess.setPassword(null);
// if authentication failed edition page is reload form user's relogin
- request.setAttribute(ATTRIBUTE_REDIRECT_URL, getRedirectUrl(svnSess));
- return "ko";
+ log.debug("AUTH REDIRECT"+getRedirectUrl(svnSess));
+ request.setAttribute(PARAMETER_FORMAT, svnSess.getFormat());
+ request.setAttribute(ATTRIBUTE_ORIG_TEXT, StringEscapeUtils.escapeHtml(newText));
+ 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, false);
+ request.setAttribute(ATTRIBUTE_PROJECT_URL, svnSess.getProjectUrl());
+ request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getScmEditorUrl());
+ request.setAttribute(ATTRIBUTE_SCM_EDITOR_URI, request.getRequestURI());
+ request.setAttribute(ATTRIBUTE_PREVIEW_SERVLET_URL, request.getContextPath() + "/previewservlet");
+
+ request.setAttribute("badLogin", true);
+ return "authError";
} catch (SVNException e) {
if(log.isErrorEnabled()) {
log.error("SVN FAIL",e);
@@ -126,7 +139,9 @@
}
if (svnSess.getCheckoutdir() != null) {
- log.debug("Delete tempdir");
+ if(log.isDebugEnabled()) {
+ log.debug("Delete tempdir");
+ }
try {
FileUtils.deleteDirectory(svnSess.getCheckoutdir());
} catch (IOException e) {
@@ -141,7 +156,7 @@
if(log.isDebugEnabled()) {
log.debug("End of commit");
}
- return "ok";
+ return "success";
}
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-17 12:56:21 UTC (rev 123)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-17 14:43:57 UTC (rev 124)
@@ -107,7 +107,7 @@
tmp_log = svnSess.getLogin();
tmp_pass = svnSess.getPassword();
}
-
+
svnSess = new SvnSession(
relativePath,
scmFileName,
Modified: trunk/src/main/resources/struts.xml
===================================================================
--- trunk/src/main/resources/struts.xml 2011-06-17 12:56:21 UTC (rev 123)
+++ trunk/src/main/resources/struts.xml 2011-06-17 14:43:57 UTC (rev 124)
@@ -12,7 +12,8 @@
<result name="editPage" >/ModificationViewer.jsp</result>
</action>
<action name="commit" class="org.nuiton.scmwebeditor.actions.ScmWebEditorCommitAction" method="execute">
- <result name="ok" >/accueil.jsp</result>
+ <result name="success" >/Redirect.jsp</result>
+ <result name="authError" >/ModificationViewer.jsp</result>
<result name="ko">/BadFileRedirect.jsp</result>
</action>
</package>
Modified: trunk/src/main/webapp/ModificationViewer.jsp
===================================================================
--- trunk/src/main/webapp/ModificationViewer.jsp 2011-06-17 12:56:21 UTC (rev 123)
+++ trunk/src/main/webapp/ModificationViewer.jsp 2011-06-17 14:43:57 UTC (rev 124)
@@ -13,7 +13,7 @@
<body onload="cleanForm();geresession(<%=request.getAttribute("InvalidateMaxTime")%>, 5);">
<a title="ScmWebEditor Project Website" target="_blank" href="http://maven-site.nuiton.org/scmwebeditor/"><img src="img/ScmWebEditor_main.png" alt="ScmWebEditor logo"/></a>
<center><h2>Welcome on SCMWebEditor</h2>
- <%if (request.getAttribute("format").equals("rst") == true){
+ <%if (request.getAttribute("format")!=null && request.getAttribute("format").equals("rst") == true){
%><h4>For any Problem with RestruturedText visit <a href="http://docutils.sourceforge.net/rst.html">RST documentation website</a>.</h4></center><%}%>
<center>
<form method="post" action=commit.action>
@@ -29,7 +29,17 @@
<p>Commit Message: <input type="text" name="commitMessage" title="Let a commit message with this file."/></p>
<%if (request.getAttribute("IsLogin").equals(false) == true){
- %><p><label ACCESSKEY=U>User name: <input TYPE=text NAME=username SIZE=12 title="Commit Username."/></label>
+ %>
+ <%if (request.getAttribute("badLogin")!=null && request.getAttribute("badLogin").equals(true)) { %>
+ <p>
+ <font color="red">
+ Bad username or password
+ </font>
+ </p>
+ <% } %>
+ <p>
+
+ <label ACCESSKEY=U>User name: <input TYPE=text NAME=username SIZE=12 title="Commit Username."/></label>
<label ACCESSKEY=P>Password: <input TYPE=password NAME=pw SIZE=12 title="Commit Password."/></label> </p><%
} else {
%><p>You are log as: <%=request.getAttribute("Login")%></p>
@@ -41,7 +51,7 @@
<input type="hidden" name="previewServletUrl" value="<%=request.getAttribute("previewServletUrl")%>"/>
<input title="Save your work and continue editing this file." type="button" value="Save and Continue Editing" name="SaveandC" onclick="javascript:saver(this.form.newText, this.form.username, this.form.pw, this.form.commitMessage, 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){
+ <%if (request.getAttribute("format")!=null && request.getAttribute("format")!=null && request.getAttribute("format").equals("rst") == true){
%><input title="html preview of the current rst file state." type="button" value="Preview" name="Preview" onclick="javascript:preview(this.form.newText, 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">
1
0
r123 - in trunk/src/main: java/org/nuiton/scmwebeditor java/org/nuiton/scmwebeditor/actions resources webapp
by kcardineaud@users.nuiton.org 17 Jun '11
by kcardineaud@users.nuiton.org 17 Jun '11
17 Jun '11
Author: kcardineaud
Date: 2011-06-17 14:56:21 +0200 (Fri, 17 Jun 2011)
New Revision: 123
Url: http://nuiton.org/repositories/revision/scmwebeditor/123
Log:
File commit is now in struts
Added:
trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java
Modified:
trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java
trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java
trunk/src/main/resources/struts.xml
trunk/src/main/webapp/ModificationViewer.jsp
trunk/src/main/webapp/OutConnection.jsp
trunk/src/main/webapp/fileSearch.js
trunk/src/main/webapp/index.jsp
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java 2011-06-17 07:43:45 UTC (rev 122)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java 2011-06-17 12:56:21 UTC (rev 123)
@@ -118,7 +118,7 @@
this.login = login;
this.password = password;
try {
- this.checkoutdir = FileUtil.createTempDirectory("", "");
+ this.checkoutdir = FileUtil.createTempDirectory("scm_", "");
} catch (IOException e) {
e.printStackTrace();
}
Added: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java (rev 0)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-17 12:56:21 UTC (rev 123)
@@ -0,0 +1,154 @@
+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.io.FileUtils;
+import org.apache.commons.lang.StringEscapeUtils;
+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.SvnSession;
+import org.tmatesoft.svn.core.SVNAuthenticationException;
+import org.tmatesoft.svn.core.SVNDepth;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.wc.SVNCommitClient;
+
+public class ScmWebEditorCommitAction extends AbstractScmWebEditor implements ServletRequestAware {
+ private static final Log log = LogFactory.getLog(ScmWebEditorCommitAction.class);
+
+ protected String newText;
+ protected String commitMessage;
+ protected String origText;
+ protected String username;
+ protected String pw;
+
+
+ protected HttpServletRequest request;
+
+ public String getCommitMessage() {
+ return commitMessage;
+ }
+
+ public void setCommitMessage(String commitMessage) {
+ this.commitMessage = commitMessage;
+ }
+
+
+ public String getNewText() {
+ return newText;
+ }
+
+ public void setNewText(String newText) {
+ this.newText = newText;
+ }
+
+ public String getOrigText() {
+ return origText;
+ }
+
+ public void setOrigText(String origText) {
+ this.origText = origText;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPw() {
+ return pw;
+ }
+
+ public void setPw(String pw) {
+ this.pw = pw;
+ }
+
+ public String execute() {
+ 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() : username,
+ svnSess.getPassword() != null && !svnSess.getPassword().equalsIgnoreCase("") ? svnSess.getPassword() : pw);
+
+ String originalText = StringEscapeUtils.unescapeHtml(origText);
+ String myText = StringEscapeUtils.unescapeHtml(newText);
+
+ File pathToFile = new File(svnSess.getCheckoutdir(), svnSess.getFileName());
+
+ SVNCommitClient commitClient = new SVNCommitClient(svnSess.getManager(), svnSess.getSvnOption());
+ try {
+ FileUtils.writeStringToFile(pathToFile, newText);
+ } catch (IOException e) {
+ if(log.isErrorEnabled()) {
+ log.error("Can't write in file " , e);
+ }
+ return "ko";
+ }
+
+
+ convertToUnicode(pathToFile);
+
+ File[] tabFile = new File[1];
+ tabFile[0] = pathToFile;
+// Sending Data to SVN
+
+ if (!myText.equals(originalText)) {
+ try {
+ if(log.isDebugEnabled()) {
+ log.debug("Try to commit");
+ }
+ commitClient.doCommit(tabFile, false, "From scmwebeditor -- "+commitMessage, null, null, false, true, SVNDepth.FILES);
+ } catch (SVNAuthenticationException authexep) {
+ if(log.isErrorEnabled()) {
+ log.error("AUTH FAIL",authexep);
+ }
+ // if authentication failed edition page is reload form user's relogin
+ request.setAttribute(ATTRIBUTE_REDIRECT_URL, getRedirectUrl(svnSess));
+ return "ko";
+ } catch (SVNException e) {
+ if(log.isErrorEnabled()) {
+ log.error("SVN FAIL",e);
+ }
+ request.setAttribute(ATTRIBUTE_REDIRECT_URL, getRedirectUrl(svnSess));
+ return "ko";
+ }
+ }
+
+ if (svnSess.getCheckoutdir() != null) {
+ log.debug("Delete tempdir");
+ try {
+ FileUtils.deleteDirectory(svnSess.getCheckoutdir());
+ } catch (IOException e) {
+ if(log.isErrorEnabled()) {
+ log.error("Can't delete the temp dir",e);
+ }
+ }
+ }
+ //if commit success user is redirect on the project page
+ request.setAttribute(ATTRIBUTE_REDIRECTION_URL, svnSess.getProjectUrl());
+
+ if(log.isDebugEnabled()) {
+ log.debug("End of commit");
+ }
+ return "ok";
+ }
+
+
+
+ @Override
+ public void setServletRequest(HttpServletRequest request) {
+ this.request = request;
+ }
+
+}
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-17 07:43:45 UTC (rev 122)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-17 12:56:21 UTC (rev 123)
@@ -6,6 +6,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+import javax.swing.Action;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
@@ -18,7 +19,6 @@
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;
@@ -95,21 +95,12 @@
//SvnSession object creation if doesn't already exist
SvnSession svnSess = getSvnSession(httpSession);
-
String relativePath = address.substring(0,address.lastIndexOf("/"));
-
- log.debug("RELATIVEPATH : "+relativePath);
- //String scmPath = address.endsWith(relativePath) ? "" : relativePath;
-
String scmFileName = address.substring(address.lastIndexOf("/")+1);
-
- log.debug("SCMFILENAME : "+scmFileName);
format = scmFileName.substring(scmFileName.lastIndexOf(".")+1);
- log.debug("FORMAT : "+scmFileName);
-
String tmp_log = null;
String tmp_pass = null;
if (svnSess != null) {
@@ -147,21 +138,28 @@
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());
+ if(log.isDebugEnabled()) {
+ log.debug("Private SCM on reading " + svnSess.getRemoteUrl());
+ }
//Suppression du repertoire temporaire
try {
svnSess.cleanCheckoutDir();
} catch (IOException e) {
- e.printStackTrace();
+ if (log.isErrorEnabled()) {
+ log.error("Can't delete temp directory",e);
+ }
}
-
- return "private";
+ //redirect to a login page
+ return "login";
+
} catch (SVNException e) {
//Suppression du repertoire temporaire
try {
svnSess.cleanCheckoutDir();
} catch (IOException ee) {
- e.printStackTrace();
+ if(log.isErrorEnabled()) {
+ log.error("Can't delete temp directory");
+ }
}
return "erreurPath";
}
@@ -186,16 +184,20 @@
// End on first part
} catch (FileNotFoundException ee) {
- // fichier non trouve, on redirige vers BadFileRedirect.jsp
+ /* fichier non trouve, on redirige vers BadFileRedirect.jsp
+ * après avoir supprimé le repertoire temporaire
+ */
try {
FileUtils.deleteDirectory(svnSess.getCheckoutdir());
} catch (IOException e) {
- e.printStackTrace();
+ if(log.isErrorEnabled()) {
+ log.error("Can't delete temp directory");
+ }
}
request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getProjectUrl());
return "erreurPath";
} catch (IOException e) {
- e.printStackTrace();
+ log.error("Can't find the checkout file",e);
}
return "editPage";
Modified: trunk/src/main/resources/struts.xml
===================================================================
--- trunk/src/main/resources/struts.xml 2011-06-17 07:43:45 UTC (rev 122)
+++ trunk/src/main/resources/struts.xml 2011-06-17 12:56:21 UTC (rev 123)
@@ -5,11 +5,15 @@
<struts>
<package name="action" extends="struts-default">
- <action name="main" class="org.nuiton.scmwebeditor.actions.ScmWebEditorMainAction" method="execute">
+ <action name="checkout" class="org.nuiton.scmwebeditor.actions.ScmWebEditorMainAction" method="execute">
<result name="noParameter" >/OutConnection.jsp</result>
- <result name="private" >/PrivateSvnRedirect.jsp</result>
+ <result name="login" >/PrivateSvnRedirect.jsp</result>
<result name="erreurPath" >/BadFileRedirect.jsp</result>
<result name="editPage" >/ModificationViewer.jsp</result>
</action>
+ <action name="commit" class="org.nuiton.scmwebeditor.actions.ScmWebEditorCommitAction" method="execute">
+ <result name="ok" >/accueil.jsp</result>
+ <result name="ko">/BadFileRedirect.jsp</result>
+ </action>
</package>
</struts>
\ No newline at end of file
Modified: trunk/src/main/webapp/ModificationViewer.jsp
===================================================================
--- trunk/src/main/webapp/ModificationViewer.jsp 2011-06-17 07:43:45 UTC (rev 122)
+++ trunk/src/main/webapp/ModificationViewer.jsp 2011-06-17 12:56:21 UTC (rev 123)
@@ -15,9 +15,10 @@
<center><h2>Welcome on SCMWebEditor</h2>
<%if (request.getAttribute("format").equals("rst") == true){
%><h4>For any Problem with RestruturedText visit <a href="http://docutils.sourceforge.net/rst.html">RST documentation website</a>.</h4></center><%}%>
- <center><form method="post" action=<%=request.getAttribute("scmEditorUri")%>>
+ <center>
+ <form method="post" action=commit.action>
<script src="GereFormSize.js" type="text/javascript"></script>
- <textarea name="Mytext" id="Mytext" rows="20" cols="150"><%=request.getAttribute("OrigText")%></textarea>
+ <textarea name="newText" id="newText" rows="20" cols="150"><%=request.getAttribute("OrigText")%></textarea>
<script src="Preview.js" type="text/javascript"></script>
<script src="Saver.js" type="text/javascript"></script>
<script src="GereSession.js" type="text/javascript"></script>
@@ -25,7 +26,7 @@
<script src="pictureUpload.js" type="text/javascript"></script>
<noscript><h4>Javascript is not activated. You can't only use Save and Quit or Reset button.</h4></noscript>
<noscript><h4>For a better use of SCMWebEditor please activate JavaScript.</h4></noscript>
- <p>Commit Message: <input type="text" name="Commit_message" title="Let a commit message with this file."/></p>
+ <p>Commit Message: <input type="text" name="commitMessage" title="Let a commit message with this file."/></p>
<%if (request.getAttribute("IsLogin").equals(false) == true){
%><p><label ACCESSKEY=U>User name: <input TYPE=text NAME=username SIZE=12 title="Commit Username."/></label>
@@ -35,16 +36,16 @@
<input type="hidden" NAME=username />
<input type="hidden" NAME=pw /><%
}%>
- <input type="hidden" name="Orig_text" value=<%=request.getAttribute("OrigText")%>/>
+ <input type="hidden" name="origText" value=<%=request.getAttribute("OrigText")%>/>
<input type="hidden" name="scmEditorUrl" value="<%=request.getAttribute("scmEditorUrl")%>"/>
<input type="hidden" name="previewServletUrl" value="<%=request.getAttribute("previewServletUrl")%>"/>
- <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 your work and continue editing this file." type="button" value="Save and Continue Editing" name="SaveandC" onclick="javascript:saver(this.form.newText, this.form.username, this.form.pw, this.form.commitMessage, 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 current 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.newText, 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);"/>
+ <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.commitMessage, this.form.Project_url, this.form.scmEditorUrl);"/>
</form></center>
<%--Title and div for rst preview--%>
<h4 id="prevtitle" ></h4>
Modified: trunk/src/main/webapp/OutConnection.jsp
===================================================================
--- trunk/src/main/webapp/OutConnection.jsp 2011-06-17 07:43:45 UTC (rev 122)
+++ trunk/src/main/webapp/OutConnection.jsp 2011-06-17 12:56:21 UTC (rev 123)
@@ -21,8 +21,8 @@
</h4>
</center>
<center>
-<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.address, this.form.searchServletUrl);"/></p>
+<form method="get" action="checkout.action">
+ <p><label>SCM path: <input TYPE=text name="address" SIZE=100></label><input disabled="disabled" type="button" value="Search Files" name="search" onclick="javascript:fileSearch(this.form.address, 'SearchServlet');"/></p>
<input type="hidden" name="projectUrl" value="<%=request.getRequestURL()%>" />
Modified: trunk/src/main/webapp/fileSearch.js
===================================================================
--- trunk/src/main/webapp/fileSearch.js 2011-06-17 07:43:45 UTC (rev 122)
+++ trunk/src/main/webapp/fileSearch.js 2011-06-17 12:56:21 UTC (rev 123)
@@ -24,7 +24,7 @@
function sendRequestToFileSearchServlet(scmPath, scmEditorUrl)
{
- http.open("POST", scmEditorUrl.value, true);
+ http.open("POST", scmEditorUrl, true);
http.onreadystatechange = handleResponseFromFileSearchServlet;
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send("adresse="+scmPath.value);
@@ -42,6 +42,6 @@
function fileSearch(scmPath, scmEditorUrl)
{
alert(scmPath.value);
- alert(scmEditorUrl.value);
+ alert(scmEditorUrl);
sendRequestToFileSearchServlet(scmPath, scmEditorUrl);
}
Modified: trunk/src/main/webapp/index.jsp
===================================================================
--- trunk/src/main/webapp/index.jsp 2011-06-17 07:43:45 UTC (rev 122)
+++ trunk/src/main/webapp/index.jsp 2011-06-17 12:56:21 UTC (rev 123)
@@ -1,3 +1,3 @@
<%
-response.sendRedirect("main.action");
+response.sendRedirect("checkout.action");
%>
\ No newline at end of file
1
0
r122 - trunk/src/main/java/org/nuiton/scmwebeditor/actions
by kcardineaud@users.nuiton.org 17 Jun '11
by kcardineaud@users.nuiton.org 17 Jun '11
17 Jun '11
Author: kcardineaud
Date: 2011-06-17 09:43:45 +0200 (Fri, 17 Jun 2011)
New Revision: 122
Url: http://nuiton.org/repositories/revision/scmwebeditor/122
Log:
Correction of a problem with import in ScmWebEditorMainAction
Modified:
trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-16 14:28:44 UTC (rev 121)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-17 07:43:45 UTC (rev 122)
@@ -13,7 +13,6 @@
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;
1
0
r121 - in trunk/src/main: java/org/nuiton/scmwebeditor java/org/nuiton/scmwebeditor/actions resources webapp
by kcardineaud@users.nuiton.org 16 Jun '11
by kcardineaud@users.nuiton.org 16 Jun '11
16 Jun '11
Author: kcardineaud
Date: 2011-06-16 16:28:44 +0200 (Thu, 16 Jun 2011)
New Revision: 121
Url: http://nuiton.org/repositories/revision/scmwebeditor/121
Log:
ScmWebEditor can only be use with the complete url
Modified:
trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java
trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java
trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java
trunk/src/main/resources/struts.xml
trunk/src/main/webapp/OutConnection.jsp
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java 2011-06-16 08:31:07 UTC (rev 120)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/AbstractScmWebEditor.java 2011-06-16 14:28:44 UTC (rev 121)
@@ -200,9 +200,6 @@
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/SvnSession.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java 2011-06-16 08:31:07 UTC (rev 120)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/SvnSession.java 2011-06-16 14:28:44 UTC (rev 121)
@@ -57,14 +57,6 @@
*/
protected String format;
/**
- * locale language
- */
- protected String lang;
- /**
- * default lang used by maven site (used to build the relative path to the resource
- */
- protected String defaultLang;
- /**
* svn path without fileName
*/
protected String svnPath;
@@ -115,15 +107,11 @@
String login,
String password,
String id,
- String lang,
- String defaultLang,
String format,
StringBuffer scmEditorUrl) {
this.scmEditorUrl = scmEditorUrl;
this.id = id;
this.format = format;
- this.lang = lang;
- this.defaultLang = defaultLang;
this.svnPath = svnPath;
this.fileName = fileName;
this.projectUrl = projectUrl;
@@ -241,14 +229,6 @@
this.svnPath = svnPath;
}
- public String getLang() {
- return lang;
- }
-
- public void setLang(String lang) {
- this.lang = lang;
- }
-
public String getFormat() {
return format;
}
@@ -274,11 +254,4 @@
}
- public String getDefaultLang() {
- return defaultLang;
- }
-
- public void setDefaultLang(String defaultLang) {
- this.defaultLang = defaultLang;
- }
}
Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java
===================================================================
--- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-16 08:31:07 UTC (rev 120)
+++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-16 14:28:44 UTC (rev 121)
@@ -1,11 +1,14 @@
package org.nuiton.scmwebeditor.actions;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.ServletRequestAware;
@@ -26,10 +29,8 @@
protected String address;
protected String projectUrl;
- protected String fileName;
protected String format;
- protected String lang;
- protected String defaultLang;
+
protected HttpServletRequest request;
@@ -54,53 +55,14 @@
}
- 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) {
+ if (address == null || address.length() == 0) {
return true;
}
else {
@@ -109,6 +71,10 @@
}
+ /**
+ * Methode principale de la classe
+ * @return
+ */
public String execute() {
@@ -129,21 +95,22 @@
//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 = address.substring(0,address.lastIndexOf("/"));
+
+ log.debug("RELATIVEPATH : "+relativePath);
- 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 scmPath = address.endsWith(relativePath) ? "" : relativePath;
-
- String scmFilename = fileName.endsWith(".html") ? fileName.replace(".html", "." + format) : fileName;
+ String scmFileName = address.substring(address.lastIndexOf("/")+1);
+ log.debug("SCMFILENAME : "+scmFileName);
+
+ format = scmFileName.substring(scmFileName.lastIndexOf(".")+1);
+
+ log.debug("FORMAT : "+scmFileName);
+
String tmp_log = null;
String tmp_pass = null;
if (svnSess != null) {
@@ -152,18 +119,16 @@
}
svnSess = new SvnSession(
- scmUrl + scmPath,
- scmFilename,
+ relativePath,
+ 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
@@ -173,7 +138,7 @@
SVNUpdateClient upclient = new SVNUpdateClient(svnSess.getManager(), svnSess.getSvnOption());
- log.debug("VALEUR SVNSESS 2: "+svnSess);
+
// Checkout svn and file organisation
try {
if (log.isDebugEnabled()) {
@@ -184,23 +149,56 @@
} catch (SVNAuthenticationException authexep) {
// if svn authentication failed user is redirected on login page
log.debug("Private SCM on reading " + svnSess.getRemoteUrl());
+ //Suppression du repertoire temporaire
try {
svnSess.cleanCheckoutDir();
} catch (IOException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
return "private";
} catch (SVNException e) {
-
+ //Suppression du repertoire temporaire
+ try {
+ svnSess.cleanCheckoutDir();
+ } catch (IOException ee) {
+ e.printStackTrace();
+ }
return "erreurPath";
}
- File file_in_dir = new File(svnSess.getCheckoutdir(), svnSess.getFileName());
+ File CheckOutFile = new File(svnSess.getCheckoutdir(), svnSess.getFileName());
+ try {
+ String originalText = FileUtils.readFileToString(CheckOutFile);
+ request.setAttribute(PARAMETER_FORMAT, svnSess.getFormat());
+ request.setAttribute(ATTRIBUTE_ORIG_TEXT, StringEscapeUtils.escapeHtml(originalText));
+ 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");
+
+ // End on first part
+
+ } catch (FileNotFoundException ee) {
+ // fichier non trouve, on redirige vers BadFileRedirect.jsp
+ try {
+ FileUtils.deleteDirectory(svnSess.getCheckoutdir());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ request.setAttribute(PARAMETER_SCM_EDITOR_URL, svnSess.getProjectUrl());
+ return "erreurPath";
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
-
return "editPage";
Modified: trunk/src/main/resources/struts.xml
===================================================================
--- trunk/src/main/resources/struts.xml 2011-06-16 08:31:07 UTC (rev 120)
+++ trunk/src/main/resources/struts.xml 2011-06-16 14:28:44 UTC (rev 121)
@@ -8,8 +8,8 @@
<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>
+ <result name="erreurPath" >/BadFileRedirect.jsp</result>
+ <result name="editPage" >/ModificationViewer.jsp</result>
</action>
</package>
</struts>
\ No newline at end of file
Modified: trunk/src/main/webapp/OutConnection.jsp
===================================================================
--- trunk/src/main/webapp/OutConnection.jsp 2011-06-16 08:31:07 UTC (rev 120)
+++ trunk/src/main/webapp/OutConnection.jsp 2011-06-16 14:28:44 UTC (rev 121)
@@ -22,21 +22,9 @@
</center>
<center>
<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
-</select></label></p>
-<p><label>Lang: <select name=lang>
-<option value="fr">Fr
-<option value="en">En
-</select></label>
-<label>Default Lang: <select name=defaultLang>
-<option value="fr">Fr
-<option value="en">En
-</select></label></p>
+ <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.address, this.form.searchServletUrl);"/></p>
+
<input type="hidden" name="projectUrl" value="<%=request.getRequestURL()%>" />
<input type="hidden" name="searchServletUrl" value="<%=request.getAttribute("searchServletUrl")%>"/>
<input type="submit" name="Save" /></form>
1
0
16 Jun '11
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);
- }
- }
-
-}
1
0