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