Examples of ContentType


Examples of javax.mail.internet.ContentType

     * @param contentType
     * @return
     * @throws ParseException
     */
    protected String getCharSet(String contentType) throws ParseException {
        ContentType type = new ContentType(contentType);
        String charset = type.getParameter("charset");
        if (charset == null) {
            charset = "us-ascii";
        }
        return MimeUtility.javaCharset(charset);
    }
View Full Code Here

Examples of javax.mail.internet.ContentType

        return contentType;
    }
   
    private String getParameter(String name) {
        try {
            return new ContentType(contentType).getParameter(name);
        } catch (ParseException ex) {
            // MIMEResource objects are only defined as constants. Therefore we
            // will never get here under normal conditions.
            throw new Error(ex);
        }
View Full Code Here

Examples of javax.mail.internet.ContentType

          LOGGER.info(String.format("Handdling attachment '%s', type: '%s'", filename, contentType));
        }
        else {

          final String textFilename;
          final ContentType ct;

          try {
            ct = new ContentType(contentType);
          }
          catch (ParseException e) {
            throw new IllegalStateException("Error while parsing content type '" + contentType + "'.", e);
          }

          if ("text/plain".equalsIgnoreCase(ct.getBaseType())) {
            textFilename = "message.txt";
          }
          else if ("text/html".equalsIgnoreCase(ct.getBaseType())) {
            textFilename = "message.html";
          }
          else {
            textFilename = "message.other";
          }
View Full Code Here

Examples of javax.mail.internet.ContentType

      this.fileName = filename;
    }

    // get mime type
    try {
      ContentType cType = new ContentType(part.getContentType());
      mimeType = cType.getBaseType();
    } catch (Exception e) {
      logger.warn("parser was unable to decode not well-formed Content-Type: {}", e.getMessage());
    } finally {
      this.mimeType = mimeType;
    }
View Full Code Here

Examples of net.sf.jpluck.spider.ContentType

      FileInputStream in = new FileInputStream(file);
      in.read(data);
      in.close();
    }
    System.out.println("Parsing HTML");
    Resource resource = new Resource(html, null, new ContentType("text/html"), data, 0, false);
    Document document = resource.parseHTML();
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    File file = new File(xml);
    System.out.println("Writing " + file.getAbsolutePath());
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
View Full Code Here

Examples of nextapp.echo2.webrender.ContentType

        try {
            if (!(imageReference instanceof StreamImageReference)) {
                throw new IOException("Image is not a StreamImageReference.");
            }
            StreamImageReference streamImageReference = (StreamImageReference) imageReference;
            conn.setContentType(new ContentType(streamImageReference.getContentType(), true));
            streamImageReference.render(conn.getOutputStream());
        } catch (IOException ex) {
            // Internet Explorer appears to enjoy making half-hearted requests for images, wherein it resets the connection
            // leaving us with an IOException.  This exception is silently eaten.
            // It would preferable to only ignore SocketExceptions, however the API documentation does not provide
View Full Code Here

Examples of org.apache.axiom.mime.ContentType

        if (log.isDebugEnabled()) {
            log.debug("Attachments contentLength=" + contentLength + ", contentTypeString=" + contentTypeString);
        }
        this.fileStorageThreshold = fileStorageThreshold;
        try {
            contentType = new ContentType(contentTypeString);
        } catch (ParseException e) {
            throw new OMException(
                    "Invalid Content Type Field in the Mime Message"
                    , e);
        }
View Full Code Here

Examples of org.apache.camel.component.salesforce.api.dto.bulk.ContentType

    }

    private void processCreateBatch(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
        String jobId;
        // since request is in the body, use headers or endpoint params
        ContentType contentType = ContentType.fromValue(
                getParameter(CONTENT_TYPE, exchange, IGNORE_BODY, NOT_OPTIONAL));
        jobId = getParameter(JOB_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);

        InputStream request;
        try {
View Full Code Here

Examples of org.apache.hadoop.hbase.rest.Dispatcher.ContentType

public class RestSerializerFactory {

  public static AbstractRestSerializer getSerializer(
      HttpServletRequest request, HttpServletResponse response)
      throws HBaseRestException {
    ContentType ct = ContentType.getContentType(request.getHeader("accept"));
    AbstractRestSerializer serializer = null;

    // TODO refactor this so it uses reflection to create the new objects.
    switch (ct) {
    case XML:
View Full Code Here

Examples of org.apache.http.entity.ContentType

        if (answer == null) {
            try {
                Object data = in.getBody();
                if (data != null) {
                    String contentTypeString = ExchangeHelper.getContentType(exchange);
                    ContentType contentType = null;
                   
                    //Check the contentType is valid or not, If not it throws an exception.
                    //When ContentType.parse parse method parse "multipart/form-data;boundary=---------------------------j2radvtrk",
                    //it removes "boundary" from Content-Type; I have to use contentType.create method.
                    if (contentTypeString != null) {
                        // using ContentType.parser for charset
                        if (contentTypeString.indexOf("charset") > 0) {
                            contentType = ContentType.parse(contentTypeString);
                        } else {
                            contentType = ContentType.create(contentTypeString);
                        }
                    }
                                       
                    if (contentTypeString != null && HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT.equals(contentTypeString)) {
                        // serialized java object
                        Serializable obj = in.getMandatoryBody(Serializable.class);
                        // write object to output stream
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        HttpHelper.writeObjectToStream(bos, obj);
                        ByteArrayEntity entity = new ByteArrayEntity(bos.toByteArray());
                        entity.setContentType(HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
                        IOHelper.close(bos);
                        answer = entity;
                    } else if (data instanceof File || data instanceof GenericFile) {
                        // file based (could potentially also be a FTP file etc)
                        File file = in.getBody(File.class);
                        if (file != null) {
                            if (contentType != null) {
                                answer = new FileEntity(file, contentType);
                            } else {
                                answer = new FileEntity(file);
                            }
                        }
                    } else if (data instanceof String) {
                        // be a bit careful with String as any type can most likely be converted to String
                        // so we only do an instanceof check and accept String if the body is really a String
                        // do not fallback to use the default charset as it can influence the request
                        // (for example application/x-www-form-urlencoded forms being sent)
                        String charset = IOHelper.getCharsetName(exchange, false);
                        if (charset == null && contentType != null) {
                            // okay try to get the charset from the content-type
                            Charset cs = contentType.getCharset();
                            if (cs != null) {
                                charset = cs.name();
                            }
                        }
                        StringEntity entity = new StringEntity((String) data, charset);
                        if (contentType != null) {
                            entity.setContentType(contentType.toString());
                        }
                        answer = entity;
                    }

                    // fallback as input stream
                    if (answer == null) {
                        // force the body as an input stream since this is the fallback
                        InputStream is = in.getMandatoryBody(InputStream.class);
                        InputStreamEntity entity = new InputStreamEntity(is, -1);
                        if (contentType != null) {
                            entity.setContentType(contentType.toString());
                        }
                        answer = entity;
                    }
                }
            } catch (UnsupportedEncodingException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.