1 16 17 package org.apache.jetspeed.util; 18 19 20 30 public class MimeType { 31 32 public static final MimeType HTML = new MimeType( "text/html", "UTF-8" ); public static final MimeType XHTML = new MimeType( "text/xhtml" ); 34 public static final MimeType WML = new MimeType( "text/vnd.wap.wml" ); 35 public static final MimeType XML = new MimeType( "text/xml" ); 36 public static final MimeType VXML = new MimeType( "text/vxml" ); 37 38 41 private String mimeType = ""; 42 46 private String charSet = null; 47 48 public MimeType( String mimeType ) { 49 if(mimeType == null) { 50 throw new NullPointerException (); 51 } 52 this.mimeType = mimeType; 53 } 54 55 58 public MimeType( String mimeType, String charSet ) { 59 if(mimeType == null) { 60 throw new NullPointerException (); 61 } 62 this.mimeType = mimeType; 63 this.charSet = charSet; 64 } 65 66 72 public String getCode() { 73 String type = this.mimeType; 74 type = type.substring(type.indexOf("/")+1); 76 int idx = type.lastIndexOf("."); 78 if (idx >= 0 ) { 79 type = type.substring(idx+1); 80 } 81 idx = type.lastIndexOf("-"); 83 if (idx >= 0 ) { 84 type = type.substring(idx+1); 85 } 86 87 return type.toLowerCase(); 88 } 89 90 93 public String getContentType() 94 { 95 return this.mimeType; 96 } 97 98 101 public String getCharSet() 102 { 103 return this.charSet; 104 } 105 106 109 public String toString() 110 { 111 if( null == this.charSet ) 112 { 113 return this.mimeType; 114 } 115 return this.mimeType + 116 "; charset=" + 117 this.charSet; 118 } 119 120 123 public boolean equals( Object obj ) { 124 if ( this == obj) { 125 return true; 126 } 127 128 if (obj instanceof MimeType) { 129 MimeType comp = (MimeType)obj; 130 return this.toString().equals( comp.toString() ); 131 } else { 132 return false; 133 } 134 } 135 136 } 137 | Popular Tags |