01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: PrintTemplate.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.engine.elements;
09:
10: import com.uwyn.rife.engine.Element;
11: import com.uwyn.rife.engine.annotations.Elem;
12: import com.uwyn.rife.engine.exceptions.PropertyRequiredException;
13: import com.uwyn.rife.engine.exceptions.UnsupportedTemplateTypeException;
14: import com.uwyn.rife.template.Template;
15: import com.uwyn.rife.template.TemplateFactory;
16:
17: @Elem
18: public class PrintTemplate extends Element {
19: public Template getTemplate() {
20: // obtain the optional template_type property
21: String template_type = null;
22: if (hasProperty("type")) {
23: template_type = getPropertyString("type");
24: }
25: // for backwards compatibility
26: else if (hasProperty("template_type")) {
27: template_type = getPropertyString("template_type");
28: } else {
29: template_type = "enginehtml";
30: }
31:
32: // obtain the optional template_encoding property
33: String template_encoding = null;
34: if (hasProperty("encoding")) {
35: template_encoding = getPropertyString("encoding");
36: }
37: // for backwards compatibility
38: else if (hasProperty("template_encoding")) {
39: template_encoding = getPropertyString("template_encoding");
40: }
41:
42: // obtain the mandatory template_name property
43: String template_name = null;
44: if (hasProperty("name")) {
45: template_name = getPropertyString("name");
46: }
47: // for backwards compatibility
48: else if (hasProperty("template_name")) {
49: template_name = getPropertyString("template_name");
50: } else {
51: throw new PropertyRequiredException(getDeclarationName(),
52: "name");
53: }
54:
55: // get a template instance and print it
56: TemplateFactory template_factory = null;
57: Template template = null;
58:
59: template_factory = TemplateFactory.getFactory(template_type);
60: if (null == template_factory) {
61: throw new UnsupportedTemplateTypeException(template_type);
62: }
63: template = template_factory.get(template_name,
64: template_encoding, null);
65:
66: return template;
67: }
68:
69: public void processElement() {
70: print(getTemplate());
71: }
72: }
|