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