package com.tianhe.frm.http;
public interface Processor
{
public byte[] process(String resource, char[] postData, String charset);
}
package com.tianhe.frm.http;
import com.tianhe.frm.context.GlobalConfig;
import com.tianhe.frm.utils.ObjectUtil;
public class ProcessorImpl implements Processor
{
public byte[] process(String resource, char[] postData, String charset)
{
Command command = createCommand(resource);
byte[] resVal = command.execute(resource, postData, charset);
return resVal;
}
private Command createCommand(String resource)
{
String type = getCommandType(resource);
String clazzName = GlobalConfig.getString("ProcessorImpl.command." + type + ".CLASS_NAME",
"com.tianhe.frm.http.CommandImpl");
Command command = (Command)ObjectUtil.createObject(clazzName);
return command;
}
private String getCommandType(String resource)
{
String vsTemp = resource;
int index = resource.indexOf("?");
if (index > 0)
{
vsTemp = vsTemp.substring(0, index);
int index2 = vsTemp.lastIndexOf(".");
vsTemp = vsTemp.substring(index2 + 1);
}
else
{
int index2 = vsTemp.lastIndexOf(".");
vsTemp = vsTemp.substring(index2 + 1);
}
return vsTemp;
}
public static void main(String[] args)
{
String type = null;
{
type = new ProcessorImpl().getCommandType("example/aaa.cmd1");
System.out.println(type);
}
{
type = new ProcessorImpl().getCommandType("example/aaa.cmd1?aaa.cmd=111");
System.out.println(type);
}
}
}