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.portal.util;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.language.LanguageUtil;
019    import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
020    import com.liferay.portal.kernel.util.GetterUtil;
021    import com.liferay.portal.kernel.util.LocaleUtil;
022    import com.liferay.portal.kernel.util.UnicodeProperties;
023    import com.liferay.portal.kernel.xml.Element;
024    import com.liferay.portal.model.Layout;
025    import com.liferay.portal.theme.ThemeDisplay;
026    import com.liferay.portlet.layoutsadmin.util.SitemapURLProvider;
027    import com.liferay.portlet.layoutsadmin.util.SitemapUtil;
028    
029    import java.util.Locale;
030    import java.util.Set;
031    
032    /**
033     * @author Eduardo Garcia
034     */
035    @OSGiBeanProperties
036    public class LayoutSitemapURLProvider implements SitemapURLProvider {
037    
038            @Override
039            public String getClassName() {
040                    return Layout.class.getName();
041            }
042    
043            @Override
044            public void visitLayout(
045                            Element element, Layout layout, ThemeDisplay themeDisplay)
046                    throws PortalException {
047    
048                    UnicodeProperties typeSettingsProperties =
049                            layout.getTypeSettingsProperties();
050    
051                    if (!PortalUtil.isLayoutSitemapable(layout) ||
052                            !GetterUtil.getBoolean(
053                                    typeSettingsProperties.getProperty("sitemap-include"), true)) {
054    
055                            return;
056                    }
057    
058                    String layoutFullURL = PortalUtil.getLayoutFullURL(
059                            layout, themeDisplay);
060    
061                    layoutFullURL = PortalUtil.getCanonicalURL(
062                            layoutFullURL, themeDisplay, layout);
063    
064                    SitemapUtil.addURLElement(
065                            element, layoutFullURL, typeSettingsProperties,
066                            layout.getModifiedDate(), layoutFullURL,
067                            SitemapUtil.getAlternateURLs(layoutFullURL, themeDisplay, layout));
068    
069                    Set<Locale> availableLocales = LanguageUtil.getAvailableLocales(
070                            layout.getGroupId());
071    
072                    if (availableLocales.size() > 1) {
073                            Locale defaultLocale = LocaleUtil.getSiteDefault();
074    
075                            for (Locale availableLocale : availableLocales) {
076                                    if (availableLocale.equals(defaultLocale)) {
077                                            continue;
078                                    }
079    
080                                    String alternateURL = PortalUtil.getAlternateURL(
081                                            layoutFullURL, themeDisplay, availableLocale, layout);
082    
083                                    SitemapUtil.addURLElement(
084                                            element, alternateURL, typeSettingsProperties,
085                                            layout.getModifiedDate(), layoutFullURL,
086                                            SitemapUtil.getAlternateURLs(
087                                                    layoutFullURL, themeDisplay, layout));
088                            }
089                    }
090            }
091    
092    }