You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ed...@apache.org on 2005/10/11 16:41:03 UTC
svn commit: r312896 [1/6] - in
/incubator/jackrabbit/trunk/contrib/jcr-commands: ./
src/java/org/apache/jackrabbit/command/
src/java/org/apache/jackrabbit/command/cli/
src/java/org/apache/jackrabbit/command/collect/
src/java/org/apache/jackrabbit/comma...
Author: edgarpoce
Date: Tue Oct 11 07:38:54 2005
New Revision: 312896
URL: http://svn.apache.org/viewcvs?rev=312896&view=rev
Log:
jcr-97: Improve Checkstyle conformance
Added:
incubator/jackrabbit/trunk/contrib/jcr-commands/xdocs/changes.xml (with props)
Modified:
incubator/jackrabbit/trunk/contrib/jcr-commands/TODO.txt
incubator/jackrabbit/trunk/contrib/jcr-commands/project.properties
incubator/jackrabbit/trunk/contrib/jcr-commands/project.xml
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/CommandException.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/CommandHelper.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/AbstractParameter.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/Argument.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/CommandLine.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/CommandLineFactory.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/ConfigurationException.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/Flag.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/JcrClient.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/JcrParser.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/JcrParserException.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/Option.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/SourceCommand.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/command-line.xml
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/collect/AbstractCollect.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/collect/CollectItems.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/collect/CollectNodes.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/collect/CollectProperties.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/AbstractSetProperty.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/AddNode.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/ClearWorkspace.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Clone.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Copy.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/CurrentNode.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Login.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Logout.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Move.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/OrderBefore.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/ReadValue.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Refresh.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/RemoveItem.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/RemoveItems.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Rename.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Save.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/SetMultivalueProperty.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/SetProperty.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/ext/ConnectToRmiServer.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/ext/CreateWorkspace.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/ext/RegisterNodeType.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/ext/StartJackrabbit.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/ext/StartJackrabbitSingleton.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/ext/StopJackrabbit.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/fs/ExportFileSystem.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/fs/ExportPropertyToFile.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/fs/ImportFileSystem.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/fs/SetPropertyFromFile.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/AbstractLs.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/AbstractLsItems.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/AbstractLsNodes.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/AbstractLsProperties.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/Cat.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/Describe.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/Dump.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/Help.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/JcrInfoCommandException.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/LsCollectedItems.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/LsCollectedNodes.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/LsCollectedProperties.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/LsItems.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/LsNamespaces.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/LsNodes.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/LsProperties.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/LsReferences.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/LsVersions.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/PrintHelper.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/lock/AddLockToken.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/lock/Lock.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/lock/RefreshLock.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/lock/RemoveLockToken.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/lock/Unlock.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/mixin/AddMixin.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/mixin/RemoveMixin.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/namespace/RegisterNamespace.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/namespace/UnregisterNamespace.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/query/AbstractQuery.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/query/SQLQuery.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/query/XPathQuery.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/resources.properties
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/version/AddVersionLabel.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/version/Checkin.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/version/Checkout.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/version/Merge.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/version/RemoveVersion.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/version/RemoveVersionByLabel.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/version/RemoveVersionLabel.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/version/Restore.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/version/RestoreByLabel.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/AbstractExportViewToFile.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/ExportDocViewToFile.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/ExportSysViewToFile.java
incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/ImportXmlFromFile.java
incubator/jackrabbit/trunk/contrib/jcr-commands/xdocs/index.xml
incubator/jackrabbit/trunk/contrib/jcr-commands/xdocs/navigation.xml
incubator/jackrabbit/trunk/contrib/jcr-commands/xdocs/userguide.xml
Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/TODO.txt
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/TODO.txt?rev=312896&r1=312895&r2=312896&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/TODO.txt (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/TODO.txt Tue Oct 11 07:38:54 2005
@@ -2,4 +2,6 @@
- javadocs
- testing
- review i18n resource file
-- replace the parser, it hardly works
\ No newline at end of file
+- replace the parser, it hardly works
+- friendly exception handling in interactive mode
+- review command syntax
\ No newline at end of file
Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/project.properties
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/project.properties?rev=312896&r1=312895&r2=312896&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/project.properties (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/project.properties Tue Oct 11 07:38:54 2005
@@ -38,8 +38,8 @@
######################################################################
# Checkstyle
######################################################################
-# maven.checkstyle.properties= checkstyle.xml
-# maven.linkcheck.enable=false
+maven.checkstyle.properties= checkstyle.xml
+maven.linkcheck.enable=false
######################################################################
# JavaDoc
@@ -74,7 +74,7 @@
# in the Maven JavaCC plugin. Therefore, do not change this value!
maven.gen.src=${maven.build.dir}/generated-src/main
-# specifying additional remote repository for downloading dependencies
+# specifying additional remote repository for downloading dependencies
# not available at www.ibiblio.org/maven/
maven.repo.remote = http://www.ibiblio.org/maven/,http://www.day.com/maven/
Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/project.xml
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/project.xml?rev=312896&r1=312895&r2=312896&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/project.xml (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/project.xml Tue Oct 11 07:38:54 2005
@@ -29,8 +29,8 @@
<type>jar</type>
</dependency>
<!--
- cqfs-jackrabbit and cqfs are optional runtime dependencies
- (an alternative FileSystem implementation);
+ cqfs-jackrabbit and cqfs are optional runtime dependencies
+ (an alternative FileSystem implementation);
commons-logging is a dependency of cqfs
-->
<dependency>
@@ -177,4 +177,21 @@
</resource>
</resources>
</build>
+ <reports>
+ <report>maven-changelog-plugin</report>
+ <report>maven-changes-plugin</report>
+ <report>maven-checkstyle-plugin</report>
+ <!-- <report>maven-clover-plugin</report> -->
+ <!-- <report>maven-developer-activity-plugin</report> -->
+ <!-- <report>maven-file-activity-plugin</report> -->
+ <report>maven-javadoc-plugin</report>
+ <!-- <report>maven-jellydoc-plugin</report> -->
+ <report>maven-junit-report-plugin</report>
+ <report>maven-jxr-plugin</report>
+ <report>maven-license-plugin</report>
+ <!-- <report>maven-linkcheck-plugin</report> -->
+ <!-- <report>maven-statcvs-plugin</report> -->
+ <report>maven-tasklist-plugin</report>
+ <report>maven-faq-plugin</report>
+ </reports>
</project>
Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/CommandException.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/CommandException.java?rev=312896&r1=312895&r2=312896&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/CommandException.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/CommandException.java Tue Oct 11 07:38:54 2005
@@ -23,10 +23,9 @@
/**
* JCR command Exception
*/
-public class CommandException extends Exception
-{
+public class CommandException extends Exception {
/** Resource bundle */
- private static ResourceBundle bundle = CommandHelper.getBundle() ;
+ private static ResourceBundle bundle = CommandHelper.getBundle();
/**
* Exception arguments
@@ -40,39 +39,42 @@
/**
* @param message
+ * the message
*/
- public CommandException(String message)
- {
+ public CommandException(String message) {
super(message);
}
/**
* @param message
+ * the message
* @param arguments
+ * the arguments
*/
- public CommandException(String message, Object[] arguments)
- {
+ public CommandException(String message, Object[] arguments) {
super(message);
this.arguments = arguments;
}
/**
* @param message
+ * the message
* @param cause
+ * the cause
*/
- public CommandException(String message, Throwable cause)
- {
+ public CommandException(String message, Throwable cause) {
super(message, cause);
}
/**
* @param message
+ * the message
* @param cause
+ * the cause
* @param arguments
+ * the arguments
*/
- public CommandException(String message, Throwable cause,
- Object[] arguments)
- {
+ public CommandException(String message, Throwable cause, Object[] arguments) {
super(message, cause);
this.arguments = arguments;
}
@@ -80,21 +82,16 @@
/**
* @return the localized message
*/
- public String getLocalizedMessage()
- {
- try
- {
- if (this.arguments == null)
- {
+ public String getLocalizedMessage() {
+ try {
+ if (this.arguments == null) {
return bundle.getString(this.getMessage());
- } else
- {
+ } else {
MessageFormat f = new MessageFormat("");
f.applyPattern(bundle.getString(this.getMessage()));
return f.format(this.arguments);
}
- } catch (MissingResourceException e)
- {
+ } catch (MissingResourceException e) {
return this.getMessage();
}
}
Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/CommandHelper.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/CommandHelper.java?rev=312896&r1=312895&r2=312896&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/CommandHelper.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/CommandHelper.java Tue Oct 11 07:38:54 2005
@@ -33,311 +33,329 @@
import org.apache.commons.collections.IteratorUtils;
/**
- * Helper class for getting and setting context attributes.
+ * Utility class for getting and setting context attributes.
*/
-public class CommandHelper
-{
- /** bundle */
- private static ResourceBundle bundle = ResourceBundle
- .getBundle(CommandHelper.class.getPackage().getName()
- + ".resources");
-
- /** Current node key */
- private static String CURRENT_NODE_KEY = "jcr.current";
-
- /** repository key */
- private static String REPOSITORY_KEY = "jcr.repository";
-
- /** session key */
- private static String SESSION_KEY = "jcr.session";
-
- /** session key */
- private static String OUTPUT_KEY = "jcr.output";
-
- /**
- * Sets the current output
- *
- * @param ctx
- * @param output
- */
- public static void setOutput(Context ctx, PrintWriter out)
- {
- if (out == null)
- {
- ctx.remove(OUTPUT_KEY);
- } else
- {
- ctx.put(OUTPUT_KEY, out);
- }
- }
-
- /**
- * Sets the current working Node
- *
- * @param ctx
- * @param node
- * @throws CommandException
- */
- public static void setCurrentNode(Context ctx, Node node)
- throws CommandException
- {
- if (node == null)
- {
- ctx.remove(CURRENT_NODE_KEY);
- } else
- {
- ctx.put(CURRENT_NODE_KEY, node);
- }
- }
-
- /**
- * Sets the current working Repository
- *
- * @param ctx
- * @param repository
- */
- public static void setRepository(Context ctx, Repository repository)
- {
- if (repository == null)
- {
- ctx.remove(REPOSITORY_KEY);
- } else
- {
- ctx.put(REPOSITORY_KEY, repository);
- }
-
- }
-
- /**
- * Sets the current working Session
- *
- * @param ctx
- * @param session
- */
- public static void setSession(Context ctx, Session session)
- {
- if (session == null)
- {
- ctx.remove(SESSION_KEY);
- } else
- {
- ctx.put(SESSION_KEY, session);
- }
- }
-
- /**
- * Gets the current working Node
- *
- * @param ctx
- * @return
- */
- public static PrintWriter getOutput(Context ctx)
- {
- PrintWriter out = (PrintWriter) ctx.get(OUTPUT_KEY);
- if (out == null)
- {
- out = new PrintWriter(System.out, true);
- }
- return out;
- }
-
- /**
- * Gets the current working Node
- *
- * @param ctx
- * @return
- * @throws CommandException
- */
- public static Node getCurrentNode(Context ctx) throws CommandException
- {
- Node n = (Node) ctx.get(CURRENT_NODE_KEY);
- if (n == null)
- {
- throw new CommandException("exception.no.current.node");
- }
- return n;
- }
-
- /**
- * Gets the current working Repository
- *
- * @param ctx
- * @return
- * @throws CommandException
- */
- public static Repository getRepository(Context ctx) throws CommandException
- {
- return (Repository) ctx.get(REPOSITORY_KEY);
- }
-
- /**
- * Gets the current working Session
- *
- * @param ctx
- * @return
- * @throws CommandException
- */
- public static Session getSession(Context ctx) throws CommandException
- {
- return (Session) ctx.get(SESSION_KEY);
- }
-
- /**
- * Gets node at the given path.
- *
- * @param ctx
- * @param path
- * @return
- * @throws CommandException
- * @throws PathNotFoundException
- * @throws RepositoryException
- */
- public static Node getNode(Context ctx, String path)
- throws CommandException, PathNotFoundException, RepositoryException
- {
- Item i = getItem(ctx, path);
- if (!i.isNode())
- {
- throw new PathNotFoundException("the path " + i.getPath()
- + "refers to a Property");
- }
- return (Node) i;
- }
-
- /**
- * Gets the Item at the given path. <br>
- * If the path is null it returns the current working node.
- *
- * @param ctx
- * @param path
- * @return the Item for the given path
- * @throws CommandException
- * @throws PathNotFoundException
- * @throws RepositoryException
- */
- public static Item getItem(Context ctx, String path)
- throws CommandException, PathNotFoundException, RepositoryException
- {
- Node current = (Node) ctx.get(CURRENT_NODE_KEY);
- Item i = null;
-
- if (path == null)
- {
- i = current;
- } else if (path.equals("/"))
- {
- i = current.getSession().getRootNode();
- } else if (path.startsWith("/"))
- {
- i = current.getSession().getItem(path);
- } else
- {
- String newPath = current.getPath();
- // handle the root node
- if (!newPath.endsWith("/"))
- {
- newPath += "/";
- }
- newPath += path;
- i = current.getSession().getItem(newPath);
- }
-
- return i;
- }
-
- /**
- * Returns true if the node exists at the given path
- *
- * @param ctx
- * @param path
- * @return
- * @throws CommandException
- * @throws RepositoryException
- */
- public static boolean hasNode(Context ctx, String path)
- throws CommandException, RepositoryException
- {
- if (path.equals("/"))
- {
- return true;
- } else if (path.startsWith("/"))
- {
- return getSession(ctx).getRootNode().hasNode(path.substring(1));
- } else
- {
- Node current = (Node) ctx.get(CURRENT_NODE_KEY);
- return current.hasNode(path);
- }
- }
-
- /**
- * Get the nodes under the given node that match the given pattern.
- *
- * @param ctx
- * Command Context
- * @param node
- * Parent node
- * @param pattern
- * @return an Iterator that contains the matching nodes
- * @throws CommandException
- * @throws RepositoryException
- */
- public static NodeIterator getNodes(Context ctx, Node node, String pattern)
- throws CommandException, RepositoryException
- {
- if (pattern != null)
- {
- return node.getNodes(pattern);
- } else
- {
- return node.getNodes();
- }
- }
-
- /**
- * Get the properties under the current working node for the given pattern
- *
- * @param ctx
- * @param node
- * Parent node
- * @param pattern
- * @return
- * @throws CommandException
- * @throws RepositoryException
- */
- public static PropertyIterator getProperties(Context ctx, Node node,
- String pattern) throws CommandException, RepositoryException
- {
- if (pattern != null)
- {
- return node.getProperties(pattern);
- } else
- {
- return node.getProperties();
- }
- }
-
- /**
- * @return default resource bundle
- */
- public static ResourceBundle getBundle()
- {
- return bundle;
- }
-
- /**
- * Get the items under the given node that match the pattern
- *
- * @param ctx
- * @return
- * @throws CommandException
- * @throws RepositoryException
- */
- public static Iterator getItems(Context ctx, Node node, String pattern)
- throws CommandException, RepositoryException
- {
- return IteratorUtils.chainedIterator(getNodes(ctx, node, pattern),
- getProperties(ctx, node, pattern));
- }
+public final class CommandHelper {
+ /** bundle */
+ private static ResourceBundle bundle = ResourceBundle
+ .getBundle(CommandHelper.class.getPackage().getName() + ".resources");
+
+ /** Current node key */
+ private static final String CURRENT_NODE_KEY = "jcr.current";
+
+ /** repository key */
+ private static final String REPOSITORY_KEY = "jcr.repository";
+
+ /** session key */
+ private static final String SESSION_KEY = "jcr.session";
+
+ /** session key */
+ private static final String OUTPUT_KEY = "jcr.output";
+
+ /**
+ * should never get called
+ */
+ private CommandHelper() {
+ super();
+ }
+
+ /**
+ * Sets the current <code>PrintWriter</code>.
+ * @param ctx
+ * the <code>Context</code>
+ * @param out
+ * the <code>PrintWriter</code>
+ */
+ public static void setOutput(Context ctx, PrintWriter out) {
+ if (out == null) {
+ ctx.remove(OUTPUT_KEY);
+ } else {
+ ctx.put(OUTPUT_KEY, out);
+ }
+ }
+
+ /**
+ * Sets the current working <code>Node</code>.
+ * @param ctx
+ * the <code>Context</code>
+ * @param node
+ * the current working <code>Node</code>.
+ */
+ public static void setCurrentNode(Context ctx, Node node) {
+ if (node == null) {
+ ctx.remove(CURRENT_NODE_KEY);
+ } else {
+ ctx.put(CURRENT_NODE_KEY, node);
+ }
+ }
+
+ /**
+ * Sets the current working <code>Repository</code>
+ * @param ctx
+ * the <code>Context</code>
+ * @param repository
+ * the current working <code>Repository</code>
+ */
+ public static void setRepository(Context ctx, Repository repository) {
+ if (repository == null) {
+ ctx.remove(REPOSITORY_KEY);
+ } else {
+ ctx.put(REPOSITORY_KEY, repository);
+ }
+ }
+
+ /**
+ * Sets the current working <code>Session</code>
+ * @param ctx
+ * the <code>Context</code>
+ * @param session
+ * the current working <code>Session</code>
+ * @throws CommandException if there's an open working <code>Session</code>
+ */
+ public static void setSession(Context ctx, Session session) throws CommandException {
+ if (session == null) {
+ ctx.remove(SESSION_KEY);
+ } else {
+ if (ctx.get(SESSION_KEY) != null) {
+ throw new CommandException("exception.already.logged.in");
+ }
+ ctx.put(SESSION_KEY, session);
+ }
+ }
+
+ /**
+ * Gets the current <code>PrintWriter</code>
+ * @param ctx
+ * the <code>Context</code>
+ * @return the current <code>PrintWriter</code>
+ */
+ public static PrintWriter getOutput(Context ctx) {
+ PrintWriter out = (PrintWriter) ctx.get(OUTPUT_KEY);
+ if (out == null) {
+ out = new PrintWriter(System.out, true);
+ }
+ return out;
+ }
+
+ /**
+ * Gets the current working <code>Node</code>
+ * @param ctx
+ * the <code>Context</code>
+ * @return the current working <code>Node</code>
+ * @throws CommandException
+ * if the current working <code>Node</code> can't be found.
+ */
+ public static Node getCurrentNode(Context ctx) throws CommandException {
+ Node n = (Node) ctx.get(CURRENT_NODE_KEY);
+ if (n == null) {
+ throw new CommandException("exception.no.current.node");
+ }
+ return n;
+ }
+
+ /**
+ * Gets the current working <code>Repository</code>
+ * @param ctx
+ * the <code>Context</code>
+ * @return the current working <code>Repository</code>
+ * @throws CommandException
+ * if the current working <code>Repository</code> is unset.
+ */
+ public static Repository getRepository(Context ctx) throws CommandException {
+ Repository r = (Repository) ctx.get(REPOSITORY_KEY);
+ if (r == null) {
+ throw new CommandException("exception.no.current.repository");
+ }
+ return r;
+ }
+
+ /**
+ * Gets the current working <code>Session</code>
+ * @param ctx
+ * the <code>Context</code>
+ * @return the current working <code>Session</code>
+ * @throws CommandException
+ * if the current working <code>Session</code> is unset.
+ */
+ public static Session getSession(Context ctx) throws CommandException {
+ Session s = (Session) ctx.get(SESSION_KEY);
+ if (s == null) {
+ throw new CommandException("exception.no.current.session");
+ }
+ return s;
+ }
+
+ /**
+ * Gets the <code>Node</code> at the given path.
+ * @param ctx
+ * the <code>Context</code>
+ * @param path
+ * the path to the <code>Node</code>
+ * @return the <code>Node</code> at the given path
+ * @throws CommandException
+ * if the <code>Node</code> isn't found.
+ * @throws RepositoryException
+ * if the underlying repository throws a
+ * <code>RepositoryException</code>
+ */
+ public static Node getNode(Context ctx, String path)
+ throws CommandException, RepositoryException {
+ try {
+ Item i = getItem(ctx, path);
+ if (!i.isNode()) {
+ throw new CommandException("exception.no.node.at",
+ new String[] {
+ path
+ });
+ }
+ return (Node) i;
+ } catch (PathNotFoundException e) {
+ throw new CommandException("exception.no.node.at", new String[] {
+ path
+ });
+ }
+ }
+
+ /**
+ * Gets the <code>Item</code> at the given path. <br>
+ * If the path is null it returns the current working <code>Node</code>.
+ * @param ctx
+ * the <code>Context</code>
+ * @param path
+ * the path to the <code>Item</code>
+ * @return the <code>Item</code> at the given path
+ * @throws CommandException
+ * if a <code>Command</code> internal error occurs.
+ * @throws PathNotFoundException
+ * if there's no <code>Node</code> at the given path.
+ * @throws RepositoryException
+ * if the underlying repository throws a
+ * <code>RepositoryException</code>
+ */
+ public static Item getItem(Context ctx, String path)
+ throws CommandException, PathNotFoundException, RepositoryException {
+ Node current = getCurrentNode(ctx);
+ Item i = null;
+
+ if (path == null) {
+ i = current;
+ } else if (path.equals("/")) {
+ i = current.getSession().getRootNode();
+ } else if (path.startsWith("/")) {
+ i = current.getSession().getItem(path);
+ } else {
+ String newPath = current.getPath();
+ // handle the root node
+ if (!newPath.endsWith("/")) {
+ newPath += "/";
+ }
+ newPath += path;
+ i = current.getSession().getItem(newPath);
+ }
+
+ return i;
+ }
+
+ /**
+ * Checks <code>Node</code> existence.
+ * @param ctx
+ * the <code>Context</code>
+ * @param path
+ * the path to the <code>Node</code>
+ * @return true if the <code>Node</code> exists at the given path
+ * @throws CommandException
+ * if the current working <code>Session</code> is unset.
+ * @throws RepositoryException
+ * if the underlying repository throws a
+ * <code>RepositoryException</code>
+ */
+ public static boolean hasNode(Context ctx, String path)
+ throws CommandException, RepositoryException {
+ Session s = getSession(ctx);
+ if (path.equals("/")) {
+ return true;
+ } else if (path.startsWith("/")) {
+ return s.getRootNode().hasNode(path.substring(1));
+ } else {
+ Node current = (Node) ctx.get(CURRENT_NODE_KEY);
+ return current.hasNode(path);
+ }
+ }
+
+ /**
+ * Gets the <code>Node</code> s under the given <code>Node</code> that
+ * match the given pattern.
+ * @param ctx
+ * the <code>Context</code>
+ * @param node
+ * the parent <code>Node</code>
+ * @param pattern
+ * the pattern
+ * @return an <code>Iterator</code> that contains the matching nodes
+ * @throws RepositoryException
+ * if the underlying repository throws a
+ * <code>RepositoryException</code>
+ */
+ public static NodeIterator getNodes(Context ctx, Node node, String pattern)
+ throws RepositoryException {
+ if (pattern != null) {
+ return node.getNodes(pattern);
+ } else {
+ return node.getNodes();
+ }
+ }
+
+ /**
+ * Gets the <code>Property</code> s under the current working node for the
+ * given pattern
+ * @param ctx
+ * the <code>Context</code>
+ * @param node
+ * the parent <code>Node</code>
+ * @param pattern
+ * the pattern
+ * @return a <code>PropertyIterator</code>
+ * @throws RepositoryException
+ * if the underlying repository throws a
+ * <code>RepositoryException</code>
+ */
+ public static PropertyIterator getProperties(
+ Context ctx,
+ Node node,
+ String pattern) throws RepositoryException {
+ if (pattern != null) {
+ return node.getProperties(pattern);
+ } else {
+ return node.getProperties();
+ }
+ }
+
+ /**
+ * @return the default <code>ResourceBundle</code>
+ */
+ public static ResourceBundle getBundle() {
+ return bundle;
+ }
+
+ /**
+ * Gets the <code>Item</code> s under the given <code>Node</code> that
+ * match the pattern
+ * @param ctx
+ * the <code>Context</code>
+ * @param node
+ * the parent <code>Node</code>
+ * @param pattern
+ * the pattern
+ * @return an <code>Iterator</code> with the <code>Item</code> s that
+ * match the given pattern.
+ * @throws RepositoryException
+ * if the underlying repository throws a
+ * <code>RepositoryException</code>
+ */
+ public static Iterator getItems(Context ctx, Node node, String pattern)
+ throws RepositoryException {
+ return IteratorUtils.chainedIterator(getNodes(ctx, node, pattern),
+ getProperties(ctx, node, pattern));
+ }
}
Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/AbstractParameter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/AbstractParameter.java?rev=312896&r1=312895&r2=312896&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/AbstractParameter.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/AbstractParameter.java Tue Oct 11 07:38:54 2005
@@ -23,139 +23,130 @@
/**
* Command Line parameter superclass
*/
-public abstract class AbstractParameter implements Cloneable
-{
+public abstract class AbstractParameter implements Cloneable {
- /** Resource bundle */
- protected ResourceBundle bundle = CommandHelper.getBundle();
+ /** Resource bundle */
+ protected ResourceBundle bundle = CommandHelper.getBundle();
- /** name */
- private String name;
+ /** name */
+ private String name;
- /** long name */
- private String longName;
-
- /** description */
- private String description;
-
- /** command or a context attribute */
- private String contextKey;
-
- /** value */
- private String value;
-
- /**
- * @return Returns the description.
- */
- public String getDescription()
- {
- return description;
- }
-
- /**
- * @return localized description
- */
- public abstract String getLocalizedDescription();
-
- /**
- * @return Returns the name.
- */
- public String getName()
- {
- return name;
- }
-
- /**
- * @param description
- * The description to set.
- */
- public void setDescription(String description)
- {
- this.description = description;
- }
-
- /**
- * @param name
- * The name to set.
- */
- public void setName(String name)
- {
- this.name = name;
- }
-
- /**
- * @return Returns the value.
- */
- public String getValue()
- {
- return value;
- }
-
- /**
- * @param value
- * The value to set.
- */
- public void setValue(String value)
- {
- this.value = value;
- }
-
- /**
- * @return Returns the longName.
- */
- public String getLongName()
- {
- return longName;
- }
-
- /**
- * @param longName
- * The longName to set.
- */
- public void setLongName(String longName)
- {
- this.longName = longName;
- }
-
- protected void clone(AbstractParameter param)
- {
- param.contextKey = this.contextKey;
- param.description = this.description;
- param.longName = this.longName;
- param.name = this.name;
- param.value = this.value;
- }
-
- /**
- * @return Returns the commandAttribute.
- * if the context key is unset it returns the parameter name
- */
- public String getContextKey()
- {
- if (contextKey == null)
- {
- return this.name;
- }
- return contextKey;
- }
-
- /**
- * @param commandAttribute
- * The commandAttribute to set.
- */
- public void setContextKey(String commandAttribute)
- {
- this.contextKey = commandAttribute;
- }
-
- /**
- * @return true if this parameter is mandatory
- */
- public abstract boolean isRequired();
-
- /**
- * @return argumentlocalized name
- */
- public abstract String getLocalizedArgName();
+ /** long name */
+ private String longName;
+
+ /** description */
+ private String description;
+
+ /** command or a context attribute */
+ private String contextKey;
+
+ /** value */
+ private String value;
+
+ /**
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @return the localized description
+ */
+ public abstract String getLocalizedDescription();
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param description
+ * The description to set
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * @param name
+ * the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the value
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * @param value
+ * The value to set
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ /**
+ * @return the longName
+ */
+ public String getLongName() {
+ return longName;
+ }
+
+ /**
+ * @param longName
+ * The longName to set
+ */
+ public void setLongName(String longName) {
+ this.longName = longName;
+ }
+
+ /**
+ * @param param
+ * the <code>AbstractParameter</code> to clone
+ */
+ protected void clone(AbstractParameter param) {
+ param.contextKey = this.contextKey;
+ param.description = this.description;
+ param.longName = this.longName;
+ param.name = this.name;
+ param.value = this.value;
+ }
+
+ /**
+ * @return the commandAttribute. if the context key is unset it returns the
+ * parameter name
+ */
+ public String getContextKey() {
+ if (contextKey == null) {
+ return this.name;
+ }
+ return contextKey;
+ }
+
+ /**
+ * @param commandAttribute
+ * The commandAttribute to set
+ */
+ public void setContextKey(String commandAttribute) {
+ this.contextKey = commandAttribute;
+ }
+
+ /**
+ * @return true if this parameter is mandatory
+ */
+ public abstract boolean isRequired();
+
+ /**
+ * @return argumentlocalized name
+ */
+ public abstract String getLocalizedArgName();
}
Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/Argument.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/Argument.java?rev=312896&r1=312895&r2=312896&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/Argument.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/Argument.java Tue Oct 11 07:38:54 2005
@@ -17,31 +17,33 @@
package org.apache.jackrabbit.command.cli;
/**
- * Command line argument.
+ * Command line argument
*/
-public class Argument extends Option
-{
+public class Argument extends Option {
/** position of the argument */
private int position;
/**
- * @return
+ * @return the position
*/
- public int getPosition()
- {
+ public int getPosition() {
return position;
}
- public void setPosition(int position)
- {
+ /**
+ * sets the argument position
+ * @param position
+ * the position
+ */
+ public void setPosition(int position) {
this.position = position;
}
/**
* @inheritDoc
+ * @return a clone
*/
- public Object clone()
- {
+ public Object clone() {
Argument arg = new Argument();
arg.position = this.position;
this.clone(arg);
Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/CommandLine.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/CommandLine.java?rev=312896&r1=312895&r2=312896&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/CommandLine.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/CommandLine.java Tue Oct 11 07:38:54 2005
@@ -29,10 +29,9 @@
import org.apache.jackrabbit.command.CommandHelper;
/**
- * Command Line.
+ * Command Line
*/
-public class CommandLine implements Comparable, Cloneable
-{
+public class CommandLine implements Comparable, Cloneable {
/** Resource bundle */
protected static ResourceBundle bundle = CommandHelper.getBundle();
@@ -51,7 +50,7 @@
/** Options */
private Map options = new TreeMap();
- /** Options */
+ /** flags */
private Map flags = new TreeMap();
/** arguments */
@@ -60,20 +59,16 @@
/**
* constructor
*/
- public CommandLine()
- {
+ public CommandLine() {
super();
}
/**
* @return required arguments
*/
- public Collection getRequiredArguments()
- {
- Predicate p = new Predicate()
- {
- public boolean evaluate(Object o)
- {
+ public Collection getRequiredArguments() {
+ Predicate p = new Predicate() {
+ public boolean evaluate(Object o) {
Argument arg = (Argument) o;
return arg.isRequired();
}
@@ -84,12 +79,9 @@
/**
* @return required options
*/
- public Collection getRequiredOptions()
- {
- Predicate p = new Predicate()
- {
- public boolean evaluate(Object o)
- {
+ public Collection getRequiredOptions() {
+ Predicate p = new Predicate() {
+ public boolean evaluate(Object o) {
Option opt = (Option) o;
return opt.isRequired();
}
@@ -98,109 +90,95 @@
}
/**
- * @return Returns the description.
+ * @return the description.
*/
- public String getDescription()
- {
+ public String getDescription() {
return description;
}
/**
- * @return Returns the localized description.
+ * @return the localized description.
*/
- public String getLocalizedDescription()
- {
- if (description == null)
- {
+ public String getLocalizedDescription() {
+ if (description == null) {
return bundle.getString("cmd." + this.name);
- } else
- {
+ } else {
return bundle.getString(this.description);
}
}
/**
* @param description
- * The description to set.
+ * The description to set
*/
- public void setDescription(String description)
- {
+ public void setDescription(String description) {
this.description = description;
}
/**
- * @return Returns the flags.
+ * @return the flags
*/
- public Map getFlags()
- {
+ public Map getFlags() {
return flags;
}
/**
* @param flags
- * The flags to set.
+ * The flags to set
*/
- public void setFlags(Map flags)
- {
+ public void setFlags(Map flags) {
this.flags = flags;
}
/**
- * @return Returns the impl.
+ * @return the impl
*/
- public String getImpl()
- {
+ public String getImpl() {
return impl;
}
/**
* @param impl
- * The impl to set.
+ * The impl to set
*/
- public void setImpl(String impl)
- {
+ public void setImpl(String impl) {
this.impl = impl;
}
/**
- * @return Returns the name.
+ * @return the name
*/
- public String getName()
- {
+ public String getName() {
return name;
}
/**
* @param name
- * The name to set.
+ * the name to set
*/
- public void setName(String name)
- {
+ public void setName(String name) {
this.name = name;
}
/**
- * @return Returns the options.
+ * @return the options
*/
- public Map getOptions()
- {
+ public Map getOptions() {
return options;
}
/**
* @param options
- * The options to set.
+ * the <code>Option</code>s to set
*/
- public void setOptions(Map options)
- {
+ public void setOptions(Map options) {
this.options = options;
}
/**
- * @inheritDoc
+ * {@inheritDoc}
*/
- public int compareTo(Object o)
- {
+ public int compareTo(Object o) {
CommandLine cl = (CommandLine) o;
return name.compareTo(cl.name);
}
@@ -208,8 +186,7 @@
/**
* @return all the parameters. i.e. args, options and flags.
*/
- public Iterator getAllParameters()
- {
+ public Iterator getAllParameters() {
IteratorChain chain = new IteratorChain();
chain.addIterator(getArguments().values().iterator());
chain.addIterator(getOptions().values().iterator());
@@ -220,8 +197,7 @@
/**
* @return the required parameters. i.e. args, options and flags.
*/
- public Iterator getRequiredParameters()
- {
+ public Iterator getRequiredParameters() {
IteratorChain chain = new IteratorChain();
chain.addIterator(getRequiredArguments().iterator());
chain.addIterator(getRequiredOptions().iterator());
@@ -229,24 +205,19 @@
}
/**
- * Adds an argument.
- *
* @param arg
+ * the <code>Argument</code> to add
*/
- public void addArgument(Argument arg)
- {
- if (arguments.containsKey(new Integer(arg.getPosition())))
- {
+ public void addArgument(Argument arg) {
+ if (arguments.containsKey(new Integer(arg.getPosition()))) {
throw new IllegalArgumentException(
"there's an argument in the position in command " + this.name);
}
// Put default values description and arg name i18n keys
- if (arg.getArgName() == null)
- {
+ if (arg.getArgName() == null) {
arg.setArgName("cmd." + this.getName() + "." + arg.getName());
}
- if (arg.getDescription() == null)
- {
+ if (arg.getDescription() == null) {
arg.setDescription("cmd." + this.getName() + "." + arg.getName()
+ ".desc");
}
@@ -254,19 +225,14 @@
}
/**
- * Add an Option
- *
- * @param opt
+ * @param opt the <code>Option</code> to add
*/
- public void addOption(Option opt)
- {
+ public void addOption(Option opt) {
// Put default values description and arg name i18n keys
- if (opt.getArgName() == null)
- {
+ if (opt.getArgName() == null) {
opt.setArgName("cmd." + this.getName() + "." + opt.getName());
}
- if (opt.getDescription() == null)
- {
+ if (opt.getDescription() == null) {
opt.setDescription("cmd." + this.getName() + "." + opt.getName()
+ ".desc");
}
@@ -274,15 +240,11 @@
}
/**
- * Flag
- *
- * @param flag
+ * @param flag the <code>Flag</code> to add
*/
- public void addFlag(Flag flag)
- {
+ public void addFlag(Flag flag) {
// Put default values description and arg name i18n keys
- if (flag.getDescription() == null)
- {
+ if (flag.getDescription() == null) {
flag.setDescription("cmd." + this.getName() + "." + flag.getName()
+ ".desc");
}
@@ -290,68 +252,58 @@
}
/**
- * @return Returns the arguments.
+ * @return the arguments
*/
- public Map getArguments()
- {
+ public Map getArguments() {
return arguments;
}
/**
* @param arguments
- * The arguments to set.
+ * the arguments to set
*/
- public void setArguments(Map arguments)
- {
+ public void setArguments(Map arguments) {
this.arguments = arguments;
}
/**
- * @return Returns the alias.
+ * @return the alias
*/
- public Collection getAlias()
- {
+ public Collection getAlias() {
return alias;
}
/**
* @param alias
- * The alias to set.
+ * the alias to set
*/
- public void setAlias(Collection alias)
- {
+ public void setAlias(Collection alias) {
this.alias = alias;
}
/**
- * Add alias
- *
- * @param alias
+ * @param alias the alias to add
*/
- public void addAlias(String alias)
- {
+ public void addAlias(String alias) {
this.alias.add(alias);
}
/**
- * @inheritDoc
+ * {@inheritDoc}
*/
- public Object clone()
- {
+ public Object clone() {
CommandLine cl = new CommandLine();
cl.alias = this.alias;
// Arguments
Iterator iter = this.arguments.values().iterator();
- while (iter.hasNext())
- {
+ while (iter.hasNext()) {
Argument arg = (Argument) iter.next();
cl.addArgument((Argument) arg.clone());
}
cl.description = this.description;
// Flags
iter = this.flags.values().iterator();
- while (iter.hasNext())
- {
+ while (iter.hasNext()) {
Flag f = (Flag) iter.next();
cl.addFlag((Flag) f.clone());
}
@@ -359,8 +311,7 @@
cl.name = this.name;
// Flags
iter = this.options.values().iterator();
- while (iter.hasNext())
- {
+ while (iter.hasNext()) {
Option o = (Option) iter.next();
cl.addOption((Option) o.clone());
}
@@ -368,10 +319,9 @@
}
/**
- * @inheritDoc
+ * {@inheritDoc}
*/
- public String toString()
- {
+ public String toString() {
return "CommandLine-" + this.getName() + "(" + impl + ")";
}
}
Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/CommandLineFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/CommandLineFactory.java?rev=312896&r1=312895&r2=312896&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/CommandLineFactory.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/CommandLineFactory.java Tue Oct 11 07:38:54 2005
@@ -32,155 +32,147 @@
import org.apache.commons.digester.xmlrules.DigesterLoader;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.jackrabbit.command.CommandException;
import org.apache.jackrabbit.command.CommandHelper;
import org.xml.sax.SAXException;
/**
- * Command line factory.
+ * Command line factory
*/
-public class CommandLineFactory
-{
- /** logger */
- private static Log log = LogFactory.getLog(CommandLineFactory.class);
-
- private static ResourceBundle bundle = CommandHelper.getBundle();
-
- /** file name */
- private static String COMMAND_LINE_FILE = "command-line.xml";
-
- /** rules file name */
- private static String COMMAND_LINE_RULES_FILE = "command-line-rules.xml";
-
- /** singleton */
- private static CommandLineFactory singleton;
-
- /** command cache */
- private Map cache = new TreeMap();
-
- /** alias cache */
- private Map alias = new HashMap();
-
- /**
- * private Constructor
- */
- private CommandLineFactory()
- {
- super();
- }
-
- /**
- * @return CliCommandFactory singleton
- */
- public static CommandLineFactory getInstance()
- {
- if (singleton == null)
- {
- try
- {
- CommandLineFactory factory = new CommandLineFactory();
- factory.init();
- singleton = factory;
- } catch (Exception e)
- {
- log.error(bundle.getString("exception.unabletoinit"), e);
- e.printStackTrace();
- }
- }
- return singleton;
- }
-
- /**
- * @return all registered commands
- * @throws CommandException
- */
- public Collection getCommandLines() throws CommandException
- {
- List cls = new ArrayList();
- Iterator iter = cache.values().iterator();
- while (iter.hasNext())
- {
- CommandLine cl = (CommandLine) iter.next();
- cls.add(cl.clone());
- }
- return cls;
- }
-
- /**
- * @param name
- * @return a new Command Line Instance for the given command name
- * @throws JcrParserException
- */
- public CommandLine getCommandLine(String name) throws JcrParserException
- {
- log.debug("lookup command " + name);
- // get Command line
- CommandLine original = (CommandLine) cache.get(name);
-
- if (original == null)
- {
- log.debug("lookup alias " + name);
- original = (CommandLine) alias.get(name);
- }
-
- if (original == null)
- {
- log.warn("command not found " + name);
- throw new JcrParserException("exception.no.command.for.name",
- new String[]
- { name });
- }
-
- // Return a clone
- return (CommandLine) original.clone();
- }
-
- /**
- * Parse configuration file
- *
- * @throws IOException
- * @throws SAXException
- * @throws ConfigurationException
- */
- private void init() throws IOException, SAXException,
- ConfigurationException
- {
- // Configure Digester from XML ruleset
- URL rulesFile = getClass().getResource(COMMAND_LINE_RULES_FILE);
- URL clFile = getClass().getResource(COMMAND_LINE_FILE);
-
- // init digester
- Digester digester = DigesterLoader.createDigester(rulesFile);
-
- // Push empty List onto Digester's Stack
- List cls = new ArrayList();
- digester.push(cls);
-
- // Parse the XML document
- InputStream input = clFile.openStream();
- digester.parse(input);
- input.close();
-
- // Add to cache
- Iterator iter = cls.iterator();
- while (iter.hasNext())
- {
- CommandLine cl = (CommandLine) iter.next();
- cache.put(cl.getName(), cl);
- // Add to alias cache
- Iterator aliasIt = cl.getAlias().iterator();
- while (aliasIt.hasNext())
- {
- String aliasName = (String) aliasIt.next();
- if (alias.containsKey(aliasName))
- {
- throw new ConfigurationException(
- "exception.alias.already.in.use", new String[]
- { aliasName, cl.getName() });
- }
- alias.put(aliasName, cl);
- }
- }
- }
+public class CommandLineFactory {
+ /** logger */
+ private static Log log = LogFactory.getLog(CommandLineFactory.class);
+
+ /** resource bundle */
+ private static ResourceBundle bundle = CommandHelper.getBundle();
+
+ /** file name */
+ private static final String COMMAND_LINE_FILE = "command-line.xml";
+
+ /** rules file name */
+ private static final String COMMAND_LINE_RULES_FILE = "command-line-rules.xml";
+
+ /** singleton */
+ private static CommandLineFactory singleton;
+
+ /** command cache */
+ private Map cache = new TreeMap();
+
+ /** alias cache */
+ private Map alias = new HashMap();
+
+ /**
+ * private constructor
+ */
+ private CommandLineFactory() {
+ super();
+ }
+
+ /**
+ * @return singleton
+ */
+ public static CommandLineFactory getInstance() {
+ if (singleton == null) {
+ try {
+ CommandLineFactory factory = new CommandLineFactory();
+ factory.init();
+ singleton = factory;
+ } catch (Exception e) {
+ log.error(bundle.getString("exception.unabletoinit"), e);
+ e.printStackTrace();
+ }
+ }
+ return singleton;
+ }
+
+ /**
+ * @return all registered <code>Command</code> s
+ */
+ public Collection getCommandLines() {
+ List cls = new ArrayList();
+ Iterator iter = cache.values().iterator();
+ while (iter.hasNext()) {
+ CommandLine cl = (CommandLine) iter.next();
+ cls.add(cl.clone());
+ }
+ return cls;
+ }
+
+ /**
+ * Get the <code>Command</code> for the given name
+ * @param name
+ * the <code>Command</code> name
+ * @return a new Command Line Instance for the given command name
+ * @throws JcrParserException
+ * if there's no <code>Command</code> for the given name
+ */
+ public CommandLine getCommandLine(String name) throws JcrParserException {
+ log.debug("lookup command " + name);
+ // get Command line
+ CommandLine original = (CommandLine) cache.get(name);
+
+ if (original == null) {
+ log.debug("lookup alias " + name);
+ original = (CommandLine) alias.get(name);
+ }
+
+ if (original == null) {
+ log.warn("command not found " + name);
+ throw new JcrParserException("exception.no.command.for.name",
+ new String[] {
+ name
+ });
+ }
+
+ // Return a clone
+ return (CommandLine) original.clone();
+ }
+
+ /**
+ * parses the configuration file
+ * @throws ConfigurationException
+ * an <code>Exception</code> occurs while parsing
+ */
+ private void init() throws ConfigurationException {
+ try {
+ // Configure Digester from XML ruleset
+ URL rulesFile = getClass().getResource(COMMAND_LINE_RULES_FILE);
+ URL clFile = getClass().getResource(COMMAND_LINE_FILE);
+
+ // init digester
+ Digester digester = DigesterLoader.createDigester(rulesFile);
+
+ // Push empty List onto Digester's Stack
+ List cls = new ArrayList();
+ digester.push(cls);
+
+ // Parse the XML document
+ InputStream input = clFile.openStream();
+ digester.parse(input);
+ input.close();
+
+ // Add to cache
+ Iterator iter = cls.iterator();
+ while (iter.hasNext()) {
+ CommandLine cl = (CommandLine) iter.next();
+ cache.put(cl.getName(), cl);
+ // Add to alias cache
+ Iterator aliasIt = cl.getAlias().iterator();
+ while (aliasIt.hasNext()) {
+ String aliasName = (String) aliasIt.next();
+ if (alias.containsKey(aliasName)) {
+ throw new ConfigurationException(
+ "exception.alias.already.in.use", new String[] {
+ aliasName, cl.getName()
+ });
+ }
+ alias.put(aliasName, cl);
+ }
+ }
+ } catch (IOException e) {
+ throw new ConfigurationException(e.getLocalizedMessage());
+ } catch (SAXException e) {
+ throw new ConfigurationException(e.getLocalizedMessage());
+ }
+ }
}
Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/ConfigurationException.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/ConfigurationException.java?rev=312896&r1=312895&r2=312896&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/ConfigurationException.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/ConfigurationException.java Tue Oct 11 07:38:54 2005
@@ -21,8 +21,7 @@
/**
* This Exception is thrown when there's an error in the command config file.
*/
-public class ConfigurationException extends CommandException
-{
+public class ConfigurationException extends CommandException {
/**
* <code>serialVersionUID</code>
@@ -31,38 +30,42 @@
/**
* @param message
+ * the message
*/
- public ConfigurationException(String message)
- {
+ public ConfigurationException(String message) {
super(message);
}
/**
* @param message
+ * the message
* @param arguments
+ * the arguments
*/
- public ConfigurationException(String message, Object[] arguments)
- {
+ public ConfigurationException(String message, Object[] arguments) {
super(message, arguments);
}
/**
* @param message
+ * the message
* @param cause
+ * the arguments
*/
- public ConfigurationException(String message, Throwable cause)
- {
+ public ConfigurationException(String message, Throwable cause) {
super(message, cause);
}
/**
* @param message
+ * the message
* @param cause
+ * the cause
* @param arguments
+ * the arguments
*/
public ConfigurationException(String message, Throwable cause,
- Object[] arguments)
- {
+ Object[] arguments) {
super(message, cause, arguments);
}
}
Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/Flag.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/Flag.java?rev=312896&r1=312895&r2=312896&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/Flag.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/Flag.java Tue Oct 11 07:38:54 2005
@@ -17,51 +17,47 @@
package org.apache.jackrabbit.command.cli;
/**
- * Command line flag. A flag is a parameter that has no other value that the
- * option name. e.g. -[flag name].
+ * A command line flag <br>
+ * A flag is a parameter that has no other value that the option name. e.g.
+ * -[flag name].
*/
-public class Flag extends AbstractParameter
-{
+public class Flag extends AbstractParameter {
+ /** true if flag is present in the user's input */
private boolean present = false;
/**
- * @return Returns the present.
+ * @return true if the flag exists in the user's input
*/
- public boolean isPresent()
- {
+ public boolean isPresent() {
return present;
}
/**
* @param present
- * The present to set.
+ * the present to set
*/
- public void setPresent(boolean present)
- {
+ public void setPresent(boolean present) {
this.present = present;
}
/**
- * @inheritDoc
+ * {@inheritDoc}
*/
- public String getValue()
- {
+ public String getValue() {
return Boolean.toString(present);
}
/**
- * @inheritDoc
+ * {@inheritDoc}
*/
- public void setValue(String value)
- {
+ public void setValue(String value) {
present = Boolean.getBoolean(value);
}
/**
- * @inheritDoc
+ * {@inheritDoc}
*/
- public Object clone()
- {
+ public Object clone() {
Flag f = new Flag();
f.present = this.present;
this.clone(f);
@@ -69,31 +65,26 @@
}
/**
- * @inheritDoc
+ * {@inheritDoc}
*/
- public boolean isRequired()
- {
+ public boolean isRequired() {
return false;
}
/**
- * @inheritDoc
+ * {@inheritDoc}
*/
- public String getLocalizedArgName()
- {
+ public String getLocalizedArgName() {
return "";
}
/**
- * @inheritDoc
+ * {@inheritDoc}
*/
- public String getLocalizedDescription()
- {
- if (this.getDescription() == null)
- {
+ public String getLocalizedDescription() {
+ if (this.getDescription() == null) {
return bundle.getString("param.flag." + this.getName() + ".desc");
- } else
- {
+ } else {
return bundle.getString(this.getDescription());
}
}
Modified: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/JcrClient.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/JcrClient.java?rev=312896&r1=312895&r2=312896&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/JcrClient.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/JcrClient.java Tue Oct 11 07:38:54 2005
@@ -24,8 +24,7 @@
import java.util.ResourceBundle;
import javax.jcr.Node;
-import javax.jcr.Repository;
-import javax.jcr.Session;
+import javax.jcr.RepositoryException;
import org.apache.commons.chain.Context;
import org.apache.commons.chain.impl.ContextBase;
@@ -37,290 +36,271 @@
import org.apache.commons.cli.Parser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.command.CommandException;
import org.apache.jackrabbit.command.CommandHelper;
/**
* Command line interface client
*/
-public class JcrClient
-{
- /** logger */
- private static Log log = LogFactory.getLog(JcrClient.class);
-
- /** Resource bundle */
- private ResourceBundle bundle = CommandHelper.getBundle();
-
- /** exit control variable */
- private boolean exit = false;
-
- /** Execution context */
- private Context ctx;
-
- /** run options */
- private Options options;
-
- /**
- * Constructor
- */
- JcrClient()
- {
- super();
- ctx = new ContextBase();
- initOptions();
- initContext();
- }
-
- /**
- * Constructor
- */
- JcrClient(Context ctx)
- {
- super();
- this.ctx = ctx;
- }
-
- /**
- * @param args
- */
- public static void main(String[] args)
- {
- JcrClient client = new JcrClient();
- client.run(args);
- }
-
- /**
- * Run client
- *
- * @param args
- */
- private void run(String[] args)
- {
- try
- {
- // parse arguments
- Parser parser = new BasicParser();
- CommandLine cl = parser.parse(options, args);
-
- // Set locale
- this.setLocale(cl);
-
- // Welcome message
- System.out.println(bundle.getString("word.welcome"));
-
- // check interactive mode
- if (cl.hasOption("source"))
- {
- this.runNonInteractive(cl);
- } else
- {
- this.runInteractive(cl);
- }
- } catch (Exception e)
- {
- HelpFormatter hf = new HelpFormatter();
- hf.printHelp("jcrclient", options);
- e.printStackTrace();
- return;
- }
- }
-
- /**
- * Run in interactive mode
- *
- * @param command
- * line
- * @throws Exception
- */
- private void runInteractive(CommandLine cl) throws Exception
- {
- // Prompt command
- while (!exit)
- {
- try
- {
- System.out.print(this.getPrompt() + ">");
- // Read input
- BufferedReader br = new BufferedReader(new InputStreamReader(
- System.in));
- String input = br.readLine();
- log.debug("running: " + input);
- if (input.trim().equals("exit") || input.trim().equals("quit"))
- { // exit?
- exit = true;
- System.out.println("Good bye..");
- } else if (input.trim().length() == 0)
- {
- // Do nothing
- } else
- {
- this.runCommand(input);
- }
- } catch (JcrParserException e)
- {
- System.out.println(e.getLocalizedMessage());
- System.out.println();
- } catch (Exception e)
- {
- handleException(e);
- }
- }
- }
-
- /**
- * Run in non interactive mode
- *
- * @param command
- * line
- * @throws Exception
- */
- private void runNonInteractive(CommandLine cl) throws Exception
- {
- this.runCommand("source " + cl.getOptionValue("source"));
- }
-
- /**
- * Parses the input and runs the specified command
- *
- * @param input
- * @throws Exception
- */
- void runCommand(String input) throws Exception
- {
- if (input.startsWith("#") || input.length() == 0)
- {
- return;
- }
-
- // Process user input
- JcrParser parser = new JcrParser();
- parser.parse(input);
-
- // populate ctx
- parser.populateContext(ctx);
-
- // Execute command
- long start = System.currentTimeMillis();
- parser.getCommand().execute(ctx);
- long elapsed = System.currentTimeMillis() - start;
-
- // depopulate ctx
- parser.depopulateContext(ctx);
-
- // Display elapsed timed
- System.out.println();
- System.out.println(bundle.getString("phrase.elapsedtime") + ": "
- + elapsed + " ms.");
- System.out.println();
- }
-
- /**
- * Handle the Exception. <br>
- * Shows a short message and prompt the user to show the entire stacktrace.
- *
- * @param e
- */
- private void handleException(Exception ex)
- {
- System.out.println();
- System.out.println(bundle.getString("exception.occurred"));
- System.out.println();
- System.out.println(bundle.getString("exception") + ": "
- + ex.getClass().getName());
- System.out.println(bundle.getString("word.message") + ": "
- + ex.getLocalizedMessage());
- System.out.println();
- String prompt = bundle.getString("phrase.display.stacktrace")
- + "? [y/n]";
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- String str = "";
- int tries = 0;
- while (!str.equals("y") && !str.equals("n") && tries < 3)
- {
- tries++;
- System.out.print(prompt);
- try
- {
- str = in.readLine();
- } catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- if (str.equals("y"))
- {
- ex.printStackTrace();
- }
- }
-
- /**
- * Prompt message
- *
- * @return prompt
- * @throws Exception
- */
- private String getPrompt() throws Exception
- {
-
- Repository r = CommandHelper.getRepository(ctx);
- if (r == null)
- {
- return bundle.getString("phrase.not.connected");
- }
-
- Session s = CommandHelper.getSession(ctx);
- if (s == null)
- {
- return bundle.getString("phrase.not.logged.in");
- }
-
- Node n = CommandHelper.getCurrentNode(ctx);
-
- return n.getPath();
- }
-
- /**
- * Init allowed CommandLine options
- */
- private void initOptions()
- {
- options = new Options();
- options.addOption("lang", "code", true, "Language code");
- options.addOption("country", "code", true, "Country code");
- options.addOption("source", "path", true,
- "Script for noninteractive mode");
- }
-
- /**
- * Sets the default Locale for the given CommandLine
- *
- * @param cl
- * @throws ParseException
- */
- private void setLocale(CommandLine cl) throws ParseException
- {
- Locale locale = null;
- if (cl.hasOption("lang") && cl.hasOption("country"))
- {
- locale = new Locale(cl.getOptionValue("lang"), cl
- .getOptionValue("country"));
- }
- if (cl.hasOption("lang") && !cl.hasOption("country"))
- {
- locale = new Locale(cl.getOptionValue("lang"));
- }
- if (locale != null)
- {
- Locale.setDefault(locale);
- }
- }
-
- /**
- * Init context. <br>
- * Sets the Context Output to the console
- */
- private void initContext()
- {
- CommandHelper.setOutput(ctx, new PrintWriter(System.out, true));
- }
+public class JcrClient {
+ /** logger */
+ private static Log log = LogFactory.getLog(JcrClient.class);
+
+ /** Resource bundle */
+ private ResourceBundle bundle = CommandHelper.getBundle();
+
+ /** exit control variable */
+ private boolean exit = false;
+
+ /** Execution context */
+ private Context ctx;
+
+ /** run options */
+ private Options options;
+
+ /**
+ * Constructor
+ */
+ JcrClient() {
+ super();
+ ctx = new ContextBase();
+ initOptions();
+ initContext();
+ }
+
+ /**
+ * Constructor
+ * @param ctx
+ * the <code>Context</code>
+ */
+ JcrClient(Context ctx) {
+ super();
+ this.ctx = ctx;
+ }
+
+ /**
+ * @param args
+ * the arguments
+ */
+ public static void main(String[] args) {
+ JcrClient client = new JcrClient();
+ client.run(args);
+ }
+
+ /**
+ * Run client
+ * @param args
+ * the arguments
+ */
+ private void run(String[] args) {
+ try {
+ // parse arguments
+ Parser parser = new BasicParser();
+ CommandLine cl = parser.parse(options, args);
+
+ // Set locale
+ this.setLocale(cl);
+
+ // Welcome message
+ System.out.println(bundle.getString("word.welcome"));
+
+ // check interactive mode
+ if (cl.hasOption("source")) {
+ this.runNonInteractive(cl);
+ } else {
+ this.runInteractive(cl);
+ }
+ } catch (Exception e) {
+ HelpFormatter hf = new HelpFormatter();
+ hf.printHelp("jcrclient", options);
+ e.printStackTrace();
+ return;
+ }
+ }
+
+ /**
+ * Run in interactive mode
+ * @param cl
+ * the <code>CommandLine</code>
+ * @throws Exception
+ * if an Exception occurs
+ */
+ private void runInteractive(CommandLine cl) throws Exception {
+ // Prompt command
+ while (!exit) {
+ try {
+ System.out.print(this.getPrompt() + ">");
+ // Read input
+ BufferedReader br = new BufferedReader(new InputStreamReader(
+ System.in));
+ String input = br.readLine();
+ log.debug("running: " + input);
+ if (input.trim().equals("exit") || input.trim().equals("quit")) { // exit?
+ exit = true;
+ System.out.println("Good bye..");
+ } else if (input.trim().length() == 0) {
+ // Do nothing
+ } else {
+ this.runCommand(input);
+ }
+ } catch (JcrParserException e) {
+ System.out.println(e.getLocalizedMessage());
+ System.out.println();
+ } catch (Exception e) {
+ handleException(e);
+ }
+ }
+ }
+
+ /**
+ * Run in non interactive mode
+ * @param cl
+ * the <code>CommandLine</code>
+ * @throws Exception
+ * if an <code>Exception</code> occurs while running the
+ * <code>Command</code>
+ */
+ private void runNonInteractive(CommandLine cl) throws Exception {
+ this.runCommand("source " + cl.getOptionValue("source"));
+ }
+
+ /**
+ * Parses the input and runs the specified command
+ * @param input
+ * the user's input
+ * @throws Exception
+ * if an <code>Exception</code> occurs while running the
+ * <code>Command</code>
+ */
+ void runCommand(String input) throws Exception {
+ if (input.startsWith("#") || input.length() == 0) {
+ return;
+ }
+
+ // Process user input
+ JcrParser parser = new JcrParser();
+ parser.parse(input);
+
+ // populate ctx
+ parser.populateContext(ctx);
+
+ // Execute command
+ long start = System.currentTimeMillis();
+ parser.getCommand().execute(ctx);
+ long elapsed = System.currentTimeMillis() - start;
+
+ // depopulate ctx
+ parser.depopulateContext(ctx);
+
+ // Display elapsed timed
+ System.out.println();
+ System.out.println(bundle.getString("phrase.elapsedtime") + ": "
+ + elapsed + " ms.");
+ System.out.println();
+ }
+
+ /**
+ * Handle the Exception. <br>
+ * Shows a short message and prompt the user to show the entire stacktrace.
+ * @param ex
+ * the <code>Exception</code> to handle
+ */
+ private void handleException(Exception ex) {
+ System.out.println();
+ System.out.println(bundle.getString("exception.occurred"));
+ System.out.println();
+ System.out.println(bundle.getString("exception") + ": "
+ + ex.getClass().getName());
+ System.out.println(bundle.getString("word.message") + ": "
+ + ex.getLocalizedMessage());
+ System.out.println();
+ String prompt = bundle.getString("phrase.display.stacktrace")
+ + "? [y/n]";
+ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+ String str = "";
+ int tries = 0;
+ while (!str.equals("y") && !str.equals("n") && tries < 3) {
+ tries++;
+ System.out.print(prompt);
+ try {
+ str = in.readLine();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (str.equals("y")) {
+ ex.printStackTrace();
+ }
+ }
+
+ /**
+ * Prompt message
+ * @return prompt the prompt message
+ * @throws RepositoryException
+ * if the current <code>Repository</code> throws a
+ * <code>RepositoryException</code>
+ */
+ private String getPrompt() throws RepositoryException {
+
+ try {
+ CommandHelper.getRepository(ctx);
+ } catch (CommandException e) {
+ return bundle.getString("phrase.not.connected");
+ }
+
+ try {
+ CommandHelper.getSession(ctx);
+ } catch (CommandException e) {
+ return bundle.getString("phrase.not.logged.in");
+ }
+
+ try {
+ Node n = CommandHelper.getCurrentNode(ctx);
+ return n.getPath();
+ } catch (CommandException e) {
+ return bundle.getString("phrase.not.logged.in");
+ }
+
+ }
+
+ /**
+ * Init allowed CommandLine options
+ */
+ private void initOptions() {
+ options = new Options();
+ options.addOption("lang", "code", true, "Language code");
+ options.addOption("country", "code", true, "Country code");
+ options.addOption("source", "path", true,
+ "Script for noninteractive mode");
+ }
+
+ /**
+ * Sets the default Locale for the given CommandLine
+ * @param cl
+ * the CLI <code>CommandLine</code>
+ * @throws ParseException
+ * if cl can't be parsed
+ */
+ private void setLocale(CommandLine cl) throws ParseException {
+ Locale locale = null;
+ if (cl.hasOption("lang") && cl.hasOption("country")) {
+ locale = new Locale(cl.getOptionValue("lang"), cl
+ .getOptionValue("country"));
+ }
+ if (cl.hasOption("lang") && !cl.hasOption("country")) {
+ locale = new Locale(cl.getOptionValue("lang"));
+ }
+ if (locale != null) {
+ Locale.setDefault(locale);
+ }
+ }
+
+ /**
+ * Init context. <br>
+ * Sets the Context Output to the console
+ */
+ private void initContext() {
+ CommandHelper.setOutput(ctx, new PrintWriter(System.out, true));
+ }
}