FileDocCategorySizeDatePackage
Article.javaAPI DocApache Commons NET 1.4.1 API7878Sat Dec 03 10:05:48 GMT 2005org.apache.commons.net.nntp

Article

public class Article extends Object implements Threadable
This is a class that contains the basic state needed for message retrieval and threading. With thanks to Jamie Zawinski
author
rwinston

Fields Summary
private int
articleNumber
private String
subject
private String
date
private String
articleId
private String
simplifiedSubject
private String
from
private StringBuffer
header
private StringBuffer
references
private boolean
isReply
public Article
kid
public Article
next
Constructors Summary
public Article()


	  
		header = new StringBuffer();
	
Methods Summary
public voidaddHeaderField(java.lang.String name, java.lang.String val)
Adds an arbitrary header key and value to this message's header.

param
name the header name
param
val the header value

		header.append(name);
		header.append(": ");
		header.append(val);
		header.append('\n");
	
public voidaddReference(java.lang.String msgId)
Adds a message-id to the list of messages that this message references (i.e. replies to)

param
msgId

		if (references == null) {
			references = new StringBuffer();
			references.append("References: ");
		}
		references.append(msgId);
		references.append("\t");
	
private voidflushSubjectCache()

		simplifiedSubject = null;
	
public java.lang.StringgetArticleId()

		return articleId;
	
public intgetArticleNumber()

		return articleNumber;
	
public java.lang.StringgetDate()

		return date;
	
public java.lang.StringgetFrom()

		return from;
	
public java.lang.String[]getReferences()
Returns the MessageId references as an array of Strings

return
an array of message-ids

		if (references == null)
			return new String[0];
		ArrayList list = new ArrayList();
		int terminator = references.toString().indexOf(':");
		StringTokenizer st =
			new StringTokenizer(references.substring(terminator), "\t");
		while (st.hasMoreTokens()) {
			list.add(st.nextToken());
		}
		return (String[]) list.toArray();
	
public java.lang.StringgetSubject()

		return subject;
	
public booleanisDummy()

		return (getSubject() == null);
	
public ThreadablemakeDummy()

		return (Threadable)new Article();
	
public java.lang.StringmessageThreadId()

		return articleId;
	
public java.lang.String[]messageThreadReferences()

		return getReferences();
	
public static voidprintThread(org.apache.commons.net.nntp.Article article, int depth)
Recursive method that traverses a pre-threaded graph (or tree) of connected Article objects and prints them out.

param
article the root of the article 'tree'
param
depth the current tree depth

			for (int i = 0; i < depth; ++i)
				System.out.print("==>");
			System.out.println(article.getSubject() + "\t" + article.getFrom());
			if (article.kid != null)
				printThread(article.kid, depth + 1);
			if (article.next != null)
				printThread(article.next, depth);
	
public voidsetArticleId(java.lang.String string)

		articleId = string;
	
public voidsetArticleNumber(int i)

		articleNumber = i;
	
public voidsetChild(Threadable child)

		this.kid = (Article) child;
		flushSubjectCache();
	
public voidsetDate(java.lang.String string)

		date = string;
	
public voidsetFrom(java.lang.String string)

		from = string;
	
public voidsetNext(Threadable next)

		this.next = (Article)next;
		flushSubjectCache();
	
public voidsetSubject(java.lang.String string)

		subject = string;
	
public java.lang.StringsimplifiedSubject()

		if(simplifiedSubject == null)
			simplifySubject();
		return simplifiedSubject;
	
private voidsimplifySubject()
Attempts to parse the subject line for some typical reply signatures, and strip them out

			int start = 0;
			String subject = getSubject();
			int len = subject.length();

			boolean done = false;

			while (!done) {
				done = true;

				// skip whitespace
				// "Re: " breaks this
				while (start < len && subject.charAt(start) == ' ") {
					start++;
				}

				if (start < (len - 2)
					&& (subject.charAt(start) == 'r" || subject.charAt(start) == 'R")
					&& (subject.charAt(start + 1) == 'e" || subject.charAt(start + 1) == 'E")) {

					if (subject.charAt(start + 2) == ':") {
						start += 3; // Skip "Re:"
						isReply = true;
						done = false;
					} else if (
						start < (len - 2) 
						&& 
						(subject.charAt(start + 2) == '[" || subject.charAt(start + 2) == '(")) {
                    	
						int i = start + 3;

						while (i < len && subject.charAt(i) >= '0" && subject.charAt(i) <= '9")
							i++;

						if (i < (len - 1)
							&& (subject.charAt(i) == ']" || subject.charAt(i) == ')")
							&& subject.charAt(i + 1) == ':") {
							start = i + 2;
							isReply = true;
							done = false;
						}
					}
				}

				if (simplifiedSubject == "(no subject)")
					simplifiedSubject = "";

				int end = len;

				while (end > start && subject.charAt(end - 1) < ' ")
					end--;

				if (start == 0 && end == len)
					simplifiedSubject = subject;
				else
					simplifiedSubject = subject.substring(start, end);
			}
		
public booleansubjectIsReply()

		if(simplifiedSubject == null)
			simplifySubject();
		return isReply;