Package railo.commons.lang.mimetype

Examples of railo.commons.lang.mimetype.ContentType


 

  public static ContentType toContentType(String str, ContentType defaultValue) {
    if( StringUtil.isEmpty(str,true)) return defaultValue;
    String[] types=str.split(";");
    ContentType ct=null;
    if(types.length>0){
        ct=new ContentType(types[0]);
        if(types.length>1) {
              String tmp=types[types.length-1].trim();
              int index=tmp.indexOf("charset=");
              if(index!=-1) {
                ct.setCharset(StringUtil.removeQuotes(tmp.substring(index+8),true));
              }
          }
      }
      return ct;
  }
View Full Code Here


        // File
          else if(type.equals("file")) {
            hasForm=true;
            if(this.method==METHOD_GET) throw new ApplicationException("httpparam type file can't only be used, when method of the tag http equal post");
            String strCT = getContentType(param);
            ContentType ct = HTTPUtil.toContentType(strCT,null);
             
            String mt="text/xml";
            if(ct!=null && !StringUtil.isEmpty(ct.getMimeType(),true)) mt=ct.getMimeType();
           
            String cs=charset;
            if(ct!=null && !StringUtil.isEmpty(ct.getCharset(),true)) cs=ct.getCharset();
           
           
            if(doMultiPart) {
              try {
                Resource res = param.getFile();
                parts.add(new FormBodyPart(
                    param.getName(),
                    new ResourceBody(res, mt, res.getName(), cs)
                ));
                //parts.add(new ResourcePart(param.getName(),new ResourcePartSource(param.getFile()),getContentType(param),_charset));
              }
              catch (FileNotFoundException e) {
                throw new ApplicationException("can't upload file, path is invalid",e.getMessage());
              }
            }
          }
        // XML
          else if(type.equals("xml")) {
            ContentType ct = HTTPUtil.toContentType(param.getMimeType(),null);
             
            String mt="text/xml";
            if(ct!=null && !StringUtil.isEmpty(ct.getMimeType(),true)) mt=ct.getMimeType();
           
            String cs=charset;
            if(ct!=null && !StringUtil.isEmpty(ct.getCharset(),true)) cs=ct.getCharset();
           
            hasBody=true;
            hasContentType=true;
            req.addHeader("Content-type", mt+"; charset="+cs);
              if(eem==null)throw new ApplicationException("type xml is only supported for type post and put");
              HTTPEngine4Impl.setBody(eem, param.getValueAsString(),mt,cs);
          }
        // Body
          else if(type.equals("body")) {
            ContentType ct = HTTPUtil.toContentType(param.getMimeType(),null);
             
            String mt=null;
            if(ct!=null && !StringUtil.isEmpty(ct.getMimeType(),true)) mt=ct.getMimeType();
           
            String cs=charset;
            if(ct!=null && !StringUtil.isEmpty(ct.getCharset(),true)) cs=ct.getCharset();
           
           
            hasBody=true;
            if(eem==null)throw new ApplicationException("type body is only supported for type post and put");
            HTTPEngine4Impl.setBody(eem, param.getValue(),mt,cs);
View Full Code Here

TOP

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

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.