1 18 package org.alfresco.web.ui.common.component; 19 20 import java.io.IOException ; 21 import java.net.URLEncoder ; 22 23 import javax.faces.component.UIOutput; 24 import javax.faces.context.FacesContext; 25 import javax.faces.context.ResponseWriter; 26 import javax.faces.el.ValueBinding; 27 28 33 public class UIOutputText extends UIOutput 34 { 35 private Boolean encodeForJavaScript = null; 36 37 40 public UIOutputText() 41 { 42 setRendererType(null); 43 } 44 45 48 public String getFamily() 49 { 50 return "org.alfresco.faces.OutputText"; 51 } 52 53 56 public void restoreState(FacesContext context, Object state) 57 { 58 Object values[] = (Object [])state; 59 super.restoreState(context, values[0]); 61 this.encodeForJavaScript = (Boolean )values[1]; 62 } 63 64 67 public Object saveState(FacesContext context) 68 { 69 Object values[] = new Object [3]; 70 values[0] = super.saveState(context); 72 values[1] = this.encodeForJavaScript; 73 return values; 74 } 75 76 81 public void setEncodeForJavaScript(boolean encodeForJavaScript) 82 { 83 this.encodeForJavaScript = Boolean.valueOf(encodeForJavaScript); 84 } 85 86 91 public boolean isEncodeForJavaScript() 92 { 93 if (this.encodeForJavaScript == null) 94 { 95 ValueBinding vb = getValueBinding("encodeForJavaScript"); 96 if (vb != null) 97 { 98 this.encodeForJavaScript = (Boolean )vb.getValue(getFacesContext()); 99 } 100 101 if (this.encodeForJavaScript == null) 102 { 103 this.encodeForJavaScript = Boolean.FALSE; 104 } 105 } 106 107 return this.encodeForJavaScript.booleanValue(); 108 } 109 110 113 public void encodeBegin(FacesContext context) throws IOException 114 { 115 if (isRendered() == false) 116 { 117 return; 118 } 119 120 ResponseWriter out = context.getResponseWriter(); 121 122 String output = null; 123 124 if (isEncodeForJavaScript()) 125 { 126 output = URLEncoder.encode((String )getValue(), "UTF-8").replace('+', ' '); 127 } 128 else 129 { 130 output = (String )getValue(); 131 } 132 133 out.write(output); 134 } 135 } 136 | Popular Tags |