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

📄 jahiaapplicationsmanagerbaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//////  JahiaApplicationsManagerBaseService//  NK      10.02.2000////package org.jahia.services.applications;import java.io.*;import java.util.*;                     // Vector, Enumerationimport org.jahia.exceptions.JahiaException;import org.jahia.data.*;           			// JahiaDataimport org.jahia.data.fields.JahiaField;          import org.jahia.data.webapps.*;      		// JahiaWebAppsDefimport org.jahia.data.applications.*;  		// ApplicationBeanimport org.jahia.params.*;         			// ParamBeanimport org.jahia.services.*;       			// JahiaServiceimport org.jahia.registries.*;       		// ServicesRegistryimport org.jahia.settings.*;          		// JahiaPrivateSettingsimport org.jahia.exceptions.*;        		// JahiaExceptionimport org.jahia.utils.*;             		// JahiaConsoleimport org.jahia.services.usermanager.*;    // JahiaGroup/** * This Service is used to manage the jahia application definitions. * * @author Khue ng * @version 1.0 */public class JahiaApplicationsManagerBaseService extends JahiaApplicationsManagerService{	/** the instance **/	private static JahiaApplicationsManagerBaseService m_Instance = null;	/** the cache of application definition **/	private Hashtable registry = new Hashtable();	/** dummy comparator application bean **/	private ApplicationBean dummyComparator;		/** is loaded status **/	private boolean isLoaded = false;			/**	 * constructor	 *	 */	protected JahiaApplicationsManagerBaseService(){    	JahiaConsole.println( "JahiaApplicationsManagerBaseService",                            "***** Starting the Jahia Applications Manager Base Service *****" );		dummyComparator = new ApplicationBean ( -1,-1,"","",0,false,-1,"","" );	}		/**	 * return the singleton instance	 */	public static synchronized JahiaApplicationsManagerBaseService getInstance(){				if ( m_Instance == null ){			m_Instance = new JahiaApplicationsManagerBaseService();		}				return m_Instance;	}    /***     * Initialze disk path     *     * @param JahiaPrivateSettings jSettings     */   	public void init( JahiaPrivateSettings jSettings )   	throws JahiaInitializationException   	{   		try {			loadAllApplications();		} catch ( Throwable t ){			t.printStackTrace();			throw new JahiaInitializationException("JahiaApplicationsManagerBaseService.init, exception occured : " + t.getMessage());		}		this.isLoaded = true;	}		//--------------------------------------------------------------------------	/***	 * return a vector of distinct Jahia web site for all application definitions     *     * @return a Vector of Jahia Web site     */    public Vector getWebSites()     throws JahiaException {		return ServicesRegistry.getInstance()				.getJahiaApplicationsPersistanceService().getWebSites();    		}    		//--------------------------------------------------------------------------	/***	 * return an Application Definition get directly from db     *     * @param int, the appID     * @return ApplicationBean, the Application Definition     */    public ApplicationBean getApplication( int appID )     throws JahiaException {				checkIsLoaded();					synchronized ( registry ){			ApplicationBean app = (ApplicationBean)registry.get(new Integer(appID));			if ( app == null ){				// try to load from db				app = ServicesRegistry.getInstance()						.getJahiaApplicationsPersistanceService()						.get_application_definition( appID );				if ( app != null ){					registry.put(new Integer(app.getID()),app);				}			}			return app;		}    		}    		//--------------------------------------------------------------------------	/***	 * return an Application Definition looking at its context.     *	 * @param context , the context     * @return ApplicationBean, the Application Definition     */    public ApplicationBean getApplication( String context )     throws JahiaException {		checkIsLoaded();		if ( context == null ){			return null;		}		synchronized ( registry ){			ApplicationBean app = null;			Enumeration keys = registry.keys();			while ( keys.hasMoreElements() )			{				app = (ApplicationBean)registry.get((Integer)keys.nextElement());				if ( app != null 					 && app.getContext() != null 					 && app.getContext().equals(context) )				{					return app;				}			}			// try to load from db			app = ServicesRegistry.getInstance()					.getJahiaApplicationsPersistanceService()					.get_application_definition( context );			if ( app != null ){				registry.put(new Integer(app.getID()),app);			}			return app;		}	}    		//--------------------------------------------------------------------------	/***	 * return all application Definitions     *      * @return Enumeration an enumerations of ApplicationBean or null if empty     */    public Vector getApplications()    throws JahiaException {        checkIsLoaded();                Vector apps = new Vector(registry.values());        Collections.sort(apps,dummyComparator);		return apps;	}	//--------------------------------------------------------------------------	/***	 * return all application Definitions for a gived site ( jahia id )     *      * @param int the JahiaID web site     * @return Vector of ApplicationBean     */    public Vector getApplications(int jahiaID)    throws JahiaException {    			checkIsLoaded();				Vector apps = new Vector();		Enumeration enum = registry.elements();		ApplicationBean app = null;		while ( enum.hasMoreElements() )		{			app = (ApplicationBean)enum.nextElement();			if ( app.getJahiaID()== jahiaID )			{				apps.add((ApplicationBean)registry.get(new Integer(app.getID())));			}		}        Collections.sort(apps,dummyComparator);		return apps;	}	//--------------------------------------------------------------------------	/***	 * set an application Visible to users	 * 	 * @param int appID	 * @param boolean visible status	 * @return false on error	 */	public boolean setVisible(int appID, boolean visible) 	throws JahiaException {		checkIsLoaded();				ApplicationBean app = getApplication( appID );			if ( app != null ){			if ( visible ){				app.setVisible(1);							} else {				app.setVisible(0);			}			return saveDefinition(app);		}							return false;	}	//--------------------------------------------------------------------------	/***	 * Add a new Application Definition.	 * both in ApplicationsRegistry and in Persistance	 * 	 * @param ApplicationBean the app Definition	 * @return false on error	 */	public boolean addDefinition(ApplicationBean app) 	throws JahiaException {				checkIsLoaded();				if ( app == null ){			return false;		}		ServicesRegistry.getInstance()						.getJahiaApplicationsPersistanceService()						.add_application(app);					registry.put(new Integer(app.getID()),app);		return true;	}	//--------------------------------------------------------------------------	/***	 * Save the Application Definition.	 * both in ApplicationsRegistry and in Persistance	 * 	 * @param ApplicationBean the app Definition	 * @return false on error	 */	public boolean saveDefinition(ApplicationBean app) 	throws JahiaException {				checkIsLoaded();				if ( app == null ){			return false;		}		ServicesRegistry.getInstance()						.getJahiaApplicationsPersistanceService()						.update_application(app);					registry.put(new Integer(app.getID()),app);		return true;	}	//--------------------------------------------------------------------------    /**     * Removes an application from the persistant storage area and from registry.     *     * @param appID identifier of the application to remove from the persistant     * storage area     * @exception generated if there was an error while removing the application     * data from persistant storage area     */    public void removeApplication ( int appID )    throws JahiaException{    	    	checkIsLoaded();		ServicesRegistry.getInstance()						.getJahiaApplicationsPersistanceService()						.removeApplication(appID);					registry.remove(new Integer(appID));    }	//--------------------------------------------------------------------------	/**	 * delete groups associated with an application.	 * When deleting an Application definition, should call this method to	 * remove unused groups	 *	 **/	public void deleteApplicationGroups(ApplicationBean app) 	throws JahiaException {		checkIsLoaded();				Vector vec = new Vector();				vec = ServicesRegistry.getInstance()						.getJahiaGroupManagerService()						.getGroupnameList();		if ( app != null && vec != null ){						int appID = app.getID();			int size = vec.size();			JahiaGroup grp = null;			String grpName = "";			String pattern = appID + "_";			for ( int i=0 ; i<size ; i++ ){				grpName = (String)vec.get(i);				if ( grpName.startsWith(pattern) ){					grp = ServicesRegistry.getInstance()									.getJahiaGroupManagerService()									.lookupGroup(grpName);					if ( grp != null ){						ServicesRegistry.getInstance()									.getJahiaGroupManagerService()									.deleteGroup(grp);					}													}			}		}	}	//--------------------------------------------------------------------------	/**	 * create groups for each context, that is for each field id	 *	 */    public void createApplicationGroups( ApplicationBean theApp, JahiaField theField)    throws JahiaException {       	//System.out.println("create_application_groups started");		// update roles		ApplicationContext appContext = ServicesRegistry.getInstance()														.getJahiaApplicationContextService()														.getApplicationContext(theApp.getID());		Enumeration updatedRoles = appContext.getRoles().elements();        String groupName = "";        String role = "";        while (updatedRoles.hasMoreElements()) {	        role = (String) updatedRoles.nextElement();      		groupName = Integer.toString(theApp.getID()) + "_" + Integer.toString(theField.getID()) + "_" + role;			ServicesRegistry.getInstance().getJahiaGroupManagerService().createGroup( 0, groupName , null); // Hollis all app role groups are of site 0 !!!       }    }	//--------------------------------------------------------------------------	/**	 * delete groups associated with a gived context, that is attached to a field id	 * and all its members	 */    public void deleteApplicationGroups( ApplicationBean theApp, JahiaField theField )    throws JahiaException {       	//System.out.println("delete_application_groups started");		ApplicationContext appContext = ServicesRegistry.getInstance()														.getJahiaApplicationContextService()														.getApplicationContext(theApp.getID());		Enumeration roles = appContext.getRoles().elements();        String groupName = "";        String role = "";        while (roles.hasMoreElements()) {	        role = (String) roles.nextElement();      		groupName = Integer.toString(theApp.getID()) + "_" + Integer.toString(theField.getID()) + "_" + role;       		JahiaGroup grp = ServicesRegistry.getInstance().getJahiaGroupManagerService().lookupGroup (0, groupName); // Hollis : All App group roles are in site 0 !!!						// delete all members			grp.removeMembers();						ServicesRegistry.getInstance().getJahiaGroupManagerService().deleteGroup( grp );        }    }    //--------------------------------------------------------------------------	/**	 * return a DOM document of applications definitions	 *	 * @param int the site id	 *	 * @return JahiaDOMObject a DOM representation of this object	 *	 * @author NK	 */	public JahiaDOMObject getApplicationDefsAsDOM( int siteID )	throws JahiaException 	{		return ServicesRegistry.getInstance()							.getJahiaApplicationsPersistanceService()							.getApplicationDefsAsDOM(siteID);	}		//--------------------------------------------------------------------------	/***	 * load all application Definitions in registry     *      */    private void loadAllApplications()    throws JahiaException {    			synchronized ( registry ) 		{			Vector apps = ServicesRegistry.getInstance()							.getJahiaApplicationsPersistanceService()							.get_applications_list(false);			if ( apps != null )			{				ApplicationBean app = null;				int size = apps.size();				for ( int i=0 ; i<size; i++ )				{					app = (ApplicationBean)apps.get(i);					Integer I = new Integer(app.getID());					registry.put(I,app);				}			}		}	}	//--------------------------------------------------------------------------	/**	 * throw an exception if the service hasn't been loaded successfully	 *	 */	private void checkIsLoaded() throws JahiaException {				if ( !isLoaded ){	            throw new JahiaException(   "Error accessing a service that was not initialized successfully",                                        "Error accessing a service that was not initialized successfully",                                         JahiaException.SERVICE_ERROR, JahiaException.CRITICAL );		}			}} // end JahiaApplicationsService

⌨️ 快捷键说明

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