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