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