Source Code Cross Referenced for SimpleNNTPHeader.java in  » Net » Apache-commons-net-1.4.1 » org » apache » commons » net » nntp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Apache commons net 1.4.1 » org.apache.commons.net.nntp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2005 The Apache Software Foundation
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.net.nntp;
017:
018:        /***
019:         * This class is used to construct the bare minimum
020:         * acceptable header for most news readers.  To construct more
021:         * complicated headers you should refer to RFC 822.  When the
022:         * Java Mail API is finalized, you will be
023:         * able to use it to compose fully compliant Internet text messages.
024:         * <p>
025:         * The main purpose of the class is to faciliatate the article posting
026:         * process, by relieving the programmer from having to explicitly format
027:         * an article header.  For example:
028:         * <pre>
029:         * writer = client.postArticle();
030:         * if(writer == null) // failure
031:         *   return false;
032:         * header = new SimpleNNTPHeader("foobar@foo.com", "Just testing");
033:         * header.addNewsgroup("alt.test");
034:         * header.addHeaderField("Organization", "Foobar, Inc.");
035:         * writer.write(header.toString());
036:         * writer.write("This is just a test");
037:         * writer.close();
038:         * if(!client.completePendingCommand()) // failure
039:         *   return false;
040:         * </pre>
041:         * <p>
042:         * <p>
043:         * @author Daniel F. Savarese
044:         * @see NNTPClient
045:         ***/
046:
047:        public class SimpleNNTPHeader {
048:            private String __subject, __from;
049:            private StringBuffer __newsgroups;
050:            private StringBuffer __headerFields;
051:            private int __newsgroupCount;
052:
053:            /***
054:             * Creates a new SimpleNNTPHeader instance initialized with the given
055:             * from and subject header field values.
056:             * <p>
057:             * @param from  The value of the <code>From:</code> header field.  This
058:             *              should be the article poster's email address.
059:             * @param subject  The value of the <code>Subject:</code> header field.
060:             *              This should be the subject of the article.
061:             ***/
062:            public SimpleNNTPHeader(String from, String subject) {
063:                __from = from;
064:                __subject = subject;
065:                __newsgroups = new StringBuffer();
066:                __headerFields = new StringBuffer();
067:                __newsgroupCount = 0;
068:            }
069:
070:            /***
071:             * Adds a newsgroup to the article <code>Newsgroups:</code> field.
072:             * <p>
073:             * @param newsgroup  The newsgroup to add to the article's newsgroup
074:             *                   distribution list.
075:             ***/
076:            public void addNewsgroup(String newsgroup) {
077:                if (__newsgroupCount++ > 0)
078:                    __newsgroups.append(',');
079:                __newsgroups.append(newsgroup);
080:            }
081:
082:            /***
083:             * Adds an arbitrary header field with the given value to the article
084:             * header.  These headers will be written after the From, Newsgroups,
085:             * and Subject fields when the SimpleNNTPHeader is convertered to a string.
086:             * An example use would be:
087:             * <pre>
088:             * header.addHeaderField("Organization", "Foobar, Inc.");
089:             * </pre>
090:             * <p>
091:             * @param headerField  The header field to add, not including the colon.
092:             * @param value  The value of the added header field.
093:             ***/
094:            public void addHeaderField(String headerField, String value) {
095:                __headerFields.append(headerField);
096:                __headerFields.append(": ");
097:                __headerFields.append(value);
098:                __headerFields.append('\n');
099:            }
100:
101:            /***
102:             * Returns the address used in the <code> From: </code> header field.
103:             * <p>
104:             * @return The from address.
105:             ***/
106:            public String getFromAddress() {
107:                return __from;
108:            }
109:
110:            /***
111:             * Returns the subject used in the <code> Subject: </code> header field.
112:             * <p>
113:             * @return The subject.
114:             ***/
115:            public String getSubject() {
116:                return __subject;
117:            }
118:
119:            /***
120:             * Returns the contents of the <code> Newsgroups: </code> header field.
121:             * <p>
122:             * @return The comma-separated list of newsgroups to which the article
123:             *         is being posted.
124:             ***/
125:            public String getNewsgroups() {
126:                return __newsgroups.toString();
127:            }
128:
129:            /***
130:             * Converts the SimpleNNTPHeader to a properly formatted header in
131:             * the form of a String, including the blank line used to separate
132:             * the header from the article body.
133:             * <p>
134:             * @return The article header in the form of a String.
135:             ***/
136:            public String toString() {
137:                StringBuffer header = new StringBuffer();
138:
139:                header.append("From: ");
140:                header.append(__from);
141:                header.append("\nNewsgroups: ");
142:                header.append(__newsgroups.toString());
143:                header.append("\nSubject: ");
144:                header.append(__subject);
145:                header.append('\n');
146:                if (__headerFields.length() > 0)
147:                    header.append(__headerFields.toString());
148:                header.append('\n');
149:
150:                return header.toString();
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.