// Path: src/main/java/net/sf/serfj/Config.java
// public class Config extends SystemConfig {
// 
// 	/**
// 	 * Flag for debug purposes.
// 	 */
// 	protected static final ConfigParam DEBUG = new ConfigParam("debug");
// 
// 	/**
// 	 * HTTP Encoding. Default is UTF-8
// 	 */
// 	public static final ConfigParam ENCODING = new ConfigParam("encoding", "UTF-8");
// 
// 	/**
// 	 * Java main package where the source is located.
// 	 */
// 	public static final ConfigParam MAIN_PACKAGE = new ConfigParam("main.package");
// 
// 	/**
// 	 * Packages style.
// 	 */
// 	public static final ConfigParam PACKAGES_STYLE = new ConfigParam("packages.style");
// 
// 	/**
// 	 * Java package where controllers will be located.
// 	 */
// 	public static final ConfigParam ALIAS_CONTROLLERS_PACKAGE = new ConfigParam("alias.controllers.package", "controllers");
// 
// 	/**
// 	 * Java package where serializers for responses will be located.
// 	 */
// 	public static final ConfigParam ALIAS_SERIALIZERS_PACKAGE = new ConfigParam("alias.serializers.package", "serializers");
// 
// 	/**
// 	 * Suffix used for controller classes
// 	 */
// 	public static final ConfigParam SUFFIX_CONTROLLER = new ConfigParam("suffix.controllers", "OFF");
// 
// 	/**
// 	 * Suffix used for serializer classes
// 	 */
// 	public static final ConfigParam SUFFIX_SERIALIZER = new ConfigParam("suffix.serializer", "Serializer");
// 
// 	/**
// 	 * Directory where the views will be located.
// 	 */
// 	public static final ConfigParam VIEWS_DIRECTORY = new ConfigParam("views.directory", "views");
// 
// 	public Config(String filename) throws ConfigFileIOException {
// 		super(filename);
// 	}
// }


import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import net.sf.serfj.Config;

/*
 * Copyright 2010 Eduardo Yáñez Parareda
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.sf.serfj.finders;




/**
 * Finds a serializer for a request. It finds a class with the the name
 * ExtensionResourceNameSerializer in the directory expected depending on the
 * package style used. Extension could be .xml, .json, .anything, so the finder
 * will look for JsonResourceNameSerializer, AnythingResourceNameSerializer,
 * etc...<br/>
 * <br/>
 * 
 * There are some default serializers:<br/>
 * - net.sf.serfj.serializers.JsonSerializer<br/>
 * - net.sf.serfj.serializers.XmlSerializer<br/>
 * - net.sf.serfj.serializers.PageSerializer<br/>
 * <br/>
 * 
 * that will be used if there aren't any serializers found for a resource.
 * 
 * @author Eduardo Yáñez 
 */
public class SerializerFinder extends ResourceFinder {

	protected static final String DEFAULT_SERIALIZERS_PACKAGE = "net.sf.serfj.serializers";
	private static final String PAGE_EXTENSION = "page";
	private static final String JSON_EXTENSION = "json";
	private static final String B64_EXTENSION = "base64";
    private static final String XML_EXTENSION = "xml";
    private static final String FILE_EXTENSION = "file";

	private static Map<String, String> contentType2Extension = new HashMap<String, String>(4);

	public SerializerFinder(String extension) {
		super(null, null, (extension == null ? PAGE_EXTENSION : extension), OFF_OPTION, null);
		this.initExtensionsCache();
	}

	public SerializerFinder(Config config, String extension) {

// Path: src/main/java/net/sf/serfj/Config.java
// public class Config extends SystemConfig {
// 
// 	/**
// 	 * Flag for debug purposes.
// 	 */
// 	protected static final ConfigParam DEBUG = new ConfigParam("debug");
// 
// 	/**
// 	 * HTTP Encoding. Default is UTF-8
// 	 */
// 	public static final ConfigParam ENCODING = new ConfigParam("encoding", "UTF-8");
// 
// 	/**
// 	 * Java main package where the source is located.
// 	 */
// 	public static final ConfigParam MAIN_PACKAGE = new ConfigParam("main.package");
// 
// 	/**
// 	 * Packages style.
// 	 */
// 	public static final ConfigParam PACKAGES_STYLE = new ConfigParam("packages.style");
// 
// 	/**
// 	 * Java package where controllers will be located.
// 	 */
// 	public static final ConfigParam ALIAS_CONTROLLERS_PACKAGE = new ConfigParam("alias.controllers.package", "controllers");
// 
// 	/**
// 	 * Java package where serializers for responses will be located.
// 	 */
// 	public static final ConfigParam ALIAS_SERIALIZERS_PACKAGE = new ConfigParam("alias.serializers.package", "serializers");
// 
// 	/**
// 	 * Suffix used for controller classes
// 	 */
// 	public static final ConfigParam SUFFIX_CONTROLLER = new ConfigParam("suffix.controllers", "OFF");
// 
// 	/**
// 	 * Suffix used for serializer classes
// 	 */
// 	public static final ConfigParam SUFFIX_SERIALIZER = new ConfigParam("suffix.serializer", "Serializer");
// 
// 	/**
// 	 * Directory where the views will be located.
// 	 */
// 	public static final ConfigParam VIEWS_DIRECTORY = new ConfigParam("views.directory", "views");
// 
// 	public Config(String filename) throws ConfigFileIOException {
// 		super(filename);
// 	}
// }


// Path: src/main/java/net/sf/serfj/finders/SerializerFinder.java
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import net.sf.serfj.Config;

/*
 * Copyright 2010 Eduardo Yáñez Parareda
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.sf.serfj.finders;




/**
 * Finds a serializer for a request. It finds a class with the the name
 * ExtensionResourceNameSerializer in the directory expected depending on the
 * package style used. Extension could be .xml, .json, .anything, so the finder
 * will look for JsonResourceNameSerializer, AnythingResourceNameSerializer,
 * etc...<br/>
 * <br/>
 * 
 * There are some default serializers:<br/>
 * - net.sf.serfj.serializers.JsonSerializer<br/>
 * - net.sf.serfj.serializers.XmlSerializer<br/>
 * - net.sf.serfj.serializers.PageSerializer<br/>
 * <br/>
 * 
 * that will be used if there aren't any serializers found for a resource.
 * 
 * @author Eduardo Yáñez 
 */
public class SerializerFinder extends ResourceFinder {

	protected static final String DEFAULT_SERIALIZERS_PACKAGE = "net.sf.serfj.serializers";
	private static final String PAGE_EXTENSION = "page";
	private static final String JSON_EXTENSION = "json";
	private static final String B64_EXTENSION = "base64";
    private static final String XML_EXTENSION = "xml";
    private static final String FILE_EXTENSION = "file";

	private static Map<String, String> contentType2Extension = new HashMap<String, String>(4);

	public SerializerFinder(String extension) {
		super(null, null, (extension == null ? PAGE_EXTENSION : extension), OFF_OPTION, null);
		this.initExtensionsCache();
	}

	public SerializerFinder(Config config, String extension) {

		super(config.getString(Config.MAIN_PACKAGE), config.getString(Config.ALIAS_SERIALIZERS_PACKAGE), 
