001    /**
002     * Copyright (c) 2000-2013 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.util;
016    
017    import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
018    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
019    import com.liferay.portal.kernel.dao.orm.Property;
020    import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
021    import com.liferay.portal.kernel.dao.orm.QueryUtil;
022    import com.liferay.portal.kernel.exception.PortalException;
023    import com.liferay.portal.kernel.exception.SystemException;
024    import com.liferay.portal.kernel.log.Log;
025    import com.liferay.portal.kernel.log.LogFactoryUtil;
026    import com.liferay.portal.kernel.servlet.SessionMessages;
027    import com.liferay.portal.kernel.util.Accessor;
028    import com.liferay.portal.kernel.util.ArrayUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.ListUtil;
032    import com.liferay.portal.kernel.util.LocaleUtil;
033    import com.liferay.portal.kernel.util.LocalizationUtil;
034    import com.liferay.portal.kernel.util.ParamUtil;
035    import com.liferay.portal.kernel.util.PrefsPropsUtil;
036    import com.liferay.portal.kernel.util.PrimitiveLongList;
037    import com.liferay.portal.kernel.util.PropsKeys;
038    import com.liferay.portal.kernel.util.PropsUtil;
039    import com.liferay.portal.kernel.util.StringPool;
040    import com.liferay.portal.kernel.util.StringUtil;
041    import com.liferay.portal.kernel.util.Validator;
042    import com.liferay.portal.kernel.xml.Document;
043    import com.liferay.portal.kernel.xml.Element;
044    import com.liferay.portal.kernel.xml.SAXReaderUtil;
045    import com.liferay.portal.model.Group;
046    import com.liferay.portal.model.GroupConstants;
047    import com.liferay.portal.model.Layout;
048    import com.liferay.portal.model.PortletConstants;
049    import com.liferay.portal.model.User;
050    import com.liferay.portal.security.auth.PrincipalException;
051    import com.liferay.portal.security.auth.PrincipalThreadLocal;
052    import com.liferay.portal.security.permission.ActionKeys;
053    import com.liferay.portal.security.permission.PermissionChecker;
054    import com.liferay.portal.service.GroupLocalServiceUtil;
055    import com.liferay.portal.service.LayoutLocalServiceUtil;
056    import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
057    import com.liferay.portal.service.SubscriptionLocalServiceUtil;
058    import com.liferay.portal.service.permission.GroupPermissionUtil;
059    import com.liferay.portal.service.permission.PortletPermissionUtil;
060    import com.liferay.portal.service.persistence.PortletPreferencesActionableDynamicQuery;
061    import com.liferay.portal.theme.ThemeDisplay;
062    import com.liferay.portal.util.PortalUtil;
063    import com.liferay.portal.util.PortletKeys;
064    import com.liferay.portal.util.PropsValues;
065    import com.liferay.portal.util.SubscriptionSender;
066    import com.liferay.portal.util.WebKeys;
067    import com.liferay.portlet.PortletPreferencesFactoryUtil;
068    import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
069    import com.liferay.portlet.asset.model.AssetCategory;
070    import com.liferay.portlet.asset.model.AssetEntry;
071    import com.liferay.portlet.asset.model.AssetRenderer;
072    import com.liferay.portlet.asset.model.AssetRendererFactory;
073    import com.liferay.portlet.asset.model.AssetTag;
074    import com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil;
075    import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
076    import com.liferay.portlet.asset.service.AssetEntryServiceUtil;
077    import com.liferay.portlet.asset.service.AssetTagLocalServiceUtil;
078    import com.liferay.portlet.asset.service.persistence.AssetEntryQuery;
079    import com.liferay.portlet.expando.model.ExpandoBridge;
080    import com.liferay.portlet.sites.util.SitesUtil;
081    import com.liferay.util.ContentUtil;
082    
083    import java.io.IOException;
084    import java.io.Serializable;
085    
086    import java.util.ArrayList;
087    import java.util.HashMap;
088    import java.util.Iterator;
089    import java.util.List;
090    import java.util.Locale;
091    import java.util.Map;
092    import java.util.concurrent.ConcurrentHashMap;
093    
094    import javax.portlet.PortletException;
095    import javax.portlet.PortletPreferences;
096    import javax.portlet.PortletRequest;
097    
098    import javax.servlet.http.HttpServletRequest;
099    import javax.servlet.http.HttpSession;
100    
101    /**
102     * @author Raymond Aug??
103     * @author Julio Camarero
104     */
105    public class AssetPublisherImpl implements AssetPublisher {
106    
107            public AssetPublisherImpl() {
108                    for (String assetEntryQueryProcessorClassName :
109                                    PropsValues.ASSET_PUBLISHER_ASSET_ENTRY_QUERY_PROCESSORS) {
110    
111                            try {
112                                    AssetEntryQueryProcessor assetEntryQueryProcessor =
113                                            (AssetEntryQueryProcessor)InstanceFactory.newInstance(
114                                                    assetEntryQueryProcessorClassName);
115    
116                                    registerAssetQueryProcessor(
117                                            assetEntryQueryProcessorClassName,
118                                            assetEntryQueryProcessor);
119                            }
120                            catch (Exception e) {
121                                    _log.error(e, e);
122                            }
123                    }
124            }
125    
126            @Override
127            public void addAndStoreSelection(
128                            PortletRequest portletRequest, String className, long classPK,
129                            int assetEntryOrder)
130                    throws Exception {
131    
132                    String referringPortletResource = ParamUtil.getString(
133                            portletRequest, "referringPortletResource");
134    
135                    if (Validator.isNull(referringPortletResource)) {
136                            return;
137                    }
138    
139                    ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
140                            WebKeys.THEME_DISPLAY);
141    
142                    Layout layout = LayoutLocalServiceUtil.getLayout(
143                            themeDisplay.getRefererPlid());
144    
145                    PortletPreferences portletPreferences =
146                            PortletPreferencesFactoryUtil.getPortletSetup(
147                                    themeDisplay.getScopeGroupId(), layout,
148                                    referringPortletResource, null);
149    
150                    String selectionStyle = portletPreferences.getValue(
151                            "selectionStyle", "dynamic");
152    
153                    if (selectionStyle.equals("dynamic")) {
154                            return;
155                    }
156    
157                    AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(
158                            className, classPK);
159    
160                    addSelection(
161                            themeDisplay, portletPreferences, referringPortletResource,
162                            assetEntry.getEntryId(), assetEntryOrder, className);
163    
164                    portletPreferences.store();
165            }
166    
167            @Override
168            public void addRecentFolderId(
169                    PortletRequest portletRequest, String className, long classPK) {
170    
171                    _getRecentFolderIds(portletRequest).put(className, classPK);
172            }
173    
174            @Override
175            public void addSelection(
176                            PortletRequest portletRequest,
177                            PortletPreferences portletPreferences, String portletId)
178                    throws Exception {
179    
180                    ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
181                            WebKeys.THEME_DISPLAY);
182    
183                    long assetEntryId = ParamUtil.getLong(portletRequest, "assetEntryId");
184                    int assetEntryOrder = ParamUtil.getInteger(
185                            portletRequest, "assetEntryOrder");
186                    String assetEntryType = ParamUtil.getString(
187                            portletRequest, "assetEntryType");
188    
189                    addSelection(
190                            themeDisplay, portletPreferences, portletId, assetEntryId,
191                            assetEntryOrder, assetEntryType);
192            }
193    
194            @Override
195            public void addSelection(
196                            ThemeDisplay themeDisplay, PortletPreferences portletPreferences,
197                            String portletId, long assetEntryId, int assetEntryOrder,
198                            String assetEntryType)
199                    throws Exception {
200    
201                    AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(
202                            assetEntryId);
203    
204                    String[] assetEntryXmls = portletPreferences.getValues(
205                            "assetEntryXml", new String[0]);
206    
207                    String assetEntryXml = _getAssetEntryXml(
208                            assetEntryType, assetEntry.getClassUuid());
209    
210                    if (!ArrayUtil.contains(assetEntryXmls, assetEntryXml)) {
211                            if (assetEntryOrder > -1) {
212                                    assetEntryXmls[assetEntryOrder] = assetEntryXml;
213                            }
214                            else {
215                                    assetEntryXmls = ArrayUtil.append(
216                                            assetEntryXmls, assetEntryXml);
217                            }
218    
219                            portletPreferences.setValues("assetEntryXml", assetEntryXmls);
220                    }
221    
222                    long plid = themeDisplay.getRefererPlid();
223    
224                    if (plid == 0) {
225                            plid = themeDisplay.getPlid();
226                    }
227    
228                    List<AssetEntry> assetEntries = new ArrayList<AssetEntry>();
229    
230                    assetEntries.add(assetEntry);
231    
232                    notifySubscribers(portletPreferences, plid, portletId, assetEntries);
233            }
234    
235            @Override
236            public void addUserAttributes(
237                            User user, String[] customUserAttributeNames,
238                            AssetEntryQuery assetEntryQuery)
239                    throws Exception {
240    
241                    if ((user == null) || (customUserAttributeNames.length == 0)) {
242                            return;
243                    }
244    
245                    Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(
246                            user.getCompanyId());
247    
248                    long[] allCategoryIds = assetEntryQuery.getAllCategoryIds();
249    
250                    PrimitiveLongList allCategoryIdsList = new PrimitiveLongList(
251                            allCategoryIds.length + customUserAttributeNames.length);
252    
253                    allCategoryIdsList.addAll(allCategoryIds);
254    
255                    for (String customUserAttributeName : customUserAttributeNames) {
256                            ExpandoBridge userCustomAttributes = user.getExpandoBridge();
257    
258                            Serializable userCustomFieldValue =
259                                    userCustomAttributes.getAttribute(customUserAttributeName);
260    
261                            if (userCustomFieldValue == null) {
262                                    continue;
263                            }
264    
265                            String userCustomFieldValueString = userCustomFieldValue.toString();
266    
267                            List<AssetCategory> assetCategories =
268                                    AssetCategoryLocalServiceUtil.search(
269                                            companyGroup.getGroupId(), userCustomFieldValueString,
270                                            new String[0], QueryUtil.ALL_POS, QueryUtil.ALL_POS);
271    
272                            for (AssetCategory assetCategory : assetCategories) {
273                                    allCategoryIdsList.add(assetCategory.getCategoryId());
274                            }
275                    }
276    
277                    assetEntryQuery.setAllCategoryIds(allCategoryIdsList.getArray());
278            }
279    
280            @Override
281            public void checkAssetEntries() throws Exception {
282                    ActionableDynamicQuery actionableDynamicQuery =
283                            new PortletPreferencesActionableDynamicQuery() {
284    
285                            @Override
286                            protected void addCriteria(DynamicQuery dynamicQuery) {
287                                    Property property = PropertyFactoryUtil.forName("portletId");
288    
289                                    String portletId =
290                                            PortletKeys.ASSET_PUBLISHER +
291                                                    PortletConstants.INSTANCE_SEPARATOR +
292                                                            StringPool.PERCENT;
293    
294                                    dynamicQuery.add(property.like(portletId));
295                            }
296    
297                            @Override
298                            protected void performAction(Object object)
299                                    throws PortalException, SystemException {
300    
301                                    _checkAssetEntries(
302                                            (com.liferay.portal.model.PortletPreferences)object);
303                            }
304    
305                    };
306    
307                    actionableDynamicQuery.performActions();
308            }
309    
310            @Override
311            public List<AssetEntry> getAssetEntries(
312                            PortletPreferences portletPreferences, Layout layout,
313                            long scopeGroupId, int max, boolean checkPermission)
314                    throws PortalException, SystemException {
315    
316                    AssetEntryQuery assetEntryQuery = getAssetEntryQuery(
317                            portletPreferences, new long[] {scopeGroupId});
318    
319                    boolean anyAssetType = GetterUtil.getBoolean(
320                            portletPreferences.getValue("anyAssetType", null), true);
321    
322                    if (!anyAssetType) {
323                            long[] availableClassNameIds =
324                                    AssetRendererFactoryRegistryUtil.getClassNameIds(
325                                            layout.getCompanyId());
326    
327                            long[] classNameIds = getClassNameIds(
328                                    portletPreferences, availableClassNameIds);
329    
330                            assetEntryQuery.setClassNameIds(classNameIds);
331                    }
332    
333                    long[] classTypeIds = GetterUtil.getLongValues(
334                            portletPreferences.getValues("classTypeIds", null));
335    
336                    assetEntryQuery.setClassTypeIds(classTypeIds);
337    
338                    boolean enablePermissions = GetterUtil.getBoolean(
339                            portletPreferences.getValue("enablePermissions", null));
340    
341                    assetEntryQuery.setEnablePermissions(enablePermissions);
342    
343                    assetEntryQuery.setEnd(max);
344    
345                    boolean excludeZeroViewCount = GetterUtil.getBoolean(
346                            portletPreferences.getValue("excludeZeroViewCount", null));
347    
348                    assetEntryQuery.setExcludeZeroViewCount(excludeZeroViewCount);
349    
350                    long[] groupIds = getGroupIds(portletPreferences, scopeGroupId, layout);
351    
352                    assetEntryQuery.setGroupIds(groupIds);
353    
354                    boolean showOnlyLayoutAssets = GetterUtil.getBoolean(
355                            portletPreferences.getValue("showOnlyLayoutAssets", null));
356    
357                    if (showOnlyLayoutAssets) {
358                            assetEntryQuery.setLayout(layout);
359                    }
360    
361                    String orderByColumn1 = GetterUtil.getString(
362                            portletPreferences.getValue("orderByColumn1", "modifiedDate"));
363    
364                    assetEntryQuery.setOrderByCol1(orderByColumn1);
365    
366                    String orderByColumn2 = GetterUtil.getString(
367                            portletPreferences.getValue("orderByColumn2", "title"));
368    
369                    assetEntryQuery.setOrderByCol2(orderByColumn2);
370    
371                    String orderByType1 = GetterUtil.getString(
372                            portletPreferences.getValue("orderByType1", "DESC"));
373    
374                    assetEntryQuery.setOrderByType1(orderByType1);
375    
376                    String orderByType2 = GetterUtil.getString(
377                            portletPreferences.getValue("orderByType2", "ASC"));
378    
379                    assetEntryQuery.setOrderByType2(orderByType2);
380    
381                    assetEntryQuery.setStart(0);
382    
383                    if (checkPermission) {
384                            return AssetEntryServiceUtil.getEntries(assetEntryQuery);
385                    }
386                    else {
387                            return AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
388                    }
389            }
390    
391            @Override
392            public List<AssetEntry> getAssetEntries(
393                            PortletRequest portletRequest,
394                            PortletPreferences portletPreferences,
395                            PermissionChecker permissionChecker, long[] groupIds,
396                            long[] allCategoryIds, String[] assetEntryXmls,
397                            String[] allTagNames, boolean deleteMissingAssetEntries,
398                            boolean checkPermission)
399                    throws Exception {
400    
401                    List<AssetEntry> assetEntries = getAssetEntries(
402                            portletRequest, portletPreferences, permissionChecker, groupIds,
403                            assetEntryXmls, deleteMissingAssetEntries, checkPermission);
404    
405                    if (assetEntries.isEmpty() ||
406                            (ArrayUtil.isEmpty(allCategoryIds) &&
407                             ArrayUtil.isEmpty(allTagNames))) {
408    
409                            return assetEntries;
410                    }
411    
412                    if (!ArrayUtil.isEmpty(allCategoryIds)) {
413                            assetEntries = _filterAssetCategoriesAssetEntries(
414                                    assetEntries, allCategoryIds);
415                    }
416    
417                    if (!ArrayUtil.isEmpty(allTagNames)) {
418                            assetEntries = _filterAssetTagNamesAssetEntries(
419                                    assetEntries, allTagNames);
420                    }
421    
422                    return assetEntries;
423            }
424    
425            @Override
426            public List<AssetEntry> getAssetEntries(
427                            PortletRequest portletRequest,
428                            PortletPreferences portletPreferences,
429                            PermissionChecker permissionChecker, long[] groupIds,
430                            String[] assetEntryXmls, boolean deleteMissingAssetEntries,
431                            boolean checkPermission)
432                    throws Exception {
433    
434                    List<AssetEntry> assetEntries = new ArrayList<AssetEntry>();
435    
436                    List<String> missingAssetEntryUuids = new ArrayList<String>();
437    
438                    for (String assetEntryXml : assetEntryXmls) {
439                            Document document = SAXReaderUtil.read(assetEntryXml);
440    
441                            Element rootElement = document.getRootElement();
442    
443                            String assetEntryUuid = rootElement.elementText("asset-entry-uuid");
444    
445                            AssetEntry assetEntry = null;
446    
447                            for (long groupId : groupIds) {
448                                    assetEntry = AssetEntryLocalServiceUtil.fetchEntry(
449                                            groupId, assetEntryUuid);
450    
451                                    if (assetEntry != null) {
452                                            break;
453                                    }
454                            }
455    
456                            if (assetEntry == null) {
457                                    if (deleteMissingAssetEntries) {
458                                            missingAssetEntryUuids.add(assetEntryUuid);
459                                    }
460    
461                                    continue;
462                            }
463    
464                            if (!assetEntry.isVisible()) {
465                                    continue;
466                            }
467    
468                            AssetRendererFactory assetRendererFactory =
469                                    AssetRendererFactoryRegistryUtil.
470                                            getAssetRendererFactoryByClassName(
471                                                    assetEntry.getClassName());
472    
473                            AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(
474                                    assetEntry.getClassPK());
475    
476                            if (!assetRendererFactory.isActive(
477                                            permissionChecker.getCompanyId())) {
478    
479                                    if (deleteMissingAssetEntries) {
480                                            missingAssetEntryUuids.add(assetEntryUuid);
481                                    }
482    
483                                    continue;
484                            }
485    
486                            if (checkPermission &&
487                                    (!assetRenderer.isDisplayable() ||
488                                     !assetRenderer.hasViewPermission(permissionChecker))) {
489    
490                                    continue;
491                            }
492    
493                            assetEntries.add(assetEntry);
494                    }
495    
496                    if (deleteMissingAssetEntries) {
497                            AssetPublisherUtil.removeAndStoreSelection(
498                                    missingAssetEntryUuids, portletPreferences);
499    
500                            if (!missingAssetEntryUuids.isEmpty()) {
501                                    SessionMessages.add(
502                                            portletRequest, "deletedMissingAssetEntries",
503                                            missingAssetEntryUuids);
504                            }
505                    }
506    
507                    return assetEntries;
508            }
509    
510            @Override
511            public AssetEntryQuery getAssetEntryQuery(
512                            PortletPreferences portletPreferences, long[] scopeGroupIds)
513                    throws PortalException, SystemException {
514    
515                    AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
516    
517                    long[] allAssetCategoryIds = new long[0];
518                    long[] anyAssetCategoryIds = new long[0];
519                    long[] notAllAssetCategoryIds = new long[0];
520                    long[] notAnyAssetCategoryIds = new long[0];
521    
522                    String[] allAssetTagNames = new String[0];
523                    String[] anyAssetTagNames = new String[0];
524                    String[] notAllAssetTagNames = new String[0];
525                    String[] notAnyAssetTagNames = new String[0];
526    
527                    for (int i = 0; true; i++) {
528                            String[] queryValues = portletPreferences.getValues(
529                                    "queryValues" + i, null);
530    
531                            if (ArrayUtil.isEmpty(queryValues)) {
532                                    break;
533                            }
534    
535                            boolean queryContains = GetterUtil.getBoolean(
536                                    portletPreferences.getValue(
537                                            "queryContains" + i, StringPool.BLANK));
538                            boolean queryAndOperator = GetterUtil.getBoolean(
539                                    portletPreferences.getValue(
540                                            "queryAndOperator" + i, StringPool.BLANK));
541                            String queryName = portletPreferences.getValue(
542                                    "queryName" + i, StringPool.BLANK);
543    
544                            if (Validator.equals(queryName, "assetCategories")) {
545                                    long[] assetCategoryIds = GetterUtil.getLongValues(queryValues);
546    
547                                    if (queryContains && queryAndOperator) {
548                                            allAssetCategoryIds = assetCategoryIds;
549                                    }
550                                    else if (queryContains && !queryAndOperator) {
551                                            anyAssetCategoryIds = assetCategoryIds;
552                                    }
553                                    else if (!queryContains && queryAndOperator) {
554                                            notAllAssetCategoryIds = assetCategoryIds;
555                                    }
556                                    else {
557                                            notAnyAssetCategoryIds = assetCategoryIds;
558                                    }
559                            }
560                            else {
561                                    if (queryContains && queryAndOperator) {
562                                            allAssetTagNames = queryValues;
563                                    }
564                                    else if (queryContains && !queryAndOperator) {
565                                            anyAssetTagNames = queryValues;
566                                    }
567                                    else if (!queryContains && queryAndOperator) {
568                                            notAllAssetTagNames = queryValues;
569                                    }
570                                    else {
571                                            notAnyAssetTagNames = queryValues;
572                                    }
573                            }
574                    }
575    
576                    assetEntryQuery.setAllCategoryIds(allAssetCategoryIds);
577    
578                    for (String assetTagName : allAssetTagNames) {
579                            long[] allAssetTagIds = AssetTagLocalServiceUtil.getTagIds(
580                                    scopeGroupIds, assetTagName);
581    
582                            assetEntryQuery.addAllTagIdsArray(allAssetTagIds);
583                    }
584    
585                    assetEntryQuery.setAnyCategoryIds(anyAssetCategoryIds);
586    
587                    long[] anyAssetTagIds = AssetTagLocalServiceUtil.getTagIds(
588                            scopeGroupIds, anyAssetTagNames);
589    
590                    assetEntryQuery.setAnyTagIds(anyAssetTagIds);
591    
592                    assetEntryQuery.setNotAllCategoryIds(notAllAssetCategoryIds);
593    
594                    for (String assetTagName : notAllAssetTagNames) {
595                            long[] notAllAssetTagIds = AssetTagLocalServiceUtil.getTagIds(
596                                    scopeGroupIds, assetTagName);
597    
598                            assetEntryQuery.addNotAllTagIdsArray(notAllAssetTagIds);
599                    }
600    
601                    assetEntryQuery.setNotAnyCategoryIds(notAnyAssetCategoryIds);
602    
603                    long[] notAnyAssetTagIds = AssetTagLocalServiceUtil.getTagIds(
604                            scopeGroupIds, notAnyAssetTagNames);
605    
606                    assetEntryQuery.setNotAnyTagIds(notAnyAssetTagIds);
607    
608                    return assetEntryQuery;
609            }
610    
611            @Override
612            public String[] getAssetTagNames(
613                            PortletPreferences portletPreferences, long scopeGroupId)
614                    throws Exception {
615    
616                    String[] allAssetTagNames = new String[0];
617    
618                    for (int i = 0; true; i++) {
619                            String[] queryValues = portletPreferences.getValues(
620                                    "queryValues" + i, null);
621    
622                            if (ArrayUtil.isEmpty(queryValues)) {
623                                    break;
624                            }
625    
626                            boolean queryContains = GetterUtil.getBoolean(
627                                    portletPreferences.getValue(
628                                            "queryContains" + i, StringPool.BLANK));
629                            boolean queryAndOperator = GetterUtil.getBoolean(
630                                    portletPreferences.getValue(
631                                            "queryAndOperator" + i, StringPool.BLANK));
632                            String queryName = portletPreferences.getValue(
633                                    "queryName" + i, StringPool.BLANK);
634    
635                            if (!Validator.equals(queryName, "assetCategories") &&
636                                    queryContains && queryAndOperator) {
637    
638                                    allAssetTagNames = queryValues;
639                            }
640                    }
641    
642                    return allAssetTagNames;
643            }
644    
645            @Override
646            public String getClassName(AssetRendererFactory assetRendererFactory) {
647                    Class<?> clazz = assetRendererFactory.getClass();
648    
649                    String className = clazz.getName();
650    
651                    int pos = className.lastIndexOf(StringPool.PERIOD);
652    
653                    return className.substring(pos + 1);
654            }
655    
656            @Override
657            public long[] getClassNameIds(
658                    PortletPreferences portletPreferences, long[] availableClassNameIds) {
659    
660                    boolean anyAssetType = GetterUtil.getBoolean(
661                            portletPreferences.getValue(
662                                    "anyAssetType", Boolean.TRUE.toString()));
663                    String selectionStyle = portletPreferences.getValue(
664                            "selectionStyle", "dynamic");
665    
666                    if (anyAssetType || selectionStyle.equals("manual")) {
667                            return availableClassNameIds;
668                    }
669    
670                    long defaultClassNameId = GetterUtil.getLong(
671                            portletPreferences.getValue("anyAssetType", null));
672    
673                    if (defaultClassNameId > 0) {
674                            return new long[] {defaultClassNameId};
675                    }
676    
677                    long[] classNameIds = GetterUtil.getLongValues(
678                            portletPreferences.getValues("classNameIds", null));
679    
680                    if (ArrayUtil.isNotEmpty(classNameIds)) {
681                            return classNameIds;
682                    }
683                    else {
684                            return availableClassNameIds;
685                    }
686            }
687    
688            @Override
689            public Long[] getClassTypeIds(
690                    PortletPreferences portletPreferences, String className,
691                    Long[] availableClassTypeIds) {
692    
693                    boolean anyAssetType = GetterUtil.getBoolean(
694                            portletPreferences.getValue(
695                                    "anyClassType" + className, Boolean.TRUE.toString()));
696    
697                    if (anyAssetType) {
698                            return availableClassTypeIds;
699                    }
700    
701                    long defaultClassTypeId = GetterUtil.getLong(
702                            portletPreferences.getValue("anyClassType" + className, null));
703    
704                    if (defaultClassTypeId > 0) {
705                            return new Long[] {defaultClassTypeId};
706                    }
707    
708                    Long[] classTypeIds = ArrayUtil.toArray(
709                            StringUtil.split(
710                                    portletPreferences.getValue(
711                                            "classTypeIds" + className, null), 0L));
712    
713                    if (classTypeIds != null) {
714                            return classTypeIds;
715                    }
716                    else {
717                            return availableClassTypeIds;
718                    }
719            }
720    
721            @Override
722            public Map<Locale, String> getEmailAssetEntryAddedBodyMap(
723                    PortletPreferences portletPreferences) {
724    
725                    Map<Locale, String> map = LocalizationUtil.getLocalizationMap(
726                            portletPreferences, "emailAssetEntryAddedBody");
727    
728                    Locale defaultLocale = LocaleUtil.getSiteDefault();
729    
730                    String defaultValue = map.get(defaultLocale);
731    
732                    if (Validator.isNotNull(defaultValue)) {
733                            return map;
734                    }
735    
736                    map.put(
737                            defaultLocale,
738                            ContentUtil.get(
739                                    PropsUtil.get(
740                                            PropsKeys.ASSET_PUBLISHER_EMAIL_ASSET_ENTRY_ADDED_BODY)));
741    
742                    return map;
743            }
744    
745            @Override
746            public boolean getEmailAssetEntryAddedEnabled(
747                    PortletPreferences portletPreferences) {
748    
749                    String emailAssetEntryAddedEnabled = portletPreferences.getValue(
750                            "emailAssetEntryAddedEnabled", StringPool.BLANK);
751    
752                    if (Validator.isNotNull(emailAssetEntryAddedEnabled)) {
753                            return GetterUtil.getBoolean(emailAssetEntryAddedEnabled);
754                    }
755                    else {
756                            return PropsValues.ASSET_PUBLISHER_EMAIL_ASSET_ENTRY_ADDED_ENABLED;
757                    }
758            }
759    
760            @Override
761            public Map<Locale, String> getEmailAssetEntryAddedSubjectMap(
762                    PortletPreferences portletPreferences) {
763    
764                    Map<Locale, String> map = LocalizationUtil.getLocalizationMap(
765                            portletPreferences, "emailAssetEntryAddedSubject");
766    
767                    Locale defaultLocale = LocaleUtil.getSiteDefault();
768    
769                    String defaultValue = map.get(defaultLocale);
770    
771                    if (Validator.isNotNull(defaultValue)) {
772                            return map;
773                    }
774    
775                    map.put(
776                            defaultLocale,
777                            ContentUtil.get(
778                                    PropsUtil.get(
779                                            PropsKeys.ASSET_PUBLISHER_EMAIL_ASSET_ENTRY_ADDED_SUBJECT))
780                    );
781    
782                    return map;
783            }
784    
785            @Override
786            public String getEmailFromAddress(
787                            PortletPreferences portletPreferences, long companyId)
788                    throws SystemException {
789    
790                    return PortalUtil.getEmailFromAddress(
791                            portletPreferences, companyId,
792                            PropsValues.ASSET_PUBLISHER_EMAIL_FROM_ADDRESS);
793            }
794    
795            @Override
796            public String getEmailFromName(
797                            PortletPreferences portletPreferences, long companyId)
798                    throws SystemException {
799    
800                    return PortalUtil.getEmailFromName(
801                            portletPreferences, companyId,
802                            PropsValues.ASSET_PUBLISHER_EMAIL_FROM_NAME);
803            }
804    
805            @Override
806            public long getGroupIdFromScopeId(
807                            String scopeId, long siteGroupId, boolean privateLayout)
808                    throws PortalException, SystemException {
809    
810                    if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) {
811                            String scopeIdSuffix = scopeId.substring(
812                                    SCOPE_ID_CHILD_GROUP_PREFIX.length());
813    
814                            long childGroupId = GetterUtil.getLong(scopeIdSuffix);
815    
816                            Group childGroup = GroupLocalServiceUtil.getGroup(childGroupId);
817    
818                            if (!childGroup.isChild(siteGroupId)) {
819                                    throw new PrincipalException();
820                            }
821    
822                            return childGroupId;
823                    }
824                    else if (scopeId.startsWith(SCOPE_ID_GROUP_PREFIX)) {
825                            String scopeIdSuffix = scopeId.substring(
826                                    SCOPE_ID_GROUP_PREFIX.length());
827    
828                            if (scopeIdSuffix.equals(GroupConstants.DEFAULT)) {
829                                    return siteGroupId;
830                            }
831    
832                            return GetterUtil.getLong(scopeIdSuffix);
833                    }
834                    else if (scopeId.startsWith(SCOPE_ID_LAYOUT_UUID_PREFIX)) {
835                            String layoutUuid = scopeId.substring(
836                                    SCOPE_ID_LAYOUT_UUID_PREFIX.length());
837    
838                            Layout scopeIdLayout =
839                                    LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(
840                                            layoutUuid, siteGroupId, privateLayout);
841    
842                            Group scopeIdGroup = null;
843    
844                            if (scopeIdLayout.hasScopeGroup()) {
845                                    scopeIdGroup = scopeIdLayout.getScopeGroup();
846                            }
847                            else {
848                                    scopeIdGroup = GroupLocalServiceUtil.addGroup(
849                                            PrincipalThreadLocal.getUserId(),
850                                            GroupConstants.DEFAULT_PARENT_GROUP_ID,
851                                            Layout.class.getName(), scopeIdLayout.getPlid(),
852                                            GroupConstants.DEFAULT_LIVE_GROUP_ID,
853                                            String.valueOf(scopeIdLayout.getPlid()), null, 0, true,
854                                            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION, null, false,
855                                            true, null);
856                            }
857    
858                            return scopeIdGroup.getGroupId();
859                    }
860                    else if (scopeId.startsWith(SCOPE_ID_LAYOUT_PREFIX)) {
861    
862                            // Legacy portlet preferences
863    
864                            String scopeIdSuffix = scopeId.substring(
865                                    SCOPE_ID_LAYOUT_PREFIX.length());
866    
867                            long scopeIdLayoutId = GetterUtil.getLong(scopeIdSuffix);
868    
869                            Layout scopeIdLayout = LayoutLocalServiceUtil.getLayout(
870                                    siteGroupId, privateLayout, scopeIdLayoutId);
871    
872                            Group scopeIdGroup = scopeIdLayout.getScopeGroup();
873    
874                            return scopeIdGroup.getGroupId();
875                    }
876                    else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) {
877                            String scopeIdSuffix = scopeId.substring(
878                                    SCOPE_ID_PARENT_GROUP_PREFIX.length());
879    
880                            long parentGroupId = GetterUtil.getLong(scopeIdSuffix);
881    
882                            Group parentGroup = GroupLocalServiceUtil.getGroup(parentGroupId);
883    
884                            if (!SitesUtil.isContentSharingWithChildrenEnabled(parentGroup)) {
885                                    throw new PrincipalException();
886                            }
887    
888                            Group group = GroupLocalServiceUtil.getGroup(siteGroupId);
889    
890                            if (!group.isChild(parentGroupId)) {
891                                    throw new PrincipalException();
892                            }
893    
894                            return parentGroupId;
895                    }
896                    else {
897                            throw new IllegalArgumentException("Invalid scope ID " + scopeId);
898                    }
899            }
900    
901            @Override
902            public long[] getGroupIds(
903                    PortletPreferences portletPreferences, long scopeGroupId,
904                    Layout layout) {
905    
906                    String[] scopeIds = portletPreferences.getValues(
907                            "scopeIds", new String[] {SCOPE_ID_GROUP_PREFIX + scopeGroupId});
908    
909                    List<Long> groupIds = new ArrayList<Long>();
910    
911                    for (String scopeId : scopeIds) {
912                            try {
913                                    long groupId = getGroupIdFromScopeId(
914                                            scopeId, scopeGroupId, layout.isPrivateLayout());
915    
916                                    groupIds.add(groupId);
917                            }
918                            catch (Exception e) {
919                                    continue;
920                            }
921                    }
922    
923                    return ArrayUtil.toLongArray(groupIds);
924            }
925    
926            @Override
927            public long getRecentFolderId(
928                    PortletRequest portletRequest, String className) {
929    
930                    Long classPK = _getRecentFolderIds(portletRequest).get(className);
931    
932                    if (classPK == null) {
933                            return 0;
934                    }
935                    else {
936                            return classPK.longValue();
937                    }
938            }
939    
940            @Override
941            public String getScopeId(Group group, long scopeGroupId)
942                    throws PortalException, SystemException {
943    
944                    String key = null;
945    
946                    if (group.isLayout()) {
947                            Layout layout = LayoutLocalServiceUtil.getLayout(
948                                    group.getClassPK());
949    
950                            key = SCOPE_ID_LAYOUT_UUID_PREFIX + layout.getUuid();
951                    }
952                    else if (group.isLayoutPrototype() ||
953                                     (group.getGroupId() == scopeGroupId)) {
954    
955                            key = SCOPE_ID_GROUP_PREFIX + GroupConstants.DEFAULT;
956                    }
957                    else {
958                            Group scopeGroup = GroupLocalServiceUtil.getGroup(scopeGroupId);
959    
960                            if (scopeGroup.hasAncestor(group.getGroupId()) &&
961                                    SitesUtil.isContentSharingWithChildrenEnabled(group)) {
962    
963                                    key = SCOPE_ID_PARENT_GROUP_PREFIX + group.getGroupId();
964                            }
965                            else if (group.hasAncestor(scopeGroup.getGroupId())) {
966                                    key = SCOPE_ID_CHILD_GROUP_PREFIX + group.getGroupId();
967                            }
968                            else {
969                                    key = SCOPE_ID_GROUP_PREFIX + group.getGroupId();
970                            }
971                    }
972    
973                    return key;
974            }
975    
976            @Override
977            public boolean isScopeIdSelectable(
978                            PermissionChecker permissionChecker, String scopeId,
979                            long companyGroupId, Layout layout)
980                    throws PortalException, SystemException {
981    
982                    long groupId = getGroupIdFromScopeId(
983                            scopeId, layout.getGroupId(), layout.isPrivateLayout());
984    
985                    if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) {
986                            Group group = GroupLocalServiceUtil.getGroup(groupId);
987    
988                            if (!group.hasAncestor(layout.getGroupId())) {
989                                    return false;
990                            }
991                    }
992                    else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) {
993                            Group siteGroup = layout.getGroup();
994    
995                            if (!siteGroup.hasAncestor(groupId)) {
996                                    return false;
997                            }
998    
999                            Group group = GroupLocalServiceUtil.getGroup(groupId);
1000    
1001                            if (SitesUtil.isContentSharingWithChildrenEnabled(group)) {
1002                                    return true;
1003                            }
1004    
1005                            if (!PrefsPropsUtil.getBoolean(
1006                                            layout.getCompanyId(),
1007                                            PropsKeys.
1008                                            SITES_CONTENT_SHARING_THROUGH_ADMINISTRATORS_ENABLED)) {
1009    
1010                                    return false;
1011                            }
1012    
1013                            return GroupPermissionUtil.contains(
1014                                    permissionChecker, groupId, ActionKeys.UPDATE);
1015                    }
1016                    else if (groupId != companyGroupId) {
1017                            return GroupPermissionUtil.contains(
1018                                    permissionChecker, groupId, ActionKeys.UPDATE);
1019                    }
1020    
1021                    return true;
1022            }
1023    
1024            @Override
1025            public boolean isSubscribed(
1026                            long companyId, long userId, long plid, String portletId)
1027                    throws PortalException, SystemException {
1028    
1029                    return SubscriptionLocalServiceUtil.isSubscribed(
1030                            companyId, userId,
1031                            com.liferay.portal.model.PortletPreferences.class.getName(),
1032                            _getPortletPreferencesId(plid, portletId));
1033            }
1034    
1035            @Override
1036            public void notifySubscribers(
1037                            PortletPreferences portletPreferences, long plid, String portletId,
1038                            List<AssetEntry> assetEntries)
1039                    throws PortalException, SystemException {
1040    
1041                    if (!getEmailAssetEntryAddedEnabled(portletPreferences) ||
1042                            assetEntries.isEmpty()) {
1043    
1044                            return;
1045                    }
1046    
1047                    AssetEntry assetEntry = assetEntries.get(0);
1048    
1049                    String fromName = getEmailFromName(
1050                            portletPreferences, assetEntry.getCompanyId());
1051                    String fromAddress = getEmailFromAddress(
1052                            portletPreferences, assetEntry.getCompanyId());
1053    
1054                    Map<Locale, String> localizedSubjectMap =
1055                            getEmailAssetEntryAddedSubjectMap(portletPreferences);
1056                    Map<Locale, String> localizedBodyMap = getEmailAssetEntryAddedBodyMap(
1057                            portletPreferences);
1058    
1059                    SubscriptionSender subscriptionSender = new SubscriptionSender();
1060    
1061                    subscriptionSender.setCompanyId(assetEntry.getCompanyId());
1062                    subscriptionSender.setContextAttributes(
1063                            "[$ASSET_ENTRIES$]",
1064                            ListUtil.toString(
1065                                    assetEntries, _titleAccessor, StringPool.COMMA_AND_SPACE));
1066                    subscriptionSender.setContextUserPrefix("ASSET_PUBLISHER");
1067                    subscriptionSender.setFrom(fromAddress, fromName);
1068                    subscriptionSender.setHtmlFormat(true);
1069                    subscriptionSender.setLocalizedBodyMap(localizedBodyMap);
1070                    subscriptionSender.setLocalizedSubjectMap(localizedSubjectMap);
1071                    subscriptionSender.setMailId("asset_entry", assetEntry.getEntryId());
1072                    subscriptionSender.setPortletId(PortletKeys.ASSET_PUBLISHER);
1073                    subscriptionSender.setReplyToAddress(fromAddress);
1074    
1075                    subscriptionSender.addPersistedSubscribers(
1076                            com.liferay.portal.model.PortletPreferences.class.getName(),
1077                            _getPortletPreferencesId(plid, portletId));
1078    
1079                    subscriptionSender.flushNotificationsAsync();
1080            }
1081    
1082            @Override
1083            public void processAssetEntryQuery(
1084                            User user, PortletPreferences portletPreferences,
1085                            AssetEntryQuery assetEntryQuery)
1086                    throws Exception {
1087    
1088                    for (AssetEntryQueryProcessor assetEntryQueryProcessor :
1089                                    _assetEntryQueryProcessor.values()) {
1090    
1091                            assetEntryQueryProcessor.processAssetEntryQuery(
1092                                    user, portletPreferences, assetEntryQuery);
1093                    }
1094            }
1095    
1096            @Override
1097            public void registerAssetQueryProcessor(
1098                    String assetQueryProcessorClassName,
1099                    AssetEntryQueryProcessor assetQueryProcessor) {
1100    
1101                    if (assetQueryProcessor == null) {
1102                            return;
1103                    }
1104    
1105                    _assetEntryQueryProcessor.put(
1106                            assetQueryProcessorClassName, assetQueryProcessor);
1107            }
1108    
1109            @Override
1110            public void removeAndStoreSelection(
1111                            List<String> assetEntryUuids, PortletPreferences portletPreferences)
1112                    throws Exception {
1113    
1114                    if (assetEntryUuids.size() == 0) {
1115                            return;
1116                    }
1117    
1118                    String[] assetEntryXmls = portletPreferences.getValues(
1119                            "assetEntryXml", new String[0]);
1120    
1121                    List<String> assetEntryXmlsList = ListUtil.fromArray(assetEntryXmls);
1122    
1123                    Iterator<String> itr = assetEntryXmlsList.iterator();
1124    
1125                    while (itr.hasNext()) {
1126                            String assetEntryXml = itr.next();
1127    
1128                            Document document = SAXReaderUtil.read(assetEntryXml);
1129    
1130                            Element rootElement = document.getRootElement();
1131    
1132                            String assetEntryUuid = rootElement.elementText("asset-entry-uuid");
1133    
1134                            if (assetEntryUuids.contains(assetEntryUuid)) {
1135                                    itr.remove();
1136                            }
1137                    }
1138    
1139                    portletPreferences.setValues(
1140                            "assetEntryXml",
1141                            assetEntryXmlsList.toArray(new String[assetEntryXmlsList.size()]));
1142    
1143                    portletPreferences.store();
1144            }
1145    
1146            @Override
1147            public void removeRecentFolderId(
1148                    PortletRequest portletRequest, String className, long classPK) {
1149    
1150                    if (getRecentFolderId(portletRequest, className) == classPK) {
1151                            _getRecentFolderIds(portletRequest).remove(className);
1152                    }
1153            }
1154    
1155            @Override
1156            public void subscribe(
1157                            PermissionChecker permissionChecker, long groupId, long plid,
1158                            String portletId)
1159                    throws PortalException, SystemException {
1160    
1161                    PortletPermissionUtil.check(
1162                            permissionChecker, plid, portletId, ActionKeys.SUBSCRIBE);
1163    
1164                    SubscriptionLocalServiceUtil.addSubscription(
1165                            permissionChecker.getUserId(), groupId,
1166                            com.liferay.portal.model.PortletPreferences.class.getName(),
1167                            _getPortletPreferencesId(plid, portletId));
1168            }
1169    
1170            @Override
1171            public void unregisterAssetQueryProcessor(
1172                    String assetQueryProcessorClassName) {
1173    
1174                    _assetEntryQueryProcessor.remove(assetQueryProcessorClassName);
1175            }
1176    
1177            @Override
1178            public void unsubscribe(
1179                            PermissionChecker permissionChecker, long plid, String portletId)
1180                    throws PortalException, SystemException {
1181    
1182                    PortletPermissionUtil.check(
1183                            permissionChecker, plid, portletId, ActionKeys.SUBSCRIBE);
1184    
1185                    SubscriptionLocalServiceUtil.deleteSubscription(
1186                            permissionChecker.getUserId(),
1187                            com.liferay.portal.model.PortletPreferences.class.getName(),
1188                            _getPortletPreferencesId(plid, portletId));
1189            }
1190    
1191            private void _checkAssetEntries(
1192                            com.liferay.portal.model.PortletPreferences
1193                            portletPreferencesModel)
1194                    throws PortalException, SystemException {
1195    
1196                    Layout layout = LayoutLocalServiceUtil.getLayout(
1197                            portletPreferencesModel.getPlid());
1198    
1199                    PortletPreferences portletPreferences =
1200                            PortletPreferencesFactoryUtil.fromXML(
1201                                    layout.getCompanyId(), portletPreferencesModel.getOwnerId(),
1202                                    portletPreferencesModel.getOwnerType(),
1203                                    portletPreferencesModel.getPlid(),
1204                                    portletPreferencesModel.getPortletId(),
1205                                    portletPreferencesModel.getPreferences());
1206    
1207                    if (!getEmailAssetEntryAddedEnabled(portletPreferences)) {
1208                            return;
1209                    }
1210    
1211                    List<AssetEntry> assetEntries = getAssetEntries(
1212                            portletPreferences, layout, layout.getGroupId(),
1213                            PropsValues.ASSET_PUBLISHER_DYNAMIC_SUBSCRIPTION_LIMIT, false);
1214    
1215                    if (assetEntries.isEmpty()) {
1216                            return;
1217                    }
1218    
1219                    long[] notifiedAssetEntryIds = GetterUtil.getLongValues(
1220                            portletPreferences.getValues("notifiedAssetEntryIds", null));
1221    
1222                    List<AssetEntry> newAssetEntries = new ArrayList<AssetEntry>();
1223    
1224                    for (int i = 0; i < assetEntries.size(); i++) {
1225                            AssetEntry assetEntry = assetEntries.get(i);
1226    
1227                            if (!ArrayUtil.contains(
1228                                            notifiedAssetEntryIds, assetEntry.getEntryId())) {
1229    
1230                                    newAssetEntries.add(assetEntry);
1231                            }
1232                    }
1233    
1234                    notifySubscribers(
1235                            portletPreferences, portletPreferencesModel.getPlid(),
1236                            portletPreferencesModel.getPortletId(), newAssetEntries);
1237    
1238                    try {
1239                            portletPreferences.setValues(
1240                                    "notifiedAssetEntryIds",
1241                                    StringUtil.split(
1242                                            ListUtil.toString(
1243                                                    assetEntries, AssetEntry.ENTRY_ID_ACCESSOR)));
1244    
1245                            portletPreferences.store();
1246                    }
1247                    catch (IOException ioe) {
1248                            throw new SystemException(ioe);
1249                    }
1250                    catch (PortletException pe) {
1251                            throw new SystemException(pe);
1252                    }
1253            }
1254    
1255            private List<AssetEntry> _filterAssetCategoriesAssetEntries(
1256                            List<AssetEntry> assetEntries, long[] assetCategoryIds)
1257                    throws Exception {
1258    
1259                    List<AssetEntry> filteredAssetEntries = new ArrayList<AssetEntry>();
1260    
1261                    for (AssetEntry assetEntry : assetEntries) {
1262                            if (ArrayUtil.containsAll(
1263                                            assetEntry.getCategoryIds(), assetCategoryIds)) {
1264    
1265                                    filteredAssetEntries.add(assetEntry);
1266                            }
1267                    }
1268    
1269                    return filteredAssetEntries;
1270            }
1271    
1272            private List<AssetEntry> _filterAssetTagNamesAssetEntries(
1273                            List<AssetEntry> assetEntries, String[] assetTagNames)
1274                    throws Exception {
1275    
1276                    List<AssetEntry> filteredAssetEntries = new ArrayList<AssetEntry>();
1277    
1278                    for (AssetEntry assetEntry : assetEntries) {
1279                            List<AssetTag> assetTags = assetEntry.getTags();
1280    
1281                            String[] assetEntryAssetTagNames = new String[assetTags.size()];
1282    
1283                            for (int i = 0; i < assetTags.size(); i++) {
1284                                    AssetTag assetTag = assetTags.get(i);
1285    
1286                                    assetEntryAssetTagNames[i] = assetTag.getName();
1287                            }
1288    
1289                            if (ArrayUtil.containsAll(assetEntryAssetTagNames, assetTagNames)) {
1290                                    filteredAssetEntries.add(assetEntry);
1291                            }
1292                    }
1293    
1294                    return filteredAssetEntries;
1295            }
1296    
1297            private String _getAssetEntryXml(
1298                    String assetEntryType, String assetEntryUuid) {
1299    
1300                    String xml = null;
1301    
1302                    try {
1303                            Document document = SAXReaderUtil.createDocument(StringPool.UTF8);
1304    
1305                            Element assetEntryElement = document.addElement("asset-entry");
1306    
1307                            Element assetEntryTypeElement = assetEntryElement.addElement(
1308                                    "asset-entry-type");
1309    
1310                            assetEntryTypeElement.addText(assetEntryType);
1311    
1312                            Element assetEntryUuidElement = assetEntryElement.addElement(
1313                                    "asset-entry-uuid");
1314    
1315                            assetEntryUuidElement.addText(assetEntryUuid);
1316    
1317                            xml = document.formattedString(StringPool.BLANK);
1318                    }
1319                    catch (IOException ioe) {
1320                            if (_log.isWarnEnabled()) {
1321                                    _log.warn(ioe);
1322                            }
1323                    }
1324    
1325                    return xml;
1326            }
1327    
1328            private long _getPortletPreferencesId(long plid, String portletId)
1329                    throws PortalException, SystemException {
1330    
1331                    com.liferay.portal.model.PortletPreferences portletPreferencesModel =
1332                            PortletPreferencesLocalServiceUtil.getPortletPreferences(
1333                                    PortletKeys.PREFS_OWNER_ID_DEFAULT,
1334                                    PortletKeys.PREFS_OWNER_TYPE_LAYOUT, plid, portletId);
1335    
1336                    return portletPreferencesModel.getPortletPreferencesId();
1337            }
1338    
1339            private Map<String, Long> _getRecentFolderIds(
1340                    PortletRequest portletRequest) {
1341    
1342                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
1343                            portletRequest);
1344                    HttpSession session = request.getSession();
1345    
1346                    ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
1347                            WebKeys.THEME_DISPLAY);
1348    
1349                    String key =
1350                            AssetPublisherUtil.class + StringPool.UNDERLINE +
1351                                    themeDisplay.getScopeGroupId();
1352    
1353                    Map<String, Long> recentFolderIds =
1354                            (Map<String, Long>)session.getAttribute(key);
1355    
1356                    if (recentFolderIds == null) {
1357                            recentFolderIds = new HashMap<String, Long>();
1358                    }
1359    
1360                    session.setAttribute(key, recentFolderIds);
1361    
1362                    return recentFolderIds;
1363            }
1364    
1365            private static Log _log = LogFactoryUtil.getLog(AssetPublisherImpl.class);
1366    
1367            private Map<String, AssetEntryQueryProcessor> _assetEntryQueryProcessor =
1368                    new ConcurrentHashMap<String, AssetEntryQueryProcessor>();
1369    
1370            private Accessor<AssetEntry, String> _titleAccessor =
1371                    new Accessor<AssetEntry, String>() {
1372    
1373                            @Override
1374                            public String get(AssetEntry assetEntry) {
1375                                    return assetEntry.getTitle(LocaleUtil.getSiteDefault());
1376                            }
1377    
1378                    };
1379    
1380    }