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