本文整理汇总了Java中javax.mail.internet.ContentType.getParameter方法的典型用法代码示例。如果您正苦于以下问题:Java ContentType.getParameter方法的具体用法?Java ContentType.getParameter怎么用?Java ContentType.getParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.internet.ContentType
的用法示例。
在下文中一共展示了ContentType.getParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRegularPartCharset
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
/**
* Get the character set of a regular part
*
* @param partIndex
* the index of the part
* @return the charset
* @throws PackageException
*/
@PublicAtsApi
public String getRegularPartCharset(
int partIndex ) throws PackageException {
// first check if there is part at this position at all
if (partIndex >= regularPartIndices.size()) {
throw new NoSuchMimePartException("No regular part at position '" + partIndex + "'");
}
try {
MimePart part = getPart(regularPartIndices.get(partIndex));
// get the content type header
ContentType contentType = new ContentType(part.getContentType());
return contentType.getParameter("charset");
} catch (MessagingException me) {
throw new PackageException(me);
}
}
示例2: getAttachmentCharset
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
/**
* Get the attachment character set
*
* @param partIndex
* the index of the attachment
* @return the character set for this attachment, null if there is no such
* @throws PackageException
*/
@PublicAtsApi
public String getAttachmentCharset(
int partIndex ) throws PackageException {
// first check if there is part at this position at all
if (partIndex >= attachmentPartIndices.size()) {
throw new NoSuchMimePartException("No attachment at position '" + partIndex + "'");
}
try {
MimePart part = getPart(attachmentPartIndices.get(partIndex));
// get the content type header
ContentType contentType = new ContentType(part.getContentType());
return contentType.getParameter("charset");
} catch (MessagingException me) {
throw new PackageException(me);
}
}
示例3: processDocument
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
public OMElement processDocument(Reader reader, String contentType,
MessageContext messageContext) throws AxisFault {
String charset;
try {
ContentType ct = new ContentType(contentType);
charset = ct.getParameter("charset");
} catch (ParseException ex) {
charset = null;
}
if (charset == null) {
charset = MessageContext.DEFAULT_CHAR_SET_ENCODING;
}
messageContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charset);
return processDocument(new ReaderInputStream(reader, charset), contentType,
messageContext);
}
示例4: getTextContent
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
/**
* Extract the text content for a {@link BodyPart}, assuming the default
* encoding.
*/
public static String getTextContent(BodyPart part) throws MessagingException, IOException {
ContentType contentType = new ContentType(part.getContentType());
String charset = contentType.getParameter("charset");
if (charset == null) {
// N.B.(schwardo): The MIME spec doesn't seem to provide a
// default charset, but the default charset for HTTP is
// ISO-8859-1. That seems like a reasonable default.
charset = "ISO-8859-1";
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteStreams.copy(part.getInputStream(), baos);
try {
return new String(baos.toByteArray(), charset);
} catch (UnsupportedEncodingException ex) {
return new String(baos.toByteArray());
}
}
示例5: handleInbound
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
@Override
public boolean handleInbound(SOAPMessageContext msgContext)
{
log.info("handleInbound");
ContentType contentType = getContentType(msgContext);
if (contentType != null)
{
log.info("contentType="+contentType);
String startInfo = contentType.getParameter("start-info");
if (!startInfo.equals(SOAPConstants.SOAP_1_1_CONTENT_TYPE))
{
return false;
}
}
else
{
return false;
}
try
{
SOAPEnvelope soapEnvelope = ((SOAPMessageContext)msgContext).getMessage().getSOAPPart().getEnvelope();
String nsURI = soapEnvelope.getNamespaceURI();
log.info("nsURI=" + nsURI);
if (!SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(nsURI))
{
return false;
}
}
catch (SOAPException se)
{
throw new WebServiceException(se);
}
return true;
}
示例6: handleInbound
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
@Override
public boolean handleInbound(SOAPMessageContext msgContext)
{
log.info("handleInbound");
ContentType contentType = getContentType(msgContext);
if (contentType != null)
{
log.info("contentType="+contentType);
String startInfo = contentType.getParameter("start-info");
if (!startInfo.equals(SOAPConstants.SOAP_1_2_CONTENT_TYPE))
{
return false;
}
}
else
{
return false;
}
try
{
SOAPEnvelope soapEnvelope = ((SOAPMessageContext)msgContext).getMessage().getSOAPPart().getEnvelope();
String nsURI = soapEnvelope.getNamespaceURI();
log.info("nsURI=" + nsURI);
if (!SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(nsURI))
{
return false;
}
}
catch (SOAPException se)
{
throw new WebServiceException(se);
}
return true;
}
示例7: handleInbound
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
@Override
public boolean handleInbound(SOAPMessageContext msgContext)
{
log.info("handleInbound");
try
{
SOAPEnvelope soapEnvelope = msgContext.getMessage().getSOAPPart().getEnvelope();
String nsURI = soapEnvelope.getNamespaceURI();
log.info("nsURI=" + nsURI);
if (!SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(nsURI))
{
return false;
}
}
catch (SOAPException se)
{
throw new WebServiceException(se);
}
ContentType contentType = getContentType(msgContext);
if (contentType != null)
{
log.info("contentType="+contentType);
String startInfo = contentType.getParameter("start-info");
if (!startInfo.equals(SOAPConstants.SOAP_1_1_CONTENT_TYPE))
{
return false;
}
}
else
{
return false;
}
return true;
}
示例8: handleInbound
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
@Override
public boolean handleInbound(SOAPMessageContext msgContext)
{
log.info("handleInbound");
try
{
SOAPEnvelope soapEnvelope = msgContext.getMessage().getSOAPPart().getEnvelope();
String nsURI = soapEnvelope.getNamespaceURI();
log.info("nsURI=" + nsURI);
if (!SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(nsURI))
{
return false;
}
}
catch (SOAPException se)
{
throw new WebServiceException(se);
}
ContentType contentType = getContentType(msgContext);
if (contentType != null)
{
log.info("contentType="+contentType);
String startInfo = contentType.getParameter("start-info");
if (!startInfo.equals(SOAPConstants.SOAP_1_2_CONTENT_TYPE))
{
return false;
}
}
else
{
return false;
}
return true;
}
示例9: charsetFromMime
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
private static String charsetFromMime(String mime) {
String charset;
try {
ContentType parsedType = new ContentType(mime);
charset = parsedType.getParameter("charset");
} catch (ParseException e) {
charset = null;
}
if (null == charset || "".equals(charset)) {
return DATA_URI_DEFAULT_CHARSET;
} else {
return charset;
}
}
示例10: outputPostamble
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
static void outputPostamble(LineOutputStream lOut, BodyPart parent, String parentBoundary, BodyPart part)
throws MessagingException, IOException
{
InputStream in;
try
{
in = ((MimeBodyPart)parent).getRawInputStream();
}
catch (MessagingException e)
{
return; // no underlying content rely on default generation
}
MimeMultipart multipart = (MimeMultipart)part.getContent();
ContentType contentType = new ContentType(multipart.getContentType());
String boundary = "--" + contentType.getParameter("boundary");
int count = multipart.getCount() + 1;
String line;
while (count != 0 && (line = readLine(in)) != null)
{
if (line.startsWith(boundary))
{
count--;
}
}
while ((line = readLine(in)) != null)
{
if (line.startsWith(parentBoundary))
{
break;
}
lOut.writeln(line);
}
in.close();
}
示例11: getParameter
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
/**
* Returns the value of the parameter with the specified name in the
* specified content type
* @param type the content type
* @param name the name of the parameter
* @return the value of the parameter, or <code>null</code> if
* not specified
* @throws ParseException if parsing failed
*/
public static String getParameter(String type, String name)
throws ParseException {
if (type == null)
throw new NullPointerException("null Content-Type");
else if (name == null)
throw new NullPointerException("null parameter name");
ContentType obj = new ContentType(type);
return obj.getParameter(name);
}
示例12: handleInbound
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
public boolean handleInbound(SOAPMessageContext msgContext)
{
log.info("handleInbound");
try
{
SOAPEnvelope soapEnvelope = (SOAPEnvelope)msgContext.getMessage().getSOAPPart().getEnvelope();
String nsURI = soapEnvelope.getNamespaceURI();
log.info("nsURI=" + nsURI);
if (!SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(nsURI))
{
throw new RuntimeException("Wrong NS uri: " + nsURI);
}
}
catch (SOAPException se)
{
throw new WebServiceException(se);
}
ContentType contentType = getContentType(msgContext);
if (contentType != null)
{
log.info("contentType="+contentType);
String startInfo = contentType.getParameter("start-info");
if (!checkMtom) {
if (startInfo != null) {
throw new RuntimeException("Unexpected multipart/related message!");
} else {
return true;
}
}
if (!startInfo.equals(SOAPConstants.SOAP_1_1_CONTENT_TYPE))
{
throw new RuntimeException("Wrong start info: " + startInfo);
}
}
else
{
throw new RuntimeException("Missing content type");
}
return true;
}
示例13: decode
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
public String decode(ContentType contentType, byte[] message) throws Exception {
String charset = contentType.getParameter("charset");
return new String(message, charset);
}
示例14: doFilter
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
if (req.getHeader(UPLOAD_HEADER) != null) {
Map<String, List<String>> blobKeys = new HashMap<String, List<String>>();
Map<String, List<Map<String, String>>> blobInfos =
new HashMap<String, List<Map<String, String>>>();
Map<String, List<String>> otherParams = new HashMap<String, List<String>>();
try {
MimeMultipart multipart = MultipartMimeUtils.parseMultipartRequest(req);
int parts = multipart.getCount();
for (int i = 0; i < parts; i++) {
BodyPart part = multipart.getBodyPart(i);
String fieldName = MultipartMimeUtils.getFieldName(part);
if (part.getFileName() != null) {
ContentType contentType = new ContentType(part.getContentType());
if ("message/external-body".equals(contentType.getBaseType())) {
String blobKeyString = contentType.getParameter("blob-key");
List<String> keys = blobKeys.get(fieldName);
if (keys == null) {
keys = new ArrayList<String>();
blobKeys.put(fieldName, keys);
}
keys.add(blobKeyString);
List<Map<String, String>> infos = blobInfos.get(fieldName);
if (infos == null) {
infos = new ArrayList<Map<String, String>>();
blobInfos.put(fieldName, infos);
}
infos.add(getInfoFromBody(MultipartMimeUtils.getTextContent(part), blobKeyString));
}
} else {
List<String> values = otherParams.get(fieldName);
if (values == null) {
values = new ArrayList<String>();
otherParams.put(fieldName, values);
}
values.add(MultipartMimeUtils.getTextContent(part));
}
}
req.setAttribute(UPLOADED_BLOBKEY_ATTR, blobKeys);
req.setAttribute(UPLOADED_BLOBINFO_ATTR, blobInfos);
} catch (MessagingException ex) {
logger.log(Level.WARNING, "Could not parse multipart message:", ex);
}
chain.doFilter(new ParameterServletWrapper(request, otherParams), response);
} else {
chain.doFilter(request, response);
}
}
示例15: writeBodyPart
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
private void writeBodyPart(
OutputStream out,
MimeBodyPart bodyPart)
throws IOException, MessagingException
{
if (bodyPart.getContent() instanceof Multipart)
{
Multipart mp = (Multipart)bodyPart.getContent();
ContentType contentType = new ContentType(mp.getContentType());
String boundary = "--" + contentType.getParameter("boundary");
SMIMEUtil.LineOutputStream lOut = new SMIMEUtil.LineOutputStream(out);
Enumeration headers = bodyPart.getAllHeaderLines();
while (headers.hasMoreElements())
{
lOut.writeln((String)headers.nextElement());
}
lOut.writeln(); // CRLF separator
SMIMEUtil.outputPreamble(lOut, bodyPart, boundary);
for (int i = 0; i < mp.getCount(); i++)
{
lOut.writeln(boundary);
writeBodyPart(out, (MimeBodyPart)mp.getBodyPart(i));
lOut.writeln(); // CRLF terminator
}
lOut.writeln(boundary + "--");
}
else
{
if (SMIMEUtil.isCanonicalisationRequired(bodyPart, defaultContentTransferEncoding))
{
out = new CRLFOutputStream(out);
}
bodyPart.writeTo(out);
}
}