001/* 002 * (C) Copyright 2011 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * Contributors: 014 * Nuxeo - initial API and implementation 015 */ 016 017package org.nuxeo.ecm.directory.localconfiguration; 018 019import static org.nuxeo.ecm.directory.localconfiguration.DirectoryConfigurationConstants.DIRECTORY_CONFIGURATION_FIELD; 020 021import org.apache.commons.logging.Log; 022import org.apache.commons.logging.LogFactory; 023import org.nuxeo.ecm.core.api.DocumentModel; 024import org.nuxeo.ecm.core.api.DocumentRef; 025import org.nuxeo.ecm.core.api.PropertyException; 026import org.nuxeo.ecm.core.api.localconfiguration.AbstractLocalConfiguration; 027 028/** 029 * Default implementation of {@code DirectoryConfiguration}. 030 * 031 * @author <a href="mailto:qlamerand@nuxeo.com">Benjamin JALON</a> 032 * @since 5.4.2 033 */ 034public class DirectoryConfigurationAdapter extends AbstractLocalConfiguration<DirectoryConfiguration> implements 035 DirectoryConfiguration { 036 037 private static final Log log = LogFactory.getLog(DirectoryConfigurationAdapter.class); 038 039 protected DocumentRef documentRef; 040 041 protected String lcDirectorySuffix; 042 043 public DirectoryConfigurationAdapter(DocumentModel doc) { 044 documentRef = doc.getRef(); 045 try { 046 lcDirectorySuffix = (String) doc.getPropertyValue(DIRECTORY_CONFIGURATION_FIELD); 047 if (lcDirectorySuffix != null) { 048 lcDirectorySuffix = lcDirectorySuffix.trim(); 049 } 050 } catch (PropertyException e) { 051 log.error("Failed to get DirectoryConfiguration", e); 052 } 053 } 054 055 @Override 056 public boolean canMerge() { 057 return false; 058 } 059 060 @Override 061 public DocumentRef getDocumentRef() { 062 return documentRef; 063 } 064 065 @Override 066 public DirectoryConfiguration merge(DirectoryConfiguration other) { 067 throw new UnsupportedOperationException("Directory configurations can't be merged"); 068 } 069 070 @Override 071 public String getDirectorySuffix() { 072 return lcDirectorySuffix; 073 } 074 075}