001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.taglib.util;
022:
023: import com.liferay.portal.kernel.log.Log;
024: import com.liferay.portal.kernel.log.LogFactoryUtil;
025: import com.liferay.portal.kernel.log.LogUtil;
026: import com.liferay.portal.kernel.servlet.StringServletResponse;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.portal.model.Theme;
029: import com.liferay.portal.util.WebKeys;
030:
031: import javax.servlet.RequestDispatcher;
032: import javax.servlet.ServletContext;
033: import javax.servlet.http.HttpServletRequest;
034: import javax.servlet.jsp.JspException;
035:
036: /**
037: * <a href="IncludeTag.java.html"><b><i>View Source</i></b></a>
038: *
039: * @author Brian Wing Shun Chan
040: *
041: */
042: public class IncludeTag extends ParamAncestorTagImpl {
043:
044: public int doEndTag() throws JspException {
045: HttpServletRequest req = null;
046:
047: try {
048: ServletContext ctx = getServletContext();
049: req = getServletRequest();
050: StringServletResponse res = getServletResponse();
051:
052: Theme theme = (Theme) req.getAttribute(WebKeys.THEME);
053:
054: String page = getPage();
055:
056: if (isTheme()) {
057: ThemeUtil.include(ctx, req, res, pageContext, page,
058: theme);
059: } else {
060: RequestDispatcher rd = ctx.getRequestDispatcher(page);
061:
062: rd.include(req, res);
063: }
064:
065: pageContext.getOut().print(res.getString());
066:
067: return EVAL_PAGE;
068: } catch (Exception e) {
069: if (req != null) {
070: String currentURL = (String) req
071: .getAttribute(WebKeys.CURRENT_URL);
072:
073: _log.error("Current URL " + currentURL
074: + " generates exception: " + e.getMessage());
075: }
076:
077: LogUtil.log(_log, e);
078:
079: return EVAL_PAGE;
080: } finally {
081: clearParams();
082: }
083: }
084:
085: public boolean isTheme() {
086: return false;
087: }
088:
089: public String getPage() {
090: if (Validator.isNull(_page)) {
091: return getDefaultPage();
092: } else {
093: return _page;
094: }
095: }
096:
097: public void setPage(String page) {
098: _page = page;
099: }
100:
101: protected String getDefaultPage() {
102: return null;
103: }
104:
105: private static Log _log = LogFactoryUtil.getLog(IncludeTag.class);
106:
107: private String _page;
108:
109: }
|