📄 jahiaorionwebappsdeployerbaseservice.java
字号:
// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////// JahiaOrionWebAppsDeployerBaseService//// NK 12.01.2001//package org.jahia.services.webapps_deployer;import java.io.*;import java.text.*;import java.util.*;//import com.sun.xml.parser.Parser;import org.jahia.exceptions.*; // JahiaExceptionimport org.jahia.utils.*; // JahiaConsoleimport org.jahia.settings.*; // JahiaPrivateSettingsimport org.jahia.registries.*; // ServicesRegistryimport org.jahia.services.*; // JahiaServiceimport org.jahia.services.sites.*; // JahiaSiteimport org.jahia.data.webapps.*; // JahiaWebAppsDefimport org.jahia.data.applications.*; // ApplicationBeanimport org.jahia.services.pages.JahiaPage;import org.jahia.services.webapps_deployer.orion.*;/** * This Service Register new Application Definition, * deploy .ear webApps under Orion . * * @author Khue ng * @version 1.0 */public class JahiaOrionWebAppsDeployerBaseService extends JahiaWebAppsDeployerService { private static JahiaOrionWebAppsDeployerBaseService m_Instance = null; /** The Orion server.xml file **/ private String m_ServerXmlFilePath; /** The Orion default-web-site.xml file **/ private String m_DefaultWebSiteFilePath; /** Orion initialization error **/ private boolean m_OrionInitErr = false; /** * Constructor */ protected JahiaOrionWebAppsDeployerBaseService(){ JahiaConsole.println( "JahiaOrionWebAppsDeployerBaseService", "***** Starting the Jahia Orion Deployer Base Service *****" ); } /** * Use this method to get an instance of this class * */ public static synchronized JahiaOrionWebAppsDeployerBaseService getInstance(){ if ( m_Instance == null ){ m_Instance = new JahiaOrionWebAppsDeployerBaseService(); } return m_Instance; } /*** * Initialize with Orion configuration files * * @param JahiaPrivateSettings jSettings */ public void init( JahiaPrivateSettings jSettings ) throws JahiaInitializationException { if (!isInitialized ()) { super.init(jSettings); m_ServerXmlFilePath = m_ServerHomeDiskPath + "config" + File.separator + "server.xml"; m_DefaultWebSiteFilePath = m_ServerHomeDiskPath + "config" + File.separator + "default-web-site.xml"; File serverXmlFile = new File(m_ServerXmlFilePath); File defaultWebSiteFile = new File(m_DefaultWebSiteFilePath); if ( serverXmlFile == null || !serverXmlFile.isFile() || !serverXmlFile.canWrite() || defaultWebSiteFile == null || !defaultWebSiteFile.isFile() || !defaultWebSiteFile.canWrite() ){ String errMsg = serverXmlFile.getAbsolutePath() + " or " + defaultWebSiteFile.getAbsolutePath() + " files cannot be accessed or don't exist " ; JahiaConsole.println("JahiaOrionWebAppsDeployerBaseService.init", errMsg + "\n" ); m_OrionInitErr = true; } JahiaConsole.println("JahiaOrionWebAppsDeployerBaseService.init"," Server Home is :" + m_ServerHomeDiskPath); m_WebAppRootPath = jSettings.jahiaWebAppsDiskPath; JahiaConsole.println("JahiaOrionWebAppsDeployerBaseService.init"," webAppRoot is :" + m_WebAppRootPath); m_NewWebAppPath = jSettings.jahiaNewWebAppsDiskPath; JahiaConsole.println("JahiaOrionWebAppsDeployerBaseService.init"," newWebAppPath is :" + m_NewWebAppPath); mIsServiceInitialized = true; } } // end init /** * With ear file , the application context is the ear file wihtout the extension * so the context gived here is ignored * @param (JahiaSite) the site * @param (String) context , the context not used and can be of any value * @param (String) filePath , the full path to the ear file */ public synchronized boolean deploy(JahiaSite site, String context, String filePath) throws JahiaException { if (!canDeploy()){ return false; } boolean success = false; if ( filePath.endsWith(".ear") ){ success = deployEarFile(site, context, filePath); } if ( success ){ deletePackage(site,filePath); return true; } else { return false; } } /** * Undeploy a web application. * * @param (ApplicationBean) the application bean object * */ public boolean undeploy(ApplicationBean app) throws JahiaException { if (!canDeploy()){ return false; } Server_Xml doc = new Server_Xml(m_ServerXmlFilePath); String context = app.getContext(); doc.removeApplication(context.substring(1,context.length())); // remove the "/" first char doc.write(); // delete appliation folder from disk File f = new File(m_WebAppRootPath + File.separator + app.getContext()); JahiaTools.deleteFile(f); // delete application package (.ear) f = new File(m_WebAppRootPath + File.separator + app.getFilename()); JahiaTools.deleteFile(f); return true; } /** * A simple way to pass a vector of J2EE .ear application files * to be deployed * * @param (JahiaSite) the site * @param (Vector) files, a vector of .ear application files * @return (boolean) true if done correctly */ public boolean deploy(JahiaSite site, Vector files) { if (!canDeploy()){ return false; } synchronized (files) { int size = files.size(); File fileItem = null; for ( int i=0 ; i<size ; i++ ){ fileItem = (File)files.get(i); if ( fileItem != null && fileItem.isFile() ){ JahiaConsole.println("JahiaOrionWebAppsDeployerBaseService::deployWebApps", " JahiaOrionWebAppsDeployerBaseService found new webApp: " + fileItem.getName() ); try { JahiaWebAppsPackage pack = null; if ( site.getWebAppsAutoDeployMode() ){ if ( fileItem.getName().endsWith(".ear") ){ pack = loadWebAppInfo(fileItem.getAbsolutePath()); if ( pack != null ){ if (! deploy(site,pack.getContextRoot(),fileItem.getAbsolutePath()) ){ fileItem.delete(); return false; } } } } else { if ( fileItem.getName().endsWith(".ear") ){ addNewFile(site,fileItem.getAbsolutePath()); } } } catch ( JahiaException e ) { String errMsg = "Failed deploying Application file " + fileItem.getName(); JahiaConsole.println( "JahiaOrionWebAppsDeployerBaseService::deployWebApps()", errMsg + "\n" + e.toString()); fileItem.delete(); } } } } return true; } /** * Under Orion actually we don't deploy war file * So return false * * @param (String) webContext , the webn context * @param (String) filePath , the full path to the war file */ protected boolean deployWarFile(String webContext, String filePath) throws JahiaException { return false; } /** * Handle Ear application File Deployment * * @param (JahiaSite) the site * @param (String) appContext, the application context * @param (String) filePath , the full path to the ear file * @return (boolean) true if success full */ protected boolean deployEarFile(JahiaSite site, String appContext, String filePath) throws JahiaException { JahiaConsole.println("JahiaOrionWebAppsDeployerBaseService.deployEarFile","started"); // move the ear file in the application deploy directory
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -