- Timestamp:
- 05/21/08 01:41:31 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs/branches/complex-obs/src/api/org/openmrs/obs/handler/ImageHandler.java
r4265 r4289 34 34 35 35 /** 36 * Handler for storing basic images for complex obs to the file system. 36 * Handler for storing basic images for complex obs to the file system. The 37 * image mime type used is taken from the image name. if the .* image name 38 * suffix matches {@link javax.imageio.ImageIO#getWriterFormatNames()} then that 39 * mime type will be used to save the image. Otherwise the default mime type is 40 * ImageHandler.MIME (currently "jpg"). 41 * 42 * Images are stored in the location specified by the global property: 43 * "obs.complex_obs_dir" 37 44 */ 38 45 public class ImageHandler implements ComplexObsHandler { … … 42 49 SimpleDateFormat longfmt; 43 50 // default mime type 44 public static final String MIME = " bmp";51 public static final String MIME = "jpg"; 45 52 private Set<String> mimes; 46 53 … … 87 94 String[] titles = t.split("\\."); 88 95 System.out.println(titles.length); 89 String mime = (titles.length < 2) ? titles[0] : titles[titles.length-1]; 96 String mime = (titles.length < 2) ? titles[0] 97 : titles[titles.length - 1]; 90 98 String MIME = mimes.contains(mime) ? mime : ImageHandler.MIME; 91 99 String title = obs.getComplexData().getTitle().replace("." + MIME, ""); … … 102 110 } else { 103 111 outputfile = new File(dir, title + "." + MIME); 104 // outputfile = new File(dir, title);112 // outputfile = new File(dir, title); 105 113 } 106 114 int i = 0; … … 112 120 // Remove the mime type from the filename. 113 121 tmp = new String(outputfile.getAbsolutePath() 114 .replace("." + MIME, ""));122 .replace("." + MIME, "")); 115 123 outputfile = null; 116 124 // Append two-digit count number to the filename. … … 120 128 nf.format(Integer.valueOf(++i))); 121 129 // Append the mime type to the filename. 122 // outputfile = new File(filename);130 // outputfile = new File(filename); 123 131 outputfile = new File(filename + "." + MIME); 124 132 } … … 164 172 File file = ImageHandler.getComplexDataFile(obs); 165 173 if (file.exists() && file.delete()) { 166 //obs.setComplexData(null);174 obs.setComplexData(null); 167 175 // obs.setValueComplex(null); 168 176 return true; … … 173 181 } 174 182 183 /** 184 * @see org.openmrs.obs.ComplexObsHandler#getComplexData(org.openmrs.Obs, java.lang.String) 185 */ 175 186 public ComplexData getComplexData(Obs obs, String view) { 176 187 return this.getObs(obs).getComplexData();