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

📄 jahiatemplatesdeployerbaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////////  JahiaTemplatesDeployerBaseService////  NK      12.01.2001////package org.jahia.services.templates_deployer;import java.io.*;import java.text.*;import java.util.*;import org.jahia.bin.Jahia;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.templates.*;  // JahiaTemplatesPackageimport org.jahia.utils.zip.*;       // JahiaArchiveFileHandlerimport org.jahia.services.pages.*;  // JahiaPageDefinitionimport org.jahia.security.license.*;/** * This Service Deploy templates packed in a .jar file. * * @author Khue ng * @version 1.0 */public class JahiaTemplatesDeployerBaseService extends JahiaTemplatesDeployerService {	private static JahiaTemplatesDeployerBaseService m_Instance = null;   	/** The Default Visible status for  Templates **/   	private int m_VisibleStatus = 0;   // FIXME , where to get it ?   	/** The relative Path to the Template Root Folder **/   	private static String m_TemplateRootPath = "";   	/** The Shared Templates Path **/   	private static String m_SharedTemplatesPath = "";   	/** The JSP context path **/   	private static String m_JspContext = "";   	/** The templates context path **/   	private static String m_TemplatesContext = "";   	/** The relative Path to the New Template Folder **/   	private static String m_NewTemplatePath = "";   	/** The classes Root Path **/   	private static String m_ClassesRootPath;   	/** The templates classe Root Path **/   	private static String m_TEMPLATES_CLASSES_ROOT_FOLDER = "jahiatemplates";	/** Meta-Inf folder **/		protected static final String m_META_INF = "Meta-Inf";   	/**     * Constructor     */   	protected JahiaTemplatesDeployerBaseService(){		JahiaConsole.println( "JahiaTemplateDeployerBaseService", "***** Starting the Jahia Templates Deployer Base Service *****" );   	}   	/**     * Use this method to get an instance of this class     *     */   	public static synchronized JahiaTemplatesDeployerBaseService getInstance(){    	if ( m_Instance == null ){        	m_Instance = new JahiaTemplatesDeployerBaseService();      	}      	return m_Instance;   	}	/***     * @param JahiaPrivateSettings jSettings     *     */   	public void init( JahiaPrivateSettings jSettings )   	throws JahiaInitializationException   	{        if (!isInitialized ()) {			Properties props 	= jSettings.getPropertiesFile();	 	   	m_TemplateRootPath 	= jSettings.jahiaTemplatesDiskPath;	 	   	m_JspContext 		= jSettings.jspContext;	 	   	m_TemplatesContext 	= jSettings.templatesContext;	  	   	m_ClassesRootPath  	= jSettings.classDiskPath + File.separator + m_TEMPLATES_CLASSES_ROOT_FOLDER;	       	m_NewTemplatePath  	= jSettings.jahiaNewTemplatesDiskPath;	       	m_SharedTemplatesPath	= jSettings.jahiaSharedTemplatesDiskPath;				System.out.println("m_TemplateRootPath=" + m_TemplateRootPath);			System.out.println("m_JspContext=" + m_JspContext);			System.out.println("m_TemplatesContext" + m_TemplatesContext);			System.out.println("m_ClassesRootPath=" + m_ClassesRootPath);				 			 				  	// create the temporary folder		  	File f = new File(m_NewTemplatePath);		  	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("JahiaTemplatesDeployerBaseService::init()", errMsg + "\n" );	         		throw new JahiaInitializationException ( errMsg );				}							m_TempFolderDiskPath = tmpFolder.getAbsolutePath();		  	}						// create the shared templates folder			File sTemplates = new File(m_SharedTemplatesPath);			sTemplates.mkdirs();						mIsServiceInitialized = true;		}				   	} // end init	/**     * Deploy a template .jar file.	 * The jar file will be unzipped in the root folder.	 *	 * If the RootFolder is equals to an empty string, the Root Folder	 * is the one described in the templates.xml     *     * @param (JahiaSite) the site     * @param (String) rootFolder, root folder for the template     * @param (String) filePath , the full path to the template.jar file     * @param (boolean) moveTemplate , if true, move te template package to the deployed directory when done     */   	public boolean deploy(JahiaSite site, String rootFolder, String filePath, boolean moveTemplate) throws JahiaException {		boolean success = true;		String fullPath = null;   		   		if ( filePath.endsWith(".jar") ){			JahiaTemplatesPackageHandler ph = null;      		try {	  			ph = new JahiaTemplatesPackageHandler(filePath);	    		JahiaTemplatesPackage tempPack = ph.getPackage();	    			    		if ( tempPack == null ){	    			String errMsg =" cannot create a JahiaTemplatesPackage on file " + filePath ;   	 				throw new JahiaException ("JahiaTemplatesDeployerBaseService::deploy()", "JahiaTemplatesDeployerBaseService" + errMsg ,	                             JahiaException.SERVICE_ERROR, JahiaException.ERROR);	    		}	      			      		StringBuffer strBuf = new StringBuffer(1024);   		  		strBuf.append(m_TemplateRootPath);   				strBuf.append(File.separator);   				strBuf.append(site.getSiteKey());   				strBuf.append(File.separator);   				if ( rootFolder.equals("") ){   					strBuf.append(tempPack.getRootFolder());   				} else {   					strBuf.append(rootFolder);				}				      			// Full path to the templates root folder   	  			fullPath = strBuf.toString();      			// Check that the root folder for the new template doesn't exist   	  			File f = new File(fullPath);   				if ( f != null && !f.isDirectory() ){       				// create the dir       				f.mkdirs();       				       				JahiaConsole.println("JahiaTemplatesDeployerBaseService","Delete meta-inf folder=" + f.getAbsolutePath());       				// Remove the Meta-Inf folder first       				removeMetaInfFolder(f.getAbsolutePath());       				 					ph.unzip(fullPath);											       				// extract the classes file       				if ( tempPack.hasClasses	() ){		 				String classesFilePath = fullPath + File.separator + tempPack.getClassesFile();		 					 				File tmpFile = new File(classesFilePath); 						try{ 							if ( tmpFile != null && tmpFile.isFile() ){   								JahiaArchiveFileHandler arch = new JahiaArchiveFileHandler(classesFilePath);   	   							arch.unzip(m_ClassesRootPath);   	   	 					} else {   	   	 						success = false;   	   	 					}       					} catch ( IOException ioe ){        					String errMsg = "Failed creating JahiaArchiveFileHandler on classes file " ;    	     				JahiaConsole.println("JahiaTemplatesDeployerBaseService::deploy()", errMsg + "\n" + ioe.toString());   	    	 				throw new JahiaException ("JahiaTemplatesDeployerBaseService::deploy()", "JahiaTemplatesDeployerBaseService" + errMsg ,                                   JahiaException.SERVICE_ERROR, JahiaException.ERROR);		        		}		        	}				}      		} catch ( JahiaException e ) {   	    		String errMsg = "Failed handling templates file " ;       	 		JahiaConsole.println("JahiaTemplatesDeployerBaseService::deploy()", errMsg + "\n" + e.toString());       			throw new JahiaException ("JahiaTemplatesDeployerBaseService::deploy()", "JahiaTemplatesDeployerBaseService" + errMsg ,                                    JahiaException.SERVICE_ERROR, JahiaException.ERROR);			} finally {				if ( ph != null ){					ph.closeArchiveFile();				}			}			if (success && moveTemplate){							// move the template package into the template root folder				File fileItem = new File (filePath);				fileItem.renameTo(new File(fullPath + File.separator + fileItem.getName()));			}						}					return success;	}    /**     * Undeploy a template     *     * @param (JahiaPageDefinition) template     */   	public boolean undeploy(JahiaPageDefinition template) throws JahiaException {				/*   				if ( template != null ){						File f = new File(m_JspContext + File.sepatator    							// Delete physically the directory on disk			JahiaTools.deleteFile(new File(m_WebAppRootPath + app.getContext()));			return true;   		}		*/   		return false;		   	}

⌨️ 快捷键说明

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