Author: andreas
Date: Tue Jun 24 05:05:32 2008
New Revision: 671148
URL: http://svn.apache.org/viewvc?rev=671148&view=rev
Log:
Append new SVN changes to existing changes in the last month, use GMT for date formatting (following the Subversion standard).
Modified:
lenya/docu/modules/forrest/java/src/org/apache/lenya/modules/forrest/UpdateChanges.java
lenya/docu/modules/forrest/resources/samples/svnLog.xml
Modified: lenya/docu/modules/forrest/java/src/org/apache/lenya/modules/forrest/UpdateChanges.java
URL: http://svn.apache.org/viewvc/lenya/docu/modules/forrest/java/src/org/apache/lenya/modules/forrest/UpdateChanges.java?rev=671148&r1=671147&r2=671148&view=diff
==============================================================================
--- lenya/docu/modules/forrest/java/src/org/apache/lenya/modules/forrest/UpdateChanges.java (original)
+++ lenya/docu/modules/forrest/java/src/org/apache/lenya/modules/forrest/UpdateChanges.java Tue Jun 24 05:05:32 2008
@@ -21,11 +21,19 @@
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.TimeZone;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.cocoon.xml.dom.DOMBuilder;
import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.publication.Document;
@@ -41,6 +49,7 @@
import org.apache.lenya.cms.site.SiteStructure;
import org.apache.lenya.cms.usecase.AbstractUsecase;
import org.apache.lenya.modules.navigation.SiteMetaDataTransformer;
+import org.apache.lenya.xml.DocumentHelper;
import org.tmatesoft.svn.core.ISVNLogEntryHandler;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
@@ -50,6 +59,10 @@
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.xml.SVNXMLLogHandler;
import org.tmatesoft.svn.core.wc.xml.SVNXMLSerializer;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
/**
* Update the changes documents from the SVN repository log. The documents are
@@ -107,14 +120,23 @@
private ServiceManager manager;
private SiteNode parent;
private Month currentMonth;
+
+ protected static final TimeZone TIME_ZONE = TimeZone.getTimeZone("GMT");
+ protected static final SimpleDateFormat YEAR_FORMAT = new SimpleDateFormat("yyyy");
+ protected static final SimpleDateFormat MONTH_FORMAT = new SimpleDateFormat("MM");
+
+ static {
+ YEAR_FORMAT.setTimeZone(TIME_ZONE);
+ MONTH_FORMAT.setTimeZone(TIME_ZONE);
+ }
protected static class Month {
private int year = 0;
private int month = 0;
private Document doc;
- private SVNXMLSerializer serializer;
private SVNXMLLogHandler handler;
- private OutputStream stream;
+ private DOMBuilder builder;
+
public Month(int year, int month, Document doc) {
this.year = year;
@@ -122,23 +144,21 @@
this.doc = doc;
}
- public boolean contains(Date date) {
- return this.year == date.getYear() && this.month == date.getMonth();
- }
-
public void start() {
- this.stream = this.doc.getOutputStream();
- this.serializer = new SVNXMLSerializer(stream);
- this.handler = new SVNXMLLogHandler(serializer);
- this.handler.startDocument();
+ org.w3c.dom.Document xml;
+ try {
+ xml = DocumentHelper.readDocument(this.doc.getInputStream());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ this.builder = new DOMBuilder(xml.getDocumentElement());
+ this.handler = new SVNXMLLogHandler(this.builder);
}
public void stop() {
- this.handler.endDocument();
try {
- this.serializer.flush();
- this.stream.close();
- } catch (IOException e) {
+ DocumentHelper.writeDocument(this.builder.getDocument(), this.doc.getOutputStream());
+ } catch (Exception e) {
throw new RuntimeException(e);
}
}
@@ -147,22 +167,31 @@
this.handler.handleLogEntry(entry);
}
- }
+ public boolean equals(int year, int month) {
+System.out.println(this.year + "=" + year + ", " + this.month + "=" + month);
+ return this.year == year && this.month == month;
+ }
+ }
+
public LogEntryHandler(ServiceManager manager, SiteNode parent) {
this.parent = parent;
this.manager = manager;
}
public void handleLogEntry(SVNLogEntry entry) throws SVNException {
- Date date = entry.getDate();
+ Calendar cal = new GregorianCalendar(TIME_ZONE);
+ cal.setTime(entry.getDate());
+System.out.println("Checking date " + entry.getDate() + ": " + entry.getAuthor() + ": " + entry.getMessage());
try {
- if (this.currentMonth == null || !this.currentMonth.contains(date)) {
+ int year = cal.get(Calendar.YEAR);
+ int month = cal.get(Calendar.MONTH);
+ if (this.currentMonth == null || !this.currentMonth.equals(year, month)) {
+System.out.println("Starting new month");
if (this.currentMonth != null) {
this.currentMonth.stop();
}
- this.currentMonth = new Month(date.getYear(), date.getMonth(),
- getDocument(date));
+ this.currentMonth = new Month(year, month, getDocument(cal));
this.currentMonth.start();
}
this.currentMonth.handleLogEntry(entry);
@@ -177,11 +206,8 @@
}
}
- protected Document getDocument(Date date) throws Exception {
- int year = date.getYear();
- int month = date.getMonth();
-
- String yearString = new SimpleDateFormat("yyyy").format(date);
+ protected Document getDocument(Calendar cal) throws Exception {
+ String yearString = YEAR_FORMAT.format(cal.getTime());
String yearPath = this.parent.getPath() + "/" + yearString;
SiteStructure site = this.parent.getStructure();
if (!site.contains(yearPath)) {
@@ -193,7 +219,7 @@
// yearString);
}
- String monthString = new SimpleDateFormat("MM").format(date);
+ String monthString = MONTH_FORMAT.format(cal.getTime());
return getDocument(yearPath + "/" + monthString, "svnLog", monthString);
}
Modified: lenya/docu/modules/forrest/resources/samples/svnLog.xml
URL: http://svn.apache.org/viewvc/lenya/docu/modules/forrest/resources/samples/svnLog.xml?rev=671148&r1=671147&r2=671148&view=diff
==============================================================================
--- lenya/docu/modules/forrest/resources/samples/svnLog.xml (original)
+++ lenya/docu/modules/forrest/resources/samples/svnLog.xml Tue Jun 24 05:05:32 2008
@@ -1,12 +1,2 @@
<?xml version="1.0"?>
-<log>
- <logentry revision="580913">
- <author>john</author>
- <date>2007-10-01T10:11:28.396022Z</date>
- <paths>
- <path action="M">/lenya/branches/branch_1_2_x_shibboleth/src/java/org/apache/lenya/ac/shibboleth/ShibbolethAuthenticator.java</path>
- <path action="M">/lenya/branches/branch_1_2_x_shibboleth/src/webapp/WEB-INF/cocoon-xconf.xsl</path>
- </paths>
- <msg>Make redirect to WAYF server configurable</msg>
- </logentry>
-</log>
+<log/>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.