if ("text/plain".equalsIgnoreCase(ct.getBaseType())) { textFilename = "message.txt"; else if ("text/html".equalsIgnoreCase(ct.getBaseType())) { textFilename = "message.html";
private boolean isMultipartRelatedContent(ContentType type) { String baseType = type.getBaseType(); return MimeConstants.TYPE_MULTIPART_RELATED.equalsIgnoreCase(baseType); } }
private boolean isSoapContent(ContentType type) { String baseType = type.getBaseType(); return MimeConstants.TYPE_SOAP11.equalsIgnoreCase(baseType) || MimeConstants.TYPE_SOAP12.equalsIgnoreCase(baseType); }
public String toString() { if (_major == null || _minor == null) { return null; } // We need to format this as if we're doing it to set into the Content-Type // header. So the parameter list gets added on as if the header name was // also included. String baseType = getBaseType(); if (_list != null) { baseType += _list.toString(baseType.length() + "Content-Type: ".length()); } return baseType; }
public String toString() { if (_major == null || _minor == null) { return null; } return getBaseType() + (_list == null ? "" : _list.toString()); }
private boolean isValidRootType(String type) throws ParseException { // The type multipart/related parameter can not have parameters itself ContentType contentType = new ContentType(type); type = contentType.getBaseType(); return rootType.equals(type); }
public static Type getTypeFromContentType(ContentType contentType) { String baseType = contentType.getBaseType(); Type type = null; for (Type candidate : Type.values()) { if (candidate.getContentType().getBaseType().equalsIgnoreCase(baseType)) { type = candidate; break; } } return type; } }
public static Type getTypeFromContentType(ContentType contentType) { String baseType = contentType.getBaseType(); Type type = null; for (Type candidate : Type.values()) { if (candidate.getContentType().getBaseType().equalsIgnoreCase(baseType)) { type = candidate; break; } } return type; } }
@Override public void process(Exchange exchange) throws Exception { String newFileName = "internal-switchyard.jpeg"; Image input = exchange.getIn().getBody(Image.class); if (input == null) { throw new RuntimeException("Image for resize not found!"); } ContentType type = new ContentType("image/jpeg"); exchange.getOut().addAttachment(newFileName, new DataHandler(input, type.getBaseType())); exchange.getOut().setBody(newFileName); }
public boolean isSigned(MimeBodyPart part) throws MessagingException { ContentType contentType = new ContentType(part.getContentType()); String baseType = contentType.getBaseType().toLowerCase(); return baseType.equalsIgnoreCase("multipart/signed"); }
/** * Checks whether the input message is <code>format=flowed</code>. */ public static boolean isFlowedTextMessage(Message m) throws MessagingException { ContentType ct = new ContentType(m.getContentType()); String format = ct.getParameter("format"); return ct.getBaseType().equals("text/plain") && format != null && format.equalsIgnoreCase("flowed"); } }
public boolean isSigned (@Nonnull final MimeBodyPart aPart) throws MessagingException { ValueEnforcer.notNull (aPart, "Part"); final ContentType aContentType = AS2HttpHelper.parseContentType (aPart.getContentType ()); if (aContentType == null) return false; final String sBaseType = aContentType.getBaseType (); return sBaseType.equalsIgnoreCase ("multipart/signed"); }
/** * Constructs a <code>MultipartRelatedDecoder</code>. This will block until the message * has been decoded. * * @param contentType the mime Content-Type header provided by the transport * @param stream The stream to pull the multipart message from */ public MultipartRelatedDecoder(ContentType contentType) throws IOException, MessagingException { this.contentType = contentType; if (MimeConstants.TYPE_MULTIPART_RELATED.equalsIgnoreCase(contentType.getBaseType()) == false) throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "NON_MULTIPART_RELATED_TYPE")); rootType = contentType.getParameter("type"); if (rootType == null) throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "MISSING_THE_ROOT_TYPE_PARAMETER")); }
public boolean isEncrypted (@Nonnull final MimeBodyPart aPart) throws MessagingException { ValueEnforcer.notNull (aPart, "Part"); // Content-Type is sthg like this if encrypted: // application/pkcs7-mime; name=smime.p7m; smime-type=enveloped-data final ContentType aContentType = AS2HttpHelper.parseContentType (aPart.getContentType ()); if (aContentType == null) return false; final String sBaseType = aContentType.getBaseType ().toLowerCase (Locale.US); if (!sBaseType.equals ("application/pkcs7-mime")) return false; final String sSmimeType = aContentType.getParameter ("smime-type"); return sSmimeType != null && sSmimeType.equalsIgnoreCase ("enveloped-data"); }
public EncodedData getBytesFromMultipart(MimeMultipart value, Marshaller marshaller) { ByteArrayOutputStream output = new ByteArrayOutputStream(); try { ContentType contentType = new ContentType(value.getContentType()); String boundary = contentType.getParameter("boundary"); output.write(Constants.cr().getBytes()); output.write(("Content-Type: " + contentType.getBaseType() + "; boundary=\"" + boundary + "\"\n").getBytes()); } catch (Exception ex) { throw ConversionException.couldNotBeConverted(value, byte[].class, ex); } try { value.writeTo(output); } catch (Exception ex) { throw ConversionException.couldNotBeConverted(value, byte[].class, ex); } return new EncodedData(output.toByteArray(), value.getContentType()); }
/** * Obtains the content of the encoded message, if previously encoded as <code>format=flowed</code>. */ public static String deflow(Message m) throws IOException, MessagingException { ContentType ct = new ContentType(m.getContentType()); String format = ct.getParameter("format"); if (ct.getBaseType().equals("text/plain") && format != null && format.equalsIgnoreCase("flowed")) { String delSp = ct.getParameter("delsp"); return deflow((String) m.getContent(), delSp != null && delSp.equalsIgnoreCase("yes")); } else if (ct.getPrimaryType().equals("text")) { return (String) m.getContent(); } else { return null; } }
public EncodedData getBytesFromMultipart(MimeMultipart value, Marshaller marshaller) { ByteArrayOutputStream output = new ByteArrayOutputStream(); try { ContentType contentType = new ContentType(value.getContentType()); String boundary = contentType.getParameter("boundary"); output.write(Constants.cr().getBytes()); output.write(("Content-Type: " + contentType.getBaseType() + "; boundary=\"" + boundary + "\"\n").getBytes()); } catch (Exception ex) { throw ConversionException.couldNotBeConverted(value, byte[].class, ex); } try { value.writeTo(output); } catch (Exception ex) { throw ConversionException.couldNotBeConverted(value, byte[].class, ex); } return new EncodedData(output.toByteArray(), value.getContentType()); }
public ContentType getContentType(ClientOptions options, ContentType contentType) throws Exception { if (contentType.getBaseType().equals(XMLMessage.Type.SWA.getContentType().getBaseType())) { OMOutputFormat outputFormat = new OMOutputFormat(); outputFormat.setMimeBoundary(options.getMimeBoundary()); outputFormat.setRootContentId(options.getRootContentId()); return new ContentType(outputFormat.getContentTypeForSwA(SOAP12Constants.SOAP_12_CONTENT_TYPE)); } else { return ContentTypeUtil.addCharset(contentType, options.getCharset()); } }
public ContentType getContentType(ClientOptions options, ContentType contentType) throws Exception { if (contentType.getBaseType().equals(XMLMessage.Type.SWA.getContentType().getBaseType())) { OMOutputFormat outputFormat = new OMOutputFormat(); outputFormat.setMimeBoundary(options.getMimeBoundary()); outputFormat.setRootContentId(options.getRootContentId()); return new ContentType(outputFormat.getContentTypeForSwA(SOAP12Constants.SOAP_12_CONTENT_TYPE)); } else { return ContentTypeUtil.addCharset(contentType, options.getCharset()); } }
public static final Canonicalizer getCanonicalizer(String mimeType) throws Exception { ContentType contentType = new ContentType(mimeType); String baseMimeType = contentType.getBaseType(); if (baseMimeType.equalsIgnoreCase(MimeConstants.TEXT_PLAIN_TYPE)) { ensureRegisteredCharset(contentType); } // use primaryMimeType as the key. // i.e. text canonicalizer will apply to text/* etc. String primaryMimeType = contentType.getPrimaryType(); Canonicalizer _canonicalizer = (Canonicalizer)_canonicalizers.get(primaryMimeType); if (_canonicalizer == null) { _canonicalizer = newCanonicalizer(primaryMimeType); } // defaults to US-ASCII String charset = contentType.getParameter("charset"); if (charset != null) _canonicalizer.setCharset(charset); return _canonicalizer; }