001    /**
002     * Copyright (c) 2000-2012 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 getFileUploadPath(BaseModel<?> baseModel) {
075                    return getDDM().getFileUploadPath(baseModel);
076            }
077    
078            public static OrderByComparator getStructureOrderByComparator(
079                    String orderByCol, String orderByType) {
080    
081                    return getDDM().getStructureOrderByComparator(orderByCol, orderByType);
082            }
083    
084            public static OrderByComparator getTemplateOrderByComparator(
085                    String orderByCol, String orderByType) {
086    
087                    return getDDM().getTemplateOrderByComparator(orderByCol, orderByType);
088            }
089    
090            public static Fields mergeFields(Fields newFields, Fields existingFields) {
091                    return getDDM().mergeFields(newFields, existingFields);
092            }
093    
094            public static void sendFieldFile(
095                            HttpServletRequest request, HttpServletResponse response,
096                            Field field, int valueIndex)
097                    throws Exception {
098    
099                    getDDM().sendFieldFile(request, response, field, valueIndex);
100            }
101    
102            public static void uploadFieldFile(
103                            long structureId, long storageId, BaseModel<?> baseModel,
104                            String fieldName, ServiceContext serviceContext)
105                    throws Exception {
106    
107                    getDDM().uploadFieldFile(
108                            structureId, storageId, baseModel, fieldName, serviceContext);
109            }
110    
111            public static void uploadFieldFile(
112                            long structureId, long storageId, BaseModel<?> baseModel,
113                            String fieldName, String fieldNamespace,
114                            ServiceContext serviceContext)
115                    throws Exception {
116    
117                    getDDM().uploadFieldFile(
118                            structureId, storageId, baseModel, fieldName, fieldNamespace,
119                            serviceContext);
120            }
121    
122            public void setDDM(DDM ddm) {
123                    PortalRuntimePermission.checkSetBeanProperty(getClass());
124    
125                    _ddm = ddm;
126            }
127    
128            private static DDM _ddm;
129    
130    }