private boolean isXmlType(String type) { try { ContentType ct = new ContentType(type); return ct.getSubType().equals("xml") && (ct.getPrimaryType().equals("text") || ct.getPrimaryType().equals("application")); } catch (ParseException ex) { return false; } catch (RuntimeException ex) { return false; } } }
private boolean isXmlType(String type) { try { ContentType ct = new ContentType(type); return ct.getSubType().equals("xml") && (ct.getPrimaryType().equals("text") || ct.getPrimaryType().equals("application")); } catch (ParseException ex) { return false; } catch (RuntimeException ex) { return false; } } }
if (!((primaryType == null && cType.getPrimaryType() == null) || (primaryType != null && primaryType.equalsIgnoreCase(cType.getPrimaryType())))) return false;
if (!((primaryType == null && cType.getPrimaryType() == null) || (primaryType != null && primaryType.equalsIgnoreCase(cType.getPrimaryType())))) return false;
private boolean isXmlType(String type) { try { ContentType ct = new ContentType(type); return ct.getSubType().equals("xml") && (ct.getPrimaryType().equals("text") || ct.getPrimaryType().equals("application")); } catch (ParseException ex) { return false; } catch (RuntimeException ex) { return false; } } }
private boolean isXmlType(String type) { try { ContentType ct = new ContentType(type); return ct.getSubType().equals("xml") && (ct.getPrimaryType().equals("text") || ct.getPrimaryType().equals("application")); } catch (Exception ex) { return false; } } }
private boolean isXmlType(String type) { try { ContentType ct = new ContentType(type); return ct.getSubType().equals("xml") && (ct.getPrimaryType().equals("text") || ct.getPrimaryType().equals("application")); } catch (ParseException ex) { return false; } catch (RuntimeException ex) { return false; } } }
private boolean isXmlType(String type) { try { ContentType ct = new ContentType(type); return ct.getSubType().equals("xml") && (ct.getPrimaryType().equals("text") || ct.getPrimaryType().equals("application")); } catch (ParseException ex) { return false; } catch (RuntimeException ex) { return false; } } }
private boolean isXmlType(String type) { try { ContentType ct = new ContentType(type); return ct.getSubType().equals("xml") && (ct.getPrimaryType().equals("text") || ct.getPrimaryType().equals("application")); } catch (ParseException ex) { return false; } catch (RuntimeException ex) { return false; } } }
private boolean isXmlType(String type) { try { ContentType ct = new ContentType(type); return ct.getSubType().equals("xml") && (ct.getPrimaryType().equals("text") || ct.getPrimaryType().equals("application")); } catch (ParseException ex) { return false; } catch (RuntimeException ex) { return false; } } }
/** * Checks if there is a matching mime pattern for mimeType in mimeTypes. This * will return true if there is an exact match (for example text/plain = * text/plain), or if there is a wildcard subtype match (text/plain = * text/*). * * @param mimeType the mime type to search for * @param mimeTypes the set of mime types to search * @return true if there is a match, false if not */ public static boolean isMemberOf(String mimeType, Set<?> mimeTypes) { if (mimeTypes.contains(mimeType)) return true; try { if (mimeTypes.contains(new ContentType(mimeType).getPrimaryType() + "/*")) return true; } catch (ParseException e) { // eat } return false; }
public static ContentType removeCharset(ContentType contentType) { ParameterList orgParamList = contentType.getParameterList(); ParameterList paramList = new ParameterList(); for (Enumeration<?> e = orgParamList.getNames(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); if (!name.equalsIgnoreCase("charset")) { paramList.set(name, orgParamList.get(name)); } } return new ContentType(contentType.getPrimaryType(), contentType.getSubType(), paramList); } }
public static ContentType removeCharset(ContentType contentType) { ParameterList orgParamList = contentType.getParameterList(); ParameterList paramList = new ParameterList(); for (Enumeration<?> e = orgParamList.getNames(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); if (!name.equalsIgnoreCase("charset")) { paramList.set(name, orgParamList.get(name)); } } return new ContentType(contentType.getPrimaryType(), contentType.getSubType(), paramList); } }
public static ContentType addCharset(ContentType contentType, String charset) { ParameterList orgParamList = contentType.getParameterList(); ParameterList paramList = new ParameterList(); if (orgParamList != null) { for (Enumeration<?> e = orgParamList.getNames(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); paramList.set(name, orgParamList.get(name)); } } paramList.set("charset", charset); return new ContentType(contentType.getPrimaryType(), contentType.getSubType(), paramList); }
/** * 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 static ContentType addCharset(ContentType contentType, String charset) { ParameterList orgParamList = contentType.getParameterList(); ParameterList paramList = new ParameterList(); if (orgParamList != null) { for (Enumeration<?> e = orgParamList.getNames(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); paramList.set(name, orgParamList.get(name)); } } paramList.set("charset", charset); return new ContentType(contentType.getPrimaryType(), contentType.getSubType(), paramList); }
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; }
private void updateContentType(boolean cleanDefaultRoot) throws MessagingException { BodyPart part = null; if (rootId == null) { part = getBodyPart(0); } else { part = getBodyPart(rootId); if (part == null) { if (cleanDefaultRoot) rootId = null; else throw new MessagingException("Can not set root: " + rootId + ": not found"); } } if (part != null) { String primaryType = baseContentTypeObject.getPrimaryType(); String subType = baseContentTypeObject.getSubType(); ParameterList params = baseContentTypeObject.getParameterList(); ContentType newContentType = new ContentType(primaryType, subType, params); ContentType rootContentType = new ContentType(part.getDataHandler().getContentType()); newContentType.setParameter("type", rootContentType.getBaseType()); if (rootId != null) newContentType.setParameter("start", stripBrackets(rootId)); contentType = newContentType.toString(); } }
private void updateContentType(boolean cleanDefaultRoot) throws MessagingException { BodyPart part = null; if (rootId == null) { part = getBodyPart(0); } else { part = getBodyPart(rootId); if (part == null) { if (cleanDefaultRoot) rootId = null; else throw new MessagingException("Can not set root: " + rootId + ": not found"); } } if (part != null) { String primaryType = baseContentTypeObject.getPrimaryType(); String subType = baseContentTypeObject.getSubType(); ParameterList params = baseContentTypeObject.getParameterList(); ContentType newContentType = new ContentType(primaryType, subType, params); ContentType rootContentType = new ContentType(part.getDataHandler().getContentType()); newContentType.setParameter("type", rootContentType.getBaseType()); if (rootId != null) newContentType.setParameter("start", rootId); contentType = newContentType.toString(); } }
private void updateContentType(boolean cleanDefaultRoot) throws MessagingException { BodyPart part = null; if (rootId == null) { part = getBodyPart(0); } else { part = getBodyPart(rootId); if (part == null) { if (cleanDefaultRoot) rootId = null; else throw new MessagingException("Can not set root: " + rootId + ": not found"); } } if (part != null) { String primaryType = baseContentTypeObject.getPrimaryType(); String subType = baseContentTypeObject.getSubType(); ParameterList params = baseContentTypeObject.getParameterList(); ContentType newContentType = new ContentType(primaryType, subType, params); ContentType rootContentType = new ContentType(part.getDataHandler().getContentType()); newContentType.setParameter("type", rootContentType.getBaseType()); if (rootId != null) newContentType.setParameter("start", stripBrackets(rootId)); contentType = newContentType.toString(); } }