001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 * Contributors:
016 * Nuxeo - initial API and implementation
017 */
018
019package org.nuxeo.ecm.directory.localconfiguration;
020
021import static org.nuxeo.ecm.directory.localconfiguration.DirectoryConfigurationConstants.DIRECTORY_CONFIGURATION_FIELD;
022
023import org.apache.commons.logging.Log;
024import org.apache.commons.logging.LogFactory;
025import org.nuxeo.ecm.core.api.DocumentModel;
026import org.nuxeo.ecm.core.api.DocumentRef;
027import org.nuxeo.ecm.core.api.PropertyException;
028import org.nuxeo.ecm.core.api.localconfiguration.AbstractLocalConfiguration;
029
030/**
031 * Default implementation of {@code DirectoryConfiguration}.
032 *
033 * @author <a href="mailto:qlamerand@nuxeo.com">Benjamin JALON</a>
034 * @since 5.4.2
035 */
036public class DirectoryConfigurationAdapter extends AbstractLocalConfiguration<DirectoryConfiguration> implements
037        DirectoryConfiguration {
038
039    private static final Log log = LogFactory.getLog(DirectoryConfigurationAdapter.class);
040
041    protected DocumentRef documentRef;
042
043    protected String lcDirectorySuffix;
044
045    public DirectoryConfigurationAdapter(DocumentModel doc) {
046        documentRef = doc.getRef();
047        try {
048            lcDirectorySuffix = (String) doc.getPropertyValue(DIRECTORY_CONFIGURATION_FIELD);
049            if (lcDirectorySuffix != null) {
050                lcDirectorySuffix = lcDirectorySuffix.trim();
051            }
052        } catch (PropertyException e) {
053            log.error("Failed to get DirectoryConfiguration", e);
054        }
055    }
056
057    @Override
058    public boolean canMerge() {
059        return false;
060    }
061
062    @Override
063    public DocumentRef getDocumentRef() {
064        return documentRef;
065    }
066
067    @Override
068    public DirectoryConfiguration merge(DirectoryConfiguration other) {
069        throw new UnsupportedOperationException("Directory configurations can't be merged");
070    }
071
072    @Override
073    public String getDirectorySuffix() {
074        return lcDirectorySuffix;
075    }
076
077}