+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.web.ajaxplorer.svn;\r
-\r
-import java.io.File;\r
-import java.io.PrintWriter;\r
-import java.text.SimpleDateFormat;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Vector;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-\r
-import org.apache.commons.io.IOUtils;\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.web.ajaxplorer.AjxpAction;\r
-import org.argeo.slc.web.ajaxplorer.AjxpAnswer;\r
-import org.argeo.slc.web.ajaxplorer.AjxpDriverException;\r
-import org.tmatesoft.svn.core.ISVNLogEntryHandler;\r
-import org.tmatesoft.svn.core.SVNException;\r
-import org.tmatesoft.svn.core.SVNLogEntry;\r
-import org.tmatesoft.svn.core.SVNLogEntryPath;\r
-import org.tmatesoft.svn.core.wc.SVNRevision;\r
-\r
-public class SvnLogAction implements AjxpAction<SvnDriver> {\r
- private final SimpleDateFormat sdfIso = new SimpleDateFormat(\r
- "yyyy-MM-dd HH:mm:ss");\r
- private final Log log = LogFactory.getLog(getClass());\r
-\r
- public AjxpAnswer execute(SvnDriver driver, HttpServletRequest request) {\r
- String fileStr = request.getParameter("file");\r
- log.debug("Log file " + fileStr);\r
- if (fileStr == null) {\r
- throw new AjxpDriverException("A file needs to be provided.");\r
- }\r
- File file = new File(driver.getBasePath() + fileStr);\r
- return new SvnLogAnswer(driver, file);\r
- }\r
-\r
- protected class SvnLogAnswer implements AjxpAnswer {\r
- private final SvnDriver driver;\r
- private final File file;\r
-\r
- public SvnLogAnswer(SvnDriver driver, File file) {\r
- this.driver = driver;\r
- this.file = file;\r
- }\r
-\r
- public void updateResponse(HttpServletResponse response) {\r
- PrintWriter writer = null;\r
- try {\r
- writer = response.getWriter();\r
- writer.append("<tree>");\r
- writer.append("<log>");\r
-\r
- final List<SVNLogEntry> logEntries = new Vector<SVNLogEntry>();\r
- ISVNLogEntryHandler logHandler = new ISVNLogEntryHandler() {\r
- public void handleLogEntry(SVNLogEntry logEntry)\r
- throws SVNException {\r
- logEntries.add(logEntry);\r
- }\r
- };\r
-\r
- driver.getManager().getLogClient().doLog(new File[] { file },\r
- SVNRevision.create(0), SVNRevision.HEAD, true, true,\r
- 100, logHandler);\r
-\r
- for (int i = logEntries.size() - 1; i >= 0; i--) {\r
- String xml = logEntryAsXml(logEntries.get(i), file);\r
- if(log.isTraceEnabled())\r
- log.trace(xml);\r
- writer.append(xml);\r
- }\r
-\r
- writer.append("</log>");\r
- writer.append("</tree>");\r
- } catch (Exception e) {\r
- throw new AjxpDriverException(\r
- "Cannot retrieve log for " + file, e);\r
- } finally {\r
- IOUtils.closeQuietly(writer);\r
- }\r
- }\r
-\r
- }\r
-\r
- protected String logEntryAsXml(SVNLogEntry entry, File file) {\r
- StringBuffer buf = new StringBuffer();\r
- buf.append("<logentry");\r
- buf.append(" revision=\"").append(entry.getRevision()).append("\"");\r
- buf.append(" is_file=\"").append(file.isDirectory() ? "0" : "1")\r
- .append("\"");\r
- buf.append(">");\r
-\r
- buf.append("<author>").append(entry.getAuthor()).append("</author>");\r
- buf.append("<date>").append(sdfIso.format(entry.getDate())).append(\r
- "</date>");\r
-\r
- buf.append("<paths>");\r
- Map<Object, SVNLogEntryPath> paths = entry.getChangedPaths();\r
- for (SVNLogEntryPath path : paths.values()) {\r
- buf.append("<path>").append(path.getPath()).append("</path>");\r
- }\r
- buf.append("</paths>");\r
-\r
- buf.append("<msg>").append(entry.getMessage()).append("</msg>");\r
-\r
- buf.append("</logentry>");\r
- return buf.toString();\r
- }\r
-\r
-}\r