001/* 002 * (C) Copyright 2008 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 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 * $Id: AbstractCreationContainerListProvider.java 30586 2008-02-26 14:30:17Z ogrisel $ 018 */ 019 020package org.nuxeo.ecm.platform.filemanager.service.extension; 021 022import java.util.Arrays; 023 024/** 025 * Helper class to contribute CreationContainerListProvider implementation to the FileManagerService. 026 * 027 * @author Olivier Grisel (ogrisel@nuxeo.com) 028 */ 029public abstract class AbstractCreationContainerListProvider implements CreationContainerListProvider { 030 031 private String name = ""; 032 033 private String[] docTypes; 034 035 public boolean accept(String docType) { 036 if (docTypes == null || docTypes.length == 0) { 037 return true; 038 } else { 039 return Arrays.asList(docTypes).contains(docType); 040 } 041 } 042 043 public String getName() { 044 return name; 045 } 046 047 public void setName(String name) { 048 this.name = name; 049 } 050 051 public String[] getDocTypes() { 052 return docTypes; 053 } 054 055 public void setDocTypes(String[] docTypes) { 056 this.docTypes = docTypes; 057 } 058 059 @Override 060 public boolean equals(Object o) { 061 if (o instanceof CreationContainerListProvider) { 062 // casting on the interface gives no guarantee that the equals 063 // relationship will be symmetric but this is documented in the interface 064 // javadoc of the getName method 065 CreationContainerListProvider provider = (CreationContainerListProvider) o; 066 return name != null && name.equals(provider.getName()); 067 } 068 return false; 069 } 070 071 @Override 072 public int hashCode() { 073 return name != null ? name.hashCode() : 0; 074 } 075 076}