KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > renderkit > dom_html_basic > DomBasicRenderer


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.faces.renderkit.dom_html_basic;
35
36 import com.icesoft.faces.context.DOMContext;
37 import com.icesoft.faces.context.effects.CurrentStyle;
38 import com.icesoft.faces.context.effects.JavascriptContext;
39 import com.icesoft.faces.util.Debug;
40 import org.w3c.dom.Element JavaDoc;
41
42 import javax.faces.FactoryFinder;
43 import javax.faces.application.Application;
44 import javax.faces.application.ApplicationFactory;
45 import javax.faces.application.FacesMessage;
46 import javax.faces.application.FacesMessage.Severity;
47 import javax.faces.component.NamingContainer;
48 import javax.faces.component.UICommand;
49 import javax.faces.component.UIComponent;
50 import javax.faces.component.UIForm;
51 import javax.faces.component.UIInput;
52 import javax.faces.component.UIMessage;
53 import javax.faces.component.UIParameter;
54 import javax.faces.component.ValueHolder;
55 import javax.faces.component.html.HtmlMessage;
56 import javax.faces.component.html.HtmlMessages;
57 import javax.faces.context.FacesContext;
58 import javax.faces.convert.Converter;
59 import javax.faces.convert.ConverterException;
60 import javax.faces.render.Renderer;
61 import java.beans.Beans JavaDoc;
62 import java.io.IOException JavaDoc;
63 import java.util.HashMap JavaDoc;
64 import java.util.Iterator JavaDoc;
65 import java.util.Map JavaDoc;
66 import java.util.Set JavaDoc;
67
68 public abstract class DomBasicRenderer extends Renderer {
69
70
71     // iceSubmitPartial
72
public final String JavaDoc ICESUBMITPARTIAL =
73             "iceSubmitPartial(form, this, event);";
74     // iceSubmit
75
public final String JavaDoc ICESUBMIT = "iceSubmit(form,this,event);";
76
77     // component family constants for UIForm and WebUIForm
78
public static final String JavaDoc WEB_UIFORM = "com.sun.rave.web.ui.Form";
79     public static final String JavaDoc UIFORM = "javax.faces.form";
80     public static final String JavaDoc WEB_UIJSFFORM = "com.sun.webui.jsf.Form";
81
82     public void decode(FacesContext facesContext, UIComponent uiComponent) {
83         CurrentStyle.decode(facesContext, uiComponent);
84         validateParameters(facesContext, uiComponent, null);
85         // only need to decode input components
86
if (!(uiComponent instanceof UIInput)) {
87             return;
88         }
89         // only need to decode enabled, writable components
90
if (isStatic(uiComponent)) {
91             return;
92         }
93         // extract component value from the request map
94
String JavaDoc clientId = uiComponent.getClientId(facesContext);
95         Debug.assertTrue(clientId != null,
96                          "Client id is not defined for decoding");
97         Map JavaDoc requestMap =
98                 facesContext.getExternalContext().getRequestParameterMap();
99         if (requestMap.containsKey(clientId)) {
100             String JavaDoc decodedValue = (String JavaDoc) requestMap.get(clientId);
101             setSubmittedValue(uiComponent, decodedValue);
102         }
103     }
104
105     /**
106      * This method should be overridden by renderers for components who subclass
107      * UIInput
108      *
109      * @param uiComponent
110      * @param value
111      */

112     public void setSubmittedValue(UIComponent uiComponent, Object JavaDoc value) {
113     }
114
115     /**
116      * Delegate rendering to the renderEnd(..) method after validating
117      * parameters and before maintaining the cursor position. The renderEnd
118      * method should be overridden by subclasses of this class so that the
119      * common infrastructure of parameter validation and cursor maintenance are
120      * provided here.
121      */

122     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
123             throws IOException JavaDoc {
124         validateParameters(facesContext, uiComponent, null);
125         renderEnd(facesContext, uiComponent,
126                   getValue(facesContext, uiComponent));
127         DOMContext domContext =
128                 DOMContext.attachDOMContext(facesContext, uiComponent);
129
130         domContext.stepOver();
131         JavascriptContext.fireEffect(uiComponent, facesContext);
132     }
133
134     /**
135      * Get the submitted value from the UIComponent argument. If the UIComponent
136      * is not an instance of UIInput, or its <code>getSubmittedValue()</code>
137      * method returns null or a non-String value, then an attempt is made to
138      * obtain the value from the UIComponent's renderer. Conversion is performed
139      * on a value obtained from the renderer.
140      *
141      * @param facesContext
142      * @param uiComponent
143      * @return String the submitted value
144      */

145     String JavaDoc getValue(FacesContext facesContext, UIComponent uiComponent) {
146         // for input components, get the submitted value
147
if (uiComponent instanceof UIInput) {
148             Object JavaDoc submittedValue = ((UIInput) uiComponent).getSubmittedValue();
149             if (submittedValue != null && submittedValue instanceof String JavaDoc) {
150                 return (String JavaDoc) submittedValue;
151             }
152         }
153         return formatComponentValue(facesContext, uiComponent,
154                                     getValue(uiComponent));
155     }
156
157     Object JavaDoc getValue(UIComponent uiComponent) {
158         return null;
159     }
160
161
162     /**
163      * The common infrastructure of parameter validation and cursor management
164      * will be provided by the encodeEnd method and rendering is delegated to
165      * this method. Renderers should override this method instead of encodeEnd
166      * to provide rendering at the time of execution of the encodeEnd method.
167      *
168      * @param facesContext
169      * @param uiComponent
170      * @param currentValue
171      * @throws IOException
172      */

173     protected void renderEnd(FacesContext facesContext,
174                              UIComponent uiComponent, String JavaDoc currentValue)
175             throws IOException JavaDoc {
176     }
177
178     /**
179      * If the parameter UIComponent instance is a ValueHolder, return the
180      * currentValue parameter. If there is a converter registered with the
181      * component then use the converter to obtain a String value.
182      *
183      * @param facesContext
184      * @param uiComponent
185      * @param currentValue
186      * @return
187      * @throws ConverterException
188      */

189     String JavaDoc formatComponentValue(FacesContext facesContext,
190                                 UIComponent uiComponent, Object JavaDoc currentValue)
191             throws ConverterException {
192
193         if (currentValue == null) {
194             return null;
195         }
196
197         if (!(uiComponent instanceof ValueHolder)) {
198             return currentValue.toString();
199         }
200
201         // look to see whether there is a converter registered with the component
202
Converter converter = ((ValueHolder) uiComponent).getConverter();
203
204         // if there was no converter registered with the component then
205
// look for the default converter for the Class of the currentValue
206
if (converter == null) {
207             if (currentValue instanceof String JavaDoc) {
208                 return (String JavaDoc) currentValue;
209             }
210             converter = getConverterForClass(currentValue.getClass());
211         }
212
213         if (converter == null) {
214             return currentValue.toString();
215         } else {
216             // Don't convert currentValues that are already a String. Some 3rd party converters attempt
217
// to cast this to a specific instance.
218
if (currentValue instanceof String JavaDoc) {
219                 return (String JavaDoc) currentValue;
220             }
221             return converter
222                     .getAsString(facesContext, uiComponent, currentValue);
223         }
224     }
225
226     /**
227      * Find the UIComponent whose id is given by the for attribute of the
228      * UIComponent parameter.
229      *
230      * @param facesContext
231      * @param uiComponent
232      * @return the UIComponent associated with the component id indicated by the
233      * value of the for attribute of the UIComponent parameter.
234      */

235     public static UIComponent findForComponent(FacesContext facesContext,
236                                                UIComponent uiComponent) {
237
238         String JavaDoc forComponentId = null;
239         if (uiComponent instanceof UIMessage) {
240             forComponentId = ((UIMessage) uiComponent).getFor();
241         } else {
242             forComponentId =
243                     (String JavaDoc) uiComponent.getAttributes().get(HTML.FOR_ATTR);
244         }
245
246         if (forComponentId == null) {
247             return null;
248         }
249         if (forComponentId.length() == 0) {
250             return null;
251         }
252
253         // Look for the 'for' component in the nearest parental naming container
254
// of the UIComponent (there's actually a bit more to this search - see
255
// the docs for the findComponent method
256
UIComponent forComponent = uiComponent.findComponent(forComponentId);
257
258         // Since the nearest naming container may be nested, search the
259
// next-to-nearest parental naming container in a recursive fashion,
260
// until we get to the view root
261
if (forComponent == null) {
262             UIComponent nextParent = uiComponent;
263             while (true) {
264                 nextParent = nextParent.getParent();
265                 // avoid extra searching by going up to the next NamingContainer
266
// (see the docs for findComponent for an information that will
267
// justify this approach)
268
while (nextParent != null &&
269                        !(nextParent instanceof NamingContainer)) {
270                     nextParent = nextParent.getParent();
271                 }
272                 if (nextParent == null) {
273                     break;
274                 } else {
275                     forComponent = nextParent.findComponent(forComponentId);
276                 }
277                 if (forComponent != null) {
278                     break;
279                 }
280             }
281         }
282
283         // There is one other situation to cover: if the 'for' component
284
// is not situated inside a NamingContainer then the algorithm above
285
// will not have found it. We need, in this case, to search for the
286
// component from the view root downwards
287
if (forComponent == null) {
288             forComponent = searchDownwardsForChildComponentWithId(
289                     facesContext.getViewRoot(),
290                     forComponentId);
291         }
292         return forComponent;
293     }
294
295     /**
296      * Retrieve the array of excluded attributes. This array should be
297      * constructed in the renderer class and then passed in to the
298      * PassThruAttributeRenderer.
299      *
300      * @return a String array of excluded attributes.
301      */

302     public static String JavaDoc[] getExcludesArray(Set JavaDoc excludes) {
303         String JavaDoc[] excludesArray = new String JavaDoc[excludes.size()];
304         excludes.toArray(excludesArray);
305         return excludesArray;
306     }
307
308     private static UIComponent searchDownwardsForChildComponentWithId(
309             UIComponent parent,
310             String JavaDoc searchChildId) {
311         UIComponent foundChild = null;
312         Iterator JavaDoc children = parent.getChildren().iterator();
313         UIComponent nextChild = null;
314         while (children.hasNext()) {
315             nextChild = (UIComponent) children.next();
316             if (nextChild instanceof NamingContainer) {
317                 foundChild = nextChild.findComponent(searchChildId);
318             }
319             if (foundChild == null) {
320                 searchDownwardsForChildComponentWithId(nextChild,
321                                                        searchChildId);
322             }
323             if (foundChild != null) {
324                 break;
325             }
326         }
327         return foundChild;
328     }
329
330     /**
331      * Recursively render the parent UIComponent instance and its children.
332      *
333      * @param facesContext
334      * @param parent
335      * @throws IOException
336      */

337     public static void encodeParentAndChildren(FacesContext facesContext,
338                                                UIComponent parent)
339             throws IOException JavaDoc {
340         parent.encodeBegin(facesContext);
341         if (parent.getRendersChildren()) {
342             parent.encodeChildren(facesContext);
343         } else {
344             Iterator JavaDoc children = parent.getChildren().iterator();
345             while (children.hasNext()) {
346                 UIComponent nextChild = (UIComponent) children.next();
347                 if (nextChild.isRendered()) {
348                     encodeParentAndChildren(facesContext, nextChild);
349                 }
350             }
351         }
352         parent.encodeEnd(facesContext);
353     }
354
355
356     protected static UIComponent getFacetByName(UIComponent uiComponent,
357                                                 String JavaDoc name) {
358         UIComponent facet = uiComponent.getFacet(name);
359         if (facet == null) {
360             return null;
361         }
362         if (!facet.isRendered()) {
363             return null;
364         }
365         return facet;
366     }
367
368     static boolean idNotNull(UIComponent uiComponent) {
369         return (uiComponent.getId() != null);
370     }
371
372     /**
373      * Set the id of the root element of the DOMContext associated with the
374      * UIComponent parameter.
375      *
376      * @param facesContext
377      * @param rootElement
378      * @param uiComponent
379      */

380     public static void setRootElementId(FacesContext facesContext,
381                                         Element JavaDoc rootElement,
382                                         UIComponent uiComponent) {
383         if (idNotNull(uiComponent)) {
384             rootElement
385                     .setAttribute("id", uiComponent.getClientId(facesContext));
386         }
387     }
388
389     /**
390      * <p/>
391      * Sets a non-null, non-empty-string, UIComponent property to the
392      * corresponding DOM Element
393      * <p/>
394      *
395      * @param uiComponent the source of the attribute value
396      * @param targetElement the DOM Element that will receive the
397      * attribute
398      * @param attrNameInComponent the property name in the UIComponent object
399      * @param attrNameInDom the attribute name in the DOM Element
400      */

401     public static void renderAttribute(UIComponent uiComponent,
402                                        Element JavaDoc targetElement,
403                                        String JavaDoc attrNameInComponent,
404                                        String JavaDoc attrNameInDom) {
405         Object JavaDoc attrValue = uiComponent.getAttributes().get(attrNameInComponent);
406         if (attrValue != null && !attrValue.equals("")) {
407             if (attrValue.toString().equalsIgnoreCase("true") ||
408                 attrValue.toString().equalsIgnoreCase("false")) {
409                 boolean trueValue =
410                         new Boolean JavaDoc(attrValue.toString()).booleanValue();
411                 if (!trueValue) {
412                     targetElement.removeAttribute(attrNameInDom.toString());
413                     return;
414                 }
415             }
416             targetElement.setAttribute(attrNameInDom.toString(),
417                                        attrValue.toString());
418         }
419     }
420
421
422     /**
423      * Due to the behaviour of the UIParameter class, the names in the
424      * name-value pairs of the Map returned by this method are guaranteed to be
425      * Strings
426      *
427      * @param uiComponent
428      * @return Map the parameterMap
429      */

430     static Map JavaDoc getParameterMap(UIComponent uiComponent) {
431         Map JavaDoc parameterMap = new HashMap JavaDoc();
432         Iterator JavaDoc children = uiComponent.getChildren().iterator();
433         while (children.hasNext()) {
434             UIComponent nextChild = (UIComponent) children.next();
435             if (nextChild instanceof UIParameter) {
436                 UIParameter uiParam = (UIParameter) nextChild;
437                 parameterMap.put(uiParam.getName(), uiParam.getValue());
438             }
439         }
440         return parameterMap;
441     }
442
443     /**
444      * Validates that the facesContext is not null, the uiComponent is not null,
445      * and that uiComponent is assignment-compatible with the
446      * validComponentType. Pass a null parameter for validComponentType to avoid
447      * any type checking.
448      *
449      * @param facesContext
450      * @param uiComponent
451      * @param validComponentType
452      * @throws NullPointerException if either of the facesContext or the
453      * uiComponent parameters are null or
454      * if a parent form is not
455      * found when the given UIComponent
456      * is a UIInput or UICommand,
457      * IllegalArgumentException if the
458      * validComponentType is not null and the
459      * uiComponent is not assignable to the given
460      * type.
461      */

462     public void validateParameters(FacesContext facesContext,
463                                    UIComponent uiComponent,
464                                    Class JavaDoc validComponentType) {
465
466         if (facesContext == null) {
467             throw new NullPointerException JavaDoc(
468                     "Invalid Parameter - FacesContext instance must not be null");
469         }
470         if (uiComponent == null) {
471             throw new NullPointerException JavaDoc(
472                     "Invalid Parameter - UIComponent instance must not be null");
473         }
474         if (!Beans.isDesignTime() && validComponentType != null &&
475             !(validComponentType.isInstance(uiComponent))) {
476             throw new IllegalArgumentException JavaDoc(
477                     "Invalid Parameter - UIComponent class should be ["
478                     + validComponentType +
479                     "] but it is an instance of ["
480                     + uiComponent.getClass() + "]");
481         }
482         
483         if ((uiComponent instanceof UIInput) || (uiComponent instanceof UICommand)) {
484             if (findForm(uiComponent) == null) {
485                 throw new NullPointerException JavaDoc("Missing Form - the UIComponent of type ["
486                         + uiComponent.getClass() + "] requires a containing form." );
487             }
488         }
489     }
490
491     /**
492      * A component is static if it is disabled or readonly.
493      *
494      * @param uiComponent
495      * @return true if the component is disabled or readonly
496      */

497     public static boolean isStatic(UIComponent uiComponent) {
498         // the algorithm here is to return true as soon as we get affirmation that
499
// the component is static
500
boolean isStatic = false;
501         Object JavaDoc disabled = uiComponent.getAttributes().get("disabled");
502         Object JavaDoc readonly = uiComponent.getAttributes().get("readonly");
503         if (disabled != null) {
504             if (disabled instanceof Boolean JavaDoc) {
505                 isStatic = ((Boolean JavaDoc) disabled).booleanValue();
506             } else if (disabled instanceof String JavaDoc) {
507                 isStatic = ((String JavaDoc) disabled).equalsIgnoreCase("true");
508             }
509         }
510         if (isStatic) {
511             return isStatic;
512         }
513         if (readonly != null) {
514             if (readonly instanceof Boolean JavaDoc) {
515                 return ((Boolean JavaDoc) readonly).booleanValue();
516             }
517             if (readonly instanceof String JavaDoc) {
518                 return ((String JavaDoc) readonly).equalsIgnoreCase("true");
519             }
520         }
521         return isStatic;
522     }
523
524     /**
525      * <p/>
526      * Given a UIComponent instance, recursively examine the heirarchy of parent
527      * UIComponents until the first NamingContainer is found. </p>
528      *
529      * @param uiComponent
530      * @return the nearest parent NamingContainer or null if none exist.
531      */

532     public static UIComponent findNamingContainer(UIComponent uiComponent) {
533         UIComponent parent = uiComponent.getParent();
534         while (parent != null) {
535             if (parent instanceof NamingContainer) {
536                 break;
537             }
538             parent = parent.getParent();
539         }
540         return parent;
541     }
542
543     /**
544      * <p/>
545      * Given a UIComponent instance, recursively examine the heirarchy of parent
546      * NamingContainers until a Form is found. </p>
547      *
548      * @param uiComponent the UIComponent instance
549      * @return form as the UIComponent instance
550      */

551     public static UIComponent findForm(UIComponent uiComponent) {
552         UIComponent parent = uiComponent.getParent();
553         while (parent != null && !(parent instanceof UIForm)) {
554             parent = findNamingContainer(parent);
555         }
556         UIComponent form = null;
557         // check family
558
if (parent != null &&
559             (parent.getFamily().equalsIgnoreCase(WEB_UIFORM) ||
560              parent.getFamily().equalsIgnoreCase(UIFORM) ||
561              parent.getFamily().equalsIgnoreCase(WEB_UIJSFFORM))) {
562             form = (UIComponent) parent;
563         }
564
565         if (form == null && Beans.isDesignTime()) {
566             form = uiComponent.getParent();
567         }
568         return form;
569     }
570
571     /**
572      * This method fabricates the clientId of a component. It should be used
573      * only when the clientId of the uiComponent is required in advance of the
574      * component existing. The uiComponentId may be provided by, for example, a
575      * label element with a 'for' attribute defined. The for attribute will be
576      * the id of the component that will eventually be created.
577      * <p/>
578      * Determine the id of the nearest parental naming container and prepend it
579      * to the id of the component's id.
580      *
581      * @param uiComponent
582      * @param facesContext
583      * @param uiComponentId
584      * @return
585      */

586     String JavaDoc fabricateClientId(UIComponent uiComponent,
587                              FacesContext facesContext, String JavaDoc uiComponentId) {
588         UIComponent parentNamingContainer = findNamingContainer(uiComponent);
589         String JavaDoc parentNamingContainerClientId = null;
590         if (parentNamingContainer == null) {
591             return uiComponentId;
592         } else {
593             parentNamingContainerClientId =
594                     parentNamingContainer.getClientId(facesContext);
595         }
596         return parentNamingContainerClientId
597                + NamingContainer.SEPARATOR_CHAR
598                + uiComponentId;
599     }
600
601     protected String JavaDoc[] getColumnStyleClasses(UIComponent uiComponent) {
602         return getStyleClasses(uiComponent, "columnClasses");
603     }
604
605     /**
606      * This method, given a component, will return an array of the component's
607      * row classes.
608      *
609      * @param uiComponent
610      * @return a String array of row classes defined in a tag attribute or
611      * defined by default, depending on the component. Can be a
612      * zero-length array
613      */

614     public String JavaDoc[] getRowStyleClasses(UIComponent uiComponent) {
615         return getStyleClasses(uiComponent, "rowClasses");
616     }
617
618     public String JavaDoc[] getStyleClasses(UIComponent uiComponent,
619                                      String JavaDoc styleClassAttributeName) {
620         String JavaDoc allStyleClasses = (String JavaDoc) uiComponent.getAttributes()
621                 .get(styleClassAttributeName);
622         if (allStyleClasses == null) {
623             return (new String JavaDoc[0]);
624         }
625
626         String JavaDoc separator = ",";
627         if (allStyleClasses.indexOf(separator) <= 0) {
628             separator = " ";
629         }
630         String JavaDoc[] styleClassesArray = allStyleClasses.trim().split(separator);
631         int numberOfStyles = styleClassesArray.length;
632         for (int i = 0; i < numberOfStyles; i++) {
633             styleClassesArray[i] = styleClassesArray[i].trim();
634         }
635         return styleClassesArray;
636     }
637
638     /**
639      * Get the style and style class associated with the severity of the
640      * FacesMessage
641      *
642      * @param uiComponent
643      * @param facesMessage
644      * @return
645      */

646     static String JavaDoc[] getStyleAndStyleClass(UIComponent uiComponent,
647                                           FacesMessage facesMessage) {
648         // obtain the severity style and severity style class
649
String JavaDoc severityStyle = null;
650         String JavaDoc severityStyleClass = null;
651         Severity messageSeverity = facesMessage.getSeverity();
652         if (messageSeverity == FacesMessage.SEVERITY_INFO) {
653             severityStyle =
654                     (String JavaDoc) uiComponent.getAttributes().get("infoStyle");
655             if (uiComponent instanceof HtmlMessage) {
656                 severityStyleClass = ((HtmlMessage) uiComponent).getInfoClass();
657             } else if (uiComponent instanceof HtmlMessages) {
658                 severityStyleClass =
659                         ((HtmlMessages) uiComponent).getInfoClass();
660             }
661         } else if (messageSeverity == FacesMessage.SEVERITY_WARN) {
662             severityStyle =
663                     (String JavaDoc) uiComponent.getAttributes().get("warnStyle");
664             if (uiComponent instanceof HtmlMessage) {
665                 severityStyleClass = ((HtmlMessage) uiComponent).getWarnClass();
666             } else if (uiComponent instanceof HtmlMessages) {
667                 severityStyleClass =
668                         ((HtmlMessages) uiComponent).getWarnClass();
669             }
670         } else if (messageSeverity == FacesMessage.SEVERITY_ERROR) {
671             severityStyle =
672                     (String JavaDoc) uiComponent.getAttributes().get("errorStyle");
673             if (uiComponent instanceof HtmlMessage) {
674                 severityStyleClass =
675                         ((HtmlMessage) uiComponent).getErrorClass();
676             } else if (uiComponent instanceof HtmlMessages) {
677                 severityStyleClass =
678                         ((HtmlMessages) uiComponent).getErrorClass();
679             }
680         } else if (messageSeverity == FacesMessage.SEVERITY_FATAL) {
681             severityStyle =
682                     (String JavaDoc) uiComponent.getAttributes().get("fatalStyle");
683             if (uiComponent instanceof HtmlMessage) {
684                 severityStyleClass =
685                         ((HtmlMessage) uiComponent).getFatalClass();
686             } else if (uiComponent instanceof HtmlMessages) {
687                 severityStyleClass =
688                         ((HtmlMessages) uiComponent).getFatalClass();
689             }
690         }
691
692         String JavaDoc style = null;
693         if (severityStyle != null) {
694             style = severityStyle;
695         } else {
696             style = (String JavaDoc) uiComponent.getAttributes().get("style");
697         }
698         String JavaDoc styleClass = null;
699         if (severityStyleClass != null) {
700             styleClass = severityStyleClass;
701         } else {
702             if (uiComponent instanceof HtmlMessage) {
703                 styleClass = ((HtmlMessage) uiComponent).getStyleClass();
704             } else if (uiComponent instanceof HtmlMessages) {
705                 styleClass = ((HtmlMessages) uiComponent).getStyleClass();
706             }
707         }
708         return new String JavaDoc[]{style, styleClass};
709     }
710
711     /**
712      * @param facesMessage
713      * @return
714      */

715     String JavaDoc[] getSummaryAndDetail(FacesMessage facesMessage) {
716         String JavaDoc summary = facesMessage.getSummary();
717         if (summary == null) {
718             summary = "";
719         }
720         String JavaDoc detail = facesMessage.getDetail();
721         if (detail == null) {
722             detail = "";
723         }
724         return new String JavaDoc[]{summary, detail};
725     }
726
727     /**
728      * @param uiComponent
729      * @return
730      */

731     boolean getToolTipAttribute(UIComponent uiComponent) {
732         boolean tooltip = false;
733         Object JavaDoc tooltipAttribute = uiComponent.getAttributes().get("tooltip");
734         if (tooltipAttribute instanceof Boolean JavaDoc
735             && ((Boolean JavaDoc) tooltipAttribute).booleanValue()) {
736             tooltip = true;
737         }
738         return tooltip;
739     }
740
741     /**
742      * @param converterClass
743      * @return
744      */

745     Converter getConverterForClass(Class JavaDoc converterClass) {
746         if (converterClass == null) {
747             return null;
748         }
749         try {
750             ApplicationFactory aFactory =
751                     (ApplicationFactory) FactoryFinder.getFactory(
752                             FactoryFinder.APPLICATION_FACTORY);
753             Application application = aFactory.getApplication();
754             return (application.createConverter(converterClass));
755         } catch (Exception JavaDoc e) {
756             return (null);
757         }
758     }
759
760     public static String JavaDoc getResourceURL(FacesContext context, String JavaDoc path) {
761         return context.getApplication().getViewHandler()
762                 .getResourceURL(context, path);
763     }
764 }
765
Popular Tags