mina-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mj...@apache.org
Subject svn commit: r787340 - in /mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler: AbstractPubSubGeneralHandler.java ErrorStanzaGenerator.java PubSubSubscribeHandler.java PubSubUnsubscribeHandler.java
Date Mon, 22 Jun 2009 18:15:13 GMT
Author: mjakl
Date: Mon Jun 22 18:15:12 2009
New Revision: 787340

URL: http://svn.apache.org/viewvc?rev=787340&view=rev
Log:
Extracted the code for generating error stanzas. This is part of VYSPER-63.

Added:
    mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/ErrorStanzaGenerator.java
Modified:
    mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/AbstractPubSubGeneralHandler.java
    mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubSubscribeHandler.java
    mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubUnsubscribeHandler.java

Modified: mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/AbstractPubSubGeneralHandler.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/AbstractPubSubGeneralHandler.java?rev=787340&r1=787339&r2=787340&view=diff
==============================================================================
--- mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/AbstractPubSubGeneralHandler.java
(original)
+++ mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/AbstractPubSubGeneralHandler.java
Mon Jun 22 18:15:12 2009
@@ -31,14 +31,16 @@
  * @author The Apache MINA Project (http://mina.apache.org)
  *
  */
-public abstract class AbstractPubSubGeneralHandler extends
-		AbstractPublishSubscribeIQHandler {
+public abstract class AbstractPubSubGeneralHandler extends AbstractPublishSubscribeIQHandler
{
 
+	ErrorStanzaGenerator errorStanzaGenerator = null;
+	
 	/**
 	 * @param root
 	 */
 	public AbstractPubSubGeneralHandler(CollectionNode root) {
 		super(root);
+		errorStanzaGenerator = new ErrorStanzaGenerator();
 	}
 
 	@Override

Added: mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/ErrorStanzaGenerator.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/ErrorStanzaGenerator.java?rev=787340&view=auto
==============================================================================
--- mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/ErrorStanzaGenerator.java
(added)
+++ mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/ErrorStanzaGenerator.java
Mon Jun 22 18:15:12 2009
@@ -0,0 +1,110 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.handler;
+
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.apache.vysper.xmpp.stanza.IQStanzaType;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+
+/**
+ * @author The Apache MINA Project (http://mina.apache.org)
+ *
+ */
+public class ErrorStanzaGenerator {
+	public Stanza generateJIDMalformedErrorStanza(Entity sender, Entity receiver, String iqStanzaID)
{
+		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
+		error.startInnerElement("error");
+		error.addAttribute("type", "modify");
+		error.startInnerElement("jid-malformed", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
+		error.endInnerElement(); // jid-malformed
+		error.endInnerElement(); // error
+		return error.getFinalStanza();
+	}
+
+	public Stanza generateInsufficientPrivilegesErrorStanza(Entity sender, Entity receiver,
String iqStanzaID) {
+		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
+		error.startInnerElement("error");
+		error.addAttribute("type", "auth");
+		error.startInnerElement("forbidden", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
+		error.endInnerElement(); // forbidden
+		error.endInnerElement(); // error
+		return error.getFinalStanza();
+	}
+
+	public Stanza generateNoSuchSubscriberErrorStanza(Entity sender, Entity receiver, String
iqStanzaID) {
+		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
+		error.startInnerElement("error");
+		error.addAttribute("type", "cancel");
+		error.startInnerElement("unexpected-request", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
+		error.endInnerElement(); // unexpected-request
+		error.startInnerElement("not-subscribed", NamespaceURIs.XEP0060_PUBSUB_ERRORS);
+		error.endInnerElement(); // not-subscribed
+		error.endInnerElement(); // error
+		return error.getFinalStanza();
+	}
+
+	public Stanza generateSubIDRequiredErrorStanza(Entity sender, Entity receiver, String iqStanzaID)
{
+		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
+		error.startInnerElement("error");
+		error.addAttribute("type", "modify");
+		error.startInnerElement("bad-request", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
+		error.endInnerElement(); // bad-request
+		error.startInnerElement("subid-required", NamespaceURIs.XEP0060_PUBSUB_ERRORS);
+		error.endInnerElement(); // subid-required
+		error.endInnerElement(); // error
+		return error.getFinalStanza();
+	}
+	
+	public Stanza generateNoNodeErrorStanza(Entity sender, Entity receiver, String iqStanzaID)
{
+		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
+		error.startInnerElement("error");
+		error.addAttribute("type", "cancel");
+		error.startInnerElement("item-does-not-exist", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
+		error.endInnerElement(); // item-does-not-exist
+		error.endInnerElement(); // error
+		return error.getFinalStanza();
+	}
+
+	public Stanza generateSubIDNotValidErrorStanza(Entity sender, Entity receiver, String iqStanzaID)
{
+		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
+		error.startInnerElement("error");
+		error.addAttribute("type", "modify");
+		error.startInnerElement("not-acceptable", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
+		error.endInnerElement(); // not-acceptable
+		error.startInnerElement("invalid-subid", NamespaceURIs.XEP0060_PUBSUB_ERRORS);
+		error.endInnerElement(); // invlaid-subid
+		error.endInnerElement(); // error
+		return error.getFinalStanza();
+	}
+	
+	public Stanza generateJIDDontMatchErrorStanza(Entity sender, Entity receiver, String iqStanzaID)
{
+		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
+		error.startInnerElement("error");
+		error.addAttribute("type", "modify");
+		error.startInnerElement("bad-request", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
+		error.endInnerElement(); // bad-request
+		error.startInnerElement("invalid-jid", NamespaceURIs.XEP0060_PUBSUB_ERRORS);
+		error.endInnerElement(); // invalid-jid
+		error.endInnerElement(); // error
+		return error.getFinalStanza();
+	}
+}

Modified: mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubSubscribeHandler.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubSubscribeHandler.java?rev=787340&r1=787339&r2=787340&view=diff
==============================================================================
--- mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubSubscribeHandler.java
(original)
+++ mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubSubscribeHandler.java
Mon Jun 22 18:15:12 2009
@@ -71,12 +71,12 @@
 		try {
 			subJID = EntityImpl.parse(strSubJID);
 		} catch (EntityFormatException e) {
-			return generateJIDMalformedErrorStanza(sender, receiver, iqStanzaID);
+			return errorStanzaGenerator.generateJIDMalformedErrorStanza(sender, receiver, iqStanzaID);
 		}
 		
 		if(!sender.getBareJID().equals(subJID.getBareJID())) {
 			// error condition 1 (6.1.3)
-			return generateJIDDontMatchErrorStanza(sender, receiver, iqStanzaID);
+			return errorStanzaGenerator.generateJIDDontMatchErrorStanza(sender, receiver, iqStanzaID);
 		}
 		
 		Entity nodeJID = extractNodeJID(stanza);
@@ -84,7 +84,7 @@
 		
 		if(node == null) {
 			// no such node (error condition 11 (6.1.3))
-			return generateNoNodeErrorStanza(sender, receiver, iqStanzaID);
+			return errorStanzaGenerator.generateNoNodeErrorStanza(sender, receiver, iqStanzaID);
 		}
 		
 		String id = idGenerator.create();
@@ -96,40 +96,6 @@
 		return new IQStanza(sb.getFinalStanza());
 	}
 
-	private Stanza generateJIDMalformedErrorStanza(Entity sender,
-			Entity receiver, String iqStanzaID) {
-		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
-		error.startInnerElement("error");
-		error.addAttribute("type", "modify");
-		error.startInnerElement("jid-malformed", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
-		error.endInnerElement(); // jid-malformed
-		error.endInnerElement(); // error
-		return error.getFinalStanza();
-	}
-
-	private Stanza generateNoNodeErrorStanza(Entity sender, Entity receiver,
-			String iqStanzaID) {
-		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
-		error.startInnerElement("error");
-		error.addAttribute("type", "cancel");
-		error.startInnerElement("item-does-not-exist", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
-		error.endInnerElement(); // item-does-not-exist
-		error.endInnerElement(); // error
-		return error.getFinalStanza();
-	}
-
-	private Stanza generateJIDDontMatchErrorStanza(Entity sender,
-			Entity receiver, String iqStanzaID) {
-		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
-		error.startInnerElement("error");
-		error.addAttribute("type", "modify");
-		error.startInnerElement("bad-request", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
-		error.endInnerElement(); // bad-request
-		error.startInnerElement("invalid-jid", NamespaceURIs.XEP0060_PUBSUB_ERRORS);
-		error.endInnerElement(); // invalid-jid
-		error.endInnerElement(); // error
-		return error.getFinalStanza();
-	}
 	
 	private void buildSuccessStanza(StanzaBuilder sb, Entity node, String jid, String subid)
{
 		sb.startInnerElement("subscription");
@@ -139,5 +105,4 @@
 		sb.addAttribute("subscription", "subscribed");
 		sb.endInnerElement();
 	}
-
 }

Modified: mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubUnsubscribeHandler.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubUnsubscribeHandler.java?rev=787340&r1=787339&r2=787340&view=diff
==============================================================================
--- mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubUnsubscribeHandler.java
(original)
+++ mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubUnsubscribeHandler.java
Mon Jun 22 18:15:12 2009
@@ -74,12 +74,12 @@
 			subJID = EntityImpl.parse(strSubJID);
 		} catch (EntityFormatException e) {
 			// return error stanza... (general error)
-			return generateJIDMalformedErrorStanza(sender, receiver, iqStanzaID);
+			return errorStanzaGenerator.generateJIDMalformedErrorStanza(sender, receiver, iqStanzaID);
 		}
 		
 		if(!sender.getBareJID().equals(subJID.getBareJID())) {
 			// insufficient privileges (error condition 3 (6.2.3))
-			return generateInsufficientPrivilegesErrorStanza(sender, receiver, iqStanzaID);
+			return errorStanzaGenerator.generateInsufficientPrivilegesErrorStanza(sender, receiver,
iqStanzaID);
 		}
 				
 		Entity nodeJID = extractNodeJID(stanza);
@@ -87,23 +87,23 @@
 		
 		if(node == null) {
 			// no such node (error condition 4 (6.2.3))
-			return generateNoNodeErrorStanza(sender, receiver, iqStanzaID);
+			return errorStanzaGenerator.generateNoNodeErrorStanza(sender, receiver, iqStanzaID);
 		}
 		
 		if(strSubID == null) {
 			try {
 				if(node.unsubscribe(subJID) == false) {
 					// has no subscription (6.2.3.2)
-					return generateNoSuchSubscriberErrorStanza(sender, receiver, iqStanzaID);
+					return errorStanzaGenerator.generateNoSuchSubscriberErrorStanza(sender, receiver, iqStanzaID);
 				}
 			} catch(MultipleSubscriptionException e) {
 				// error case 6.2.3.1
-				return generateSubIDRequiredErrorStanza(sender, receiver, iqStanzaID);
+				return errorStanzaGenerator.generateSubIDRequiredErrorStanza(sender, receiver, iqStanzaID);
 			}
 		} else {
 			if(node.unsubscribe(strSubID, subJID) == false) {
 				// subID not valid (6.2.3.5)
-				return generateSubIDNotValidErrorStanza(sender, receiver, iqStanzaID);
+				return errorStanzaGenerator.generateSubIDNotValidErrorStanza(sender, receiver, iqStanzaID);
 			}
 		}
 		
@@ -111,69 +111,4 @@
 		return new IQStanza(sb.getFinalStanza());
 	}
 	
-	private Stanza generateJIDMalformedErrorStanza(Entity sender, Entity receiver, String iqStanzaID)
{
-		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
-		error.startInnerElement("error");
-		error.addAttribute("type", "modify");
-		error.startInnerElement("jid-malformed", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
-		error.endInnerElement(); // jid-malformed
-		error.endInnerElement(); // error
-		return error.getFinalStanza();
-	}
-
-	private Stanza generateInsufficientPrivilegesErrorStanza(Entity sender, Entity receiver,
String iqStanzaID) {
-		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
-		error.startInnerElement("error");
-		error.addAttribute("type", "auth");
-		error.startInnerElement("forbidden", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
-		error.endInnerElement(); // forbidden
-		error.endInnerElement(); // error
-		return error.getFinalStanza();
-	}
-
-	private Stanza generateNoSuchSubscriberErrorStanza(Entity sender, Entity receiver, String
iqStanzaID) {
-		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
-		error.startInnerElement("error");
-		error.addAttribute("type", "cancel");
-		error.startInnerElement("unexpected-request", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
-		error.endInnerElement(); // unexpected-request
-		error.startInnerElement("not-subscribed", NamespaceURIs.XEP0060_PUBSUB_ERRORS);
-		error.endInnerElement(); // not-subscribed
-		error.endInnerElement(); // error
-		return error.getFinalStanza();
-	}
-
-	private Stanza generateSubIDRequiredErrorStanza(Entity sender, Entity receiver, String iqStanzaID)
{
-		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
-		error.startInnerElement("error");
-		error.addAttribute("type", "modify");
-		error.startInnerElement("bad-request", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
-		error.endInnerElement(); // bad-request
-		error.startInnerElement("subid-required", NamespaceURIs.XEP0060_PUBSUB_ERRORS);
-		error.endInnerElement(); // subid-required
-		error.endInnerElement(); // error
-		return error.getFinalStanza();
-	}
-	
-	private Stanza generateNoNodeErrorStanza(Entity sender, Entity receiver, String iqStanzaID)
{
-		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
-		error.startInnerElement("error");
-		error.addAttribute("type", "cancel");
-		error.startInnerElement("item-does-not-exist", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
-		error.endInnerElement(); // item-does-not-exist
-		error.endInnerElement(); // error
-		return error.getFinalStanza();
-	}
-
-	private Stanza generateSubIDNotValidErrorStanza(Entity sender, Entity receiver, String iqStanzaID)
{
-		StanzaBuilder error = StanzaBuilder.createIQStanza(receiver, sender, IQStanzaType.ERROR,
iqStanzaID);
-		error.startInnerElement("error");
-		error.addAttribute("type", "modify");
-		error.startInnerElement("not-acceptable", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS);
-		error.endInnerElement(); // not-acceptable
-		error.startInnerElement("invalid-subid", NamespaceURIs.XEP0060_PUBSUB_ERRORS);
-		error.endInnerElement(); // invlaid-subid
-		error.endInnerElement(); // error
-		return error.getFinalStanza();
-	}
 }



Mime
View raw message