use of org.eclipse.ecf.bulletinboard.IThreadMessage in project ecf by eclipse.
the class PHPBB method getMessage.
public IThreadMessage getMessage(ID id) throws BBException {
GetRequest request = new GetRequest(httpClient, url, "viewtopic.php");
request.addParameter(new NameValuePair("p", String.valueOf(((ThreadMessageID) id).getLongValue())));
String resp = null;
try {
request.execute();
resp = request.getResponseBodyAsString();
} catch (IOException e) {
e.printStackTrace();
}
request.releaseConnection();
if (resp != null) {
ThreadMessage msg = getParser().parseRequestedMessage((ThreadMessageID) id, resp);
msg.setBulletinBoard(this);
IMember author = msg.author;
((Member) author).setBulletinBoard(this);
return msg;
}
return null;
}
use of org.eclipse.ecf.bulletinboard.IThreadMessage in project ecf by eclipse.
the class Thread method createReplyMessage.
public IThreadMessage createReplyMessage() throws IllegalWriteException {
if ((mode & READ_ONLY) == READ_ONLY) {
throw new IllegalWriteException(E_READ_ONLY);
}
ThreadMessage msg = new ThreadMessage();
msg.setBulletinBoard(bb);
msg.setThread(this);
return msg;
}
use of org.eclipse.ecf.bulletinboard.IThreadMessage in project ecf by eclipse.
the class Thread method postReply.
public ID postReply(IThreadMessage message) throws IllegalWriteException, BBException {
if ((mode & READ_ONLY) == READ_ONLY) {
throw new IllegalWriteException(E_READ_ONLY);
}
ThreadMessage msg = (ThreadMessage) message;
// FIXME assert msg.bb == bb;
assert msg.getThread() == this;
PostRequest request = new PostRequest(bb.getHttpClient(), bb.getURL(), "posting.php");
NameValuePair[] params = new NameValuePair[] { new NameValuePair("subject", msg.getName()), new NameValuePair("message", msg.getMessage()), new NameValuePair("t", String.valueOf(id.getLongValue())), new NameValuePair("mode", "reply"), // checkbox : disabled new NameValuePair("notify", "on"),
new NameValuePair("post", "Submit") };
request.addParameters(params);
String resp = null;
try {
request.execute();
resp = request.getResponseBodyAsString();
String info = ((PHPBBParser) bb.getParser()).parseInformationMessage(resp);
Matcher m = Pattern.compile("<a href=\"viewtopic.php\\?p=([0-9]+)(?:.*?)\">").matcher(info);
if (m.find()) {
synchronized (this) {
try {
lastReadMessageId = (ThreadMessageID) new ThreadMessageFactory().createBBObjectId(bb.getNamespace(), bb.getURL(), m.group(1));
return lastReadMessageId;
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IDCreateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else {
throw new BBException("The message was not posted.");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
use of org.eclipse.ecf.bulletinboard.IThreadMessage in project ecf by eclipse.
the class ThreadBrowser2 method fetchNewMessages.
public List<IThreadMessage> fetchNewMessages() throws BBException {
List<IThreadMessage> messages = new ArrayList<IThreadMessage>();
try {
int nextPage = STARTPAGE;
while (nextPage > NONE) {
WebRequest req = createRequest(nextPage);
req.execute();
String resp = req.getResponseBodyAsString();
req.releaseConnection();
// Add messages from page
messages.addAll(0, ((PHPBBParser) bb.getParser()).parseMessages2(resp, thread.lastReadMessageId, true));
nextPage = ((PHPBBParser) bb.getParser()).parseNextPage(resp);
}
} catch (IOException e) {
e.printStackTrace();
}
return messages;
}
use of org.eclipse.ecf.bulletinboard.IThreadMessage in project ecf by eclipse.
the class Thread method createReplyMessage.
public IThreadMessage createReplyMessage(IThreadMessage replyTo) throws IllegalWriteException {
ThreadMessage msg = (ThreadMessage) createReplyMessage();
msg.setReplyTo(replyTo);
return msg;
}
Aggregations