001 // Copyright 2009 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 *
025 * @since 5.1.0.1
026 */
027 public interface ClientDataEncoder
028 {
029 /**
030 * Creates a sink for client data. The sink provides an output stream and ultimately, a string representation of
031 * the data sent to the stream.
032 *
033 * @return a new sink
034 */
035 ClientDataSink createSink();
036
037 /**
038 * Decodes data previously obtained from {@link ClientDataSink#getClientData()}.
039 *
040 * @param clientData encoded client data
041 * @return stream of decoded data
042 */
043 ObjectInputStream decodeClientData(String clientData) throws IOException;
044
045 /**
046 * Decoes client data obtained via {@link ClientDataSink#getEncodedClientData()}.
047 *
048 * @param clientData URLEncoded client data
049 * @return stream of objects
050 * @throws IOException
051 * @since 5.1.0.4
052 */
053 ObjectInputStream decodeEncodedClientData(String clientData) throws IOException;
054 }