001    /**
002     * Copyright (c) 2000-present 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.dynamicdatamapping.util;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.json.JSONArray;
019    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
020    import com.liferay.portal.kernel.xml.Document;
021    import com.liferay.portal.kernel.xml.Element;
022    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
023    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
024    import com.liferay.portlet.dynamicdatamapping.storage.Field;
025    import com.liferay.portlet.dynamicdatamapping.storage.Fields;
026    
027    import java.util.Locale;
028    
029    import javax.servlet.http.HttpServletRequest;
030    import javax.servlet.http.HttpServletResponse;
031    
032    /**
033     * @author Eduardo Lundgren
034     * @author Brian Wing Shun Chan
035     */
036    public class DDMXSDUtil {
037    
038            public static DDMXSD getDDMXSD() {
039                    PortalRuntimePermission.checkGetBeanProperty(DDMXSDUtil.class);
040    
041                    return _ddmXSD;
042            }
043    
044            public static String getFieldHTMLByName(
045                            HttpServletRequest request, HttpServletResponse response,
046                            long classNameId, long classPK, String fieldName, Fields fields,
047                            String portletNamespace, String namespace, String mode,
048                            boolean readOnly, Locale locale)
049                    throws Exception {
050    
051                    return getDDMXSD().getFieldHTMLByName(
052                            request, response, classNameId, classPK, fieldName, fields,
053                            portletNamespace, namespace, mode, readOnly, locale);
054            }
055    
056            public static String getHTML(
057                            HttpServletRequest request, HttpServletResponse response,
058                            DDMStructure ddmStructure, Fields fields, String portletNamespace,
059                            String namespace, boolean readOnly, Locale locale)
060                    throws Exception {
061    
062                    return getDDMXSD().getHTML(
063                            request, response, ddmStructure, fields, portletNamespace,
064                            namespace, readOnly, locale);
065            }
066    
067            public static String getHTML(
068                            HttpServletRequest request, HttpServletResponse response,
069                            DDMTemplate ddmTemplate, Fields fields, String portletNamespace,
070                            String namespace, boolean readOnly, Locale locale)
071                    throws Exception {
072    
073                    return getDDMXSD().getHTML(
074                            request, response, ddmTemplate, fields, portletNamespace, namespace,
075                            readOnly, locale);
076            }
077    
078            public static String getHTML(
079                            HttpServletRequest request, HttpServletResponse response,
080                            String xml, Fields fields, String portletNamespace, Locale locale)
081                    throws Exception {
082    
083                    return getDDMXSD().getHTML(
084                            request, response, xml, fields, portletNamespace, locale);
085            }
086    
087            public static String getHTML(
088                            HttpServletRequest request, HttpServletResponse response,
089                            String xml, Fields fields, String portletNamespace,
090                            String namespace, boolean readOnly, Locale locale)
091                    throws Exception {
092    
093                    return getDDMXSD().getHTML(
094                            request, response, xml, fields, portletNamespace, namespace,
095                            readOnly, locale);
096            }
097    
098            public static String getHTML(
099                            HttpServletRequest request, HttpServletResponse response,
100                            String xml, Fields fields, String portletNamespace,
101                            String namespace, Locale locale)
102                    throws Exception {
103    
104                    return getDDMXSD().getHTML(
105                            request, response, xml, fields, portletNamespace, namespace,
106                            locale);
107            }
108    
109            public static String getHTML(
110                            HttpServletRequest request, HttpServletResponse response,
111                            String xml, Fields fields, String portletNamespace,
112                            String namespace, String mode, boolean readOnly, Locale locale)
113                    throws Exception {
114    
115                    return getDDMXSD().getHTML(
116                            request, response, xml, fields, portletNamespace, namespace, mode,
117                            readOnly, locale);
118            }
119    
120            public static String getHTML(
121                            HttpServletRequest request, HttpServletResponse response,
122                            String xml, String portletNamespace, Locale locale)
123                    throws Exception {
124    
125                    return getDDMXSD().getHTML(
126                            request, response, xml, portletNamespace, locale);
127            }
128    
129            public static JSONArray getJSONArray(DDMStructure structure, String xsd)
130                    throws PortalException {
131    
132                    return getDDMXSD().getJSONArray(structure, xsd);
133            }
134    
135            public static JSONArray getJSONArray(Document document)
136                    throws PortalException {
137    
138                    return getDDMXSD().getJSONArray(document);
139            }
140    
141            public static JSONArray getJSONArray(Element element)
142                    throws PortalException {
143    
144                    return getDDMXSD().getJSONArray(element);
145            }
146    
147            public static JSONArray getJSONArray(String xml) throws PortalException {
148                    return getDDMXSD().getJSONArray(xml);
149            }
150    
151            public static String getSimpleFieldHTML(
152                            HttpServletRequest request, HttpServletResponse response,
153                            Element element, Field field, String portletNamespace,
154                            String namespace, String mode, boolean readOnly, Locale locale)
155                    throws Exception {
156    
157                    return getDDMXSD().getSimpleFieldHTML(
158                            request, response, element, field, portletNamespace, namespace,
159                            mode, readOnly, locale);
160            }
161    
162            public static String getSimpleFieldHTMLByName(
163                            HttpServletRequest request, HttpServletResponse response,
164                            long classNameId, long classPK, Field field,
165                            String portletNamespace, String namespace, String mode,
166                            boolean readOnly, Locale locale)
167                    throws Exception {
168    
169                    return getDDMXSD().getSimpleFieldHTMLByName(
170                            request, response, classNameId, classPK, field, portletNamespace,
171                            namespace, mode, readOnly, locale);
172            }
173    
174            public static String getXSD(long classNameId, long classPK)
175                    throws PortalException {
176    
177                    return getDDMXSD().getXSD(classNameId, classPK);
178            }
179    
180            public static String getXSD(String json) throws PortalException {
181                    return getDDMXSD().getXSD(json);
182            }
183    
184            public void setDDMXSD(DDMXSD ddmXSD) {
185                    PortalRuntimePermission.checkSetBeanProperty(getClass());
186    
187                    _ddmXSD = ddmXSD;
188            }
189    
190            private static DDMXSD _ddmXSD;
191    
192    }