1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * 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 and15 * limitations under the License.16 */17packageorg.apache.jetspeed.velocity;
1819import java.lang.reflect.Constructor;
2021import javax.portlet.PortletException;
2223import org.apache.commons.logging.Log;
24import org.apache.commons.logging.LogFactory;
25import org.apache.jetspeed.aggregator.PortletRenderer;
26import org.apache.jetspeed.layout.JetspeedPowerTool;
27import org.apache.jetspeed.request.RequestContext;
28import org.apache.jetspeed.services.title.DynamicTitleService;
2930publicclassJetspeedPowerToolFactory implements org.apache.jetspeed.layout.JetspeedPowerToolFactory
31 {
32protectedstaticfinal Log log = LogFactory.getLog(JetspeedPowerToolFactory.class);
3334private Class jptClass;
35private Constructor constructor;
36privateDynamicTitleService titleService;
3738/* Allows us to render portlets and other fragments */39private PortletRenderer renderer;
4041publicJetspeedPowerToolFactory(String jptClassName, DynamicTitleService titleService, PortletRenderer renderer)
42 throws ClassNotFoundException, NoSuchMethodException
43 {
44 jptClass = Thread.currentThread().getContextClassLoader().loadClass(jptClassName);
45 constructor =
46 jptClass.getConstructor(
47new Class[] {RequestContext.class, DynamicTitleService.class, PortletRenderer.class});
48this.titleService = titleService;
49this.renderer = renderer;
50 }
5152public JetspeedPowerTool getJetspeedPowerTool(RequestContext requestContext)
53 throws PortletException
54 {
55try56 {
57 Object [] initArgs = { requestContext, this.titleService, this.renderer };
58return (JetspeedPowerTool)constructor.newInstance(initArgs);
59 }
60catch (Exception e)
61 {
62 e.printStackTrace();
63thrownew PortletException(e);
64 }
65 }
66 }
67