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.dynamicdatalists.util;
016    
017    import com.liferay.portal.kernel.json.JSONArray;
018    import com.liferay.portal.kernel.json.JSONObject;
019    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
020    import com.liferay.portal.kernel.xml.Element;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portlet.dynamicdatalists.model.DDLRecord;
024    import com.liferay.portlet.dynamicdatalists.model.DDLRecordSet;
025    
026    import java.util.List;
027    import java.util.Map;
028    
029    import javax.portlet.PortletPreferences;
030    import javax.portlet.RenderRequest;
031    import javax.portlet.RenderResponse;
032    
033    import javax.servlet.http.HttpServletRequest;
034    import javax.servlet.http.HttpServletResponse;
035    
036    /**
037     * @author Eduardo Lundgren
038     */
039    public class DDLUtil {
040    
041            public static void addAllReservedEls(
042                    Element rootElement, Map<String, String> tokens,
043                    DDLRecordSet recordSet) {
044    
045                    getDDL().addAllReservedEls(rootElement, tokens, recordSet);
046            }
047    
048            public static DDL getDDL() {
049                    PortalRuntimePermission.checkGetBeanProperty(DDLUtil.class);
050    
051                    return _ddl;
052            }
053    
054            public static void getRecordFileUpload(
055                            HttpServletRequest request, HttpServletResponse response,
056                            DDLRecord record, String fieldName)
057                    throws Exception {
058    
059                    getDDL().sendRecordFileUpload(request, response, record, fieldName);
060            }
061    
062            public static JSONObject getRecordJSONObject(DDLRecord record)
063                    throws Exception {
064    
065                    return getDDL().getRecordJSONObject(record);
066            }
067    
068            public static JSONObject getRecordJSONObject(
069                            DDLRecord record, boolean latestRecordVersion)
070                    throws Exception {
071    
072                    return getDDL().getRecordJSONObject(record, latestRecordVersion);
073            }
074    
075            public static JSONArray getRecordSetJSONArray(DDLRecordSet recordSet)
076                    throws Exception {
077    
078                    return getDDL().getRecordSetJSONArray(recordSet);
079            }
080    
081            public static JSONArray getRecordsJSONArray(List<DDLRecord> records)
082                    throws Exception {
083    
084                    return getDDL().getRecordsJSONArray(records);
085            }
086    
087            public static JSONArray getRecordsJSONArray(
088                            List<DDLRecord> records, boolean latestRecordVersion)
089                    throws Exception {
090    
091                    return getDDL().getRecordsJSONArray(records, latestRecordVersion);
092            }
093    
094            public static String getTemplateContent(
095                            long ddmTemplateId, DDLRecordSet recordSet,
096                            ThemeDisplay themeDisplay, RenderRequest renderRequest,
097                            RenderResponse renderResponse)
098                    throws Exception {
099    
100                    return getDDL().getTemplateContent(
101                            ddmTemplateId, recordSet, themeDisplay, renderRequest,
102                            renderResponse);
103            }
104    
105            public static boolean isEditable(
106                            HttpServletRequest request, String portletId, long groupId)
107                    throws Exception {
108    
109                    return getDDL().isEditable(request, portletId, groupId);
110            }
111    
112            public static boolean isEditable(
113                            PortletPreferences preferences, String portletId, long groupId)
114                    throws Exception {
115    
116                    return getDDL().isEditable(preferences, portletId, groupId);
117            }
118    
119            public static void sendRecordFileUpload(
120                            HttpServletRequest request, HttpServletResponse response,
121                            DDLRecord record, String fieldName)
122                    throws Exception {
123    
124                    getDDL().sendRecordFileUpload(request, response, record, fieldName);
125            }
126    
127            public static void sendRecordFileUpload(
128                            HttpServletRequest request, HttpServletResponse response,
129                            long recordId, String fieldName)
130                    throws Exception {
131    
132                    getDDL().sendRecordFileUpload(request, response, recordId, fieldName);
133            }
134    
135            public static DDLRecord updateRecord(
136                            long recordId, long recordSetId, boolean mergeFields,
137                            boolean checkPermission, ServiceContext serviceContext)
138                    throws Exception {
139    
140                    return getDDL().updateRecord(
141                            recordId, recordSetId, mergeFields, checkPermission,
142                            serviceContext);
143            }
144    
145            public static DDLRecord updateRecord(
146                            long recordId, long recordSetId, boolean mergeFields,
147                            ServiceContext serviceContext)
148                    throws Exception {
149    
150                    return getDDL().updateRecord(
151                            recordId, recordSetId, mergeFields, serviceContext);
152            }
153    
154            public static String uploadRecordFieldFile(
155                            DDLRecord record, String fieldName, ServiceContext serviceContext)
156                    throws Exception {
157    
158                    return getDDL().uploadRecordFieldFile(
159                            record, fieldName, serviceContext);
160            }
161    
162            public void setDDL(DDL ddl) {
163                    PortalRuntimePermission.checkSetBeanProperty(getClass());
164    
165                    _ddl = ddl;
166            }
167    
168            private static DDL _ddl;
169    
170    }