⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jahiafiletransferbaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////  JahiaFileTransferBaseServices//  EV      30.11.2000////  init( jSettings )//  downloadApp( fileName, urlPath, diskPath )//  downloadTemplate( fileName, urlPath, diskPath )//package org.jahia.services.files;import java.io.*;					    // IOExceptionimport java.net.*;					    // HttpURLConnectionimport java.util.*;					    // Vectorimport org.jahia.utils.*;           // JahiaConsoleimport org.jahia.settings.*;        // JahiaPrivateSettingsimport org.jahia.services.*;        // JahiaService Interfaceimport org.jahia.exceptions.*;      // JahiaException & JahiaInitializationException/** * Class JahiaFileTransFerBaseService * */public class JahiaFileTransferBaseService extends JahiaFileTransferService {    private static String serviceName = "JahiaFileTransferBaseService";    private static String componentsDiskPath   = "";    private static String tmpDiskPath     = "";    private static JahiaFileTransferBaseService theObject = null;   /**    * constructor     * EV    18.11.2000    */    protected JahiaFileTransferBaseService()    {        JahiaConsole.println( "Service", "***** Starting " + serviceName + " *****" );    } // end constructor   /***    * getInstance     * EV    31.10.2000    *    */    public static synchronized JahiaFileTransferBaseService getInstance()    {        if (theObject == null) {            theObject = new JahiaFileTransferBaseService();        }        return theObject;    } // end getInstance   /***    * init     * EV    30.11.2000    *    */   public void init( JahiaPrivateSettings jSettings ) throws JahiaInitializationException    {        JahiaConsole.println( "Service", "***** initializing " + serviceName + " *****" );        componentsDiskPath  = jSettings.componentsDiskPath;        tmpDiskPath         = jSettings.jahiaTemplatesDiskPath;    } // end init   /***    * downloadApp     * EV    30.11.2000     * called by DownloadApp_Engine.processForm    *    */    public boolean downloadApp( String fileName, String urlPath, String diskPath )    {        JahiaConsole.println("JahiaFileTransferBaseService.downloadApp","ComponentsDiskPath is " + componentsDiskPath );        String completeDiskPath = componentsDiskPath + File.separator + diskPath + "\\";        // let's first check if the directory already exists        // checkFile will check :        //  - if directory already exists, this means that the appliation is already there ! -> do nothin'        //  - if directory does not exist, create it and return true        if (checkFile( completeDiskPath, fileName )) {            // now we can download the file, and return true            downloadFile( urlPath + fileName, completeDiskPath + fileName );            return true;        } else {            // couldn't replace the application -> problems !            return false;        }    } // end downloadApp   /***    * downloadTemplate     * EV    30.11.2000     * called by DownloadTemplate_Engine.processForm    *    */    public boolean downloadTemplate( String fileName, String urlPath, String diskPath )    {        String completeDiskPath = tmpDiskPath + diskPath + "\\";        JahiaConsole.println("JahiaFileTransferBaseService.downloadTemplate","Downloading template to : " + completeDiskPath );        // let's first check if the directory already exists        // checkFile will check :        //  - if directory already exists, this means that the appliation is already there ! -> do nothin'        //  - if directory does not exist, create it and return true        if (checkFile( completeDiskPath, fileName )) {            // now we can download the file            if (downloadFile( urlPath + fileName, completeDiskPath + fileName )) {                // download ok, return true                return true;            } else {                // download failed -> problems !                return false;            }        } else {            // couldn't replace the template -> problems !            return false;        }    } // end downloadTemplate   /***    * checkFile     * EV    30.11.2000     * called by downloadApp    *    */   protected boolean checkFile( String diskPath, String fileName )    {        File fAppPath = new File( diskPath );        if (!fAppPath.exists()) {            JahiaConsole.println( "FileTransferManager", "Creating " + diskPath + " path " );            fAppPath.mkdirs();        }        File fApp = new File( diskPath + "\\" + fileName );        if (fApp.exists()) {            if (fApp.delete()) {                return true;            } else {                String msg = "Failed to replace existing file " + diskPath + "\\" + fileName + " for download";                JahiaException je = new JahiaException( "Download error", msg,                                        JahiaException.TEMPLATE_ERROR, JahiaException.WARNING );                return false;            }        } else {            return true;        }    } // end checkFile   /***    * downloadFile     * EV    30.11.2000     * called by downloadApp    *    */    protected boolean downloadFile( String urlPath, String diskPath )    {        try {            URL url             = new URL( urlPath );            InputStream input   = url.openStream();            File myFile         = new File( diskPath );            OutputStream output = (OutputStream) new FileOutputStream( myFile );            FileUtils.getInstance().copyStream( input, output );            JahiaConsole.println("JahiaFileTransferBaseService.downloadFile", diskPath + " successfully transfered from " + urlPath );            return true;        } catch (IOException ie) {            String msg = "IOException while trying to download " + diskPath + " from " + urlPath;            JahiaException je = new JahiaException( "Download error", msg,                                    JahiaException.TEMPLATE_ERROR, JahiaException.WARNING );            return false;        }    } // end downloadFile   /**    * set the service name    */    public void setName(String name){      serviceName = name;    }} // end JahiaFileTransferBaseService

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -