View Javadoc
1 /* 2 * Copyright (c) 2003 3 * Information Desire GmbH 4 * All rights reserved. 5 */ 6 package com.infodesire.infobit.render.velocity; 7 import java.io.IOException; 8 import java.io.Writer; 9 10 import org.apache.velocity.context.InternalContextAdapter; 11 import org.apache.velocity.context.Context; 12 13 import org.apache.velocity.runtime.directive.InputBase; 14 15 import org.apache.velocity.runtime.RuntimeConstants; 16 17 import org.apache.velocity.runtime.parser.node.Node; 18 import org.apache.velocity.runtime.parser.node.SimpleNode; 19 20 import org.apache.velocity.runtime.resource.Resource; 21 22 import org.apache.velocity.exception.MethodInvocationException; 23 import org.apache.velocity.exception.ResourceNotFoundException; 24 import org.apache.velocity.exception.ParseErrorException; 25 26 import org.apache.velocity.Template; 27 28 import com.infodesire.infobit.data.Content; 29 30 /*** 31 * pluggable directive to render version content. it will delegate to velocity 32 * renderer to to render it appropriately. this directve shall be supplied with 33 * correct content object 34 * 35 * @author konstantin 36 * @created September 16, 2003 37 * @version $Revision: 1.1 $ 38 */ 39 public class ContentDirective extends InputBase { 40 41 /*** 42 * Return name of this directive. 43 * 44 * @return The Name value 45 */ 46 public String getName() { 47 return "content"; 48 } 49 50 51 /*** 52 * Return type of this directive. 53 * 54 * @return The Type value 55 */ 56 public int getType() { 57 return LINE; 58 } 59 60 61 /*** 62 * render given infobit content 63 * 64 * @param context Description of Parameter 65 * @param writer Description of Parameter 66 * @param node Description of Parameter 67 * @return Description of the Returned Value 68 * @exception IOException Description of Exception 69 * @exception ResourceNotFoundException Description of Exception 70 * @exception ParseErrorException Description of Exception 71 * @exception MethodInvocationException Description of Exception 72 */ 73 public boolean render(InternalContextAdapter context, 74 Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, 75 MethodInvocationException { 76 VelocityRenderer renderer = (VelocityRenderer) rsvc.getApplicationAttribute(VelocityRenderer.class.getName()); 77 if (renderer == null) { 78 rsvc.error("#content() error: no velocity renderer configured"); 79 return false; 80 } 81 82 // get supplied object 83 Object value = node.jjtGetChild(0).value(context); 84 85 // do we have it? 86 if (node.jjtGetChild(0) == null) { 87 rsvc.error("#content() error : null argument"); 88 return false; 89 } 90 91 // and is of correct type? 92 if (!(value instanceof Content)) { 93 rsvc.error("#content() error : supplied argument is not infobit content"); 94 return false; 95 } 96 97 renderer.renderContent(writer, (Content) value); 98 return true; 99 } 100 }

This page was automatically generated by Maven