KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > diagnostics > report > html > HTMLText


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.diagnostics.report.html;
24
25 import java.io.File JavaDoc;
26 import java.io.FileWriter JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.io.Writer JavaDoc;
29
30 /**
31  * Provide a basic implementation of a text node.
32  */

33 public class HTMLText implements Text {
34     
35     
36     /**
37      * The text content of this node.
38      */

39     private String JavaDoc text = null;
40     
41     
42     /**
43      * Make a new text node.
44      * @param text The text.
45      */

46     public HTMLText(String JavaDoc text) {
47         setValue(text);
48     }
49
50
51     /**
52      */

53     public String JavaDoc getValue() {
54         return text;
55     }
56
57
58     /**
59      */

60     public void setValue(String JavaDoc text) {
61         if (text == null) {
62             throw new NullPointerException JavaDoc("Text is null.");
63         }
64         this.text = text;
65     }
66
67
68     /**
69      * @see java.lang.Object#toString()
70      */

71     public String JavaDoc toString() {
72         return Escape.getInstance().encodeEntities(text, "");
73     }
74
75
76     /**
77      */

78     public void write(Writer JavaDoc output) throws IOException JavaDoc {
79         output.append(toString());
80         output.flush();
81     }
82
83
84     /**
85      */

86     public void write(File JavaDoc file) throws IOException JavaDoc {
87         FileWriter JavaDoc fw = new FileWriter JavaDoc(file);
88         write(fw);
89         fw.close();
90     }
91
92 }
93
Popular Tags