亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? freemarkerview.java

?? spring framework 2.5.4源代碼
?? JAVA
字號(hào):
/*
 * Copyright 2002-2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.web.servlet.view.freemarker;

import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;

import javax.servlet.GenericServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import freemarker.core.ParseException;
import freemarker.ext.jsp.TaglibFactory;
import freemarker.ext.servlet.FreemarkerServlet;
import freemarker.ext.servlet.HttpRequestHashModel;
import freemarker.ext.servlet.HttpRequestParametersHashModel;
import freemarker.ext.servlet.HttpSessionHashModel;
import freemarker.ext.servlet.ServletContextHashModel;
import freemarker.template.Configuration;
import freemarker.template.ObjectWrapper;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContextException;
import org.springframework.web.servlet.support.RequestContextUtils;
import org.springframework.web.servlet.view.AbstractTemplateView;

/**
 * View using the FreeMarker template engine.
 *
 * <p>Exposes the following JavaBean properties:
 * <ul>
 * <li><b>url</b>: the location of the FreeMarker template to be wrapped,
 * relative to the FreeMarker template context (directory).
 * <li><b>encoding</b> (optional, default is determined by FreeMarker configuration):
 * the encoding of the FreeMarker template file
 * </ul>
 *
 * <p>Depends on a single {@link FreeMarkerConfig} object such as {@link FreeMarkerConfigurer}
 * being accessible in the current web application context, with any bean name.
 * Alternatively, you can set the FreeMarker {@link Configuration} object as bean property.
 * See {@link #setConfiguration} for more details on the impacts of this approach.
 *
 * <p>Note: Spring's FreeMarker support requires FreeMarker 2.3 or higher.
 *
 * @author Darren Davison
 * @author Juergen Hoeller
 * @since 03.03.2004
 * @see #setUrl
 * @see #setExposeSpringMacroHelpers
 * @see #setEncoding
 * @see #setConfiguration
 * @see FreeMarkerConfig
 * @see FreeMarkerConfigurer
 */
public class FreeMarkerView extends AbstractTemplateView {

	private String encoding;

	private Configuration configuration;

	private TaglibFactory taglibFactory;

	private ServletContextHashModel servletContextHashModel;


	/**
	 * Set the encoding of the FreeMarker template file. Default is determined
	 * by the FreeMarker Configuration: "ISO-8859-1" if not specified otherwise.
	 * <p>Specify the encoding in the FreeMarker Configuration rather than per
	 * template if all your templates share a common encoding.
	 */
	public void setEncoding(String encoding) {
		this.encoding = encoding;
	}

	/**
	 * Return the encoding for the FreeMarker template.
	 */
	protected String getEncoding() {
		return this.encoding;
	}

