Asset Renderer
为资产创建标题和摘要
public String getSummary public String getTitle
如果要为asset提供唯一的URL,则可以指定URL标题。URL标题是用于直接访问asset的URL(例如localhost:8080 /-/ this-is-my-blog-asset)
public String getUrlTitle()
如果asset受权限保护,则可以通过asset renderer设置asset的权限。
@Override
public long getUserId() {return _entry.getUserId();
}@Override public String getUserName() {return _entry.getUserName(); }public boolean hasDeletePermission(PermissionCheckerpermissionChecker) {return BlogsEntryPermission.contains(permissionChecker, _entry, ActionKeys.DELETE); }@Override public boolean hasEditPermission(PermissionCheckerpermissionChecker) {return BlogsEntryPermission.contains(permissionChecker, _entry, ActionKeys.UPDATE); }@Override public boolean hasViewPermission(PermissionCheckerpermissionChecker) {return BlogsEntryPermission.contains(permissionChecker, _entry, ActionKeys.VIEW); }
getURLView(…):生成一个URL,该URL在Asset Publisher中显示asset的全部内容。分配给可点击的asset name
@Override
public String getURLView(LiferayPortletResponse liferayPortletResponse,WindowState windowState)throws Exception {AssetRendererFactory<BlogsEntry> assetRendererFactory =getAssetRendererFactory();PortletURL portletURL = assetRendererFactory.getURLView(liferayPortletResponse, windowState);portletURL.setParameter("mvcRenderCommandName", "/blogs/view_entry");portletURL.setParameter("entryId", String.valueOf(_entry.getEntryId()));portletURL.setWindowState(windowState);return portletURL.toString();
}
将asset renderer组合在一起以满足JSP模板开发要求
1.将getJspPath(…)方法添加到asset renderer。此方法应将路径返回到JSP,该路径在Asset Publisher中呈现
@Override
public String getJspPath(HttpServletRequest request, String template) {if (template.equals(TEMPLATE_ABSTRACT) ||template.equals(TEMPLATE_FULL_CONTENT)) {return "/blogs/asset/" + template + ".jsp";}else {return null;} }
2.重写include,包括该JSP
@Override
public boolean include(HttpServletRequest request, HttpServletResponse response,String template)throws Exception {request.setAttribute(WebKeys.BLOGS_ENTRY, _entry);return super.include(request, response, template);
}