001/* 002 * (C) Copyright 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 * Thierry Delprat 018 */ 019package org.nuxeo.template.api; 020 021import java.util.Collection; 022import java.util.List; 023import java.util.Map; 024 025import org.nuxeo.ecm.core.api.Blob; 026import org.nuxeo.ecm.core.api.CoreSession; 027import org.nuxeo.ecm.core.api.DocumentModel; 028import org.nuxeo.template.api.adapters.TemplateBasedDocument; 029import org.nuxeo.template.api.adapters.TemplateSourceDocument; 030import org.nuxeo.template.api.context.DocumentWrapper; 031import org.nuxeo.template.api.descriptor.ContextExtensionFactoryDescriptor; 032import org.nuxeo.template.api.descriptor.OutputFormatDescriptor; 033import org.nuxeo.template.api.descriptor.TemplateProcessorDescriptor; 034 035/** 036 * This is the service interface to manage {@link TemplateProcessor} and associated templates. 037 * 038 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 039 */ 040public interface TemplateProcessorService { 041 042 /** 043 * Finds the template processor name for a given {@link Blob}. The template processor is found based on mime-types. 044 * 045 * @return the {@link TemplateProcessor} name 046 */ 047 String findProcessorName(Blob templateBlob); 048 049 /** 050 * Finds the {@link TemplateProcessor} for a given {@link Blob}. The template processor is found based on 051 * mime-types. 052 * 053 * @return the {@link TemplateProcessor} 054 */ 055 TemplateProcessor findProcessor(Blob templateBlob); 056 057 /** 058 * Get a {@link TemplateProcessor} by it's name. Name is defined in the associated descriptor. 059 * 060 * @return the {@link TemplateProcessor} 061 */ 062 TemplateProcessor getProcessor(String name); 063 064 /** 065 * Returns all registered {@link TemplateProcessor}s 066 * 067 * @return collection of registered {@link TemplateProcessorDescriptor} 068 */ 069 Collection<TemplateProcessorDescriptor> getRegisteredTemplateProcessors(); 070 071 /** 072 * Find {@link TemplateSourceDocument}s that can be bound to a given doc type. 073 * 074 * @param targetType the target Document Type 075 * @return List of applicable DocumentModel 076 */ 077 List<DocumentModel> getAvailableTemplateDocs(CoreSession session, String targetType); 078 079 /** 080 * Find {@link TemplateSourceDocument}s that can be bound to a given doc type. 081 * 082 * @param targetType the target Document Type 083 * @return List of applicable {@link TemplateSourceDocument} 084 */ 085 List<TemplateSourceDocument> getAvailableTemplates(CoreSession session, String targetType); 086 087 /** 088 * Returns a template with a given templateName. 089 * 090 * @param name the name of the template 091 * 092 * @since 9.1 093 */ 094 DocumentModel getTemplateDoc(CoreSession session, String name); 095 096 /** 097 * Retrieve the {@link TemplateSourceDocument} that can be used as an Office template (i.e that support to store the 098 * template file as main blob of target DocumentModel) 099 */ 100 List<TemplateSourceDocument> getAvailableOfficeTemplates(CoreSession session, String targetType); 101 102 /** 103 * Retrieve the DocumentModels using a given {@link TemplateSourceDocument} 104 * 105 * @param source the {@link TemplateSourceDocument} 106 */ 107 List<TemplateBasedDocument> getLinkedTemplateBasedDocuments(DocumentModel source); 108 109 /** 110 * Retrieve the Map used for mapping Document Types to Template Names. This Map represent the Templates that must be 111 * automatically bound at creation time for each Document Type. 112 * 113 * @return the Type2Template mapping 114 */ 115 Map<String, List<String>> getTypeMapping(); 116 117 /** 118 * Update Type2Template Mapping from the data contained in the source DocumentModel. 119 */ 120 void registerTypeMapping(DocumentModel doc); 121 122 /** 123 * Associate a {@link DocumentModel} to a {@link TemplateSourceDocument}. If the DocumentModel is not already a 124 * {@link TemplateBasedDocument}, the associated facet will be automatically added. 125 * 126 * @param targetDoc the DocumentModel to associate to a template 127 * @param sourceTemplateDoc the DocumentModel holding the template 128 * @param save flag to indicate if target DocumentModel must be saved or not 129 * @return the updated DocumentModel 130 */ 131 DocumentModel makeTemplateBasedDocument(DocumentModel targetDoc, DocumentModel sourceTemplateDoc, boolean save); 132 133 /** 134 * Detach a Template from a {@link DocumentModel} 135 * 136 * @param targetDoc the DocumentModel to detach 137 * @param templateName the name of the template to detach 138 * @param save save flag to indicate if target DocumentModel must be saved or not 139 * @return the updated DocumentModel 140 */ 141 DocumentModel detachTemplateBasedDocument(DocumentModel targetDoc, String templateName, boolean save); 142 143 void addContextExtensions(DocumentModel currentDocument, DocumentWrapper wrapper, Map<String, Object> ctx); 144 145 Map<String, ContextExtensionFactoryDescriptor> getRegistredContextExtensions(); 146 147 List<String> getReservedContextKeywords(); 148 149 /** 150 * @return the list of registered Ouput formats used to convert output of a rendered document. 151 */ 152 Collection<OutputFormatDescriptor> getOutputFormats(); 153 154 /** 155 * The returned {@link OutputFormatDescriptor} contains either an operation chain or a mime-type use to convert the 156 * output of a rendered document. 157 * 158 * @return {@link OutputFormatDescriptor} 159 */ 160 OutputFormatDescriptor getOutputFormatDescriptor(String outputFormatId); 161 162}