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.assetpublisher.context;
016    
017    import com.liferay.portal.kernel.dao.search.SearchContainer;
018    import com.liferay.portal.kernel.util.ArrayUtil;
019    import com.liferay.portal.kernel.util.GetterUtil;
020    import com.liferay.portal.kernel.util.JavaConstants;
021    import com.liferay.portal.kernel.util.ParamUtil;
022    import com.liferay.portal.kernel.util.PredicateFilter;
023    import com.liferay.portal.kernel.util.PrefsPropsUtil;
024    import com.liferay.portal.kernel.util.PropsKeys;
025    import com.liferay.portal.kernel.util.PropsUtil;
026    import com.liferay.portal.kernel.util.StringComparator;
027    import com.liferay.portal.kernel.util.StringPool;
028    import com.liferay.portal.kernel.util.StringUtil;
029    import com.liferay.portal.kernel.util.Validator;
030    import com.liferay.portal.model.PortletConstants;
031    import com.liferay.portal.theme.PortletDisplay;
032    import com.liferay.portal.theme.ThemeDisplay;
033    import com.liferay.portal.util.PortletKeys;
034    import com.liferay.portal.util.PropsValues;
035    import com.liferay.portal.util.WebKeys;
036    import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
037    import com.liferay.portlet.asset.model.AssetEntry;
038    import com.liferay.portlet.asset.model.AssetRenderer;
039    import com.liferay.portlet.asset.model.AssetRendererFactory;
040    import com.liferay.portlet.asset.model.ClassType;
041    import com.liferay.portlet.asset.model.ClassTypeField;
042    import com.liferay.portlet.asset.model.ClassTypeReader;
043    import com.liferay.portlet.asset.service.persistence.AssetEntryQuery;
044    import com.liferay.portlet.asset.util.AssetUtil;
045    import com.liferay.portlet.assetpublisher.util.AssetPublisherUtil;
046    import com.liferay.portlet.dynamicdatamapping.util.DDMIndexerUtil;
047    import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplateUtil;
048    import com.liferay.util.RSSUtil;
049    
050    import java.util.Locale;
051    import java.util.Set;
052    
053    import javax.portlet.PortletConfig;
054    import javax.portlet.PortletPreferences;
055    
056    import javax.servlet.http.HttpServletRequest;
057    
058    /**
059     * @author Eudaldo Alonso
060     */
061    public class AssetPublisherDisplayContext {
062    
063            public AssetPublisherDisplayContext(
064                    HttpServletRequest request, PortletPreferences portletPreferences) {
065    
066                    _request = request;
067                    _portletPreferences = portletPreferences;
068            }
069    
070            public int getAbstractLength() {
071                    if (_abstractLength == null) {
072                            _abstractLength = GetterUtil.getInteger(
073                                    _portletPreferences.getValue("abstractLength", null), 200);
074                    }
075    
076                    return _abstractLength;
077            }
078    
079            public long[] getAllAssetCategoryIds() throws Exception {
080                    if (_allAssetCategoryIds != null) {
081                            return _allAssetCategoryIds;
082                    }
083    
084                    _allAssetCategoryIds = new long[0];
085    
086                    long assetCategoryId = ParamUtil.getLong(_request, "categoryId");
087    
088                    String selectionStyle = getSelectionStyle();
089    
090                    if (selectionStyle.equals("dynamic")) {
091                            _allAssetCategoryIds = AssetPublisherUtil.getAssetCategoryIds(
092                                    _portletPreferences);
093                    }
094    
095                    if ((assetCategoryId > 0) &&
096                            !ArrayUtil.contains(_allAssetCategoryIds, assetCategoryId)) {
097    
098                            _allAssetCategoryIds = ArrayUtil.append(
099                                    _allAssetCategoryIds, assetCategoryId);
100                    }
101    
102                    return _allAssetCategoryIds;
103            }
104    
105            public String[] getAllAssetTagNames() throws Exception {
106                    if (_allAssetTagNames != null) {
107                            return _allAssetTagNames;
108                    }
109    
110                    _allAssetTagNames = new String[0];
111    
112                    String assetTagName = ParamUtil.getString(_request, "tag");
113    
114                    String selectionStyle = getSelectionStyle();
115    
116                    if (selectionStyle.equals("dynamic")) {
117                            _allAssetTagNames = AssetPublisherUtil.getAssetTagNames(
118                                    _portletPreferences);
119                    }
120    
121                    if (Validator.isNotNull(assetTagName) &&
122                            !ArrayUtil.contains(_allAssetTagNames, assetTagName)) {
123    
124                            _allAssetTagNames = ArrayUtil.append(
125                                    _allAssetTagNames, assetTagName);
126                    }
127    
128                    if (isMergeURLTags() || isMergeLayoutTags()) {
129                            _allAssetTagNames = ArrayUtil.append(
130                                    _allAssetTagNames, getCompilerTagNames());
131                    }
132    
133                    _allAssetTagNames = ArrayUtil.distinct(
134                            _allAssetTagNames, new StringComparator());
135    
136                    return _allAssetTagNames;
137            }
138    
139            public AssetEntryQuery getAssetEntryQuery() throws Exception {
140                    ThemeDisplay themeDisplay = (ThemeDisplay)_request.getAttribute(
141                            WebKeys.THEME_DISPLAY);
142    
143                    AssetEntryQuery assetEntryQuery = AssetPublisherUtil.getAssetEntryQuery(
144                            _portletPreferences, getGroupIds(), getAllAssetCategoryIds(),
145                            getAllAssetTagNames());
146    
147                    String portletName = getPortletName();
148    
149                    if (!portletName.equals(PortletKeys.RELATED_ASSETS)) {
150                            assetEntryQuery.setGroupIds(getGroupIds());
151                    }
152    
153                    assetEntryQuery.setClassTypeIds(getClassTypeIds());
154                    assetEntryQuery.setEnablePermissions(isEnablePermissions());
155                    assetEntryQuery.setExcludeZeroViewCount(isExcludeZeroViewCount());
156    
157                    configureSubtypeFieldFilter(assetEntryQuery, themeDisplay.getLocale());
158    
159                    if (isShowOnlyLayoutAssets()) {
160                            assetEntryQuery.setLayout(themeDisplay.getLayout());
161                    }
162    
163                    if (portletName.equals(PortletKeys.RELATED_ASSETS)) {
164                            AssetEntry layoutAssetEntry = (AssetEntry)_request.getAttribute(
165                                    WebKeys.LAYOUT_ASSET_ENTRY);
166    
167                            if (layoutAssetEntry != null) {
168                                    assetEntryQuery.setLinkedAssetEntryId(
169                                            layoutAssetEntry.getEntryId());
170                            }
171                    }
172    
173                    assetEntryQuery.setPaginationType(getPaginationType());
174                    assetEntryQuery.setOrderByCol1(getOrderByColumn1());
175                    assetEntryQuery.setOrderByCol2(getOrderByColumn2());
176                    assetEntryQuery.setOrderByType1(getOrderByType1());
177                    assetEntryQuery.setOrderByType2(getOrderByType2());
178    
179                    AssetPublisherUtil.processAssetEntryQuery(
180                            themeDisplay.getUser(), _portletPreferences, assetEntryQuery);
181    
182                    return assetEntryQuery;
183            }
184    
185            public String getAssetLinkBehavior() {
186                    if (_assetLinkBehavior == null) {
187                            _assetLinkBehavior = GetterUtil.getString(
188                                    _portletPreferences.getValue(
189                                            "assetLinkBehavior", "showFullContent"));
190                    }
191    
192                    return _assetLinkBehavior;
193            }
194    
195            public long[] getAvailableClassNameIds() {
196                    if (_availableClassNameIds == null) {
197                            ThemeDisplay themeDisplay = (ThemeDisplay)_request.getAttribute(
198                                    WebKeys.THEME_DISPLAY);
199    
200                            _availableClassNameIds =
201                                    AssetRendererFactoryRegistryUtil.getClassNameIds(
202                                            themeDisplay.getCompanyId(), true);
203                    }
204    
205                    return _availableClassNameIds;
206            }
207    
208            public long[] getClassNameIds() {
209                    if (_classNameIds == null) {
210                            _classNameIds = AssetPublisherUtil.getClassNameIds(
211                                    _portletPreferences, getAvailableClassNameIds());
212                    }
213    
214                    return _classNameIds;
215            }
216    
217            public long[] getClassTypeIds() {
218                    if (_classTypeIds == null) {
219                            _classTypeIds = GetterUtil.getLongValues(
220                                    _portletPreferences.getValues("classTypeIds", null));
221                    }
222    
223                    return _classTypeIds;
224            }
225    
226            public String[] getCompilerTagNames() {
227                    if (_compilerTagNames != null) {
228                            return _compilerTagNames;
229                    }
230    
231                    _compilerTagNames = new String[0];
232    
233                    if (isMergeURLTags()) {
234                            _compilerTagNames = ParamUtil.getParameterValues(_request, "tags");
235                    }
236    
237                    if (isMergeLayoutTags()) {
238                            Set<String> layoutTagNames = AssetUtil.getLayoutTagNames(_request);
239    
240                            if (!layoutTagNames.isEmpty()) {
241                                    _compilerTagNames = ArrayUtil.append(
242                                            _compilerTagNames,
243                                            layoutTagNames.toArray(new String[layoutTagNames.size()]));
244                            }
245                    }
246    
247                    return _compilerTagNames;
248            }
249    
250            public String getDDMStructureDisplayFieldValue() throws Exception {
251                    if (_ddmStructureDisplayFieldValue == null) {
252                            setDDMStructure();
253                    }
254    
255                    return _ddmStructureDisplayFieldValue;
256            }
257    
258            public String getDDMStructureFieldLabel() throws Exception {
259                    if (_ddmStructureFieldLabel == null) {
260                            setDDMStructure();
261                    }
262    
263                    return _ddmStructureFieldLabel;
264            }
265    
266            public String getDDMStructureFieldName() throws Exception {
267                    if (_ddmStructureFieldName == null) {
268                            setDDMStructure();
269                    }
270    
271                    return _ddmStructureFieldName;
272            }
273    
274            public String getDDMStructureFieldValue() throws Exception {
275                    if (_ddmStructureFieldValue == null) {
276                            setDDMStructure();
277                    }
278    
279                    return _ddmStructureFieldValue;
280            }
281    
282            public Integer getDelta() {
283                    if (_delta != null) {
284                            return _delta;
285                    }
286    
287                    _delta = GetterUtil.getInteger(
288                            _portletPreferences.getValue("delta", null),
289                            SearchContainer.DEFAULT_DELTA);
290    
291                    String portletName = getPortletName();
292    
293                    if (portletName.equals(PortletKeys.RECENT_CONTENT)) {
294                            _delta = PropsValues.RECENT_CONTENT_MAX_DISPLAY_ITEMS;
295                    }
296    
297                    return _delta;
298            }
299    
300            public String getDisplayStyle() {
301                    if (_displayStyle == null) {
302                            _displayStyle = GetterUtil.getString(
303                                    _portletPreferences.getValue(
304                                            "displayStyle",
305                                            PropsValues.ASSET_PUBLISHER_DISPLAY_STYLE_DEFAULT));
306                    }
307    
308                    return _displayStyle;
309            }
310    
311            public long getDisplayStyleGroupId() {
312                    if (_displayStyleGroupId == null) {
313                            ThemeDisplay themeDisplay = (ThemeDisplay)_request.getAttribute(
314                                    WebKeys.THEME_DISPLAY);
315    
316                            _displayStyleGroupId = GetterUtil.getLong(
317                                    _portletPreferences.getValue("displayStyleGroupId", null),
318                                    themeDisplay.getScopeGroupId());
319                    }
320    
321                    return _displayStyleGroupId;
322            }
323    
324            public String[] getExtensions() {
325                    if (_extensions == null) {
326                            _extensions = _portletPreferences.getValues(
327                                    "extensions", new String[0]);
328                    }
329    
330                    return _extensions;
331            }
332    
333            public String[] getExtensions(AssetRenderer assetRenderer) {
334                    final String[] supportedConversions =
335                            assetRenderer.getSupportedConversions();
336    
337                    if (supportedConversions == null) {
338                            return getExtensions();
339                    }
340    
341                    return ArrayUtil.filter(
342                            getExtensions(),
343                            new PredicateFilter<String>() {
344    
345                                    @Override
346                                    public boolean filter(String extension) {
347                                            return ArrayUtil.contains(supportedConversions, extension);
348                                    }
349    
350                            });
351            }
352    
353            public long[] getGroupIds() {
354                    if (_groupIds == null) {
355                            ThemeDisplay themeDisplay = (ThemeDisplay)_request.getAttribute(
356                                    WebKeys.THEME_DISPLAY);
357    
358                            _groupIds = AssetPublisherUtil.getGroupIds(
359                                    _portletPreferences, themeDisplay.getScopeGroupId(),
360                                    themeDisplay.getLayout());
361                    }
362    
363                    return _groupIds;
364            }
365    
366            public String[] getMetadataFields() {
367                    if (_metadataFields == null) {
368                            _metadataFields = StringUtil.split(
369                                    _portletPreferences.getValue(
370                                            "metadataFields", StringPool.BLANK));
371                    }
372    
373                    return _metadataFields;
374            }
375    
376            public String getOrderByColumn1() {
377                    if (_orderByColumn1 == null) {
378                            _orderByColumn1 = GetterUtil.getString(
379                                    _portletPreferences.getValue("orderByColumn1", "modifiedDate"));
380                    }
381    
382                    return _orderByColumn1;
383            }
384    
385            public String getOrderByColumn2() {
386                    if (_orderByColumn2 == null) {
387                            _orderByColumn2 = GetterUtil.getString(
388                                    _portletPreferences.getValue("orderByColumn2", "title"));
389                    }
390    
391                    return _orderByColumn2;
392            }
393    
394            public String getOrderByType1() {
395                    if (_orderByType1 == null) {
396                            _orderByType1 = GetterUtil.getString(
397                                    _portletPreferences.getValue("orderByType1", "DESC"));
398                    }
399    
400                    return _orderByType1;
401            }
402    
403            public String getOrderByType2() {
404                    if (_orderByType2 == null) {
405                            _orderByType2 = GetterUtil.getString(
406                                    _portletPreferences.getValue("orderByType2", "ASC"));
407                    }
408    
409                    return _orderByType2;
410            }
411    
412            public String getPaginationType() {
413                    if (_paginationType == null) {
414                            _paginationType = GetterUtil.getString(
415                                    _portletPreferences.getValue("paginationType", "none"));
416                    }
417    
418                    return _paginationType;
419            }
420    
421            public Long getPortletDisplayDDMTemplateId() {
422                    if (_portletDisplayDDMTemplateId == null) {
423                            _portletDisplayDDMTemplateId =
424                                    PortletDisplayTemplateUtil.
425                                            getPortletDisplayTemplateDDMTemplateId(
426                                                    getDisplayStyleGroupId(), getDisplayStyle());
427                    }
428    
429                    return _portletDisplayDDMTemplateId;
430            }
431    
432            public String getPortletResource() {
433                    if (_portletResource == null) {
434                            _portletResource = ParamUtil.getString(_request, "portletResource");
435                    }
436    
437                    return _portletResource;
438            }
439    
440            public String getRootPortletId() {
441                    if (_rootPortletId == null) {
442                            _rootPortletId = PortletConstants.getRootPortletId(
443                                    getPortletResource());
444                    }
445    
446                    return _rootPortletId;
447            }
448    
449            public int getRSSDelta() {
450                    if (_rssDelta == null) {
451                            _rssDelta = GetterUtil.getInteger(
452                                    _portletPreferences.getValue("rssDelta", StringPool.BLANK),
453                                    SearchContainer.DEFAULT_DELTA);
454                    }
455    
456                    return _rssDelta;
457            }
458    
459            public String getRSSDisplayStyle() {
460                    if (_rssDisplayStyle == null) {
461                            _rssDisplayStyle = _portletPreferences.getValue(
462                                    "rssDisplayStyle", RSSUtil.DISPLAY_STYLE_ABSTRACT);
463                    }
464    
465                    return _rssDisplayStyle;
466            }
467    
468            public String getRSSFeedType() {
469                    if (_rssFeedType == null) {
470                            _rssFeedType = _portletPreferences.getValue(
471                                    "rssFeedType", RSSUtil.FEED_TYPE_DEFAULT);
472                    }
473    
474                    return _rssFeedType;
475            }
476    
477            public String getRSSName() {
478                    if (_rssName != null) {
479                            return _rssName;
480                    }
481    
482                    ThemeDisplay themeDisplay = (ThemeDisplay)_request.getAttribute(
483                            WebKeys.THEME_DISPLAY);
484    
485                    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
486    
487                    _rssName = _portletPreferences.getValue(
488                            "rssName", portletDisplay.getTitle());
489    
490                    return _rssName;
491            }
492    
493            public String getSelectionStyle() {
494                    if (_selectionStyle == null) {
495                            _selectionStyle = GetterUtil.getString(
496                                    _portletPreferences.getValue("selectionStyle", null),
497                                    "dynamic");
498                    }
499    
500                    return _selectionStyle;
501            }
502    
503            public String getSocialBookmarksDisplayPosition() {
504                    if (_socialBookmarksDisplayPosition == null) {
505                            _socialBookmarksDisplayPosition = _portletPreferences.getValue(
506                                    "socialBookmarksDisplayPosition", "bottom");
507                    }
508    
509                    return _socialBookmarksDisplayPosition;
510            }
511    
512            public String getSocialBookmarksDisplayStyle() {
513                    if (_socialBookmarksDisplayStyle != null) {
514                            return _socialBookmarksDisplayStyle;
515                    }
516    
517                    _socialBookmarksDisplayStyle = _portletPreferences.getValue(
518                            "socialBookmarksDisplayStyle", null);
519    
520                    if (Validator.isNull(_socialBookmarksDisplayStyle)) {
521                            String[] socialBookmarksDisplayStyles = PropsUtil.getArray(
522                                    PropsKeys.SOCIAL_BOOKMARK_DISPLAY_STYLES);
523    
524                            _socialBookmarksDisplayStyle = socialBookmarksDisplayStyles[0];
525                    }
526    
527                    return _socialBookmarksDisplayStyle;
528            }
529    
530            public Boolean isAnyAssetType() {
531                    if (_anyAssetType == null) {
532                            _anyAssetType = GetterUtil.getBoolean(
533                                    _portletPreferences.getValue("anyAssetType", null), true);
534                    }
535    
536                    return _anyAssetType;
537            }
538    
539            public boolean isAssetLinkBehaviorShowFullContent() {
540                    String assetLinkBehavior = getAssetLinkBehavior();
541    
542                    return assetLinkBehavior.equals("showFullContent");
543            }
544    
545            public boolean isAssetLinkBehaviorViewInPortlet() {
546                    String assetLinkBehavior = getAssetLinkBehavior();
547    
548                    return assetLinkBehavior.equals("viewInPortlet");
549            }
550    
551            public boolean isEnableCommentRatings() {
552                    if (_enableCommentRatings == null) {
553                            _enableCommentRatings = GetterUtil.getBoolean(
554                                    _portletPreferences.getValue("enableCommentRatings", null));
555                    }
556    
557                    return _enableCommentRatings;
558            }
559    
560            public boolean isEnableComments() {
561                    if (_enableComments == null) {
562                            _enableComments = GetterUtil.getBoolean(
563                                    _portletPreferences.getValue("enableComments", null));
564                    }
565    
566                    return _enableComments;
567            }
568    
569            public Boolean isEnableConversions() throws Exception {
570                    if (_enableConversions == null) {
571                            _enableConversions =
572                                    isOpenOfficeServerEnabled() &&
573                                            ArrayUtil.isNotEmpty(getExtensions());
574                    }
575    
576                    return _enableConversions;
577            }
578    
579            public boolean isEnableFlags() {
580                    if (_enableFlags == null) {
581                            _enableFlags = GetterUtil.getBoolean(
582                                    _portletPreferences.getValue("enableFlags", null));
583                    }
584    
585                    return _enableFlags;
586            }
587    
588            public Boolean isEnablePermissions() {
589                    if (_enablePermissions != null) {
590                            return _enablePermissions;
591                    }
592    
593                    String portletName = getPortletName();
594    
595                    if (!portletName.equals(PortletKeys.HIGHEST_RATED_ASSETS) &&
596                            !portletName.equals(PortletKeys.MOST_VIEWED_ASSETS) &&
597                            PropsValues.ASSET_PUBLISHER_SEARCH_WITH_INDEX) {
598    
599                            _enablePermissions = true;
600    
601                            return _enablePermissions;
602                    }
603    
604                    if (!PropsValues.ASSET_PUBLISHER_PERMISSION_CHECKING_CONFIGURABLE) {
605                            _enablePermissions = true;
606    
607                            return _enablePermissions;
608                    }
609    
610                    _enablePermissions = GetterUtil.getBoolean(
611                            _portletPreferences.getValue("enablePermissions", null));
612    
613                    return _enablePermissions;
614            }
615    
616            public boolean isEnablePrint() {
617                    if (_enablePrint == null) {
618                            _enablePrint = GetterUtil.getBoolean(
619                                    _portletPreferences.getValue("enablePrint", null));
620                    }
621    
622                    return _enablePrint;
623            }
624    
625            public boolean isEnableRatings() {
626                    if (_enableRatings == null) {
627                            _enableRatings = GetterUtil.getBoolean(
628                                    _portletPreferences.getValue("enableRatings", null));
629                    }
630    
631                    return _enableRatings;
632            }
633    
634            public boolean isEnableRelatedAssets() {
635                    if (_enableRelatedAssets == null) {
636                            _enableRelatedAssets = GetterUtil.getBoolean(
637                                    _portletPreferences.getValue("enableRelatedAssets", null),
638                                    true);
639                    }
640    
641                    return _enableRelatedAssets;
642            }
643    
644            public boolean isEnableRSS() {
645                    if (_enableRSS == null) {
646                            _enableRSS = GetterUtil.getBoolean(
647                                    _portletPreferences.getValue("enableRss", null));
648                    }
649    
650                    return _enableRSS;
651            }
652    
653            public boolean isEnableSocialBookmarks() {
654                    if (_enableSocialBookmarks == null) {
655                            _enableSocialBookmarks = GetterUtil.getBoolean(
656                                    _portletPreferences.getValue("enableSocialBookmarks", null),
657                                    true);
658                    }
659    
660                    return _enableSocialBookmarks;
661            }
662    
663            public boolean isEnableTagBasedNavigation() {
664                    if (_enableTagBasedNavigation == null) {
665                            _enableTagBasedNavigation = GetterUtil.getBoolean(
666                                    _portletPreferences.getValue("enableTagBasedNavigation", null));
667                    }
668    
669                    return _enableTagBasedNavigation;
670            }
671    
672            public boolean isExcludeZeroViewCount() {
673                    if (_excludeZeroViewCount == null) {
674                            _excludeZeroViewCount = GetterUtil.getBoolean(
675                                    _portletPreferences.getValue("excludeZeroViewCount", null));
676                    }
677    
678                    return _excludeZeroViewCount;
679            }
680    
681            public boolean isMergeLayoutTags() {
682                    if (_mergeLayoutTags == null) {
683                            _mergeLayoutTags = GetterUtil.getBoolean(
684                                    _portletPreferences.getValue("mergeLayoutTags", null), false);
685                    }
686    
687                    return _mergeLayoutTags;
688            }
689    
690            public boolean isMergeURLTags() {
691                    if (_mergeURLTags == null) {
692                            _mergeURLTags = GetterUtil.getBoolean(
693                                    _portletPreferences.getValue("mergeUrlTags", null), true);
694                    }
695    
696                    return _mergeURLTags;
697            }
698    
699            public boolean isOpenOfficeServerEnabled() {
700                    if (_openOfficeServerEnabled == null) {
701                            _openOfficeServerEnabled = PrefsPropsUtil.getBoolean(
702                                    PropsKeys.OPENOFFICE_SERVER_ENABLED,
703                                    PropsValues.OPENOFFICE_SERVER_ENABLED);
704                    }
705    
706                    return _openOfficeServerEnabled;
707            }
708    
709            public boolean isOrderingAndGroupingEnabled() {
710                    String rootPortletId = getRootPortletId();
711    
712                    if (rootPortletId.equals(PortletKeys.HIGHEST_RATED_ASSETS) ||
713                            rootPortletId.equals(PortletKeys.MOST_VIEWED_ASSETS)) {
714    
715                            return false;
716                    }
717    
718                    return true;
719            }
720    
721            public boolean isOrderingByTitleEnabled() {
722                    String rootPortletId = getRootPortletId();
723    
724                    if (!PropsValues.ASSET_PUBLISHER_SEARCH_WITH_INDEX ||
725                            rootPortletId.equals(PortletKeys.RELATED_ASSETS)) {
726    
727                            return false;
728                    }
729    
730                    return true;
731            }
732    
733            public boolean isPaginationTypeNone() {
734                    String paginationType = getPaginationType();
735    
736                    return paginationType.equals("none");
737            }
738    
739            public boolean isPaginationTypeRegular() {
740                    String paginationType = getPaginationType();
741    
742                    return paginationType.equals("regular");
743            }
744    
745            public boolean isPaginationTypeSimple() {
746                    String paginationType = getPaginationType();
747    
748                    return paginationType.equals("simple");
749            }
750    
751            public boolean isSelectionStyleDynamic() {
752                    String selectionStyle = getSelectionStyle();
753    
754                    return selectionStyle.equals("dynamic");
755            }
756    
757            public boolean isSelectionStyleEnabled() {
758                    String rootPortletId = getRootPortletId();
759    
760                    if (rootPortletId.equals(PortletKeys.HIGHEST_RATED_ASSETS) ||
761                            rootPortletId.equals(PortletKeys.MOST_VIEWED_ASSETS) ||
762                            rootPortletId.equals(PortletKeys.RELATED_ASSETS)) {
763    
764                            return false;
765                    }
766    
767                    return true;
768            }
769    
770            public boolean isSelectionStyleManual() {
771                    String selectionStyle = getSelectionStyle();
772    
773                    return selectionStyle.equals("manual");
774            }
775    
776            public boolean isShowAddContentButton() {
777                    if (_showAddContentButton == null) {
778                            _showAddContentButton = GetterUtil.getBoolean(
779                                    _portletPreferences.getValue("showAddContentButton", null),
780                                    true);
781                    }
782    
783                    return _showAddContentButton;
784            }
785    
786            public Boolean isShowAssetTitle() {
787                    if (_showAssetTitle == null) {
788                            _showAssetTitle = GetterUtil.getBoolean(
789                                    _portletPreferences.getValue("showAssetTitle", null), true);
790                    }
791    
792                    return _showAssetTitle;
793            }
794    
795            public Boolean isShowAvailableLocales() {
796                    if (_showAvailableLocales == null) {
797                            _showAvailableLocales = GetterUtil.getBoolean(
798                                    _portletPreferences.getValue("showAvailableLocales", null));
799                    }
800    
801                    return _showAvailableLocales;
802            }
803    
804            public Boolean isShowContextLink() {
805                    if (_showContextLink == null) {
806                            _showContextLink = GetterUtil.getBoolean(
807                                    _portletPreferences.getValue("showContextLink", null), true);
808                    }
809    
810                    return _showContextLink;
811            }
812    
813            public boolean isShowEnableAddContentButton() {
814                    String rootPortletId = getRootPortletId();
815    
816                    if (rootPortletId.equals(PortletKeys.HIGHEST_RATED_ASSETS) ||
817                            rootPortletId.equals(PortletKeys.MOST_VIEWED_ASSETS)) {
818    
819                            return false;
820                    }
821    
822                    return true;
823            }
824    
825            public Boolean isShowEnablePermissions() {
826                    if (PropsValues.ASSET_PUBLISHER_SEARCH_WITH_INDEX) {
827                            return false;
828                    }
829    
830                    return PropsValues.ASSET_PUBLISHER_PERMISSION_CHECKING_CONFIGURABLE;
831            }
832    
833            public boolean isShowEnableRelatedAssets() {
834                    String rootPortletId = getRootPortletId();
835    
836                    if (rootPortletId.equals(PortletKeys.RELATED_ASSETS)) {
837                            return false;
838                    }
839    
840                    return true;
841            }
842    
843            public boolean isShowExtraInfo() {
844                    if (_showExtraInfo == null) {
845                            _showExtraInfo = GetterUtil.getBoolean(
846                                    _portletPreferences.getValue("showExtraInfo", null), true);
847                    }
848    
849                    return _showExtraInfo;
850            }
851    
852            public boolean isShowMetadataDescriptions() {
853                    if (_showMetadataDescriptions == null) {
854                            _showMetadataDescriptions = GetterUtil.getBoolean(
855                                    _portletPreferences.getValue("showMetadataDescriptions", null),
856                                    true);
857                    }
858    
859                    return _showMetadataDescriptions;
860            }
861    
862            public boolean isShowOnlyLayoutAssets() {
863                    if (_showOnlyLayoutAssets == null) {
864                            _showOnlyLayoutAssets = GetterUtil.getBoolean(
865                                    _portletPreferences.getValue("showOnlyLayoutAssets", null));
866                    }
867    
868                    return _showOnlyLayoutAssets;
869            }
870    
871            public boolean isShowScopeSelector() {
872                    String rootPortletId = getRootPortletId();
873    
874                    if (rootPortletId.equals(PortletKeys.RELATED_ASSETS)) {
875                            return false;
876                    }
877    
878                    return true;
879            }
880    
881            public boolean isShowSubtypeFieldsFilter() {
882                    String rootPortletId = getRootPortletId();
883    
884                    if (!PropsValues.ASSET_PUBLISHER_SEARCH_WITH_INDEX ||
885                            rootPortletId.equals(PortletKeys.RELATED_ASSETS)) {
886    
887                            return false;
888                    }
889    
890                    return true;
891            }
892    
893            public boolean isSubtypeFieldsFilterEnabled() {
894                    if (_subtypeFieldsFilterEnabled == null) {
895                            _subtypeFieldsFilterEnabled = GetterUtil.getBoolean(
896                                    _portletPreferences.getValue(
897                                            "subtypeFieldsFilterEnabled", Boolean.FALSE.toString()));
898                    }
899    
900                    return _subtypeFieldsFilterEnabled;
901            }
902    
903            public void setSelectionStyle(String selectionStyle) {
904                    _selectionStyle = selectionStyle;
905            }
906    
907            public void setShowContextLink(Boolean showContextLink) {
908                    _showContextLink = showContextLink;
909            }
910    
911            protected void configureSubtypeFieldFilter(
912                            AssetEntryQuery assetEntryQuery, Locale locale)
913                    throws Exception {
914    
915                    long[] classNameIds = getClassNameIds();
916                    long[] classTypeIds = getClassTypeIds();
917    
918                    if (!isSubtypeFieldsFilterEnabled() || (classNameIds.length != 1) ||
919                            (classTypeIds.length != 1) ||
920                            Validator.isNull(getDDMStructureFieldName()) ||
921                            Validator.isNull(getDDMStructureFieldValue())) {
922    
923                            return;
924                    }
925    
926                    AssetRendererFactory assetRendererFactory =
927                            AssetRendererFactoryRegistryUtil.
928                                    getAssetRendererFactoryByClassNameId(classNameIds[0]);
929    
930                    ClassTypeReader classTypeReader =
931                            assetRendererFactory.getClassTypeReader();
932    
933                    ClassType classType = classTypeReader.getClassType(
934                            classTypeIds[0], locale);
935    
936                    ClassTypeField classTypeField = classType.getClassTypeField(
937                            getDDMStructureFieldName());
938    
939                    assetEntryQuery.setAttribute(
940                            "ddmStructureFieldName",
941                            DDMIndexerUtil.encodeName(
942                                    classTypeField.getClassTypeId(), getDDMStructureFieldName(),
943                                    locale));
944                    assetEntryQuery.setAttribute(
945                            "ddmStructureFieldValue", getDDMStructureFieldValue());
946            }
947    
948            protected String getPortletName() {
949                    PortletConfig portletConfig = (PortletConfig)_request.getAttribute(
950                            JavaConstants.JAVAX_PORTLET_CONFIG);
951    
952                    if (portletConfig == null) {
953                            return StringPool.BLANK;
954                    }
955    
956                    return portletConfig.getPortletName();
957            }
958    
959            protected void setDDMStructure() throws Exception {
960                    ThemeDisplay themeDisplay = (ThemeDisplay)_request.getAttribute(
961                            WebKeys.THEME_DISPLAY);
962    
963                    _ddmStructureDisplayFieldValue = StringPool.BLANK;
964                    _ddmStructureFieldLabel = StringPool.BLANK;
965                    _ddmStructureFieldName = StringPool.BLANK;
966                    _ddmStructureFieldValue = null;
967    
968                    long[] classNameIds = getClassNameIds();
969                    long[] classTypeIds = getClassTypeIds();
970    
971                    if (!isSubtypeFieldsFilterEnabled() || (classNameIds.length != 1) ||
972                            (classTypeIds.length != 1)) {
973    
974                            return;
975                    }
976    
977                    _ddmStructureDisplayFieldValue = GetterUtil.getString(
978                            _portletPreferences.getValue(
979                                    "ddmStructureDisplayFieldValue", StringPool.BLANK));
980                    _ddmStructureFieldName = GetterUtil.getString(
981                            _portletPreferences.getValue(
982                                    "ddmStructureFieldName", StringPool.BLANK));
983                    _ddmStructureFieldValue = _portletPreferences.getValue(
984                            "ddmStructureFieldValue", StringPool.BLANK);
985    
986                    if (Validator.isNotNull(_ddmStructureFieldName) &&
987                            Validator.isNotNull(_ddmStructureFieldValue)) {
988    
989                            AssetRendererFactory assetRendererFactory =
990                                    AssetRendererFactoryRegistryUtil.
991                                            getAssetRendererFactoryByClassNameId(classNameIds[0]);
992    
993                            ClassTypeReader classTypeReader =
994                                    assetRendererFactory.getClassTypeReader();
995    
996                            ClassType classType = classTypeReader.getClassType(
997                                    classTypeIds[0], themeDisplay.getLocale());
998    
999                            ClassTypeField classTypeField = classType.getClassTypeField(
1000                                    _ddmStructureFieldName);
1001    
1002                            _ddmStructureFieldLabel = classTypeField.getLabel();
1003                    }
1004            }
1005    
1006            private Integer _abstractLength;
1007            private long[] _allAssetCategoryIds;
1008            private String[] _allAssetTagNames;
1009            private Boolean _anyAssetType;
1010            private String _assetLinkBehavior;
1011            private long[] _availableClassNameIds;
1012            private long[] _classNameIds;
1013            private long[] _classTypeIds;
1014            private String[] _compilerTagNames;
1015            private String _ddmStructureDisplayFieldValue;
1016            private String _ddmStructureFieldLabel;
1017            private String _ddmStructureFieldName;
1018            private String _ddmStructureFieldValue;
1019            private Integer _delta;
1020            private String _displayStyle;
1021            private Long _displayStyleGroupId;
1022            private Boolean _enableCommentRatings;
1023            private Boolean _enableComments;
1024            private Boolean _enableConversions;
1025            private Boolean _enableFlags;
1026            private Boolean _enablePermissions;
1027            private Boolean _enablePrint;
1028            private Boolean _enableRatings;
1029            private Boolean _enableRelatedAssets;
1030            private Boolean _enableRSS;
1031            private Boolean _enableSocialBookmarks;
1032            private Boolean _enableTagBasedNavigation;
1033            private Boolean _excludeZeroViewCount;
1034            private String[] _extensions;
1035            private long[] _groupIds;
1036            private Boolean _mergeLayoutTags;
1037            private Boolean _mergeURLTags;
1038            private String[] _metadataFields;
1039            private Boolean _openOfficeServerEnabled;
1040            private String _orderByColumn1;
1041            private String _orderByColumn2;
1042            private String _orderByType1;
1043            private String _orderByType2;
1044            private String _paginationType;
1045            private Long _portletDisplayDDMTemplateId;
1046            private final PortletPreferences _portletPreferences;
1047            private String _portletResource;
1048            private final HttpServletRequest _request;
1049            private String _rootPortletId;
1050            private Integer _rssDelta;
1051            private String _rssDisplayStyle;
1052            private String _rssFeedType;
1053            private String _rssName;
1054            private String _selectionStyle;
1055            private Boolean _showAddContentButton;
1056            private Boolean _showAssetTitle;
1057            private Boolean _showAvailableLocales;
1058            private Boolean _showContextLink;
1059            private Boolean _showExtraInfo;
1060            private Boolean _showMetadataDescriptions;
1061            private Boolean _showOnlyLayoutAssets;
1062            private String _socialBookmarksDisplayPosition;
1063            private String _socialBookmarksDisplayStyle;
1064            private Boolean _subtypeFieldsFilterEnabled;
1065    
1066    }