Author: dkatayev
Date: 2009-08-27 08:31:38 -0400 (Thu, 27 Aug 2009)
New Revision: 17
Added:
jcr/trunk/build.cmd
jcr/trunk/exo-checkstyle-suppressions.xml
jcr/trunk/frameworks/
jcr/trunk/frameworks/command/
jcr/trunk/frameworks/command/pom.xml
jcr/trunk/frameworks/command/src/
jcr/trunk/frameworks/command/src/main/
jcr/trunk/frameworks/command/src/main/java/
jcr/trunk/frameworks/command/src/main/java/conf/
jcr/trunk/frameworks/command/src/main/java/conf/jcr-client-commands.xml
jcr/trunk/frameworks/command/src/main/java/conf/jcr-commands.xml
jcr/trunk/frameworks/command/src/main/java/conf/test-commands1.xml
jcr/trunk/frameworks/command/src/main/java/org/
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/AbstractCliCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/AddNodeCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/CliAppContext.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/CopyNodeCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetContextInfoCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetItemCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetNodeCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetNodesCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetPropertiesCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetPropertyCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/HelpCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/LoginCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/MoveNodeCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/ParameterNotFoundException.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/RemoveItemCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/SetPropertyCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/BasicAppContext.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/DefaultKeys.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/JCRAppContext.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/JCRCommandHelper.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/AddNodeCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetChildNodesCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetChildPropertiesCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetNodeCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetPropertyCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/RemoveItemCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/SaveCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/SetPropertyCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/ext/
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/ext/AddResourceFileCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/ext/FilterNodesByTypesCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/DisplayResourceCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/GenericWebAppContext.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/AbstractFCKConnector.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/AppConstants.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/CreateFolderCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/FCKConnectorXMLOutput.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/GetFoldersOrFilesCommand.java
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/ShowEditorCommand.java.1
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/UploadFileCommand.java
jcr/trunk/frameworks/command/src/test/
jcr/trunk/frameworks/command/src/test/java/
jcr/trunk/frameworks/command/src/test/java/conf/
jcr/trunk/frameworks/command/src/test/java/conf/standalone/
jcr/trunk/frameworks/command/src/test/java/conf/standalone/test-configuration.xml
jcr/trunk/frameworks/command/src/test/java/conf/standalone/test-jcr-framework-config.xml
jcr/trunk/frameworks/command/src/test/java/org/
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/GetNodeAsXMLCommand.java
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/TestJCRCommands.java
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/cli/
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/cli/TestJCRClientCommands.java
jcr/trunk/frameworks/command/src/test/resources/
jcr/trunk/frameworks/command/src/test/resources/login.conf
jcr/trunk/frameworks/ftpclient/
jcr/trunk/frameworks/ftpclient/pom.xml
jcr/trunk/frameworks/ftpclient/src/
jcr/trunk/frameworks/ftpclient/src/main/
jcr/trunk/frameworks/ftpclient/src/main/java/
jcr/trunk/frameworks/ftpclient/src/main/java/org/
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/FtpConst.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/FtpUtils.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/Log.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/client/
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/client/FtpClientSession.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/client/FtpClientSessionImpl.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdCdUp.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdCwd.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdDele.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdHelp.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdList.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdMkd.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdMode.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdNlst.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdNoop.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPass.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPasv.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPort.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPwd.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdQuit.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRest.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRetr.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRmd.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRnFr.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRnTo.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdSize.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdStat.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdStor.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdStru.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdSyst.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdType.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdUser.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/FtpCommand.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/FtpCommandImpl.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpDataTransiver.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpDataTransiverImpl.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpFileInfo.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpFileInfoImpl.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpSlowInputStream1.java
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpSlowOutputStream.java
jcr/trunk/frameworks/ftpclient/src/test/
jcr/trunk/frameworks/ftpclient/src/test/java/
jcr/trunk/frameworks/ftpclient/src/test/java/org/
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/FtpTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/FtpTestConfig.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/FtpTests.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/MultiThreadFtpTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/CDUPTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/CWDTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/DELETest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/HELPTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/LISTTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/MKDTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/MODETest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/NLSTTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/NOOPTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/PASVTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/PORTTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/PWDTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/QUITTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RESTTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RETRTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RMDTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RNFRTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RNTOTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/SIZETest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/STATTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/STORTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/STRUTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/SYSTTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/TYPETest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/USERPASSTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/multimulti/
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/multimulti/MultiThreadCrushTest.java
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/multimulti/TestAgent.java
jcr/trunk/frameworks/web/
jcr/trunk/frameworks/web/pom.xml
jcr/trunk/frameworks/web/src/
jcr/trunk/frameworks/web/src/main/
jcr/trunk/frameworks/web/src/main/java/
jcr/trunk/frameworks/web/src/main/java/org/
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/CommandControllerServlet.java
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/DisplayJCRContentServlet.java
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/ThreadLocalSessionProviderInitializedFilter.java
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/WebConstants.java
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/fckeditor/
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/fckeditor/FCKeditor.java
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/fckeditor/FCKeditorConfigurations.java
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/fckeditor/JCRContentFCKeditor.java
jcr/trunk/pom.xml
Log:
EXOJCR-2 jcr trunk added
Added: jcr/trunk/build.cmd
===================================================================
--- jcr/trunk/build.cmd (rev 0)
+++ jcr/trunk/build.cmd 2009-08-27 12:31:38 UTC (rev 17)
@@ -0,0 +1 @@
+@start mvn -Dmaven.test.skip=true clean install
\ No newline at end of file
Added: jcr/trunk/exo-checkstyle-suppressions.xml
===================================================================
--- jcr/trunk/exo-checkstyle-suppressions.xml (rev 0)
+++ jcr/trunk/exo-checkstyle-suppressions.xml 2009-08-27 12:31:38 UTC (rev 17)
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+<!DOCTYPE suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.0//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
+<suppressions>
+ <suppress checks="PackageHtmlCheck" files=".+[\\\/]*" />
+
+ <!--suppress checks=".*" files="DummyResponse.java"/-->
+ <!--suppress checks=".*" files=".+[\\\/]query[\\\/]"/-->
+ <!--suppress checks="NewlineAtEndOfFile"
files=".+[\\\/]*"/-->
+
+
+ <!-- RMI -->
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]iterator[\\\/]" />
+ <suppress checks=".*" files=".+[\\\/]rmi[\\\/]api[\\\/]" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]RemoteAdapterFactoryImpl.java"
/>
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerEventCollection.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerItem.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerItemDefinition.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerLock.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerNamespaceRegistry.java"
/>
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerNode.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerNodeDefinition.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerNodeType.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerNodeTypeManager.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerObject.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerObservationManager.java"
/>
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerProperty.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerPropertyDefinition.java"
/>
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerQuery.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerQueryManager.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerQueryResult.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerRepository.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerRow.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerSession.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerVersion.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerVersionHistory.java" />
+ <suppress checks=".*"
files=".+[\\\/]rmi[\\\/]impl[\\\/]server[\\\/]ServerWorkspace.java" />
+
+ <!-- CORE -->
+ <suppress checks=".*" files=".+[\\\/]query[\\\/]" />
+ <suppress checks="MagicNumberCheck"
files=".+[\\\/]jcr[\\\/]impl[\\\/]xml[\\\/]XMLChar.java" />
+
+
+ <!-- WebDAV -->
+ <suppress checks="MagicNumberCheck"
files=".+[\\\/]jcr[\\\/]webdav[\\\/]lnkproducer[\\\/]LinkGenerator.java" />
+
+
+</suppressions>
Added: jcr/trunk/frameworks/command/pom.xml
===================================================================
--- jcr/trunk/frameworks/command/pom.xml (rev 0)
+++ jcr/trunk/frameworks/command/pom.xml 2009-08-27 12:31:38 UTC (rev 17)
@@ -0,0 +1,89 @@
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>config</artifactId>
+ <version>1.12-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>exo.jcr.framework.command</artifactId>
+
+ <name>eXo JCR :: Framework :: Command</name>
+ <description>eXo JCR command framework</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.component.core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.component.ext</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.command</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-fileupload</groupId>
+ <artifactId>commons-fileupload</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/TestJCRCommands.java</include>
+ <include>**/cli/Test*.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+</project>
Added: jcr/trunk/frameworks/command/src/main/java/conf/jcr-client-commands.xml
===================================================================
--- jcr/trunk/frameworks/command/src/main/java/conf/jcr-client-commands.xml
(rev 0)
+++ jcr/trunk/frameworks/command/src/main/java/conf/jcr-client-commands.xml 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,49 @@
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+<catalog name="CLI">
+ <!--JCR client commands-->
+ <command name="addnode"
className="org.exoplatform.frameworks.jcr.cli.AddNodeCommand" />
+ <command name="mkdir"
className="org.exoplatform.frameworks.jcr.cli.AddNodeCommand" />
+ <command name="login"
className="org.exoplatform.frameworks.jcr.cli.LoginCommand" />
+ <command name="getitem"
className="org.exoplatform.frameworks.jcr.cli.GetItemCommand" />
+ <command name="cd"
className="org.exoplatform.frameworks.jcr.cli.GetItemCommand" />
+ <command name="getnode"
className="org.exoplatform.frameworks.jcr.cli.GetNodeCommand" />
+ <command name="cdn"
className="org.exoplatform.frameworks.jcr.cli.GetNodeCommand" />
+ <command name="getproperty"
className="org.exoplatform.frameworks.jcr.cli.GetPropertyCommand" />
+ <command name="cdp"
className="org.exoplatform.frameworks.jcr.cli.GetPropertyCommand" />
+ <command name="getnodes"
className="org.exoplatform.frameworks.jcr.cli.GetNodesCommand" />
+ <command name="lsn"
className="org.exoplatform.frameworks.jcr.cli.GetNodesCommand" />
+ <command name="getproperties"
className="org.exoplatform.frameworks.jcr.cli.GetPropertiesCommand" />
+ <command name="lsp"
className="org.exoplatform.frameworks.jcr.cli.GetPropertiesCommand" />
+ <command name="ls"
className="org.exoplatform.frameworks.jcr.cli.GetNodesCommand" />
+ <command name="setproperty"
className="org.exoplatform.frameworks.jcr.cli.SetPropertyCommand" />
+ <command name="setp"
className="org.exoplatform.frameworks.jcr.cli.SetPropertyCommand" />
+ <command name="getcontextinfo"
className="org.exoplatform.frameworks.jcr.cli.GetContextInfoCommand" />
+ <command name="info"
className="org.exoplatform.frameworks.jcr.cli.GetContextInfoCommand" />
+ <command name="remove"
className="org.exoplatform.frameworks.jcr.cli.RemoveItemCommand" />
+ <command name="rem"
className="org.exoplatform.frameworks.jcr.cli.RemoveItemCommand" />
+ <command name="copynode"
className="org.exoplatform.frameworks.jcr.cli.CopyNodeCommand" />
+ <command name="copy"
className="org.exoplatform.frameworks.jcr.cli.CopyNodeCommand" />
+ <command name="movenode"
className="org.exoplatform.frameworks.jcr.cli.MoveNodeCommand" />
+ <command name="move"
className="org.exoplatform.frameworks.jcr.cli.MoveNodeCommand" />
+ <command name="help"
className="org.exoplatform.frameworks.jcr.cli.HelpCommand" />
+ <command name="man"
className="org.exoplatform.frameworks.jcr.cli.HelpCommand" />
+</catalog>
Added: jcr/trunk/frameworks/command/src/main/java/conf/jcr-commands.xml
===================================================================
--- jcr/trunk/frameworks/command/src/main/java/conf/jcr-commands.xml
(rev 0)
+++ jcr/trunk/frameworks/command/src/main/java/conf/jcr-commands.xml 2009-08-27 12:31:38
UTC (rev 17)
@@ -0,0 +1,31 @@
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+<catalog>
+ <!-- Core JCR commands -->
+ <command name="addNode"
className="org.exoplatform.frameworks.jcr.command.core.AddNodeCommand" />
+ <command name="save"
className="org.exoplatform.frameworks.jcr.command.core.SaveCommand" />
+ <command name="setProperty"
className="org.exoplatform.frameworks.jcr.command.core.SetPropertyCommand"
/>
+ <command name="remove"
className="org.exoplatform.frameworks.jcr.command.core.RemoveItemCommand" />
+ <command name="getProperty"
className="org.exoplatform.frameworks.jcr.command.core.GetPropertyCommand"
/>
+ <command name="getNode"
className="org.exoplatform.frameworks.jcr.command.core.GetNodeCommand" />
+ <command name="getNodes"
className="org.exoplatform.frameworks.jcr.command.core.GetChildNodesCommand"
/>
+ <command name="getProperties"
className="org.exoplatform.frameworks.jcr.command.core.GetChildPropertiesCommand"
/>
+</catalog>
Added: jcr/trunk/frameworks/command/src/main/java/conf/test-commands1.xml
===================================================================
--- jcr/trunk/frameworks/command/src/main/java/conf/test-commands1.xml
(rev 0)
+++ jcr/trunk/frameworks/command/src/main/java/conf/test-commands1.xml 2009-08-27 12:31:38
UTC (rev 17)
@@ -0,0 +1,48 @@
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+<catalog>
+ <!-- Core JCR commands -->
+ <command name="addNode"
className="org.exoplatform.frameworks.jcr.command.core.AddNodeCommand" />
+ <command name="save"
className="org.exoplatform.frameworks.jcr.command.core.SaveCommand" />
+ <command name="setProperty"
className="org.exoplatform.frameworks.jcr.command.core.SetPropertyCommand"
/>
+ <command name="remove"
className="org.exoplatform.frameworks.jcr.command.core.RemoveItemCommand" />
+ <command name="getProperty"
className="org.exoplatform.frameworks.jcr.command.core.GetPropertyCommand"
/>
+ <command name="getNode"
className="org.exoplatform.frameworks.jcr.command.core.GetNodeCommand" />
+ <command name="getNodes"
className="org.exoplatform.frameworks.jcr.command.core.GetChildNodesCommand"
/>
+ <command name="getProperties"
className="org.exoplatform.frameworks.jcr.command.core.GetChildPropertiesCommand"
/>
+
+
+ <command name="filterNodesByTypes"
className="org.exoplatform.frameworks.jcr.command.ext.FilterNodesByTypesCommand"
/>
+ <command name="addResourceFile"
className="org.exoplatform.frameworks.jcr.command.ext.AddResourceFileCommand"
/>
+
+
+ <!-- Chains with nested commands -->
+ <chain name="retrieveNodeCommand">
+ <command id="1"
className="org.exoplatform.frameworks.jcr.command.core.GetNodeCommand" />
+ <command id="2"
className="org.exoplatform.frameworks.jcr.command.GetNodeAsXMLCommand" />
+ </chain>
+
+ <chain name="displayResource">
+ <command id="1"
className="org.exoplatform.frameworks.jcr.command.core.GetNodeCommand" />
+ <command id="2"
className="org.exoplatform.frameworks.jcr.command.web.DisplayResourceCommand"
/>
+ </chain>
+
+</catalog>
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/AbstractCliCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/AbstractCliCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/AbstractCliCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Gennady Azarenkov
+ * @version $Id: $
+ */
+
+public abstract class AbstractCliCommand implements Command
+{
+
+ public final boolean execute(Context ctx) throws Exception
+ {
+ CliAppContext cliCtx = (CliAppContext)ctx;
+ cliCtx.clearOutput();
+ boolean result = perform(cliCtx);
+ return result;
+ }
+
+ public abstract boolean perform(CliAppContext ctx) throws Exception;
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/AddNodeCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/AddNodeCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/AddNodeCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import javax.jcr.Node;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author Vitaliy Obmanjuk
+ * @version $Id: $
+ */
+
+public class AddNodeCommand extends AbstractCliCommand
+{
+
+ public boolean perform(CliAppContext ctx)
+ {
+ String output = "";
+ try
+ {
+ int parametersCount = ctx.getParameters().size();
+ String nodeName = ctx.getParameter(0);
+ // String nodeType = ctx.getParameter(1);
+ String nodeType = parametersCount == 2 ? ctx.getParameter(1) : null;
+ Node curNode = (Node)ctx.getCurrentItem();
+ Node newNode = null;
+ if (nodeType == null)
+ {
+ newNode = curNode.addNode(nodeName);
+ }
+ else
+ {
+ newNode = curNode.addNode(nodeName, nodeType);
+ }
+ ctx.getSession().save();
+ ctx.setCurrentItem(newNode);
+ output = "Node: " + newNode.getPath() + " created succesfully
\n";
+ }
+ catch (Exception e)
+ {
+ output = "Can't execute command - " + e.getMessage() +
"\n";
+ }
+ ctx.setOutput(output);
+ return false;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/CliAppContext.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/CliAppContext.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/CliAppContext.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import org.exoplatform.frameworks.jcr.command.BasicAppContext;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+
+import java.util.List;
+
+import javax.jcr.Credentials;
+import javax.jcr.Item;
+import javax.naming.NamingException;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Gennady Azarenkov
+ * @version $Id: $
+ */
+
+public class CliAppContext extends BasicAppContext
+{
+
+ protected final String currentItemKey = "CURRENT_ITEM";
+
+ protected final String parametersKey;
+
+ protected final String outputKey = "OUTPUT";
+
+ public CliAppContext(ManageableRepository rep, String parametersKey) throws
NamingException
+ {
+ super(rep);
+ this.parametersKey = parametersKey;
+ }
+
+ @Deprecated
+ public CliAppContext(ManageableRepository rep, String parametersKey, Credentials cred)
throws NamingException
+ {
+ super(rep);
+ this.parametersKey = parametersKey;
+ }
+
+ public String getUserName()
+ {
+ try
+ {
+ return getSession().getUserID();
+ }
+ catch (Exception e)
+ {
+ log.error("GetUserName error: " + e);
+ return "Undefined";
+ }
+ }
+
+ public String getCurrentWorkspace()
+ {
+ return currentWorkspace;
+ }
+
+ public List<String> getParameters()
+ {
+ return (List<String>)get(parametersKey);
+ }
+
+ public String getParameter(int index) throws ParameterNotFoundException
+ {
+ List<String> params = getParameters();
+ if (params.size() <= index)
+ throw new ParameterNotFoundException("Not enough number of parameters
expected at least: " + (index + 1)
+ + " found: " + params.size());
+ return params.get(index);
+ }
+
+ public void setCurrentItem(Item item)
+ {
+ put(currentItemKey, item);
+ }
+
+ public Item getCurrentItem()
+ {
+ return (Item)get(currentItemKey);
+ }
+
+ public String getOutput()
+ {
+ return (String)get(outputKey);
+ }
+
+ public void setOutput(String output)
+ {
+ put(outputKey, output);
+ }
+
+ public void clearOutput()
+ {
+ put(outputKey, "");
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/CopyNodeCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/CopyNodeCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/CopyNodeCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import javax.jcr.Workspace;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author Vitaliy Obmanjuk
+ * @version $Id: $
+ */
+
+public class CopyNodeCommand extends AbstractCliCommand
+{
+
+ public boolean perform(CliAppContext ctx)
+ {
+ String output = "";
+ try
+ {
+ String srcAbsPath = ctx.getParameter(0);
+ String destAbsPath = ctx.getParameter(1);
+ Workspace workspace = ctx.getSession().getWorkspace();
+ workspace.copy(srcAbsPath, destAbsPath);
+ output = "Node [" + srcAbsPath + "] has been copied to [" +
destAbsPath + "] successfully \n";
+ }
+ catch (Exception e)
+ {
+ output = "Can't execute command - " + e.getMessage() +
"\n";
+ }
+ ctx.setOutput(output);
+ return false;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetContextInfoCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetContextInfoCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetContextInfoCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+import org.exoplatform.services.jcr.impl.core.PropertyImpl;
+
+import java.util.Iterator;
+
+import javax.jcr.Item;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.nodetype.ItemDefinition;
+import javax.jcr.nodetype.PropertyDefinition;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author Vitaliy Obmanjuk
+ * @version $Id: $
+ */
+
+public class GetContextInfoCommand extends AbstractCliCommand
+{
+
+ public boolean perform(CliAppContext ctx)
+ {
+ String output = "";
+ try
+ {
+ output = "Context info: \n";
+ Item item = ctx.getCurrentItem();
+ ItemDefinition itemDefinition;
+ if (item.isNode())
+ {
+ itemDefinition = ((NodeImpl)item).getDefinition();
+ }
+ else
+ {
+ itemDefinition = ((PropertyImpl)item).getDefinition();
+ }
+ output += "username: " + ctx.getUserName() + "\n";
+ output += "workspace: " + ctx.getCurrentWorkspace() + "\n";
+ output += "item path: " + item.getPath() + "\n";
+ String itemType = item.isNode() ? "Node" : "Property";
+ output += "item type: " + itemType + "\n";
+ output += "item definitions:\n";
+ output += " name: " + itemDefinition.getName() + "\n";
+ output += " autocreated:" + itemDefinition.isAutoCreated() +
"\n";
+ output += " mandatory:" + itemDefinition.isMandatory() +
"\n";
+ output += " protected:" + itemDefinition.isProtected() +
"\n";
+ output += " onparentversion:" + itemDefinition.getOnParentVersion() +
"\n";
+ if (item.isNode() == false)
+ {
+ Property property = (Property)item;
+ int propertyType = property.getValue().getType();
+ if (propertyType != (PropertyType.BINARY))
+ {
+ PropertyDefinition propertyDefinition =
(PropertyDefinition)itemDefinition;
+ if (propertyDefinition.isMultiple() == false)
+ {
+ output += "property value:" + property.getValue().getString()
+ "\n";
+ }
+ else
+ {
+ output += "property value is multiple" + "\n";
+ }
+ }
+ else
+ {
+ output += "can't show property value:" + "\n";
+ }
+ }
+ output += "parameters:\n";
+ Iterator parametersIterator = ctx.getParameters().iterator();
+ int i = 0;
+ while (parametersIterator.hasNext())
+ {
+ output += " [" + i + "]" + " : " +
(String)parametersIterator.next() + "\n";
+ i++;
+ }
+ }
+ catch (Exception e)
+ {
+ output = "Can't execute command - " + e.getMessage() +
"\n";
+ }
+ ctx.setOutput(output);
+ return false;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetItemCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetItemCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetItemCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author Vitaliy Obmanjuk
+ * @version $Id: $
+ */
+
+public class GetItemCommand extends AbstractCliCommand
+{
+
+ @Override
+ public boolean perform(CliAppContext ctx)
+ {
+ String output = "";
+ try
+ {
+ String path = ctx.getParameter(0);
+ Item resultItem = null;
+ if (path.equals(".."))
+ {
+ Item currentItem = ctx.getCurrentItem();
+ resultItem = currentItem.getParent();
+ }
+ else
+ {
+ // here we need to analize what kind of the path we have: relPath or
+ // absPath
+ if (path.startsWith("/"))
+ {// absPath
+ resultItem = ctx.getSession().getItem(path);
+ }
+ else
+ {// relPath
+ if (ctx.getCurrentItem().isNode())
+ {
+ Node node = (Node)ctx.getCurrentItem();
+ resultItem = node.getNode(path);
+ }
+ else
+ {// do nothing
+ resultItem = ctx.getCurrentItem();
+ }
+ }
+ }
+ ctx.setCurrentItem(resultItem);
+ output = "Current item: " + ctx.getCurrentItem().getPath() +
"\n";
+ }
+ catch (Exception e)
+ {
+ output = "Can't execute command - " + e.getMessage() +
"\n";
+ }
+ ctx.setOutput(output);
+ return false;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetNodeCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetNodeCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetNodeCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import javax.jcr.Node;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author Vitaliy Obmanjuk
+ * @version $Id: $
+ */
+
+public class GetNodeCommand extends AbstractCliCommand
+{
+
+ @Override
+ public boolean perform(CliAppContext ctx)
+ {
+ String output = "";
+ try
+ {
+ String relPath = ctx.getParameter(0);
+ Node currentNode = (Node)ctx.getCurrentItem();
+ Node resultNode = currentNode.getNode(relPath);
+ ctx.setCurrentItem(resultNode);
+ output = "Current node: " + resultNode.getPath() + "\n";
+ }
+ catch (Exception e)
+ {
+ output = "Can't execute command - " + e.getMessage() +
"\n";
+ }
+ ctx.setOutput(output);
+ return false;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetNodesCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetNodesCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetNodesCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author Vitaliy Obmanjuk
+ * @version $Id: $
+ */
+
+public class GetNodesCommand extends AbstractCliCommand
+{
+
+ @Override
+ public boolean perform(CliAppContext ctx)
+ {
+ String output = "";
+ try
+ {
+ if (ctx.getCurrentItem().isNode())
+ {
+ Node currentNode = (Node)ctx.getCurrentItem();
+ PropertyIterator propertyIterator = currentNode.getProperties();
+ output += "Properties list for " + currentNode.getPath() +
":\n";
+ while (propertyIterator.hasNext())
+ {
+ Property property = propertyIterator.nextProperty();
+ output += property.getName() + "\n";
+ }
+ NodeIterator nodeIterator = currentNode.getNodes();
+ output += "Nodes list for " + currentNode.getPath() +
":\n";
+ while (nodeIterator.hasNext())
+ {
+ Node node = nodeIterator.nextNode();
+ output += node.getPath() + "\n";
+ }
+ }
+ else
+ {
+ output += "Current item is property: " +
((Property)ctx.getCurrentItem()).getName() + "\n";
+ }
+ }
+ catch (Exception e)
+ {
+ output = "Can't execute command - " + e.getMessage() +
"\n";
+ }
+ ctx.setOutput(output);
+ return false;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetPropertiesCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetPropertiesCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetPropertiesCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author Vitaliy Obmanjuk
+ * @version $Id: $
+ */
+
+public class GetPropertiesCommand extends AbstractCliCommand
+{
+
+ @Override
+ public boolean perform(CliAppContext ctx)
+ {
+ String output = "";
+ try
+ {
+ Node currentNode = (Node)ctx.getCurrentItem();
+ PropertyIterator propertyIterator = currentNode.getProperties();
+ output = "Properties:\n";
+ while (propertyIterator.hasNext())
+ {
+ Property property = propertyIterator.nextProperty();
+ output += property.getName() + "\n";
+ }
+ }
+ catch (Exception e)
+ {
+ output = "Can't execute command - " + e.getMessage() +
"\n";
+ }
+ ctx.setOutput(output);
+ return false;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetPropertyCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetPropertyCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/GetPropertyCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author Vitaliy Obmanjuk
+ * @version $Id: $
+ */
+
+public class GetPropertyCommand extends AbstractCliCommand
+{
+
+ @Override
+ public boolean perform(CliAppContext ctx)
+ {
+ String output = "";
+ try
+ {
+ String relPath = ctx.getParameter(0);
+ Node currentNode = (Node)ctx.getCurrentItem();
+ Property resultProperty = currentNode.getProperty(relPath);
+ ctx.setCurrentItem(resultProperty);
+ try
+ {
+ output = "Current property value: " +
resultProperty.getValue().getString() + "\n";
+ }
+ catch (Exception e)
+ {
+ output = "Can't display the property value";
+ }
+ }
+ catch (Exception e)
+ {
+ output = "Can't execute command - " + e.getMessage() +
"\n";
+ }
+ ctx.setOutput(output);
+ return false;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/HelpCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/HelpCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/HelpCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.TreeMap;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author Vitaliy Obmanjuk
+ * @version $Id: $
+ */
+
+public class HelpCommand extends AbstractCliCommand
+{
+
+ private TreeMap<String, String> map = new TreeMap<String, String>();
+
+ private final int WORD_LENGTH = 15;
+
+ public HelpCommand()
+ {
+ map.put("addnode", "<name>, <type> add node as child
node of current node");
+ map.put("mkdir", "<name>, <type> add node as child node
of current node");
+ map.put("login", "[<workspace name>] login to
workspace");
+ map.put("getitem", "<absPath> or <relPath> or <..>
change the current item");
+ map.put("cd", "<absPath> or <relPath> or < ..>
change the current item, node names should not contain spaces");
+ map.put("getnode", "<relPath> change the current node");
+ map.put("cdn", "<relPath> change the current node");
+ map.put("getproperty", "<relPath> change the current
property");
+ map.put("cdp", "<relPath> change the current property");
+ map.put("getnodes", "<> get the list of nodes");
+ map.put("lsn", "<> get the list of nodes");
+ map.put("getproperties", "<> get the list of
properties");
+ map.put("lsp", "<> get the list of properties");
+ map.put("ls", "<> get the list of the nodes and
properties");
+ map.put("setproperty", "<name>, <value>, <type>
set the property");
+ map.put("setp", "<name>, <value>, <type> set the
property");
+ map.put("getcontextinfo", "<> show the info of the current
context");
+ map.put("info", "<> show the info of the current
context");
+ map.put("remove", "<> remove the current item and go to parent
item");
+ map.put("rem", "<> remove the current item and go to parent
item");
+ map.put("copynode", "<srcAbsPath>, <destAbsPath> copy
the node at srcAbsPath to the new location at destAbsPath");
+ map.put("copy", "<srcAbsPath>, <destAbsPath> copy the
node at srcAbsPath to the new location at destAbsPath");
+ map.put("movenode", "<srcAbsPath>, <destAbsPath> move
the node at srcAbsPath to the new location at destAbsPath");
+ map.put("move", "<srcAbsPath>, <destAbsPath> move the
node at srcAbsPath to the new location at destAbsPath");
+ map
+ .put(
+ "|",
+ "<console size> limit the count of lines to output, e.g. |20 will
displayed only 20 lines, works in standalone mode only");
+ }
+
+ @Override
+ public boolean perform(CliAppContext ctx)
+ {
+ String output = "";
+ try
+ {
+ String findHelpCommand = null;
+ try
+ {
+ findHelpCommand = ctx.getParameter(0);
+ }
+ catch (Exception e)
+ {
+ // no parameters found
+ }
+ if (findHelpCommand != null)
+ {
+ Set keys = map.keySet();
+ Iterator iterator = keys.iterator();
+ boolean found = false;
+ while (iterator.hasNext())
+ {
+ String currentHelpCommand = (String)(iterator.next());
+ if (findHelpCommand.equals(currentHelpCommand))
+ {
+ // begin format output string (adding spaces)
+ String findHelpCommandFormatted = currentHelpCommand;
+ int commandLength = currentHelpCommand.length();
+ if (commandLength < WORD_LENGTH)
+ {
+ for (int i = currentHelpCommand.length(); i < WORD_LENGTH; i++)
+ {
+ findHelpCommandFormatted += " ";
+ }
+ }
+ // end format
+ output += findHelpCommandFormatted + " - " +
map.get(findHelpCommand) + "\n";
+ found = true;
+ break;
+ }
+ }
+ if (found == false)
+ {
+ output += "Can't find help for the: " + findHelpCommand +
" command\n";
+ }
+ }
+ else
+ {
+ Set keys = map.keySet();
+ Iterator iterator = keys.iterator();
+ while (iterator.hasNext())
+ {
+ String currentHelpCommand = (String)(iterator.next());
+ // begin format output string (adding spaces)
+ String currentHelpCommandFormatted = currentHelpCommand;
+ int commandLength = currentHelpCommand.length();
+ if (commandLength < WORD_LENGTH)
+ {
+ for (int i = currentHelpCommand.length(); i < WORD_LENGTH; i++)
+ {
+ currentHelpCommandFormatted += " ";
+ }
+ }
+ // end format
+ output += currentHelpCommandFormatted + " - " +
map.get(currentHelpCommand) + "\n";
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ output = "Can't execute command - " + e.getMessage() +
"\n";
+ }
+ ctx.setOutput(output);
+ return false;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/LoginCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/LoginCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/LoginCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import javax.jcr.Node;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author Vitaliy Obmanjuk
+ * @version $Id: $
+ */
+
+public class LoginCommand extends AbstractCliCommand
+{
+
+ @Override
+ public boolean perform(CliAppContext ctx)
+ {
+ String output = "";
+ try
+ {
+ String workspace = null;
+ if (ctx.getParameters().size() >= 1)
+ { // ws parameter is present
+ workspace = ctx.getParameter(0);
+ }
+ else
+ {
+ workspace = ctx.getSession().getWorkspace().getName();
+ }
+ // ctx.getSession().getRepository().login(workspace);
+ ctx.setCurrentWorkspace(workspace);
+ Node root = ctx.getSession().getRootNode();
+ output = "Successfully logged into workspace " + workspace + " as
" + ctx.getSession().getUserID() + "\n";
+ ctx.setCurrentItem(root);
+ }
+ catch (Exception e)
+ {
+ // e.printStackTrace();
+ output = "Can't execute command - " + e.getMessage() +
"\n";
+ }
+ ctx.setOutput(output);
+ return false;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/MoveNodeCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/MoveNodeCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/MoveNodeCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import javax.jcr.Workspace;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author Vitaliy Obmanjuk
+ * @version $Id: $
+ */
+
+public class MoveNodeCommand extends AbstractCliCommand
+{
+
+ public boolean perform(CliAppContext ctx)
+ {
+ String output = "";
+ try
+ {
+ String srcAbsPath = ctx.getParameter(0);
+ String destAbsPath = ctx.getParameter(1);
+ Workspace workspace = ctx.getSession().getWorkspace();
+ workspace.move(srcAbsPath, destAbsPath);
+ output = "Node [" + srcAbsPath + "] has been moved to [" +
destAbsPath + "] successfully \n";
+ }
+ catch (Exception e)
+ {
+ output = "Can't execute command - " + e.getMessage() +
"\n";
+ }
+ ctx.setOutput(output);
+ return false;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/ParameterNotFoundException.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/ParameterNotFoundException.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/ParameterNotFoundException.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Gennady Azarenkov
+ * @version $Id: $
+ */
+
+public class ParameterNotFoundException extends Exception
+{
+
+ public ParameterNotFoundException()
+ {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public ParameterNotFoundException(String arg0, Throwable arg1)
+ {
+ super(arg0, arg1);
+ // TODO Auto-generated constructor stub
+ }
+
+ public ParameterNotFoundException(String arg0)
+ {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+ public ParameterNotFoundException(Throwable arg0)
+ {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/RemoveItemCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/RemoveItemCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/RemoveItemCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import javax.jcr.Item;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author Vitaliy Obmanjuk
+ * @version $Id: $
+ */
+
+public class RemoveItemCommand extends AbstractCliCommand
+{
+
+ public boolean perform(CliAppContext ctx)
+ {
+ String output = "";
+ try
+ {
+ Item currentItem = ctx.getCurrentItem();
+ Item parentItem = currentItem.getParent();
+ currentItem.remove();
+ ctx.getSession().save();
+ output = "Item " + currentItem.getPath() + " removed succesfully
\n";
+ ctx.setCurrentItem(parentItem);
+ output = "Current item: " + ctx.getCurrentItem().getPath() +
"\n";
+ }
+ catch (Exception e)
+ {
+ output = "Can't execute command - " + e.getMessage() +
"\n";
+ }
+ ctx.setOutput(output);
+ return false;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/SetPropertyCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/SetPropertyCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/cli/SetPropertyCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.cli;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author Vitaliy Obmanjuk
+ * @version $Id: $
+ */
+
+public class SetPropertyCommand extends AbstractCliCommand
+{
+
+ public boolean perform(CliAppContext ctx)
+ {
+ String output = "";
+ try
+ {
+ int parametersCount = ctx.getParameters().size();
+ String propertyName = ctx.getParameter(0);
+ String propertyValue = ctx.getParameter(1);
+ String propertyType = parametersCount == 3 ? ctx.getParameter(2) : null;
+ Node node = (Node)ctx.getCurrentItem();
+ Property property = null;
+ if (propertyType == null)
+ {
+ property = node.setProperty(propertyName, propertyValue);
+ }
+ else
+ {
+ int correctPropertyType = new Integer(propertyType);
+ property = node.setProperty(propertyName, propertyValue,
correctPropertyType);
+ }
+ ctx.getSession().save();
+ output = "Property: " + propertyName + " , " + propertyValue
+ " created succesfully \n";
+ ctx.setCurrentItem(property);
+ }
+ catch (Exception e)
+ {
+ output = "Can't execute command - " + e.getMessage() +
"\n";
+ }
+ ctx.setOutput(output);
+ return false;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/BasicAppContext.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/BasicAppContext.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/BasicAppContext.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command;
+
+import org.apache.commons.chain.impl.ContextBase;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.common.SessionProvider;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.security.ConversationState;
+
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.naming.NamingException;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: BasicAppContext.java 10160 2006-11-08 09:14:24Z geaz $
+ */
+
+public class BasicAppContext extends ContextBase implements JCRAppContext
+{
+
+ protected static Log log = ExoLogger.getLogger("jcr.BasicAppContext");
+
+ protected final SessionProvider sessionProvider;
+
+ protected final ManageableRepository repository;
+
+ protected String currentWorkspace;
+
+ public BasicAppContext(ManageableRepository rep) throws NamingException
+ {
+ this.sessionProvider = new SessionProvider(ConversationState.getCurrent());
+ this.repository = rep;
+ this.currentWorkspace = rep.getConfiguration().getDefaultWorkspaceName();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.exoplatform.frameworks.jcr.command.JCRAppContext#getSession()
+ */
+ public Session getSession() throws LoginException, NoSuchWorkspaceException,
RepositoryException
+ {
+ return sessionProvider.getSession(currentWorkspace, repository);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.exoplatform.frameworks.jcr.command.JCRAppContext#setCurrentWorkspace(java.lang.String)
+ */
+ public void setCurrentWorkspace(String workspaceName)
+ {
+ this.currentWorkspace = workspaceName;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/DefaultKeys.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/DefaultKeys.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/DefaultKeys.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: DefaultKeys.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public interface DefaultKeys
+{
+
+ // public static final String COMMAND = "command";
+
+ public static final String PATH = "path";
+
+ public static final String WORKSPACE = "workspace";
+
+ public static final String NODE_TYPE = "nodeType";
+
+ public static final String RESULT = "result";
+
+ public static final String CURRENT_NODE = "currentNode";
+
+ public static final String NAME = "name";
+
+ public static final String PROPERTY_TYPE = "propertyType";
+
+ public static final String VALUES = "values";
+
+ public static final String MULTI_VALUED = "multiValued";
+
+ public static final String[] JCR_KEYS = {PATH, WORKSPACE, NODE_TYPE, RESULT,
CURRENT_NODE};
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/JCRAppContext.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/JCRAppContext.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/JCRAppContext.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command;
+
+import org.apache.commons.chain.Context;
+
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: JCRAppContext.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public interface JCRAppContext extends Context
+{
+
+ /**
+ * Change current workspace name.
+ *
+ * @param workspaceName
+ */
+ void setCurrentWorkspace(String workspaceName);
+
+ /**
+ * Return Session of the context.
+ *
+ * @return the session
+ * @throws LoginException
+ * @throws NoSuchWorkspaceException
+ * @throws RepositoryException
+ */
+ Session getSession() throws LoginException, NoSuchWorkspaceException,
RepositoryException;
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/JCRCommandHelper.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/JCRCommandHelper.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/JCRCommandHelper.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command;
+
+import java.io.InputStream;
+import java.util.Calendar;
+
+import javax.jcr.Item;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author Gennady Azarenkov
+ * @version $Id: JCRCommandHelper.java 9857 2006-10-28 20:49:03Z geaz $
+ */
+
+public class JCRCommandHelper
+{
+
+ /**
+ * creates nt:file node and fills it with incoming data
+ *
+ * @param parentNode
+ * @param relPath
+ * @param data
+ * @param mimeType
+ * @return
+ * @throws Exception
+ */
+ public static Node createResourceFile(Node parentNode, String relPath, Object data,
String mimeType)
+ throws Exception
+ {
+
+ Node file = parentNode.addNode(relPath, "nt:file");
+ Node contentNode = file.addNode("jcr:content", "nt:resource");
+
+ if (data instanceof InputStream)
+ contentNode.setProperty("jcr:data", (InputStream)data);
+ else if (data instanceof String)
+ contentNode.setProperty("jcr:data", (String)data);
+ // else if(data instanceof BinaryValue)
+ // contentNode.setProperty("jcr:data", (BinaryValue)data);
+ else
+ throw new Exception("Invalid object for jcr:data " + data);
+
+ contentNode.setProperty("jcr:mimeType", mimeType);
+ contentNode.setProperty("jcr:lastModified", Calendar.getInstance());
+ return file;
+
+ }
+
+ /**
+ * traverses incoming node trying to find primary nt:resource node
+ *
+ * @param node
+ * @return nt:resource node
+ * @throws ItemNotFoundException
+ * if no such node found
+ * @throws RepositoryException
+ */
+ public static Node getNtResourceRecursively(Node node) throws ItemNotFoundException,
RepositoryException
+ {
+
+ if (node.isNodeType("nt:resource"))
+ return node;
+
+ Item pi = node.getPrimaryItem();
+ if (pi.isNode())
+ {
+ return getNtResourceRecursively((Node)pi);
+ }
+ throw new ItemNotFoundException("No nt:resource node found for " +
node.getPath());
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/AddNodeCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/AddNodeCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/AddNodeCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.core;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.frameworks.jcr.command.DefaultKeys;
+import org.exoplatform.frameworks.jcr.command.JCRAppContext;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: AddNodeCommand.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public class AddNodeCommand implements Command
+{
+
+ private String pathKey = DefaultKeys.PATH;
+
+ private String currentNodeKey = DefaultKeys.CURRENT_NODE;
+
+ private String resultKey = DefaultKeys.RESULT;
+
+ private String nodeTypeKey = DefaultKeys.NODE_TYPE;
+
+ public boolean execute(Context context) throws Exception
+ {
+
+ Session session = ((JCRAppContext)context).getSession();
+
+ Node parentNode = (Node)session.getItem((String)context.get(currentNodeKey));
+ String relPath = (String)context.get(pathKey);
+ if (context.containsKey(nodeTypeKey))
+ context.put(resultKey, parentNode.addNode(relPath,
(String)context.get(nodeTypeKey)));
+ else
+ context.put(resultKey, parentNode.addNode(relPath));
+
+ return true;
+ }
+
+ public String getResultKey()
+ {
+ return resultKey;
+ }
+
+ public String getCurrentNodeKey()
+ {
+ return currentNodeKey;
+ }
+
+ public String getNodeTypeKey()
+ {
+ return nodeTypeKey;
+ }
+
+ public String getPathKey()
+ {
+ return pathKey;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetChildNodesCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetChildNodesCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetChildNodesCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.core;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.frameworks.jcr.command.DefaultKeys;
+import org.exoplatform.frameworks.jcr.command.JCRAppContext;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Session;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: GetChildNodesCommand.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public class GetChildNodesCommand implements Command
+{
+
+ private String currentNodeKey = DefaultKeys.CURRENT_NODE;
+
+ private String resultKey = DefaultKeys.RESULT;
+
+ public boolean execute(Context context) throws Exception
+ {
+ Session session = ((JCRAppContext)context).getSession();
+ Node curNode = (Node)session.getItem((String)context.get(currentNodeKey));
+ NodeIterator nodes = curNode.getNodes();
+ context.put(resultKey, nodes);
+ return true;
+ }
+
+ public String getResultKey()
+ {
+ return resultKey;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetChildPropertiesCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetChildPropertiesCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetChildPropertiesCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.core;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.frameworks.jcr.command.DefaultKeys;
+import org.exoplatform.frameworks.jcr.command.JCRAppContext;
+
+import javax.jcr.Node;
+import javax.jcr.PropertyIterator;
+import javax.jcr.Session;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: GetChildPropertiesCommand.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public class GetChildPropertiesCommand implements Command
+{
+
+ private String currentNodeKey = DefaultKeys.CURRENT_NODE;
+
+ private String resultKey = DefaultKeys.RESULT;
+
+ public boolean execute(Context context) throws Exception
+ {
+ Session session = ((JCRAppContext)context).getSession();
+ Node curNode = (Node)session.getItem((String)context.get(currentNodeKey));
+ PropertyIterator props = curNode.getProperties();
+ context.put(resultKey, props);
+ return true;
+ }
+
+ public String getResultKey()
+ {
+ return resultKey;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetNodeCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetNodeCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetNodeCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.core;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.frameworks.jcr.command.DefaultKeys;
+import org.exoplatform.frameworks.jcr.command.JCRAppContext;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: GetNodeCommand.java 5878 2006-05-31 09:44:14Z peterit $
+ */
+
+public class GetNodeCommand implements Command
+{
+
+ private String pathKey = DefaultKeys.PATH;
+
+ private String workspaceKey = DefaultKeys.WORKSPACE;
+
+ private String currentNodeKey = DefaultKeys.CURRENT_NODE;
+
+ private String resultKey = DefaultKeys.RESULT;
+
+ public boolean execute(Context context) throws Exception
+ {
+
+ String wsName = (String)context.get(workspaceKey);
+ if (wsName != null)
+ ((JCRAppContext)context).setCurrentWorkspace(wsName);
+ Session session = ((JCRAppContext)context).getSession();
+ String relPath = (String)context.get(pathKey);
+
+ Node parentNode = (Node)session.getItem((String)context.get(currentNodeKey));
+
+ context.put(resultKey, parentNode.getNode(relPath));
+ return false;
+ }
+
+ public String getCurrentNodeKey()
+ {
+ return currentNodeKey;
+ }
+
+ public String getPathKey()
+ {
+ return pathKey;
+ }
+
+ public String getResultKey()
+ {
+ return resultKey;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetPropertyCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetPropertyCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/GetPropertyCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.core;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.frameworks.jcr.command.DefaultKeys;
+import org.exoplatform.frameworks.jcr.command.JCRAppContext;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: GetPropertyCommand.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public class GetPropertyCommand implements Command
+{
+
+ private String pathKey = DefaultKeys.PATH;
+
+ private String currentNodeKey = DefaultKeys.CURRENT_NODE;
+
+ private String resultKey = DefaultKeys.RESULT;
+
+ public boolean execute(Context context) throws Exception
+ {
+ Session session = ((JCRAppContext)context).getSession();
+ String relPath = (String)context.get(pathKey);
+ Node parentNode = (Node)session.getItem((String)context.get(currentNodeKey));
+
+ context.put(resultKey, parentNode.getProperty(relPath));
+ return false;
+ }
+
+ public String getCurrentNodeKey()
+ {
+ return currentNodeKey;
+ }
+
+ public String getPathKey()
+ {
+ return pathKey;
+ }
+
+ public String getResultKey()
+ {
+ return resultKey;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/RemoveItemCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/RemoveItemCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/RemoveItemCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.core;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.frameworks.jcr.command.DefaultKeys;
+import org.exoplatform.frameworks.jcr.command.JCRAppContext;
+
+import javax.jcr.Session;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: RemoveItemCommand.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public class RemoveItemCommand implements Command
+{
+
+ private String pathKey = DefaultKeys.PATH;
+
+ private String resultKey = DefaultKeys.RESULT;
+
+ public boolean execute(Context context) throws Exception
+ {
+
+ Session session = ((JCRAppContext)context).getSession();
+ session.getItem((String)context.get(pathKey)).remove();
+
+ return true;
+ }
+
+ public String getResultKey()
+ {
+ return resultKey;
+ }
+
+ public String getPathKey()
+ {
+ return pathKey;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/SaveCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/SaveCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/SaveCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.core;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.frameworks.jcr.command.DefaultKeys;
+import org.exoplatform.frameworks.jcr.command.JCRAppContext;
+
+import javax.jcr.Item;
+import javax.jcr.Session;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: SaveCommand.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public class SaveCommand implements Command
+{
+
+ private String pathKey = DefaultKeys.PATH;
+
+ public boolean execute(Context context) throws Exception
+ {
+
+ Session session = ((JCRAppContext)context).getSession();
+ String relPath = (String)context.get(pathKey);
+ if (relPath == null)
+ session.save();
+ else
+ ((Item)session.getItem(relPath)).save();
+
+ return true;
+ }
+
+ public String getPathKey()
+ {
+ return pathKey;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/SetPropertyCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/SetPropertyCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/core/SetPropertyCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.core;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.frameworks.jcr.command.DefaultKeys;
+import org.exoplatform.frameworks.jcr.command.JCRAppContext;
+
+import java.io.InputStream;
+
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
+import javax.jcr.Session;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: SetPropertyCommand.java 7137 2006-07-18 15:01:20Z vetal_ok $
+ */
+
+public class SetPropertyCommand implements Command
+{
+
+ private String nameKey = DefaultKeys.NAME;
+
+ private String currentNodeKey = DefaultKeys.CURRENT_NODE;
+
+ private String resultKey = DefaultKeys.RESULT;
+
+ private String propertyTypeKey = DefaultKeys.PROPERTY_TYPE;
+
+ private String valuesKey = DefaultKeys.VALUES;
+
+ private String multiValuedKey = DefaultKeys.MULTI_VALUED;
+
+ public boolean execute(Context context) throws Exception
+ {
+
+ Session session = ((JCRAppContext)context).getSession();
+
+ Node parentNode = (Node)session.getItem((String)context.get(currentNodeKey));
+ String name = (String)context.get(nameKey);
+
+ int type = PropertyType.valueFromName((String)context.get(propertyTypeKey));
+ boolean multi;// = ((Boolean)context.get(multiValuedKey)).booleanValue();
+ if (context.get(multiValuedKey).equals("true"))
+ {
+ multi = true;
+ }
+ else
+ {
+ multi = false;
+ }
+ Object values = context.get(valuesKey);
+ if (values instanceof String)
+ context.put(resultKey, parentNode.setProperty(name, (String)values, type));
+ else if (values instanceof String[])
+ context.put(resultKey, parentNode.setProperty(name, (String[])values, type));
+ else if (values instanceof InputStream)
+ context.put(resultKey, parentNode.setProperty(name, (InputStream)values));
+ else
+ throw new Exception("Values other than String, String[], InputStream is not
supported");
+
+ return false;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/ext/AddResourceFileCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/ext/AddResourceFileCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/ext/AddResourceFileCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.ext;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.frameworks.jcr.command.DefaultKeys;
+import org.exoplatform.frameworks.jcr.command.JCRAppContext;
+import org.exoplatform.frameworks.jcr.command.JCRCommandHelper;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: AddResourceFileCommand.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public class AddResourceFileCommand implements Command
+{
+
+ private String pathKey = DefaultKeys.PATH;
+
+ private String currentNodeKey = DefaultKeys.CURRENT_NODE;
+
+ private String resultKey = DefaultKeys.RESULT;
+
+ private String dataKey = "data";
+
+ private String mimeTypeKey = "mimeType";
+
+ public boolean execute(Context context) throws Exception
+ {
+
+ Session session = ((JCRAppContext)context).getSession();
+
+ Node parentNode = (Node)session.getItem((String)context.get(currentNodeKey));
+ String relPath = (String)context.get(pathKey);
+ Object data = context.get(dataKey);
+ String mimeType = (String)context.get(mimeTypeKey);
+
+ Node file = JCRCommandHelper.createResourceFile(parentNode, relPath, data,
mimeType);
+
+ // Node file = parentNode.addNode(relPath, "nt:file");
+ // Node contentNode = file.addNode("jcr:content",
"nt:resource");
+ // if(data instanceof InputStream)
+ // contentNode.setProperty("jcr:data", (InputStream)data);
+ // else
+ // contentNode.setProperty("jcr:data", (String)data);
+ // contentNode.setProperty("jcr:mimeType",
+ // (String)context.get(mimeTypeKey));
+ // contentNode.setProperty("jcr:lastModified", session
+ // .getValueFactory().createValue(Calendar.getInstance()));
+
+ context.put(resultKey, file);
+ return true;
+ }
+
+ public String getResultKey()
+ {
+ return resultKey;
+ }
+
+ public String getCurrentNodeKey()
+ {
+ return currentNodeKey;
+ }
+
+ public String getPathKey()
+ {
+ return pathKey;
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/ext/FilterNodesByTypesCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/ext/FilterNodesByTypesCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/ext/FilterNodesByTypesCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.ext;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.frameworks.jcr.command.DefaultKeys;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: FilterNodesByTypesCommand.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public class FilterNodesByTypesCommand implements Command
+{
+
+ private String pathKey = DefaultKeys.PATH;
+
+ private String incomingNodesKey = DefaultKeys.RESULT;
+
+ private String typesKey = "nodeTypes";
+
+ private String resultKey = DefaultKeys.RESULT;
+
+ public boolean execute(Context context) throws Exception
+ {
+ Object obj = context.get(incomingNodesKey);
+ if (obj == null || !(obj instanceof NodeIterator))
+ throw new Exception("Invalid incoming nodes iterator " + obj);
+ NodeIterator nodes = (NodeIterator)obj;
+
+ obj = context.get(typesKey);
+ if (obj == null || !(obj instanceof String[]))
+ throw new Exception("Invalid node types object, expected String[] " +
obj);
+ String[] nts = (String[])context.get(typesKey);
+
+ List nodes1 = new ArrayList();
+ while (nodes.hasNext())
+ {
+ Node n = nodes.nextNode();
+ for (int i = 0; i < nts.length; i++)
+ {
+ if (n.isNodeType(nts[i]))
+ nodes1.add(n);
+ }
+ }
+ // context.put(resultKey, new EntityCollection(nodes1));
+ context.put(resultKey, nodes1);
+
+ return false;
+ }
+
+ public String getIncomingNodesKey()
+ {
+ return incomingNodesKey;
+ }
+
+ public String getPathKey()
+ {
+ return pathKey;
+ }
+
+ public String getResultKey()
+ {
+ return resultKey;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/DisplayResourceCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/DisplayResourceCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/DisplayResourceCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.web;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.commons.utils.MimeTypeResolver;
+import org.exoplatform.frameworks.jcr.command.DefaultKeys;
+import org.exoplatform.frameworks.jcr.command.JCRCommandHelper;
+
+import java.io.InputStream;
+import java.io.PrintWriter;
+
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SAS .<br/> the command to output nt:resource to
Servlet Response gets
+ * DefaultKeys.PATH attrribute from the Context and acts as follow: - if there is
nt:resource Node
+ * on DefaultKeys.PATH displays it - otherwise recursively tries to get nt:resource from
incoming
+ * node's primary items and display it - throws PathNotFoundException if no such a
node found
+ * WARNING: this mechanizm is not suitable for big files streaming as uses byte arry
buffer for data
+ * transfer!
+ *
+ * @author Gennady Azarenkov
+ * @version $Id: DisplayResourceCommand.java 13861 2007-03-28 11:31:16Z vetal_ok $
+ */
+
+public class DisplayResourceCommand implements Command
+{
+
+ public static String DEFAULT_MAPPING = "/jcr";
+
+ public static String DEFAULT_ENCODING = "UTF-8";
+
+ private String pathKey = DefaultKeys.PATH;
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.commons.chain.Command#execute(org.apache.commons.chain.Context)
+ */
+ public boolean execute(Context context) throws Exception
+ {
+ GenericWebAppContext webCtx = (GenericWebAppContext)context;
+ HttpServletResponse response = webCtx.getResponse();
+ HttpServletRequest request = webCtx.getRequest();
+
+ // standalone request?
+ String servletPath = request.getPathInfo();
+ boolean doClose = true;
+ // or included?
+ if (servletPath == null)
+ {
+ servletPath =
(String)request.getAttribute("javax.servlet.include.path_info");
+ if (servletPath != null)
+ doClose = false;
+ }
+
+ Node file = (Node)webCtx.getSession().getItem((String)context.get(pathKey));
+ file.refresh(false);
+
+ Node content = null;
+
+ try
+ {
+ content = JCRCommandHelper.getNtResourceRecursively(file);
+ }
+ catch (ItemNotFoundException e)
+ {
+ // Patch for ver 1.0 back compatibility
+ // as exo:image was not primary item
+ if (file.isNodeType("exo:article"))
+ {
+ try
+ {
+ content = file.getNode("exo:image");
+ }
+ catch (PathNotFoundException e1)
+ {
+ throw e; // new ItemNotFoundException("No nt:resource node found at
+ // "+file.getPath()+" nor primary items of nt:resource type
+ // ");
+ }
+ }
+ else
+ {
+ throw e; // new ItemNotFoundException("No nt:resource node found at
+ // "+file.getPath()+" nor primary items of nt:resource type
+ // ");
+ }
+
+ }
+
+ // if(file.isNodeType("nt:file")) {
+ // content = file.getNode("jcr:content");
+ // } else if(file.isNodeType("exo:article")) {
+ // content = file.getNode("exo:image");
+ // } else
+ // throw new Exception("Invalid node type, expected nt:file or exo:article,
+ // have "+file.getPrimaryNodeType().getName()+" at
"+file.getPath());
+
+ Property data;
+ try
+ {
+ data = content.getProperty("jcr:data");
+ }
+ catch (PathNotFoundException e)
+ {
+ throw new PathNotFoundException("No jcr:data node found at " +
content.getPath());
+ }
+
+ String mime = content.getProperty("jcr:mimeType").getString();
+ String encoding =
+ content.hasProperty("jcr:encoding") ?
content.getProperty("jcr:encoding").getString() : DEFAULT_ENCODING;
+
+ MimeTypeResolver resolver = new MimeTypeResolver();
+ String fileName = file.getName();
+ String fileExt = "";
+ if (fileName.lastIndexOf(".") > -1)
+ {
+ fileExt = fileName.substring(fileName.lastIndexOf(".") + 1);
+ fileName = fileName.substring(0, fileName.lastIndexOf("."));
+ }
+ String mimeExt = resolver.getExtension(mime);
+ if (fileExt == null || fileExt.length() == 0)
+ {
+ fileExt = mimeExt;
+ }
+ response.setContentType(mime + "; charset=" + encoding);
+ String parameter = (String)context.get("cache-control-max-age");
+ String cacheControl = parameter == null ? "" : "public,
max-age=" + parameter;
+ response.setHeader("Cache-Control: ", cacheControl);
+ response.setHeader("Pragma: ", ""); // leave blank to avoid IE
errors
+ response.setHeader("Content-disposition", "attachment;
filename=\"" + fileName + "." + fileExt + "\"");
+
+ if (mime.startsWith("text"))
+ {
+ PrintWriter out = response.getWriter();
+ out.write(data.getString());
+ out.flush();
+ if (doClose)
+ out.close();
+ }
+ else
+ {
+ InputStream is = data.getStream();
+ byte[] buf = new byte[is.available()];
+ is.read(buf);
+ ServletOutputStream os = response.getOutputStream();
+ os.write(buf);
+ os.flush();
+ if (doClose)
+ os.close();
+ }
+
+ return true;
+ }
+
+ /**
+ * @return path Key
+ */
+ public String getPathKey()
+ {
+ return pathKey;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/GenericWebAppContext.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/GenericWebAppContext.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/GenericWebAppContext.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.web;
+
+import org.apache.commons.chain.web.servlet.ServletWebContext;
+import org.exoplatform.frameworks.jcr.command.JCRAppContext;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.common.SessionProvider;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.Enumeration;
+
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: GenericWebAppContext.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public class GenericWebAppContext extends ServletWebContext implements JCRAppContext
+{
+
+ public static final String JCR_CONTENT_MAPPING =
"org.exoplatform.frameworks.web.repositoryMapping";
+
+ private static Log log = ExoLogger.getLogger("jcr.JCRWebAppContext");
+
+ protected final SessionProvider sessionProvider;
+
+ protected final ManageableRepository repository;
+
+ protected String currentWorkspace;
+
+ public GenericWebAppContext(ServletContext servletContext, HttpServletRequest request,
HttpServletResponse response,
+ SessionProvider sessionProvider, ManageableRepository repository)
+ {
+
+ initialize(servletContext, request, response);
+
+ this.sessionProvider = sessionProvider;
+ this.repository = repository;
+
+ // log.info("WEb context ---------------");
+ // initialize context with all props
+ Enumeration en = servletContext.getInitParameterNames();
+ while (en.hasMoreElements())
+ {
+ String name = (String)en.nextElement();
+ put(name, servletContext.getInitParameter(name));
+ log.debug("ServletContext init param: " + name + "=" +
servletContext.getInitParameter(name));
+ }
+
+ en = servletContext.getAttributeNames();
+ while (en.hasMoreElements())
+ {
+ String name = (String)en.nextElement();
+ put(name, servletContext.getAttribute(name));
+ log.debug("ServletContext: " + name + "=" +
servletContext.getAttribute(name));
+ }
+
+ HttpSession session = request.getSession(false);
+ if (session != null)
+ {
+ en = session.getAttributeNames();
+ while (en.hasMoreElements())
+ {
+ String name = (String)en.nextElement();
+ put(name, session.getAttribute(name));
+ log.debug("Session: " + name + "=" +
session.getAttribute(name));
+ }
+ }
+
+ en = request.getAttributeNames();
+ while (en.hasMoreElements())
+ {
+ String name = (String)en.nextElement();
+ put(name, request.getAttribute(name));
+ }
+
+ en = request.getParameterNames();
+ while (en.hasMoreElements())
+ {
+ String name = (String)en.nextElement();
+ put(name, request.getParameter(name));
+ log.debug("Request: " + name + "=" +
request.getParameter(name));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.exoplatform.frameworks.jcr.command.JCRAppContext#getSession()
+ */
+ public Session getSession() throws LoginException, NoSuchWorkspaceException,
RepositoryException
+ {
+ return sessionProvider.getSession(currentWorkspace, repository);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.exoplatform.frameworks.jcr.command.JCRAppContext#setCurrentWorkspace(java.lang.String)
+ */
+ public void setCurrentWorkspace(String workspaceName)
+ {
+ this.currentWorkspace = workspaceName;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/AbstractFCKConnector.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/AbstractFCKConnector.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/AbstractFCKConnector.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.web.fckeditor;
+
+import org.exoplatform.frameworks.jcr.command.web.GenericWebAppContext;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: AbstractFCKConnector.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public abstract class AbstractFCKConnector
+{
+
+ /**
+ * Return FCKeditor current folder path.
+ *
+ * @param context
+ * @return String path
+ */
+ protected String getCurrentFolderPath(GenericWebAppContext context)
+ {
+ // To limit browsing set Servlet init param "digitalAssetsPath" with
desired JCR path
+ String rootFolderStr =
+
(String)context.get("org.exoplatform.frameworks.jcr.command.web.fckeditor.digitalAssetsPath");
+
+ if (rootFolderStr == null)
+ rootFolderStr = "/";
+
+ // set current folder
+ String currentFolderStr = (String)context.get("CurrentFolder");
+ if (currentFolderStr == null)
+ currentFolderStr = "";
+ else if (currentFolderStr.length() < rootFolderStr.length())
+ currentFolderStr = rootFolderStr;
+
+ return currentFolderStr;
+ }
+
+ /**
+ * Compile REST path of the given resource.
+ *
+ * @param workspace
+ * @param resource
+ * , we assume that path starts with '/'
+ * @return
+ */
+ protected String makeRESTPath(String repoName, String workspace, String resource)
+ {
+ return "/rest/jcr/" + repoName + "/" + workspace + resource;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/AppConstants.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/AppConstants.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/AppConstants.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.web.fckeditor;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: AppConstants.java 34445 2009-07-24 07:51:18Z dkatayev $
+ */
+
+public interface AppConstants
+{
+ public static String DIGITAL_ASSETS_PROP =
+
"org.exoplatform.frameworks.jcr.command.web.fckeditor.digitalAssetsWorkspace";
+
+ public static String DEFAULT_DIGITAL_ASSETS_WS = "digital-assets";
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/CreateFolderCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/CreateFolderCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/CreateFolderCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.web.fckeditor;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.frameworks.jcr.command.web.GenericWebAppContext;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.jcr.Node;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: CreateFolderCommand.java 34445 2009-07-24 07:51:18Z dkatayev $
+ */
+
+public class CreateFolderCommand extends FCKConnectorXMLOutput implements Command
+{
+
+ public boolean execute(Context context) throws Exception
+ {
+ GenericWebAppContext webCtx = (GenericWebAppContext)context;
+ HttpServletResponse response = webCtx.getResponse();
+ HttpServletRequest request = webCtx.getRequest();
+
+ String type = (String)context.get("Type");
+ if (type == null)
+ type = "";
+
+ // // To limit browsing set Servlet init param "digitalAssetsPath"
+ // // with desired JCR path
+ // String rootFolderStr =
+ //
(String)context.get("org.exoplatform.frameworks.jcr.command.web.fckeditor.digitalAssetsPath"
+ // );
+ //
+ // if(rootFolderStr == null)
+ // rootFolderStr = "/";
+ //
+ // // set current folder
+ // String currentFolderStr = (String)context.get("CurrentFolder");
+ // if(currentFolderStr == null)
+ // currentFolderStr = "";
+ // else if(currentFolderStr.length() < rootFolderStr.length())
+ // currentFolderStr = rootFolderStr;
+ //
+ // String folderName = (String)context.get("NewFolderName");
+ // if(folderName == null)
+ // throw new Exception("NewFolderName not defined");
+ //
+ // String jcrMapping =
(String)context.get(GenericWebAppContext.JCR_CONTENT_MAPPING);
+ // if(jcrMapping == null)
+ // jcrMapping = DisplayResourceCommand.DEFAULT_MAPPING;
+ //
+ // String digitalWS = (String)webCtx.get(AppConstants.DIGITAL_ASSETS_PROP);
+ // if(digitalWS == null)
+ // digitalWS = AppConstants.DEFAULT_DIGITAL_ASSETS_WS;
+ //
+ // webCtx.setCurrentWorkspace(digitalWS);
+ //
+ // Node currentFolder = (Node) webCtx.getSession().getItem(currentFolderStr);
+ // Node newFolder = currentFolder.addNode(folderName, "nt:folder");
+ // currentFolder.save();
+ //
+ // String url = request.getContextPath()+jcrMapping+"?"+
+ // "workspace="+digitalWS+
+ // "&path="+currentFolderStr;
+
+ String workspace = (String)webCtx.get(AppConstants.DIGITAL_ASSETS_PROP);
+ if (workspace == null)
+ workspace = AppConstants.DEFAULT_DIGITAL_ASSETS_WS;
+
+ String currentFolderStr = getCurrentFolderPath(webCtx);
+
+ String folderName = (String)context.get("NewFolderName");
+ if (folderName == null)
+ throw new Exception("NewFolderName not defined");
+
+ webCtx.setCurrentWorkspace(workspace);
+
+ Node currentFolder = (Node)webCtx.getSession().getItem(currentFolderStr);
+ Node newFolder = currentFolder.addNode(folderName, "nt:folder");
+ currentFolder.save();
+
+ String repoName =
((ManageableRepository)webCtx.getSession().getRepository()).getConfiguration().getName();
+
+ String url = request.getContextPath() + makeRESTPath(repoName, workspace,
currentFolderStr);
+
+ initRootElement("CreateFolder", type, newFolder.getPath() +
"/", url);
+
+ Document doc = rootElement.getOwnerDocument();
+
+ // TODO
+ String retVal = "0";
+
+ Element errElement = doc.createElement("Error");
+ errElement.setAttribute("number", retVal);
+ rootElement.appendChild(errElement);
+
+ outRootElement(response);
+
+ return false;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/FCKConnectorXMLOutput.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/FCKConnectorXMLOutput.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/FCKConnectorXMLOutput.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.web.fckeditor;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import java.io.PrintWriter;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: FCKConnectorXMLOutput.java 34445 2009-07-24 07:51:18Z dkatayev $
+ */
+
+public class FCKConnectorXMLOutput extends AbstractFCKConnector
+{
+
+ protected Element rootElement;
+
+ protected void initRootElement(String commandStr, String typeStr, String currentPath,
String currentUrl)
+ throws ParserConfigurationException
+ {
+
+ Document doc = null;
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ doc = builder.newDocument();
+
+ rootElement = doc.createElement("Connector");
+ doc.appendChild(rootElement);
+ rootElement.setAttribute("command", commandStr);
+ rootElement.setAttribute("resourceType", typeStr);
+
+ Element myEl = doc.createElement("CurrentFolder");
+ myEl.setAttribute("path", currentPath);
+ myEl.setAttribute("url", currentUrl);
+ rootElement.appendChild(myEl);
+ }
+
+ protected void outRootElement(HttpServletResponse response) throws Exception
+ {
+ response.setContentType("text/xml; charset=UTF-8");
+ response.setHeader("Cache-Control", "no-cache");
+ PrintWriter out = response.getWriter();
+
+ rootElement.normalize();
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ Transformer transformer = tFactory.newTransformer();
+ DOMSource source = new DOMSource(rootElement.getOwnerDocument());
+
+ StreamResult result = new StreamResult(out);
+ transformer.transform(source, result);
+ out.flush();
+ out.close();
+ }
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/GetFoldersOrFilesCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/GetFoldersOrFilesCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/GetFoldersOrFilesCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.web.fckeditor;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.frameworks.jcr.command.web.GenericWebAppContext;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: GetFoldersOrFilesCommand.java 34445 2009-07-24 07:51:18Z dkatayev $
+ */
+
+public class GetFoldersOrFilesCommand extends FCKConnectorXMLOutput implements Command
+{
+
+ public boolean execute(Context context) throws Exception
+ {
+
+ GenericWebAppContext webCtx = (GenericWebAppContext)context;
+ HttpServletResponse response = webCtx.getResponse();
+ HttpServletRequest request = webCtx.getRequest();
+
+ String filter = (String)context.get("Command");
+
+ String type = (String)context.get("Type");
+ if (type == null)
+ type = "";
+
+ // To limit browsing set Servlet init param "digitalAssetsPath" with
desired JCR path
+ // String rootFolderStr =
+ //
(String)context.get("org.exoplatform.frameworks.jcr.command.web.fckeditor.digitalAssetsPath"
+ // );
+ //
+ // if(rootFolderStr == null)
+ // rootFolderStr = "/";
+ //
+ // // set current folder
+ // String currentFolderStr = get;
+ // if(currentFolderStr == null)
+ // currentFolderStr = "";
+ // else if(currentFolderStr.length() < rootFolderStr.length())
+ // currentFolderStr = rootFolderStr;
+ //
+ // String jcrMapping =
(String)context.get(GenericWebAppContext.JCR_CONTENT_MAPPING);
+ // if(jcrMapping == null)
+ // jcrMapping = DisplayResourceCommand.DEFAULT_MAPPING;
+ //
+ // String workspace = (String)webCtx.get(AppConstants.DIGITAL_ASSETS_PROP);
+ // if(workspace == null)
+ // workspace = AppConstants.DEFAULT_DIGITAL_ASSETS_WS;
+ //
+ // webCtx.setCurrentWorkspace(workspace);
+ //
+ // Node currentFolder = (Node) webCtx.getSession().getItem(currentFolderStr);
+ //
+ // initRootElement(filter, type, currentPath,
request.getContextPath()+currentPath);
+ // String url = request.getContextPath()+jcrMapping+"?"+
+ // "workspace="+digitalWS+
+ // "&path="+currentFolderStr;
+
+ // /portal/jcr?workspace=collaboration&path=/Digital Assets/Pictures/my
+ // images/39515971.u1D8dTVD.wilersee_5924.jpg
+
+ String workspace = (String)webCtx.get(AppConstants.DIGITAL_ASSETS_PROP);
+ if (workspace == null)
+ workspace = AppConstants.DEFAULT_DIGITAL_ASSETS_WS;
+
+ String currentFolderStr = getCurrentFolderPath(webCtx);
+
+ webCtx.setCurrentWorkspace(workspace);
+ Node currentFolder = (Node)webCtx.getSession().getItem(currentFolderStr);
+
+ String repoName =
((ManageableRepository)webCtx.getSession().getRepository()).getConfiguration().getName();
+
+ String url = request.getContextPath() + makeRESTPath(repoName, workspace,
currentFolderStr);
+
+ initRootElement(filter, type, currentFolderStr, url);
+
+ Document doc = rootElement.getOwnerDocument();
+ if (!filter.equals("GetFiles"))
+ {
+ Element nodesElement =
rootElement.getOwnerDocument().createElement("Folders");
+ rootElement.appendChild(nodesElement);
+ NodeIterator nodeList = currentFolder.getNodes();
+ while (nodeList.hasNext())
+ {
+ Node n = nodeList.nextNode();
+ // System.out.println(" >>> "+n.getPath());
+ if (n.isNodeType("nt:folder") ||
n.isNodeType("nt:unstructured"))
+ {
+ Element folderElement = doc.createElement("Folder");
+ folderElement.setAttribute("name", n.getName());
+ nodesElement.appendChild(folderElement);
+ }
+ }
+ }
+
+ if (!filter.equals("GetFolders"))
+ {
+ Element nodesElement =
rootElement.getOwnerDocument().createElement("Files");
+ rootElement.appendChild(nodesElement);
+ NodeIterator nodeList = currentFolder.getNodes();
+ while (nodeList.hasNext())
+ {
+ Node n = nodeList.nextNode();
+ // System.out.println(" >>> " + n.getPath() + "
"
+ // + n.isNodeType("nt:file") + " " +
n.getPrimaryNodeType().getName());
+ if (n.isNodeType("nt:file"))
+ {
+ Element fileElement = doc.createElement("File");
+ long size =
n.getNode("jcr:content").getProperty("jcr:data").getLength();
+ fileElement.setAttribute("name", n.getName());
+ fileElement.setAttribute("size", "" + size);
+ nodesElement.appendChild(fileElement);
+ }
+ }
+ }
+
+ outRootElement(response);
+
+ return false;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/ShowEditorCommand.java.1
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/ShowEditorCommand.java.1
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/ShowEditorCommand.java.1 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.web.fckeditor;
+
+import java.io.PrintWriter;
+
+import javax.jcr.Property;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.exoplatform.frameworks.jcr.command.DefaultKeys;
+import org.exoplatform.frameworks.jcr.command.web.WebAppContext;
+import org.exoplatform.frameworks.web.fckeditor.FCKeditor;
+/**
+ * Created by The eXo Platform SARL .
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: ShowEditorCommand.java.1 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public class ShowEditorCommand implements Command {
+
+ // should be set in servletContext? no defaults?
+ private static final String DEFAULT_EDITOR_NAME = "FCKEditor";
+
+ private static final String DEFAULT_SUBMIT_NAME = "Submit";
+ private static final String DEFAULT_ACTION_NAME = "/index.jsp";
+
+ private String contentKey = DefaultKeys.RESULT;
+ private String pathKey = DefaultKeys.PATH;
+
+ private String editorKey = "editor";
+ private String formActionKey = "formAction";
+ private String submitKey = "submit";
+
+ public boolean execute(Context context) throws Exception {
+ WebAppContext webCtx = (WebAppContext)context;
+ HttpServletResponse response = webCtx.getResponse();
+ HttpServletRequest request = webCtx.getRequest();
+ PrintWriter out = response.getWriter();
+
+ String content = (String)context.get(contentKey);
+ if(content == null)
+ content = "";
+ //throw new Exception("path undefined");
+ if(content == "") {
+ String path = (String)context.get(pathKey);
+ if(path != null) {
+
//System.out.println(webCtx.getSession().getItem(path+"/jcr:content/jcr:data"));
+ Property prop =
(Property)webCtx.getSession().getItem(path+"/jcr:content/jcr:data");
+ content = prop.getString();
+ }
+ }
+
+ String editorName = (String)context.get(editorKey);
+ if(editorName == null)
+ editorName = DEFAULT_EDITOR_NAME;
+
+ String formAction = (String)context.get(formActionKey);
+ if(formAction == null)
+ formAction = DEFAULT_ACTION_NAME;
+
+ String submit = (String)context.get(submitKey);
+ if(submit == null)
+ submit = DEFAULT_SUBMIT_NAME;
+
+ FCKeditor editor = new FCKeditor(request, editorName);
+ editor.setValue(content);
+ out.println("<form
action="+request.getContextPath()+formAction+"?editor="+editorName+"
method=POST>");
+ out.println(editor.create());
+ out.println("<br/><input type=submit
value="+submit+">");
+
+ out.println("</form>");
+ out.flush();
+ out.close();
+
+ //response.sendRedirect(formAction);
+
+ return false;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/UploadFileCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/UploadFileCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/main/java/org/exoplatform/frameworks/jcr/command/web/fckeditor/UploadFileCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.web.fckeditor;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.fileupload.DiskFileUpload;
+import org.apache.commons.fileupload.FileItem;
+import org.exoplatform.frameworks.jcr.command.JCRCommandHelper;
+import org.exoplatform.frameworks.jcr.command.web.GenericWebAppContext;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SAS .<br/>
+ * connector?Command=FileUpload&Type=ResourceType&CurrentFolder=FolderPath
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: UploadFileCommand.java 34445 2009-07-24 07:51:18Z dkatayev $
+ */
+
+public class UploadFileCommand extends AbstractFCKConnector implements Command
+{
+
+ public boolean execute(Context context) throws Exception
+ {
+
+ GenericWebAppContext webCtx = (GenericWebAppContext)context;
+ HttpServletResponse response = webCtx.getResponse();
+ HttpServletRequest request = webCtx.getRequest();
+ PrintWriter out = response.getWriter();
+ response.setContentType("text/html; charset=UTF-8");
+ response.setHeader("Cache-Control", "no-cache");
+
+ String type = (String)context.get("Type");
+ if (type == null)
+ type = "";
+
+ // // To limit browsing set Servlet init param "digitalAssetsPath"
+ // // with desired JCR path
+ // String rootFolderStr =
+ //
(String)context.get("org.exoplatform.frameworks.jcr.command.web.fckeditor.digitalAssetsPath"
+ // );
+ //
+ // if(rootFolderStr == null)
+ // rootFolderStr = "/";
+ //
+ // // set current folder
+ // String currentFolderStr = (String)context.get("CurrentFolder");
+ // if(currentFolderStr == null)
+ // currentFolderStr = "";
+ // else if(currentFolderStr.length() < rootFolderStr.length())
+ // currentFolderStr = rootFolderStr;
+ //
+ // String jcrMapping =
(String)context.get(GenericWebAppContext.JCR_CONTENT_MAPPING);
+ // if(jcrMapping == null)
+ // jcrMapping = DisplayResourceCommand.DEFAULT_MAPPING;
+ //
+ // String digitalWS = (String)webCtx.get(AppConstants.DIGITAL_ASSETS_PROP);
+ // if(digitalWS == null)
+ // digitalWS = AppConstants.DEFAULT_DIGITAL_ASSETS_WS;
+
+ String workspace = (String)webCtx.get(AppConstants.DIGITAL_ASSETS_PROP);
+ if (workspace == null)
+ workspace = AppConstants.DEFAULT_DIGITAL_ASSETS_WS;
+
+ String currentFolderStr = getCurrentFolderPath(webCtx);
+
+ webCtx.setCurrentWorkspace(workspace);
+
+ Node parentFolder = (Node)webCtx.getSession().getItem(currentFolderStr);
+
+ DiskFileUpload upload = new DiskFileUpload();
+ List items = upload.parseRequest(request);
+
+ Map fields = new HashMap();
+
+ Iterator iter = items.iterator();
+ while (iter.hasNext())
+ {
+ FileItem item = (FileItem)iter.next();
+ if (item.isFormField())
+ fields.put(item.getFieldName(), item.getString());
+ else
+ fields.put(item.getFieldName(), item);
+ }
+ FileItem uplFile = (FileItem)fields.get("NewFile");
+
+ // On IE, the file name is specified as an absolute path.
+ String fileName = new File(uplFile.getName()).getName();
+
+ Node file =
+ JCRCommandHelper
+ .createResourceFile(parentFolder, fileName, uplFile.getInputStream(),
uplFile.getContentType());
+
+ parentFolder.save();
+
+ // TODO
+ int retVal = 0;
+
+ out.println("<script type=\"text/javascript\">");
+
out.println("window.parent.frames['frmUpload'].OnUploadCompleted(" +
retVal + ",'" + file.getName() + "');");
+ out.println("</script>");
+ out.flush();
+ out.close();
+
+ return false;
+ }
+
+}
Added: jcr/trunk/frameworks/command/src/test/java/conf/standalone/test-configuration.xml
===================================================================
--- jcr/trunk/frameworks/command/src/test/java/conf/standalone/test-configuration.xml
(rev 0)
+++
jcr/trunk/frameworks/command/src/test/java/conf/standalone/test-configuration.xml 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,168 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+<configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd
http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+
+ <component>
+ <key>org.exoplatform.services.log.LogConfigurationInitializer</key>
+ <type>org.exoplatform.services.log.LogConfigurationInitializer</type>
+ <init-params>
+ <value-param>
+ <name>logger</name>
+
<value>org.exoplatform.services.log.impl.BufferedLog4JLogger</value>
+ </value-param>
+ <value-param>
+ <name>configurator</name>
+
<value>org.exoplatform.services.log.impl.Log4JConfigurator</value>
+ </value-param>
+ <properties-param>
+ <name>properties</name>
+ <description>Log4J properties</description>
+ <property name="log4j.rootLogger" value="INFO, stdout,
file" />
+
+ <property name="log4j.appender.stdout"
value="org.apache.log4j.ConsoleAppender" />
+ <property name="log4j.appender.stdout.threshold"
value="INFO" />
+
+ <property name="log4j.appender.stdout.layout"
value="org.apache.log4j.PatternLayout" />
+ <property name="log4j.appender.stdout.layout.ConversionPattern"
value="%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m (%F, line %L) %n" />
+
+ <property name="log4j.appender.file"
value="org.apache.log4j.FileAppender" />
+ <property name="log4j.appender.file.File"
value="target/jcr.log" />
+
+ <property name="log4j.appender.file.layout"
value="org.apache.log4j.PatternLayout" />
+ <property name="log4j.appender.file.layout.ConversionPattern"
value="%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m (%F, line %L) %n" />
+
+ <!-- property name="log4j.category.jcr.DBInitializer"
value="DEBUG"/ -->
+
+ </properties-param>
+ </init-params>
+ </component>
+
+ <component>
+
<key>org.exoplatform.services.jcr.config.RepositoryServiceConfiguration</key>
+
<type>org.exoplatform.services.jcr.impl.config.RepositoryServiceConfigurationImpl</type>
+ <init-params>
+ <value-param>
+ <name>conf-path</name>
+ <description>JCR configuration file</description>
+
<value>jar:/conf/standalone/test-jcr-framework-config.xml</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <component>
+ <key>org.exoplatform.services.jcr.RepositoryService</key>
+ <type>org.exoplatform.services.jcr.impl.RepositoryServiceImpl</type>
+ <component-plugins>
+ <component-plugin>
+ <name>add.namespaces</name>
+ <set-method>addPlugin</set-method>
+
<type>org.exoplatform.services.jcr.impl.AddNamespacesPlugin</type>
+ <init-params>
+ <properties-param>
+ <name>namespaces</name>
+ <property name="dc"
value="http://purl.org/dc/elements/1.1/" />
+ </properties-param>
+ </init-params>
+ </component-plugin>
+ <component-plugin>
+ <name>add.nodeType</name>
+ <set-method>addPlugin</set-method>
+ <type>org.exoplatform.services.jcr.impl.AddNodeTypePlugin</type>
+ <init-params>
+ <values-param>
+ <name>autoCreatedInNewRepository</name>
+ <description>Node types configuration file</description>
+ <value>jar:/conf/ext-nodetypes-config.xml</value>
+ </values-param>
+ </init-params>
+ </component-plugin>
+ </component-plugins>
+ </component>
+
+ <component>
+
<type>org.exoplatform.services.organization.impl.mock.DummyOrganizationService</type>
+ </component>
+
+ <component>
+ <key>org.exoplatform.services.security.Authenticator</key>
+
<type>org.exoplatform.services.organization.auth.OrganizationAuthenticatorImpl</type>
+ </component>
+
+ <external-component-plugins>
+
<target-component>org.exoplatform.services.command.impl.CommandService</target-component>
+ <component-plugin>
+ <name>config.catalog</name>
+ <set-method>addPlugin</set-method>
+
<type>org.exoplatform.services.command.impl.CommonsXMLConfigurationPlugin</type>
+ <init-params>
+ <value-param>
+ <name>config-file</name>
+ <value>conf/test-commands1.xml</value>
+ </value-param>
+ </init-params>
+ </component-plugin>
+ <component-plugin>
+ <name>config.catalog</name>
+ <set-method>addPlugin</set-method>
+
<type>org.exoplatform.services.command.impl.CommonsXMLConfigurationPlugin</type>
+ <init-params>
+ <value-param>
+ <name>config-file</name>
+ <value>conf/jcr-client-commands.xml</value>
+ </value-param>
+ </init-params>
+ </component-plugin>
+ </external-component-plugins>
+
+ <external-component-plugins>
+
<target-component>org.exoplatform.services.naming.InitialContextInitializer</target-component>
+ <component-plugin>
+ <name>bind.datasource</name>
+ <set-method>addPlugin</set-method>
+ <type>org.exoplatform.services.naming.BindReferencePlugin</type>
+ <init-params>
+ <value-param>
+ <name>bind-name</name>
+ <value>jdbcjcr</value>
+ </value-param>
+ <value-param>
+ <name>class-name</name>
+ <value>javax.sql.DataSource</value>
+ </value-param>
+ <value-param>
+ <name>factory</name>
+ <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
+ </value-param>
+ <properties-param>
+ <name>ref-addresses</name>
+ <description>ref-addresses</description>
+ <property name="driverClassName"
value="org.hsqldb.jdbcDriver" />
+ <property name="url"
value="jdbc:hsqldb:file:target/temp3/data/portal" />
+ <property name="username" value="sa" />
+ <property name="password" value="" />
+ </properties-param>
+ </init-params>
+ </component-plugin>
+ </external-component-plugins>
+
+</configuration>
Added:
jcr/trunk/frameworks/command/src/test/java/conf/standalone/test-jcr-framework-config.xml
===================================================================
---
jcr/trunk/frameworks/command/src/test/java/conf/standalone/test-jcr-framework-config.xml
(rev 0)
+++
jcr/trunk/frameworks/command/src/test/java/conf/standalone/test-jcr-framework-config.xml 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,51 @@
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+<repository-service default-repository="db1">
+ <repositories>
+ <repository name="db1" system-workspace="ws"
default-workspace="ws">
+ <security-domain>exo-domain</security-domain>
+ <access-control>disable</access-control>
+
<authentication-policy>org.exoplatform.services.jcr.impl.core.access.JAASAuthenticator</authentication-policy>
+ <workspaces>
+ <workspace name="ws"
auto-init-root-nodetype="nt:unstructured">
+ <!-- for system storage -->
+ <container
class="org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer">
+ <properties>
+ <property name="source-name" value="jdbcjcr"
/>
+ <property name="multi-db" value="true" />
+ </properties>
+ </container>
+ <cache enabled="true">
+ <properties>
+ <property name="max-size" value="1000" />
+ <property name="live-time" value="1800"
/><!-- 30 min -->
+ </properties>
+ </cache>
+ <!-- query-handler
class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
+ <properties>
+ <property name="index-dir"
value="target/temp/index" />
+ </properties>
+ </query-handler -->
+ </workspace>
+ </workspaces>
+ </repository>
+ </repositories>
+</repository-service>
Added:
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/GetNodeAsXMLCommand.java
===================================================================
---
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/GetNodeAsXMLCommand.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/GetNodeAsXMLCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+
+import javax.jcr.Node;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: GetNodeAsXMLCommand.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public class GetNodeAsXMLCommand implements Command
+{
+
+ private String pathKey = DefaultKeys.PATH;
+
+ private String incomingNodeKey = DefaultKeys.RESULT;
+
+ private String resultKey = DefaultKeys.RESULT;
+
+ public boolean execute(Context context) throws Exception
+ {
+ Object obj = context.get(incomingNodeKey);
+ if (obj == null || !(obj instanceof Node))
+ throw new Exception("Invalid incoming node " + obj);
+ Node node = (Node)context.get(incomingNodeKey);
+ String xml = "<node path='" + node.getPath() +
"'/>";
+ context.put(resultKey, xml);
+ return false;
+ }
+
+ public String getIncomingNodeKey()
+ {
+ return incomingNodeKey;
+ }
+
+ public String getPathKey()
+ {
+ return pathKey;
+ }
+
+ public String getResultKey()
+ {
+ return resultKey;
+ }
+
+}
Added:
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/TestJCRCommands.java
===================================================================
---
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/TestJCRCommands.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/TestJCRCommands.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.chain.Command;
+import org.exoplatform.container.StandaloneContainer;
+import org.exoplatform.frameworks.jcr.command.core.AddNodeCommand;
+import org.exoplatform.frameworks.jcr.command.core.SaveCommand;
+import org.exoplatform.services.command.impl.CommandService;
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.security.Authenticator;
+import org.exoplatform.services.security.ConversationState;
+import org.exoplatform.services.security.Credential;
+import org.exoplatform.services.security.Identity;
+import org.exoplatform.services.security.PasswordCredential;
+import org.exoplatform.services.security.UsernameCredential;
+
+import java.util.Iterator;
+
+import javax.jcr.NodeIterator;
+import javax.jcr.PropertyType;
+
+/**
+ * Created by The eXo Platform SARL .
+ *
+ * @author <a href="mailto:geaz@users.sourceforge.net">Gennady Azarenkov
</a>
+ * @version $Id: TestJCRCommands.java 34445 2009-07-24 07:51:18Z dkatayev $
+ */
+public class TestJCRCommands extends TestCase
+{
+
+ private StandaloneContainer container;
+
+ private CommandService cservice;
+
+ private BasicAppContext ctx;
+
+ public void setUp() throws Exception
+ {
+
+ String containerConf =
getClass().getResource("/conf/standalone/test-configuration.xml").toString();
+ String loginConf =
Thread.currentThread().getContextClassLoader().getResource("login.conf").toString();
+
+ if (System.getProperty("java.security.auth.login.config") == null)
+ System.setProperty("java.security.auth.login.config", loginConf);
+
+ StandaloneContainer.addConfigurationURL(containerConf);
+ container = StandaloneContainer.getInstance();
+
+ RepositoryService repService =
(RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
+
+ cservice =
(CommandService)container.getComponentInstanceOfType(CommandService.class);
+
+ // login via Authenticator
+ Authenticator authr =
(Authenticator)container.getComponentInstanceOfType(Authenticator.class);
+ String validUser =
+ authr.validateUser(new Credential[]{new UsernameCredential("root"),
new PasswordCredential("exo")});
+ Identity id = authr.createIdentity(validUser);
+ ConversationState s = new ConversationState(id);
+ ConversationState.setCurrent(s);
+
+ ctx = new BasicAppContext(repService.getDefaultRepository());
+
+ // System.out.println("CTX "+ctx);
+ }
+
+ public void testCatalogInit() throws Exception
+ {
+ Iterator cs = cservice.getCatalog().getNames();
+ assertTrue(cs.hasNext());
+ while (cs.hasNext())
+ {
+ System.out.println(cs.next());
+ }
+ }
+
+ public void testAddNode() throws Exception
+ {
+
+ AddNodeCommand addNode =
(AddNodeCommand)cservice.getCatalog().getCommand("addNode");
+ System.out.println(" " + addNode);
+ ctx.put("currentNode", "/");
+ ctx.put(addNode.getPathKey(), "test");
+ addNode.execute(ctx);
+
+ System.out.println(">>> " + ctx.get(addNode.getResultKey()));
+
+ SaveCommand save =
(SaveCommand)cservice.getCatalog().getCommand("save");
+ // ctx.remove(save.getPathKey());
+ ctx.put(addNode.getPathKey(), "/");
+ save.execute(ctx);
+
+ System.out.println(">>> SAVE >>> ");
+ }
+
+ public void testSetProperty() throws Exception
+ {
+
+ Command c = cservice.getCatalog().getCommand("setProperty");
+ ctx.put("currentNode", "/test");
+ ctx.put("name", "testProperty");
+ ctx.put("propertyType", PropertyType.TYPENAME_STRING);
+ ctx.put("values", "testValue");
+ ctx.put("multiValued", Boolean.FALSE);
+
+ c.execute(ctx);
+
+ System.out.println("> set property>> " +
ctx.get("result"));
+
+ Command save = cservice.getCatalog().getCommand("save");
+ save.execute(ctx);
+
+ }
+
+ public void testGetNodes() throws Exception
+ {
+
+ Command c = cservice.getCatalog().getCommand("getNodes");
+ ctx.put("currentNode", "/");
+ c.execute(ctx);
+
+ assertTrue(ctx.get("result") instanceof NodeIterator);
+ NodeIterator nodes = (NodeIterator)ctx.get("result");
+
+ // System.out.println("> getNodes >> "+nodes.getSize());
+
+ assertTrue(nodes.getSize() > 0);
+ }
+
+ public void testAddResourceFile() throws Exception
+ {
+
+ Command c = cservice.getCatalog().getCommand("addResourceFile");
+ ctx.put("currentNode", "/");
+ ctx.put("path", "resource");
+ ctx.put("data", "Node data");
+ ctx.put("mimeType", "text/html");
+
+ c.execute(ctx);
+
+ System.out.println(">>> Resource >>> " +
ctx.get("result"));
+
+ Command save = cservice.getCatalog().getCommand("save");
+ ctx.put("path", "/");
+ save.execute(ctx);
+
+ }
+
+ public void testGetNodeChain() throws Exception
+ {
+ Command cmd = cservice.getCatalog().getCommand("retrieveNodeCommand");
+ ctx.put("currentNode", "/");
+ ctx.put("path", "test");
+ cmd.execute(ctx);
+
+ System.out.println("RESULT >>>>>> " +
ctx.get("result"));
+
+ }
+}
Added:
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/cli/TestJCRClientCommands.java
===================================================================
---
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/cli/TestJCRClientCommands.java
(rev 0)
+++
jcr/trunk/frameworks/command/src/test/java/org/exoplatform/frameworks/jcr/command/cli/TestJCRClientCommands.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,344 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.command.cli;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.container.StandaloneContainer;
+import org.exoplatform.frameworks.jcr.cli.AddNodeCommand;
+import org.exoplatform.frameworks.jcr.cli.CliAppContext;
+import org.exoplatform.frameworks.jcr.cli.CopyNodeCommand;
+import org.exoplatform.frameworks.jcr.cli.GetContextInfoCommand;
+import org.exoplatform.frameworks.jcr.cli.GetItemCommand;
+import org.exoplatform.frameworks.jcr.cli.GetNodeCommand;
+import org.exoplatform.frameworks.jcr.cli.GetNodesCommand;
+import org.exoplatform.frameworks.jcr.cli.GetPropertiesCommand;
+import org.exoplatform.frameworks.jcr.cli.GetPropertyCommand;
+import org.exoplatform.frameworks.jcr.cli.HelpCommand;
+import org.exoplatform.frameworks.jcr.cli.LoginCommand;
+import org.exoplatform.frameworks.jcr.cli.MoveNodeCommand;
+import org.exoplatform.frameworks.jcr.cli.RemoveItemCommand;
+import org.exoplatform.frameworks.jcr.cli.SetPropertyCommand;
+import org.exoplatform.services.command.impl.CommandService;
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.security.Authenticator;
+import org.exoplatform.services.security.ConversationState;
+import org.exoplatform.services.security.Credential;
+import org.exoplatform.services.security.Identity;
+import org.exoplatform.services.security.PasswordCredential;
+import org.exoplatform.services.security.UsernameCredential;
+
+import java.util.ArrayList;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+
+/**
+ * Created by The eXo Platform SARL .
+ *
+ * @author <a href="mailto:vitaliy.obmanjuk@exoplatform.com.ua">Vitaliy
Obmanjuk </a>
+ * @version $Id: TestJCRClientCommands.java 34445 2009-07-24 07:51:18Z dkatayev $
+ */
+
+public class TestJCRClientCommands extends TestCase
+{
+
+ private StandaloneContainer container;
+
+ private CommandService cservice;
+
+ private static CliAppContext ctx;
+
+ private ArrayList<String> params = new ArrayList<String>();
+
+ private final static String PARAMETERS_KEY = "parametersss";
+
+ public void setUp() throws Exception
+ {
+
+ String containerConf =
getClass().getResource("/conf/standalone/test-configuration.xml").toString();
+ String loginConf =
Thread.currentThread().getContextClassLoader().getResource("login.conf").toString();
+
+ if (System.getProperty("java.security.auth.login.config") == null)
+ System.setProperty("java.security.auth.login.config", loginConf);
+
+ StandaloneContainer.addConfigurationURL(containerConf);
+ container = StandaloneContainer.getInstance();
+
+ RepositoryService repService =
(RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
+
+ cservice =
(CommandService)container.getComponentInstanceOfType(CommandService.class);
+
+ // we need to login (see BasicAppContext, 38) and set current item before ctx
using
+ if (ctx == null)
+ {
+ // login via Authenticator
+ Authenticator authr =
(Authenticator)container.getComponentInstanceOfType(Authenticator.class);
+ String validUser =
+ authr.validateUser(new Credential[]{new UsernameCredential("root"),
new PasswordCredential("exo")});
+ Identity id = authr.createIdentity(validUser);
+ ConversationState s = new ConversationState(id);
+ ConversationState.setCurrent(s);
+
+ ctx = new CliAppContext(repService.getDefaultRepository(), PARAMETERS_KEY);
+ Node root = ctx.getSession().getRootNode();
+ ctx.setCurrentItem(root);
+ if (root.hasNode("testJCRClientCommands") == false)
+ {
+ Node node =
root.addNode("testJCRClientCommands").addNode("childOftestJCRClientCommands");
+ node.setProperty("testProperty", "test");
+ root.save();
+ }
+ }
+ assertNotNull(ctx);
+ }
+
+ /*
+ * /testJCRClientCommands /testJCRClientCommands/childOftestJCRClientCommands
+ * /testJCRClientCommands/childOftestJCRClientCommands/childOftestJCRClientCommands2
+ * /copyOftestJCRClientCommands /newCopyOftestJCRClientCommands
+ */
+
+ public void testCtxLogin() throws Exception
+ {
+ params.clear();
+ LoginCommand loginCommand =
(LoginCommand)cservice.getCatalog("CLI").getCommand("login");
+ params.add("ws");
+ ctx.put(PARAMETERS_KEY, params);
+ loginCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+ assertEquals(ctx.getCurrentItem(), ctx.getSession().getRootNode());
+ assertEquals("ws", ctx.getSession().getWorkspace().getName());
+ }
+
+ public void testGetCtxItem() throws Exception
+ {
+
+ params.clear();
+ GetItemCommand getItemCommand =
(GetItemCommand)cservice.getCatalog("CLI").getCommand("getitem");
+ params.add("/testJCRClientCommands");
+ ctx.put(PARAMETERS_KEY, params);
+ getItemCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+ assertEquals(ctx.getCurrentItem().getName(), "testJCRClientCommands");
+ }
+
+ public void testGetCtxNode() throws Exception
+ {
+ params.clear();
+ GetNodeCommand getNodeCommand =
(GetNodeCommand)cservice.getCatalog("CLI").getCommand("getnode");
+ params.add("childOftestJCRClientCommands");
+ ctx.put(PARAMETERS_KEY, params);
+ getNodeCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+ assertEquals(ctx.getCurrentItem().getName(),
"childOftestJCRClientCommands");
+ }
+
+ public void testGetCtxProperty() throws Exception
+ {
+ params.clear();
+ GetPropertyCommand getPropertyCommand =
(GetPropertyCommand)cservice.getCatalog("CLI").getCommand("getproperty");
+ params.add("testProperty");
+ ctx.put(PARAMETERS_KEY, params);
+ getPropertyCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+ assertEquals(((Property)ctx.getCurrentItem()).getValue().getString(),
"test");
+ }
+
+ public void testGetCtxNodes() throws Exception
+ {
+ System.out.println("=== ls ===");
+ params.clear();
+ // current item is Property, need to go to Node
+ GetItemCommand getItemCommand =
(GetItemCommand)cservice.getCatalog("CLI").getCommand("getitem");
+ params.add("/testJCRClientCommands");
+ ctx.put(PARAMETERS_KEY, params);
+ getItemCommand.execute(ctx);
+ // ok, now currentItem is Node "/testJCRClientCommands"
+ GetNodesCommand getNodesCommand =
(GetNodesCommand)cservice.getCatalog("CLI").getCommand("getnodes");
+ getNodesCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+ assertTrue(ctx.getOutput().contains("childOftestJCRClientCommands"));
+ }
+
+ public void testGetCtxProperties() throws Exception
+ {
+ GetPropertiesCommand getPropertiesCommand =
+
(GetPropertiesCommand)cservice.getCatalog("CLI").getCommand("getproperties");
+ getPropertiesCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+ assertTrue(ctx.getOutput().contains("jcr:primaryType"));
+ }
+
+ public void testAddNode1() throws Exception
+ {
+ params.clear();
+ AddNodeCommand addNodeCommand =
(AddNodeCommand)cservice.getCatalog("CLI").getCommand("addnode");
+ params.add("childOftestJCRClientCommands1");
+ ctx.put(PARAMETERS_KEY, params);
+ addNodeCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+ assertEquals(ctx.getCurrentItem().getName(),
"childOftestJCRClientCommands1");
+ }
+
+ public void testAddNode2() throws Exception
+ {
+ params.clear();
+ AddNodeCommand addNodeCommand =
(AddNodeCommand)cservice.getCatalog("CLI").getCommand("addnode");
+ params.add("childOftestJCRClientCommands2");
+ params.add("nt:unstructured");
+ ctx.put(PARAMETERS_KEY, params);
+ addNodeCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+ assertEquals(((Node)ctx.getCurrentItem()).getPrimaryNodeType().getName(),
"nt:unstructured");
+ }
+
+ public void testSetProperty1() throws Exception
+ {
+ params.clear();
+ SetPropertyCommand setPropertyCommand =
(SetPropertyCommand)cservice.getCatalog("CLI").getCommand("setproperty");
+ params.add("propertyName1");
+ params.add("propertyValue1");
+ ctx.put(PARAMETERS_KEY, params);
+ setPropertyCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+ assertEquals(((Property)ctx.getCurrentItem()).getName(),
"propertyName1");
+ assertEquals(((Property)ctx.getCurrentItem()).getValue().getString(),
"propertyValue1");
+ }
+
+ public void testSetProperty2() throws Exception
+ {
+ params.clear();
+ //
+ GetItemCommand getItemCommand =
(GetItemCommand)cservice.getCatalog("CLI").getCommand("getitem");
+ params.add("..");
+ ctx.put(PARAMETERS_KEY, params);
+ getItemCommand.execute(ctx);
+ //
+ params.clear();
+ SetPropertyCommand setPropertyCommand =
(SetPropertyCommand)cservice.getCatalog("CLI").getCommand("setproperty");
+ params.add("propertyName2");
+ params.add("12345");
+ params.add((new Integer(PropertyType.LONG)).toString());
+ ctx.put(PARAMETERS_KEY, params);
+ setPropertyCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+ assertEquals(((Property)ctx.getCurrentItem()).getName(),
"propertyName2");
+ assertEquals(((Property)ctx.getCurrentItem()).getValue().getLong(), 12345);
+ }
+
+ public void testContextInfoCommand() throws Exception
+ {
+ GetContextInfoCommand getContextInfoCommand =
+
(GetContextInfoCommand)cservice.getCatalog("CLI").getCommand("getcontextinfo");
+ getContextInfoCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+ assertTrue(ctx.getOutput().contains("root"));
+ assertTrue(ctx.getOutput().contains("ws"));
+ }
+
+ public void testRemoveItemCommand() throws Exception
+ {
+ RemoveItemCommand removeItemCommand =
(RemoveItemCommand)cservice.getCatalog("CLI").getCommand("remove");
+ removeItemCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+ assertEquals(((Node)ctx.getCurrentItem()).getName(),
"childOftestJCRClientCommands2");
+ }
+
+ public void testCopyNodeCommand() throws Exception
+ {
+ params.clear();
+ CopyNodeCommand copyNodeCommand =
(CopyNodeCommand)cservice.getCatalog("CLI").getCommand("copynode");
+ params.add("/testJCRClientCommands");
+ params.add("/copyOftestJCRClientCommands");
+ ctx.put(PARAMETERS_KEY, params);
+ copyNodeCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+
assertNotNull(ctx.getSession().getRootNode().getNode("copyOftestJCRClientCommands"));
+ }
+
+ public void testMoveNodeCommand() throws Exception
+ {
+ params.clear();
+ MoveNodeCommand moveNodeCommand =
(MoveNodeCommand)cservice.getCatalog("CLI").getCommand("movenode");
+ params.add("/copyOftestJCRClientCommands");
+ params.add("/newCopyOftestJCRClientCommands");
+ ctx.put(PARAMETERS_KEY, params);
+ moveNodeCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+
assertNotNull(ctx.getSession().getRootNode().getNode("newCopyOftestJCRClientCommands"));
+ }
+
+ public void testHelpCommand() throws Exception
+ {
+ params.clear();
+ HelpCommand helpCommand =
(HelpCommand)cservice.getCatalog("CLI").getCommand("help");
+ // params.add("addnode");
+ ctx.put(PARAMETERS_KEY, params);
+ helpCommand.execute(ctx);
+ System.out.println("[out]:" + ctx.getOutput());
+ assertTrue(ctx.getOutput().contains("addnode"));
+ }
+
+ public void testCdCommand() throws Exception
+ {
+ // go to root
+ params.clear();
+ GetItemCommand getItemCommand1 =
(GetItemCommand)cservice.getCatalog("CLI").getCommand("getitem");
+ params.add("/");
+ ctx.put(PARAMETERS_KEY, params);
+ getItemCommand1.execute(ctx);
+ // test absPath
+ params.clear();
+ GetItemCommand getItemCommandAbsPath =
(GetItemCommand)cservice.getCatalog("CLI").getCommand("getitem");
+ params.add("/testJCRClientCommands");
+ ctx.put(PARAMETERS_KEY, params);
+ getItemCommandAbsPath.execute(ctx);
+ assertEquals(ctx.getCurrentItem().getName(), "testJCRClientCommands");
+ // go to root again
+ params.clear();
+ GetItemCommand getItemCommand2 =
(GetItemCommand)cservice.getCatalog("CLI").getCommand("getitem");
+ params.add("/");
+ ctx.put(PARAMETERS_KEY, params);
+ getItemCommand2.execute(ctx);
+ // test relPath
+ params.clear();
+ GetItemCommand getItemCommandRelPath =
(GetItemCommand)cservice.getCatalog("CLI").getCommand("getitem");
+ params.add("testJCRClientCommands");
+ ctx.put(PARAMETERS_KEY, params);
+ getItemCommandRelPath.execute(ctx);
+ assertEquals(ctx.getCurrentItem().getName(), "testJCRClientCommands");
+ }
+
+ public void testFinallyRemoveNodes() throws Exception
+ {
+ Node root = ctx.getSession().getRootNode();
+ NodeIterator nodeIterator = root.getNodes();
+ while (nodeIterator.hasNext())
+ {
+ Node node = nodeIterator.nextNode();
+ if (!node.getPath().startsWith("/jcr:system"))
+ node.remove();
+ }
+ root.save();
+ assertTrue(root.getNodes().getSize() == 1 &&
root.getNode("jcr:system") != null);
+ }
+}
Added: jcr/trunk/frameworks/command/src/test/resources/login.conf
===================================================================
--- jcr/trunk/frameworks/command/src/test/resources/login.conf
(rev 0)
+++ jcr/trunk/frameworks/command/src/test/resources/login.conf 2009-08-27 12:31:38 UTC
(rev 17)
@@ -0,0 +1,3 @@
+exo-domain {
+ org.exoplatform.services.security.jaas.DefaultLoginModule required;
+};
\ No newline at end of file
Added: jcr/trunk/frameworks/ftpclient/pom.xml
===================================================================
--- jcr/trunk/frameworks/ftpclient/pom.xml (rev 0)
+++ jcr/trunk/frameworks/ftpclient/pom.xml 2009-08-27 12:31:38 UTC (rev 17)
@@ -0,0 +1,67 @@
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>config</artifactId>
+ <version>1.12-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>exo.jcr.framework.ftpclient</artifactId>
+
+ <name>eXo JCR :: Framework :: FTP Client</name>
+ <description>eXo FTP Client</description>
+
+ <properties>
+ <exo.test.includes>*</exo.test.includes>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.command</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+</project>
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/FtpConst.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/FtpConst.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/FtpConst.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class FtpConst
+{
+
+ public static final String FTP_PREFIX = "exo.ftpclient.";
+
+ public static final String EXC_MSG = "Unhandled exception. ";
+
+ public class Commands
+ {
+ public static final String CMD_USER = "USER";
+
+ public static final String CMD_PASS = "PASS";
+
+ public static final String CMD_TYPE = "TYPE";
+
+ public static final String CMD_CWD = "CWD";
+
+ public static final String CMD_PWD = "PWD";
+
+ public static final String CMD_QUIT = "QUIT";
+
+ public static final String CMD_HELP = "HELP";
+
+ public static final String CMD_SYST = "SYST";
+
+ public static final String CMD_PASV = "PASV";
+
+ public static final String CMD_NOOP = "NOOP";
+
+ public static final String CMD_LIST = "LIST";
+
+ public static final String CMD_CDUP = "CDUP";
+
+ public static final String CMD_MKD = "MKD";
+
+ public static final String CMD_MODE = "MODE";
+
+ public static final String CMD_RMD = "RMD";
+
+ public static final String CMD_RNFR = "RNFR";
+
+ public static final String CMD_RNTO = "RNTO";
+
+ public static final String CMD_STOR = "STOR";
+
+ public static final String CMD_RETR = "RETR";
+
+ public static final String CMD_DELE = "DELE";
+
+ public static final String CMD_REST = "REST";
+
+ public static final String CMD_NLST = "NLST";
+
+ public static final String CMD_PORT = "PORT";
+
+ public static final String CMD_SIZE = "SIZE";
+
+ public static final String CMD_STRU = "STRU";
+
+ public static final String CMD_STAT = "STAT";
+ }
+
+ public class Replyes
+ {
+ public static final int REPLY_125 = 125;
+
+ public static final int REPLY_150 = 150;
+
+ public static final int REPLY_200 = 200;
+
+ public static final int REPLY_211 = 211;
+
+ public static final int REPLY_213 = 213;
+
+ public static final int REPLY_214 = 214;
+
+ public static final int REPLY_215 = 215;
+
+ public static final int REPLY_221 = 221;
+
+ public static final int REPLY_226 = 226;
+
+ public static final int REPLY_227 = 227;
+
+ public static final int REPLY_230 = 230;
+
+ public static final int REPLY_250 = 250;
+
+ public static final int REPLY_257 = 257;
+
+ public static final int REPLY_331 = 331;
+
+ public static final int REPLY_350 = 350;
+
+ public static final int REPLY_421 = 421;
+
+ public static final int REPLY_425 = 425;
+
+ public static final int REPLY_450 = 450;
+
+ public static final int REPLY_500 = 500;
+
+ public static final int REPLY_501 = 501;
+
+ public static final int REPLY_503 = 503;
+
+ public static final int REPLY_504 = 504;
+
+ public static final int REPLY_530 = 530;
+
+ public static final int REPLY_550 = 550;
+
+ public static final int REPLY_553 = 553;
+ }
+
+ public class SysTypes
+ {
+ public static final String WINDOWS_NT = "Windows_NT";
+
+ public static final String UNIX_L8 = "UNIX Type: L8";
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/FtpUtils.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/FtpUtils.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/FtpUtils.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient;
+
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.net.ServerSocket;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class FtpUtils
+{
+
+ protected static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"FtpUtils");
+
+ public static int getReplyCode(String reply)
+ {
+ if (reply.charAt(3) != ' ')
+ {
+ return -1;
+ }
+ String replyCodeVal = reply.substring(0, 3);
+ return new Integer(replyCodeVal);
+ }
+
+ public static boolean isPortFree(int port)
+ {
+ try
+ {
+ ServerSocket serverSocket = new ServerSocket(port);
+ serverSocket.close();
+ return true;
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return false;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/Log.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/Log.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/Log.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class Log
+{
+
+ private String moduleName;
+
+ public Log(String moduleName)
+ {
+ this.moduleName = moduleName;
+ }
+
+ public void info(String message)
+ {
+ System.out.println(moduleName + ":" + message);
+ }
+
+ public void info(String message, Throwable thr)
+ {
+ System.out.println(moduleName + ":" + message);
+ thr.printStackTrace(System.out);
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/client/FtpClientSession.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/client/FtpClientSession.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/client/FtpClientSession.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.client;
+
+import org.exoplatform.frameworks.ftpclient.commands.FtpCommand;
+import org.exoplatform.frameworks.ftpclient.data.FtpDataTransiver;
+
+import java.net.Socket;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public interface FtpClientSession
+{
+
+ Socket getClientSocket();
+
+ boolean connect() throws Exception;
+
+ boolean connect(int attemptsCount) throws Exception;
+
+ void close();
+
+ int executeCommand(FtpCommand command) throws Exception;
+
+ int executeCommand(FtpCommand command, int expectReply, int attemptsCount) throws
Exception;
+
+ void setSystemType(String systemType);
+
+ String getSystemType();
+
+ void setDataTransiver(FtpDataTransiver dataTransiver);
+
+ FtpDataTransiver getDataTransiver();
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/client/FtpClientSessionImpl.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/client/FtpClientSessionImpl.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/client/FtpClientSessionImpl.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.client;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.commands.FtpCommand;
+import org.exoplatform.frameworks.ftpclient.data.FtpDataTransiver;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class FtpClientSessionImpl implements FtpClientSession
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"FtpClientSessionImpl");
+
+ protected String host;
+
+ protected int port;
+
+ protected Socket clientSocket = null;
+
+ protected String systemType;
+
+ protected FtpDataTransiver dataTransiver = null;
+
+ public FtpClientSessionImpl(String host, int port)
+ {
+ // log.info("Starting client...");
+ this.host = host;
+ this.port = port;
+ }
+
+ public boolean connect() throws Exception
+ {
+ return connect(1);
+ }
+
+ public boolean connect(int attemptsCount) throws Exception
+ {
+ Exception prevExc = null;
+ for (int i = 0; i < attemptsCount; i++)
+ {
+ try
+ {
+ clientSocket = new Socket();
+ SocketAddress sockAddr = new InetSocketAddress(host, port);
+ clientSocket.connect(sockAddr);
+ // log.info("Connected - " + clientSocket.isConnected());
+
+ boolean connected = false;
+ for (int wi = 0; wi < 200; wi++)
+ {
+ if (clientSocket.isConnected())
+ {
+ connected = true;
+ break;
+ }
+ Thread.sleep(1);
+ }
+
+ if (!connected)
+ {
+ throw new Exception();
+ }
+
+ BufferedReader br = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
+
+ String reply = "";
+ while (!reply.startsWith("220 "))
+ {
+ reply = br.readLine();
+ // log.info("REPLY - " + reply);
+ }
+
+ return true;
+ }
+ catch (Exception exc)
+ {
+ prevExc = exc;
+ }
+ Thread.sleep(3000);
+ //
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
sleeping.........");
+ }
+
+ log.info("unhandled exception. " + prevExc.getMessage(), prevExc);
+
+ return false;
+ }
+
+ public void close()
+ {
+ try
+ {
+ if (dataTransiver != null)
+ {
+ dataTransiver.close();
+ }
+
+ if (clientSocket == null)
+ {
+ return;
+ }
+ if (clientSocket.isConnected())
+ {
+ clientSocket.close();
+ }
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ }
+
+ public Socket getClientSocket()
+ {
+ return clientSocket;
+ }
+
+ public int executeCommand(FtpCommand command) throws Exception
+ {
+ if (clientSocket == null)
+ {
+ return -1;
+ }
+ return command.run(this);
+ }
+
+ public int executeCommand(FtpCommand command, int expectReply, int attemptsCount)
throws Exception
+ {
+ int reply = -1;
+ for (int i = 0; i < attemptsCount; i++)
+ {
+ reply = command.run(this);
+ if (reply == expectReply)
+ {
+ return reply;
+ }
+ Thread.sleep(100);
+ }
+ return reply;
+ }
+
+ public void setSystemType(String systemType)
+ {
+ this.systemType = systemType;
+ }
+
+ public String getSystemType()
+ {
+ return systemType;
+ }
+
+ public void setDataTransiver(FtpDataTransiver dataTransiver)
+ {
+ this.dataTransiver = dataTransiver;
+ }
+
+ public FtpDataTransiver getDataTransiver()
+ {
+ return dataTransiver;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdCdUp.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdCdUp.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdCdUp.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdCdUp extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdCdUp");
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(FtpConst.Commands.CMD_CDUP);
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdCwd.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdCwd.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdCwd.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdCwd extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdCwd");
+
+ protected String path;
+
+ public CmdCwd(String path)
+ {
+ this.path = path;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_CWD, path));
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdDele.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdDele.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdDele.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdDele extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdDele");
+
+ protected String path;
+
+ public CmdDele(String path)
+ {
+ this.path = path;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_DELE,
path));
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdHelp.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdHelp.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdHelp.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class CmdHelp extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdHelp");
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(FtpConst.Commands.CMD_HELP);
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdList.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdList.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdList.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.data.FtpDataTransiver;
+import org.exoplatform.frameworks.ftpclient.data.FtpFileInfo;
+import org.exoplatform.frameworks.ftpclient.data.FtpFileInfoImpl;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.ArrayList;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdList extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdList");
+
+ protected String path = "";
+
+ protected byte[] fileData;
+
+ protected ArrayList<FtpFileInfo> files = new ArrayList<FtpFileInfo>();
+
+ public CmdList()
+ {
+ }
+
+ public CmdList(String path)
+ {
+ this.path = path;
+ }
+
+ public byte[] getFileData()
+ {
+ return fileData;
+ }
+
+ public ArrayList<FtpFileInfo> getFiles()
+ {
+ return files;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ if (clientSession.getSystemType() == null)
+ {
+ clientSession.executeCommand(new CmdSyst());
+ }
+
+ String req;
+
+ if ("".equals(path))
+ {
+ req = FtpConst.Commands.CMD_LIST;
+ }
+ else
+ {
+ req = String.format("%s %s", FtpConst.Commands.CMD_LIST, path);
+ }
+ sendCommand(req);
+
+ int reply = getReply();
+
+ if (reply == FtpConst.Replyes.REPLY_125 || reply == FtpConst.Replyes.REPLY_150)
+ {
+ FtpDataTransiver dataTransiver = clientSession.getDataTransiver();
+
+ fileData = dataTransiver.receive();
+
+ dataTransiver.close();
+
+ String dd = new String(fileData, "windows-1251");
+
+ String[] lines = dd.split("\r\n");
+
+ String systemType = clientSession.getSystemType();
+ systemType = systemType.substring(systemType.indexOf(" ") + 1);
+
+ for (int i = 0; i < lines.length; i++)
+ {
+ try
+ {
+ FtpFileInfo fileInfo = new FtpFileInfoImpl();
+ if (!"".equals(lines[i]))
+ {
+ fileInfo.parseDir(lines[i], systemType);
+ files.add(fileInfo);
+ }
+ }
+ catch (Exception exc)
+ {
+ log.info("CAN'T PARSE FILE LINE: [" + lines[i] +
"]");
+ }
+ }
+ reply = getReply();
+ }
+ return reply;
+ }
+ catch (Exception exc)
+ {
+ log.info("Unhandled exception. " + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdMkd.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdMkd.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdMkd.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdMkd extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdMkd");
+
+ protected String path = "";
+
+ public CmdMkd(String path)
+ {
+ this.path = path;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_MKD, path));
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdMode.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdMode.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdMode.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class CmdMode extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdMode");
+
+ private String mode;
+
+ public CmdMode(String mode)
+ {
+ this.mode = mode;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_MODE,
mode));
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdNlst.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdNlst.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdNlst.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.data.FtpDataTransiver;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.ArrayList;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdNlst extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdNlst");
+
+ protected String path = "";
+
+ protected ArrayList<String> names = new ArrayList<String>();
+
+ public CmdNlst()
+ {
+ }
+
+ public CmdNlst(String path)
+ {
+ this.path = path;
+ }
+
+ public ArrayList<String> getNames()
+ {
+ return names;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ String req = "";
+ if (!"".equals(path))
+ {
+ req = String.format("%s %s", FtpConst.Commands.CMD_NLST, path);
+ }
+ else
+ {
+ req = FtpConst.Commands.CMD_NLST;
+ }
+ sendCommand(req);
+
+ int reply = getReply();
+
+ if (reply == FtpConst.Replyes.REPLY_125)
+ {
+ FtpDataTransiver dataTransiver = clientSession.getDataTransiver();
+
+ for (int i = 0; i < 15; i++)
+ {
+ if (!dataTransiver.isConnected())
+ {
+ Thread.sleep(1000);
+ }
+ }
+
+ byte[] data = dataTransiver.receive();
+ dataTransiver.close();
+
+ String dd = "";
+ for (int i = 0; i < data.length; i++)
+ {
+ dd += (char)data[i];
+ }
+
+ String[] lines = dd.split("\r\n");
+ for (int i = 0; i < lines.length; i++)
+ {
+ names.add(lines[i]);
+ }
+
+ reply = getReply();
+ }
+
+ return reply;
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdNoop.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdNoop.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdNoop.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdNoop extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdNoop");
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(FtpConst.Commands.CMD_NOOP);
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPass.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPass.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPass.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdPass extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdPass");
+
+ protected String pass;
+
+ public CmdPass(String pass)
+ {
+ this.pass = pass;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_PASS,
pass));
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPasv.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPasv.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPasv.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.data.FtpDataTransiver;
+import org.exoplatform.frameworks.ftpclient.data.FtpDataTransiverImpl;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdPasv extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdPasv");
+
+ protected String host = "";
+
+ protected int port = 0;
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(FtpConst.Commands.CMD_PASV);
+
+ int reply = getReply();
+
+ if (FtpConst.Replyes.REPLY_227 != reply)
+ {
+ return reply;
+ }
+
+ String descrVal = getDescription();
+ descrVal = descrVal.substring(descrVal.indexOf("(") + 1,
descrVal.indexOf(")"));
+
+ String[] addrValues = descrVal.split(",");
+
+ host = "";
+ for (int i = 0; i < 3; i++)
+ {
+ host += addrValues[i] + ".";
+ }
+ host += addrValues[3];
+
+ port = new Integer(addrValues[4]) * 256 + new Integer(addrValues[5]);
+
+ if (FtpConst.Replyes.REPLY_227 == reply)
+ {
+ FtpDataTransiver dataTransiver = new FtpDataTransiverImpl();
+ dataTransiver.OpenPassive(host, port);
+ clientSession.setDataTransiver(dataTransiver);
+ }
+
+ return reply;
+ }
+ catch (Exception exc)
+ {
+ log.info("unhandled ecxeption. " + exc.getMessage(), exc);
+ }
+ log.info("SOME ERRORS");
+ return -1;
+ }
+
+ public String getHost()
+ {
+ return host;
+ }
+
+ public int getPort()
+ {
+ return port;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPort.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPort.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPort.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdPort extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdPort");
+
+ protected String host;
+
+ protected int port;
+
+ public CmdPort(String host, int port)
+ {
+ this.host = host;
+ this.port = port;
+ }
+
+ public int execute()
+ {
+ try
+ {
+
+ // this "IF" for tests only. try to get reply 500
+ if (host == null)
+ {
+ sendCommand(FtpConst.Commands.CMD_PORT);
+ return getReply();
+ }
+
+ sendCommand(String.format("%s %s,%d,%d", FtpConst.Commands.CMD_PORT,
host, port / 256, port % 256).replace(
+ '.', ','));
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPwd.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPwd.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdPwd.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdPwd extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdPwd");
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(FtpConst.Commands.CMD_PWD);
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+ public String getCurrentPath()
+ {
+ String pVal = getDescription();
+
+ if (pVal.indexOf(" \"") != 0)
+ {
+ pVal = pVal.substring(pVal.indexOf(" \"") + 2,
pVal.lastIndexOf("\" "));
+ }
+
+ return pVal;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdQuit.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdQuit.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdQuit.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class CmdQuit extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdQuit");
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(FtpConst.Commands.CMD_QUIT);
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdRest extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdRest");
+
+ protected String offset;
+
+ public CmdRest(int offset)
+ {
+ this.offset = String.format("%d", offset);
+ }
+
+ public CmdRest(String offset)
+ {
+ this.offset = offset;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ // for tests only
+ if (offset == null)
+ {
+ sendCommand(FtpConst.Commands.CMD_REST);
+ return getReply();
+ }
+
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_REST,
offset));
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRetr.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRetr.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRetr.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdRetr extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdRetr");
+
+ protected String path;
+
+ protected byte[] fileContent = null;
+
+ public CmdRetr(String path)
+ {
+ this.path = path;
+ }
+
+ public byte[] getFileContent()
+ {
+ return fileContent;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ // for tests only
+ if (path == null)
+ {
+ sendCommand(FtpConst.Commands.CMD_RETR);
+ return getReply();
+ }
+
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_RETR,
path));
+
+ int reply = getReply();
+ if (reply == FtpConst.Replyes.REPLY_125)
+ {
+ fileContent = clientSession.getDataTransiver().receive();
+ reply = getReply();
+ }
+
+ return reply;
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRmd.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRmd.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRmd.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdRmd extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdRmd");
+
+ protected String path;
+
+ public CmdRmd(String path)
+ {
+ this.path = path;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_RMD, path));
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRnFr.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRnFr.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRnFr.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdRnFr extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdRnFr");
+
+ protected String path;
+
+ public CmdRnFr(String path)
+ {
+ this.path = path;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ // for tests only
+ if (path == null)
+ {
+ sendCommand(FtpConst.Commands.CMD_RNFR);
+ return getReply();
+ }
+
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_RNFR,
path));
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRnTo.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRnTo.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdRnTo.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdRnTo extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdRnTo");
+
+ protected String path;
+
+ public CmdRnTo(String path)
+ {
+ this.path = path;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ // for tests only
+ if (path == null)
+ {
+ sendCommand(FtpConst.Commands.CMD_RNTO);
+ return getReply();
+ }
+
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_RNTO,
path));
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdSize.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdSize.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdSize.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdSize extends FtpCommandImpl
+{
+
+ public static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdSize");
+
+ protected String path;
+
+ protected int size = 0;
+
+ public CmdSize(String path)
+ {
+ this.path = path;
+ }
+
+ public int getSize()
+ {
+ return size;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ // for tests only
+ if (path == null)
+ {
+ sendCommand(FtpConst.Commands.CMD_SIZE);
+ return getReply();
+ }
+
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_SIZE,
path));
+
+ int reply = getReply();
+
+ if (reply == FtpConst.Replyes.REPLY_213)
+ {
+ String descr = getDescription();
+ String sizeVal = descr.substring(descr.indexOf(" ") + 1);
+ size = new Integer(sizeVal);
+ }
+ return reply;
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdStat.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdStat.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdStat.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class CmdStat extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdStat");
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(FtpConst.Commands.CMD_STAT);
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdStor.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdStor.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdStor.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.data.FtpDataTransiver;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdStor extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdStor");
+
+ protected String path;
+
+ protected byte[] fileContent = null;
+
+ public CmdStor(String path)
+ {
+ this.path = path;
+ }
+
+ public void setFileContent(byte[] fileContent)
+ {
+ this.fileContent = fileContent;
+ }
+
+ public int execute()
+ {
+ if (fileContent == null)
+ {
+ return -1;
+ }
+
+ try
+ {
+ FtpDataTransiver dataTransiver = clientSession.getDataTransiver();
+
+ if (dataTransiver != null)
+ {
+ for (int i = 0; i < 150; i++)
+ {
+ if (!dataTransiver.isConnected())
+ {
+ Thread.sleep(100);
+ }
+ }
+ }
+
+ if (path == null)
+ {
+ sendCommand(FtpConst.Commands.CMD_STOR);
+ return getReply();
+ }
+
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_STOR,
path));
+
+ int reply = getReply();
+ if (reply == FtpConst.Replyes.REPLY_125)
+ {
+ dataTransiver.send(fileContent);
+ reply = getReply();
+ }
+ return reply;
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdStru.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdStru.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdStru.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class CmdStru extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdStru");
+
+ private String structureType;
+
+ public CmdStru(String structureType)
+ {
+ this.structureType = structureType;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_STRU,
structureType));
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdSyst.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdSyst.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdSyst.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdSyst extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdSyst");
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(FtpConst.Commands.CMD_SYST);
+
+ int reply = getReply();
+
+ if (reply == FtpConst.Replyes.REPLY_215)
+ {
+ String systemType = getDescription();
+ clientSession.setSystemType(systemType);
+ }
+
+ return reply;
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdType.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdType.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdType.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdType extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdType");
+
+ protected String type;
+
+ public CmdType(String type)
+ {
+ this.type = type;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_TYPE,
type));
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdUser.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdUser.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/CmdUser.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class CmdUser extends FtpCommandImpl
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"CmdUser");
+
+ protected String userName;
+
+ public CmdUser(String userName)
+ {
+ this.userName = userName;
+ }
+
+ public int execute()
+ {
+ try
+ {
+ sendCommand(String.format("%s %s", FtpConst.Commands.CMD_USER,
userName));
+ return getReply();
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/FtpCommand.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/FtpCommand.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/FtpCommand.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public interface FtpCommand
+{
+
+ int run(FtpClientSession clientSession);
+
+ int execute();
+
+ int getReply() throws Exception;
+
+ String getDescription();
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/FtpCommandImpl.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/FtpCommandImpl.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/commands/FtpCommandImpl.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.commands;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpUtils;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.OutputStream;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public abstract class FtpCommandImpl implements FtpCommand
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"FtpCommandImpl");
+
+ protected FtpClientSession clientSession;
+
+ // protected PrintStream outPrintStream;
+
+ protected int replyCode;
+
+ protected String descript = "";
+
+ public int run(FtpClientSession clientSession)
+ {
+ this.clientSession = clientSession;
+ try
+ {
+ // outPrintStream = new
PrintStream(clientSession.getClientSocket().getOutputStream());
+ int status = execute();
+ return status;
+ }
+ catch (Exception exc)
+ {
+ log.info("Unhandled exception. " + exc.getMessage(), exc);
+ }
+ return -1;
+ }
+
+ public abstract int execute();
+
+ public void sendCommand(String command)
+ {
+ log.info(">>> " + command);
+
+ try
+ {
+ byte[] data = command.getBytes();
+ OutputStream outStream = clientSession.getClientSocket().getOutputStream();
+ outStream.write(data);
+ outStream.write("\r\n".getBytes());
+ }
+ catch (Exception exc)
+ {
+ log.info("Unhandled exception. " + exc.getMessage(), exc);
+ }
+ }
+
+ private boolean isReplyString(String replyString)
+ {
+ if (replyString.length() < 4)
+ {
+ return false;
+ }
+
+ if (replyString.charAt(0) >= '0' && replyString.charAt(0) <=
'9' && replyString.charAt(1) >= '0'
+ && replyString.charAt(1) <= '9' &&
replyString.charAt(2) >= '0' && replyString.charAt(2) <=
'9'
+ && replyString.charAt(3) == ' ')
+ {
+ return true;
+ }
+ return false;
+ }
+
+ public int getReply() throws Exception
+ {
+ log.info("try get reply..........");
+ String reply = "";
+ String curReply = "";
+
+ while (true)
+ {
+ curReply = readLine();
+
+ if ("".equals(curReply))
+ {
+ reply += "\r\n";
+ }
+ else
+ {
+ reply += curReply;
+ if (isReplyString(curReply))
+ {
+ break;
+ }
+ else
+ {
+ reply += "\r\n";
+ }
+ }
+
+ }
+
+ descript = reply;
+
+ replyCode = FtpUtils.getReplyCode(curReply);
+ log.info("<<< " + descript);
+ return replyCode;
+ }
+
+ public String getDescription()
+ {
+ return descript;
+ }
+
+ // public String readLine() throws Exception {
+ // BufferedReader br = new BufferedReader(new
+ // InputStreamReader(clientSession.getClientSocket().getInputStream()));
+ // return br.readLine();
+ // }
+
+ public String readLine() throws Exception
+ {
+ byte[] buffer = new byte[4 * 1024];
+ int bufPos = 0;
+ byte prevByte = 0;
+
+ while (true)
+ {
+ int received = clientSession.getClientSocket().getInputStream().read();
+ if (received < 0)
+ {
+ return null;
+ }
+
+ buffer[bufPos] = (byte)received;
+ bufPos++;
+
+ if (prevByte == '\r' && received == '\n')
+ {
+ String resultLine = "";
+ for (int i = 0; i < bufPos - 2; i++)
+ {
+ resultLine += (char)buffer[i];
+ }
+ return resultLine;
+ }
+
+ prevByte = (byte)received;
+ }
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpDataTransiver.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpDataTransiver.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpDataTransiver.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.data;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public interface FtpDataTransiver
+{
+
+ public void OpenPassive(String host, int port);
+
+ public boolean OpenActive(int port);
+
+ public boolean isConnected();
+
+ public void close();
+
+ public byte[] receive();
+
+ public boolean send(byte[] data);
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpDataTransiverImpl.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpDataTransiverImpl.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpDataTransiverImpl.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,230 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.data;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.ByteArrayOutputStream;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class FtpDataTransiverImpl implements FtpDataTransiver
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"FtpDataTransiverImpl");
+
+ protected Socket dataSocket = null;
+
+ protected Thread connectionThread;
+
+ public FtpDataTransiverImpl()
+ {
+ }
+
+ public void OpenPassive(String host, int port)
+ {
+ connectionThread = new PassiveThread(host, port);
+ connectionThread.start();
+ }
+
+ public boolean OpenActive(int port)
+ {
+ try
+ {
+ connectionThread = new ActiveThread(port);
+ connectionThread.start();
+ return true;
+ }
+ catch (Exception exc)
+ {
+ log.info("Can't open active mode. PORT is busy. " +
exc.getMessage(), exc);
+ }
+ return false;
+ }
+
+ public boolean isConnected()
+ {
+ if (dataSocket == null)
+ {
+ return false;
+ }
+ return dataSocket.isConnected();
+ }
+
+ public void close()
+ {
+ try
+ {
+ if (connectionThread != null)
+ {
+ connectionThread.stop();
+ }
+ if (dataSocket != null && dataSocket.isConnected())
+ {
+ dataSocket.close();
+ }
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ }
+
+ public byte[] receive()
+ {
+ if (dataSocket == null)
+ {
+ return null;
+ }
+
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+
+ try
+ {
+ byte[] buffer = new byte[4096];
+ while (dataSocket.isConnected())
+ {
+ int readed = dataSocket.getInputStream().read(buffer);
+ if (readed < 0)
+ {
+ break;
+ }
+ outStream.write(buffer, 0, readed);
+ Thread.sleep(10);
+ }
+ }
+ catch (SocketException exc)
+ {
+ // ..
+ }
+ catch (Exception exc)
+ {
+ exc.printStackTrace();
+ }
+
+ try
+ {
+ if (dataSocket.isConnected())
+ {
+ dataSocket.close();
+ }
+ }
+ catch (Exception exc)
+ {
+ log.info("Unhandled exception. " + exc.getMessage(), exc);
+ }
+
+ return outStream.toByteArray();
+ }
+
+ public boolean send(byte[] data)
+ {
+ if (dataSocket != null)
+ {
+ try
+ {
+ dataSocket.getOutputStream().write(data);
+ dataSocket.close();
+ return true;
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ }
+ return false;
+ }
+
+ protected class PassiveThread extends Thread
+ {
+
+ private Log passiveLog =
ExoLogger.getLogger("jcr.FtpDataTransiverImpl__PassiveThread");
+
+ protected String host;
+
+ protected int port;
+
+ public PassiveThread(String host, int port)
+ {
+ this.host = host;
+ this.port = port;
+ }
+
+ public void run()
+ {
+ dataSocket = new Socket();
+ SocketAddress sockAddr = new InetSocketAddress(host, port);
+
+ try
+ {
+ dataSocket.connect(sockAddr);
+ }
+ catch (Exception exc)
+ {
+ passiveLog.info("Can't open PASSIVE mode. " + exc.getMessage(),
exc);
+ }
+
+ }
+
+ }
+
+ protected class ActiveThread extends Thread
+ {
+
+ private Log activeLog =
ExoLogger.getLogger("jcr.FtpDataTransiverImpl__ActiveThread");
+
+ protected int port;
+
+ protected ServerSocket serverSocket;
+
+ public ActiveThread(int port) throws Exception
+ {
+ this.port = port;
+ serverSocket = new ServerSocket(port);
+ }
+
+ public void run()
+ {
+ try
+ {
+ dataSocket = serverSocket.accept();
+ serverSocket.close();
+ }
+ catch (Exception exc)
+ {
+ activeLog.info("Can't open ACTIVE mode. " + exc.getMessage(),
exc);
+ }
+
+ }
+
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpFileInfo.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpFileInfo.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpFileInfo.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.data;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public interface FtpFileInfo
+{
+
+ public void setName(String name);
+
+ public String getName();
+
+ public void setSize(long size);
+
+ public long getSize();
+
+ public void setType(boolean collection);
+
+ public boolean isCollection();
+
+ public void setDate(String date);
+
+ public String getDate();
+
+ public void setTime(String time);
+
+ public String getTime();
+
+ public boolean parseDir(String fileLine, String systemType);
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpFileInfoImpl.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpFileInfoImpl.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpFileInfoImpl.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,278 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.data;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class FtpFileInfoImpl implements FtpFileInfo
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"FtpFileInfoImpl");
+
+ protected String name = "";
+
+ protected long size = 0;
+
+ protected boolean collection = true;
+
+ protected String date = "";
+
+ protected String time = "";
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setSize(long size)
+ {
+ this.size = size;
+ }
+
+ public long getSize()
+ {
+ return size;
+ }
+
+ public void setType(boolean collection)
+ {
+ this.collection = collection;
+ }
+
+ public boolean isCollection()
+ {
+ return collection;
+ }
+
+ public void setDate(String date)
+ {
+ this.date = date;
+ }
+
+ public String getDate()
+ {
+ return date;
+ }
+
+ public void setTime(String time)
+ {
+ this.time = time;
+ }
+
+ public String getTime()
+ {
+ return time;
+ }
+
+ public boolean parseDir(String fileLine, String systemType)
+ {
+ if (systemType.startsWith(FtpConst.SysTypes.WINDOWS_NT))
+ {
+ return parseWindowsNT(fileLine);
+ }
+ if (systemType.startsWith(FtpConst.SysTypes.UNIX_L8))
+ {
+ return parseUnixL8(fileLine);
+ }
+ return false;
+ }
+
+ protected boolean parseWindowsNT(String fileLine)
+ {
+ String fileL = fileLine.substring(0);
+
+ String _date = "";
+ while (fileL.charAt(0) != ' ')
+ {
+ _date += fileL.charAt(0);
+ fileL = fileL.substring(1);
+ }
+
+ while (fileL.charAt(0) == ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+
+ String _time = "";
+
+ while (fileL.charAt(0) != ' ')
+ {
+ _time += fileL.charAt(0);
+ fileL = fileL.substring(1);
+ }
+
+ while (fileL.charAt(0) == ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+
+ String _size = "";
+
+ if (fileL.indexOf("<DIR>") == 0)
+ {
+ collection = true;
+ while (fileL.charAt(0) != ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+ _size = "0";
+ }
+ else
+ {
+ while (fileL.charAt(0) != ' ')
+ {
+ _size += fileL.charAt(0);
+ fileL = fileL.substring(1);
+ }
+ }
+
+ while (fileL.charAt(0) == ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+
+ String _name = fileL;
+
+ this.name = _name;
+ this.date = _date;
+ this.time = _time;
+ this.size = new Long(_size);
+
+ return false;
+ }
+
+ protected boolean parseUnixL8(String fileLine)
+ {
+ String fileL = fileLine;
+
+ if (fileL.charAt(0) == 'd')
+ {
+ collection = true;
+ }
+ else
+ {
+ collection = false;
+ }
+
+ while (fileL.charAt(0) != ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+ while (fileL.charAt(0) == ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+ while (fileL.charAt(0) != ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+ while (fileL.charAt(0) == ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+ while (fileL.charAt(0) != ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+ while (fileL.charAt(0) == ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+ while (fileL.charAt(0) != ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+ while (fileL.charAt(0) == ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+
+ String _size = "";
+ while (fileL.charAt(0) != ' ')
+ {
+ _size += fileL.charAt(0);
+ fileL = fileL.substring(1);
+ }
+
+ while (fileL.charAt(0) == ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+
+ String _month = "";
+ while (fileL.charAt(0) != ' ')
+ {
+ _month += fileL.charAt(0);
+ fileL = fileL.substring(1);
+ }
+
+ while (fileL.charAt(0) == ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+
+ String _day = "";
+ while (fileL.charAt(0) != ' ')
+ {
+ _day += fileL.charAt(0);
+ fileL = fileL.substring(1);
+ }
+
+ while (fileL.charAt(0) == ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+
+ String _time = "";
+ while (fileL.charAt(0) != ' ')
+ {
+ _time += fileL.charAt(0);
+ fileL = fileL.substring(1);
+ }
+
+ while (fileL.charAt(0) == ' ')
+ {
+ fileL = fileL.substring(1);
+ }
+
+ String _name = fileL;
+
+ this.name = _name;
+ this.date = _month + " " + _day;
+ this.time = _time;
+ this.size = new Long(_size);
+
+ return false;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpSlowInputStream1.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpSlowInputStream1.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpSlowInputStream1.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.data;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class FtpSlowInputStream1 extends InputStream
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"FtpSlowInputStream");
+
+ protected InputStream nativeInputStream;
+
+ protected int bytesPerSec;
+
+ protected int blockSize = 0;
+
+ protected int readed = 0;
+
+ public FtpSlowInputStream1(InputStream nativeInputStream, int bytesPerSec)
+ {
+ this.nativeInputStream = nativeInputStream;
+ this.bytesPerSec = bytesPerSec;
+ blockSize = bytesPerSec / 10;
+ }
+
+ protected void tryWaiting()
+ {
+ if (readed >= blockSize)
+ {
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch (Exception exc)
+ {
+ log.info("Unhandled exception until Thread.sleep(...). " +
exc.getMessage(), exc);
+ }
+ readed = 0;
+ }
+ }
+
+ public int read() throws IOException
+ {
+ tryWaiting();
+ int curReaded = nativeInputStream.read();
+ if (curReaded >= 0)
+ {
+ readed++;
+ }
+ return curReaded;
+ }
+
+ public int read(byte[] buffer) throws IOException
+ {
+ return read(buffer, 0, buffer.length);
+ }
+
+ public int read(byte[] buffer, int offset, int size) throws IOException
+ {
+ tryWaiting();
+
+ int curBlockSize = blockSize - readed;
+ if (curBlockSize > size)
+ {
+ curBlockSize = size;
+ }
+
+ int curReaded = nativeInputStream.read(buffer, offset, curBlockSize);
+
+ readed += curReaded;
+ return curReaded;
+ }
+
+ public long skip(long skipVal) throws IOException
+ {
+ return nativeInputStream.skip(skipVal);
+ }
+
+ public int available() throws IOException
+ {
+ return nativeInputStream.available();
+ }
+
+ public void close() throws IOException
+ {
+ nativeInputStream.close();
+ }
+
+ public synchronized void mark(int markVal)
+ {
+ nativeInputStream.mark(markVal);
+ }
+
+ public synchronized void reset() throws IOException
+ {
+ nativeInputStream.reset();
+ }
+
+ public boolean markSupported()
+ {
+ return nativeInputStream.markSupported();
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpSlowOutputStream.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpSlowOutputStream.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/main/java/org/exoplatform/frameworks/ftpclient/data/FtpSlowOutputStream.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.data;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class FtpSlowOutputStream extends OutputStream
+{
+
+ private static Log log = ExoLogger.getLogger(FtpConst.FTP_PREFIX +
"FtpSlowOutputStream");
+
+ private OutputStream nativeOutputStream;
+
+ private int bytesPerSec;
+
+ private int blockSize;
+
+ private int writed = 0;
+
+ public FtpSlowOutputStream(OutputStream nativeOutputStream, int bytesPerSec)
+ {
+ this.nativeOutputStream = nativeOutputStream;
+ this.bytesPerSec = bytesPerSec;
+
+ blockSize = bytesPerSec / 10;
+ }
+
+ protected void tryWaiting()
+ {
+ if (writed >= blockSize)
+ {
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch (Exception exc)
+ {
+ log.info("Unhandled exception. " + exc.getMessage(), exc);
+ }
+ writed = 0;
+ }
+ }
+
+ public void write(int dataByte) throws IOException
+ {
+ tryWaiting();
+ nativeOutputStream.write(dataByte);
+ writed++;
+ }
+
+ public void write(byte[] dataBytes) throws IOException
+ {
+ write(dataBytes, 0, dataBytes.length);
+ }
+
+ public void write(byte[] dataBytes, int offset, int len) throws IOException
+ {
+ int allWrited = 0;
+ int curOffset = offset;
+
+ while (allWrited < len)
+ {
+ tryWaiting();
+
+ int curBlockSize = blockSize - writed;
+ if ((curBlockSize + allWrited) > len)
+ {
+ curBlockSize = len - allWrited;
+ }
+
+ nativeOutputStream.write(dataBytes, curOffset, curBlockSize);
+
+ allWrited += curBlockSize;
+ writed += curBlockSize;
+ curOffset += curBlockSize;
+ }
+ }
+
+ public void flush() throws IOException
+ {
+ nativeOutputStream.flush();
+ }
+
+ public void close() throws IOException
+ {
+ nativeOutputStream.close();
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/FtpTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/FtpTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/FtpTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,697 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdCdUp;
+import org.exoplatform.frameworks.ftpclient.commands.CmdCwd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdDele;
+import org.exoplatform.frameworks.ftpclient.commands.CmdList;
+import org.exoplatform.frameworks.ftpclient.commands.CmdMkd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdNlst;
+import org.exoplatform.frameworks.ftpclient.commands.CmdNoop;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPasv;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPort;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPwd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRest;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRetr;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRmd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRnFr;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRnTo;
+import org.exoplatform.frameworks.ftpclient.commands.CmdSize;
+import org.exoplatform.frameworks.ftpclient.commands.CmdStor;
+import org.exoplatform.frameworks.ftpclient.commands.CmdSyst;
+import org.exoplatform.frameworks.ftpclient.commands.CmdType;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+import org.exoplatform.frameworks.ftpclient.data.FtpDataTransiver;
+import org.exoplatform.frameworks.ftpclient.data.FtpDataTransiverImpl;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.Random;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class FtpTest extends TestCase
+{
+
+ protected static Log getLogger(String unitName)
+ {
+ return ExoLogger.getLogger("jcr." + unitName);
+ }
+
+ public void testNOOP() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_NOOP);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(new CmdNoop()));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testUSER() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_USER);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testPASS() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_PASS);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testSYST() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_SYST);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
+
+ log.info("Complete.");
+ }
+
+ public void testPWD() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_PWD);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+
+ CmdPwd cmdPwd = new CmdPwd();
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdPwd));
+
+ log.info("CURRENTPATH - [" + cmdPwd.getCurrentPath() + "]");
+
+ // assertEquals("/", cmdPwd.getCurrentPath());
+
+ log.info("Complete.");
+ }
+
+ public void testCWD() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_CWD);
+ log.info("Test...");
+
+ // success
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdCwd("production")));
+
+ CmdPwd cmdPwd = new CmdPwd();
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdPwd));
+ assertEquals("/production", cmdPwd.getCurrentPath());
+
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdCwd("../backup/")));
+
+ cmdPwd = new CmdPwd();
+
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdPwd));
+ assertEquals("/backup", cmdPwd.getCurrentPath());
+
+ assertEquals(FtpConst.Replyes.REPLY_550, client.executeCommand(new
CmdCwd("production")));
+
+ client.close();
+
+ // denied
+ client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(new
CmdCwd("production")));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testCDUP() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_CDUP);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdCwd("production")));
+
+ CmdPwd cmdPwd = new CmdPwd();
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdPwd));
+ assertEquals("/production", cmdPwd.getCurrentPath());
+
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new CmdCdUp()));
+
+ cmdPwd = new CmdPwd();
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdPwd));
+ assertEquals("/", cmdPwd.getCurrentPath());
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testTYPE() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_TYPE);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+
+ assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(new
CmdType("A")));
+ assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(new
CmdType("I")));
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(new
CmdType("SOMETYPE")));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testPASV() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_PASV);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ boolean connected = false;
+
+ for (int i = 0; i < 15; i++)
+ {
+ try
+ {
+ if (client.getDataTransiver().isConnected())
+ {
+ connected = true;
+ break;
+ }
+ Thread.sleep(1000);
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ }
+
+ assertEquals(true, connected);
+
+ client.getDataTransiver().close();
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testPORT() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_PORT);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+
+ int MIN_PORT_VAL = 9000;
+ int MAX_PORT_VAL = 10000;
+
+ int ports = MAX_PORT_VAL - MIN_PORT_VAL + 1;
+
+ Random random = new Random();
+
+ String host = "127.0.0.1";
+ int port = 0;
+
+ boolean enableSearch = true;
+ while (enableSearch)
+ {
+ port = MIN_PORT_VAL + random.nextInt(ports);
+ if (FtpUtils.isPortFree(port))
+ {
+ enableSearch = false;
+ }
+ }
+
+ FtpDataTransiver dataTransiver = new FtpDataTransiverImpl();
+ dataTransiver.OpenActive(port);
+ client.setDataTransiver(dataTransiver);
+
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+
+ CmdPort cmdPort = new CmdPort(host, port);
+
+ assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(cmdPort));
+
+ boolean connected = false;
+ for (int i = 0; i < 15; i++)
+ {
+ try
+ {
+ if (client.getDataTransiver().isConnected())
+ {
+ connected = true;
+ break;
+ }
+ Thread.sleep(1000);
+ }
+ catch (Exception exc)
+ {
+ log.info(FtpConst.EXC_MSG + exc.getMessage(), exc);
+ }
+ }
+
+ assertEquals(true, connected);
+
+ client.getDataTransiver().close();
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testLIST() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_LIST);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdCwd("production")));
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(new CmdList()));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testNLST() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_NLST);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdCwd("production")));
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(new CmdNlst()));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testMKD() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_MKD);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(new
CmdMkd("/production/test_folder")));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testRMD() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_RMD);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(new
CmdMkd("/production/test_folder")));
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdRmd("/production/test_folder")));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testRNFR_RNTO() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_RNFR + "_" +
FtpConst.Commands.CMD_RNTO);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(new
CmdMkd("/production/test_kokanoid_torename")));
+
+ assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(new
CmdRnFr("/production/test_kokanoid_torename")));
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdRnTo("/production/test_kokanoid_renamed")));
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdRmd("/production/test_kokanoid_renamed")));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ protected static final String FILE_CONTENT = "eXo TEST File Content...";
+
+ public void testSTOR() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_STOR);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ CmdStor cmdStor = new CmdStor("/production/test_file.txt");
+
+ byte[] data = new byte[FILE_CONTENT.length()];
+ char[] chars = FILE_CONTENT.toCharArray();
+ for (int i = 0; i < data.length; i++)
+ {
+ data[i] = (byte)chars[i];
+ }
+
+ cmdStor.setFileContent(data);
+
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdStor));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testSIZE() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_SIZE);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
+
+ assertEquals(FtpConst.Replyes.REPLY_213, client.executeCommand(new
CmdSize("/production/test_file.txt")));
+
+ // retrieve size here..., assert it
+
+ assertEquals(FtpConst.Replyes.REPLY_550, client.executeCommand(new
CmdSize("/production/test_file_absent.txt")));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testRETR() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_RETR);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ CmdRetr cmdRetr = new CmdRetr("/production/test_file.txt");
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdRetr));
+
+ byte[] fileContent = cmdRetr.getFileContent();
+ assertEquals(fileContent.length, FILE_CONTENT.length());
+
+ for (int i = 0; i < fileContent.length; i++)
+ {
+ if (fileContent[i] != FILE_CONTENT.charAt(i))
+ {
+ fail();
+ }
+ }
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testREST() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_REST);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(new CmdRest(9)));
+
+ CmdRetr cmdRetr = new CmdRetr("/production/test_file.txt");
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdRetr));
+
+ byte[] fileContent = cmdRetr.getFileContent();
+ assertEquals(fileContent.length, FILE_CONTENT.length() - 9);
+
+ for (int i = 0; i < fileContent.length; i++)
+ {
+ if (fileContent[i] != FILE_CONTENT.charAt(i + 9))
+ {
+ fail();
+ }
+ }
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ public void testDELE() throws Exception
+ {
+ Log log = getLogger(FtpConst.Commands.CMD_DELE);
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdDele("/production/test_file.txt")));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+ protected byte[] getBytes(String content)
+ {
+ byte[] data = new byte[content.length()];
+ for (int i = 0; i < data.length; i++)
+ {
+ data[i] = (byte)content.charAt(i);
+ }
+ return data;
+ }
+
+ public void testREST_STOR() throws Exception
+ {
+ Log log = getLogger("REST_STOR");
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
+
+ String fileName = "/production/resr_test_file.txt";
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ byte[] data = getBytes("DATABYTES");
+
+ CmdStor cmdStor = new CmdStor(fileName);
+ cmdStor.setFileContent(data);
+
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdStor));
+
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ CmdRetr cmdRetr = new CmdRetr(fileName);
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdRetr));
+
+ byte[] dataAfter = cmdRetr.getFileContent();
+ for (int i = 0; i < dataAfter.length; i++)
+ {
+ if (dataAfter[i] != data[i])
+ {
+ fail();
+ }
+ }
+
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(new
CmdRest(data.length)));
+
+ byte[] secondData = getBytes("_APPENDED");
+
+ cmdStor = new CmdStor(fileName);
+ cmdStor.setFileContent(secondData);
+
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdStor));
+
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ cmdRetr = new CmdRetr(fileName);
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdRetr));
+
+ String secondString = "DATABYTES_APPENDED";
+
+ byte[] secondDataAfter = cmdRetr.getFileContent();
+ for (int i = 0; i < secondDataAfter.length; i++)
+ {
+ if (secondDataAfter[i] != (byte)secondString.charAt(i))
+ {
+ fail();
+ }
+ }
+
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(new CmdRest(4)));
+
+ byte[] replasedData = getBytes("INT");
+
+ cmdStor = new CmdStor(fileName);
+ cmdStor.setFileContent(replasedData);
+
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdStor));
+
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ cmdRetr = new CmdRetr(fileName);
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdRetr));
+
+ String readyString = "DATAINTES_APPENDED";
+
+ byte[] readyBytes = cmdRetr.getFileContent();
+ for (int i = 0; i < readyBytes.length; i++)
+ {
+ if (readyBytes[i] != (byte)readyString.charAt(i))
+ {
+ fail();
+ }
+ }
+
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdDele(fileName)));
+
+ client.close();
+
+ log.info("Complete.");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/FtpTestConfig.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/FtpTestConfig.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/FtpTestConfig.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient;
+
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSessionImpl;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class FtpTestConfig
+{
+
+ /*
+ * Server location
+ */
+
+ public static final String FTP_HOST = "localhost";
+
+ public static final int FTP_PORT = 2121;
+
+ /*
+ * Credentials and workspaceName
+ */
+
+ public static final String USER_ID = "admin";
+
+ public static final String USER_PASS = "admin";
+
+ public static final String TEST_WORKSPACE = "production";
+
+ /*
+ * MultiThread
+ */
+
+ public static final int CLIENTS_COUNT = 20;
+
+ public static final int CLIENT_DEPTH = 2;
+
+ public static final String TEST_FOLDER = "/" + TEST_WORKSPACE +
"/crash_test2";
+
+ public static FtpClientSession getTestFtpClient()
+ {
+ return new FtpClientSessionImpl(FTP_HOST, FTP_PORT);
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/FtpTests.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/FtpTests.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/FtpTests.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.cmdtests.CDUPTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.CWDTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.DELETest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.HELPTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.LISTTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.MKDTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.MODETest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.NLSTTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.NOOPTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.PASVTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.PORTTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.PWDTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.QUITTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.RESTTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.RETRTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.RMDTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.RNFRTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.RNTOTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.SIZETest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.STATTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.STORTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.STRUTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.SYSTTest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.TYPETest;
+import org.exoplatform.frameworks.ftpclient.cmdtests.USERPASSTest;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class FtpTests extends TestCase
+{
+
+ public static TestSuite suite()
+ {
+ Log log = new Log("FtpTests");
+
+ log.info("Checking server...");
+
+ TestSuite suite = new TestSuite("jcr.ftp tests");
+
+ log.info("checking...");
+ if (!isServerPresent())
+ {
+ log.info("Server not found! Tests are skipping...");
+ return suite;
+ }
+
+ log.info("Preparing FTP tests...");
+
+ suite.addTestSuite(NOOPTest.class);
+ suite.addTestSuite(HELPTest.class);
+ suite.addTestSuite(QUITTest.class);
+ suite.addTestSuite(USERPASSTest.class);
+ suite.addTestSuite(MODETest.class);
+ suite.addTestSuite(TYPETest.class);
+ suite.addTestSuite(SYSTTest.class);
+ suite.addTestSuite(STRUTest.class);
+ suite.addTestSuite(STATTest.class);
+ suite.addTestSuite(PWDTest.class);
+ suite.addTestSuite(CWDTest.class);
+ suite.addTestSuite(CDUPTest.class);
+ suite.addTestSuite(MKDTest.class);
+ suite.addTestSuite(RMDTest.class);
+ suite.addTestSuite(DELETest.class);
+ suite.addTestSuite(PASVTest.class);
+ suite.addTestSuite(PORTTest.class);
+ suite.addTestSuite(LISTTest.class);
+ suite.addTestSuite(NLSTTest.class);
+ suite.addTestSuite(SIZETest.class);
+ suite.addTestSuite(RNFRTest.class);
+ suite.addTestSuite(RNTOTest.class);
+ suite.addTestSuite(RESTTest.class);
+ suite.addTestSuite(STORTest.class);
+ suite.addTestSuite(RETRTest.class);
+
+ return suite;
+ }
+
+ private static boolean isServerPresent()
+ {
+ try
+ {
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ boolean connected = client.connect();
+
+ if (connected)
+ {
+ client.close();
+ return true;
+ }
+
+ }
+ catch (Exception exc)
+ {
+ }
+
+ return false;
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/MultiThreadFtpTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/MultiThreadFtpTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/MultiThreadFtpTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,288 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSessionImpl;
+import org.exoplatform.frameworks.ftpclient.commands.CmdList;
+import org.exoplatform.frameworks.ftpclient.commands.CmdMkd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPasv;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRetr;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRmd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdStor;
+import org.exoplatform.frameworks.ftpclient.commands.CmdSyst;
+import org.exoplatform.frameworks.ftpclient.commands.CmdType;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.ArrayList;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author Vitaly Guly
+ * @version $Id: $
+ */
+
+public class MultiThreadFtpTest extends TestCase
+{
+
+ public static final int ITEMS_COUNT = 3;
+
+ public static final int CLIENTS_COUNT = 10;
+
+ protected class FtpThreadTest extends Thread
+ {
+
+ protected Log log;
+
+ protected String testFolder;
+
+ public FtpThreadTest(String testFolder)
+ {
+ log = ExoLogger.getLogger("jcr." + this);
+ this.testFolder = testFolder;
+ }
+
+ protected void createFolders(String rootTestFolder)
+ {
+ try
+ {
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser(FtpTestConfig.USER_ID)));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass(FtpTestConfig.USER_PASS)));
+
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new
CmdSyst()));
+ assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(new
CmdType("A")));
+
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new
CmdPasv()));
+
+ log.info("Verify folder exists...");
+
+ if (client.executeCommand(new CmdList(rootTestFolder)) ==
FtpConst.Replyes.REPLY_226)
+ {
+ log.info("Test folder exist. try delete it...");
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdRmd(rootTestFolder)));
+ log.info("Deleted.");
+ }
+
+ for (int i1 = 1; i1 <= ITEMS_COUNT; i1++)
+ {
+ String folder1 = rootTestFolder + "/folder_" + i1;
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(new
CmdMkd(folder1)));
+ for (int i2 = 1; i2 <= ITEMS_COUNT; i2++)
+ {
+ String folder2 = folder1.substring(0);
+ folder2 += "/subfolder_" + i2;
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(new
CmdMkd(folder2)));
+
+ for (int i3 = 0; i3 < ITEMS_COUNT; i3++)
+ {
+
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new
CmdPasv()));
+
+ String file3 = folder2.substring(0);
+ file3 += "/test_file_" + i3 + ".txt";
+
+ CmdStor cmdStor = new CmdStor(file3);
+
+ byte[] fileData = new byte[256 * 4];
+ for (int c = 0; c < 256 * 4; c++)
+ {
+ fileData[c] = (byte)'A';
+ fileData[c] = fileData[c] += (byte)i3;
+ }
+
+ cmdStor.setFileContent(fileData);
+ assertEquals(FtpConst.Replyes.REPLY_226,
client.executeCommand(cmdStor));
+
+ log.info("File [" + file3 + "] created");
+
+ }
+
+ }
+ }
+
+ client.close();
+ }
+ catch (Exception exc)
+ {
+ log.info("Unhandled exception. " + exc.getMessage(), exc);
+ }
+ }
+
+ public void readAllFolders(String rootTestFolder)
+ {
+ try
+ {
+ FtpClientSession client = new FtpClientSessionImpl("127.0.0.1",
21);
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new
CmdSyst()));
+ assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(new
CmdType("A")));
+
+ for (int i1 = 1; i1 <= ITEMS_COUNT; i1++)
+ {
+ String folder1 = rootTestFolder + "/folder_" + i1;
+ for (int i2 = 1; i2 <= ITEMS_COUNT; i2++)
+ {
+ String folder2 = folder1.substring(0);
+ folder2 += "/subfolder_" + i2;
+ for (int i3 = 0; i3 < ITEMS_COUNT; i3++)
+ {
+ String file3 = folder2.substring(0);
+ file3 += "/test_file_" + i3 + ".txt";
+
+ log.info("CurFileName - [" + file3 + "]");
+
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new
CmdPasv()));
+
+ CmdRetr cmdRetr = new CmdRetr(file3);
+ int reply = client.executeCommand(cmdRetr);
+
+ log.info("RETR REPLY - " + reply);
+
+ }
+
+ }
+
+ }
+
+ client.close();
+
+ }
+ catch (Exception exc)
+ {
+ log.info("Unhandled exception. " + exc.getMessage(), exc);
+ }
+ }
+
+ public void removeAllFolders(String rootTestFolder)
+ {
+ log.info("Clearing...");
+ try
+ {
+ FtpClientSession client = new FtpClientSessionImpl("127.0.0.1",
21);
+ client.connect();
+
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser("admin")));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass("admin")));
+
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new
CmdSyst()));
+ assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(new
CmdType("A")));
+
+ for (int i1 = 1; i1 <= ITEMS_COUNT; i1++)
+ {
+ String folder1 = rootTestFolder + "/folder_" + i1;
+ for (int i2 = 1; i2 <= ITEMS_COUNT; i2++)
+ {
+ String folder2 = folder1.substring(0);
+ folder2 += "/subfolder_" + i2;
+ for (int i3 = 0; i3 < ITEMS_COUNT; i3++)
+ {
+ String file3 = folder2.substring(0);
+ file3 += "/test_file_" + i3 + ".txt";
+
+ log.info("Try delete [" + file3 + "]...");
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdRmd(file3)));
+ }
+
+ log.info("Try delete [" + folder2 + "]...");
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdRmd(folder2)));
+ }
+
+ log.info("Try delete [" + folder1 + "]...");
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdRmd(folder1)));
+
+ }
+
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdRmd(rootTestFolder)));
+
+ client.close();
+ }
+ catch (Exception exc)
+ {
+ log.info("Unhandled exception. " + exc.getMessage(), exc);
+ }
+ log.info("Complete.");
+ }
+
+ public void run()
+ {
+ log.info("Start test...");
+ createFolders(testFolder);
+ readAllFolders(testFolder);
+ removeAllFolders(testFolder);
+ log.info("Test complete.");
+ }
+
+ }
+
+ public void testMultiThread() throws Exception
+ {
+ Log log = ExoLogger.getLogger("jcr.MultiThreadFtpTest");
+ log.info("Test...");
+
+ ArrayList<FtpThreadTest> testers = new ArrayList<FtpThreadTest>();
+
+ for (int i = 0; i < CLIENTS_COUNT; i++)
+ {
+ String testFolder = "/production/test_folder_" + i;
+ FtpThreadTest curTest = new FtpThreadTest(testFolder);
+ testers.add(curTest);
+ curTest.start();
+ }
+
+ try
+ {
+ boolean enable = true;
+ while (enable)
+ {
+
+ enable = false;
+ for (int i = 0; i < testers.size(); i++)
+ {
+ FtpThreadTest curTest = testers.get(i);
+ if (curTest.isAlive())
+ {
+ enable = true;
+ }
+ }
+
+ Thread.sleep(100);
+ }
+ }
+ catch (Exception exc)
+ {
+ log.info("Unhandled ecxeption. " + exc.getMessage(), exc);
+ }
+
+ log.info("Complete.");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/CDUPTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/CDUPTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/CDUPTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdCdUp;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class CDUPTest extends TestCase
+{
+
+ private static Log log = new Log("CDUPTest");
+
+ public void testCDUP() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdCdUp cmdCdUp = new CmdCdUp();
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdCdUp));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdCdUp cmdCdUp = new CmdCdUp();
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdCdUp));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/CWDTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/CWDTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/CWDTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdCwd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class CWDTest extends TestCase
+{
+
+ private static Log log = new Log("CWDTest");
+
+ public void testCWD() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdCwd cmdCwd = new CmdCwd("");
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdCwd));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdCwd cmdCwd = new CmdCwd("");
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdCwd));
+ }
+
+ {
+ CmdCwd cmdCwd = new CmdCwd("NotExistFolder");
+ assertEquals(FtpConst.Replyes.REPLY_550, client.executeCommand(cmdCwd));
+ }
+
+ {
+ CmdCwd cmdCwd = new CmdCwd("production");
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdCwd));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/DELETest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/DELETest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/DELETest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdCwd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdDele;
+import org.exoplatform.frameworks.ftpclient.commands.CmdMkd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class DELETest extends TestCase
+{
+
+ private static Log log = new Log("DELETest");
+
+ public void testDELE() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdDele cmdDele = new CmdDele("");
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdDele));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdDele cmdDele = new CmdDele("");
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdDele));
+ }
+
+ {
+ CmdDele cmdDele = new CmdDele("NotExistFolder");
+ assertEquals(FtpConst.Replyes.REPLY_550, client.executeCommand(cmdDele));
+ }
+
+ {
+ CmdCwd cmdCwd = new CmdCwd("production");
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdCwd));
+ }
+
+ String folderName = "testFolder_" + System.currentTimeMillis();
+
+ {
+ CmdMkd cmdMkd = new CmdMkd(folderName);
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdMkd));
+ }
+
+ {
+ CmdDele cmdDele = new CmdDele(folderName);
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdDele));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/HELPTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/HELPTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/HELPTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdHelp;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class HELPTest extends TestCase
+{
+
+ private static Log log = new Log("HELPTest");
+
+ public void testHELP() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ CmdHelp cmdHelp = new CmdHelp();
+ assertEquals(FtpConst.Replyes.REPLY_214, client.executeCommand(cmdHelp));
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/LISTTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/LISTTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/LISTTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdList;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPasv;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class LISTTest extends TestCase
+{
+
+ private static Log log = new Log("LISTTest");
+
+ public void testLIST() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdList cmdList = new CmdList();
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdList));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdList cmdList = new CmdList();
+ assertEquals(FtpConst.Replyes.REPLY_425, client.executeCommand(cmdList));
+ }
+
+ {
+ {
+ CmdPasv cmdPasv = new CmdPasv();
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(cmdPasv));
+ }
+
+ {
+ CmdList cmdList = new CmdList("NotExistFolder");
+ assertEquals(FtpConst.Replyes.REPLY_450, client.executeCommand(cmdList));
+ }
+ }
+
+ {
+ {
+ CmdPasv cmdPasv = new CmdPasv();
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(cmdPasv));
+ }
+
+ // Normal executing replies sequence 125..226
+ // 125 used in List command inside
+ {
+ CmdList cmdList = new CmdList();
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdList));
+ }
+ }
+
+ client.close();
+
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/MKDTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/MKDTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/MKDTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdCwd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdMkd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRmd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class MKDTest extends TestCase
+{
+
+ private static Log log = new Log("MKDTest");
+
+ public void testMKD() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdMkd cmdMkd = new CmdMkd("");
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdMkd));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdMkd cmdMkd = new CmdMkd("");
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdMkd));
+ }
+
+ {
+ CmdMkd cmdMkd = new CmdMkd("myfolder");
+ assertEquals(FtpConst.Replyes.REPLY_550, client.executeCommand(cmdMkd));
+ }
+
+ {
+ CmdCwd cmdCwd = new CmdCwd("production");
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdCwd));
+
+ String folderName = "test_folder_" + System.currentTimeMillis();
+
+ CmdMkd cmdMkd = new CmdMkd(folderName);
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdMkd));
+
+ CmdRmd cmdRmd = new CmdRmd(folderName);
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdRmd));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/MODETest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/MODETest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/MODETest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdMode;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class MODETest extends TestCase
+{
+
+ private static Log log = new Log("MODETest");
+
+ public void testMODE() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ // param required
+ {
+ CmdMode cmdMode = new CmdMode("");
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdMode));
+ }
+
+ // Mode set to S
+
+ {
+ CmdMode cmdMode = new CmdMode("s");
+ assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(cmdMode));
+ }
+
+ // unsupported modes - c, b
+
+ {
+ CmdMode cmdMode = new CmdMode("c");
+ assertEquals(FtpConst.Replyes.REPLY_504, client.executeCommand(cmdMode));
+ }
+
+ {
+ CmdMode cmdMode = new CmdMode("b");
+ assertEquals(FtpConst.Replyes.REPLY_504, client.executeCommand(cmdMode));
+ }
+
+ // unrecognized modes
+
+ {
+ CmdMode cmdMode = new CmdMode("a");
+ assertEquals(FtpConst.Replyes.REPLY_501, client.executeCommand(cmdMode));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/NLSTTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/NLSTTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/NLSTTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdNlst;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPasv;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class NLSTTest extends TestCase
+{
+
+ private static Log log = new Log("NLSTTest");
+
+ public void testNLST() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdNlst cmdNlst = new CmdNlst();
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdNlst));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdNlst cmdNlst = new CmdNlst();
+ assertEquals(FtpConst.Replyes.REPLY_425, client.executeCommand(cmdNlst));
+ }
+
+ {
+ {
+ CmdPasv cmdPasv = new CmdPasv();
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(cmdPasv));
+ }
+
+ {
+ CmdNlst cmdNlst = new CmdNlst("NotExistFolder");
+ assertEquals(FtpConst.Replyes.REPLY_450, client.executeCommand(cmdNlst));
+ }
+ }
+
+ {
+ {
+ CmdPasv cmdPasv = new CmdPasv();
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(cmdPasv));
+ }
+
+ // Normal executing replies sequence 125..226
+ // 125 used in NLst command inside
+ {
+ CmdNlst cmdNlst = new CmdNlst();
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdNlst));
+ }
+ }
+
+ client.close();
+
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/NOOPTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/NOOPTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/NOOPTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdNoop;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class NOOPTest extends TestCase
+{
+
+ private static Log log = new Log("NOOPTest");
+
+ public void testNOOP() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ CmdNoop cmdNoop = new CmdNoop();
+ assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(cmdNoop));
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/PASVTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/PASVTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/PASVTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPasv;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class PASVTest extends TestCase
+{
+
+ private static Log log = new Log("PASVTest");
+
+ public void testPASV() throws Exception
+ {
+ log.info("Test...");
+
+ {
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdPasv cmdPasv = new CmdPasv();
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdPasv));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdPasv cmdPasv = new CmdPasv();
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(cmdPasv));
+ }
+
+ log.info("Waiting for connection...");
+
+ while (true)
+ {
+ if (client.getDataTransiver().isConnected())
+ {
+ break;
+ }
+ Thread.sleep(1);
+ }
+
+ log.info("Connected.");
+
+ client.close();
+ }
+
+ // // NOW try to get all available channels
+ // // then server reply 421
+ // {
+ //
+ // ArrayList<FtpClientSession> clients = new
ArrayList<FtpClientSession>();
+ //
+ // // configuration params
+ // int FTP_MIN_PORT = 32000;
+ // int FTP_MAX_PORT = 32100;
+ //
+ // int CLIENTS_COUNT = FTP_MAX_PORT - FTP_MIN_PORT + 2;
+ //
+ // log.info("Starting CRUSH test...");
+ // log.info("CLIENTS COUNT - " + CLIENTS_COUNT);
+ // Thread.sleep(2000);
+ // log.info("Started...");
+ //
+ // for (int i = 0; i < CLIENTS_COUNT; i++) {
+ // FtpClientSession curClient = FtpTestConfig.getTestFtpClient();
+ // curClient.connect();
+ //
+ // clients.add(curClient);
+ //
+ // {
+ // CmdUser cmdUser = new CmdUser(USER_ID);
+ // assertEquals(FtpConst.Replyes.REPLY_331, curClient.executeCommand(cmdUser));
+ // }
+ //
+ // {
+ // CmdPass cmdPass = new CmdPass(USER_PASS);
+ // assertEquals(FtpConst.Replyes.REPLY_230, curClient.executeCommand(cmdPass));
+ // }
+ //
+ // CmdPasv cmdPasv = new CmdPasv();
+ //
+ // if (i == CLIENTS_COUNT - 1) {
+ // assertEquals(FtpConst.Replyes.REPLY_421, curClient.executeCommand(cmdPasv));
+ // } else {
+ // assertEquals(FtpConst.Replyes.REPLY_227, curClient.executeCommand(cmdPasv));
+ // }
+ //
+ // }
+ //
+ // for (int i = 0; i < CLIENTS_COUNT; i++) {
+ // FtpClientSession curClient = clients.get(i);
+ // curClient.close();
+ // }
+ //
+ // }
+
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/PORTTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/PORTTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/PORTTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPort;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class PORTTest extends TestCase
+{
+
+ private static Log log = new Log("PORTTest");
+
+ public void testPORT() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdPort cmdPort = new CmdPort("127.0.0.1", 80);
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdPort));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdPort cmdPort = new CmdPort(null, 80);
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdPort));
+ }
+
+ {
+ CmdPort cmdPort = new CmdPort("invalidhost", 80);
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdPort));
+ }
+
+ {
+ CmdPort cmdPort = new CmdPort("127,0,0,1", 80);
+ assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(cmdPort));
+ }
+
+ client.close();
+
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/PWDTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/PWDTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/PWDTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPwd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class PWDTest extends TestCase
+{
+
+ private static Log log = new Log("PWDTest");
+
+ public void testPWD() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdPwd cmdPwd = new CmdPwd();
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdPwd));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdPwd cmdPwd = new CmdPwd();
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdPwd));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/QUITTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/QUITTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/QUITTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdQuit;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class QUITTest extends TestCase
+{
+
+ private static Log log = new Log("QUITTest");
+
+ public void test_QUIT() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ CmdQuit cmdQuit = new CmdQuit();
+ assertEquals(FtpConst.Replyes.REPLY_221, client.executeCommand(cmdQuit));
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RESTTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RESTTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RESTTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRest;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class RESTTest extends TestCase
+{
+
+ private static Log log = new Log("RESTTest");
+
+ public void testREST() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdRest cmdRest = new CmdRest(-1);
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdRest));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdRest cmdRest = new CmdRest(null);
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdRest));
+ }
+
+ {
+ CmdRest cmdRest = new CmdRest("notoffset");
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdRest));
+ }
+
+ {
+ CmdRest cmdRest = new CmdRest("100");
+ assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(cmdRest));
+ }
+
+ {
+ CmdRest cmdRest = new CmdRest(200);
+ assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(cmdRest));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RETRTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RETRTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RETRTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdCwd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdDele;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPasv;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRest;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRetr;
+import org.exoplatform.frameworks.ftpclient.commands.CmdStor;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class RETRTest extends TestCase
+{
+
+ private static Log log = new Log("RETRTest");
+
+ public void testRETR() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ // desired reply - 530 Please login with USER and PASS
+ {
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(new
CmdRetr(null)));
+ }
+
+ // login
+ {
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser(FtpTestConfig.USER_ID)));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass(FtpTestConfig.USER_PASS)));
+ }
+
+ // desired reply - 425 Unable to build data connection
+ {
+ assertEquals(FtpConst.Replyes.REPLY_425, client.executeCommand(new
CmdRetr(null)));
+ }
+
+ // desired reply - 500 RETR: command requires a parameter
+ {
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(new
CmdRetr(null)));
+ }
+
+ String fileName = "test_file_" + System.currentTimeMillis() +
".txt";
+ byte[] fileContent = "THIS FILE CONTENT".getBytes();
+
+ // desired reply - 550 $: Permission denied
+ {
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+ assertEquals(FtpConst.Replyes.REPLY_550, client.executeCommand(new
CmdRetr(fileName)));
+ }
+
+ {
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdCwd("production")));
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ CmdStor cmdStor = new CmdStor(fileName);
+ cmdStor.setFileContent(fileContent);
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdStor));
+ }
+
+ // desired reply - 125 Data connection already open; Transfer starting
+ // 226 Transfer complete
+ {
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+ CmdRetr cmdRetr = new CmdRetr(fileName);
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdRetr));
+ }
+
+ // desired reply - 550 Restore value invalid
+ {
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+ assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(new
CmdRest(100000)));
+
+ CmdRetr cmdRetr = new CmdRetr(fileName);
+ assertEquals(FtpConst.Replyes.REPLY_550, client.executeCommand(cmdRetr));
+ }
+
+ {
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdDele(fileName)));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RMDTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RMDTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RMDTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdCwd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdMkd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRmd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class RMDTest extends TestCase
+{
+
+ private static Log log = new Log("RMDTest");
+
+ public void testRMD() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdRmd cmdRmd = new CmdRmd("");
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdRmd));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdRmd cmdRmd = new CmdRmd("");
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdRmd));
+ }
+
+ {
+ CmdRmd cmdRmd = new CmdRmd("NotexistFolder");
+ assertEquals(FtpConst.Replyes.REPLY_550, client.executeCommand(cmdRmd));
+ }
+
+ {
+ CmdCwd cmdCwd = new CmdCwd("production");
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdCwd));
+
+ String folderName = "test_folder_" + System.currentTimeMillis();
+
+ CmdMkd cmdMkd = new CmdMkd(folderName);
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdMkd));
+
+ CmdRmd cmdRmd = new CmdRmd(folderName);
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdRmd));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RNFRTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RNFRTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RNFRTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdDele;
+import org.exoplatform.frameworks.ftpclient.commands.CmdMkd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRnFr;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class RNFRTest extends TestCase
+{
+
+ private static Log log = new Log("RNFRTest");
+
+ public void testRNFR() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdRnFr cmdRnFr = new CmdRnFr(null);
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdRnFr));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdRnFr cmdRnFr = new CmdRnFr(null);
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdRnFr));
+ }
+
+ {
+ CmdRnFr cmdRnFr = new CmdRnFr("NotExistFolder");
+ assertEquals(FtpConst.Replyes.REPLY_550, client.executeCommand(cmdRnFr));
+ }
+
+ String folderName = "/production/folder_to_rename";
+
+ {
+ CmdMkd cmdMkd = new CmdMkd(folderName);
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdMkd));
+ }
+
+ {
+ CmdRnFr cmdRnFr = new CmdRnFr(folderName);
+ assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(cmdRnFr));
+ }
+
+ {
+ CmdDele cmdDele = new CmdDele(folderName);
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdDele));
+ }
+
+ client.close();
+
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RNTOTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RNTOTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/RNTOTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdCwd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdDele;
+import org.exoplatform.frameworks.ftpclient.commands.CmdMkd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRnFr;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRnTo;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class RNTOTest extends TestCase
+{
+
+ private static Log log = new Log("RNTOTest");
+
+ public void testRNTO() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdRnTo cmdRnTo = new CmdRnTo(null);
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdRnTo));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdRnTo cmdRnTo = new CmdRnTo(null);
+ assertEquals(FtpConst.Replyes.REPLY_503, client.executeCommand(cmdRnTo));
+ }
+
+ {
+ CmdCwd cmdCwd = new CmdCwd("production");
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdCwd));
+ }
+
+ String folder_from = "FOLDER_FROM_" + System.currentTimeMillis();
+ String folder_to = "FOLDER_TO_" + System.currentTimeMillis();
+ String folder_existed = "FOLDER_EXISTED_" + System.currentTimeMillis();
+
+ {
+ CmdMkd cmdMkd = new CmdMkd(folder_from);
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdMkd));
+ }
+
+ {
+ CmdRnFr cmdRnFr = new CmdRnFr(folder_from);
+ assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(cmdRnFr));
+ }
+
+ {
+ CmdRnTo cmdRnTo = new CmdRnTo(null);
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdRnTo));
+ }
+
+ {
+ CmdMkd cmdMkd = new CmdMkd(folder_existed);
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdMkd));
+ }
+
+ {
+ CmdRnFr cmdRnFr = new CmdRnFr(folder_from);
+ assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(cmdRnFr));
+ }
+
+ {
+ CmdRnTo cmdRnTo = new CmdRnTo(folder_existed);
+ assertEquals(FtpConst.Replyes.REPLY_553, client.executeCommand(cmdRnTo));
+ }
+
+ {
+ CmdRnFr cmdRnFr = new CmdRnFr(folder_from);
+ assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(cmdRnFr));
+ }
+
+ {
+ CmdRnTo cmdRnTo = new CmdRnTo(folder_to);
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdRnTo));
+ }
+
+ {
+ CmdDele cmdDele = new CmdDele(folder_to);
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdDele));
+ }
+
+ {
+ CmdDele cmdDele = new CmdDele(folder_existed);
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdDele));
+ }
+
+ client.close();
+
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/SIZETest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/SIZETest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/SIZETest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdDele;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPasv;
+import org.exoplatform.frameworks.ftpclient.commands.CmdSize;
+import org.exoplatform.frameworks.ftpclient.commands.CmdStor;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class SIZETest extends TestCase
+{
+
+ private static Log log = new Log("SIZETest");
+
+ public void testSIZE() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdSize cmdSize = new CmdSize(null);
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdSize));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdSize cmdSize = new CmdSize(null);
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdSize));
+ }
+
+ {
+ CmdSize cmdSize = new CmdSize("NoSuchFile");
+ assertEquals(FtpConst.Replyes.REPLY_550, client.executeCommand(cmdSize));
+ }
+
+ String filePath = "/production/test_size_file.txt";
+ String fileContent = "This test File for SIZE command.";
+ int fileSize = fileContent.length();
+
+ {
+ CmdPasv cmdPasv = new CmdPasv();
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(cmdPasv));
+ }
+
+ {
+ CmdStor cmdStor = new CmdStor(filePath);
+ cmdStor.setFileContent(fileContent.getBytes());
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdStor));
+ }
+
+ {
+ CmdSize cmdSize = new CmdSize(filePath);
+ assertEquals(FtpConst.Replyes.REPLY_213, client.executeCommand(cmdSize));
+ assertEquals(fileSize, cmdSize.getSize());
+ }
+
+ {
+ CmdDele cmdDele = new CmdDele(filePath);
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdDele));
+ }
+
+ client.close();
+
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/STATTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/STATTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/STATTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdStat;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class STATTest extends TestCase
+{
+
+ private static Log log = new Log("STATTest");
+
+ public void testSTAT() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdStat cmdStat = new CmdStat();
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdStat));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdStat cmdStat = new CmdStat();
+ assertEquals(FtpConst.Replyes.REPLY_211, client.executeCommand(cmdStat));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/STORTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/STORTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/STORTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdCwd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdDele;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPasv;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRest;
+import org.exoplatform.frameworks.ftpclient.commands.CmdStor;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class STORTest extends TestCase
+{
+
+ private static Log log = new Log("STORTest");
+
+ public void testSTOR() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ byte[] fileContent = "THIS FILE CONTENT".getBytes();
+
+ // desired reply - 530 Please login with USER and PASS
+ {
+ CmdStor cmdStor = new CmdStor(null);
+ cmdStor.setFileContent(fileContent);
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdStor));
+ }
+
+ // login
+ {
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new
CmdUser(FtpTestConfig.USER_ID)));
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new
CmdPass(FtpTestConfig.USER_PASS)));
+ }
+
+ // desired reply - 425 Unable to build data connection
+ {
+ CmdStor cmdStor = new CmdStor(null);
+ cmdStor.setFileContent(fileContent);
+ assertEquals(FtpConst.Replyes.REPLY_425, client.executeCommand(cmdStor));
+ }
+
+ // desired reply - 500 STOR: command requires a parameter
+ {
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ CmdStor cmdStor = new CmdStor(null);
+ cmdStor.setFileContent(fileContent);
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdStor));
+ }
+
+ String fileName = "test_stor_file_" + System.currentTimeMillis() +
".txt";
+
+ // desired reply - 550 test_stor_file.txt: Permission denied
+ {
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ CmdStor cmdStor = new CmdStor(fileName);
+ cmdStor.setFileContent(fileContent);
+ assertEquals(FtpConst.Replyes.REPLY_550, client.executeCommand(cmdStor));
+ }
+
+ // desired reply - 125 Data connection already open; Transfer starting
+ // 226 Transfer complete
+ {
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdCwd("production")));
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+
+ CmdStor cmdStor = new CmdStor(fileName);
+ cmdStor.setFileContent(fileContent);
+ assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdStor));
+ }
+
+ // desired reply - 550 Restore value invalid
+ {
+ assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));
+ assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(new
CmdRest(1000)));
+
+ CmdStor cmdStor = new CmdStor(fileName);
+ cmdStor.setFileContent(fileContent);
+ assertEquals(FtpConst.Replyes.REPLY_550, client.executeCommand(cmdStor));
+ }
+
+ {
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdDele(fileName)));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/STRUTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/STRUTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/STRUTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdStru;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class STRUTest extends TestCase
+{
+
+ private static Log log = new Log("STRUTest");
+
+ public void testSTRU() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdStru cmdStru = new CmdStru("");
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdStru));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdStru cmdStru = new CmdStru("");
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdStru));
+ }
+
+ {
+ CmdStru cmdStru = new CmdStru("f");
+ assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(cmdStru));
+ }
+
+ {
+ CmdStru cmdStru = new CmdStru("any");
+ assertEquals(FtpConst.Replyes.REPLY_501, client.executeCommand(cmdStru));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/SYSTTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/SYSTTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/SYSTTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdSyst;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class SYSTTest extends TestCase
+{
+
+ private static Log log = new Log("SYSTTest");
+
+ public void testSYST() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdSyst cmdSyst = new CmdSyst();
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdSyst));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdSyst cmdSyst = new CmdSyst();
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(cmdSyst));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/TYPETest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/TYPETest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/TYPETest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdType;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class TYPETest extends TestCase
+{
+
+ private static Log log = new Log("TYPETest");
+
+ public void testTYPE() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdType cmdType = new CmdType("");
+ assertEquals(FtpConst.Replyes.REPLY_530, client.executeCommand(cmdType));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdType cmdType = new CmdType("a");
+ assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(cmdType));
+ }
+
+ {
+ CmdType cmdType = new CmdType("i");
+ assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(cmdType));
+ }
+
+ {
+ CmdType cmdType = new CmdType("any");
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdType));
+ }
+
+ {
+ CmdType cmdType = new CmdType("");
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdType));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/USERPASSTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/USERPASSTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/cmdtests/USERPASSTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.cmdtests;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class USERPASSTest extends TestCase
+{
+
+ private static Log log = new Log("USERPASSTest");
+
+ public void testUSER_PASS() throws Exception
+ {
+ log.info("Test...");
+
+ FtpClientSession client = FtpTestConfig.getTestFtpClient();
+ client.connect();
+
+ {
+ CmdUser cmdUser = new CmdUser("");
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass("");
+ assertEquals(FtpConst.Replyes.REPLY_503, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass("");
+ assertEquals(FtpConst.Replyes.REPLY_500, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ client.close();
+ log.info("Complete.\r\n");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/multimulti/MultiThreadCrushTest.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/multimulti/MultiThreadCrushTest.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/multimulti/MultiThreadCrushTest.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,216 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.multimulti;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSessionImpl;
+import org.exoplatform.frameworks.ftpclient.commands.CmdCwd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdDele;
+import org.exoplatform.frameworks.ftpclient.commands.CmdMkd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdSyst;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Random;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class MultiThreadCrushTest extends TestCase
+{
+
+ private static Log log = new Log("MultiThreadCrushTest");
+
+ public static boolean IsNeedWaitAll = true;
+
+ public void testSingleThread() throws Exception
+ {
+ log.info("testSingleThread...");
+
+ {
+ FtpClientSession client = new FtpClientSessionImpl(FtpTestConfig.FTP_HOST,
FtpTestConfig.FTP_PORT);
+ client.connect();
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdSyst cmdSyst = new CmdSyst();
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(cmdSyst));
+ }
+
+ {
+ CmdCwd cmdCwd = new CmdCwd(FtpTestConfig.TEST_FOLDER);
+ if (FtpConst.Replyes.REPLY_550 == client.executeCommand(cmdCwd))
+ {
+ CmdMkd cmdMkd = new CmdMkd(FtpTestConfig.TEST_FOLDER);
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdMkd));
+
+ cmdCwd = new CmdCwd(FtpTestConfig.TEST_FOLDER);
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdCwd));
+ }
+
+ for (int i1 = 0; i1 < 10; i1++)
+ {
+
+ String folderName = FtpTestConfig.TEST_FOLDER + "/" + i1;
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(new
CmdMkd(folderName)));
+
+ for (int i2 = 0; i2 < 10; i2++)
+ {
+ String testSubFolder = folderName + "/" + i2;
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(new
CmdMkd(testSubFolder)));
+ }
+
+ }
+ }
+
+ client.close();
+ }
+
+ HashMap<Integer, TestAgent> clients = new HashMap<Integer,
TestAgent>();
+ int count = 0;
+
+ Random random = new Random();
+
+ while (count < FtpTestConfig.CLIENTS_COUNT)
+ {
+ int nextId = random.nextInt(Integer.MAX_VALUE);
+ log.info("NEXT ID: [" + nextId + "]");
+
+ if (nextId < 10000)
+ {
+ continue;
+ }
+
+ Integer curInteger = new Integer(nextId);
+ if (clients.containsKey(curInteger))
+ {
+ continue;
+ }
+
+ TestAgent testAgent = new TestAgent(curInteger, FtpTestConfig.CLIENT_DEPTH);
+ clients.put(curInteger, testAgent);
+ count++;
+ }
+
+ log.info("CLIENTS: [" + clients.size() + "]");
+
+ Thread.sleep(3000);
+ log.info("START ALL!!!!!!!!!!!!!!!!!!!!!!!!");
+ IsNeedWaitAll = false;
+ Thread.sleep(3000);
+
+ {
+ boolean alive = true;
+
+ while (alive)
+ {
+ alive = false;
+ Thread.sleep(2000);
+
+ int live = 0;
+
+ Iterator<Integer> keyIter = clients.keySet().iterator();
+ while (keyIter.hasNext())
+ {
+ Integer agentKey = keyIter.next();
+ TestAgent agent = clients.get(agentKey);
+ if (agent.isAlive())
+ {
+ alive = true;
+ live++;
+ }
+ }
+
+ log.info(">>>>>>>>>>>>> LIVE:
[" + live + "]");
+
+ }
+ }
+
+ {
+ {
+ FtpClientSession client = new FtpClientSessionImpl(FtpTestConfig.FTP_HOST,
FtpTestConfig.FTP_PORT);
+ client.connect();
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ {
+ CmdSyst cmdSyst = new CmdSyst();
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(cmdSyst));
+ }
+
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdDele(FtpTestConfig.TEST_FOLDER)));
+ }
+ }
+
+ {
+ int successed = 0;
+ Iterator<Integer> keyIter = clients.keySet().iterator();
+ while (keyIter.hasNext())
+ {
+ Integer agentKey = keyIter.next();
+ TestAgent agent = clients.get(agentKey);
+
+ if (agent.isSuccessed())
+ {
+ successed++;
+ }
+
+ }
+
+ log.info("SUCCESSED: [" + successed + "]");
+ log.info("FAILURES: [" + (FtpTestConfig.CLIENTS_COUNT - successed) +
"]");
+ Thread.sleep(2000);
+
+ if (FtpTestConfig.CLIENTS_COUNT != successed)
+ {
+ fail();
+ }
+ }
+
+ log.info("done.");
+ }
+
+}
Added:
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/multimulti/TestAgent.java
===================================================================
---
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/multimulti/TestAgent.java
(rev 0)
+++
jcr/trunk/frameworks/ftpclient/src/test/java/org/exoplatform/frameworks/ftpclient/multimulti/TestAgent.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,317 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.ftpclient.multimulti;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.frameworks.ftpclient.FtpConst;
+import org.exoplatform.frameworks.ftpclient.FtpTestConfig;
+import org.exoplatform.frameworks.ftpclient.Log;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSession;
+import org.exoplatform.frameworks.ftpclient.client.FtpClientSessionImpl;
+import org.exoplatform.frameworks.ftpclient.commands.CmdCwd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdDele;
+import org.exoplatform.frameworks.ftpclient.commands.CmdMkd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPass;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPasv;
+import org.exoplatform.frameworks.ftpclient.commands.CmdPwd;
+import org.exoplatform.frameworks.ftpclient.commands.CmdRetr;
+import org.exoplatform.frameworks.ftpclient.commands.CmdStor;
+import org.exoplatform.frameworks.ftpclient.commands.CmdSyst;
+import org.exoplatform.frameworks.ftpclient.commands.CmdUser;
+
+/**
+ * Created by The eXo Platform SAS Author : Vitaly Guly
<gavrik-vetal(a)ukr.net/mail.ru>
+ *
+ * @version $Id: $
+ */
+
+public class TestAgent extends TestCase
+{
+
+ public static final int SLEEP = 100;
+
+ private Log log;
+
+ private int agentId;
+
+ private int itemsCount;
+
+ private ClientThread clientThread;
+
+ private boolean successed = false;
+
+ public TestAgent(int agentId, int itemsCount)
+ {
+ log = new Log("TestAgent[" + agentId + "]");
+
+ this.agentId = agentId;
+ this.itemsCount = itemsCount;
+
+ log.info("construct agent with ID [" + agentId + "]");
+ clientThread = new ClientThread();
+ clientThread.start();
+ }
+
+ public boolean isAlive()
+ {
+ return clientThread.isAlive();
+ }
+
+ public boolean isSuccessed()
+ {
+ return successed;
+ }
+
+ private class ClientThread extends Thread
+ {
+
+ private Log log = new Log("ClientThread[" + agentId + "]");
+
+ private FtpClientSession client;
+
+ public ClientThread()
+ {
+ }
+
+ public void run()
+ {
+
+ try
+ {
+
+ while (MultiThreadCrushTest.IsNeedWaitAll)
+ {
+ Thread.sleep(1000);
+ }
+
+ client = new FtpClientSessionImpl(FtpTestConfig.FTP_HOST,
FtpTestConfig.FTP_PORT);
+
+ if (!client.connect(60))
+ {
+ return;
+ }
+
+ {
+ CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
+ assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
+ }
+
+ Thread.sleep(SLEEP);
+
+ {
+ CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
+ assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
+ }
+
+ Thread.sleep(SLEEP);
+
+ {
+ CmdSyst cmdSyst = new CmdSyst();
+ assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(cmdSyst));
+ }
+
+ Thread.sleep(SLEEP);
+
+ {
+ CmdPwd cmdPwd = new CmdPwd();
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdPwd));
+ }
+
+ Thread.sleep(SLEEP);
+
+ {
+ CmdCwd cmdCwd = new CmdCwd(FtpTestConfig.TEST_FOLDER);
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdCwd));
+ }
+
+ Thread.sleep(SLEEP);
+
+ {
+ CmdPwd cmdPwd = new CmdPwd();
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdPwd));
+ assertEquals(FtpTestConfig.TEST_FOLDER, cmdPwd.getCurrentPath());
+ }
+
+ Thread.sleep(SLEEP);
+
+ String folderName = "" + agentId;
+
+ String folder1Name = folderName.substring(0, 1);
+ log.info("FOLDER 1 NAME: [" + folder1Name + "]");
+
+ {
+ CmdCwd cmdCwd = new CmdCwd(folder1Name);
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdCwd));
+ }
+
+ Thread.sleep(SLEEP);
+
+ String folder2Name = folderName.substring(1, 2);
+
+ {
+ CmdCwd cmdCwd = new CmdCwd(folder2Name);
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdCwd));
+ }
+
+ Thread.sleep(SLEEP);
+
+ {
+ CmdMkd cmdMkd = new CmdMkd(folderName);
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdMkd,
FtpConst.Replyes.REPLY_257, 3));
+ }
+
+ Thread.sleep(SLEEP);
+
+ {
+ CmdCwd cmdCwd = new CmdCwd(folderName);
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdCwd));
+ }
+
+ Thread.sleep(SLEEP);
+
+ String folderPath = FtpTestConfig.TEST_FOLDER + "/" + folder1Name +
"/" + folder2Name + "/" + folderName;
+ log.info("FOLDER PATH: [" + folderPath + "]");
+
+ {
+ CmdPwd cmdPwd = new CmdPwd();
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdPwd));
+ assertEquals(folderPath, cmdPwd.getCurrentPath());
+ }
+
+ Thread.sleep(SLEEP);
+
+ for (int i1 = 0; i1 < itemsCount; i1++)
+ {
+
+ String tf1Name = "test_folder_" + i1;
+
+ CmdMkd cmdMkd = new CmdMkd(tf1Name);
+ assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdMkd,
FtpConst.Replyes.REPLY_257, 3));
+
+ Thread.sleep(SLEEP);
+
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdCwd(tf1Name)));
+
+ Thread.sleep(SLEEP);
+
+ for (int i2 = 0; i2 < itemsCount; i2++)
+ {
+ String tf2Name = "test_file_" + i2;
+
+ int expectReply = 3;
+ while (expectReply > 0)
+ {
+
+ int pasvReply = client.executeCommand(new CmdPasv(),
FtpConst.Replyes.REPLY_227, 3);
+ if (pasvReply == FtpConst.Replyes.REPLY_227)
+ {
+ // byte []data = ("TEST FILE CONTENT " +
i2).getBytes();
+ byte[] data = new byte[20 * 1024];
+
+ CmdStor cmdStor = new CmdStor(tf2Name);
+ cmdStor.setFileContent(data);
+ int storReply = client.executeCommand(cmdStor);
+ if (storReply == FtpConst.Replyes.REPLY_226)
+ {
+ break;
+ }
+ Thread.sleep(SLEEP);
+ }
+
+ Thread.sleep(SLEEP);
+ expectReply--;
+ }
+
+ if (expectReply == 0)
+ {
+ fail();
+ }
+ }
+
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdCwd("..")));
+ Thread.sleep(SLEEP);
+ }
+
+ for (int i1 = 0; i1 < itemsCount; i1++)
+ {
+
+ String tf1Name = "test_folder_" + i1;
+
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdCwd(tf1Name)));
+ Thread.sleep(SLEEP);
+
+ for (int i2 = 0; i2 < itemsCount; i2++)
+ {
+ String tf2Name = "test_file_" + i2;
+
+ int expectReply = 3;
+ while (expectReply > 0)
+ {
+ int pasvReply = client.executeCommand(new CmdPasv(),
FtpConst.Replyes.REPLY_227, 3);
+ if (pasvReply == FtpConst.Replyes.REPLY_227)
+ {
+ CmdRetr cmdRetr = new CmdRetr(tf2Name);
+ int retrReply = client.executeCommand(cmdRetr);
+ if (retrReply == FtpConst.Replyes.REPLY_226)
+ {
+ break;
+ }
+ }
+ }
+
+ if (expectReply == 0)
+ {
+ fail();
+ }
+
+ Thread.sleep(SLEEP);
+ }
+
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdCwd("..")));
+ }
+
+ Thread.sleep(SLEEP);
+
+ {
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdCwd("..")));
+ }
+
+ Thread.sleep(SLEEP);
+
+ {
+ assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new
CmdDele(folderName)));
+ }
+
+ Thread.sleep(SLEEP);
+
+ client.close();
+
+ successed = true;
+ }
+ catch (Throwable exc)
+ {
+ log.info("Unhandled exception. " + exc.getMessage(), exc);
+ }
+
+ }
+
+ }
+
+}
Added: jcr/trunk/frameworks/web/pom.xml
===================================================================
--- jcr/trunk/frameworks/web/pom.xml (rev 0)
+++ jcr/trunk/frameworks/web/pom.xml 2009-08-27 12:31:38 UTC (rev 17)
@@ -0,0 +1,79 @@
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>config</artifactId>
+ <version>1.12-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>exo.jcr.framework.web</artifactId>
+
+ <name>eXo JCR :: Framework :: Web</name>
+ <description>eXo JCR REST adapter</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.component.ext</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.framework.command</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.container</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.common</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
\ No newline at end of file
Added:
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/CommandControllerServlet.java
===================================================================
---
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/CommandControllerServlet.java
(rev 0)
+++
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/CommandControllerServlet.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.web;
+
+import org.apache.commons.chain.Command;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.frameworks.jcr.command.web.GenericWebAppContext;
+import org.exoplatform.services.command.impl.CommandService;
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.ext.app.SessionProviderService;
+
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: CommandControllerServlet.java 14756 2008-05-26 14:47:15Z pnedonosko $
+ */
+
+public class CommandControllerServlet extends HttpServlet
+{
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException,
+ IOException
+ {
+
+ ExoContainer container =
(ExoContainer)getServletContext().getAttribute(WebConstants.EXO_CONTAINER);
+ if (container == null)
+ {
+ String portalName = getServletContext().getServletContextName();
+ container = ExoContainerContext.getCurrentContainer();
+ }
+
+ SessionProviderService sessionProviderService =
+
(SessionProviderService)container.getComponentInstanceOfType(SessionProviderService.class);
+
+ RepositoryService repositoryService =
+
(RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
+
+ GenericWebAppContext ctx;
+ try
+ {
+ ctx =
+ new GenericWebAppContext(getServletContext(), request, response,
sessionProviderService
+ .getSessionProvider(null), // null for
+ // ThreadLocalSessionProvider
+ repositoryService.getDefaultRepository());
+ }
+ catch (final RepositoryException e)
+ {
+ throw new IOException()
+ {
+ @Override
+ public Throwable getCause()
+ {
+ return e;
+ }
+ };
+ }
+ catch (final RepositoryConfigurationException e)
+ {
+ throw new IOException()
+ {
+ @Override
+ public Throwable getCause()
+ {
+ return e;
+ }
+ };
+ }
+
+ CommandService commandService =
(CommandService)container.getComponentInstanceOfType(CommandService.class);
+ String catalogName = (String)ctx.get(WebConstants.CATALOG_NAME);
+
+ // command from context
+ String commandName = (String)ctx.get("Command");
+ if (commandName == null)
+ throw new ServletException("No Command found at the Context");
+ Command cmd;
+ if (catalogName == null)
+ cmd = commandService.getCatalog().getCommand(commandName);
+ else
+ cmd = commandService.getCatalog(catalogName).getCommand(commandName);
+
+ if (cmd == null)
+ throw new ServletException("No Command found " + commandName);
+ try
+ {
+ cmd.execute(ctx);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new ServletException(e);
+ }
+ }
+
+}
Added:
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/DisplayJCRContentServlet.java
===================================================================
---
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/DisplayJCRContentServlet.java
(rev 0)
+++
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/DisplayJCRContentServlet.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.web;
+
+import org.apache.commons.chain.Command;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.frameworks.jcr.command.web.GenericWebAppContext;
+import org.exoplatform.services.command.impl.CommandService;
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.ext.app.SessionProviderService;
+
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SAS . Shortcut for
+ *
http://localhost:8080/simple-cms/jcr?workspace=digital-assets&path=/I...
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: DisplayJCRContentServlet.java 14756 2008-05-26 14:47:15Z pnedonosko $
+ */
+@Deprecated
+public class DisplayJCRContentServlet extends HttpServlet
+{
+
+ ServletConfig config;
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException,
+ IOException
+ {
+
+ ExoContainer container =
(ExoContainer)getServletContext().getAttribute(WebConstants.EXO_CONTAINER);
+ if (container == null)
+ {
+ String portalName = getServletContext().getServletContextName();
+ container = ExoContainerContext.getCurrentContainer();
+ }
+
+ SessionProviderService sessionProviderService =
+
(SessionProviderService)container.getComponentInstanceOfType(SessionProviderService.class);
+
+ RepositoryService repositoryService =
+
(RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
+ CommandService commandService =
(CommandService)container.getComponentInstanceOfType(CommandService.class);
+
+ GenericWebAppContext ctx;
+ try
+ {
+ ctx =
+ new GenericWebAppContext(getServletContext(), request, response,
sessionProviderService
+ .getSessionProvider(null), // null for
+ // ThreadLocalSessionProvider
+ repositoryService.getDefaultRepository());
+ }
+ catch (final RepositoryException e)
+ {
+ throw new IOException()
+ {
+ @Override
+ public Throwable getCause()
+ {
+ return e;
+ }
+ };
+ }
+ catch (final RepositoryConfigurationException e)
+ {
+ throw new IOException()
+ {
+ @Override
+ public Throwable getCause()
+ {
+ return e;
+ }
+ };
+ }
+
+ String catalogName = (String)ctx.get(WebConstants.CATALOG_NAME);
+
+ String wsName = (String)ctx.get("workspace");
+ if (wsName != null)
+ ctx.setCurrentWorkspace(wsName);
+
+ String currentPath = (String)ctx.get("path");
+
+ if (currentPath == null)
+ throw new ServletException("Path undefined " +
request.getParameter("path") + " Request: "
+ + request.getRequestURI());
+
+ try
+ {
+ Command cmd;
+ if (catalogName == null)
+ cmd = commandService.getCatalog().getCommand("displayResource");
+ else
+ cmd =
commandService.getCatalog(catalogName).getCommand("displayResource");
+
+ if (cmd == null)
+ throw new Exception("No 'displayResource' command found");
+ ctx.put("path", currentPath);
+ ctx.put("cache-control-max-age",
getServletConfig().getInitParameter("cache-control-max-age"));
+ cmd.execute(ctx);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new ServletException(e);
+ }
+ }
+
+}
Added:
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/ThreadLocalSessionProviderInitializedFilter.java
===================================================================
---
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/ThreadLocalSessionProviderInitializedFilter.java
(rev 0)
+++
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/ThreadLocalSessionProviderInitializedFilter.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.web;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.services.jcr.ext.app.SessionProviderService;
+import org.exoplatform.services.jcr.ext.common.SessionProvider;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.security.ConversationRegistry;
+import org.exoplatform.services.security.ConversationState;
+import org.exoplatform.services.security.StateKey;
+import org.exoplatform.services.security.web.HttpSessionStateKey;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+/**
+ * Created by The eXo Platform SAS . <br/> Checks out if there are SessionProvider
instance in
+ * current thread using ThreadLocalSessionProviderService, if no, initializes it getting
current
+ * credentials from AuthenticationService and initializing
ThreadLocalSessionProviderService with
+ * newly created SessionProvider
+ *
+ * @author Gennady Azarenkov
+ * @version $Id: $
+ */
+public class ThreadLocalSessionProviderInitializedFilter implements Filter
+{
+
+ private ConversationRegistry stateRegistry;
+
+ private SessionProviderService providerService;
+
+ private static final Log log =
ExoLogger.getLogger("jcr.ThreadLocalSessionProviderInitializedFilter");
+
+ /*
+ * (non-Javadoc)
+ * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
+ */
+ public void init(FilterConfig config) throws ServletException
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
javax.servlet.ServletResponse,
+ * javax.servlet.FilterChain)
+ */
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException,
+ ServletException
+ {
+
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+
+ providerService =
(SessionProviderService)container.getComponentInstanceOfType(SessionProviderService.class);
+ stateRegistry =
(ConversationRegistry)container.getComponentInstanceOfType(ConversationRegistry.class);
+
+ HttpServletRequest httpRequest = (HttpServletRequest)request;
+
+ ConversationState state = ConversationState.getCurrent();
+ SessionProvider provider = null;
+
+ // NOTE not create new HTTP session, if session is not created yet
+ // this means some settings is incorrect, see web.xml for filter
+ // org.exoplatform.services.security.web.SetCurrentIdentityFilter
+ HttpSession httpSession = httpRequest.getSession(false);
+ if (state == null)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Current conversation state is not set");
+
+ if (httpSession != null)
+ {
+ StateKey stateKey = new HttpSessionStateKey(httpSession);
+ // initialize thread local SessionProvider
+ state = stateRegistry.getState(stateKey);
+ if (state != null)
+ provider = new SessionProvider(state);
+ else if (log.isDebugEnabled())
+ log.debug("WARN: Conversation State is null, id " +
httpSession.getId());
+ }
+ }
+ else
+ {
+ provider = new SessionProvider(state);
+ }
+
+ if (provider == null)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Create SessionProvider for anonymous.");
+ provider = SessionProvider.createAnonimProvider();
+ }
+ try
+ {
+ if (ConversationState.getCurrent() != null)
+ ConversationState.getCurrent().setAttribute(SessionProvider.SESSION_PROVIDER,
provider);
+
+ providerService.setSessionProvider(null, provider);
+
+ chain.doFilter(request, response);
+
+ }
+ finally
+ {
+ if (ConversationState.getCurrent() != null)
+ {
+ try
+ {
+
ConversationState.getCurrent().removeAttribute(SessionProvider.SESSION_PROVIDER);
+ }
+ catch (Exception e)
+ {
+ log.warn("An error occured while removing the session provider from
the conversation state", e);
+ }
+ }
+ if (providerService.getSessionProvider(null) != null)
+ {
+ try
+ {
+ // remove SessionProvider
+ providerService.removeSessionProvider(null);
+ }
+ catch (Exception e)
+ {
+ log.warn("An error occured while cleaning the ThreadLocal", e);
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.servlet.Filter#destroy()
+ */
+ public void destroy()
+ {
+ }
+
+}
Added:
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/WebConstants.java
===================================================================
---
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/WebConstants.java
(rev 0)
+++
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/WebConstants.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.web;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: WebConstants.java 5800 2006-05-28 18:03:31Z geaz $
+ */
+
+public interface WebConstants
+{
+ public static final String APP_CONTEXT =
"org.exoplatform.frameworks.web.appContext";
+
+ public static final String REPOSITORY_JNDI_NAME =
"org.exoplatform.frameworks.web.repositoryJNDIName";
+
+ public static final String EXO_CONTAINER =
"org.exoplatform.frameworks.web.eXoContainer";
+
+ public static final String CATALOG_NAME =
"org.exoplatform.frameworks.web.catalogName";
+}
Added:
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/fckeditor/FCKeditor.java
===================================================================
---
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/fckeditor/FCKeditor.java
(rev 0)
+++
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/fckeditor/FCKeditor.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,399 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.web.fckeditor;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * The main class of the class lib.<br>
+ * It's the container for all properties and the class that generate the output based
on browser
+ * capabilities and configurations passed by the developer.
+ *
+ * @author Simone Chiaretta (simo(a)users.sourceforge.net)
+ */
+public class FCKeditor
+{
+
+ private FCKeditorConfigurations oConfig;
+
+ private String instanceName;
+
+ private String userAgent;
+
+ private String value = "";
+
+ private String basePath;
+
+ private String toolbarSet = "Default";
+
+ private String width = "100%";
+
+ private String height = "200";
+
+ /**
+ * Get the unique name of the editor
+ *
+ * @return name
+ */
+ public String getInstanceName()
+ {
+ return instanceName;
+ }
+
+ /**
+ * Set the unique name of the editor
+ *
+ * @param value
+ * name
+ */
+ public void setInstanceName(String value)
+ {
+ instanceName = value;
+ }
+
+ /**
+ * Get the initial value to be edited.<br>
+ * In HTML code
+ *
+ * @return value
+ */
+ public String getValue()
+ {
+ return value;
+ }
+
+ /**
+ * Set the initial value to be edited.<br>
+ * In HTML code
+ *
+ * @param value
+ * value
+ */
+ public void setValue(String value)
+ {
+ this.value = value;
+ }
+
+ /**
+ * Get the dir where the FCKeditor files reside on the server
+ *
+ * @return path
+ */
+ public String getBasePath()
+ {
+ return basePath;
+ }
+
+ /**
+ * Set the dir where the FCKeditor files reside on the server.<br>
+ *<b>Remarks</b>:<br>
+ *Avoid using relative paths. It is preferable to set the base path starting from the
root (/).<br>
+ *Always finish the path with a slash (/).
+ *
+ * @param value
+ * path
+ */
+ public void setBasePath(String value)
+ {
+ basePath = value;
+ }
+
+ /**
+ * Get the name of the toolbar to display
+ *
+ * @return toolbar name
+ */
+ public String getToolbarSet()
+ {
+ return toolbarSet;
+ }
+
+ /**
+ * Set the name of the toolbar to display
+ *
+ * @param value
+ * toolbar name
+ */
+ public void setToolbarSet(String value)
+ {
+ toolbarSet = value;
+ }
+
+ /**
+ * Get the width of the textarea
+ *
+ * @return width
+ */
+ public String getWidth()
+ {
+ return width;
+ }
+
+ /**
+ * Set the width of the textarea
+ *
+ * @param value
+ * width
+ */
+ public void setWidth(String value)
+ {
+ width = value;
+ }
+
+ /**
+ * Get the height of the textarea
+ *
+ * @return height
+ */
+ public String getHeight()
+ {
+ return height;
+ }
+
+ /**
+ * Set the height of the textarea
+ *
+ * @param value
+ * height
+ */
+ public void setHeight(String value)
+ {
+ height = value;
+ }
+
+ /**
+ * Get the advanced configuation set.<br>
+ * Adding element to this collection you can override the settings specified in the
config.js
+ * file.
+ *
+ * @return configuration collection
+ */
+ public FCKeditorConfigurations getConfig()
+ {
+ return oConfig;
+ }
+
+ /**
+ * Set the advanced configuation set.
+ *
+ * @param value
+ * configuration collection
+ */
+ public void setConfig(FCKeditorConfigurations value)
+ {
+ oConfig = value;
+ }
+
+ /**
+ * Initialize the object setting all value to the default ones.
+ * <p>
+ * <ul>
+ * <li>width: 100%</li>
+ * <li>height: 200</li>
+ * <li>toolbar name: Default</li>
+ * <li>basePath: context root + "/FCKeditor/"</li>
+ * </ul>
+ * </p>
+ *
+ * @param req
+ * request object
+ */
+ public FCKeditor(HttpServletRequest req)
+ {
+ // request=req;
+ userAgent = req.getHeader("user-agent");
+ basePath = req.getContextPath() + "/FCKeditor/";
+ oConfig = new FCKeditorConfigurations();
+ }
+
+ /**
+ * Initialize the object setting the unique name and then all value to the default
ones.
+ * <p>
+ * <ul>
+ * <li>width: 100%</li>
+ * <li>height: 200</li>
+ * <li>toolbar name: Default</li>
+ * <li>basePath: context root + "/FCKeditor/"</li>
+ * </ul>
+ * </p>
+ *
+ * @param req
+ * request object
+ * @param parInstanceName
+ * unique name
+ */
+ public FCKeditor(HttpServletRequest req, String parInstanceName)
+ {
+ // request=req;
+ userAgent = req.getHeader("user-agent");
+ basePath = req.getContextPath() + "/FCKeditor/";
+ instanceName = parInstanceName;
+ oConfig = new FCKeditorConfigurations();
+ }
+
+ /**
+ * Initialize the object setting all basic configurations.<br>
+ * The basePath is context root + "/FCKeditor/"
+ *
+ * @param req
+ * request object
+ * @param parInstanceName
+ * unique name
+ * @param parWidth
+ * width
+ * @param parHeight
+ * height
+ * @param parToolbarSet
+ * toolbarSet name
+ * @param parValue
+ * initial value
+ */
+ public FCKeditor(HttpServletRequest req, String parInstanceName, String parWidth,
String parHeight,
+ String parToolbarSet, String parValue)
+ {
+ // request=req;
+ userAgent = req.getHeader("user-agent");
+ basePath = req.getContextPath() + "/FCKeditor/";
+ instanceName = parInstanceName;
+ width = parWidth;
+ height = parHeight;
+ toolbarSet = parToolbarSet;
+ value = parValue;
+ oConfig = new FCKeditorConfigurations();
+ }
+
+ private boolean isCompatible()
+ {
+ // [PN] 11.07.06 userAgent as global var, no request stored in editor
+ // String userAgent=request.getHeader("user-agent");
+ if (userAgent == null)
+ return false;
+ String userAgentString = userAgent.toLowerCase();
+ if ((userAgentString.indexOf("msie") != -1) &&
(userAgentString.indexOf("mac") == -1)
+ && (userAgentString.indexOf("opera") == -1))
+ {
+ if (retrieveBrowserVersion(userAgentString) >= 5.5)
+ return true;
+ }
+ else if (userAgentString.indexOf("gecko") != -1)
+ {
+ if (retrieveBrowserVersion(userAgentString) >= 20030210)
+ return true;
+ }
+ return false;
+ }
+
+ private double retrieveBrowserVersion(String userAgentString)
+ {
+ if (userAgentString.indexOf("msie") > -1)
+ {
+ String str = userAgentString.substring(userAgentString.indexOf("msie")
+ 5);
+ return Double.parseDouble(str.substring(0, str.indexOf(";")));
+ }
+ else
+ {
+ String str =
userAgentString.substring(userAgentString.indexOf("gecko") + 6);
+ return Double.parseDouble(str.substring(0, 8));
+ }
+ }
+
+ private String HTMLEncode(String txt)
+ {
+ txt = txt.replaceAll("&", "&");
+ txt = txt.replaceAll("<", "<");
+ txt = txt.replaceAll(">", ">");
+ txt = txt.replaceAll("\"", """);
+ txt = txt.replaceAll("'", "’");
+ return txt;
+ }
+
+ /**
+ * Generate the HTML Code for the editor. <br>
+ * Evalute the browser capabilities and generate the editor if IE 5.5 or Gecko
20030210 or
+ * greater, or a simple textarea otherwise.
+ *
+ * @return html code
+ */
+ public String create()
+ {
+ StringBuffer strEditor = new StringBuffer();
+
+ strEditor.append("<div>");
+ String encodedValue = HTMLEncode(value);
+
+ if (isCompatible())
+ {
+
+ strEditor.append("<input type=\"hidden\" id=\"" +
instanceName + "\" name=\"" + instanceName + "\"
value=\""
+ + encodedValue + "\">");
+
+ strEditor.append(createConfigHTML());
+ strEditor.append(createIFrameHTML());
+
+ }
+ else
+ {
+ strEditor.append("<TEXTAREA name=\"" + instanceName +
"\" rows=\"4\" cols=\"40\" style=\"WIDTH: " +
width
+ + "; HEIGHT: " + height + "\"
wrap=\"virtual\">" + encodedValue + "</TEXTAREA>");
+ }
+ strEditor.append("</div>");
+ return strEditor.toString();
+ }
+
+ private String createConfigHTML()
+ {
+ String configStr = oConfig.getUrlParams();
+
+ if (!configStr.equals(""))
+ configStr = configStr.substring(1);
+
+ return "<input type=\"hidden\" id=\"" + instanceName +
"___Config\" value=\"" + configStr + "\">";
+ }
+
+ private String createIFrameHTML()
+ {
+
+ String sLink = basePath + "editor/fckeditor.html?InstanceName=" +
instanceName;
+
+ if (!toolbarSet.equals(""))
+ sLink += "&Toolbar=" + toolbarSet;
+
+ return "<iframe id=\"" + instanceName + "___Frame\"
src=\"" + sLink + "\" width=\"" + width + "\"
height=\""
+ + height + "\" frameborder=\"no\"
scrolling=\"no\"></iframe>";
+
+ }
+
+ /**
+ * @return the userAgent
+ */
+ public String getUserAgent()
+ {
+ return userAgent;
+ }
+
+ /**
+ * @param userAgent
+ * the userAgent to set
+ */
+ public void setUserAgent(String userAgent)
+ {
+ this.userAgent = userAgent;
+ }
+
+}
Added:
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/fckeditor/FCKeditorConfigurations.java
===================================================================
---
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/fckeditor/FCKeditorConfigurations.java
(rev 0)
+++
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/fckeditor/FCKeditorConfigurations.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.web.fckeditor;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Contains the configuration settings for the FCKEditor.<br>
+ * Adding element to this collection you can override the settings specified in the
config.js file.
+ *
+ * @author Simone Chiaretta (simo(a)users.sourceforge.net)
+ */
+public class FCKeditorConfigurations extends HashMap
+{
+
+ /**
+ * Initialize the configuration collection
+ */
+ public FCKeditorConfigurations()
+ {
+ super();
+ }
+
+ /**
+ * Generate the url parameter sequence used to pass this configuration to the editor.
+ *
+ * @return html endocode sequence of configuration parameters
+ */
+ public String getUrlParams()
+ {
+ StringBuffer osParams = new StringBuffer();
+
+ for (Iterator i = this.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ if (entry.getValue() != null)
+ osParams.append("&" + encodeConfig(entry.getKey().toString()) +
"="
+ + encodeConfig(entry.getValue().toString()));
+ }
+ return osParams.toString();
+ }
+
+ private String encodeConfig(String txt)
+ {
+ txt = txt.replaceAll("&", "%26");
+ txt = txt.replaceAll("=", "%3D");
+ txt = txt.replaceAll("\"", "%22");
+ return txt;
+ }
+
+}
Added:
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/fckeditor/JCRContentFCKeditor.java
===================================================================
---
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/fckeditor/JCRContentFCKeditor.java
(rev 0)
+++
jcr/trunk/frameworks/web/src/main/java/org/exoplatform/frameworks/jcr/web/fckeditor/JCRContentFCKeditor.java 2009-08-27
12:31:38 UTC (rev 17)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.frameworks.jcr.web.fckeditor;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.frameworks.jcr.web.WebConstants;
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.app.SessionProviderService;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * Created by The eXo Platform SAS .
+ *
+ * @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
+ * @version $Id: JCRContentFCKeditor.java 6944 2006-07-11 08:06:04Z peterit $
+ */
+
+public class JCRContentFCKeditor extends FCKeditor
+{
+
+ private final static Log LOG =
ExoLogger.getLogger("jcr.JCRContentFCKeditor");
+
+ private Node file;
+
+ public JCRContentFCKeditor(HttpServletRequest req, String parInstanceName, String
workspaceName, String filePath,
+ String newNodeType) throws RepositoryException
+ {
+ super(req, parInstanceName);
+
+ ExoContainer container =
+
(ExoContainer)req.getSession().getServletContext().getAttribute(WebConstants.EXO_CONTAINER);
+ if (container == null)
+ { // this
+ String portalName =
req.getSession().getServletContext().getServletContextName(); // req.
+ // getContextPath
+ // ();
+ container = ExoContainerContext.getCurrentContainer();
+ }
+
+ SessionProviderService sessionProviderService =
+
(SessionProviderService)container.getComponentInstanceOfType(SessionProviderService.class);
+
+ RepositoryService repositoryService =
+
(RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
+
+ ManageableRepository repo = repositoryService.getCurrentRepository();
+ Session session =
+
sessionProviderService.getSessionProvider(null).getSession(repo.getConfiguration().getDefaultWorkspaceName(),
+ repo);
+ try
+ {
+ this.file = (Node)session.getItem(filePath);
+ }
+ catch (PathNotFoundException e1)
+ {
+ this.file = session.getRootNode().addNode(filePath.substring(1), newNodeType);
+ }
+ if (!file.isNodeType("nt:file"))
+ throw new RepositoryException("The Node should be nt:file type");
+ try
+ {
+ Property content = (Property)session.getItem(filePath +
"/jcr:content/jcr:data");
+ this.setValue(content.getString());
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error("Repository error " + e, e);
+ }
+ }
+
+ public void saveValue(String value) throws RepositoryException
+ {
+ // file.setProperty("jcr:content/jcr:data", value);
+ // [VO] "jcr:content/jcr:data" - impossible according to spec
+ file.getNode("jcr:content").setProperty("jcr:data", value);
+ setValue(value);
+ file.getSession().save();
+ }
+}
Added: jcr/trunk/pom.xml
===================================================================
--- jcr/trunk/pom.xml (rev 0)
+++ jcr/trunk/pom.xml 2009-08-27 12:31:38 UTC (rev 17)
@@ -0,0 +1,475 @@
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.exoplatform</groupId>
+ <artifactId>foundation-parent</artifactId>
+ <version>1</version>
+ </parent>
+
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>config</artifactId>
+ <version>1.12-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <name>eXo JCR</name>
+
+ <properties>
+ <exo.product.name>exo-jcr</exo.product.name>
+ <exo.product.specification>1.12</exo.product.specification>
+
+
<org.exoplatform.kernel.version>2.2.Alpha3</org.exoplatform.kernel.version>
+
<org.exoplatform.core.version>2.3.Alpha4</org.exoplatform.core.version>
+ <org.exoplatform.ws.version>2.1.Alpha4</org.exoplatform.ws.version>
+
+ <exo.tck.skip>true</exo.tck.skip>
+ </properties>
+
+ <scm>
+
<
connection>scm:svn:http://svn.exoplatform.org/projects/exorh/exo-jcr/j...
+
<
developerConnection>scm:svn:http://svn.exoplatform.org/projects/exorh/...
+
<
url>http://fisheye.exoplatform.org/browse/projects/exorh/exo-jcr/jcr/t...
+ </scm>
+
+ <modules>
+ <module>component/core</module>
+ <module>component/ext</module>
+ <module>component/ftp</module>
+ <module>component/webdav</module>
+
+ <module>connectors/jca</module>
+
+ <module>frameworks/command</module>
+ <module>frameworks/web</module>
+ <module>frameworks/ftpclient</module>
+
+ <module>applications/config</module>
+ <module>applications/java/web/samples/browser</module>
+ <module>applications/java/web/samples/fckeditor</module>
+ <module>applications/java/web/rest</module>
+ <module>applications/java/web/ear</module>
+ <module>applications/java/standalone/backupconsole</module>
+ </modules>
+
+ <dependencyManagement>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.applications.fckeditor</artifactId>
+ <version>${project.version}</version>
+ <type>war</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.applications.browser</artifactId>
+ <version>${project.version}</version>
+ <type>war</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.applications.rest</artifactId>
+ <version>${project.version}</version>
+ <type>war</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.component.core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.component.ext</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.component.ftp</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.component.webdav</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.framework.command</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.framework.web</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.framework.ftpclient</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.exoplatform.jcr</groupId>
+ <artifactId>exo.jcr.connectors.localadapter</artifactId>
+ <type>rar</type>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.container</artifactId>
+ <version>${org.exoplatform.kernel.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.command</artifactId>
+ <version>${org.exoplatform.kernel.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.common</artifactId>
+ <version>${org.exoplatform.kernel.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.cache</artifactId>
+ <version>${org.exoplatform.kernel.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.core</groupId>
+ <artifactId>exo.core.component.organization.api</artifactId>
+ <version>${org.exoplatform.core.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.core</groupId>
+ <artifactId>exo.core.component.document</artifactId>
+ <version>${org.exoplatform.core.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.core</groupId>
+ <artifactId>exo.core.component.security.core</artifactId>
+ <version>${org.exoplatform.core.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.core</groupId>
+ <artifactId>exo.core.component.script.groovy</artifactId>
+ <version>${org.exoplatform.core.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.commons</artifactId>
+ <version>${org.exoplatform.ws.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.rest.core</artifactId>
+ <version>${org.exoplatform.ws.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.rest.ext</artifactId>
+ <version>${org.exoplatform.ws.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.frameworks.servlet</artifactId>
+ <version>${org.exoplatform.ws.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.ws.commons</groupId>
+ <artifactId>ws-commons-util</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>jsr311-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-jcr-tests</artifactId>
+ <version>1.4</version>
+ </dependency>
+
+ <!-- slf4j-log4j12 for TCK sources -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.6</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-core</artifactId>
+ <version>2.2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-spellchecker</artifactId>
+ <version>2.2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-memory</artifactId>
+ <version>2.2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.xml.stream</groupId>
+ <artifactId>stax-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.xml.stream</groupId>
+ <artifactId>sjsxp</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.8.0.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ <version>1.2.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>jotm</groupId>
+ <artifactId>jotm</artifactId>
+ <version>2.0.10</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.resource</groupId>
+ <artifactId>connector</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.resource</groupId>
+ <artifactId>connector-api</artifactId>
+ <version>1.5</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ <version>1.0.1B</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>concurrent</groupId>
+ <artifactId>concurrent</artifactId>
+ <version>1.3.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.ws.commons</groupId>
+ <artifactId>ws-commons-util</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>jgroups</groupId>
+ <artifactId>jgroups</artifactId>
+ <version>2.6.10.GA</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-chain</groupId>
+ <artifactId>commons-chain</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.3</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.amazon</groupId>
+ <artifactId>s3</artifactId>
+ <version>0.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.amazonaws.sdb</groupId>
+ <artifactId>simpledb</artifactId>
+ <version>2007-11-07</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ <version>2.1.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-fileupload</groupId>
+ <artifactId>commons-fileupload</artifactId>
+ <version>1.2.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.resource</groupId>
+ <artifactId>connector</artifactId>
+ <version>1.5</version>
+ </dependency>
+
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.xml</include>
+ <include>**/*.xsl</include>
+ <include>**/*.properties</include>
+ <include>**/*.ion</include>
+ <include>**/*.conf</include>
+ <include>**/*.config</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.xml</include>
+ <include>**/*.xsl</include>
+ <include>**/*.properties</include>
+ <include>**/login.conf</include>
+ <include>**/*.ion</include>
+ <include>**/*.conf</include>
+ <include>**/*.config</include>
+ </includes>
+ </resource>
+ </resources>
+
+ <testResources>
+ <testResource>
+ <directory>src/test/java</directory>
+ <includes>
+ <include>**/*.properties</include>
+ <include>**/*.xml</include>
+ <include>**/*.txt</include>
+ <include>**/*.conf</include>
+ <include>**/*.config</include>
+ </includes>
+ </testResource>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <includes>
+ <include>**/*.properties</include>
+ <include>**/*.xml</include>
+ <include>**/*.txt</include>
+ <include>**/*.conf</include>
+ <include>**/*.config</include>
+ </includes>
+ </testResource>
+ </testResources>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/${exo.test.includes}.java</include>
+ </includes>
+ <excludes>
+ <exclude>**/ftpclient/**/*.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>