1 /*
2 * Copyright (c) 2003
3 * Information Desire GmbH
4 * All rights reserved.
5 */
6 package com.infodesire.infobit.render.velocity;
7
8 import org.apache.commons.collections.ExtendedProperties;
9
10 import org.apache.velocity.exception.ResourceNotFoundException;
11 import org.apache.velocity.runtime.RuntimeServices;
12 import org.apache.velocity.runtime.resource.Resource;
13 import org.apache.velocity.runtime.resource.loader.ResourceLoader;
14
15 import com.infodesire.infobit.InfobitManager;
16 import com.infodesire.infobit.data.Infobit;
17 import com.infodesire.infobit.data.Version;
18 import com.infodesire.infobit.data.Content;
19 import com.infodesire.infobit.data.TextContent;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import java.io.InputStream;
25 /***
26 * infobit resource loader. loads version by infobit name. delegates back to
27 * infobit renderer for recursive rendering.
28 *
29 * @author konstantin
30 * @created August 21, 2003
31 * @version $Revision: 1.3 $
32 */
33 public class InfobitTemplateLoader extends ResourceLoader {
34 private static Log _log = LogFactory.getLog(InfobitTemplateLoader.class);
35
36 InfobitManager _manager = null;
37 VelocityRenderer _renderer = null;
38
39
40 /***
41 * Get an InputStream so that the Runtime can build a template with it.
42 *
43 * @param name name of template to get
44 * @return InputStream containing the template
45 * @throws ResourceNotFoundException if template not found in classpath.
46 */
47 public synchronized InputStream getResourceStream(String name)
48 throws ResourceNotFoundException {
49
50 if (name == null || name.length() == 0) {
51 throw new ResourceNotFoundException("No infobit template name provided");
52 }
53 try {
54 if (_log.isDebugEnabled()) {
55 _log.debug("retrieving " + name);
56 }
57 return _renderer.getTemplate(name);
58 } catch (Exception ex) {
59 _log.error("exception occured while loading infobit template:", ex);
60 throw new ResourceNotFoundException(ex.getMessage());
61 }
62 }
63
64
65 /***
66 * @param resource Description of Parameter
67 * @return The SourceModified value
68 * @todo develop checking of last modification date
69 */
70 public boolean isSourceModified(Resource resource) {
71 return false;
72 }
73
74
75 /***
76 * @param resource Description of Parameter
77 * @return The LastModified value
78 * @todo return real last modification date ( version date )
79 */
80 public long getLastModified(Resource resource) {
81 return 0;
82 }
83
84
85 /***
86 * initialize loader
87 *
88 * @param configuration Description of Parameter
89 */
90 public void init(ExtendedProperties configuration) {
91 rsvc.info("InfobitTemplateLoader : initialization starting.");
92 Object obj = rsvc.getApplicationAttribute(InfobitManager.class.getName());
93 if (obj instanceof InfobitManager) {
94 _manager = (InfobitManager) obj;
95 }
96 else {
97 rsvc.error("InfobitTemplateLoader : unable to retrieve Infobit manager");
98 }
99 obj = rsvc.getApplicationAttribute(VelocityRenderer.class.getName());
100 if (obj instanceof VelocityRenderer) {
101 _renderer = (VelocityRenderer) obj;
102 }
103 else {
104 rsvc.error("InfobitTemplateLoader : unable to retrieve velocity renderer");
105 }
106 rsvc.info("InfobitTemplateLoader : initialization complete.");
107 }
108 }
This page was automatically generated by Maven