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 */ 046 DocumentModel setTemplate(DocumentModel template, boolean save) throws PropertyException; 047 048 /** 049 * Retrieve the {@link TemplateSourceDocument} for a given template name 050 * 051 * @param templateName name of the template 052 * @return the {@link TemplateSourceDocument} 053 */ 054 TemplateSourceDocument getSourceTemplate(String templateName); 055 056 /** 057 * Retrieve the Template {@link DocumentRef} for a given template name 058 * 059 * @param templateName name of the template 060 * @return the associated template {@link DocumentRef} 061 */ 062 DocumentRef getSourceTemplateDocRef(String templateName); 063 064 /** 065 * Retrieve the Template {@link DocumentModel} for a given template name 066 * 067 * @param templateName name of the template 068 * @return the associated template {@link DocumentModel} 069 */ 070 DocumentModel getSourceTemplateDoc(String templateName); 071 072 /** 073 * List all {@link TemplateSourceDocument}s that are bound to the underlying {@link DocumentModel} 074 */ 075 List<TemplateSourceDocument> getSourceTemplates(); 076 077 /** 078 * Return the template type for a given template name 079 */ 080 String getTemplateType(String templateName); 081 082 /** 083 * Initialize the template parameters from the associated template 084 * 085 * @param save flag to indicate if target DocumentModel must be saved or not 086 * @return the updated DocumentModel 087 */ 088 DocumentModel initializeFromTemplate(String templateName, boolean save); 089 090 /** 091 * Render the named template against the underlying DocumentModel and store the result in the main Blob 092 * 093 * @param save flag to indicate if target DocumentModel must be saved or not 094 * @return the resulting {@link Blob} 095 */ 096 Blob renderAndStoreAsAttachment(String templateName, boolean save); 097 098 /** 099 * Render the named template against the underlying DocumentModel 100 * 101 * @return the resulting {@link Blob} 102 */ 103 Blob renderWithTemplate(String templateName); 104 105 /** 106 * Indicate of the associated Template requires parameters or not 107 */ 108 boolean hasParams(String templateName); 109 110 /** 111 * Retrieve parameters for the associated template 112 */ 113 List<TemplateInput> getParams(String templateName); 114 115 /** 116 * Save parameters changes. 117 * 118 * @param params the updated list of parameters 119 * @param save flag to indicate if target DocumentModel must be saved or not 120 */ 121 DocumentModel saveParams(String templateName, List<TemplateInput> params, boolean save); 122 123 /** 124 * Return the underlying adapted {@link DocumentModel} 125 */ 126 DocumentModel getAdaptedDoc(); 127 128 /** 129 * Return the {@link Blob} of the associated template 130 */ 131 Blob getTemplateBlob(String templateName); 132 133 /** 134 * Indicate of the associated Template has editable parameters or not 135 */ 136 boolean hasEditableParams(String templateName); 137 138 /** 139 * Find the template associated to a given RenditionName 140 * 141 * @return the template name if any, null otherwise 142 */ 143 String getTemplateNameForRendition(String renditionName); 144 145 /** 146 * Get the names of all the associated templates 147 */ 148 List<String> getTemplateNames(); 149 150 /** 151 * Detach a template from the underlying {@link DocumentModel} 152 */ 153 DocumentModel removeTemplateBinding(String templateName, boolean save); 154}