1 package org.apache.turbine.modules; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import org.apache.turbine.Turbine; 23 import org.apache.turbine.pipeline.PipelineData; 24 import org.apache.turbine.util.RunData; 25 26 /** 27 * The purpose of this class is to allow one to load and execute Page 28 * modules. 29 * 30 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> 31 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 32 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 33 * @version $Id: PageLoader.java 1078552 2011-03-06 19:58:46Z tv $ 34 */ 35 public class PageLoader 36 extends GenericLoader<Page> 37 implements Loader<Page> 38 { 39 /** The single instance of this class. */ 40 private static PageLoader instance = new PageLoader(); 41 42 /** 43 * These ctor's are private to force clients to use getInstance() 44 * to access this class. 45 */ 46 private PageLoader() 47 { 48 super(); 49 } 50 51 /** 52 * Attempts to load and execute the external page. 53 * @deprecated Use PipelineData version instead. 54 * @param data Turbine information. 55 * @param name Name of object that will execute the page. 56 * @exception Exception a generic exception. 57 */ 58 @Deprecated 59 @Override 60 public void exec(RunData data, String name) 61 throws Exception 62 { 63 // Execute page 64 getAssembler(name).build(data); 65 } 66 67 /** 68 * Attempts to load and execute the external page. 69 * 70 * @param data Turbine information. 71 * @param name Name of object that will execute the page. 72 * @exception Exception a generic exception. 73 */ 74 @Override 75 public void exec(PipelineData pipelineData, String name) 76 throws Exception 77 { 78 // Execute page 79 getAssembler(name).build(pipelineData); 80 } 81 82 83 84 /** 85 * Pulls out an instance of the object by name. Name is just the 86 * single name of the object. This is equal to getInstance but 87 * returns an Assembler object and is needed to fulfil the Loader 88 * interface. 89 * 90 * @param name Name of object instance. 91 * @return A Screen with the specified name, or null. 92 * @exception Exception a generic exception. 93 */ 94 public Page getAssembler(String name) 95 throws Exception 96 { 97 return getAssembler(Page.NAME, name); 98 } 99 100 /** 101 * @see org.apache.turbine.modules.Loader#getCacheSize() 102 */ 103 public int getCacheSize() 104 { 105 return PageLoader.getConfiguredCacheSize(); 106 } 107 108 /** 109 * The method through which this class is accessed. 110 * 111 * @return The single instance of this class. 112 */ 113 public static PageLoader getInstance() 114 { 115 return instance; 116 } 117 118 /** 119 * Helper method to get the configured cache size for this module 120 * 121 * @return the configure cache size 122 */ 123 private static int getConfiguredCacheSize() 124 { 125 return Turbine.getConfiguration().getInt(Page.CACHE_SIZE_KEY, 126 Page.CACHE_SIZE_DEFAULT); 127 } 128 }