Search in sources :

Example 1 with MemberFactory

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

the class VBulletin method login.

public boolean login(IBBCredentials credentials) throws BBException {
    PostRequest request = new PostRequest(httpClient, url, "login.php");
    NameValuePair[] params = { new NameValuePair("vb_login_username", credentials.getUsername()), new NameValuePair("cookieuser", "1"), new NameValuePair("vb_login_password", credentials.getPassword()), new NameValuePair("submit", "Login"), new NameValuePair("s", ""), new NameValuePair("do", "login"), new NameValuePair("forceredirect", "0"), new NameValuePair("vb_login_md5password", ""), new NameValuePair("vb_login_md5password_utf", "") };
    request.setParameters(params);
    try {
        request.execute();
        request.releaseConnection();
        Map<String, String> detectedCookies = VBCookies.detectCookies(httpClient.getState().getCookies());
        if (detectedCookies.containsKey(VBCookies.KEY_SESS_ID)) {
            // We have a session id
            sessionId = detectedCookies.get(VBCookies.KEY_SESS_ID);
        }
        if (detectedCookies.containsKey(VBCookies.KEY_USER_ID)) {
            // We have a user id
            ID id = new MemberFactory().createBBObjectId(namespace, url, (String) detectedCookies.get(VBCookies.KEY_USER_ID));
            if (id == null) {
                return false;
            } else {
                loggedInMemberId = id;
                return true;
            }
        }
    } catch (Exception e) {
        throw new BBException(e);
    }
    return false;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest) MemberFactory(org.eclipse.ecf.internal.provider.vbulletin.internal.MemberFactory) BBException(org.eclipse.ecf.bulletinboard.BBException) ID(org.eclipse.ecf.core.identity.ID) ThreadID(org.eclipse.ecf.internal.provider.vbulletin.identity.ThreadID) MemberID(org.eclipse.ecf.internal.provider.vbulletin.identity.MemberID) IOException(java.io.IOException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) BBException(org.eclipse.ecf.bulletinboard.BBException)

Example 2 with MemberFactory

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

Aggregations

ID (org.eclipse.ecf.core.identity.ID)2 MemberFactory (org.eclipse.ecf.internal.provider.vbulletin.internal.MemberFactory)2 IOException (java.io.IOException)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 NameValuePair (org.apache.commons.httpclient.NameValuePair)1 BBException (org.eclipse.ecf.bulletinboard.BBException)1 IMember (org.eclipse.ecf.bulletinboard.IMember)1 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)1 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)1 PostRequest (org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest)1 MemberID (org.eclipse.ecf.internal.provider.vbulletin.identity.MemberID)1 ThreadID (org.eclipse.ecf.internal.provider.vbulletin.identity.ThreadID)1 ThreadMessageID (org.eclipse.ecf.internal.provider.vbulletin.identity.ThreadMessageID)1 ThreadMessageFactory (org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory)1