001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.ecm.platform.rendering.fm.adapters; 016 017import org.nuxeo.ecm.core.api.model.Property; 018import org.nuxeo.ecm.core.api.model.impl.ListProperty; 019 020import freemarker.template.AdapterTemplateModel; 021import freemarker.template.TemplateCollectionModel; 022import freemarker.template.TemplateModel; 023import freemarker.template.TemplateModelException; 024import freemarker.template.TemplateModelIterator; 025import freemarker.template.TemplateSequenceModel; 026 027/** 028 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 029 */ 030public class ListPropertyTemplate extends PropertyWrapper implements TemplateCollectionModel, TemplateSequenceModel, 031 AdapterTemplateModel { 032 033 protected final ListProperty property; 034 035 public ListPropertyTemplate(DocumentObjectWrapper wrapper, ListProperty property) { 036 super(wrapper); 037 this.property = property; 038 } 039 040 @Override 041 @SuppressWarnings("rawtypes") 042 public Object getAdaptedObject(Class hint) { 043 return property; 044 } 045 046 @Override 047 public TemplateModelIterator iterator() throws TemplateModelException { 048 return new PropertyIteratorTemplate(wrapper, property.iterator()); 049 } 050 051 @Override 052 public TemplateModel get(int arg0) throws TemplateModelException { 053 Property p = property.get(arg0); 054 return wrap(p); 055 } 056 057 @Override 058 public int size() throws TemplateModelException { 059 return property.size(); 060 } 061 062}