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