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 * Estelle Giuly <egiuly@nuxeo.com> 019 * 020 */ 021package org.nuxeo.ecm.core.convert.api; 022 023import java.io.IOException; 024import java.io.Serializable; 025import java.util.List; 026import java.util.Map; 027 028import org.nuxeo.ecm.core.api.Blob; 029import org.nuxeo.ecm.core.api.blobholder.BlobHolder; 030 031/** 032 * Interface for the Conversion Service. 033 * 034 * @author tiry 035 */ 036public interface ConversionService { 037 038 /** 039 * Gets the convertName given a source and destination MimeType. 040 */ 041 String getConverterName(String sourceMimeType, String destinationMimeType); 042 043 /** 044 * Gets the available convertNames given a source and destination MimeType. 045 */ 046 List<String> getConverterNames(String sourceMimeType, String destinationMimeType); 047 048 /** 049 * Converts a Blob given a converter name. 050 */ 051 BlobHolder convert(String converterName, BlobHolder blobHolder, Map<String, Serializable> parameters) 052 throws ConversionException; 053 054 /** 055 * Converts a Blob given a target destination MimeType. 056 */ 057 BlobHolder convertToMimeType(String destinationMimeType, BlobHolder blobHolder, Map<String, Serializable> parameters) 058 throws ConversionException; 059 060 /** 061 * Converts a Blob to PDF. If the blob has inner blobs such as images, they will be correctly rendered in the PDF. 062 * 063 * @since 9.1 064 */ 065 Blob convertBlobToPDF(Blob blob) throws IOException; 066 067 /** 068 * Returns the names of the registered converters. 069 */ 070 List<String> getRegistredConverters(); 071 072 /** 073 * Checks for converter availability. 074 * <p> 075 * Result can be: 076 * <ul> 077 * <li>{@link ConverterNotRegistered} if converter is not registered. 078 * <li>Error Message / Installation message if converter dependencies are not available an successful check. 079 * </ul> 080 */ 081 ConverterCheckResult isConverterAvailable(String converterName, boolean refresh) throws ConverterNotRegistered; 082 083 /** 084 * Checks for converter availability. 085 * <p> 086 * Result can be: 087 * <ul> 088 * <li>{@link ConverterNotRegistered} if converter is not registered. 089 * <li>Error Message / Installation message if converter dependencies are not available an successful check. 090 * </ul> 091 * <p> 092 * Result can be taken from an internal cache. 093 */ 094 ConverterCheckResult isConverterAvailable(String converterName) throws ConversionException; 095 096 /** 097 * Returns true if the converter supports the given {@code sourceMimeType}, false otherwise. 098 * 099 * @since 5.8 100 */ 101 boolean isSourceMimeTypeSupported(String converterName, String sourceMimeType); 102 103 /** 104 * Schedules a conversion given a converter name. 105 * <p> 106 * Returns a conversion id to be used by {@link #getConversionResult(String, boolean)}. 107 * 108 * @since 7.4 109 */ 110 String scheduleConversion(String converterName, BlobHolder blobHolder, Map<String, Serializable> parameters); 111 112 /** 113 * Schedules a conversion given a target mime type. 114 * <p> 115 * Returns a conversion id to be used by {@link #getConversionResult(String, boolean)}. 116 * 117 * @since 7.10 118 */ 119 String scheduleConversionToMimeType(String destinationMimeType, BlobHolder blobHolder, Map<String, Serializable> parameters); 120 121 /** 122 * Returns the status of a scheduled conversion given its {@code id}, or {@code null} if no conversion scheduled. 123 * 124 * @since 7.4 125 */ 126 ConversionStatus getConversionStatus(String id); 127 128 /** 129 * Returns the conversion result for the given {@code id} if any, {@code null} otherwise. 130 * 131 * @since 7.4 132 */ 133 BlobHolder getConversionResult(String id, boolean cleanTransientStoreEntry); 134}