001/*
002 * (C) Copyright 2010 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.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 *     Olivier Grisel
016 */
017package org.nuxeo.ecm.platform.video.storyboard;
018
019import org.apache.commons.logging.Log;
020import org.apache.commons.logging.LogFactory;
021import org.nuxeo.ecm.core.api.DocumentModel;
022import org.nuxeo.ecm.core.api.PropertyException;
023import org.nuxeo.ecm.platform.ui.web.tag.fn.DocumentModelFunctions;
024
025/**
026 * Small DTO to precompute the thumbnail URLs for JSF
027 */
028public class StoryboardItem {
029
030    public static final Log log = LogFactory.getLog(StoryboardItem.class);
031
032    protected final DocumentModel doc;
033
034    protected final int position;
035
036    protected final String blobPropertyName;
037
038    protected final String filename;
039
040    protected String timecode = "0";
041
042    public StoryboardItem(DocumentModel doc, String basePropertyPath, int position) {
043        this.doc = doc;
044        this.position = position;
045        String propertyPath = basePropertyPath + "/" + position;
046        blobPropertyName = propertyPath + "/content";
047        filename = String.format("storyboard-%03d.jpeg", position);
048        try {
049            Double tc = (Double) doc.getPropertyValue(propertyPath + "/timecode");
050            if (tc != null) {
051                timecode = String.format("%.2f", tc);
052            }
053            // TODO: read filename from blob too
054        } catch (PropertyException e) {
055            log.warn(e);
056        }
057    }
058
059    public String getUrl() {
060        return DocumentModelFunctions.bigFileUrl(doc, blobPropertyName, filename);
061    }
062
063    public String getTimecode() {
064        return timecode;
065    }
066}