Search in sources :

Example 6 with IThreadMessage

use of org.eclipse.ecf.bulletinboard.IThreadMessage in project ecf by eclipse.

the class Thread method getNewMessages.

public List<IThreadMessage> getNewMessages() throws BBException {
    ThreadBrowser2 browser = new ThreadBrowser2((AbstractBulletinBoard) bb, this);
    List<IThreadMessage> msgs = browser.fetchNewMessages();
    if (msgs.size() > 0) {
        lastReadMessageId = (ThreadMessageID) msgs.get(msgs.size() - 1).getID();
        for (IThreadMessage message : msgs) {
            ThreadMessage msg = (ThreadMessage) message;
            msg.setBulletinBoard(bb);
            msg.thread = this;
            IMember author = msg.author;
            ((Member) author).setBulletinBoard(bb);
        }
    }
    return msgs;
}
Also used : IThreadMessage(org.eclipse.ecf.bulletinboard.IThreadMessage) IThreadMessage(org.eclipse.ecf.bulletinboard.IThreadMessage) IMember(org.eclipse.ecf.bulletinboard.IMember) IMember(org.eclipse.ecf.bulletinboard.IMember)

Example 7 with IThreadMessage

use of org.eclipse.ecf.bulletinboard.IThreadMessage in project ecf by eclipse.

the class Thread method getNewMessages.

public List<IThreadMessage> getNewMessages() throws BBException {
    ThreadBrowser2 browser = new ThreadBrowser2((VBulletin) bb, this);
    List<IThreadMessage> msgs = browser.fetchNewMessages();
    if (msgs.size() > 0) {
        lastReadMessageId = (ThreadMessageID) msgs.get(msgs.size() - 1).getID();
        for (IThreadMessage message : msgs) {
            ThreadMessage msg = (ThreadMessage) message;
            msg.setBulletinBoard(bb);
            msg.thread = this;
            IMember author = msg.author;
            ((Member) author).setBulletinBoard(bb);
        }
    }
    return msgs;
}
Also used : IThreadMessage(org.eclipse.ecf.bulletinboard.IThreadMessage) IThreadMessage(org.eclipse.ecf.bulletinboard.IThreadMessage) IMember(org.eclipse.ecf.bulletinboard.IMember) IMember(org.eclipse.ecf.bulletinboard.IMember)

Example 8 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(), "newreply.php");
    NameValuePair[] params = new NameValuePair[] { new NameValuePair("emailupdate", "9999"), new NameValuePair("rating", "0") };
    request.addParameters(params);
    params = new NameValuePair[] { new NameValuePair("title", message.getName()), new NameValuePair("message", msg.getMessage()), new NameValuePair("iconid", "0"), new NameValuePair("s", ""), new NameValuePair("do", "postreply"), new NameValuePair("t", String.valueOf(id.getLongValue())) };
    request.addParameters(params);
    if (message.getReplyTo() != null) {
        params = new NameValuePair[] { new NameValuePair("p", String.valueOf(((ThreadMessageID) message.getReplyTo().getID()).getLongValue())) };
        request.addParameters(params);
    }
    params = new NameValuePair[] { new NameValuePair("posthash", ""), new NameValuePair("poststarttime", ""), new NameValuePair("sbutton", "Submit Reply"), new NameValuePair("parseurl", "1") // checkbox : disabled new NameValuePair("disablesmilies", "1"),
    };
    request.addParameters(params);
    try {
        request.execute();
        // TODO: do we have to do this?
        String resp = request.getResponseBodyAsString();
        Header newLocation = request.getMethod().getResponseHeader("Location");
        if (newLocation == null) {
            throw ((VBParser) bb.getParser()).createVBException("The message was not posted.", resp);
        }
        Matcher m = Pattern.compile("showthread.php\\?p=([0-9]+)").matcher(newLocation.getValue());
        if (m.find()) {
            synchronized (this) {
                lastReadMessageId = (ThreadMessageID) new ThreadMessageFactory().createBBObjectId(bb.getNamespace(), bb.getURL(), m.group(1));
                return lastReadMessageId;
            }
        } else {
            throw ((VBParser) bb.getParser()).createVBException("The message was not posted.", resp);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IDCreateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ThreadMessageFactory(org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory) Matcher(java.util.regex.Matcher) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IOException(java.io.IOException) PostRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest) Header(org.apache.commons.httpclient.Header) IllegalWriteException(org.eclipse.ecf.bulletinboard.IllegalWriteException) IThreadMessage(org.eclipse.ecf.bulletinboard.IThreadMessage)

Example 9 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 10 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;
        SkippedStatus skipped = new SkippedStatus();
        while (nextPage > NONE) {
            WebRequest req = createRequest(nextPage);
            req.execute();
            String resp = req.getResponseBodyAsString();
            req.releaseConnection();
            messages.addAll(0, bb.getParser().parseMessages2(resp, thread.lastReadMessageId, true, skipped));
            if (skipped.messagesSkipped) {
                nextPage = NONE;
            } else {
                nextPage = 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)

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