mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Fix for AWC-394
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2333 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,10 +18,12 @@
|
||||
package org.alfresco.web.ui.common.component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import javax.faces.component.UIOutput;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.ResponseWriter;
|
||||
import javax.faces.el.ValueBinding;
|
||||
|
||||
/**
|
||||
* Component that simply renders text
|
||||
@@ -30,6 +32,8 @@ import javax.faces.context.ResponseWriter;
|
||||
*/
|
||||
public class UIOutputText extends UIOutput
|
||||
{
|
||||
private Boolean encodeForJavaScript = null;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
@@ -45,6 +49,40 @@ public class UIOutputText extends UIOutput
|
||||
{
|
||||
return "org.alfresco.faces.OutputText";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the text should be encoded for JavaScript consumption
|
||||
*
|
||||
* @param encodeForJavaScript true to escape text
|
||||
*/
|
||||
public void setEncodeForJavaScript(boolean encodeForJavaScript)
|
||||
{
|
||||
this.encodeForJavaScript = Boolean.valueOf(encodeForJavaScript);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the text is going to be encoded or not
|
||||
*
|
||||
* @return true if the text is going to be encoded
|
||||
*/
|
||||
public boolean isEncodeForJavaScript()
|
||||
{
|
||||
if (this.encodeForJavaScript == null)
|
||||
{
|
||||
ValueBinding vb = getValueBinding("encodeForJavaScript");
|
||||
if (vb != null)
|
||||
{
|
||||
this.encodeForJavaScript = (Boolean)vb.getValue(getFacesContext());
|
||||
}
|
||||
|
||||
if (this.encodeForJavaScript == null)
|
||||
{
|
||||
this.encodeForJavaScript = Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return this.encodeForJavaScript.booleanValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
|
||||
@@ -57,6 +95,18 @@ public class UIOutputText extends UIOutput
|
||||
}
|
||||
|
||||
ResponseWriter out = context.getResponseWriter();
|
||||
out.write((String)getValue());
|
||||
|
||||
String output = null;
|
||||
|
||||
if (isEncodeForJavaScript())
|
||||
{
|
||||
output = URLEncoder.encode((String)getValue(), "UTF-8").replace('+', ' ');
|
||||
}
|
||||
else
|
||||
{
|
||||
output = (String)getValue();
|
||||
}
|
||||
|
||||
out.write(output);
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ import javax.faces.component.UIComponent;
|
||||
public class OutputTextTag extends HtmlComponentTag
|
||||
{
|
||||
private String value;
|
||||
private String encodeForJavaScript;
|
||||
|
||||
/**
|
||||
* @see javax.faces.webapp.UIComponentTag#getComponentType()
|
||||
@@ -51,6 +52,7 @@ public class OutputTextTag extends HtmlComponentTag
|
||||
{
|
||||
super.setProperties(component);
|
||||
setStringProperty(component, "value", this.value);
|
||||
setBooleanProperty(component, "encodeForJavaScript", this.encodeForJavaScript);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,6 +62,7 @@ public class OutputTextTag extends HtmlComponentTag
|
||||
{
|
||||
super.release();
|
||||
this.value = null;
|
||||
this.encodeForJavaScript = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,4 +74,14 @@ public class OutputTextTag extends HtmlComponentTag
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the encodeForJavaScript flag
|
||||
*
|
||||
* @param encodeForJavaScript true to encode the text for use in JavaScript
|
||||
*/
|
||||
public void setEncodeForJavaScript(String encodeForJavaScript)
|
||||
{
|
||||
this.encodeForJavaScript = encodeForJavaScript;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user