001    /**
002     * Copyright (c) 2000-2012 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.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    }