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