001    /**
002     * Copyright (c) 2000-2013 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            @Override
031            public String getSessionIdDelimiter() {
032                    return _sessionIdDelimiter;
033            }
034    
035            @Override
036            public boolean hasSessionDelimiter() {
037                    return Validator.isNotNull(_sessionIdDelimiter);
038            }
039    
040            @Override
041            public String parseSessionId(String sessionId) {
042                    if (Validator.isNull(_sessionIdDelimiter)) {
043                            return sessionId;
044                    }
045    
046                    int pos = sessionId.indexOf(_sessionIdDelimiter);
047    
048                    if (pos == -1) {
049                            return sessionId;
050                    }
051    
052                    return sessionId.substring(0, pos);
053            }
054    
055            private static String _sessionIdDelimiter;
056    
057            static {
058                    String sessionIdDelimiter = PropsValues.SESSION_ID_DELIMITER;
059    
060                    if (Validator.isNull(sessionIdDelimiter)) {
061                            sessionIdDelimiter = PropsUtil.get(
062                                    "session.id." + ServerDetector.getServerId() + ".delimiter");
063                    }
064    
065                    if (sessionIdDelimiter == null) {
066                            sessionIdDelimiter = StringPool.BLANK;
067                    }
068    
069                    _sessionIdDelimiter = sessionIdDelimiter;
070            }
071    
072    }