001/* 002 * (C) Copyright 2006-2016 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 * Tiago Cardoso <[email protected]> 018 */ 019package org.nuxeo.ecm.platform.threed.renderView; 020 021import org.apache.commons.logging.Log; 022import org.apache.commons.logging.LogFactory; 023import org.nuxeo.ecm.core.api.Blob; 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.core.api.PropertyException; 026import org.nuxeo.ecm.platform.ui.web.tag.fn.DocumentModelFunctions; 027 028import java.util.Calendar; 029 030/** 031 * Small DTO to precompute the thumbnail URLs for JSF 032 * 033 * @since 8.4 034 */ 035public class RenderViewItem { 036 037 public static final Log log = LogFactory.getLog(RenderViewItem.class); 038 039 protected final DocumentModel doc; 040 041 protected final int position; 042 043 protected final String blobPropertyName; 044 045 protected final String thumbnailPropertyName; 046 047 protected final String titlePropertyName; 048 049 protected String filename; 050 051 protected String thumbFilename; 052 053 protected String title; 054 055 public RenderViewItem(DocumentModel doc, String basePropertyPath, int position) { 056 this.doc = doc; 057 this.position = position; 058 String propertyPath = basePropertyPath + "/" + position; 059 blobPropertyName = propertyPath + "/content"; 060 thumbnailPropertyName = propertyPath + "/thumbnail"; 061 titlePropertyName = propertyPath + "/title"; 062 try { 063 filename = ((Blob) doc.getPropertyValue(blobPropertyName)).getFilename(); 064 thumbFilename = ((Blob) doc.getPropertyValue(blobPropertyName)).getFilename(); 065 title = (String) doc.getPropertyValue(titlePropertyName); 066 } catch (PropertyException e) { 067 log.warn(e); 068 } 069 } 070 071 public String getThumbnailUrl() { 072 return DocumentModelFunctions.bigFileUrl(doc, thumbnailPropertyName, thumbFilename); 073 } 074 075 public String getUrl() { 076 return DocumentModelFunctions.bigFileUrl(doc, blobPropertyName, filename); 077 } 078 079 public String getTitle() { 080 return title; 081 } 082 083 public Integer getAzimuth() { 084 return Integer.valueOf(thumbFilename.split("-")[3]); 085 } 086 087 public Integer getZenith() { 088 return Integer.valueOf(thumbFilename.split("-")[4]); 089 } 090 091}