1 16 package org.apache.commons.net.nntp; 17 18 46 47 public class SimpleNNTPHeader 48 { 49 private String __subject, __from; 50 private StringBuffer __newsgroups; 51 private StringBuffer __headerFields; 52 private int __newsgroupCount; 53 54 63 public SimpleNNTPHeader(String from, String subject) 64 { 65 __from = from; 66 __subject = subject; 67 __newsgroups = new StringBuffer (); 68 __headerFields = new StringBuffer (); 69 __newsgroupCount = 0; 70 } 71 72 78 public void addNewsgroup(String newsgroup) 79 { 80 if (__newsgroupCount++ > 0) 81 __newsgroups.append(','); 82 __newsgroups.append(newsgroup); 83 } 84 85 97 public void addHeaderField(String headerField, String value) 98 { 99 __headerFields.append(headerField); 100 __headerFields.append(": "); 101 __headerFields.append(value); 102 __headerFields.append('\n'); 103 } 104 105 106 111 public String getFromAddress() 112 { 113 return __from; 114 } 115 116 121 public String getSubject() 122 { 123 return __subject; 124 } 125 126 132 public String getNewsgroups() 133 { 134 return __newsgroups.toString(); 135 } 136 137 144 public String toString() 145 { 146 StringBuffer header = new StringBuffer (); 147 148 header.append("From: "); 149 header.append(__from); 150 header.append("\nNewsgroups: "); 151 header.append(__newsgroups.toString()); 152 header.append("\nSubject: "); 153 header.append(__subject); 154 header.append('\n'); 155 if (__headerFields.length() > 0) 156 header.append(__headerFields.toString()); 157 header.append('\n'); 158 159 return header.toString(); 160 } 161 } 162 | Popular Tags |