Search in sources :

Example 1 with ClientDataRequest

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;
        }
    }
}
Also used : ClientDataRequest(javax.portlet.ClientDataRequest) BridgeDefaultViewNotSpecifiedException(javax.portlet.faces.BridgeDefaultViewNotSpecifiedException) URISyntaxException(java.net.URISyntaxException) BridgeException(javax.portlet.faces.BridgeException) FacesException(javax.faces.FacesException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BridgeInvalidViewPathException(javax.portlet.faces.BridgeInvalidViewPathException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) PortletException(javax.portlet.PortletException)

Example 2 with ClientDataRequest

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);
        }
    }
}
Also used : ClientDataRequest(javax.portlet.ClientDataRequest) ContextMapFactory(com.liferay.faces.bridge.context.map.internal.ContextMapFactory) UploadedFile(com.liferay.faces.bridge.model.UploadedFile) ExternalContext(javax.faces.context.ExternalContext) List(java.util.List) Map(java.util.Map)

Example 3 with 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;
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ClientDataRequest(javax.portlet.ClientDataRequest) ExternalContext(javax.faces.context.ExternalContext) BufferedReader(java.io.BufferedReader) Map(java.util.Map) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 4 with ClientDataRequest

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
    }
}
Also used : ClientDataRequest(javax.portlet.ClientDataRequest)

Example 5 with ClientDataRequest

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;
        }
    }
}
Also used : ClientDataRequest(javax.portlet.ClientDataRequest)

Aggregations

ClientDataRequest (javax.portlet.ClientDataRequest)7 List (java.util.List)2 Map (java.util.Map)2 ExternalContext (javax.faces.context.ExternalContext)2 ContextMapFactory (com.liferay.faces.bridge.context.map.internal.ContextMapFactory)1 UploadedFile (com.liferay.faces.bridge.model.UploadedFile)1 BridgeTest (com.liferay.faces.bridge.tck.annotation.BridgeTest)1 FacesRequestParameterMap (com.liferay.faces.util.context.map.FacesRequestParameterMap)1 MultiPartFormData (com.liferay.faces.util.context.map.MultiPartFormData)1 Product (com.liferay.faces.util.product.Product)1 ProductFactory (com.liferay.faces.util.product.ProductFactory)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 FacesException (javax.faces.FacesException)1 FacesContext (javax.faces.context.FacesContext)1 PortalContext (javax.portlet.PortalContext)1