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 2007/11/02 17:54:25 UTC

svn commit: r591399 - in /lenya/sandbox/modules/forrest/java: src/org/apache/lenya/modules/forrest/Importer.java test/org/apache/lenya/modules/forrest/ImportTest.java

Author: andreas
Date: Fri Nov  2 09:54:24 2007
New Revision: 591399

URL: http://svn.apache.org/viewvc?rev=591399&view=rev
Log:
Updated import and test

Modified:
    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/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=591399&r1=591398&r2=591399&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 Fri Nov  2 09:54:24 2007
@@ -172,8 +172,10 @@
             }
 
             if (xml == null) {
-                createDocument(info, info.forrestResourceType,
-                        getSampleUri(info.forrestResourceType), basePath, nodeName, linkName, title);
+                // create container site node
+                String path = concatPath(basePath, nodeName);
+                SiteNode node = info.area.getSite().add(path);
+                // TODO: add link (not supported by API yet)
             } else {
                 String localName = xml.getDocumentElement().getLocalName();
                 ResourceType type = null;

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=591399&r1=591398&r2=591399&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 Fri Nov  2 09:54:24 2007
@@ -31,8 +31,11 @@
 import org.apache.lenya.cms.publication.PublicationException;
 import org.apache.lenya.cms.publication.ResourceType;
 import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.cms.site.SiteNode;
 import org.apache.lenya.cms.site.SiteStructure;
 import org.apache.lenya.xml.DocumentHelper;
+import org.apache.xpath.XPathAPI;
+import org.w3c.dom.Element;
 
 /**
  * Import example content into test publication.
@@ -71,7 +74,7 @@
         session.commit();
     }
     
-    public void testUpdateResourceType() throws Exception {
+    public void disabled_testUpdateResourceType() throws Exception {
         Session session = login("lenya");
         Publication pub = getPublication(session, PUB_ID);
         Area area = pub.getArea("authoring");
@@ -98,6 +101,58 @@
                 getManager().release(selector);
             }
         }
+        session.commit();
+    }
+    
+    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();
+    }
+    
+    public void 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();
     }
 



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