├── .gitignore
├── INSTALL
├── LICENSE
├── README
├── changelog.html
├── lib
├── commons-collections-3.2.jar
├── commons-fileupload-1.2.1.jar
├── commons-io-1.4.jar
├── commons-lang-2.1.jar
├── commons-pool-1.3.jar
├── derby-10.2.2.0.jar
├── geronimo-jpa_3.0_spec-1.0.jar
├── geronimo-jta_1.1_spec-1.1.jar
├── google-collect-1.0-rc2.jar
├── mime-util-2.1.2.jar
├── openjpa-1.2.1.jar
├── serp-1.13.1.jar
└── servlet.jar
├── license.html
├── plugin.xml
├── readme.html
└── src
├── include
└── META-INF
│ ├── drop_tables.sql
│ └── persistence.xml
├── java
└── org
│ └── onesocialweb
│ └── openfire
│ ├── OswPlugin.java
│ ├── exception
│ ├── AccessDeniedException.java
│ ├── AuthenticationException.java
│ ├── InvalidActivityException.java
│ ├── InvalidNotificationException.java
│ ├── InvalidParameterValueException.java
│ ├── InvalidRelationException.java
│ └── MissingParameterException.java
│ ├── handler
│ ├── MessageEventInterceptor.java
│ ├── activity
│ │ ├── ActivityDeleteHandler.java
│ │ ├── ActivityPublishHandler.java
│ │ ├── ActivityQueryHandler.java
│ │ ├── ActivitySubscribeHandler.java
│ │ ├── ActivitySubscribersHandler.java
│ │ ├── ActivitySubscriptionsHandler.java
│ │ ├── ActivityUnsubscribeHandler.java
│ │ ├── IQSubscribeInterceptor.java
│ │ └── PEPActivityHandler.java
│ ├── inbox
│ │ ├── InboxQueryHandler.java
│ │ └── PEPInboxHandler.java
│ ├── pep
│ │ ├── IQPEPHandler.java
│ │ ├── PEPCommandHandler.java
│ │ └── PEPNodeHandler.java
│ ├── profile
│ │ ├── IQProfilePublishHandler.java
│ │ └── IQProfileQueryHandler.java
│ └── relation
│ │ ├── IQRelationQueryHandler.java
│ │ ├── IQRelationSetupHandler.java
│ │ └── IQRelationUpdateHandler.java
│ ├── manager
│ ├── AclManager.java
│ ├── ActivityManager.java
│ ├── InboxManager.java
│ ├── ProfileManager.java
│ └── RelationManager.java
│ ├── model
│ ├── ActivityMessage.java
│ ├── FileEntry.java
│ ├── PersistentActivityMessage.java
│ ├── PersistentFileEntry.java
│ ├── PersistentSubscription.java
│ ├── Subscription.java
│ ├── acl
│ │ ├── PersistentAclAction.java
│ │ ├── PersistentAclDomReader.java
│ │ ├── PersistentAclFactory.java
│ │ ├── PersistentAclRule.java
│ │ └── PersistentAclSubject.java
│ ├── activity
│ │ ├── PersistentActivityActor.java
│ │ ├── PersistentActivityDomReader.java
│ │ ├── PersistentActivityEntry.java
│ │ ├── PersistentActivityFactory.java
│ │ ├── PersistentActivityObject.java
│ │ └── PersistentActivityVerb.java
│ ├── atom
│ │ ├── PersistentAtomCategory.java
│ │ ├── PersistentAtomCommon.java
│ │ ├── PersistentAtomContent.java
│ │ ├── PersistentAtomDomReader.java
│ │ ├── PersistentAtomEntry.java
│ │ ├── PersistentAtomFactory.java
│ │ ├── PersistentAtomLink.java
│ │ ├── PersistentAtomPerson.java
│ │ ├── PersistentAtomReplyTo.java
│ │ └── PersistentAtomSource.java
│ ├── relation
│ │ ├── PersistentRelation.java
│ │ ├── PersistentRelationDomReader.java
│ │ └── PersistentRelationFactory.java
│ └── vcard4
│ │ ├── PersistentBirthdayField.java
│ │ ├── PersistentEmailField.java
│ │ ├── PersistentFullNameField.java
│ │ ├── PersistentGenderField.java
│ │ ├── PersistentNameField.java
│ │ ├── PersistentNoteField.java
│ │ ├── PersistentPhotoField.java
│ │ ├── PersistentProfile.java
│ │ ├── PersistentProfileFactory.java
│ │ ├── PersistentTelField.java
│ │ ├── PersistentTimeZoneField.java
│ │ ├── PersistentUrlField.java
│ │ └── PersistentVCard4DomReader.java
│ └── web
│ ├── FileServlet.java
│ ├── SessionValidator.java
│ └── UploadManager.java
└── web
├── WEB-INF
└── web-custom.xml
├── form.html
├── images
└── wallpaper.jpg
└── js
└── jquery
├── jquery-1.3.2.js
├── jquery-ui-1.7.2.custom.min.js
└── jquery.form.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .project
3 | lib/osw-model.jar
4 | bin/
5 |
--------------------------------------------------------------------------------
/INSTALL:
--------------------------------------------------------------------------------
1 | This section explains how to compile and deploy the onesocialweb plugin in an
2 | Ignite’s Openfire server installation.
3 |
4 | Last updated April 12th 2010.
5 |
6 | 1. Pre-requisites
7 | =================
8 |
9 | In order to build the code of the onesocialweb plugin you will need the following:
10 |
11 | - A JDK with Java 1.5 compliance or higher.
12 | - The Ant Java build tool.
13 | - The source code of the Openfire server, and to compile them. Please refer to: http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/source-build.html
14 | - A properly configured installation of the Openfire server in which to deploy the plugin. Please see: http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/install-guide.html
15 |
16 | 2. Getting the code from the repository
17 | =======================================
18 |
19 | The source code of the onesocialweb plugin can be obtained from the Github repository.
20 |
21 | git clone http://github.com/onesocialweb/openfire-plugin.git
22 |
23 | The high level folder should have the following structure:
24 |
25 | - /src
26 | - /lib
27 | - changelog.html
28 | - license.html
29 | - plugin.xml
30 | - readme.html
31 |
32 | 3. Compiling the plugin
33 | =======================
34 |
35 | Once the plugin source code is in your local system, place the high level
36 | folder into the /src/plugins folder of your Openfire source. You probably want
37 | to rename the directory or use a symbolic name with a different name
38 | (e.g. call it 'onesocialweb' instead of 'openfire-plugin')
39 |
40 | After that, you can invoke via command line the plugin task in the
41 | /build/build.xml file of the Openfire source
42 |
43 | ant plugin –Dplugin=onesocialweb (or whatever the name of the folder in /plugins)
44 |
45 | This will compile the onesocialweb plugin source and package it into a
46 | jar file. You will find it in the /target/openfire/plugins folder of your
47 | Openfire source.
48 |
49 |
50 | 4. Deploying
51 | ============
52 |
53 | Once the plugin jar file has been built you can now place it in the
54 | /plugins directory of your Openfire installation. The jar file will be
55 | extracted and initialized by Openfire.
56 |
57 | 5. Working with the code - Project dependencies
58 | ===============================================
59 |
60 | If you wish to dive into the code of the onesocialweb plugin, you can go
61 | ahead and create an Eclipse project and name it ‘openfire-plugin’, for example.
62 |
63 | Select the high-level plugin source code folder as the src folder of the
64 | Eclipse Project (Create Project from Existing Source).
65 |
66 | As you will find, the plugin requires classes in the Openfire server API,
67 | so you will also need to create an Eclipse project for the Openfire server
68 | and add it to the classpath (Buildpath) of your plugin project.
69 |
70 |
71 | 6. Remote Process and XML debugging
72 | ===================================
73 |
74 | Ignite’s Openfire source is shipped with the xmldebugger plugin, which you
75 | can also compile and deploy in your sever installation. This will print the
76 | XML traffic on your server to the server’s console, and it is a nice way for
77 | you to see how Profile and Activity querying and publishing in OneSocialWeb
78 | looks like in terms of XMPP stanzas.
79 |
80 | You can also setup remote debugging to the Openfire server and by placing
81 | breakpoints into the onesocialweb plugin code you could follow the execution
82 | of a bit of code that interests you. For this, start the Openfire sever in
83 | remote debug mode; for example:
84 |
85 | java -Xdebug -Xint -server -Xnoagent –
86 |
87 | Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 -jar ..\lib\startup.jar
88 |
89 | and create a Remote Java Application Debug Configuration in Eclipse,
90 | indicating the onesocialweb plugin project as the source, as well as the
91 | address and remote debugging port of your Openfire server.
92 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Source code for the Openfire plugin of the onesocialweb project.
2 | Released under an Apache 2.0 License (see LICENSE).
3 | Copyright 2010 Vodafone Group Services Limited.
4 |
5 | All documentation and tutorials available on http://onesocialweb.org
6 |
7 | Version 0.6.1 - Released September 28th 2010
8 |
--------------------------------------------------------------------------------
/changelog.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
49 | Openfire plugin for the Onesocialweb protocol extendsion. Released under an Apache 2.0 License.
50 | Copyright 2010 Vodafone Group Services Limited.
51 |
52 |
53 |
Installation
54 |
55 |
Copy the plugin jar archive into the plugins directory of your Openfire installation. The
56 | plugin will then be automatically deployed. To upgrade to a new version, copy the new archive
57 | over the existing file.
58 |
59 |
Configuration
60 |
61 | No configuration for now.
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/src/include/META-INF/drop_tables.sql:
--------------------------------------------------------------------------------
1 | Drop table AclAction;
2 | Drop table AclRule;
3 | Drop table AclRule_AclAction;
4 | Drop table AclRule_AclSubject;
5 | Drop table AclSubject;
6 | Drop table Activities;
7 | Drop table Activities_AclRule;
8 | Drop table Activities_ActivityVerb;
9 | Drop table Activities_AtomCategory;
10 | Drop table Activities_AtomContent;
11 | Drop table Activities_AtomLink;
12 | Drop table Activities_AtomPerson;
13 | Drop table Activities_AtomReplyTo;
14 | Drop table Activities_Objects;
15 | Drop table ActivityVerb;
16 | Drop table AtomCategory;
17 | Drop table AtomContent;
18 | Drop table AtomEntry;
19 | Drop table AtomEntry_AtomCategory;
20 | Drop table AtomEntry_AtomContent;
21 | Drop table AtomEntry_AtomLink;
22 | Drop table AtomEntry_AtomPerson;
23 | Drop table AtomEntry_AtomReplyTo;
24 | Drop table AtomLink;
25 | Drop table AtomPerson;
26 | Drop table AtomReplyTo;
27 | Drop table AtomSource;
28 | Drop table Messages;
29 | Drop table OPENJPA_SEQUENCE_TABLE;
30 | Drop table Objects;
31 | Drop table Objects_AtomCategory;
32 | Drop table Objects_AtomContent;
33 | Drop table Objects_AtomLink;
34 | Drop table Objects_AtomPerson;
35 | Drop table Objects_AtomReplyTo;
36 | Drop table PersistentFileEntry;
37 | Drop table Profile;
38 | Drop table Relation;
39 | Drop table Relation_AclRule;
40 | Drop table Subscriptions;
41 | Drop table BirthdayField;
42 | Drop table BirthdayField_AclRule;
43 | Drop table FullNameField;
44 | Drop table FullNameField_AclRule;
45 | Drop table GenderField;
46 | Drop table GenderField_AclRule;
47 | Drop table NoteField;
48 | Drop table NoteField_AclRule;
49 | Drop table PhotoField;
50 | Drop table PhotoField_AclRule;
51 | Drop table Profile_PhotoField;
52 |
--------------------------------------------------------------------------------
/src/include/META-INF/persistence.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | org.apache.openjpa.persistence.PersistenceProviderImpl
5 | org.onesocialweb.openfire.model.acl.PersistentAclRule
6 | org.onesocialweb.openfire.model.acl.PersistentAclAction
7 | org.onesocialweb.openfire.model.acl.PersistentAclSubject
8 | org.onesocialweb.openfire.model.activity.PersistentActivityEntry
9 | org.onesocialweb.openfire.model.activity.PersistentActivityObject
10 | org.onesocialweb.openfire.model.activity.PersistentActivityActor
11 | org.onesocialweb.openfire.model.activity.PersistentActivityVerb
12 | org.onesocialweb.openfire.model.atom.PersistentAtomCommon
13 | org.onesocialweb.openfire.model.atom.PersistentAtomCategory
14 | org.onesocialweb.openfire.model.atom.PersistentAtomContent
15 | org.onesocialweb.openfire.model.atom.PersistentAtomEntry
16 | org.onesocialweb.openfire.model.atom.PersistentAtomLink
17 | org.onesocialweb.openfire.model.atom.PersistentAtomPerson
18 | org.onesocialweb.openfire.model.atom.PersistentAtomSource
19 | org.onesocialweb.openfire.model.atom.PersistentAtomReplyTo
20 | org.onesocialweb.openfire.model.relation.PersistentRelation
21 | org.onesocialweb.openfire.model.PersistentSubscription
22 | org.onesocialweb.openfire.model.PersistentFileEntry
23 | org.onesocialweb.openfire.model.PersistentActivityMessage
24 | org.onesocialweb.openfire.model.vcard4.PersistentBirthdayField
25 | org.onesocialweb.openfire.model.vcard4.PersistentFullNameField
26 | org.onesocialweb.openfire.model.vcard4.PersistentGenderField
27 | org.onesocialweb.openfire.model.vcard4.PersistentNoteField
28 | org.onesocialweb.openfire.model.vcard4.PersistentPhotoField
29 | org.onesocialweb.openfire.model.vcard4.PersistentNameField
30 | org.onesocialweb.openfire.model.vcard4.PersistentUrlField
31 | org.onesocialweb.openfire.model.vcard4.PersistentTelField
32 | org.onesocialweb.openfire.model.vcard4.PersistentTimeZoneField
33 | org.onesocialweb.openfire.model.vcard4.PersistentEmailField
34 | org.onesocialweb.openfire.model.vcard4.PersistentProfile
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/exception/AccessDeniedException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.exception;
18 |
19 | @SuppressWarnings("serial")
20 | public class AccessDeniedException extends Exception {
21 |
22 | public AccessDeniedException(String message) {
23 | super(message);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/exception/AuthenticationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.exception;
18 |
19 | @SuppressWarnings("serial")
20 | public class AuthenticationException extends Exception {
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/exception/InvalidActivityException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.exception;
18 |
19 | @SuppressWarnings("serial")
20 | public class InvalidActivityException extends Exception {
21 |
22 | public InvalidActivityException(String message) {
23 | super(message);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/exception/InvalidNotificationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.exception;
18 |
19 | @SuppressWarnings("serial")
20 | public class InvalidNotificationException extends Exception {
21 |
22 | public InvalidNotificationException(String message) {
23 | super(message);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/exception/InvalidParameterValueException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.exception;
18 |
19 | @SuppressWarnings("serial")
20 | public class InvalidParameterValueException extends Exception {
21 |
22 | private final String parameter;
23 |
24 | private final String value;
25 |
26 | public InvalidParameterValueException(String parameter, String value) {
27 | this.parameter = parameter;
28 | this.value = value;
29 | }
30 |
31 | public String getParameter() {
32 | return parameter;
33 | }
34 |
35 | public String getValue() {
36 | return value;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/exception/InvalidRelationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.exception;
18 |
19 | @SuppressWarnings("serial")
20 | public class InvalidRelationException extends Exception {
21 |
22 | public InvalidRelationException(String message) {
23 | super(message);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/exception/MissingParameterException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.exception;
18 |
19 | @SuppressWarnings("serial")
20 | public class MissingParameterException extends Exception {
21 |
22 | private final String parameter;
23 |
24 | public MissingParameterException(String parameter) {
25 | this.parameter = parameter;
26 | }
27 |
28 | public String getParameter() {
29 | return parameter;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/MessageEventInterceptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler;
18 |
19 | import java.util.HashSet;
20 | import java.util.Iterator;
21 | import java.util.List;
22 | import java.util.Set;
23 |
24 | import javax.activity.InvalidActivityException;
25 |
26 | import org.dom4j.Element;
27 | import org.jivesoftware.openfire.SessionManager;
28 | import org.jivesoftware.openfire.XMPPServer;
29 | import org.jivesoftware.openfire.interceptor.PacketInterceptor;
30 | import org.jivesoftware.openfire.interceptor.PacketRejectedException;
31 | import org.jivesoftware.openfire.session.ClientSession;
32 | import org.jivesoftware.openfire.session.Session;
33 | import org.jivesoftware.util.Log;
34 | import org.onesocialweb.model.activity.ActivityEntry;
35 | import org.onesocialweb.model.relation.Relation;
36 | import org.onesocialweb.openfire.exception.AccessDeniedException;
37 | import org.onesocialweb.openfire.exception.InvalidRelationException;
38 | import org.onesocialweb.openfire.handler.activity.PEPActivityHandler;
39 | import org.onesocialweb.openfire.manager.ActivityManager;
40 | import org.onesocialweb.openfire.manager.RelationManager;
41 | import org.onesocialweb.openfire.model.activity.PersistentActivityDomReader;
42 | import org.onesocialweb.openfire.model.relation.PersistentRelationDomReader;
43 | import org.onesocialweb.xml.dom.ActivityDomReader;
44 | import org.onesocialweb.xml.dom.RelationDomReader;
45 | import org.onesocialweb.xml.dom4j.ElementAdapter;
46 | import org.xmpp.packet.JID;
47 | import org.xmpp.packet.Message;
48 | import org.xmpp.packet.Packet;
49 |
50 | public class MessageEventInterceptor implements PacketInterceptor {
51 |
52 | private final XMPPServer server;
53 |
54 | public MessageEventInterceptor() {
55 | server = XMPPServer.getInstance();
56 | }
57 |
58 | @SuppressWarnings( { "deprecation", "unchecked" })
59 | public void interceptPacket(Packet packet, Session session,
60 | boolean incoming, boolean processed) throws PacketRejectedException {
61 |
62 | // We only care for incoming Messages has not yet been processed
63 | if (incoming && !processed && packet instanceof Message) {
64 |
65 | final Message message = (Message) packet;
66 | final JID fromJID = message.getFrom();
67 | final JID toJID = message.getTo();
68 |
69 | // We are only interested by message to bareJID (we don't touch the one sent to fullJID)
70 | if (!toJID.toBareJID().equalsIgnoreCase(toJID.toString())) {
71 | return;
72 | }
73 |
74 | // We only care for messaes to local users
75 | if (!server.isLocal(toJID)
76 | || !server.getUserManager().isRegisteredUser(toJID)) {
77 | return;
78 | }
79 |
80 | // We only bother about pubsub events
81 | Element eventElement = message.getChildElement("event",
82 | "http://jabber.org/protocol/pubsub#event");
83 | if (eventElement == null) {
84 | return;
85 | }
86 |
87 | // That contains items
88 | Element itemsElement = eventElement.element("items");
89 | if (itemsElement == null || itemsElement.attribute("node") == null)
90 | return;
91 |
92 | // Relating to the microblogging node
93 | if (itemsElement.attribute("node").getValue().equals(
94 | PEPActivityHandler.NODE)) {
95 |
96 |
97 | Log.debug("Processing an activity event from " + fromJID
98 | + " to " + toJID);
99 | final ActivityDomReader reader = new PersistentActivityDomReader();
100 | List items=(List) itemsElement.elements("item");
101 | if ((items!=null) && (items.size()!=0)){
102 | for (Element itemElement :items) {
103 | ActivityEntry activity = reader
104 | .readEntry(new ElementAdapter(itemElement
105 | .element("entry")));
106 | try {
107 |
108 | ActivityManager.getInstance().handleMessage(
109 | fromJID.toBareJID(), toJID.toBareJID(),
110 | activity);
111 |
112 | } catch (InvalidActivityException e) {
113 | throw new PacketRejectedException();
114 | } catch (AccessDeniedException e) {
115 | throw new PacketRejectedException();
116 | }
117 | }
118 | } else if (itemsElement.element("retract")!=null)
119 | {
120 | Element retractElement = itemsElement.element("retract");
121 | String activityId=reader.readActivityId(new ElementAdapter(retractElement));
122 | ActivityManager.getInstance().deleteMessage(activityId);
123 | }
124 | Set recipientFullJIDs = getFullJIDs(toJID
125 | .toBareJID());
126 | Iterator it = recipientFullJIDs.iterator();
127 | Message extendedMessage = message.createCopy();
128 | while (it.hasNext()) {
129 | String fullJid = it.next().toString();
130 | extendedMessage.setTo(fullJid);
131 | server.getMessageRouter().route(extendedMessage);
132 | }
133 | throw new PacketRejectedException();
134 | }
135 |
136 | // or a relation event
137 | else if (itemsElement.attribute("node").getValue().equals(
138 | RelationManager.NODE)) {
139 | final RelationDomReader reader = new PersistentRelationDomReader();
140 | for (Element itemElement : (List) itemsElement
141 | .elements("item")) {
142 | Relation relation = reader.readElement(new ElementAdapter(
143 | itemElement.element("relation")));
144 | try {
145 | RelationManager.getInstance().handleMessage(
146 | fromJID.toBareJID(), toJID.toBareJID(),
147 | relation);
148 | } catch (InvalidRelationException e) {
149 | throw new PacketRejectedException();
150 | }
151 | }
152 | }
153 |
154 | else return;
155 | }
156 | }
157 |
158 | /*
159 | * Returns a Set of the FullJids for all connected resources of a given
160 | * BareJid
161 | */
162 | private Set getFullJIDs(String jid) {
163 | JID recipientJID = new JID(jid);
164 | Set recipientFullJIDs = new HashSet();
165 | if (XMPPServer.getInstance().isLocal(recipientJID)) {
166 | if (recipientJID.getResource() == null) {
167 | for (ClientSession clientSession : SessionManager.getInstance()
168 | .getSessions(recipientJID.getNode())) {
169 | int prior = clientSession.getPresence().getPriority();
170 | if (prior >= 0) {
171 | recipientFullJIDs.add(clientSession.getAddress());
172 | }
173 | }
174 | }
175 | }
176 |
177 | return recipientFullJIDs;
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/activity/ActivityDeleteHandler.java:
--------------------------------------------------------------------------------
1 | package org.onesocialweb.openfire.handler.activity;
2 |
3 | import org.dom4j.Element;
4 | import org.jivesoftware.openfire.XMPPServer;
5 | import org.jivesoftware.openfire.auth.UnauthorizedException;
6 | import org.jivesoftware.openfire.user.UserManager;
7 | import org.jivesoftware.util.LocaleUtils;
8 | import org.jivesoftware.util.Log;
9 | import org.onesocialweb.openfire.handler.pep.PEPCommandHandler;
10 | import org.onesocialweb.openfire.manager.ActivityManager;
11 | import org.onesocialweb.openfire.model.activity.PersistentActivityDomReader;
12 | import org.onesocialweb.xml.dom.ActivityDomReader;
13 | import org.onesocialweb.xml.dom4j.ElementAdapter;
14 | import org.xmpp.packet.IQ;
15 | import org.xmpp.packet.JID;
16 | import org.xmpp.packet.PacketError;
17 |
18 | public class ActivityDeleteHandler extends PEPCommandHandler {
19 |
20 | public static final String COMMAND = "retract";
21 |
22 | private ActivityManager activityManager;
23 |
24 | private UserManager userManager;
25 |
26 | public ActivityDeleteHandler() {
27 | super("OneSocialWeb - Delete activity handler");
28 | }
29 |
30 | @Override
31 | public String getCommand() {
32 | return COMMAND;
33 | }
34 |
35 | @SuppressWarnings( { "deprecation", "unchecked" })
36 | @Override
37 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
38 |
39 | JID sender = packet.getFrom();
40 | JID target = packet.getTo();
41 | String id=packet.getID();
42 |
43 |
44 | // Process the request inside a try/catch so that unhandled exceptions
45 | // (oufofbounds etc...) can trigger a server error and we can send a
46 | // error result packet
47 |
48 | try {
49 |
50 | // A valid request is an IQ of type set,
51 | if (!packet.getType().equals(IQ.Type.set)) {
52 | IQ result = IQ.createResultIQ(packet);
53 | result.setChildElement(packet.getChildElement().createCopy());
54 | result.setError(PacketError.Condition.bad_request);
55 | return result;
56 | }
57 |
58 | // If a recipient is specified, it must be equal to the sender
59 | // bareJID
60 | if (target != null && !target.toString().equals(sender.toBareJID())) {
61 | IQ result = IQ.createResultIQ(packet);
62 | result.setChildElement(packet.getChildElement().createCopy());
63 | result.setError(PacketError.Condition.not_authorized);
64 | return result;
65 | }
66 |
67 | // Only a local user can delete an activity to his stream
68 | if (!userManager.isRegisteredUser(sender.getNode())) {
69 | IQ result = IQ.createResultIQ(packet);
70 | result.setChildElement(packet.getChildElement().createCopy());
71 | result.setError(PacketError.Condition.not_authorized);
72 | return result;
73 | }
74 |
75 | ActivityDomReader reader = new PersistentActivityDomReader();
76 | Element pubsubElement = packet.getChildElement();
77 | Element retractElement = pubsubElement.element("retract");
78 | Element item = (Element)retractElement.elements("item").get(0);
79 | String activityId=reader.readActivityId(new ElementAdapter(item));
80 |
81 | if ((activityId==null) || (activityId.length()==0)){
82 | IQ result = IQ.createResultIQ(packet);
83 | result.setChildElement(packet.getChildElement().createCopy());
84 | result.setError(PacketError.Condition.item_not_found);
85 | return result;
86 | }
87 |
88 | activityManager.deleteActivity(sender.toBareJID(), activityId);
89 |
90 | // Send a success result as specified in XEP-0060...
91 | IQ result = IQ.createResultIQ(packet);
92 | result.setFrom(target);
93 | result.setTo(sender);
94 | result.setID(id);
95 |
96 | return result;
97 |
98 | } catch (Exception e) {
99 | Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
100 | IQ result = IQ.createResultIQ(packet);
101 | result.setChildElement(packet.getChildElement().createCopy());
102 | result.setError(PacketError.Condition.internal_server_error);
103 | return result;
104 | }
105 |
106 | }
107 |
108 | @Override
109 | public void initialize(XMPPServer server) {
110 | super.initialize(server);
111 | userManager = server.getUserManager();
112 | activityManager = ActivityManager.getInstance();
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/activity/ActivityPublishHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.activity;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import org.dom4j.Element;
23 | import org.jivesoftware.openfire.XMPPServer;
24 | import org.jivesoftware.openfire.auth.UnauthorizedException;
25 | import org.jivesoftware.openfire.user.UserManager;
26 | import org.jivesoftware.openfire.user.UserNotFoundException;
27 | import org.jivesoftware.util.LocaleUtils;
28 | import org.jivesoftware.util.Log;
29 | import org.onesocialweb.model.activity.ActivityEntry;
30 | import org.onesocialweb.openfire.handler.pep.PEPCommandHandler;
31 | import org.onesocialweb.openfire.manager.ActivityManager;
32 | import org.onesocialweb.openfire.model.activity.PersistentActivityDomReader;
33 | import org.onesocialweb.xml.dom.ActivityDomReader;
34 | import org.onesocialweb.xml.dom4j.ElementAdapter;
35 | import org.xmpp.packet.IQ;
36 | import org.xmpp.packet.JID;
37 | import org.xmpp.packet.PacketError;
38 |
39 | public class ActivityPublishHandler extends PEPCommandHandler {
40 |
41 | public static final String COMMAND = "publish";
42 |
43 | private UserManager userManager;
44 |
45 | private ActivityManager activityManager;
46 |
47 | public ActivityPublishHandler() {
48 | super("OneSocialWeb - Publish activity handler");
49 | }
50 |
51 | @Override
52 | public String getCommand() {
53 | return COMMAND;
54 | }
55 |
56 | @SuppressWarnings( { "deprecation", "unchecked" })
57 | @Override
58 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
59 | final JID sender = packet.getFrom();
60 | final JID recipient = packet.getTo();
61 |
62 | // Process the request inside a try/catch so that unhandled exceptions
63 | // (oufofbounds etc...) can trigger a server error and we can send a
64 | // error result packet
65 | try {
66 |
67 | // A valid request is an IQ of type set,
68 | if (!packet.getType().equals(IQ.Type.set)) {
69 | IQ result = IQ.createResultIQ(packet);
70 | result.setChildElement(packet.getChildElement().createCopy());
71 | result.setError(PacketError.Condition.bad_request);
72 | return result;
73 | }
74 |
75 | // If a recipient is specified, it must be equal to the sender
76 | // bareJID
77 | if (recipient != null && !recipient.toString().equals(sender.toBareJID())) {
78 | IQ result = IQ.createResultIQ(packet);
79 | result.setChildElement(packet.getChildElement().createCopy());
80 | result.setError(PacketError.Condition.not_authorized);
81 | return result;
82 | }
83 |
84 | // Only a local user can publish an activity to his stream
85 | if (!userManager.isRegisteredUser(sender.getNode())) {
86 | IQ result = IQ.createResultIQ(packet);
87 | result.setChildElement(packet.getChildElement().createCopy());
88 | result.setError(PacketError.Condition.not_authorized);
89 | return result;
90 | }
91 |
92 | // A valid submit request must contain at least one entry
93 | Element pubsubElement = packet.getChildElement();
94 | Element publishElement = pubsubElement.element("publish");
95 | List items = publishElement.elements("item");
96 | if (items == null || items.size() == 0) {
97 | IQ result = IQ.createResultIQ(packet);
98 | result.setChildElement(packet.getChildElement().createCopy());
99 | result.setError(PacketError.Condition.bad_request);
100 | return result;
101 | }
102 |
103 | // Parse the activities
104 | ActivityDomReader reader = new PersistentActivityDomReader();
105 | List itemIds = new ArrayList(items.size());
106 | for (Element item : items) {
107 | Element entry = item.element("entry");
108 | if (entry != null) {
109 | ActivityEntry activity = reader.readEntry(new ElementAdapter(entry));
110 | Log.debug("ActivityPublishHandler received activity: " + activity);
111 | try {
112 | if ((activity.getId()!=null) && (activity.getId().length()!=0))
113 | activityManager.updateActivity(sender.toBareJID(), activity);
114 | else{
115 | activityManager.publishActivity(sender.toBareJID(), activity);
116 | itemIds.add(activity.getId());
117 | }
118 | } catch (UserNotFoundException e) {}
119 | }
120 | }
121 |
122 | // Send a success result
123 | IQ result = IQ.createResultIQ(packet);
124 | Element resultPubsubElement = result.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");
125 | Element resultPublishElement = resultPubsubElement.addElement("publish", "http://jabber.org/protocol/pubsub");
126 | resultPublishElement.addAttribute("node", PEPActivityHandler.NODE);
127 | for (String itemId : itemIds) {
128 | Element itemElement = resultPublishElement.addElement("item");
129 | itemElement.addAttribute("id", itemId);
130 | }
131 | return result;
132 |
133 | } catch (Exception e) {
134 | Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
135 | IQ result = IQ.createResultIQ(packet);
136 | result.setChildElement(packet.getChildElement().createCopy());
137 | result.setError(PacketError.Condition.internal_server_error);
138 | return result;
139 | }
140 | }
141 |
142 | @Override
143 | public void initialize(XMPPServer server) {
144 | super.initialize(server);
145 | userManager = server.getUserManager();
146 | activityManager = ActivityManager.getInstance();
147 | }
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/activity/ActivityQueryHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.onesocialweb.openfire.handler.activity;
19 |
20 | import java.util.List;
21 |
22 | import org.dom4j.dom.DOMDocument;
23 | import org.jivesoftware.openfire.XMPPServer;
24 | import org.jivesoftware.openfire.auth.UnauthorizedException;
25 | import org.jivesoftware.openfire.user.UserManager;
26 | import org.jivesoftware.util.LocaleUtils;
27 | import org.jivesoftware.util.Log;
28 | import org.onesocialweb.model.activity.ActivityEntry;
29 | import org.onesocialweb.openfire.handler.pep.PEPCommandHandler;
30 | import org.onesocialweb.openfire.manager.ActivityManager;
31 | import org.onesocialweb.xml.dom.ActivityDomWriter;
32 | import org.onesocialweb.xml.dom.imp.DefaultActivityDomWriter;
33 | import org.onesocialweb.xml.namespace.Atom;
34 | import org.w3c.dom.Element;
35 | import org.xmpp.packet.IQ;
36 | import org.xmpp.packet.JID;
37 | import org.xmpp.packet.PacketError;
38 |
39 | public class ActivityQueryHandler extends PEPCommandHandler {
40 |
41 | public static final String COMMAND = "items";
42 |
43 | private UserManager userManager;
44 |
45 | public ActivityQueryHandler() {
46 | super("OneSocialWeb - Query a user activities");
47 | }
48 |
49 | @Override
50 | public String getCommand() {
51 | return COMMAND;
52 | }
53 |
54 | @SuppressWarnings( { "deprecation" })
55 | @Override
56 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
57 |
58 | JID sender = packet.getFrom();
59 | JID target = packet.getTo();
60 |
61 | // Process the request inside a try/catch so that unhandled exceptions
62 | // (oufofbounds etc...) can trigger a server error and we can send a
63 | // error result packet
64 | try {
65 | // If no recipient, then the target is the sender
66 | if (target == null || target.getNode() == null) {
67 | target = packet.getFrom();
68 | }
69 |
70 | // A valid request is an IQ of type get, for a valid and local recipient
71 | if (!(packet.getType().equals(IQ.Type.get) && target != null && target.getNode() != null
72 | && userManager.isRegisteredUser(target.getNode()))) {
73 | IQ result = IQ.createResultIQ(packet);
74 | result.setChildElement(packet.getChildElement().createCopy());
75 | result.setError(PacketError.Condition.bad_request);
76 | return result;
77 | }
78 |
79 | // We fetch the activities of the target user
80 | List activities = ActivityManager.getInstance().getActivities(sender.toBareJID(), target.toBareJID());
81 |
82 | // Prepare the result packet
83 | ActivityDomWriter writer = new DefaultActivityDomWriter();
84 | DOMDocument domDocument = new DOMDocument();
85 | IQ result = IQ.createResultIQ(packet);
86 | org.dom4j.Element pubsubElement = result.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");
87 | org.dom4j.Element itemsElement = pubsubElement.addElement("items");
88 | itemsElement.addAttribute("node", PEPActivityHandler.NODE);
89 |
90 | for (ActivityEntry entry : activities) {
91 | Element entryElement = (Element) domDocument.appendChild(domDocument.createElementNS(Atom.NAMESPACE, Atom.ENTRY_ELEMENT));
92 | writer.write(entry, entryElement);
93 | domDocument.removeChild(entryElement);
94 | org.dom4j.Element itemElement = itemsElement.addElement("item");
95 | itemElement.addAttribute("id", entry.getId());
96 | itemElement.add((org.dom4j.Element) entryElement);
97 | }
98 |
99 | // Return and send the result packet
100 | return result;
101 |
102 | } catch (Exception e) {
103 | Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
104 | IQ result = IQ.createResultIQ(packet);
105 | result.setChildElement(packet.getChildElement().createCopy());
106 | result.setError(PacketError.Condition.internal_server_error);
107 | return result;
108 | }
109 | }
110 |
111 | @Override
112 | public void initialize(XMPPServer server) {
113 | super.initialize(server);
114 | userManager = server.getUserManager();
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/activity/ActivitySubscribeHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.onesocialweb.openfire.handler.activity;
19 |
20 | import org.dom4j.Attribute;
21 | import org.dom4j.Element;
22 | import org.jivesoftware.openfire.XMPPServer;
23 | import org.jivesoftware.openfire.auth.UnauthorizedException;
24 | import org.jivesoftware.openfire.user.UserManager;
25 | import org.jivesoftware.util.LocaleUtils;
26 | import org.jivesoftware.util.Log;
27 | import org.onesocialweb.openfire.handler.pep.PEPCommandHandler;
28 | import org.onesocialweb.openfire.manager.ActivityManager;
29 | import org.xmpp.packet.IQ;
30 | import org.xmpp.packet.JID;
31 | import org.xmpp.packet.PacketError;
32 |
33 | public class ActivitySubscribeHandler extends PEPCommandHandler {
34 |
35 | public static final String COMMAND = "subscribe";
36 |
37 | private UserManager userManager;
38 |
39 | public ActivitySubscribeHandler() {
40 | super("OneSocialWeb - Subscribe to a user activities");
41 | }
42 |
43 | @Override
44 | public String getCommand() {
45 | return COMMAND;
46 | }
47 |
48 | @SuppressWarnings( { "deprecation" })
49 | @Override
50 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
51 |
52 | JID sender = packet.getFrom();
53 | JID recipient = packet.getTo();
54 |
55 | // Process the request inside a try/catch so that unhandled exceptions
56 | // (oufofbounds etc...) can trigger a server error and we can send a
57 | // error result packet
58 | try {
59 |
60 | // A valid request is an IQ of type set, for a valid and local recipient
61 | if (!(packet.getType().equals(IQ.Type.set) && recipient != null && recipient.getNode() != null
62 | && userManager.isRegisteredUser(recipient.getNode()))) {
63 | IQ result = IQ.createResultIQ(packet);
64 | result.setChildElement(packet.getChildElement().createCopy());
65 | result.setError(PacketError.Condition.bad_request);
66 | return result;
67 | }
68 |
69 | // A valid request has a (bare) JID attribute
70 | Element pubsubElement = packet.getChildElement();
71 | Element subscribeElement = pubsubElement.element("subscribe");
72 | Attribute jidAttribute = subscribeElement.attribute("jid");
73 | if (jidAttribute == null || !sender.toBareJID().equals(jidAttribute.getValue())) {
74 | IQ result = IQ.createResultIQ(packet);
75 | result.setChildElement(packet.getChildElement().createCopy());
76 | result.setError(PacketError.Condition.bad_request);
77 | return result;
78 | }
79 |
80 | // Add the relation to the database
81 | ActivityManager.getInstance().subscribe(sender.toBareJID(), recipient.toBareJID());
82 |
83 | // Return and send a result packet
84 | IQ result = IQ.createResultIQ(packet);
85 | Element resultPubsubElement = result.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");
86 | Element resultSubscriptionElement = resultPubsubElement.addElement("subscription", "http://jabber.org/protocol/pubsub");
87 | resultSubscriptionElement.addAttribute("node", PEPActivityHandler.NODE);
88 | resultSubscriptionElement.addAttribute("jid", recipient.toBareJID());
89 | resultSubscriptionElement.addAttribute("subscription", "subscribed");
90 | return result;
91 |
92 | } catch (Exception e) {
93 | Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
94 | IQ result = IQ.createResultIQ(packet);
95 | result.setChildElement(packet.getChildElement().createCopy());
96 | result.setError(PacketError.Condition.internal_server_error);
97 | return result;
98 | }
99 | }
100 |
101 | @Override
102 | public void initialize(XMPPServer server) {
103 | super.initialize(server);
104 | userManager = server.getUserManager();
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/activity/ActivitySubscribersHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.activity;
18 |
19 | import java.util.List;
20 |
21 | import org.dom4j.Element;
22 | import org.jivesoftware.openfire.XMPPServer;
23 | import org.jivesoftware.openfire.auth.UnauthorizedException;
24 | import org.jivesoftware.openfire.user.UserManager;
25 | import org.jivesoftware.util.LocaleUtils;
26 | import org.jivesoftware.util.Log;
27 | import org.onesocialweb.model.atom.DefaultAtomHelper;
28 | import org.onesocialweb.openfire.handler.pep.PEPCommandHandler;
29 | import org.onesocialweb.openfire.manager.ActivityManager;
30 | import org.onesocialweb.openfire.model.Subscription;
31 | import org.xmpp.packet.IQ;
32 | import org.xmpp.packet.JID;
33 | import org.xmpp.packet.PacketError;
34 |
35 | public class ActivitySubscribersHandler extends PEPCommandHandler {
36 |
37 | public static final String COMMAND = "subscribers";
38 |
39 | private UserManager userManager;
40 |
41 | private ActivityManager activityManager;
42 |
43 | public ActivitySubscribersHandler() {
44 | super("OneSocialWeb - Retrieves a user subscribers");
45 | }
46 |
47 | @Override
48 | public String getCommand() {
49 | return COMMAND;
50 | }
51 |
52 | @SuppressWarnings( { "deprecation"})
53 | @Override
54 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
55 | JID sender = packet.getFrom();
56 | JID recipient = packet.getTo();
57 |
58 | // Process the request inside a try/catch so that unhandled exceptions
59 | // (oufofbounds etc...) can trigger a server error and we can send a
60 | // error result packet
61 | try {
62 | // If no recipient, we assume the recipient is the sender
63 | if (recipient == null) {
64 | recipient = sender;
65 | }
66 |
67 | // A valid request is an IQ of type get, for a valid and local recipient
68 | if (!(packet.getType().equals(IQ.Type.get) && recipient != null && recipient.getNode() != null
69 | && userManager.isRegisteredUser(recipient.getNode()))) {
70 | IQ result = IQ.createResultIQ(packet);
71 | result.setChildElement(packet.getChildElement().createCopy());
72 | result.setError(PacketError.Condition.bad_request);
73 | return result;
74 | }
75 |
76 | // Fetch the subscribers
77 | List subscribers = activityManager.getSubscribers(recipient.toBareJID());
78 |
79 | // Send a success result
80 | IQ result = IQ.createResultIQ(packet);
81 | Element resultPubsubElement = result.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");
82 | Element resultPublishElement = resultPubsubElement.addElement("subscribers", "http://jabber.org/protocol/pubsub");
83 | resultPublishElement.addAttribute("node", PEPActivityHandler.NODE);
84 | for (Subscription sub : subscribers) {
85 | Element subElement = resultPublishElement.addElement("subscriber");
86 | subElement.addAttribute("node", PEPActivityHandler.NODE);
87 | subElement.addAttribute("jid", sub.getSubscriber());
88 | subElement.addAttribute("created", DefaultAtomHelper.format(sub.getCreated()));
89 | }
90 | return result;
91 |
92 | } catch (Exception e) {
93 | Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
94 | IQ result = IQ.createResultIQ(packet);
95 | result.setChildElement(packet.getChildElement().createCopy());
96 | result.setError(PacketError.Condition.internal_server_error);
97 | return result;
98 | }
99 | }
100 |
101 | @Override
102 | public void initialize(XMPPServer server) {
103 | super.initialize(server);
104 | userManager = server.getUserManager();
105 | activityManager = ActivityManager.getInstance();
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/activity/ActivitySubscriptionsHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.activity;
18 |
19 | import java.util.List;
20 |
21 | import org.dom4j.Element;
22 | import org.jivesoftware.openfire.XMPPServer;
23 | import org.jivesoftware.openfire.auth.UnauthorizedException;
24 | import org.jivesoftware.openfire.user.UserManager;
25 | import org.jivesoftware.util.LocaleUtils;
26 | import org.jivesoftware.util.Log;
27 | import org.onesocialweb.model.atom.DefaultAtomHelper;
28 | import org.onesocialweb.openfire.handler.pep.PEPCommandHandler;
29 | import org.onesocialweb.openfire.manager.ActivityManager;
30 | import org.onesocialweb.openfire.model.Subscription;
31 | import org.xmpp.packet.IQ;
32 | import org.xmpp.packet.JID;
33 | import org.xmpp.packet.PacketError;
34 |
35 | public class ActivitySubscriptionsHandler extends PEPCommandHandler {
36 |
37 | public static final String COMMAND = "subscriptions";
38 |
39 | private UserManager userManager;
40 |
41 | private ActivityManager activityManager;
42 |
43 | public ActivitySubscriptionsHandler() {
44 | super("OneSocialWeb - Retrieves a user subscriptions");
45 | }
46 |
47 | @Override
48 | public String getCommand() {
49 | return COMMAND;
50 | }
51 |
52 | @SuppressWarnings( { "deprecation"})
53 | @Override
54 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
55 | JID sender = packet.getFrom();
56 | JID recipient = packet.getTo();
57 |
58 | // Process the request inside a try/catch so that unhandled exceptions
59 | // (oufofbounds etc...) can trigger a server error and we can send a
60 | // error result packet
61 | try {
62 |
63 | // If no recipient, we assume the recipient is the sender
64 | if (recipient == null) {
65 | recipient = sender;
66 | }
67 |
68 | // A valid request is an IQ of type get, for a valid and local recipient
69 | if (!(packet.getType().equals(IQ.Type.get) && recipient != null && recipient.getNode() != null
70 | && userManager.isRegisteredUser(recipient.getNode()))) {
71 | IQ result = IQ.createResultIQ(packet);
72 | result.setChildElement(packet.getChildElement().createCopy());
73 | result.setError(PacketError.Condition.bad_request);
74 | return result;
75 | }
76 |
77 | // Fetch the subscriptions
78 | List subscriptions = activityManager.getSubscriptions(recipient.toBareJID());
79 |
80 | // Send a success result
81 | IQ result = IQ.createResultIQ(packet);
82 | Element resultPubsubElement = result.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");
83 | Element resultPublishElement = resultPubsubElement.addElement("subscriptions", "http://jabber.org/protocol/pubsub");
84 | resultPublishElement.addAttribute("node", PEPActivityHandler.NODE);
85 | for (Subscription sub : subscriptions) {
86 | Element subElement = resultPublishElement.addElement("subscription");
87 | subElement.addAttribute("node", PEPActivityHandler.NODE);
88 | subElement.addAttribute("jid", sub.getTarget());
89 | subElement.addAttribute("subscription", "subscribed");
90 | subElement.addAttribute("created", DefaultAtomHelper.format(sub.getCreated()));
91 | }
92 | return result;
93 |
94 | } catch (Exception e) {
95 | Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
96 | IQ result = IQ.createResultIQ(packet);
97 | result.setChildElement(packet.getChildElement().createCopy());
98 | result.setError(PacketError.Condition.internal_server_error);
99 | return result;
100 | }
101 | }
102 |
103 | @Override
104 | public void initialize(XMPPServer server) {
105 | super.initialize(server);
106 | userManager = server.getUserManager();
107 | activityManager = ActivityManager.getInstance();
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/activity/ActivityUnsubscribeHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.onesocialweb.openfire.handler.activity;
19 |
20 | import org.dom4j.Attribute;
21 | import org.dom4j.Element;
22 | import org.jivesoftware.openfire.XMPPServer;
23 | import org.jivesoftware.openfire.auth.UnauthorizedException;
24 | import org.jivesoftware.openfire.user.UserManager;
25 | import org.jivesoftware.util.LocaleUtils;
26 | import org.jivesoftware.util.Log;
27 | import org.onesocialweb.openfire.handler.pep.PEPCommandHandler;
28 | import org.onesocialweb.openfire.manager.ActivityManager;
29 | import org.xmpp.packet.IQ;
30 | import org.xmpp.packet.JID;
31 | import org.xmpp.packet.PacketError;
32 |
33 | public class ActivityUnsubscribeHandler extends PEPCommandHandler {
34 |
35 | public static final String COMMAND = "unsubscribe";
36 |
37 | private UserManager userManager;
38 |
39 | public ActivityUnsubscribeHandler() {
40 | super("OneSocialWeb - Unsubscribe to a user activities");
41 | }
42 |
43 | @Override
44 | public String getCommand() {
45 | return COMMAND;
46 | }
47 |
48 | @SuppressWarnings( { "deprecation" })
49 | @Override
50 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
51 |
52 | JID sender = packet.getFrom();
53 | JID recipient = packet.getTo();
54 |
55 | // Process the request inside a try/catch so that unhandled exceptions
56 | // (oufofbounds etc...) can trigger a server error and we can send a
57 | // error result packet
58 | try {
59 |
60 | // A valid request is an IQ of type set, for a valid and local recipient
61 | if (!(packet.getType().equals(IQ.Type.set) && recipient != null && recipient.getNode() != null
62 | && userManager.isRegisteredUser(recipient.getNode()))) {
63 | IQ result = IQ.createResultIQ(packet);
64 | result.setChildElement(packet.getChildElement().createCopy());
65 | result.setError(PacketError.Condition.bad_request);
66 | return result;
67 | }
68 |
69 | // A valid request has a (bare) JID attribute
70 | Element pubsubElement = packet.getChildElement();
71 | Element subscribeElement = pubsubElement.element("unsubscribe");
72 | Attribute jidAttribute = subscribeElement.attribute("jid");
73 | if (jidAttribute == null || !sender.toBareJID().equals(jidAttribute.getValue())) {
74 | IQ result = IQ.createResultIQ(packet);
75 | result.setChildElement(packet.getChildElement().createCopy());
76 | result.setError(PacketError.Condition.bad_request);
77 | return result;
78 | }
79 |
80 | // Add the relation to the database
81 | ActivityManager.getInstance().unsubscribe(sender.toBareJID(), recipient.toBareJID());
82 |
83 | // Return and send a result packet
84 | IQ result = IQ.createResultIQ(packet);
85 | return result;
86 |
87 | } catch (Exception e) {
88 | Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
89 | IQ result = IQ.createResultIQ(packet);
90 | result.setChildElement(packet.getChildElement().createCopy());
91 | result.setError(PacketError.Condition.internal_server_error);
92 | return result;
93 | }
94 | }
95 |
96 | @Override
97 | public void initialize(XMPPServer server) {
98 | super.initialize(server);
99 | userManager = server.getUserManager();
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/activity/IQSubscribeInterceptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.activity;
18 |
19 | import org.dom4j.Attribute;
20 | import org.dom4j.Element;
21 | import org.dom4j.Namespace;
22 | import org.jivesoftware.openfire.XMPPServer;
23 | import org.jivesoftware.openfire.interceptor.PacketInterceptor;
24 | import org.jivesoftware.openfire.interceptor.PacketRejectedException;
25 | import org.jivesoftware.openfire.session.Session;
26 | import org.onesocialweb.openfire.manager.ActivityManager;
27 | import org.xmpp.packet.IQ;
28 | import org.xmpp.packet.JID;
29 | import org.xmpp.packet.Packet;
30 |
31 | public class IQSubscribeInterceptor implements PacketInterceptor {
32 |
33 | private final XMPPServer server;
34 |
35 | public IQSubscribeInterceptor() {
36 | server = XMPPServer.getInstance();
37 | }
38 |
39 | public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
40 |
41 | // We only care for incoming IQ that have not yet been processed
42 | if (incoming && !processed && packet instanceof IQ) {
43 |
44 | final IQ iq = (IQ) packet;
45 | final JID fromJID = iq.getFrom();
46 | final JID toJID = iq.getTo();
47 |
48 | // Must be iq of type set and sent to remote users
49 | if (!iq.getType().equals(IQ.Type.set) || server.isLocal(toJID)) {
50 | return;
51 | }
52 |
53 | // With a pubsub requests
54 | Element requestElement = iq.getChildElement();
55 | if (!requestElement.getNamespace().equals(Namespace.get("http://jabber.org/protocol/pubsub"))) {
56 | return;
57 | }
58 |
59 | // With a subscibe or unsubscribe command
60 | Element commandElement = requestElement.element("subscribe");
61 | if (commandElement == null) {
62 | commandElement = requestElement.element("unsubscribe");
63 | if (commandElement == null) {
64 | return;
65 | }
66 | }
67 |
68 | // Relating to the microblogging node
69 | Attribute nodeAttribute = commandElement.attribute("node");
70 | if (!(nodeAttribute != null && nodeAttribute.getValue().equals(PEPActivityHandler.NODE))) {
71 | return;
72 | }
73 |
74 | // Then we keep track of the subscribe/unsubscribe request
75 | if (commandElement.getName().equals("subscribe")) {
76 | ActivityManager.getInstance().subscribe(fromJID.toBareJID(), toJID.toBareJID());
77 | } else {
78 | ActivityManager.getInstance().unsubscribe(fromJID.toBareJID(), toJID.toBareJID());
79 | }
80 |
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/activity/PEPActivityHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.onesocialweb.openfire.handler.activity;
19 |
20 | import java.util.List;
21 | import java.util.Map;
22 | import java.util.concurrent.ConcurrentHashMap;
23 |
24 | import org.dom4j.Element;
25 | import org.jivesoftware.openfire.XMPPServer;
26 | import org.jivesoftware.openfire.auth.UnauthorizedException;
27 | import org.onesocialweb.openfire.handler.pep.PEPCommandHandler;
28 | import org.onesocialweb.openfire.handler.pep.PEPNodeHandler;
29 | import org.xmpp.packet.IQ;
30 | import org.xmpp.packet.PacketError;
31 |
32 | public class PEPActivityHandler extends PEPNodeHandler {
33 |
34 | public static String NODE = "urn:xmpp:microblog:0";
35 |
36 | private XMPPServer server;
37 |
38 | private Map handlers = new ConcurrentHashMap();
39 |
40 | public PEPActivityHandler() {
41 | super("Handler for PEP microbloging PEP node");
42 | }
43 |
44 | @Override
45 | public String getNode() {
46 | return NODE;
47 | }
48 |
49 | @Override
50 | public void initialize(XMPPServer server) {
51 | super.initialize(server);
52 | this.server = server;
53 | addHandler(new ActivityPublishHandler());
54 | addHandler(new ActivityQueryHandler());
55 | addHandler(new ActivityDeleteHandler());
56 | addHandler(new ActivitySubscribeHandler());
57 | addHandler(new ActivityUnsubscribeHandler());
58 | addHandler(new ActivitySubscribersHandler());
59 | addHandler(new ActivitySubscriptionsHandler());
60 | }
61 |
62 | @SuppressWarnings("unchecked")
63 | @Override
64 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
65 | // We search for a handler based on the element name
66 | // and process the packet with the handler if found.
67 | final Element childElement = packet.getChildElement();
68 | final List pubsubElements = childElement.elements();
69 |
70 | if (pubsubElements != null && pubsubElements.size() > 0) {
71 | Element actionElement = pubsubElements.get(0);
72 | PEPCommandHandler handler = getHandler(actionElement.getName());
73 | if (handler != null) {
74 | return handler.handleIQ(packet);
75 | }
76 | }
77 |
78 | // No valid hanlder found. Return a feature not implemented
79 | // error.
80 | IQ result = IQ.createResultIQ(packet);
81 | result.setChildElement(packet.getChildElement().createCopy());
82 | result.setError(PacketError.Condition.feature_not_implemented);
83 | return result;
84 | }
85 |
86 | private void addHandler(PEPCommandHandler handler) {
87 | handler.initialize(server);
88 | handlers.put(handler.getCommand(), handler);
89 | }
90 |
91 | private PEPCommandHandler getHandler(String name) {
92 | return handlers.get(name);
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/inbox/InboxQueryHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.inbox;
18 |
19 | import java.util.List;
20 |
21 | import org.dom4j.dom.DOMDocument;
22 | import org.jivesoftware.openfire.XMPPServer;
23 | import org.jivesoftware.openfire.auth.UnauthorizedException;
24 | import org.jivesoftware.openfire.user.UserManager;
25 | import org.jivesoftware.util.LocaleUtils;
26 | import org.jivesoftware.util.Log;
27 | import org.onesocialweb.openfire.handler.activity.PEPActivityHandler;
28 | import org.onesocialweb.openfire.handler.pep.PEPCommandHandler;
29 | import org.onesocialweb.openfire.manager.InboxManager;
30 | import org.onesocialweb.openfire.model.ActivityMessage;
31 | import org.onesocialweb.xml.dom.ActivityDomWriter;
32 | import org.onesocialweb.xml.dom.imp.DefaultActivityDomWriter;
33 | import org.onesocialweb.xml.namespace.Atom;
34 | import org.w3c.dom.Element;
35 | import org.xmpp.packet.IQ;
36 | import org.xmpp.packet.JID;
37 | import org.xmpp.packet.PacketError;
38 |
39 | public class InboxQueryHandler extends PEPCommandHandler {
40 |
41 | public static final String COMMAND = "items";
42 |
43 | private InboxManager inboxManager;
44 |
45 | private UserManager userManager;
46 |
47 | public InboxQueryHandler() {
48 | super("OneSocialWeb - Query a user activities");
49 | }
50 |
51 | @Override
52 | public String getCommand() {
53 | return COMMAND;
54 | }
55 |
56 | @SuppressWarnings( { "deprecation" })
57 | @Override
58 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
59 |
60 | final JID sender = packet.getFrom();
61 | final JID recipient = packet.getTo();
62 |
63 | // Process the request inside a try/catch so that unhandled exceptions
64 | // (oufofbounds etc...) can trigger a server error and we can send a
65 | // error result packet
66 | try {
67 | // A valid request is an IQ of type get
68 | if (!(packet.getType().equals(IQ.Type.get))) {
69 | IQ result = IQ.createResultIQ(packet);
70 | result.setChildElement(packet.getChildElement().createCopy());
71 | result.setError(PacketError.Condition.bad_request);
72 | return result;
73 | }
74 |
75 | // If a recipient is specified, it must be equal to the sender
76 | // bareJID
77 | if (recipient != null && !recipient.toString().equals(sender.toBareJID())) {
78 | IQ result = IQ.createResultIQ(packet);
79 | result.setChildElement(packet.getChildElement().createCopy());
80 | result.setError(PacketError.Condition.not_authorized);
81 | return result;
82 | }
83 |
84 | // Only a local user has an inbox
85 | if (!userManager.isRegisteredUser(sender.getNode())) {
86 | IQ result = IQ.createResultIQ(packet);
87 | result.setChildElement(packet.getChildElement().createCopy());
88 | result.setError(PacketError.Condition.not_authorized);
89 | return result;
90 | }
91 |
92 | // We fetch the notifications fot the requesting user
93 | List messages = inboxManager.getMessages(sender.toBareJID());
94 |
95 | // Prepare the result packet
96 | ActivityDomWriter writer = new DefaultActivityDomWriter();
97 | DOMDocument domDocument = new DOMDocument();
98 | IQ result = IQ.createResultIQ(packet);
99 | org.dom4j.Element pubsubElement = result.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");
100 | org.dom4j.Element itemsElement = pubsubElement.addElement("items");
101 | itemsElement.addAttribute("node", PEPActivityHandler.NODE);
102 |
103 | for (ActivityMessage message : messages) {
104 | Element entryElement = (Element) domDocument.appendChild(domDocument.createElementNS(Atom.NAMESPACE, Atom.ENTRY_ELEMENT));
105 | writer.write(message.getActivity(), entryElement);
106 | domDocument.removeChild(entryElement);
107 | org.dom4j.Element itemElement = itemsElement.addElement("item");
108 | itemElement.addAttribute("id", message.getActivity().getId());
109 | itemElement.add((org.dom4j.Element) entryElement);
110 | }
111 |
112 | // Return and send the result packet
113 | return result;
114 |
115 | } catch (Exception e) {
116 | Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
117 | IQ result = IQ.createResultIQ(packet);
118 | result.setChildElement(packet.getChildElement().createCopy());
119 | result.setError(PacketError.Condition.internal_server_error);
120 | return result;
121 | }
122 | }
123 |
124 | @Override
125 | public void initialize(XMPPServer server) {
126 | super.initialize(server);
127 | userManager = server.getUserManager();
128 | inboxManager = InboxManager.getInstance();
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/inbox/PEPInboxHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.inbox;
18 |
19 | import java.util.List;
20 | import java.util.Map;
21 | import java.util.concurrent.ConcurrentHashMap;
22 |
23 | import org.dom4j.Element;
24 | import org.jivesoftware.openfire.XMPPServer;
25 | import org.jivesoftware.openfire.auth.UnauthorizedException;
26 | import org.onesocialweb.openfire.handler.pep.PEPCommandHandler;
27 | import org.onesocialweb.openfire.handler.pep.PEPNodeHandler;
28 | import org.xmpp.packet.IQ;
29 | import org.xmpp.packet.PacketError;
30 |
31 | public class PEPInboxHandler extends PEPNodeHandler {
32 |
33 | public static String NODE = "http://onesocialweb.org/spec/1.0/inbox";
34 |
35 | private XMPPServer server;
36 |
37 | private Map handlers = new ConcurrentHashMap();
38 |
39 | public PEPInboxHandler() {
40 | super("Handler for Onesocialweb inbox PEP node");
41 | }
42 |
43 | @Override
44 | public String getNode() {
45 | return NODE;
46 | }
47 |
48 | @Override
49 | public void initialize(XMPPServer server) {
50 | super.initialize(server);
51 | this.server = server;
52 | addHandler(new InboxQueryHandler());
53 | }
54 |
55 | @SuppressWarnings("unchecked")
56 | @Override
57 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
58 | // We search for a handler based on the element name
59 | // and process the packet with the handler if found.
60 | final Element childElement = packet.getChildElement();
61 | final List pubsubElements = childElement.elements();
62 |
63 | if (pubsubElements != null && pubsubElements.size() > 0) {
64 | Element actionElement = pubsubElements.get(0);
65 | PEPCommandHandler handler = getHandler(actionElement.getName());
66 | if (handler != null) {
67 | return handler.handleIQ(packet);
68 | }
69 | }
70 |
71 | // No valid hanlder found. Return a feature not implemented
72 | // error.
73 | IQ result = IQ.createResultIQ(packet);
74 | result.setChildElement(packet.getChildElement().createCopy());
75 | result.setError(PacketError.Condition.feature_not_implemented);
76 | return result;
77 | }
78 |
79 | public void addHandler(PEPCommandHandler handler) {
80 | handler.initialize(server);
81 | handlers.put(handler.getCommand(), handler);
82 | }
83 |
84 | public PEPCommandHandler getHandler(String name) {
85 | return handlers.get(name);
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/pep/IQPEPHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.pep;
18 |
19 | import java.util.List;
20 | import java.util.Map;
21 | import java.util.concurrent.ConcurrentHashMap;
22 |
23 | import org.dom4j.Attribute;
24 | import org.dom4j.Element;
25 | import org.jivesoftware.openfire.IQHandlerInfo;
26 | import org.jivesoftware.openfire.XMPPServer;
27 | import org.jivesoftware.openfire.auth.UnauthorizedException;
28 | import org.jivesoftware.openfire.handler.IQHandler;
29 | import org.xmpp.packet.IQ;
30 |
31 | public class IQPEPHandler extends IQHandler {
32 |
33 | private XMPPServer server;
34 |
35 | private Map handlers = new ConcurrentHashMap();
36 |
37 | public IQPEPHandler() {
38 | super("Intercept PEP request and divert to another handler based on node URI");
39 | }
40 |
41 | @Override
42 | public void initialize(XMPPServer server) {
43 | super.initialize(server);
44 | this.server = server;
45 | }
46 |
47 | @Override
48 | public IQHandlerInfo getInfo() {
49 | return new IQHandlerInfo("pubsub", "http://jabber.org/protocol/pubsub");
50 | }
51 |
52 | @SuppressWarnings("unchecked")
53 | @Override
54 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
55 | final Element childElement = packet.getChildElement();
56 | final List pubsubElements = childElement.elements();
57 |
58 | if (pubsubElements != null && pubsubElements.size() > 0) {
59 | Element actionElement = pubsubElements.get(0);
60 | Attribute node = actionElement.attribute("node");
61 | PEPNodeHandler handler = getHandler(node.getValue());
62 | if (handler != null) {
63 | return handler.handleIQ(packet);
64 | }
65 | }
66 |
67 | return XMPPServer.getInstance().getIQPEPHandler().handleIQ(packet);
68 | }
69 |
70 | public void addHandler(PEPNodeHandler handler) {
71 | handler.initialize(server);
72 | handlers.put(handler.getNode(), handler);
73 | }
74 |
75 | public PEPNodeHandler getHandler(String node) {
76 | return handlers.get(node);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/pep/PEPCommandHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.pep;
18 |
19 | import org.jivesoftware.openfire.auth.UnauthorizedException;
20 | import org.jivesoftware.openfire.container.BasicModule;
21 | import org.xmpp.packet.IQ;
22 |
23 | public abstract class PEPCommandHandler extends BasicModule {
24 |
25 | /**
26 | * Create a basic module with the given name.
27 | *
28 | * @param moduleName The name for the module or null to use the default
29 | */
30 | public PEPCommandHandler(String moduleName) {
31 | super(moduleName);
32 | }
33 |
34 | public abstract IQ handleIQ(IQ packet) throws UnauthorizedException;
35 |
36 | public abstract String getCommand();
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/pep/PEPNodeHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.pep;
18 |
19 | import org.jivesoftware.openfire.auth.UnauthorizedException;
20 | import org.jivesoftware.openfire.container.BasicModule;
21 | import org.xmpp.packet.IQ;
22 |
23 | public abstract class PEPNodeHandler extends BasicModule {
24 |
25 | /**
26 | * Create a basic module with the given name.
27 | *
28 | * @param moduleName The name for the module or null to use the default
29 | */
30 | public PEPNodeHandler(String moduleName) {
31 | super(moduleName);
32 | }
33 |
34 | public abstract IQ handleIQ(IQ packet) throws UnauthorizedException;
35 |
36 | public abstract String getNode();
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/profile/IQProfilePublishHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.profile;
18 |
19 | import org.dom4j.Element;
20 | import org.dom4j.QName;
21 | import org.jivesoftware.openfire.IQHandlerInfo;
22 | import org.jivesoftware.openfire.XMPPServer;
23 | import org.jivesoftware.openfire.auth.UnauthorizedException;
24 | import org.jivesoftware.openfire.handler.IQHandler;
25 | import org.jivesoftware.openfire.user.UserManager;
26 | import org.jivesoftware.openfire.user.UserNotFoundException;
27 | import org.jivesoftware.util.LocaleUtils;
28 | import org.jivesoftware.util.Log;
29 | import org.onesocialweb.model.vcard4.Profile;
30 | import org.onesocialweb.openfire.manager.ProfileManager;
31 | import org.onesocialweb.openfire.model.vcard4.PersistentVCard4DomReader;
32 | import org.onesocialweb.xml.dom.VCard4DomReader;
33 | import org.onesocialweb.xml.dom4j.ElementAdapter;
34 | import org.onesocialweb.xml.namespace.VCard4;
35 | import org.xmpp.packet.IQ;
36 | import org.xmpp.packet.JID;
37 | import org.xmpp.packet.PacketError;
38 |
39 | public class IQProfilePublishHandler extends IQHandler {
40 |
41 | private final IQHandlerInfo info = new IQHandlerInfo("publish", "http://onesocialweb.org/spec/1.0/vcard4#publish");
42 |
43 | private UserManager userManager;
44 |
45 | public IQProfilePublishHandler() {
46 | super("OneSocialWeb - Publish profile handler");
47 | }
48 |
49 | @Override
50 | public IQHandlerInfo getInfo() {
51 | return info;
52 | }
53 |
54 | @SuppressWarnings("deprecation")
55 | @Override
56 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
57 | final JID sender = packet.getFrom();
58 | final JID recipient = packet.getTo();
59 |
60 | // Process the request inside a try/catch so that unhandled exceptions
61 | // (oufofbounds etc...) can trigger a server error and we can send a
62 | // error result packet
63 | try {
64 |
65 | // A valid request is an IQ of type set,
66 | if (!packet.getType().equals(IQ.Type.set)) {
67 | IQ result = IQ.createResultIQ(packet);
68 | result.setChildElement(packet.getChildElement().createCopy());
69 | result.setError(PacketError.Condition.bad_request);
70 | return result;
71 | }
72 |
73 | // If a recipient is specified, it must be equal to the sender
74 | // bareJID
75 | if (recipient != null && !recipient.toString().equals(sender.toBareJID())) {
76 | IQ result = IQ.createResultIQ(packet);
77 | result.setChildElement(packet.getChildElement().createCopy());
78 | result.setError(PacketError.Condition.not_authorized);
79 | return result;
80 | }
81 |
82 | // Only a local user can publish its profile
83 | if (!userManager.isRegisteredUser(sender.getNode())) {
84 | IQ result = IQ.createResultIQ(packet);
85 | result.setChildElement(packet.getChildElement().createCopy());
86 | result.setError(PacketError.Condition.not_authorized);
87 | return result;
88 | }
89 |
90 | // A valid submit requets must contain a vcard4 entry
91 | Element request = packet.getChildElement();
92 | Element e_profile = request.element(QName.get(VCard4.VCARD_ELEMENT, VCard4.NAMESPACE));
93 | if (e_profile == null) {
94 | IQ result = IQ.createResultIQ(packet);
95 | result.setChildElement(packet.getChildElement().createCopy());
96 | result.setError(PacketError.Condition.bad_request);
97 | return result;
98 | }
99 |
100 | // Parse the profile
101 | VCard4DomReader reader = new PersistentVCard4DomReader();
102 | Profile profile = reader.readProfile(new ElementAdapter(e_profile));
103 |
104 | // Commit the profile (this will also trigger the messages)
105 | try {
106 | ProfileManager.getInstance().publishProfile(sender.toBareJID(), profile);
107 | } catch (UserNotFoundException e) {
108 | // We know this cannot happen
109 | }
110 |
111 | // Send a success result
112 | // TODO should this contain more, like the ID of the new activities ?
113 | IQ result = IQ.createResultIQ(packet);
114 | return result;
115 |
116 | } catch (Exception e) {
117 | Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
118 | IQ result = IQ.createResultIQ(packet);
119 | result.setChildElement(packet.getChildElement().createCopy());
120 | result.setError(PacketError.Condition.internal_server_error);
121 | return result;
122 | }
123 | }
124 |
125 | @Override
126 | public void initialize(XMPPServer server) {
127 | super.initialize(server);
128 | userManager = server.getUserManager();
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/profile/IQProfileQueryHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.profile;
18 |
19 | import org.dom4j.dom.DOMDocument;
20 | import org.jivesoftware.openfire.IQHandlerInfo;
21 | import org.jivesoftware.openfire.XMPPServer;
22 | import org.jivesoftware.openfire.auth.UnauthorizedException;
23 | import org.jivesoftware.openfire.handler.IQHandler;
24 | import org.jivesoftware.openfire.user.UserManager;
25 | import org.jivesoftware.util.LocaleUtils;
26 | import org.jivesoftware.util.Log;
27 | import org.onesocialweb.model.vcard4.Profile;
28 | import org.onesocialweb.openfire.manager.ProfileManager;
29 | import org.onesocialweb.xml.dom.VCard4DomWriter;
30 | import org.onesocialweb.xml.dom.imp.DefaultVCard4DomWriter;
31 | import org.onesocialweb.xml.namespace.VCard4;
32 | import org.w3c.dom.Element;
33 | import org.xmpp.packet.IQ;
34 | import org.xmpp.packet.JID;
35 | import org.xmpp.packet.PacketError;
36 |
37 | public class IQProfileQueryHandler extends IQHandler {
38 |
39 | public static final String NAME = "query";
40 |
41 | public static final String NAMESPACE = "http://onesocialweb.org/spec/1.0/vcard4#query";
42 |
43 | private final IQHandlerInfo info = new IQHandlerInfo(NAME, NAMESPACE);
44 |
45 | private UserManager userManager;
46 |
47 | public IQProfileQueryHandler() {
48 | super("OneSocialWeb - Query a user activities");
49 | }
50 |
51 | @Override
52 | public IQHandlerInfo getInfo() {
53 | return info;
54 | }
55 |
56 | @SuppressWarnings( { "deprecation" })
57 | @Override
58 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
59 |
60 | JID sender = packet.getFrom();
61 | JID target = packet.getTo();
62 |
63 | // Process the request inside a try/catch so that unhandled exceptions
64 | // (oufofbounds etc...) can trigger a server error and we can send a
65 | // error result packet
66 | try {
67 | // If no recipient, then the target is the sender
68 | if (target == null || target.getNode() == null) {
69 | target = packet.getFrom();
70 | }
71 |
72 | // A valid request is an IQ of type get, for a valid and local recipient
73 | if (!(packet.getType().equals(IQ.Type.get) && target != null && target.getNode() != null
74 | && userManager.isRegisteredUser(target.getNode()))) {
75 | IQ result = IQ.createResultIQ(packet);
76 | result.setChildElement(packet.getChildElement().createCopy());
77 | result.setError(PacketError.Condition.bad_request);
78 | return result;
79 | }
80 |
81 | // We fetch the profile of the target user
82 | Profile profile = ProfileManager.getInstance().getProfile(sender.toBareJID(), target.toBareJID());
83 |
84 | // Prepare the result packet
85 | VCard4DomWriter writer = new DefaultVCard4DomWriter();
86 | DOMDocument domDocument = new DOMDocument();
87 | IQ result = IQ.createResultIQ(packet);
88 | Element query = (Element) domDocument.appendChild(domDocument.createElementNS(NAMESPACE, NAME));
89 | if (profile != null) {
90 | writer.toElement(profile, query);
91 | } else {
92 | query.appendChild(domDocument.createElementNS(VCard4.NAMESPACE, VCard4.VCARD_ELEMENT));
93 | }
94 | result.setChildElement((org.dom4j.Element) query);
95 |
96 | // Return and send the result packet
97 | return result;
98 |
99 | } catch (Exception e) {
100 | Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
101 | IQ result = IQ.createResultIQ(packet);
102 | result.setChildElement(packet.getChildElement().createCopy());
103 | result.setError(PacketError.Condition.internal_server_error);
104 | return result;
105 | }
106 | }
107 |
108 | @Override
109 | public void initialize(XMPPServer server) {
110 | super.initialize(server);
111 | userManager = server.getUserManager();
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/relation/IQRelationQueryHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.relation;
18 |
19 | import java.util.List;
20 |
21 | import org.dom4j.dom.DOMDocument;
22 | import org.jivesoftware.openfire.IQHandlerInfo;
23 | import org.jivesoftware.openfire.XMPPServer;
24 | import org.jivesoftware.openfire.auth.UnauthorizedException;
25 | import org.jivesoftware.openfire.handler.IQHandler;
26 | import org.jivesoftware.openfire.user.UserManager;
27 | import org.jivesoftware.util.LocaleUtils;
28 | import org.jivesoftware.util.Log;
29 | import org.onesocialweb.model.relation.Relation;
30 | import org.onesocialweb.openfire.manager.RelationManager;
31 | import org.onesocialweb.xml.dom.RelationDomWriter;
32 | import org.onesocialweb.xml.dom.imp.DefaultRelationDomWriter;
33 | import org.w3c.dom.Element;
34 | import org.xmpp.packet.IQ;
35 | import org.xmpp.packet.JID;
36 | import org.xmpp.packet.PacketError;
37 |
38 | public class IQRelationQueryHandler extends IQHandler {
39 |
40 | public static final String NAME = "query";
41 |
42 | public static final String NAMESPACE = "http://onesocialweb.org/spec/1.0/relations#query";
43 |
44 | private final IQHandlerInfo info = new IQHandlerInfo(NAME, NAMESPACE);
45 |
46 | private UserManager userManager;
47 |
48 | public IQRelationQueryHandler() {
49 | super("OneSocialWeb - Query a user relations");
50 | }
51 |
52 | @Override
53 | public IQHandlerInfo getInfo() {
54 | return info;
55 | }
56 |
57 | @SuppressWarnings( { "deprecation" })
58 | @Override
59 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
60 |
61 | JID sender = packet.getFrom();
62 | JID target = packet.getTo();
63 |
64 | // Process the request inside a try/catch so that unhandled exceptions
65 | // (oufofbounds etc...) can trigger a server error and we can send a
66 | // error result packet
67 | try {
68 | // If no recipient, then the target is the sender
69 | if (target == null || target.getNode() == null) {
70 | target = packet.getFrom();
71 | }
72 |
73 | // A valid request is an IQ of type get, for a valid and local recipient
74 | if (!(packet.getType().equals(IQ.Type.get) && target != null && target.getNode() != null
75 | && userManager.isRegisteredUser(target.getNode()))) {
76 | IQ result = IQ.createResultIQ(packet);
77 | result.setChildElement(packet.getChildElement().createCopy());
78 | result.setError(PacketError.Condition.bad_request);
79 | return result;
80 | }
81 |
82 | // We fetch the relations of the target user
83 | List relations = RelationManager.getInstance().getRelations(sender.toBareJID(), target.toBareJID());
84 |
85 | // Prepare the result packet
86 | RelationDomWriter writer = new DefaultRelationDomWriter();
87 | DOMDocument domDocument = new DOMDocument();
88 | IQ result = IQ.createResultIQ(packet);
89 | Element query = (Element) domDocument.appendChild(domDocument.createElementNS(NAMESPACE, NAME));
90 | for (Relation relation : relations) {
91 | writer.toElement(relation,query);
92 | }
93 | result.setChildElement((org.dom4j.Element) query);
94 | // Return and send the result packet
95 | return result;
96 |
97 | } catch (Exception e) {
98 | Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
99 | IQ result = IQ.createResultIQ(packet);
100 | result.setChildElement(packet.getChildElement().createCopy());
101 | result.setError(PacketError.Condition.internal_server_error);
102 | return result;
103 | }
104 | }
105 |
106 | @Override
107 | public void initialize(XMPPServer server) {
108 | super.initialize(server);
109 | userManager = server.getUserManager();
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/relation/IQRelationSetupHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.relation;
18 |
19 | import java.util.Iterator;
20 |
21 | import org.dom4j.Element;
22 | import org.dom4j.Namespace;
23 | import org.dom4j.QName;
24 | import org.jivesoftware.openfire.IQHandlerInfo;
25 | import org.jivesoftware.openfire.XMPPServer;
26 | import org.jivesoftware.openfire.auth.UnauthorizedException;
27 | import org.jivesoftware.openfire.handler.IQHandler;
28 | import org.jivesoftware.openfire.user.UserManager;
29 | import org.jivesoftware.util.LocaleUtils;
30 | import org.jivesoftware.util.Log;
31 | import org.onesocialweb.openfire.manager.RelationManager;
32 | import org.onesocialweb.openfire.model.relation.PersistentRelation;
33 | import org.onesocialweb.openfire.model.relation.PersistentRelationDomReader;
34 | import org.onesocialweb.xml.dom.RelationDomReader;
35 | import org.onesocialweb.xml.dom4j.ElementAdapter;
36 | import org.onesocialweb.xml.namespace.Onesocialweb;
37 | import org.xmpp.packet.IQ;
38 | import org.xmpp.packet.JID;
39 | import org.xmpp.packet.PacketError;
40 |
41 | public class IQRelationSetupHandler extends IQHandler {
42 |
43 | public static final String NAME = "setup";
44 |
45 | public static final String NAMESPACE = "http://onesocialweb.org/spec/1.0/relations#setup";
46 |
47 | private final IQHandlerInfo info = new IQHandlerInfo(NAME, NAMESPACE);
48 |
49 | private UserManager userManager;
50 |
51 | private RelationManager relationManager;
52 |
53 | public IQRelationSetupHandler() {
54 | super("OneSocialWeb - Setup relations handler");
55 | }
56 |
57 | @Override
58 | public IQHandlerInfo getInfo() {
59 | return info;
60 | }
61 |
62 | @SuppressWarnings( { "deprecation", "unchecked" })
63 | @Override
64 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
65 | final JID sender = packet.getFrom();
66 | final JID recipient = packet.getTo();
67 |
68 | // Process the request inside a try/catch so that unhandled exceptions
69 | // (oufofbounds etc...) can trigger a server error and we can send a
70 | // error result packet
71 | try {
72 |
73 | // A valid request is an IQ of type set,
74 | if (!packet.getType().equals(IQ.Type.set)) {
75 | IQ result = IQ.createResultIQ(packet);
76 | result.setChildElement(packet.getChildElement().createCopy());
77 | result.setError(PacketError.Condition.bad_request);
78 | return result;
79 | }
80 |
81 | // If a recipient is specified, it must be equal to the sender
82 | // bareJID
83 | if (recipient != null && !recipient.toString().equals(sender.toBareJID())) {
84 | IQ result = IQ.createResultIQ(packet);
85 | result.setChildElement(packet.getChildElement().createCopy());
86 | result.setError(PacketError.Condition.not_authorized);
87 | return result;
88 | }
89 |
90 | // Only a local user can publish an activity to his stream
91 | if (!userManager.isRegisteredUser(sender.getNode())) {
92 | IQ result = IQ.createResultIQ(packet);
93 | result.setChildElement(packet.getChildElement().createCopy());
94 | result.setError(PacketError.Condition.not_authorized);
95 | return result;
96 | }
97 |
98 | // A valid submit requets must contain one relation item
99 | Element request = packet.getChildElement();
100 | Iterator i_entry = request.elementIterator(QName.get(Onesocialweb.RELATION_ELEMENT, Namespace.get(Onesocialweb.NAMESPACE)));
101 | if (!i_entry.hasNext()) {
102 | IQ result = IQ.createResultIQ(packet);
103 | result.setChildElement(packet.getChildElement().createCopy());
104 | result.setError(PacketError.Condition.bad_request);
105 | return result;
106 | }
107 |
108 | // Parse the relation
109 | RelationDomReader reader = new PersistentRelationDomReader();
110 | Element e_entry = i_entry.next();
111 | PersistentRelation relation = (PersistentRelation) reader.readElement(new ElementAdapter(e_entry));
112 | Log.debug("IQRelationSetup received request: " + relation);
113 |
114 | // Setup the relation (this will also trigger the notification to the user)
115 | relationManager.setupRelation(sender.toBareJID(), relation);
116 |
117 | // Send a success result
118 | IQ result = IQ.createResultIQ(packet);
119 | return result;
120 |
121 | } catch (Exception e) {
122 | Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
123 | IQ result = IQ.createResultIQ(packet);
124 | result.setChildElement(packet.getChildElement().createCopy());
125 | result.setError(PacketError.Condition.internal_server_error);
126 | return result;
127 | }
128 | }
129 |
130 | @Override
131 | public void initialize(XMPPServer server) {
132 | super.initialize(server);
133 | userManager = server.getUserManager();
134 | relationManager = RelationManager.getInstance();
135 | }
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/handler/relation/IQRelationUpdateHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.handler.relation;
18 |
19 | import java.util.Iterator;
20 |
21 | import org.dom4j.Element;
22 | import org.dom4j.Namespace;
23 | import org.dom4j.QName;
24 | import org.jivesoftware.openfire.IQHandlerInfo;
25 | import org.jivesoftware.openfire.XMPPServer;
26 | import org.jivesoftware.openfire.auth.UnauthorizedException;
27 | import org.jivesoftware.openfire.handler.IQHandler;
28 | import org.jivesoftware.openfire.user.UserManager;
29 | import org.jivesoftware.util.LocaleUtils;
30 | import org.jivesoftware.util.Log;
31 | import org.onesocialweb.openfire.manager.RelationManager;
32 | import org.onesocialweb.openfire.model.relation.PersistentRelation;
33 | import org.onesocialweb.openfire.model.relation.PersistentRelationDomReader;
34 | import org.onesocialweb.xml.dom.RelationDomReader;
35 | import org.onesocialweb.xml.dom4j.ElementAdapter;
36 | import org.onesocialweb.xml.namespace.Onesocialweb;
37 | import org.xmpp.packet.IQ;
38 | import org.xmpp.packet.JID;
39 | import org.xmpp.packet.PacketError;
40 |
41 | public class IQRelationUpdateHandler extends IQHandler {
42 |
43 | public static final String NAME = "update";
44 |
45 | public static final String NAMESPACE = "http://onesocialweb.org/spec/1.0/relations#update";
46 |
47 | private final IQHandlerInfo info = new IQHandlerInfo(NAME, NAMESPACE);
48 |
49 | private UserManager userManager;
50 |
51 | private RelationManager relationManager;
52 |
53 | public IQRelationUpdateHandler() {
54 | super("OneSocialWeb - Update relations handler");
55 | }
56 |
57 | @Override
58 | public IQHandlerInfo getInfo() {
59 | return info;
60 | }
61 |
62 | @SuppressWarnings( { "deprecation", "unchecked" })
63 | @Override
64 | public IQ handleIQ(IQ packet) throws UnauthorizedException {
65 | final JID sender = packet.getFrom();
66 | final JID recipient = packet.getTo();
67 |
68 | // Process the request inside a try/catch so that unhandled exceptions
69 | // (oufofbounds etc...) can trigger a server error and we can send a
70 | // error result packet
71 | try {
72 |
73 | // Only a local user can request to update a relation
74 | if (!userManager.isRegisteredUser(sender.getNode())) {
75 | IQ result = IQ.createResultIQ(packet);
76 | result.setChildElement(packet.getChildElement().createCopy());
77 | result.setError(PacketError.Condition.not_authorized);
78 | return result;
79 | }
80 |
81 | // A valid request is an IQ of type set, sent to the bare server
82 | if ((!packet.getType().equals(IQ.Type.set) || (recipient != null && recipient.getNode() != null))) {
83 | IQ result = IQ.createResultIQ(packet);
84 | result.setChildElement(packet.getChildElement().createCopy());
85 | result.setError(PacketError.Condition.bad_request);
86 | return result;
87 | }
88 |
89 | // A valid submit requets must contain one relation item
90 | Element request = packet.getChildElement();
91 | Iterator i_entry = request.elementIterator(QName.get(Onesocialweb.RELATION_ELEMENT, Namespace.get(Onesocialweb.NAMESPACE)));
92 | if (!i_entry.hasNext()) {
93 | IQ result = IQ.createResultIQ(packet);
94 | result.setChildElement(packet.getChildElement().createCopy());
95 | result.setError(PacketError.Condition.bad_request);
96 | return result;
97 | }
98 |
99 | // Parse the relation
100 | RelationDomReader reader = new PersistentRelationDomReader();
101 | Element e_entry = i_entry.next();
102 | PersistentRelation relation = (PersistentRelation) reader.readElement(new ElementAdapter(e_entry));
103 | Log.debug("IQRelationUpdate received request: " + relation);
104 |
105 | // Setup the relation (this will also trigger the notification to the user)
106 | relationManager.updateRelation(sender.toBareJID(), relation);
107 |
108 | // Send a success result
109 | IQ result = IQ.createResultIQ(packet);
110 | return result;
111 |
112 | } catch (Exception e) {
113 | Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
114 | IQ result = IQ.createResultIQ(packet);
115 | result.setChildElement(packet.getChildElement().createCopy());
116 | result.setError(PacketError.Condition.internal_server_error);
117 | return result;
118 | }
119 | }
120 |
121 | @Override
122 | public void initialize(XMPPServer server) {
123 | super.initialize(server);
124 | userManager = server.getUserManager();
125 | relationManager = RelationManager.getInstance();
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/manager/AclManager.java:
--------------------------------------------------------------------------------
1 | package org.onesocialweb.openfire.manager;
2 |
3 | import java.util.List;
4 |
5 | import org.jivesoftware.openfire.XMPPServer;
6 | import org.jivesoftware.openfire.roster.Roster;
7 | import org.jivesoftware.openfire.roster.RosterItem;
8 | import org.jivesoftware.openfire.user.UserNotFoundException;
9 | import org.onesocialweb.model.acl.AclRule;
10 | import org.onesocialweb.model.acl.AclSubject;
11 | import org.xmpp.packet.JID;
12 |
13 | public class AclManager
14 | {
15 |
16 | public static boolean canSee(String owner, AclRule rule, String viewer) throws UserNotFoundException {
17 |
18 | // Get the subjects, if none then access denied
19 | final List subjects = rule.getSubjects();
20 | if (subjects == null)
21 | return false;
22 |
23 | Roster roster =XMPPServer.getInstance().getRosterManager().getRoster(new JID(owner).getNode());
24 | // Get the roster entry that match the viewer, this is only
25 | // used for the groups based matches
26 | RosterItem rosterItem = null;
27 | try {
28 | rosterItem = roster.getRosterItem(new JID(viewer));
29 | } catch (UserNotFoundException e) {
30 | }
31 |
32 | // Iterate through the subjects and hope for the best
33 | for (AclSubject aclSubject : subjects) {
34 | if (aclSubject.getType().equals(AclSubject.EVERYONE)) {
35 | return true;
36 | } else if (aclSubject.getType().equals(AclSubject.GROUP)) {
37 | if (rosterItem != null && rosterItem.getGroups().contains(aclSubject.getName())) {
38 | return true;
39 | }
40 | } else if (aclSubject.getType().equals(AclSubject.PERSON)) {
41 | if (viewer.equals(aclSubject.getName())) {
42 | return true;
43 | }
44 | }
45 | }
46 |
47 | // Still here ? Then we did not find a match and it is a deny
48 | return false;
49 |
50 |
51 | }
52 |
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/manager/InboxManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.manager;
18 |
19 | import java.util.Collections;
20 | import java.util.List;
21 |
22 | import javax.persistence.EntityManager;
23 | import javax.persistence.Query;
24 |
25 | import org.onesocialweb.openfire.OswPlugin;
26 | import org.onesocialweb.openfire.model.ActivityMessage;
27 |
28 | /**
29 | * The inbox manager is a singleton class taking care of all the business
30 | * logic related to querying, creating, updating and deleting offline messages.
31 | *
32 | * @author eschenal
33 | *
34 | */
35 | public class InboxManager {
36 |
37 | /**
38 | * Singleton: keep a static reference to teh only instance
39 | */
40 | private static InboxManager instance;
41 |
42 | public static InboxManager getInstance() {
43 | if (instance == null) {
44 | // Carefull, we are in a threaded environment !
45 | synchronized (InboxManager.class) {
46 | instance = new InboxManager();
47 | }
48 | }
49 | return instance;
50 | }
51 |
52 | /**
53 | * Retrieves the last 20 message (which are in fact received activity entries) from
54 | * a user inbox as a immutable list.
55 | *
56 | * @param userJID the user requesting his inbox
57 | * @return the last 20 messages from the user inbox
58 | */
59 | @SuppressWarnings("unchecked")
60 | public List getMessages(String userJID) {
61 | final EntityManager em = OswPlugin.getEmFactory().createEntityManager();
62 | Query query = em.createQuery("SELECT x FROM Messages x WHERE x.recipient = ?1 ORDER BY x.received DESC");
63 | query.setParameter(1, userJID);
64 | query.setMaxResults(20);
65 | List messages = query.getResultList();
66 | em.close();
67 | return Collections.unmodifiableList(messages);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/manager/ProfileManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.manager;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import javax.persistence.EntityManager;
23 |
24 | import org.jivesoftware.openfire.user.UserNotFoundException;
25 | import org.onesocialweb.model.acl.AclAction;
26 | import org.onesocialweb.model.acl.AclFactory;
27 | import org.onesocialweb.model.acl.AclRule;
28 | import org.onesocialweb.model.vcard4.Field;
29 | import org.onesocialweb.model.vcard4.Profile;
30 | import org.onesocialweb.model.vcard4.exception.CardinalityException;
31 | import org.onesocialweb.model.vcard4.exception.UnsupportedFieldException;
32 | import org.onesocialweb.openfire.OswPlugin;
33 | import org.onesocialweb.openfire.model.acl.PersistentAclFactory;
34 | import org.onesocialweb.openfire.model.vcard4.PersistentProfile;
35 |
36 | /**
37 | * The profile manager is a singleton class taking care of all the business
38 | * logic related to querying, creating, and updating a user profile.
39 | *
40 | * @author eschenal
41 | *
42 | */
43 | public class ProfileManager {
44 |
45 | /**
46 | * Singleton: keep a static reference to teh only instance
47 | */
48 | private static ProfileManager instance;
49 |
50 | private final AclFactory aclFactory;
51 |
52 | public static ProfileManager getInstance() {
53 | if (instance == null) {
54 | instance = new ProfileManager();
55 | }
56 | return instance;
57 | }
58 |
59 | /**
60 | * Retrieves the profile of the target entity has can be seen by the
61 | * requesting entity.
62 | *
63 | * TODO ACL is not yet implemented. All fields are returned at this stage.
64 | *
65 | * @param requestorJID
66 | * the entity requesting the profile
67 | * @param targetJID
68 | * the entity whose profile is requested
69 | * @return the profile of the target entity as can be seen by the requesting
70 | * entity.
71 | * @throws UserNotFoundException
72 | */
73 | public Profile getProfile(String requestorJID, String targetJID) throws UserNotFoundException {
74 | final EntityManager em = OswPlugin.getEmFactory().createEntityManager();
75 | PersistentProfile profile = em.find(PersistentProfile.class, targetJID);
76 | em.close();
77 | if (profile != null) {
78 | if (requestorJID.equals(targetJID)) {
79 | return profile;
80 | } else {
81 | // We should filter all fields that the requestor is not
82 | // supposed to see and strip all data related to ACLs.
83 |
84 | final AclAction viewAction = aclFactory.aclAction(AclAction.ACTION_VIEW, AclAction.PERMISSION_GRANT);
85 | List fields =profile.getFields();
86 | List canSeefields= new ArrayList();
87 | for (Field field: fields)
88 | {
89 | boolean canSee=false;
90 | List rules= field.getAclRules();
91 | //this is a patch, so that the profile and its fields can be retrieved even when the acl rules where not set...
92 | // currently the vodafonernd.com DB has many profiles without any ACL rules, which retrieves empty profiles...
93 | if (rules.isEmpty())
94 | canSee=true;
95 | for (AclRule rule: rules)
96 | {
97 | if ((rule.hasAction(viewAction)) && (AclManager.canSee(targetJID, rule, requestorJID)))
98 | canSee=true;
99 | }
100 | if (canSee)
101 | canSeefields.add(field);
102 | }
103 |
104 | profile.removeAll();
105 | try{
106 | for (Field f: canSeefields){
107 | f.setAclRules(new ArrayList());
108 | profile.addField(f);
109 | }
110 | }catch (CardinalityException ce){
111 | }catch (UnsupportedFieldException ufe){
112 | }
113 | return profile;
114 | }
115 | } else {
116 | return null;
117 | }
118 | }
119 |
120 | /**
121 | * Create or update the profile of a user.
122 | *
123 | * If the user already has a profile defined, that profile will first be deleted and
124 | * replaced by the new profile.
125 | *
126 | * @param userJID the user whose profile is to be changed
127 | * @param profile the new profile
128 | * @throws UserNotFoundException
129 | */
130 | public void publishProfile(String userJID, Profile profile) throws UserNotFoundException {
131 | // open a transaction since we want delete and update to be atomical
132 | final EntityManager em = OswPlugin.getEmFactory().createEntityManager();
133 | em.getTransaction().begin();
134 |
135 | // Overide the user to avoid spoofing
136 | profile.setUserId(userJID);
137 |
138 | // Remove an old profile
139 | PersistentProfile oldProfile = em.find(PersistentProfile.class, userJID);
140 | if (oldProfile != null) {
141 | em.remove(oldProfile);
142 | }
143 |
144 | // Persist the profile
145 | em.persist(profile);
146 |
147 | // Safe to commit here
148 | em.getTransaction().commit();
149 | em.close();
150 | }
151 |
152 | /**
153 | * Private constructor to enforce the singleton
154 | */
155 | private ProfileManager() {
156 | //
157 | aclFactory = new PersistentAclFactory();
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/ActivityMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model;
18 |
19 | import java.util.Date;
20 |
21 | import org.onesocialweb.model.activity.ActivityEntry;
22 |
23 | public interface ActivityMessage {
24 |
25 | public String getSender();
26 |
27 | public void setSender(String fromJID);
28 |
29 | public String getRecipient();
30 |
31 | public void setRecipient(String toJID);
32 |
33 | public Date getReceived();
34 |
35 | public void setReceived(Date received);
36 |
37 | public ActivityEntry getActivity();
38 |
39 | public void setActivity(ActivityEntry activity);
40 |
41 | }
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/FileEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model;
18 |
19 | public interface FileEntry {
20 |
21 | public String getId();
22 |
23 | public void setId(String id);
24 |
25 | public String getName();
26 |
27 | public void setName(String name);
28 |
29 | public String getType();
30 |
31 | public void setType(String type);
32 |
33 | public String getOwner();
34 |
35 | public void setOwner(String owner);
36 |
37 | public long getSize();
38 |
39 | public void setSize(long size);
40 |
41 | }
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/PersistentActivityMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model;
18 |
19 | import java.util.Date;
20 |
21 | import javax.persistence.Basic;
22 | import javax.persistence.CascadeType;
23 | import javax.persistence.Entity;
24 | import javax.persistence.FetchType;
25 | import javax.persistence.OneToOne;
26 | import javax.persistence.Temporal;
27 | import javax.persistence.TemporalType;
28 |
29 | import org.onesocialweb.model.activity.ActivityEntry;
30 | import org.onesocialweb.openfire.model.activity.PersistentActivityEntry;
31 |
32 | @Entity(name = "Messages")
33 | public class PersistentActivityMessage implements ActivityMessage {
34 |
35 | @Basic
36 | private String sender;
37 |
38 | @Basic
39 | private String recipient;
40 |
41 | @Temporal(TemporalType.TIMESTAMP)
42 | private Date received;
43 |
44 | @OneToOne(cascade = CascadeType.ALL, targetEntity = PersistentActivityEntry.class, fetch = FetchType.EAGER)
45 | private ActivityEntry activity;
46 |
47 | @Override
48 | public String getSender() {
49 | return sender;
50 | }
51 |
52 | @Override
53 | public void setSender(String fromJID) {
54 | this.sender = fromJID;
55 | }
56 |
57 | /*
58 | * (non-Javadoc)
59 | *
60 | * @see org.onesocialweb.openfire.model.ActivityMessage#getRecipient()
61 | */
62 | @Override
63 | public String getRecipient() {
64 | return recipient;
65 | }
66 |
67 | /*
68 | * (non-Javadoc)
69 | *
70 | * @see
71 | * org.onesocialweb.openfire.model.ActivityMessage#setRecipient(java.lang
72 | * .String)
73 | */
74 | @Override
75 | public void setRecipient(String userJID) {
76 | this.recipient = userJID;
77 | }
78 |
79 | /*
80 | * (non-Javadoc)
81 | *
82 | * @see org.onesocialweb.openfire.model.ActivityMessage#getReceived()
83 | */
84 | public Date getReceived() {
85 | return received;
86 | }
87 |
88 | /*
89 | * (non-Javadoc)
90 | *
91 | * @see
92 | * org.onesocialweb.openfire.model.ActivityMessage#setReceived(java.util
93 | * .Date)
94 | */
95 | public void setReceived(Date received) {
96 | this.received = received;
97 | }
98 |
99 | /*
100 | * (non-Javadoc)
101 | *
102 | * @see org.onesocialweb.openfire.model.ActivityMessage#getActivity()
103 | */
104 | public ActivityEntry getActivity() {
105 | return activity;
106 | }
107 |
108 | /*
109 | * (non-Javadoc)
110 | *
111 | * @see
112 | * org.onesocialweb.openfire.model.ActivityMessage#setActivity(org.onesocialweb
113 | * .model.activity.ActivityEntry)
114 | */
115 | public void setActivity(ActivityEntry activity) {
116 | this.activity = activity;
117 | }
118 |
119 | }
120 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/PersistentFileEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model;
18 |
19 | import javax.persistence.Basic;
20 | import javax.persistence.Entity;
21 | import javax.persistence.Id;
22 |
23 | @Entity
24 | public class PersistentFileEntry implements FileEntry {
25 |
26 | @Id
27 | private String id;
28 |
29 | @Basic
30 | private String name;
31 |
32 | @Basic
33 | private String type;
34 |
35 | @Basic
36 | private String owner;
37 |
38 | @Basic
39 | private long size;
40 |
41 | /* (non-Javadoc)
42 | * @see org.onesocialweb.openfire.model.FileEntry#getId()
43 | */
44 | public String getId() {
45 | return id;
46 | }
47 |
48 | /* (non-Javadoc)
49 | * @see org.onesocialweb.openfire.model.FileEntry#setId(java.lang.String)
50 | */
51 | public void setId(String id) {
52 | this.id = id;
53 | }
54 |
55 | /* (non-Javadoc)
56 | * @see org.onesocialweb.openfire.model.FileEntry#getName()
57 | */
58 | public String getName() {
59 | return name;
60 | }
61 |
62 | /* (non-Javadoc)
63 | * @see org.onesocialweb.openfire.model.FileEntry#setName(java.lang.String)
64 | */
65 | public void setName(String name) {
66 | this.name = name;
67 | }
68 |
69 | /* (non-Javadoc)
70 | * @see org.onesocialweb.openfire.model.FileEntry#getType()
71 | */
72 | public String getType() {
73 | return type;
74 | }
75 |
76 | /* (non-Javadoc)
77 | * @see org.onesocialweb.openfire.model.FileEntry#setType(java.lang.String)
78 | */
79 | public void setType(String type) {
80 | this.type = type;
81 | }
82 |
83 | /* (non-Javadoc)
84 | * @see org.onesocialweb.openfire.model.FileEntry#getOwner()
85 | */
86 | public String getOwner() {
87 | return owner;
88 | }
89 |
90 | /* (non-Javadoc)
91 | * @see org.onesocialweb.openfire.model.FileEntry#setOwner(java.lang.String)
92 | */
93 | public void setOwner(String owner) {
94 | this.owner = owner;
95 | }
96 |
97 | /* (non-Javadoc)
98 | * @see org.onesocialweb.openfire.model.FileEntry#getSize()
99 | */
100 | public long getSize() {
101 | return size;
102 | }
103 |
104 | /* (non-Javadoc)
105 | * @see org.onesocialweb.openfire.model.FileEntry#setSize(long)
106 | */
107 | public void setSize(long size) {
108 | this.size = size;
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/PersistentSubscription.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model;
18 |
19 | import java.util.Date;
20 |
21 | import javax.persistence.Basic;
22 | import javax.persistence.Entity;
23 | import javax.persistence.Temporal;
24 | import javax.persistence.TemporalType;
25 |
26 | @Entity(name="Subscriptions")
27 | public class PersistentSubscription implements Subscription {
28 |
29 | @Basic
30 | private String subscriber;
31 |
32 | @Basic
33 | private String target;
34 |
35 | @Temporal(TemporalType.TIMESTAMP)
36 | private Date created;
37 |
38 | /* (non-Javadoc)
39 | * @see org.onesocialweb.openfire.database.model.Subscription#getCreated()
40 | */
41 | public Date getCreated() {
42 | return created;
43 | }
44 |
45 | /* (non-Javadoc)
46 | * @see org.onesocialweb.openfire.database.model.Subscription#setCreated(java.util.Date)
47 | */
48 | public void setCreated(Date created) {
49 | this.created = created;
50 | }
51 |
52 | /* (non-Javadoc)
53 | * @see org.onesocialweb.openfire.database.model.Subscription#getSubscriber()
54 | */
55 | public String getSubscriber() {
56 | return subscriber;
57 | }
58 |
59 | /* (non-Javadoc)
60 | * @see org.onesocialweb.openfire.database.model.Subscription#setSubscriber(java.lang.String)
61 | */
62 | public void setSubscriber(String subscriber) {
63 | this.subscriber = subscriber;
64 | }
65 |
66 | /* (non-Javadoc)
67 | * @see org.onesocialweb.openfire.database.model.Subscription#getTarget()
68 | */
69 | public String getTarget() {
70 | return target;
71 | }
72 |
73 | /* (non-Javadoc)
74 | * @see org.onesocialweb.openfire.database.model.Subscription#setTarget(java.lang.String)
75 | */
76 | public void setTarget(String target) {
77 | this.target = target;
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/Subscription.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model;
18 |
19 | import java.util.Date;
20 |
21 | public interface Subscription {
22 |
23 | public Date getCreated();
24 |
25 | public void setCreated(Date created);
26 |
27 | public String getSubscriber();
28 |
29 | public void setSubscriber(String subscriber);
30 |
31 | public String getTarget();
32 |
33 | public void setTarget(String target);
34 |
35 | }
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/acl/PersistentAclAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.acl;
18 |
19 | import javax.persistence.Basic;
20 | import javax.persistence.Entity;
21 |
22 | import org.onesocialweb.model.acl.AclAction;
23 |
24 | @Entity(name="AclAction")
25 | public class PersistentAclAction implements AclAction {
26 |
27 | @Basic
28 | private String name;
29 |
30 | @Basic
31 | private String permission;
32 |
33 | @Override
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | @Override
39 | public String getPermission() {
40 | return permission;
41 | }
42 |
43 | @Override
44 | public void setName(String name) {
45 | this.name = name;
46 | }
47 |
48 | @Override
49 | public void setPermission(String permission) {
50 | this.permission = permission;
51 | }
52 |
53 | @Override
54 | public boolean hasName() {
55 | return (name != null && !name.isEmpty());
56 | }
57 |
58 | @Override
59 | public boolean hasPermission() {
60 | return (permission != null && !permission.isEmpty());
61 | }
62 |
63 | @Override
64 | public boolean equals(Object obj) {
65 | if (obj instanceof AclAction) {
66 | AclAction other = (AclAction) obj;
67 | return (other.getPermission().equals(permission) && other.getName()
68 | .equals(name));
69 | } else {
70 | return false;
71 | }
72 | }
73 |
74 | @Override
75 | public String toString() {
76 | StringBuffer buffer = new StringBuffer();
77 | buffer.append("[AclAction ");
78 | if (name != null) {
79 | buffer.append("name:" + name + " ");
80 | }
81 | if (permission != null) {
82 | buffer.append("permission:" + permission + " ");
83 | }
84 | buffer.append("]");
85 | return buffer.toString();
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/acl/PersistentAclDomReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.acl;
18 |
19 | import org.onesocialweb.model.acl.AclFactory;
20 | import org.onesocialweb.xml.dom.AclDomReader;
21 |
22 | public class PersistentAclDomReader extends AclDomReader {
23 |
24 | @Override
25 | protected AclFactory getAclFactory() {
26 | return new PersistentAclFactory();
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/acl/PersistentAclFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.acl;
18 |
19 | import org.onesocialweb.model.acl.AclAction;
20 | import org.onesocialweb.model.acl.AclFactory;
21 | import org.onesocialweb.model.acl.AclRule;
22 | import org.onesocialweb.model.acl.AclSubject;
23 |
24 | public class PersistentAclFactory extends AclFactory {
25 |
26 | @Override
27 | public AclAction aclAction() {
28 | return new PersistentAclAction();
29 | }
30 |
31 | @Override
32 | public AclRule aclRule() {
33 | return new PersistentAclRule();
34 | }
35 |
36 | @Override
37 | public AclSubject aclSubject() {
38 | return new PersistentAclSubject();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/acl/PersistentAclRule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.acl;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import javax.persistence.CascadeType;
23 | import javax.persistence.Entity;
24 | import javax.persistence.FetchType;
25 | import javax.persistence.OneToMany;
26 |
27 | import org.onesocialweb.model.acl.AclAction;
28 | import org.onesocialweb.model.acl.AclRule;
29 | import org.onesocialweb.model.acl.AclSubject;
30 |
31 | @Entity(name="AclRule")
32 | public class PersistentAclRule implements AclRule {
33 |
34 | @OneToMany(cascade=CascadeType.ALL, targetEntity=org.onesocialweb.openfire.model.acl.PersistentAclSubject.class, fetch=FetchType.EAGER)
35 | private List subjects = new ArrayList();
36 |
37 | @OneToMany(cascade=CascadeType.ALL, targetEntity=org.onesocialweb.openfire.model.acl.PersistentAclAction.class, fetch=FetchType.EAGER)
38 | private List actions = new ArrayList();
39 |
40 | @Override
41 | public List getActions() {
42 | return actions;
43 | }
44 |
45 | @Override
46 | public void setActions(List actions) {
47 | this.actions = actions;
48 | }
49 |
50 | @Override
51 | public List getSubjects() {
52 | return subjects;
53 | }
54 |
55 | @Override
56 | public void setSubjects(List subjects) {
57 | this.subjects = subjects;
58 | }
59 |
60 | @Override
61 | public void addAction(AclAction action) {
62 | this.actions.add(action);
63 | }
64 |
65 | @Override
66 | public void addSubject(AclSubject subject) {
67 | this.subjects.add(subject);
68 | }
69 |
70 | @Override
71 | public void removeAction(AclAction action) {
72 | this.actions.remove(action);
73 | }
74 |
75 | @Override
76 | public void removeSubject(AclSubject subject) {
77 | this.subjects.remove(subject);
78 | }
79 |
80 | @Override
81 | public boolean equals(Object obj) {
82 | if (obj instanceof AclRule) {
83 | AclRule rule = (AclRule) obj;
84 | return actions.equals(rule.getActions())
85 | && subjects.equals(rule.getSubjects());
86 | } else {
87 | return false;
88 | }
89 | }
90 |
91 | @Override
92 | public String toString() {
93 | StringBuffer buffer = new StringBuffer();
94 | buffer.append("[AclRule ");
95 | for (AclAction action : actions) {
96 | buffer.append(action);
97 | }
98 | for (AclSubject subject : subjects) {
99 | buffer.append(subject);
100 | }
101 | buffer.append("]");
102 | return buffer.toString();
103 | }
104 |
105 | @Override
106 | public boolean hasAction(AclAction action) {
107 | if (actions == null || action == null) return false;
108 |
109 | for (AclAction target : actions) {
110 | if (target.equals(action)) {
111 | return true;
112 | }
113 | }
114 |
115 | return false;
116 | }
117 |
118 | @Override
119 | public boolean hasSubject(AclSubject subject) {
120 | if (subjects == null || subject == null) return false;
121 |
122 | for (AclSubject target : subjects) {
123 | if (target.equals(subject)) {
124 | return true;
125 | }
126 | }
127 |
128 | return false;
129 | }
130 |
131 | @Override
132 | public boolean hasActions() {
133 | return (actions != null && !actions.isEmpty());
134 | }
135 |
136 | @Override
137 | public boolean hasSubjects() {
138 | return (subjects != null && !subjects.isEmpty());
139 | }
140 |
141 | @Override
142 | public List getActions(String name, String permission) {
143 | List result = new ArrayList();
144 |
145 | if (actions == null) return result;
146 |
147 | for (AclAction target : actions) {
148 | if (target.getName().equals(name) && target.getPermission().equals(permission)) {
149 | result.add(target);
150 | }
151 | }
152 |
153 | return result;
154 | }
155 |
156 | @Override
157 | public List getSubjects(String type) {
158 | List result = new ArrayList();
159 |
160 | if (subjects == null || type == null) return result;
161 |
162 | for (AclSubject aclSubject : result) {
163 | if (aclSubject.getType().equals(type)) {
164 | result.add(aclSubject);
165 | }
166 | }
167 |
168 | return result;
169 | }
170 |
171 | }
172 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/acl/PersistentAclSubject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.acl;
18 |
19 | import javax.persistence.Basic;
20 | import javax.persistence.Entity;
21 |
22 | import org.onesocialweb.model.acl.AclSubject;
23 |
24 | @Entity(name="AclSubject")
25 | public class PersistentAclSubject implements AclSubject {
26 |
27 | @Basic
28 | private String name;
29 |
30 | @Basic
31 | private String type;
32 |
33 | @Override
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | @Override
39 | public String getType() {
40 | return type;
41 | }
42 |
43 | @Override
44 | public void setName(String name) {
45 | this.name = name;
46 | }
47 |
48 | @Override
49 | public void setType(String type) {
50 | this.type = type;
51 | }
52 |
53 | @Override
54 | public boolean hasName() {
55 | return (name != null && !name.isEmpty());
56 | }
57 |
58 | @Override
59 | public boolean hasType() {
60 | return (type != null && !type.isEmpty());
61 | }
62 |
63 | @Override
64 | public boolean equals(Object obj) {
65 | if (obj instanceof AclSubject) {
66 | AclSubject other = (AclSubject) obj;
67 | return other.getName().equals(name) && other.getType().equals(type);
68 | } else {
69 | return false;
70 | }
71 | }
72 |
73 | @Override
74 | public String toString() {
75 | StringBuffer buffer = new StringBuffer();
76 | buffer.append("[AclSubject ");
77 | if (name != null) {
78 | buffer.append("name:" + name + " ");
79 | }
80 | if (type != null) {
81 | buffer.append("type:" + type + " ");
82 | }
83 | buffer.append("]");
84 | return buffer.toString();
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/activity/PersistentActivityActor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.activity;
18 |
19 | import javax.persistence.Entity;
20 |
21 | import org.onesocialweb.model.activity.ActivityActor;
22 | import org.onesocialweb.openfire.model.atom.PersistentAtomPerson;
23 |
24 | @Entity(name="ActivityActor")
25 | public class PersistentActivityActor extends PersistentAtomPerson implements ActivityActor {
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/activity/PersistentActivityDomReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.activity;
18 |
19 | import java.util.Date;
20 |
21 | import org.onesocialweb.model.activity.ActivityFactory;
22 | import org.onesocialweb.model.atom.DefaultAtomHelper;
23 | import org.onesocialweb.openfire.model.acl.PersistentAclDomReader;
24 | import org.onesocialweb.openfire.model.atom.PersistentAtomDomReader;
25 | import org.onesocialweb.xml.dom.AclDomReader;
26 | import org.onesocialweb.xml.dom.ActivityDomReader;
27 | import org.onesocialweb.xml.dom.AtomDomReader;
28 |
29 | public class PersistentActivityDomReader extends ActivityDomReader {
30 |
31 | @Override
32 | protected AclDomReader getAclDomReader() {
33 | return new PersistentAclDomReader();
34 | }
35 |
36 | @Override
37 | protected ActivityFactory getActivityFactory() {
38 | return new PersistentActivityFactory();
39 | }
40 |
41 | @Override
42 | protected AtomDomReader getAtomDomReader() {
43 | return new PersistentAtomDomReader();
44 | }
45 |
46 | @Override
47 | protected Date parseDate(String atomDate) {
48 | return DefaultAtomHelper.parseDate(atomDate);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/activity/PersistentActivityEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.activity;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import javax.persistence.CascadeType;
23 | import javax.persistence.Entity;
24 | import javax.persistence.FetchType;
25 | import javax.persistence.Inheritance;
26 | import javax.persistence.InheritanceType;
27 | import javax.persistence.OneToMany;
28 | import javax.persistence.OneToOne;
29 | import javax.persistence.Table;
30 |
31 | import org.onesocialweb.model.acl.AclRule;
32 | import org.onesocialweb.model.activity.ActivityActor;
33 | import org.onesocialweb.model.activity.ActivityEntry;
34 | import org.onesocialweb.model.activity.ActivityObject;
35 | import org.onesocialweb.model.activity.ActivityVerb;
36 | import org.onesocialweb.openfire.model.acl.PersistentAclRule;
37 | import org.onesocialweb.openfire.model.atom.PersistentAtomEntry;
38 |
39 | @Entity(name="ActivityEntry")
40 | @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
41 | @Table(name="Activities")
42 | public class PersistentActivityEntry extends PersistentAtomEntry implements ActivityEntry {
43 |
44 | @OneToOne(cascade=CascadeType.ALL, targetEntity=PersistentActivityActor.class, fetch=FetchType.EAGER)
45 | private ActivityActor actor;
46 |
47 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentAclRule.class, fetch=FetchType.EAGER)
48 | private List rules = new ArrayList();
49 |
50 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentActivityObject.class, fetch=FetchType.EAGER)
51 | private List objects = new ArrayList();
52 |
53 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentActivityVerb.class, fetch=FetchType.EAGER)
54 | private List verbs = new ArrayList();
55 |
56 | @Override
57 | public void addObject(ActivityObject object) {
58 | this.objects.add(object);
59 | }
60 |
61 | @Override
62 | public void addVerb(ActivityVerb verb) {
63 | this.verbs.add(verb);
64 | }
65 |
66 | @Override
67 | public void addAclRule(AclRule rule) {
68 | this.rules.add(rule);
69 | }
70 |
71 | @Override
72 | public List getAclRules() {
73 | return rules;
74 | }
75 |
76 | @Override
77 | public ActivityActor getActor() {
78 | return actor;
79 | }
80 |
81 | @Override
82 | public List getObjects() {
83 | return objects;
84 | }
85 |
86 | @Override
87 | public List getVerbs() {
88 | return verbs;
89 | }
90 |
91 | @Override
92 | public void removeObject(ActivityObject object) {
93 | this.objects.remove(object);
94 | }
95 |
96 | @Override
97 | public void removeVerb(ActivityVerb verb) {
98 | this.verbs.remove(verb);
99 | }
100 |
101 | @Override
102 | public void removeAclRule(AclRule rule) {
103 | this.rules.remove(rule);
104 | }
105 |
106 | @Override
107 | public void setAclRules(List rules) {
108 | this.rules = rules;
109 | }
110 |
111 | @Override
112 | public void setActor(final ActivityActor actor) {
113 | this.actor = actor;
114 | }
115 |
116 | @Override
117 | public void setObjects(List objects) {
118 | this.objects = objects;
119 | }
120 |
121 | @Override
122 | public void setVerbs(final List verbs) {
123 | this.verbs = verbs;
124 | }
125 |
126 | @Override
127 | public String toString() {
128 | StringBuffer buffer = new StringBuffer();
129 | buffer.append("[ActivityEntry ");
130 | buffer.append(super.toString());
131 | if (actor != null) {
132 | buffer.append("actor:" + actor + " ");
133 | }
134 | for (ActivityVerb verb : verbs) {
135 | buffer.append(verb.toString());
136 | }
137 | for (ActivityObject object : objects) {
138 | buffer.append(object.toString());
139 | }
140 | for (AclRule rule : rules) {
141 | buffer.append(rule.toString());
142 | }
143 | buffer.append("]");
144 | return buffer.toString();
145 | }
146 |
147 | @Override
148 | public boolean hasAclRules() {
149 | return (rules != null && rules.size() > 0);
150 | }
151 |
152 | @Override
153 | public boolean hasActor() {
154 | return (actor != null);
155 | }
156 |
157 | @Override
158 | public boolean hasObjects() {
159 | return (objects != null && objects.size() > 0);
160 | }
161 |
162 | @Override
163 | public boolean hasVerbs() {
164 | return (verbs != null && verbs.size() > 0);
165 | }
166 |
167 | }
168 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/activity/PersistentActivityFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.activity;
18 |
19 | import org.onesocialweb.model.activity.ActivityActor;
20 | import org.onesocialweb.model.activity.ActivityEntry;
21 | import org.onesocialweb.model.activity.ActivityFactory;
22 | import org.onesocialweb.model.activity.ActivityObject;
23 | import org.onesocialweb.model.activity.ActivityVerb;
24 |
25 | public class PersistentActivityFactory extends ActivityFactory {
26 |
27 | @Override
28 | public ActivityActor actor() {
29 | return new PersistentActivityActor();
30 | }
31 |
32 | @Override
33 | public ActivityEntry entry() {
34 | return new PersistentActivityEntry();
35 | }
36 |
37 | @Override
38 | public ActivityObject object() {
39 | return new PersistentActivityObject();
40 | }
41 |
42 | @Override
43 | public ActivityVerb verb() {
44 | return new PersistentActivityVerb();
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/activity/PersistentActivityObject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.activity;
18 |
19 | import javax.persistence.Basic;
20 | import javax.persistence.Entity;
21 | import javax.persistence.Inheritance;
22 | import javax.persistence.InheritanceType;
23 | import javax.persistence.Table;
24 |
25 | import org.onesocialweb.model.activity.ActivityObject;
26 | import org.onesocialweb.openfire.model.atom.PersistentAtomEntry;
27 |
28 | @Entity(name="ActivityObject")
29 | @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
30 | @Table(name="Objects")
31 | public class PersistentActivityObject extends PersistentAtomEntry implements ActivityObject {
32 |
33 | @Basic
34 | private String type;
35 |
36 | @Override
37 | public String getType() {
38 | return type;
39 | }
40 |
41 | @Override
42 | public void setType(String type) {
43 | this.type = type;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/activity/PersistentActivityVerb.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.activity;
18 |
19 | import javax.persistence.Basic;
20 | import javax.persistence.Entity;
21 |
22 | import org.onesocialweb.model.activity.ActivityVerb;
23 |
24 | @Entity(name="ActivityVerb")
25 | public class PersistentActivityVerb implements ActivityVerb {
26 |
27 | @Basic
28 | private String verb;
29 |
30 | @Override
31 | public String getValue() {
32 | return this.verb;
33 | }
34 |
35 | @Override
36 | public void setValue(String verb) {
37 | this.verb = verb;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/atom/PersistentAtomCategory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.atom;
18 |
19 | import javax.persistence.Basic;
20 | import javax.persistence.Entity;
21 |
22 | import org.onesocialweb.model.atom.AtomCategory;
23 |
24 | @Entity(name="AtomCategory")
25 | public class PersistentAtomCategory extends PersistentAtomCommon implements AtomCategory {
26 |
27 | @Basic
28 | private String label;
29 |
30 | @Basic
31 | private String scheme;
32 |
33 | @Basic
34 | private String term;
35 |
36 | @Override
37 | public String getLabel() {
38 | return label;
39 | }
40 |
41 | @Override
42 | public String getScheme() {
43 | return scheme;
44 | }
45 |
46 | @Override
47 | public String getTerm() {
48 | return term;
49 | }
50 |
51 | @Override
52 | public boolean hasLabel() {
53 | return (label != null);
54 | }
55 |
56 | @Override
57 | public boolean hasScheme() {
58 | return scheme != null;
59 | }
60 |
61 | @Override
62 | public boolean hasTerm() {
63 | return term != null;
64 | }
65 |
66 | @Override
67 | public void setLabel(final String label) {
68 | this.label = label;
69 | }
70 |
71 | @Override
72 | public void setScheme(final String scheme) {
73 | this.scheme = scheme;
74 | }
75 |
76 | @Override
77 | public void setTerm(final String term) {
78 | this.term = term;
79 | }
80 |
81 | @Override
82 | public String toString() {
83 | StringBuffer buffer = new StringBuffer();
84 | buffer.append("[AtomCategory ");
85 | if (label != null) {
86 | buffer.append("label:" + label + " ");
87 | }
88 | if (term != null) {
89 | buffer.append("term:" + term + " ");
90 | }
91 | if (scheme != null) {
92 | buffer.append("scheme:" + scheme + " ");
93 | }
94 | buffer.append("]");
95 | return buffer.toString();
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/atom/PersistentAtomCommon.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.atom;
18 |
19 | import javax.persistence.MappedSuperclass;
20 |
21 | import org.onesocialweb.model.atom.AtomCommon;
22 |
23 | @MappedSuperclass
24 | public class PersistentAtomCommon implements AtomCommon {
25 |
26 | private String xmlBase;
27 |
28 | private String xmlLang;
29 |
30 | @Override
31 | public String getXmlBase() {
32 | return xmlBase;
33 | }
34 |
35 | @Override
36 | public String getXmlLang() {
37 | return xmlLang;
38 | }
39 |
40 | @Override
41 | public void setXmlBase(String xmlBase) {
42 | this.xmlBase = xmlBase;
43 | }
44 |
45 | @Override
46 | public void setXmlLang(String xmlLang) {
47 | this.xmlLang = xmlLang;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/atom/PersistentAtomContent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.atom;
18 |
19 | import javax.persistence.Basic;
20 | import javax.persistence.Entity;
21 |
22 | import org.onesocialweb.model.atom.AtomContent;
23 |
24 | @Entity(name="AtomContent")
25 | public class PersistentAtomContent extends PersistentAtomCommon implements AtomContent {
26 |
27 | @Basic
28 | private String src;
29 |
30 | @Basic
31 | private String type;
32 |
33 | @Basic
34 | private String value;
35 |
36 | @Override
37 | public String getSrc() {
38 | return src;
39 | }
40 |
41 | @Override
42 | public String getType() {
43 | return type;
44 | }
45 |
46 | @Override
47 | public String getValue() {
48 | return value;
49 | }
50 |
51 | @Override
52 | public void setSrc(final String src) {
53 | this.src = src;
54 | }
55 |
56 | @Override
57 | public void setType(final String type) {
58 | this.type = type;
59 | }
60 |
61 | @Override
62 | public void setValue(final String value) {
63 | this.value = value;
64 | }
65 |
66 | @Override
67 | public String toString() {
68 | StringBuffer buffer = new StringBuffer();
69 | buffer.append("[AtomContent ");
70 | if (type != null) {
71 | buffer.append("type:" + type + " ");
72 | }
73 | if (src != null) {
74 | buffer.append("src:" + src + " ");
75 | }
76 | if (value != null) {
77 | buffer.append("value:" + value + " ");
78 | }
79 | buffer.append("]");
80 |
81 | return buffer.toString();
82 | }
83 |
84 | @Override
85 | public boolean hasSrc() {
86 | return (src != null);
87 | }
88 |
89 | @Override
90 | public boolean hasType() {
91 | return (type != null);
92 | }
93 |
94 | @Override
95 | public boolean hasValue() {
96 | return (value != null);
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/atom/PersistentAtomDomReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.atom;
18 |
19 | import java.util.Date;
20 |
21 | import org.onesocialweb.model.atom.AtomFactory;
22 | import org.onesocialweb.model.atom.DefaultAtomHelper;
23 | import org.onesocialweb.xml.dom.AtomDomReader;
24 |
25 |
26 | public class PersistentAtomDomReader extends AtomDomReader {
27 |
28 | @Override
29 | protected AtomFactory getAtomFactory() {
30 | return new PersistentAtomFactory();
31 | }
32 |
33 | @Override
34 | protected Date parseDate(String atomDate) {
35 | return DefaultAtomHelper.parseDate(atomDate);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/atom/PersistentAtomFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.atom;
18 |
19 | import org.onesocialweb.model.atom.AtomCategory;
20 | import org.onesocialweb.model.atom.AtomContent;
21 | import org.onesocialweb.model.atom.AtomEntry;
22 | import org.onesocialweb.model.atom.AtomFactory;
23 | import org.onesocialweb.model.atom.AtomLink;
24 | import org.onesocialweb.model.atom.AtomPerson;
25 | import org.onesocialweb.model.atom.AtomReplyTo;
26 | import org.onesocialweb.model.atom.AtomSource;
27 |
28 | public class PersistentAtomFactory extends AtomFactory {
29 |
30 | @Override
31 | public AtomCategory category() {
32 | return new PersistentAtomCategory();
33 | }
34 |
35 | @Override
36 | public AtomContent content() {
37 | return new PersistentAtomContent();
38 | }
39 |
40 | @Override
41 | public AtomEntry entry() {
42 | return new PersistentAtomEntry();
43 | }
44 |
45 | @Override
46 | public AtomLink link() {
47 | return new PersistentAtomLink();
48 | }
49 |
50 | @Override
51 | public AtomPerson person() {
52 | return new PersistentAtomPerson();
53 | }
54 |
55 | @Override
56 | public AtomSource source() {
57 | return new PersistentAtomSource();
58 | }
59 |
60 | @Override
61 | public AtomReplyTo reply() {
62 | return new PersistentAtomReplyTo();
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/atom/PersistentAtomLink.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.atom;
18 |
19 | import javax.persistence.Basic;
20 | import javax.persistence.Entity;
21 |
22 | import org.onesocialweb.model.atom.AtomLink;
23 |
24 | @Entity(name="AtomLink")
25 | public class PersistentAtomLink extends PersistentAtomCommon implements AtomLink {
26 |
27 | @Basic
28 | private String href;
29 |
30 | @Basic
31 | private String hrefLang;
32 |
33 | @Basic
34 | private String rel;
35 |
36 | @Basic
37 | private String title;
38 |
39 | @Basic
40 | private String type;
41 |
42 | @Basic
43 | private String length;
44 |
45 | @Override
46 | public String getHref() {
47 | return href;
48 | }
49 |
50 | @Override
51 | public String getHreflang() {
52 | return hrefLang;
53 | }
54 |
55 | @Override
56 | public String getLength() {
57 | return length;
58 | }
59 |
60 | @Override
61 | public String getRel() {
62 | return rel;
63 | }
64 |
65 | @Override
66 | public String getTitle() {
67 | return title;
68 | }
69 |
70 | @Override
71 | public String getType() {
72 | return type;
73 | }
74 |
75 | @Override
76 | public void setHref(final String href) {
77 | this.href = href;
78 | }
79 |
80 | @Override
81 | public void setHreflang(final String hreflang) {
82 | this.hrefLang = hreflang;
83 | }
84 |
85 | @Override
86 | public void setLength(final String length) {
87 | this.length = length;
88 | }
89 |
90 | @Override
91 | public void setRel(final String rel) {
92 | this.rel = rel;
93 | }
94 |
95 | @Override
96 | public void setTitle(final String title) {
97 | this.title = title;
98 | }
99 |
100 | @Override
101 | public void setType(final String type) {
102 | this.type = type;
103 | }
104 |
105 | @Override
106 | public String toString() {
107 | StringBuffer buffer = new StringBuffer();
108 | buffer.append("[AtomLink ");
109 | if (href != null) {
110 | buffer.append("href:" + href + " ");
111 | }
112 | if (hrefLang != null) {
113 | buffer.append("hrefLang:" + hrefLang + " ");
114 | }
115 | if (length != null) {
116 | buffer.append("length:" + length + " ");
117 | }
118 | if (rel != null) {
119 | buffer.append("rel:" + rel + " ");
120 | }
121 | if (title != null) {
122 | buffer.append("title:" + title + " ");
123 | }
124 | if (type != null) {
125 | buffer.append("type:" + type + " ");
126 | }
127 | buffer.append("]");
128 | return buffer.toString();
129 | }
130 |
131 | @Override
132 | public boolean hasHref() {
133 | return href != null;
134 | }
135 |
136 | @Override
137 | public boolean hasHreflang() {
138 | return hrefLang != null;
139 | }
140 |
141 | @Override
142 | public boolean hasLength() {
143 | return length != null;
144 | }
145 |
146 | @Override
147 | public boolean hasRel() {
148 | return rel != null;
149 | }
150 |
151 | @Override
152 | public boolean hasTitle() {
153 | return title != null;
154 | }
155 |
156 | @Override
157 | public boolean hasType() {
158 | return type != null;
159 | }
160 |
161 | }
162 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/atom/PersistentAtomPerson.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.atom;
18 |
19 | import javax.persistence.Basic;
20 | import javax.persistence.Entity;
21 |
22 | import org.onesocialweb.model.atom.AtomPerson;
23 |
24 | @Entity(name="AtomPerson")
25 | public class PersistentAtomPerson extends PersistentAtomCommon implements AtomPerson {
26 |
27 | @Basic
28 | private String email;
29 |
30 | @Basic
31 | private String name;
32 |
33 | @Basic
34 | private String uri;
35 |
36 | @Override
37 | public String getEmail() {
38 | return email;
39 | }
40 |
41 | @Override
42 | public String getName() {
43 | return name;
44 | }
45 |
46 | @Override
47 | public String getUri() {
48 | return uri;
49 | }
50 |
51 | @Override
52 | public void setEmail(String email) {
53 | this.email = email;
54 | }
55 |
56 | @Override
57 | public void setName(String name) {
58 | this.name = name;
59 | }
60 |
61 | @Override
62 | public void setUri(String uri) {
63 | this.uri = uri;
64 | }
65 |
66 | @Override
67 | public String toString() {
68 | StringBuffer buffer = new StringBuffer();
69 | buffer.append("[AtomPerson ");
70 | if (name != null) {
71 | buffer.append("name:" + name + " ");
72 | }
73 | if (email != null) {
74 | buffer.append("email:" + email + " ");
75 | }
76 | if (uri != null) {
77 | buffer.append("uri:" + uri + " ");
78 | }
79 | buffer.append("]");
80 | return buffer.toString();
81 | }
82 |
83 | @Override
84 | public boolean hasEmail() {
85 | return email != null;
86 | }
87 |
88 | @Override
89 | public boolean hasName() {
90 | return name != null;
91 | }
92 |
93 | @Override
94 | public boolean hasUri() {
95 | return uri != null;
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/atom/PersistentAtomReplyTo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.atom;
18 |
19 | import javax.persistence.Basic;
20 |
21 | import javax.persistence.Entity;
22 |
23 | import org.onesocialweb.model.atom.AtomReplyTo;
24 | @Entity(name="AtomReplyTo")
25 | public class PersistentAtomReplyTo extends PersistentAtomCommon implements AtomReplyTo {
26 |
27 | @Basic
28 | private String ref;
29 |
30 | @Basic
31 | private String href;
32 |
33 | @Basic
34 | private String type;
35 |
36 | @Basic
37 | private String source;
38 |
39 | @Override
40 | public String getHref() {
41 | return href;
42 | }
43 |
44 | @Override
45 | public String getRef() {
46 | return ref;
47 | }
48 |
49 | @Override
50 | public String getSource() {
51 | return source;
52 | }
53 |
54 | @Override
55 | public String getType() {
56 | return type;
57 | }
58 |
59 | @Override
60 | public boolean hasHref() {
61 | return href != null;
62 | }
63 |
64 | @Override
65 | public boolean hasRef() {
66 | return ref != null;
67 | }
68 |
69 | @Override
70 | public boolean hasSource() {
71 | return source != null;
72 | }
73 |
74 | @Override
75 | public boolean hasType() {
76 | return type != null;
77 | }
78 |
79 | @Override
80 | public void setHref(String href) {
81 | this.href = href;
82 | }
83 |
84 | @Override
85 | public void setRef(String ref) {
86 | this.ref = ref;
87 | }
88 |
89 | @Override
90 | public void setSource(String source) {
91 | this.source = source;
92 | }
93 |
94 | @Override
95 | public void setType(String type) {
96 | this.type = type;
97 | }
98 |
99 |
100 | @Override
101 | public String toString() {
102 | StringBuffer buffer = new StringBuffer();
103 | buffer.append("[AtomLink ");
104 | if (href != null) {
105 | buffer.append("href:" + href + " ");
106 | }
107 | if (ref != null) {
108 | buffer.append("ref:" + ref + " ");
109 | }
110 | if (type != null) {
111 | buffer.append("type:" + type + " ");
112 | }
113 | if (source != null) {
114 | buffer.append("source:" + source + " ");
115 | }
116 | buffer.append("]");
117 | return buffer.toString();
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/atom/PersistentAtomSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.atom;
18 |
19 | import javax.persistence.Entity;
20 |
21 | import org.onesocialweb.model.atom.AtomSource;
22 |
23 | @Entity(name="AtomSource")
24 | public class PersistentAtomSource extends PersistentAtomCommon implements AtomSource {
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/relation/PersistentRelation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.relation;
18 | import java.util.ArrayList;
19 | import java.util.Date;
20 | import java.util.List;
21 |
22 | import javax.persistence.Basic;
23 | import javax.persistence.CascadeType;
24 | import javax.persistence.Embeddable;
25 | import javax.persistence.Entity;
26 | import javax.persistence.FetchType;
27 | import javax.persistence.OneToMany;
28 | import javax.persistence.Temporal;
29 | import javax.persistence.TemporalType;
30 |
31 | import org.onesocialweb.model.acl.AclRule;
32 | import org.onesocialweb.model.relation.Relation;
33 | import org.onesocialweb.openfire.model.acl.PersistentAclRule;
34 |
35 | @Embeddable
36 | @Entity(name="Relation")
37 | public class PersistentRelation implements Relation {
38 |
39 | @Basic
40 | private String guid;
41 |
42 | @Basic
43 | private String comment;
44 |
45 | @Basic
46 | private String origin;
47 |
48 | @Basic
49 | private String message;
50 |
51 | @Basic
52 | private String nature;
53 |
54 | @Basic
55 | private String owner;
56 |
57 | @Basic
58 | @Temporal(TemporalType.TIMESTAMP)
59 | private Date published;
60 |
61 | @Basic
62 | private String status;
63 |
64 | @Basic
65 | private String target;
66 |
67 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentAclRule.class, fetch=FetchType.EAGER)
68 | private List aclRules = new ArrayList();
69 |
70 | @Override
71 | public void addAclRule(AclRule rule) {
72 | this.aclRules.add(rule);
73 | }
74 |
75 | @Override
76 | public List getAclRules() {
77 | return aclRules;
78 | }
79 |
80 | @Override
81 | public String getComment() {
82 | return comment;
83 | }
84 |
85 | @Override
86 | public String getFrom() {
87 | return origin;
88 | }
89 |
90 | @Override
91 | public String getId() {
92 | return guid;
93 | }
94 |
95 | @Override
96 | public String getMessage() {
97 | return message;
98 | }
99 |
100 | @Override
101 | public String getNature() {
102 | return nature;
103 | }
104 |
105 | public String getOwner() {
106 | return owner;
107 | }
108 |
109 | @Override
110 | public Date getPublished() {
111 | return published;
112 | }
113 |
114 | @Override
115 | public String getStatus() {
116 | return status;
117 | }
118 |
119 | @Override
120 | public String getTo() {
121 | return target;
122 | }
123 |
124 | @Override
125 | public boolean hasAclRules() {
126 | return (aclRules != null && !aclRules.isEmpty());
127 | }
128 |
129 | @Override
130 | public boolean hasComment() {
131 | return (comment != null);
132 | }
133 |
134 | @Override
135 | public boolean hasFrom() {
136 | return (origin != null);
137 | }
138 |
139 | @Override
140 | public boolean hasId() {
141 | return (guid != null);
142 | }
143 |
144 | @Override
145 | public boolean hasMessage() {
146 | return (message != null);
147 | }
148 |
149 | @Override
150 | public boolean hasNature() {
151 | return (nature != null);
152 | }
153 |
154 | public boolean hasOwner() {
155 | return (owner != null);
156 | }
157 |
158 | @Override
159 | public boolean hasPublished() {
160 | return (published != null);
161 | }
162 |
163 | @Override
164 | public boolean hasStatus() {
165 | return (status != null);
166 | }
167 |
168 | @Override
169 | public boolean hasTo() {
170 | return (target != null);
171 | }
172 |
173 | @Override
174 | public void removeAclRule(AclRule rule) {
175 | this.aclRules.remove(rule);
176 | }
177 |
178 | @Override
179 | public void setAclRules(List rules) {
180 | this.aclRules = rules;
181 | }
182 |
183 | @Override
184 | public void setComment(String comment) {
185 | this.comment = comment;
186 | }
187 |
188 | @Override
189 | public void setFrom(String from) {
190 | this.origin = from;
191 | }
192 |
193 | @Override
194 | public void setId(String id) {
195 | this.guid = id;
196 | }
197 |
198 | @Override
199 | public void setMessage(String message) {
200 | this.message = message;
201 | }
202 |
203 | @Override
204 | public void setNature(String nature) {
205 | this.nature = nature;
206 | }
207 |
208 | public void setOwner(String owner) {
209 | this.owner = owner;
210 | }
211 |
212 | @Override
213 | public void setPublished(Date published) {
214 | this.published = published;
215 | }
216 |
217 | @Override
218 | public void setStatus(String status) {
219 | this.status = status;
220 | }
221 |
222 | @Override
223 | public void setTo(String to) {
224 | this.target = to;
225 | }
226 |
227 | @Override
228 | public String toString() {
229 | StringBuffer buffer = new StringBuffer();
230 | buffer.append("[Relation ");
231 | if (guid != null) {
232 | buffer.append("id:" + guid + " ");
233 | }
234 | if (origin != null) {
235 | buffer.append("from:" + origin + " ");
236 | }
237 | if (target != null) {
238 | buffer.append("to:" + target + " ");
239 | }
240 | if (nature != null) {
241 | buffer.append("nature:" + nature + " ");
242 | }
243 | if (status != null) {
244 | buffer.append("status:" + status + " ");
245 | }
246 | if (message != null) {
247 | buffer.append("message:" + message + " ");
248 | }
249 | if (comment != null) {
250 | buffer.append("comment:" + comment + " ");
251 | }
252 | buffer.append("]");
253 | return buffer.toString();
254 | }
255 |
256 | }
257 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/relation/PersistentRelationDomReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.relation;
18 |
19 | import org.onesocialweb.model.relation.RelationFactory;
20 | import org.onesocialweb.openfire.model.acl.PersistentAclDomReader;
21 | import org.onesocialweb.xml.dom.AclDomReader;
22 | import org.onesocialweb.xml.dom.RelationDomReader;
23 |
24 | public class PersistentRelationDomReader extends RelationDomReader {
25 |
26 | @Override
27 | protected AclDomReader getAclDomReader() {
28 | return new PersistentAclDomReader();
29 | }
30 |
31 | @Override
32 | protected RelationFactory getRelationFactory() {
33 | return new PersistentRelationFactory();
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/relation/PersistentRelationFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.relation;
18 |
19 | import org.onesocialweb.model.relation.Relation;
20 | import org.onesocialweb.model.relation.RelationFactory;
21 |
22 | public class PersistentRelationFactory extends RelationFactory {
23 |
24 | @Override
25 | public Relation relation() {
26 | return new PersistentRelation();
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/vcard4/PersistentBirthdayField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.onesocialweb.openfire.model.vcard4;
19 |
20 | import java.util.ArrayList;
21 | import java.util.Collections;
22 | import java.util.Date;
23 | import java.util.List;
24 |
25 | import javax.persistence.Basic;
26 | import javax.persistence.CascadeType;
27 | import javax.persistence.Entity;
28 | import javax.persistence.EnumType;
29 | import javax.persistence.Enumerated;
30 | import javax.persistence.FetchType;
31 | import javax.persistence.OneToMany;
32 | import javax.persistence.Temporal;
33 | import javax.persistence.TemporalType;
34 |
35 | import org.onesocialweb.model.acl.AclRule;
36 | import org.onesocialweb.model.atom.DefaultAtomHelper;
37 | import org.onesocialweb.model.vcard4.BirthdayField;
38 | import org.onesocialweb.openfire.model.acl.PersistentAclRule;
39 |
40 | @Entity(name="BirthdayField")
41 | public class PersistentBirthdayField extends BirthdayField {
42 |
43 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentAclRule.class, fetch=FetchType.EAGER)
44 | private List rules = new ArrayList();
45 |
46 | @Basic
47 | @Temporal(TemporalType.TIMESTAMP)
48 | private Date birthday;
49 |
50 | @Enumerated(EnumType.ORDINAL)
51 | private BirthdayField.Type type = BirthdayField.Type.DateTime;
52 |
53 | @Override
54 | public String getBirthday() {
55 | if (birthday != null) {
56 | return formatDate(birthday);
57 | } else {
58 | return null;
59 | }
60 | }
61 |
62 | @Override
63 | public Date getDate() {
64 | return birthday;
65 | }
66 |
67 | @Override
68 | public Type getType() {
69 | return type;
70 | }
71 |
72 | @Override
73 | public void setBirthday(String value, Type type) {
74 | setDate(parseDate(value));
75 | this.type = type;
76 | }
77 |
78 | @Override
79 | public void setDate(Date date) {
80 | this.birthday = date;
81 | this.type = BirthdayField.Type.DateTime;
82 | }
83 |
84 | @Override
85 | public void addAclRule(AclRule rule) {
86 | rules.add(rule);
87 | }
88 |
89 | @Override
90 | public List getAclRules() {
91 | return Collections.unmodifiableList(rules);
92 | }
93 |
94 | @Override
95 | public void setAclRules(List rules) {
96 | this.rules = rules;
97 | }
98 |
99 | @Override
100 | public void removeAclRule(AclRule rule) {
101 | rules.remove(rule);
102 | }
103 |
104 | @Override
105 | public boolean hasAclRules() {
106 | if (rules != null && rules.size() > 0) {
107 | return true;
108 | }
109 | return false;
110 | }
111 |
112 | protected Date parseDate(String dateString) {
113 | return DefaultAtomHelper.parseDate(dateString);
114 | }
115 |
116 | protected String formatDate(Date date) {
117 | return DefaultAtomHelper.format(birthday);
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/vcard4/PersistentEmailField.java:
--------------------------------------------------------------------------------
1 | package org.onesocialweb.openfire.model.vcard4;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.List;
6 |
7 | import javax.persistence.Basic;
8 | import javax.persistence.CascadeType;
9 | import javax.persistence.Entity;
10 | import javax.persistence.EnumType;
11 | import javax.persistence.Enumerated;
12 | import javax.persistence.FetchType;
13 | import javax.persistence.OneToMany;
14 |
15 | import org.onesocialweb.model.acl.AclRule;
16 | import org.onesocialweb.model.vcard4.EmailField;
17 | import org.onesocialweb.openfire.model.acl.PersistentAclRule;
18 |
19 | @Entity(name="EmailField")
20 | public class PersistentEmailField extends EmailField {
21 |
22 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentAclRule.class, fetch=FetchType.EAGER)
23 | private List rules = new ArrayList();
24 |
25 | @Enumerated(EnumType.ORDINAL)
26 | private EmailField.Type type = EmailField.Type.Home;
27 |
28 | @Basic
29 | private String email;
30 |
31 | @Override
32 | public String getEmail() {
33 | return this.email;
34 | }
35 |
36 | @Override
37 | public void setEmail(String email) {
38 | this.email = email;
39 | }
40 |
41 | @Override
42 | public void setEmail(String email, Type type) {
43 | this.email = email;
44 | this.type= type;
45 | }
46 |
47 | @Override
48 | public Type getType(){
49 | return this.type;
50 | }
51 |
52 | @Override
53 | public void addAclRule(AclRule rule) {
54 | rules.add(rule);
55 | }
56 |
57 | @Override
58 | public List getAclRules() {
59 | return Collections.unmodifiableList(rules);
60 | }
61 |
62 | @Override
63 | public void removeAclRule(AclRule rule) {
64 | rules.remove(rule);
65 | }
66 |
67 | @Override
68 | public void setAclRules(List rules) {
69 | this.rules = rules;
70 | }
71 |
72 | @Override
73 | public boolean hasAclRules() {
74 | if (rules != null && rules.size() > 0) {
75 | return true;
76 | }
77 | return false;
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/vcard4/PersistentFullNameField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.onesocialweb.openfire.model.vcard4;
19 |
20 | import java.util.ArrayList;
21 | import java.util.Collections;
22 | import java.util.List;
23 |
24 | import javax.persistence.Basic;
25 | import javax.persistence.CascadeType;
26 | import javax.persistence.Entity;
27 | import javax.persistence.FetchType;
28 | import javax.persistence.OneToMany;
29 |
30 | import org.onesocialweb.model.acl.AclRule;
31 | import org.onesocialweb.model.vcard4.FullNameField;
32 | import org.onesocialweb.openfire.model.acl.PersistentAclRule;
33 |
34 | @Entity(name="FullNameField")
35 | public class PersistentFullNameField extends FullNameField {
36 |
37 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentAclRule.class, fetch=FetchType.EAGER)
38 | private List rules = new ArrayList();
39 |
40 | @Basic
41 | private String fullName;
42 |
43 | @Override
44 | public String getFullName() {
45 | return fullName;
46 | }
47 |
48 | @Override
49 | public void setFullName(String fullName) {
50 | this.fullName = fullName;
51 | }
52 |
53 | @Override
54 | public void addAclRule(AclRule rule) {
55 | rules.add(rule);
56 | }
57 |
58 | @Override
59 | public List getAclRules() {
60 | return Collections.unmodifiableList(rules);
61 | }
62 |
63 | @Override
64 | public void removeAclRule(AclRule rule) {
65 | rules.remove(rule);
66 | }
67 |
68 | @Override
69 | public void setAclRules(List rules) {
70 | this.rules = rules;
71 | }
72 |
73 | @Override
74 | public boolean hasAclRules() {
75 | if (rules != null && rules.size() > 0) {
76 | return true;
77 | }
78 | return false;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/vcard4/PersistentGenderField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.onesocialweb.openfire.model.vcard4;
19 |
20 | import java.util.ArrayList;
21 | import java.util.Collections;
22 | import java.util.List;
23 |
24 | import javax.persistence.CascadeType;
25 | import javax.persistence.Entity;
26 | import javax.persistence.EnumType;
27 | import javax.persistence.Enumerated;
28 | import javax.persistence.FetchType;
29 | import javax.persistence.OneToMany;
30 |
31 | import org.onesocialweb.model.acl.AclRule;
32 | import org.onesocialweb.model.vcard4.GenderField;
33 | import org.onesocialweb.openfire.model.acl.PersistentAclRule;
34 |
35 | @Entity(name="GenderField")
36 | public class PersistentGenderField extends GenderField {
37 |
38 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentAclRule.class, fetch=FetchType.EAGER)
39 | private List rules = new ArrayList();
40 |
41 | @Enumerated(EnumType.ORDINAL)
42 | private GenderField.Type type = GenderField.Type.NOTKNOWN;
43 |
44 | @Override
45 | public Type getGender() {
46 | return type;
47 | }
48 |
49 | @Override
50 | public void setGender(Type type) {
51 | this.type = type;
52 | }
53 |
54 | @Override
55 | public void addAclRule(AclRule rule) {
56 | rules.add(rule);
57 | }
58 |
59 | @Override
60 | public List getAclRules() {
61 | return Collections.unmodifiableList(rules);
62 | }
63 |
64 | @Override
65 | public void removeAclRule(AclRule rule) {
66 | rules.remove(rule);
67 | }
68 |
69 | @Override
70 | public void setAclRules(List rules) {
71 | this.rules = rules;
72 | }
73 |
74 | @Override
75 | public boolean hasAclRules() {
76 | if (rules != null && rules.size() > 0) {
77 | return true;
78 | }
79 | return false;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/vcard4/PersistentNameField.java:
--------------------------------------------------------------------------------
1 | package org.onesocialweb.openfire.model.vcard4;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.List;
6 |
7 | import javax.persistence.Basic;
8 | import javax.persistence.CascadeType;
9 | import javax.persistence.Entity;
10 | import javax.persistence.FetchType;
11 | import javax.persistence.OneToMany;
12 |
13 | import org.onesocialweb.model.acl.AclRule;
14 | import org.onesocialweb.model.vcard4.NameField;
15 | import org.onesocialweb.openfire.model.acl.PersistentAclRule;
16 |
17 | @Entity(name="NameField")
18 | public class PersistentNameField extends NameField
19 | {
20 |
21 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentAclRule.class, fetch=FetchType.EAGER)
22 | private List rules = new ArrayList();
23 |
24 | @Basic
25 | private String surname;
26 |
27 | @Basic
28 | private String given;
29 |
30 | @Basic
31 | private String suffix;
32 |
33 | @Basic
34 | private String prefix;
35 |
36 | @Override
37 | public String getSurname() {
38 | return surname;
39 | }
40 |
41 | @Override
42 | public void setSurname(String surname) {
43 | this.surname = surname;
44 | }
45 |
46 | @Override
47 | public String getGiven() {
48 | return given;
49 | }
50 |
51 | @Override
52 | public void setGiven(String given) {
53 | this.given = given;
54 | }
55 |
56 | @Override
57 | public String getSuffix() {
58 | return suffix;
59 | }
60 |
61 | @Override
62 | public void setSuffix(String suffix) {
63 | this.suffix = suffix;
64 | }
65 |
66 | @Override
67 | public String getPrefix() {
68 | return prefix;
69 | }
70 |
71 | @Override
72 | public void setPrefix(String preffix) {
73 | this.prefix = preffix;
74 | }
75 |
76 |
77 | @Override
78 | public void addAclRule(AclRule rule) {
79 | rules.add(rule);
80 | }
81 |
82 | @Override
83 | public List getAclRules() {
84 | return Collections.unmodifiableList(rules);
85 | }
86 |
87 | @Override
88 | public void removeAclRule(AclRule rule) {
89 | rules.remove(rule);
90 | }
91 |
92 | @Override
93 | public void setAclRules(List rules) {
94 | this.rules = rules;
95 | }
96 |
97 | @Override
98 | public boolean hasAclRules() {
99 | if (rules != null && rules.size() > 0) {
100 | return true;
101 | }
102 | return false;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/vcard4/PersistentNoteField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.onesocialweb.openfire.model.vcard4;
19 |
20 | import java.util.ArrayList;
21 | import java.util.Collections;
22 | import java.util.List;
23 |
24 | import javax.persistence.Basic;
25 | import javax.persistence.CascadeType;
26 | import javax.persistence.Entity;
27 | import javax.persistence.FetchType;
28 | import javax.persistence.OneToMany;
29 |
30 | import org.onesocialweb.model.acl.AclRule;
31 | import org.onesocialweb.model.vcard4.NoteField;
32 | import org.onesocialweb.openfire.model.acl.PersistentAclRule;
33 |
34 | @Entity(name="NoteField")
35 | public class PersistentNoteField extends NoteField {
36 |
37 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentAclRule.class, fetch=FetchType.EAGER)
38 | private List rules = new ArrayList();
39 |
40 | @Basic
41 | private String note;
42 |
43 | @Override
44 | public String getNote() {
45 | return note;
46 | }
47 |
48 | @Override
49 | public void setNote(String note) {
50 | this.note = note;
51 | }
52 |
53 | @Override
54 | public void addAclRule(AclRule rule) {
55 | rules.add(rule);
56 | }
57 |
58 | @Override
59 | public List getAclRules() {
60 | return Collections.unmodifiableList(rules);
61 | }
62 |
63 | @Override
64 | public void removeAclRule(AclRule rule) {
65 | rules.remove(rule);
66 | }
67 |
68 | @Override
69 | public void setAclRules(List rules) {
70 | this.rules = rules;
71 | }
72 |
73 | @Override
74 | public boolean hasAclRules() {
75 | if (rules != null && rules.size() > 0) {
76 | return true;
77 | }
78 | return false;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/vcard4/PersistentPhotoField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.onesocialweb.openfire.model.vcard4;
19 |
20 | import java.util.ArrayList;
21 | import java.util.Collections;
22 | import java.util.List;
23 |
24 | import javax.persistence.Basic;
25 | import javax.persistence.CascadeType;
26 | import javax.persistence.Entity;
27 | import javax.persistence.FetchType;
28 | import javax.persistence.OneToMany;
29 |
30 | import org.onesocialweb.model.acl.AclRule;
31 | import org.onesocialweb.model.vcard4.PhotoField;
32 | import org.onesocialweb.openfire.model.acl.PersistentAclRule;
33 |
34 | @Entity(name="PhotoField")
35 | public class PersistentPhotoField extends PhotoField {
36 |
37 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentAclRule.class, fetch=FetchType.EAGER)
38 | private List rules = new ArrayList();
39 |
40 | @Basic
41 | private String uri;
42 |
43 | @Override
44 | public String getUri() {
45 | return uri;
46 | }
47 |
48 | @Override
49 | public void setUri(String uri) {
50 | this.uri = uri;
51 | }
52 |
53 | @Override
54 | public void addAclRule(AclRule rule) {
55 | rules.add(rule);
56 | }
57 |
58 | @Override
59 | public List getAclRules() {
60 | return Collections.unmodifiableList(rules);
61 | }
62 |
63 | @Override
64 | public void removeAclRule(AclRule rule) {
65 | rules.remove(rule);
66 | }
67 |
68 | @Override
69 | public void setAclRules(List rules) {
70 | this.rules = rules;
71 | }
72 |
73 | @Override
74 | public boolean hasAclRules() {
75 | if (rules != null && rules.size() > 0) {
76 | return true;
77 | }
78 | return false;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/vcard4/PersistentProfileFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.onesocialweb.openfire.model.vcard4;
19 |
20 | import org.onesocialweb.model.vcard4.BirthdayField;
21 | import org.onesocialweb.model.vcard4.EmailField;
22 | import org.onesocialweb.model.vcard4.FullNameField;
23 | import org.onesocialweb.model.vcard4.GenderField;
24 | import org.onesocialweb.model.vcard4.NameField;
25 | import org.onesocialweb.model.vcard4.NoteField;
26 | import org.onesocialweb.model.vcard4.PhotoField;
27 | import org.onesocialweb.model.vcard4.Profile;
28 | import org.onesocialweb.model.vcard4.TelField;
29 | import org.onesocialweb.model.vcard4.TimeZoneField;
30 | import org.onesocialweb.model.vcard4.URLField;
31 | import org.onesocialweb.model.vcard4.VCard4Factory;
32 |
33 | public class PersistentProfileFactory extends VCard4Factory {
34 |
35 | @Override
36 | public BirthdayField birthday() {
37 | return new PersistentBirthdayField();
38 | }
39 |
40 | @Override
41 | public FullNameField fullname() {
42 | return new PersistentFullNameField();
43 | }
44 |
45 | @Override
46 | public GenderField gender() {
47 | return new PersistentGenderField();
48 | }
49 |
50 | @Override
51 | public NoteField note() {
52 | return new PersistentNoteField();
53 | }
54 |
55 | @Override
56 | public PhotoField photo() {
57 | return new PersistentPhotoField();
58 | }
59 |
60 | @Override
61 | public EmailField email() {
62 | return new PersistentEmailField();
63 | }
64 |
65 | @Override
66 | public URLField url() {
67 | return new PersistentUrlField();
68 | }
69 |
70 | @Override
71 | public NameField name() {
72 | return new PersistentNameField();
73 | }
74 |
75 | @Override
76 | public TimeZoneField timeZone() {
77 | return new PersistentTimeZoneField();
78 | }
79 |
80 | @Override
81 | public TelField tel() {
82 | return new PersistentTelField();
83 | }
84 |
85 | @Override
86 | public Profile profile() {
87 | return new PersistentProfile();
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/vcard4/PersistentTelField.java:
--------------------------------------------------------------------------------
1 | package org.onesocialweb.openfire.model.vcard4;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.List;
6 |
7 | import javax.persistence.Basic;
8 | import javax.persistence.CascadeType;
9 | import javax.persistence.Entity;
10 | import javax.persistence.EnumType;
11 | import javax.persistence.Enumerated;
12 | import javax.persistence.FetchType;
13 | import javax.persistence.OneToMany;
14 |
15 | import org.onesocialweb.model.acl.AclRule;
16 | import org.onesocialweb.model.vcard4.TelField;
17 | import org.onesocialweb.openfire.model.acl.PersistentAclRule;
18 |
19 | @Entity(name="TelField")
20 | public class PersistentTelField extends TelField{
21 |
22 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentAclRule.class, fetch=FetchType.EAGER)
23 | private List rules = new ArrayList();
24 |
25 | @Enumerated(EnumType.ORDINAL)
26 | private TelField.Type type = TelField.Type.VOICE;
27 |
28 | @Basic
29 | private String tel;
30 |
31 | @Override
32 | public String getNumber() {
33 | return tel;
34 | }
35 |
36 | @Override
37 | public void setNumber(String tel, Type type) {
38 | this.tel = tel;
39 | this.type=type;
40 | }
41 |
42 | public Type getType()
43 | {
44 | return this.type;
45 | }
46 |
47 | @Override
48 | public void addAclRule(AclRule rule) {
49 | rules.add(rule);
50 | }
51 |
52 | @Override
53 | public List getAclRules() {
54 | return Collections.unmodifiableList(rules);
55 | }
56 |
57 | @Override
58 | public void removeAclRule(AclRule rule) {
59 | rules.remove(rule);
60 | }
61 |
62 | @Override
63 | public void setAclRules(List rules) {
64 | this.rules = rules;
65 | }
66 |
67 | @Override
68 | public boolean hasAclRules() {
69 | if (rules != null && rules.size() > 0) {
70 | return true;
71 | }
72 | return false;
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/vcard4/PersistentTimeZoneField.java:
--------------------------------------------------------------------------------
1 | package org.onesocialweb.openfire.model.vcard4;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.List;
6 | import java.util.TimeZone;
7 |
8 | import javax.persistence.Basic;
9 | import javax.persistence.CascadeType;
10 | import javax.persistence.Entity;
11 | import javax.persistence.EnumType;
12 | import javax.persistence.Enumerated;
13 | import javax.persistence.FetchType;
14 | import javax.persistence.OneToMany;
15 |
16 | import org.onesocialweb.model.acl.AclRule;
17 | import org.onesocialweb.model.vcard4.TimeZoneField;
18 | import org.onesocialweb.openfire.model.acl.PersistentAclRule;
19 |
20 | @Entity(name="TimeZoneField")
21 | public class PersistentTimeZoneField extends TimeZoneField
22 | {
23 |
24 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentAclRule.class, fetch=FetchType.EAGER)
25 | private List rules = new ArrayList();
26 |
27 | @Enumerated(EnumType.ORDINAL)
28 | private TimeZoneField.Type type = TimeZoneField.Type.TEXT;
29 |
30 | @Basic
31 | private TimeZone timezone;
32 |
33 |
34 | @Override
35 | public String getTimeZone() {
36 | if (timezone != null) {
37 | return timezone.getID();
38 | } else {
39 | return null;
40 | }
41 | }
42 |
43 | @Override
44 | public TimeZone getJavaTimeZone() {
45 | return timezone;
46 | }
47 |
48 | @Override
49 | public Type getType() {
50 | return type;
51 | }
52 |
53 | @Override
54 | public void setTimeZone(String value, Type type) {
55 | TimeZone tz=TimeZone.getTimeZone(value);
56 | if (!tz.getID().equalsIgnoreCase(value))
57 | tz=TimeZone.getDefault();
58 | setJavaTimeZone(tz);
59 | this.type = type;
60 | }
61 |
62 | @Override
63 | public void setJavaTimeZone(TimeZone tz) {
64 | this.timezone = tz;
65 | }
66 |
67 | @Override
68 | public void addAclRule(AclRule rule) {
69 | rules.add(rule);
70 | }
71 |
72 | @Override
73 | public List getAclRules() {
74 | return Collections.unmodifiableList(rules);
75 | }
76 |
77 | @Override
78 | public void removeAclRule(AclRule rule) {
79 | rules.remove(rule);
80 | }
81 |
82 | @Override
83 | public void setAclRules(List rules) {
84 | this.rules = rules;
85 | }
86 |
87 | @Override
88 | public boolean hasAclRules() {
89 | if (rules != null && rules.size() > 0) {
90 | return true;
91 | }
92 | return false;
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/vcard4/PersistentUrlField.java:
--------------------------------------------------------------------------------
1 | package org.onesocialweb.openfire.model.vcard4;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.List;
6 |
7 | import javax.persistence.Basic;
8 | import javax.persistence.CascadeType;
9 | import javax.persistence.Entity;
10 | import javax.persistence.FetchType;
11 | import javax.persistence.OneToMany;
12 |
13 | import org.onesocialweb.model.acl.AclRule;
14 | import org.onesocialweb.model.vcard4.URLField;
15 | import org.onesocialweb.openfire.model.acl.PersistentAclRule;
16 |
17 | @Entity(name="URLField")
18 | public class PersistentUrlField extends URLField {
19 |
20 | @OneToMany(cascade=CascadeType.ALL, targetEntity=PersistentAclRule.class, fetch=FetchType.EAGER)
21 | private List rules = new ArrayList();
22 |
23 | @Basic
24 | private String url;
25 |
26 | @Override
27 | public String getURL() {
28 | return url;
29 | }
30 |
31 | @Override
32 | public void setURL(String url) {
33 | this.url = url;
34 | }
35 |
36 | @Override
37 | public void addAclRule(AclRule rule) {
38 | rules.add(rule);
39 | }
40 |
41 | @Override
42 | public List getAclRules() {
43 | return Collections.unmodifiableList(rules);
44 | }
45 |
46 | @Override
47 | public void removeAclRule(AclRule rule) {
48 | rules.remove(rule);
49 | }
50 |
51 | @Override
52 | public void setAclRules(List rules) {
53 | this.rules = rules;
54 | }
55 |
56 | @Override
57 | public boolean hasAclRules() {
58 | if (rules != null && rules.size() > 0) {
59 | return true;
60 | }
61 | return false;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/model/vcard4/PersistentVCard4DomReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.model.vcard4;
18 |
19 | import org.onesocialweb.model.vcard4.VCard4Factory;
20 | import org.onesocialweb.openfire.model.acl.PersistentAclDomReader;
21 | import org.onesocialweb.xml.dom.AclDomReader;
22 | import org.onesocialweb.xml.dom.VCard4DomReader;
23 |
24 | public class PersistentVCard4DomReader extends VCard4DomReader {
25 |
26 | @Override
27 | protected AclDomReader getAclDomReader() {
28 | return new PersistentAclDomReader();
29 | }
30 |
31 | @Override
32 | protected VCard4Factory getProfileFactory() {
33 | return new PersistentProfileFactory();
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/web/SessionValidator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.web;
18 |
19 | import org.jivesoftware.openfire.SessionManager;
20 | import org.jivesoftware.openfire.XMPPServer;
21 | import org.jivesoftware.openfire.session.Session;
22 | import org.xmpp.packet.JID;
23 |
24 | public class SessionValidator {
25 |
26 | private static SessionValidator instance;
27 |
28 | private XMPPServer xmppServer;
29 |
30 | private SessionManager sessionManager;
31 |
32 | public static SessionValidator getInstance() {
33 | if (instance == null) {
34 | instance = new SessionValidator();
35 | }
36 | return instance;
37 | }
38 |
39 | public boolean validateSession(String jid, String signature) throws Exception {
40 | if (xmppServer.isLocal(new JID(jid))) {
41 | return validateLocalSession(jid, signature);
42 | } else {
43 | throw new Exception("Not yet implemented for remote sessions");
44 | }
45 | }
46 |
47 | private boolean validateLocalSession(String jid, String signature) {
48 | Session session = sessionManager.getSession(new JID(jid));
49 |
50 | // Does a valid session exist ?
51 | if (session == null || !session.validate()) {
52 | return false;
53 | }
54 |
55 | // Is the session authenticated ?
56 | if (session.getStatus() != Session.STATUS_AUTHENTICATED) {
57 | return false;
58 | }
59 |
60 | // Is the provided signature correct ?
61 | // TODO the signature should be a hash of stuff...
62 | String streamID = session.getStreamID().getID();
63 | System.out.println("Validating signature " + signature + " against ID " + streamID);
64 | if (!streamID.equals(signature)) {
65 | return false;
66 | }
67 |
68 | // All checks OK ! Session is valid then
69 | return true;
70 | }
71 |
72 | /**
73 | * Private constructor to enforce singleton
74 | */
75 | private SessionValidator() {
76 | xmppServer = XMPPServer.getInstance();
77 | sessionManager = SessionManager.getInstance();
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/java/org/onesocialweb/openfire/web/UploadManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Vodafone Group Services Ltd.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 | package org.onesocialweb.openfire.web;
18 |
19 | import java.io.File;
20 | import java.util.Collection;
21 | import java.util.Iterator;
22 |
23 | import javax.persistence.EntityManager;
24 |
25 | import org.dom4j.Element;
26 | import org.jivesoftware.openfire.XMPPServer;
27 | import org.onesocialweb.openfire.OswPlugin;
28 | import org.onesocialweb.openfire.model.FileEntry;
29 | import org.onesocialweb.openfire.model.PersistentFileEntry;
30 | import org.xmpp.packet.JID;
31 | import org.xmpp.packet.Message;
32 |
33 | import eu.medsea.mimeutil.MimeType;
34 | import eu.medsea.mimeutil.MimeUtil;
35 |
36 | public class UploadManager {
37 |
38 | private static UploadManager instance;
39 |
40 | public static UploadManager getInstance() {
41 | if (instance == null) {
42 | instance = new UploadManager();
43 | }
44 | return instance;
45 | }
46 |
47 | public void updateProgress(JID user, long pBytesRead, long pContentLength, String requestId) {
48 | Message message = new Message();
49 | message.setTo(user);
50 | Element payload = message.addChildElement("upload", "http://onesocialweb.org/spec/1.0/upload");
51 | payload.addElement("request-id").setText(requestId);
52 | payload.addElement("status").setText("progress");
53 | payload.addElement("bytes-read").setText(Long.toString(pBytesRead));
54 | payload.addElement("size").setText(Long.toString(pContentLength));
55 | XMPPServer.getInstance().getMessageRouter().route(message);
56 | }
57 |
58 | public void commitFile(JID user, File file, String name, String requestId) {
59 | FileEntry entry = new PersistentFileEntry();
60 | entry.setId(file.getName());
61 | entry.setOwner(user.toBareJID());
62 | entry.setName(name);
63 | entry.setSize(file.length());
64 | entry.setType("unknown/unknown");
65 |
66 | // Attemtp to detect the mime type
67 | MimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
68 | try {
69 | Collection> mimeTypes = MimeUtil.getMimeTypes(file);
70 | if (!mimeTypes.isEmpty()) {
71 | Iterator> i = mimeTypes.iterator();
72 | if (i.hasNext()) {
73 | MimeType mimeType = (MimeType) i.next();
74 | entry.setType(mimeType.toString());
75 | }
76 | }
77 | } catch (Exception e) {};
78 |
79 | // Store the file in the database
80 |
81 | // Initialize then entity manager
82 | EntityManager em = OswPlugin.getEmFactory().createEntityManager();
83 | em.getTransaction().begin();
84 | em.persist(entry);
85 | em.getTransaction().commit();
86 | em.close();
87 |
88 | Message message = new Message();
89 | message.setTo(user);
90 | Element payload = message.addChildElement("upload", "http://onesocialweb.org/spec/1.0/upload");
91 | payload.addElement("request-id").setText(requestId);
92 | payload.addElement("status").setText("completed");
93 | payload.addElement("file-id").setText(file.getName());
94 | payload.addElement("size").setText(Long.toString(entry.getSize()));
95 | payload.addElement("mime-type").setText(entry.getType());
96 | XMPPServer.getInstance().getMessageRouter().route(message);
97 | }
98 |
99 | public FileEntry getFile(String id) {
100 | EntityManager em = OswPlugin.getEmFactory().createEntityManager();
101 | FileEntry entry = em.find(PersistentFileEntry.class, id);
102 | em.close();
103 | return entry;
104 | }
105 |
106 | /*
107 | * Private constructor to enforce the singleton
108 | */
109 | private UploadManager() {
110 | //
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/src/web/WEB-INF/web-custom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | FileServlet
7 | org.onesocialweb.openfire.web.FileServlet
8 |
9 |
10 |
11 |
12 | FileServlet
13 | /file
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/web/form.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Simple File Upload
9 |
10 |
11 |