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