001 /** 002 * Copyright (c) 2000-present Liferay, Inc. All rights reserved. 003 * 004 * This library is free software; you can redistribute it and/or modify it under 005 * the terms of the GNU Lesser General Public License as published by the Free 006 * Software Foundation; either version 2.1 of the License, or (at your option) 007 * any later version. 008 * 009 * This library is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 012 * details. 013 */ 014 015 package com.liferay.portlet.portletdisplaytemplate.util; 016 017 import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission; 018 import com.liferay.portal.kernel.template.TemplateHandler; 019 import com.liferay.portal.kernel.template.TemplateVariableGroup; 020 import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate; 021 022 import java.util.List; 023 import java.util.Map; 024 025 import javax.servlet.http.HttpServletRequest; 026 import javax.servlet.http.HttpServletResponse; 027 028 /** 029 * @author Eduardo Garcia 030 */ 031 public class PortletDisplayTemplateUtil { 032 033 /** 034 * Returns the portlet display template's DDM template matching the group 035 * and display style stored in the portlet configuration. 036 * 037 * @param groupId the primary key of the group 038 * @param displayStyle the display style stored in the portlet 039 * configuration 040 * @return the portlet display template's DDM template matching the group 041 * and the display style stored in the portlet configuration 042 */ 043 public static DDMTemplate fetchDDMTemplate( 044 long groupId, String displayStyle) { 045 046 return getPortletDisplayTemplate().fetchDDMTemplate( 047 groupId, displayStyle); 048 } 049 050 /** 051 * Returns the group ID of the portlet display template's DDM template. 052 * 053 * @param groupId the primary key of the group 054 * @return the group ID of the portlet display template's DDM template 055 */ 056 public static long getDDMTemplateGroupId(long groupId) { 057 return getPortletDisplayTemplate().getDDMTemplateGroupId(groupId); 058 } 059 060 /** 061 * Returns the UUID of the portlet display template's DDM template from the 062 * display style stored in the portlet configuration. 063 * 064 * @param displayStyle the display style stored in the portlet 065 * configuration 066 * @return the UUID of the portlet display template's DDM template from the 067 * display style stored in the portlet configuration 068 */ 069 public static String getDDMTemplateUuid(String displayStyle) { 070 return getPortletDisplayTemplate().getDDMTemplateUuid(displayStyle); 071 } 072 073 public static PortletDisplayTemplate getPortletDisplayTemplate() { 074 PortalRuntimePermission.checkGetBeanProperty( 075 PortletDisplayTemplate.class); 076 077 return _portletDisplayTemplate; 078 } 079 080 /** 081 * Returns the primary key of the portlet display template's DDM template 082 * matching the group and the display style stored in the portlet 083 * configuration. 084 * 085 * @param groupId the primary key of the group 086 * @param displayStyle the display style stored in the portlet 087 * configuration 088 * @return the primary key of the portlet display template's DDM template 089 * matching the group and the display style stored in the portlet 090 * configuration 091 */ 092 public static long getPortletDisplayTemplateDDMTemplateId( 093 long groupId, String displayStyle) { 094 095 return 096 getPortletDisplayTemplate().getPortletDisplayTemplateDDMTemplateId( 097 groupId, displayStyle); 098 } 099 100 /** 101 * Returns the portlet display template handlers. 102 * 103 * @return the portlet display template handlers 104 */ 105 public static List<TemplateHandler> getPortletDisplayTemplateHandlers() { 106 return getPortletDisplayTemplate().getPortletDisplayTemplateHandlers(); 107 } 108 109 /** 110 * Returns the portlet display template's map of script variable groups for 111 * which hints are displayed in the template editor palette. 112 * 113 * @param language the portlet display template's scripting language. 114 * Acceptable values for the FreeMarker, Velocity, or XSL languages 115 * are {@link TemplateConstants.LANG_TYPE_FTL}, {@link 116 * TemplateConstants.LANG_TYPE_VM}, or {@link 117 * TemplateConstants.LANG_TYPE_XSL}, respectively. 118 * @return the portlet display template's map of script variable groups for 119 * which hints are displayed in the template editor palette 120 * @see TemplateHandler#getTemplateVariableGroups(long, String, Locale) 121 */ 122 public static Map<String, TemplateVariableGroup> 123 getTemplateVariableGroups(String language) { 124 125 return getPortletDisplayTemplate().getTemplateVariableGroups(language); 126 } 127 128 /** 129 * Returns the result of rendering the DDM template with the entries in the 130 * page context. 131 * 132 * @param request the request with which the template is rendered. 133 * @param response the response with which the template is rendered. 134 * @param ddmTemplateId the primary key of the DDM template 135 * @param entries the entries that are rendered in the template 136 * @return the result of rendering the DDM template with the entries in the 137 * page context 138 * @throws Exception if the DDM template could not be rendered 139 */ 140 public static String renderDDMTemplate( 141 HttpServletRequest request, HttpServletResponse response, 142 long ddmTemplateId, List<?> entries) 143 throws Exception { 144 145 return getPortletDisplayTemplate().renderDDMTemplate( 146 request, response, ddmTemplateId, entries); 147 } 148 149 /** 150 * Returns the result of rendering the DDM template with the entries in the 151 * page context and template context. 152 * 153 * @param request the request with which the template is rendered. 154 * @param response the response with which the template is rendered. 155 * @param ddmTemplateId the primary key of the DDM template 156 * @param entries the entries that are rendered in the template 157 * @param contextObjects the map of objects defining the context in which 158 * the template is rendered 159 * @return the result of rendering the DDM template with the entries in the 160 * page context and template context 161 * @throws Exception if the DDM template could not be rendered 162 */ 163 public static String renderDDMTemplate( 164 HttpServletRequest request, HttpServletResponse response, 165 long ddmTemplateId, List<?> entries, 166 Map<String, Object> contextObjects) 167 throws Exception { 168 169 return getPortletDisplayTemplate().renderDDMTemplate( 170 request, response, ddmTemplateId, entries, contextObjects); 171 } 172 173 public void setPortletDisplayTemplate( 174 PortletDisplayTemplate portletDisplayTemplate) { 175 176 PortalRuntimePermission.checkSetBeanProperty(getClass()); 177 178 _portletDisplayTemplate = portletDisplayTemplate; 179 } 180 181 private static PortletDisplayTemplate _portletDisplayTemplate; 182 183 }