Exemplo n.º 1
0
  protected void configureSubtypeFieldFilter(AssetEntryQuery assetEntryQuery, Locale locale)
      throws Exception {

    long[] classNameIds = getClassNameIds();
    long[] classTypeIds = getClassTypeIds();

    if (!isSubtypeFieldsFilterEnabled()
        || (classNameIds.length != 1)
        || (classTypeIds.length != 1)
        || Validator.isNull(getDDMStructureFieldName())
        || Validator.isNull(getDDMStructureFieldValue())) {

      return;
    }

    AssetRendererFactory<?> assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassNameId(classNameIds[0]);

    ClassTypeReader classTypeReader = assetRendererFactory.getClassTypeReader();

    ClassType classType = classTypeReader.getClassType(classTypeIds[0], locale);

    ClassTypeField classTypeField = classType.getClassTypeField(getDDMStructureFieldName());

    assetEntryQuery.setAttribute(
        "ddmStructureFieldName",
        AssetPublisherUtil.encodeName(
            classTypeField.getClassTypeId(), getDDMStructureFieldName(), locale));
    assetEntryQuery.setAttribute("ddmStructureFieldValue", getDDMStructureFieldValue());
  }
  @Override
  public String getIconCssClass() {
    AssetRendererFactory<?> assetRendererFactory = getAssetRendererFactory();

    if (assetRendererFactory != null) {
      return assetRendererFactory.getIconCssClass();
    }

    return StringPool.BLANK;
  }
  @Override
  public AssetRenderer<T> getAssetRenderer(long classPK) throws PortalException {

    AssetRendererFactory<T> assetRendererFactory = getAssetRendererFactory();

    if (assetRendererFactory != null) {
      return assetRendererFactory.getAssetRenderer(classPK, AssetRendererFactory.TYPE_LATEST);
    } else {
      return null;
    }
  }
  protected boolean isCategorizable(long classNameId) {
    String className = PortalUtil.getClassName(classNameId);

    AssetRendererFactory<?> assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(className);

    if ((assetRendererFactory == null) || !assetRendererFactory.isCategorizable()) {

      return false;
    }

    return true;
  }
Exemplo n.º 5
0
  protected void setDDMStructure() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    _ddmStructureDisplayFieldValue = StringPool.BLANK;
    _ddmStructureFieldLabel = StringPool.BLANK;
    _ddmStructureFieldName = StringPool.BLANK;
    _ddmStructureFieldValue = null;

    long[] classNameIds = getClassNameIds();
    long[] classTypeIds = getClassTypeIds();

    if (!isSubtypeFieldsFilterEnabled()
        || (classNameIds.length != 1)
        || (classTypeIds.length != 1)) {

      return;
    }

    _ddmStructureDisplayFieldValue =
        ParamUtil.getString(
            _request,
            "ddmStructureDisplayFieldValue",
            _portletPreferences.getValue("ddmStructureDisplayFieldValue", StringPool.BLANK));
    _ddmStructureFieldName =
        ParamUtil.getString(
            _request,
            "ddmStructureFieldName",
            _portletPreferences.getValue("ddmStructureFieldName", StringPool.BLANK));
    _ddmStructureFieldValue =
        ParamUtil.getString(
            _request,
            "ddmStructureFieldValue",
            _portletPreferences.getValue("ddmStructureFieldValue", StringPool.BLANK));

    if (Validator.isNotNull(_ddmStructureFieldName)
        && Validator.isNotNull(_ddmStructureFieldValue)) {

      AssetRendererFactory<?> assetRendererFactory =
          AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassNameId(classNameIds[0]);

      ClassTypeReader classTypeReader = assetRendererFactory.getClassTypeReader();

      ClassType classType = classTypeReader.getClassType(classTypeIds[0], themeDisplay.getLocale());

      ClassTypeField classTypeField = classType.getClassTypeField(_ddmStructureFieldName);

      _ddmStructureFieldLabel = classTypeField.getLabel();
    }
  }
Exemplo n.º 6
0
  public static String getSearchResultViewURL(
      RenderRequest renderRequest,
      RenderResponse renderResponse,
      String className,
      long classPK,
      boolean viewInContext,
      String currentURL)
      throws Exception {

    try {
      PortletURL viewContentURL = renderResponse.createRenderURL();

      viewContentURL.setParameter("mvcPath", "/view_content.jsp");
      viewContentURL.setParameter("redirect", currentURL);
      viewContentURL.setPortletMode(PortletMode.VIEW);
      viewContentURL.setWindowState(WindowState.MAXIMIZED);

      if (Validator.isNull(className) || (classPK <= 0)) {
        return viewContentURL.toString();
      }

      AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(className, classPK);

      AssetRendererFactory<?> assetRendererFactory =
          AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(className);

      if (assetRendererFactory == null) {
        return viewContentURL.toString();
      }

      viewContentURL.setParameter("assetEntryId", String.valueOf(assetEntry.getEntryId()));
      viewContentURL.setParameter("type", assetRendererFactory.getType());

      if (viewInContext) {
        String viewFullContentURLString = viewContentURL.toString();

        viewFullContentURLString =
            HttpUtil.setParameter(viewFullContentURLString, "redirect", currentURL);

        AssetRenderer<?> assetRenderer = assetRendererFactory.getAssetRenderer(classPK);

        String viewURL =
            assetRenderer.getURLViewInContext(
                (LiferayPortletRequest) renderRequest,
                (LiferayPortletResponse) renderResponse,
                viewFullContentURLString);

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

        return AssetUtil.checkViewURL(assetEntry, viewInContext, viewURL, currentURL, themeDisplay);
      }

      return viewContentURL.toString();
    } catch (Exception e) {
      _log.error(
          "Unable to get search result  view URL for class "
              + className
              + " with primary key "
              + classPK,
          e);

      return "";
    }
  }
  @Override
  public String getActualURL(
      long companyId,
      long groupId,
      boolean privateLayout,
      String mainPath,
      String friendlyURL,
      Map<String, String[]> params,
      Map<String, Object> requestContext)
      throws PortalException {

    String urlTitle =
        friendlyURL.substring(JournalArticleConstants.CANONICAL_URL_SEPARATOR.length());

    JournalArticle journalArticle =
        _journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle);

    Layout layout = getJournalArticleLayout(groupId, privateLayout, friendlyURL);

    String layoutActualURL = PortalUtil.getLayoutActualURL(layout, mainPath);

    InheritableMap<String, String[]> actualParams = new InheritableMap<>();

    if (params != null) {
      actualParams.setParentMap(params);
    }

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    String defaultAssetPublisherPortletId =
        typeSettingsProperties.get(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID);

    String currentDefaultAssetPublisherPortletId = defaultAssetPublisherPortletId;

    if (Validator.isNull(defaultAssetPublisherPortletId)) {
      PortletInstance portletInstance =
          new PortletInstance(AssetPublisherPortletKeys.ASSET_PUBLISHER);

      defaultAssetPublisherPortletId = portletInstance.getPortletInstanceKey();
    }

    HttpServletRequest request = (HttpServletRequest) requestContext.get("request");

    if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
      String actualPortletAuthenticationToken =
          AuthTokenUtil.getToken(request, layout.getPlid(), defaultAssetPublisherPortletId);

      actualParams.put("p_p_auth", new String[] {actualPortletAuthenticationToken});
    }

    actualParams.put("p_p_id", new String[] {defaultAssetPublisherPortletId});
    actualParams.put("p_p_lifecycle", new String[] {"0"});

    if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
      actualParams.put("p_p_state", new String[] {WindowState.MAXIMIZED.toString()});
    }

    actualParams.put("p_p_mode", new String[] {"view"});
    actualParams.put("p_j_a_id", new String[] {String.valueOf(journalArticle.getId())});

    String namespace = PortalUtil.getPortletNamespace(defaultAssetPublisherPortletId);

    actualParams.put(namespace + "mvcPath", new String[] {"/view_content.jsp"});

    AssetRendererFactory<?> assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
            JournalArticle.class.getName());

    actualParams.put(namespace + "type", new String[] {assetRendererFactory.getType()});

    actualParams.put(namespace + "urlTitle", new String[] {journalArticle.getUrlTitle()});

    String queryString = HttpUtil.parameterMapToString(actualParams, false);

    if (layoutActualURL.contains(StringPool.QUESTION)) {
      layoutActualURL = layoutActualURL + StringPool.AMPERSAND + queryString;
    } else {
      layoutActualURL = layoutActualURL + StringPool.QUESTION + queryString;
    }

    Locale locale = PortalUtil.getLocale(request);

    PortalUtil.addPageSubtitle(journalArticle.getTitle(locale), request);
    PortalUtil.addPageDescription(journalArticle.getDescription(locale), request);

    List<AssetTag> assetTags =
        _assetTagLocalService.getTags(
            JournalArticle.class.getName(), journalArticle.getPrimaryKey());

    if (!assetTags.isEmpty()) {
      PortalUtil.addPageKeywords(ListUtil.toString(assetTags, AssetTag.NAME_ACCESSOR), request);
    }

    return layoutActualURL;
  }