1 23 package com.sun.enterprise.tools.jsfext.component.factory.basic; 24 25 import com.sun.enterprise.tools.jsfext.component.factory.ComponentFactoryBase; 26 import com.sun.enterprise.tools.jsfext.layout.descriptor.LayoutComponent; 27 28 import com.sun.web.ui.util.MessageUtil; 29 30 import javax.faces.component.UIComponent; 31 import javax.faces.component.html.HtmlOutputText; 32 import javax.faces.context.FacesContext; 33 34 35 41 public class LocalizedStringFactory extends ComponentFactoryBase { 42 43 54 public UIComponent create(FacesContext context, LayoutComponent descriptor, UIComponent parent) { 55 String baseName = 57 (String ) descriptor.getEvaluatedOption(context, BASE_NAME, parent); 58 if (baseName == null) { 59 throw new IllegalArgumentException ("'" + BASE_NAME 60 + "' is missing for LayoutComponent: '" 61 + descriptor.getUnevaluatedId() + "'!"); 62 } 63 String key = 64 (String ) descriptor.getEvaluatedOption(context, KEY, parent); 65 if (key == null) { 66 throw new IllegalArgumentException ("'" + KEY 67 + "' is missing for LayoutComponent: '" 68 + descriptor.getUnevaluatedId() + "'!"); 69 } 70 71 Object parameters = 73 descriptor.getEvaluatedOption(context, PARAMETERS, parent); 74 Object [] args = null; 75 if (parameters != null) { 76 if (parameters.getClass().isArray()) { 78 args = (Object []) parameters; 79 } else { 80 args = new Object [] {parameters.toString()}; 82 } 83 } 84 85 String value = MessageUtil.getMessage(context, baseName, key, args); 87 88 HtmlOutputText output = new HtmlOutputText(); 90 91 if (parent != null) { 94 addChild(context, descriptor, parent, output); 95 } 96 97 output.setValue(value); 99 100 setOptions(context, descriptor, output); 102 103 return output; 105 } 106 107 108 112 public static final String BASE_NAME = "baseName"; 113 114 117 public static final String KEY = "key"; 118 119 123 public static final String PARAMETERS = "parameters"; 124 } 125 | Popular Tags |