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

📄 jahiatemplatesdeployerservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////////  JahiaTemplatesDeployerService////  NK      12.01.2001////package org.jahia.services.templates_deployer;import java.io.*;import java.text.*;import java.util.*;import org.jahia.exceptions.*;  // JahiaExceptionimport org.jahia.utils.*;       // JahiaConsoleimport org.jahia.services.*;    // JahiaServiceimport org.jahia.services.sites.*;  // JahiaSiteimport org.jahia.data.templates.*;  // JahiaTemplatesPackageimport org.jahia.services.pages.*;  // JahiaPageDefinition/** * This Service Deploy templates packed in a .jar file.  *  * @author Khue ng * @version 1.0 */public abstract class JahiaTemplatesDeployerService extends JahiaService {   	/** a temporary folder **/   	protected static String m_TempFolderDiskPath = "";   	/** temp folder prefix **/   	protected static String m_TempFolderPrefix = "todelete_" ;   	/**	 * The hashtable of templates packages.	 * The entry key is the path to an archive file ( .jar )	 * The value Object is a JahiaTemplatesPackage object	 * containing a list of JahiaWebAppDef ( web components informations bean )	 *	 */	protected static Hashtable m_TemplatesPackage = new Hashtable();	/** The templates.xml descriptor **/   	private static final String TEMPLATES_XML = "templates.xml";    //-------------------------------------------------------------------------    /**     * Deploy a template .jar file     *     * @param (int) 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 abstract boolean deploy(JahiaSite site, String rootFolder, String filePath, boolean moveTemplate) throws JahiaException ;    //-------------------------------------------------------------------------    /**     * Undeploy a template     *     * @param (JahiaPageDefinition) template     */   	public abstract boolean undeploy(JahiaPageDefinition template) throws JahiaException ;    //-------------------------------------------------------------------------	/**     * Deploy a Vector of .jar templates files     *      * @param (JahiaSite) the site     * @param (Vector) files, a vector of .jar templates package file     * @return (boolean) false on exception     */   	public abstract boolean deploy(JahiaSite site, Vector files) ;    //-------------------------------------------------------------------------	/**	 * Return the template root path	 *	 * @return String the template root path	 */	public abstract String getTemplateRootPath() ;    //-------------------------------------------------------------------------	/**	 * Return the template jsp context	 *	 * @return String the template jsp context	 */	public abstract String getTemplatesContext();    //-------------------------------------------------------------------------	/**	 * Return the new templates root path	 *	 * @return String the new templates root path	 */	public abstract String getNewTemplatesPath() ;    //-------------------------------------------------------------------------	/**	 * Return the shared templates folder disk path	 *	 * @return String the shared templates folder disk path	 */	public abstract String getSharedTemplatesPath();    //-------------------------------------------------------------------------	/**	 * Try to load info from a .jar template file or an unzipped directory	 * Informations are read from the templates.xml file	 *	 * @param (String) full path to a file or directory	 * @return a  JahiaTemplatesPackage object or null	 */	public abstract JahiaTemplatesPackage loadTemplatesInfo(String path) ;    //-------------------------------------------------------------------------	/**	 * Register templates in Jahia	 *	 * @param JahiaSite the site	 * @param JahiaTemplatesPackage the templates package	 */	public abstract void registerTemplates( JahiaSite site, JahiaTemplatesPackage pack ) throws JahiaException ;	/************************************************************************	 * Templates Packages ( .jar files ) handling	 *	 * 	 * The directory jahiafiles/new_templates is periodically scanned for new 	 * templates packages. A package is a .jar file	 *	 * If the informations contained in the templates.xml descriptor	 * file is scanned successfully a JahiaTemplatesPackage object that holds 	 * all informations needed by Jahia to deploy them is created.	 *	 * If the deployment mode is automatic, they are automatically deployed and 	 * registered in Jahia. If not, they are added in the HashTable of packages	 * waiting to be deployed manually throught the JahiaAdministration interface.	 *	 * The Key in the hashtable of packages used to identify each package is 	 * the filename of the package.	 * 	 ************************************************************************/    //-------------------------------------------------------------------------	/**	 * delete a package reference in the hashtable of detected packages	 * and delete it physically from disk.	 *	 * @param (JahiaSite) the site in which the templates package belong to	 * @param (String) full path to a file or directory	 * @return true if successful	 */	public boolean deletePackage(JahiaSite site, String path) {						synchronized(m_TemplatesPackage){						File tmpFile = new File(path);			StringBuffer filename = new StringBuffer(site.getSiteKey());			filename.append("_");			filename.append(tmpFile.getName());						//System.out.println(" deletePackage key is =" + filename );						if ( tmpFile != null && tmpFile.isFile() ){					if (tmpFile.delete()){							m_TemplatesPackage.remove(filename.toString());					return true;				} else {					return false;				}				} else {					m_TemplatesPackage.remove(filename.toString());				return true;			}		}	}     //-------------------------------------------------------------------------	/**	 * add a new file or directory only if it is recognized	 * as a valid template package.	 * And only if it is not registered yet.	 *	 * @param (JahiaSite) the site for which to register the templates	 * @param (String) full path to a file or directory	 */	public void addNewFile(JahiaSite site, String path) {									synchronized(m_TemplatesPackage){						File tmpFile = new File(path);			StringBuffer filename = new StringBuffer(site.getSiteKey());			filename.append("_");			filename.append(tmpFile.getName());						JahiaTemplatesPackage pack = null;							if ( m_TemplatesPackage.get(filename.toString())==null ) {										pack = loadTemplatesInfo(path);				if ( pack != null ){					m_TemplatesPackage.remove(filename.toString());					m_TemplatesPackage.put(filename.toString(),pack);				}							}		}	}     //-------------------------------------------------------------------------	/***	 * return an Enumerations of the keys of the Hashtable of package	 *	 * @return (Enumeration) the enumeration of all keys	 */	public Enumeration getTemplatesPackageKeys(){				synchronized(m_TemplatesPackage){			return m_TemplatesPackage.keys();		}		}    //-------------------------------------------------------------------------	/***	 * return an Enumerations of the keys of the Hashtable of package for a gived site	 *	 * @return (String) the site key identifier	 * @return (Enumeration) the enumeration of all keys	 */	public Enumeration getTemplatesPackageKeys(String siteKey){				Enumeration enum = null;		Vector result = new Vector();		synchronized(m_TemplatesPackage){							enum = m_TemplatesPackage.keys();			String name = null;			String siteIdent = siteKey + "_";			while ( enum.hasMoreElements() ){				name = (String)enum.nextElement();				if ( name.startsWith(siteIdent) ){					result.add(siteIdent);				}			}			return result.elements();					}		}    //-------------------------------------------------------------------------	/***	 * return an enumeration of templates package Hashtable for a gived site	 *	 * @return (String) the site key identifier	 * @return (Enumeration) the enumeration of the packages	 */	public Enumeration getTemplatesPackages(String siteKey){		Enumeration enum = null;		Vector result = new Vector();		synchronized(m_TemplatesPackage){							enum = m_TemplatesPackage.keys();			String name = null;			String siteIdent = siteKey + "_";			while ( enum.hasMoreElements() ){				name = (String)enum.nextElement();				if ( name.startsWith(siteIdent) ){					result.add(m_TemplatesPackage.get(name));				}			}			return result.elements();					}	}    //-------------------------------------------------------------------------	/***	 * return a web app package in the Hashtable m_TemplatesPackage	 * looking at the key	 * @param (String) the key	 * @return (Object) a templates package or null 		 */	public Object getTemplatesPackage(String theKey){				synchronized(m_TemplatesPackage){			return m_TemplatesPackage.get(theKey);		}	}    //-------------------------------------------------------------------------	/***	 * scan a directory for templates package.	 * Add them to the HashTable of TemplatesPackage.     *      * @param the full path to a directory     * @return an Hashtable      */    public void scanDirectory(String path)    throws JahiaException {    			synchronized(m_TemplatesPackage){					JahiaTemplatesPackage pack = null;					File dir = new File(path);		    if ( dir != null && dir.isDirectory() ){							File[] files = dir.listFiles();         		int size = files.length;         		for ( int i=0; i<size ; i++ ){            	            		if ( files[i].canWrite() ){										pack = loadTemplatesInfo(files[i].getAbsolutePath());						if ( pack != null ){							//System.out.println("added package in hashtable " + files[i].getAbsolutePath() );							// remove old map							m_TemplatesPackage.remove(files[i].getName());							// set the new map							m_TemplatesPackage.put(files[i].getName(),pack);						}						}				}            }        }	}   } // end JahiaTemplatesDeployerService

⌨️ 快捷键说明

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