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