001/*
002 * (C) Copyright 2009-2013 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 *     Peter Di Lorenzo
018 *     Florent Guillaume
019 */
020package org.nuxeo.ecm.platform.video.importer;
021
022import org.nuxeo.ecm.core.api.Blob;
023import org.nuxeo.ecm.core.api.DocumentModel;
024import org.nuxeo.ecm.platform.filemanager.service.extension.AbstractFileImporter;
025import org.nuxeo.ecm.platform.types.Type;
026import org.nuxeo.ecm.platform.types.TypeManager;
027import org.nuxeo.ecm.platform.video.VideoConstants;
028import org.nuxeo.runtime.api.Framework;
029
030/**
031 * This class will create a Document of type "Video" from the uploaded file, if the uploaded file matches any of the
032 * mime types listed in the filemanager-plugins.xml file.
033 * <p>
034 * If an existing document with the same title is found, it will overwrite it and increment the version number if the
035 * overwrite flag is set to true; Otherwise, it will generate a new title and create a new Document of type Video with
036 * that title.
037 */
038public class VideoImporter extends AbstractFileImporter {
039
040    private static final long serialVersionUID = 1L;
041
042    @Override
043    public String getDefaultDocType() {
044        return VideoConstants.VIDEO_TYPE;
045    }
046
047    @Override
048    public boolean isOverwriteByTitle() {
049        return true;
050    }
051
052    @Override
053    public void updateDocument(DocumentModel doc, Blob content) {
054        super.updateDocument(doc, content);
055        // update the icon
056        Type type = Framework.getService(TypeManager.class).getType(doc.getType());
057        if (type != null) {
058            doc.setProperty("common", "icon", type.getIcon());
059        }
060    }
061
062}