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.asset.util;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
022    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
023    import com.liferay.portal.kernel.portlet.LiferayWindowState;
024    import com.liferay.portal.kernel.search.Document;
025    import com.liferay.portal.kernel.search.Field;
026    import com.liferay.portal.kernel.search.Hits;
027    import com.liferay.portal.kernel.search.Indexer;
028    import com.liferay.portal.kernel.search.SearchContext;
029    import com.liferay.portal.kernel.search.SearchContextFactory;
030    import com.liferay.portal.kernel.search.Sort;
031    import com.liferay.portal.kernel.util.ArrayUtil;
032    import com.liferay.portal.kernel.util.CharPool;
033    import com.liferay.portal.kernel.util.Constants;
034    import com.liferay.portal.kernel.util.GetterUtil;
035    import com.liferay.portal.kernel.util.ListUtil;
036    import com.liferay.portal.kernel.util.LocaleUtil;
037    import com.liferay.portal.kernel.util.ParamUtil;
038    import com.liferay.portal.kernel.util.StringPool;
039    import com.liferay.portal.kernel.util.StringUtil;
040    import com.liferay.portal.kernel.util.Validator;
041    import com.liferay.portal.model.Layout;
042    import com.liferay.portal.model.Portlet;
043    import com.liferay.portal.security.permission.comparator.ModelResourceComparator;
044    import com.liferay.portal.service.PortletLocalServiceUtil;
045    import com.liferay.portal.theme.PortletDisplay;
046    import com.liferay.portal.theme.ThemeDisplay;
047    import com.liferay.portal.util.PortalUtil;
048    import com.liferay.portal.util.WebKeys;
049    import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
050    import com.liferay.portlet.asset.NoSuchTagException;
051    import com.liferay.portlet.asset.model.AssetCategory;
052    import com.liferay.portlet.asset.model.AssetCategoryProperty;
053    import com.liferay.portlet.asset.model.AssetEntry;
054    import com.liferay.portlet.asset.model.AssetRendererFactory;
055    import com.liferay.portlet.asset.model.AssetTag;
056    import com.liferay.portlet.asset.model.AssetTagProperty;
057    import com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil;
058    import com.liferay.portlet.asset.service.AssetCategoryPropertyLocalServiceUtil;
059    import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
060    import com.liferay.portlet.asset.service.AssetTagLocalServiceUtil;
061    import com.liferay.portlet.asset.service.AssetTagPropertyLocalServiceUtil;
062    import com.liferay.portlet.asset.service.persistence.AssetEntryQuery;
063    import com.liferay.portlet.assetpublisher.util.AssetSearcher;
064    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
065    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
066    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
067    import com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalServiceUtil;
068    import com.liferay.portlet.dynamicdatamapping.util.DDMIndexerImpl;
069    import com.liferay.portlet.journal.model.JournalArticle;
070    
071    import java.io.Serializable;
072    
073    import java.util.ArrayList;
074    import java.util.Collections;
075    import java.util.HashMap;
076    import java.util.HashSet;
077    import java.util.List;
078    import java.util.Locale;
079    import java.util.Map;
080    import java.util.Set;
081    import java.util.TreeMap;
082    
083    import javax.portlet.PortletMode;
084    import javax.portlet.PortletRequest;
085    import javax.portlet.PortletURL;
086    
087    import javax.servlet.http.HttpServletRequest;
088    
089    /**
090     * @author Brian Wing Shun Chan
091     * @author Jorge Ferrer
092     */
093    public class AssetUtil {
094    
095            public static final String CLASSNAME_SEPARATOR = "_CLASSNAME_";
096    
097            public static final char[] INVALID_CHARACTERS = new char[] {
098                    CharPool.AMPERSAND, CharPool.APOSTROPHE, CharPool.AT,
099                    CharPool.BACK_SLASH, CharPool.CLOSE_BRACKET, CharPool.CLOSE_CURLY_BRACE,
100                    CharPool.COLON, CharPool.COMMA, CharPool.EQUAL, CharPool.GREATER_THAN,
101                    CharPool.FORWARD_SLASH, CharPool.LESS_THAN, CharPool.NEW_LINE,
102                    CharPool.OPEN_BRACKET, CharPool.OPEN_CURLY_BRACE, CharPool.PERCENT,
103                    CharPool.PIPE, CharPool.PLUS, CharPool.POUND, CharPool.PRIME,
104                    CharPool.QUESTION, CharPool.QUOTE, CharPool.RETURN, CharPool.SEMICOLON,
105                    CharPool.SLASH, CharPool.STAR, CharPool.TILDE
106            };
107    
108            public static Set<String> addLayoutTags(
109                    HttpServletRequest request, List<AssetTag> tags) {
110    
111                    Set<String> layoutTags = getLayoutTagNames(request);
112    
113                    for (AssetTag tag : tags) {
114                            layoutTags.add(tag.getName());
115                    }
116    
117                    return layoutTags;
118            }
119    
120            public static void addPortletBreadcrumbEntries(
121                            long assetCategoryId, HttpServletRequest request,
122                            PortletURL portletURL)
123                    throws Exception {
124    
125                    AssetCategory assetCategory = AssetCategoryLocalServiceUtil.getCategory(
126                            assetCategoryId);
127    
128                    List<AssetCategory> ancestorCategories = assetCategory.getAncestors();
129    
130                    Collections.reverse(ancestorCategories);
131    
132                    for (AssetCategory ancestorCategory : ancestorCategories) {
133                            portletURL.setParameter(
134                                    "categoryId", String.valueOf(ancestorCategory.getCategoryId()));
135    
136                            PortalUtil.addPortletBreadcrumbEntry(
137                                    request, ancestorCategory.getTitleCurrentValue(),
138                                    portletURL.toString());
139                    }
140    
141                    portletURL.setParameter("categoryId", String.valueOf(assetCategoryId));
142    
143                    PortalUtil.addPortletBreadcrumbEntry(
144                            request, assetCategory.getTitleCurrentValue(),
145                            portletURL.toString());
146            }
147    
148            public static PortletURL getAddPortletURL(
149                            LiferayPortletRequest liferayPortletRequest,
150                            LiferayPortletResponse liferayPortletResponse, String className,
151                            long classTypeId, long[] allAssetCategoryIds,
152                            String[] allAssetTagNames, String redirect)
153                    throws Exception {
154    
155                    ThemeDisplay themeDisplay =
156                            (ThemeDisplay)liferayPortletRequest.getAttribute(
157                                    WebKeys.THEME_DISPLAY);
158    
159                    AssetRendererFactory assetRendererFactory =
160                            AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
161                                    className);
162    
163                    if (assetRendererFactory == null) {
164                            return null;
165                    }
166    
167                    liferayPortletRequest.setAttribute(
168                            WebKeys.ASSET_RENDERER_FACTORY_CLASS_TYPE_ID, classTypeId);
169    
170                    PortletURL addPortletURL = assetRendererFactory.getURLAdd(
171                            liferayPortletRequest, liferayPortletResponse);
172    
173                    if (addPortletURL == null) {
174                            return null;
175                    }
176    
177                    if (redirect != null) {
178                            addPortletURL.setParameter("redirect", redirect);
179                    }
180    
181                    String referringPortletResource = ParamUtil.getString(
182                            liferayPortletRequest, "portletResource");
183    
184                    if (Validator.isNotNull(referringPortletResource)) {
185                            addPortletURL.setParameter(
186                                    "referringPortletResource", referringPortletResource);
187                    }
188                    else {
189                            PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
190    
191                            addPortletURL.setParameter(
192                                    "referringPortletResource", portletDisplay.getId());
193    
194                            if (allAssetCategoryIds != null) {
195                                    Map<Long, String> assetVocabularyAssetCategoryIds =
196                                            new HashMap<Long, String>();
197    
198                                    for (long assetCategoryId : allAssetCategoryIds) {
199                                            AssetCategory assetCategory =
200                                                    AssetCategoryLocalServiceUtil.fetchAssetCategory(
201                                                            assetCategoryId);
202    
203                                            if (assetCategory == null) {
204                                                    continue;
205                                            }
206    
207                                            long assetVocabularyId = assetCategory.getVocabularyId();
208    
209                                            if (assetVocabularyAssetCategoryIds.containsKey(
210                                                            assetVocabularyId)) {
211    
212                                                    String assetCategoryIds =
213                                                            assetVocabularyAssetCategoryIds.get(
214                                                                    assetVocabularyId);
215    
216                                                    assetVocabularyAssetCategoryIds.put(
217                                                            assetVocabularyId,
218                                                            assetCategoryIds + StringPool.COMMA +
219                                                                    assetCategoryId);
220                                            }
221                                            else {
222                                                    assetVocabularyAssetCategoryIds.put(
223                                                            assetVocabularyId, String.valueOf(assetCategoryId));
224                                            }
225                                    }
226    
227                                    for (Map.Entry<Long, String> entry :
228                                                    assetVocabularyAssetCategoryIds.entrySet()) {
229    
230                                            long assetVocabularyId = entry.getKey();
231                                            String assetCategoryIds = entry.getValue();
232    
233                                            addPortletURL.setParameter(
234                                                    "assetCategoryIds_" + assetVocabularyId,
235                                                    assetCategoryIds);
236                                    }
237                            }
238    
239                            if (allAssetTagNames != null) {
240                                    addPortletURL.setParameter(
241                                            "assetTagNames", StringUtil.merge(allAssetTagNames));
242                            }
243                    }
244    
245                    if (classTypeId > 0) {
246                            addPortletURL.setParameter(
247                                    "classTypeId", String.valueOf(classTypeId));
248    
249                            if (className.equals(DLFileEntry.class.getName())) {
250                                    addPortletURL.setParameter(Constants.CMD, Constants.ADD);
251                                    addPortletURL.setParameter(
252                                            "folderId",
253                                            String.valueOf(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID));
254                                    addPortletURL.setParameter(
255                                            "fileEntryTypeId", String.valueOf(classTypeId));
256                            }
257    
258                            if (className.equals(JournalArticle.class.getName())) {
259                                    DDMStructure ddmStructure =
260                                            DDMStructureLocalServiceUtil.getStructure(classTypeId);
261    
262                                    addPortletURL.setParameter(
263                                            "structureId", ddmStructure.getStructureKey());
264                            }
265                    }
266    
267                    addPortletURL.setPortletMode(PortletMode.VIEW);
268                    addPortletURL.setWindowState(LiferayWindowState.POP_UP);
269    
270                    return addPortletURL;
271            }
272    
273            public static Map<String, PortletURL> getAddPortletURLs(
274                            LiferayPortletRequest liferayPortletRequest,
275                            LiferayPortletResponse liferayPortletResponse, long[] classNameIds,
276                            long[] classTypeIds, long[] allAssetCategoryIds,
277                            String[] allAssetTagNames, String redirect)
278                    throws Exception {
279    
280                    ThemeDisplay themeDisplay =
281                            (ThemeDisplay)liferayPortletRequest.getAttribute(
282                                    WebKeys.THEME_DISPLAY);
283    
284                    Map<String, PortletURL> addPortletURLs =
285                            new TreeMap<String, PortletURL>(
286                                    new ModelResourceComparator(themeDisplay.getLocale()));
287    
288                    if (Validator.isNull(redirect)) {
289                            PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
290    
291                            PortletURL redirectURL =
292                                    liferayPortletResponse.createLiferayPortletURL(
293                                            themeDisplay.getPlid(), portletDisplay.getId(),
294                                            PortletRequest.RENDER_PHASE, false);
295    
296                            redirectURL.setParameter(
297                                    "struts_action", "/asset_publisher/add_asset_redirect");
298                            redirectURL.setParameter("redirect", themeDisplay.getURLCurrent());
299                            redirectURL.setWindowState(LiferayWindowState.POP_UP);
300    
301                            redirect = redirectURL.toString();
302                    }
303    
304                    for (long classNameId : classNameIds) {
305                            String className = PortalUtil.getClassName(classNameId);
306    
307                            AssetRendererFactory assetRendererFactory =
308                                    AssetRendererFactoryRegistryUtil.
309                                            getAssetRendererFactoryByClassName(className);
310    
311                            Portlet portlet = PortletLocalServiceUtil.getPortletById(
312                                    themeDisplay.getCompanyId(),
313                                    assetRendererFactory.getPortletId());
314    
315                            if (!portlet.isActive()) {
316                                    continue;
317                            }
318    
319                            Map<Long, String> classTypes = assetRendererFactory.getClassTypes(
320                                    new long[] {
321                                            themeDisplay.getCompanyGroupId(),
322                                            themeDisplay.getScopeGroupId()
323                                    },
324                                    themeDisplay.getLocale());
325    
326                            if ((classTypeIds.length == 0) || classTypes.isEmpty()) {
327                                    PortletURL addPortletURL = getAddPortletURL(
328                                            liferayPortletRequest, liferayPortletResponse, className, 0,
329                                            allAssetCategoryIds, allAssetTagNames, redirect);
330    
331                                    if (addPortletURL != null) {
332                                            addPortletURLs.put(className, addPortletURL);
333                                    }
334                            }
335    
336                            for (long classTypeId : classTypes.keySet()) {
337                                    if (ArrayUtil.contains(classTypeIds, classTypeId) ||
338                                            (classTypeIds.length == 0)) {
339    
340                                            PortletURL addPortletURL = getAddPortletURL(
341                                                    liferayPortletRequest, liferayPortletResponse,
342                                                    className, classTypeId, allAssetCategoryIds,
343                                                    allAssetTagNames, redirect);
344    
345                                            if (addPortletURL != null) {
346                                                    String mesage =
347                                                            className + CLASSNAME_SEPARATOR +
348                                                                    classTypes.get(classTypeId);
349    
350                                                    addPortletURLs.put(mesage, addPortletURL);
351                                            }
352                                    }
353                            }
354                    }
355    
356                    return addPortletURLs;
357            }
358    
359            public static List<AssetEntry> getAssetEntries(Hits hits) {
360                    List<AssetEntry> assetEntries = new ArrayList<AssetEntry>();
361    
362                    for (Document document : hits.getDocs()) {
363                            String className = GetterUtil.getString(
364                                    document.get(Field.ENTRY_CLASS_NAME));
365                            long classPK = GetterUtil.getLong(
366                                    document.get(Field.ENTRY_CLASS_PK));
367    
368                            try {
369                                    AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(
370                                            className, classPK);
371    
372                                    assetEntries.add(assetEntry);
373                            }
374                            catch (Exception e) {
375                            }
376                    }
377    
378                    return assetEntries;
379            }
380    
381            public static String getAssetKeywords(String className, long classPK)
382                    throws SystemException {
383    
384                    List<AssetTag> tags = AssetTagLocalServiceUtil.getTags(
385                            className, classPK);
386                    List<AssetCategory> categories =
387                            AssetCategoryLocalServiceUtil.getCategories(className, classPK);
388    
389                    StringBuffer sb = new StringBuffer();
390    
391                    sb.append(ListUtil.toString(tags, AssetTag.NAME_ACCESSOR));
392    
393                    if (!tags.isEmpty()) {
394                            sb.append(StringPool.COMMA);
395                    }
396    
397                    sb.append(ListUtil.toString(categories, AssetCategory.NAME_ACCESSOR));
398    
399                    return sb.toString();
400            }
401    
402            public static Set<String> getLayoutTagNames(HttpServletRequest request) {
403                    Set<String> tagNames = (Set<String>)request.getAttribute(
404                            WebKeys.ASSET_LAYOUT_TAG_NAMES);
405    
406                    if (tagNames == null) {
407                            tagNames = new HashSet<String>();
408    
409                            request.setAttribute(WebKeys.ASSET_LAYOUT_TAG_NAMES, tagNames);
410                    }
411    
412                    return tagNames;
413            }
414    
415            public static boolean hasSubtype(
416                    String subtypeClassName, Map<String, PortletURL> addPortletURLs) {
417    
418                    for (Map.Entry<String, PortletURL> entry : addPortletURLs.entrySet()) {
419                            String className = entry.getKey();
420    
421                            if (className.startsWith(subtypeClassName) &&
422                                    !className.equals(subtypeClassName)) {
423    
424                                    return true;
425                            }
426                    }
427    
428                    return false;
429            }
430    
431            public static boolean isValidWord(String word) {
432                    if (Validator.isNull(word)) {
433                            return false;
434                    }
435    
436                    char[] wordCharArray = word.toCharArray();
437    
438                    for (char c : wordCharArray) {
439                            for (char invalidChar : INVALID_CHARACTERS) {
440                                    if (c == invalidChar) {
441                                            if (_log.isDebugEnabled()) {
442                                                    _log.debug(
443                                                            "Word " + word + " is not valid because " + c +
444                                                                    " is not allowed");
445                                            }
446    
447                                            return false;
448                                    }
449                            }
450                    }
451    
452                    return true;
453            }
454    
455            public static Hits search(
456                            HttpServletRequest request, AssetEntryQuery assetEntryQuery,
457                            int start, int end)
458                    throws Exception {
459    
460                    SearchContext searchContext = SearchContextFactory.getInstance(request);
461    
462                    return search(searchContext, assetEntryQuery, start, end);
463            }
464    
465            public static Hits search(
466                            SearchContext searchContext, AssetEntryQuery assetEntryQuery,
467                            int start, int end)
468                    throws Exception {
469    
470                    Indexer searcher = AssetSearcher.getInstance();
471    
472                    AssetSearcher assetSearcher = (AssetSearcher)searcher;
473    
474                    assetSearcher.setAssetEntryQuery(assetEntryQuery);
475    
476                    Layout layout = assetEntryQuery.getLayout();
477    
478                    if (layout != null) {
479                            searchContext.setAttribute(Field.LAYOUT_UUID, layout.getUuid());
480                    }
481    
482                    String ddmStructureFieldName = (String)assetEntryQuery.getAttribute(
483                            "ddmStructureFieldName");
484                    Serializable ddmStructureFieldValue = assetEntryQuery.getAttribute(
485                            "ddmStructureFieldValue");
486    
487                    if (Validator.isNotNull(ddmStructureFieldName) &&
488                            Validator.isNotNull(ddmStructureFieldValue)) {
489    
490                            searchContext.setAttribute(
491                                    "ddmStructureFieldName", ddmStructureFieldName);
492                            searchContext.setAttribute(
493                                    "ddmStructureFieldValue", ddmStructureFieldValue);
494                    }
495    
496                    String paginationType = GetterUtil.getString(
497                            assetEntryQuery.getPaginationType(), "more");
498    
499                    if (!paginationType.equals("none") &&
500                            !paginationType.equals("simple")) {
501    
502                            searchContext.setAttribute("paginationType", paginationType);
503                    }
504    
505                    searchContext.setClassTypeIds(assetEntryQuery.getClassTypeIds());
506                    searchContext.setEnd(end);
507                    searchContext.setGroupIds(assetEntryQuery.getGroupIds());
508    
509                    if (Validator.isNotNull(assetEntryQuery.getKeywords())) {
510                            searchContext.setLike(true);
511                    }
512    
513                    searchContext.setSorts(
514                            getSorts(assetEntryQuery, searchContext.getLocale()));
515                    searchContext.setStart(start);
516    
517                    return assetSearcher.search(searchContext);
518            }
519    
520            public static String substituteCategoryPropertyVariables(
521                            long groupId, long categoryId, String s)
522                    throws SystemException {
523    
524                    String result = s;
525    
526                    AssetCategory category = null;
527    
528                    if (categoryId > 0) {
529                            category = AssetCategoryLocalServiceUtil.fetchCategory(categoryId);
530                    }
531    
532                    if (category != null) {
533                            List<AssetCategoryProperty> categoryProperties =
534                                    AssetCategoryPropertyLocalServiceUtil.getCategoryProperties(
535                                            categoryId);
536    
537                            for (AssetCategoryProperty categoryProperty : categoryProperties) {
538                                    result = StringUtil.replace(
539                                            result, "[$" + categoryProperty.getKey() + "$]",
540                                            categoryProperty.getValue());
541                            }
542                    }
543    
544                    return StringUtil.stripBetween(result, "[$", "$]");
545            }
546    
547            public static String substituteTagPropertyVariables(
548                            long groupId, String tagName, String s)
549                    throws PortalException, SystemException {
550    
551                    String result = s;
552    
553                    AssetTag tag = null;
554    
555                    if (tagName != null) {
556                            try {
557                                    tag = AssetTagLocalServiceUtil.getTag(groupId, tagName);
558                            }
559                            catch (NoSuchTagException nste) {
560                            }
561                    }
562    
563                    if (tag != null) {
564                            List<AssetTagProperty> tagProperties =
565                                    AssetTagPropertyLocalServiceUtil.getTagProperties(
566                                            tag.getTagId());
567    
568                            for (AssetTagProperty tagProperty : tagProperties) {
569                                    result = StringUtil.replace(
570                                            result, "[$" + tagProperty.getKey() + "$]",
571                                            tagProperty.getValue());
572                            }
573                    }
574    
575                    return StringUtil.stripBetween(result, "[$", "$]");
576            }
577    
578            public static String toWord(String text) {
579                    if (Validator.isNull(text)) {
580                            return text;
581                    }
582    
583                    char[] textCharArray = text.toCharArray();
584    
585                    for (int i = 0; i < textCharArray.length; i++) {
586                            char c = textCharArray[i];
587    
588                            for (char invalidChar : INVALID_CHARACTERS) {
589                                    if (c == invalidChar) {
590                                            textCharArray[i] = CharPool.SPACE;
591    
592                                            break;
593                                    }
594                            }
595                    }
596    
597                    return new String(textCharArray);
598            }
599    
600            protected static Sort getSort(
601                            String orderByType, String sortField, Locale locale)
602                    throws Exception {
603    
604                    if (Validator.isNull(orderByType)) {
605                            orderByType = "asc";
606                    }
607    
608                    int sortType = getSortType(sortField);
609    
610                    if (sortField.startsWith(
611                                    DDMIndexerImpl.DDM_FIELD_NAMESPACE +
612                                            StringPool.FORWARD_SLASH)) {
613    
614                            String[] sortFields = sortField.split(StringPool.FORWARD_SLASH);
615    
616                            long ddmStructureId = GetterUtil.getLong(sortFields[1]);
617                            String fieldName = sortFields[2];
618    
619                            DDMStructure ddmStructure =
620                                    DDMStructureLocalServiceUtil.getStructure(ddmStructureId);
621    
622                            String fieldType = ddmStructure.getFieldType(fieldName);
623    
624                            sortType = getSortType(fieldType);
625    
626                            sortField = sortField.concat(StringPool.UNDERLINE).concat(
627                                    LocaleUtil.toLanguageId(locale));
628                    }
629                    else if (sortField.equals("modifiedDate")) {
630                            sortField = Field.MODIFIED_DATE;
631                    }
632                    else if (sortField.equals("title")) {
633                            sortField = "localized_title_".concat(
634                                    LocaleUtil.toLanguageId(locale));
635                    }
636    
637                    return new Sort(
638                            sortField, sortType,
639                            !StringUtil.equalsIgnoreCase(orderByType, "asc"));
640            }
641    
642            protected static Sort[] getSorts(
643                            AssetEntryQuery assetEntryQuery, Locale locale)
644                    throws Exception {
645    
646                    Sort sort1 = getSort(
647                            assetEntryQuery.getOrderByType1(), assetEntryQuery.getOrderByCol1(),
648                            locale);
649                    Sort sort2 = getSort(
650                            assetEntryQuery.getOrderByType2(), assetEntryQuery.getOrderByCol2(),
651                            locale);
652    
653                    return new Sort[] {sort1, sort2};
654            }
655    
656            protected static int getSortType(String sortField) {
657                    int sortType = Sort.STRING_TYPE;
658    
659                    if (sortField.equals(Field.CREATE_DATE) ||
660                            sortField.equals(Field.EXPIRATION_DATE) ||
661                            sortField.equals(Field.PUBLISH_DATE) ||
662                            sortField.equals("ddm-date") ||
663                            sortField.equals("modifiedDate")) {
664    
665                            sortType = Sort.LONG_TYPE;
666                    }
667                    else if (sortField.equals(Field.PRIORITY) ||
668                                     sortField.equals(Field.RATINGS) ||
669                                     sortField.equals("ddm-decimal") ||
670                                     sortField.equals("ddm-number")) {
671    
672                            sortType = Sort.DOUBLE_TYPE;
673                    }
674                    else if (sortField.equals(Field.VIEW_COUNT) ||
675                                     sortField.equals("ddm-integer")) {
676    
677                            sortType = Sort.INT_TYPE;
678                    }
679    
680                    return sortType;
681            }
682    
683            private static Log _log = LogFactoryUtil.getLog(AssetUtil.class);
684    
685    }