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

📄 jahiaapplicationcontextbaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//////////  NK      18.06.2002////package org.jahia.services.applications;import java.io.*;import java.text.*;import java.util.*;import javax.servlet.*;					            // ServletExceptionimport javax.servlet.http.*;			            // HttpServletRequest, HttpSerlvetResponseimport javax.xml.parsers.SAXParser;import org.xml.sax.helpers.ParserAdapter;import org.xml.sax.EntityResolver;import org.jahia.data.webapps.*;      	// JahiaWebAppsDefimport org.jahia.data.applications.*; 	// ApplicationBeanimport org.jahia.utils.*;       		// JahiaConsoleimport org.jahia.utils.xml.*;      		// DtdEntityResolverimport org.jahia.exceptions.*;  		// JahiaExceptionimport org.jahia.services.*;    		// JahiaServiceimport org.jahia.registries.*;        	// ServicesRegistryimport org.jahia.settings.*;          	// JahiaPrivateSettings/** * Application context manager service. * * @author Khue Nguyen <a href="mailto:khue@jahia.com">khue@jahia.com</a> * @version 1.0 */public class JahiaApplicationContextBaseService extends JahiaApplicationContextService {    private static final String CLASS_NAME = JahiaApplicationContextBaseService.class.getName();    /** the DTD Entity Resolver we use with local dtd files **/    private static EntityResolver mResolver ;    /** The web.xml file **/    private static final String WEB_XML_FILE = "/WEB-INF/web.xml";	/** the instance **/	private static JahiaApplicationContextBaseService mInstance = null;	/** the cache of application context beans **/	private Hashtable mRegistry = new Hashtable();    /** The Server ServerContext **/    private ServletContext mContext;	//--------------------------------------------------------------------------	/**	 * constructor	 *	 */	protected JahiaApplicationContextBaseService(){    	JahiaConsole.println( "JahiaApplicationContextBaseService",       	"***** Starting the Jahia Application Context Manager Base Service *****" );	}	//--------------------------------------------------------------------------	/**	 * return the singleton instance	 */	public static synchronized JahiaApplicationContextBaseService getInstance(){				if ( mInstance == null ){			mInstance = new JahiaApplicationContextBaseService();		}				return mInstance;	}		//--------------------------------------------------------------------------    /***     * Services initializations     *     * @param JahiaPrivateSettings jSettings     */    public void init( JahiaPrivateSettings jSettings )    throws JahiaInitializationException    {        if (!isInitialized ()) {			mContext				= jSettings.context;            mResolver 				= (EntityResolver)jSettings.getDtdEntityResolver();            mIsServiceInitialized = true;        }    }	//--------------------------------------------------------------------------	/**	 * Get an ApplicationContext for a given application id	 *	 * @param id , the application id	 * @return the application context , null if not found	 */	public ApplicationContext getApplicationContext(int id) 	throws JahiaException {	    JahiaConsole.println("JahiaApplicationContextBaseService.getApplicationContext",	                         "Requested application : [" + id +"]" );				ApplicationBean appBean = ServicesRegistry.getInstance()													.getJahiaApplicationsManagerService()													.getApplication(id);		if ( appBean == null ){			String errMsg = "Error getting application bean for application [" + id + "]";		    JahiaConsole.println("JahiaApplicationContextBaseService",errMsg);           	throw new JahiaException(errMsg,errMsg,                                    JahiaException.ERROR,                                    JahiaException.APPLICATION_ERROR);		}				return getApplicationContext(appBean.getContext());	}	//--------------------------------------------------------------------------	/**	 * Get an ApplicationContext for a given context	 *	 * @param context , the context	 * @return the application context , null if not found	 */	public ApplicationContext getApplicationContext(String context) 	throws JahiaException {	    JahiaConsole.println("JahiaApplicationContextBaseService.getApplicationContext",	                         "Requested for context : " + context );				if ( context == null ){			return null;		}		ApplicationContext appContext = null;		synchronized ( mRegistry ){			appContext = (ApplicationContext)mRegistry.get(context);						if ( appContext == null ){				// try to load from disk				appContext = loadContextInfoFromDisk(context);			}			if ( appContext == null ){				// create a fake Application Context to avoid loading from disk the next time.				appContext = new ApplicationContext(context);                     			}			mRegistry.put(context,appContext);		}		return appContext;	}	//--------------------------------------------------------------------------	/**	 * Returns a ApplicationContext bean with the information loaded from the web.xml	 * file of a given context	 *	 * @param context , the context	 * @return an ApplicationContext or null on error	 */	private ApplicationContext loadContextInfoFromDisk( String context ) throws JahiaException {		ServletContext dispatchedContext = mContext.getContext(context);    		if (dispatchedContext == null) {		    JahiaConsole.println("JahiaApplicationContextBaseService",		                        "Error getting dispatch context [" +		                         context + "]");           throw new JahiaException("Can't access context " +                                    context,                                    "Error getting request context " + context,                                    JahiaException.ERROR,                                    JahiaException.APPLICATION_ERROR);		}					String path = dispatchedContext.getRealPath(WEB_XML_FILE);		            			JahiaConsole.println("JahiaApplicationContextBaseService",		                 		 "dispatched context real Path :  " + path );				// extract data from the web.xml file		ApplicationContext appContext = null;		Web_App_Xml webXmlDoc = new Web_App_Xml(path);		webXmlDoc.extractDocumentData();						appContext = new ApplicationContext( context,											 webXmlDoc.getDisplayName(),											 webXmlDoc.getdesc(),											 new Vector(),											 webXmlDoc.getServletMappings(),											 new Vector(),											 webXmlDoc.getWelcomeFiles() );		Vector servlets = webXmlDoc.getServlets();		Servlet_Element servlet = null;		ServletBean servletBean = null;		for ( int i=0 ; i<servlets.size(); i++ ){			servlet = (Servlet_Element)servlets.get(i);						            servletBean = new ServletBean(                                            servlet.getType(),                                            servlet.getDisplayName(),                                            servlet.getName(),                                            servlet.getSource(),                                            context,                                            servlet.getdesc()                                         );        	appContext.addServlet(servletBean);                            		}		Vector roles = webXmlDoc.getRoles();		Security_Role role = null;		for ( int i=0 ; i<roles.size(); i++ ){			role = (Security_Role)roles.get(i);						        	appContext.addRole(role.getName());                            		}											 		return appContext;	}}

⌨️ 快捷键说明

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