Package railo.commons.lang.mimetype

Examples of railo.commons.lang.mimetype.MimeType


        else matrix.setEL(entry.trim(), "");
      }
     
      // get accept
      List<MimeType> accept = ReqRspUtil.getAccept(this);
      MimeType contentType = ReqRspUtil.getContentType(this);
     
      // check for format extension
      //int format = getApplicationContext().getRestSettings().getReturnFormat();
      int format;
      boolean hasFormatExtension=false;
View Full Code Here


    Entry<Key, Object> e;
    Object value;
    UDF udf;
    Struct meta;
    int status=404;
    MimeType bestP,bestC;
    while(it.hasNext()){
      e = it.next();
      value=e.getValue();
      if(value instanceof UDF){
        udf=(UDF)value;
View Full Code Here

    if(ArrayUtil.isEmpty(produces)){
      if(accept.length>0) return accept[0];
      return MimeType.ALL;
    }
   
    MimeType best=null,tmp;
   
    for(int a=0;a<accept.length;a++){
      tmp=accept[a].bestMatch(produces);
      if(tmp!=null && !accept[a].hasWildCards() && tmp.hasWildCards()){
        tmp=accept[a];
      }
      if(tmp!=null &&
          (best==null ||
           best.getQuality()<tmp.getQuality() ||
           (best.getQuality()==tmp.getQuality() && best.hasWildCards() && !tmp.hasWildCards())))
        best=tmp;
    }
   
   
   
View Full Code Here

  }
   
    public static MimeType getContentType(PageContext pc) {
      java.util.Iterator<String> it = ReqRspUtil.getHeadersIgnoreCase(pc, "content-type").iterator();
      String value;
      MimeType rtn=null;
    while(it.hasNext()){
      value=it.next();
      MimeType[] mtes = MimeType.getInstances(value, ',');
      if(mtes!=null)for(int i=0;i<mtes.length;i++){
        rtn= mtes[i];
View Full Code Here

    if(rtn==null) return MimeType.ALL;
    return rtn;
  }
   
    public static String getContentTypeAsString(PageContext pc,String defaultValue) {
      MimeType mt = getContentType(pc);
      if(mt==MimeType.ALL) return defaultValue;
      return mt.toString();
    }
View Full Code Here

   * @return
   */
  public static Object getRequestBody(PageContext pc,boolean deserialized, Object defaultValue) {
    HttpServletRequest req = pc.getHttpServletRequest();
     
    MimeType contentType = getContentType(pc);
    String strContentType=contentType==MimeType.ALL?null:contentType.toString();
        String strCS = getCharacterEncoding(pc,req);
        Charset cs = CharsetUtil.toCharset(strCS);
       
        boolean isBinary =!(
            strContentType == null ||
View Full Code Here

      pc=ThreadLocalPageContext.get(pc);
      InputStream is=null;
     
      try{
        HTTPResponse rsp = HTTPEngine.get(metaURL, username, password, -1, 0, "UTF-8", USER_AGENT, proxyData, null);
        MimeType mt = getMimeType(rsp,null);
        int format = MimeType.toFormat(mt, -1);
        if(format==-1) throw new ApplicationException("cannot convert response with mime type ["+mt+"] to a CFML Object");
        is = rsp.getContentAsStream();
        Struct data = Caster.toStruct(ReqRspUtil.toObject(pc,IOUtil.toBytes(is,false),format,mt.getCharset(),null));
        Object oUDF=data.get(KeyConstants._functions,null);
        Object oAACF=data.get(ComponentPage.ACCEPT_ARG_COLL_FORMATS,null);
       
        if(oUDF!=null && oAACF!=null) {
          meta=Caster.toStruct(oUDF);
View Full Code Here

      // call remote cfc
      HTTPResponse rsp = HTTPEngine.post(url, username, password, -1, 0, "UTF-8", USER_AGENT, proxyData,headers, formfields);
     
      // read result
      Header[] rspHeaders = rsp.getAllHeaders();
      MimeType mt = getMimeType(rspHeaders,null);
      int format = MimeType.toFormat(mt, -1);
      if(format==-1) {
        if(rsp.getStatusCode()!=200) {
          boolean hasMsg=false;
          String msg=rsp.getStatusText();
          for(int i=0;i<rspHeaders.length;i++){
            if(rspHeaders[i].getName().equalsIgnoreCase("exception-message")){
              msg=rspHeaders[i].getValue();
              hasMsg=true;
            }
          }
          is = rsp.getContentAsStream();
          ApplicationException ae = new ApplicationException("remote component throws the following error:"+msg);
          if(!hasMsg)ae.setAdditional(KeyImpl.init("respone-body"),IOUtil.toString(is, mt.getCharset()));
         
          throw ae;
        }
        throw new ApplicationException("cannot convert response with mime type ["+mt+"] to a CFML Object");
      }
      is = rsp.getContentAsStream();
      return ReqRspUtil.toObject(pc,IOUtil.toBytes(is,false),format,mt.getCharset(),null);
    }
    catch (IOException ioe) {
      throw Caster.toPageException(ioe);
    }
    finally {
View Full Code Here

    String returnFormat=null,contentType=null;
    for(int i=0;i<headers.length;i++){
      if(headers[i].getName().equalsIgnoreCase("Return-Format"))returnFormat=headers[i].getValue();
      else if(headers[i].getName().equalsIgnoreCase("Content-Type"))contentType=headers[i].getValue();
    }
    MimeType rf=null,ct=null;
   
    // return format
    if(!StringUtil.isEmpty(returnFormat)) {
      int format=UDFUtil.toReturnFormat(returnFormat,-1);
      rf=MimeType.toMimetype(format, null);
    }
    // ContentType
    if(!StringUtil.isEmpty(contentType)) {
      ct= MimeType.getInstance(contentType);
    }
    if(rf!=null && ct!=null) {
      if(rf.same(ct)) return ct; // because this has perhaps a charset definition
      return rf;
    }
    if(rf!=null) return rf;
    if(ct!=null) return ct;
   
View Full Code Here

    else ext=null;
   
    if(StringUtil.isEmpty(accept,true)) return;
   
   
    MimeType mt = MimeType.getInstance(contentType),sub;
   
    Array whishedTypes=ListUtil.listToArrayRemoveEmpty(accept,',');
    int len=whishedTypes.size();
    for(int i=1;i<=len;i++) {
      String whishedType=Caster.toString(whishedTypes.getE(i)).trim().toLowerCase();
      if(whishedType.equals("*")) return;
      // check mimetype
      if(ListUtil.len(whishedType, "/", true)==2){
        sub=MimeType.getInstance(whishedType);
        if(mt.match(sub)) return;
      }
     
      // check extension
      if(ext!=null && !strict){
        if(whishedType.startsWith("*."))whishedType=whishedType.substring(2);
 
View Full Code Here

TOP

Related Classes of railo.commons.lang.mimetype.MimeType

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.