Integrate Upstream r 1864: add parameter for content section to import tool

git-svn-id: https://svn.libreccm.org/ccm/trunk@143 8810af33-2d31-482b-a856-94f89814c4df
master
pb 2009-04-19 18:42:07 +00:00
parent 40428d8a99
commit 380a76bb15
1 changed files with 31 additions and 7 deletions

View File

@ -31,6 +31,7 @@ import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.Folder; import com.arsdigita.cms.Folder;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.london.importer.DomainObjectMapper; import com.arsdigita.london.importer.DomainObjectMapper;
import com.arsdigita.london.importer.ImportParser; import com.arsdigita.london.importer.ImportParser;
import com.arsdigita.london.importer.ParserDispatcher; import com.arsdigita.london.importer.ParserDispatcher;
@ -43,7 +44,7 @@ import com.arsdigita.util.UncheckedWrapperException;
* It can be invoked by: * It can be invoked by:
* <pre> * <pre>
* ccm-run com.arsdigita.london.importer.cms.ItemImportTool \ * ccm-run com.arsdigita.london.importer.cms.ItemImportTool \
* master-import.xml /dir/with/files/to/include /dir/containing/lobs * master-import.xml /dir/with/files/to/include /dir/containing/lobs content-section-name
* </pre> * </pre>
* *
* @see com.arsdigita.london.importer * @see com.arsdigita.london.importer
@ -55,19 +56,19 @@ public class ItemImportTool extends Program {
public ItemImportTool() { public ItemImportTool() {
super("Item Import Tool", super("Item Import Tool",
"1.0.0", "1.0.0",
"INDEX-FILE ITEM-DIR ASSET-DIR"); "INDEX-FILE ITEM-DIR ASSET-DIR CONTENT-SECTION");
} }
public ItemImportTool(boolean startup) { public ItemImportTool(boolean startup) {
super("Item Import Tool", super("Item Import Tool",
"1.0.0", "1.0.0",
"INDEX-FILE ITEM-DIR ASSET-DIR", "INDEX-FILE ITEM-DIR ASSET-DIR CONTENT-SECTION",
startup); startup);
} }
protected void doRun(CommandLine cmdLine) { protected void doRun(CommandLine cmdLine) {
final String[] args = cmdLine.getArgs(); final String[] args = cmdLine.getArgs();
if (args.length != 3) { if (args.length != 4) {
help(System.err); help(System.err);
System.exit(1); System.exit(1);
} }
@ -75,12 +76,10 @@ public class ItemImportTool extends Program {
final String masterFile = args[0]; final String masterFile = args[0];
final File itemDir = new File(args[1]); final File itemDir = new File(args[1]);
final File assetDir = new File(args[2]); final File assetDir = new File(args[2]);
final ContentSection section = getContentSection(args[3]);
final DomainObjectMapper mapper = new DomainObjectMapper(); final DomainObjectMapper mapper = new DomainObjectMapper();
final ContentSection section = (ContentSection)ContentSection
.retrieveApplicationForPath("/content/");
final List items = new ArrayList(); final List items = new ArrayList();
Transaction session = new Transaction() { Transaction session = new Transaction() {
@ -145,4 +144,29 @@ public class ItemImportTool extends Program {
new ItemImportTool().run(args); new ItemImportTool().run(args);
} }
/**
* Get the content section for the entered path, adding "/" prefix and suffix if necessary.
*
* @param rawPath the raw path of the content section, e.g. "content".
*
* @return the content section
*/
private ContentSection getContentSection(String rawPath) {
final StringBuilder path = new StringBuilder();
if (!rawPath.startsWith("/")) {
path.append("/");
}
path.append(rawPath);
if (!rawPath.endsWith("/")) {
path.append("/");
}
final ContentSection section = (ContentSection)ContentSection
.retrieveApplicationForPath(path.toString());
if (section == null) {
throw new DataObjectNotFoundException("Content section not found with path " + path);
}
return section;
}
} }