r136 - in trunk: . src/main/java/org/nuiton/scmwebeditor src/main/java/org/nuiton/scmwebeditor/actions src/main/webapp
Author: kcardineaud Date: 2011-06-24 15:43:55 +0200 (Fri, 24 Jun 2011) New Revision: 136 Url: http://nuiton.org/repositories/revision/scmwebeditor/136 Log: Svn files are show in order by repertory Added: trunk/src/main/java/org/nuiton/scmwebeditor/UrlSvnFile.java Modified: trunk/pom.xml trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java trunk/src/main/webapp/BadFileRedirect.jsp trunk/src/main/webapp/Search.jsp Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2011-06-24 08:13:58 UTC (rev 135) +++ trunk/pom.xml 2011-06-24 13:43:55 UTC (rev 136) @@ -73,6 +73,11 @@ <version>1.2.1</version> </dependency> + <dependency> + <groupId>org.apache.tika</groupId> + <artifactId>tika-core</artifactId> + <version>0.9</version> + </dependency> <!-- Struts --> Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-06-24 08:13:58 UTC (rev 135) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-06-24 13:43:55 UTC (rev 136) @@ -30,6 +30,11 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.tika.exception.TikaException; +import org.apache.tika.metadata.Metadata; +import org.apache.tika.parser.AutoDetectParser; +import org.apache.tika.sax.BodyContentHandler; +import org.xml.sax.SAXException; import com.opensymphony.xwork2.ActionSupport; @@ -78,7 +83,7 @@ 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_PROJECT_URL = "projectUrl"; 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"; @@ -215,5 +220,18 @@ String url = buffer.toString(); return url; } + + + protected String getMineType(File file) throws IOException, SAXException, TikaException { + FileInputStream is = new FileInputStream(file); + BodyContentHandler contenthandler = new BodyContentHandler(); + Metadata metadata = new Metadata(); + metadata.set(Metadata.RESOURCE_NAME_KEY, file.getName()); + AutoDetectParser parser = new AutoDetectParser(); + parser.parse(is, contenthandler, metadata); + String result = metadata.get(Metadata.CONTENT_TYPE); + log.info("Mine type of " + file.getName() + " is : " + result); + return result; + } } Added: trunk/src/main/java/org/nuiton/scmwebeditor/UrlSvnFile.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/UrlSvnFile.java (rev 0) +++ trunk/src/main/java/org/nuiton/scmwebeditor/UrlSvnFile.java 2011-06-24 13:43:55 UTC (rev 136) @@ -0,0 +1,50 @@ +package org.nuiton.scmwebeditor; + + + +public class UrlSvnFile implements java.lang.Comparable<UrlSvnFile> { + String url; + + public UrlSvnFile (String url) { + this.url=url; + } + + public String toString() { + return url; + } + + public int getLevel() { + String[] tab = url.split("/"); + return tab.length; + } + + + @Override + public int compareTo(UrlSvnFile o) { + int level1 = o.getLevel(); + int level2 = this.getLevel(); + + if (level1 > level2) { + return -1; + } + else if(level1 == level2) { + if(o.toString().length() > this.toString().length()) { + return -1; + } + else if(o.toString().length() == this.toString().length()) { + return 0; + } + else { + return 1; + } + + } + else { + return 1; + } + } + + + + +} Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-24 08:13:58 UTC (rev 135) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorCommitAction.java 2011-06-24 13:43:55 UTC (rev 136) @@ -177,10 +177,6 @@ /* * Commit process */ - - 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()); Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-24 08:13:58 UTC (rev 135) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-24 13:43:55 UTC (rev 136) @@ -25,9 +25,7 @@ public class ScmWebEditorMainAction extends ScmWebEditorBaseAction implements ServletRequestAware { - /** - * - */ + private static final long serialVersionUID = 8361035067228171624L; private static final Log log = LogFactory.getLog(ScmWebEditorMainAction.class); @@ -110,6 +108,7 @@ log.debug("--------------------------"); log.debug("Connection to SCMWebEditor"); log.debug("--------------------------"); + /* Si il n'y a pas de parametre, l'utilisateur est renvoyé * vers la page de configuration (OutConnection) @@ -158,7 +157,6 @@ setSvnSession(httpSession, svnSess); -// Tempdir creation on servlet default temporary directory DAVRepositoryFactory.setup(); @@ -186,6 +184,7 @@ return Action.LOGIN; } catch (SVNException e) { + request.setAttribute("projectUrl", projectUrl); //Suppression du repertoire temporaire delTempDirectory(svnSess); return "erreurPath"; @@ -193,7 +192,26 @@ File CheckOutFile = new File(svnSess.getCheckoutdir(), svnSess.getFileName()); + + String mineType =null; try { + mineType = getMineType(CheckOutFile); + } catch (Exception e) { + if(log.isErrorEnabled()) { + log.error("",e); + } + } + + + + // Si le fichier n'est pas de type texte, on ne peut pas l'éditer + if(!mineType.contains("text")) { + request.setAttribute("projectUrl", projectUrl); + return "erreurPath"; + } + + + try { String originalText = FileUtils.readFileToString(CheckOutFile); request.setAttribute(PARAMETER_FORMAT, svnSess.getFormat()); request.setAttribute(ATTRIBUTE_ORIG_TEXT, StringEscapeUtils.escapeHtml(originalText)); Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java 2011-06-24 08:13:58 UTC (rev 135) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java 2011-06-24 13:43:55 UTC (rev 136) @@ -1,12 +1,14 @@ package org.nuiton.scmwebeditor.actions; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.scmwebeditor.ScmWebEditorBaseAction; +import org.nuiton.scmwebeditor.UrlSvnFile; import org.tmatesoft.svn.core.SVNAuthenticationException; import org.tmatesoft.svn.core.SVNDirEntry; import org.tmatesoft.svn.core.SVNException; @@ -36,7 +38,7 @@ String address; - LinkedList<String> files; + LinkedList<UrlSvnFile> files; String username; String pw; @@ -56,7 +58,7 @@ } - public LinkedList<String> getFiles() { + public LinkedList<UrlSvnFile> getFiles() { return files; } @@ -110,7 +112,7 @@ password=pw; } - files = new LinkedList<String>(); + files = new LinkedList<UrlSvnFile>(); if(address.endsWith("/")) { @@ -143,7 +145,7 @@ } listEntries( repository , "" ); - + Collections.sort(files); } catch (SVNAuthenticationException authexep) { return "authError"; @@ -151,7 +153,8 @@ catch ( SVNException svne ) { log.error("Can't access to the repository",svne); } - + + return Action.SUCCESS; } @@ -161,8 +164,7 @@ try { entries = repository.getDir( path, -1 , null , (Collection<?>) null ); } catch (SVNException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + log.error("Can not reach the repository",e); } Iterator<?> iterator = entries.iterator(); @@ -170,7 +172,6 @@ SVNDirEntry entry = (SVNDirEntry) iterator.next(); if(log.isInfoEnabled()) { log.info("/" + (path.equals("") ? "" : path + "/") + entry.getName()+ "\n"); - info+="/" + (path.equals("") ? "" : path + "/") + entry.getName()+ "\n"; } String fichier = address+"/" + (path.equals("") ? "" : path + "/") + entry.getName(); @@ -179,10 +180,13 @@ listEntries(repository, (path.equals("")) ? entry.getName() : path + "/" + entry.getName()); } else { + // On ajoute dans la liste files seulement les fichiers et pas les répertoires - files.add(fichier); + files.add(new UrlSvnFile(fichier)); + } } + } @@ -202,6 +206,9 @@ return string; } } + - + + + } Modified: trunk/src/main/webapp/BadFileRedirect.jsp =================================================================== --- trunk/src/main/webapp/BadFileRedirect.jsp 2011-06-24 08:13:58 UTC (rev 135) +++ trunk/src/main/webapp/BadFileRedirect.jsp 2011-06-24 13:43:55 UTC (rev 136) @@ -10,14 +10,13 @@ <title>Error...</title> <link rel="icon" href="img/ScmWebEditor_little.png" type="image/png"> <link rel="stylesheet" type="text/css" href="css/main.css"> -<meta http-equiv="Refresh" content="3; url= -<%=request.getParameter("projectUrl")%>"> +<meta http-equiv="Refresh" content="3; url=<%=request.getAttribute("projectUrl")%>"> </head> <body> <a target="_blank" href="http://maven-site.nuiton.org/scmwebeditor/"><img src="img/ScmWebEditor_main.png" alt="$alt" /></a> <p>Bad SCM path or file name! Please correct it.</p> <p>You should be transferred automatically to the form page. If not -please <a href="<%=request.getParameter("projectUrl")%>">click +please <a href="<%=request.getAttribute("projectUrl")%>">click this link</a>.</p> <p>©2004-2009 CodeLutin</p> </body> Modified: trunk/src/main/webapp/Search.jsp =================================================================== --- trunk/src/main/webapp/Search.jsp 2011-06-24 08:13:58 UTC (rev 135) +++ trunk/src/main/webapp/Search.jsp 2011-06-24 13:43:55 UTC (rev 136) @@ -3,6 +3,7 @@ <%@page import="org.nuiton.scmwebeditor.actions.SearchAction"%> <%@page import="java.util.LinkedList" %> <%@page import="java.util.Iterator" %> +<%@page import="org.nuiton.scmwebeditor.UrlSvnFile" %> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="sj" uri="/struts-jquery-tags"%> <sj:head jquerytheme="default"/> @@ -13,15 +14,16 @@ <% SearchAction action = SearchAction.getAction(); - LinkedList<String> files = action.getFiles(); + LinkedList<UrlSvnFile> files = action.getFiles(); - Iterator<String> it = files.iterator(); + Iterator<UrlSvnFile> it = files.iterator(); while(it.hasNext()) { - String file = it.next(); + UrlSvnFile file = it.next(); + %> <tr><td> - <a href="checkout.action?address=<%=file%>&projectUrl="<%=request.getRequestURL()%>" ><%=file%></a> + <a href="checkout.action?address=<%=file%>" ><%=file+" "+file.getLevel()%></a> </td></tr> <% } %>
participants (1)
-
kcardineaud@users.nuiton.org