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.dynamicdatamapping.util;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
020    import com.liferay.portal.kernel.util.OrderByComparator;
021    import com.liferay.portal.model.BaseModel;
022    import com.liferay.portal.service.ServiceContext;
023    import com.liferay.portlet.dynamicdatamapping.storage.Field;
024    import com.liferay.portlet.dynamicdatamapping.storage.Fields;
025    
026    import javax.servlet.http.HttpServletRequest;
027    import javax.servlet.http.HttpServletResponse;
028    
029    /**
030     * @author Eduardo Lundgren
031     */
032    public class DDMUtil {
033    
034            public static DDM getDDM() {
035                    PortalRuntimePermission.checkGetBeanProperty(DDMUtil.class);
036    
037                    return _ddm;
038            }
039    
040            public static Fields getFields(
041                            long ddmStructureId, long ddmTemplateId,
042                            ServiceContext serviceContext)
043                    throws PortalException, SystemException {
044    
045                    return getDDM().getFields(
046                            ddmStructureId, ddmTemplateId, serviceContext);
047            }
048    
049            public static Fields getFields(
050                            long ddmStructureId, long ddmTemplateId, String fieldNamespace,
051                            ServiceContext serviceContext)
052                    throws PortalException, SystemException {
053    
054                    return getDDM().getFields(
055                            ddmStructureId, ddmTemplateId, fieldNamespace, serviceContext);
056            }
057    
058            public static Fields getFields(
059                            long ddmStructureId, ServiceContext serviceContext)
060                    throws PortalException, SystemException {
061    
062                    return getDDM().getFields(ddmStructureId, serviceContext);
063            }
064    
065            public static Fields getFields(
066                            long ddmStructureId, String fieldNamespace,
067                            ServiceContext serviceContext)
068                    throws PortalException, SystemException {
069    
070                    return getDDM().getFields(
071                            ddmStructureId, fieldNamespace, serviceContext);
072            }
073    
074            public static String[] getFieldsDisplayValues(Field fieldsDisplayField)
075                    throws Exception {
076    
077                    return getDDM().getFieldsDisplayValues(fieldsDisplayField);
078            }
079    
080            public static String getFileUploadPath(BaseModel<?> baseModel) {
081                    return getDDM().getFileUploadPath(baseModel);
082            }
083    
084            public static OrderByComparator getStructureOrderByComparator(
085                    String orderByCol, String orderByType) {
086    
087                    return getDDM().getStructureOrderByComparator(orderByCol, orderByType);
088            }
089    
090            public static OrderByComparator getTemplateOrderByComparator(
091                    String orderByCol, String orderByType) {
092    
093                    return getDDM().getTemplateOrderByComparator(orderByCol, orderByType);
094            }
095    
096            public static Fields mergeFields(Fields newFields, Fields existingFields) {
097                    return getDDM().mergeFields(newFields, existingFields);
098            }
099    
100            public static void sendFieldFile(
101                            HttpServletRequest request, HttpServletResponse response,
102                            Field field, int valueIndex)
103                    throws Exception {
104    
105                    getDDM().sendFieldFile(request, response, field, valueIndex);
106            }
107    
108            public static void uploadFieldFile(
109                            long structureId, long storageId, BaseModel<?> baseModel,
110                            String fieldName, ServiceContext serviceContext)
111                    throws Exception {
112    
113                    getDDM().uploadFieldFile(
114                            structureId, storageId, baseModel, fieldName, serviceContext);
115            }
116    
117            public static void uploadFieldFile(
118                            long structureId, long storageId, BaseModel<?> baseModel,
119                            String fieldName, String fieldNamespace,
120                            ServiceContext serviceContext)
121                    throws Exception {
122    
123                    getDDM().uploadFieldFile(
124                            structureId, storageId, baseModel, fieldName, fieldNamespace,
125                            serviceContext);
126            }
127    
128            public void setDDM(DDM ddm) {
129                    PortalRuntimePermission.checkSetBeanProperty(getClass());
130    
131                    _ddm = ddm;
132            }
133    
134            private static DDM _ddm;
135    
136    }