Package com.gentics.cr.util

Examples of com.gentics.cr.util.CRBinaryRequestBuilder


    log.debug("Request:" + request.getQueryString());
    // starttime
    long s = new Date().getTime();
    // get the objects
    CRBinaryRequestBuilder rb = new CRBinaryRequestBuilder(request);
    CRRequest req = rb.getBinaryRequest();

    try {
      Collection<CRResolvableBean> coll = this.rp.getObjects(req);
      if (coll != null) {
        request.setAttribute("objects", coll);
View Full Code Here


    HashMap<String, Resolvable> objects = new HashMap<String, Resolvable>();
    objects.put("request", new BeanWrapper(request));
    objects.put("session", new HttpSessionWrapper(request.getSession()));
    container.processService(
      new CRBinaryRequestBuilder(request),
      objects,
      response.getOutputStream(),
      new ServletResponseTypeSetter(response));

    if (contentDisposition != null && contentDisposition != "") {
View Full Code Here

    HashMap<String, Resolvable> objects = new HashMap<String, Resolvable>();
    objects.put("request", new BeanWrapper(request));
    objects.put("session", new HttpSessionWrapper(request.getSession()));
    container.processService(
      new CRBinaryRequestBuilder(request),
      objects,
      response.getOutputStream(),
      new ServletResponseTypeSetter(response));

    if (contentDisposition != null && contentDisposition != "") {
View Full Code Here

   * @param responsetypesetter responsetypesetter
   */
  public final void processService(final CRBinaryRequestBuilder reqBuilder,
      final Map<String, Resolvable> wrappedObjectsToDeploy, final OutputStream stream,
      final IResponseTypeSetter responsetypesetter) {
    CRBinaryRequestBuilder myReqBuilder = reqBuilder;
    CRResolvableBean crBean = null;
    CRRequest req;
    try {
      req = myReqBuilder.getBinaryRequest();
      //The StreamingBinaryContainer will
      //not render velocity in the content
      req.setDoVelocity(false);
      // DEPLOY OBJECTS TO REQUEST
      for (Iterator<Map.Entry<String, Resolvable>> i = wrappedObjectsToDeploy.entrySet().iterator(); i.hasNext();) {
        Map.Entry<String, Resolvable> entry = (Entry<String, Resolvable>) i.next();
        req.addObjectForFilterDeployment((String) entry.getKey(), entry.getValue());
      }
      if (this.crConf.usesContentidUrl()) {
        if (req.getContentid() == null) {
          Object obj = reqBuilder.getRequest();
          if (obj instanceof HttpServletRequest) {
            String[] reqURI = ((HttpServletRequest) obj).getRequestURI().split("/");
            ArrayList<String> reqList = new ArrayList<String>(Arrays.asList(reqURI));
            int index = reqList.indexOf(((HttpServletRequest) obj).getServletPath().replaceAll("/", ""));
            if (reqList.size() >= index + 1) {
              req.setRequestFilter("object.contentid==" + reqList.get(index + 1).toString());
            }
          }
        }
      }
      req.setAttributeArray(new String[] { "mimetype" });
      // load by url if no contentid
      if (req.isUrlRequest()) {
        crBean = rp.getBeanByURL(req);
      } else {
        crBean = rp.getFirstMatchingResolvable(req);
      }
      if (crBean != null) {
        // set mimetype.
        if (crBean.getMimetype() == null) {

          CRConfigUtil rpConf = crConf.getRequestProcessorConfig(1);
          if (crBean.getObj_type().equals(rpConf.getPageType())) {
            this.contenttype = "text/html; charset=" + this.responseEncoding;
            log.info("Responding with mimetype: text/html");
          } else {
            log.info("Mimetype has not been set, using " + "standard instead. (" + crBean.getObj_type()
                + "!=" + rpConf.getPageType() + ")");
          }
        } else {

          this.contenttype = crBean.getMimetype() + "; charset=" + this.responseEncoding;

          log.info("Responding with mimetype: " + crBean.getMimetype());
        }

        responsetypesetter.setContentType(this.getContentType());
        // output data.
        if (crBean.isBinary()) {
          stream.write(crBean.getBinaryContent());

        } else {

          PLinkOutputStream plos = new PLinkOutputStream(stream, new PlinkReplacer(plinkProcessor, req));

          OutputStreamWriter wr = new OutputStreamWriter(plos, this.responseEncoding);
          String content = crBean.getContent(this.responseEncoding);
          wr.write(content);
          wr.flush();
          wr.close();
        }
      } else {
        CRException crex = new CRException("NoDataFound", "Data could not be found.", ERRORTYPE.NO_DATA_FOUND);
        this.respondWithError(stream, crex, myReqBuilder.isDebug());
      }
      stream.flush();
      stream.close();
    } catch (CRException e1) {
      this.contenttype = "text/html; charset=" + this.responseEncoding;
      respondWithError((OutputStream) stream, e1, myReqBuilder.isDebug());
      e1.printStackTrace();
    } catch (Exception e) {
      log.error("Error while processing service " + "(RESTBinaryContainer)", e);
      CRException crex = new CRException(e);
      this.respondWithError(stream, crex, myReqBuilder.isDebug());
    }

  }
View Full Code Here

TOP

Related Classes of com.gentics.cr.util.CRBinaryRequestBuilder

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.