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.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 CMISWebServicesRepository 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.BINDING_TYPE, BindingType.WEBSERVICES.value());
044                    parameters.put(SessionParameter.COMPRESSION, Boolean.TRUE.toString());
045    
046                    Locale locale = LocaleUtil.getDefault();
047    
048                    parameters.put(
049                            SessionParameter.LOCALE_ISO3166_COUNTRY,
050                            locale.getCountry());
051                    parameters.put(SessionParameter.LOCALE_ISO639_LANGUAGE,
052                            locale.getLanguage());
053    
054                    String password = PrincipalThreadLocal.getPassword();
055    
056                    parameters.put(SessionParameter.PASSWORD, password);
057    
058                    String login = getLogin();
059    
060                    parameters.put(SessionParameter.USER, login);
061    
062                    parameters.put(
063                            SessionParameter.WEBSERVICES_ACL_SERVICE,
064                            getTypeSettingsValue(_WEBSERVICES_ACL_SERVICE));
065                    parameters.put(
066                            SessionParameter.WEBSERVICES_DISCOVERY_SERVICE,
067                            getTypeSettingsValue(_WEBSERVICES_DISCOVERY_SERVICE));
068                    parameters.put(
069                            SessionParameter.WEBSERVICES_MULTIFILING_SERVICE,
070                            getTypeSettingsValue(_WEBSERVICES_MULTIFILING_SERVICE));
071                    parameters.put(
072                            SessionParameter.WEBSERVICES_NAVIGATION_SERVICE,
073                            getTypeSettingsValue(_WEBSERVICES_NAVIGATION_SERVICE));
074                    parameters.put(
075                            SessionParameter.WEBSERVICES_OBJECT_SERVICE,
076                            getTypeSettingsValue(_WEBSERVICES_OBJECT_SERVICE));
077                    parameters.put(
078                            SessionParameter.WEBSERVICES_POLICY_SERVICE,
079                            getTypeSettingsValue(_WEBSERVICES_POLICY_SERVICE));
080                    parameters.put(
081                            SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE,
082                            getTypeSettingsValue(_WEBSERVICES_RELATIONSHIP_SERVICE));
083                    parameters.put(
084                            SessionParameter.WEBSERVICES_REPOSITORY_SERVICE,
085                            getTypeSettingsValue(_WEBSERVICES_REPOSITORY_SERVICE));
086                    parameters.put(
087                            SessionParameter.WEBSERVICES_VERSIONING_SERVICE,
088                            getTypeSettingsValue(_WEBSERVICES_VERSIONING_SERVICE));
089    
090                    CMISRepositoryUtil.checkRepository(
091                            getRepositoryId(), parameters, getTypeSettingsProperties(),
092                            _REPOSITORY_ID);
093    
094                    return CMISRepositoryUtil.createSession(parameters);
095            }
096    
097            public String[] getSupportedConfigurations() {
098                    return _SUPPORTED_CONFIGURATIONS;
099            }
100    
101            public String[][] getSupportedParameters() {
102                    return _SUPPORTED_PARAMETERS;
103            }
104    
105            protected String getTypeSettingsValue(String typeSettingsKey)
106                    throws InvalidRepositoryException {
107    
108                    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
109    
110                    return CMISRepositoryUtil.getTypeSettingsValue(
111                            typeSettingsProperties, typeSettingsKey);
112            }
113    
114            private static final String _CONFIGURATION_WEBSERVICES = "WEBSERVICES";
115    
116            private static final String _REPOSITORY_ID = "REPOSITORY_ID";
117    
118            private static final String _WEBSERVICES_ACL_SERVICE =
119                    "WEBSERVICES_ACL_SERVICE";
120    
121            private static final String _WEBSERVICES_DISCOVERY_SERVICE =
122                    "WEBSERVICES_DISCOVERY_SERVICE";
123    
124            private static final String _WEBSERVICES_MULTIFILING_SERVICE =
125                    "WEBSERVICES_MULTIFILING_SERVICE";
126    
127            private static final String _WEBSERVICES_NAVIGATION_SERVICE =
128                    "WEBSERVICES_NAVIGATION_SERVICE";
129    
130            private static final String _WEBSERVICES_OBJECT_SERVICE =
131                    "WEBSERVICES_OBJECT_SERVICE";
132    
133            private static final String _WEBSERVICES_POLICY_SERVICE =
134                    "WEBSERVICES_POLICY_SERVICE";
135    
136            private static final String _WEBSERVICES_RELATIONSHIP_SERVICE =
137                    "WEBSERVICES_RELATIONSHIP_SERVICE";
138    
139            private static final String _WEBSERVICES_REPOSITORY_SERVICE =
140                    "WEBSERVICES_REPOSITORY_SERVICE";
141    
142            private static final String _WEBSERVICES_VERSIONING_SERVICE =
143                    "WEBSERVICES_VERSIONING_SERVICE";
144    
145            private static final String[] _SUPPORTED_CONFIGURATIONS = {
146                    _CONFIGURATION_WEBSERVICES
147            };
148    
149            private static final String[][] _SUPPORTED_PARAMETERS = {
150                    {
151                            _REPOSITORY_ID, _WEBSERVICES_ACL_SERVICE,
152                            _WEBSERVICES_DISCOVERY_SERVICE, _WEBSERVICES_MULTIFILING_SERVICE,
153                            _WEBSERVICES_NAVIGATION_SERVICE, _WEBSERVICES_OBJECT_SERVICE,
154                            _WEBSERVICES_POLICY_SERVICE, _WEBSERVICES_RELATIONSHIP_SERVICE,
155                            _WEBSERVICES_REPOSITORY_SERVICE, _WEBSERVICES_VERSIONING_SERVICE
156                    }
157            };
158    
159    }