Author: kcardineaud Date: 2011-06-22 14:46:07 +0200 (Wed, 22 Jun 2011) New Revision: 131 Url: http://nuiton.org/repositories/revision/scmwebeditor/131 Log: Add a search function Added: trunk/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java trunk/src/main/webapp/Search.jsp Removed: trunk/src/main/java/org/nuiton/scmwebeditor/SearchServlet.java Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java trunk/src/main/resources/log4j.properties trunk/src/main/resources/struts.xml trunk/src/main/webapp/BadFileRedirect.jsp trunk/src/main/webapp/OutConnection.jsp trunk/src/main/webapp/Save.jsp Deleted: trunk/src/main/java/org/nuiton/scmwebeditor/SearchServlet.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/SearchServlet.java 2011-06-21 12:56:58 UTC (rev 130) +++ trunk/src/main/java/org/nuiton/scmwebeditor/SearchServlet.java 2011-06-22 12:46:07 UTC (rev 131) @@ -1,101 +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 java.util.logging.Level; -import java.util.logging.Logger; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.tmatesoft.svn.core.ISVNDirEntryHandler; -import org.tmatesoft.svn.core.SVNDirEntry; -import org.tmatesoft.svn.core.SVNException; -import org.tmatesoft.svn.core.SVNURL; -import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; -import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions; -import org.tmatesoft.svn.core.wc.ISVNRepositoryPool; -import org.tmatesoft.svn.core.wc.SVNClientManager; -import org.tmatesoft.svn.core.wc.SVNLogClient; -import org.tmatesoft.svn.core.wc.SVNRevision; -import org.tmatesoft.svn.core.wc.SVNWCUtil; - -public class SearchServlet extends ScmWebEditorBaseAction { - - /** - * - */ - private static final long serialVersionUID = 8229295563440910960L; - private static final Log log = LogFactory.getLog(SearchServlet.class); - - /** - * Handles the HTTP <code>POST</code> method. - * Search files list on scm repository - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - */ - - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException { - try { - String adresse = request.getParameter(PARAMETER_ADRESSE); - if (log.isDebugEnabled()) { - log.debug("Search for files on " + adresse + " repository"); - } - //Create default access - DefaultSVNOptions svnOption = SVNWCUtil.createDefaultOptions(false); - ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(); - log.debug("Authentication manager and svnOption created"); - //Convert url to SVNUrl - SVNURL svnUrl = SVNURL.parseURIEncoded(adresse); - log.debug("Svn url created"); - // create a SVNRepositoryPool - SVNClientManager plop = SVNClientManager.newInstance(svnOption, authManager); - ISVNRepositoryPool pool = plop.getRepositoryPool(); - //get a SVNLogClient - SVNLogClient logClient = new SVNLogClient(pool, svnOption); - log.debug("LogClient Created"); - //recup info about svn repository - ISVNDirEntryHandler dirEntryHandler = new ISVNDirEntryHandler() { - @Override - public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException { - log.debug("Handle dirEntries"); - log.debug("le fichier est: " + dirEntry.getName()); - throw new UnsupportedOperationException("Not supported yet."); - } - }; - log.debug("Begin handle listEntries"); - logClient.doList(svnUrl, SVNRevision.WORKING, SVNRevision.HEAD, true, true, dirEntryHandler); - log.debug("List handle"); - } catch (SVNException ex) { - response.setStatus(401); - Logger.getLogger(SearchServlet.class.getName()).log(Level.SEVERE, null, ex); - } - - - } -} \ No newline at end of file Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-21 12:56:58 UTC (rev 130) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-06-22 12:46:07 UTC (rev 131) @@ -93,6 +93,11 @@ return "noParameter"; } + if(log.isInfoEnabled()) { + log.info("ProjectUrl= "+request.getHeader("referer")); + } + projectUrl=request.getHeader("referer"); + HttpSession httpSession = request.getSession(true); System.setProperty("file.encoding", "UTF-8"); Added: trunk/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java (rev 0) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/SearchAction.java 2011-06-22 12:46:07 UTC (rev 131) @@ -0,0 +1,174 @@ +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.tmatesoft.svn.core.SVNDirEntry; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.SVNNodeKind; +import org.tmatesoft.svn.core.SVNURL; +import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; +import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; + +import org.tmatesoft.svn.core.io.SVNRepository; +import org.tmatesoft.svn.core.io.SVNRepositoryFactory; + +import org.tmatesoft.svn.core.wc.SVNWCUtil; + +import com.opensymphony.xwork2.Action; +import com.opensymphony.xwork2.ActionContext; + + +public class SearchAction extends ScmWebEditorBaseAction { + + /** + * + */ + private static final long serialVersionUID = 4432027215087932750L; + + + private static final Log log = LogFactory.getLog(SearchAction.class); + + + String address; + LinkedList<String> files; + + String info; + + String list; + + public String getList() { + return list; + } + + + public void setList(String list) { + this.list = list; + } + + + public LinkedList<String> getFiles() { + return files; + } + + + public String getInfo() { + return info; + } + + + public String getAddress() { + return address; + } + + + public void setAddress(String address) { + this.address = address; + } + + + public String execute() { + search(); + return Action.SUCCESS; + } + + + public void search() { + + DAVRepositoryFactory.setup(); + + String url = address; + + String name = "anonymous"; + String password="anonymous"; + + files = new LinkedList<String>(); + + + if(address.endsWith("/")) { + address = address.substring(0, address.length()-1); + } + + + SVNRepository repository = null; + try { + repository = SVNRepositoryFactory.create( SVNURL.parseURIDecoded( url ) ); + ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( name , password ); + repository.setAuthenticationManager( authManager ); + + if(log.isInfoEnabled()) { + log.info( "Repository Root: " + repository.getRepositoryRoot( true ) ); + log.info( "Repository UUID: " + repository.getRepositoryUUID( true ) ); + } + + SVNNodeKind nodeKind = repository.checkPath( "" , -1 ); + if ( nodeKind == SVNNodeKind.NONE ) { + if(log.isErrorEnabled()) { + log.error( "There is no entry at '" + url + "'." ); + } + return; + } else if ( nodeKind == SVNNodeKind.FILE ) { + if(log.isErrorEnabled()) { + log.error( "The entry at '" + url + "' is a file while a directory was expected." ); + } + return; + } + + listEntries( repository , "" ); + + + } catch ( Exception svne ) { + log.error("Can't access to the repository",svne); + } + + } + + + public void listEntries( SVNRepository repository, String path ) throws SVNException { + Collection<?> entries = repository.getDir( path, -1 , null , (Collection<?>) null ); + Iterator<?> iterator = entries.iterator(); + + while (iterator.hasNext()) { + 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(); + + + if ( entry.getKind() == SVNNodeKind.DIR ) { + 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); + } + } + + } + + + static public SearchAction getAction() { + return (SearchAction) ActionContext.getContext() + .get(CONTEXT_ACTION_KEY); + } + + public static String replaceLast(String string, String toReplace, String replacement) { + int pos = string.lastIndexOf(toReplace); + if (pos > -1) { + return string.substring(0, pos) + + replacement + + string.substring(pos + toReplace.length(), string.length()); + } else { + return string; + } + } + + +} Modified: trunk/src/main/resources/log4j.properties =================================================================== --- trunk/src/main/resources/log4j.properties 2011-06-21 12:56:58 UTC (rev 130) +++ trunk/src/main/resources/log4j.properties 2011-06-22 12:46:07 UTC (rev 131) @@ -1,5 +1,5 @@ # Global logging configuration -log4j.rootLogger=DEBUG, stdout +log4j.rootLogger=INFO, stdout # Console output... log4j.appender.stdout=org.apache.log4j.ConsoleAppender Modified: trunk/src/main/resources/struts.xml =================================================================== --- trunk/src/main/resources/struts.xml 2011-06-21 12:56:58 UTC (rev 130) +++ trunk/src/main/resources/struts.xml 2011-06-22 12:46:07 UTC (rev 131) @@ -23,10 +23,7 @@ <result>/Preview.jsp</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> + <result>/Search.jsp</result> </action> </package> </struts> \ No newline at end of file Modified: trunk/src/main/webapp/BadFileRedirect.jsp =================================================================== --- trunk/src/main/webapp/BadFileRedirect.jsp 2011-06-21 12:56:58 UTC (rev 130) +++ trunk/src/main/webapp/BadFileRedirect.jsp 2011-06-22 12:46:07 UTC (rev 131) @@ -11,13 +11,13 @@ <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("scmEditorUrl")%>"> +<%=request.getParameter("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("scmEditorUrl")%>">click +please <a href="<%=request.getParameter("projectUrl")%>">click this link</a>.</p> <p>©2004-2009 CodeLutin</p> </body> Modified: trunk/src/main/webapp/OutConnection.jsp =================================================================== --- trunk/src/main/webapp/OutConnection.jsp 2011-06-21 12:56:58 UTC (rev 130) +++ trunk/src/main/webapp/OutConnection.jsp 2011-06-22 12:46:07 UTC (rev 131) @@ -1,5 +1,9 @@ <%-- Document : OutConnection Created on : 6 oct. 2009, 12:07:27 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"> @@ -21,12 +25,28 @@ </h4> </center> <center> -<form method="get" action="checkout.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);"/></p> +<form id="configForm" method="get" action="checkout.action"> + <p><label>SCM path: <input TYPE=text name="address" SIZE=100></label> + + <s:url id="ajaxSearch" value="search.action" /> + + <sj:submit + id="ajaxSearchButton" + formIds="configForm" + targets="htmlcontentSearch" + href="%{ajaxSearch}" + indicator="indicator" + button="true" + buttonIcon="ui-icon-refresh" + value="Search" + > + </sj:submit> + + </p> +<div id="htmlcontentSearch" ></div> -<input type="hidden" name="projectUrl" value="<%=request.getRequestURL()%>" /> -<input type="hidden" name="searchServletUrl" value="<%=request.getAttribute("searchServletUrl")%>"/> +<input type="hidden" name="projectUrl" value="<%=request.getHeader("referer")%>" /> <input type="submit" name="Save" /></form> </center> <p align="right">©2004-2009 CodeLutin</p> Modified: trunk/src/main/webapp/Save.jsp =================================================================== --- trunk/src/main/webapp/Save.jsp 2011-06-21 12:56:58 UTC (rev 130) +++ trunk/src/main/webapp/Save.jsp 2011-06-22 12:46:07 UTC (rev 131) @@ -10,7 +10,7 @@ <%if(result.equals("authError")) { %> - <h4> Bad login or password, can't save modification </h4> + <h4> <font color="red"> Bad username or password, can't save modification</font> </h4> <% } else if(result.equals("erreur")) { %> <h4> Can't save modification </h4> <% } else if(result.equals("uselessSave")) { %> Added: trunk/src/main/webapp/Search.jsp =================================================================== --- trunk/src/main/webapp/Search.jsp (rev 0) +++ trunk/src/main/webapp/Search.jsp 2011-06-22 12:46:07 UTC (rev 131) @@ -0,0 +1,27 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@page import="org.nuiton.scmwebeditor.actions.SearchAction"%> +<%@page import="java.util.LinkedList" %> +<%@page import="java.util.Iterator" %> + <%@ taglib prefix="s" uri="/struts-tags"%> + <%@ taglib prefix="sj" uri="/struts-jquery-tags"%> + <sj:head jquerytheme="default"/> + +<table> + <% + SearchAction action = SearchAction.getAction(); + + LinkedList<String> files = action.getFiles(); + + Iterator<String> it = files.iterator(); + + while(it.hasNext()) { + String file = it.next(); + %> + <tr><td> + <a href="checkout.action?address=<%=file%>&projectUrl="<%=request.getRequestURL()%>" ><%=file%></a> + + </td></tr> + <% } %> + +</table> \ No newline at end of file