001 package org.apache.turbine.modules; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import org.apache.turbine.Turbine; 023 import org.apache.turbine.pipeline.PipelineData; 024 import org.apache.turbine.util.RunData; 025 026 /** 027 * The purpose of this class is to allow one to load and execute Page 028 * modules. 029 * 030 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> 031 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 032 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 033 * @version $Id: PageLoader.java 1078552 2011-03-06 19:58:46Z tv $ 034 */ 035 public class PageLoader 036 extends GenericLoader<Page> 037 implements Loader<Page> 038 { 039 /** The single instance of this class. */ 040 private static PageLoader instance = new PageLoader(); 041 042 /** 043 * These ctor's are private to force clients to use getInstance() 044 * to access this class. 045 */ 046 private PageLoader() 047 { 048 super(); 049 } 050 051 /** 052 * Attempts to load and execute the external page. 053 * @deprecated Use PipelineData version instead. 054 * @param data Turbine information. 055 * @param name Name of object that will execute the page. 056 * @exception Exception a generic exception. 057 */ 058 @Deprecated 059 @Override 060 public void exec(RunData data, String name) 061 throws Exception 062 { 063 // Execute page 064 getAssembler(name).build(data); 065 } 066 067 /** 068 * Attempts to load and execute the external page. 069 * 070 * @param data Turbine information. 071 * @param name Name of object that will execute the page. 072 * @exception Exception a generic exception. 073 */ 074 @Override 075 public void exec(PipelineData pipelineData, String name) 076 throws Exception 077 { 078 // Execute page 079 getAssembler(name).build(pipelineData); 080 } 081 082 083 084 /** 085 * Pulls out an instance of the object by name. Name is just the 086 * single name of the object. This is equal to getInstance but 087 * returns an Assembler object and is needed to fulfil the Loader 088 * interface. 089 * 090 * @param name Name of object instance. 091 * @return A Screen with the specified name, or null. 092 * @exception Exception a generic exception. 093 */ 094 public Page getAssembler(String name) 095 throws Exception 096 { 097 return getAssembler(Page.NAME, name); 098 } 099 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 }