001/* 002 * (C) Copyright 2006-2012 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 * Nuxeo - initial API and implementation 018 * 019 */ 020package org.nuxeo.template.api.adapters; 021 022import java.util.List; 023 024import org.nuxeo.ecm.core.api.Blob; 025import org.nuxeo.ecm.core.api.DocumentModel; 026import org.nuxeo.ecm.core.api.DocumentRef; 027import org.nuxeo.ecm.core.api.PropertyException; 028import org.nuxeo.template.api.TemplateInput; 029 030/** 031 * Adapter interface for the {@link DocumentModel} that support rendering via a Template. This Document can be 032 * associated with a {@link TemplateSourceDocument} that provides the rendering template as well as the default inputs 033 * used for rendering. 034 * 035 * @author Tiry (tdelprat@nuxeo.com) 036 */ 037public interface TemplateBasedDocument { 038 039 /** 040 * Associate the document to a Template. 041 * 042 * @param template DocumentModel holding the template 043 * @param save flag to indicate if target DocumentModel must be saved or not 044 * @return the updated DocumentModel 045 * @throws PropertyException 046 */ 047 public DocumentModel setTemplate(DocumentModel template, boolean save) throws PropertyException; 048 049 /** 050 * Retrieve the {@link TemplateSourceDocument} for a given template name 051 * 052 * @param templateName name of the template 053 * @return the {@link TemplateSourceDocument} 054 */ 055 public TemplateSourceDocument getSourceTemplate(String templateName); 056 057 /** 058 * Retrieve the Template {@link DocumentRef} for a given template name 059 * 060 * @param templateName name of the template 061 * @return the associated template {@link DocumentRef} 062 */ 063 public DocumentRef getSourceTemplateDocRef(String templateName); 064 065 /** 066 * Retrieve the Template {@link DocumentModel} for a given template name 067 * 068 * @param templateName name of the template 069 * @return the associated template {@link DocumentModel} 070 */ 071 public DocumentModel getSourceTemplateDoc(String templateName); 072 073 /** 074 * List all {@link TemplateSourceDocument}s that are bound to the underlying {@link DocumentModel} 075 * 076 * @return 077 */ 078 public List<TemplateSourceDocument> getSourceTemplates(); 079 080 /** 081 * Return the template type for a given template name 082 * 083 * @param templateName 084 * @return 085 */ 086 public String getTemplateType(String templateName); 087 088 /** 089 * Initialize the template parameters from the associated template 090 * 091 * @param templateName 092 * @param save flag to indicate if target DocumentModel must be saved or not 093 * @return the updated DocumentModel 094 */ 095 public DocumentModel initializeFromTemplate(String templateName, boolean save); 096 097 /** 098 * Render the named template against the underlying DocumentModel and store the result in the main Blob 099 * 100 * @param templateName 101 * @param save flag to indicate if target DocumentModel must be saved or not 102 * @return the resulting {@link Blob} 103 */ 104 public Blob renderAndStoreAsAttachment(String templateName, boolean save); 105 106 /** 107 * Render the named template against the underlying DocumentModel 108 * 109 * @param templateName 110 * @return the resulting {@link Blob} 111 */ 112 public Blob renderWithTemplate(String templateName); 113 114 /** 115 * Indicate of the associated Template requires parameters or not 116 * 117 * @param templateName 118 * @return 119 */ 120 public boolean hasParams(String templateName); 121 122 /** 123 * Retrieve parameters for the associated template 124 * 125 * @param templateName 126 * @return 127 */ 128 public List<TemplateInput> getParams(String templateName); 129 130 /** 131 * Save parameters changes. 132 * 133 * @param templateName 134 * @param params the updated list of parameters 135 * @param save flag to indicate if target DocumentModel must be saved or not 136 * @return 137 */ 138 public DocumentModel saveParams(String templateName, List<TemplateInput> params, boolean save); 139 140 /** 141 * Return the underlying adapted {@link DocumentModel} 142 * 143 * @return 144 */ 145 public DocumentModel getAdaptedDoc(); 146 147 /** 148 * Return the {@link Blob} of the associated template 149 * 150 * @param templateName 151 * @return 152 */ 153 public Blob getTemplateBlob(String templateName); 154 155 /** 156 * Indicate of the associated Template has editable parameters or not 157 * 158 * @param templateName 159 * @return 160 */ 161 public boolean hasEditableParams(String templateName); 162 163 /** 164 * Find the template associated to a given RenditionName 165 * 166 * @param renditionName 167 * @return the template name if any, null otherwise 168 */ 169 String getTemplateNameForRendition(String renditionName); 170 171 /** 172 * Get the names of all the associated templates 173 * 174 * @return 175 */ 176 public List<String> getTemplateNames(); 177 178 /** 179 * Detach a template from the underlying {@link DocumentModel} 180 * 181 * @param templateName 182 * @param save 183 * @return 184 */ 185 public DocumentModel removeTemplateBinding(String templateName, boolean save); 186}