001/*
002 * (C) Copyright 2006-2012 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$
018 */
019package org.nuxeo.ecm.platform.scanimporter.service;
020
021import java.io.Serializable;
022import java.util.HashMap;
023import java.util.List;
024import java.util.Map;
025
026import org.nuxeo.ecm.core.api.Blob;
027import org.nuxeo.ecm.core.api.blobholder.BlobHolder;
028import org.nuxeo.ecm.core.api.blobholder.SimpleBlobHolder;
029
030/**
031 * Extended implementation of {@link BlobHolder} - stores properties extracted from XML - stores documentType extracted
032 * from XML
033 *
034 * @author Thierry Delprat
035 */
036public class ScanFileBlobHolder extends SimpleBlobHolder {
037
038    protected final Map<String, Serializable> properties;
039
040    protected String targetType = null;
041
042    public ScanFileBlobHolder(List<Blob> blobs, Map<String, Serializable> properties, String targetType) {
043        super(blobs);
044        this.properties = properties;
045        this.targetType = targetType;
046    }
047
048    public ScanFileBlobHolder(Blob blob, String targetType) {
049        super(blob);
050        this.properties = new HashMap<String, Serializable>();
051        this.targetType = targetType;
052    }
053
054    @Override
055    public Serializable getProperty(String name) {
056        if (properties == null) {
057            return null;
058        }
059        return properties.get(name);
060    }
061
062    @Override
063    public Map<String, Serializable> getProperties() {
064        return properties;
065    }
066
067    public String getTargetType() {
068        if (targetType == null) {
069            return ScanFileMappingDescriptor.DEFAULT_LEAF_TYPE;
070        }
071        return targetType;
072    }
073
074}