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