001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.util;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.StringUtil;
020    import com.liferay.portal.kernel.util.Validator;
021    import com.liferay.portal.model.LayoutSet;
022    import com.liferay.util.ContentUtil;
023    
024    /**
025     * @author David Truong
026     */
027    public class RobotsUtil {
028    
029            public static String getDefaultRobots() {
030                    return getDefaultRobots(null);
031            }
032    
033            public static String getDefaultRobots(String virtualHost) {
034                    if (Validator.isNotNull(virtualHost)) {
035                            String content = ContentUtil.get(
036                                    PropsValues.ROBOTS_TXT_WITH_SITEMAP);
037    
038                            content = StringUtil.replace(content, "[$HOST$]", virtualHost);
039    
040                            return content;
041                    }
042    
043                    return ContentUtil.get(PropsValues.ROBOTS_TXT_WITHOUT_SITEMAP);
044            }
045    
046            public static String getRobots(LayoutSet layoutSet) {
047                    if (layoutSet == null) {
048                            return getDefaultRobots(null);
049                    }
050    
051                    String virtualHostname = StringPool.BLANK;
052    
053                    try {
054                            virtualHostname = layoutSet.getVirtualHostname();
055                    }
056                    catch (Exception e) {
057                    }
058    
059                    return GetterUtil.get(
060                            layoutSet.getSettingsProperty(
061                                    layoutSet.isPrivateLayout() + "-robots.txt"),
062                                    getDefaultRobots(virtualHostname));
063            }
064    
065    }