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 * Nuxeo - initial API and implementation 018 * 019 */ 020 021package org.nuxeo.template.api.adapters; 022 023import java.util.List; 024 025import org.nuxeo.ecm.core.api.Blob; 026import org.nuxeo.ecm.core.api.DocumentModel; 027import org.nuxeo.ecm.core.api.PropertyException; 028import org.nuxeo.template.api.TemplateInput; 029import org.nuxeo.template.api.TemplateProcessor; 030 031/** 032 * It is mainly the source used by {@link TemplateBasedDocument} to handle the rendering. 033 * 034 * @author Tiry (tdelprat@nuxeo.com) 035 */ 036public interface TemplateSourceDocument { 037 038 String INIT_DONE_FLAG = "TEMPLATE_INIT_DONE"; 039 040 /** 041 * Return the String representation of the parameters of the template 042 */ 043 String getParamsAsString() throws PropertyException; 044 045 /** 046 * Add or update a {@link TemplateInput} to the list of template parameters. 047 */ 048 List<TemplateInput> addInput(TemplateInput input); 049 050 /** 051 * Returns whether or not the {@link TemplateInput} already exists, based on the name, in the template. 052 */ 053 boolean hasInput(String inputName); 054 055 /** 056 * Return the template Type (i.e. the associated {@link TemplateProcessor} name. 057 * 058 * @return {@link TemplateProcessor} name if any, null otherwise 059 */ 060 String getTemplateType(); 061 062 /** 063 * Initialize the DocumentModel 064 * <ul> 065 * <li>finds associated TemplateProcessor</li> 066 * <li>extract Template parameters</li> 067 * </ul> 068 * 069 * @param save flag to indicate if target DocumentModel must be saved or not 070 */ 071 void initTemplate(boolean save); 072 073 /** 074 * Initialize the Types2Template binding 075 */ 076 void initTypesBindings(); 077 078 /** 079 * Retrieve the Blob holding the template file 080 */ 081 Blob getTemplateBlob() throws PropertyException; 082 083 /** 084 * Retrieve the parameters associated to the Template file 085 */ 086 List<TemplateInput> getParams() throws PropertyException; 087 088 /** 089 * Save parameters changes 090 * 091 * @param params the updated list of parameters 092 * @param save flag to indicate if target DocumentModel must be saved or not 093 * @return the updated DocumentModel 094 */ 095 DocumentModel saveParams(List<TemplateInput> params, boolean save); 096 097 /** 098 * Return the underlying adapted {@link DocumentModel}s 099 */ 100 DocumentModel getAdaptedDoc(); 101 102 /** 103 * Save changes in the underlying {@link DocumentModel} 104 */ 105 DocumentModel save(); 106 107 /** 108 * Return flag to indicate if Documents associated to this template can override parametes value 109 */ 110 boolean allowInstanceOverride(); 111 112 /** 113 * Indicate of the associated Template has editable parameters or not 114 */ 115 boolean hasEditableParams(); 116 117 /** 118 * Get List of Document Types than can be associated to this Template. 119 * 120 * @return List of Document Types or an empty List 121 */ 122 List<String> getApplicableTypes(); 123 124 /** 125 * Get List of Document Types that must be automatically bound to this template at creation time 126 * 127 * @return List of Document Types or an empty List 128 */ 129 List<String> getForcedTypes(); 130 131 /** 132 * Get the list of {@link TemplateBasedDocument}s associated to this template 133 */ 134 List<TemplateBasedDocument> getTemplateBasedDocuments(); 135 136 /** 137 * Remove Type mapping for this template 138 */ 139 void removeForcedType(String type, boolean save); 140 141 /** 142 * Update the Type mapping for this template 143 */ 144 void setForcedTypes(String[] forcedTypes, boolean save); 145 146 /** 147 * Sets the expected output mime-type. If the expected mime-type is different from the output of the rendering, 148 * converters will be applied. 149 */ 150 void setOutputFormat(String mimetype, boolean save); 151 152 /** 153 * Return the expected mime-type of the resulting rendering 154 */ 155 String getOutputFormat(); 156 157 /** 158 * Indicate if the template can be used as main blob in the {@link TemplateBasedDocument} (i.e. if the template is 159 * editable by the end user) 160 */ 161 boolean useAsMainContent(); 162 163 /** 164 * Shortcut to access the underlying {@link DocumentModel} name 165 */ 166 String getName(); 167 168 /** 169 * Shortcut to access the underlying {@link Blob} filename 170 * 171 * @return name 172 */ 173 String getFileName(); 174 175 /** 176 * Shortcut to access the underlying {@link DocumentModel} title 177 * 178 * @return template filename 179 */ 180 String getTitle(); 181 182 /** 183 * Shortcut to access the underlying {@link DocumentModel} versionLabel 184 * 185 * @return versionLabel 186 */ 187 String getVersionLabel(); 188 189 /** 190 * Shortcut to access the underlying {@link DocumentModel} uuid 191 * 192 * @return UUID 193 */ 194 String getId(); 195 196 /** 197 * Return label key used for template 198 */ 199 String getLabel(); 200 201 /** 202 * Associate Template to a Rendition 203 */ 204 void setTargetRenditioName(String renditionName, boolean save); 205 206 /** 207 * Get the associated Rendition if any 208 * 209 * @return Rendition name or null 210 */ 211 String getTargetRenditionName(); 212 213 /** 214 * Write accessor to the {@link Blob} used to store the template 215 */ 216 void setTemplateBlob(Blob blob, boolean save); 217 218}