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.servlet.filters.compoundsessionid;
016    
017    import com.liferay.portal.kernel.servlet.filters.compoundsessionid.CompoundSessionIdSplitter;
018    import com.liferay.portal.kernel.util.PropsUtil;
019    import com.liferay.portal.kernel.util.ServerDetector;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.kernel.util.Validator;
022    import com.liferay.portal.util.PropsValues;
023    
024    /**
025     * @author Michael C. Han
026     */
027    public class CompoundSessionIdSplitterImpl
028            implements CompoundSessionIdSplitter {
029    
030            public String getSessionIdDelimiter() {
031                    return _sessionIdDelimiter;
032            }
033    
034            public boolean hasSessionDelimiter() {
035                    return Validator.isNotNull(_sessionIdDelimiter);
036            }
037    
038            public String parseSessionId(String sessionId) {
039                    if (Validator.isNull(_sessionIdDelimiter)) {
040                            return sessionId;
041                    }
042    
043                    int pos = sessionId.indexOf(_sessionIdDelimiter);
044    
045                    if (pos == -1) {
046                            return sessionId;
047                    }
048    
049                    return sessionId.substring(0, pos);
050            }
051    
052            private static String _sessionIdDelimiter;
053    
054            static {
055                    String sessionIdDelimiter = PropsValues.SESSION_ID_DELIMITER;
056    
057                    if (Validator.isNull(sessionIdDelimiter)) {
058                            _sessionIdDelimiter = PropsUtil.get(
059                                    "session.id." + ServerDetector.getServerId() + " .delimiter");
060                    }
061    
062                    if (_sessionIdDelimiter == null) {
063                            _sessionIdDelimiter = StringPool.BLANK;
064                    }
065    
066                    _sessionIdDelimiter = sessionIdDelimiter;
067            }
068    
069    }