use of org.axe.bean.mvc.FormParam in project Axe by DongyuCai.
the class HomeService method saveAxeProperties.
public String saveAxeProperties(Param param) {
URL resource = Thread.currentThread().getContextClassLoader().getResource(ConfigConstant.CONFIG_FILE);
File configFile = null;
if (resource != null) {
configFile = FileUtil.backupAndCreateNewFile(resource.getFile());
} else {
configFile = new File(Thread.currentThread().getContextClassLoader().getClass().getResource("/").getPath() + ConfigConstant.CONFIG_FILE);
}
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
//#保存需要保存的配置
for (List<FormParam> formParamList : param.getFieldMap().values()) {
String fieldName = null;
String fieldValue = null;
for (FormParam formParam : formParamList) {
fieldName = formParam.getFieldName();
if (StringUtil.isNotEmpty(formParam.getFieldValue()) && !"null".equalsIgnoreCase(formParam.getFieldValue())) {
fieldValue = fieldValue == null ? formParam.getFieldValue() : fieldValue + "," + formParam.getFieldValue();
}
}
if (StringUtil.isNotEmpty(fieldValue)) {
if (!fieldName.startsWith("NOSAVE.")) {
writer.write(fieldName + "=" + fieldValue);
writer.newLine();
}
}
}
//#登录ID和密码需要生成TOKEN后保存
List<FormParam> signIdList = param.getFieldMap().get(ConfigConstant.AXE_SIGN_IN);
if (CollectionUtil.isNotEmpty(signIdList)) {
if ("true".equalsIgnoreCase(signIdList.get(0).getFieldValue())) {
//#需要登录才保存
List<FormParam> idList = param.getFieldMap().get("NOSAVE.axe.signin.id");
String id = "";
if (CollectionUtil.isNotEmpty(idList)) {
id = idList.get(0).getFieldValue();
}
List<FormParam> passwordList = param.getFieldMap().get("NOSAVE.axe.signin.password");
String password = "";
if (CollectionUtil.isNotEmpty(passwordList)) {
password = passwordList.get(0).getFieldValue();
}
id = id == null ? "" : id;
password = password == null ? "" : password;
String fieldName = ConfigConstant.AXE_SIGN_IN_TOKEN;
String fieldValue = MD5Util.getMD5Code(id + ":" + password);
writer.write(fieldName + "=" + fieldValue);
writer.newLine();
}
}
writer.close();
} catch (Exception e) {
LOGGER.error("home error", e);
}
return configFile.getAbsolutePath();
}
use of org.axe.bean.mvc.FormParam in project Axe by DongyuCai.
the class FormRequestHelper method createParam.
/**
* 创建请求对象
*/
public static Param createParam(HttpServletRequest request, String requestPath, String mappingPath) {
List<FormParam> formParamList = new ArrayList<>();
List<FileParam> fileParamList = new ArrayList<>();
try {
//解析表单请求参数、文件
Map<String, List<FileItem>> fileItemListMap = servletFileUpload.parseParameterMap(request);
if (CollectionUtil.isNotEmpty(fileItemListMap)) {
for (Map.Entry<String, List<FileItem>> fileItemListEntry : fileItemListMap.entrySet()) {
String fieldName = fileItemListEntry.getKey();
List<FileItem> fileItemList = fileItemListEntry.getValue();
if (CollectionUtil.isNotEmpty(fileItemList)) {
for (FileItem fileItem : fileItemList) {
if (fileItem.isFormField()) {
String fieldValue = fileItem.getString("UTF-8");
formParamList.add(new FormParam(fieldName, fieldValue));
} else {
String fileName = FileUtil.getRealFileName(new String(fileItem.getName().getBytes(), "UTF-8"));
if (StringUtil.isNotEmpty(fileName)) {
long fileSize = fileItem.getSize();
String contentType = fileItem.getContentType();
InputStream inputStream = fileItem.getInputStream();
fileParamList.add(new FileParam(fieldName, fileName, fileSize, contentType, inputStream));
}
}
}
}
}
}
//解析url请求参数
formParamList.addAll(RequestUtil.parseParameter(request, requestPath, mappingPath));
} catch (Exception e) {
LOGGER.error("create param failed", e);
throw new RuntimeException(e);
}
return new Param(null, formParamList, fileParamList, null);
}
use of org.axe.bean.mvc.FormParam in project Axe by DongyuCai.
the class RequestUtil method parseParameter.
public static List<FormParam> parseParameter(HttpServletRequest request, String requestPath, String mappingPath) {
List<FormParam> formParamList = new ArrayList<>();
//分析url查询字符串
Enumeration<String> paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String fieldName = paramNames.nextElement();
String[] fieldValues = request.getParameterValues(fieldName);
if (ArrayUtil.isNotEmpty(fieldValues)) {
for (String fieldValue : fieldValues) {
formParamList.add(new FormParam(fieldName, fieldValue));
}
}
}
//分析url路径参数
//requestPath 客户端过来的servletPath
//action方法上的@Quest.value注解值
Pattern reg4requestPath = Pattern.compile(mappingPath.replaceAll("\\{[" + REG_WORD + "]*\\}", "([" + REG_WORD + "]*)"));
Matcher matcher4requestPath = reg4requestPath.matcher(requestPath);
Pattern reg4mappingPath = Pattern.compile("\\{([" + REG_WORD + "]*)\\}");
Matcher matcher4mappingPath = reg4mappingPath.matcher(mappingPath);
boolean fieldValueFind = matcher4requestPath.find();
for (int fieldValueGroupIndex = 1; matcher4mappingPath.find(); fieldValueGroupIndex++) {
String fieldName = matcher4mappingPath.group(1);
String fieldValue = null;
if (fieldValueFind && fieldValueGroupIndex <= matcher4requestPath.groupCount()) {
fieldValue = matcher4requestPath.group(fieldValueGroupIndex);
}
formParamList.add(new FormParam(fieldName, fieldValue));
}
return formParamList;
}
use of org.axe.bean.mvc.FormParam in project Axe by DongyuCai.
the class RequestUtil method getFormParamList.
/**
* List<?>、List<Object>、List<String>
* 三个参数形式,都是一样的取请求参数的逻辑
*/
public static List<String> getFormParamList(String fieldName, Map<String, List<FormParam>> fieldMap) {
List<String> parameterValue = null;
if (fieldMap.containsKey(fieldName)) {
List<FormParam> formParamList = fieldMap.get(fieldName);
List<String> list = new ArrayList<>();
if (formParamList != null) {
for (FormParam formParam : formParamList) {
list.add(formParam.getFieldValue());
}
}
parameterValue = list.size() > 0 ? list : null;
}
return parameterValue;
}
use of org.axe.bean.mvc.FormParam in project Axe by DongyuCai.
the class FormRequestHelper method initParam.
/**
* 创建请求对象
*/
public static void initParam(Param param, HttpServletRequest request, String requestPath, String mappingPath) {
List<FormParam> formParamList = new ArrayList<>();
List<FileParam> fileParamList = new ArrayList<>();
try {
//解析表单请求参数、文件
Map<String, List<FileItem>> fileItemListMap = servletFileUpload.parseParameterMap(request);
if (CollectionUtil.isNotEmpty(fileItemListMap)) {
for (Map.Entry<String, List<FileItem>> fileItemListEntry : fileItemListMap.entrySet()) {
String fieldName = fileItemListEntry.getKey();
List<FileItem> fileItemList = fileItemListEntry.getValue();
if (CollectionUtil.isNotEmpty(fileItemList)) {
for (FileItem fileItem : fileItemList) {
if (fileItem.isFormField()) {
String fieldValue = fileItem.getString("UTF-8");
formParamList.add(new FormParam(fieldName, fieldValue));
} else {
String fileName = FileUtil.getRealFileName(new String(fileItem.getName().getBytes(), "UTF-8"));
if (StringUtil.isNotEmpty(fileName)) {
long fileSize = fileItem.getSize();
String contentType = fileItem.getContentType();
InputStream inputStream = fileItem.getInputStream();
fileParamList.add(new FileParam(fieldName, fileName, fileSize, contentType, inputStream));
}
}
}
}
}
}
//解析url请求参数
formParamList.addAll(RequestUtil.parseParameter(request, requestPath, mappingPath));
} catch (Exception e) {
LOGGER.error("create param failed", e);
throw new RuntimeException(e);
}
param.init(null, formParamList, fileParamList, null);
}
Aggregations