|
@@ -1,8 +1,6 @@
|
|
package com.qmth.cqb.utils;
|
|
package com.qmth.cqb.utils;
|
|
|
|
|
|
-import java.io.BufferedReader;
|
|
|
|
-import java.io.InputStream;
|
|
|
|
-import java.io.InputStreamReader;
|
|
|
|
|
|
+import java.io.*;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
@@ -15,6 +13,7 @@ import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
import java.util.stream.Stream;
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
+import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
import org.apache.commons.lang3.StringEscapeUtils;
|
|
import org.apache.commons.lang3.StringEscapeUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.dom4j.Attribute;
|
|
import org.dom4j.Attribute;
|
|
@@ -24,6 +23,8 @@ import org.dom4j.DocumentHelper;
|
|
import org.dom4j.Element;
|
|
import org.dom4j.Element;
|
|
|
|
|
|
import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Created by songyue on 16/12/27.
|
|
* Created by songyue on 16/12/27.
|
|
@@ -39,6 +40,8 @@ public final class CommonUtils {
|
|
public static final String PAPER_TITLE="中国石油大学";
|
|
public static final String PAPER_TITLE="中国石油大学";
|
|
public static final String PAPER_SUB_TITLE="网络教育";
|
|
public static final String PAPER_SUB_TITLE="网络教育";
|
|
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(CommonUtils.class);
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 加载properties配置文件
|
|
* 加载properties配置文件
|
|
*
|
|
*
|
|
@@ -53,7 +56,7 @@ public final class CommonUtils {
|
|
BufferedReader bf = new BufferedReader(new InputStreamReader(inputStream));
|
|
BufferedReader bf = new BufferedReader(new InputStreamReader(inputStream));
|
|
properties.load(bf);
|
|
properties.load(bf);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ log.error("加载配置异常:",e.getMessage());
|
|
}
|
|
}
|
|
return properties;
|
|
return properties;
|
|
}
|
|
}
|
|
@@ -272,11 +275,22 @@ public final class CommonUtils {
|
|
return idValues;
|
|
return idValues;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 保留两位小数
|
|
|
|
+ * @param number
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
public static double formatDouble(double number){
|
|
public static double formatDouble(double number){
|
|
BigDecimal formatNumber = new BigDecimal(number);
|
|
BigDecimal formatNumber = new BigDecimal(number);
|
|
return formatNumber.setScale(2, RoundingMode.HALF_UP).doubleValue();
|
|
return formatNumber.setScale(2, RoundingMode.HALF_UP).doubleValue();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 补全html标签
|
|
|
|
+ * @param htmlStr
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
public static String repairHtmlStr(String htmlStr)throws Exception{
|
|
public static String repairHtmlStr(String htmlStr)throws Exception{
|
|
htmlStr = htmlStr.trim();
|
|
htmlStr = htmlStr.trim();
|
|
if(htmlStr.toLowerCase().contains("<!doctype html ")){
|
|
if(htmlStr.toLowerCase().contains("<!doctype html ")){
|
|
@@ -320,7 +334,8 @@ public final class CommonUtils {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//添加body标签
|
|
//添加body标签
|
|
- if(!htmlStr.toLowerCase().contains("<body")){
|
|
|
|
|
|
+ if((htmlStr.toLowerCase().contains("<p") || htmlStr.toLowerCase().contains("<span"))
|
|
|
|
+ && !htmlStr.toLowerCase().contains("<body")){
|
|
htmlStr = "<body>"+htmlStr+"</body>";
|
|
htmlStr = "<body>"+htmlStr+"</body>";
|
|
}
|
|
}
|
|
return new String(htmlStr.getBytes("UTF-8"));
|
|
return new String(htmlStr.getBytes("UTF-8"));
|
|
@@ -357,6 +372,12 @@ public final class CommonUtils {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 格式化html
|
|
|
|
+ * @param htmlStr
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
public static String formatHtml(String htmlStr)throws Exception{
|
|
public static String formatHtml(String htmlStr)throws Exception{
|
|
if(StringUtils.isEmpty(htmlStr)){
|
|
if(StringUtils.isEmpty(htmlStr)){
|
|
return "";
|
|
return "";
|
|
@@ -365,13 +386,23 @@ public final class CommonUtils {
|
|
htmlStr = StringEscapeUtils.unescapeHtml4(htmlStr);
|
|
htmlStr = StringEscapeUtils.unescapeHtml4(htmlStr);
|
|
return htmlStr;
|
|
return htmlStr;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 过滤非空格的空字符
|
|
|
|
+ * @param str
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static String trimNoBlankSpace(final String str){
|
|
|
|
+ if(str == null || str.length() == 0){
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+ return str.replaceAll("[\\t\\r\\f]*","");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) throws Exception{
|
|
// QuesStructType quesStructType = getEnum(QuesStructType.class,"单选");
|
|
// QuesStructType quesStructType = getEnum(QuesStructType.class,"单选");
|
|
// System.out.println(quesStructType.getName());
|
|
// System.out.println(quesStructType.getName());
|
|
// System.out.println(characterToNumber("A"));
|
|
// System.out.println(characterToNumber("A"));
|
|
- System.out.println(toCHNum(111111));
|
|
|
|
-
|
|
|
|
|
|
+ System.out.println("");
|
|
}
|
|
}
|
|
}
|
|
}
|