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.security.pacl.permission.PortalRuntimePermission;
020    import com.liferay.portal.kernel.xml.Document;
021    import com.liferay.portal.kernel.xml.XPath;
022    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
023    import com.liferay.portlet.dynamicdatamapping.storage.Fields;
024    
025    import java.util.List;
026    import java.util.Locale;
027    
028    /**
029     * @author Bruno Basto
030     * @author Brian Wing Shun Chan
031     */
032    public class DDMXMLUtil {
033    
034            public static String formatXML(Document document) throws SystemException {
035                    return getDDMXML().formatXML(document);
036            }
037    
038            public static String formatXML(String xml) throws SystemException {
039                    return getDDMXML().formatXML(xml);
040            }
041    
042            public static DDMXML getDDMXML() {
043                    PortalRuntimePermission.checkGetBeanProperty(DDMXMLUtil.class);
044    
045                    return _ddmXML;
046            }
047    
048            public static Fields getFields(DDMStructure structure, String xml)
049                    throws PortalException, SystemException {
050    
051                    return getDDMXML().getFields(structure, xml);
052            }
053    
054            public static Fields getFields(
055                            DDMStructure structure, XPath xPath, String xml,
056                            List<String> fieldNames)
057                    throws PortalException, SystemException {
058    
059                    return getDDMXML().getFields(structure, xPath, xml, fieldNames);
060            }
061    
062            public static String getXML(Document document, Fields fields)
063                    throws SystemException {
064    
065                    return getDDMXML().getXML(document, fields);
066            }
067    
068            public static String getXML(Fields fields) throws SystemException {
069                    return getDDMXML().getXML(fields);
070            }
071    
072            public static String updateXMLDefaultLocale(
073                            String xml, Locale contentDefaultLocale,
074                            Locale contentNewDefaultLocale)
075                    throws SystemException {
076    
077                    return getDDMXML().updateXMLDefaultLocale(
078                            xml, contentDefaultLocale, contentNewDefaultLocale);
079            }
080    
081            public static String validateXML(String xml) throws PortalException {
082                    return getDDMXML().validateXML(xml);
083            }
084    
085            public void setDDMXML(DDMXML ddmXML) {
086                    PortalRuntimePermission.checkSetBeanProperty(getClass());
087    
088                    _ddmXML = ddmXML;
089            }
090    
091            private static DDMXML _ddmXML;
092    
093    }