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 static org.nuxeo.ecm.platform.video.VideoConstants.STORYBOARD_PROPERTY; 022 023import java.util.ArrayList; 024import java.util.Collections; 025import java.util.List; 026 027import org.codehaus.jackson.map.ObjectMapper; 028import org.codehaus.jackson.node.ObjectNode; 029import org.jboss.seam.ScopeType; 030import org.jboss.seam.annotations.Name; 031import org.jboss.seam.annotations.Scope; 032import org.nuxeo.ecm.core.api.DocumentModel; 033import org.nuxeo.ecm.core.api.PropertyException; 034import org.nuxeo.ecm.platform.video.VideoConstants; 035 036/** 037 * Backing bean for the Storyboard view of an document with the video storyboard facet. 038 * 039 * @author ogrisel 040 */ 041@Name("storyboardActions") 042@Scope(ScopeType.EVENT) 043public class StoryboardActions { 044 045 public List<StoryboardItem> getItems(DocumentModel doc) throws PropertyException { 046 if (!doc.hasFacet(VideoConstants.HAS_STORYBOARD_FACET)) { 047 return Collections.emptyList(); 048 } 049 int size = doc.getProperty(STORYBOARD_PROPERTY).getValue(List.class).size(); 050 List<StoryboardItem> items = new ArrayList<StoryboardItem>(size); 051 for (int i = 0; i < size; i++) { 052 items.add(new StoryboardItem(doc, STORYBOARD_PROPERTY, i)); 053 } 054 return items; 055 } 056 057 public String getStoryboardItemsAsJsonSettings(DocumentModel doc) throws PropertyException { 058 List<StoryboardItem> items = getItems(doc); 059 ObjectMapper o = new ObjectMapper(); 060 ObjectNode settings = o.createObjectNode(); 061 for (StoryboardItem storyboardItem : items) { 062 ObjectNode thumb = o.createObjectNode(); 063 thumb.put("src", storyboardItem.getUrl()); 064 settings.put(storyboardItem.getTimecode().split("\\.")[0], thumb); 065 } 066 return settings.toString(); 067 } 068 069}