Incorporate TUV r1852 (code cleanup)
git-svn-id: https://svn.libreccm.org/ccm/trunk@94 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
6127eca638
commit
ed0197e820
|
|
@ -19,20 +19,19 @@
|
||||||
package com.arsdigita.london.exporter;
|
package com.arsdigita.london.exporter;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
import org.apache.commons.cli.OptionBuilder;
|
import org.apache.commons.cli.OptionBuilder;
|
||||||
|
|
||||||
import com.arsdigita.categorization.Category;
|
import com.arsdigita.categorization.Category;
|
||||||
|
import com.arsdigita.london.util.Transaction;
|
||||||
|
import com.arsdigita.packaging.Program;
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
import com.arsdigita.web.Application;
|
import com.arsdigita.web.Application;
|
||||||
import com.arsdigita.london.util.Program;
|
|
||||||
import com.arsdigita.london.util.Transaction;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class CategoryExportTool extends Program {
|
public class CategoryExportTool extends Program {
|
||||||
|
|
||||||
|
|
@ -64,8 +63,9 @@ public class CategoryExportTool extends Program {
|
||||||
}
|
}
|
||||||
|
|
||||||
final File catDir = new File(args[2]);
|
final File catDir = new File(args[2]);
|
||||||
if (!catDir.exists()) {
|
if (!catDir.exists() && !catDir.mkdir()) {
|
||||||
catDir.mkdir();
|
System.err.println("Could not mkdir " + catDir);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String app = args[0];
|
final String app = args[0];
|
||||||
|
|
@ -89,13 +89,13 @@ public class CategoryExportTool extends Program {
|
||||||
try {
|
try {
|
||||||
catExporter.export(root,
|
catExporter.export(root,
|
||||||
key,
|
key,
|
||||||
new URL(url),
|
new URI(url),
|
||||||
title,
|
title,
|
||||||
null,
|
null,
|
||||||
version,
|
version,
|
||||||
new Date(),
|
new Date(),
|
||||||
exportItems);
|
exportItems);
|
||||||
} catch (MalformedURLException ex) {
|
} catch (URISyntaxException ex) {
|
||||||
throw new UncheckedWrapperException("Cannot parse url " + url, ex);
|
throw new UncheckedWrapperException("Cannot parse url " + url, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,32 +18,28 @@
|
||||||
|
|
||||||
package com.arsdigita.london.exporter;
|
package com.arsdigita.london.exporter;
|
||||||
|
|
||||||
import com.arsdigita.categorization.Category;
|
|
||||||
import com.arsdigita.domain.DomainCollection;
|
|
||||||
import com.arsdigita.cms.ContentItem;
|
|
||||||
import com.arsdigita.cms.ContentPage;
|
|
||||||
import com.arsdigita.xml.Element;
|
|
||||||
import com.arsdigita.xml.Document;
|
|
||||||
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import com.arsdigita.categorization.Category;
|
||||||
|
import com.arsdigita.cms.ContentItem;
|
||||||
|
import com.arsdigita.cms.ContentPage;
|
||||||
|
import com.arsdigita.domain.DomainCollection;
|
||||||
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
|
import com.arsdigita.xml.Document;
|
||||||
|
import com.arsdigita.xml.Element;
|
||||||
|
|
||||||
public class CategoryExporter {
|
public class CategoryExporter {
|
||||||
|
|
||||||
private static final Logger s_log = Logger.getLogger(CategoryExporter.class);
|
private static final Logger s_log = Logger.getLogger(CategoryExporter.class);
|
||||||
|
|
@ -62,7 +58,7 @@ public class CategoryExporter {
|
||||||
|
|
||||||
public void export(Category root,
|
public void export(Category root,
|
||||||
String key,
|
String key,
|
||||||
URL url,
|
URI url,
|
||||||
String title,
|
String title,
|
||||||
String description,
|
String description,
|
||||||
String version,
|
String version,
|
||||||
|
|
@ -80,7 +76,7 @@ public class CategoryExporter {
|
||||||
|
|
||||||
public void export(Category root,
|
public void export(Category root,
|
||||||
String key,
|
String key,
|
||||||
URL url,
|
URI url,
|
||||||
String title,
|
String title,
|
||||||
String description,
|
String description,
|
||||||
String version,
|
String version,
|
||||||
|
|
@ -96,7 +92,7 @@ public class CategoryExporter {
|
||||||
|
|
||||||
private void exportDomain(Category root,
|
private void exportDomain(Category root,
|
||||||
String key,
|
String key,
|
||||||
URL url,
|
URI url,
|
||||||
String title,
|
String title,
|
||||||
String description,
|
String description,
|
||||||
String version,
|
String version,
|
||||||
|
|
@ -125,7 +121,7 @@ public class CategoryExporter {
|
||||||
if (!cat.equals(root)) {
|
if (!cat.equals(root)) {
|
||||||
Element term = domain.newChildElement("terms:term",
|
Element term = domain.newChildElement("terms:term",
|
||||||
TERMS_XML_NS);
|
TERMS_XML_NS);
|
||||||
term.addAttribute("id", new Integer(id).toString());
|
term.addAttribute("id", Integer.valueOf(id).toString());
|
||||||
term.addAttribute("name", cat.getName());
|
term.addAttribute("name", cat.getName());
|
||||||
term.addAttribute("inAtoZ", "false");
|
term.addAttribute("inAtoZ", "false");
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +133,7 @@ public class CategoryExporter {
|
||||||
|
|
||||||
private void exportHierarchy(Category root,
|
private void exportHierarchy(Category root,
|
||||||
String key,
|
String key,
|
||||||
URL url) {
|
URI url) {
|
||||||
Map idMap = getIDMap(url);
|
Map idMap = getIDMap(url);
|
||||||
|
|
||||||
Element hier = new Element("terms:hierarchy",
|
Element hier = new Element("terms:hierarchy",
|
||||||
|
|
@ -210,7 +206,7 @@ public class CategoryExporter {
|
||||||
|
|
||||||
private void exportItems(Category root,
|
private void exportItems(Category root,
|
||||||
String key,
|
String key,
|
||||||
URL url) {
|
URI url) {
|
||||||
Map idMap = getIDMap(url);
|
Map idMap = getIDMap(url);
|
||||||
|
|
||||||
Element items = new Element("terms:itemMapping",
|
Element items = new Element("terms:itemMapping",
|
||||||
|
|
@ -246,7 +242,7 @@ public class CategoryExporter {
|
||||||
save(items, key + "-items.xml");
|
save(items, key + "-items.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map getIDMap(URL url) {
|
private Map getIDMap(URI url) {
|
||||||
if (!m_idMaps.containsKey(url)) {
|
if (!m_idMaps.containsKey(url)) {
|
||||||
m_idMaps.put(url, new HashMap());
|
m_idMaps.put(url, new HashMap());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,10 @@ public class ContentExporter {
|
||||||
String systemID) {
|
String systemID) {
|
||||||
Session session = SessionManager.getSession();
|
Session session = SessionManager.getSession();
|
||||||
|
|
||||||
|
if (!m_itemDir.exists() && !m_itemDir.mkdirs()) {
|
||||||
|
throw new UncheckedWrapperException(new IOException("mkdirs " + m_itemDir + " failed"));
|
||||||
|
}
|
||||||
|
|
||||||
DataCollection folders = session.retrieve(Folder.BASE_DATA_OBJECT_TYPE);
|
DataCollection folders = session.retrieve(Folder.BASE_DATA_OBJECT_TYPE);
|
||||||
Filter f = folders.addInSubqueryFilter(ACSObject.ID,
|
Filter f = folders.addInSubqueryFilter(ACSObject.ID,
|
||||||
"com.arsdigita.london.exporter.itemIDsInSection");
|
"com.arsdigita.london.exporter.itemIDsInSection");
|
||||||
|
|
@ -104,7 +108,10 @@ public class ContentExporter {
|
||||||
String path = (parent == null ? "" : m_paths.get(parent) + "/" + folder.getName());
|
String path = (parent == null ? "" : m_paths.get(parent) + "/" + folder.getName());
|
||||||
m_paths.put(folder, path);
|
m_paths.put(folder, path);
|
||||||
File dir = new File(m_itemDir, path);
|
File dir = new File(m_itemDir, path);
|
||||||
dir.mkdir();
|
|
||||||
|
if (!dir.exists() && !dir.mkdir()) {
|
||||||
|
throw new UncheckedWrapperException(new IOException("mkdir " + dir + " failed"));
|
||||||
|
}
|
||||||
|
|
||||||
if (pel != null) {
|
if (pel != null) {
|
||||||
s_log.debug("Adding " + el + " to " + pel);
|
s_log.debug("Adding " + el + " to " + pel);
|
||||||
|
|
@ -172,7 +179,7 @@ public class ContentExporter {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File dst = new File(m_itemDir, "index.xml");
|
File dst = new File(m_itemDir, "index.xml");
|
||||||
FileOutputStream os = new FileOutputStream(dst);
|
FileOutputStream os = new FileOutputStream(dst, false);
|
||||||
|
|
||||||
os.write(doc.toString(true).getBytes("UTF-8"));
|
os.write(doc.toString(true).getBytes("UTF-8"));
|
||||||
os.flush();
|
os.flush();
|
||||||
|
|
@ -191,7 +198,7 @@ public class ContentExporter {
|
||||||
|
|
||||||
OID oid = (OID)oids.next();
|
OID oid = (OID)oids.next();
|
||||||
|
|
||||||
if (s_log.isDebugEnabled()) {
|
if (s_log.isInfoEnabled()) {
|
||||||
s_log.info("Exporting item " + oid);
|
s_log.info("Exporting item " + oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -262,7 +269,7 @@ public class ContentExporter {
|
||||||
Folder parent = (Folder)m_folders.get(base);
|
Folder parent = (Folder)m_folders.get(base);
|
||||||
|
|
||||||
if (s_log.isDebugEnabled()) {
|
if (s_log.isDebugEnabled()) {
|
||||||
s_log.warn("Item " + item.getOID() + " with " + ancestors + " parent " + base + " obj " + parent);
|
s_log.debug("Item " + item.getOID() + " with " + ancestors + " parent " + base + " obj " + parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent;
|
return parent;
|
||||||
|
|
|
||||||
|
|
@ -18,22 +18,17 @@
|
||||||
|
|
||||||
package com.arsdigita.london.exporter;
|
package com.arsdigita.london.exporter;
|
||||||
|
|
||||||
import com.arsdigita.runtime.AbstractConfig;
|
|
||||||
|
|
||||||
import com.arsdigita.util.parameter.Parameter;
|
|
||||||
import com.arsdigita.util.parameter.URLParameter;
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import com.arsdigita.runtime.AbstractConfig;
|
||||||
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
|
import com.arsdigita.util.parameter.Parameter;
|
||||||
|
import com.arsdigita.util.parameter.URLParameter;
|
||||||
|
|
||||||
public class ExporterConfig extends AbstractConfig {
|
public class ExporterConfig extends AbstractConfig {
|
||||||
private static final Logger s_log =
|
|
||||||
Logger.getLogger(ExporterConfig.class);
|
|
||||||
|
|
||||||
private Parameter m_adapters;
|
private Parameter m_adapters;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,17 +19,14 @@
|
||||||
package com.arsdigita.london.exporter;
|
package com.arsdigita.london.exporter;
|
||||||
|
|
||||||
import com.arsdigita.db.DbHelper;
|
import com.arsdigita.db.DbHelper;
|
||||||
|
import com.arsdigita.domain.xml.TraversalHandler;
|
||||||
import com.arsdigita.persistence.pdl.ManifestSource;
|
import com.arsdigita.persistence.pdl.ManifestSource;
|
||||||
import com.arsdigita.persistence.pdl.NameFilter;
|
import com.arsdigita.persistence.pdl.NameFilter;
|
||||||
|
|
||||||
import com.arsdigita.runtime.RuntimeConfig;
|
|
||||||
import com.arsdigita.runtime.PDLInitializer;
|
|
||||||
import com.arsdigita.runtime.CompoundInitializer;
|
import com.arsdigita.runtime.CompoundInitializer;
|
||||||
|
|
||||||
import com.arsdigita.runtime.LegacyInitEvent;
|
import com.arsdigita.runtime.LegacyInitEvent;
|
||||||
|
import com.arsdigita.runtime.PDLInitializer;
|
||||||
|
import com.arsdigita.runtime.RuntimeConfig;
|
||||||
import com.arsdigita.xml.XML;
|
import com.arsdigita.xml.XML;
|
||||||
import com.arsdigita.domain.xml.TraversalHandler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the Exporter app
|
* Initializes the Exporter app
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,15 @@ package com.arsdigita.london.exporter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.apache.commons.cli.CommandLine;
|
||||||
|
|
||||||
import com.arsdigita.cms.ContentItem;
|
import com.arsdigita.cms.ContentItem;
|
||||||
import com.arsdigita.cms.ContentSection;
|
import com.arsdigita.cms.ContentSection;
|
||||||
|
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||||
|
import com.arsdigita.london.util.Transaction;
|
||||||
|
import com.arsdigita.packaging.Program;
|
||||||
import com.arsdigita.web.Application;
|
import com.arsdigita.web.Application;
|
||||||
import com.arsdigita.web.Web;
|
import com.arsdigita.web.Web;
|
||||||
import com.arsdigita.london.util.Program;
|
|
||||||
import com.arsdigita.london.util.Transaction;
|
|
||||||
|
|
||||||
import org.apache.commons.cli.CommandLine;
|
|
||||||
|
|
||||||
|
|
||||||
public class ItemExportTool extends Program {
|
public class ItemExportTool extends Program {
|
||||||
|
|
@ -46,21 +47,38 @@ public class ItemExportTool extends Program {
|
||||||
}
|
}
|
||||||
|
|
||||||
File itemDir = new File(args[0]);
|
File itemDir = new File(args[0]);
|
||||||
if (!itemDir.exists()) {
|
if (!itemDir.exists() && !itemDir.mkdir()) {
|
||||||
itemDir.mkdir();
|
System.err.println("mkdir " + itemDir + "failed");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
File assetDir = new File(args[1]);
|
File assetDir = new File(args[1]);
|
||||||
if (!assetDir.exists()) {
|
if (!assetDir.exists() && !assetDir.mkdir()) {
|
||||||
assetDir.mkdir();
|
System.err.println("mkdir " + assetDir + "failed");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ContentExporter exporter = new ContentExporter(itemDir,
|
final ContentExporter exporter = new ContentExporter(itemDir,
|
||||||
assetDir);
|
assetDir);
|
||||||
|
|
||||||
|
// Construct the path to the content section, assuming the user
|
||||||
|
// may or may not have enter the preceding and trailing slashes
|
||||||
|
final StringBuilder path = new StringBuilder();
|
||||||
|
if (!args[2].startsWith("/")) {
|
||||||
|
path.append("/");
|
||||||
|
}
|
||||||
|
path.append(args[2]);
|
||||||
|
if (!args[2].endsWith("/")) {
|
||||||
|
path.append("/");
|
||||||
|
}
|
||||||
|
|
||||||
Transaction txn = new Transaction() {
|
Transaction txn = new Transaction() {
|
||||||
public void doRun() {
|
public void doRun() {
|
||||||
ContentSection section = (ContentSection)Application
|
ContentSection section = (ContentSection)Application
|
||||||
.retrieveApplicationForPath(args[2]);
|
.retrieveApplicationForPath(path.toString());
|
||||||
|
|
||||||
|
if (section == null) {
|
||||||
|
throw new DataObjectNotFoundException("No content section has a path of '" + path + "'");
|
||||||
|
}
|
||||||
|
|
||||||
exporter.exportManifest(section,
|
exporter.exportManifest(section,
|
||||||
ContentItem.DRAFT,
|
ContentItem.DRAFT,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue