import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.log4j.Logger;
import org.dom4j.io.SAXReader;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import com.huawei.ngbss.esb.FileManager;
public class Tools
{
// 序列号,用于构造ESB_TRACKING_ID
private static int sn = 0;
// 序列号,用于构造SEQ_ID
private static int seq_id = 0;
private static Logger logger = Logger.getLogger(Tools.class);
private static final String INITPROPERTIES = "init.properties";
// 为了防止写数据库的线程挂死,sql不断累加增加,
// 导致内存泄露,当队列中的数据超过maxLength没有处理,
// 数据将被丢弃。写到日志中
private static int maxLength = 0;
// 每批次的批量写数据库的SQL条数
private static int maxeachBatch = 0;
// 日期格式
private static String df = null;
// 批量线程的sleep 时间
private static long THREADSLEEP = 5000;
private static String ENDPOINT = null;
private static String ENCRYPT_ALGO = null;
private static DocumentBuilderFactory factory = null;
private static String[] seq_array = null;
private static String[] trancking_array = null;
/**
* 在第一次调用该类初始化int.properties, 这里面主要有数据库配置文件,XPath的配置文件路径
*/
static
{
init();
}
public static void init()
{
logger.info("Initial Properties");
maxLength = Integer.parseInt(FileManager.getProperty(INITPROPERTIES,
"maxLength", "10000"));
maxeachBatch = Integer.parseInt(FileManager.getProperty(INITPROPERTIES,
"maxeachBatch", "500"));
// 时间格式
df = FileManager.getProperty(INITPROPERTIES, "date_format");
THREADSLEEP = Long.parseLong(FileManager.getProperty(INITPROPERTIES,
"threadSleep", "5000"));
ENDPOINT = FileManager.getProperty(INITPROPERTIES, "endpoint", "");
factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
ENCRYPT_ALGO = FileManager.getProperty(INITPROPERTIES, "ENCRYPT_ALGO",
"");
}
private Tools()
{
}
public static Document string2JDKDocument(String message)
throws ParserConfigurationException, SAXException, IOException
{
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new ByteArrayInputStream(message
.getBytes()));
return doc;
}
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.log4j.Logger;
import org.dom4j.io.SAXReader;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import com.huawei.ngbss.esb.FileManager;
public class Tools
{
// 序列号,用于构造ESB_TRACKING_ID
private static int sn = 0;
// 序列号,用于构造SEQ_ID
private static int seq_id = 0;
private static Logger logger = Logger.getLogger(Tools.class);
private static final String INITPROPERTIES = "init.properties";
// 为了防止写数据库的线程挂死,sql不断累加增加,
// 导致内存泄露,当队列中的数据超过maxLength没有处理,
// 数据将被丢弃。写到日志中
private static int maxLength = 0;
// 每批次的批量写数据库的SQL条数
private static int maxeachBatch = 0;
// 日期格式
private static String df = null;
// 批量线程的sleep 时间
private static long THREADSLEEP = 5000;
private static String ENDPOINT = null;
private static String ENCRYPT_ALGO = null;
private static DocumentBuilderFactory factory = null;
private static String[] seq_array = null;
private static String[] trancking_array = null;
/**
* 在第一次调用该类初始化int.properties, 这里面主要有数据库配置文件,XPath的配置文件路径
*/
static
{
init();
}
public static void init()
{
logger.info("Initial Properties");
maxLength = Integer.parseInt(FileManager.getProperty(INITPROPERTIES,
"maxLength", "10000"));
maxeachBatch = Integer.parseInt(FileManager.getProperty(INITPROPERTIES,
"maxeachBatch", "500"));
// 时间格式
df = FileManager.getProperty(INITPROPERTIES, "date_format");
THREADSLEEP = Long.parseLong(FileManager.getProperty(INITPROPERTIES,
"threadSleep", "5000"));
ENDPOINT = FileManager.getProperty(INITPROPERTIES, "endpoint", "");
factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
ENCRYPT_ALGO = FileManager.getProperty(INITPROPERTIES, "ENCRYPT_ALGO",
"");
}
private Tools()
{
}
public static Document string2JDKDocument(String message)
throws ParserConfigurationException, SAXException, IOException
{
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new ByteArrayInputStream(message
.getBytes()));
return doc;
}