Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/21/08 01:41:31 (8 months ago)
Author:
bmckown
Message:

complex_obs branch: TextHandler is now able to do file i/o for files using byte stream. Cleaned up WebImageHandler giving it very limited function. Added byte array to ComplexData to facilitate byte streaming for files.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/complex-obs/src/api/org/openmrs/obs/handler/ImageHandler.java

    r4265 r4289  
    3434 
    3535/** 
    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"   
    3744 */ 
    3845public class ImageHandler implements ComplexObsHandler { 
     
    4249        SimpleDateFormat longfmt; 
    4350        // default mime type 
    44         public static final String MIME = "bmp"; 
     51        public static final String MIME = "jpg"; 
    4552        private Set<String> mimes; 
    4653 
     
    8794                String[] titles = t.split("\\."); 
    8895                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]; 
    9098                String MIME = mimes.contains(mime) ? mime : ImageHandler.MIME; 
    9199                String title = obs.getComplexData().getTitle().replace("." + MIME, ""); 
     
    102110                        } else { 
    103111                                outputfile = new File(dir, title + "." + MIME); 
    104                                 //outputfile = new File(dir, title); 
     112                                // outputfile = new File(dir, title); 
    105113                        } 
    106114                        int i = 0; 
     
    112120                                // Remove the mime type from the filename. 
    113121                                tmp = new String(outputfile.getAbsolutePath() 
    114                                                                                        .replace("." + MIME, "")); 
     122                                                           .replace("." + MIME, "")); 
    115123                                outputfile = null; 
    116124                                // Append two-digit count number to the filename. 
     
    120128                                                      nf.format(Integer.valueOf(++i))); 
    121129                                // Append the mime type to the filename. 
    122                                 //outputfile = new File(filename); 
     130                                // outputfile = new File(filename); 
    123131                                outputfile = new File(filename + "." + MIME); 
    124132                        } 
     
    164172                File file = ImageHandler.getComplexDataFile(obs); 
    165173                if (file.exists() && file.delete()) { 
    166                         // obs.setComplexData(null); 
     174                        obs.setComplexData(null); 
    167175                        // obs.setValueComplex(null); 
    168176                        return true; 
     
    173181        } 
    174182 
     183        /** 
     184         * @see org.openmrs.obs.ComplexObsHandler#getComplexData(org.openmrs.Obs, java.lang.String) 
     185         */ 
    175186        public ComplexData getComplexData(Obs obs, String view) { 
    176187                return this.getObs(obs).getComplexData();