| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| VelocityDirectScreen |
|
| 4.0;4 |
| 1 | package org.apache.turbine.modules.screens; | |
| 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.commons.lang.StringUtils; | |
| 23 | import org.apache.commons.lang.exception.ExceptionUtils; | |
| 24 | import org.apache.turbine.TurbineConstants; | |
| 25 | import org.apache.turbine.pipeline.PipelineData; | |
| 26 | import org.apache.turbine.util.RunData; | |
| 27 | import org.apache.velocity.context.Context; | |
| 28 | ||
| 29 | /** | |
| 30 | * VelocityDirectScreen is a screen class which returns its output | |
| 31 | * directly to the output stream. It can be used if buffering an | |
| 32 | * output screen isn't possible or the result doesn't fit in the | |
| 33 | * memory. | |
| 34 | * <p> | |
| 35 | * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> | |
| 36 | * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> | |
| 37 | * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> | |
| 38 | * @version $Id: VelocityDirectScreen.java 1773378 2016-12-09 13:19:59Z tv $ | |
| 39 | */ | |
| 40 | 0 | public class VelocityDirectScreen |
| 41 | extends VelocityScreen | |
| 42 | { | |
| 43 | /** The prefix for lookup up screen pages */ | |
| 44 | 0 | private String prefix = getPrefix() + "/"; |
| 45 | ||
| 46 | /** | |
| 47 | * This builds the Velocity template. | |
| 48 | * | |
| 49 | * @param pipelineData Turbine information. | |
| 50 | * @return the content of the screen | |
| 51 | * @throws Exception a generic exception. | |
| 52 | */ | |
| 53 | @Override | |
| 54 | public String buildTemplate(PipelineData pipelineData) | |
| 55 | throws Exception | |
| 56 | { | |
| 57 | 0 | RunData data = getRunData(pipelineData); |
| 58 | 0 | Context context = velocity.getContext(pipelineData); |
| 59 | ||
| 60 | 0 | String screenTemplate = data.getTemplateInfo().getScreenTemplate(); |
| 61 | 0 | String templateName |
| 62 | = templateService.getScreenTemplateName(screenTemplate); | |
| 63 | ||
| 64 | // The Template Service could not find the Screen | |
| 65 | 0 | if (StringUtils.isEmpty(templateName)) |
| 66 | { | |
| 67 | 0 | log.error("Screen " + screenTemplate + " not found!"); |
| 68 | 0 | throw new Exception("Could not find screen for " + screenTemplate); |
| 69 | } | |
| 70 | ||
| 71 | try | |
| 72 | { | |
| 73 | 0 | velocity.handleRequest(context, |
| 74 | prefix + templateName, | |
| 75 | data.getResponse().getOutputStream()); | |
| 76 | ||
| 77 | } | |
| 78 | 0 | catch (Exception e) |
| 79 | { | |
| 80 | // If there is an error, build a $processingException and | |
| 81 | // attempt to call the error.vm template in the screens | |
| 82 | // directory. | |
| 83 | 0 | context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, e.toString()); |
| 84 | 0 | context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, ExceptionUtils.getStackTrace(e)); |
| 85 | ||
| 86 | 0 | velocity.handleRequest(context, prefix + templateError, |
| 87 | data.getResponse().getOutputStream()); | |
| 88 | 0 | } |
| 89 | ||
| 90 | 0 | return null; |
| 91 | } | |
| 92 | } |