Coverage Report - org.codeforamerica.open311.facade.InvalidXMLWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
InvalidXMLWrapper
0%
0/5
N/A
1
 
 1  
 package org.codeforamerica.open311.facade;
 2  
 
 3  
 import java.net.URL;
 4  
 import java.util.Map;
 5  
 
 6  
 import org.codeforamerica.open311.facade.exceptions.APIWrapperException;
 7  
 import org.codeforamerica.open311.internals.caching.Cache;
 8  
 import org.codeforamerica.open311.internals.network.NetworkManager;
 9  
 import org.codeforamerica.open311.internals.parsing.DataParser;
 10  
 
 11  
 /**
 12  
  * Some endpoints return invalid characters in its XML response. Instances of
 13  
  * this class will parse those responses and clear the invalid characters.
 14  
  * 
 15  
  * @author Santiago MunĂ­n <santimunin@gmail.com>
 16  
  * 
 17  
  */
 18  
 public class InvalidXMLWrapper extends APIWrapper {
 19  
 
 20  
         InvalidXMLWrapper(String endpointUrl, Format format, EndpointType type,
 21  
                         DataParser dataParser, NetworkManager networkManager, Cache cache,
 22  
                         String jurisdictionId, String apiKey) {
 23  0
                 super(endpointUrl, format, type, dataParser, networkManager, cache,
 24  
                                 jurisdictionId, apiKey);
 25  0
         }
 26  
 
 27  
         /**
 28  
          * GET operation. Calls {@link #sanitizeOutput(String)} right after
 29  
          * receiving the response.
 30  
          */
 31  
         @Override
 32  
         protected String networkGet(URL url) throws APIWrapperException {
 33  0
                 return sanitizeOutput(super.networkGet(url));
 34  
         }
 35  
 
 36  
         /**
 37  
          * POST operation. Calls {@link #sanitizeOutput(String)} right after
 38  
          * receiving the response.
 39  
          */
 40  
         @Override
 41  
         protected String networkPost(URL url, Map<String, String> parameters)
 42  
                         throws APIWrapperException {
 43  0
                 return sanitizeOutput(super.networkPost(url, parameters));
 44  
         }
 45  
 
 46  
         /**
 47  
          * Skips invalid characters.
 48  
          * 
 49  
          * @param response
 50  
          *            Received response.
 51  
          * @return Same string without the invalid characters.
 52  
          */
 53  
         private String sanitizeOutput(String response) {
 54  0
                 return response.replace("\u0010", "");
 55  
         }
 56  
 
 57  
 }