Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2007-02-27 17:43:32 +0000
committerslewis2007-02-27 17:43:32 +0000
commit9528acfe8c8019349ae7219026ba00faf52256da (patch)
treebff763640b3c72ea03789b6f665aaa57079b4753 /incubation/bundles
parentd91bcdc1b47a8851469c4c7c6502fc3440067210 (diff)
downloadorg.eclipse.ecf-9528acfe8c8019349ae7219026ba00faf52256da.tar.gz
org.eclipse.ecf-9528acfe8c8019349ae7219026ba00faf52256da.tar.xz
org.eclipse.ecf-9528acfe8c8019349ae7219026ba00faf52256da.zip
Initial checkin to support bbapi
Diffstat (limited to 'incubation/bundles')
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/.classpath7
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/.project28
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/META-INF/MANIFEST.MF21
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/build.properties5
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/plugin.xml29
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Category.java72
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/CategoryFactory.java52
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Forum.java161
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ForumFactory.java48
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/GuestFactory.java49
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Member.java66
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/MemberFactory.java49
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/MemberGroup.java112
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/MemberGroupFactory.java50
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBB.java244
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBCookies.java55
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBException.java25
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBFactory.java32
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBObject.java21
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBParser.java584
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBPlugin.java65
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPUtil.java63
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Thread.java230
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadBrowser2.java76
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadFactory.java58
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadMessage.java116
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadMessageFactory.java50
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/container/ContainerInstantiator.java44
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/container/PHPBBContainer.java31
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/CategoryID.java43
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/ForumID.java43
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/GuestID.java36
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/MemberGroupID.java44
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/MemberID.java45
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/PHPBBID.java60
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/PHPBBNamespace.java87
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/ThreadID.java44
-rw-r--r--incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/ThreadMessageID.java44
38 files changed, 2889 insertions, 0 deletions
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/.classpath b/incubation/bundles/org.eclipse.ecf.provider.phpbb/.classpath
new file mode 100644
index 000000000..00e032c3d
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/.project b/incubation/bundles/org.eclipse.ecf.provider.phpbb/.project
new file mode 100644
index 000000000..8436c8348
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.ecf.provider.phpbb</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/META-INF/MANIFEST.MF b/incubation/bundles/org.eclipse.ecf.provider.phpbb/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..0d39651ae
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/META-INF/MANIFEST.MF
@@ -0,0 +1,21 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: ECF phpBB Provider
+Bundle-SymbolicName: org.eclipse.ecf.provider.phpbb;singleton:=true
+Bundle-Version: 0.1.0
+Bundle-Vendor: Erkki Lindpere
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.ecf,
+ org.eclipse.ecf.bulletinboard,
+ org.eclipse.core.runtime,
+ org.eclipse.ecf.bulletinboard.commons
+Bundle-Activator: org.eclipse.ecf.internal.provider.phpbb.PHPBBPlugin
+Eclipse-LazyStart: false
+Import-Package: org.apache.commons.httpclient,
+ org.apache.commons.httpclient.methods,
+ org.apache.commons.httpclient.methods.multipart
+Export-Package:
+ org.eclipse.ecf.internal.provider.phpbb;x-internal:=true,
+ org.eclipse.ecf.internal.provider.phpbb.container;x-internal:=true,
+ org.eclipse.ecf.internal.provider.phpbb.identity;x-internal:=true
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/build.properties b/incubation/bundles/org.eclipse.ecf.provider.phpbb/build.properties
new file mode 100644
index 000000000..110a2d2dc
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = target/classes/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/plugin.xml b/incubation/bundles/org.eclipse.ecf.provider.phpbb/plugin.xml
new file mode 100644
index 000000000..5d8a56710
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/plugin.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.ecf.identity.namespace">
+ <namespace
+ class="org.eclipse.ecf.internal.provider.phpbb.identity.PHPBBNamespace"
+ description="phpBB Namespace"
+ name="ecf.phpbb"/>
+ </extension>
+ <extension
+ point="org.eclipse.ecf.containerFactory">
+ <containerFactory
+ class="org.eclipse.ecf.internal.provider.phpbb.container.ContainerInstantiator"
+ description="phpBB HTTP Client"
+ name="ecf.phpbb.http">
+ <property
+ name="org.eclipse.ecf.example.collab.ui.JoinGroupWizardPage.usenickname"
+ value="true"/>
+ <property
+ name="org.eclipse.ecf.example.collab.ui.JoinGroupWizardPage.usepassword"
+ value="true"/>
+ <property
+ name="org.eclipse.ecf.example.collab.ui.JoinGroupWizardPage.groupIDLabel"
+ value="URL:"/>
+ </containerFactory>
+ </extension>
+
+</plugin>
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Category.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Category.java
new file mode 100644
index 000000000..90978c731
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Category.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.ecf.bulletinboard.BBException;
+import org.eclipse.ecf.bulletinboard.IForum;
+import org.eclipse.ecf.bulletinboard.IThread;
+import org.eclipse.ecf.internal.provider.phpbb.identity.CategoryID;
+
+public class Category extends Forum {
+
+ public Category(CategoryID id, String name) {
+ super(id, name);
+ this.mode = READ_ONLY;
+ }
+
+ protected void addSubForum(Forum forum) {
+ subforums.add(forum);
+ }
+
+ public String getDescription() {
+ // Descriptions not supported for categories.
+ return null;
+ }
+
+ public int getType() {
+ return IForum.HOLDS_FORUMS;
+ }
+
+ public List<IThread> getThreads() {
+ return Collections.emptyList();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.tigris.bbapi.phpBB.Forum#createThread()
+ */
+ @Override
+ public IThread createThread() throws BBException {
+ throw new BBException("This forum cannot hold threads.");
+ }
+
+ public boolean postThread(IThread thread) throws BBException {
+ throw new BBException("This forum cannot hold threads.");
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Category) {
+ Category grp = (Category) obj;
+ return id.equals(grp.id);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/CategoryFactory.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/CategoryFactory.java
new file mode 100644
index 000000000..79374b6ea
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/CategoryFactory.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+
+import org.eclipse.ecf.bulletinboard.IBBObject;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.internal.bulletinboard.commons.IBBObjectFactory;
+import org.eclipse.ecf.internal.provider.phpbb.identity.CategoryID;
+import org.eclipse.ecf.internal.provider.phpbb.identity.PHPBBNamespace;
+
+public class CategoryFactory implements IBBObjectFactory {
+
+ public ID createBBObjectId(Namespace namespace, String stringValue)
+ throws IDCreateException {
+ try {
+ return new CategoryID((PHPBBNamespace) namespace, new URI(
+ stringValue));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public ID createBBObjectId(Namespace namespace, URL baseURL, String longValue)
+ throws IDCreateException {
+ try {
+ return new CategoryID((PHPBBNamespace) namespace, baseURL,
+ Long.parseLong(longValue));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public IBBObject createBBObject(ID id, String name, Map<String, Object> parameters) {
+ return new Category((CategoryID) id, name);
+ }
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Forum.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Forum.java
new file mode 100644
index 000000000..246f7915a
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Forum.java
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.httpclient.NameValuePair;
+import org.eclipse.ecf.bulletinboard.BBException;
+import org.eclipse.ecf.bulletinboard.IForum;
+import org.eclipse.ecf.bulletinboard.IThread;
+import org.eclipse.ecf.bulletinboard.IllegalWriteException;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.internal.bulletinboard.commons.AbstractBBObject;
+import org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest;
+import org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest;
+import org.eclipse.ecf.internal.bulletinboard.commons.webapp.WebRequest;
+import org.eclipse.ecf.internal.provider.phpbb.identity.ForumID;
+
+public class Forum extends PHPBBObject implements IForum {
+ private static final String E_READ_ONLY = "This forum is read only.";
+
+ private Category parent;
+
+ protected ArrayList<IForum> subforums;
+
+ private String description;
+
+ protected ForumID id;
+
+ public Forum(ForumID id, String name) {
+ super(name, READ_WRITE);
+ this.id = id;
+ this.parent = null;
+ this.subforums = new ArrayList<IForum>();
+ }
+
+ public ID getID() {
+ return id;
+ }
+
+ protected void setParent(Category cat) {
+ this.parent = cat;
+ }
+
+ protected void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public int getType() {
+ return IForum.HOLDS_THREADS;
+ }
+
+ public IForum getParentForum() {
+ return parent;
+ }
+
+ public List<IForum> getSubForums() {
+ return subforums;
+ }
+
+ public Collection<IThread> getThreads() {
+ PHPBBParser parser = (PHPBBParser) bb.getParser();
+ Map<ID, IThread> threadMap = null;
+ try {
+ WebRequest request = new GetRequest(bb.getHttpClient(), new URL(id
+ .toExternalForm()), "");
+ request.addParameter(new NameValuePair("f", String.valueOf(id
+ .getLongValue())));
+ request.execute();
+ String resp = request.getResponseBodyAsString();
+ request.releaseConnection();
+ threadMap = parser.parseThreads(resp);
+ for (IThread thread : threadMap.values()) {
+ ((AbstractBBObject) thread).setBulletinBoard(bb);
+ ((Thread) thread).forum = this;
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return new HashSet<IThread>(threadMap.values());
+ }
+
+ public IThread createThread() throws IllegalWriteException, BBException {
+ if ((mode & READ_ONLY) == READ_ONLY) {
+ throw new IllegalWriteException(E_READ_ONLY);
+ }
+ Thread thread = new Thread();
+ thread.setBulletinBoard(bb);
+ thread.forum = this;
+ return thread;
+ }
+
+ public boolean postThread(IThread thread) throws IllegalWriteException,
+ BBException {
+ if ((mode & READ_ONLY) == READ_ONLY) {
+ throw new IllegalWriteException(E_READ_ONLY);
+ }
+ WebRequest request = new PostRequest(bb.getHttpClient(), bb.getURL(),
+ "posting.php");
+
+ NameValuePair params[];
+ params = new NameValuePair[] {
+ new NameValuePair("subject", thread.getPrePostMessage()
+ .getName()),
+ new NameValuePair("message", thread.getPrePostMessage()
+ .getMessage()),
+ new NameValuePair("f", String.valueOf(id.getLongValue())),
+ new NameValuePair("mode", "newtopic"),
+ // checkbox : disabled new NameValuePair("disable_smilies",
+ // "on"),
+ // checkbox : disabled new NameValuePair("disable_bbcode",
+ // "on"),
+ // checkbox : disabled new NameValuePair("notify", "on"),
+ new NameValuePair("post", "Submit") };
+ request.addParameters(params);
+ // We seem to always have to get the response body.
+ try {
+ request.execute();
+ request.getResponseBodyAsString();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ request.releaseConnection();
+ return true;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Forum) {
+ Forum grp = (Forum) obj;
+ return id.equals(grp.id);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ForumFactory.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ForumFactory.java
new file mode 100644
index 000000000..8d251b0a0
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ForumFactory.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+
+import org.eclipse.ecf.bulletinboard.IBBObject;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.internal.bulletinboard.commons.IBBObjectFactory;
+import org.eclipse.ecf.internal.provider.phpbb.identity.ForumID;
+import org.eclipse.ecf.internal.provider.phpbb.identity.PHPBBNamespace;
+
+public class ForumFactory implements IBBObjectFactory {
+ public ID createBBObjectId(Namespace namespace, String stringValue)
+ throws IDCreateException {
+ try {
+ return new ForumID((PHPBBNamespace) namespace, new URI(stringValue));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public ID createBBObjectId(Namespace namespace, URL baseURL, String longValue)
+ throws IDCreateException {
+ try {
+ return new ForumID((PHPBBNamespace) namespace, baseURL, Long.parseLong(longValue));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public IBBObject createBBObject(ID id, String name, Map<String, Object> parameters) {
+ return new Forum((ForumID) id, name);
+ }
+} \ No newline at end of file
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/GuestFactory.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/GuestFactory.java
new file mode 100644
index 000000000..220378dd2
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/GuestFactory.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+
+import org.eclipse.ecf.bulletinboard.IBBObject;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.internal.bulletinboard.commons.IBBObjectFactory;
+import org.eclipse.ecf.internal.provider.phpbb.identity.GuestID;
+import org.eclipse.ecf.internal.provider.phpbb.identity.PHPBBNamespace;
+
+public class GuestFactory implements IBBObjectFactory {
+ public ID createBBObjectId(Namespace namespace, String stringValue)
+ throws IDCreateException {
+ try {
+ return new GuestID((PHPBBNamespace) namespace, new URI(stringValue));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public ID createBBObjectId(Namespace namespace, URL baseURL,
+ String longValue) throws IDCreateException {
+ try {
+ return new GuestID((PHPBBNamespace) namespace, baseURL, longValue);
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public IBBObject createBBObject(ID id, String name,
+ Map<String, Object> parameters) {
+ return new Member((GuestID) id, name);
+ }
+} \ No newline at end of file
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Member.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Member.java
new file mode 100644
index 000000000..b7d727841
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Member.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+import org.eclipse.ecf.bulletinboard.IMember;
+import org.eclipse.ecf.bulletinboard.IMemberGroup;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.internal.bulletinboard.commons.AbstractBulletinBoard;
+
+public class Member extends PHPBBObject implements IMember {
+ // private static final Logger log = Logger.getLogger(Member.class);
+
+ private static final long serialVersionUID = -4327906596939705648L;
+
+ private ID id;
+
+ public Member(ID id, String name) {
+ super(name, READ_ONLY);
+ this.id = id;
+ }
+
+ public ID getID() {
+ return id;
+ }
+
+ public boolean isMemberOf(IMemberGroup group) {
+ // TODO maybe a better way?
+ return group.getMembers().contains(this);
+ }
+
+ public Collection<IMemberGroup> getGroups() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Member) {
+ Member grp = (Member) obj;
+ return id.equals(grp.id);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+
+ public Map getProperties() {
+ return Collections.emptyMap();
+ }
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/MemberFactory.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/MemberFactory.java
new file mode 100644
index 000000000..e41c68de9
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/MemberFactory.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+
+import org.eclipse.ecf.bulletinboard.IBBObject;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.internal.bulletinboard.commons.IBBObjectFactory;
+import org.eclipse.ecf.internal.provider.phpbb.identity.MemberID;
+import org.eclipse.ecf.internal.provider.phpbb.identity.PHPBBNamespace;
+
+public class MemberFactory implements IBBObjectFactory {
+ public ID createBBObjectId(Namespace namespace, String stringValue)
+ throws IDCreateException {
+ try {
+ return new MemberID((PHPBBNamespace) namespace,
+ new URI(stringValue));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public ID createBBObjectId(Namespace namespace, URL baseURL, String longValue)
+ throws IDCreateException {
+ try {
+ return new MemberID((PHPBBNamespace) namespace, baseURL, Long.parseLong(longValue));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public IBBObject createBBObject(ID id, String name, Map<String, Object> parameters) {
+ return new Member((MemberID) id, name);
+ }
+} \ No newline at end of file
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/MemberGroup.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/MemberGroup.java
new file mode 100644
index 000000000..6e899a90b
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/MemberGroup.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+
+import org.apache.commons.httpclient.NameValuePair;
+import org.eclipse.ecf.bulletinboard.IMember;
+import org.eclipse.ecf.bulletinboard.IMemberGroup;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.internal.bulletinboard.commons.AbstractBBObject;
+import org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest;
+import org.eclipse.ecf.internal.provider.phpbb.identity.MemberGroupID;
+
+public class MemberGroup extends PHPBBObject implements IMemberGroup {
+
+ private String description;
+
+ private MemberGroupID id;
+
+ private boolean detailsFetched;
+
+ public MemberGroup(MemberGroupID id, String name) {
+ super(name, READ_ONLY);
+ this.id = id;
+ this.detailsFetched = false;
+ }
+
+ private void attainDetailsFetched() {
+ if (!detailsFetched) {
+ GetRequest request = new GetRequest(bb.getHttpClient(),
+ bb.getURL(), "groupcp.php");
+ request.addParameter(new NameValuePair("g", String.valueOf(id
+ .getLongValue())));
+ String resp = null;
+ try {
+ request.execute();
+ resp = request.getResponseBodyAsString();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ request.releaseConnection();
+ if (resp != null) {
+ MemberGroup group = ((PHPBBParser) bb.getParser())
+ .parseMemberGroup(resp);
+ group.detailsFetched = true;
+ this.description = group.getDescription();
+ }
+ }
+ }
+
+ public String getDescription() {
+ attainDetailsFetched();
+ return description;
+ }
+
+ public Collection<IMember> getMembers() {
+ Map<ID, IMember> map = Collections.emptyMap();
+ GetRequest request = new GetRequest(bb.getHttpClient(), bb.getURL(),
+ "groupcp.php");
+ request.addParameter(new NameValuePair("g", String.valueOf(id
+ .getLongValue())));
+ try {
+ request.execute();
+ String str = request.getResponseBodyAsString();
+ request.releaseConnection();
+ if (str != null) {
+ map = bb.getParser().parseMembers(str);
+ for (IMember member : map.values()) {
+ ((AbstractBBObject) member).setBulletinBoard(bb);
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return new HashSet<IMember>(map.values());
+ }
+
+ public ID getID() {
+ return id;
+ }
+
+ protected void setDescription(String desc) {
+ this.description = desc;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof MemberGroup) {
+ MemberGroup grp = (MemberGroup) obj;
+ return id.equals(grp.id);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/MemberGroupFactory.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/MemberGroupFactory.java
new file mode 100644
index 000000000..f936e1df9
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/MemberGroupFactory.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+
+import org.eclipse.ecf.bulletinboard.IBBObject;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.internal.bulletinboard.commons.IBBObjectFactory;
+import org.eclipse.ecf.internal.provider.phpbb.identity.MemberGroupID;
+import org.eclipse.ecf.internal.provider.phpbb.identity.PHPBBNamespace;
+
+public class MemberGroupFactory implements IBBObjectFactory {
+ public ID createBBObjectId(Namespace namespace, String stringValue)
+ throws IDCreateException {
+ try {
+ return new MemberGroupID((PHPBBNamespace) namespace, new URI(
+ stringValue));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public ID createBBObjectId(Namespace namespace, URL baseURL, String longValue)
+ throws IDCreateException {
+ try {
+ return new MemberGroupID((PHPBBNamespace) namespace, baseURL,
+ Long.parseLong(longValue));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public IBBObject createBBObject(ID id, String name, Map<String, Object> parameters) {
+ return new MemberGroup((MemberGroupID) id, name);
+ }
+} \ No newline at end of file
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBB.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBB.java
new file mode 100644
index 000000000..e3f08d8e6
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBB.java
@@ -0,0 +1,244 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.httpclient.NameValuePair;
+import org.eclipse.ecf.bulletinboard.BBException;
+import org.eclipse.ecf.bulletinboard.IBBCredentials;
+import org.eclipse.ecf.bulletinboard.IForum;
+import org.eclipse.ecf.bulletinboard.IMember;
+import org.eclipse.ecf.bulletinboard.IThread;
+import org.eclipse.ecf.bulletinboard.IThreadMessage;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.internal.bulletinboard.commons.AbstractBulletinBoard;
+import org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest;
+import org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest;
+import org.eclipse.ecf.internal.bulletinboard.commons.webapp.WebRequest;
+import org.eclipse.ecf.internal.provider.phpbb.container.PHPBBContainer;
+import org.eclipse.ecf.internal.provider.phpbb.identity.MemberID;
+import org.eclipse.ecf.internal.provider.phpbb.identity.ThreadID;
+import org.eclipse.ecf.internal.provider.phpbb.identity.ThreadMessageID;
+
+public class PHPBB extends AbstractBulletinBoard {
+ public static final String P_SESSION_ID_COOKIE = "phpBB.sessionIdCookie";
+
+ public static final String P_DATA_COOKIE = "phpBB.dataCookie";
+
+ private Map<ID, Forum> cachedForums;
+
+ private String sessionId;
+
+ private String title;
+
+ protected PHPBB(PHPBBContainer mainContainer) {
+ super(mainContainer);
+ }
+
+ protected void reset() {
+ this.cachedForums = new HashMap<ID, Forum>();
+ super.reset();
+ }
+
+ public void postConnect() {
+ super.postConnect();
+ parser = new PHPBBParser(namespace, url);
+ }
+
+ public void postDisconnect() {
+ parser = null;
+ super.postDisconnect();
+ }
+
+ /**
+ * @return Returns the sessionId.
+ */
+ protected String getSessionId() {
+ return sessionId;
+ }
+
+ public List<IForum> getForums() {
+ if (cachedForums.isEmpty()) {
+ GetRequest request = new GetRequest(httpClient, url, "");
+ try {
+ request.execute();
+ String resp = request.getResponseBodyAsString();
+ request.releaseConnection();
+ cachedForums = getParser().parseForums(resp);
+ for (Forum forum : cachedForums.values()) {
+ forum.setBulletinBoard(this);
+ }
+ } catch (IOException e) {
+ // log.error(e);
+ }
+ }
+ return new ArrayList<IForum>(cachedForums.values());
+ }
+
+ public List<IForum> getTopLevelForums() {
+ List<IForum> topForums = new ArrayList<IForum>();
+ for (IForum forum : getForums()) {
+ if (forum.getParentForum() == null) {
+ topForums.add(forum);
+ }
+ }
+ return topForums;
+ }
+
+ public IForum getForum(ID id) {
+ if (cachedForums.isEmpty()) {
+ getForums();
+ }
+ return cachedForums.get(id);
+ }
+
+ public PHPBBParser getParser() {
+ return (PHPBBParser) this.parser;
+ }
+
+ @Override
+ protected WebRequest createMemberListRequest() {
+ return new GetRequest(httpClient, url, "memberlist.php");
+ }
+
+ @Override
+ protected WebRequest createMemberPageRequest(ID id) {
+ WebRequest request = new GetRequest(httpClient, url, "profile.php");
+
+ NameValuePair params[] = {
+ new NameValuePair("mode", "viewprofile"),
+ new NameValuePair("u", String.valueOf(((MemberID) id)
+ .getLongValue())) };
+ request.setParameters(params);
+ return request;
+ }
+
+ @Override
+ protected WebRequest createMemberGroupListRequest() {
+ return new GetRequest(httpClient, url, "groupcp.php");
+ }
+
+ public boolean login(IBBCredentials credentials) throws BBException {
+ PostRequest request = new PostRequest(httpClient, url, "login.php");
+ NameValuePair params[] = {
+ new NameValuePair("username", credentials.getUsername()),
+ new NameValuePair("password", credentials.getPassword()),
+ // disabled checkbox: new NameValuePair("autologin", "on"),
+ new NameValuePair("redirect", ""),
+ new NameValuePair("login", "Log in") };
+ request.setParameters(params);
+
+ try {
+ request.execute();
+ request.releaseConnection();
+ Map<String, String> detectedCookies = PHPBBCookies
+ .detectCookies(httpClient.getState().getCookies());
+ if (detectedCookies.containsKey(PHPBBCookies.KEY_SESS_ID)) {
+ // We have a session id
+ sessionId = detectedCookies.get(PHPBBCookies.KEY_SESS_ID);
+ }
+ if (detectedCookies.containsKey(PHPBBCookies.KEY_USER_ID)) {
+ // We have a user id
+ ID id = new MemberFactory().createBBObjectId(getNamespace(),
+ url, (String) detectedCookies
+ .get(PHPBBCookies.KEY_USER_ID));
+ if (id == null) {
+ return false;
+ } else {
+ loggedInMemberId = id;
+ return true;
+ }
+ }
+ } catch (Exception e) {
+ throw new BBException(e);
+ }
+ return false;
+ }
+
+ public boolean logout() throws BBException {
+ PostRequest request = new PostRequest(httpClient, url, "login.php");
+ request.addParameter(new NameValuePair("logout", "true"));
+ try {
+ request.execute();
+ request.releaseConnection();
+ loggedInMemberId = null;
+ return true;
+ } catch (Exception e) {
+ throw new BBException(e);
+ }
+ }
+
+ public IThread getThread(ID id) throws BBException {
+ GetRequest request = new GetRequest(httpClient, url, "viewtopic.php");
+ request.addParameter(new NameValuePair("t", String
+ .valueOf(((ThreadID) id).getLongValue())));
+ String resp = null;
+ try {
+ request.execute();
+ resp = request.getResponseBodyAsString();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ request.releaseConnection();
+ if (resp != null) {
+ Thread t = getParser().parseThreadPageForThreadAttributes(resp);
+ t.setBulletinBoard(this);
+ return t;
+ }
+ return null;
+ }
+
+ public IThreadMessage getMessage(ID id) throws BBException {
+ GetRequest request = new GetRequest(httpClient, url, "viewtopic.php");
+ request.addParameter(new NameValuePair("p", String
+ .valueOf(((ThreadMessageID) id).getLongValue())));
+ String resp = null;
+ try {
+ request.execute();
+ resp = request.getResponseBodyAsString();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ request.releaseConnection();
+ if (resp != null) {
+ ThreadMessage msg = getParser().parseRequestedMessage(
+ (ThreadMessageID) id, resp);
+ msg.setBulletinBoard(this);
+ IMember author = msg.author;
+ ((Member) author).setBulletinBoard(this);
+ return msg;
+ }
+ return null;
+ }
+
+ public String getTitle() throws BBException {
+ if (this.title == null) {
+ GetRequest request = new GetRequest(httpClient, url, "");
+ String resp = null;
+ try {
+ request.execute();
+ resp = request.getResponseBodyAsString();
+ } catch (IOException e) {
+ throw new BBException(e);
+ }
+ request.releaseConnection();
+ if (resp != null) {
+ this.title = getParser().parseTitle(resp);
+ }
+ }
+ return this.title;
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBCookies.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBCookies.java
new file mode 100644
index 000000000..5e4c6a7fc
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBCookies.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.apache.commons.httpclient.Cookie;
+
+public class PHPBBCookies {
+ public static final String KEY_SESS_ID = "phpbb.sessionid";
+
+ public static final String KEY_USER_ID = "phpbb.userid";
+
+ /**
+ * Matches an MD5.
+ */
+ private static final Pattern PAT_SESS_ID = Pattern
+ .compile("[0-9abcdef]{32}");
+
+ public static Map<String, String> detectCookies(Cookie[] cookies) {
+ Map<String, String> detected = new HashMap<String, String>();
+ for (Cookie cookie : cookies) {
+ if (PAT_SESS_ID.matcher(cookie.getValue()).matches()) {
+ // detected session id
+ detected.put(KEY_SESS_ID, cookie.getValue());
+ } else {
+ // try to detect user id
+ try {
+ String value = URLDecoder
+ .decode(cookie.getValue(), "UTF-8");
+ Map<String, String> map = PHPUtil
+ .deserializeStringArray(value);
+ if (map != null && map.containsKey("userid")) {
+ detected.put(KEY_USER_ID, map.get("userid"));
+ }
+ } catch (UnsupportedEncodingException e) {
+ // do nothing
+ }
+ }
+ }
+ return detected;
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBException.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBException.java
new file mode 100644
index 000000000..7b291785a
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBException.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+/**
+ * This exception is set as the cause of a BBException when an exception message
+ * was parseable from the PHPBB HTML after a failed operation.
+ *
+ * @author Erkki
+ */
+public class PHPBBException extends Exception {
+ private static final long serialVersionUID = 7050504740362137141L;
+
+ public PHPBBException(String message) {
+ super(message);
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBFactory.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBFactory.java
new file mode 100644
index 000000000..aa53e6d23
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBFactory.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import org.eclipse.ecf.internal.provider.phpbb.container.PHPBBContainer;
+
+public class PHPBBFactory {
+ private static PHPBBFactory instance;
+
+ private PHPBBFactory() {
+ super();
+ }
+
+ public static PHPBBFactory getDefault() {
+ if (instance == null) {
+ instance = new PHPBBFactory();
+ }
+ return instance;
+ }
+
+ public PHPBB createPHPBB(PHPBBContainer mainContainer) {
+ return new PHPBB(mainContainer);
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBObject.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBObject.java
new file mode 100644
index 000000000..8f47778c6
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBObject.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import org.eclipse.ecf.bulletinboard.IBBObject;
+import org.eclipse.ecf.internal.bulletinboard.commons.AbstractBBObject;
+
+public abstract class PHPBBObject extends AbstractBBObject implements IBBObject {
+
+ public PHPBBObject(String name, int mode) {
+ super(name, mode);
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBParser.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBParser.java
new file mode 100644
index 000000000..16da3518d
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBParser.java
@@ -0,0 +1,584 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.net.URL;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.ecf.bulletinboard.BBException;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.internal.bulletinboard.commons.AbstractParser;
+import org.eclipse.ecf.internal.bulletinboard.commons.IBBObjectFactory;
+import org.eclipse.ecf.internal.bulletinboard.commons.parsing.DefaultPatternDescriptor;
+import org.eclipse.ecf.internal.bulletinboard.commons.parsing.IPatternDescriptor;
+import org.eclipse.ecf.internal.bulletinboard.commons.util.StringUtil;
+import org.eclipse.ecf.internal.provider.phpbb.identity.ThreadMessageID;
+
+/**
+ * NB! use new String(Matcher.group(int)) instead of Matcher.group(int)
+ *
+ * @author Erkki
+ */
+public class PHPBBParser extends AbstractParser {
+
+ public PHPBBParser(Namespace namespace, URL baseURL) {
+ super(namespace, baseURL);
+ }
+
+ public static final Pattern PAT_PHPBB_SIGNATURE = Pattern.compile(
+ "<span class=\"copyright\">(.*)</span>", Pattern.DOTALL);
+
+ public static final String PHPBB_SIGNATURE = "Powered by phpBB";
+
+ public boolean isServiceSupported(final CharSequence seq) {
+ Matcher m = PAT_PHPBB_SIGNATURE.matcher(seq);
+ if (m.find()) {
+ String copyright = m.group(1);
+ copyright = StringUtil.stripHTMLTrim(copyright);
+ return copyright.contains(PHPBB_SIGNATURE);
+ }
+ return false;
+ }
+
+ public static final Pattern PAT_FORUM_OR_CATEGORY = Pattern
+ .compile("(?:"
+ + "<span class=\"forumlink\"> <a href=\"viewforum.php\\?f=([0-9]+)(?:.*)\" class=\"forumlink\">(.*)</a><br />"
+ + "(?:\\s*)</span> <span class=\"genmed\">(?s)(.*?)</span>"
+ + ")|(?:"
+ + "<a href=\"index.php\\?c=([0-9]+)(?:.*)\" class=\"cattitle\">(.*)</a>"
+ + ")");
+
+ /**
+ * Parses forum HTML output into a list of forums.
+ */
+ public Map<ID, Forum> parseForums(final CharSequence seq) {
+ Map<ID, Forum> forums = new LinkedHashMap<ID, Forum>();
+ Matcher matcher = PAT_FORUM_OR_CATEGORY.matcher(seq);
+ Category lastCat = null;
+ while (matcher.find()) {
+ // Matched forum
+ if (matcher.group(2) != null) {
+ String name = StringUtil.stripHTMLTrim(matcher.group(2));
+ String desc = StringUtil.stripHTMLTrim(matcher.group(3));
+ if (StringUtil.notEmptyStr(name)) {
+ ForumFactory ff = new ForumFactory();
+ String idStr = matcher.group(1);
+ ID id = null;
+ try {
+ id = ff.createBBObjectId(namespace, baseURL, idStr);
+ } catch (IDCreateException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Forum forum = (Forum) ff.createBBObject(id, name, null);
+ forum.setDescription(desc);
+ if (lastCat != null) {
+ lastCat.addSubForum(forum);
+ forum.setParent(lastCat);
+ }
+ forums.put(id, forum);
+ }
+ }
+ // Matched category
+ if (matcher.group(5) != null) {
+ String name = StringUtil.stripHTMLTrim(matcher.group(5));
+ if (StringUtil.notEmptyStr(name)) {
+ CategoryFactory cf = new CategoryFactory();
+ String idStr = matcher.group(4);
+ ID id = null;
+ try {
+ id = cf.createBBObjectId(namespace, baseURL, idStr);
+ } catch (NumberFormatException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IDCreateException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ lastCat = (Category) cf.createBBObject(id, name, null);
+ forums.put(id, lastCat);
+ }
+ }
+ }
+ return forums;
+ }
+
+ @Override
+ public IBBObjectFactory getThreadFactory() {
+ return new ThreadFactory();
+ }
+
+ @Override
+ public IPatternDescriptor getThreadPattern() {
+ return DefaultPatternDescriptor
+ .defaultCustom(
+ Pattern
+ .compile(
+ "<a href=\"viewtopic.php\\?t=([0-9]+)(?:.*?)\" class=\"topictitle\">(.*)</a>(?:.*?)<span class=\"name\">(.+?)</span>",
+ Pattern.DOTALL), new String[] { "id",
+ "name", "authorInfo" });
+ }
+
+ @Override
+ public IBBObjectFactory getMemberFactory() {
+ return new MemberFactory();
+ }
+
+ public Pattern getMemberNamePattern() {
+ return Pattern.compile("Viewing profile :: (.*?)</th>");
+ }
+
+ @Override
+ public IPatternDescriptor getAuthorInfoMemberPattern() {
+ return DefaultPatternDescriptor
+ .defaultIdAndName(Pattern
+ .compile("<a href=\"profile.php\\?mode=viewprofile&amp;u=([0-9]+?)\">(.*?)</a>"));
+ }
+
+ @Override
+ public IBBObjectFactory getGuestFactory() {
+ return new GuestFactory();
+ }
+
+ /*
+ *
+ * <table class="forumline" width="100%" cellspacing="1" cellpadding="4"
+ * border="0"> <tr> <th class="thHead" height="25"><b>Information</b></th>
+ *
+ * </tr> <tr> <td class="row1"><table width="100%" cellspacing="0"
+ * cellpadding="1" border="0"> <tr> <td>&nbsp;</td> </tr> <tr>
+ * <td align="center"><span class="gen">The topic or post you requested
+ * does not exist</span></td>
+ *
+ * </tr> <tr> <td>&nbsp;</td> </tr> </table></td> </tr> </table>
+ */
+ public static final Pattern PAT_MSG_INFORMATION = Pattern
+ .compile(
+ "<table class=\"forumline\"(?:.*?)"
+ + "<th class=\"thHead\"(?:.*?)><b>Information</b></th>(?:.*?)"
+ + "<td align=\"center\"><span class=\"gen\">(.*?)</span></td>",
+ Pattern.DOTALL);
+
+ public String parseInformationMessage(CharSequence seq) {
+ String msg = null;
+ Matcher m = PAT_MSG_INFORMATION.matcher(seq);
+ if (m.find()) {
+ msg = "PHPBB: " + m.group(1);
+ }
+ return msg;
+ }
+
+ private BBException createPHPBBException(String msg, CharSequence seq) {
+ String phpBBmsg = parseInformationMessage(seq);
+ if (phpBBmsg != null) {
+ return new BBException(msg, new PHPBBException(phpBBmsg));
+ } else {
+ return new BBException(msg);
+ }
+ }
+
+ public static final Pattern PAT_THEAD_ATTRS = Pattern
+ // .compile("<title>(?:.*?) :: View topic - (.*?)</title>");
+ .compile("<a class=\"maintitle\" href=\"viewtopic.php\\?t=([0-9]+)(?:.*?)\">(.*?)</a>");
+
+ public static final Pattern PAT_THEAD_ATTRS_FORUM = Pattern
+ .compile("<link rel=\"up\" href=\"viewforum.php\\?f=([0-9]+?)\" title=\"(.*?)\" />");
+
+ public static final IPatternDescriptor PD_THREAD_ATTRS = DefaultPatternDescriptor
+ .defaultIdAndName(PAT_THEAD_ATTRS);
+
+ public static final IPatternDescriptor PD_THREAD_ATTRS_FORUM = DefaultPatternDescriptor
+ .defaultIdAndName(PAT_THEAD_ATTRS_FORUM);
+
+ public Thread parseThreadPageForThreadAttributes(CharSequence seq)
+ throws BBException {
+ Thread t = (Thread) genericParser.parseSingleIdName(PD_THREAD_ATTRS,
+ seq, new ThreadFactory());
+ if (t != null) {
+ Forum f = (Forum) genericParser.parseSingleIdName(
+ PD_THREAD_ATTRS_FORUM, seq, new ForumFactory());
+ t.forum = f;
+ return t;
+ } else {
+ throw createPHPBBException("Failed to parse the thread.", seq);
+ }
+ }
+
+ public static final Pattern PAT_MSG_TIMESTAMP = Pattern
+ .compile("Posted: (.*?)<span class=\"gen\">&nbsp;</span>");
+
+ public static final Pattern PAT_MSG = Pattern
+ .compile(
+ "<tr>(?:.*?)<td width=\"150\" align=\"left\" valign=\"top\" class=\"row(?:[12]{1})\"><span class=\"name\">(.*?)<script language=\"JavaScript\"",
+ Pattern.DOTALL);
+
+ public static final Pattern PAT_MSG_USERID = Pattern
+ .compile("profile.php\\?mode=viewprofile&amp;u=([0-9]+)");
+
+ public static final Pattern PAT_MSG_POSTID_USERNAME = Pattern
+ .compile("<a name=\"([0-9]+)\"></a><b>(.*?)</b></span>");
+
+ public static final Pattern PAT_MSG_TITLE = Pattern
+ .compile("Post subject: (.*?)</span>");
+
+ // <td colspan="2"><span class="postbody">test</span><span
+ // class="gensmall"></span></td>
+ public static final Pattern PAT_MSG_MESSAGE = Pattern
+ .compile(
+ "<td colspan=\"2\"><span class=\"postbody\">(.*?)</span><span class=\"gensmall\"></span></td>",
+ Pattern.DOTALL);
+
+ public String parseMessageId(String msgContent) {
+ Matcher matcher = PAT_MSG_POSTID_USERNAME.matcher(msgContent);
+ if (matcher.find()) {
+ return new String(matcher.group(1));
+ }
+ return null;
+ }
+
+ public void parseMessage(final CharSequence seq) {
+ /*
+ * String username = null; Matcher matcher; // Match date
+ * //message.setTime(parseTimestamp(str)); // Match user id and name
+ * matcher = PAT_MSG_POSTID_USERNAME.matcher(seq); if (matcher.find()) {
+ * username = StringUtil.simpleStripHTML(matcher.group(2));
+ * message.setId(matcher.group(1)); } matcher =
+ * PAT_MSG_USERID.matcher(str); if (matcher.find()) {
+ * message.setAuthor(app.userFor(matcher.group(1), username)); } else {
+ * message.setAuthor(app.userFor(null, username)); } // Match title
+ * matcher = PAT_MSG_TITLE.matcher(seq); if (matcher.find()) {
+ * message.setTitle(matcher.group(1)); } // Match message matcher =
+ * PAT_MSG_MESSAGE.matcher(seq); if (matcher.find()) {
+ * message.setMessage(StringUtil.stripHTMLFullTrim(matcher.group(1))); }
+ */
+ }
+
+ public ThreadMessage parseRequestedMessage(final ThreadMessageID id,
+ final CharSequence seq) throws BBException {
+ ThreadMessageFactory tmf = new ThreadMessageFactory();
+ // lastRead = -1 the one we want
+ ThreadMessageID lastReadId = null;
+ try {
+ lastReadId = (ThreadMessageID) tmf.createBBObjectId(namespace,
+ baseURL, String.valueOf(id.getLongValue() - 1));
+ } catch (IDCreateException e) {
+ e.printStackTrace();
+ }
+ List<ThreadMessage> msgs = parseMessages2(seq, lastReadId, true);
+ if (msgs.size() > 0) {
+ return msgs.get(0);
+ }
+ return null;
+ }
+
+ public List<ThreadMessage> parseMessages2(final CharSequence seq,
+ final ThreadMessageID lastReadId, boolean desc) throws BBException {
+ Matcher m;
+ ThreadMessage msg;
+ List<ThreadMessage> messages = new ArrayList<ThreadMessage>();
+ m = PAT_MSG.matcher(seq);
+ while (m.find()) {
+ String msgSrc = m.group(1);
+ msg = parseMessage2(msgSrc, lastReadId);
+ if (msg != null) {
+ if (desc) {
+ messages.add(0, msg);
+ } else {
+ messages.add(msg);
+ }
+ }
+ }
+ return messages;
+ }
+
+ @Override
+ public Long parseTimestamp(CharSequence seq) {
+ Long l = null;
+ final Locale locale = Locale.ENGLISH;
+ final String dateFormat = "EEE MMM d, yyyy";
+ final String timeFormat = "h:mm aa";
+ final String dateTimeSeparator = " ";
+ final DateFormat fmtTimestamp = new SimpleDateFormat(dateFormat
+ + dateTimeSeparator + timeFormat, locale);
+ final DateFormat fmtTime = new SimpleDateFormat(timeFormat, locale);
+ String timestamp = new StringBuilder(seq).toString();
+ /*
+ * timestamp = timestamp.replaceAll("1st", "1"); timestamp =
+ * timestamp.replaceAll("2nd", "2"); timestamp =
+ * timestamp.replaceAll("3rd", "3"); timestamp =
+ * timestamp.replaceAll("th", "");
+ */
+ if (timestamp.startsWith("Today") || timestamp.startsWith("Yesterday")) {
+ String[] s = timestamp.split(dateTimeSeparator);
+ try {
+ Calendar now = Calendar
+ .getInstance(/* fmtTime.getTimeZone() */);
+ if ("Yesterday".equals(s[0])) {
+ now.add(Calendar.DATE, -1);
+ }
+
+ Date d = fmtTime.parse(s[1]);
+ Calendar then = Calendar.getInstance(fmtTime.getTimeZone());
+ then.setTime(d);
+ then.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now
+ .get(Calendar.DATE));
+ l = new Long(then.getTimeInMillis());
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ } else {
+ try {
+ l = new Long(fmtTimestamp.parse(timestamp).getTime());
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ }
+ return l;
+ }
+
+ private ThreadMessage parseMessage2(final CharSequence seq,
+ final ThreadMessageID lastReadId) {
+ ThreadMessage msg = null;
+ Matcher m;
+ m = PAT_MSG_POSTID_USERNAME.matcher(seq);
+ if (m.find()) {
+ ThreadMessageFactory tmf = new ThreadMessageFactory();
+ String idStr = m.group(1);
+ ThreadMessageID id = null;
+ try {
+ id = (ThreadMessageID) tmf.createBBObjectId(namespace, baseURL,
+ idStr);
+ } catch (IDCreateException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ if (lastReadId == null
+ || id.getLongValue() > lastReadId.getLongValue()) {
+ 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();
+ String message = StringUtil.stripHTMLFullTrim(m.group(1));
+ msg.message = message;
+ m = PAT_MEMBER_ID_FROM_LINK.matcher(seq);
+ if (m.find()) {
+ MemberFactory mf = new MemberFactory();
+ idStr = m.group(1);
+ ID id2 = null;
+ try {
+ id2 = mf.createBBObjectId(namespace, baseURL, idStr);
+ } catch (NumberFormatException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IDCreateException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ msg.author = new Member(id2, uname);
+ } else {
+ GuestFactory gf = new GuestFactory();
+ ID id2 = null;
+ try {
+ id2 = gf.createBBObjectId(namespace, baseURL, null);
+ } catch (IDCreateException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ msg.author = new Member(id2, uname);
+ }
+ }
+ }
+ return msg;
+ }
+
+ public Map<ID, ThreadMessage> parseMessages(final CharSequence seq,
+ final boolean newOnly) throws BBException {
+ Matcher matcher;
+ String title;
+ ThreadMessage msg;
+ Map<ID, ThreadMessage> messages = new HashMap<ID, ThreadMessage>();
+ matcher = PAT_MSG.matcher(seq);
+ boolean anyFound = false;
+ while (matcher.find()) {
+ anyFound = true;
+ title = StringUtil.stripHTMLTrim(matcher.group(3));
+ if (StringUtil.notEmptyStr(title)) {
+ ThreadMessageFactory tmf = new ThreadMessageFactory();
+ String idStr = matcher.group(1);
+ ID id = null;
+ try {
+ id = tmf.createBBObjectId(namespace, baseURL, idStr);
+ } catch (NumberFormatException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IDCreateException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ msg = (ThreadMessage) tmf.createBBObject(id, title, null);
+ messages.put(id, msg);
+ }
+ }
+ if (!anyFound) {
+ throw createPHPBBException("No messages found!", seq);
+ }
+ return messages;
+ }
+
+ public static final Pattern PAT_PAGES = Pattern
+ .compile("<span class=\"nav\">Page <b>([0-9]+)</b> of <b>([0-9]+)</b></span>");
+
+ public int parseNextPage(CharSequence seq) {
+ Matcher m = PAT_PAGES.matcher(seq);
+ int next = -1;
+ if (m.find()) {
+ int current = Integer.parseInt(m.group(1));
+ int last = Integer.parseInt(m.group(2));
+ if (current < last) {
+ next = current + 1;
+ }
+ }
+ return next;
+ }
+
+ public int parsePrevPage(CharSequence seq) {
+ Matcher m = PAT_PAGES.matcher(seq);
+ int prev = -1;
+ if (m.find()) {
+ int current = Integer.parseInt(m.group(1));
+ if (current > 1) {
+ prev = current - 1;
+ }
+ }
+ return prev;
+ }
+
+ /*
+ * <tr> <td class="row1" width="20%"><span class="gen">Group name:</span></td>
+ * <td class="row2"><span class="gen"><b>Zerobot</b></span></td>
+ *
+ * </tr> <tr> <td class="row1" width="20%"><span class="gen">Group
+ * description:</span></td> <td class="row2"><span class="gen">Zerobot
+ * identities</span></td> </tr>
+ */
+ public static final Pattern PAT_GROUP = Pattern
+ .compile(
+ "<form action=\"groupcp.php\\?g=([0-9]+?)\" method=\"post\">"
+ + "(?:.*?)<tr>"
+ + "(?:.*?)<td class=\"row1\"(?:.*?)><span class=\"gen\">Group name:</span></td>"
+ + "(?:.*?)<td class=\"row2\"(?:.*?)><span class=\"gen\">(.*?)</span></td>"
+ + "(?:.*?)</tr>"
+ + "(?:.*?)<tr>"
+ + "(?:.*?)<td class=\"row1\"(?:.*?)><span class=\"gen\">Group description:</span></td>"
+ + "(?:.*?)<td class=\"row2\"(?:.*?)><span class=\"gen\">(.*?)</span></td>"
+ + "(?:.*?)</tr>" + "(?:.*?)</form>", Pattern.DOTALL);
+
+ public MemberGroup parseMemberGroup(CharSequence seq) {
+ Matcher m = PAT_GROUP.matcher(seq);
+ if (m.find()) {
+ MemberGroupFactory mgf = new MemberGroupFactory();
+ String idStr = m.group(1);
+ String name = StringUtil.stripHTMLTrim(m.group(2));
+ String desc = StringUtil.stripHTMLTrim(m.group(3));
+ ID id = null;
+ try {
+ id = mgf.createBBObjectId(namespace, baseURL, idStr);
+ } catch (IDCreateException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ MemberGroup grp = (MemberGroup) mgf.createBBObject(id, name, null);
+ grp.setDescription(desc);
+ return grp;
+ }
+ return null;
+ }
+
+ /*
+ * <select name="g"><option value="7">Unit Test Group</option><option
+ * value="4">Zerobot</option></select> TODO this didn't work for several
+ * groups, so I split into two patterns
+ */
+ public static final Pattern PAT_GROUPS = Pattern
+ .compile("<select name=\"g\">"
+ + "(?:<option value=\"([0-9]+?)\">(.*?)</option>?)"
+ + "</select>");
+
+ public static final Pattern PAT_GROUPS_GROUP = Pattern
+ .compile("<option value=\"([0-9]+?)\">(.*?)</option>");
+
+ @Override
+ public IBBObjectFactory getMemberGroupFactory() {
+ return new MemberGroupFactory();
+ }
+
+ public Pattern getMemberGroupContainerPattern() {
+ return Pattern.compile("<select name=\"g\">"
+ + "(?:<option value=\"([0-9]+?)\">(.*?)</option>?)"
+ + "</select>");
+ }
+
+ public IPatternDescriptor getMemberGroupPattern() {
+ return DefaultPatternDescriptor.defaultIdAndName(Pattern
+ .compile("<option value=\"([0-9]+?)\">(.*?)</option>"));
+ }
+
+ @Deprecated
+ private static final Pattern PAT_MEMBER_ID_FROM_LINK = Pattern
+ .compile("<a href=\"profile.php\\?mode=viewprofile&amp;u=([0-9]+?)\">");
+
+ public IPatternDescriptor getMemberPattern() {
+ return DefaultPatternDescriptor
+ .defaultIdAndName(Pattern
+ .compile("<a href=\"profile.php\\?mode=viewprofile&amp;u=([0-9]+?)\" class=\"gen\">(.*?)</a>"));
+ }
+
+ private static final Pattern PAT_TITLE = Pattern
+ .compile("<title>(.*?)</title>");
+
+ public String parseTitle(CharSequence seq) {
+ Matcher m = PAT_TITLE.matcher(seq);
+ if (m.find()) {
+ String title = new String(m.group(1));
+ return title;
+ }
+ return null;
+ }
+
+ @Override
+ public void throwException(final String msg, final CharSequence seq)
+ throws BBException {
+ throw createPHPBBException(msg, seq);
+ }
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBPlugin.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBPlugin.java
new file mode 100644
index 000000000..705ea4c1f
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPBBPlugin.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class PHPBBPlugin extends Plugin {
+
+ public static final String NAMESPACE_IDENTIFIER = "ecf.phpbb";
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.ecf.provider.phpbb";
+
+ // The shared instance
+ private static PHPBBPlugin plugin;
+
+ /**
+ * The constructor
+ */
+ public PHPBBPlugin() {
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static PHPBBPlugin getDefault() {
+ return plugin;
+ }
+
+ public static String getNamespaceIdentifier() {
+ return NAMESPACE_IDENTIFIER;
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPUtil.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPUtil.java
new file mode 100644
index 000000000..a7d35bccc
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/PHPUtil.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Util class for de-serializing objects serialized in PHP.
+ *
+ * @author Erkki
+ */
+public class PHPUtil {
+ /**
+ * Matches an array.
+ */
+ private static final Pattern PHP_STRING_ARRAY = Pattern
+ .compile("a:(?:[0-9]+):\\{(.*)\\}");
+
+ /**
+ * Matches a string.
+ */
+ private static final Pattern PHP_STRING = Pattern
+ .compile("s:(?:[0-9]+):\"(.*?)\"");
+
+ /**
+ * Deserializes a PHP array that has string key and value pairs as a HashMap
+ * or null if it was not an array.
+ *
+ * @param serializedArray
+ * the character sequence that contains the serialized array
+ * @return the deserialized array as a HashMap or null
+ */
+ public static Map<String, String> deserializeStringArray(CharSequence serializedArray) {
+ Matcher m = PHP_STRING_ARRAY.matcher(serializedArray);
+ if (m.matches()) {
+ Map<String, String> map = new HashMap<String, String>();
+ Matcher strMatcher = PHP_STRING.matcher(m.group(1));
+ String key = null;
+ while (strMatcher.find()) {
+ if (key == null) {
+ key = strMatcher.group(1);
+ } else {
+ map.put(key, strMatcher.group(1));
+ key = null;
+ }
+ }
+ return map;
+ } else {
+ return null;
+ }
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Thread.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Thread.java
new file mode 100644
index 000000000..5c635f481
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/Thread.java
@@ -0,0 +1,230 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.httpclient.NameValuePair;
+import org.eclipse.ecf.bulletinboard.BBException;
+import org.eclipse.ecf.bulletinboard.IForum;
+import org.eclipse.ecf.bulletinboard.IMember;
+import org.eclipse.ecf.bulletinboard.IPoll;
+import org.eclipse.ecf.bulletinboard.IThread;
+import org.eclipse.ecf.bulletinboard.IThreadMessage;
+import org.eclipse.ecf.bulletinboard.IllegalWriteException;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.internal.bulletinboard.commons.AbstractBulletinBoard;
+import org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest;
+import org.eclipse.ecf.internal.provider.phpbb.identity.ThreadID;
+import org.eclipse.ecf.internal.provider.phpbb.identity.ThreadMessageID;
+
+public class Thread extends PHPBBObject implements IThread {
+ // private static final Logger log = Logger.getLogger(Thread.class);
+
+ private static final String E_READ_ONLY = "This thread is read only.";
+
+ private ThreadID id;
+
+ protected Forum forum;
+
+ private ThreadMessage prePostMessage;
+
+ private IMember author;
+
+ public ThreadMessageID lastReadMessageId;
+
+ public Thread() {
+ super(null, READ_WRITE);
+ this.prePostMessage = new ThreadMessage();
+ prePostMessage.setThread(this);
+ }
+
+ public Thread(ThreadID id, String name) {
+ super(name, READ_WRITE);
+ this.id = id;
+ }
+
+ public IPoll getPoll() {
+ return null;
+ }
+
+ public IForum getForum() {
+ return forum;
+ }
+
+ public List<IThreadMessage> getMessages() throws BBException {
+ // TODO Auto-generated method stub
+ return 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;
+ }
+
+ public List<IThreadMessage> getNewMessages(ID lastReadId)
+ throws BBException {
+ if (lastReadId != null) {
+ lastReadMessageId = (ThreadMessageID) lastReadId;
+ }
+ return getNewMessages();
+ }
+
+ public ID getID() {
+ return id;
+ }
+
+ public int getType() {
+ return 0;
+ }
+
+ 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;
+ }
+
+ public IThreadMessage createReplyMessage(IThreadMessage replyTo)
+ throws IllegalWriteException {
+ ThreadMessage msg = (ThreadMessage) createReplyMessage();
+ msg.setReplyTo(replyTo);
+ return msg;
+ }
+
+ 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("disable_smilies",
+ // "on"),
+ // checkbox : disabled new NameValuePair("disable_bbcode",
+ // "on"),
+ // 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;
+ }
+
+ public int getSubscriptionStatus() {
+ return -1;
+ }
+
+ public boolean updateSubscription(int newSubscriptionStatus)
+ throws BBException {
+ return false;
+ }
+
+ public IThreadMessage getPrePostMessage() throws IllegalWriteException {
+ return prePostMessage;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Thread) {
+ Thread grp = (Thread) obj;
+ return id.equals(grp.id);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+
+ public IMember getAuthor() {
+ return author;
+ }
+
+ protected void setAuthor(IMember author) {
+ this.author = author;
+ }
+
+ public int getNumberOfMessages() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public Date getTimePosted() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Date getTimeUpdated() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadBrowser2.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadBrowser2.java
new file mode 100644
index 000000000..5d9f7953d
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadBrowser2.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.httpclient.NameValuePair;
+import org.eclipse.ecf.bulletinboard.BBException;
+import org.eclipse.ecf.bulletinboard.IThreadMessage;
+import org.eclipse.ecf.internal.bulletinboard.commons.AbstractBulletinBoard;
+import org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest;
+import org.eclipse.ecf.internal.bulletinboard.commons.webapp.WebRequest;
+import org.eclipse.ecf.internal.provider.phpbb.identity.ThreadID;
+
+public class ThreadBrowser2 {
+ Thread thread;
+
+ private AbstractBulletinBoard bb;
+
+ public ThreadBrowser2(AbstractBulletinBoard bb, Thread thread) {
+ this.bb = bb;
+ this.thread = thread;
+ }
+
+ private static final int STARTPAGE = 1;
+
+ private static final int NONE = -1;
+
+ public List<IThreadMessage> fetchNewMessages() throws BBException {
+ List<IThreadMessage> messages = new ArrayList<IThreadMessage>();
+ try {
+ int nextPage = STARTPAGE;
+ while (nextPage > NONE) {
+ WebRequest req = createRequest(nextPage);
+ req.execute();
+ String resp = req.getResponseBodyAsString();
+ req.releaseConnection();
+ // Add messages from page
+ messages.addAll(0, ((PHPBBParser) bb.getParser())
+ .parseMessages2(resp, thread.lastReadMessageId, true));
+ nextPage = ((PHPBBParser) bb.getParser()).parseNextPage(resp);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return messages;
+ }
+
+ public WebRequest createRequest(int page) {
+ /*
+ * String ppStr =
+ * bb.getActiveConfiguration().getProperties().getProperty(
+ * IBBConfiguration.P_POSTS_PER_PAGE);
+ */
+ int pp = 15;
+ int start = (page - 1) * pp;
+
+ WebRequest req = new PostRequest(bb.getHttpClient(), bb.getURL(),
+ "viewtopic.php?t=" + ((ThreadID) thread.getID()).getLongValue()
+ + "&start=" + start);
+ req.addParameter(new NameValuePair("postorder", "desc"));
+ req.addParameter(new NameValuePair("postdays", "0"));
+ req.addParameter(new NameValuePair("submit", "Go"));
+ return req;
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadFactory.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadFactory.java
new file mode 100644
index 000000000..a7b6020a4
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadFactory.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+
+import org.eclipse.ecf.bulletinboard.IBBObject;
+import org.eclipse.ecf.bulletinboard.IMember;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.internal.bulletinboard.commons.IBBObjectFactory;
+import org.eclipse.ecf.internal.provider.phpbb.identity.PHPBBNamespace;
+import org.eclipse.ecf.internal.provider.phpbb.identity.ThreadID;
+
+public class ThreadFactory implements IBBObjectFactory {
+ public ID createBBObjectId(Namespace namespace, String stringValue)
+ throws IDCreateException {
+ try {
+ return new ThreadID((PHPBBNamespace) namespace,
+ new URI(stringValue));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public ID createBBObjectId(Namespace namespace, URL baseURL,
+ String longValue) throws IDCreateException {
+ try {
+ return new ThreadID((PHPBBNamespace) namespace, baseURL, Long
+ .parseLong(longValue));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public IBBObject createBBObject(ID id, String name,
+ Map<String, Object> parameters) {
+ Thread t = new Thread((ThreadID) id, name);
+ if (parameters != null) {
+ if (parameters.containsKey("author")) {
+ t.setAuthor((IMember) parameters.get("author"));
+ }
+ }
+ return t;
+ }
+} \ No newline at end of file
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadMessage.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadMessage.java
new file mode 100644
index 000000000..870de4766
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadMessage.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.util.Date;
+
+import org.eclipse.ecf.bulletinboard.IMember;
+import org.eclipse.ecf.bulletinboard.IMessageBase;
+import org.eclipse.ecf.bulletinboard.IThread;
+import org.eclipse.ecf.bulletinboard.IThreadMessage;
+import org.eclipse.ecf.bulletinboard.IllegalWriteException;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.internal.provider.phpbb.identity.ThreadMessageID;
+
+public class ThreadMessage extends PHPBBObject implements IThreadMessage {
+ // private static final Logger log = Logger.getLogger(ThreadMessage.class);
+
+ private static final String E_READ_ONLY = "This message is read only.";
+
+ protected String message;
+
+ protected IMember author;
+
+ private ThreadMessageID id;
+
+ protected Thread thread;
+
+ protected Date timePosted;
+
+ public ThreadMessage(ThreadMessageID id, String name) {
+ super(name, READ_ONLY);
+ this.id = id;
+ }
+
+ public ThreadMessage() {
+ super(null, READ_WRITE);
+ }
+
+ public int getMessageNumber() {
+ // TODO Implement message numbering
+ return -1;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public IMember getFrom() {
+ return author;
+ }
+
+ public IMessageBase getReplyTo() {
+ // TODO Implement reply relationships
+ return null;
+ }
+
+ public void setReplyTo(IMessageBase message) throws IllegalWriteException {
+ // TODO Auto-generated method stub
+ }
+
+ public ID getID() {
+ return id;
+ }
+
+ public IThread getThread() {
+ return thread;
+ }
+
+ /**
+ * @param thread
+ * The thread to set.
+ */
+ protected void setThread(Thread thread) {
+ this.thread = thread;
+ }
+
+ public void setName(String name) throws IllegalWriteException {
+ if ((mode & READ_ONLY) == READ_ONLY) {
+ throw new IllegalWriteException(E_READ_ONLY);
+ }
+ this.name = name;
+ }
+
+ public void setMessage(String message) throws IllegalWriteException {
+ if ((mode & READ_ONLY) == READ_ONLY) {
+ throw new IllegalWriteException(E_READ_ONLY);
+ }
+ this.message = message;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof ThreadMessage) {
+ ThreadMessage grp = (ThreadMessage) obj;
+ return id.equals(grp.id);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+
+ public Date getTimePosted() {
+ return timePosted;
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadMessageFactory.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadMessageFactory.java
new file mode 100644
index 000000000..e3a3e9435
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/ThreadMessageFactory.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+
+import org.eclipse.ecf.bulletinboard.IBBObject;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.internal.bulletinboard.commons.IBBObjectFactory;
+import org.eclipse.ecf.internal.provider.phpbb.identity.PHPBBNamespace;
+import org.eclipse.ecf.internal.provider.phpbb.identity.ThreadMessageID;
+
+public class ThreadMessageFactory implements IBBObjectFactory {
+ public ID createBBObjectId(Namespace namespace, String stringValue)
+ throws IDCreateException {
+ try {
+ return new ThreadMessageID((PHPBBNamespace) namespace, new URI(
+ stringValue));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public ID createBBObjectId(Namespace namespace, URL baseURL, String longValue)
+ throws IDCreateException {
+ try {
+ return new ThreadMessageID((PHPBBNamespace) namespace, baseURL,
+ Long.parseLong(longValue));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException(e);
+ }
+ }
+
+ public IBBObject createBBObject(ID id, String name, Map<String, Object> parameters) {
+ return new ThreadMessage((ThreadMessageID) id, name);
+ }
+} \ No newline at end of file
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/container/ContainerInstantiator.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/container/ContainerInstantiator.java
new file mode 100644
index 000000000..0e5437c0e
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/container/ContainerInstantiator.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb.container;
+
+import org.eclipse.ecf.core.ContainerCreateException;
+import org.eclipse.ecf.core.ContainerTypeDescription;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.provider.IContainerInstantiator;
+
+public class ContainerInstantiator implements IContainerInstantiator {
+
+ public IContainer createInstance(ContainerTypeDescription description,
+ Object[] args) throws ContainerCreateException {
+ ID guid;
+ try {
+ guid = IDFactory.getDefault().createGUID();
+ } catch (IDCreateException e) {
+ throw new ContainerCreateException("Exception creating ID", e);
+ }
+ return new PHPBBContainer(guid);
+ }
+
+ public String[] getSupportedAdapterTypes(
+ ContainerTypeDescription description) {
+ return new String[] { "org.eclipse.ecf.bulletinboard.IBulletinBoardContainerAdapter" };
+ }
+
+ public Class[][] getSupportedParameterTypes(
+ ContainerTypeDescription description) {
+ return new Class[][] {};
+ }
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/container/PHPBBContainer.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/container/PHPBBContainer.java
new file mode 100644
index 000000000..38b3bfb38
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/container/PHPBBContainer.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb.container;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.internal.bulletinboard.commons.AbstractBBContainer;
+import org.eclipse.ecf.internal.provider.phpbb.PHPBBFactory;
+import org.eclipse.ecf.internal.provider.phpbb.PHPBBPlugin;
+
+public class PHPBBContainer extends AbstractBBContainer {
+
+ public PHPBBContainer(ID id) {
+ super(id);
+ this.bb = PHPBBFactory.getDefault().createPHPBB(this);
+ }
+
+ public Namespace getConnectNamespace() {
+ return IDFactory.getDefault().getNamespaceByName(
+ PHPBBPlugin.getNamespaceIdentifier());
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/CategoryID.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/CategoryID.java
new file mode 100644
index 000000000..b17293ef7
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/CategoryID.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb.identity;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.ecf.internal.bulletinboard.commons.util.IDUtil;
+
+public class CategoryID extends ForumID {
+
+ private static final long serialVersionUID = 6005970691318023633L;
+
+ public CategoryID(PHPBBNamespace namespace, URI uri)
+ throws URISyntaxException {
+ super(namespace, uri);
+ }
+
+ public CategoryID(PHPBBNamespace namespace, URL baseURL, long longValue)
+ throws URISyntaxException {
+ super(namespace, IDUtil.composeURI(baseURL, "index.php?c=" + longValue));
+ }
+
+ public long getLongValue() {
+ Matcher m = Pattern.compile("index.php\\?(?:.*?)c=([0-9]+)").matcher(
+ uri.toString());
+ if (m.find()) {
+ return Long.parseLong(m.group(1));
+ }
+ return -1;
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/ForumID.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/ForumID.java
new file mode 100644
index 000000000..402a93a24
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/ForumID.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb.identity;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.ecf.internal.bulletinboard.commons.util.IDUtil;
+
+public class ForumID extends PHPBBID {
+
+ private static final long serialVersionUID = 6005970691318023633L;
+
+ public ForumID(PHPBBNamespace namespace, URI uri) throws URISyntaxException {
+ super(namespace, uri);
+ }
+
+ public ForumID(PHPBBNamespace namespace, URL baseURL, long longValue)
+ throws URISyntaxException {
+ super(namespace, IDUtil.composeURI(baseURL, "viewforum.php?f="
+ + longValue));
+ }
+
+ public long getLongValue() {
+ Matcher m = Pattern.compile("viewforum.php\\?(?:.*?)f=([0-9]+)")
+ .matcher(uri.toString());
+ if (m.find()) {
+ return Long.parseLong(m.group(1));
+ }
+ return -1;
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/GuestID.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/GuestID.java
new file mode 100644
index 000000000..6f7752177
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/GuestID.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb.identity;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.eclipse.ecf.internal.bulletinboard.commons.util.IDUtil;
+
+public class GuestID extends PHPBBID {
+
+ private static final long serialVersionUID = 6005970691318023633L;
+
+ public GuestID(PHPBBNamespace namespace, URI uri) throws URISyntaxException {
+ super(namespace, uri);
+ }
+
+ public GuestID(PHPBBNamespace namespace, URL baseURL, String name)
+ throws URISyntaxException {
+ super(namespace, IDUtil.composeURI(baseURL,
+ "profile.php?mode=viewprofile&u=0#" + name));
+ }
+
+ public long getLongValue() {
+ return 0;
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/MemberGroupID.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/MemberGroupID.java
new file mode 100644
index 000000000..7fc17cf79
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/MemberGroupID.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb.identity;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.ecf.internal.bulletinboard.commons.util.IDUtil;
+
+public class MemberGroupID extends PHPBBID {
+
+ private static final long serialVersionUID = 6005970691318023633L;
+
+ public MemberGroupID(PHPBBNamespace namespace, URI uri)
+ throws URISyntaxException {
+ super(namespace, uri);
+ }
+
+ public MemberGroupID(PHPBBNamespace namespace, URL baseURL, long longValue)
+ throws URISyntaxException {
+ super(namespace, IDUtil.composeURI(baseURL, "groupcp.php?g="
+ + longValue));
+ }
+
+ public long getLongValue() {
+ Matcher m = Pattern.compile("groupcp.php\\?(?:.*?)g=([0-9]+)").matcher(
+ uri.toString());
+ if (m.find()) {
+ return Long.parseLong(m.group(1));
+ }
+ return -1;
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/MemberID.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/MemberID.java
new file mode 100644
index 000000000..974ccc62d
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/MemberID.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb.identity;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.ecf.internal.bulletinboard.commons.util.IDUtil;
+
+public class MemberID extends PHPBBID {
+
+ private static final long serialVersionUID = 6005970691318023633L;
+
+ public MemberID(PHPBBNamespace namespace, URI uri)
+ throws URISyntaxException {
+ super(namespace, uri);
+ }
+
+ public MemberID(PHPBBNamespace namespace, URL baseURL, long longValue)
+ throws URISyntaxException {
+ super(namespace, IDUtil.composeURI(baseURL,
+ "profile.php?mode=viewprofile&u=" + longValue));
+ }
+
+ public long getLongValue() {
+ Matcher m = Pattern.compile(
+ "profile.php\\?mode=viewprofile(?:.*?)u=([0-9]+)").matcher(
+ uri.toString());
+ if (m.find()) {
+ return Long.parseLong(m.group(1));
+ }
+ return -1;
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/PHPBBID.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/PHPBBID.java
new file mode 100644
index 000000000..f51edbab1
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/PHPBBID.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb.identity;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.eclipse.ecf.core.identity.BaseID;
+
+public class PHPBBID extends BaseID {
+
+ private static final long serialVersionUID = 7679927919437059784L;
+
+ protected URI uri;
+
+ public PHPBBID(PHPBBNamespace namespace, URI uri) throws URISyntaxException {
+ super(namespace);
+ this.uri = uri;
+ }
+
+ @Override
+ protected int namespaceCompareTo(BaseID o) {
+ if (!(o instanceof PHPBBID)) {
+ throw new ClassCastException("Uncomparable types.");
+ }
+ return uri.compareTo(((PHPBBID) o).uri);
+ }
+
+ @Override
+ protected boolean namespaceEquals(BaseID o) {
+ if (!(o instanceof PHPBBID)) {
+ return false;
+ }
+ return uri.equals(((PHPBBID) o).uri);
+ }
+
+ @Override
+ protected String namespaceGetName() {
+ return uri.toString();
+ }
+
+ @Override
+ protected int namespaceHashCode() {
+ return (int) uri.hashCode();
+ }
+
+ @Override
+ protected String namespaceToExternalForm() {
+ return uri.toString();
+ }
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/PHPBBNamespace.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/PHPBBNamespace.java
new file mode 100644
index 000000000..65e5fea36
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/PHPBBNamespace.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb.identity;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.internal.bulletinboard.commons.PatternFactoryPair;
+import org.eclipse.ecf.internal.provider.phpbb.CategoryFactory;
+import org.eclipse.ecf.internal.provider.phpbb.ForumFactory;
+import org.eclipse.ecf.internal.provider.phpbb.MemberFactory;
+import org.eclipse.ecf.internal.provider.phpbb.MemberGroupFactory;
+import org.eclipse.ecf.internal.provider.phpbb.ThreadFactory;
+import org.eclipse.ecf.internal.provider.phpbb.ThreadMessageFactory;
+
+public class PHPBBNamespace extends Namespace {
+
+ private static final long serialVersionUID = 5509243089799844682L;
+
+ private static final String PROTOCOL = "http://";
+
+ private static final PatternFactoryPair[] ID_FACTORIES = {
+ new PatternFactoryPair(Pattern
+ .compile("(.*?)viewforum.php\\?(?:.*?)f=([0-9]+)"),
+ new ForumFactory()),
+ new PatternFactoryPair(Pattern
+ .compile("(.*?)index.php\\?(?:.*?)c=([0-9]+)"),
+ new CategoryFactory()),
+ new PatternFactoryPair(Pattern
+ .compile("(.*?)viewtopic.php\\?(?:.*?)t=([0-9]+)"),
+ new ThreadFactory()),
+ new PatternFactoryPair(Pattern
+ .compile("(.*?)viewtopic.php\\?(?:.*?)p=([0-9]+)"),
+ new ThreadMessageFactory()),
+ new PatternFactoryPair(
+ Pattern
+ .compile("(.*?)profile.php\\?mode=viewprofile(?:.*?)u=([0-9]+)"),
+ new MemberFactory()),
+ new PatternFactoryPair(Pattern
+ .compile("(.*?)groupcp.php\\?(?:.*?)g=([0-9]+)"),
+ new MemberGroupFactory()) };
+
+ @Override
+ public ID createInstance(Object[] args)
+ throws IDCreateException {
+ try {
+ ID id = null;
+ for (PatternFactoryPair creator : ID_FACTORIES) {
+ Matcher m = creator.getPattern()
+ .matcher((CharSequence) args[0]);
+ if (m.find()) {
+ id = creator.getFactory().createBBObjectId(this,
+ new URL(m.group(1)), m.group(2));
+ return id;
+ }
+ }
+ return new PHPBBID(this, new URI((String) args[0]));
+ } catch (URISyntaxException e) {
+ throw new IDCreateException("phpBB ID creation exception", e);
+ } catch (NumberFormatException e) {
+ throw new IDCreateException("phpBB ID creation exception", e);
+ } catch (MalformedURLException e) {
+ throw new IDCreateException("phpBB ID creation exception", e);
+ }
+ }
+
+ @Override
+ public String getScheme() {
+ return PROTOCOL;
+ }
+
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/ThreadID.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/ThreadID.java
new file mode 100644
index 000000000..0a5da306d
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/ThreadID.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb.identity;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.ecf.internal.bulletinboard.commons.util.IDUtil;
+
+public class ThreadID extends PHPBBID {
+
+ private static final long serialVersionUID = 6005970691318023633L;
+
+ public ThreadID(PHPBBNamespace namespace, URI uri)
+ throws URISyntaxException {
+ super(namespace, uri);
+ }
+
+ public ThreadID(PHPBBNamespace namespace, URL baseURL, long longValue)
+ throws URISyntaxException {
+ super(namespace, IDUtil.composeURI(baseURL, "viewtopic.php?t="
+ + longValue));
+ }
+
+ public long getLongValue() {
+ Matcher m = Pattern.compile("viewtopic.php\\?(?:.*?)t=([0-9]+)")
+ .matcher(uri.toString());
+ if (m.find()) {
+ return Long.parseLong(m.group(1));
+ }
+ return -1;
+ }
+}
diff --git a/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/ThreadMessageID.java b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/ThreadMessageID.java
new file mode 100644
index 000000000..3b8e951c6
--- /dev/null
+++ b/incubation/bundles/org.eclipse.ecf.provider.phpbb/src/org/eclipse/ecf/internal/provider/phpbb/identity/ThreadMessageID.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Erkki Lindpere and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Erkki Lindpere - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.provider.phpbb.identity;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.ecf.internal.bulletinboard.commons.util.IDUtil;
+
+public class ThreadMessageID extends PHPBBID {
+
+ private static final long serialVersionUID = 6005970691318023633L;
+
+ public ThreadMessageID(PHPBBNamespace namespace, URI uri)
+ throws URISyntaxException {
+ super(namespace, uri);
+ }
+
+ public ThreadMessageID(PHPBBNamespace namespace, URL baseURL, long longValue)
+ throws URISyntaxException {
+ super(namespace, IDUtil.composeURI(baseURL, "viewtopic.php?p="
+ + longValue + "#" + longValue));
+ }
+
+ public long getLongValue() {
+ Matcher m = Pattern.compile("viewtopic.php\\?(?:.*?)p=([0-9]+)")
+ .matcher(uri.toString());
+ if (m.find()) {
+ return Long.parseLong(m.group(1));
+ }
+ return -1;
+ }
+}

Back to the top