View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.rest.support;
14  
15  import com.eviware.soapui.impl.rest.support.handlers.DefaultMediaTypeHandler;
16  import com.eviware.soapui.impl.rest.support.handlers.HtmlMediaTypeHandler;
17  import com.eviware.soapui.impl.rest.support.handlers.JsonMediaTypeHandler;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  public class MediaTypeHandlerRegistry
23  {
24     private static List<MediaTypeHandler> mediaTypeHandlers = new ArrayList<MediaTypeHandler>();
25     private static MediaTypeHandler defaultMediaTypeHandler = new DefaultMediaTypeHandler();
26  
27     static
28     {
29        mediaTypeHandlers.add( new JsonMediaTypeHandler() );
30        mediaTypeHandlers.add( new HtmlMediaTypeHandler() );
31     }
32  
33     public static MediaTypeHandler getTypeHandler( String contentType )
34     {
35        for( MediaTypeHandler handler : mediaTypeHandlers )
36        {
37           if( handler.canHandle(contentType))
38              return handler;
39        }
40  
41     	return defaultMediaTypeHandler;
42     }
43  
44     public static MediaTypeHandler getDefaultMediaTypeHandler() {
45        return defaultMediaTypeHandler;
46     }
47  
48     public static void setDefaultMediaTypeHandler(MediaTypeHandler defaultMediaTypeHandler) {
49        MediaTypeHandlerRegistry.defaultMediaTypeHandler = defaultMediaTypeHandler;
50     }
51  }