use of javax.portlet.ClientDataRequest in project liferay-faces-bridge-impl by liferay.
the class ExternalContextImpl method getRequestCharacterEncoding.
@Override
public String getRequestCharacterEncoding() {
if (portletRequest instanceof ClientDataRequest) {
ClientDataRequest clientDataRequest = (ClientDataRequest) portletRequest;
String requestCharacterEncoding = clientDataRequest.getCharacterEncoding();
if (manageIncongruities) {
try {
incongruityContext.setRequestCharacterEncoding(requestCharacterEncoding);
} catch (Exception e) {
logger.error(e);
}
}
return requestCharacterEncoding;
} else {
if (manageIncongruities) {
return incongruityContext.getRequestCharacterEncoding();
} else {
// returned, so throwing an IllegalStateException is not an option.
return null;
}
}
}
use of javax.portlet.ClientDataRequest in project liferay-faces-bridge-impl by liferay.
the class FileUploadRendererPortletImpl method decode.
@Override
public void decode(FacesContext facesContext, UIComponent uiComponent) {
ExternalContext externalContext = facesContext.getExternalContext();
ClientDataRequest clientDataRequest = (ClientDataRequest) externalContext.getRequest();
ContextMapFactory contextMapFactory = (ContextMapFactory) FactoryExtensionFinder.getFactory(externalContext, ContextMapFactory.class);
Map<String, List<UploadedFile>> uploadedFileMap = (Map<String, List<UploadedFile>>) contextMapFactory.getUploadedFileMap(clientDataRequest);
if (!uploadedFileMap.isEmpty()) {
try {
externalContext.setRequest(new HttpServletRequestFileUploadAdapter(clientDataRequest, uploadedFileMap, externalContext));
super.decode(facesContext, uiComponent);
} finally {
externalContext.setRequest(clientDataRequest);
}
}
}
use of javax.portlet.ClientDataRequest in project liferay-faces-bridge-impl by liferay.
the class Tests method setRequestCharacterEncodingActionTest.
// Test is MultiRequest -- tests both setting request in action and render
// Note: this tests that you can't get an encoding after reading the parameter.
// we can't test for the positive -- that the setEncoding actually works
// as portlet containers are supposed to process the form parameters before
// the portlet reads them -- some containers (WebSphere) chooses to do this
// before calling the portlet.
// Test #6.37
@BridgeTest(test = "setRequestCharacterEncodingActionTest")
public String setRequestCharacterEncodingActionTest(TestBean testBean) {
final String utf8 = "UTF-8";
final String utf16 = "UTF-16";
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
// done by navigation rule.
if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
String s = externalContext.getRequestCharacterEncoding();
String testEncoding = null;
// be most accomodative
try {
BufferedReader b = ((ClientDataRequest) externalContext.getRequest()).getReader();
int i = 0;
} catch (Exception e) {
// container likely did the right thing -- but make sure by reading the parameters
Map<String, String[]> requestParameterMap = ((PortletRequest) externalContext.getRequest()).getParameterMap();
}
if ((s == null) || ((s != null) && !s.equalsIgnoreCase(utf8))) {
testEncoding = utf8;
} else {
testEncoding = utf16;
}
try {
externalContext.setRequestCharacterEncoding(testEncoding);
String v = externalContext.getRequestCharacterEncoding();
if (((v == null) && (s == null)) || ((v != null) && (s != null) && v.equalsIgnoreCase(s))) {
testBean.setTestResult(true, "setRequestCharacterEncoding was correctly ignored after reading a parameter in an action request.");
} else {
testBean.setTestResult(false, "setRequestCharacterEncoding incorrectly set a new encoding after reading a parameter in an action request.");
}
} catch (Exception e) {
testBean.setTestResult(false, "setRequestCharacterEncoding was correctly ignored after reading a parameter in an action request.");
}
return "setRequestCharacterEncodingActionTest";
} else {
testBean.setTestComplete(true);
if (testBean.getTestStatus()) {
return Constants.TEST_SUCCESS;
} else {
return Constants.TEST_FAILED;
}
}
}
use of javax.portlet.ClientDataRequest in project liferay-faces-bridge-impl by liferay.
the class RequestHeaderValuesMap method addContentTypeHeader.
/**
* Adds a "Content-Type" header to the hashmap, according to the content-type and character-encoding in the
* specified request. Example Value: Content-Type: text/html; charset=ISO-8859-4
*
* @param portletRequest The current portlet request.
*
* @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">RFC2616</a>
*/
protected void addContentTypeHeader(PortletRequest portletRequest) {
// use that to build the header.
if (portletRequest instanceof ClientDataRequest) {
ClientDataRequest clientDataRequest = (ClientDataRequest) portletRequest;
String contentType = clientDataRequest.getContentType();
String characterSetEncoding = clientDataRequest.getCharacterEncoding();
StringBuilder header = new StringBuilder();
header.append(HEADER_CONTENT_TYPE);
header.append(": ");
header.append(contentType);
if (characterSetEncoding != null) {
header.append("; ");
header.append(CHARSET);
header.append("=");
header.append(characterSetEncoding);
}
String contentTypeHeader = header.toString();
logger.debug("Adding contentTypeHeader=[{0}] to header map", contentTypeHeader);
put(HEADER_CONTENT_TYPE, new String[] { header.toString() });
} else {
// TCK: getRequestHeaderMapRenderTest
}
}
use of javax.portlet.ClientDataRequest in project liferay-faces-bridge-impl by liferay.
the class ExternalContextImpl method getRequestContentType.
@Override
public String getRequestContentType() {
if (portletRequest instanceof ClientDataRequest) {
ClientDataRequest clientDataRequest = (ClientDataRequest) portletRequest;
// If using ICEfaces 3.0.x/2.0.x then need to return the legacy value.
// http://issues.liferay.com/browse/FACES-1228
String requestContentType;
if (isICEfacesLegacyMode(clientDataRequest)) {
requestContentType = clientDataRequest.getResponseContentType();
} else {
requestContentType = clientDataRequest.getContentType();
}
if (manageIncongruities) {
incongruityContext.setRequestContentType(requestContentType);
}
return requestContentType;
} else {
if (manageIncongruities) {
return incongruityContext.getRequestContentType();
} else {
// IllegalStateException is not an option.
return null;
}
}
}
Aggregations