	/**
	 * Set the FreeMarker Configuration to be used by this view.
	 * If this is not set, the default lookup will occur: a single {@link FreeMarkerConfig}
	 * is expected in the current web application context, with any bean name.
	 * <strong>Note:</strong> using this method will cause a new instance of {@link TaglibFactory}
	 * to created for every single {@link FreeMarkerView} instance. This can be quite expensive
	 * in terms of memory and initial CPU usage. In production it is recommended that you use
	 * a {@link FreeMarkerConfig} which exposes a single shared {@link TaglibFactory}.
	 */
	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}

	/**
	 * Return the FreeMarker configuration used by this view.
	 */
	protected Configuration getConfiguration() {
		return this.configuration;
	}


	/**
	 * Invoked on startup. Looks for a single FreeMarkerConfig bean to
	 * find the relevant Configuration for this factory.
	 * <p>Checks that the template for the default Locale can be found:
	 * FreeMarker will check non-Locale-specific templates if a
	 * locale-specific one is not found.
	 * @see freemarker.cache.TemplateCache#getTemplate
	 */
	protected void initApplicationContext() throws BeansException {
		super.initApplicationContext();

		if (getConfiguration() != null) {
			this.taglibFactory = new TaglibFactory(getServletContext());
		}
		else {
			FreeMarkerConfig config = autodetectConfiguration();
			setConfiguration(config.getConfiguration());
			this.taglibFactory = config.getTaglibFactory();
		}

		GenericServlet servlet = new GenericServletAdapter();
		try {
			servlet.init(new DelegatingServletConfig());
		}
		catch (ServletException ex) {
			throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
		}
		this.servletContextHashModel = new ServletContextHashModel(servlet, getObjectWrapper());

		checkTemplate();
	}

	/**
	 * Autodetect a {@link FreeMarkerConfig} object via the ApplicationContext.
	 * @return the Configuration instance to use for FreeMarkerViews
	 * @throws BeansException if no Configuration instance could be found
	 * @see #getApplicationContext
	 * @see #setConfiguration
	 */
	protected FreeMarkerConfig autodetectConfiguration() throws BeansException {
		try {
			return (FreeMarkerConfig) BeanFactoryUtils.beanOfTypeIncludingAncestors(
					getApplicationContext(), FreeMarkerConfig.class, true, false);
		}
		catch (NoSuchBeanDefinitionException ex) {
			throw new ApplicationContextException(
					"Must define a single FreeMarkerConfig bean in this web application context " +
					"(may be inherited): FreeMarkerConfigurer is the usual implementation. " +
					"This bean may be given any name.", ex);
		}
	}

	/**
	 * Return the configured FreeMarker {@link ObjectWrapper}, or the
	 * {@link ObjectWrapper#DEFAULT_WRAPPER default wrapper} if none specified.
	 * @see freemarker.template.Configuration#getObjectWrapper()
	 */
	protected ObjectWrapper getObjectWrapper() {
		ObjectWrapper ow = getConfiguration().getObjectWrapper();
		return (ow != null ? ow : ObjectWrapper.DEFAULT_WRAPPER);
	}

	/**
	 * Check that the FreeMarker template used for this view exists and is valid.
	 * <p>Can be overridden to customize the behavior, for example in case of
	 * multiple templates to be rendered into a single view.
	 * @throws ApplicationContextException if the template cannot be found or is invalid
	 */
	protected void checkTemplate() throws ApplicationContextException {
		try {
			// Check that we can get the template, even if we might subsequently get it again.
			getTemplate(getConfiguration().getLocale());
		}
		catch (ParseException ex) {
			throw new ApplicationContextException(
					"Failed to parse FreeMarker template for URL [" +  getUrl() + "]", ex);
		}
		catch (IOException ex) {
			throw new ApplicationContextException(
					"Could not load FreeMarker template for URL [" + getUrl() + "]", ex);
		}
	}


	/**
	 * Process the model map by merging it with the FreeMarker template.
	 * Output is directed to the servlet response.
	 * <p>This method can be overridden if custom behavior is needed.
	 */
	protected void renderMergedTemplateModel(
			Map model, HttpServletRequest request, HttpServletResponse response) throws Exception {

		exposeHelpers(model, request);
		doRender(model, request, response);
	}

	/**
	 * Expose helpers unique to each rendering operation. This is necessary so that
	 * different rendering operations can't overwrite each other's formats etc.
	 * <p>Called by <code>renderMergedTemplateModel</code>. The default implementation
	 * is empty. This method can be overridden to add custom helpers to the model.
	 * @param model The model that will be passed to the template at merge time
	 * @param request current HTTP request
	 * @throws Exception if there's a fatal error while we're adding information to the context
	 * @see #renderMergedTemplateModel
	 */
	protected void exposeHelpers(Map model, HttpServletRequest request) throws Exception {
	}

	/**
	 * Render the FreeMarker view to the given response, using the given model
	 * map which contains the complete template model to use.
	 * <p>The default implementation renders the template specified by the "url"
	 * bean property, retrieved via <code>getTemplate</code>. It delegates to the
	 * <code>processTemplate</code> method to merge the template instance with
	 * the given template model.
	 * <p>Adds the standard Freemarker hash models to the model: request parameters,
	 * request, session and application (ServletContext), as well as the JSP tag
	 * library hash model.
	 * <p>Can be overridden to customize the behavior, for example to render
	 * multiple templates into a single view.
	 * @param model the template model to use for rendering
	 * @param request current HTTP request
	 * @param response current servlet response
	 * @throws IOException if the template file could not be retrieved
	 * @throws Exception if rendering failed
	 * @see #setUrl
	 * @see org.springframework.web.servlet.support.RequestContextUtils#getLocale
	 * @see #getTemplate(java.util.Locale)
	 * @see #processTemplate
	 * @see freemarker.ext.servlet.FreemarkerServlet
	 */
	protected void doRender(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception {
		// Expose model to JSP tags (as request attributes).
		exposeModelAsRequestAttributes(model, request);

		// Expose all standard FreeMarker hash models.
		model.put(FreemarkerServlet.KEY_JSP_TAGLIBS, this.taglibFactory);
		model.put(FreemarkerServlet.KEY_APPLICATION, this.servletContextHashModel);
		model.put(FreemarkerServlet.KEY_SESSION, buildSessionModel(request, response));
		model.put(FreemarkerServlet.KEY_REQUEST, new HttpRequestHashModel(request, response, getObjectWrapper()));
		model.put(FreemarkerServlet.KEY_REQUEST_PARAMETERS, new HttpRequestParametersHashModel(request));

		if (logger.isDebugEnabled()) {
			logger.debug("Rendering FreeMarker template [" + getUrl() + "] in FreeMarkerView '" + getBeanName() + "'");
		}
		// Grab the locale-specific version of the template.
		Locale locale = RequestContextUtils.getLocale(request);
		processTemplate(getTemplate(locale), model, response);
	}

	/**
	 * Build a FreeMarker {@link HttpSessionHashModel} for the given request,
	 * detecting whether a session already exists and reacting accordingly.
	 * @param request current HTTP request
	 * @param response current servlet response
	 * @return the FreeMarker HttpSessionHashModel
	 */
	private HttpSessionHashModel buildSessionModel(HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession(false);
		if (session != null) {
			return new HttpSessionHashModel(session, getObjectWrapper());
		}
		else {
			return new HttpSessionHashModel(null, request, response, getObjectWrapper());
		}
	}

	/**
	 * Retrieve the FreeMarker template for the given locale,
	 * to be rendering by this view.
	 * <p>By default, the template specified by the "url" bean property
	 * will be retrieved.
	 * @param locale the current locale
	 * @return the FreeMarker template to render
	 * @throws IOException if the template file could not be retrieved
	 * @see #setUrl
	 * @see #getTemplate(String, java.util.Locale)
	 */
	protected Template getTemplate(Locale locale) throws IOException {
		return getTemplate(getUrl(), locale);
	}

	/**
	 * Retrieve the FreeMarker template specified by the given name,
	 * using the encoding specified by the "encoding" bean property.
	 * <p>Can be called by subclasses to retrieve a specific template,
	 * for example to render multiple templates into a single view.
	 * @param name the file name of the desired template
	 * @param locale the current locale
	 * @return the FreeMarker template
	 * @throws IOException if the template file could not be retrieved
	 */
	protected Template getTemplate(String name, Locale locale) throws IOException {
		return (getEncoding() != null ?
				getConfiguration().getTemplate(name, locale, getEncoding()) :
				getConfiguration().getTemplate(name, locale));
	}

	/**
	 * Process the FreeMarker template to the servlet response.
	 * <p>Can be overridden to customize the behavior.
	 * @param template the template to process
	 * @param model the model for the template
	 * @param response servlet response (use this to get the OutputStream or Writer)
	 * @throws IOException if the template file could not be retrieved
	 * @throws TemplateException if thrown by FreeMarker
	 * @see freemarker.template.Template#process(Object, java.io.Writer)
	 */
	protected void processTemplate(Template template, Map model, HttpServletResponse response)
			throws IOException, TemplateException {

		template.process(model, response.getWriter());
	}


	/**
	 * Simple adapter class that extends {@link GenericServlet}.
	 * Needed for JSP access in FreeMarker.
	 */
	private static class GenericServletAdapter extends GenericServlet {

		public void service(ServletRequest servletRequest, ServletResponse servletResponse) {
			// no-op
		}
	}


	/**
	 * Internal implementation of the {@link ServletConfig} interface,
	 * to be passed to the servlet adapter.
	 */
	private class DelegatingServletConfig implements ServletConfig {

		public String getServletName() {
			return FreeMarkerView.this.getBeanName();
		}

		public ServletContext getServletContext() {
			return FreeMarkerView.this.getServletContext();
		}

		public String getInitParameter(String paramName) {
			return null;
		}

		public Enumeration getInitParameterNames() {
			return Collections.enumeration(Collections.EMPTY_SET);
		}
	}

}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本道色综合久久| 欧美婷婷六月丁香综合色| 国产精品免费丝袜| 欧美网站一区二区| 极品少妇xxxx偷拍精品少妇| 中文字幕人成不卡一区| 3atv在线一区二区三区| 国产aⅴ精品一区二区三区色成熟| 亚洲国产毛片aaaaa无费看| 国产午夜精品一区二区| 91麻豆精品国产无毒不卡在线观看| 懂色一区二区三区免费观看| 日韩不卡在线观看日韩不卡视频| 亚洲久草在线视频| 国产精品久久久久久久久图文区| 欧美成人高清电影在线| 欧美剧在线免费观看网站| 色婷婷av久久久久久久| 成人白浆超碰人人人人| 99久久精品免费观看| 国内精品在线播放| 精品一区中文字幕| 青青青伊人色综合久久| 午夜精品久久久久久久99樱桃| 亚洲欧美经典视频| 国产精品传媒视频| 国产精品免费免费| 国产三级精品三级| 久久精品视频免费| 久久久99精品久久| 久久精品一区蜜桃臀影院| 精品久久久久一区二区国产| 91麻豆精品国产| 欧美丰满美乳xxx高潮www| 91成人免费在线视频| 色综合天天综合色综合av | 国产精品国产三级国产aⅴ入口 | 午夜精品视频在线观看| 亚洲欧美日韩在线| 亚洲欧美另类小说视频| 亚洲老司机在线| 亚洲自拍偷拍综合| 亚洲第四色夜色| 日本在线不卡视频一二三区| 天天操天天色综合| 日本成人在线不卡视频| 男人的天堂亚洲一区| 毛片不卡一区二区| 国产精品91一区二区| 国产999精品久久| 99久久精品免费| 色诱视频网站一区| 8v天堂国产在线一区二区| 555www色欧美视频| 精品欧美乱码久久久久久 | 国产精品毛片无遮挡高清| 国产精品久久久久久久久搜平片| 亚洲欧美日韩精品久久久久| 亚洲国产va精品久久久不卡综合| 婷婷综合五月天| 国产一区二区三区精品欧美日韩一区二区三区| 韩国精品在线观看| 91视频你懂的| 7777精品伊人久久久大香线蕉的 | 成人av资源下载| a在线欧美一区| 欧美视频三区在线播放| 91精品综合久久久久久| 2欧美一区二区三区在线观看视频| 欧美国产禁国产网站cc| 亚洲男女一区二区三区| 三级欧美韩日大片在线看| 国产在线不卡一卡二卡三卡四卡| 国产不卡视频一区二区三区| 91国偷自产一区二区开放时间 | 欧美最猛性xxxxx直播| 91精品国产欧美一区二区| 国产视频不卡一区| 一区二区三区国产| 精品一区二区三区av| 97se亚洲国产综合在线| 欧美一区二区成人6969| 国产精品毛片高清在线完整版| 亚洲国产一区视频| 国产精品456| 这里只有精品99re| 亚洲三级视频在线观看| 久久97超碰色| 欧洲中文字幕精品| 久久久不卡影院| 亚洲一区二区三区小说| 国产在线国偷精品产拍免费yy| 99re这里都是精品| 久久蜜桃一区二区| 五月婷婷久久综合| 盗摄精品av一区二区三区| 欧美在线免费播放| 国产精品久久久久毛片软件| 久久99国产精品久久99果冻传媒| 99精品国产热久久91蜜凸| 日韩精品影音先锋| 亚洲一卡二卡三卡四卡五卡| 不卡一区中文字幕| 日韩精品一区二区三区四区| 亚洲精品久久嫩草网站秘色| 国产精品资源在线| 欧美丰满美乳xxx高潮www| 亚洲色图在线看| 国产一区二区视频在线| 欧美精品v国产精品v日韩精品| 中文字幕精品一区二区精品绿巨人| 全国精品久久少妇| 欧美婷婷六月丁香综合色| 国产精品萝li| 国产黄色精品视频| 51精品秘密在线观看| 亚洲一区免费视频| 94-欧美-setu| 国产精品伦一区| 国产精品亚洲第一区在线暖暖韩国 | 99国产一区二区三精品乱码| www成人在线观看| 黄网站免费久久| 精品国产区一区| 精品一区二区精品| 日韩一级完整毛片| 日日夜夜一区二区| 欧美自拍偷拍午夜视频| 亚洲天堂av一区| av电影一区二区| 国产人久久人人人人爽| 国产精品18久久久久久久久久久久 | 亚洲国产精品久久久久婷婷884 | 国产91富婆露脸刺激对白| 欧美精品一区二区不卡| 国产一区二区主播在线| 久久综合成人精品亚洲另类欧美| 狠狠色狠狠色综合| 国产区在线观看成人精品| 国产精品996| 综合在线观看色| 在线影院国内精品| 亚洲国产精品久久不卡毛片| 欧美日免费三级在线| 日韩av中文字幕一区二区三区| 欧美一区二区三区啪啪| 老司机免费视频一区二区三区| 精品人在线二区三区| 国产传媒日韩欧美成人| 中文字幕一区av| 欧美在线观看一二区| 蜜桃视频在线一区| 国产亚洲1区2区3区| 成人中文字幕电影| 亚洲精品videosex极品| 欧美日韩国产精品自在自线| 日本午夜精品一区二区三区电影| 精品国产乱码久久久久久久久| 国产精品自在在线| 亚洲欧美偷拍另类a∨色屁股| 在线免费亚洲电影| 日本视频免费一区| 久久精品亚洲一区二区三区浴池| a在线欧美一区| 石原莉奈在线亚洲三区| 久久久久久电影| av影院午夜一区| 视频一区二区三区在线| 久久夜色精品国产噜噜av| 97se亚洲国产综合在线| 男人的天堂亚洲一区| 国产精品女同一区二区三区| 欧美日韩一区三区| 国产精品影视在线观看| 亚洲最色的网站| 26uuu另类欧美| 欧美午夜免费电影| 激情久久五月天| 一区二区三区不卡在线观看| 欧美成人r级一区二区三区| 91在线视频观看| 黄页网站大全一区二区| 亚洲一区二区三区激情| xfplay精品久久| 欧美性xxxxx极品少妇| 国产乱码字幕精品高清av | 成人免费视频视频在线观看免费 | 久久国产尿小便嘘嘘| 伊人夜夜躁av伊人久久| 欧美精品一区二区不卡| 欧美日韩色综合| 成人在线视频首页| 麻豆精品一区二区三区| 亚洲日本va在线观看| 精品国产一二三| 欧美日韩国产系列| www.视频一区| 精品在线亚洲视频| 午夜久久久久久久久久一区二区| 国产精品人人做人人爽人人添 |