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

📄 engineresourcebundletag.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
package org.jahia.taglibs.resourcebundle;import java.util.Locale;import java.util.ResourceBundle;import org.jahia.data.JahiaData;import org.jahia.params.ParamBean;import org.jahia.exceptions.JahiaException;import org.jahia.utils.JahiaTools;import org.jahia.utils.JahiaConsole;import org.jahia.resourcebundle.JahiaResourceBundle;import java.io.*;import java.util.*;import javax.servlet.http.*;import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;/** * Support for Engine's ResourceBundle within Jahia * * Returns the requested resource. * * If the requested resource bundle is missing and useDefault is true, * Jahia will look for another engine resource bundle in that order : * *		1. 	Look for the engine resource bundle of the page. *			This resource bundle can be set in the template used by the page *			with the SetEngineResourceBundleTag. *	 *		2.  Look for the site's default engine resource bundle. *  	    Each site can have a default engine resource bundle. It's name *			must be of this form : "JahiaEnginesResourcesMYJAHIASITE" *			where MYJAHIASITE is the virtual site's sitekey in uppercase. * *		3.  Finally if none of the previous resource bundle are available, *			Jahia will return the internal engine's default resource bundle *			named "JahiaEnginesResources". * *	 * @see JahiaResourceBundle * @see SetEngineResourceBundleTag * @see JahiaEnginesResources.properties * * @author Khue Nguyen */public class EngineResourceBundleTag extends TagSupport {	private static final String CLASS_NAME = EngineResourceBundleTag.class.getName();    public static final String JAHIA_ENGINE_TAG 				= "<jahiaEngine>";    public static final String SITE_TEMPLATE_TAG 				= "<siteTemplate>";	    private String resourceName   = "";	    public void setResourceName(String resourceName) {    	if ( resourceName == null )    		resourceName = "";        this.resourceName = resourceName;    }    public int doStartTag() {		HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();		JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData");		if (jData == null) {			HashMap tempEngineMap = (HashMap) request.getAttribute("org.jahia.engines.EngineHashMap");			jData                 = (JahiaData) tempEngineMap.get("jData");		}				String resValue = null;		try {			resValue = JahiaResourceBundle						.getEngineResource(  resourceName,										 	 jData.params(),										 	 jData.params().getLocale() );										 		} catch ( MissingResourceException mre ) {					    JahiaConsole.println(CLASS_NAME+"doStartTag", mre.toString());    	}        if (resValue == null) {        	resValue = "";        }		try {		    JspWriter out = pageContext.getOut();		    out.print( parseResourceValue(resValue,jData.params()) );		} catch (IOException ioe) {		    JahiaConsole.println(CLASS_NAME+"doStartTag", ioe.toString());		}	    return SKIP_BODY;    }        //--------------------------------------------------------------------------    /**     * parse the resource value and replace :	 * <jahiaEngine> 	: by /jsp/jahia/engines/	 * <siteTemplate>	: by /jsp/jahia/templates/<mysite>/	 *					  where <mysite> is the sitekey of the current site	 *     * @param String val, the String to parse     * @param ParamBean, the paramBean     * @return String , the parsed value     */    public static String parseResourceValue(String val,ParamBean jParams){     	    	if ( (val == null) || (jParams == null) || (jParams.getSite()== null) )    		return val;				val = JahiaTools.replacePattern(val,JAHIA_ENGINE_TAG,														 "/jsp/jahia/engines/");				val = JahiaTools.replacePattern(val,SITE_TEMPLATE_TAG,				"/jsp/jahia/templates/" + jParams.getSite().getSiteKey() + "/");				return val;            }	    }

⌨️ 快捷键说明

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