001/*
002 * (C) Copyright 2006-20012 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 *
017 */
018package org.nuxeo.template.api.adapters;
019
020import java.util.List;
021
022import org.nuxeo.ecm.core.api.Blob;
023import org.nuxeo.ecm.core.api.DocumentModel;
024import org.nuxeo.ecm.core.api.DocumentRef;
025import org.nuxeo.ecm.core.api.PropertyException;
026import org.nuxeo.template.api.TemplateInput;
027
028/**
029 * Adapter interface for the {@link DocumentModel} that support rendering via a Template. This Document can be
030 * associated with a {@link TemplateSourceDocument} that provides the rendering template as well as the default inputs
031 * used for rendering.
032 *
033 * @author Tiry (tdelprat@nuxeo.com)
034 */
035public interface TemplateBasedDocument {
036
037    /**
038     * Associate the document to a Template.
039     *
040     * @param template DocumentModel holding the template
041     * @param save flag to indicate if target DocumentModel must be saved or not
042     * @return the updated DocumentModel
043     * @throws PropertyException
044     */
045    public DocumentModel setTemplate(DocumentModel template, boolean save) throws PropertyException;
046
047    /**
048     * Retrieve the {@link TemplateSourceDocument} for a given template name
049     *
050     * @param templateName name of the template
051     * @return the {@link TemplateSourceDocument}
052     */
053    public TemplateSourceDocument getSourceTemplate(String templateName);
054
055    /**
056     * Retrieve the Template {@link DocumentRef} for a given template name
057     *
058     * @param templateName name of the template
059     * @return the associated template {@link DocumentRef}
060     */
061    public DocumentRef getSourceTemplateDocRef(String templateName);
062
063    /**
064     * Retrieve the Template {@link DocumentModel} for a given template name
065     *
066     * @param templateName name of the template
067     * @return the associated template {@link DocumentModel}
068     */
069    public DocumentModel getSourceTemplateDoc(String templateName);
070
071    /**
072     * List all {@link TemplateSourceDocument}s that are bound to the underlying {@link DocumentModel}
073     *
074     * @return
075     */
076    public List<TemplateSourceDocument> getSourceTemplates();
077
078    /**
079     * Return the template type for a given template name
080     *
081     * @param templateName
082     * @return
083     */
084    public String getTemplateType(String templateName);
085
086    /**
087     * Initialize the template parameters from the associated template
088     *
089     * @param templateName
090     * @param save flag to indicate if target DocumentModel must be saved or not
091     * @return the updated DocumentModel
092     */
093    public DocumentModel initializeFromTemplate(String templateName, boolean save);
094
095    /**
096     * Render the named template against the underlying DocumentModel and store the result in the main Blob
097     *
098     * @param templateName
099     * @param save flag to indicate if target DocumentModel must be saved or not
100     * @return the resulting {@link Blob}
101     */
102    public Blob renderAndStoreAsAttachment(String templateName, boolean save);
103
104    /**
105     * Render the named template against the underlying DocumentModel
106     *
107     * @param templateName
108     * @return the resulting {@link Blob}
109     */
110    public Blob renderWithTemplate(String templateName);
111
112    /**
113     * Indicate of the associated Template requires parameters or not
114     *
115     * @param templateName
116     * @return
117     */
118    public boolean hasParams(String templateName);
119
120    /**
121     * Retrieve parameters for the associated template
122     *
123     * @param templateName
124     * @return
125     */
126    public List<TemplateInput> getParams(String templateName);
127
128    /**
129     * Save parameters changes.
130     *
131     * @param templateName
132     * @param params the updated list of parameters
133     * @param save flag to indicate if target DocumentModel must be saved or not
134     * @return
135     */
136    public DocumentModel saveParams(String templateName, List<TemplateInput> params, boolean save);
137
138    /**
139     * Return the underlying adapted {@link DocumentModel}
140     *
141     * @return
142     */
143    public DocumentModel getAdaptedDoc();
144
145    /**
146     * Return the {@link Blob} of the associated template
147     *
148     * @param templateName
149     * @return
150     */
151    public Blob getTemplateBlob(String templateName);
152
153    /**
154     * Indicate of the associated Template has editable parameters or not
155     *
156     * @param templateName
157     * @return
158     */
159    public boolean hasEditableParams(String templateName);
160
161    /**
162     * Find the template associated to a given RenditionName
163     *
164     * @param renditionName
165     * @return the template name if any, null otherwise
166     */
167    String getTemplateNameForRendition(String renditionName);
168
169    /**
170     * Get the names of all the associated templates
171     *
172     * @return
173     */
174    public List<String> getTemplateNames();
175
176    /**
177     * Detach a template from the underlying {@link DocumentModel}
178     *
179     * @param templateName
180     * @param save
181     * @return
182     */
183    public DocumentModel removeTemplateBinding(String templateName, boolean save);
184}