Search in sources :

Example 11 with IDCreateException

use of org.eclipse.ecf.core.identity.IDCreateException 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 12 with IDCreateException

use of org.eclipse.ecf.core.identity.IDCreateException 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 13 with IDCreateException

use of org.eclipse.ecf.core.identity.IDCreateException in project ecf by eclipse.

the class ServiceIDTest method testServiceIDFactoryNullProto.

/*
	 * org.eclipse.ecf.discovery.identity.IServiceIDFactory.createServiceID(Namespace, String[], String[], String[], String, String)
	 */
public void testServiceIDFactoryNullProto() {
    try {
        Namespace namespaceByName = IDFactory.getDefault().getNamespaceByName(namespace);
        ServiceIDFactory.getDefault().createServiceTypeID(namespaceByName, services, scopes, null, namingAuthority);
    } catch (IDCreateException e) {
        return;
    }
    fail("Invalid services may cause InvalidIDException");
}
Also used : IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) Namespace(org.eclipse.ecf.core.identity.Namespace)

Example 14 with IDCreateException

use of org.eclipse.ecf.core.identity.IDCreateException in project ecf by eclipse.

the class AbstractParser method parseThreads.

public Map<ID, IThread> parseThreads(final CharSequence seq) {
    IPatternDescriptor pattern = getThreadPattern();
    IBBObjectFactory factory = getThreadFactory();
    Matcher m = pattern.getPattern().matcher(seq);
    Map<ID, IThread> threads = new LinkedHashMap<ID, IThread>();
    while (m.find()) {
        Map<String, Object> values = pattern.getValueMap(m);
        ID id = null;
        try {
            id = factory.createBBObjectId(namespace, baseURL, (String) values.get(IPatternDescriptor.ID_PARAM));
        } catch (IDCreateException e) {
            // TODO autogen e
            e.printStackTrace();
        }
        String name = StringUtil.stripHTMLTrim((String) values.get(IPatternDescriptor.NAME_PARAM));
        String authorInfo = (String) values.get("authorInfo");
        IBBObject member = genericParser.parseSingleIdName(getAuthorInfoMemberPattern(), authorInfo, getMemberFactory());
        if (member != null) {
            values.put("author", member);
        } else {
            IBBObjectFactory gf = getGuestFactory();
            String guestName = StringUtil.stripHTMLTrim(authorInfo);
            ID guestID = null;
            try {
                guestID = gf.createBBObjectId(namespace, baseURL, guestName);
            } catch (IDCreateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            values.put("author", getGuestFactory().createBBObject(guestID, guestName, null));
        }
        IThread obj = (IThread) factory.createBBObject(id, new String(name), values);
        threads.put(id, obj);
    }
    return threads;
}
Also used : Matcher(java.util.regex.Matcher) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IBBObject(org.eclipse.ecf.bulletinboard.IBBObject) IBBObject(org.eclipse.ecf.bulletinboard.IBBObject) ID(org.eclipse.ecf.core.identity.ID) IPatternDescriptor(org.eclipse.ecf.internal.bulletinboard.commons.parsing.IPatternDescriptor) IThread(org.eclipse.ecf.bulletinboard.IThread) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with IDCreateException

use of org.eclipse.ecf.core.identity.IDCreateException in project ecf by eclipse.

the class PHPBBParser method parseMessage2.

private ThreadMessage parseMessage2(final CharSequence seq, final ThreadMessageID lastReadId) {
    ThreadMessage msg = null;
    Matcher m;
    m = PAT_MSG_POSTID_USERNAME.matcher(seq);
    if (m.find()) {
        final ThreadMessageFactory tmf = new ThreadMessageFactory();
        String idStr = m.group(1);
        ThreadMessageID id = null;
        try {
            id = (ThreadMessageID) tmf.createBBObjectId(namespace, baseURL, idStr);
        } catch (final IDCreateException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        if (lastReadId == null || id.getLongValue() > lastReadId.getLongValue()) {
            final String uname = new String(m.group(2));
            msg = new ThreadMessage(id, null);
            m = PAT_MSG_TIMESTAMP.matcher(seq);
            if (m.find()) {
                msg.timePosted = new Date(parseTimestamp(new String(m.group(1))).longValue());
            }
            m = PAT_MSG_TITLE.matcher(seq);
            m.find();
            msg.setNameInternal(new String(m.group(1)));
            m = PAT_MSG_MESSAGE.matcher(seq);
            m.find();
            final String message = StringUtil.stripHTMLFullTrim(m.group(1));
            msg.message = message;
            m = PAT_MEMBER_ID_FROM_LINK.matcher(seq);
            if (m.find()) {
                final MemberFactory mf = new MemberFactory();
                idStr = m.group(1);
                ID id2 = null;
                try {
                    id2 = mf.createBBObjectId(namespace, baseURL, idStr);
                } catch (final NumberFormatException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (final IDCreateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                msg.author = new Member(id2, uname);
            } else {
                final GuestFactory gf = new GuestFactory();
                ID id2 = null;
                try {
                    id2 = gf.createBBObjectId(namespace, baseURL, null);
                } catch (final IDCreateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                msg.author = new Member(id2, uname);
            }
        }
    }
    return msg;
}
Also used : Matcher(java.util.regex.Matcher) ThreadMessageID(org.eclipse.ecf.internal.provider.phpbb.identity.ThreadMessageID) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) ID(org.eclipse.ecf.core.identity.ID) ThreadMessageID(org.eclipse.ecf.internal.provider.phpbb.identity.ThreadMessageID) Date(java.util.Date)

Aggregations

IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)34 ID (org.eclipse.ecf.core.identity.ID)16 Matcher (java.util.regex.Matcher)11 Namespace (org.eclipse.ecf.core.identity.Namespace)8 ThreadMessageID (org.eclipse.ecf.internal.provider.phpbb.identity.ThreadMessageID)5 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 ExecutionException (org.eclipse.core.commands.ExecutionException)4 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)4 UnknownHostException (java.net.UnknownHostException)3 ContainerConnectedEvent (org.eclipse.ecf.core.events.ContainerConnectedEvent)3 ContainerConnectingEvent (org.eclipse.ecf.core.events.ContainerConnectingEvent)3 ThreadMessageFactory (org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory)3 URI (java.net.URI)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 NameValuePair (org.apache.commons.httpclient.NameValuePair)2 Job (org.eclipse.core.runtime.jobs.Job)2 IBBObject (org.eclipse.ecf.bulletinboard.IBBObject)2 IThreadMessage (org.eclipse.ecf.bulletinboard.IThreadMessage)2