本文整理汇总了Java中com.liferay.portal.kernel.template.Template类的典型用法代码示例。如果您正苦于以下问题:Java Template类的具体用法?Java Template怎么用?Java Template使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Template类属于com.liferay.portal.kernel.template包,在下文中一共展示了Template类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transform
import com.liferay.portal.kernel.template.Template; //导入依赖的package包/类
/**
* based on the example of com.liferay.portal.templateparser.Transformer
*
* @param contextObjects
* @param script
* @param langType
* @return
* @throws Exception
*/
public static String transform(Map<String, Object> contextObjects, String script, String templateId, String langType)
throws Exception {
if (Validator.isNull(langType)) {
return null;
}
Template template = getTemplate(templateId, script, langType);
UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter();
try {
if (contextObjects != null) {
for (String key : contextObjects.keySet()) {
template.put(key, contextObjects.get(key));
}
}
mergeTemplate(template, unsyncStringWriter, true);
} catch (Exception e) {
_log.error(e);
throw new TransformException("Unhandled exception", e);
}
return unsyncStringWriter.toString();
}
示例2: mergeTemplate
import com.liferay.portal.kernel.template.Template; //导入依赖的package包/类
protected static void mergeTemplate(Template template, UnsyncStringWriter unsyncStringWriter,
boolean propagateException) throws Exception {
if (propagateException) {
template.doProcessTemplate(unsyncStringWriter);
} else {
template.processTemplate(unsyncStringWriter);
}
}
示例3: writeTemplate
import com.liferay.portal.kernel.template.Template; //导入依赖的package包/类
/**
* Writes the template's rendering in the portlet response
*
* @param request The request
* @param response The response
* @param ctx The template context
* @param templateResourcePath The template to write
*
* @throws IOException Thrown if something goes wrong when writing the response
* @throws TemplateException Thrown if something goes wrong when processing the template
*/
private void writeTemplate(RenderRequest request, RenderResponse response, Map<String, Object> ctx, String templateResourcePath) throws TemplateException, IOException {
TemplateResource templateResource = this.templateResourceLoader.getTemplateResource(templateResourcePath);
Template template = this.templateManager.getTemplate(templateResource, false);
this.templateManager.addTaglibSupport(template, this.portal.getHttpServletRequest(request), this.portal.getHttpServletResponse(response));
this.enrichTemplateContext(request, response, template);
Set<Entry<String, Object>> contextObjects = ctx.entrySet();
for(Entry<String, Object> obj : contextObjects) {
template.put(obj.getKey(), obj.getValue());
}
template.processTemplate(response.getWriter());
}
示例4: enrichTemplateContext
import com.liferay.portal.kernel.template.Template; //导入依赖的package包/类
/**
* Puts commonly used variables in the template context
* @param request The request
* @param response The response
* @param template The template
*/
private void enrichTemplateContext(RenderRequest request, RenderResponse response, Template template) {
template.put(TemplateVariable.LOCALE.getVariableName(), request.getLocale());
template.put(TemplateVariable.PORTLET_CONTEXT.getVariableName(), this.getPortletContext());
template.put(TemplateVariable.REQUEST.getVariableName(), request);
template.put(TemplateVariable.RESPONSE.getVariableName(), response);
template.put(TemplateVariable.THEME_DISPLAY.getVariableName(), request.getAttribute(WebKeys.THEME_DISPLAY));
template.put(TemplateVariable.USER_INFO.getVariableName(), request.getAttribute(PortletRequest.USER_INFO));
}
示例5: getTemplate
import com.liferay.portal.kernel.template.Template; //导入依赖的package包/类
protected static Template getTemplate(String templateId, String script, String langType) throws Exception {
TemplateResource templateResource = new StringTemplateResource(templateId, script);
TemplateResource errorTemplateResource = null;
return TemplateManagerUtil.getTemplate(langType, templateResource, errorTemplateResource, _restricted);
}
示例6: render
import com.liferay.portal.kernel.template.Template; //导入依赖的package包/类
@Override
public String render(
RenderRequest renderRequest, RenderResponse renderResponse) {
if (_log.isDebugEnabled()) {
_log.debug("ViewMVCRenderCommand.render()");
}
// Hide portlet if we are on the search page
if (getCurrentFriendlyURL(renderRequest).equals(_gSearchConfiguration.searchPortletPage())) {
renderRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, false);
}
Template template =
(Template) renderRequest.getAttribute(WebKeys.TEMPLATE);
// Set namespace (a convenience alias for $id).
String portletNamespace = renderResponse.getNamespace();
template.put(GSearchMiniWebKeys.PORTLET_NAMESPACE, portletNamespace);
// Autocomplete on/off.
template.put(
GSearchMiniWebKeys.AUTO_COMPLETE_ENABLED,
_gSearchConfiguration.enableAutoComplete());
// Autocomplete request delay.
template.put(
GSearchMiniWebKeys.AUTO_COMPLETE_REQUEST_DELAY,
_gSearchConfiguration.autoCompleteRequestDelay());
// Set request timeout.
template.put(
GSearchMiniWebKeys.REQUEST_TIMEOUT,
_gSearchConfiguration.requestTimeout());
// Set query min length.
template.put(
GSearchMiniWebKeys.QUERY_MIN_LENGTH,
_gSearchConfiguration.queryMinLength());
// Enable / disable JS console logging messages.
template.put(
GSearchMiniWebKeys.JS_DEBUG_ENABLED,
_gSearchConfiguration.jsDebuggingEnabled());
// Set search page url.
template.put(
GSearchMiniWebKeys.SEARCHPAGE_URL, _portal.getPortalURL(renderRequest) +
_gSearchConfiguration.searchPortletPage());
// Set autocomplete/suggestions resource url.
template.put(
GSearchMiniWebKeys.SUGGESTIONS_URL,
createResourceURL(renderResponse, GSearchMiniResourceKeys.GET_SUGGESTIONS));
return "MiniView";
}