r129 - in trunk/src/main: java/org/nuiton/scmwebeditor java/org/nuiton/scmwebeditor/actions resources webapp
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/scmweb... $ - * %% - * Copyright (C) 2009 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.scmwebeditor; - -import info.monitorenter.cpdetector.io.*; - -import org.apache.commons.io.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/scmweb... $ + * %% + * Copyright (C) 2009 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.scmwebeditor; + +import info.monitorenter.cpdetector.io.*; + +import org.apache.commons.io.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>
participants (1)
-
kcardineaud@users.nuiton.org