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