001/*
002 * (C) Copyright 2006-2008 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 * $Id$
018 */
019
020package org.nuxeo.ecm.platform.picture.api.adapters;
021
022import java.io.IOException;
023import java.util.ArrayList;
024import java.util.List;
025import java.util.Map;
026
027import org.nuxeo.ecm.core.api.Blob;
028import org.nuxeo.ecm.core.api.DocumentModel;
029import org.nuxeo.ecm.core.api.PropertyException;
030import org.nuxeo.ecm.platform.picture.api.ImageInfo;
031
032public interface PictureResourceAdapter {
033
034    void setDocumentModel(DocumentModel doc);
035
036    /**
037     * @deprecated since 5.7. Use
038     *             {@link #fillPictureViews(org.nuxeo.ecm.core.api.Blob, String, String, java.util.ArrayList)} instead.
039     */
040    @Deprecated
041    boolean createPicture(Blob fileContent, String filename, String title,
042            ArrayList<Map<String, Object>> pictureConversions) throws IOException;
043
044    /**
045     * Fill this Picture views using the given {@code pictureConversions} and {@code blob} to compute the picture views.
046     * <p>
047     * The {@code blob} is converted to fit the defined {@code pictureConversions}.
048     *
049     * @since 5.7
050     */
051    boolean fillPictureViews(Blob blob, String filename, String title, ArrayList<Map<String, Object>> pictureConversions)
052            throws IOException;
053
054    /**
055     * This method just delegate the job to
056     * {@link PictureResourceAdapter#fillPictureViews(Blob, String, String, ArrayList)} by passing null instead of
057     * statics picture templates. <br/>
058     * <br/>
059     * This will fill the picture views by using the registered picture templates.
060     *
061     * @see {@link PictureResourceAdapter#fillPictureViews(Blob, String, String, ArrayList)}
062     * @since 6.9.6
063     */
064    boolean fillPictureViews(Blob blob, String filename, String title) throws IOException;
065
066    /**
067     * Pre-fill this Picture views using the given {@code pictureConversions} and {@code blob}.
068     * <p>
069     * The {@code blob} is not converted and just stored as the Blob of the picture views.
070     *
071     * @since 5.7
072     */
073    void preFillPictureViews(Blob blob, List<Map<String, Object>> pictureConversions, ImageInfo imageInfo)
074            throws IOException;
075
076    void doRotate(int angle);
077
078    void doCrop(String coords);
079
080    Blob getPictureFromTitle(String title) throws PropertyException;
081
082    /**
083     * Returns the XPath of the given view name, or {@code null} if the view is not found on the Picture.
084     *
085     * @param viewName the view name
086     */
087    String getViewXPath(String viewName);
088
089    /**
090     * Convenience method to get the XPath of the first view of the Picture.
091     *
092     * @return the XPath of the first view
093     */
094    String getFirstViewXPath();
095
096}