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.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 List<DDLRecord> getRecords(Hits hits) throws Exception {
076                    return getDDL().getRecords(hits);
077            }
078    
079            public static JSONArray getRecordSetJSONArray(DDLRecordSet recordSet)
080                    throws Exception {
081    
082                    return getDDL().getRecordSetJSONArray(recordSet);
083            }
084    
085            public static JSONArray getRecordsJSONArray(List<DDLRecord> records)
086                    throws Exception {
087    
088                    return getDDL().getRecordsJSONArray(records);
089            }
090    
091            public static JSONArray getRecordsJSONArray(
092                            List<DDLRecord> records, boolean latestRecordVersion)
093                    throws Exception {
094    
095                    return getDDL().getRecordsJSONArray(records, latestRecordVersion);
096            }
097    
098            public static String getTemplateContent(
099                            long ddmTemplateId, DDLRecordSet recordSet,
100                            ThemeDisplay themeDisplay, RenderRequest renderRequest,
101                            RenderResponse renderResponse)
102                    throws Exception {
103    
104                    return getDDL().getTemplateContent(
105                            ddmTemplateId, recordSet, themeDisplay, renderRequest,
106                            renderResponse);
107            }
108    
109            public static void sendRecordFileUpload(
110                            HttpServletRequest request, HttpServletResponse response,
111                            DDLRecord record, String fieldName)
112                    throws Exception {
113    
114                    getDDL().sendRecordFileUpload(request, response, record, fieldName);
115            }
116    
117            public static void sendRecordFileUpload(
118                            HttpServletRequest request, HttpServletResponse response,
119                            long recordId, String fieldName)
120                    throws Exception {
121    
122                    getDDL().sendRecordFileUpload(request, response, recordId, fieldName);
123            }
124    
125            public static DDLRecord updateRecord(
126                            long recordId, long recordSetId, boolean mergeFields,
127                            boolean checkPermission, ServiceContext serviceContext)
128                    throws Exception {
129    
130                    return getDDL().updateRecord(
131                            recordId, recordSetId, mergeFields, checkPermission,
132                            serviceContext);
133            }
134    
135            public static DDLRecord updateRecord(
136                            long recordId, long recordSetId, boolean mergeFields,
137                            ServiceContext serviceContext)
138                    throws Exception {
139    
140                    return getDDL().updateRecord(
141                            recordId, recordSetId, mergeFields, serviceContext);
142            }
143    
144            public static String uploadRecordFieldFile(
145                            DDLRecord record, String fieldName, ServiceContext serviceContext)
146                    throws Exception {
147    
148                    return getDDL().uploadRecordFieldFile(
149                            record, fieldName, serviceContext);
150            }
151    
152            public void setDDL(DDL ddl) {
153                    PortalRuntimePermission.checkSetBeanProperty(getClass());
154    
155                    _ddl = ddl;
156            }
157    
158            private static DDL _ddl;
159    
160    }