You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2008/03/03 02:05:29 UTC

svn commit: r632904 - in /lenya/sandbox/modules/forrest: config/ config/cocoon-xconf/ java/src/org/apache/lenya/modules/forrest/ java/test/org/apache/lenya/modules/forrest/

Author: andreas
Date: Sun Mar  2 17:05:28 2008
New Revision: 632904

URL: http://svn.apache.org/viewvc?rev=632904&view=rev
Log:
Updated forrest import usecase, added usecase to update the SVN changes.

Added:
    lenya/sandbox/modules/forrest/config/cocoon-xconf/usecase-updateChanges.xconf
    lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/Changes.java
    lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/UpdateChanges.java
Modified:
    lenya/sandbox/modules/forrest/config/cocoon-xconf/resourcetype-forrestDocument20.xconf
    lenya/sandbox/modules/forrest/config/cocoon-xconf/resourcetype-forrestFaq20.xconf
    lenya/sandbox/modules/forrest/config/module.xml
    lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/Importer.java
    lenya/sandbox/modules/forrest/java/test/org/apache/lenya/modules/forrest/ImportTest.java

Modified: lenya/sandbox/modules/forrest/config/cocoon-xconf/resourcetype-forrestDocument20.xconf
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/forrest/config/cocoon-xconf/resourcetype-forrestDocument20.xconf?rev=632904&r1=632903&r2=632904&view=diff
==============================================================================
--- lenya/sandbox/modules/forrest/config/cocoon-xconf/resourcetype-forrestDocument20.xconf (original)
+++ lenya/sandbox/modules/forrest/config/cocoon-xconf/resourcetype-forrestDocument20.xconf Sun Mar  2 17:05:28 2008
@@ -39,7 +39,9 @@
     <link-attribute xpath="//*/@src"/>
     <format name="xhtml" uri="cocoon://modules/forrest/xhtml.xml"/>
     <format name="webdavGET" uri="cocoon://modules/forrest/davget.xml"/>
+    <!--
     <format name="luceneIndex" uri="cocoon://modules/forrest/lucene-index"/>
+    -->
     <!-- "xslt-clean" format is used by webDAV (and other editors?) to "clean" xml content before it is validated/saved --> 
     <format name="xslt-clean" uri="fallback://lenya/modules/forrest/xslt/clean-xhtml.xsl"/>
     <format name="icon" uri="cocoon://modules/forrest/icon"/>

Modified: lenya/sandbox/modules/forrest/config/cocoon-xconf/resourcetype-forrestFaq20.xconf
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/forrest/config/cocoon-xconf/resourcetype-forrestFaq20.xconf?rev=632904&r1=632903&r2=632904&view=diff
==============================================================================
--- lenya/sandbox/modules/forrest/config/cocoon-xconf/resourcetype-forrestFaq20.xconf (original)
+++ lenya/sandbox/modules/forrest/config/cocoon-xconf/resourcetype-forrestFaq20.xconf Sun Mar  2 17:05:28 2008
@@ -42,7 +42,9 @@
     <link-attribute xpath="//*/@src"/>
     <format name="xhtml" uri="cocoon://modules/forrest/xhtml.xml"/>
     <format name="webdavGET" uri="cocoon://modules/forrest/davget.xml"/>
+    <!--
     <format name="luceneIndex" uri="cocoon://modules/forrest/lucene-index"/>
+    -->
     <!-- "xslt-clean" format is used by webDAV (and other editors?) to "clean" xml content before it is validated/saved --> 
     <format name="xslt-clean" uri="fallback://lenya/modules/forrest/xslt/clean-xhtml.xsl"/>
     <format name="icon" uri="cocoon://modules/forrest/icon"/>

Added: lenya/sandbox/modules/forrest/config/cocoon-xconf/usecase-updateChanges.xconf
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/forrest/config/cocoon-xconf/usecase-updateChanges.xconf?rev=632904&view=auto
==============================================================================
--- lenya/sandbox/modules/forrest/config/cocoon-xconf/usecase-updateChanges.xconf (added)
+++ lenya/sandbox/modules/forrest/config/cocoon-xconf/usecase-updateChanges.xconf Sun Mar  2 17:05:28 2008
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!-- $Id: usecases-workflow-deactivate.xconf 348547 2005-11-23 20:13:01Z chestnut $ -->
+<!--
+    This file defines the publication specific use-cases
+-->
+
+<xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'forrest.updateChanges']">
+
+  <component-instance name="forrest.updateChanges" logger="lenya.modules.forrest"
+      class="org.apache.lenya.modules.forrest.UpdateChanges">
+    <view template="modules/forrest/usecases/updateChanges.jx"/>
+  </component-instance>
+  
+</xconf>

Modified: lenya/sandbox/modules/forrest/config/module.xml
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/forrest/config/module.xml?rev=632904&r1=632903&r2=632904&view=diff
==============================================================================
--- lenya/sandbox/modules/forrest/config/module.xml (original)
+++ lenya/sandbox/modules/forrest/config/module.xml Sun Mar  2 17:05:28 2008
@@ -21,6 +21,8 @@
 <module xmlns="http://apache.org/lenya/module/1.0">
   <id>org.apache.lenya.modules.forrest</id>
   <depends module="org.apache.lenya.modules.externallinks"/>
+  <depends module="org.apache.lenya.modules.linkdocument"/>
+  <depends module="org.apache.lenya.modules.foldernode"/>
   <package>org.apache.lenya.modules</package>
   <version>0.1-dev</version>
   <name>Forrest</name>

