public String renderDDMTemplate(
      PageContext pageContext,
      long ddmTemplateId,
      List<?> entries,
      Map<String, Object> contextObjects)
      throws Exception {

    contextObjects.put(PortletDisplayTemplateConstants.DDM_TEMPLATE_ID, ddmTemplateId);
    contextObjects.put(PortletDisplayTemplateConstants.ENTRIES, entries);

    if (entries.size() == 1) {
      contextObjects.put(PortletDisplayTemplateConstants.ENTRY, entries.get(0));
    }

    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    contextObjects.put(PortletDisplayTemplateConstants.LOCALE, request.getLocale());

    contextObjects.put(PortletDisplayTemplateConstants.REQUEST, request);

    RenderRequest renderRequest =
        (RenderRequest) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);

    contextObjects.put(PortletDisplayTemplateConstants.RENDER_REQUEST, renderRequest);

    RenderResponse renderResponse =
        (RenderResponse) request.getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);

    contextObjects.put(PortletDisplayTemplateConstants.RENDER_RESPONSE, renderResponse);

    PortletURL currentURL = PortletURLUtil.getCurrent(renderRequest, renderResponse);

    contextObjects.put(PortletDisplayTemplateConstants.CURRENT_URL, currentURL.toString());

    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    contextObjects.put(PortletDisplayTemplateConstants.THEME_DISPLAY, themeDisplay);

    // Taglibs

    DDMTemplate ddmTemplate = DDMTemplateLocalServiceUtil.getTemplate(ddmTemplateId);

    String language = ddmTemplate.getLanguage();

    if (language.equals(TemplateConstants.LANG_TYPE_FTL)) {
      _addTaglibSupportFTL(contextObjects, pageContext);
    } else if (language.equals(TemplateConstants.LANG_TYPE_VM)) {
      _addTaglibSupportVM(contextObjects, pageContext);
    }

    contextObjects.putAll(_getPortletPreferences(renderRequest));

    return _transformer.transform(themeDisplay, contextObjects, ddmTemplate.getScript(), language);
  }
  protected ManagementBarFilterItem getManagementBarFilterItem(int status)
      throws PortalException, PortletException {

    boolean active = false;

    if (status == getStatus()) {
      active = true;
    }

    PortletURL portletURL = PortletURLUtil.clone(getPortletURL(), _liferayPortletResponse);

    portletURL.setParameter("status", String.valueOf(status));

    return new ManagementBarFilterItem(
        active, WorkflowConstants.getStatusLabel(status), portletURL.toString());
  }
示例#3
0
  protected void addBreadcrumbEntries(
      HttpServletRequest request,
      LiferayPortletResponse liferayPortletResponse,
      String className,
      long classPK,
      String paramName,
      PortletURL containerModelURL,
      boolean checkInTrashContainers)
      throws PortalException, PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    PortletURL portletURL = PortletURLUtil.clone(containerModelURL, liferayPortletResponse);

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    List<ContainerModel> containerModels = trashHandler.getParentContainerModels(classPK);

    Collections.reverse(containerModels);

    for (ContainerModel containerModel : containerModels) {
      TrashHandler containerModelTrashHandler =
          TrashHandlerRegistryUtil.getTrashHandler(containerModel.getModelClassName());

      if (checkInTrashContainers
          && !containerModelTrashHandler.isInTrash(containerModel.getContainerModelId())) {

        continue;
      }

      portletURL.setParameter(paramName, String.valueOf(containerModel.getContainerModelId()));

      String name = containerModel.getContainerModelName();

      if (containerModelTrashHandler.isInTrash(containerModel.getContainerModelId())) {

        name = TrashUtil.getOriginalTitle(name);
      }

      PortalUtil.addPortletBreadcrumbEntry(request, name, portletURL.toString());
    }

    TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

    PortalUtil.addPortletBreadcrumbEntry(
        request, trashRenderer.getTitle(themeDisplay.getLocale()), null);
  }
  @Override
  public String renderDDMTemplate(
      HttpServletRequest request,
      HttpServletResponse response,
      DDMTemplate ddmTemplate,
      List<?> entries,
      Map<String, Object> contextObjects)
      throws Exception {

    Transformer transformer = TransformerHolder.getTransformer();

    contextObjects.put(PortletDisplayTemplateConstants.TEMPLATE_ID, ddmTemplate.getTemplateId());
    contextObjects.put(PortletDisplayTemplateConstants.ENTRIES, entries);

    if (!entries.isEmpty()) {
      contextObjects.put(PortletDisplayTemplateConstants.ENTRY, entries.get(0));
    }

    contextObjects.put(PortletDisplayTemplateConstants.LOCALE, request.getLocale());

    contextObjects.put(PortletDisplayTemplateConstants.REQUEST, request);

    RenderRequest renderRequest =
        (RenderRequest) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);

    contextObjects.put(PortletDisplayTemplateConstants.RENDER_REQUEST, renderRequest);

    RenderResponse renderResponse =
        (RenderResponse) request.getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);

    contextObjects.put(PortletDisplayTemplateConstants.RENDER_RESPONSE, renderResponse);

    if ((renderRequest != null) && (renderResponse != null)) {
      PortletURL currentURL = PortletURLUtil.getCurrent(renderRequest, renderResponse);

      contextObjects.put(PortletDisplayTemplateConstants.CURRENT_URL, currentURL.toString());
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    contextObjects.put(PortletDisplayTemplateConstants.THEME_DISPLAY, themeDisplay);

    // Custom context objects

    contextObjects.put(TemplateConstants.CLASS_NAME_ID, ddmTemplate.getClassNameId());

    String language = ddmTemplate.getLanguage();

    TemplateManager templateManager = TemplateManagerUtil.getTemplateManager(language);

    TemplateHandler templateHandler =
        TemplateHandlerRegistryUtil.getTemplateHandler(ddmTemplate.getClassNameId());

    templateManager.addContextObjects(contextObjects, templateHandler.getCustomContextObjects());

    // Taglibs

    templateManager.addTaglibApplication(
        contextObjects,
        PortletDisplayTemplateConstants.FREEMARKER_SERVLET_APPLICATION,
        request.getServletContext());

    templateManager.addTaglibRequest(
        contextObjects,
        PortletDisplayTemplateConstants.FREEMARKER_SERVLET_REQUEST,
        request,
        response);

    templateManager.addTaglibFactory(
        contextObjects,
        PortletDisplayTemplateConstants.TAGLIB_LIFERAY_HASH,
        request.getServletContext());

    UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter();

    templateManager.addTaglibTheme(
        contextObjects,
        "taglibLiferay",
        request,
        new PipingServletResponse(response, unsyncStringWriter));

    contextObjects.put(TemplateConstants.WRITER, unsyncStringWriter);

    if (renderRequest != null) {
      contextObjects.putAll(_getPortletPreferences(renderRequest));
    }

    return transformer.transform(
        themeDisplay, contextObjects, ddmTemplate.getScript(), language, unsyncStringWriter);
  }