Search in sources :

Example 1 with IThreadMessage

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;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) GetRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest) IOException(java.io.IOException) IThreadMessage(org.eclipse.ecf.bulletinboard.IThreadMessage) IMember(org.eclipse.ecf.bulletinboard.IMember) IMember(org.eclipse.ecf.bulletinboard.IMember)

Example 2 with IThreadMessage

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;
}
Also used : IllegalWriteException(org.eclipse.ecf.bulletinboard.IllegalWriteException) IThreadMessage(org.eclipse.ecf.bulletinboard.IThreadMessage)

Example 3 with IThreadMessage

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;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) Matcher(java.util.regex.Matcher) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) BBException(org.eclipse.ecf.bulletinboard.BBException) IOException(java.io.IOException) PostRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest) IllegalWriteException(org.eclipse.ecf.bulletinboard.IllegalWriteException) IThreadMessage(org.eclipse.ecf.bulletinboard.IThreadMessage)

Example 4 with IThreadMessage

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;
}
Also used : IThreadMessage(org.eclipse.ecf.bulletinboard.IThreadMessage) WebRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.WebRequest) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 5 with IThreadMessage

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;
}
Also used : IThreadMessage(org.eclipse.ecf.bulletinboard.IThreadMessage)

Aggregations

IThreadMessage (org.eclipse.ecf.bulletinboard.IThreadMessage)10 IOException (java.io.IOException)5 IllegalWriteException (org.eclipse.ecf.bulletinboard.IllegalWriteException)4 NameValuePair (org.apache.commons.httpclient.NameValuePair)3 IMember (org.eclipse.ecf.bulletinboard.IMember)3 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)2 PostRequest (org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest)2 WebRequest (org.eclipse.ecf.internal.bulletinboard.commons.webapp.WebRequest)2 Header (org.apache.commons.httpclient.Header)1 BBException (org.eclipse.ecf.bulletinboard.BBException)1 GetRequest (org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest)1 ThreadMessageFactory (org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory)1