Added: lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/Changes.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/Changes.java?rev=632904&view=auto
==============================================================================
--- lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/Changes.java (added)
+++ lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/Changes.java Sun Mar  2 17:05:28 2008
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.modules.forrest;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.lenya.cms.metadata.MetaData;
+import org.apache.lenya.cms.metadata.MetaDataException;
+import org.apache.lenya.cms.metadata.dublincore.DublinCore;
+import org.apache.lenya.cms.publication.Area;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.ResourceType;
+import org.apache.lenya.cms.site.SiteNode;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.apache.lenya.util.Assert;
+import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.NamespaceHelper;
+import org.tmatesoft.svn.core.ISVNLogEntryHandler;
+import org.tmatesoft.svn.core.SVNLogEntry;
+import org.tmatesoft.svn.core.wc.xml.SVNXMLLogHandler;
+import org.tmatesoft.svn.core.wc.xml.SVNXMLSerializer;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+public class Changes {
+
+    private Document delegate;
+    private int year;
+    private int month;
+    private long lastRevision;
+
+    public Changes(Document doc) {
+        Assert.notNull(doc);
+        this.delegate = doc;
+        try {
+            String name = doc.getLink().getNode().getName();
+            String yearString = name.substring(0, 4);
+            this.year = Integer.parseInt(yearString);
+            String monthString = name.substring(4, 6);
+            this.month = Integer.parseInt(monthString);
+
+        } catch (DocumentException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public Changes(ServiceManager manager, SiteNode parent, int year, int month,
+            long lastRevision) {
+        this.year = year;
+        this.month = month;
+        this.lastRevision = lastRevision;
+
+        try {
+            SiteStructure site = parent.getStructure();
+            Publication pub = site.getPublication();
+            String language = pub.getDefaultLanguage();
+            String name = "" + this.year + this.month;
+            String path = parent.getPath() + "/" + name;
+            if (site.contains(path)) {
+                this.delegate = site.getNode(path).getLink(language).getDocument();
+            } else {
+                DocumentManager docMgr = null;
+                ServiceSelector selector = null;
+                ResourceType type = null;
+                try {
+                    selector = (ServiceSelector) manager.lookup(ResourceType.ROLE + "Selector");
+                    type = (ResourceType) selector.select("svnLog");
+                    String sampleUri = type.getSample(type.getSampleNames()[0]).getUri();
+
+                    String title = this.year + "-" + this.month;
+
+                    docMgr = (DocumentManager) manager.lookup(DocumentManager.ROLE);
+                    this.delegate = docMgr.add(pub.getFactory(), type, sampleUri, pub, site
+                            .getArea(), path, language, "xml", title, true);
+                } finally {
+                    if (docMgr != null) {
+                        manager.release(docMgr);
+                    }
+                    if (selector != null) {
+                        if (type != null) {
+                            selector.release(type);
+                        }
+                        manager.release(selector);
+                    }
+                }
+            }
+            MetaData meta = getDcTerms();
+            meta.setValue(DublinCore.TERM_HASVERSION, Long.toString(this.lastRevision));
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
+    /*
+     * protected void load() { org.w3c.dom.Document xml; try { xml =
+     * DocumentHelper.readDocument(this.delegate.getInputStream()); } catch (Exception e) { throw
+     * new RuntimeException(e); } NamespaceHelper helper = new NamespaceHelper("", "", xml);
+     * Element[] elements = helper.getChildren(xml.getDocumentElement(),
+     * SVNXMLLogHandler.LOGENTRY_TAG); for (int i = 0; i < elements.length; i++) { long revision =
+     * Long.parseLong(elements[i].getAttribute(SVNXMLLogHandler.REVISION_ATTR)); Element dateElement =
+     * helper.getFirstChild(elements[i], SVNXMLLogHandler.DATE_TAG); String dateString =
+     * DocumentHelper.getSimpleElementText(dateElement); Date date =
+     * 
+     * Map paths = new HashMap();
+     * 
+     * SVNLogEntry entry = new SVNLogEntry(paths, revision, author, date, message); } }
+     */
+
+    /**
+     * @return The revisions, starting with the lowest revision number. public long[] getRevisions() { }
+     */
+
+    public long getLastRevision() {
+        try {
+            MetaData meta = getDcTerms();
+            String revisionString = meta.getFirstValue(DublinCore.TERM_HASVERSION);
+            return Long.parseLong(revisionString);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
+    protected MetaData getDcTerms() throws MetaDataException {
+        MetaData meta = this.delegate.getMetaData(DublinCore.DCTERMS_NAMESPACE);
+        return meta;
+    }
+
+    public Document getDocument() {
+        return this.delegate;
+    }
+
+}

Modified: lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/Importer.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/Importer.java?rev=632904&r1=632903&r2=632904&view=diff
==============================================================================
--- lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/Importer.java (original)
+++ lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/Importer.java Sun Mar  2 17:05:28 2008
@@ -22,9 +22,11 @@
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
@@ -46,6 +48,8 @@
 import org.apache.lenya.cms.site.SiteStructure;
 import org.apache.lenya.modules.externallinks.ExternalLinks;
 import org.apache.lenya.modules.externallinks.ExternalLinksRewriter;
+import org.apache.lenya.modules.foldernode.FolderNodeTransformer;
+import org.apache.lenya.modules.linkdocument.LinkDocument;
 import org.apache.lenya.xml.DocumentHelper;
 import org.apache.lenya.xml.NamespaceHelper;
 import org.apache.xpath.XPathAPI;
@@ -66,6 +70,26 @@
         this.manager = manager;
     }
 
+    protected static Set blockedPaths = new HashSet();
+    protected static Map changedPaths = new HashMap();
+    protected static Object pathToRemove = "-";
+
+    static {
+        blockedPaths.add("/index/changes/");
+        
+        changedPaths.put("/project-information", pathToRemove);
+        changedPaths.put("/project-information/indexpm", "/index");
+        changedPaths.put("/project-information/", "/index/");
+        changedPaths.put("/docu", pathToRemove);
+        changedPaths.put("/docu/index", "/docu");
+        changedPaths.put("/docu20", pathToRemove);
+        changedPaths.put("/docu20/index", "/docu20");
+        changedPaths.put("/docu12x", pathToRemove);
+        changedPaths.put("/docu12x/index", "/docu12x");
+        changedPaths.put("/community", pathToRemove);
+        changedPaths.put("/community/indexcom", "/community");
+    }
+
     protected static final String CONTENT_PATH = "src/documentation/content/xdocs";
     protected static final String SITE_FILE = "site.xml";
     protected static final String SITE_NAMESPACE = "http://apache.org/forrest/linkmap/1.0";
@@ -77,6 +101,13 @@
     protected static final String LANGUAGE = "en";
     protected static final String EXTENSION = "xml";
     protected static final String SITE_PROTOCOL = "site:";
+    
+    private static final int DEBUG = 0;
+    private static final int INFO = 1;
+    private static final int WARN = 2;
+    private static final int ERROR = 3;
+    private static final int FATAL = 4;
+    private static final int LOG_LEVEL = INFO;
 
     public void importSite(Area area) throws Exception {
 
@@ -94,23 +125,26 @@
         ResourceType forrestResourceType = null;
         ResourceType mediaResourceType = null;
         ResourceType faqResourceType = null;
+        ResourceType linkResourceType = null;
         DocumentManager docMgr = null;
         try {
             selector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE + "Selector");
             forrestResourceType = (ResourceType) selector.select(RESOURCE_TYPE_NAME_FORREST);
             faqResourceType = (ResourceType) selector.select(RESOURCE_TYPE_NAME_FAQ);
             mediaResourceType = (ResourceType) selector.select(RESOURCE_TYPE_NAME_MEDIA);
+            linkResourceType = (ResourceType) selector.select(LinkDocument.RESOURCE_TYPE);
             docMgr = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
 
             ImportInfo info = new ImportInfo();
             info.area = area;
             info.forrestResourceType = forrestResourceType;
             info.faqResourceType = faqResourceType;
+            info.linkResourceType = linkResourceType;
             info.mediaResourceType = mediaResourceType;
             info.helper = helper;
             info.docMgr = docMgr;
             info.links = links;
-            
+
             info.externalLinks = new ExternalLinks(this.manager, area, getLogger());
             info.externalLinksRewriter = new ExternalLinksRewriter(this.manager, area, getLogger());
 
@@ -136,9 +170,13 @@
                 if (mediaResourceType != null) {
                     selector.release(mediaResourceType);
                 }
+                if (linkResourceType != null) {
+                    selector.release(linkResourceType);
+                }
                 this.manager.release(selector);
             }
         }
+        log("Done, committing session.", INFO);
     }
 
     protected void importChildren(ImportInfo info, Element element, String baseUri, String basePath)
@@ -160,47 +198,90 @@
         }
 
         String href = element.getAttribute(ATTR_HREF);
-        String title = element.getAttribute(ATTR_LABEL);
-
         String sourceUri = concatPath(baseUri, href);
 
-        if (href.startsWith("http:")) {
-            info.links.put(linkName, href);
-            /*
-             * String path = concatPath(basePath, nodeName); SiteNode node =
-             * info.area.getSite().add(path); node.setHref(href);
-             */
-        }
-        else if (info.externalLinksRewriter.matches(href)) {
-            SiteNode node = getSiteNode(info, basePath, nodeName);
-            String externalUri = info.externalLinksRewriter.rewrite(href);
-            
-            // FIXME: not supported yet
-            // node.setHref(externalUri);
-        } else if (sourceUri.endsWith(".png") || sourceUri.endsWith(".gif")) {
-            createDocument(info, info.mediaResourceType, sourceUri, basePath, nodeName, linkName,
-                    title);
+        String path = concatPath(basePath, nodeName);
+        if (changedPaths.containsKey(path)) {
+            path = (String) changedPaths.get(path);
         } else {
-            if (sourceUri.endsWith(".html")) {
-                sourceUri = sourceUri.substring(0, sourceUri.length() - ".href".length()) + ".xml";
+            String[] steps = path.split("/");
+            final String prefix = "/" + steps[1] + "/";
+            if (changedPaths.containsKey(prefix)) {
+                final String newPrefix = (String) changedPaths.get(prefix);
+                path = newPrefix + path.substring(prefix.length());
             }
-            org.w3c.dom.Document xml = null;
-            try {
-                xml = SourceUtil.readDOM(sourceUri, this.manager);
-            } catch (Exception ignore) {
+        }
+        
+        boolean blocked = false;
+        for (Iterator i = blockedPaths.iterator(); i.hasNext(); ) {
+            String prefix = (String) i.next();
+            if (path.startsWith(prefix)) {
+                log("Blocking path " + path, INFO);
+                blocked = true;
             }
+        }
 
-            if (xml == null) {
-                SiteNode node = getSiteNode(info, basePath, nodeName);
+        if (!blocked && !path.equals(pathToRemove)) {
+
+            String title = element.getAttribute(ATTR_LABEL);
+
+            log("------------------------------------------------------------------", DEBUG);
+            log("basePath: " + basePath, DEBUG);
+            log("href: " + href, DEBUG);
+            log("sourceUri: " + sourceUri, DEBUG);
+            log("baseUri: " + baseUri, DEBUG);
+            log("Target path " + basePath + "/" + linkName, DEBUG);
+
+            if (href.startsWith("http:")) {
+                log("HTTP link: " + href, DEBUG);
+                info.links.put(linkName, href);
+                String[] samples = info.linkResourceType.getSampleNames();
+                sourceUri = info.linkResourceType.getSample(samples[0]).getUri();
+                Document doc = createDocument(info, info.linkResourceType, sourceUri, path,
+                        linkName, title);
+                LinkDocument linkDoc = new LinkDocument(doc);
+                linkDoc.setHref(href);
+            } else if (info.externalLinksRewriter.matches(href)) {
+                log("External link: " + href, DEBUG);
+                String externalUri = info.externalLinksRewriter.rewrite(href);
+                Document doc = createDocument(info, info.linkResourceType, sourceUri, path,
+                        linkName, title);
+                LinkDocument linkDoc = new LinkDocument(doc);
+                linkDoc.setHref(externalUri);
+            } else if (sourceUri.endsWith(".png") || sourceUri.endsWith(".gif")) {
+                log("Image: " + sourceUri, DEBUG);
+                createDocument(info, info.mediaResourceType, sourceUri, path, linkName, title);
             } else {
-                String localName = xml.getDocumentElement().getLocalName();
-                ResourceType type = null;
-                if (localName.equals(ELEMENT_FAQS)) {
-                    type = info.faqResourceType;
-                } else {
+                log("HTML document: " + sourceUri, DEBUG);
+                if (sourceUri.endsWith(".html")) {
+                    sourceUri = sourceUri.substring(0, sourceUri.length() - ".href".length())
+                            + ".xml";
+                }
+                org.w3c.dom.Document xml = null;
+                try {
+                    xml = SourceUtil.readDOM(sourceUri, this.manager);
+                } catch (Exception ignore) {
+                }
+
+                boolean isFolderNode = (xml == null);
+
+                ResourceType type;
+                String contentSourceUri;
+                if (isFolderNode) {
+                    log("Creating folder node.", DEBUG);
                     type = info.forrestResourceType;
+                    String[] samples = type.getSampleNames();
+                    contentSourceUri = type.getSample(samples[0]).getUri();
+                } else {
+                    contentSourceUri = sourceUri;
+                    type = getResourceType(xml, info);
+                    log("Creating " + type.getName() + " document.", DEBUG);
+                }
+                Document doc = createDocument(info, type, contentSourceUri, path, linkName, title);
+                if (isFolderNode) {
+                    doc.getMetaData(FolderNodeTransformer.NAMESPACE).setValue(
+                            FolderNodeTransformer.ELEM_FOLDERNODE, Boolean.toString(true));
                 }
-                createDocument(info, type, sourceUri, basePath, nodeName, linkName, title);
             }
         }
 
@@ -210,20 +291,26 @@
 
     }
 
-    protected SiteNode getSiteNode(ImportInfo info, String basePath, String nodeName)
-            throws SiteException {
-        SiteNode node;
-        String path = concatPath(basePath, nodeName);
-        SiteStructure site = info.area.getSite();
-        if (site.contains(path)) {
-            node = site.getNode(path);
+    protected ResourceType getResourceType(org.w3c.dom.Document xml, ImportInfo info) {
+        String localName = xml.getDocumentElement().getLocalName();
+        ResourceType type;
+        if (localName.equals(ELEMENT_FAQS)) {
+            type = info.faqResourceType;
         } else {
-            node = site.add(path);
-            // TODO: add link (not supported by API yet)
+            type = info.forrestResourceType;
         }
-        return node;
+        return type;
     }
 
+    /*
+     * protected SiteNode getSiteNode(ImportInfo info, String basePath, String
+     * nodeName) throws SiteException { SiteNode node; String path =
+     * concatPath(basePath, nodeName); SiteStructure site = info.area.getSite();
+     * if (site.contains(path)) { node = site.getNode(path); } else { node =
+     * site.add(path); // TODO: add link (not supported by API yet) } return
+     * node; }
+     */
+
     protected String concatPath(String path1, String path2) {
         StringBuffer path = new StringBuffer();
         path.append(path1);
@@ -244,9 +331,8 @@
         return sample.getUri();
     }
 
-    protected void createDocument(ImportInfo info, ResourceType type, String sourceUri,
-            String basePath, String nodeName, String linkName, String title) throws Exception {
-        String path = concatPath(basePath, nodeName);
+    protected Document createDocument(ImportInfo info, ResourceType type, String sourceUri,
+            String path, String linkName, String title) throws Exception {
         DocumentFactory factory = info.area.getPublication().getFactory();
         try {
 
@@ -269,9 +355,9 @@
                         String sourceString = IOUtils.toString(source.getInputStream());
                         String docString = IOUtils.toString(doc.getInputStream());
                         if (sourceString.equals(docString)) {
-                            log(path + " is up to date (" + info.counterToString() + ")");
+                            log(path + " is up to date (" + info.counterToString() + ")", INFO);
                         } else {
-                            log("Updating " + path + " (" + info.counterToString() + ")");
+                            log("Updating " + path + " (" + info.counterToString() + ")", INFO);
                             IOUtils.write(sourceString, doc.getOutputStream());
                         }
                     } finally {
@@ -286,17 +372,20 @@
                 String extension = sourceUri.substring(lastDotIndex + 1);
                 doc = info.docMgr.add(factory, type, sourceUri, info.area.getPublication(),
                         info.area.getName(), path, LANGUAGE, extension, title, true);
-                Link link = new Link();
-                link.setUuid(doc.getUUID());
-                info.links.put(linkName, link.getUri());
                 log("Created " + extension.toUpperCase() + " document (" + info.counterToString()
-                        + ") [" + path + "]");
+                        + ") [" + path + "] from [" + sourceUri + "]", INFO);
             }
+            
+            Link link = new Link();
+            link.setUuid(doc.getUUID());
+            info.links.put(linkName, link.getUri());
+
+            return doc;
 
         } catch (Exception e) {
-            log("A problem occured:");
-            log("Path: '" + path + "'");
-            log("URI:  '" + sourceUri + "'");
+            log("A problem occured:", ERROR);
+            log("Path: '" + path + "'", ERROR);
+            log("URI:  '" + sourceUri + "'", ERROR);
             throw e;
         }
     }
@@ -305,14 +394,17 @@
         return string.replaceAll("[^a-zA-Z0-9\\-]+", "");
     }
 
-    protected void log(String message) {
-        System.out.println(message);
-        getLogger().info(message);
+    protected void log(String message, int level) {
+        if (level >= LOG_LEVEL) {
+            System.out.println(message);
+            getLogger().info(message);
+        }
     }
 
     protected class ImportInfo {
         protected int number = 0;
         protected int counter = 0;
+        protected ResourceType linkResourceType;
         protected ResourceType mediaResourceType;
         protected ResourceType forrestResourceType;
         protected ResourceType faqResourceType;
@@ -372,7 +464,7 @@
         }
         for (Iterator i = docsToConvert.iterator(); i.hasNext();) {
             Document doc = (Document) i.next();
-            log("Converting links (" + info.counterToString() + "): " + doc.getPath());
+            log("Converting links (" + info.counterToString() + "): " + doc.getPath(), INFO);
             org.w3c.dom.Document xml = DocumentHelper.readDocument(doc.getInputStream());
             convertLinks(info, xml.getDocumentElement());
             DocumentHelper.writeDocument(xml, doc.getOutputStream());
@@ -385,13 +477,13 @@
             Attr attr = (Attr) attrs.item(i);
             String value = attr.getNodeValue();
             if (value.startsWith(SITE_PROTOCOL)) {
-                log("Converting link [" + value + "]");
+                log("Converting link [" + value + "]", INFO);
                 String name = value.substring(SITE_PROTOCOL.length());
                 if (info.links.containsKey(name)) {
                     String linkUri = (String) info.links.get(name);
                     attr.setNodeValue(linkUri);
                 } else {
-                    log("No document found for link [" + value + "]");
+                    log("No document found for link [" + value + "]", WARN);
                 }
             }
         }
@@ -412,7 +504,7 @@
         for (int i = 0; i < children.length; i++) {
             String name = children[i].getLocalName();
             String uri = baseUri + children[i].getAttribute("href");
-            log("Adding external link: " + name + " -> " + uri);
+            log("Adding external link: " + name + " -> " + uri, INFO);
             info.externalLinks.setUri(name, uri);
             createExternalLinks(info, children[i], uri);
         }

Added: lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/UpdateChanges.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/UpdateChanges.java?rev=632904&view=auto
==============================================================================
--- lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/UpdateChanges.java (added)
+++ lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/UpdateChanges.java Sun Mar  2 17:05:28 2008
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.lenya.modules.forrest;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.lenya.cms.metadata.MetaData;
+import org.apache.lenya.cms.metadata.dublincore.DublinCore;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentBuildException;
+import org.apache.lenya.cms.publication.DocumentFactory;
+import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.cms.publication.ResourceType;
+import org.apache.lenya.cms.publication.URLInformation;
+import org.apache.lenya.cms.site.SiteException;
+import org.apache.lenya.cms.site.SiteNode;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.apache.lenya.cms.usecase.AbstractUsecase;
+import org.apache.lenya.modules.foldernode.FolderNodeTransformer;
+import org.apache.lenya.modules.linkdocument.LinkDocument;
+import org.tmatesoft.svn.core.ISVNLogEntryHandler;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.SVNLogEntry;
+import org.tmatesoft.svn.core.SVNURL;
+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.xml.SVNXMLLogHandler;
+import org.tmatesoft.svn.core.wc.xml.SVNXMLSerializer;
+
+/**
+ * Update the changes documents from the SVN repository log. The documents are
+ * stored at the path {@link #CHANGES_PATH}/{year}/{month}.
+ */
+public class UpdateChanges extends AbstractUsecase {
+
+    protected static final String CHANGES_PATH = "/index/changes";
+    protected static final String SVN_URL = "http://svn.apache.org/repos/asf/lenya";
+
+    protected void doExecute() throws Exception {
+        super.doExecute();
+
+        setupLibrary();
+
+        DocumentFactory factory = getDocumentFactory();
+        URLInformation url = new URLInformation(getSourceURL());
+        Publication pub = factory.getPublication(url.getPublicationId());
+
+        SiteStructure site = pub.getArea(Publication.AUTHORING_AREA).getSite();
+        SiteNode changesNode = site.getNode(CHANGES_PATH);
+
+        Document changesDoc = changesNode.getLink(pub.getDefaultLanguage()).getDocument();
+        MetaData meta = changesDoc.getMetaData(DublinCore.DCTERMS_NAMESPACE);
+        String lastRevisionString = meta.getFirstValue(DublinCore.TERM_HASVERSION);
+
+        long lastRevision = 0;
+        if (lastRevisionString != null) {
+            lastRevision = Long.parseLong(lastRevisionString);
+        }
+
+        SVNRepository repo = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(SVN_URL));
+        long endRevision = repo.getLatestRevision();
+
+        LogEntryHandler handler = new LogEntryHandler(this.manager, changesNode);
+        repo.log(new String[] { "" }, lastRevision, endRevision, true, true, handler);
+        handler.stop();
+
+        meta.setValue(DublinCore.TERM_HASVERSION, Long.toString(endRevision));
+    }
+
+    /**
+     * Initializes the library to work with a repository via different
+     * protocols.
+     */
+    protected void setupLibrary() {
+        DAVRepositoryFactory.setup();
+    }
+
+    /**
+     * Log entry handler which creates a new Lenya document for each month.
+     */
+    protected static class LogEntryHandler implements ISVNLogEntryHandler {
+
+        private ServiceManager manager;
+        private SiteNode parent;
+        private Month currentMonth;
+
+        protected static class Month {
+            private int year = 0;
+            private int month = 0;
+            private Document doc;
+            private SVNXMLSerializer serializer;
+            private SVNXMLLogHandler handler;
+            private OutputStream stream;
+
+            public Month(int year, int month, Document doc) {
+                this.year = year;
+                this.month = month;
+                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();
+            }
+
+            public void stop() {
+                this.handler.endDocument();
+                try {
+                    this.serializer.flush();
+                    this.stream.close();
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+
+            public void handleLogEntry(SVNLogEntry entry) throws SVNException {
+                this.handler.handleLogEntry(entry);
+            }
+
+        }
+
+        public LogEntryHandler(ServiceManager manager, SiteNode parent) {
+            this.parent = parent;
+            this.manager = manager;
+        }
+
+        public void handleLogEntry(SVNLogEntry entry) throws SVNException {
+            Date date = entry.getDate();
+            try {
+                if (this.currentMonth == null || !this.currentMonth.contains(date)) {
+                    if (this.currentMonth != null) {
+                        this.currentMonth.stop();
+                    }
+                    this.currentMonth = new Month(date.getYear(), date.getMonth(),
+                            getDocument(date));
+                    this.currentMonth.start();
+                }
+                this.currentMonth.handleLogEntry(entry);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        public void stop() {
+            if (this.currentMonth != null) {
+                this.currentMonth.stop();
+            }
+        }
+
+        protected Document getDocument(Date date) throws Exception {
+            int year = date.getYear();
+            int month = date.getMonth();
+
+            String yearString = new SimpleDateFormat("yyyy").format(date);
+            String yearPath = this.parent.getPath() + "/" + yearString;
+            SiteStructure site = this.parent.getStructure();
+            if (!site.contains(yearPath)) {
+                Document doc = getDocument(yearPath, "forrestDocument20", yearString);
+                doc.getMetaData(FolderNodeTransformer.NAMESPACE).setValue(
+                        FolderNodeTransformer.ELEM_FOLDERNODE, Boolean.toString(true));
+                // SiteNode node = createNodeAtBeginning(site, yearPath);
+                // node.addLink(site.getPublication().getDefaultLanguage(),
+                // yearString);
+            }
+
+            String monthString = new SimpleDateFormat("MM").format(date);
+            return getDocument(yearPath + "/" + monthString, "svnLog", monthString);
+        }
+
+        protected Document getDocument(String path, String resourceTypeName, String title)
+                throws SiteException, ServiceException, DocumentBuildException,
+                PublicationException {
+            Document doc;
+            SiteStructure site = this.parent.getStructure();
+            Publication pub = site.getPublication();
+            String language = pub.getDefaultLanguage();
+            if (site.contains(path)) {
+                doc = site.getNode(path).getLink(language).getDocument();
+            } else {
+                DocumentManager docMgr = null;
+                ServiceSelector selector = null;
+                ResourceType type = null;
+                try {
+                    selector = (ServiceSelector) manager.lookup(ResourceType.ROLE + "Selector");
+                    type = (ResourceType) selector.select(resourceTypeName);
+                    String sampleUri = type.getSample(type.getSampleNames()[0]).getUri();
+
+                    createNodeAtBeginning(site, path);
+
+                    docMgr = (DocumentManager) manager.lookup(DocumentManager.ROLE);
+                    doc = docMgr.add(pub.getFactory(), type, sampleUri, pub, site.getArea(), path,
+                            language, "xml", title, true);
+                } finally {
+                    if (docMgr != null) {
+                        manager.release(docMgr);
+                    }
+                    if (selector != null) {
+                        if (type != null) {
+                            selector.release(type);
+                        }
+                        manager.release(selector);
+                    }
+                }
+            }
+            return doc;
+        }
+
+        protected SiteNode createNodeAtBeginning(SiteStructure site, String path)
+                throws SiteException {
+            String parentPath = path.substring(0, path.lastIndexOf("/"));
+            SiteNode parent = site.getNode(parentPath);
+            SiteNode[] children = parent.getChildren();
+            SiteNode node;
+            if (children.length > 0) {
+                String followingSiblingPath = children[0].getPath();
+                node = site.add(path, followingSiblingPath);
+            } else {
+                node = site.add(path);
+            }
+            return node;
+        }
+
+    }
+
+}

Modified: lenya/sandbox/modules/forrest/java/test/org/apache/lenya/modules/forrest/ImportTest.java
URL: http://svn.apache.org/viewvc/lenya/sandbox/modules/forrest/java/test/org/apache/lenya/modules/forrest/ImportTest.java?rev=632904&r1=632903&r2=632904&view=diff
==============================================================================
--- lenya/sandbox/modules/forrest/java/test/org/apache/lenya/modules/forrest/ImportTest.java (original)
+++ lenya/sandbox/modules/forrest/java/test/org/apache/lenya/modules/forrest/ImportTest.java Sun Mar  2 17:05:28 2008
@@ -17,50 +17,62 @@
  */
 package org.apache.lenya.modules.forrest;
 
-import org.apache.avalon.framework.service.ServiceException;
+import java.util.Collections;
+
 import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.lenya.ac.AccessControlException;
 import org.apache.lenya.ac.impl.AbstractAccessControlTest;
-import org.apache.lenya.cms.linking.Link;
-import org.apache.lenya.cms.linking.LinkManager;
 import org.apache.lenya.cms.metadata.MetaData;
 import org.apache.lenya.cms.metadata.dublincore.DublinCore;
 import org.apache.lenya.cms.publication.Area;
 import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.publication.DocumentBuildException;
+import org.apache.lenya.cms.publication.DocumentFactory;
+import org.apache.lenya.cms.publication.DocumentUtil;
 import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationException;
 import org.apache.lenya.cms.publication.ResourceType;
+import org.apache.lenya.cms.repository.RepositoryException;
 import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.cms.site.SiteException;
 import org.apache.lenya.cms.site.SiteNode;
 import org.apache.lenya.cms.site.SiteStructure;
+import org.apache.lenya.cms.usecase.UsecaseException;
+import org.apache.lenya.cms.usecase.UsecaseInvoker;
+import org.apache.lenya.cms.workflow.WorkflowUtil;
+import org.apache.lenya.workflow.Workflowable;
 import org.apache.lenya.xml.DocumentHelper;
-import org.apache.xpath.XPathAPI;
-import org.w3c.dom.Element;
 
 /**
  * Import example content into test publication.
  */
 public class ImportTest extends AbstractAccessControlTest {
 
+    protected static final String SUBMIT_USECASE = "workflow.submit";
+    protected static final String PUBLISH_USECASE = "workflow.publish";
     protected static final String PUB_ID = "docu";
 
     /**
      * @throws Exception if an error occurs.
      */
-    public void disabled_testImport() throws Exception {
-        Session session = login("lenya");
+    public void testImport() throws Exception {
+        Session session = getFreshSession();
         Publication pub = getPublication(session, PUB_ID);
         Area area = pub.getArea("authoring");
-        
+        /*
         Importer importer = new Importer(getManager(), getLogger());
         importer.importSite(area);
         session.commit();
+*/
+        assertTrue(area.getSite().contains("/index"));
         
-        assertTrue(area.getSite().contains("/project-information"));
+        /*
+        updateChanges();
+         */
+        publish();
     }
-    
+
     public void disabled_testUpdateTitles() throws Exception {
-        Session session = login("lenya");
+        Session session = getFreshSession();
         Publication pub = getPublication(session, PUB_ID);
         Area area = pub.getArea("authoring");
         Document[] docs = area.getDocuments();
@@ -71,9 +83,9 @@
         }
         session.commit();
     }
-    
+
     public void disabled_testUpdateResourceType() throws Exception {
-        Session session = login("lenya");
+        Session session = getFreshSession();
         Publication pub = getPublication(session, PUB_ID);
         Area area = pub.getArea("authoring");
         Document[] docs = area.getDocuments();
@@ -84,14 +96,14 @@
             faqResourceType = (ResourceType) selector.select(Importer.RESOURCE_TYPE_NAME_FAQ);
             for (int i = 0; i < docs.length; i++) {
                 if (docs[i].getResourceType().getName().equals(Importer.RESOURCE_TYPE_NAME_FORREST)) {
-                    org.w3c.dom.Document xml = DocumentHelper.readDocument(docs[i].getInputStream());
+                    org.w3c.dom.Document xml = DocumentHelper
+                            .readDocument(docs[i].getInputStream());
                     if (xml.getDocumentElement().getLocalName().equals(Importer.ELEMENT_FAQS)) {
                         docs[i].setResourceType(faqResourceType);
                     }
                 }
             }
-        }
-        finally {
+        } finally {
             if (selector != null) {
                 if (faqResourceType != null) {
                     selector.release(faqResourceType);
@@ -100,70 +112,148 @@
             }
         }
         session.commit();
+        
     }
-    
+
     /**
-     * The method is temporarily disabled because some methods it relies on are not yet committed into the
-     * trunk.
+     * The method is temporarily disabled because some methods it relies on are
+     * not yet committed into the trunk.
      * 
-    public void disabled_testRemoveEmptyDocs() throws Exception {
-        Session session = login("lenya");
-        Publication pub = getPublication(session, PUB_ID);
-        Area area = pub.getArea("authoring");
-        Document[] docs = area.getDocuments();
-        DocumentManager docMgr = null;
+     * public void disabled_testRemoveEmptyDocs() throws Exception { Session
+     * session = login("lenya"); Publication pub = getPublication(session,
+     * PUB_ID); Area area = pub.getArea("authoring"); Document[] docs =
+     * area.getDocuments(); DocumentManager docMgr = null; try { docMgr =
+     * (DocumentManager) getManager().lookup(DocumentManager.ROLE); for (int i =
+     * 0; i < docs.length; i++) { System.out.println("Checking document " + (i +
+     * 1) + " of " + docs.length); SiteNode node = docs[i].getLink().getNode();
+     * if (node.getChildren().length > 0) { org.w3c.dom.Document xml =
+     * DocumentHelper.readDocument(docs[i].getInputStream()); Element p =
+     * (Element) XPathAPI.selectSingleNode(xml.getDocumentElement(), "body/p");
+     * if (p != null) { String text =
+     * DocumentHelper.getSimpleElementText(p).trim(); if (text.equals("This is a
+     * Forrest Document 2.0 sample.")) { System.out.println("Removing document " +
+     * docs[i].getUUID()); node.removeUuid(); docs[i].delete(); } } } } }
+     * finally { if (docMgr != null) { getManager().release(docMgr); } }
+     * session.commit(); }
+     */
+
+    /**
+     * The method is temporarily disabled because some methods it relies on are
+     * not yet committed into the trunk.
+     * 
+     * public void disabled_testRemoveUuids() throws Exception { Session session =
+     * login("lenya"); Publication pub = getPublication(session, PUB_ID); Area
+     * area = pub.getArea("authoring");
+     * 
+     * SiteStructure site = area.getSite(); SiteNode[] nodes = site.getNodes();
+     * for (int i = 0; i < nodes.length; i++) { System.out.println("Checking
+     * node " + i + " of " + nodes.length); String uuid = nodes[i].getUuid(); if
+     * (uuid != null && !area.contains(uuid, Importer.LANGUAGE)) {
+     * System.out.println("Removing node UUID " + uuid); nodes[i].removeUuid(); } }
+     * 
+     * session.commit(); }
+     */
+    
+    public void updateChanges() throws Exception {
+        UsecaseInvoker invoker = null;
         try {
-            docMgr = (DocumentManager) getManager().lookup(DocumentManager.ROLE);
-            for (int i = 0; i < docs.length; i++) {
-                System.out.println("Checking document " + (i + 1) + " of " + docs.length);
-                SiteNode node = docs[i].getLink().getNode();
-                if (node.getChildren().length > 0) {
-                    org.w3c.dom.Document xml = DocumentHelper.readDocument(docs[i].getInputStream());
-                    Element p = (Element) XPathAPI.selectSingleNode(xml.getDocumentElement(), "body/p");
-                    if (p != null) {
-                        String text = DocumentHelper.getSimpleElementText(p).trim();
-                        if (text.equals("This is a Forrest Document 2.0 sample.")) {
-                            System.out.println("Removing document " + docs[i].getUUID());
-                            node.removeUuid();
-                            docs[i].delete();
-                        }
-                    }
-                }
+            invoker = (UsecaseInvoker) getManager().lookup(UsecaseInvoker.ROLE);
+            String url = "/" + PUB_ID + "/authoring/index.html";
+            invoker.invoke(url, "forrest.updateChanges", Collections.EMPTY_MAP);
+        } finally {
+            if (invoker != null) {
+                getManager().release(invoker);
             }
         }
-        finally {
-            if (docMgr != null) {
-                getManager().release(docMgr);
-            }
-        }
-        session.commit();
     }
-    */
-    
-    /**
-     * The method is temporarily disabled because some methods it relies on are not yet committed into the
-     * trunk.
-     * 
-    public void disabled_testRemoveUuids() throws Exception {
-        Session session = login("lenya");
+
+    public void publish() throws Exception {
+        Session session = login("alice");
         Publication pub = getPublication(session, PUB_ID);
         Area area = pub.getArea("authoring");
-        
-        SiteStructure site = area.getSite();
-        SiteNode[] nodes = site.getNodes();
+
+        UsecaseInvoker invoker = null;
+        try {
+            invoker = (UsecaseInvoker) getManager().lookup(UsecaseInvoker.ROLE);
+
+            SiteStructure site = area.getSite();
+            SiteNode[] nodes = site.getTopLevelNodes();
+            publish(nodes, invoker);
+        } finally {
+            if (invoker != null) {
+                getManager().release(invoker);
+            }
+        }
+    }
+
+    protected void publish(SiteNode[] nodes, UsecaseInvoker invoker) throws Exception {
         for (int i = 0; i < nodes.length; i++) {
-            System.out.println("Checking node " + i + " of " + nodes.length);
-            String uuid = nodes[i].getUuid();
-            if (uuid != null && !area.contains(uuid, Importer.LANGUAGE)) {
-                System.out.println("Removing node UUID " + uuid);
-                nodes[i].removeUuid();
+            if (nodes[i].getLanguages().length == 0) {
+                System.out.println("Node " + nodes[i].getPath() + " has no document.");
+                break;
+            }
+            System.out.println("------------------------------------------------------------");
+            String lang = nodes[i].getLanguages()[0];
+            Document doc = nodes[i].getLink(lang).getDocument();
+            String url = doc.getCanonicalWebappURL();
+            
+            forceCheckIn(doc);
+            forceCheckIn(doc.getAreaVersion("live"));
+            
+            Session session = getFreshSession();
+            Document freshDoc = getFreshDocument(doc, session);
+            if (WorkflowUtil.canInvoke(getManager(), session, getLogger(), freshDoc, "edit")) {
+                System.out.println("Editing " + nodes[i].getPath());
+                WorkflowUtil.invoke(getManager(), session, getLogger(), freshDoc, "edit");
+                session.commit();
+            }
+            
+            session = getFreshSession();
+            freshDoc = getFreshDocument(doc, session);
+            if (WorkflowUtil.canInvoke(getManager(), session, getLogger(), freshDoc, "submit")) {
+                System.out.println("Submitting " + nodes[i].getPath());
+                invoker.invoke(url, SUBMIT_USECASE, Collections.EMPTY_MAP);
             }
+            
+            session = getFreshSession();
+            freshDoc = getFreshDocument(doc, session);
+            if (WorkflowUtil.canInvoke(getManager(), session, getLogger(), freshDoc, "publish")) {
+                System.out.println("Publishing " + nodes[i].getPath());
+                invoker.invoke(url, PUBLISH_USECASE, Collections.EMPTY_MAP);
+            }
+            
+            session = getFreshSession();
+            freshDoc = getFreshDocument(doc, session);
+            Workflowable newWf = WorkflowUtil.getWorkflowable(getManager(), session, getLogger(), freshDoc);
+            System.out.println("State:   " + newWf.getLatestVersion().getState());
+            System.out.println("is_live: " + newWf.getLatestVersion().getValue("is_live"));
+            assertEquals(newWf.getLatestVersion().getValue("is_live"), true);
+            
+            publish(nodes[i].getChildren(), invoker);
+        }
+    }
+
+    protected Document getFreshDocument(Document doc, Session session)
+            throws DocumentBuildException {
+        DocumentFactory newFactory = DocumentUtil.createDocumentFactory(getManager(), session);
+        Document newDoc = newFactory.get(doc.getIdentifier());
+        return newDoc;
+    }
+
+    protected Session getFreshSession() throws AccessControlException {
+        return login("lenya");
+    }
+
+    protected void forceCheckIn(Document doc) throws RepositoryException {
+        if (doc.getRepositoryNode().isCheckedOut()) {
+            doc.getRepositoryNode().forceCheckIn();
         }
-        
-        session.commit();
     }
-     */
     
+    /*
+     * protected String getUserId() { return "alice"; }
+     */
+
     public void testNothing() {
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org