001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.RenderRequest;
030    import javax.portlet.RenderResponse;
031    
032    import javax.servlet.http.HttpServletRequest;
033    import javax.servlet.http.HttpServletResponse;
034    
035    /**
036     * @author Eduardo Lundgren
037     */
038    public class DDLUtil {
039    
040            public static void addAllReservedEls(
041                    Element rootElement, Map<String, String> tokens,
042                    DDLRecordSet recordSet) {
043    
044                    getDDL().addAllReservedEls(rootElement, tokens, recordSet);
045            }
046    
047            public static DDL getDDL() {
048                    PortalRuntimePermission.checkGetBeanProperty(DDLUtil.class);
049    
050                    return _ddl;
051            }
052    
053            public static void getRecordFileUpload(
054                            HttpServletRequest request, HttpServletResponse response,
055                            DDLRecord record, String fieldName)
056                    throws Exception {
057    
058                    getDDL().sendRecordFileUpload(request, response, record, fieldName);
059            }
060    
061            public static JSONObject getRecordJSONObject(DDLRecord record)
062                    throws Exception {
063    
064                    return getDDL().getRecordJSONObject(record);
065            }
066    
067            public static JSONObject getRecordJSONObject(
068                            DDLRecord record, boolean latestRecordVersion)
069                    throws Exception {
070    
071                    return getDDL().getRecordJSONObject(record, latestRecordVersion);
072            }
073    
074            public static JSONArray getRecordSetJSONArray(DDLRecordSet recordSet)
075                    throws Exception {
076    
077                    return getDDL().getRecordSetJSONArray(recordSet);
078            }
079    
080            public static JSONArray getRecordsJSONArray(List<DDLRecord> records)
081                    throws Exception {
082    
083                    return getDDL().getRecordsJSONArray(records);
084            }
085    
086            public static JSONArray getRecordsJSONArray(
087                            List<DDLRecord> records, boolean latestRecordVersion)
088                    throws Exception {
089    
090                    return getDDL().getRecordsJSONArray(records, latestRecordVersion);
091            }
092    
093            public static String getTemplateContent(
094                            long ddmTemplateId, DDLRecordSet recordSet,
095                            ThemeDisplay themeDisplay, RenderRequest renderRequest,
096                            RenderResponse renderResponse)
097                    throws Exception {
098    
099                    return getDDL().getTemplateContent(
100                            ddmTemplateId, recordSet, themeDisplay, renderRequest,
101                            renderResponse);
102            }
103    
104            public static void sendRecordFileUpload(
105                            HttpServletRequest request, HttpServletResponse response,
106                            DDLRecord record, String fieldName)
107                    throws Exception {
108    
109                    getDDL().sendRecordFileUpload(request, response, record, fieldName);
110            }
111    
112            public static void sendRecordFileUpload(
113                            HttpServletRequest request, HttpServletResponse response,
114                            long recordId, String fieldName)
115                    throws Exception {
116    
117                    getDDL().sendRecordFileUpload(request, response, recordId, fieldName);
118            }
119    
120            public static DDLRecord updateRecord(
121                            long recordId, long recordSetId, boolean mergeFields,
122                            boolean checkPermission, ServiceContext serviceContext)
123                    throws Exception {
124    
125                    return getDDL().updateRecord(
126                            recordId, recordSetId, mergeFields, checkPermission,
127                            serviceContext);
128            }
129    
130            public static DDLRecord updateRecord(
131                            long recordId, long recordSetId, boolean mergeFields,
132                            ServiceContext serviceContext)
133                    throws Exception {
134    
135                    return getDDL().updateRecord(
136                            recordId, recordSetId, mergeFields, serviceContext);
137            }
138    
139            public static String uploadRecordFieldFile(
140                            DDLRecord record, String fieldName, ServiceContext serviceContext)
141                    throws Exception {
142    
143                    return getDDL().uploadRecordFieldFile(
144                            record, fieldName, serviceContext);
145            }
146    
147            public void setDDL(DDL ddl) {
148                    PortalRuntimePermission.checkSetBeanProperty(getClass());
149    
150                    _ddl = ddl;
151            }
152    
153            private static DDL _ddl;
154    
155    }