001    /**
002     * Copyright (c) 2000-2012 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.portal.kernel.portletdisplaytemplate;
016    
017    import com.liferay.portal.kernel.configuration.Filter;
018    import com.liferay.portal.kernel.util.PropsKeys;
019    import com.liferay.portal.kernel.util.PropsUtil;
020    import com.liferay.portal.kernel.util.StringUtil;
021    import com.liferay.portal.kernel.util.Validator;
022    import com.liferay.portal.kernel.xml.Document;
023    import com.liferay.portal.kernel.xml.Element;
024    import com.liferay.portal.kernel.xml.SAXReaderUtil;
025    
026    import java.util.Collections;
027    import java.util.List;
028    
029    /**
030     * @author Eduardo Garcia
031     */
032    public abstract class BasePortletDisplayTemplateHandler
033            implements PortletDisplayTemplateHandler {
034    
035            public List<Element> getDefaultTemplateElements() throws Exception {
036                    String templatesConfigPath = getTemplatesConfigPath();
037    
038                    if (Validator.isNull(templatesConfigPath)) {
039                            return Collections.emptyList();
040                    }
041    
042                    Class<?> clazz = getClass();
043    
044                    String xml = StringUtil.read(
045                            clazz.getClassLoader(), templatesConfigPath, false);
046    
047                    Document document = SAXReaderUtil.read(xml);
048    
049                    Element rootElement = document.getRootElement();
050    
051                    return rootElement.elements("template");
052            }
053    
054            public String getTemplatesHelpPath(String language) {
055                    return PropsUtil.get(getTemplatesHelpKey(), new Filter(language));
056            }
057    
058            protected String getTemplatesConfigPath() {
059                    return null;
060            }
061    
062            protected String getTemplatesHelpKey() {
063                    return PropsKeys.PORTLET_DISPLAY_TEMPLATES_HELP;
064            }
065    
066    }