mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
V1.3 to HEAD (3005, 3014, 3021, 3027, 3045, 3064, 3105, 3106)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3162 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -60,7 +60,7 @@ public final class Export extends Tool
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.tools.Tool#getToolName()
|
||||
*/
|
||||
@Override
|
||||
protected @Override
|
||||
String getToolName()
|
||||
{
|
||||
return "Alfresco Repository Exporter";
|
||||
@@ -72,7 +72,7 @@ public final class Export extends Tool
|
||||
* @param args the arguments
|
||||
* @return the export context
|
||||
*/
|
||||
@Override
|
||||
protected @Override
|
||||
/*package*/ ToolContext processArgs(String[] args)
|
||||
{
|
||||
context = new ExportContext();
|
||||
@@ -91,7 +91,7 @@ public final class Export extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <store> for the parameter -store must be specified");
|
||||
throw new ToolArgumentException("The value <store> for the parameter -store must be specified");
|
||||
}
|
||||
context.storeRef = new StoreRef(args[i]);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public final class Export extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <path> for the parameter -path must be specified");
|
||||
throw new ToolArgumentException("The value <path> for the parameter -path must be specified");
|
||||
}
|
||||
context.path = args[i];
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public final class Export extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <dir> for the parameter -dir must be specified");
|
||||
throw new ToolArgumentException("The value <dir> for the parameter -dir must be specified");
|
||||
}
|
||||
context.destDir = args[i];
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public final class Export extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <packagedir> for the parameter -packagedir must be specified");
|
||||
throw new ToolArgumentException("The value <packagedir> for the parameter -packagedir must be specified");
|
||||
}
|
||||
context.packageDir = args[i];
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public final class Export extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <user> for the option -user must be specified");
|
||||
throw new ToolArgumentException("The value <user> for the option -user must be specified");
|
||||
}
|
||||
context.setUsername(args[i]);
|
||||
}
|
||||
@@ -136,7 +136,7 @@ public final class Export extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <password> for the option -pwd must be specified");
|
||||
throw new ToolArgumentException("The value <password> for the option -pwd must be specified");
|
||||
}
|
||||
context.setPassword(args[i]);
|
||||
}
|
||||
@@ -170,7 +170,7 @@ public final class Export extends Tool
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ToolException("Unknown option " + args[i]);
|
||||
throw new ToolArgumentException("Unknown option " + args[i]);
|
||||
}
|
||||
|
||||
// next argument
|
||||
@@ -183,34 +183,35 @@ public final class Export extends Tool
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.tools.Tool#displayHelp()
|
||||
*/
|
||||
@Override
|
||||
protected @Override
|
||||
/*package*/ void displayHelp()
|
||||
{
|
||||
System.out.println("Usage: export -user username -s[tore] store [options] packagename");
|
||||
System.out.println("");
|
||||
System.out.println("username: username for login");
|
||||
System.out.println("store: the store to extract from in the form of scheme://store_name");
|
||||
System.out.println("packagename: the filename to export to (with or without extension)");
|
||||
System.out.println("");
|
||||
System.out.println("Options:");
|
||||
System.out.println(" -h[elp] display this help");
|
||||
System.out.println(" -p[ath] the path within the store to extract from (default: /)");
|
||||
System.out.println(" -d[ir] the destination directory to export to (default: current directory)");
|
||||
System.out.println(" -pwd password for login");
|
||||
System.out.println(" -packagedir the directory to place extracted content (default: dir/<packagename>)");
|
||||
System.out.println(" -root extract the item located at export path");
|
||||
System.out.println(" -nochildren do not extract children of the item at export path");
|
||||
System.out.println(" -overwrite force overwrite of existing export package if it already exists");
|
||||
System.out.println(" -quiet do not display any messages during export");
|
||||
System.out.println(" -verbose report export progress");
|
||||
System.out.println(" -zip export in zip format");
|
||||
logError("Usage: export -user username -s[tore] store [options] packagename");
|
||||
logError("");
|
||||
logError("username: username for login");
|
||||
logError("store: the store to extract from in the form of scheme://store_name");
|
||||
logError("packagename: the filename to export to (with or without extension)");
|
||||
logError("");
|
||||
logError("Options:");
|
||||
logError(" -h[elp] display this help");
|
||||
logError(" -p[ath] the path within the store to extract from (default: /)");
|
||||
logError(" -d[ir] the destination directory to export to (default: current directory)");
|
||||
logError(" -pwd password for login");
|
||||
logError(" -packagedir the directory to place extracted content (default: dir/<packagename>)");
|
||||
logError(" -root extract the item located at export path");
|
||||
logError(" -nochildren do not extract children of the item at export path");
|
||||
logError(" -overwrite force overwrite of existing export package if it already exists");
|
||||
logError(" -quiet do not display any messages during export");
|
||||
logError(" -verbose report export progress");
|
||||
logError(" -zip export in zip format");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.tools.Tool#execute()
|
||||
*/
|
||||
@Override
|
||||
void execute() throws ToolException
|
||||
protected @Override
|
||||
/*package*/ int execute()
|
||||
throws ToolException
|
||||
{
|
||||
ExporterService exporter = getServiceRegistry().getExporterService();
|
||||
MimetypeService mimetypeService = getServiceRegistry().getMimetypeService();
|
||||
@@ -238,9 +239,10 @@ public final class Export extends Tool
|
||||
}
|
||||
catch(ExporterException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new ToolException("Failed to export", e);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,7 +272,7 @@ public final class Export extends Tool
|
||||
*/
|
||||
protected void log(String message)
|
||||
{
|
||||
Export.this.log(message);
|
||||
Export.this.logInfo(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +303,7 @@ public final class Export extends Tool
|
||||
*/
|
||||
protected void log(String message)
|
||||
{
|
||||
Export.this.log(message);
|
||||
Export.this.logInfo(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,18 +343,18 @@ public final class Export extends Tool
|
||||
|
||||
if (storeRef == null)
|
||||
{
|
||||
throw new ToolException("Store to export from has not been specified.");
|
||||
throw new ToolArgumentException("Store to export from has not been specified.");
|
||||
}
|
||||
if (packageName == null)
|
||||
{
|
||||
throw new ToolException("Package name has not been specified.");
|
||||
throw new ToolArgumentException("Package name has not been specified.");
|
||||
}
|
||||
if (destDir != null)
|
||||
{
|
||||
File fileDestDir = new File(destDir);
|
||||
if (fileDestDir.exists() == false)
|
||||
{
|
||||
throw new ToolException("Destination directory " + fileDestDir.getAbsolutePath() + " does not exist.");
|
||||
throw new ToolArgumentException("Destination directory " + fileDestDir.getAbsolutePath() + " does not exist.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -612,7 +614,7 @@ public final class Export extends Tool
|
||||
*/
|
||||
public void warning(String warning)
|
||||
{
|
||||
log("Warning: " + warning);
|
||||
logInfo("Warning: " + warning);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@@ -61,8 +61,9 @@ public class Import extends Tool
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.tools.Tool#processArgs(java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
protected @Override
|
||||
/*package*/ ToolContext processArgs(String[] args)
|
||||
throws ToolArgumentException
|
||||
{
|
||||
context = new ImportContext();
|
||||
context.setLogin(true);
|
||||
@@ -80,7 +81,7 @@ public class Import extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <store> for the option -store must be specified");
|
||||
throw new ToolArgumentException("The value <store> for the option -store must be specified");
|
||||
}
|
||||
context.storeRef = new StoreRef(args[i]);
|
||||
}
|
||||
@@ -89,7 +90,7 @@ public class Import extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <path> for the option -path must be specified");
|
||||
throw new ToolArgumentException("The value <path> for the option -path must be specified");
|
||||
}
|
||||
context.path = args[i];
|
||||
}
|
||||
@@ -98,7 +99,7 @@ public class Import extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <dir> for the option -dir must be specified");
|
||||
throw new ToolArgumentException("The value <dir> for the option -dir must be specified");
|
||||
}
|
||||
context.sourceDir = args[i];
|
||||
}
|
||||
@@ -107,7 +108,7 @@ public class Import extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <user> for the option -user must be specified");
|
||||
throw new ToolArgumentException("The value <user> for the option -user must be specified");
|
||||
}
|
||||
context.setUsername(args[i]);
|
||||
}
|
||||
@@ -116,7 +117,7 @@ public class Import extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <password> for the option -pwd must be specified");
|
||||
throw new ToolArgumentException("The value <password> for the option -pwd must be specified");
|
||||
}
|
||||
context.setPassword(args[i]);
|
||||
}
|
||||
@@ -125,7 +126,7 @@ public class Import extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <encoding> for the option -encoding must be specified");
|
||||
throw new ToolArgumentException("The value <encoding> for the option -encoding must be specified");
|
||||
}
|
||||
context.encoding = args[i];
|
||||
}
|
||||
@@ -138,7 +139,7 @@ public class Import extends Tool
|
||||
}
|
||||
catch(IllegalArgumentException e)
|
||||
{
|
||||
throw new ToolException("The value " + args[i] + " is an invalid uuidBinding");
|
||||
throw new ToolArgumentException("The value " + args[i] + " is an invalid uuidBinding");
|
||||
}
|
||||
}
|
||||
else if (args[i].equals("-quiet"))
|
||||
@@ -155,7 +156,7 @@ public class Import extends Tool
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ToolException("Unknown option " + args[i]);
|
||||
throw new ToolArgumentException("Unknown option " + args[i]);
|
||||
}
|
||||
|
||||
// next argument
|
||||
@@ -168,30 +169,30 @@ public class Import extends Tool
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.tools.Tool#displayHelp()
|
||||
*/
|
||||
@Override
|
||||
protected @Override
|
||||
/*package*/ void displayHelp()
|
||||
{
|
||||
System.out.println("Usage: import -user username -s[tore] store [options] packagename");
|
||||
System.out.println("");
|
||||
System.out.println("username: username for login");
|
||||
System.out.println("store: the store to import into the form of scheme://store_name");
|
||||
System.out.println("packagename: the filename to import from (with or without extension)");
|
||||
System.out.println("");
|
||||
System.out.println("Options:");
|
||||
System.out.println(" -h[elp] display this help");
|
||||
System.out.println(" -p[ath] the path within the store to extract into (default: /)");
|
||||
System.out.println(" -d[ir] the source directory to import from (default: current directory)");
|
||||
System.out.println(" -pwd password for login");
|
||||
System.out.println(" -encoding package file encoding (default: " + Charset.defaultCharset() + ")");
|
||||
System.out.println(" -uuidBinding CREATE_NEW, REMOVE_EXISTING, REPLACE_EXISTING, UPDATE_EXISTING, THROW_ON_COLLISION (default: CREATE_NEW)");
|
||||
System.out.println(" -quiet do not display any messages during import");
|
||||
System.out.println(" -verbose report import progress");
|
||||
logError("Usage: import -user username -s[tore] store [options] packagename");
|
||||
logError("");
|
||||
logError("username: username for login");
|
||||
logError("store: the store to import into the form of scheme://store_name");
|
||||
logError("packagename: the filename to import from (with or without extension)");
|
||||
logError("");
|
||||
logError("Options:");
|
||||
logError(" -h[elp] display this help");
|
||||
logError(" -p[ath] the path within the store to extract into (default: /)");
|
||||
logError(" -d[ir] the source directory to import from (default: current directory)");
|
||||
logError(" -pwd password for login");
|
||||
logError(" -encoding package file encoding (default: " + Charset.defaultCharset() + ")");
|
||||
logError(" -uuidBinding CREATE_NEW, REMOVE_EXISTING, REPLACE_EXISTING, UPDATE_EXISTING, THROW_ON_COLLISION (default: CREATE_NEW)");
|
||||
logError(" -quiet do not display any messages during import");
|
||||
logError(" -verbose report import progress");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.tools.Tool#getToolName()
|
||||
*/
|
||||
@Override
|
||||
protected @Override
|
||||
/*package*/ String getToolName()
|
||||
{
|
||||
return "Alfresco Repository Importer";
|
||||
@@ -200,8 +201,8 @@ public class Import extends Tool
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.tools.Tool#execute()
|
||||
*/
|
||||
@Override
|
||||
/*package*/ void execute() throws ToolException
|
||||
protected @Override
|
||||
/*package*/ int execute() throws ToolException
|
||||
{
|
||||
ImporterService importer = getServiceRegistry().getImporterService();
|
||||
|
||||
@@ -225,6 +226,8 @@ public class Import extends Tool
|
||||
{
|
||||
throw new ToolException("Failed to import package due to " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,7 +256,7 @@ public class Import extends Tool
|
||||
*/
|
||||
protected void log(String message)
|
||||
{
|
||||
Import.this.log(message);
|
||||
Import.this.logInfo(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +286,7 @@ public class Import extends Tool
|
||||
*/
|
||||
protected void log(String message)
|
||||
{
|
||||
Import.this.log(message);
|
||||
Import.this.logInfo(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,18 +395,18 @@ public class Import extends Tool
|
||||
|
||||
if (storeRef == null)
|
||||
{
|
||||
throw new ToolException("Store to import into has not been specified.");
|
||||
throw new ToolArgumentException("Store to import into has not been specified.");
|
||||
}
|
||||
if (packageName == null)
|
||||
{
|
||||
throw new ToolException("Package name has not been specified.");
|
||||
throw new ToolArgumentException("Package name has not been specified.");
|
||||
}
|
||||
if (sourceDir != null)
|
||||
{
|
||||
File fileSourceDir = getSourceDir();
|
||||
if (fileSourceDir.exists() == false)
|
||||
{
|
||||
throw new ToolException("Source directory " + fileSourceDir.getAbsolutePath() + " does not exist.");
|
||||
throw new ToolArgumentException("Source directory " + fileSourceDir.getAbsolutePath() + " does not exist.");
|
||||
}
|
||||
}
|
||||
if (packageName.endsWith(".acp"))
|
||||
@@ -411,7 +414,7 @@ public class Import extends Tool
|
||||
File packageFile = new File(getSourceDir(), packageName);
|
||||
if (!packageFile.exists())
|
||||
{
|
||||
throw new ToolException("Package zip file " + packageFile.getAbsolutePath() + " does not exist.");
|
||||
throw new ToolArgumentException("Package zip file " + packageFile.getAbsolutePath() + " does not exist.");
|
||||
}
|
||||
zipFile = true;
|
||||
}
|
||||
@@ -420,7 +423,7 @@ public class Import extends Tool
|
||||
File packageFile = new File(getSourceDir(), getDataFile().getPath());
|
||||
if (!packageFile.exists())
|
||||
{
|
||||
throw new ToolException("Package file " + packageFile.getAbsolutePath() + " does not exist.");
|
||||
throw new ToolArgumentException("Package file " + packageFile.getAbsolutePath() + " does not exist.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,13 +26,13 @@ import java.io.IOException;
|
||||
*/
|
||||
public class Repository extends Tool
|
||||
{
|
||||
@Override
|
||||
protected @Override
|
||||
String getToolName()
|
||||
{
|
||||
return "Repository";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Override
|
||||
ToolContext processArgs(String[] args) throws ToolException
|
||||
{
|
||||
ToolContext context = new ToolContext();
|
||||
@@ -51,7 +51,7 @@ public class Repository extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <user> for the option -user must be specified");
|
||||
throw new ToolArgumentException("The value <user> for the option -user must be specified");
|
||||
}
|
||||
context.setUsername(args[i]);
|
||||
}
|
||||
@@ -60,13 +60,13 @@ public class Repository extends Tool
|
||||
i++;
|
||||
if (i == args.length || args[i].length() == 0)
|
||||
{
|
||||
throw new ToolException("The value <password> for the option -pwd must be specified");
|
||||
throw new ToolArgumentException("The value <password> for the option -pwd must be specified");
|
||||
}
|
||||
context.setPassword(args[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ToolException("Unknown option " + args[i] + ". Use -help for options.");
|
||||
throw new ToolArgumentException("Unknown option " + args[i] + ". Use -help for options.");
|
||||
}
|
||||
|
||||
// next argument
|
||||
@@ -76,10 +76,10 @@ public class Repository extends Tool
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Override
|
||||
void displayHelp()
|
||||
{
|
||||
System.out.println(
|
||||
logError(
|
||||
"usage: repository [OPTIONS] \n" +
|
||||
"\n" +
|
||||
"Initialize the Alfresco application context, initiating any \n" +
|
||||
@@ -92,7 +92,7 @@ public class Repository extends Tool
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized void execute() throws ToolException
|
||||
protected synchronized int execute() throws ToolException
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -107,6 +107,8 @@ public class Repository extends Tool
|
||||
{
|
||||
// just ignore
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -16,6 +16,9 @@
|
||||
*/
|
||||
package org.alfresco.tools;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
@@ -44,8 +47,8 @@ public abstract class Tool
|
||||
* @return the tool context
|
||||
* @throws ToolException
|
||||
*/
|
||||
/*package*/ ToolContext processArgs(String[] args)
|
||||
throws ToolException
|
||||
protected ToolContext processArgs(String[] args)
|
||||
throws ToolArgumentException
|
||||
{
|
||||
return new ToolContext();
|
||||
}
|
||||
@@ -53,9 +56,9 @@ public abstract class Tool
|
||||
/**
|
||||
* Display Tool Help
|
||||
*/
|
||||
/*package*/ void displayHelp()
|
||||
protected void displayHelp()
|
||||
{
|
||||
System.out.println("Sorry. Help is not available.");
|
||||
logError("Sorry. Help is not available.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +66,7 @@ public abstract class Tool
|
||||
*
|
||||
* @throws ToolException
|
||||
*/
|
||||
/*package*/ abstract void execute()
|
||||
protected abstract int execute()
|
||||
throws ToolException;
|
||||
|
||||
/**
|
||||
@@ -71,34 +74,14 @@ public abstract class Tool
|
||||
*
|
||||
* @return the tool name
|
||||
*/
|
||||
/*package*/ abstract String getToolName();
|
||||
protected abstract String getToolName();
|
||||
|
||||
/**
|
||||
* Get the Application Context
|
||||
*
|
||||
* @return the application context
|
||||
*/
|
||||
/*package*/ final ApplicationContext getApplicationContext()
|
||||
{
|
||||
return appContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Repository Service Registry
|
||||
*
|
||||
* @return the service registry
|
||||
*/
|
||||
/*package*/ final ServiceRegistry getServiceRegistry()
|
||||
{
|
||||
return serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log message
|
||||
*
|
||||
* @param msg message to log
|
||||
*/
|
||||
/*package*/ final void log(String msg)
|
||||
protected void logInfo(String msg)
|
||||
{
|
||||
if (toolContext.isQuiet() == false)
|
||||
{
|
||||
@@ -111,65 +94,124 @@ public abstract class Tool
|
||||
*
|
||||
* @param msg message to log
|
||||
*/
|
||||
/*package*/ final void logVerbose(String msg)
|
||||
protected void logVerbose(String msg)
|
||||
{
|
||||
if (toolContext.isVerbose())
|
||||
{
|
||||
log(msg);
|
||||
logInfo(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log Error message
|
||||
*
|
||||
* @param msg message to log
|
||||
*/
|
||||
protected void logError(String msg)
|
||||
{
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Error Message
|
||||
*
|
||||
* @param e exception
|
||||
*/
|
||||
protected int handleError(Throwable e)
|
||||
{
|
||||
if (e instanceof ToolArgumentException)
|
||||
{
|
||||
logError(e.getMessage());
|
||||
logError("");
|
||||
displayHelp();
|
||||
}
|
||||
else if (e instanceof ToolException)
|
||||
{
|
||||
logError(e.getMessage());
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("The following error has occurred:");
|
||||
logError(e.getMessage());
|
||||
if (toolContext != null && toolContext.isVerbose())
|
||||
{
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
PrintWriter printWriter = new PrintWriter(stringWriter);
|
||||
e.printStackTrace(printWriter);
|
||||
logError(stringWriter.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// return generic error code
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit Tool
|
||||
*
|
||||
* @param status status code
|
||||
*/
|
||||
protected void exit(int status)
|
||||
{
|
||||
System.exit(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Application Context
|
||||
*
|
||||
* @return the application context
|
||||
*/
|
||||
protected final ApplicationContext getApplicationContext()
|
||||
{
|
||||
return appContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Repository Service Registry
|
||||
*
|
||||
* @return the service registry
|
||||
*/
|
||||
protected final ServiceRegistry getServiceRegistry()
|
||||
{
|
||||
return serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tool entry point
|
||||
*
|
||||
* @param args the tool arguments
|
||||
*/
|
||||
/*package*/ final void start(String[] args)
|
||||
public final void start(String[] args)
|
||||
{
|
||||
int status = -1;
|
||||
|
||||
try
|
||||
{
|
||||
// Process tool arguments
|
||||
toolContext = processArgs(args);
|
||||
toolContext.validate();
|
||||
|
||||
try
|
||||
if (toolContext.isHelp())
|
||||
{
|
||||
if (toolContext.isHelp())
|
||||
{
|
||||
// Display help, if requested
|
||||
displayHelp();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Perform Tool behaviour
|
||||
log(getToolName());
|
||||
initialiseRepository();
|
||||
login();
|
||||
execute();
|
||||
log(getToolName() + " successfully completed.");
|
||||
}
|
||||
System.exit(0);
|
||||
// Display help, if requested
|
||||
displayHelp();
|
||||
}
|
||||
catch (ToolException e)
|
||||
else
|
||||
{
|
||||
displayError(e);
|
||||
System.exit(-1);
|
||||
// Perform Tool behaviour
|
||||
logInfo(getToolName());
|
||||
initialiseRepository();
|
||||
login();
|
||||
status = execute();
|
||||
logInfo(getToolName() + " successfully completed.");
|
||||
}
|
||||
}
|
||||
catch(ToolException e)
|
||||
{
|
||||
System.out.println(e.getMessage());
|
||||
System.out.println();
|
||||
displayHelp();
|
||||
System.exit(-1);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
System.out.println("The following error has occurred:");
|
||||
System.out.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
System.exit(-1);
|
||||
status = handleError(e);
|
||||
}
|
||||
|
||||
exit(status);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,7 +222,7 @@ public abstract class Tool
|
||||
// TODO: Replace with call to ServiceRegistry
|
||||
AuthenticationService auth = (AuthenticationService) serviceRegistry.getAuthenticationService();
|
||||
auth.authenticate(toolContext.getUsername(), toolContext.getPassword().toCharArray());
|
||||
log("Connected as " + toolContext.getUsername());
|
||||
logInfo("Connected as " + toolContext.getUsername());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,18 +234,4 @@ public abstract class Tool
|
||||
serviceRegistry = (ServiceRegistry) appContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display Error Message
|
||||
*
|
||||
* @param e exception
|
||||
*/
|
||||
private void displayError(Throwable e)
|
||||
{
|
||||
System.out.println(e.getMessage());
|
||||
if (toolContext != null && toolContext.isVerbose())
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
38
source/java/org/alfresco/tools/ToolArgumentException.java
Normal file
38
source/java/org/alfresco/tools/ToolArgumentException.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.tools;
|
||||
|
||||
/**
|
||||
* Tool Argument Exception
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
/*package*/ class ToolArgumentException extends ToolException
|
||||
{
|
||||
private static final long serialVersionUID = 3880274996297222647L;
|
||||
|
||||
/*package*/ ToolArgumentException(String msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/*package*/ ToolArgumentException(String msg, Throwable cause)
|
||||
{
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
}
|
@@ -162,7 +162,7 @@ package org.alfresco.tools;
|
||||
* Validate Tool Context
|
||||
*/
|
||||
/*package*/ void validate()
|
||||
throws ToolException
|
||||
throws ToolArgumentException
|
||||
{
|
||||
if (login)
|
||||
{
|
||||
|
Reference in New Issue
Block a user