Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/arranger/jarl/script/jarlsp/SimpleJarlSPRuntime.java


1   package com.arranger.jarl.script.jarlsp;
2   
3   import com.arranger.jarl.util.Debug;
4   import com.arranger.jarl.util.StringTools;
5   import com.arranger.jarl.clazz.JarlClassLoader;
6   
7   import java.io.Writer;
8   import java.util.Map;
9   import java.util.HashMap;
10  import java.util.Date;
11  import java.text.SimpleDateFormat;
12  
13  /**
14   * SimpleISPRuntime created on Jan 17, 2003
15   */
16  public class SimpleJarlSPRuntime implements JarlSPRuntime {
17  
18      protected Writer m_writer;
19      protected Map m_properties;
20  
21      protected String m_classOutput;
22  
23  
24      public SimpleJarlSPRuntime(String classOutput) {
25          m_classOutput = classOutput;
26      }
27  
28      public Writer getWriter() {
29          return m_writer;
30      }
31  
32      /**
33       * Returns specified parameter.
34       *
35       * @param name Name of parameter to get.
36       * @return Parameter value or null if not found.
37       */
38      public Object get(String name) {
39          return m_properties.get(name);
40      }
41  
42      /**
43       * Get all the current properties
44       */
45      public Map getProperties() {
46          return m_properties;
47      }
48  
49      /**
50       * Sets the specified parameter
51       *
52       * @param name Name of parameter to set
53       * @param value parameter value to set
54       */
55      public void put(String name, Object value) {
56          m_properties.put(name, value);
57      }
58  
59      /**
60       * Executes an jarlsp based upon its className
61       * @param jarlspClassName name of the class to execute
62       * @param writer the writer to use
63       * @param properties for this jarlSP
64       * @throws Exception
65       */
66      public void execute(String jarlspClassName, Writer writer, Map properties) throws Exception {
67          Writer origWriter = m_writer;
68          Map origProps = m_properties;
69          try {
70              m_writer = writer;
71              m_properties = (properties == null) ? new HashMap() : properties;
72  
73              //new classLoader
74              JarlSPBase jarlspBase = getJarlSPBase(jarlspClassName);
75  
76              //initialize
77              Map props = new HashMap();
78              props.put("page.title", StringTools.getLastSegment(jarlspBase.getClass().getName(), ".", false));
79              props.put("last.updated", new SimpleDateFormat("EEEE, MMMM dd -- yyyy").format(new Date()));
80              jarlspBase.init(this, props);
81  
82              //render it
83              jarlspBase.execute();
84          } catch (Exception e) {
85              Debug.warn(Debug.getStackTrace(e));
86              Debug.warn(e.toString());
87          } finally {
88              m_writer = origWriter;
89              m_properties = origProps;
90          }
91      }
92  
93      protected JarlSPBase getJarlSPBase(String ispClassName) throws Exception {
94          JarlClassLoader jarlLoader = new JarlClassLoader(m_classOutput, StringTools.stripLastSegment(ispClassName, "."));
95          JarlSPBase jarlspBase = (JarlSPBase)jarlLoader.findClass(ispClassName).newInstance();
96          return jarlspBase;
97      }
98  }