001    // Copyright 2009, 2012 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry5.services;
016    
017    import java.io.IOException;
018    import java.io.ObjectInputStream;
019    
020    /**
021     * A service used when a component or service needs to encode some amount of data on the client as a string. The string
022     * may be a query parameter, hidden form field, or a portion of a URL.  The default implementation converts the object
023     * output stream into a Base64 string.
024     * <p/>
025     * Starting in release 5.3.6, the encoded data incorporates an HMAC (hash based message authentication code) signature,
026     * as a prefix. HMAC requires a secret key, configured using the
027     * {@link org.apache.tapestry5.SymbolConstants#HMAC_PASSPHRASE} symbol.
028     *
029     * @since 5.1.0.1
030     */
031    public interface ClientDataEncoder
032    {
033        /**
034         * Creates a sink for client data.  The sink provides an output stream and ultimately, a string representation of
035         * the data sent to the stream.
036         *
037         * @return a new sink
038         */
039        ClientDataSink createSink();
040    
041        /**
042         * Decodes data previously obtained from {@link ClientDataSink#getClientData()}.
043         *
044         * @param clientData
045         *         encoded client data
046         * @return stream of decoded data
047         * @throws IOException
048         *         if the client data has been corrupted (verified via the HMAC)
049         */
050        ObjectInputStream decodeClientData(String clientData) throws IOException;
051    
052        /**
053         * Decodes client data obtained via {@link ClientDataSink#getEncodedClientData()}.
054         *
055         * @param clientData
056         *         URLEncoded client data
057         * @return stream of objects
058         * @throws IOException
059         *         if the client data has been corrupted (verified via the HMAC)
060         * @since 5.1.0.4
061         */
062        ObjectInputStream decodeEncodedClientData(String clientData) throws IOException;
063    }