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

📄 webappsobserver.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////////  WebAppsObserver////  NK      23.04.2001////package org.jahia.services.deamons.filewatcher.webappobserver;import java.io.*;import java.text.*;import java.util.*;import org.jahia.bin.Jahia;import org.jahia.services.deamons.filewatcher.*;import org.jahia.services.sites.*;  // JahiaSiteimport org.jahia.exceptions.*;  // JahiaExceptionimport org.jahia.utils.*;       // JahiaConsoleimport org.jahia.services.*;    // JahiaServiceimport org.jahia.services.webapps_deployer.*;import org.jahia.registries.*;  // ServicesRegistryimport org.jahia.services.jef.JecFile;import org.jahia.security.license.*;import org.jahia.services.jef.*;/** * An Observable object for web apps * * @author Khue ng * @version 1.0 */public class WebAppsObserver implements Observer {	/** updatedOnce true if update() has been executed once **/	private boolean mUpdatedOnce = false;	    /** 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;	/** the class name **/	private static final String CLASS_NAME = "WebAppsObserver";    /**     * 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 WebAppsObserver(	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(CLASS_NAME,"init:: " + e.getMessage() );                throw new JahiaInitializationException ("WebAppsObserver::init failed ");            }        }    }    //-------------------------------------------------------------------------    /**     * Handles new files detection     *     */    public void update(	Observable subject,                        Object args ){        synchronized (args) {								            JahiaWebAppsDeployerService ads = ServicesRegistry.getInstance()                                                              .getJahiaWebAppsDeployerService();            JahiaSitesService ss = ServicesRegistry.getInstance()                                                   .getJahiaSitesService();                        if ( ads != null && ads.isInitialized()                && ss != null && ss.isInitialized() && Jahia.isInitiated() ) {						                Vector files = (Vector)args;				int size = files.size();				File f = null;				JecFile jec = null;				boolean reScan = false;								LicenseKey licenseKey = Jahia.getLicenseKey();								if ( licenseKey != null && !mUpdatedOnce ){										// get license info					int jecLicenseType			= 0;					int jecLicenseTypeRelComp 	= 0;																// decrypt Jahia Encrypted Components					for ( int i=0 ; i<size ; i++ ){						f = (File)files.get(i);						if ( f.isFile() && (f.getName().toLowerCase()).endsWith(".jec") ){							try {								jec = new JecFile(f.getAbsolutePath());								jecLicenseType = jec.getLicenseType();								jecLicenseTypeRelComp = jec.getLicenseTypeRelComp();										if ( licenseKey.compareLicense(jecLicenseType,											    		  jecLicenseTypeRelComp) ){																												jec.extractFiles();									f.delete();									reScan = true;								}								jec = null;							} catch ( JefFileKeyNotFoundException knf ){								File tmpFile = new File(f.getAbsolutePath() + "_error");								f.renameTo(tmpFile);								} catch ( JefFileInvalidKeyValueException ikv ){								File tmpFile = new File(f.getAbsolutePath() + "_error");								f.renameTo(tmpFile);								} catch ( InvalidJefFileException ijf ){								File tmpFile = new File(f.getAbsolutePath() + "_error");								f.renameTo(tmpFile);								} catch ( IOException ioe ){								ioe.printStackTrace();							} catch ( JahiaException je ){								// security exception								je.printStackTrace();								} catch ( Throwable t ){								t.printStackTrace();							}						}					}										mUpdatedOnce = true;				}											if ( reScan ){					return;				}				               	try {                    JahiaSite site = ServicesRegistry.getInstance()                    								 .getJahiaSitesService()                    								 .getSite(mSiteID);                    if ( site != null ){                    	ads.deploy(site,files);                	}                } catch ( JahiaException je ){                        JahiaConsole.println(CLASS_NAME,"WebAppsObserver, webapps exception " + je.getMessage() );                }            }        }    }} // end WebAppsObserver

⌨️ 快捷键说明

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