Package org.primefaces.model

Examples of org.primefaces.model.StreamedContent


    }

    public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ELContext elContext = facesContext.getELContext();
        StreamedContent content = (StreamedContent) value.getValue(elContext);

        if(content == null) {
            return;
        }

        ExternalContext externalContext = facesContext.getExternalContext();
        String contentDispositionValue = contentDisposition != null ? (String) contentDisposition.getValue(elContext) : "attachment";

        InputStream inputStream = null;

        try {
            externalContext.setResponseContentType(content.getContentType());
            externalContext.setResponseHeader("Content-Disposition", contentDispositionValue + ";filename=\"" + content.getName() + "\"");
            externalContext.addResponseCookie(Constants.DOWNLOAD_COOKIE, "true", Collections.<String, Object>emptyMap());

            if(RequestContext.getCurrentInstance().isSecure()) {
                externalContext.setResponseHeader("Cache-Control", "public");
                externalContext.setResponseHeader("Pragma", "public");
            }

            byte[] buffer = new byte[2048];
            int length;
            inputStream = content.getStream();
            OutputStream outputStream = externalContext.getResponseOutputStream();

            while ((length = (inputStream.read(buffer))) != -1) {
                outputStream.write(buffer, 0, length);
            }
View Full Code Here


        String library = params.get("ln");
        String dynamicContentId = (String) params.get(Constants.DYNAMIC_CONTENT_PARAM);
        StringEncrypter strEn = RequestContext.getCurrentInstance().getEncrypter();
       
        if(dynamicContentId != null && library != null && library.equals(Constants.LIBRARY)) {
            StreamedContent streamedContent = null;
            boolean cache = Boolean.valueOf(params.get(Constants.DYNAMIC_CONTENT_CACHE_PARAM));
           
            try {
                String dynamicContentEL = strEn.decrypt(dynamicContentId);               
                ExternalContext externalContext = context.getExternalContext();
                
                if(dynamicContentEL != null) {
                    ELContext eLContext = context.getELContext();
                    ValueExpression ve = context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(), dynamicContentEL, StreamedContent.class);
                    streamedContent = (StreamedContent) ve.getValue(eLContext);

                    externalContext.setResponseStatus(200);
                    externalContext.setResponseContentType(streamedContent.getContentType());
                   
                    handleCache(externalContext, cache);
                   
                    if(streamedContent.getContentEncoding() != null) {
                        externalContext.setResponseHeader("Content-Encoding", streamedContent.getContentEncoding());
                    }

                    byte[] buffer = new byte[2048];

                    int length;
                    InputStream inputStream = streamedContent.getStream();
                    while ((length = (inputStream.read(buffer))) >= 0) {
                        externalContext.getResponseOutputStream().write(buffer, 0, length);
                    }
                }

                externalContext.responseFlushBuffer();
                context.responseComplete();

            } catch(Exception e) {
                logger.log(Level.SEVERE, "Error in streaming dynamic resource. {0}", new Object[]{e.getMessage()});
                throw new IOException(e);
            }
            finally {
                //cleanup
                if(streamedContent != null) {
                    streamedContent.getStream().close();
                }
            }
        }
    }
View Full Code Here

        }
        else if (value instanceof String) {
            src = ComponentUtils.getResourceURL(context, (String) value);
        }
        else if (value instanceof StreamedContent) {
            StreamedContent streamedContent = (StreamedContent) value;
            Resource resource = context.getApplication().getResourceHandler().createResource("dynamiccontent.properties", "primefaces", streamedContent.getContentType());
            String resourcePath = resource.getRequestPath();
            StringEncrypter encrypter = RequestContext.getCurrentInstance().getEncrypter();

            ValueExpression expression = ValueExpressionAnalyzer.getExpression(context.getELContext(), component.getValueExpression("value"));
            String rid = encrypter.encrypt(expression.getExpressionString());
View Full Code Here

        if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
            return new DefaultStreamedContent();
        }
        else {
            InputStream is = new ByteArrayInputStream(currentImage.getContent());
            StreamedContent sc = new DefaultStreamedContent(is, "image/jpg", currentImage.getName());
            return sc;
        }
    }   
View Full Code Here

        }
    }

    public StreamedContent getStreamedContent() {

        StreamedContent uploadedFile = null;

        if (fileContent != null) {
            uploadedFile = new DefaultStreamedContent(new ByteArrayInputStream(
                    fileContent));
        }
View Full Code Here

     * @return
     * @throws ServiceBusinessException
     */
    public StreamedContent getImageFile() throws ServiceBusinessException {

        StreamedContent content = null;

        if (FacesUtil.getFacesContext().getRenderResponse()) {
            content = new DefaultStreamedContent();

        } else {
View Full Code Here

           
            try {
                String dynamicContentEL = (String) session.get(dynamicContentId);
                ELContext eLContext = context.getELContext();
                ValueExpression ve = context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(), dynamicContentEL, StreamedContent.class);
                StreamedContent content = (StreamedContent) ve.getValue(eLContext);
                HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();

                response.setContentType(content.getContentType());

                byte[] buffer = new byte[2048];

                int length;
                while ((length = (content.getStream().read(buffer))) >= 0) {
                    response.getOutputStream().write(buffer, 0, length);
                }

                response.setStatus(200);
                response.getOutputStream().flush();
View Full Code Here

    if(value == null) {
            src = "";
        }
        else {
            if(value instanceof StreamedContent) {
                StreamedContent streamedContent = (StreamedContent) value;
                Resource resource = context.getApplication().getResourceHandler().createResource("dynamiccontent", "primefaces", streamedContent.getContentType());
                String resourcePath = resource.getRequestPath();
                String rid = createUniqueContentId(context);
                StringBuilder builder = new StringBuilder(resourcePath);

                builder.append("&").append(PrimeResourceHandler.DYNAMIC_CONTENT_PARAM).append("=").append(rid);
View Full Code Here

        if(value == null) {
            src = "";
        }
        else {
            if(value instanceof StreamedContent) {
                StreamedContent streamedContent = (StreamedContent) value;
                Resource resource = context.getApplication().getResourceHandler().createResource("dynamiccontent", "primefaces", streamedContent.getContentType());
                String resourcePath = resource.getRequestPath();
                String rid = createUniqueContentId(context);
                StringBuilder builder = new StringBuilder(resourcePath);

                builder.append("&").append(PrimeResourceHandler.DYNAMIC_CONTENT_PARAM).append("=").append(rid);
View Full Code Here

    FacesContext facesContext = FacesContext.getCurrentInstance();
    ELContext elContext = facesContext.getELContext();
    HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
 
    String contentDispositionValue = contentDisposition != null ? (String) contentDisposition.getValue(elContext) : "attachment"
    StreamedContent content = (StreamedContent) value.getValue(elContext);
   
    try {
      response.setContentType(content.getContentType());
      response.setHeader("Content-Disposition", contentDispositionValue + ";filename=\"" + content.getName() + "\"");
     
      byte[] buffer = new byte[2048];
 
      int length;
      while ((length = (content.getStream().read(buffer))) >= 0) {
        response.getOutputStream().write(buffer, 0, length);
      }
     
      response.setStatus(200);
     
      content.getStream().close();
      response.getOutputStream().flush();
      facesContext.responseComplete();
    }catch (IOException e) {
      e.printStackTrace();
    }
View Full Code Here

TOP

Related Classes of org.primefaces.model.StreamedContent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.