KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > magnet > render > AbstractRenderable


1 package org.sapia.magnet.render;
2
3 // Import of Sapia's utility classes
4
// ---------------------------------
5
import org.sapia.util.text.TemplateElementIF;
6 import org.sapia.util.text.TemplateFactory;
7 import org.sapia.util.text.TemplateException;
8
9
10 /**
11  *
12  *
13  * @author Jean-Cedric Desrochers
14  *
15  * <dl>
16  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
17  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
18  * <a HREF="http://www.sapia-oss.org/license.html" target="sapia-license">license page</a> at the Sapia OSS web site</dd></dt>
19  * </dl>
20  */

21 public abstract class AbstractRenderable implements RenderableIF {
22
23   /////////////////////////////////////////////////////////////////////////////////////////
24
///////////////////////////////// INSTANCE ATTRIBUTES /////////////////////////////////
25
/////////////////////////////////////////////////////////////////////////////////////////
26

27   /** The template factory of this abstract renderable object. */
28   private TemplateFactory _theTemplateFactory;
29
30   /////////////////////////////////////////////////////////////////////////////////////////
31
//////////////////////////////////// CONSTRUCTORS /////////////////////////////////////
32
/////////////////////////////////////////////////////////////////////////////////////////
33

34   /**
35    * Creates a new AbstractRenderable instance.
36    */

37   protected AbstractRenderable() {
38     _theTemplateFactory = new TemplateFactory(
39             TemplateFactory.DEFAULT_STARTING_DELIMITER, TemplateFactory.DEFAULT_ENDING_DELIMITER);
40   }
41
42   /////////////////////////////////////////////////////////////////////////////////////////
43
/////////////////////////////////// HELPER METHODS ////////////////////////////////////
44
/////////////////////////////////////////////////////////////////////////////////////////
45

46   /**
47    * Utility methods that resolve the value passed with for the given context.
48    *
49    * @param aContext The context to use for the resolution operation.
50    * @param aValue The value to resolve.
51    * @exception RenderingException If an error occurs resolving the value.
52    */

53   protected String JavaDoc resolveValue(MagnetContext aContext, String JavaDoc aValue) throws RenderingException {
54     try {
55       if (aValue == null) {
56         return null;
57       } else {
58         TemplateElementIF aTemplate = _theTemplateFactory.parse(aValue);
59         return aTemplate.render(aContext);
60       }
61     } catch (TemplateException te) {
62       throw new RenderingException("Unable to resolve the value " + aValue, te);
63     }
64   }
65
66   /////////////////////////////////////////////////////////////////////////////////////////
67
/////////////////////////////// INTERACE IMPLEMENTATION ///////////////////////////////
68
/////////////////////////////////////////////////////////////////////////////////////////
69

70   /**
71    * Renders this objects to the magnet context passed in.
72    *
73    * @param aContext The magnet context to use.
74    * @exception RenderingException If an error occurs while rendering this object.
75    */

76   public void render(MagnetContext aContext) throws RenderingException {
77   }
78 }
79
Popular Tags