001/*
002 * (C) Copyright 2006-2007 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 *
019 * $Id: DocumentViewCodecManager.java 22535 2007-07-13 14:57:58Z atchertchian $
020 */
021
022package org.nuxeo.ecm.platform.url.api;
023
024import java.io.Serializable;
025
026import org.nuxeo.ecm.platform.url.codec.api.DocumentViewCodec;
027
028/**
029 * Service used generate meaningful and permanent urls.
030 * <p>
031 * It handles a set of codecs, used to code/decode a document information between a url and a {@link DocumentView}
032 * instance.
033 *
034 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
035 */
036public interface DocumentViewCodecManager extends Serializable {
037
038    /**
039     * Returns the default codec name.
040     * <p>
041     * This information is set on codec descriptors.
042     */
043    String getDefaultCodecName();
044
045    /**
046     * Returns a DocumentView applying for given url, or null.
047     * <p>
048     * Iterates over registered codecs, starting from the default codec, and if
049     * {@link DocumentViewCodec#handleUrl(String)} returns true, calls
050     * {@link DocumentViewCodec#getDocumentViewFromUrl(String)}. Stops iterating when a codec returns a non-null value.
051     *
052     * @param url the original url from request, including request parameters if any.
053     * @param hasBaseUrl boolean indicating if base url should be removed from given url.
054     * @param baseUrl value of the base url.
055     */
056    DocumentView getDocumentViewFromUrl(String url, boolean hasBaseUrl, String baseUrl);
057
058    /**
059     * Returns a DocumentView calling {@link DocumentViewCodec#getDocumentViewFromUrl(String, boolean, String)} on codec
060     * with given name.
061     *
062     * @param url the original url from request, including request parameters if any.
063     * @param hasBaseUrl boolean indicating if base url should be removed from given url.
064     * @param baseUrl value of the base url.
065     */
066    DocumentView getDocumentViewFromUrl(String codecName, String url, boolean hasBaseUrl, String baseUrl);
067
068    /**
069     * Returns an URL applying for given document view, or null.
070     * <p>
071     * Iterates over registered codecs, starting from the default codec, and if
072     * {@link DocumentViewCodec#handleDocumentView(DocumentView)} returns true, calls
073     * {@link DocumentViewCodec#getUrlFromDocumentView(DocumentView)}. Stops iterating when a codec returns a non-null
074     * value. am docView the original document view from request
075     *
076     * @param docView the original document view from request
077     * @param hasBaseUrl boolean indicating if base url should be added to the url returned by the codec.
078     * @param baseUrl value of the base url.
079     */
080    String getUrlFromDocumentView(DocumentView docView, boolean needBaseUrl, String baseUrl);
081
082/**
083     * Returns an URL calling
084     * {@link DocumentViewCodec#getUrlFromDocumentView(DocumentView) on codec
085     * with given name.
086     *
087     * @param docView the original document view from request
088     * @param hasBaseUrl boolean indicating if base url should be added to the
089     *            url returned by the codec.
090     * @param baseUrl value of the base url.
091     */
092    String getUrlFromDocumentView(String codecName, DocumentView docView, boolean needBaseUrl, String baseUrl);
093
094}