001    /**
002     * Copyright (c) 2000-present 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.repository.cmis.CMISRepositoryHandler;
020    import com.liferay.portal.kernel.repository.cmis.Session;
021    import com.liferay.portal.kernel.util.LocaleUtil;
022    import com.liferay.portal.kernel.util.UnicodeProperties;
023    import com.liferay.portal.kernel.util.Validator;
024    import com.liferay.portal.security.auth.PrincipalThreadLocal;
025    import com.liferay.portal.util.PropsValues;
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 {
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 login = getLogin();
057                    String password = null;
058    
059                    if (Validator.isNotNull(login)) {
060                            password = PrincipalThreadLocal.getPassword();
061                    }
062                    else {
063                            login = PropsValues.DL_REPOSITORY_GUEST_USERNAME;
064                            password = PropsValues.DL_REPOSITORY_GUEST_PASSWORD;
065                    }
066    
067                    parameters.put(SessionParameter.PASSWORD, password);
068                    parameters.put(SessionParameter.USER, login);
069    
070                    CMISRepositoryUtil.checkRepository(
071                            getRepositoryId(), parameters, getTypeSettingsProperties(),
072                            _REPOSITORY_ID);
073    
074                    return CMISRepositoryUtil.createSession(parameters);
075            }
076    
077            @Override
078            public String[] getSupportedConfigurations() {
079                    return _SUPPORTED_CONFIGURATIONS;
080            }
081    
082            @Override
083            public String[][] getSupportedParameters() {
084                    return _SUPPORTED_PARAMETERS;
085            }
086    
087            protected String getTypeSettingsValue(String typeSettingsKey)
088                    throws InvalidRepositoryException {
089    
090                    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
091    
092                    return CMISRepositoryUtil.getTypeSettingsValue(
093                            typeSettingsProperties, typeSettingsKey);
094            }
095    
096            private static final String _ATOMPUB_URL = "ATOMPUB_URL";
097    
098            private static final String _CONFIGURATION_ATOMPUB = "ATOMPUB";
099    
100            private static final String _REPOSITORY_ID = "REPOSITORY_ID";
101    
102            private static final String[] _SUPPORTED_CONFIGURATIONS = {
103                    _CONFIGURATION_ATOMPUB
104            };
105    
106            private static final String[][] _SUPPORTED_PARAMETERS = {
107                    {_ATOMPUB_URL, _REPOSITORY_ID}
108            };
109    
110    }