View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  package org.apache.portals.bridges.velocity;
    18
    19  import javax.portlet.PortletRequest;
    20
    21  import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
    22  import org.apache.portals.messaging.PortletMessaging;
    23
    24  /***
    25   * velocity abstract messaging portlet
    26   *
    27   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
    28   * @version $Id: AbstractVelocityMessagingPortlet.java,v 1.3 2005/03/23 06:24:38 david Exp $
    29   */
    30  public abstract class AbstractVelocityMessagingPortlet extends GenericVelocityPortlet
    31  {
    32      private String topic = null;
    33      public static final String STATUS_MESSAGE = "statusMsg";
    34
    35      protected boolean isEmpty(String s)
    36      {
    37          if (s == null)
    38              return true;
    39
    40          if (s.trim().length() == 0)
    41              return true;
    42
    43          return false;
    44      }
    45
    46      protected String getTopic()
    47      {
    48          return topic;
    49      }
    50      protected void setTopic(String topic)
    51      {
    52          this.topic = topic;
    53      }
    54
    55      protected void cancelRenderMessage(PortletRequest request, String message)
    56      {
    57          try
    58          {
    59              if (topic == null)
    60                  PortletMessaging.cancel(request, message);
    61              else
    62                  PortletMessaging.cancel(request, topic, message);
    63          }
    64          catch (Exception e)
    65          {}
    66      }
    67
    68      protected Object receiveRenderMessage(PortletRequest request, String message)
    69      {
    70          try
    71          {
    72              if (topic == null)
    73                  return PortletMessaging.receive(request, message);
    74              else
    75                  return PortletMessaging.receive(request, topic, message);
    76          }
    77          catch (Exception e)
    78          {}
    79          return null;
    80      }
    81
    82      protected Object consumeRenderMessage(PortletRequest request, String message)
    83      {
    84          try
    85          {
    86              if (topic == null)
    87                  return PortletMessaging.consume(request, message);
    88              else
    89                  return PortletMessaging.consume(request, topic, message);
    90          }
    91          catch (Exception e)
    92          {}
    93          return null;
    94      }
    95
    96      protected void publishRenderMessage(PortletRequest request, String message, Object value)
    97      {
    98          try
    99          {
    100             if (topic == null)
    101                 PortletMessaging.publish(request, message, value);
    102             else
    103                 PortletMessaging.publish(request, topic, message, value);
    104         }
    105         catch (Exception e)
    106         {}
    107     }
    108
    109 }