📄 buffers.java
字号:
package com.saas.sys.buffer;
import java.util.ArrayList;
import com.saas.biz.commen.config;
import java.util.Iterator;
import org.apache.struts.upload.FormFile;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.*;
import com.saas.sys.log.Logger;
import java.lang.reflect.*;
import java.util.HashMap;
import java.io.*;
import org.apache.commons.beanutils.PropertyUtils;
import com.saas.sys.dbm.QueryXML;
import java.net.*;
import com.saas.biz.commen.commMethodMgr;
import com.saas.biz.interfaceMgr.*;
public class Buffers implements BufferIntf {
Buffer httpBuffer;
Buffer saasBuffer;
Logger log;
commMethodMgr comm;
public Buffers() {
httpBuffer = new Buffer();
saasBuffer = new Buffer();
log = new Logger(this);
comm = new commMethodMgr();
}
public void setHttpBuffer(Buffer buffer) {
this.httpBuffer = buffer;
}
public Buffer getHttpBuffer() {
return this.httpBuffer;
}
public Buffer convert(HttpServletRequest req, ActionForm form, HttpSession session) {
this.init(req);
this.setCommenFields(saasBuffer, this.httpBuffer);
this.setString("REALPATH", req.getRealPath(""));
for (Iterator it = saasBuffer.iterator(); it.hasNext();) {
HashMap map = (HashMap) it.next();
if (map.get("name") != null) {
// 从HttpServletRequest中获取字段内容
if (req.getParameter(map.get("name").toString().toLowerCase()) != null) {
this.addField(map.get("name").toString(), saasBuffer, this.httpBuffer);
this.setString(map.get("name").toString().toUpperCase(), req.getParameter(map.get("name").toString().toLowerCase()).toString());
}
// 从session中获取字段内容
if (session != null) {
if (session.getAttribute(map.get("name").toString()) != null) {
this.addField(map.get("name").toString(), saasBuffer, this.httpBuffer);
String strValue = (String) session.getAttribute(map.get("name").toString());
this.setString(map.get("name").toString().toUpperCase(), strValue);
}
}
// 从ActionForm中获取字段内容
try {
Method[] methods = form.getClass().getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().startsWith("get") && !methods[i].getName().equals("getMap") && !methods[i].getName().equals("getServletWrapper") && !methods[i].getName().equals("getLog") && !methods[i].getName().equals("getMultipartRequestHandler") && !methods[i].getName().equals("getClass")) {
String strField = "";
if (form.getClass().getDeclaredField(map.get("name").toString().toLowerCase()) != null) {
strField = form.getClass().getDeclaredField(map.get("name").toString().toLowerCase()).getName();
Object value = PropertyUtils.getProperty(form, strField);
if (map.get("name").toString().toUpperCase().equalsIgnoreCase(strField.toUpperCase())) {
if (value != null) {
this.addField(map.get("name").toString(), saasBuffer, this.httpBuffer);
this.setString(map.get("name").toString().toUpperCase(), value.toString());
}
}
}
if (form.getClass().getDeclaredField(map.get("name").toString().toLowerCase()) != null) {
if (form.getClass().getDeclaredField(map.get("name").toString().toLowerCase()).getType().getName() == "org.apache.struts.upload.FormFile") {
strField = form.getClass().getDeclaredField(map.get("name").toString().toLowerCase()).getName();
FormFile value = (FormFile) PropertyUtils.getProperty(form, strField);
if (value.getFileSize() > 0) {
String gen_id = comm.GenTradeId();
String filePathall = saveUploadFile(value, req, session, gen_id);
String basepath = req.getRealPath("");
String file_name = value.getFileName();
String filePath = filePathall;
try {
log.LOG_INFO("file_name===" + value.getFileName() + "|===>");
log.LOG_INFO("filePath===" + filePath + "|===>");
}
catch (Exception e) {
log.LOG_INFO("FormFormate::::" + e.getMessage());
}
this.setString("UPLOADFILEDIR", filePath);
this.setString("FILE_NAME", file_name);
this.setString(map.get("name").toString().toUpperCase(), value.toString());
log.LOG_INFO("FormFile::::" + value.toString());
}
else {
this.setString("UPLOADFILEDIR", "");
this.setString(map.get("name").toString().toUpperCase(), value.toString());
}
}
}
break;
}
}
}
catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
catch (NoSuchFieldException e) {
}
}
}
log.LOG_INFO("********本次业务提交初始化域字段列表开始************************");
list();
log.LOG_INFO("********本次业务提交初始化域字段列表结束************************");
return null;
}
public void clear() {
}
public void setString(String fields, String value) {
if (this.httpBuffer.isEmpty()) {
throw new RuntimeException(" in Buffer is Empty");
}
if (checkContainsKey(fields, this.httpBuffer) == 0)
this.addField(fields, saasBuffer, this.httpBuffer);
for (Iterator it = this.httpBuffer.iterator(); it.hasNext();) {
HashMap map = (HashMap) it.next();
if (map.get("name") != null) {
if (map.get("name").toString().toUpperCase().equalsIgnoreCase(fields.toUpperCase())) {
map.put("value", value);
break;
}
}
if (!it.hasNext()) {
throw new RuntimeException("[" + fields + "]域字段不存在,[setString]操作失败!");
}
}
}
public void setInt(String fields, int value) {
if (this.httpBuffer.isEmpty()) {
throw new RuntimeException("Buffer is Empty");
}
if (checkContainsKey(fields, this.httpBuffer) == 0)
this.addField(fields, saasBuffer, this.httpBuffer);
String strValue = String.valueOf(value);
for (Iterator it = this.httpBuffer.iterator(); it.hasNext();) {
HashMap map = (HashMap) it.next();
if (map.get("name") != null) {
if (map.get("name").toString().toUpperCase().equalsIgnoreCase(fields.toUpperCase())) {
map.put("value", strValue);
break;
}
}
if (!it.hasNext()) {
throw new RuntimeException("[" + fields + "]域字段不存在,[setInt]赋值操作失败!");
}
}
}
public String getString(String fields) {
if (this.httpBuffer.isEmpty()) {
throw new RuntimeException("缓存还没有初始化,[getString]操作失败!");
}
String str = "";
for (Iterator it = this.httpBuffer.iterator(); it.hasNext();) {
HashMap map = (HashMap) it.next();
if (map.get("name") != null) {
if (map.get("name").toString().toUpperCase().equalsIgnoreCase(fields.toUpperCase())) {
if (map.get("type").toString().equalsIgnoreCase("string")) {
if (map.get("value") != null) {
if (map.get("value").equals("")) {
str = "";
}
else {
str = map.get("value").toString();
}
}
}
else {
throw new RuntimeException("类型不匹配,字段[" + fields + "]不是字符串类型,[getString]操作失败!");
}
break;
}
}
if (!it.hasNext()) {
throw new RuntimeException("[" + fields + "]域字段不存在,[getString]操作失败!");
}
}
// return str;
return convetStrToDb(str);
// return str;
}
public String getStringWeb(String fields) {
if (this.httpBuffer.isEmpty()) {
throw new RuntimeException("缓存还没有初始化,[getString]操作失败!");
}
String str = "";
for (Iterator it = this.httpBuffer.iterator(); it.hasNext();) {
HashMap map = (HashMap) it.next();
if (map.get("name") != null) {
if (map.get("name").toString().toUpperCase().equalsIgnoreCase(fields.toUpperCase())) {
if (map.get("type").toString().trim().equalsIgnoreCase("string")) {
if (map.get("value") != null) {
if (map.get("value").equals("")) {
str = "";
}
else {
str = map.get("value").toString();
}
}
}
else {
throw new RuntimeException("类型不匹配,字段[" + fields + "]不是字符串类型,[getString]操作失败!");
}
break;
}
}
if (!it.hasNext()) {
throw new RuntimeException("[" + fields + "]域字段不存在,[getString]操作失败!");
}
}
return str;
}
public int getInt(String fields) {
if (this.httpBuffer.isEmpty()) {
throw new RuntimeException("缓存还没有初始化,[getInt]操作失败!");
}
String str = "";
for (Iterator it = this.httpBuffer.iterator(); it.hasNext();) {
HashMap map = (HashMap) it.next();
if (map.get("name") != null) {
if (map.get("name").toString().toUpperCase().equalsIgnoreCase(fields.toUpperCase())) {
if (map.get("type").toString().equalsIgnoreCase("int")) {
if (map.get("value") != null) {
if (map.get("value").equals("")) {
str = "0";
}
else {
str = map.get("value").toString();
}
}
}
else {
throw new RuntimeException("类型不匹配,字段[" + fields + "]不是字符串类型,[getInt]操作失败!");
}
break;
}
}
if (!it.hasNext()) {
throw new RuntimeException("[" + fields + "]域字段不存在,[getInt]操作失败!");
}
}
return new Integer(str).intValue();
}
public Buffer copyFrom(Buffer buffer) {
return null;
}
public void init(HttpServletRequest req) {
String basepath = req.getRealPath("");
Buffer saasBuffer = new Buffer();
String fieldspath = basepath + "/WEB-INF/saas.flds";
log.LOG_INFO(fieldspath);
try {
FileReader ffield = new FileReader(fieldspath);
BufferedReader fieldbuff = new BufferedReader(ffield);
String fieldline = fieldbuff.readLine();
while (fieldline != null) {
if (!fieldline.trim().equalsIgnoreCase("")) {
if (!fieldline.substring(0, 1).equalsIgnoreCase("#")) {
String[] fieldlinestr = fieldline.split(",");
HashMap map = new HashMap();
map.put("name", fieldlinestr[0].toUpperCase());
map.put("type", fieldlinestr[1]);
if (fieldlinestr[1].equalsIgnoreCase("string")) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -