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

📄 jahiawebappsdeployerservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////////  JahiaWebAppsDeployerService////  NK      12.01.2001////package org.jahia.services.webapps_deployer;import java.io.*;import java.text.*;import java.util.*;import javax.xml.parsers.SAXParser;import org.xml.sax.helpers.ParserAdapter;import org.xml.sax.EntityResolver;import org.jahia.services.sites.*;      	// JahiaSiteimport org.jahia.data.webapps.*;      	// JahiaWebAppsDefimport org.jahia.data.applications.*; 	// ApplicationBeanimport org.jahia.data.constants.*; 		// JahiaConstantsimport org.jahia.utils.*;       		// JahiaConsoleimport org.jahia.utils.xml.*;      		// DtdEntityResolverimport org.jahia.exceptions.*;  		// JahiaExceptionimport org.jahia.services.*;    		// JahiaServiceimport org.jahia.registries.*;        	// ServicesRegistryimport org.jahia.settings.*;          	// JahiaPrivateSettings/** * Web Application Deployment service API * * @author Khue ng * @version 1.0 */public class JahiaWebAppsDeployerService extends JahiaService {    private static final String CLASS_NAME = JahiaWebAppsDeployerService.class.getName();    /** The Server Type **/    protected String m_ServerType = "";    /** The Server Home Disk Path **/    protected String m_ServerHomeDiskPath = "";    /** The full path to the WebApp Root Folder **/    protected static String m_WebAppRootPath = "";    /** The full path to the New WebApp Folder **/    protected static String m_NewWebAppPath = "";    /** The full path to jahia folder **/    protected static String m_JahiaHomeDiskPath = "";    /** The Shared Components Path **/    private static String m_SharedComponentsPath = "";    /** The right **/    protected int m_AppRight = 1;            // FIXME , where to get it ?    /** Is the web Apps visible by default to all user **/    protected int m_VisibleStatus = 1;       // FIXME , where to get it ?    /** a temporary folder **/    protected static String m_TempFolderDiskPath = "";    /** temp folder prefix **/    protected static String m_TempFolderPrefix = "todelete_" ;    /** the DTD Entity Resolver we use with local dtd files **/    protected static EntityResolver m_Resolver ;    /** WEB-INF folder **/    protected static final String m_WEB_INF = "WEB-INF";    /** Meta-Inf folder **/    protected static final String m_META_INF = "Meta-Inf";    /**     * The hashtable of web apps packages.     * The entry key is the path to an archive file ( war, ear )     * or an unziped directory     * The value Object is a vector of JahiaWebAppsPackage     * containing a list of JahiaWebAppDef ( web components informations bean )     *     */    protected static Hashtable m_WebAppsPackage = new Hashtable();    /** The web.xml file in case of .war file **/    private static final String WEB_XML_FILE = "WEB-INF/web.xml";    /***     * Services initializations     *     * @param JahiaPrivateSettings jSettings     */    public void init( JahiaPrivateSettings jSettings )    throws JahiaInitializationException    {        if (!isInitialized ()) {            m_ServerType		 	= jSettings.server;            m_ServerHomeDiskPath 	= jSettings.serverHomeDiskPath;            m_WebAppRootPath		= jSettings.jahiaWebAppsDiskPath;            m_NewWebAppPath  		= jSettings.jahiaNewWebAppsDiskPath;            m_JahiaHomeDiskPath		= jSettings.jahiaHomeDiskPath;            m_SharedComponentsPath	= jSettings.jahiaSharedComponentsDiskPath;            m_Resolver 				= (EntityResolver)jSettings.getDtdEntityResolver();            JahiaConsole.println(CLASS_NAME+".init"," jahiaHomeDiskPath= " + m_JahiaHomeDiskPath);            // create the temporary folder            File f = new File(m_NewWebAppPath);            File parent = f.getParentFile();            if ( parent != null ){                File tmpFolder = new File(parent.getAbsolutePath() + File.separator + "tmp");                tmpFolder.mkdirs();                if ( tmpFolder == null || !tmpFolder.isDirectory() ){                    String errMsg = " cannot create a temporaty folder "  ;                    JahiaConsole.println(CLASS_NAME+".init()", errMsg + "\n" );                    throw new JahiaInitializationException ( errMsg );                }                m_TempFolderDiskPath = tmpFolder.getAbsolutePath();            }            // create the shared components folder            File sComponents = new File(m_SharedComponentsPath);            sComponents.mkdirs();            mIsServiceInitialized = true;        }    } // end init    /************************************************************************     * Abstract Methods , need different implementations depending of the     * type of server ( Tomcat, orion , ... )     *     *     *     ***********************************************************************/    /**     * Hot Deploy a .ear or .war file.     * Hot Deploy a web component on the specifiy server, active them to     * be immediately accessible in Jahia     *     * If it's a .ear file, the context is the application context     * If it's a .war file, the context is the web application context     *     * @param (JahiaSite) the site     * @param (String) context , the context     * @param (String) filePath , the full path to the ear file     * @return (boolean) true if successfull     */    public boolean deploy(JahiaSite site, String context, String filePath) throws JahiaException {    	return false;		}    /**     * Undeploy a web application. Delete the web component from disk.     *     * @param (ApplicationBean) the application bean object     * @return (boolean) true if successfull     */    public boolean undeploy(ApplicationBean app) throws JahiaException {    	return false;		}    /**     * A Simple way to pass a vector of .ear or .war files     * to be deployed or to be added in the hashtable of packages     *     * @param (JahiaSite) the site     * @param (Vector) files, a vector of .ear application files     */    public boolean deploy(JahiaSite site, Vector files){    	return false;	    }    //-------------------------------------------------------------------------    /**     * Return true if deployment functionallities are available or not     * If they are not available ( due to some init initialization or missing resources),     * deploy services always return false.     */    public boolean canDeploy(){    	return false;    }        /**************************************************************************     * Default Implementations     *     *     *************************************************************************/    public static String getNewWebAppsPath(){        return m_NewWebAppPath ;    }    public static String getWebAppsRootPath(){        return m_WebAppRootPath ;    }    public static String getJahiaHomeDiskPath(){        return m_JahiaHomeDiskPath ;    }    public static String getSharedComponentsPath(){        return m_SharedComponentsPath ;    }   /**    * Register Web Apps Definition in Jahia    *    * @param (JahiaSite) the site    * @param (String) appContext , the context root for the web apps    * @param (String) filename , the package file ( .war or .ear needed for undeploying under orion    * @param (Vector) webApps , the vector of JahiaWebAppDef objects    */    public void registerWebApps(JahiaSite site, String appContext, String filename, Vector webApps) throws JahiaException {        int size = webApps.size();        //System.out.println("registerWebApps started");        for ( int i=0 ; i<size ; i++ ) {            JahiaWebAppDef webAppDef = (JahiaWebAppDef)webApps.get(i);            // check if an application with same context and servletsrc already exists or not            ApplicationBean theWebApp = ServicesRegistry.getInstance().                                        getJahiaApplicationsManagerService().                                        getApplication("/" + appContext);            if ( theWebApp == null ){                //System.out.println("registerWebApps app context " + appContext + " not used");                // save definition in db                theWebApp = new ApplicationBean(                                                    0,                      // id                                                    site.getID(),                                                    webAppDef.getName(),                                                    "/" + appContext,                                                    m_VisibleStatus,                                                    false, // not shared                                                    m_AppRight,                                                    filename,                                                    webAppDef.getdesc()                                                    );                ServicesRegistry.getInstance().getJahiaApplicationsManagerService().addDefinition(theWebApp);                //System.out.println("registerWebApps()" + webAppDef.getName() );            }        }   }    /**     * Try to scan web component deployment descriptor files     * ( META-INF\applications.xml  or WEB-INF\web.xml file ).     * A JahiaWebAppsPackage object is returned that holds     * informations extracted from those files     *     * @param (String) full path to a file or directory     * @return a  JahiaWebAppsPackage object or null     */    public JahiaWebAppsPackage loadWebAppInfo(String path) {        synchronized(m_WebAppsPackage){            JahiaWebAppsPackage pack = null;            // check for case sensitive            if ( !JahiaTools.checkFileNameCaseSensitive(path) ){                return null;            }            File f = new File(path);            try  {                // wait while the file is still modified                long fLength = f.length();                Thread.sleep(500);                while ( fLength != f.length() ){                    fLength = f.length();                    Thread.sleep(500);                }            } catch ( Throwable tr ){                return null;            }            if ( f != null && ( f.isFile() || f.isDirectory() ) ){                if (f.isDirectory() ){                    try {                        pack = loadWebAppInfoFromDirectory(path);                    } catch ( JahiaException je ){                        return null;                    }                } else {                    try {                        pack = loadWebAppInfoFromFile(path);                    } catch ( JahiaException je ){                        return null;                    }                }            }            return pack;        }    }    /**     * read the informations contained in a web.xml file     *     * @param path , the full path to a directory     * @return a JahiaWebAppsPackage or null     */    protected JahiaWebAppsPackage loadWebAppInfoFromDirectory(String path) throws JahiaException {        Web_App_Xml doc = null;        Vector vec = new Vector();        JahiaWebAppsPackage pack = null;        // extract data from the web.xml file        doc = new Web_App_Xml(  path  + File.separator + WEB_XML_FILE );        doc.extractDocumentData();        // Actually the Context Root for the web application is the current directory        File tmpFile = new File(path);        String contextRoot = tmpFile.getName();        // build the list of the Web Apps Definition        pack = new JahiaWebAppsPackage(contextRoot);        Vector servlets = doc.getServlets();        int size = servlets.size();        Servlet_Element  servlet = null;        JahiaWebAppDef webAppDef = new JahiaWebAppDef(	doc.getDisplayName(),                                                        contextRoot                                                     );        webAppDef.addRoles(doc.getRoles());        for ( int i=0 ; i<size ; i++ ){            servlet = (Servlet_Element)servlets.get(i);            webAppDef.addServlet(servlet);        }        pack.addWebAppDef(webAppDef);        if ( pack.getWebApps().size()>0 ){            pack.setFileName(tmpFile.getName());            pack.setFilePath(path);        } else {            return null;        }        return pack;    }    /**     * Load Web App info from a file     *     * @param path , the full path to a file     * @return a JahiaWebAppsPackage or null     */    protected JahiaWebAppsPackage loadWebAppInfoFromFile(String path) throws JahiaException {        File fileItem = new File(path);        JahiaWebAppsPackage pack = null;        if ( fileItem != null && fileItem.getName().endsWith(".war") ){            JahiaWebAppsWarPackage warPackage = loadWebAppInfoFromWar(fileItem.getAbsolutePath());

⌨️ 快捷键说明

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