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.jetspeed.velocity;
18:
19: import java.lang.reflect.Constructor;
20:
21: import javax.portlet.PortletException;
22:
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25: import org.apache.jetspeed.aggregator.PortletRenderer;
26: import org.apache.jetspeed.layout.JetspeedPowerTool;
27: import org.apache.jetspeed.request.RequestContext;
28: import org.apache.jetspeed.services.title.DynamicTitleService;
29:
30: public class JetspeedPowerToolFactory implements
31: org.apache.jetspeed.layout.JetspeedPowerToolFactory {
32: protected static final Log log = LogFactory
33: .getLog(JetspeedPowerToolFactory.class);
34:
35: private Class jptClass;
36: private Constructor constructor;
37: private DynamicTitleService titleService;
38:
39: /* Allows us to render portlets and other fragments */
40: private PortletRenderer renderer;
41:
42: public JetspeedPowerToolFactory(String jptClassName,
43: DynamicTitleService titleService, PortletRenderer renderer)
44: throws ClassNotFoundException, NoSuchMethodException {
45: jptClass = Thread.currentThread().getContextClassLoader()
46: .loadClass(jptClassName);
47: constructor = jptClass.getConstructor(new Class[] {
48: RequestContext.class, DynamicTitleService.class,
49: PortletRenderer.class });
50: this .titleService = titleService;
51: this .renderer = renderer;
52: }
53:
54: public JetspeedPowerTool getJetspeedPowerTool(
55: RequestContext requestContext) throws PortletException {
56: try {
57: Object[] initArgs = { requestContext, this .titleService,
58: this .renderer };
59: return (JetspeedPowerTool) constructor
60: .newInstance(initArgs);
61: } catch (Exception e) {
62: e.printStackTrace();
63: throw new PortletException(e);
64: }
65: }
66: }
|