You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Unico Hommes <Un...@hippo.nl> on 2003/07/07 16:03:34 UTC

[SourceResolve] need for mime-type mappings

Hi all,

I was thinking that we need a common way to map mime-types in Avalon and
that sourceresolve package is the place to put it. I have two use cases
that raise the need for such a utility both related to sourceresolve:
one is FTPSource where I need to determine what FTP transfer mode to use
(ascii or binary) and the other is a XML database backed Source that
stores both DOM objects and Blob objects. Depending on whether the
location string identifies  one or the other I want to the SourceFactory
to return an XMLIzable Source or a plain one.

Now in Cocoon there exists a utility class MIMEUtils that loads a
mapping file for cases that the Cocoon Context object is not in the know
about such things. I'd like to have a more general solution to this
problem, and one that resides in the avalon namespace. The fact that
systems have existing ways of providing such a service (Servlet API
provides ServletContext.getMimeType() method and web.xml markup for
declaring these mappings) suggests to me a service role instead of a
static utility class.

interface MimeTypeMapping
{
	String getMimeType( String file );
}

class ServletMimeTypeMapping
{
	private ServletContext m_servletContext;
	void contextualize( Context context )
	{
		m_servletContext = context.get( "servlet-context" );
	}
	String getMimeType( String file )
	{
		return m_servletContext.getMimeType( file );
	}
}

class ConfigurableMimeTypeMapping
{
	private Map mimeTypeMap;
	void configure( Configuration configuration )
	{
		Configuration[] children = configuration.getChildren(
"mime-mapping" );
		for ( int i = 0; children.length < i; i++ )
		{
			mimeTypeMap.put( children[i].getChild(
"extension" ).getValue(), 
				children[i].getChild( "mime-type"
).getValue();
		} 
	}
	String getMimeType( String file )
	{
		return mimeTypeMap.get( file.getExtension() );
	}
}

Etc.


What do you think. Would this be a useful addition to sourceresolve?

Regards,
Unico

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org