List of usage examples for javax.mail.internet ContentType getPrimaryType
public String getPrimaryType()
From source file:org.silverpeas.core.mail.extractor.EMLExtractor.java
private boolean isTextPart(Part part) throws MessagingException { String disposition = part.getDisposition(); if (!Part.ATTACHMENT.equals(disposition) && !Part.INLINE.equals(disposition)) { try {/*from ww w .java2 s . c om*/ ContentType type = new ContentType(part.getContentType()); return "text".equalsIgnoreCase(type.getPrimaryType()); } catch (ParseException e) { SilverLogger.getLogger(this).error(e); } } else if (Part.INLINE.equals(disposition)) { try { ContentType type = new ContentType(part.getContentType()); return "text".equalsIgnoreCase(type.getPrimaryType()) && getFileName(part) == null; } catch (ParseException e) { SilverLogger.getLogger(this).error(e); } } return false; }
From source file:org.silverpeas.util.mail.EMLExtractor.java
private boolean isTextPart(Part part) throws MessagingException { String disposition = part.getDisposition(); if (!Part.ATTACHMENT.equals(disposition) && !Part.INLINE.equals(disposition)) { try {//from ww w . jav a 2 s . co m ContentType type = new ContentType(part.getContentType()); return "text".equalsIgnoreCase(type.getPrimaryType()); } catch (ParseException e) { SilverTrace.error("util", EMLExtractor.class.getSimpleName() + ".getFileName", "root.EX_NO_MESSAGE", e); } } else if (Part.INLINE.equals(disposition)) { try { ContentType type = new ContentType(part.getContentType()); return "text".equalsIgnoreCase(type.getPrimaryType()) && getFileName(part) == null; } catch (ParseException e) { SilverTrace.error("util", EMLExtractor.class.getSimpleName() + ".getFileName", "root.EX_NO_MESSAGE", e); } } return false; }
From source file:org.trancecode.xproc.binding.DataPortBinding.java
private void writeContent(final SaxonBuilder builder) { final URI uri = URI.create(href); if (uri.getScheme() != null && !StringUtils.equals("file", uri.getScheme()) && !StringUtils.equals("http", uri.getScheme())) { throw XProcExceptions.xd0012(this.getLocation(), uri.toASCIIString()); }/*www . j a va 2s.c o m*/ try { final URL url; if (uri.isAbsolute()) { url = uri.toURL(); } else { url = node.getBaseURI().resolve(uri).toURL(); } final QName contentTypeAtt = (wrapper == null) ? XProcXmlModel.Attributes.CONTENT_TYPE : XProcXmlModel.Attributes.C_CONTENT_TYPE; final QName encodingAtt = (wrapper == null) ? XProcXmlModel.Attributes.ENCODING : XProcXmlModel.Attributes.C_ENCODING; final URLConnection urlConnection = url.openConnection(); final ContentType guessContentType; if (StringUtils.equals("http", url.getProtocol())) { guessContentType = Steps.getContentType(urlConnection.getContentType(), node); } else { if (contentType != null) { guessContentType = contentType; } else { guessContentType = Steps .getContentType("application/octet-stream ; encoding=" + Steps.ENCODING_BASE64, node); } } final Charset charset; if (contentType != null && contentType.getParameter("charset") != null) { charset = Charset.forName(contentType.getParameter("charset")); } else { charset = Charset.forName("UTF-8"); } final InputStream stream = urlConnection.getInputStream(); builder.attribute(contentTypeAtt, Steps.contentTypeToString(guessContentType)); if (StringUtils.equals("text", guessContentType.getPrimaryType()) || StringUtils.contains(guessContentType.getSubType(), "xml")) { if (guessContentType.getParameter("encoding") != null) { builder.attribute(encodingAtt, guessContentType.getParameter("encoding")); } builder.startContent(); builder.text(IOUtils.toString(stream, charset.name())); } else { builder.attribute(encodingAtt, Steps.ENCODING_BASE64); builder.startContent(); builder.text(Base64.encodeBytes(IOUtils.toByteArray(stream), Base64.DO_BREAK_LINES)); } } catch (final IOException ioe) { throw XProcExceptions.xd0029(this.getLocation()); } }