1 16 17 package org.apache.struts.faces.renderer; 18 19 20 import java.util.ArrayList ; 21 import java.util.Iterator ; 22 23 import javax.faces.component.UIComponent; 24 import javax.faces.component.UIParameter; 25 import javax.faces.component.ValueHolder; 26 import javax.faces.context.FacesContext; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.struts.Globals; 31 import org.apache.struts.util.MessageResources; 32 import org.apache.struts.util.ResponseUtils; 33 34 35 41 42 public class MessageRenderer extends WriteRenderer { 43 44 45 47 48 51 private static Log log = LogFactory.getLog(MessageRenderer.class); 52 53 54 56 57 59 60 71 protected String getText(FacesContext context, UIComponent component) { 72 73 String bundle = (String ) component.getAttributes().get("bundle"); 75 if (bundle == null) { 76 bundle = Globals.MESSAGES_KEY; 77 } 78 MessageResources resources = (MessageResources) 79 context.getExternalContext().getApplicationMap().get(bundle); 80 if (resources == null) { throw new IllegalArgumentException ("MessageResources bundle " + 82 bundle + " not found"); 83 } 84 85 Object value = component.getAttributes().get("key"); 87 if (value == null) { 88 value = ((ValueHolder) component).getValue(); 89 } 90 if (value == null) { throw new NullPointerException ("Component '" + 92 component.getClientId(context) + 93 "' has no current value"); 94 } 95 String key = value.toString(); 96 97 ArrayList list = new ArrayList (); 99 Iterator kids = component.getChildren().iterator(); 100 while (kids.hasNext()) { 101 UIComponent kid = (UIComponent) kids.next(); 102 if (!(kid instanceof UIParameter)) { 103 continue; 104 } 105 list.add(((UIParameter) kid).getValue()); 106 } 107 Object args[] = list.toArray(new Object [list.size()]); 108 109 String text = resources.getMessage(context.getViewRoot().getLocale(), 111 key, args); 112 Boolean filter = (Boolean ) component.getAttributes().get("filter"); 113 if (filter == null) { 114 filter = Boolean.FALSE; 115 } 116 if (filter.booleanValue()) { 117 return (ResponseUtils.filter(text)); 118 } else { 119 return (text); 120 } 121 122 } 123 124 125 } 126 | Popular Tags |