锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
* Excel WorkBook瀵硅薄綾?
* @author zhouqian
*
*/
public class ExcelWorkBook {
/** 宸ヤ綔綈?*/
private static HSSFWorkbook workbook = new HSSFWorkbook();
/** 宸ヤ綔琛?*/
private HSSFSheet sheet;
/** 琛ㄥご鏁版嵁 */
private String[] tableHeader;
/**
* 鏋勯犲嚱鏁?br />
* @param workbookName 宸ヤ綔琛ㄥ悕
* @param tableHeader 琛ㄥご鏁版嵁
*/
public ExcelWorkBook(String workbookName, String[] tableHeader) {
super();
this.tableHeader = tableHeader;
sheet = workbook.createSheet(workbookName);
}
/**
* 鍒涘緩琛ㄥご
* @param headerName
*/
public void createTableHeader(String headerName) {
HSSFHeader header = sheet.getHeader();
header.setCenter(headerName);
HSSFRow headerRow = sheet.createRow(0);
int cellNumber = tableHeader.length;
for (int i = 0; i < cellNumber; i++) {
HSSFCell headerCell = headerRow.createCell((short)i);
headerCell.setEncoding(HSSFCell.ENCODING_UTF_16);
headerCell.setCellValue(tableHeader[i]);
}
}
/**
* 鍒涘緩琛?br />
* @param data 瑕佸啓鍏ョ殑鏁版嵁
* @param rowIndex 絎瑀owIndex琛?
*/
public void createTableRow(String[] data, int rowIndex) {
HSSFRow row = sheet.createRow(rowIndex);
for (int i = 0; i < data.length; i++) {
HSSFCell cell = row.createCell((short)i);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(data[i]);
}
}
/**
* 鍒涘緩鏁翠釜Excel琛?br />
* @param headerName
*/
public void createExcelSheet(String headerName, String[][] data) {
this.createTableHeader(headerName);
String[] rowData;
for (int i = 0; i < data.length; i++) {
rowData = data[i];
createTableRow(rowData, i + 1);
}
}
/**
* 瀵煎嚭Excel琛ㄦ牸
* @param os
* @throws IOException
*/
public void exportExcel(OutputStream os) throws IOException {
sheet.setGridsPrinted(true);
HSSFFooter footer = sheet.getFooter();
footer.setRight("Page " + HSSFFooter.page() + " of " + HSSFFooter.numPages());
workbook.write(os);
}
public HSSFSheet getSheet() {
return sheet;
}
public void setSheet(HSSFSheet sheet) {
this.sheet = sheet;
}
public String[] getTableHeader() {
return tableHeader;
}
public void setTableHeader(String[] tableHeader) {
this.tableHeader = tableHeader;
}
}
/** 娑堟伅瀵硅薄 */
private Message message;
/** 閭歡浼氳瘽 */
private Session session;
public MailClient() {
super();
this.session = createDefaultSession();
}
public MailClient(Session session) {
super();
this.session = session;
}
public MailClient(Message message) {
this();
this.message = message;
}
public MailClient(Session session, Message message) {
super();
this.session = session;
this.message = message;
}
/**
* 鍒涘緩閭歡浼氳瘽
*
* @return
*/
protected Session createDefaultSession() {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.163.com");
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props);
session.setDebug(true);
return session;
}
/**
* 鍒涘緩綰枃鏈偖浠?br />
*
* @param recipientTO
* @param recipientCC
* @param recipientBCC
* @return
* @throws MessagingException
*/
protected Message createMimeMessage(String subject, String content,
String recipientTO, String recipientCC, String recipientBCC)
throws MessagingException {
Message message = createBlankMessage(recipientTO, recipientCC,
recipientBCC);
// 璁劇疆閭歡鏍囬
message.setSubject(subject);
// 璁劇疆閭歡鍐呭
message.setText(content);
// 璁劇疆鍙戦佹椂闂?br /> message.setSentDate(new Date(System.currentTimeMillis()));
// 瀛樺偍閭歡淇℃伅
message.saveChanges();
return message;
}
/**
* 鍒涘緩甯TML鍐呭鐨勯偖浠?br />
*
* @param subject
* @param content
* @param recipientTO
* @param recipientCC
* @param recipientBCC
* @return
* @throws MessagingException
*/
protected Message createHTMLMessage(String subject, String content,
String recipientTO, String recipientCC, String recipientBCC)
throws MessagingException {
Message message = createBlankMessage(recipientTO, recipientCC,
recipientBCC);
// 璁劇疆閭歡鏍囬
message.setSubject(subject);
// 璁劇疆鍙戦佹椂闂?br /> message.setSentDate(new Date(System.currentTimeMillis()));
// 鍒涘緩瀛樻斁閭歡鍐呭鐨凚odyPart瀵硅薄
BodyPart bp = new MimeBodyPart();
bp.setContent(content, "text/html;charset=gb2312");
// 鍒涘緩涓涓狹imeMultipart鏉ュ瓨鏀綛odyPart瀵硅薄
Multipart mp = new MimeMultipart();
mp.addBodyPart(bp);
message.setContent(mp);
message.saveChanges();
return message;
}
/**
* 鍒涘緩甯﹂檮浠剁殑閭歡
*
* @param subject
* @param content
* @param recipientTO
* @param recipientCC
* @param recipientBCC
* @return
* @throws MessagingException
*/
protected Message createAttachMessage(String subject, String content,
File attachment, String recipientTO, String recipientCC,
String recipientBCC) throws MessagingException {
Message message = createBlankMessage(recipientTO, recipientCC,
recipientBCC);
// 璁劇疆閭歡鏍囬
message.setSubject(subject);
// 璁劇疆鍙戦佹椂闂?br /> message.setSentDate(new Date(System.currentTimeMillis()));
// 鍒涘緩瀛樻斁閭歡鍐呭鐨凚odyPart瀵硅薄
BodyPart bp = new MimeBodyPart();
bp.setContent(content, "text/html;charset=gb2312");
// 鍒涘緩涓涓狹imeMultipart鏉ュ瓨鏀綛odyPart瀵硅薄
Multipart mp = new MimeMultipart();
mp.addBodyPart(bp);
// 璁劇疆閭歡鐨勯檮浠?br />
bp = new MimeBodyPart();
FileDataSource fds = new FileDataSource(attachment.getName());
DataHandler dh = new DataHandler(fds);
try {
bp.setFileName(new String(attachment.getName().getBytes("gb2312")));
} catch (UnsupportedEncodingException e) {
final String errMess = "Caught exception while encoding file name:"
+ attachment.getName();
logger.error(errMess);
throw new MailException(errMess, e);
}
bp.setDataHandler(dh);
mp.addBodyPart(bp);
message.setContent(mp);
message.saveChanges();
return message;
}
/**
* 鍒涘緩絀虹櫧閭歡
*
* @param recipientTO
* @param recipientCC
* @param recipientBCC
* @return
* @throws MessagingException
*/
protected Message createBlankMessage(String recipientTO,
String recipientCC, String recipientBCC) throws MessagingException {
Message message = new MimeMessage(session);
// 璁劇疆鍙戜歡浜?br />
InternetAddress from = new InternetAddress("mfktfp2004@163.com");
message.setFrom(from);
// 璁劇疆鏀朵歡浜?br />
InternetAddress to = new InternetAddress(recipientTO);
message.setRecipient(Message.RecipientType.TO, to);
if (StringUtil.isNotEmpty(recipientCC)) {
InternetAddress cc = new InternetAddress(recipientCC);
message.setRecipient(Message.RecipientType.CC, cc);
}
if (StringUtil.isNotEmpty(recipientBCC)) {
InternetAddress bcc = new InternetAddress(recipientBCC);
message.setRecipient(Message.RecipientType.BCC, bcc);
}
return message;
}
/**
* 鍙戦侀偖浠?br />
*
* @param message
* @throws MessagingException
*/
public void sendEmail(Message message) throws MessagingException {
// 浠mtp鏂瑰紡鐧婚檰閭
Transport transport = session.getTransport("smtp");
transport.connect("smtp.163.com", "mfktfp2004", "19850921"); // SMTP鍦板潃錛岀敤鎴峰悕錛屽瘑鐮?/p>
// 鍙戦侀偖浠?br />
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
/**
* 鍙戦佺函鏂囨湰閭歡
*
* @param subject
* @param content
* @param recipientTO
* @param recipientCC
* @param recipientBCC
*/
public void sendMimeEmail(String subject, String content,
String recipientTO, String recipientCC, String recipientBCC) {
Message message = null;
try {
message = createMimeMessage(subject, content, recipientTO,
recipientCC, recipientBCC);
sendEmail(message);
} catch (MessagingException e) {
logger.error("Send mime email failure", e);
throw new MailException("Error sending email, failure", e);
}
}
/**
* 鍙戦佸甫HTML鍐呭鐨勯偖浠?br />
*
* @param subject
* @param content
* @param recipientTO
* @param recipientCC
* @param recipientBCC
*/
public void sendHTMLEmail(String subject, String content,
String recipientTO, String recipientCC, String recipientBCC) {
Message message = null;
try {
message = createHTMLMessage(subject, content, recipientTO,
recipientCC, recipientBCC);
sendEmail(message);
} catch (MessagingException e) {
logger.error("Send html email failure", e);
throw new MailException("Error sending email, failure", e);
}
}
/**
* 鍙戦佸甫闄勪歡鐨勯偖浠?br />
*
* @param subject
* @param content
* @param recipientTO
* @param recipientCC
* @param recipientBCC
*/
public void sendAttachEmail(String subject, String content,
File attachment, String recipientTO, String recipientCC,
String recipientBCC) {
Message message = null;
try {
message = createAttachMessage(subject, content, attachment,
recipientTO, recipientCC, recipientBCC);
sendEmail(message);
} catch (MessagingException e) {
logger.error("Send html email failure", e);
throw new MailException("Error sending email, failure", e);
}
}
public Message getMessage() {
return message;
}
public void setMessage(Message message) {
this.message = message;
}
public Session getSession() {
return session;
}
public void setSession(Session session) {
this.session = session;
}
public static void main(String[] args) {
MailClient client = new MailClient();
client.sendMimeEmail("test", "test", "zhouqian1103@163.com", null, null);
}
}
public class MailException extends RuntimeException {
private static final long serialVersionUID = 1L;
/** Throwable瀹炰緥 */
protected Throwable throwable;
public MailException() {
super();
}
public MailException(String message) {
super(message);
}
public MailException(Throwable cause) {
this.throwable = cause;
}
public MailException(String message, Throwable cause) {
super(message);
this.throwable = cause;
}
public void printStackTrace(PrintStream ps) {
super.printStackTrace(ps);
if (throwable != null) {
ps.println("with nested Exception:" + throwable);
throwable.printStackTrace(ps);
}
}
public void printStackTrace(PrintWriter pw) {
super.printStackTrace(pw);
if (throwable != null) {
pw.println("with nested Exception:" + throwable);
throwable.printStackTrace(pw);
}
}
public String toString() {
if (throwable == null) {
return super.toString();
} else {
return super.toString() + "with nested exception:" + throwable;
}
}
public Throwable getThrowable() {
return throwable;
}
}
//鍒涘緩騫惰瀹歞iv鐨勫弬鏁?
function setDiv(content)
{
//闃叉閲嶅鎵撳紑
if (div)
{
eCloseDiv();
}
var newLeft,newTop,newWidth,newHeight;
theBody = document.body;
div = document.createElement("div");
div.id = "panelDiv";
div.style.position = "absolute";
div.style.backgroundColor = "#5F86B5" // 杈規棰滆壊
div.style.padding = "1px 1px 1px 1px";
div.style.overflow = "hidden";
div.style.zIndex = 1;
//璁懼畾鎵撳紑鐨勫ぇ灝忓拰浣嶇疆
Function()
{
//榛樿澶у皬榛樿浣嶇疆灞呬腑鎵撳紑
newWidth = "350px";
newHeight = "260px";
newLeft = (theBody.clientWidth - parseInt(newWidth)) / 2 + "px";
newTop = (theBody.clientHeight - parseInt(newHeight)) / 2 + "px";
div.style.width = newWidth;
div.style.height = newHeight;
div.style.left = newLeft;
div.style.top = newTop;
}
div = setChild(div,content);
theBody.appendChild(div);
// var ipt = document.getElementsByTagName("input");
// for(var i = 0; i < ipt.length; i++)
// {
// ipt[i].disabled = true;
// }
}
function setChild(div,content)
{
//鍙惁縐誨姩銆佽皟鏁?
var isMove = true
var isResize = true;
//搴曡壊
var cDiv = document.createElement;
var backDiv = cDiv("div");
backDiv.style.cssText = "left: 0px; top: 0px; width: 100%; height: 100%; background-color:#DFE8F6;" ;
div.appendChild(backDiv);
//鏍囬
var topDiv = cDiv("div");
topDiv.style.cssText = "left: 1px; top: 1px; width: 100%; height: 22px; border-bottom:1px solid #5F86B5; position: absolute; background: url(images/bgd.gif) repeat-x; vertical-align: middle; z-index: 5";
if (isMove)
{
topDiv.style.cursor = "move";
topDiv.setAttribute("onmousedown", function(){setMove(this)});
}
else
{
topDiv.style.cursor = "default";
}
topDiv.innerHTML = "<span style='top: 5px; left:5px; font-size: 12px; font-weight: bold; color: #102548; position: relative;' onselectstart='return false'>榪囨護鎻愮ず</span>";
div.appendChild(topDiv);
//鍏抽棴鎸夐挳
var closeDiv = cDiv("div");
closeDiv.style.cssText = "right: 8px; top : 4px; width: 16px; height: 16px; position: absolute; text-align: center; vertical-align: middle; cursor: pointer; z-index:10";
closeDiv.setAttribute("onclick", function() {eCloseDiv()});
closeDiv.innerHTML = "<span style='font-size: 12px; font-weight: bold; color: #0E377A;' title='Esc蹇嵎閿?><img src = 'images/close.gif'/></span>";
div.appendChild(closeDiv);
//鍐呭
var contentDiv = cDiv("div");
contentDiv.style.cssText = "left: 1px; top: 35px; background-color:#DFE8F6; width: 100%; position: absolute; overflow: auto; padding:5px;";
contentDiv.style.height = (parseInt(div.style.height) - 40) + "px";
contentDiv.innerHTML = "<table style='width: 100%; height: 100%; text-align: left; vertical-align: hidden'><tr><td><p>"+content+"</p></td></tr></table>";
div.appendChild(contentDiv);
//璋冩暣澶у皬
var reDiv = cDiv("div");
reDiv.style.cssText = "right: 0px; bottom: 0px; width: 5px; height: 5px; position: absolute;";
if (isResize)
{
reDiv.style.cursor = "se-resize";
reDiv.setAttribute("onmousedown", function(){setResize(this)});
}
else
{
reDiv.style.cursor = "default";
}
div.appendChild(reDiv);
return div;
}
var oX, oY, oLeft, oTop, oWidth, oHeight; //瀛樺偍鍘熷縐誨姩鍓嶇殑浣嶇疆
var divClone, oDiv; //鍏嬮殕鐨勮妭鐐瑰拰鍘熷鑺傜偣
var oTime;
//clone鎷栫Щ鐨勮妭鐐?
function setMove(obj)
{
if (event.button == 1)
{
if (oTime)
{
clearTimeout(oTime);
divClone.parentNode.removeChild(divClone);
}
oDiv = obj.parentNode;
divClone = oDiv.cloneNode(true);
divClone.style.filter = "Alpha(opacity=50)";
divClone.childNodes[1].setAttribute("onmousemove", function(){startMove(this)});
divClone.childNodes[1].setAttribute("onmouseup", function(){endMove()});
oX = parseInt(event.clientX);
oY = parseInt(event.clientY);
oLeft = parseInt(divClone.style.left);
oTop = parseInt(divClone.style.top);
document.body.appendChild(divClone);
divClone.childNodes[1].setCapture();
eventType = "move";
}
}
//鎷栫Щ
function startMove(obj)
{
if (eventType == "move" && event.button == 1)
{
var moveDiv = obj.parentNode;
moveDiv.style.left = (oLeft + event.clientX - oX) + "px";
moveDiv.style.top = (oTop + event.clientY - oY) + "px";
}
}
//鎷栫Щ緇撴潫璋冪敤鍔ㄧ敾
function endMove()
{
if (eventType == "move")
{
divClone.childNodes[1].releaseCapture();
move(parseInt(divClone.style.left), parseInt(divClone.style.top));
eventType = "";
}
}
//縐誨姩鐨勫姩鐢?
function move(aimLeft, aimTop)
{
var nowLeft = parseInt(oDiv.style.left);
var nowTop = parseInt(oDiv.style.top);
var moveSize = 30;
if (nowLeft > aimLeft + moveSize || nowLeft < aimLeft - moveSize || nowTop > aimTop + moveSize || nowTop < aimTop - moveSize)
{
oDiv.style.left = aimLeft > nowLeft + moveSize ? (nowLeft + moveSize) + "px" : aimLeft < nowLeft - moveSize ? (nowLeft - moveSize) + "px" : nowLeft + "px";
oDiv.style.top = aimTop > nowTop + moveSize ? (nowTop + moveSize) + "px" : aimTop < nowTop - moveSize ? (nowTop - moveSize) + "px" : nowTop + "px";
oTime = setTimeout("move(" + aimLeft + ", " + aimTop + ")", 1);
}
else
{
oDiv.style.left = divClone.style.left;
oDiv.style.top = divClone.style.top;
divClone.parentNode.removeChild(divClone);
divClone == null;
}
}
//clone璋冩暣澶у皬鐨勮妭鐐?
function setResize(obj)
{
if (event.button == 1)
{
if (oTime)
{
clearTimeout(oTime);
divClone.parentNode.removeChild(divClone);
}
oDiv = obj.parentNode;
divClone = oDiv.cloneNode(true);
divClone.style.filter = "Alpha(opacity=50)";
divClone.childNodes[4].setAttribute("onmousemove", function(){startResize(this)});
divClone.childNodes[4].setAttribute("onmouseup", function(){endResize()});
oX = parseInt(event.clientX);
oY = parseInt(event.clientY);
oWidth = parseInt(divClone.style.width);
oHeight = parseInt(divClone.style.height);
document.body.appendChild(divClone);
divClone.childNodes[4].setCapture();
eventType = "resize";
}
}
//鎷栧姩璋冩暣澶у皬
function startResize(obj)
{
if (eventType == "resize" && event.button == 1)
{
var nX = event.clientX;
var nY = event.clientY;
if (nX > oX - oWidth && nY > oY - oHeight + 40)
{
var resizeDiv = obj.parentNode;
resizeDiv.style.width = (oWidth + event.clientX - oX) + "px";
resizeDiv.style.height = (oHeight + event.clientY - oY) + "px";
resizeDiv.childNodes[3].style.height = (parseInt(resizeDiv.style.height) - 40) + "px";
}
}
}
//璋冩暣澶у皬緇撴潫
function endResize()
{
if (eventType == "resize")
{
divClone.childNodes[4].releaseCapture();
resize(parseInt(divClone.style.width), parseInt(divClone.style.height));
eventType = "";
}
}
//璋冩暣澶у皬鐨勫姩鐢?
function resize(aimWidth, aimHeight)
{
var nowWidth = parseInt(oDiv.style.width);
var nowHeight = parseInt(oDiv.style.height);
var resizeSize = 30;
if (nowWidth > aimWidth + resizeSize || nowWidth < aimWidth - resizeSize || nowHeight > aimHeight + resizeSize || nowHeight < aimHeight - resizeSize)
{
oDiv.style.width = aimWidth > nowWidth + resizeSize ? (nowWidth + resizeSize) + "px" : aimWidth < nowWidth - resizeSize ? (nowWidth - resizeSize) + "px" : nowWidth + "px";
oDiv.style.height = aimHeight > nowHeight + resizeSize ? (nowHeight + resizeSize) + "px" : aimHeight < nowHeight - resizeSize ? (nowHeight - resizeSize) + "px" : nowHeight + "px";
oDiv.childNodes[3].style.height = (parseInt(oDiv.style.height) - 40) + "px";
oTime = setTimeout("resize(" + aimWidth + ", " + aimHeight + ")", 1);
}
else
{
oDiv.style.width = divClone.style.width;
oDiv.style.height = divClone.style.height;
oDiv.childNodes[3].style.height = (parseInt(oDiv.style.height) - 40) + "px";
divClone.parentNode.removeChild(divClone);
divClone == null;
}
}
//鍏抽棴DIV
function eCloseDiv()
{
if (div)
{
div.parentNode.removeChild(div);
// var ipt = document.getElementsByTagName("input");
// for(var i = 0; i < ipt.length; i++)
// {
// ipt[i].disabled = false;
// }
div = null;
}
}
//淇濈暀浣嶇疆鍜屽ぇ灝?
function saveDiv()
{
if (div)
{
saveLeft = div.style.left;
saveTop = div.style.top;
saveWidth = div.style.width;
saveHeight = div.style.height;
}
}
//蹇嵎閿?
document.onkeydown = function()
{
event.keyCode == 27 ? eCloseDiv() : null; //Esc蹇嵎閿?
event.ctrlKey && (event.keyCode == 83 || event.keyCode == 115) ? saveDiv() : null; //ctrl+s淇濆瓨浣嶇疆
event.ctrlKey && event.keyCode == 13 ? setDiv() : null //ctrl+enter鎵撳紑Div
!event.ctrlKey && (event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 40) ? arrowMove(event.keyCode) : null;
event.ctrlKey && (event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 40) ? arrowResize(event.keyCode) : null;
}
// 鍗曞嚮灞備互澶栫殑鍦版柟闅愯棌灞?br />
document.onclick = function()
{
if (div)
{
if(typeof event.srcElement.message == "undefined")
{
if (div.componentFromPoint(event.clientX,event.clientY)=="outside")
{
eCloseDiv();
}
}
}
}
//涓婁笅宸﹀彸綆ご縐誨姩div
function arrowMove(eKeyCode)
{
if (div)
{
var isMove = document.getElementById("isMove").checked;
if (isMove)
{
switch(eKeyCode)
{
case 37:
div.style.left = (parseInt(div.style.left) - 1) + "px"; //left
break
case 38:
div.style.top = (parseInt(div.style.top) - 1) + "px"; //up
break
case 39:
div.style.left = (parseInt(div.style.left) + 1) + "px"; //right
break
case 40:
div.style.top = (parseInt(div.style.top) + 1) + "px"; //down
break
}
}
}
}
//ctrl+涓婁笅宸﹀彸綆ご璋冩暣div澶у皬
function arrowResize(eKeyCode)
{
if (div)
{
var isResize = document.getElementById("isResize").checked;
if (isResize)
{
switch(eKeyCode)
{
case 37:
div.style.width = (parseInt(div.style.width) - 1) + "px"; //left
break
case 38:
div.style.height = (parseInt(div.style.height) - 1) + "px"; //up
break
case 39:
div.style.width = (parseInt(div.style.width) + 1) + "px"; //right
break
case 40:
div.style.height = (parseInt(div.style.height) + 1) + "px"; //down
break
}
}
}
}
鍚庡彴錛?/p>
SAXBuilder saxb = new SAXBuilder();
Document doc = saxb.build(request.getInputStream());
Element root = doc.getRootElement();
String type = root.getChildText("type");
String inputCondition = root.getChildText("condition");