Commit 27a413c5 by s_guodong

整理pom

parent 60b399cd
......@@ -15,14 +15,11 @@
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.version>3.6.0</maven.compiler.version>
<maven.build.helper.version>1.4</maven.build.helper.version>
<maven-dependency-plugin.version>3.2.0</maven-dependency-plugin.version>
<xstream.version>1.4.5</xstream.version>
<dom4j.version>1.6.1</dom4j.version>
<mina.version>2.0.13</mina.version>
<io.version>2.4</io.version>
<javamail.version>1.8.3</javamail.version>
<jms.version>2.0.1</jms.version>
<jfreechart.version>1.0.17</jfreechart.version>
<beanutils.version>1.9.2</beanutils.version>
<elasticsearch.version>1.5.1</elasticsearch.version>
<lang.version>2.6</lang.version>
......@@ -38,28 +35,19 @@
<net.version>3.3</net.version>
<jsch.version>0.1.53</jsch.version>
<ibm.mq.allclient.version>9.1.5.0</ibm.mq.allclient.version>
<wss4j.version>1.6.11</wss4j.version>
<jetty.version>8.1.15.v20140411</jetty.version>
<rocketmq-client.version>4.4.0</rocketmq-client.version>
<ons-client.version>1.8.0.Final</ons-client.version>
<commons-httpclient.version>3.1</commons-httpclient.version>
<httpcore.version>4.2.4</httpcore.version>
<httpclient.version>4.2.5</httpclient.version>
<commons-modeler.version>2.0.1</commons-modeler.version>
<nekohtml.version>1.9.19</nekohtml.version>
<ant.version>1.9.2</ant.version>
<pw-swift-core.version>SRU2014-7.6</pw-swift-core.version>
<commons-jexl.version>2.1.1</commons-jexl.version>
<httpclient.version>4.5.11</httpclient.version>
<httpcore.version>4.4.13</httpcore.version>
<velocity.version>1.7</velocity.version>
<cxf.version>2.7.3</cxf.version>
<jsp-api.version>2.1</jsp-api.version>
<mail.version>1.4.7</mail.version>
<connector-api.version>1.5</connector-api.version>
<mybatis.version>3.3.1</mybatis.version>
<ojdbc6.version>12.1.0.2.0</ojdbc6.version>
<hutool.core.version>5.8.3</hutool.core.version>
<!--activemq-->
<spring.tx.version>5.3.21</spring.tx.version>
<spring.core.version>5.3.21</spring.core.version>
......@@ -68,9 +56,6 @@
<spring.jms.version>5.3.21</spring.jms.version>
<active.client.version>5.9.0</active.client.version>
<active.broker.version>5.9.0</active.broker.version>
<hawtbuf.version>1.11</hawtbuf.version>
<geronimo-j2ee-management_1.1_spec.version>1.0.1</geronimo-j2ee-management_1.1_spec.version>
<geronimo-jms_1.1_spec.version>1.1.1</geronimo-jms_1.1_spec.version>
<hessian.version>4.0.66</hessian.version>
<snmp4j.version>2.5.0</snmp4j.version>
<!-- 日志 -->
......@@ -79,6 +64,7 @@
<log4j2_version>2.16.0</log4j2_version>
<logback_version>1.2.11</logback_version>
<log4j_version>1.7.32</log4j_version>
<log4j.version>1.2.17</log4j.version>
</properties>
<dependencies>
......@@ -111,11 +97,6 @@
<version>${beanutils.version}</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${lang.version}</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${fileupload.version}</version>
......@@ -141,11 +122,6 @@
<version>${net.version}</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>${commons-httpclient.version}</version>
</dependency>
<dependency>
<groupId>commons-modeler</groupId>
<artifactId>commons-modeler</artifactId>
<version>${commons-modeler.version}</version>
......@@ -155,11 +131,6 @@
<artifactId>commons-jexl</artifactId>
<version>${commons-jexl.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.javamail</groupId>
<artifactId>geronimo-javamail_1.4_mail</artifactId>
<version>${javamail.version}</version>
</dependency>
<!--jms相关-->
<dependency>
<groupId>javax.jms</groupId>
......@@ -181,68 +152,11 @@
<artifactId>ons-client</artifactId>
<version>${ons-client.version}</version>
</dependency>
<!--activemq-->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>${active.client.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
<version>${active.broker.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.fusesource.hawtbuf</groupId>
<artifactId>hawtbuf</artifactId>
<version>${hawtbuf.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-j2ee-management_1.1_spec</artifactId>
<version>${geronimo-j2ee-management_1.1_spec.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
<version>${geronimo-jms_1.1_spec.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.tx.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.jms.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.context.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.core.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.beans.version}</version>
</dependency>
<!--图表-->
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>${jfreechart.version}</version>
</dependency>
<!--es-->
<dependency>
<groupId>org.elasticsearch</groupId>
......@@ -300,11 +214,6 @@
<artifactId>cxf-bundle</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>${wss4j.version}</version>
</dependency>
<!--httpServer中-->
<dependency>
<groupId>org.eclipse.jetty</groupId>
......@@ -328,12 +237,6 @@
<artifactId>ant</artifactId>
<version>${ant.version}</version>
</dependency>
<!--swift相关-->
<dependency>
<groupId>com.prowidesoftware</groupId>
<artifactId>pw-swift-core</artifactId>
<version>${pw-swift-core.version}</version>
</dependency>
<!--通信相关-->
<!--ssh-->
<dependency>
......@@ -342,16 +245,6 @@
<version>${jsch.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>${httpcore.version}</version>
</dependency>
<dependency>
<groupId>javax.resource</groupId>
<artifactId>connector-api</artifactId>
<version>${connector-api.version}</version>
......@@ -371,12 +264,6 @@
<artifactId>snmp4j-agent</artifactId>
<version>${snmp4j.version}</version>
</dependency>
<!--插件httpConnectionBetter使用-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-core</artifactId>
<version>${hutool.core.version}</version>
</dependency>
<!--模板引擎-->
<dependency>
<groupId>org.apache.velocity</groupId>
......@@ -410,48 +297,40 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${log4j_version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>provided</scope>
<version>${log4j.version}</version>
</dependency>
<!-- log4j2 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2_version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2_version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2_version}</version>
<scope>provided</scope>
</dependency>
<!-- logback-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback_version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback_version}</version>
<scope>provided</scope>
</dependency>
<!--本地依赖-->
<dependency>
<groupId>com.swetake</groupId>
......@@ -468,13 +347,6 @@
<systemPath>${pom.basedir}/lib/PKIBASE_JDK16_20140820.jar</systemPath>
</dependency>
<dependency>
<groupId>com.cfca</groupId>
<artifactId>CFCACertKitJS</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/lib/CFCACertKitJS.jar</systemPath>
</dependency>
<dependency>
<groupId>org.keyczar</groupId>
<artifactId>keyczar</artifactId>
<version>0.71g</version>
......@@ -501,36 +373,11 @@
<compilerArguments>
<bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath>
</compilerArguments>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<!-- 复制依赖 -->
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- 排除 junit, 只包含runtime and compile(默认不配scope是compile) dependencies -->
<includeScope>runtime</includeScope>
<!-- 依赖包 输出目录 -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<!-- 是否不包含间接依赖的包 -->
<excludeTransitive>false</excludeTransitive>
<!-- 复制的jar文件去掉版本信息 -->
<stripVersion>false</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${maven.build.helper.version}</version>
......
package com.brilliance.eibs.el;
import com.brilliance.eibs.coder.impl.Base64Coder;
import com.brilliance.eibs.coder.impl.MDCoder;
import com.brilliance.eibs.core.exception.InterfaceException;
import com.brilliance.eibs.core.frame.ISocketProxy;
import com.brilliance.eibs.core.model.converter.BeBean2Xml;
import com.brilliance.eibs.core.model.impl.InterfaceDef;
import com.brilliance.eibs.factory.parser.ParserFactory;
import com.brilliance.eibs.factory.parser.ParserFactory.ParserName;
import com.brilliance.eibs.factory.parser.impl.XmlParser;
import com.brilliance.eibs.server.terminal.api.TerminalAPI;
import com.brilliance.eibs.swift.MessageReader;
import com.brilliance.eibs.util.*;
import com.google.gson.Gson;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import org.keyczar.exceptions.KeyczarException;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.XMLGregorianCalendar;
import java.io.*;
import java.math.BigDecimal;
import java.net.*;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CommonFunctionUtils {
public static String defaultFormate = "yyyy-MM-dd HH:mm:ss,SSS"; // 默认的日期格式
static final DecimalFormat format8 = new DecimalFormat("00000000");
static final DecimalFormat format6 = new DecimalFormat("00.0000");
static boolean emptyAsBlank = false;
static boolean emptyAsNull = true;
/***
**************** 定义ArrayUtil类中的函数*********************
**/
public static boolean isArray(Object object) {
return ArrayUtil.isArray(object);
}
public static boolean isPrimitiveArray(Object object) {
return ArrayUtil.isPrimitiveArray(object);
}
public static byte[] byteMerger(byte[] byte_1, byte[] byte_2) {
byte[] byte_3 = new byte[byte_1.length + byte_2.length];
System.arraycopy(byte_1, 0, byte_3, 0, byte_1.length);
System.arraycopy(byte_2, 0, byte_3, byte_1.length, byte_2.length);
return byte_3;
}
/***
**************** 定义ByteUtil类中的函数*********************
**/
/**
* 此方法存在缺陷,慎用
*
* @param bytes
* @param offset
* @param n
* @return
*/
@Deprecated
public static int bytes2int(byte[] bytes, int offset, int n) {
return ByteUtil.bytes2int(bytes, offset, n);
}
public static int bytesToInt(byte[] bytes) {
return ByteUtil.bytesToInt(bytes);
}
public static int bytesToIntC(byte[] bytes) {
return ByteUtil.bytesToIntC(bytes);
}
public static int byteToShort(byte[] b) {
return ByteUtil.byteToShort(b);
}
public static int byteToShortC(byte[] b) {
return ByteUtil.byteToShortC(b);
}
public static byte[] int2bytes(int i, int n) {
return ByteUtil.int2bytes(i, n);
}
public static byte[] intToBytes(int i) {
return ByteUtil.intToBytes(i);
}
public static byte[] intToBytesC(int i) {
return ByteUtil.intToBytesC(i);
}
public static String parseByte2HexStr(byte buf[]) {
return ByteUtil.parseByte2HexStr(buf);
}
public static String caculateMd5(String filepath) {
FileInputStream fis = null;
try {
fis = new FileInputStream(filepath);
return MDCoder.encodeMD5Hex(IOUtils.toByteArray(fis));
} catch (IOException e) {
return null;
} finally {
IOUtils.closeQuietly(fis);
}
}
public static byte[] parseHexStr2Byte(String hexStr) {
return ByteUtil.parseHexStr2Byte(hexStr);
}
public static byte[] shortToByte(int number) {
return ByteUtil.shortToByte(number);
}
public static byte[] shortToByteC(int number) {
return ByteUtil.shortToByteC(number);
}
public static byte[] decryptBASE64(String key) throws Exception {
return CipherUtil.decryptBASE64(key);
}
public static String decryptStr(String strMi, Key key) {
return CipherUtil.decryptStr(strMi, key);
}
public static String encryptBASE64(byte[] key) throws Exception {
return CipherUtil.encryptBASE64(key);
}
public static String encryptcommonBASE64(byte[] key) throws Exception {
return CipherUtil.encryptcommonBASE64(key);
}
public static byte[] decodeBase64(String data)
throws UnsupportedEncodingException {
return Base64Coder.decodeBase64(data);
}
public static byte[] encryptHMAC(byte[] data, String key) throws Exception {
return CipherUtil.encryptHMAC(data, key);
}
public static byte[] encryptMD5(byte[] data) throws Exception {
return CipherUtil.encryptMD5(data);
}
public static String encryptMD5(String inStr) throws Exception {
return CipherUtil.encryptMD5(inStr);
}
public static byte[] encryptSHA(byte[] data) throws Exception {
return CipherUtil.encryptSHA(data);
}
public static byte[] encryptSHA1(String data) throws Exception {
return CipherUtil.encryptSHA1(data);
}
public static String encryptStr(String strMing, Key key) {
return CipherUtil.encryptStr(strMing, key);
}
public static String initMacKey() throws Exception {
return CipherUtil.initMacKey();
}
public static Key setKey(String strKey) {
return CipherUtil.setKey(strKey);
}
public static void zipFile(String sourceDirectory, String zipFile,
boolean pathStyle) throws IOException {
CompressUtil.zipFile(sourceDirectory, zipFile, pathStyle);
}
public static void zipFile(String[] paths, String zipFile)
throws IOException {
CompressUtil.zipFile(paths, zipFile, true);
}
public static void zipFile(String sourceDirectory, String zipFile,
boolean pathStyle, boolean iscontaincurrent) throws IOException {
CompressUtil.zipFile(sourceDirectory, zipFile, pathStyle,
iscontaincurrent);
}
public static void tarFile(String sourceDirectory, String tarFile,
boolean pathStyle) throws IOException {
CompressUtil.tarFile(sourceDirectory, tarFile, pathStyle);
}
public static void tarFile(String sourceDirectory, String tarFile,
boolean pathStyle, boolean iscontainCurrent) throws IOException {
CompressUtil.tarFile(sourceDirectory, tarFile, pathStyle,
iscontainCurrent);
}
public static void unzipFile(String zipFileName, String targetDirectory)
throws IOException {
CompressUtil.unzipFile(zipFileName, targetDirectory);
}
public static void untarFile(String tarFileName, String targetDirectory)
throws IOException {
CompressUtil.untarFile(tarFileName, targetDirectory);
}
public static void untarFile(String tarFileName, String targetDirectory,
String case_convert) throws IOException {
CompressUtil.untarFile(tarFileName, targetDirectory, case_convert);
}
public static Date parseDate(Date date, String parsePattern)
throws ParseException {
return DateUtil.parseDate(date, parsePattern);
}
public static int compareDate(Date firstDate, Date secondDate) {
return DateUtil.compareDate(firstDate, secondDate);
}
public static final Date dateAdd(Date paramDate, int paramInt1,
int paramInt2) {
return DateUtil.dateAdd(paramDate, paramInt1, paramInt2);
}
public static int getDayOfWeek(String year, String month, String day) {
return DateUtil.getDayOfWeek(year, month, day);
}
public static String formatNow() {
return DateUtil.formatNow();
}
public static String formatNow(String pattern) {
return DateUtil.formatNow(pattern);
}
public static String format(Date date) {
return DateUtil.format(date);
}
public static String format(Date date, String pattern) {
return DateUtil.format(date, pattern);
}
public static String format(XMLGregorianCalendar xgc, String pattern) {
return DateUtil.format(xgc, pattern);
}
public static XMLGregorianCalendar parseXMLGregorianCalendar(String time,
String pattern) throws ParseException,
DatatypeConfigurationException {
return DateUtil.parseXMLGregorianCalendar(time, pattern);
}
public static XMLGregorianCalendar parseXMLGregorianCalendar(Date date)
throws ParseException, DatatypeConfigurationException {
return DateUtil.parseXMLGregorianCalendar(date);
}
public static XMLGregorianCalendar parseXMLGregorianCalendar(String time) {
return DateUtil.parseXMLGregorianCalendar(time);
}
public static Date parseDate(XMLGregorianCalendar xgc) {
return DateUtil.parseDate(xgc);
}
public static Date formatAndParseDate(Date date, String pattern)
throws ParseException {
return DateUtil.formatAndParseDate(date, pattern);
}
public static String parseAndFormatDate(String date, String parsePattern,
String formatPattern) throws ParseException {
return DateUtil.parseAndFormatDate(date, parsePattern, formatPattern);
}
public static final Timestamp time2(String paramString1, String paramString2)
throws ParseException {
return DateUtil.time2(paramString1, paramString2);
}
@Deprecated
public static final String decodeAES(byte[] paramArrayOfByte,
String paramString1, String paramString2)
throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException,
BadPaddingException, IOException {
return EncryptUtils.decodeAES(paramArrayOfByte, paramString1,
paramString2);
}
@Deprecated
public static final String decodeAES(String paramString)
throws KeyczarException {
return EncryptUtils.decodeAES(paramString);
}
@Deprecated
public static final String decodeDES(byte[] paramArrayOfByte,
String paramString1, String paramString2)
throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException,
BadPaddingException, IOException {
return EncryptUtils.decodeDES(paramArrayOfByte, paramString1,
paramString2);
}
@Deprecated
public static final String encodeAES(String paramString)
throws KeyczarException {
return EncryptUtils.encodeAES(paramString);
}
@Deprecated
public static final String encodeDES(byte[] paramArrayOfByte,
String paramString1, String paramString2)
throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException,
BadPaddingException, IOException {
return EncryptUtils.encodeDES(paramArrayOfByte, paramString1,
paramString2);
}
public static boolean copyFile(String resFilePath, String distFolder) {
return FileUtil.copyFile(resFilePath, distFolder);
}
public static boolean deleteFile(String targetPath) {
return FileUtil.deleteFile(targetPath);
}
public static File[] fileLastModifiedSort(String directory) {
return FileUtil.fileLastModifiedSort(directory);
}
public static List<String> getFileNamesByRegex(String path, String regex) {
return FileUtil.getFileNamesByRegex(path, regex);
}
public static String html2Xml(String htmlStr) {
return HtmlUtil.html2Xml(htmlStr);
}
// 前补零八位字符串,参数为Number(待转换数值)
public static final String str8(Number paramNumber) {
return format8.format(paramNumber);
}
// str8前补零八位字符串,参数为Number(待转换数值)
public static final String str(Number paramNumber, String paramString) {
return new DecimalFormat(paramString).format(paramNumber);
}
// 合并字符串(含trim),参数为两字符串
public static final String cat(String paramString1, String paramString2) {
if (paramString1 == null)
return paramString2.trim();
if (paramString2 == null)
return paramString1.trim();
return paramString1.trim() + paramString2.trim();
}
// 合并字符串(含trim及之间加换行),参数为两字符串
public static final String cat1(String paramString1, String paramString2) {
if (paramString1 == null)
return "\r" + paramString2.trim();
if (paramString2 == null)
return paramString1.trim() + "\r";
return paramString1.trim() + "\r" + paramString2.trim();
}
// 去除空格,参数为字符串
public static final String trim(String paramString)
throws UnsupportedEncodingException {
if (paramString != null)
paramString = paramString.trim();
if ("".equals(paramString))
return emptyAsNull ? null : emptyAsBlank ? " " : paramString;
return paramString;
}
// 由A码转为B码后去除空格,参数为字符串,源码制,转码制
public static final String trim4(String paramString1, String paramString2,
String paramString3) throws UnsupportedEncodingException {
if (paramString1 != null)
if ((paramString2 == null) || ("".equals(paramString2)))
paramString1 = new String(paramString1.getBytes(paramString3),
paramString3);
else
paramString1 = new String(paramString1.getBytes(paramString2),
paramString3);
return trim(paramString1);
}
/**
* 获取长度
**/
public static final int length(String paramString)
throws UnsupportedEncodingException {
if (paramString == null)
return 0;
return paramString.trim().getBytes("UTF-8").length;
}
/**
* 获取长度
**/
public static final int length(String paramString, String encode)
throws UnsupportedEncodingException {
if (paramString == null)
return 0;
return paramString.trim().getBytes(encode).length;
}
/**
* 获取大小
*
* @throws UnsupportedEncodingException
**/
public static final int size1(Object obj)
throws UnsupportedEncodingException {
if (obj == null)
return 0;
if (obj instanceof byte[]) {
return ((byte[]) obj).length;
} else if (obj instanceof Map) {
return ((Map) obj).size();
} else if (obj instanceof List) {
return ((List) obj).size();
} else if (obj instanceof String) {
// TODO
return ((String) obj).getBytes("utf-8").length;
}
return 0;
}
/**
* 根据字符集获取大小
*
* @throws UnsupportedEncodingException
**/
public static final int size2(Object obj, String encoding)
throws UnsupportedEncodingException {
if (obj == null)
return 0;
if (obj instanceof byte[]) {
return ((byte[]) obj).length;
} else if (obj instanceof Map) {
return ((Map) obj).size();
} else if (obj instanceof List) {
return ((List) obj).size();
} else if (obj instanceof String) {
// TODO
return ((String) obj).getBytes(encoding).length;
}
return 0;
}
/**
* 字符串截取
**/
public static final String substr(String paramString, int paramInt1,
int paramInt2) {
if (paramString == null)
return null;
int i = paramString.length();
if (paramInt1 > i)
return null;
if ((paramInt2 > i) || (paramInt1 >= paramInt2))
return paramString.substring(paramInt1);
return paramString.substring(paramInt1, paramInt2);
}
public static final String substr1(String paramString, int paramInt) {
return substr(paramString, paramInt, -1);
}
/**
* 字符串转数值型,参数为字符串
**/
public static final Number number1(String paramString)
throws ParseException {
return number2(paramString, "#,##0.##");
}
/**
* 按格式字符串转数值型,参数为字符串,字符串
**/
public static final Number number2(String paramString1, String paramString2)
throws ParseException {
if (StringUtil.isEmpty(paramString1))
return null;
return new DecimalFormat(paramString2).parse(paramString1);
}
/**
* 字符串转化为Date类型
*
* @param date
* 日期字符串
* @param parsePattern
* 日期格式
* @return
* @throws ParseException
*/
public static Date parseDate(String date, String parsePattern)
throws ParseException {
return DateUtils.parseDate(date, new String[] { parsePattern });
}
public static double accurateDivide(double dividend, double divisor,
int digits) {
return NumberUtil.accurateDivide(dividend, divisor, digits);
}
public static String accurateDivide(String dividend, String divisor,
int digits) {
return NumberUtil.accurateDivide(dividend, divisor, digits);
}
public static String decimalFormat(String decimal) {
return NumberUtil.decimalFormat(decimal);
}
public static String decimalFormat(Object decimal, int num) {
return NumberUtil.decimalFormat(decimal, num);
}
public static String formatAmt(String amt, int dot) {
return NumberUtil.formatAmt(amt, dot);
}
public static int getMax(int[] values) {
return NumberUtil.getMax(values);
}
public static double round(double v, int scale) {
return NumberUtil.round(v, scale);
}
public static String getPropertyValue(String propertyFile,
String propertyName) {
return PropertyUtil.getPropertyValue(propertyFile, propertyName);
}
public static Properties getProperties(String propertyFile, String encoding)
throws IOException {
return PropertyUtil.getProperties(propertyFile, encoding);
}
public static String processTemplate(String template,
Map<String, Object> params) {
if (template == null || params == null)
return null;
StringBuffer sb = new StringBuffer();
Matcher m = Pattern.compile("\\$\\{\\w+\\}").matcher(template);
while (m.find()) {
String param = m.group();
Object value = params.get(param.substring(2, param.length() - 1));
m.appendReplacement(sb, value == null ? "" : value.toString());
}
m.appendTail(sb);
return sb.toString();
}
public synchronized static boolean setPropertyValue(String propertyFile,
String propertyName, String propertyValue) {
return PropertyUtil.setPropertyValue(propertyFile, propertyName,
propertyValue);
}
public static String bytesToString(byte[] bytes, String encoding)
throws UnsupportedEncodingException {
return StringUtil.bytesToString(bytes);
}
public static String fillWithChar(Object obj, String chars, String direct,
int totalLen) {
return StringUtil.fillWithChar(obj, chars, direct, totalLen);
}
public static String formatDouble(double db) {
return StringUtil.formatDouble(db);
}
public static String formatDouble(double db, String pattern) {
return StringUtil.formatDouble(db, pattern);
}
public static byte[] getBytes(String srcStr, String encoding)
throws UnsupportedEncodingException {
return StringUtil.getBytes(srcStr, encoding);
}
public static boolean isEmpty(String content) {
return StringUtil.isEmpty(content);
}
public static List<String> match(String pattern, String target) {
return StringUtil.match(pattern, target);
}
public static String[] split(String regex, String s) {
return StringUtil.split(regex, s);
}
public static String toHexString(String s) {
return StringUtil.toHexString(s);
}
/**
* 返回数组或队列的长度
*
* @param obj
* @return
*/
public static int getArrayLen(Object obj) {
if (obj instanceof Object[]) {
return ((Object[]) obj).length;
} else if (obj instanceof List) {
return ((List<?>) obj).size();
}
return 0;
}
public static void touch(Object obj) throws IOException {
if (obj instanceof String)
FileUtils.touch(new File((String) obj));
else if (obj instanceof File)
FileUtils.touch((File) obj);
}
/***
* @param flg
* ="path" 获取文件路径;flg="name" 获取文件名;flg="file" 返回文件对象
*
**/
public static void listFiles(String root, List<Object> listFiles, String flg) {
File file = new File(root);
File[] subFile = file.listFiles();
for (int i = 0; i < subFile.length; i++) {
if (subFile[i].isDirectory()) {
listFiles(subFile[i].getAbsolutePath(), listFiles, flg);
} else {
String filename = subFile[i].getName();
String path = subFile[i].getPath();
if (flg.equals("name"))
listFiles.add(filename);
else if (flg.equals("path"))
listFiles.add(path);
else if (flg.equals("file"))
listFiles.add(subFile[i]);
}
}
}
public static void sleep(long time) throws InterruptedException {
Thread.sleep(time);
}
public static void close() throws InterruptedException {
Thread.currentThread().interrupt();
}
public synchronized static void addSocketProxy(String key,
ISocketProxy socketProxy) {
SocketManagerFactoryUtil.addSocketProxy(key, socketProxy);
}
public static ISocketProxy getSocketProxyofManager(String key) {
return SocketManagerFactoryUtil.getSocketProxyofManager(key);
}
public static Map<String, ISocketProxy> getSocketProxyMap()
throws IOException {
return SocketManagerFactoryUtil.getSocketProxyMap();
}
public synchronized static void removeProxy(String key) {
SocketManagerFactoryUtil.removeProxy(key);
}
public static boolean existProxy(String key) {
return SocketManagerFactoryUtil.existProxy(key);
}
public static boolean isalive(String key) {
return SocketManagerFactoryUtil.isalive(key);
}
public static final void unloadExcel(List paramList, String pathname,
boolean paramBoolean) throws FileNotFoundException {
ExcelUtil.unloadExcel(paramList, pathname, paramBoolean);
}
public static Date now() {
return new Date();
}
public static Date now(String pattern) throws ParseException {
DateFormat df = new SimpleDateFormat(pattern);
return parseDate(df.format(new Date()), pattern);
}
public static String getRootPath() {
URL url = Thread.currentThread().getContextClassLoader()
.getResource("");
if (url == null)
url = CommonFunctionUtils.class.getClassLoader().getResource("");
String path = url.getPath();
return path;
}
public static String toJson(Object obj) {
return new Gson().toJson(obj);
}
public static Object fromJson(String json, String jsontype) {
Class<?> beantype = null;
if (json.startsWith("[") || jsontype.equals("list"))
beantype = List.class;
else if (jsontype.equals("map"))
beantype = HashMap.class;
else {
try {
beantype = Class.forName(jsontype);
} catch (ClassNotFoundException e) {
new InterfaceException("01302", e.getMessage());
}
}
return new Gson().fromJson(json, beantype);
}
/** 该函数暂时不要删除,特殊场景需要用到 **/
public static boolean isFlag(byte[] bitmap) {
byte b = bitmap[0];
String s = ByteUtil.byte2bits(b);
if (s.startsWith("1")) {
return true;
}
return false;
}
public static Class getClass(String classname)
throws ClassNotFoundException {
return Class.forName(classname);
}
/** 洛阳银行使用函数,不要删除 **/
public static boolean fileupname(String path) {
boolean rename = false;
File f = new File(path);
if (!f.exists()) {
return rename;
}
File[] fs = f.listFiles();
for (File ff : fs) {
if (ff.isFile()) {
ff.renameTo(new File(ff.getParent() + File.separator
+ ff.getName().toUpperCase()));
} else if (ff.isDirectory()) {
fileupname(path + File.separator + ff.getName());
}
}
f.renameTo(new File(f.getParent() + File.separator
+ f.getName().toUpperCase()));
rename = true;
return rename;
}
/** 洛阳银行使用函数,不要删除 **/
public static boolean filelowname(String path) {
boolean rename = false;
File f = new File(path);
if (!f.exists()) {
return rename;
}
File[] fs = f.listFiles();
for (File ff : fs) {
if (ff.isFile()) {
ff.renameTo(new File(ff.getParent() + File.separator
+ ff.getName().toLowerCase()));
} else if (ff.isDirectory()) {
filelowname(path + File.separator + ff.getName());
}
}
f.renameTo(new File(f.getParent() + File.separator
+ f.getName().toLowerCase()));
rename = true;
return rename;
}
public static String fmtToswift(String fmt) throws FileNotFoundException,
IOException {
return MessageReader.fmtToswift(fmt);
}
public static String bytes2Str(byte[] buffer, String encoding)
throws UnsupportedEncodingException {
return ByteUtil.bytes2Str(buffer, encoding);
}
public static String bytes2Str(byte[] buffer)
throws UnsupportedEncodingException {
return ByteUtil.bytes2Str(buffer);
}
public static String findBic(String s, String sep) {
return find(s, "(?<=\\s|:)\\p{Upper}{6}\\p{Alnum}{5}(?=$|\\s|-)", sep);
}
public static String find(String s, String pattern, String sep) {
String result = "";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(s);
int idx = 0;
while (m.find()) {
if (idx != 0)
result += sep;
result += m.group();
idx++;
}
return result;
}
public static String catLine(Object... obj) {
String str = "";
for (int i = 0; i < obj.length; i++) {
if (i > 0) {
str = str + "\r\n" + obj[i];
}
if (i == 0)
str += obj[i];
}
return str;
}
public static Map<String, String> splitTagValue(String message) {
return MessageReader.splitTagValue(message);
}
public static List<List<Map<String, String>>> splitDtl(String val,
String fmttype, String inipth) throws IOException {
return MessageReader.splitDtl(val, fmttype, inipth);
}
public static String getenv(String name) {
return System.getenv(name);
}
/**
* @param year
* @param month
* @param day
* @return boolean 是否为星期六或者星期天
**/
public static boolean isWeekend(String year, String month, String day) {
boolean isWeekend = false;
int a = StringUtil.getDayOfWeek(year, month, day);
if (a == 1 || a == 7) {
isWeekend = true;
}
return isWeekend;
}
public static String formatMinutesLater(String pattern, int min) {
return DateUtil.formatMinutesLater(pattern, min);
}
/**
* 会死循环,不建议使用
*
* @param source
* 原始字符串
* @param maxByteLen
* 字符编码
* @param maxByteLen
* 最大截取长度
* @param flag
* 表示处理汉字的方式。1表示遇到半个汉字时补全,-1表示遇到半个汉字时舍弃
**/
@Deprecated
public static String str4(String source, String encode, int maxByteLen,
int flag) throws UnsupportedEncodingException {
List<String> list = new ArrayList<String>();
do {
String retstr = "";
retstr = leftStr(source, encode, maxByteLen, flag);
list.add(retstr);
source = source.substring(retstr.length());
if (StringUtil.isEmpty(source)) {
break;
}
source = "//" + source;
} while (source.getBytes(encode).length > 0);
System.out.println(list);
return CommonFunctionUtils.catLine(list.toArray());
}
/**
* @param source
* 原始字符串
* @param maxByteLen
* 截取的字节数
* @param flag
* 表示处理汉字的方式。1表示遇到半个汉字时补全,-1表示遇到半个汉字时舍弃
* @return 截取后的字符串
* @throws UnsupportedEncodingException
**/
public static String leftStr(String source, String encode, int maxByteLen,
int flag) throws UnsupportedEncodingException {
if (source == null || maxByteLen <= 0) {
return "";
}
byte[] bStr = source.getBytes(encode);
if (maxByteLen >= bStr.length)
return source;
String cStr = new String(bStr, maxByteLen - 1, 2, encode);
if (cStr.length() == 1 && source.contains(cStr)) {
maxByteLen += flag;
}
return new String(bStr, 0, maxByteLen, encode);
}
/**
* 判断给定路径下的文件是否存在
*
* @return 存在返回文件路径,否则返回空
*/
public static String getFilePath(String filepth) {
File f = null;
try {
f = new File(getCommonURL(filepth).toURI());
} catch (URISyntaxException e) {
return null;
}
return f == null ? null : f.exists() ? f.getPath() : null;
}
public static URL getCommonURL(String relativePath) {
URL url = Thread.currentThread().getContextClassLoader()
.getResource(relativePath);
if (url == null) {
// System.out.println("URL1 is NULL");
url = CommonFunctionUtils.class.getClassLoader().getResource(
relativePath);
// System.out.println("URL2 is NULL");
if (url == null) {
url = CommonFunctionUtils.class.getClassLoader()
.getResource("");
try {
return new URL(url + relativePath);
// System.out.println(url == null ? "FileURL is NULL" :
// "FileURL is Not NULL");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return url;
/*
* URL url
* =CommonFunctionUtils.class.getClassLoader().getResource(relativePath
* );
*/
}
/******************* Socket 终端API 注册 **************************/
public static boolean terminalIsConnected(String name) {
return TerminalAPI.isConnected(name);
}
public static boolean terminalSend(String name, byte[] b) {
return TerminalAPI.send(name, b);
}
// 解析GTP使用的映射
private static String[][] unpackRuleMappings = new String[][] {
{ "\\\\\\\\", "__backslash__", "\\\\" },
{ "\\\\=", "__equal__", "=" },
{ "\\\\\\[", "__leftbracket__", "[" },
{ "\\\\]", "__rightbracket__", "]" },
{ "\\\\\\{", "__leftbrace__", "{" },
{ "\\\\}", "__rightbrace__", "}" }, { "\\\\,", "__comma__", "," } };
// 组装GTP使用的映射
private static String[][] packRuleMappings = new String[][] {
{ "\\\\", "\\\\\\\\" }, { "=", "\\\\=" }, { "\\[", "\\\\[" },
{ "]", "\\\\]" }, { "\\{", "\\\\{" }, { "}", "\\\\}" },
{ ",", "\\\\," } };
public static Map gtpToMap(String str) {
// 转化前替换value中的关键字符
for (String[] mapping : unpackRuleMappings) {
str = str.replaceAll(mapping[0], mapping[1]);
}
// 转化为JSON格式字符串
// str = str.replaceAll("(\\w+)\\s*=\\s*([^\\s,\\[\\]\\{\\}]+)",
// "\"$1\":\"$2\"");
str = str.replaceAll("([A-Z]\\d{2})\\s*=", "\"$1\":\""); // 处理 域号= 为
// "域号":
str = str.replaceAll("(?<=:\\s{0,100})\"(?=\\[)", ""); // 去除[ 之前的 ",
str = str.replaceAll("(?<!(\\]|\\}))\\s*,", "\","); // 处理 : 之后的 , 为 ",
str = str.replaceAll("(?<!(\\\"|\\]))\\}\\s*(?=(,|\\]))", "\"}"); // 补充
// ,
str = str.replaceAll("(?<!\\])$", "\"");
str = "{" + str + "}";
// 转化后换回value中的关键字符
for (String[] mapping : unpackRuleMappings) {
str = str.replaceAll(mapping[1], mapping[2]);
}
return new Gson().fromJson(str, LinkedHashMap.class);
}
/**
* Map转化为GTP格式字符串
*
* @param map
* @return
*/
public static String mapToGtp(Map map) {
Iterator<String> it = map.keySet().iterator();
StringBuffer sb = new StringBuffer("{");
while (it.hasNext()) {
String key = it.next();
Object objValue = map.get(key);
if (objValue == null) {
sb.append(key + "=" + "null").append(",");
} else if (objValue instanceof Map) {
sb.append(mapToGtp((Map) objValue)).append(",");
} else if (objValue instanceof List) {
sb.append(listToGtp((List) objValue)).append(",");
} else {
String str = objValue.toString();
for (String[] mapping : packRuleMappings) {
str = str.replaceAll(mapping[0], mapping[1]);
}
sb.append(key + "=" + str).append(",");
}
}
return StringUtils.chomp(sb.toString(), ",") + "]";
}
/**
* List类型转化为GTP格式字符串
*
* @param list
* @return
*/
private static String listToGtp(List list) {
int size = list.size();
StringBuffer sb = new StringBuffer("[");
for (int i = 0; i < size; i++) {
Object objValue = list.get(i);
if (objValue == null) {
sb.append("null").append(",");
} else if (objValue instanceof Map) {
sb.append(mapToGtp((Map) objValue)).append(",");
} else if (objValue instanceof List) {
sb.append(listToGtp((List) objValue)).append(",");
} else {
String str = objValue.toString();
for (String[] mapping : packRuleMappings) {
str = str.replaceAll(mapping[0], mapping[1]);
}
sb.append(str).append(",");
}
}
return StringUtils.chomp(sb.toString(), ",") + "]";
}
public static Properties getProperties(String propertyFile)
throws IOException {
return PropertyUtil.getProperties(propertyFile);
}
public static String formatHexString(byte[] b) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < b.length; i++) {
if (i % 16 == 0)
sb.append(new Sys().getLineSeparator());
String hex = Integer.toHexString(b[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
sb.append(hex.toUpperCase()).append(' ');
}
return sb.toString();
}
public static int byteToShort(byte[] b, int flg) {
return ByteUtil.byteToShort(b, flg);
}
public static byte[] shortToByte(int number, int flg) {
return ByteUtil.shortToByte(number, flg);
}
public static int bytesToInt(byte[] bytes, int flg) {
return ByteUtil.bytesToInt(bytes, flg);
}
public static byte[] intToBytes(int i, int flg) {
return ByteUtil.intToBytes(i, flg);
}
public static void bean2xml() {
bean2xml(null, null);
}
public static void bean2xml(String path) {
bean2xml(path, null);
}
public static void bean2xml(String path, String interfacenam) {
new BeBean2Xml().bean2xml(path, interfacenam);
}
public static InterfaceDef xml2InterfaceDef(String xml) {
XmlParser xmlParser = (XmlParser) ParserFactory.getInstance(
ParserName.XMLPARSER, LogUtil.getLogger("xml2obj"));
return (InterfaceDef) xmlParser.xml2InterfaceDef(xml);
}
public static String localIp() throws UnknownHostException {
InetAddress addr = InetAddress.getLocalHost();
String ip = addr.getHostAddress().toString();
return ip;
}
private static int memcnt = 0;
public synchronized static int memcnt() {
memcnt = memcnt + 1;
return memcnt;
}
public static String findlog(String currentdate, List<String> list)
throws ParseException {
String pattern = "yyyy-MM-dd HH:mm:ss,SSS";
StringBuffer sb = new StringBuffer();
int i = 0;
for (String str : list) {
i++;
str = str.trim();
// System.out.println(str);
if (!StringUtil.isEmpty(str)) {
if (str.length() >= 23) {
String head = str.substring(0, 10);
if (head.matches("\\d{4}-\\d{2}-\\d{2}")) {
head = str.substring(0, 23);
if (parseDate(head, pattern).compareTo(
parseDate(currentdate, pattern)) >= 0) {
i--;
break;
}
}
}
}
}
for (int k = i; k < list.size(); k++) {
sb.append(list.get(k) + "\r\n");
}
return sb.toString();
}
public static String ASCIItoString(String str) {
return StringUtil.ASCIItoString(str);
}
public static String toASCII(String str) {
return StringUtil.toASCII(str);
}
public static boolean isDigit(String s) {
if (isEmpty(s))
return false;
return s.matches("-?[0-9]*.?[0-9]+");
}
/*
* public static boolean upload(HttpServletRequest request,
* HttpServletResponse response, String basePath) { return
* UploadUtil.upload(request, response, basePath);
*
* }
*/
/**
* 将第一位表示小数位的无小数点数据转换为正常的带小数点的数据。例如将"69972522"转换为"9.972522"
*
* @param value
* @return
*/
public static String normalRate(String value) {
int decimalpos = Integer.parseInt(value.substring(0, 1));
String orgrate = value.substring(1);
return orgrate.substring(0, orgrate.length() - decimalpos) + "."
+ orgrate.substring(orgrate.length() - decimalpos);
}
// public static int getPdfPageCount(String path) {
// return PdfUtil.getPdfPageCount(path);
// }
public static Double multiply(String a, String b) {
return new BigDecimal(a).multiply(new BigDecimal(b)).doubleValue();
}
public static Double divide(String a, String b) {
return new BigDecimal(a).divide(new BigDecimal(b), 10,
BigDecimal.ROUND_HALF_UP).doubleValue();
}
public static Double add(String a, String b) {
return new BigDecimal(a).add(new BigDecimal(b)).doubleValue();
}
public static Double subtract(String a, String b) {
return new BigDecimal(a).subtract(new BigDecimal(b)).doubleValue();
}
public static Double multiply(Double a, Double b) {
return new BigDecimal(a).multiply(new BigDecimal(b)).doubleValue();
}
public static Double divide(Double a, Double b) {
return new BigDecimal(a).divide(new BigDecimal(b), 10,
BigDecimal.ROUND_HALF_UP).doubleValue();
}
public static Double add(Double a, Double b) {
return new BigDecimal(a).add(new BigDecimal(b)).doubleValue();
}
public static Double subtract(Double a, Double b) {
return new BigDecimal(a).subtract(new BigDecimal(b)).doubleValue();
}
/**
* 用于计算时间周期针对四海华彩项目加入
*/
private static final long MINUTE_MILLISECOND = 60 * 1000;
/*
* private static String calculateSection(String date, String pattern, int
* n) throws ParseException { return calculateSection(date, pattern,
* pattern, n); }
*/
private static String calculateSection(String date, String pattern,
String pattern1, int n, boolean isStart) throws ParseException {
Date rDate = calculateSectionDate(date, pattern, n, isStart);
return DateFormatUtils.format(rDate, pattern1);
}
private static Date calculateSectionDate(String date, String pattern,
int n, boolean isStart) throws ParseException {
Date current = DateUtil.parseDate(date, pattern);
return new Date((current.getTime() / (n * MINUTE_MILLISECOND))
* (n * MINUTE_MILLISECOND)
+ (isStart ? 0 : n * MINUTE_MILLISECOND));
}
private static long calculateDiff(String date1, String date2, String pattern)
throws ParseException {
Date time1 = DateUtil.parseDate(date1, pattern);
Date time2 = DateUtil.parseDate(date2, pattern);
return time1.getTime() - time2.getTime();
}
private static String dateFormat(String date, String pattern,
String pattern1) throws ParseException {
Date time = DateUtil.parseDate(date, pattern);
return DateFormatUtils.format(time, pattern1);
}
private static boolean isRange(String[] interval, Date current)
throws ParseException {
String currentMinute = DateFormatUtils.format(current, "HH:mm");
if (null == interval || interval.length == 0)
return true;
if (interval.length == 1) {
return currentMinute.equals(interval[0]);
}
if (interval.length == 2) {
if (interval[0].compareTo(interval[1]) >= 0) {
if (currentMinute.compareTo(interval[0]) >= 0
&& currentMinute.compareTo("24:00") <= 0
|| currentMinute.compareTo("00:00") >= 0
&& currentMinute.compareTo(interval[1]) <= 0)
return true;
} else {
if (currentMinute.compareTo(interval[0]) >= 0
&& currentMinute.compareTo(interval[1]) <= 0)
return true;
}
}
return false;
}
public static List<String[]> calculateTimelot(String timeslot,
String pattern, String type) throws ParseException {
List<String[]> result = new ArrayList<String[]>();
String[] times = timeslot.split("\\|");
List<String[]> tmp = new ArrayList<String[]>();
for (int i = 0; i < times.length; i++) {
String[] interval = times[i].split("\\-");
if (interval.length == 2) {
if (interval[0].compareTo(interval[1]) >= 0) {
tmp.add(new String[] { interval[0], "24:00" });
tmp.add(new String[] { "00:00", interval[1] });
} else {
tmp.add(new String[] { interval[0], interval[1] });
}
}
}
if ("MIN60".equals(type)) {
long diffTime = 0;
for (int i = 0; i < tmp.size(); i++) {
String[] interval = tmp.get(i);
if (interval.length == 2) {
if (diffTime > 0) {
Date start = parseDate(interval[0], pattern);
Date next = new Date(start.getTime() + diffTime);
diffTime = next.getTime()
- parseDate(interval[1], pattern).getTime();
if (diffTime > 0) {
if (i == tmp.size() - 1)
result.get(result.size() - 1)[1] = interval[1];
else
continue;
} else {
String nextStr = format(next, pattern);
if (nextStr.equals("00:00"))
nextStr = "24:00";
result.get(result.size() - 1)[1] = nextStr;
diffTime = loopTimelot(result, nextStr,
interval[1], pattern, type);
if (diffTime == 0)
continue;
}
}
if (diffTime == 0)
diffTime = loopTimelot(result, interval[0],
interval[1], pattern, type);
if (diffTime > 0 && i == tmp.size() - 1)
result.get(result.size() - 1)[1] = interval[1];
}
}
}
return result;
}
private static long loopTimelot(List<String[]> result, String start,
String end, String pattern, String type) throws ParseException {
Date nextDate = null;
if ("MIN60".equals(type))
nextDate = dateAdd(parseDate(start, pattern), 3, 1);
if (nextDate == null)
return -1;
long diffTime = nextDate.getTime() - parseDate(end, pattern).getTime();
String next = format(nextDate, pattern);
if (diffTime == 0) {
if (next.equals("00:00"))
next = "24:00";
result.add(new String[] { start, next });
return diffTime;
}
if (diffTime > 0) {
result.add(new String[] { start, null });
} else {
if (next.equals("00:00"))
next = "24:00";
result.add(new String[] { start, next });
diffTime = loopTimelot(result, next, end, pattern, type);
}
return diffTime;
}
public static String calculateRange(String date, String pattern,
String type, String timeslot, List<Map<String, String>> hoildayrs)
throws ParseException {
boolean isStart = true;
if (!StringUtils.isEmpty(timeslot))
isStart = false;
if ("MIN01".equals(type)) {
return calculateSection(date, pattern, "HHmm", 1, isStart);
}
if ("MIN02".equals(type)) {
return calculateSection(date, pattern, "HHmm", 2, isStart);
}
if ("MIN03".equals(type)) {
return calculateSection(date, pattern, "HHmm", 3, isStart);
}
if ("MIN05".equals(type)) {
return calculateSection(date, pattern, "HHmm", 5, isStart);
}
if ("MIN30".equals(type)) {
return calculateSection(date, pattern, "HHmm", 30, isStart);
}
if ("MIN60".equals(type)) {
if (StringUtils.isEmpty(timeslot)) {
return calculateSection(date, pattern, "HHmm", 60, true);
}
List<String[]> calculateTimelot = calculateTimelot(timeslot,
"HH:mm", type);
String minute = dateFormat(date, pattern, "HH:mm");
for (String[] ss : calculateTimelot) {
if (ss.length == 2) {
if (minute.compareTo(ss[0]) >= 0
&& minute.compareTo(ss[1]) < 0) {
return dateFormat(ss[1], "HH:mm", "HHmm");
}
}
}
}
if ("MIN90".equals(type))
return null;
if ("HOUR04".equals(type))
return null;
if ("DAY".equals(type))
return dateFormat(date, pattern, "yyyyMMdd");
if ("WEEK".equals(type)) {
Calendar cal = Calendar.getInstance();
cal.setTime(DateUtil.parseDate(date, pattern));
if (isStart) {
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
return DateFormatUtils.format(cal, "yyyyMMdd");
} else {
cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
return calculateExceptHolidays(cal, hoildayrs);
}
}
if ("MONTH".equals(type))
return dateFormat(date, pattern, "yyyyMM");
if ("YEAR".equals(type))
return dateFormat(date, pattern, "yyyy");
return null;
}
public static String calculateExceptHolidays(Calendar calendar,
List<Map<String, String>> hoildayrs) {
for (Map<String, String> m : hoildayrs) {
if (m.get("spec_date").equals(
DateFormatUtils.format(calendar, "yyyyMMdd"))
|| calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
|| calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
calendar.add(Calendar.DATE, -1);
return calculateExceptHolidays(calendar, hoildayrs);
}
}
return DateFormatUtils.format(calendar, "yyyyMMdd");
}
/**
* 提炼FileConnection的写文件功能
*
* @param content
* 待写入文件的内容,可以是字节数组或者字符串
* @param path
* 文件路径
* @param append
* 是追加写到文件末尾还是从文件开始处写
* @param encode
* 文件内容编码
*/
public static void writeFile(Object content, String path, boolean append,
String encode) {
File file = new File(path);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
if (!append || !file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
throw new InterfaceException("00803", "create new file error.",
e);
}
}
if (content == null || content.toString().equals("")) {
return;
}
PrintWriter pw = null;
try {
FileOutputStream fos = new FileOutputStream(file, append);
if (content instanceof byte[]) {
IOUtils.write((byte[]) content, fos);
fos.close();
return;
} else {
pw = new PrintWriter(new OutputStreamWriter(fos, encode), true);
pw.print(content);
pw.flush();
return;
}
} catch (Exception e) {
throw new InterfaceException("00803", "write file error.", e);
} finally {
if (null != pw)
pw.close();
}
}
private static Map<String, BlockingQueue<Object>> queue = new ConcurrentHashMap<String, BlockingQueue<Object>>();
public static void createBlockingQueue(String key, int capacity,
boolean fair) {
if (queue.containsKey(key))
return;
queue.put(key, new ArrayBlockingQueue<Object>(capacity, fair));
}
public static Object takeFromBlockingQueue(String key) throws Exception {
Object obj = null;
if (queue.get(key) == null)
return obj;
return queue.get(key).take();
}
public static boolean put2BlockingQueue(String key, Object obj)
throws Exception {
if (queue.get(key) == null)
return false;
queue.get(key).put(obj);
return true;
}
public static boolean isValidDate(String str, String style) {
boolean convertSuccess = true;
SimpleDateFormat format = new SimpleDateFormat(style);
try {
format.setLenient(false);
format.parse(str);
} catch (ParseException e) {
// 如果throw java.text.ParseException或者NullPointerException,就说明格式不对
convertSuccess = false;
}
return convertSuccess;
}
public static String decodeURL(String path) {
try {
return URLDecoder.decode(path, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static String decimalFormat2(Object decimal, int num) {
if (decimal == null
|| ((decimal instanceof String) && (decimal.toString().trim()
.equals(""))))
decimal = "0";
return decimalFormat(decimal, num);
}
public static Map<String, Object> fileAtrri(String path, String encode) {
Map<String, Object> map = new HashMap<String, Object>();
File f = new File(path);
map.put("fsize", f.length());
String line = "";
int i = 0;
FileInputStream fis = null;
InputStreamReader isr = null;
BufferedReader br = null;
try {
fis = new FileInputStream(f);
isr = new InputStreamReader(fis, encode);
br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
i++;
}
map.put("flength", i);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
IOUtils.closeQuietly(br);
IOUtils.closeQuietly(isr);
IOUtils.closeQuietly(fis);
}
return map;
}
public static File file(String path) {
return new File(path);
}
public static void makeFileByTemplate(String template,
Map<String, Object> cache, String outPut, String encode)
throws IOException {
TemplateUtil.makeFileByTemplate(template, cache, outPut, encode);
}
public static String getXmlValue(String xmlStr, String etag) {
return XmlUtil.getXmlValue(xmlStr, etag);
}
/**
* 将Exception对象转为Exception文字信息
*
* @param e
* @return
* @throws IOException
*/
public static String exceptionToExceptionMsg(Exception e) {
// 记入错误日志
ByteArrayOutputStream buf = new ByteArrayOutputStream();
String exceptionMessage = "";
try {
e.printStackTrace(new PrintWriter(buf, true));
exceptionMessage = buf.toString();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
buf.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
return exceptionMessage;
}
/**
* 根据XPath取XML节点
*
* @param xmlStr
* @param xPath
* @return
* @throws Exception
*/
public static Element getElementByXPath(String xmlStr, String xPath,
String charset) throws Exception {
List elementList = null;
if (xmlStr != null && !"".equals(xmlStr) && xPath != null
&& !"".equals(xPath)) {
SAXReader reader = new SAXReader();
Document xmlDoc = reader.read(new ByteArrayInputStream(xmlStr
.getBytes(charset)));
elementList = xmlDoc.selectNodes(xPath);
if (elementList != null && elementList.size() >= 1) {
if (elementList.get(0) != null) {
return (Element) elementList.get(0);
}
}
}
return null;
}
/**
* 由XML元素获取XML字符串
*
* @param element
* XML元素
* @param indent
* 缩进填充字符串
* @param newlines
* 是否折行
* @return XML字符串
*/
public static String Stringize(Element element, String indent,
boolean newlines, String charset) {
XMLWriter writer = null;
StringWriter out = null;
try {
OutputFormat formate = OutputFormat.createPrettyPrint();
formate.setNewLineAfterDeclaration(false);
if (newlines) {
formate.setIndent(indent);
}
formate.setNewlines(Boolean.valueOf(newlines));
formate.setEncoding(charset);
formate.setExpandEmptyElements(true);
out = new StringWriter();
writer = new XMLWriter(out, formate);
if (element.getDocument() != null) {
writer.write(element.getDocument());
} else {
Document doc = DocumentHelper.createDocument(element);
writer.write(doc);
}
} catch (Exception e) {
throw new InterfaceException("02803", e);
} finally {
try {
if (out != null) {
out.close();
}
if (writer != null) {
writer.close();
}
} catch (IOException ioe) {
throw new InterfaceException("02904", ioe);
}
}
return out.toString().trim();
}
public static Element Elementize(String xml) {
try {
Document document = DocumentHelper.parseText(xml);
Element rt = document.getRootElement();
return rt;
} catch (Exception e) {
throw new InterfaceException("02801", e);
}
}
}
......@@ -81,8 +81,10 @@ public class LogUtil {
}
public static Logger getLogger(Context context) {
Logger log = (Logger) context.getTransactionMap().get(Constants.Log_VAR);
return log;
if (context != null && context.getTransactionMap() != null && context.getTransactionMap().get(Constants.Log_VAR) != null) {
return (Logger) context.getTransactionMap().get(Constants.Log_VAR);
}
return LoggerFactory.getLogger(LogUtil.class);
}
public static Logger getTrnLog(String interfaceName, String transactionName, String pre,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment