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

📄 templatesobserver.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////////  TemplatesObserver////  NK      23.04.2001////package org.jahia.services.deamons.filewatcher.templateobserver;import java.io.*;import java.text.*;import java.util.*;import org.jahia.services.deamons.filewatcher.*;import org.jahia.exceptions.*;  	// JahiaExceptionimport org.jahia.services.sites.*;  // JahiaSiteimport org.jahia.utils.*;       	// JahiaConsoleimport org.jahia.services.*;    	// JahiaServiceimport org.jahia.services.pages.*;import org.jahia.services.templates_deployer.*;import org.jahia.registries.*;  	// ServicesRegistry/** * An Observable object * * @author Khue ng * @version 1.0 */public class TemplatesObserver implements Observer {    /** used to attach an observer with a site **/    private int mSiteID = -1;    /** the path of the folder to watch **/    private String mPath;    /** check new file by last modif date or not **/    private boolean mCheckDate = false;    /** the interval **/    private long mInterval;    /** Check bot files and directory **/    private boolean mFileOnly = true;    /**     * Constructor     *     * @param int 			siteID, used to attach a observer with a site     * @param String		path, the path of directory to watch.     * @param boolean		checkDate, check by last modif date or not     * @param long			interval, the interval of check     * @param boolean		fileOnly, check both new files and directory     */    public TemplatesObserver(	int siteID,                            String path,                            boolean checkDate,                            long interval,                            boolean fileOnly ) throws JahiaException {        mSiteID 	= siteID;        mPath 		= path;        mCheckDate	= checkDate;        mInterval	= interval;        mFileOnly	= fileOnly;        JahiaFileWatcherService fws = ServicesRegistry                                            .getInstance()                                            .getJahiaFileWatcherService();        if ( fws != null ){            try {                fws.addFileWatcher(	mPath,                                    mPath,                                    mCheckDate,                                    mInterval,                                    mFileOnly);                fws.registerObserver(mPath,this);                fws.startFileWatcher(mPath);            } catch ( JahiaException e ) {                JahiaConsole.println("TemplatesObserver","init:: " + e.getMessage() );                throw new JahiaInitializationException ("TemplatesObserver::init failed ");            }        }    }    //-------------------------------------------------------------------------    /**     * Handles new files detection     *     */    public void update(	Observable subject,                        Object args ){        synchronized (args) {						JahiaPageTemplateService pts = ServicesRegistry.getInstance()                            				.getJahiaPageTemplateService();            JahiaSitesService ss = ServicesRegistry.getInstance()                            				.getJahiaSitesService();                            				            JahiaTemplatesDeployerService tds = ServicesRegistry.getInstance()                            						.getJahiaTemplatesDeployerService();            if ( pts != null && pts.isInitialized()                && ss != null && ss.isInitialized()                && tds != null && tds.isInitialized() ) {                Vector files = (Vector)args;                                try {                	JahiaSite site = ss.getSite(mSiteID);		        	if ( site != null ){                		tds.deploy(site,files);                    }            	} catch ( JahiaException je ){            		JahiaConsole.println("TemplatesObserver.update", "templates exception " + je.getMessage() );            	}            }        }    }} // end JahiaTemplateObserverService

⌨️ 快捷键说明

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