KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > value > AbstractStreamableValue


1 /*
2  * $Header: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/value/Attic/AbstractStreamableValue.java,v 1.4 2004/08/03 14:29:56 dflorey Exp $
3  * $Revision: 1.4 $
4  * $Date: 2004/08/03 14:29:56 $
5  *
6  * ====================================================================
7  *
8  * Copyright 2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.projector.value;
25
26 import java.io.IOException JavaDoc;
27 import java.util.logging.Level JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29
30 import org.apache.slide.projector.util.StreamHelper;
31
32 import de.zeigermann.xml.XMLEncode;
33 import de.zeigermann.xml.XMLStringWriter;
34 import de.zeigermann.xml.XMLWriter;
35
36 /**
37  * The AbstractStreamableResource class
38  *
39  */

40 public abstract class AbstractStreamableValue implements StreamableValue, PrintableValue {
41     private static Logger JavaDoc logger = Logger.getLogger(AbstractStreamableValue.class.getName());
42
43     public StringBuffer JavaDoc print(StringBuffer JavaDoc buffer) {
44         try {
45             return buffer.append(StreamHelper.streamToString(this));
46         } catch ( IOException JavaDoc exception ) {
47             logger.log(Level.SEVERE, "Exception while streaming value", exception);
48             return buffer;
49         }
50     }
51
52     public void save(XMLStringWriter writer) {
53         try {
54             writer.writeElementWithPCData(XMLWriter.createStartTag("value"), XMLEncode.xmlEncodeText(StreamHelper.streamToString(this)), XMLWriter.createEndTag("value"));
55         } catch (IOException JavaDoc e) {
56             writer.writeEmptyElement(XMLWriter.createEmptyTag("value"));
57         }
58     }
59 }
60
Popular Tags