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