View Javadoc

1   /*
2    * Copyright 2000-2004 The Apache Software Foundation.
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  package org.apache.portals.bridges.velocity;
17  
18  import javax.portlet.PortletRequest;
19  
20  import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
21  import org.apache.portals.messaging.PortletMessaging;
22  
23  /***
24   * velocity abstract messaging portlet
25   * 
26   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
27   * @version $Id: AbstractVelocityMessagingPortlet.java,v 1.3 2005/03/23 06:24:38 david Exp $
28   */
29  public abstract class AbstractVelocityMessagingPortlet extends GenericVelocityPortlet
30  {
31      private String topic = null;
32      public static final String STATUS_MESSAGE = "statusMsg";
33      
34      protected boolean isEmpty(String s)
35      {
36          if (s == null)
37              return true;
38          
39          if (s.trim().length() == 0)
40              return true;
41          
42          return false;
43      }
44      
45      protected String getTopic()
46      {
47          return topic;
48      }
49      protected void setTopic(String topic)
50      {
51          this.topic = topic;
52      }
53      
54      protected void cancelRenderMessage(PortletRequest request, String message)
55      {
56          try
57          {
58              if (topic == null)
59                  PortletMessaging.cancel(request, message);
60              else
61                  PortletMessaging.cancel(request, topic, message);
62          }
63          catch (Exception e)
64          {}
65      }
66      
67      protected Object receiveRenderMessage(PortletRequest request, String message)
68      {
69          try
70          {
71              if (topic == null)
72                  return PortletMessaging.receive(request, message);
73              else
74                  return PortletMessaging.receive(request, topic, message);
75          }
76          catch (Exception e)
77          {}
78          return null;
79      }
80      
81      protected Object consumeRenderMessage(PortletRequest request, String message)
82      {
83          try
84          {
85              if (topic == null)
86                  return PortletMessaging.consume(request, message);            
87              else
88                  return PortletMessaging.consume(request, topic, message);            
89          }
90          catch (Exception e)
91          {}        
92          return null;
93      }
94      
95      protected void publishRenderMessage(PortletRequest request, String message, Object value)
96      {
97          try
98          {
99              if (topic == null)
100                 PortletMessaging.publish(request, message, value);
101             else
102                 PortletMessaging.publish(request, topic, message, value);
103         }
104         catch (Exception e)
105         {}
106     }
107 
108 }