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

📄 jahiatemplatesdeployerbaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	/**     * 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 boolean deploy(JahiaSite site, Vector files) {    	synchronized (files) {			if ( site == null ) {				return false;			}												        	// Check first if JahiaPageDefinitionsRegistry is loaded            if (!ServicesRegistry.getInstance().getJahiaPageTemplateService().isInitialized()) {				return false;			}        	        	if ( !Jahia.isInitiated() ){        		return false;        	}        	        	int size = files.size();           	File fileItem = null;           	for ( int i=0 ; i<size ; i++ ){           		fileItem = (File)files.get(i);           		if ( fileItem.isFile() && fileItem.getName().endsWith(".jar") ){               		/*               		JahiaConsole.println("JahiaTemplatesDeployerBaseService::deployPackages",                								" JahiaTemplatesDeployerBaseService found new template: "                								+ fileItem.getName() );					*/               								               		try {												int templateLimit = Jahia.getLicenseKey().getPageTemplateLimit();								  				if ( site.getTemplatesAutoDeployMode() ){							JahiaTemplatesPackage pack = loadTemplatesInfo(fileItem.getAbsolutePath());	                   		if ( pack != null ) {	                   				                   			// check for license limitation	                   			int nbTemplates = ServicesRegistry.getInstance()	                   												.getJahiaPageTemplateService()	                   												.getNbPageTemplates(site.getID());	                   				                   			if ( (Jahia.getLicenseKey().getPageTemplateLimit() != -1)	                   				 && (nbTemplates + pack.getTemplates().size()) > 	                   					templateLimit ){	                   				site.setTemplatesAutoDeployMode(false);				                   					                   				ServicesRegistry.getInstance().getJahiaSitesService().updateSite(site);	                   						   	           				addNewFile(site,fileItem.getAbsolutePath());	                   			} else {			                   							                   			if ( deploy(site,"",fileItem.getAbsolutePath(),true) ){		   	            				// register in Jahia		   	   		    				registerTemplates(site, pack);		       	       					deletePackage(site,fileItem.getAbsolutePath());									} else {			               				fileItem.delete();		               					deletePackage(site,fileItem.getAbsolutePath());		       	      					return false;		       	      				}		       	      			}		       	      			           	   				} else {								try {									File newFile = new File(fileItem.getAbsolutePath()+"_error");									//newFile.createNewFile();									fileItem.renameTo(newFile);													} catch ( Throwable t ){									//System.out.println("Exception while trying to rename error file ");								}													           	   				}       	        	   	} else {		   	           		addNewFile(site,fileItem.getAbsolutePath());                	    }	                  	} catch ( JahiaException e ) {                    	String errMsg = "Failed deploying file " ;                     	JahiaConsole.println("JahiaTemplatesDeployerBaseService::deploy()",                      								errMsg + "\n" + e.toString());                    	fileItem.delete();                    	return false;					}           		}        	}        	return true;     	}	}	/**	 * 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 JahiaTemplatesPackage loadTemplatesInfo(String path) {		JahiaTemplatesPackage 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() ) ){			JahiaTemplatesPackageHandler ph = null;			try {				ph = new JahiaTemplatesPackageHandler(path);   				pack = ph.getPackage();   				return pack;			} catch ( JahiaException je ){				// FIXME not critial				//System.out.println("Error scanning template in " + path + " , " + je.getMessage());				return null;			} finally {				if ( ph != null ){					ph.closeArchiveFile();				}			}		}		return pack;	}	/**	 * Register templates in Jahia	 *	 * @param int site id , which site 	 * @param JahiaTemplatesPackage the templates package	 */	public void registerTemplates(JahiaSite site, JahiaTemplatesPackage pack ) throws JahiaException {      	//JahiaConsole.println( "JahiaTemplatesDeployerBaseService", "registerTemplates(), started ");      	      	//JahiaConsole.println( "JahiaTemplatesDeployerBaseService", "registerTemplates(), for site " + site.getServerName() );       	       	// save definition in db       	int size = pack.getTemplates().size();       	StringBuffer tempFullPath = new StringBuffer (1024);       	tempFullPath.append(m_TemplatesContext);       	tempFullPath.append(site.getSiteKey());       	tempFullPath.append("/") ;       	tempFullPath.append(pack.getRootFolder());       	tempFullPath.append("/") ;       	for ( int i=0 ; i<size ; i++ ) {            JahiaTemplateDef tempDef = (JahiaTemplateDef)pack.getTemplates().get(i);      		//JahiaConsole.println( "JahiaTemplatesDeployerBaseService", "try to add template " +  tempDef.getDisplayName());			JahiaPageDefinition pageDef = ServicesRegistry.getInstance().getJahiaPageTemplateService().											getPageTemplateBySourcePath(site.getID(),tempFullPath.toString() + tempDef.getFileName());                        if ( pageDef == null || ( !pageDef.getName().equals(tempDef.getDisplayName()) ) ){            	            	ServicesRegistry.getInstance().getJahiaPageTemplateService().                        createPageTemplate (                        	                        					site.getID(),                         					tempDef.getDisplayName(),                            				tempFullPath.toString() + tempDef.getFileName(),                            				tempDef.isVisible(),                            				"",      // no image                            				site.getAclID());            	JahiaConsole.println( "JahiaTemplatesDeployerBaseService.registerTemplates", "Added template " + tempDef.getFileName()  );            }       	}	}    //-------------------------------------------------------------------------	/**	 * Return the template root path	 *	 * @return String the template root path	 */	public String getTemplateRootPath(){		return m_TemplateRootPath;	}    //-------------------------------------------------------------------------	/**	 * Return the template jsp context	 *	 * @return String the template jsp context	 */	public String getTemplatesContext(){		return m_TemplatesContext;	}    //-------------------------------------------------------------------------	/**	 * Return the new templates root path	 *	 * @return String the new templates root path	 */	public String getNewTemplatesPath(){		return m_NewTemplatePath;		}    //-------------------------------------------------------------------------	/**	 * Return the shared templates folder disk path	 *	 * @return String the shared templates folder disk path	 */	public String getSharedTemplatesPath(){		return m_SharedTemplatesPath;		}	//-------------------------------------------------------------------------   	/**     * Search and remove the Meta-Inf folder     * @param String parentPath, the path of the parent Folder     * @return (boolean) true if successfull     */   	protected boolean removeMetaInfFolder(String parentPath){				if ( parentPath == null ){			return false;		}				File f = new File(parentPath);		File[] files = f.listFiles();		for (int i=0 ; i<files.length ; i++){			if ( files[i].getName().equalsIgnoreCase(m_META_INF) ){				try {					return JahiaTools.deleteFile(files[i],false);				}catch ( Throwable t ){					t.printStackTrace();					return false;				}			}		}				return false;   	   	}} // end JahiaTemplatesDeployerService

⌨️ 快捷键说明

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