Search in sources :

Example 1 with ThreadMessageFactory

use of org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory in project ecf by eclipse.

the class VBParser method parseMessages2.

public List<ThreadMessage> parseMessages2(final CharSequence seq, final ID lastReadId, boolean desc, SkippedStatus skipped) throws BBException {
    Matcher m;
    ThreadMessage msg;
    List<ThreadMessage> messages = new ArrayList<ThreadMessage>();
    m = PAT_MSG.matcher(seq);
    while (m.find()) {
        ThreadMessageFactory tmf = new ThreadMessageFactory();
        ThreadMessageID id = null;
        try {
            id = (ThreadMessageID) tmf.createBBObjectId(namespace, baseURL, m.group(1));
        } catch (NumberFormatException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IDCreateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (lastReadId == null || id.getLongValue() > ((ThreadMessageID) lastReadId).getLongValue()) {
            String msgSrc = m.group(2);
            msg = parseMessage2(id, msgSrc);
            if (msg != null) {
                if (desc) {
                    messages.add(0, msg);
                } else {
                    messages.add(msg);
                }
            }
        } else {
            skipped.messagesSkipped = true;
        }
    }
    return messages;
}
Also used : ThreadMessageFactory(org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory) Matcher(java.util.regex.Matcher) ThreadMessageID(org.eclipse.ecf.internal.provider.vbulletin.identity.ThreadMessageID) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) ArrayList(java.util.ArrayList)

Example 2 with ThreadMessageFactory

use of org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory in project ecf by eclipse.

the class VBParser method parseMessage2.

private ThreadMessage parseMessage2(final ID id, final CharSequence seq) {
    ThreadMessage msg = null;
    ThreadMessageFactory tmf = new ThreadMessageFactory();
    msg = (ThreadMessage) tmf.createBBObject(id, null, null);
    Matcher m;
    String uname;
    Long l = parseTimestamp(seq);
    if (l != null) {
        msg.timePosted = new Date(l);
    }
    m = Pattern.compile("<div id=\"postmenu_" + ((ThreadMessageID) id).getLongValue() + "\">(.*?)</div>", Pattern.DOTALL).matcher(seq);
    if (m.find()) {
        String userInfoStr = m.group(1);
        m = PAT_MSG_USER.matcher(userInfoStr);
        if (m.find()) {
            MemberFactory mf = new MemberFactory();
            uname = new String(StringUtil.simpleStripHTML(m.group(3)));
            ID uid = null;
            try {
                uid = mf.createBBObjectId(namespace, baseURL, m.group(2));
            } catch (NumberFormatException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IDCreateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            msg.author = (IMember) mf.createBBObject(uid, uname, null);
        } else {
            // Didn't find a registered author, so the userinfo should
            // contain only the username.
            msg.author = new Member(new String(userInfoStr.trim()));
        }
    }
    m = Pattern.compile("#<a href=\"showpost.php\\?p=" + ((ThreadMessageID) id).getLongValue() + "(?:.*?)><strong>([0-9]+)</strong></a>").matcher(seq);
    m.find();
    msg.number = Integer.parseInt(m.group(1));
    m = PAT_MSG_TITLE.matcher(seq);
    m.find();
    msg.setNameInternal(new String(StringUtil.stripHTMLTrim(m.group(1))));
    m = PAT_MSG_MESSAGE.matcher(seq);
    m.find();
    String message = StringUtil.stripHTMLFullTrim(m.group(1));
    msg.message = message;
    return msg;
}
Also used : ThreadMessageFactory(org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory) Matcher(java.util.regex.Matcher) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) MemberFactory(org.eclipse.ecf.internal.provider.vbulletin.internal.MemberFactory) ThreadMessageID(org.eclipse.ecf.internal.provider.vbulletin.identity.ThreadMessageID) ID(org.eclipse.ecf.core.identity.ID) IMember(org.eclipse.ecf.bulletinboard.IMember) Date(java.util.Date)

Example 3 with ThreadMessageFactory

use of org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory 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)

Aggregations

Matcher (java.util.regex.Matcher)3 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)3 ThreadMessageFactory (org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory)3 ThreadMessageID (org.eclipse.ecf.internal.provider.vbulletin.identity.ThreadMessageID)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Header (org.apache.commons.httpclient.Header)1 NameValuePair (org.apache.commons.httpclient.NameValuePair)1 IMember (org.eclipse.ecf.bulletinboard.IMember)1 IThreadMessage (org.eclipse.ecf.bulletinboard.IThreadMessage)1 IllegalWriteException (org.eclipse.ecf.bulletinboard.IllegalWriteException)1 ID (org.eclipse.ecf.core.identity.ID)1 PostRequest (org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest)1 MemberFactory (org.eclipse.ecf.internal.provider.vbulletin.internal.MemberFactory)1