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.portal.model;
016    
017    /**
018     * @author Brian Wing Shun Chan
019     */
020    public class PortletConstants {
021    
022            /**
023             * Default preferences.
024             */
025            public static final String DEFAULT_PREFERENCES = "<portlet-preferences />";
026    
027            /**
028             * Facebook integration method for FBML.
029             */
030            public static final String FACEBOOK_INTEGRATION_FBML = "fbml";
031    
032            /**
033             * Facebook integration method for IFrame.
034             */
035            public static final String FACEBOOK_INTEGRATION_IFRAME = "iframe";
036    
037            /**
038             * Instance separator.
039             */
040            public static final String INSTANCE_SEPARATOR = "_INSTANCE_";
041    
042            /**
043             * Layout separator.
044             */
045            public static final String LAYOUT_SEPARATOR = "_LAYOUT_";
046    
047            /**
048             * User principal strategy for screen name.
049             */
050            public static final String USER_PRINCIPAL_STRATEGY_SCREEN_NAME =
051                    "screenName";
052    
053            /**
054             * User principal strategy for screen name.
055             */
056            public static final String USER_PRINCIPAL_STRATEGY_USER_ID = "userId";
057    
058            /**
059             * War file separator.
060             */
061            public static final String WAR_SEPARATOR = "_WAR_";
062    
063            /**
064             * Returns the instance ID of the portlet.
065             *
066             * @return the instance ID of the portlet
067             */
068            public static String getInstanceId(String portletId) {
069                    int pos = portletId.indexOf(INSTANCE_SEPARATOR);
070    
071                    if (pos == -1) {
072                            return null;
073                    }
074                    else {
075                            return portletId.substring(pos + INSTANCE_SEPARATOR.length());
076                    }
077            }
078    
079            /**
080             * Returns the root portlet ID of the portlet.
081             *
082             * @return the root portlet ID of the portlet
083             */
084            public static String getRootPortletId(String portletId) {
085                    int pos = portletId.indexOf(INSTANCE_SEPARATOR);
086    
087                    if (pos == -1) {
088                            return portletId;
089                    }
090                    else {
091                            return portletId.substring(0, pos);
092                    }
093            }
094    
095            public static boolean hasInstanceId(String portletId) {
096                    return portletId.contains(INSTANCE_SEPARATOR);
097            }
098    
099    }