01: /**
02: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a copy
05: * of this software and associated documentation files (the "Software"), to deal
06: * in the Software without restriction, including without limitation the rights
07: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
08: * copies of the Software, and to permit persons to whom the Software is
09: * furnished to do so, subject to the following conditions:
10: *
11: * The above copyright notice and this permission notice shall be included in
12: * all copies or substantial portions of the Software.
13: *
14: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20: * SOFTWARE.
21: */package com.liferay.jbi.servicemix.util;
22:
23: import com.liferay.util.Http;
24:
25: import java.io.IOException;
26:
27: import java.util.HashMap;
28: import java.util.Iterator;
29: import java.util.Map;
30:
31: import javax.jbi.messaging.MessageExchange;
32: import javax.jbi.messaging.MessagingException;
33: import javax.jbi.messaging.NormalizedMessage;
34:
35: import org.apache.servicemix.components.util.TransformComponentSupport;
36: import org.apache.servicemix.jbi.jaxp.StringSource;
37:
38: /**
39: * <a href="URLTransformComponent.java.html"><b><i>View Source</i></b></a>
40: *
41: * @author Charles May
42: * @author Brian Wing Shun Chan
43: *
44: */
45: public class URLTransformComponent extends TransformComponentSupport {
46:
47: public String getUrl() {
48: return _url;
49: }
50:
51: public void setUrl(String url) {
52: _url = url;
53: }
54:
55: public String getUrlResult(NormalizedMessage in)
56: throws MessagingException {
57: Map parts = new HashMap();
58:
59: Iterator itr = in.getPropertyNames().iterator();
60:
61: while (itr.hasNext()) {
62: String key = (String) itr.next();
63:
64: Object value = (Object) in.getProperty(key);
65:
66: if (value instanceof String) {
67:
68: parts.put(key, value);
69: }
70: }
71:
72: try {
73: return Http.URLtoString(_url, null, parts, true);
74: } catch (IOException ioe) {
75: throw new MessagingException(ioe.getMessage());
76: }
77: }
78:
79: public boolean transform(MessageExchange exchange,
80: NormalizedMessage in, NormalizedMessage out)
81: throws MessagingException {
82:
83: out.setContent(new StringSource(getUrlResult(in)));
84:
85: return true;
86: }
87:
88: private String _url;
89:
90: }
|