1 23 package com.sun.enterprise.diagnostics.report.html; 24 25 import java.io.File ; 26 import java.io.FileWriter ; 27 import java.io.IOException ; 28 import java.io.Writer ; 29 30 31 34 public class HTMLAttribute implements Attribute, Text { 35 36 39 private String name = null; 40 41 44 private String value = null; 45 46 private static final String DOUBLE_QUOTES ="\""; 47 48 private static final char EQUALS = '='; 49 54 public HTMLAttribute(String name, String value) { 55 setName(name); 56 setValue(value); 57 } 58 59 62 public String getName() { 63 return name; 64 } 65 66 69 public void setName(String name) { 70 if (name == null) { 71 throw new NullPointerException ("Attribute name is null"); 72 } 73 this.name = name; 74 } 75 76 77 80 public String getValue() { 81 return value; 82 } 83 84 85 88 public void setValue(String value) { 89 if (value == null) { 90 throw new NullPointerException ("Attribute value is null."); 91 } 92 this.value = value; 93 } 94 95 96 99 public String toString() { 100 String nameStr = Escape.getInstance().encodeEntities(name, " \t\r\n"); 101 String valueStr = Escape.getInstance().encodeEntities(value, ""); 102 StringBuffer buf = new StringBuffer (); 103 buf.append(nameStr) 104 .append(EQUALS+DOUBLE_QUOTES) 105 .append(valueStr) 106 .append(DOUBLE_QUOTES); 107 return buf.toString(); 108 } 109 110 111 113 public void write(Writer output) throws IOException { 114 output.append(toString()); 115 output.flush(); 116 } 117 118 119 121 public void write(File file) throws IOException { 122 FileWriter fw = new FileWriter (file); 123 write(fw); 124 fw.close(); 125 } 126 127 128 } 129 | Popular Tags |