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,
058            Map<String, Serializable> parameters) 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     * @deprecated since 9.2, use {@link #convertToMimeType(String, BlobHolder, Map)} with the PDF mimetype as
065     *             destination instead
066     */
067    @Deprecated
068    Blob convertBlobToPDF(Blob blob) throws IOException;
069
070    /**
071     * Returns the names of the registered converters.
072     */
073    List<String> getRegistredConverters();
074
075    /**
076     * Checks for converter availability.
077     * <p>
078     * Result can be:
079     * <ul>
080     * <li>{@link ConverterNotRegistered} if converter is not registered.
081     * <li>Error Message / Installation message if converter dependencies are not available an successful check.
082     * </ul>
083     */
084    ConverterCheckResult isConverterAvailable(String converterName, boolean refresh) throws ConverterNotRegistered;
085
086    /**
087     * Checks for converter availability.
088     * <p>
089     * Result can be:
090     * <ul>
091     * <li>{@link ConverterNotRegistered} if converter is not registered.
092     * <li>Error Message / Installation message if converter dependencies are not available an successful check.
093     * </ul>
094     * <p>
095     * Result can be taken from an internal cache.
096     */
097    ConverterCheckResult isConverterAvailable(String converterName) throws ConversionException;
098
099    /**
100     * Returns true if the converter supports the given {@code sourceMimeType}, false otherwise.
101     *
102     * @since 5.8
103     */
104    boolean isSourceMimeTypeSupported(String converterName, String sourceMimeType);
105
106    /**
107     * Schedules a conversion given a converter name.
108     * <p>
109     * Returns a conversion id to be used by {@link #getConversionResult(String, boolean)}.
110     *
111     * @since 7.4
112     */
113    String scheduleConversion(String converterName, BlobHolder blobHolder, Map<String, Serializable> parameters);
114
115    /**
116     * Schedules a conversion given a target mime type.
117     * <p>
118     * Returns a conversion id to be used by {@link #getConversionResult(String, boolean)}.
119     *
120     * @since 7.10
121     */
122    String scheduleConversionToMimeType(String destinationMimeType, BlobHolder blobHolder,
123            Map<String, Serializable> parameters);
124
125    /**
126     * Returns the status of a scheduled conversion given its {@code id}, or {@code null} if no conversion scheduled.
127     *
128     * @since 7.4
129     */
130    ConversionStatus getConversionStatus(String id);
131
132    /**
133     * Returns the conversion result for the given {@code id} if any, {@code null} otherwise.
134     *
135     * @since 7.4
136     */
137    BlobHolder getConversionResult(String id, boolean cleanTransientStoreEntry);
138
139}