01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.cocoon.acting;
18:
19: import java.util.Collections;
20: import java.util.Map;
21:
22: import javax.jms.Message;
23:
24: import org.apache.avalon.framework.parameters.Parameters;
25: import org.apache.avalon.framework.thread.ThreadSafe;
26: import org.apache.cocoon.environment.Redirector;
27: import org.apache.cocoon.environment.SourceResolver;
28:
29: import org.apache.cocoon.components.jms.AbstractMessagePublisher;
30:
31: /**
32: * Action to publish TextMessages to a JMS Topic. For description of static
33: * parameter configuration see {@link org.apache.cocoon.components.jms.AbstractMessagePublisher}
34: *
35: * <p>Sitemap parameters:</p>
36: * <table border="1">
37: * <tbody>
38: * <tr>
39: * <th align="left">parameter</th>
40: * <th align="left">required</th>
41: * <th align="left">default</th>
42: * <th align="left">description</th>
43: * </tr>
44: * <tbody>
45: * <tr>
46: * <td>message</td>
47: * <td>required</td>
48: * <td> </td>
49: * <td>Content of TextMessage to publish</td>
50: * </tr>
51: * </tbody>
52: * </table>
53: */
54: public class JMSPublisherAction extends AbstractMessagePublisher
55: implements Action, ThreadSafe {
56:
57: // ---------------------------------------------------- Constants
58:
59: private static final String MESSAGE_PARAM = "message";
60:
61: // ---------------------------------------------------- Lifecycle
62:
63: public JMSPublisherAction() {
64: }
65:
66: // ---------------------------------------------------- Action
67:
68: public Map act(Redirector redirector, SourceResolver resolver,
69: Map objectModel, String source, Parameters parameters)
70: throws Exception {
71:
72: Map result = null;
73: try {
74: // publish the message
75: final String event = parameters.getParameter(MESSAGE_PARAM);
76: final Message message = m_session.createTextMessage(event);
77: publishMessage(message);
78: result = Collections.EMPTY_MAP;
79: } catch (Exception e) {
80: if (getLogger().isWarnEnabled()) {
81: getLogger().warn("Error delivering message.", e);
82: }
83: }
84:
85: return result;
86: }
87:
88: }
|