/** * Creates a new ContentTypeHeader based on the newly supplied contentType and * contentSubType values. * * @param contentType - the new string content type value. * @param contentSubType - the new string content sub-type value. * @throws ParseException which signals that an error has been reached * unexpectedly while parsing the content type or content subtype value. * @return the newly created ContentTypeHeader object. */ public ContentTypeHeader createContentTypeHeader( String contentType, String contentSubType) throws ParseException { if (contentType == null || contentSubType == null) throw new NullPointerException("null contentType or subType"); ContentType c = new ContentType(); c.setContentType(contentType); c.setContentSubType(contentSubType); return c; }
/** * Encode into a canonical string. * @return String. */ public String encodeBody() { return encodeBody(new StringBuilder()).toString(); }
public boolean equals(Object other) { if (other instanceof ContentTypeHeader) { final ContentTypeHeader o = (ContentTypeHeader) other; return this.getContentType().equalsIgnoreCase( o.getContentType() ) && this.getContentSubType().equalsIgnoreCase( o.getContentSubType() ) && equalParameters( o ); } return false; } }
/** * Set the message content given type and subtype. * * @param type is the message type (eg. application) * @param subType is the message sybtype (eg. sdp) * @param messageContent is the messge content as a string. */ public void setMessageContent(String type, String subType, String messageContent) { if (messageContent == null) throw new IllegalArgumentException("messgeContent is null"); ContentType ct = new ContentType(type, subType); this.setHeader(ct); this.messageContent = messageContent; this.messageContentBytes = null; this.messageContentObject = null; // Could be double byte so we need to compute length // after converting to byte[] computeContentLength(messageContent); }
/** Constructor given a content type and subtype. *@param contentType is the content type. *@param contentSubtype is the content subtype */ public ContentType(String contentType, String contentSubtype) { this(); this.setContentType(contentType, contentSubtype); }
/** Get the charset parameter. */ public String getCharset() { return this.getParameter("charset"); }
/** * Returns the charset to use for encoding/decoding the body of this message */ protected final String getCharset() { ContentType ct = getContentTypeHeader(); if (ct!=null) { String c = ct.getCharset(); return c!=null ? c : contentEncodingCharset; } else return contentEncodingCharset; }
protected StringBuilder encodeBody(StringBuilder buffer) { mediaRange.encode(buffer); if (hasParameters()) { buffer.append(SEMICOLON); parameters.encode(buffer); } return buffer; }
/** * Set the message content for a given type and subtype. * * @param type is the messge type. * @param subType is the message subType. * @param messageContent is the message content as a byte array. */ public void setMessageContent(String type, String subType, byte[] messageContent) { ContentType ct = new ContentType(type, subType); this.setHeader(ct); this.setMessageContent(messageContent); computeContentLength(messageContent); }
public SIPHeader parse() throws ParseException { ContentType contentType = new ContentType(); if (debug) dbg_enter("ContentTypeParser.parse"); try { this.headerName(TokenTypes.CONTENT_TYPE); // The type: lexer.match(TokenTypes.ID); Token type = lexer.getNextToken(); this.lexer.SPorHT(); contentType.setContentType(type.getTokenValue()); // The sub-type: lexer.match('/'); lexer.match(TokenTypes.ID); Token subType = lexer.getNextToken(); this.lexer.SPorHT(); contentType.setContentSubType(subType.getTokenValue()); super.parse(contentType); this.lexer.match('\n'); } finally { if (debug) dbg_leave("ContentTypeParser.parse"); } return contentType; }
ContentTypeHeader cth = new ContentType("message", "sipfrag"); buf.append("\r\n" + cth.toString()); ContentLength clengthHeader = new ContentLength(clength);
public SIPHeader parse() throws ParseException { ContentType contentType = new ContentType(); if (debug) dbg_enter("ContentTypeParser.parse"); try { this.headerName(TokenTypes.CONTENT_TYPE); // The type: lexer.match(TokenTypes.ID); Token type = lexer.getNextToken(); this.lexer.SPorHT(); contentType.setContentType(type.getTokenValue()); // The sub-type: lexer.match('/'); lexer.match(TokenTypes.ID); Token subType = lexer.getNextToken(); this.lexer.SPorHT(); contentType.setContentSubType(subType.getTokenValue()); super.parse(contentType); this.lexer.match('\n'); } finally { if (debug) dbg_leave("ContentTypeParser.parse"); } return contentType; }
public MultipartMimeContent createMultipartMimeContent(ContentTypeHeader multipartMimeCth, String[] contentType, String[] contentSubtype, String[] contentBody) { String boundary = multipartMimeCth.getParameter("boundary"); MultipartMimeContentImpl retval = new MultipartMimeContentImpl(multipartMimeCth); for (int i = 0 ; i < contentType.length; i++ ) { ContentTypeHeader cth = new ContentType(contentType[i],contentSubtype[i]); ContentImpl contentImpl = new ContentImpl(contentBody[i]); contentImpl.setContentTypeHeader(cth); retval.add(contentImpl); } return retval; }