KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > modules > parameters > ParameterPresentationStyle


1 /*
2  * Copyright 2000-2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jetspeed.modules.parameters;
18
19 // Turbine support
20
import org.apache.turbine.modules.Assembler;
21 import org.apache.turbine.util.RunData;
22
23 // Jetspeed logging classes
24
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
25 import org.apache.jetspeed.services.logging.JetspeedLogger;
26
27 // Java support
28
import java.util.Map JavaDoc;
29 import java.util.Hashtable JavaDoc;
30 import java.util.Iterator JavaDoc;
31
32 /**
33  * Interface to be implemented by parameter presentation style class
34  *
35  * @author <a HREF="mailto:mark_orciuch@ngsltd.com">Mark Orciuch</a>
36  * @version $Id: ParameterPresentationStyle.java,v 1.4 2004/02/23 03:01:20 jford Exp $
37  */

38 public abstract class ParameterPresentationStyle extends Assembler
39 {
40
41     /**
42      * Static initialization of the logger for this class
43      */

44     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(ParameterPresentationStyle.class.getName());
45     
46     private Map JavaDoc styleparms = null;
47
48     /**
49      * Returns presentation method html fragment
50      *
51      * @param data run context info
52      * @param name name for the returned control
53      * @param value default value for the control
54      * @param parms hashtable with presentation parameters
55      * @return html for the control
56      */

57     public abstract String JavaDoc getContent(RunData data, String JavaDoc name, String JavaDoc value, Map JavaDoc parms);
58
59     /**
60      * Allows to initialize style parameter hashtable
61      *
62      * @param parms
63      */

64     public void setParms(Map JavaDoc parms)
65     {
66
67         this.styleparms = parms;
68     }
69
70     /**
71      * Allows to retrieve a style parameter with default
72      *
73      * @param key
74      * @param def
75      * @return object
76      */

77     public Object JavaDoc getParm(String JavaDoc key, Object JavaDoc def)
78     {
79
80         Object JavaDoc result = null;
81
82         if ( this.styleparms != null )
83         {
84             result = this.styleparms.get(key);
85         }
86
87         if ( result == null )
88         {
89             result = def;
90         }
91
92         return result;
93     }
94
95     /**
96      * <P>Returns javascript event definitions as defined by "[name].style.javascript:[event]".</P>
97      * <P> For example: <CODE>symbols.style.javascipt:onChange</CODE>
98      *
99      * @return map of javascript events
100      */

101     public Map JavaDoc getJavascriptEvents()
102     {
103
104         Hashtable JavaDoc result = null;
105
106         if (this.styleparms != null)
107         {
108              Iterator JavaDoc it = this.styleparms.keySet().iterator();
109              while (it.hasNext())
110              {
111                  String JavaDoc parmkey = (String JavaDoc) it.next();
112                  if (parmkey.startsWith("javascript:"))
113                  {
114                      try
115                      {
116                          if (result == null)
117                          {
118                              result = new Hashtable JavaDoc();
119                          }
120                          String JavaDoc event = parmkey.substring(parmkey.lastIndexOf(":") + 1);
121                          result.put(event, this.styleparms.get(parmkey));
122                      }
123                      catch (Exception JavaDoc e)
124                      {
125                          logger.error("Exception", e);
126                      }
127                  }
128              }
129          }
130
131         return result;
132     }
133
134 }
Popular Tags