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: /*
18: * Created on Jul 28, 2004
19: *
20: * TODO To change the template for this generated file go to
21: * Window - Preferences - Java - Code Generation - Code and Comments
22: */
23: package org.apache.jetspeed.velocity;
24:
25: import org.apache.commons.httpclient.HttpClient;
26: import org.apache.commons.httpclient.methods.GetMethod;
27: import org.apache.velocity.tools.view.tools.ViewTool;
28:
29: /**
30: * <p>
31: * ContentTool
32: * </p>
33: * <p>
34: *
35: * </p>
36: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
37: * @version $Id: RemoteContentTool.java 516881 2007-03-11 10:34:21Z ate $
38: *
39: */
40: public class RemoteContentTool implements ViewTool {
41:
42: /**
43: * <p>
44: * init
45: * </p>
46: *
47: * @see org.apache.velocity.tools.view.tools.ViewTool#init(java.lang.Object)
48: * @param arg0
49: */
50: public void init(Object arg0) {
51:
52: }
53:
54: public String include(String remoteContentUrl) {
55: GetMethod remoteContentGet = null;
56:
57: try {
58: HttpClient client = new HttpClient();
59: remoteContentGet = new GetMethod(remoteContentUrl);
60: client.executeMethod(remoteContentGet);
61: return remoteContentGet.getResponseBodyAsString();
62: } catch (Exception e) {
63: return e.toString() + " message:" + e.getMessage();
64: } finally {
65: if (remoteContentGet != null) {
66: remoteContentGet.releaseConnection();
67: }
68: }
69: }
70:
71: }
|