001/*
002 *  Copyright 2010 Anyware Services
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 */
016package org.ametys.cms.transformation;
017
018import java.io.IOException;
019
020import org.xml.sax.ContentHandler;
021import org.xml.sax.SAXException;
022
023import org.ametys.cms.data.RichText;
024import org.ametys.plugins.repository.AmetysRepositoryException;
025import org.ametys.plugins.repository.metadata.ModifiableRichText;
026import org.ametys.runtime.model.type.DataContext;
027
028/**
029 * Transform back and forth between a {@link String} and a {@link RichText}.
030 */
031public interface RichTextTransformer
032{
033    /**
034     * Transform a {@link String} into a {@link ModifiableRichText}.
035     * @param source the source.
036     * @param dest the {@link ModifiableRichText} to populate.
037     * @throws AmetysRepositoryException if an error occurs.
038     * @throws IOException if an error occurs.
039     * @deprecated use {@link #transform(String, RichText)} instead
040     */
041    @Deprecated
042    void transform(String source, ModifiableRichText dest) throws AmetysRepositoryException, IOException;
043    
044    /**
045     * Transform a {@link String} into a {@link RichText}.
046     * @param source the source.
047     * @param dest the {@link RichText} to populate.
048     * @throws AmetysRepositoryException if an error occurs.
049     * @throws IOException if an error occurs.
050     */
051    void transform (String source, RichText dest) throws AmetysRepositoryException, IOException;
052    
053    /**
054     * Transform a {@link ModifiableRichText} into a {@link StringBuilder}.
055     * @param source the source.
056     * @param dest the {@link StringBuilder} to populate.
057     * @throws AmetysRepositoryException if an error occurs.
058     * @throws IOException if an error occurs.
059     * @deprecated use {@link #transformForEditing(RichText, DataContext, StringBuilder)} instead
060     */
061    @Deprecated
062    void transformForEditing(ModifiableRichText source, StringBuilder dest) throws AmetysRepositoryException, IOException;
063    
064    /**
065     * Transform a {@link RichText} into a {@link StringBuilder}.
066     * @param source the source.
067     * @param dataContext the context of the rich text
068     * @param dest the {@link StringBuilder} to populate.
069     * @throws AmetysRepositoryException if an error occurs.
070     * @throws IOException if an error occurs.
071     */
072    void transformForEditing(RichText source, DataContext dataContext, StringBuilder dest) throws AmetysRepositoryException, IOException;
073    
074    /**
075     * SAXes a {@link RichText} into a {@link ContentHandler} for rendering purposes.
076     * @param source the source.
077     * @param handler the {@link StringBuilder} to populate.
078     * @throws AmetysRepositoryException if an error occurs.
079     * @throws SAXException if an error occurs.
080     * @throws IOException if an error occurs.
081     */
082    void transformForRendering(RichText source, ContentHandler handler) throws AmetysRepositoryException, SAXException, IOException;
083}