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