List of usage examples for javax.servlet.jsp JspFactory getDefaultFactory
public static JspFactory getDefaultFactory()
From source file:ro.raisercostin.web.DebuggingFilter.java
public String debug(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, DebuggingPrinter debuggingPrinter, boolean debugAll, boolean debugRequest) { final JspFactory jspFactory = JspFactory.getDefaultFactory(); HttpSession session = request.getSession(); debuggingPrinter.addHeader();/*from www . j a v a 2 s. c o m*/ debuggingPrinter.addSection("Request Parameters"); for (Iterator iterator = request.getParameterMap().entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> parameter = (Map.Entry<String, Object>) iterator.next(); addRow(debuggingPrinter, parameter.getKey(), StringUtils.arrayToCommaDelimitedString((Object[]) parameter.getValue())); } debuggingPrinter.endSection(); if (debugRequest) { debuggingPrinter.addSection("Request Header"); for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { String parameterName = (String) e.nextElement(); addRow(debuggingPrinter, parameterName, debuggingPrinter.transform(request.getHeader(parameterName))); } debuggingPrinter.endSection(); debuggingPrinter.addSection("Request Attributes"); java.util.Enumeration en = request.getAttributeNames(); while (en.hasMoreElements()) { String attrName = (String) en.nextElement(); try { addRow(debuggingPrinter, split(attrName, 50), toString2(request.getAttribute(attrName), 120)); } catch (Exception e) { addRow(debuggingPrinter, split(attrName, 50), toString(e, 120)); } } debuggingPrinter.endSection(); debuggingPrinter.addSection("Session Attributes"); en = session.getAttributeNames(); while (en.hasMoreElements()) { String attrName = (String) en.nextElement(); try { addRow(debuggingPrinter, split(attrName, 50), toString2(session.getAttribute(attrName), 120)); } catch (Exception e) { addRow(debuggingPrinter, split(attrName, 50), toString(e, 120)); } } debuggingPrinter.endSection(); debuggingPrinter.addSection("Request Info"); addRow(debuggingPrinter, "AuthType", request.getAuthType()); addRow(debuggingPrinter, "ContextPath", request.getContextPath()); addRow(debuggingPrinter, "Method", request.getMethod()); addRow(debuggingPrinter, "PathInfo", request.getPathInfo()); addRow(debuggingPrinter, "PathTranslated", request.getPathTranslated()); addRow(debuggingPrinter, "Protocol", request.getProtocol()); addRow(debuggingPrinter, "QueryString", request.getQueryString()); addRow(debuggingPrinter, "RemoteAddr", request.getRemoteAddr()); addRow(debuggingPrinter, "RemoteUser", request.getRemoteUser()); addRow(debuggingPrinter, "RequestedSessionId", request.getRequestedSessionId()); addRow(debuggingPrinter, "RequestURI", request.getRequestURI()); addRow(debuggingPrinter, "RequestURL", request.getRequestURL().toString()); addRow(debuggingPrinter, "ServletPath", request.getServletPath()); addRow(debuggingPrinter, "Scheme", request.getScheme()); addRow(debuggingPrinter, "ServletPath", request.getServletPath()); } if (debugAll) { debuggingPrinter.addSection("Server"); addRow(debuggingPrinter, "Server Info", servletContext.getServerInfo()); addRow(debuggingPrinter, "Servlet Engine Version", servletContext.getMajorVersion() + "." + servletContext.getMinorVersion()); addRow(debuggingPrinter, "JSP Version", jspFactory.getEngineInfo().getSpecificationVersion()); debuggingPrinter.endSection(); debuggingPrinter.addSection("JVM Properties"); for (Enumeration e = System.getProperties().propertyNames(); e.hasMoreElements();) { String parameterName = (String) e.nextElement(); addRow(debuggingPrinter, parameterName, debuggingPrinter.transform(System.getProperty(parameterName))); } debuggingPrinter.endSection(); debuggingPrinter.addSection("Environment"); for (Map.Entry<String, String> property : System.getenv().entrySet()) { addRow(debuggingPrinter, property.getKey(), debuggingPrinter.transform(property.getValue())); } debuggingPrinter.endSection(); debuggingPrinter.addSection("Debugger Provided by"); addRow(debuggingPrinter, "provided by", "raisercostin"); debuggingPrinter.addRow("source", "<a target='_blank' href='http://code.google.com/p/raisercostin/wiki/DebuggingFilter'>http://code.google.com/p/raisercostin/wiki/DebuggingFilter</a>"); addRow(debuggingPrinter, "version", "1.0"); addRow(debuggingPrinter, "timestamp", "2008.June.14"); addRow(debuggingPrinter, "license", "<a target='_blank' href='http://www.apache.org/licenses/LICENSE-2.0.html'>Apache License 2.0</a>"); debuggingPrinter.endSection(); } debuggingPrinter.addFooter(); return debuggingPrinter.getString(); }
From source file:freemarker.ext.jsp._FreeMarkerPageContext21.java
@Override public ELContext getELContext() { if (elContext == null) { JspApplicationContext jspctx = JspFactory.getDefaultFactory() .getJspApplicationContext(getServletContext()); if (jspctx instanceof FreeMarkerJspApplicationContext) { elContext = ((FreeMarkerJspApplicationContext) jspctx).createNewELContext(this); elContext.putContext(JspContext.class, this); } else {//from w w w . j a v a 2 s . co m throw new UnsupportedOperationException( "Can not create an ELContext using a foreign JspApplicationContext (of class " + ClassUtil.getShortClassNameOfObject(jspctx) + ").\n" + "Hint: The cause of this is often that you are trying to use JSTL tags/functions in FTL. " + "In that case, know that that's not really suppored, and you are supposed to use FTL " + "constrcuts instead, like #list instead of JSTL's forEach, etc."); } } return elContext; }
From source file:io.undertow.test.jsp.expression.ExpressionJspTestCase.java
public static void testIIllegalState(PageContext pageContext, JspWriter out) throws Exception { assert pageContext != null; ELContext elContext = pageContext.getELContext(); assert elContext != null; JspApplicationContext jaContext = JspFactory.getDefaultFactory() .getJspApplicationContext(pageContext.getServletContext()); assert jaContext != null; try {// ww w . j a va 2 s. c o m jaContext.addELResolver(new CompositeELResolver()); out.println("addELResolver call succeeded. Test FAILED."); } catch (IllegalStateException ise) { out.println("Test PASSED"); } }
From source file:org.apache.jsp.html.portlet.ext.ecommerce.admin.view_jsp.java
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { JspFactory _jspxFactory = null;// ww w.j a v a 2 s.c o m PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { _jspxFactory = JspFactory.getDefaultFactory(); response.setContentType("text/html; charset=UTF-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write('\n'); /** * Copyright (c) 2000-2006 Liferay, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ out.write('\n'); out.write('\n'); /** * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); // liferay-theme:defineObjects com.liferay.taglib.theme.DefineObjectsTag _jspx_th_liferay_002dtheme_005fdefineObjects_005f0 = (com.liferay.taglib.theme.DefineObjectsTag) _005fjspx_005ftagPool_005fliferay_002dtheme_005fdefineObjects_005fnobody .get(com.liferay.taglib.theme.DefineObjectsTag.class); _jspx_th_liferay_002dtheme_005fdefineObjects_005f0.setPageContext(_jspx_page_context); _jspx_th_liferay_002dtheme_005fdefineObjects_005f0.setParent(null); int _jspx_eval_liferay_002dtheme_005fdefineObjects_005f0 = _jspx_th_liferay_002dtheme_005fdefineObjects_005f0 .doStartTag(); if (_jspx_th_liferay_002dtheme_005fdefineObjects_005f0 .doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) { _005fjspx_005ftagPool_005fliferay_002dtheme_005fdefineObjects_005fnobody .reuse(_jspx_th_liferay_002dtheme_005fdefineObjects_005f0); return; } _005fjspx_005ftagPool_005fliferay_002dtheme_005fdefineObjects_005fnobody .reuse(_jspx_th_liferay_002dtheme_005fdefineObjects_005f0); com.liferay.portal.theme.ThemeDisplay themeDisplay = null; com.liferay.portal.model.Company company = null; com.liferay.portal.model.Account account = null; com.liferay.portal.model.User user = null; com.liferay.portal.model.User realUser = null; com.liferay.portal.model.Contact contact = null; com.liferay.portal.model.Layout layout = null; java.util.List layouts = null; java.lang.Long plid = null; com.liferay.portal.model.LayoutTypePortlet layoutTypePortlet = null; java.lang.Long portletGroupId = null; com.liferay.portal.kernel.security.permission.PermissionChecker permissionChecker = null; java.util.Locale locale = null; java.util.TimeZone timeZone = null; com.liferay.portal.model.Theme theme = null; com.liferay.portal.model.ColorScheme colorScheme = null; com.liferay.portal.theme.PortletDisplay portletDisplay = null; themeDisplay = (com.liferay.portal.theme.ThemeDisplay) _jspx_page_context.findAttribute("themeDisplay"); company = (com.liferay.portal.model.Company) _jspx_page_context.findAttribute("company"); account = (com.liferay.portal.model.Account) _jspx_page_context.findAttribute("account"); user = (com.liferay.portal.model.User) _jspx_page_context.findAttribute("user"); realUser = (com.liferay.portal.model.User) _jspx_page_context.findAttribute("realUser"); contact = (com.liferay.portal.model.Contact) _jspx_page_context.findAttribute("contact"); layout = (com.liferay.portal.model.Layout) _jspx_page_context.findAttribute("layout"); layouts = (java.util.List) _jspx_page_context.findAttribute("layouts"); plid = (java.lang.Long) _jspx_page_context.findAttribute("plid"); layoutTypePortlet = (com.liferay.portal.model.LayoutTypePortlet) _jspx_page_context .findAttribute("layoutTypePortlet"); portletGroupId = (java.lang.Long) _jspx_page_context.findAttribute("portletGroupId"); permissionChecker = (com.liferay.portal.kernel.security.permission.PermissionChecker) _jspx_page_context .findAttribute("permissionChecker"); locale = (java.util.Locale) _jspx_page_context.findAttribute("locale"); timeZone = (java.util.TimeZone) _jspx_page_context.findAttribute("timeZone"); theme = (com.liferay.portal.model.Theme) _jspx_page_context.findAttribute("theme"); colorScheme = (com.liferay.portal.model.ColorScheme) _jspx_page_context.findAttribute("colorScheme"); portletDisplay = (com.liferay.portal.theme.PortletDisplay) _jspx_page_context .findAttribute("portletDisplay"); out.write("\r\n"); out.write("\r\n"); /** * Copyright (c) 2000-2006 Liferay, LLC. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); //@ page import="com.liferay.portal.kernel.util.PortletExtKeys" out.write("\r\n"); out.write("\r\n"); String contextPath = PropsUtil.get(PropsUtil.PORTAL_CTX); if (contextPath.equals("/")) { contextPath = ""; } out.write('\r'); out.write('\n'); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write('\n'); out.write('\n'); // portlet:defineObjects com.liferay.taglib.portlet.DefineObjectsTag _jspx_th_portlet_005fdefineObjects_005f0 = (com.liferay.taglib.portlet.DefineObjectsTag) _005fjspx_005ftagPool_005fportlet_005fdefineObjects_005fnobody .get(com.liferay.taglib.portlet.DefineObjectsTag.class); _jspx_th_portlet_005fdefineObjects_005f0.setPageContext(_jspx_page_context); _jspx_th_portlet_005fdefineObjects_005f0.setParent(null); int _jspx_eval_portlet_005fdefineObjects_005f0 = _jspx_th_portlet_005fdefineObjects_005f0.doStartTag(); if (_jspx_th_portlet_005fdefineObjects_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) { _005fjspx_005ftagPool_005fportlet_005fdefineObjects_005fnobody .reuse(_jspx_th_portlet_005fdefineObjects_005f0); return; } _005fjspx_005ftagPool_005fportlet_005fdefineObjects_005fnobody .reuse(_jspx_th_portlet_005fdefineObjects_005f0); javax.portlet.PortletConfig portletConfig = null; java.lang.String portletName = null; javax.portlet.PortletPreferences portletPreferences = null; javax.portlet.PortletSession portletSession = null; javax.portlet.RenderRequest renderRequest = null; javax.portlet.RenderResponse renderResponse = null; portletConfig = (javax.portlet.PortletConfig) _jspx_page_context.findAttribute("portletConfig"); portletName = (java.lang.String) _jspx_page_context.findAttribute("portletName"); portletPreferences = (javax.portlet.PortletPreferences) _jspx_page_context .findAttribute("portletPreferences"); portletSession = (javax.portlet.PortletSession) _jspx_page_context.findAttribute("portletSession"); renderRequest = (javax.portlet.RenderRequest) _jspx_page_context.findAttribute("renderRequest"); renderResponse = (javax.portlet.RenderResponse) _jspx_page_context.findAttribute("renderResponse"); out.write('\n'); out.write('\n'); PortletURL currentURLObj = PortletURLUtil.getCurrent(renderRequest, renderResponse); //String currentURL = currentURLObj.toString(); String currentURL = PortalUtil.getCurrentURL(request); out.write('\n'); out.write('\n'); /** * Copyright (c) 2000-2006 Liferay, LLC. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); String defLang = com.liferay.portal.util.PropsUtil.get("locale.default"); //String redirect = (String)request.getParameter("redirect"); PortletRequest portletRequest = (PortletRequest) request .getAttribute(com.liferay.portal.kernel.util.JavaConstants.JAVAX_PORTLET_REQUEST); String portletID = null; if (portletRequest instanceof RenderRequest) { RenderRequestImpl req = (RenderRequestImpl) portletRequest; portletID = req.getPortletName(); } else { ActionRequestImpl req = (ActionRequestImpl) portletRequest; portletID = req.getPortletName(); } boolean managetopic = true; Boolean managetopics = (Boolean) request.getAttribute("managetopics"); if (managetopics != null) { managetopic = managetopics.booleanValue(); } else { String isTopicPermissions = GetterUtil.getString(PropsUtil.get("gn.topics.permissions"), "off"); int isTopics = 0; if (request.getAttribute("isTopics") != null) isTopics = ((Integer) request.getAttribute("isTopics")).intValue(); String topicid = (String) request.getParameter("topicid"); if (isTopicPermissions.equals("on") && isTopics != GnPortletSetting.TOPICS_ENABLED_FALSE) { if (topicid != null && !topicid.equals("") && !com.ext.portlet.topics.service.permission.GnTopicPermission.contains( permissionChecker, new Integer(topicid), com.liferay.portal.kernel.security.permission.ActionExtKeys.MANAGECONTENT)) managetopic = false; } } out.write('\n'); out.write('\n'); boolean hasAdmin = PortletPermissionUtil.contains(permissionChecker, plid, portletID, ActionExtKeys.ADMINISTRATE) && managetopic; boolean hasPublish = PermissionsService.getInstance() .isPortletPublishingEnabled(PortalUtil.getCompanyId(request), portletID) && PortletPermissionUtil.contains(permissionChecker, plid, portletID, ActionExtKeys.PUBLISH) && managetopic; boolean hasViewUnPublished = hasPublish; //PermissionsService.getInstance().isPortletPublishingEnabled(portletID) && PortletPermission.contains(permissionChecker, plid, portletID, ActionExtKeys.VIEW_UNPUBLISHED) && managetopic; boolean hasAdd = PortletPermissionUtil.contains(permissionChecker, plid, portletID, ActionExtKeys.ADD) && managetopic; boolean hasEdit = PortletPermissionUtil.contains(permissionChecker, plid, portletID, ActionExtKeys.EDIT) && managetopic; boolean hasDelete = PortletPermissionUtil.contains(permissionChecker, plid, portletID, ActionExtKeys.DELETE) && managetopic; out.write('\n'); out.write('\n'); out.write('\n'); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); PortletPreferences prefs = renderRequest.getPreferences(); String portletResource = ParamUtil.getString(request, "portletResource"); if (Validator.isNotNull(portletResource)) { prefs = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource, true, true); } int instanceTopicId = GetterUtil.getInteger(prefs.getValue("topic-id", StringPool.BLANK)); String instancePortletSearch = GetterUtil.getString(prefs.getValue("portlet-search", StringPool.BLANK)); String instancePortletBrowseType = GetterUtil .getString(prefs.getValue("browse-type", StringPool.BLANK)); String instancePortletListStyle = ParamUtil.getString(request, "listStyle", prefs.getValue("list-style", StringPool.BLANK)); String instancePortletTopicStyle = ParamUtil.getString(request, "topicStyle", prefs.getValue("topic-style", StringPool.BLANK)); String instancePortletShowRelContent = prefs.getValue("showRelContent", StringPool.BLANK); String instancePortletShowRelContentDescription = prefs.getValue("showRelContentDescription", StringPool.BLANK); com.ext.portlet.base.contentrel.ContentRelUtil relUtil = com.ext.portlet.base.contentrel.ContentRelUtil .getInstance(); String[] classNames = relUtil.getPortletClassNames(); String[] portletNames = relUtil.getPortletNames(); String instanceYearsStartYear = GetterUtil .getString(prefs.getValue("years_startYear", StringPool.BLANK)); boolean instanceYearsShowFuture = GetterUtil.getBoolean(prefs.getValue("years_showFuture", "true"), true); boolean instanceYearsShowEmptyYears = GetterUtil .getBoolean(prefs.getValue("years_showEmptyYears", "true"), true); boolean topicsOnOff = GetterUtil.getBoolean(prefs.getValue("topicsOnOff", "false"), false); String topicFieldSetkey = GetterUtil.getString(prefs.getValue("topicFieldSetkey", StringPool.BLANK)); String instanceUseTopicNav = GetterUtil.getString(prefs.getValue("use-topic-nav", "no")); boolean enableRatings = GetterUtil.getBoolean(prefs.getValue("enableRatings", StringPool.BLANK), false); boolean enableComments = GetterUtil.getBoolean(prefs.getValue("enableComments", StringPool.BLANK), false); String instanceEmbedMedia = GetterUtil.getString(prefs.getValue("embed_media", "no")); String instanceRelEmbedMedia = GetterUtil.getString(prefs.getValue("embed_rel_media", "no")); boolean showOnlyMine = GetterUtil.getBoolean(prefs.getValue("showOnlyMine", StringPool.BLANK), false); boolean notifyPublisher = GetterUtil.getBoolean(prefs.getValue("notifyPublisher", StringPool.BLANK), false); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); // portlet:defineObjects com.liferay.taglib.portlet.DefineObjectsTag _jspx_th_portlet_005fdefineObjects_005f1 = (com.liferay.taglib.portlet.DefineObjectsTag) _005fjspx_005ftagPool_005fportlet_005fdefineObjects_005fnobody .get(com.liferay.taglib.portlet.DefineObjectsTag.class); _jspx_th_portlet_005fdefineObjects_005f1.setPageContext(_jspx_page_context); _jspx_th_portlet_005fdefineObjects_005f1.setParent(null); int _jspx_eval_portlet_005fdefineObjects_005f1 = _jspx_th_portlet_005fdefineObjects_005f1.doStartTag(); if (_jspx_th_portlet_005fdefineObjects_005f1.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) { _005fjspx_005ftagPool_005fportlet_005fdefineObjects_005fnobody .reuse(_jspx_th_portlet_005fdefineObjects_005f1); return; } _005fjspx_005ftagPool_005fportlet_005fdefineObjects_005fnobody .reuse(_jspx_th_portlet_005fdefineObjects_005f1); portletConfig = (javax.portlet.PortletConfig) _jspx_page_context.findAttribute("portletConfig"); portletName = (java.lang.String) _jspx_page_context.findAttribute("portletName"); portletPreferences = (javax.portlet.PortletPreferences) _jspx_page_context .findAttribute("portletPreferences"); portletSession = (javax.portlet.PortletSession) _jspx_page_context.findAttribute("portletSession"); renderRequest = (javax.portlet.RenderRequest) _jspx_page_context.findAttribute("renderRequest"); renderResponse = (javax.portlet.RenderResponse) _jspx_page_context.findAttribute("renderResponse"); out.write('\n'); out.write('\n'); String redirect = (String) request.getParameter("redirect"); long rootPlid1 = GetterUtil.getLong(prefs.getValue("root-plid", StringPool.BLANK)); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); String propertiesNamespace = GetterUtil.getString(prefs.getValue("propertiesNamespace", "eshop")); out.write("\r\n"); out.write("\r\n"); out.write("<form action=\""); if (_jspx_meth_portlet_005factionURL_005f0(_jspx_page_context)) return; out.write("\" method=\"post\" enctype=\"multipart/form-data\" >\r\n"); out.write("<table>\t\t\r\n"); out.write("\t"); List headerNames = new ArrayList(); headerNames.add("property"); headerNames.add("value"); Map portalProps = new TreeMap(); portalProps.putAll(GnPropsUtil.getProperties(propertiesNamespace)); List results = ListUtil.fromCollection(portalProps.entrySet()); for (int i = 0; i < results.size(); i++) { Map.Entry entry = (Map.Entry) results.get(i); String property = (String) entry.getKey(); String value = (String) entry.getValue(); if (!property.equals("include-and-override")) { out.write("\r\n"); out.write("\t\t\t<tr><td>"); out.print(LanguageUtil.get(pageContext, property)); out.write(" : </td><td><input name=\""); out.print(property); out.write("\" value=\""); out.print(value); out.write("\" type=\"text\"></td></tr>\r\n"); out.write("\t"); } } out.write("\r\n"); out.write("\t\t\t<tr><td>\t\r\n"); out.write("\t\t\t\t<input type=\"hidden\" name=\"submitted\" value=\"1\">\r\n"); out.write("\t\t\t\t<input type=\"submit\" value=\""); out.print(LanguageUtil.get(pageContext, "save")); out.write("\">\r\n"); out.write("\t\t\t\t</td>\r\n"); out.write("\t\t\t</tr>\r\n"); out.write("</table>\r\n"); out.write("</form>\r\n"); out.write("\r\n"); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); } } finally { if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context); } }
From source file:org.apache.roller.weblogger.ui.rendering.servlets.PageServlet.java
/** * Handle GET requests for weblog pages. */// w w w. j a v a2 s. c o m public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("Entering"); // do referrer processing, if it's enabled // NOTE: this *must* be done first because it triggers a hibernate flush // which will close the active session and cause lazy init exceptions // otherwise if (this.processReferrers) { boolean spam = this.processReferrer(request); if (spam) { log.debug("spammer, giving 'em a 403"); if (!response.isCommitted()) { response.reset(); } response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } } Weblog weblog = null; boolean isSiteWide = false; WeblogPageRequest pageRequest = null; try { pageRequest = new WeblogPageRequest(request); weblog = pageRequest.getWeblog(); if (weblog == null) { throw new WebloggerException("unable to lookup weblog: " + pageRequest.getWeblogHandle()); } // is this the site-wide weblog? isSiteWide = WebloggerRuntimeConfig.isSiteWideWeblog(pageRequest.getWeblogHandle()); } catch (Exception e) { // some kind of error parsing the request or looking up weblog log.debug("error creating page request", e); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // determine the lastModified date for this content long lastModified = System.currentTimeMillis(); if (isSiteWide) { lastModified = siteWideCache.getLastModified().getTime(); } else if (weblog.getLastModified() != null) { lastModified = weblog.getLastModified().getTime(); } // 304 Not Modified handling. // We skip this for logged in users to avoid the scenerio where a user // views their weblog, logs in, then gets a 304 without the 'edit' links if (!pageRequest.isLoggedIn()) { if (ModDateHeaderUtil.respondIfNotModified(request, response, lastModified)) { return; } else { // set last-modified date ModDateHeaderUtil.setLastModifiedHeader(response, lastModified); } } // generate cache key String cacheKey = null; if (isSiteWide) { cacheKey = siteWideCache.generateKey(pageRequest); } else { cacheKey = weblogPageCache.generateKey(pageRequest); } // Development only. Reload if theme has been modified if (themeReload && !weblog.getEditorTheme().equals(WeblogTemplate.ACTION_CUSTOM) && (pageRequest.getPathInfo() == null || pageRequest.getPathInfo() != null)) { try { ThemeManager manager = WebloggerFactory.getWeblogger().getThemeManager(); boolean reloaded = manager.reLoadThemeFromDisk(weblog.getEditorTheme()); if (reloaded) { if (isSiteWide) { siteWideCache.clear(); } else { weblogPageCache.clear(); } I18nMessages.reloadBundle(weblog.getLocaleInstance()); } } catch (Exception ex) { log.error("ERROR - reloading theme " + ex); } } // cached content checking if ((!this.excludeOwnerPages || !pageRequest.isLoggedIn()) && request.getAttribute("skipCache") == null) { CachedContent cachedContent = null; if (isSiteWide) { cachedContent = (CachedContent) siteWideCache.get(cacheKey); } else { cachedContent = (CachedContent) weblogPageCache.get(cacheKey, lastModified); } if (cachedContent != null) { log.debug("HIT " + cacheKey); // allow for hit counting if (!isSiteWide) { this.processHit(weblog, request.getRequestURL().toString(), request.getHeader("referer")); } response.setContentLength(cachedContent.getContent().length); response.setContentType(cachedContent.getContentType()); response.getOutputStream().write(cachedContent.getContent()); return; } else { log.debug("MISS " + cacheKey); } } log.debug("Looking for template to use for rendering"); // figure out what template to use ThemeTemplate page = null; // If this is a popup request, then deal with it specially // TODO: do we really need to keep supporting this? if (request.getParameter("popup") != null) { try { // Does user have a popupcomments page? page = weblog.getTheme().getTemplateByName("_popupcomments"); } catch (Exception e) { // ignored ... considered page not found } // User doesn't have one so return the default if (page == null) { page = new StaticThemeTemplate("templates/weblog/popupcomments.vm", "velocity"); } // If request specified the page, then go with that } else if ("page".equals(pageRequest.getContext())) { page = pageRequest.getWeblogPage(); // if we don't have this page then 404, we don't let // this one fall through to the default template if (page == null) { if (!response.isCommitted()) { response.reset(); } response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // If request specified tags section index, then look for custom // template } else if ("tags".equals(pageRequest.getContext()) && pageRequest.getTags() != null) { try { page = weblog.getTheme().getTemplateByAction(ThemeTemplate.ACTION_TAGSINDEX); } catch (Exception e) { log.error("Error getting weblog page for action 'tagsIndex'", e); } // if we don't have a custom tags page then 404, we don't let // this one fall through to the default template if (page == null) { if (!response.isCommitted()) { response.reset(); } response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // If this is a permalink then look for a permalink template } else if (pageRequest.getWeblogAnchor() != null) { try { page = weblog.getTheme().getTemplateByAction(ThemeTemplate.ACTION_PERMALINK); } catch (Exception e) { log.error("Error getting weblog page for action 'permalink'", e); } } // if we haven't found a page yet then try our default page if (page == null) { try { page = weblog.getTheme().getDefaultTemplate(); } catch (Exception e) { log.error("Error getting default page for weblog = " + weblog.getHandle(), e); } } // Still no page? Then that is a 404 if (page == null) { if (!response.isCommitted()) { response.reset(); } response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } log.debug("page found, dealing with it"); // validation. make sure that request input makes sense. boolean invalid = false; if (pageRequest.getWeblogPageName() != null && page.isHidden()) { invalid = true; } if (pageRequest.getLocale() != null) { // locale view only allowed if weblog has enabled it if (!pageRequest.getWeblog().isEnableMultiLang()) { invalid = true; } } if (pageRequest.getWeblogAnchor() != null) { // permalink specified. // entry must exist, be published before current time, and locale // must match WeblogEntry entry = pageRequest.getWeblogEntry(); if (entry == null) { invalid = true; } else if (pageRequest.getLocale() != null && !entry.getLocale().startsWith(pageRequest.getLocale())) { invalid = true; } else if (!entry.isPublished()) { invalid = true; } else if (new Date().before(entry.getPubTime())) { invalid = true; } } else if (pageRequest.getWeblogCategoryName() != null) { // category specified. category must exist. if (pageRequest.getWeblogCategory() == null) { invalid = true; } } else if (pageRequest.getTags() != null && pageRequest.getTags().size() > 0) { try { // tags specified. make sure they exist. WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager(); invalid = !wmgr.getTagComboExists(pageRequest.getTags(), (isSiteWide) ? null : weblog); } catch (WebloggerException ex) { invalid = true; } } if (invalid) { log.debug("page failed validation, bailing out"); if (!response.isCommitted()) { response.reset(); } response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // do we need to force a specific locale for the request? if (pageRequest.getLocale() == null && !weblog.isShowAllLangs()) { pageRequest.setLocale(weblog.getLocale()); } // allow for hit counting if (!isSiteWide) { this.processHit(weblog, request.getRequestURL().toString(), request.getHeader("referer")); } // looks like we need to render content // set the content deviceType String contentType = "text/html; charset=utf-8"; if (StringUtils.isNotEmpty(page.getOutputContentType())) { contentType = page.getOutputContentType() + "; charset=utf-8"; } else { String mimeType = RollerContext.getServletContext().getMimeType(page.getLink()); if (mimeType != null) { // we found a match ... set the content deviceType contentType = mimeType + "; charset=utf-8"; } else { contentType = "text/html; charset=utf-8"; } } HashMap model = new HashMap(); try { PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(this, request, response, "", false, 8192, true); // special hack for menu tag request.setAttribute("pageRequest", pageRequest); // populate the rendering model Map initData = new HashMap(); initData.put("requestParameters", request.getParameterMap()); initData.put("parsedRequest", pageRequest); initData.put("pageContext", pageContext); // define url strategy initData.put("urlStrategy", WebloggerFactory.getWeblogger().getUrlStrategy()); // if this was a comment posting, check for comment form WeblogEntryCommentForm commentForm = (WeblogEntryCommentForm) request.getAttribute("commentForm"); if (commentForm != null) { initData.put("commentForm", commentForm); } // Load models for pages String pageModels = WebloggerConfig.getProperty("rendering.pageModels"); ModelLoader.loadModels(pageModels, model, initData, true); // Load special models for site-wide blog if (WebloggerRuntimeConfig.isSiteWideWeblog(weblog.getHandle())) { String siteModels = WebloggerConfig.getProperty("rendering.siteModels"); ModelLoader.loadModels(siteModels, model, initData, true); } // Load weblog custom models ModelLoader.loadCustomModels(weblog, model, initData); // ick, gotta load pre-3.0 model stuff as well :( ModelLoader.loadOldModels(model, request, response, pageContext, pageRequest, WebloggerFactory.getWeblogger().getUrlStrategy()); } catch (WebloggerException ex) { log.error("Error loading model objects for page", ex); if (!response.isCommitted()) { response.reset(); } response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } // lookup Renderer we are going to use Renderer renderer = null; try { log.debug("Looking up renderer"); renderer = RendererManager.getRenderer(page, pageRequest.getDeviceType()); } catch (Exception e) { // nobody wants to render my content :( log.error("Couldn't find renderer for page " + page.getId(), e); if (!response.isCommitted()) { response.reset(); } response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // render content. use size of about 24K for a standard page CachedContent rendererOutput = new CachedContent(24567, contentType); try { log.debug("Doing rendering"); renderer.render(model, rendererOutput.getCachedWriter()); // flush rendered output and close rendererOutput.flush(); rendererOutput.close(); } catch (Exception e) { // bummer, error during rendering log.error("Error during rendering for page " + page.getId(), e); if (!response.isCommitted()) { response.reset(); } response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // post rendering process // flush rendered content to response log.debug("Flushing response output"); response.setContentType(contentType); response.setContentLength(rendererOutput.getContent().length); response.getOutputStream().write(rendererOutput.getContent()); // cache rendered content. only cache if user is not logged in? if ((!this.excludeOwnerPages || !pageRequest.isLoggedIn()) && request.getAttribute("skipCache") == null) { log.debug("PUT " + cacheKey); // put it in the right cache if (isSiteWide) { siteWideCache.put(cacheKey, rendererOutput); } else { weblogPageCache.put(cacheKey, rendererOutput); } } else { log.debug("SKIPPED " + cacheKey); } log.debug("Exiting"); }
From source file:org.apache.roller.weblogger.ui.rendering.servlets.PreviewServlet.java
/** * Handle GET requests for weblog pages. *//*from w ww . j ava2 s . c o m*/ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("Entering"); Weblog weblog = null; WeblogPreviewRequest previewRequest = null; String type = null; try { previewRequest = new WeblogPreviewRequest(request); // type of the page we are going to preview type = previewRequest.getType(); // lookup weblog specified by preview request weblog = previewRequest.getWeblog(); if (weblog == null) { throw new WebloggerException("unable to lookup weblog: " + previewRequest.getWeblogHandle()); } } catch (Exception e) { // some kind of error parsing the request or getting weblog log.debug("error creating preview request", e); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // Get the deviceType from user agent MobileDeviceRepository.DeviceType deviceType = MobileDeviceRepository.getRequestType(request); // for previews we explicitly set the deviceType attribute if (request.getParameter("type") != null) { deviceType = request.getParameter("type").equals("standard") ? MobileDeviceRepository.DeviceType.standard : MobileDeviceRepository.DeviceType.mobile; } Weblog tmpWebsite = weblog; if (previewRequest.getThemeName() != null) { // only create temporary weblog object if theme name was specified // in request, which indicates we're doing a theme preview // try getting the preview theme log.debug("preview theme = " + previewRequest.getThemeName()); Theme previewTheme = previewRequest.getTheme(); // construct a temporary Website object for this request // and set the EditorTheme to our previewTheme tmpWebsite = new Weblog(); tmpWebsite.setData(weblog); if (previewTheme != null && previewTheme.isEnabled()) { tmpWebsite.setEditorTheme(previewTheme.getId()); } else if (WeblogTheme.CUSTOM.equals(previewRequest.getThemeName())) { tmpWebsite.setEditorTheme(WeblogTheme.CUSTOM); } // we've got to set the weblog in our previewRequest because that's // the object that gets referenced during rendering operations previewRequest.setWeblog(tmpWebsite); } // do we need to force a specific locale for the request? if (previewRequest.getLocale() == null && !weblog.isShowAllLangs()) { previewRequest.setLocale(weblog.getLocale()); } Template page = null; if ("page".equals(previewRequest.getContext())) { page = previewRequest.getWeblogPage(); // If request specified tags section index, then look for custom template } else if ("tags".equals(previewRequest.getContext()) && previewRequest.getTags() == null) { try { page = weblog.getTheme().getTemplateByAction(ThemeTemplate.ACTION_TAGSINDEX); } catch (Exception e) { log.error("Error getting weblog page for action 'tagsIndex'", e); } // if we don't have a custom tags page then 404, we don't let // this one fall through to the default template if (page == null) { if (!response.isCommitted()) response.reset(); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // If this is a permalink then look for a permalink template } else if (previewRequest.getWeblogAnchor() != null) { try { page = weblog.getTheme().getTemplateByAction(ThemeTemplate.ACTION_PERMALINK); } catch (Exception e) { log.error("Error getting weblog page for action 'permalink'", e); } } if (page == null) { try { page = tmpWebsite.getTheme().getDefaultTemplate(); } catch (WebloggerException re) { log.error("Error getting default page for preview", re); } } // Still no page? Then that is a 404 if (page == null) { if (!response.isCommitted()) response.reset(); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } log.debug("preview page found, dealing with it"); // set the content type String pageLink = previewRequest.getWeblogPageName(); String mimeType = pageLink != null ? RollerContext.getServletContext().getMimeType(pageLink) : null; String contentType = "text/html; charset=utf-8"; if (mimeType != null) { // we found a match ... set the content type contentType = mimeType + "; charset=utf-8"; } else if ("_css".equals(previewRequest.getWeblogPageName())) { // TODO: store content-type for each page so this hack is unnecessary contentType = "text/css; charset=utf-8"; } // looks like we need to render content Map model = new HashMap(); try { PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(this, request, response, "", false, 8192, true); // special hack for menu tag request.setAttribute("pageRequest", previewRequest); // populate the rendering model Map initData = new HashMap(); initData.put("parsedRequest", previewRequest); initData.put("pageContext", pageContext); // define url strategy initData.put("urlStrategy", WebloggerFactory.getWeblogger().getUrlStrategy() .getPreviewURLStrategy(previewRequest.getThemeName())); // Load models for page previewing String pageModels = WebloggerConfig.getProperty("rendering.previewModels"); ModelLoader.loadModels(pageModels, model, initData, true); // Load special models for site-wide blog if (WebloggerRuntimeConfig.isSiteWideWeblog(weblog.getHandle())) { String siteModels = WebloggerConfig.getProperty("rendering.siteModels"); ModelLoader.loadModels(siteModels, model, initData, true); } // Load weblog custom models ModelLoader.loadCustomModels(weblog, model, initData); // ick, gotta load pre-3.0 model stuff as well :( ModelLoader.loadOldModels(model, request, response, pageContext, previewRequest, WebloggerFactory .getWeblogger().getUrlStrategy().getPreviewURLStrategy(previewRequest.getThemeName())); } catch (WebloggerException ex) { log.error("ERROR loading model for page", ex); if (!response.isCommitted()) response.reset(); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } // lookup Renderer we are going to use Renderer renderer = null; try { log.debug("Looking up renderer"); renderer = RendererManager.getRenderer(page, deviceType); } catch (Exception e) { // nobody wants to render my content :( log.error("Couldn't find renderer for page " + page.getId(), e); if (!response.isCommitted()) response.reset(); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // render content. use default size of about 24K for a standard page CachedContent rendererOutput = new CachedContent(24567); try { log.debug("Doing rendering"); renderer.render(model, rendererOutput.getCachedWriter()); // flush rendered output and close rendererOutput.flush(); rendererOutput.close(); } catch (Exception e) { // bummer, error during rendering log.error("Error during rendering for page " + page.getId(), e); if (!response.isCommitted()) response.reset(); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // post rendering process // flush rendered content to response log.debug("Flushing response output"); response.setContentType(contentType); response.setContentLength(rendererOutput.getContent().length); response.getOutputStream().write(rendererOutput.getContent()); log.debug("Exiting"); }
From source file:org.apache.roller.weblogger.ui.rendering.servlets.SearchServlet.java
/** * Handle GET requests for weblog pages. *//*w w w . jav a 2 s . c o m*/ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("Entering"); Weblog weblog = null; WeblogSearchRequest searchRequest = null; // first off lets parse the incoming request and validate it try { searchRequest = new WeblogSearchRequest(request); // now make sure the specified weblog really exists weblog = WebloggerFactory.getWeblogger().getWeblogManager() .getWeblogByHandle(searchRequest.getWeblogHandle(), Boolean.TRUE); } catch (Exception e) { // invalid search request format or weblog doesn't exist log.debug("error creating weblog search request", e); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // Get the deviceType from user agent MobileDeviceRepository.DeviceType deviceType = MobileDeviceRepository.getRequestType(request); // for previews we explicitly set the deviceType attribute if (request.getParameter("type") != null) { deviceType = request.getParameter("type").equals("standard") ? MobileDeviceRepository.DeviceType.standard : MobileDeviceRepository.DeviceType.mobile; } // do we need to force a specific locale for the request? if (searchRequest.getLocale() == null && !weblog.isShowAllLangs()) { searchRequest.setLocale(weblog.getLocale()); } // lookup template to use for rendering ThemeTemplate page = null; try { // try looking for a specific search page page = weblog.getTheme().getTemplateByAction(ThemeTemplate.ACTION_SEARCH); // if not found then fall back on default page if (page == null) { page = weblog.getTheme().getDefaultTemplate(); } // if still null then that's a problem if (page == null) { throw new WebloggerException("Could not lookup default page " + "for weblog " + weblog.getHandle()); } } catch (Exception e) { log.error("Error getting default page for weblog " + weblog.getHandle(), e); } // set the content type response.setContentType("text/html; charset=utf-8"); // looks like we need to render content Map model = new HashMap(); try { PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(this, request, response, "", false, 8192, true); // populate the rendering model Map initData = new HashMap(); initData.put("request", request); initData.put("pageContext", pageContext); // this is a little hacky, but nothing we can do about it // we need the 'weblogRequest' to be a pageRequest so other models // are properly loaded, which means that searchRequest needs its // own custom initData property aside from the standard weblogRequest. // possible better approach is make searchRequest extend pageRequest. WeblogPageRequest pageRequest = new WeblogPageRequest(); pageRequest.setWeblogHandle(searchRequest.getWeblogHandle()); pageRequest.setWeblogCategoryName(searchRequest.getWeblogCategoryName()); initData.put("parsedRequest", pageRequest); initData.put("searchRequest", searchRequest); // define url strategy initData.put("urlStrategy", WebloggerFactory.getWeblogger().getUrlStrategy()); // Load models for pages String searchModels = WebloggerConfig.getProperty("rendering.searchModels"); ModelLoader.loadModels(searchModels, model, initData, true); // Load special models for site-wide blog if (WebloggerRuntimeConfig.isSiteWideWeblog(weblog.getHandle())) { String siteModels = WebloggerConfig.getProperty("rendering.siteModels"); ModelLoader.loadModels(siteModels, model, initData, true); } // Load weblog custom models ModelLoader.loadCustomModels(weblog, model, initData); // ick, gotta load pre-3.0 model stuff as well :( ModelLoader.loadOldModels(model, request, response, pageContext, pageRequest, WebloggerFactory.getWeblogger().getUrlStrategy()); // manually add search model again to support pre-3.0 weblogs Model searchModel = new SearchResultsModel(); searchModel.init(initData); model.put("searchResults", searchModel); } catch (WebloggerException ex) { log.error("Error loading model objects for page", ex); if (!response.isCommitted()) response.reset(); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } // Development only. Reload if theme has been modified if (themeReload && !weblog.getEditorTheme().equals(WeblogTemplate.ACTION_CUSTOM) && (searchRequest.getPathInfo() == null || searchRequest.getPathInfo() != null && !searchRequest.getPathInfo().endsWith(".css"))) { try { ThemeManager manager = WebloggerFactory.getWeblogger().getThemeManager(); boolean reloaded = manager.reLoadThemeFromDisk(weblog.getEditorTheme()); if (reloaded) { if (WebloggerRuntimeConfig.isSiteWideWeblog(searchRequest.getWeblogHandle())) { SiteWideCache.getInstance().clear(); } else { WeblogPageCache.getInstance().clear(); } I18nMessages.reloadBundle(weblog.getLocaleInstance()); } } catch (Exception ex) { log.error("ERROR - reloading theme " + ex); } } // lookup Renderer we are going to use Renderer renderer = null; try { log.debug("Looking up renderer"); renderer = RendererManager.getRenderer(page, deviceType); } catch (Exception e) { // nobody wants to render my content :( log.error("Couldn't find renderer for rsd template", e); if (!response.isCommitted()) response.reset(); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // render content CachedContent rendererOutput = new CachedContent(4096); try { log.debug("Doing rendering"); renderer.render(model, rendererOutput.getCachedWriter()); // flush rendered output and close rendererOutput.flush(); rendererOutput.close(); } catch (Exception e) { // bummer, error during rendering log.error("Error during rendering for rsd template", e); if (!response.isCommitted()) response.reset(); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // post rendering process // flush rendered content to response log.debug("Flushing response output"); response.setContentLength(rendererOutput.getContent().length); response.getOutputStream().write(rendererOutput.getContent()); log.debug("Exiting"); }
From source file:org.apache.struts2.dispatcher.VelocityResult.java
/** * Creates a Velocity context from the action, loads a Velocity template and executes the * template. Output is written to the servlet output stream. * * @param finalLocation the location of the Velocity template * @param invocation an encapsulation of the action execution state. * @throws Exception if an error occurs when creating the Velocity context, loading or executing * the template or writing output to the servlet response stream. *///from w w w .j a va 2 s .c om public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { ValueStack stack = ActionContext.getContext().getValueStack(); HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); JspFactory jspFactory = null; ServletContext servletContext = ServletActionContext.getServletContext(); Servlet servlet = JspSupportServlet.jspSupportServlet; velocityManager.init(servletContext); boolean usedJspFactory = false; PageContext pageContext = (PageContext) ActionContext.getContext().get(ServletActionContext.PAGE_CONTEXT); if (pageContext == null && servlet != null) { jspFactory = JspFactory.getDefaultFactory(); pageContext = jspFactory.getPageContext(servlet, request, response, null, true, 8192, true); ActionContext.getContext().put(ServletActionContext.PAGE_CONTEXT, pageContext); usedJspFactory = true; } try { String encoding = getEncoding(finalLocation); String contentType = getContentType(finalLocation); if (encoding != null) { contentType = contentType + ";charset=" + encoding; } Template t = getTemplate(stack, velocityManager.getVelocityEngine(), invocation, finalLocation, encoding); Context context = createContext(velocityManager, stack, request, response, finalLocation); Writer writer = new OutputStreamWriter(response.getOutputStream(), encoding); response.setContentType(contentType); t.merge(context, writer); // always flush the writer (we used to only flush it if this was a jspWriter, but someone asked // to do it all the time (WW-829). Since Velocity support is being deprecated, we'll oblige :) writer.flush(); } catch (Exception e) { log.error("Unable to render Velocity Template, '" + finalLocation + "'", e); throw e; } finally { if (usedJspFactory) { jspFactory.releasePageContext(pageContext); } } return; }
From source file:org.apache.struts2.portlet.result.PortletVelocityResult.java
/** * Creates a Velocity context from the action, loads a Velocity template and * executes the template. Output is written to the servlet output stream. * * @param finalLocation the location of the Velocity template * @param invocation an encapsulation of the action execution state. * @throws Exception if an error occurs when creating the Velocity context, * loading or executing the template or writing output to the * servlet response stream./*from w ww . j a v a2 s. co m*/ */ public void executeRenderResult(String finalLocation, ActionInvocation invocation) throws Exception { prepareServletActionContext(); ValueStack stack = ActionContext.getContext().getValueStack(); HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); JspFactory jspFactory = null; ServletContext servletContext = ServletActionContext.getServletContext(); Servlet servlet = JspSupportServlet.jspSupportServlet; velocityManager.init(servletContext); boolean usedJspFactory = false; PageContext pageContext = (PageContext) ActionContext.getContext().get(ServletActionContext.PAGE_CONTEXT); if (pageContext == null && servlet != null) { jspFactory = JspFactory.getDefaultFactory(); pageContext = jspFactory.getPageContext(servlet, request, response, null, true, 8192, true); ActionContext.getContext().put(ServletActionContext.PAGE_CONTEXT, pageContext); usedJspFactory = true; } try { String encoding = getEncoding(finalLocation); String contentType = getContentType(finalLocation); if (encoding != null) { contentType = contentType + ";charset=" + encoding; } Template t = getTemplate(stack, velocityManager.getVelocityEngine(), invocation, finalLocation, encoding); Context context = createContext(velocityManager, stack, request, response, finalLocation); Writer writer = new OutputStreamWriter(response.getOutputStream(), encoding); response.setContentType(contentType); t.merge(context, writer); // always flush the writer (we used to only flush it if this was a // jspWriter, but someone asked // to do it all the time (WW-829). Since Velocity support is being // deprecated, we'll oblige :) writer.flush(); } catch (Exception e) { log.error("Unable to render Velocity Template, '" + finalLocation + "'", e); throw e; } finally { if (usedJspFactory) { jspFactory.releasePageContext(pageContext); } } return; }
From source file:org.apache.struts2.views.zipscript.ZipScriptResult.java
/** * Creates a ZipScript context from the action, loads a ZipScript template and * executes the template. Output is written to the servlet output stream. * /*from w w w .j a v a 2 s. c o m*/ * @param finalLocation * the location of the ZipScript template * @param invocation * an encapsulation of the action execution state. * @throws Exception * if an error occurs when creating the ZipScript context, * loading or executing the template or writing output to the * servlet response stream. */ public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { ResultData resultData = new ResultData(finalLocation); // get working values ValueStack stack = ActionContext.getContext().getValueStack(); HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); JspFactory jspFactory = null; ServletContext servletContext = ServletActionContext.getServletContext(); Servlet servlet = JspSupportServlet.jspSupportServlet; if (null == zipScriptManager) { zipScriptManager = (ZipScriptManager) servletContext.getAttribute(ZipScriptManager.class.getName()); if (null == zipScriptManager) { zipScriptManager = new ZipScriptManager(); servletContext.setAttribute(ZipScriptManager.class.getName(), zipScriptManager); } } ZipEngine zipEngine = zipScriptManager.getZipEngine(servletContext); boolean usedJspFactory = false; PageContext pageContext = (PageContext) ActionContext.getContext().get(ServletActionContext.PAGE_CONTEXT); if (pageContext == null && servlet != null) { jspFactory = JspFactory.getDefaultFactory(); pageContext = jspFactory.getPageContext(servlet, request, response, null, true, 8192, true); ActionContext.getContext().put(ServletActionContext.PAGE_CONTEXT, pageContext); usedJspFactory = true; } try { String encoding = getEncoding(finalLocation); String contentType = getContentType(finalLocation); if (encoding != null) { contentType = contentType + ";charset=" + encoding; } Writer writer = new OutputStreamWriter(response.getOutputStream(), encoding); Context context = zipScriptManager.createContext(invocation, resultData, request); loadContext(context); writeOutput(context, stack, zipEngine, invocation, resultData, servletContext, request, response, writer); response.setContentType(contentType); writer.flush(); } catch (Exception e) { log.error("Unable to render ZipScript Template, '" + finalLocation + "'", e); throw e; } catch (Throwable e) { log.error("Unable to render ZipScript Template, '" + finalLocation + "'", e); throw new Exception(e); } finally { if (usedJspFactory) { jspFactory.releasePageContext(pageContext); } } return; }