Coverage Report - org.codeforamerica.open311.facade.Format
 
Classes in this File Line Coverage Branch Coverage Complexity
Format
100%
15/15
100%
4/4
1.8
 
 1  
 package org.codeforamerica.open311.facade;
 2  
 
 3  
 /**
 4  
  * Represent the different formats allowed by the library.
 5  
  * 
 6  
  * @author Santiago MunĂ­n <santimunin@gmail.com>
 7  
  * 
 8  
  */
 9  2
 public enum Format {
 10  1
         XML("xml", "text/xml"), JSON("json", "application/json");
 11  
 
 12  
         private String description;
 13  
         private String httpContentType;
 14  
 
 15  2
         Format(String description, String httpContentType) {
 16  2
                 this.description = description;
 17  2
                 this.httpContentType = httpContentType;
 18  2
         }
 19  
 
 20  
         public String getDescription() {
 21  13
                 return description;
 22  
         }
 23  
 
 24  
         public String getHTTPContentType() {
 25  2
                 return httpContentType;
 26  
         }
 27  
 
 28  
         public String toString() {
 29  11
                 return getDescription();
 30  
         }
 31  
 
 32  
         /**
 33  
          * Builds an instance from the content type.
 34  
          * 
 35  
          * @param contentTypeString
 36  
          *            A string representing a content type.
 37  
          * @return <code>null</code> if the given content type is not allowed.
 38  
          */
 39  
         public static Format getFromHTTPContentTypeString(String contentTypeString) {
 40  27
                 contentTypeString = contentTypeString.toLowerCase();
 41  27
                 if (contentTypeString.equals(JSON.httpContentType)) {
 42  1
                         return Format.JSON;
 43  
                 }
 44  26
                 if (contentTypeString.equals(XML.httpContentType)) {
 45  25
                         return Format.XML;
 46  
                 }
 47  1
                 return null;
 48  
         }
 49  
 }