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

📄 jahiasitesbaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//////  JahiaSitesBaseService////  NK      12.03.2001//package org.jahia.services.sites;import java.io.*;import java.util.Vector;import java.util.Hashtable;import java.util.Enumeration;import org.jahia.utils.JahiaConsole;import org.jahia.utils.JahiaTools;import org.jahia.settings.JahiaPrivateSettings;import org.jahia.exceptions.JahiaException;import org.jahia.exceptions.JahiaInitializationException;import org.jahia.registries.ServicesRegistry;import org.jahia.services.filemanager.*;import org.jahia.services.usermanager.*;import org.jahia.services.pages.*;import org.jahia.services.acl.*;                // ACLimport org.jahia.data.*;/** * Jahia Multi Sites Management Service * * @author Khue ng */public class JahiaSitesBaseService extends JahiaSitesService{    private static JahiaSitesBaseService m_Instance = null;    /** The cache in memory */    protected Hashtable             mSiteCache = null;    // list of sites going to be deleted.    // This is used by some services like search engine to avoid useless indexation.    private Vector sitesToDelete = new Vector();    /** reference to the jahia private settings */    protected JahiaPrivateSettings  mJahiaSettings = null;	private static final String CLASS_NAME = "JahiaSitesServices";    //--------------------------------------------------------------------------    protected JahiaSitesBaseService() throws JahiaException {        JahiaConsole.println( "JahiaSitesBaseService",                                "***** Starting the Jahia Sites Base Service *****" );        setServiceName ("JahiaSitesBaseService");        mSiteCache = new Hashtable();        loadSitesInCache();    }    //--------------------------------------------------------------------------    public static synchronized JahiaSitesBaseService getInstance() throws JahiaException {        if ( m_Instance == null ){            m_Instance = new JahiaSitesBaseService();        }        return m_Instance;    }    //--------------------------------------------------------------------------    /**     * return the list of all sites     *     * @return Enumeration an enumeration of JahiaSite bean     * @auhtor NK     */    public Enumeration getSites() throws JahiaException{        return mSiteCache.elements();    }    /***     * @param JahiaPrivateSettings jSettings     *     */	public void init( JahiaPrivateSettings jSettings )	throws JahiaInitializationException	{		if (!isInitialized ()) {	    	mIsServiceInitialized = true;	    	mJahiaSettings = jSettings;	    }	    initFilemanagers();	}    //--------------------------------------------------------------------------    // FH   10 May 2001 Cache storing improvments for performance issues.    /**     * return a site bean looking at it id     *     * @param int the JahiaSite id     * @return JahiaSite the JahiaSite bean     * @auhtor NK     */    public JahiaSite getSite (int id)        throws JahiaException    {        JahiaSite site = (JahiaSite)mSiteCache.get (new Integer(id));        if (site == null) {            // try to load from db            site = JahiaSitesPersistance.getInstance().dbGetSite(id);            // if the site could be loaded, add it into the cache            if (site != null) {                mSiteCache.put (new Integer(id), site);            }        }        return site;    }    //--------------------------------------------------------------------------    // FH   10 May 2001 Cache storing improvments for performance issues.    /**     * return a site bean looking at it key     *     * @param String the site key     * @return JahiaSite the JahiaSite bean     * @auhtor NK     */    public JahiaSite getSiteByKey (String siteKey)        throws JahiaException    {        if (siteKey == null) {            return null;        }        JahiaSite site = null;        // try to find the site in the cache        Enumeration sites = mSiteCache.elements();        while (sites.hasMoreElements()) {            site = (JahiaSite)sites.nextElement();            if (siteKey.equals (site.getSiteKey())) {                return site;            }        }        // the site was not found in the cache, try to load it from the        // database.        site = JahiaSitesPersistance.getInstance().dbGetSiteByKey(siteKey);        // if the site could be loaded from the database, add it into the cache.        if (site != null) {            mSiteCache.put(new Integer(site.getID()), site);        }        return site;    }    //--------------------------------------------------------------------------    // FH   10 May 2001 Cache storing improvments for performance issues.    /**     * return a site looking at it's name     *     * @param String site name     * @return JahiaSite the JahiaSite bean or null     * @auhtor NK     */    public JahiaSite getSite (String name)        throws JahiaException    {        if (name == null) {            return null;        }        JahiaSite site = null;        // try to find the site in the cache.        Enumeration sites = mSiteCache.elements();        while (sites.hasMoreElements()) {            site = (JahiaSite)sites.nextElement();            if (name.equals (site.getServerName())) {                return site;            }        }        // try to load the site from the database.        site = JahiaSitesPersistance.getInstance().dbGetSite (name);        if (site != null) {            mSiteCache.put (new Integer(site.getID()), site);        }        return site;    }    //--------------------------------------------------------------------------    /**     * Add a new site only if there is no other site with same server name     *     * @param JahiaSite the JahiaSite bean     *     * @return boolean false if there is another site using same server name     * @auhtor NK     * @auhtor AK     */    public synchronized boolean addSite( JahiaSite site )       throws JahiaException    {        if ( site == null ){            return false;        }        // check there is no site with same server name before adding        if ( getSite(site.getServerName()) == null                && getSiteByKey(site.getSiteKey()) == null ){            JahiaSitesPersistance.getInstance().dbAddSite(site);            if ( site.getID() == -1 ){                return false;            }            mSiteCache.put(new Integer(site.getID()),site);            return true;        }        return false;    }    //--------------------------------------------------------------------------    /**     * remove a site     *     * @param JahiaSite the JahiaSite bean     * @auhtor NK     */    public synchronized void removeSite( JahiaSite site ) throws JahiaException{        JahiaSitesPersistance.getInstance().dbRemoveSite(site.getID());        mSiteCache.remove(new Integer(site.getID()));    }    //--------------------------------------------------------------------------    /**     * Update a JahiaSite definition     *     * @param JahiaSite the site bean object     * @auhtor NK     */    public synchronized void updateSite( JahiaSite site ) throws JahiaException{        JahiaSitesPersistance.getInstance().dbUpdateSite(site);        mSiteCache.put(new Integer(site.getID()),site);    }    //--------------------------------------------------------------------------    /**     * load all sites from database in cache     *     * @auhtor NK     */    protected void loadSitesInCache() throws JahiaException {        Vector sites = JahiaSitesPersistance.getInstance().dbGetSites();		//--------------------------------------------------------------		// ACL on templates Patch		//		// 30.01.2002 : NK Patch : give admin permission for root admin grp		//						   and site's admin grp on the site ACL if not set		//						   This is needed for ACL who have as parent , the site's ACL		//		// root admin group		JahiaGroup rootAdminGrp = ServicesRegistry.getInstance()			.getJahiaGroupManagerService().getAdministratorGroup(0);		// site admin group		JahiaGroup siteAdminGrp = null;		// settings default permissions		JahiaACLEntry adminAclEntry = new JahiaACLEntry(7,0);		// End Patch		//---------------------------------------------------------------        if ( sites != null ){            int size = sites.size();            for( int i=0 ; i<size ; i++ ){                JahiaSite site = (JahiaSite)sites.get(i);                //--------------------------------------------------------------                // ACL on templates Patch                //                // 30.01.2002 : NK Patch : give admin permission for root admin grp                //						   and site's admin grp on the site ACL if not set                //						   This is needed for ACL who have as parent , the site's ACL                //				if ( !ACLResource.checkAdminAccess(site,rootAdminGrp,site.getID()) ){                	site.getACL().setGroupEntry(rootAdminGrp,adminAclEntry);					siteAdminGrp = ServicesRegistry.getInstance()						.getJahiaGroupManagerService().getAdministratorGroup(site.getID());                	site.getACL().setGroupEntry(siteAdminGrp,adminAclEntry);				}				// End Patch				//--------------------------------------------------------------                // start and create the site's new templates folder if not exists                JahiaSiteTools.startTemplateObserver(site);                // start and create the site's new webapps folder if not exists                JahiaSiteTools.startWebAppsObserver(site);                mSiteCache.put(new Integer(site.getID()),site);            }        }    }    //-------------------------------------------------------------------------    /**     * Add a site to the list of site going to be deleted     *     * @param int siteID     */    public synchronized void addSiteToDelete (int siteID)    {        Integer I = new Integer(siteID);        if ( !this.sitesToDelete.contains(I) ){        	this.sitesToDelete.add(I);        }    }    //-------------------------------------------------------------------------    /**     * Remove a given site from the list of site going to be deleted     *     * @param int siteID     */    public synchronized void removeSiteToDelete (int siteID)    {        this.sitesToDelete.remove(new Integer(siteID));    }    //-------------------------------------------------------------------------    /**     * Return true if the given site is going to be deleted     *     * @param int the site id     * @return boolean     */    public synchronized boolean isSiteToBeDeleted (int siteID)    {        return (this.sitesToDelete.contains(new Integer(siteID)));    }    //-------------------------------------------------------------------------    // FH   2 May 2001    // javadocs automaticaly imported from the JahiaSitesService class.    //    public int getNbSites ()        throws  JahiaException    {        return JahiaSitesPersistance.getInstance().getNbSites ();    }    //--------------------------------------------------------------------------    /**     * returns a DOM representation of a site     *     * @param int siteID     * @auhtor NK     */    public JahiaDOMObject getSiteAsDOM( int siteID ) throws JahiaException{		return JahiaSitesPersistance.getInstance().getSiteAsDOM (siteID);  	}    //--------------------------------------------------------------------------    /**     * returns a DOM representation of a site's properties     *     * @param int siteID     * @auhtor NK     */    public JahiaDOMObject getSitePropsAsDOM( int siteID ) throws JahiaException{		return JahiaSitesPersistance.getInstance().getSitePropsAsDOM (siteID);  	}    //--------------------------------------------------------------------------    /**     * create the filemager's directory for the site     *     * @auhtor NK     */    public void initFilemanagers(){		try {			JahiaFilemanagerService fmngServ = ServicesRegistry.getInstance()			.getJahiaFilemanagerService();			if( fmngServ == null ){				return;			}			Enumeration enum = getSites();			JahiaSite site = null;			while( enum.hasMoreElements() ){				site = (JahiaSite)enum.nextElement();				fmngServ.createDirectory(site);			}		} catch ( Throwable t ){			t.printStackTrace();		}    }}

⌨️ 快捷键说明

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