From: <ap...@vh...> - 2005-12-18 20:18:16
|
Author: apevec Date: 2005-12-18 21:15:30 +0100 (Sun, 18 Dec 2005) New Revision: 1066 Added: trunk/ccm-ldn-atoz/src/com/arsdigita/london/atoz/AddAtoZ.java Log: command line class to add new AtoZ application instanace usage: ccm-run com.arsdigita.london.atoz.AddAtoZ [OPTION]... URL-FRAGMENT TITLE Added: trunk/ccm-ldn-atoz/src/com/arsdigita/london/atoz/AddAtoZ.java =================================================================== --- trunk/ccm-ldn-atoz/src/com/arsdigita/london/atoz/AddAtoZ.java 2005-12-18 19:20:50 UTC (rev 1065) +++ trunk/ccm-ldn-atoz/src/com/arsdigita/london/atoz/AddAtoZ.java 2005-12-18 20:15:30 UTC (rev 1066) @@ -0,0 +1,81 @@ +package com.arsdigita.london.atoz; + +import org.apache.commons.cli.CommandLine; +import org.apache.log4j.Logger; + +import com.arsdigita.domain.DomainObject; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.domain.DomainObjectInstantiator; +import com.arsdigita.kernel.ACSObjectInstantiator; +import com.arsdigita.kernel.Kernel; +import com.arsdigita.kernel.KernelExcursion; +import com.arsdigita.london.util.Program; +import com.arsdigita.london.util.Transaction; +import com.arsdigita.persistence.DataObject; +import com.arsdigita.web.Application; +import com.arsdigita.web.ApplicationSetup; +import com.arsdigita.web.ApplicationType; +import com.arsdigita.web.ApplicationTypeCollection; + +public class AddAtoZ extends Program { + + private static final Logger LOG = Logger.getLogger(AddAtoZ.class); + + public AddAtoZ() { + super("Add AtoZ instance", "1.0.0", "URL-FRAGMENT TITLE"); + } + + private void addAtoZ(String atozURL, String atozTitle) { + if (!Application.isInstalled(AtoZ.BASE_DATA_OBJECT_TYPE, "/"+atozURL+"/")) { + DomainObjectFactory.registerInstantiator( + AtoZ.BASE_DATA_OBJECT_TYPE, new DomainObjectInstantiator() { + public DomainObject doNewInstance(DataObject dataObject) { + return new AtoZ(dataObject); + } + }); + Application app = Application.createApplication( + AtoZ.BASE_DATA_OBJECT_TYPE, atozURL, atozTitle, null); + app.save(); + } else { + System.err.println(AtoZ.BASE_DATA_OBJECT_TYPE + + " already installed at " + atozURL); + System.exit(1); + } + } + + protected void doRun(final CommandLine cmdLine) { + new Transaction() { + public void doRun() { + new KernelExcursion() { + public void excurse() { + setEffectiveParty(Kernel.getSystemParty()); + String[] args = cmdLine.getArgs(); + if (args.length == 2) { + String atozURL = args[0]; + String atozTitle = args[1]; + if (atozURL != null && atozURL.length() != 0 + && atozTitle != null && atozTitle.length() != 0) { + addAtoZ(atozURL, atozTitle); + } else { + help(System.err); + System.exit(1); + } + } else { + help(System.err); + System.exit(1); + } + } + }.run(); + } + }.run(); + + } + + /** + * @param args + */ + public static void main(String[] args) { + new AddAtoZ().run(args); + } + +} |