List of usage examples for javax.mail.internet ContentType ContentType
public ContentType(String s) throws ParseException
From source file:com.eviware.soapui.impl.wsdl.monitor.ContentTypes.java
public static ContentTypes of(String contentTypes) { List<ContentType> contentTypeList = new ArrayList<ContentType>(); for (String ct : contentTypes.split(",")) { try {/*from w w w . j a v a 2s. co m*/ contentTypeList.add(new ContentType(ct.trim())); } catch (ParseException ignore) { } } return new ContentTypes(contentTypeList); }
From source file:org.nuxeo.drive.operations.NuxeoDriveOperationHelper.java
public static void normalizeMimeTypeAndEncoding(Blob blob) throws ParseException { String mimeType = blob.getMimeType(); if (!StringUtils.isEmpty(mimeType) && !"null".equals(mimeType)) { ContentType contentType = new ContentType(mimeType); blob.setMimeType(contentType.getBaseType()); if (StringUtils.isEmpty(blob.getEncoding())) { String charset = contentType.getParameter("charset"); if (!StringUtils.isEmpty(charset)) { blob.setEncoding(charset); }//from w w w. j a va 2s. com } } }
From source file:com.adaptris.core.mail.attachment.MailContent.java
protected MailContent() throws ParseException { contentType = new ContentType("application/octet-stream"); }
From source file:com.adaptris.core.http.ContentTypeProviderImpl.java
private boolean hasCharset(String mimeType) { boolean result = false; try {//from w w w . j a v a 2 s . c o m ContentType ct = new ContentType(mimeType); String charset = ct.getParameter("charset"); result = !isBlank(charset); } catch (ParseException e) { // couldn't parse, hasn't got a charset. result = false; } return result; }
From source file:com.adaptris.core.mail.attachment.MailContent.java
public MailContent(byte[] bytes) throws ParseException { this(bytes, new ContentType("application/octet-stream")); }
From source file:com.eviware.soapui.impl.wsdl.monitor.ContentTypes.java
public boolean matches(String value) { for (ContentType contentType : contentTypes) { try {//from w w w . ja v a 2 s .c o m ContentType respondedContentType = new ContentType(value); if (contentTypeMatches(contentType, respondedContentType)) { return true; } } catch (ParseException ignore) { } } return false; }
From source file:com.example.app.model.UserProfileDAO.java
/** * Get the file extension./*w ww . j a va 2s . c o m*/ * * @param file the file. * @return the extension preceeded by a '.' or an empty string. */ private static String _getFileExtensionWithDot(FileEntity file) { String ext = ""; // Cannot use the file name since the file may have been converted. final String contentType = file.getContentType(); if (ext.isEmpty() && !ContentTypes.Application.octet_stream.toString().equals(contentType)) { try { ext = new ContentType(contentType).getSubType().toLowerCase(); switch (ext) { case "jpeg": ext = "jpg"; break; case "tiff": ext = "tif"; break; case "svg+xml": ext = "svg"; break; case "x-portable-anymap": ext = "pnm"; break; case "x-portable-bitmap": ext = "pbm"; break; case "x-portable-graymap": ext = "pgm"; break; case "x-portable-pixmap": ext = "ppm"; break; default: break; } } catch (ParseException e) { _logger.error("Unable to parse content type: " + contentType, e); } } return ext.isEmpty() ? ext : '.' + ext; }
From source file:org.apache.axis2.transport.rabbitmq.utils.RabbitMQUtils.java
public static void setSOAPEnvelope(RabbitMQMessage message, MessageContext msgContext, String contentType) throws AxisFault { int index = contentType.indexOf(';'); String type = index > 0 ? contentType.substring(0, index) : contentType; Builder builder = BuilderUtil.getBuilderFromSelector(type, msgContext); if (builder == null) { if (log.isDebugEnabled()) { log.debug("No message builder found for type '" + type + "'. Falling back to SOAP."); }/* ww w . java2s. c o m*/ builder = new SOAPBuilder(); } OMElement documentElement; String charSetEnc = null; try { if (contentType != null) { charSetEnc = new ContentType(contentType).getParameter("charset"); } } catch (ParseException ex) { log.debug("Parse error", ex); } msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc); documentElement = builder.processDocument(new ByteArrayInputStream(message.getBody()), contentType, msgContext); msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement)); }
From source file:rogerthat.topdesk.bizz.Util.java
static String getContent(HTTPResponse response) throws ParseException, UnsupportedEncodingException { String contentType = getHeader(response, "Content-Type"); String characterSet = null;/*from w w w. j a va 2 s .c om*/ if (contentType != null) { ContentType type = new ContentType(contentType); characterSet = type.getParameter("charset"); } if (characterSet == null) { characterSet = "ASCII"; } log.info("characterset: " + characterSet); return new String(response.getContent(), characterSet); }
From source file:org.apache.axis2.transport.testkit.http.JettyByteArrayAsyncEndpoint.java
@Override protected IncomingMessage<byte[]> handle(HttpRequest request) throws HttpException, IOException { byte[] data = IOUtils.toByteArray(request.getInputStream()); logRequest(request, data);//ww w . j a v a 2s . c o m ContentType contentType; try { contentType = new ContentType(request.getContentType()); } catch (ParseException ex) { throw new HttpException(500, "Unparsable Content-Type"); } return new IncomingMessage<byte[]>(contentType, data); }