View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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 java.util.ArrayList;
16  import java.util.List;
17  
18  import com.eviware.soapui.impl.rest.support.handlers.DefaultMediaTypeHandler;
19  import com.eviware.soapui.impl.rest.support.handlers.HtmlMediaTypeHandler;
20  import com.eviware.soapui.impl.rest.support.handlers.JsonMediaTypeHandler;
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  	{
46  		return defaultMediaTypeHandler;
47  	}
48  
49  	public static void setDefaultMediaTypeHandler( MediaTypeHandler defaultMediaTypeHandler )
50  	{
51  		MediaTypeHandlerRegistry.defaultMediaTypeHandler = defaultMediaTypeHandler;
52  	}
53  }