Package com.sos.VirtualFileSystem.Factory

Source Code of com.sos.VirtualFileSystem.Factory.VFSFactory

/********************************************************* begin of preamble
**
** Copyright (C) 2003-2010 Software- und Organisations-Service GmbH.
** All rights reserved.
**
** This file may be used under the terms of either the
**
**   GNU General Public License version 2.0 (GPL)
**
**   as published by the Free Software Foundation
**   http://www.gnu.org/licenses/gpl-2.0.txt and appearing in the file
**   LICENSE.GPL included in the packaging of this file.
**
** or the
** 
**   Agreement for Purchase and Licensing
**
**   as offered by Software- und Organisations-Service GmbH
**   in the respective terms of supply that ship with this file.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
** IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
********************************************************** end of preamble*/
package com.sos.VirtualFileSystem.Factory;

import java.net.URL;

import org.apache.log4j.Logger;

import com.sos.VirtualFileSystem.FTP.SOSFTPOptions;
import com.sos.VirtualFileSystem.FTP.SOSVfsFtp;
import com.sos.VirtualFileSystem.FTPS.SOSVfsFtpS;
import com.sos.VirtualFileSystem.Interfaces.ISOSAuthenticationOptions;
import com.sos.VirtualFileSystem.Interfaces.ISOSVFSHandler;
import com.sos.VirtualFileSystem.SFTP.SOSVfsSFtp;
import com.sos.VirtualFileSystem.local.SOSVfsLocal;
import com.sos.VirtualFileSystem.zip.SOSVfsZip;
import com.sos.i18n.Msg;
import com.sos.i18n.Msg.BundleBaseName;
import com.sos.i18n.annotation.I18NMessage;
import com.sos.i18n.annotation.I18NMessages;
import com.sos.i18n.annotation.I18NResourceBundle;

/**
* \class VFSFactory
*
* \brief VFSFactory -
*
* \details
*
* \section VFSFactory.java_intro_sec Introduction
*
* \section VFSFactory.java_samples Some Samples
*
* \code
*   .... code goes here ...
* \endcode
*
* <p style="text-align:center">
* <br />---------------------------------------------------------------------------
* <br /> APL/Software GmbH - Berlin
* <br />##### generated by ClaviusXPress (http://www.sos-berlin.com) #########
* <br />---------------------------------------------------------------------------
* </p>
* \author KB
* @version $Id: VFSFactory.java 14789 2011-07-08 15:51:52Z sos $21.05.2010
* \see reference
*
* Created on 21.05.2010 12:44:25
*/

/**
* @author KB
*
*/
@I18NResourceBundle(baseName = "SOSVirtualFileSystem", defaultLocale = "en")
public class VFSFactory {

  private final static String  conClassName  = "VFSFactory";
  private static Logger    logger      = Logger.getLogger(VFSFactory.class);

  protected static Msg    objMsg      = new Msg(new BundleBaseName("SOSVirtualFileSystem"));

  @I18NMessages(value = { @I18NMessage("%1$s returns instance of %2$s"), //
      @I18NMessage(value = "%1$s returns instance of %2$s", //
      locale = "en_UK", //
      explanation = "%1$s returns instance of %2$s" //
      ), //
      @I18NMessage(value = "%1$s liefert eine Instanz der Klasse %2$s", //
      locale = "de", //
      explanation = "%1$s returns instance of %2$s" //
      ), //
      @I18NMessage(value = "%1$s returns instance of %2$s", locale = "es", //
      explanation = "%1$s returns instance of %2$s" //
      ), //
      @I18NMessage(value = "%1$s returns instance of %2$s", locale = "fr", //
      explanation = "%1$s returns instance of %2$s" //
      ), //
      @I18NMessage(value = "%1$s returns instance of %2$s", locale = "it", //
      explanation = "%1$s returns instance of %2$s" //
      ) //
  }, msgnum = "SOSVfs-D-0201", msgurl = "SOSVfs-D-0201")
  /*!
   * \var SOSVfs_D_0201
   * \brief %1$s returns instance of %2$s
   */
  public static final String  SOSVfs_D_0201  = "SOSVfs_D_0201";

  @I18NMessages(value = { @I18NMessage("undefined Virtual File System requested: %1$s"), //
      @I18NMessage(value = "undefined Virtual File System requested: %1$s", //
      locale = "en_UK", //
      explanation = "undefined Virtual File System requested: %1$s" //
      ), //
      @I18NMessage(value = "Virtuelles Datei-System nicht erkannt: %1$s", //
      locale = "de", //
      explanation = "undefined Virtual File System requested: %1$s" //
      ), //
      @I18NMessage(value = "undefined Virtual File System requested: %1$s", locale = "es", //
      explanation = "undefined Virtual File System requested: %1$s" //
      ), //
      @I18NMessage(value = "undefined Virtual File System requested: %1$s", locale = "fr", //
      explanation = "undefined Virtual File System requested: %1$s" //
      ), //
      @I18NMessage(value = "undefined Virtual File System requested: %1$s", locale = "it", //
      explanation = "undefined Virtual File System requested: %1$s" //
      ) //
  }, msgnum = "SOSVfs-E-0203", msgurl = "SOSVfs-E-0203")
/*!
* \var SOSVfs_E_0203
* \brief Msgundefined Virtual File System requested: %1$s
*/
  public static final String SOSVfs_E_0203 = "SOSVfs-E-0203";

