com.us.data.ContentTypeProcesser.java Source code

Java tutorial

Introduction

Here is the source code for com.us.data.ContentTypeProcesser.java

Source

/*
 * @(#)ContentTypeProcesser.java 2011-9-21
 * ?us??  2008-2011, Inc. All rights reserved.
 * s.server. Use is subject to license terms.
 */

package com.us.data;

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.springframework.util.ResourceUtils;

import com.us.exception.UsMsgException;
import com.us.util.JSONHelper;
import com.us.util.LogHelper;

/**
 * ??Response??
 * 
 * @author <a href="mailto:monlyu.hong@gmail.com">monlyu</a>
 * @version 0.4.3, 2011-9-21
 * @since JDK6.0
 */
public class ContentTypeProcesser implements Processor {

    Log log = LogHelper.getLog();
    /** HashMapHttp? */
    private static Map<String, Object> ALL_TYPES = new HashMap<String, Object>();

    /**
     * ?
     * 
     * @param key
     * @return
     */
    public static String findType(String key) {
        Object type = ALL_TYPES.get(key.toLowerCase());
        if (type != null)
            return type.toString();
        return "";
    }

    @Override
    public void doProcess(Object data) {
        log.info("?HttpResponse?");
        String fileLocation = data.toString();
        try {
            ALL_TYPES = JSONHelper.readJSON(ResourceUtils.getFile(fileLocation));
        } catch (FileNotFoundException e) {
            throw UsMsgException.newInstance(String.format("?[%s]", fileLocation),
                    e);
        }
    }
}