1 package org.apache.turbine.pipeline; 2 3 4 /* 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 */ 22 23 24 import java.io.IOException; 25 26 import org.apache.logging.log4j.LogManager; 27 import org.apache.logging.log4j.Logger; 28 import org.apache.turbine.util.RunData; 29 import org.apache.turbine.util.TurbineException; 30 import org.apache.turbine.util.uri.URIConstants; 31 32 /** 33 * This valve is responsible for setting the 'target' property of the RunData. 34 * If it is not already set it attempts to get the target from the request 35 * parameter 'template'. If the parameter is not set, we use the homepage 36 * specified by the configuration property Turbine.TEMPLATE_HOMEPAGE. 37 * 38 * FIXME: The request parameter which determines the template should be 39 * configurable. 40 * 41 * @author <a href="mailto:james@jamestaylor.org">James Taylor</a> 42 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 43 */ 44 public class DetermineTargetValve implements Valve 45 { 46 private static final Logger log 47 = LogManager.getLogger(DetermineTargetValve.class); 48 49 /** 50 * @see org.apache.turbine.pipeline.Valve#invoke(PipelineData, ValveContext) 51 */ 52 @Override 53 public void invoke(PipelineData pipelineData, ValveContext context) 54 throws IOException, TurbineException 55 { 56 RunData runData = pipelineData.getRunData(); 57 if (!runData.hasScreen()) 58 { 59 String target = runData.getParameters().getString(URIConstants.CGI_SCREEN_PARAM); 60 61 if (target != null) 62 { 63 runData.setScreen(target); 64 log.debug("Set screen target from request parameter"); 65 } 66 else 67 { 68 log.debug("No target screen"); 69 } 70 } 71 72 log.debug("Screen Target is now: {}", runData::getScreen); 73 74 // Pass control to the next Valve in the Pipeline 75 context.invokeNext(pipelineData); 76 } 77 }