Search in sources :

Example 1 with IBBObject

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

the class AbstractParser method parseMemberGroups.

public Map<ID, IMemberGroup> parseMemberGroups(final CharSequence seq) throws BBException {
    Matcher m = getMemberGroupContainerPattern().matcher(seq);
    if (m.find()) {
        // TODO is stripHTMLTrim needed? GenericParser doesn't do it
        Map<ID, IBBObject> objects = genericParser.parseMultiIdName(getMemberGroupPattern(), m.group(0), getMemberGroupFactory(), true);
        Map<ID, IMemberGroup> members = new LinkedHashMap<ID, IMemberGroup>(objects.size());
        for (IBBObject obj : objects.values()) {
            members.put(obj.getID(), (IMemberGroup) obj);
        }
        return members;
    } else {
        throwException("Could not find member groups.", seq);
    }
    return Collections.emptyMap();
}
Also used : IMemberGroup(org.eclipse.ecf.bulletinboard.IMemberGroup) Matcher(java.util.regex.Matcher) IBBObject(org.eclipse.ecf.bulletinboard.IBBObject) ID(org.eclipse.ecf.core.identity.ID) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with IBBObject

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

the class VBParser method parseThreadPageForThreadAttributes.

public Thread parseThreadPageForThreadAttributes(CharSequence seq) throws BBException {
    Thread t = (Thread) genericParser.parseSingleIdName(PD_THREAD_ATTRS, seq, new ThreadFactory());
    if (t != null) {
        Map<ID, IBBObject> forums = genericParser.parseMultiIdName(PD_THREAD_ATTRS_FORUM, seq, new ForumFactory(), true);
        Forum prev = null;
        Forum f = null;
        for (IBBObject obj : forums.values()) {
            f = (Forum) obj;
            if (prev != null) {
                prev.subforums.add(f);
            }
            f.setParent(prev);
            prev = f;
        }
        t.forum = f;
        return t;
    } else {
        throw new BBException("Failed to parse the thread.");
    }
}
Also used : ForumFactory(org.eclipse.ecf.internal.provider.vbulletin.internal.ForumFactory) BBException(org.eclipse.ecf.bulletinboard.BBException) IBBObject(org.eclipse.ecf.bulletinboard.IBBObject) ThreadMessageID(org.eclipse.ecf.internal.provider.vbulletin.identity.ThreadMessageID) ID(org.eclipse.ecf.core.identity.ID)

Example 3 with IBBObject

use of org.eclipse.ecf.bulletinboard.IBBObject 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 4 with IBBObject

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

the class AbstractParser method parseMembers.

public Map<ID, IMember> parseMembers(final CharSequence seq) {
    // TODO is stripHTMLTrim needed? GenericParser doesn't do it
    Map<ID, IBBObject> objects = genericParser.parseMultiIdName(getMemberPattern(), seq, getMemberFactory(), true);
    Map<ID, IMember> members = new LinkedHashMap<ID, IMember>(objects.size());
    for (IBBObject obj : objects.values()) {
        members.put(obj.getID(), (IMember) obj);
    }
    return members;
}
Also used : IBBObject(org.eclipse.ecf.bulletinboard.IBBObject) ID(org.eclipse.ecf.core.identity.ID) IMember(org.eclipse.ecf.bulletinboard.IMember) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with IBBObject

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

the class GenericParser method parseIdNamePairs.

private Object parseIdNamePairs(IPatternDescriptor pattern, CharSequence sequence, IBBObjectFactory factory, boolean expectMultipleMatches, boolean preserveOrder) {
    final Matcher m = pattern.getPattern().matcher(sequence);
    Map<ID, IBBObject> objectMap = null;
    if (expectMultipleMatches) {
        if (preserveOrder) {
            objectMap = new LinkedHashMap<ID, IBBObject>();
        } else {
            objectMap = new HashMap<ID, IBBObject>();
        }
    }
    while (m.find()) {
        final Map<String, Object> values = pattern.getValueMap(m);
        ID id = null;
        try {
            id = factory.createBBObjectId(namespace, baseURL, (String) values.get(IPatternDescriptor.ID_PARAM));
        } catch (final IDCreateException e) {
            // TODO autogen e
            e.printStackTrace();
        }
        final String name = StringUtil.stripHTMLTrim((String) values.get(IPatternDescriptor.NAME_PARAM));
        final IBBObject obj = factory.createBBObject(id, new String(name), values);
        if (expectMultipleMatches) {
            objectMap.put(id, obj);
        } else {
            return obj;
        }
    }
    if (expectMultipleMatches) {
        return objectMap;
    } else {
        return null;
    }
}
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)

Aggregations

IBBObject (org.eclipse.ecf.bulletinboard.IBBObject)5 ID (org.eclipse.ecf.core.identity.ID)5 LinkedHashMap (java.util.LinkedHashMap)3 Matcher (java.util.regex.Matcher)3 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)2 BBException (org.eclipse.ecf.bulletinboard.BBException)1 IMember (org.eclipse.ecf.bulletinboard.IMember)1 IMemberGroup (org.eclipse.ecf.bulletinboard.IMemberGroup)1 IThread (org.eclipse.ecf.bulletinboard.IThread)1 IPatternDescriptor (org.eclipse.ecf.internal.bulletinboard.commons.parsing.IPatternDescriptor)1 ThreadMessageID (org.eclipse.ecf.internal.provider.vbulletin.identity.ThreadMessageID)1 ForumFactory (org.eclipse.ecf.internal.provider.vbulletin.internal.ForumFactory)1