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.repository.cmis;
016    
017    import com.liferay.portal.InvalidRepositoryException;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.exception.SystemException;
020    import com.liferay.portal.kernel.repository.cmis.CMISRepositoryHandler;
021    import com.liferay.portal.kernel.repository.cmis.Session;
022    import com.liferay.portal.kernel.util.LocaleUtil;
023    import com.liferay.portal.kernel.util.UnicodeProperties;
024    import com.liferay.portal.security.auth.PrincipalThreadLocal;
025    
026    import java.util.HashMap;
027    import java.util.Locale;
028    import java.util.Map;
029    
030    import org.apache.chemistry.opencmis.commons.SessionParameter;
031    import org.apache.chemistry.opencmis.commons.enums.BindingType;
032    
033    /**
034     * @author Alexander Chow
035     */
036    public class CMISAtomPubRepository extends CMISRepositoryHandler {
037    
038            @Override
039            public Session getSession() throws PortalException, SystemException {
040                    Map<String, String> parameters = new HashMap<String, String>();
041    
042                    parameters.put(
043                            SessionParameter.ATOMPUB_URL, getTypeSettingsValue(_ATOMPUB_URL));
044                    parameters.put(
045                            SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
046                    parameters.put(SessionParameter.COMPRESSION, Boolean.TRUE.toString());
047    
048                    Locale locale = LocaleUtil.getDefault();
049    
050                    parameters.put(
051                            SessionParameter.LOCALE_ISO3166_COUNTRY,
052                            locale.getCountry());
053                    parameters.put(
054                            SessionParameter.LOCALE_ISO639_LANGUAGE, locale.getLanguage());
055    
056                    String password = PrincipalThreadLocal.getPassword();
057    
058                    parameters.put(SessionParameter.PASSWORD, password);
059    
060                    String login = getLogin();
061    
062                    parameters.put(SessionParameter.USER, login);
063    
064                    CMISRepositoryUtil.checkRepository(
065                            getRepositoryId(), parameters, getTypeSettingsProperties(),
066                            _REPOSITORY_ID);
067    
068                    return CMISRepositoryUtil.createSession(parameters);
069            }
070    
071            public String[] getSupportedConfigurations() {
072                    return _SUPPORTED_CONFIGURATIONS;
073            }
074    
075            public String[][] getSupportedParameters() {
076                    return _SUPPORTED_PARAMETERS;
077            }
078    
079            protected String getTypeSettingsValue(String typeSettingsKey)
080                    throws InvalidRepositoryException {
081    
082                    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
083    
084                    return CMISRepositoryUtil.getTypeSettingsValue(
085                            typeSettingsProperties, typeSettingsKey);
086            }
087    
088            private static final String _ATOMPUB_URL = "ATOMPUB_URL";
089    
090            private static final String _CONFIGURATION_ATOMPUB = "ATOMPUB";
091    
092            private static final String _REPOSITORY_ID = "REPOSITORY_ID";
093    
094            private static final String[] _SUPPORTED_CONFIGURATIONS = {
095                    _CONFIGURATION_ATOMPUB
096            };
097    
098            private static final String[][] _SUPPORTED_PARAMETERS = {
099                    {_ATOMPUB_URL, _REPOSITORY_ID}
100            };
101    
102    }