  public static enum enuTransferTypes {
    local, /* filesystem on localhost */
    file, /* same as local */
    ftp, sftp, ftps, ssh2, zip, mq, // Message Queue
    http, https, svn
    /* */;

    public String Text() {
      String strT = this.name();
      return strT;
    }
  }

  /**
   *
   * \brief VFSFactory
   *
   * \details
   *
   */
  public VFSFactory() {
    //
  }

  @SuppressWarnings("unchecked")
  public static ISOSVFSHandler getHandler(String pstrWhatURL) throws Exception {

    // TODO eigener Datentyp SOSVirtualFileHandlerSystemType

    final String conMethodName = conClassName + "::getHandler";

    ISOSVFSHandler objC = null;
    URL objURL = null;
    // TODO Type of filesystem as an enumeration

    String strWhatSystem = pstrWhatURL;

    // Possible Elements of an URL are:
    //
    // http://hans:geheim@www.example.org:80/demo/example.cgi?land=de&stadt=aa#geschichte
    // | | | | | | | |
    // | | | host | url-path searchpart fragment
    // | | password port
    // | user
    // protocol

    int i = pstrWhatURL.indexOf("//");
    if (i > 0) {
      objURL = new URL(pstrWhatURL);
      strWhatSystem = pstrWhatURL.substring(0, i);
      if (strWhatSystem.equalsIgnoreCase(objURL.getProtocol())) {
        // nothing to do
      }
      strWhatSystem = objURL.getProtocol();
    }
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

    if (strWhatSystem.equalsIgnoreCase(enuTransferTypes.ssh2.Text())) {
      // TODO �ber late binding laden, damit es auch als Option verwendet werden kann
      // com.sos.VirtualFileSystem.SSH.SOSSSH2TriLeadImpl
      // objC = new SOSSSH2TriLeadImpl();
      // logger.debug(conMethodName + " returns instance of " + SOSSSH2TriLeadImpl.class.toString());
      // com.sos.VirtualFileSystem.SSH.SOSSSH2GanymedImpl
      // objC = new SOSSSH2GanymedImpl();
      // logger.debug(conMethodName + " returns instance of " + SOSSSH2GanymedImpl.class.toString());

//       Class objA = classLoader.loadClass("com.sos.VirtualFileSystem.SSH.SOSSSH2GanymedImpl");
      Class objA = classLoader.loadClass("com.sos.VirtualFileSystem.SSH.SOSSSH2TriLeadImpl");
      ISOSVFSHandler objD = (ISOSVFSHandler) objA.newInstance();
      logger.debug(String.format(objMsg.getMsg(SOSVfs_D_0201), conMethodName, objD.toString()));

      if (objD instanceof ISOSVFSHandler) {
        logger.debug("ISOSVFSHandler is part of class   ...  " + objA.toString());
        objC = (ISOSVFSHandler) objD;
      }
      else {
        logger.error("ISOSVFSHandler not part of class");
      }
    }

    if (strWhatSystem.equalsIgnoreCase(enuTransferTypes.ftp.Text())) {
      objC = new SOSVfsFtp();
      logger.debug(String.format(objMsg.getMsg(SOSVfs_D_0201), conMethodName, SOSVfsFtp.class.toString()));
    }

    if (strWhatSystem.equalsIgnoreCase(enuTransferTypes.ftps.Text())) {
      objC = new SOSVfsFtpS();
      logger.debug(String.format(objMsg.getMsg(SOSVfs_D_0201), conMethodName, SOSVfsFtpS.class.toString()));
    }

    if (strWhatSystem.equalsIgnoreCase(enuTransferTypes.sftp.Text())) {
      objC = new SOSVfsSFtp();
      logger.debug(String.format(objMsg.getMsg(SOSVfs_D_0201), conMethodName, SOSVfsFtp.class.toString()));
    }

    if (strWhatSystem.equalsIgnoreCase(enuTransferTypes.local.Text()) || strWhatSystem.equalsIgnoreCase(enuTransferTypes.file.Text())) {
      objC = new SOSVfsLocal();
      logger.debug(String.format(objMsg.getMsg(SOSVfs_D_0201), conMethodName, SOSVfsLocal.class.toString()));
    }

    if (strWhatSystem.equalsIgnoreCase(enuTransferTypes.zip.Text())) {
      objC = new SOSVfsZip();
      logger.debug(String.format(objMsg.getMsg(SOSVfs_D_0201), conMethodName, SOSVfsZip.class.toString()));
    }

    if (objC == null) {
      throw new Exception(String.format(objMsg.getMsg(SOSVfs_E_0203), strWhatSystem));
    }

    if (objURL != null) {
      String strHost = objURL.getHost();
      if (strHost != null) {
        int intPort = objURL.getPort();
        objC.Connect(strHost, intPort);
        ISOSAuthenticationOptions objAO = new SOSFTPOptions();
        String strUserInfo = objURL.getUserInfo();
        logger.info("User-Info = " + strUserInfo);
        String[] strUI = strUserInfo.split(":");
        objAO.getUser().Value(strUI[0]);
        objAO.getPassword().Value(strUI[1]);
        objC.Authenticate(objAO);
        objAO = null;
        logger.info("objURL.getAuthority() : " + objURL.getAuthority());
        logger.info("objURL.getFile()" + objURL.getFile());
      }
    }
    return objC;
  }
}
TOP

Related Classes of com.sos.VirtualFileSystem.Factory.VFSFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.