KickJava   Java API By Example, From Geeks To Geeks.

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


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 comment.
32  */

33 public class HTMLComment implements Text {
34     
35     
36     /**
37      * The text of the comment.
38      */

39     private String JavaDoc text = null;
40
41     private static String JavaDoc COMMENT_BEGIN = "<!-- ";
42     private static String JavaDoc COMMENT_END = "-->";
43     
44     /**
45      * Create a new comment.
46      * @param text The text of the comment.
47      */

48     public HTMLComment(String JavaDoc text) {
49         setValue(text);
50     }
51     
52     
53     /**
54      */

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

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

73     public String JavaDoc toString() {
74         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
75         buf.append(COMMENT_BEGIN)
76             .append(Escape.getInstance().encodeEntities(text, ""))
77             .append(COMMENT_END);
78         return buf.toString();
79     }
80
81
82     /**
83      */

84     public void write(Writer JavaDoc output) throws IOException JavaDoc {
85         output.append(toString());
86         output.flush();
87     }
88
89
90     /**
91      *
92      */

93     public void write(File JavaDoc file) throws IOException JavaDoc {
94         FileWriter JavaDoc fw = new FileWriter JavaDoc(file);
95         write(fw);
96         fw.close();
97     }
98
99 }
Popular Tags