svn commit: r590478 - /lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/Importer.java
[email protected] Tue, 30 Oct 2007 21:50:36 -0000
Newsgroups
gmane.comp.cms.lenya.cvs
Message-ID
<[email protected] >
Author: andreas
Date: Tue Oct 30 14:50:27 2007
New Revision: 590478
URL: http://svn.apache.org/viewvc?rev=590478&view=rev
Log:
Improved forrest import
Modified:
lenya/sandbox/modules/forrest/java/src/org/apache/lenya/modules/forrest/Importer.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=590478&r1=590477&r2=590478&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 Tue Oct 30 14:50:27 2007
@@ -17,10 +17,13 @@
*/
package org.apache.lenya.modules.forrest;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import org.apache.avalon.framework.container.ContainerUtil;
@@ -35,6 +38,7 @@
import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.DocumentManager;
import org.apache.lenya.cms.publication.ResourceType;
+import org.apache.lenya.cms.site.SiteNode;
import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.NamespaceHelper;
import org.apache.xpath.XPathAPI;
@@ -140,7 +144,15 @@
String sourceUri = concatPath(baseUri, href);
- if (sourceUri.endsWith(".png") || sourceUri.endsWith(".gif")) {
+ 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 (sourceUri.endsWith(".png") || sourceUri.endsWith(".gif")) {
createDocument(info, info.mediaResourceType, sourceUri, basePath, nodeName, linkName,
title);
} else {
@@ -198,7 +210,9 @@
String extension = sourceUri.substring(lastDotIndex + 1);
Document doc = info.docMgr.add(factory, type, sourceUri, info.area.getPublication(),
info.area.getName(), path, LANGUAGE, extension, title, true);
- info.links.put(linkName, doc.getUUID());
+ Link link = new Link();
+ link.setUuid(doc.getUUID());
+ info.links.put(linkName, link.getUri());
log("Created " + extension.toUpperCase() + " document (" + info.counterToString() + ") [" + path + "]");
} catch (Exception e) {
log("A problem occured:");
@@ -268,14 +282,19 @@
Document[] docs = info.area.getDocuments();
info.start();
info.number = docs.length;
+ List docsToConvert = new ArrayList();
for (int i = 0; i < docs.length; i++) {
if (docs[i].getResourceType().getName().equals(info.forrestResourceType.getName())) {
- log("Converting links (" + info.counterToString() + "): " + docs[i].getPath());
- org.w3c.dom.Document xml = DocumentHelper.readDocument(docs[i].getInputStream());
- convertLinks(info, xml.getDocumentElement());
- DocumentHelper.writeDocument(xml, docs[i].getOutputStream());
+ docsToConvert.add(docs[i]);
}
}
+ for (Iterator i = docsToConvert.iterator(); i.hasNext(); ) {
+ Document doc = (Document) i.next();
+ log("Converting links (" + info.counterToString() + "): " + doc.getPath());
+ org.w3c.dom.Document xml = DocumentHelper.readDocument(doc.getInputStream());
+ convertLinks(info, xml.getDocumentElement());
+ DocumentHelper.writeDocument(xml, doc.getOutputStream());
+ }
}
protected void convertLinks(ImportInfo info, Element element) {
@@ -287,10 +306,8 @@
log("Converting link [" + value + "]");
String name = value.substring(SITE_PROTOCOL.length());
if (info.links.containsKey(name)) {
- String uuid = (String) info.links.get(name);
- Link link = new Link();
- link.setUuid(uuid);
- attr.setNodeValue(link.getUri());
+ String linkUri = (String) info.links.get(name);
+ attr.setNodeValue(linkUri);
} else {
log("No document found for link [" + value + "]");
}