| 1 | |
package org.apache.turbine.modules.screens; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
import org.apache.commons.lang.StringUtils; |
| 23 | |
import org.apache.commons.lang.exception.ExceptionUtils; |
| 24 | |
import org.apache.ecs.ConcreteElement; |
| 25 | |
import org.apache.turbine.Turbine; |
| 26 | |
import org.apache.turbine.TurbineConstants; |
| 27 | |
import org.apache.turbine.pipeline.PipelineData; |
| 28 | |
import org.apache.turbine.services.template.TurbineTemplate; |
| 29 | |
import org.apache.turbine.services.velocity.TurbineVelocity; |
| 30 | |
import org.apache.turbine.util.RunData; |
| 31 | |
import org.apache.velocity.context.Context; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | 0 | public class VelocityDirectScreen |
| 45 | |
extends VelocityScreen |
| 46 | |
{ |
| 47 | |
|
| 48 | 0 | private String prefix = getPrefix() + "/"; |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
public ConcreteElement buildTemplate(RunData data) |
| 59 | |
throws Exception |
| 60 | |
{ |
| 61 | 0 | Context context = TurbineVelocity.getContext(data); |
| 62 | |
|
| 63 | 0 | String screenTemplate = data.getTemplateInfo().getScreenTemplate(); |
| 64 | 0 | String templateName |
| 65 | |
= TurbineTemplate.getScreenTemplateName(screenTemplate); |
| 66 | |
|
| 67 | |
|
| 68 | 0 | if (StringUtils.isEmpty(templateName)) |
| 69 | |
{ |
| 70 | 0 | log.error("Screen " + screenTemplate + " not found!"); |
| 71 | 0 | throw new Exception("Could not find screen for " + screenTemplate); |
| 72 | |
} |
| 73 | |
|
| 74 | |
try |
| 75 | |
{ |
| 76 | 0 | TurbineVelocity.handleRequest(context, |
| 77 | |
prefix + templateName, |
| 78 | |
data.getResponse().getOutputStream()); |
| 79 | |
|
| 80 | |
} |
| 81 | 0 | catch (Exception e) |
| 82 | |
{ |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | 0 | context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, e.toString()); |
| 87 | 0 | context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, ExceptionUtils.getStackTrace(e)); |
| 88 | |
|
| 89 | 0 | templateName = Turbine.getConfiguration() |
| 90 | |
.getString(TurbineConstants.TEMPLATE_ERROR_KEY, |
| 91 | |
TurbineConstants.TEMPLATE_ERROR_VM); |
| 92 | |
|
| 93 | 0 | TurbineVelocity.handleRequest(context, |
| 94 | |
prefix + templateName, |
| 95 | |
data.getResponse().getOutputStream()); |
| 96 | 0 | } |
| 97 | |
|
| 98 | 0 | return null; |
| 99 | |
} |
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
public ConcreteElement buildTemplate(PipelineData pipelineData) |
| 109 | |
throws Exception |
| 110 | |
{ |
| 111 | 0 | RunData data = getRunData(pipelineData); |
| 112 | 0 | Context context = TurbineVelocity.getContext(pipelineData); |
| 113 | |
|
| 114 | 0 | String screenTemplate = data.getTemplateInfo().getScreenTemplate(); |
| 115 | 0 | String templateName |
| 116 | |
= TurbineTemplate.getScreenTemplateName(screenTemplate); |
| 117 | |
|
| 118 | |
|
| 119 | 0 | if (StringUtils.isEmpty(templateName)) |
| 120 | |
{ |
| 121 | 0 | log.error("Screen " + screenTemplate + " not found!"); |
| 122 | 0 | throw new Exception("Could not find screen for " + screenTemplate); |
| 123 | |
} |
| 124 | |
|
| 125 | |
try |
| 126 | |
{ |
| 127 | 0 | TurbineVelocity.handleRequest(context, |
| 128 | |
prefix + templateName, |
| 129 | |
data.getResponse().getOutputStream()); |
| 130 | |
|
| 131 | |
} |
| 132 | 0 | catch (Exception e) |
| 133 | |
{ |
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | 0 | context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, e.toString()); |
| 138 | 0 | context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, ExceptionUtils.getStackTrace(e)); |
| 139 | |
|
| 140 | 0 | templateName = Turbine.getConfiguration() |
| 141 | |
.getString(TurbineConstants.TEMPLATE_ERROR_KEY, |
| 142 | |
TurbineConstants.TEMPLATE_ERROR_VM); |
| 143 | |
|
| 144 | 0 | TurbineVelocity.handleRequest(context, |
| 145 | |
prefix + templateName, |
| 146 | |
data.getResponse().getOutputStream()); |
| 147 | 0 | } |
| 148 | |
|
| 149 | 0 | return null; |
| 150 | |
} |
| 151 | |
} |