www.pudn.com > mobileMms.rar > MMContent.java


/**File Name:MMContent.java 
 * Company:  中国移动集团公司 
 * Date  :   2004-1-30 
 * */ 
 
package com.cmcc.mm7.vasp.common; 
 
import java.io.*; 
import java.util.*; 
 
public class MMContent implements Serializable, Cloneable 
{ 
  private MMContentType ContentType; 
  private String ContentID; 
  private String ContentLocation; 
  private MMContent PresentionContent; 
  private String Charset; 
  private boolean ContentIDExist; 
  private boolean ContentLocationExist; 
  private boolean PresentionContentExist; 
  public List SubContents = new ArrayList(); 
  private boolean Multipart; 
  private ByteArrayOutputStream byteOutput; 
 
  /** 
   * 构造方法 
   * */ 
  public MMContent() 
  { 
    ContentType = new MMContentType(); 
    ContentID = ""; 
    ContentLocation = ""; 
    Charset = "UTF-8"; 
    ContentIDExist = false; 
    ContentLocationExist = false; 
    PresentionContentExist = false; 
    //SubContents = new ArrayList(); 
    Multipart = false; 
    byteOutput = new ByteArrayOutputStream(); 
  } 
  /** 
   * 该构造方法是为了几个create方法所创建的。外部并不能调用。所以申明成private。 
   * */ 
  private MMContent(byte[] content) 
  { 
    byteOutput = new ByteArrayOutputStream(); 
    try{ 
      byteOutput.write(content); 
    }catch(IOException e){ 
      System.err.println(e); 
    } 
  } 
  /** 
   * 获得此MMContent嵌套的子MMContent的List 
   * */ 
  public List getSubContents() 
  { 
    return(SubContents); 
  } 
  /** 
   * 是否存在嵌套媒体 
   * */ 
  public boolean isMultipart() 
  { 
    return(Multipart); 
  } 
  /** 
   * 获得内容类型 
   * */ 
  public MMContentType getContentType() 
  { 
    return(ContentType); 
  } 
  /** 
   * 设置内容类型 
   * */ 
  public void setContentType(MMContentType contentType) 
  { 
    ContentType = contentType; 
  } 
 
  ////////////// 
  public void setContentType(String type) 
  { 
    MMContentType conType = new MMContentType(type); 
    ContentType = conType; 
  } 
 
  ///////////////////// 
 
  /** 
   * 获得ContentID 
   * */ 
  public String getContentID() 
  { 
    return(ContentID); 
  } 
  /** 
   * 设置ContentID 
   * */ 
  public void setContentID(String contentID) 
  { 
    ContentID = contentID; 
    ContentIDExist = true; 
  } 
  /** 
   * 是否存在ContentID 
   * */ 
  public boolean isContentIDExist() 
  { 
    return(ContentIDExist); 
  } 
  /** 
   * 获得ContentLocation 
   * */ 
  public String getContentLocation() 
  { 
    return(ContentLocation); 
  } 
  /** 
   * 设置ContentLocation 
   * */ 
  public void setContentLocation(String contentLocation) 
  { 
    ContentLocation = contentLocation; 
    ContentLocationExist = true; 
  } 
  /** 
   * 是否存在ContentLocation 
   * */ 
  public boolean isContentLocationExist() 
  { 
    return(ContentLocationExist); 
  } 
  /** 
   * 获得Presentation部份的内容 
   * */ 
  public MMContent getPresentionContent() 
  { 
    return(PresentionContent); 
  } 
  /** 
   * 设置MMContent为Presentation部份 
   * */ 
  public void setPresentionContent(MMContent presentionContent) 
  { 
    PresentionContent = presentionContent; 
    PresentionContentExist = true; 
  } 
  /** 
   * 是否存在Presentation部份 
   * */ 
  public boolean isPresentionContentExist() 
  { 
    return(PresentionContentExist); 
  } 
  /** 
   * 加入单个MMContent到MMContent(List) 
   * */ 
  public void addSubContent(MMContent content) 
  { 
     SubContents.add(content); 
     Multipart = true; 
  } 
  /** 
   * 以二进制方式获得MMContent的内容 
   * */ 
  public byte[] getContent() 
  { 
    return(byteOutput.toByteArray()); 
  } 
  /** 
   * 以String方式获得MMContent的内容 
   * */ 
  public String getContentAsString() 
  { 
    String charset = getCharset(); 
    if(charset == null || charset.equals("")) 
      charset = "UTF-8"; 
    try{ 
      return (byteOutput.toString(charset)); 
      //return (byteOutput.toString()); 
    }catch(IOException ioe){ 
      System.err.println(ioe); 
      return null; 
    } 
  } 
  /** 
   * 通过ContentID获得MMContent类型的subContent 
   * */ 
  public MMContent getSubContentByID(String contentID) 
  { 
    List subcontents = new ArrayList(); 
    subcontents = SubContents; 
    MMContent subContent = new MMContent(); 
    for(int i=0;i