114 lines
3.4 KiB
Java
114 lines
3.4 KiB
Java
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package com.ifish.util;
|
|
|
|
import com.ifish.enums.SubDirectoryEnum;
|
|
import java.io.InputStream;
|
|
import java.lang.reflect.Field;
|
|
import java.util.Properties;
|
|
|
|
/**
|
|
*
|
|
* @author Administrator
|
|
*/
|
|
public class IfishFilePath {
|
|
|
|
//头像地址
|
|
public static String path_img;
|
|
/**
|
|
* 图片头地址
|
|
*/
|
|
public static String link_img_head;
|
|
//商家图片地址
|
|
public static String path_shops;
|
|
//商品介绍图片
|
|
public static String path_commodity;
|
|
//微信分享页面
|
|
public static String path_share_html;
|
|
//微信分享页图片
|
|
public static String path_share_img;
|
|
//看护报告页面
|
|
public static String path_look_html;
|
|
//看护报告图片
|
|
public static String path_look_img;
|
|
//html名字
|
|
public static String html_name;
|
|
//图片上传格式
|
|
public static String check_style;
|
|
//云信爱鱼奇官方帐号
|
|
public static String ifish_account;
|
|
//IM官方手机号
|
|
public static String netease_phone;
|
|
//直播间封面
|
|
public static String path_room_img;
|
|
//FastDFS商家视频上传URL访问路径(本地和测试环境)
|
|
public static String fastDFS_url_local;
|
|
//FastDFS商家视频上传URL访问路径(正式环境)
|
|
public static String fastDFS_url_app;
|
|
//开发模式
|
|
public static boolean devModel;
|
|
//本机IP
|
|
public static String ifiship;
|
|
//本机端口
|
|
public static int ifishport;
|
|
|
|
static {
|
|
Properties prop = new Properties();
|
|
InputStream in = IfishFilePath.class.getResourceAsStream("/property.properties");
|
|
try {
|
|
prop.load(in);
|
|
//利用反射机制给属性赋值
|
|
Field[] fields = IfishFilePath.class.getDeclaredFields();
|
|
for (Field field : fields) {
|
|
String name = field.getName();
|
|
//获取property.properties的值
|
|
String value = prop.getProperty(name).trim();
|
|
//判断这个值希望塞入的变量类型,并进行转换
|
|
Object value1 = getValue(value, field);
|
|
//转换完成后塞入此变量
|
|
field.set(IfishFilePath.class, value1);
|
|
|
|
}
|
|
in.close();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 验证图片格式
|
|
*/
|
|
public static String checkImgName(String fileName) {
|
|
//对格式进行验证
|
|
int index = fileName.lastIndexOf(".");
|
|
String extEndName = fileName.substring(++index, fileName.length());
|
|
if (check_style.indexOf(extEndName.toUpperCase()) == -1) {
|
|
return null;
|
|
}
|
|
//返回格式.png
|
|
return "." + extEndName;
|
|
}
|
|
|
|
/**
|
|
* 获取图片链接地址
|
|
*
|
|
* @param type
|
|
* @return
|
|
*/
|
|
public static String getPath(SubDirectoryEnum pictureEnum, String fileName) {
|
|
return link_img_head + pictureEnum.getKey() + fileName;
|
|
}
|
|
|
|
private static Object getValue(String value, Field field) {
|
|
if (field.getType().equals(int.class)) {
|
|
return Integer.valueOf(value);
|
|
} else if (field.getType().equals(boolean.class)) {
|
|
return Boolean.valueOf(value);
|
|
}
|
|
return value;
|
|
}
|
|
}
|