r133 - in trunk/src/main: java/org/nuiton/scmwebeditor/actions resources webapp
Author: kcardineaud Date: 2011-06-23 16:15:20 +0200 (Thu, 23 Jun 2011) New Revision: 133 Url: http://nuiton.org/repositories/revision/scmwebeditor/133 Log: Add the upload file function Added: trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java trunk/src/main/webapp/uploadForm.jsp trunk/src/main/webapp/uploadSuccess.jsp Modified: trunk/src/main/resources/struts.xml trunk/src/main/webapp/ModificationViewer.jsp trunk/src/main/webapp/accueil.jsp trunk/src/main/webapp/pictureUpload.js Added: trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java (rev 0) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/UploadAction.java 2011-06-23 14:15:20 UTC (rev 133) @@ -0,0 +1,143 @@ +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.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts2.interceptor.ServletRequestAware; +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.SVNClientManager; + +import com.opensymphony.xwork2.Action; + +public class UploadAction extends ScmWebEditorBaseAction implements ServletRequestAware { + + /** + * + */ + private static final long serialVersionUID = 4244339447567114412L; + private static final Log log = LogFactory.getLog(UploadAction.class); + protected File upload; + protected String uploadFileName; + protected String uploadContentType; + protected String username; + protected String pw; + protected String svnPath; + + protected HttpServletRequest request; + + + public String getSvnPath() { + return svnPath; + } + public void setSvnPath(String svnPath) { + this.svnPath = svnPath; + } + public File getUpload() { + return upload; + } + public void setUpload(File upload) { + this.upload = upload; + } + public String getUploadContentType() { + return uploadContentType; + } + public void setUploadContentType(String uploadContentType) { + this.uploadContentType = uploadContentType; + } + public String getUploadFileName() { + return uploadFileName; + } + public void setUploadFileName(String uploadFileName) { + this.uploadFileName = uploadFileName; + } + 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() { + + if(log.isInfoEnabled()) { + log.info("PictureName : "+uploadFileName); + log.info("ContentType : "+uploadContentType); + } + + + + + HttpSession httpSession = request.getSession(true); + SvnSession svnSess = getSvnSession(httpSession); + + File checkoutDir = svnSess.getCheckoutdir(); + + String checkoutPath = checkoutDir.getAbsolutePath(); + File file = new File(checkoutPath,uploadFileName); + + + try { + FileUtils.copyFile(upload, file); + } catch (IOException e) { + log.error("Can't copy the file to the checkout directory",e); + } + + +// 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); + + + + SVNClientManager manager = svnSess.getManager(); + + File[] tabFile = new File[1]; + tabFile[0] = file; + + try { + //On ajoute l'image aux fichiers versionnés + manager.getWCClient().doAdd( file , false , false , false , SVNDepth.FILES, false, false ); + //On commit la modification + manager.getCommitClient().doCommit(tabFile, false, "From scmwebeditor -- add the file : "+uploadFileName, null, null, false, true, SVNDepth.FILES); + } catch (SVNAuthenticationException authexep) { + log.error("authentification fail"); + request.setAttribute(ATTRIBUTE_BAD_LOGIN, true); + return Action.LOGIN; + } + catch (SVNException e) { + log.error("Erreur SVN",e); + request.setAttribute("error", true); + return Action.ERROR; + } + + + return Action.SUCCESS; + } + + + @Override + public void setServletRequest(HttpServletRequest request) { + this.request=request; + } + + + +} Modified: trunk/src/main/resources/struts.xml =================================================================== --- trunk/src/main/resources/struts.xml 2011-06-22 15:16:18 UTC (rev 132) +++ trunk/src/main/resources/struts.xml 2011-06-23 14:15:20 UTC (rev 133) @@ -11,20 +11,31 @@ <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="success" >/Redirect.jsp</result> <result name="authError" >/ModificationViewer.jsp</result> <result name="erreur">/BadFileRedirect.jsp</result> </action> + <action name="save" class="org.nuiton.scmwebeditor.actions.SaveAction" method="save"> <result>/Save.jsp</result> </action> + + <action name="doUpload" class="org.nuiton.scmwebeditor.actions.UploadAction" method="execute"> + <result>/uploadSuccess.jsp</result> + <result name="login" >/uploadForm.jsp</result> + <result name="error" >/uploadForm.jsp</result> + </action> + <action name="preview" class="org.nuiton.scmwebeditor.actions.PreviewAction" method="execute"> <result>/Preview.jsp</result> </action> + <action name="search" class="org.nuiton.scmwebeditor.actions.SearchAction" method="search"> <result>/Search.jsp</result> <result name="authError" >/LoginSearch.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-22 15:16:18 UTC (rev 132) +++ trunk/src/main/webapp/ModificationViewer.jsp 2011-06-23 14:15:20 UTC (rev 133) @@ -93,11 +93,35 @@ <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> - - - - + + <button onClick="javascript:upload_popup('uploadForm.jsp','upload');" >Upload</button> + + <!-- + <form method="POST" id="uploadForm" action="doUpload" enctype="multipart/form-data"> + + <label>Upload File : <input type=file name="upload" /></label> + <input type="submit"> + + + <s:file name="upload" label="File"/> + + + + <sj:submit + id="ajaxUploadButton" + targets="htmlcontentUpload" + button="true" + value="upload" + > + </sj:submit> + + + </form> + --> + + <sj:div id="htmlcontentUpload"></sj:div> </center> + <div id="htmlcontentPreview"></div> <p align="right">©2004-2009 CodeLutin</p> Modified: trunk/src/main/webapp/accueil.jsp =================================================================== --- trunk/src/main/webapp/accueil.jsp 2011-06-22 15:16:18 UTC (rev 132) +++ trunk/src/main/webapp/accueil.jsp 2011-06-23 14:15:20 UTC (rev 133) @@ -1,9 +1,3 @@ <%@ page contentType="text/html; charset=UTF-8" %> -<html> - <head> - </head> - <body> <p>Parametres detectés</p> - </body> -</html> \ No newline at end of file Modified: trunk/src/main/webapp/pictureUpload.js =================================================================== --- trunk/src/main/webapp/pictureUpload.js 2011-06-22 15:16:18 UTC (rev 132) +++ trunk/src/main/webapp/pictureUpload.js 2011-06-23 14:15:20 UTC (rev 133) @@ -0,0 +1,4 @@ +function upload_popup(page, name) +{ +window.open (page, name, config='top=300, left=300, height=300, width=500, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no') +} \ No newline at end of file Added: trunk/src/main/webapp/uploadForm.jsp =================================================================== --- trunk/src/main/webapp/uploadForm.jsp (rev 0) +++ trunk/src/main/webapp/uploadForm.jsp 2011-06-23 14:15:20 UTC (rev 133) @@ -0,0 +1,34 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title>UploadFile</title> +</head> +<body> + + <form method="POST" id="uploadForm" action="doUpload" enctype="multipart/form-data"> + <label>Upload a picture : <input type="file" name="upload"/></label><br/> + <label>Path on svn : <input type="text" name="svnPath" /></label><br/> + <label>username : <input type="text" name="username" /></label><br/> + <label>password : <input type="password" name="pw" /></label><br/> + <%if (request.getAttribute("badLogin")!=null && request.getAttribute("badLogin").equals(true)) { %> + <p> + <font color="red"> + Bad username or password + </font> + </p> + <% } %> + <%if (request.getAttribute("error")!=null && request.getAttribute("error").equals(true)) { %> + <p> + <font color="red"> + Erreur SVN + </font> + </p> + <% } %> + <input type="submit"/> + </form> + +</body> +</html> \ No newline at end of file Added: trunk/src/main/webapp/uploadSuccess.jsp =================================================================== --- trunk/src/main/webapp/uploadSuccess.jsp (rev 0) +++ trunk/src/main/webapp/uploadSuccess.jsp 2011-06-23 14:15:20 UTC (rev 133) @@ -0,0 +1,15 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title>Success</title> +</head> +<body> +<p>File upload successful</p> + <form> + <input type="button" value="close" onclick="window.close()"> + </form> +</body> +</html> \ No newline at end of file
participants (1)
-
kcardineaud@users.nuiton.org