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