XML工具 Tools 01

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值