提交 d1912c0f 编写于 作者: O o2null

Merge branch 'fix/application_codeSafe' into 'wrdp'

applicationServer codeSafe扫描更新

See merge request o2oa/o2oa!4468
......@@ -3,6 +3,6 @@
"pickPersonWithName": false,
"pickIdentityWithName": false,
"###unitLevelOrderNumberDigits": "unit中unitLevelOrderNumber扩充位数,\u003c\u003d0不扩充.###",
"###pickPersonWithName": "人员识别过程中过程为先查找 distinguishedName 再查找中间的 unique 如果还是没有查找到是否要通过那么进行查找.###",
"###pickIdentityWithName": "身份识别过程中过程为先查找 distinguishedName 再查找中间的 unique 如果还是没有查找到是否要通过那么进行查找.###"
"###pickPersonWithName": "zhangsan@123@P人员识别过程中过程为先查找 distinguishedName 再查找中间的 unique 如果还是没有查找到是否要通过名称进行查找.###",
"###pickIdentityWithName": "zhangsan@456@I身份识别过程中过程为先查找 distinguishedName 再查找中间的 unique 如果还是没有查找到是否要通过名称进行查找.###"
}
\ No newline at end of file
......@@ -20,57 +20,64 @@ import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
/**
* 抽象Excel2007读取器,excel2007的底层数据结构是xml文件,采用SAX的事件驱动的方法解析
* xml,需要继承DefaultHandler,在遇到文件内容时,事件会触发,这种做法可以大大降低
* 内存的耗费,特别使用于大数据量的文件。
* xml,需要继承DefaultHandler,在遇到文件内容时,事件会触发,这种做法可以大大降低 内存的耗费,特别使用于大数据量的文件。
*
*/
public class Excel2007Reader extends DefaultHandler {
//共享字符串表
private static Logger logger = LoggerFactory.getLogger(Excel2007Reader.class);
// 共享字符串表
private SharedStringsTable sst;
//上一次的内容
// 上一次的内容
private String lastContents;
private boolean nextIsString;
private int sheetIndex = -1;
private List<String> rowlist = new ArrayList<String>();
//当前行
// 当前行
private int curRow = 0;
//当前列
// 当前列
private int curCol = 0;
//日期标志
// 日期标志
private boolean dateFlag;
//数字标志
// 数字标志
private boolean numberFlag;
private boolean isTElement;
private String fileKey;
private int startRow;
private IRowReader rowReader;
public void setRowReader( IRowReader rowReader, String fileKey, int startRow ){
public void setRowReader(IRowReader rowReader, String fileKey, int startRow) {
this.rowReader = rowReader;
this.fileKey = fileKey;
this.startRow = startRow;
}
/**只遍历一个电子表格,其中sheetId为要遍历的sheet索引,从1开始,1-3
/**
* 只遍历一个电子表格,其中sheetId为要遍历的sheet索引,从1开始,1-3
*
* @param filename
* @param sheetId
* @throws Exception
*/
public void processOneSheet(String filename,int sheetId) throws Exception {
public void processOneSheet(String filename, int sheetId) throws Exception {
OPCPackage pkg = OPCPackage.open(filename);
XSSFReader r = new XSSFReader(pkg);
SharedStringsTable sst = r.getSharedStringsTable();
XMLReader parser = fetchSheetParser(sst);
// 根据 rId# 或 rSheet# 查找sheet
InputStream sheet2 = r.getSheet("rId"+sheetId);
InputStream sheet2 = r.getSheet("rId" + sheetId);
sheetIndex++;
InputSource sheetSource = new InputSource(sheet2);
parser.parse(sheetSource);
......@@ -79,11 +86,12 @@ public class Excel2007Reader extends DefaultHandler {
/**
* 遍历工作簿中所有的电子表格
*
* @param filename
* @param fileKey
* @param fileKey
* @throws Exception
*/
public void process( String filename ) throws Exception {
public void process(String filename) throws Exception {
OPCPackage pkg = OPCPackage.open(filename);
XSSFReader r = new XSSFReader(pkg);
SharedStringsTable sst = r.getSharedStringsTable();
......@@ -94,20 +102,21 @@ public class Excel2007Reader extends DefaultHandler {
sheetIndex++;
InputStream sheet = sheets.next();
InputSource sheetSource = new InputSource(sheet);
parser.parse( sheetSource );
parser.parse(sheetSource);
sheet.close();
}
//数据读取完成
// 数据读取完成
}
/**
* 遍历工作簿中所有的电子表格
*
* @param filename
* @param fileKey
* @param fileKey
* @throws Exception
*/
public void process( InputStream is ) throws Exception {
OPCPackage pkg = OPCPackage.open( is );
public void process(InputStream is) throws Exception {
OPCPackage pkg = OPCPackage.open(is);
XSSFReader r = new XSSFReader(pkg);
SharedStringsTable sst = r.getSharedStringsTable();
XMLReader parser = fetchSheetParser(sst);
......@@ -117,7 +126,7 @@ public class Excel2007Reader extends DefaultHandler {
sheetIndex++;
InputStream sheet = sheets.next();
InputSource sheetSource = new InputSource(sheet);
parser.parse( sheetSource );
parser.parse(sheetSource);
sheet.close();
}
}
......@@ -130,7 +139,7 @@ public class Excel2007Reader extends DefaultHandler {
}
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
// c => 单元格
if ("c".equals(name)) {
// 如果下一个元素是 SST 的索引,则将nextIsString标记为true
......@@ -140,48 +149,46 @@ public class Excel2007Reader extends DefaultHandler {
} else {
nextIsString = false;
}
//日期格式
// 日期格式
String cellDateType = attributes.getValue("s");
if ("1".equals(cellDateType)){
if ("1".equals(cellDateType)) {
dateFlag = true;
} else {
dateFlag = false;
}
String cellNumberType = attributes.getValue("s");
if("2".equals(cellNumberType)){
if ("2".equals(cellNumberType)) {
numberFlag = true;
} else {
numberFlag = false;
}
}
//当元素为t时
if("t".equals(name)){
// 当元素为t时
if ("t".equals(name)) {
isTElement = true;
} else {
isTElement = false;
}
// 置空
lastContents = "";
}
public void endElement(String uri, String localName, String name)
throws SAXException {
public void endElement(String uri, String localName, String name) throws SAXException {
// 根据SST的索引值的到单元格的真正要存储的字符串
// 这时characters()方法可能会被调用多次
if (nextIsString) {
try {
int idx = Integer.parseInt(lastContents);
lastContents = new XSSFRichTextString(sst.getEntryAt(idx))
.toString();
lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString();
} catch (Exception e) {
logger.error(e);
}
}
//t元素也包含字符串
if(isTElement){
}
// t元素也包含字符串
if (isTElement) {
String value = lastContents.trim();
rowlist.add(curCol, value);
curCol++;
......@@ -190,44 +197,43 @@ public class Excel2007Reader extends DefaultHandler {
// 将单元格内容加入rowlist中,在这之前先去掉字符串前后的空白符
} else if ("v".equals(name)) {
String value = lastContents.trim();
value = value.equals("")?" ":value;
//日期格式处理
if(dateFlag){
try{
value = value.equals("") ? " " : value;
// 日期格式处理
if (dateFlag) {
try {
Date date = HSSFDateUtil.getJavaDate(Double.valueOf(value));
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
value = dateFormat.format(date);
}catch(Exception e){
} catch (Exception e) {
logger.error(e);
}
}
//数字类型处理
if(numberFlag){
try{
}
// 数字类型处理
if (numberFlag) {
try {
BigDecimal bd = new BigDecimal(value);
value = bd.setScale(3,BigDecimal.ROUND_UP).toString();
}catch(Exception e){
value = bd.setScale(3, BigDecimal.ROUND_UP).toString();
} catch (Exception e) {
logger.error(e);
}
}
rowlist.add(curCol, value);
curCol++;
}else {
//如果标签名称为 row ,这说明已到行尾,调用 optRows() 方法
} else {
// 如果标签名称为 row ,这说明已到行尾,调用 optRows() 方法
if (name.equals("row")) {
rowReader.getRows(sheetIndex,curRow,rowlist, this.fileKey, this.startRow );
rowReader.getRows(sheetIndex, curRow, rowlist, this.fileKey, this.startRow);
rowlist.clear();
curRow++;
curCol = 0;
}
}
}
public void characters(char[] ch, int start, int length)
throws SAXException {
//得到单元格内容的值
public void characters(char[] ch, int start, int length) throws SAXException {
// 得到单元格内容的值
lastContents += new String(ch, start, length);
}
}
......@@ -20,20 +20,20 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* 抽象excel2007读入器,先构建.xlsx一张模板,改写模板中的sheet.xml,使用这种方法
* 写入.xlsx文件,不需要太大的内存
* 抽象excel2007读入器,先构建.xlsx一张模板,改写模板中的sheet.xml,使用这种方法 写入.xlsx文件,不需要太大的内存
*
*/
public abstract class AbstractExcel2007Writer {
private SpreadsheetWriter sw;
/**
* 写入电子表格的主要流程
*
* @param fileName
* @throws Exception
*/
public void process(String fileName) throws Exception{
public void process(String fileName) throws Exception {
// 建立工作簿和电子表格对象
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("sheet1");
......@@ -44,29 +44,30 @@ public abstract class AbstractExcel2007Writer {
FileOutputStream os = new FileOutputStream("template.xlsx");
wb.write(os);
os.close();
// 生成xml文件
File tmp = File.createTempFile("sheet", ".xml");
Writer fw = new FileWriter(tmp);
sw = new SpreadsheetWriter(fw);
generate();
fw.close();
// 使用产生的数据替换模板
File templateFile = new File("template.xlsx");
FileOutputStream out = new FileOutputStream(fileName);
substitute(templateFile, tmp, sheetRef.substring(1), out);
out.close();
//删除文件之前调用一下垃圾回收器,否则无法删除模板文件
// 删除文件之前调用一下垃圾回收器,否则无法删除模板文件
System.gc();
// 删除临时模板文件
if (templateFile.isFile()&&templateFile.exists()){
if (templateFile.isFile() && templateFile.exists()) {
templateFile.delete();
}
}
/**
* 类使用者应该使用此方法进行写操作
*
* @throws Exception
*/
public abstract void generate() throws Exception;
......@@ -99,34 +100,32 @@ public abstract class AbstractExcel2007Writer {
*
* @param zipfile the template file
* @param tmpfile the XML file with the sheet data
* @param entry the name of the sheet entry to substitute, e.g. xl/worksheets/sheet1.xml
* @param out the stream to write the result to
* @param entry the name of the sheet entry to substitute, e.g.
* xl/worksheets/sheet1.xml
* @param out the stream to write the result to
*/
private static void substitute(File zipfile, File tmpfile, String entry,
OutputStream out) throws IOException {
ZipFile zip = new ZipFile(zipfile);
ZipOutputStream zos = new ZipOutputStream(out);
@SuppressWarnings("unchecked")
Enumeration<ZipEntry> en = (Enumeration<ZipEntry>) zip.entries();
while (en.hasMoreElements()) {
ZipEntry ze = en.nextElement();
if (!ze.getName().equals(entry)) {
zos.putNextEntry(new ZipEntry(ze.getName()));
InputStream is = zip.getInputStream(ze);
private static void substitute(File zipfile, File tmpfile, String entry, OutputStream out) throws IOException {
try (ZipFile zip = new ZipFile(zipfile); ZipOutputStream zos = new ZipOutputStream(out)) {
@SuppressWarnings("unchecked")
Enumeration<ZipEntry> en = (Enumeration<ZipEntry>) zip.entries();
while (en.hasMoreElements()) {
ZipEntry ze = en.nextElement();
if (!ze.getName().equals(entry)) {
zos.putNextEntry(new ZipEntry(ze.getName()));
InputStream is = zip.getInputStream(ze);
copyStream(is, zos);
is.close();
}
}
zos.putNextEntry(new ZipEntry(entry));
try (InputStream is = new FileInputStream(tmpfile)) {
copyStream(is, zos);
is.close();
}
}
zos.putNextEntry(new ZipEntry(entry));
InputStream is = new FileInputStream(tmpfile);
copyStream(is, zos);
is.close();
zos.close();
}
private static void copyStream(InputStream in, OutputStream out)
throws IOException {
private static void copyStream(InputStream in, OutputStream out) throws IOException {
byte[] chunk = new byte[1024];
int count;
while ((count = in.read(chunk)) >= 0) {
......@@ -149,8 +148,8 @@ public abstract class AbstractExcel2007Writer {
public void beginSheet() throws IOException {
_out.write("<?xml version=\"1.0\" encoding=\"GB2312\"?>"
+ "<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">");
_out.write("<sheetData>"+LINE_SEPARATOR);
+ "<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">");
_out.write("<sheetData>" + LINE_SEPARATOR);
}
public void endSheet() throws IOException {
......@@ -164,7 +163,7 @@ public abstract class AbstractExcel2007Writer {
* @param rownum 以0开始
*/
public void insertRow(int rownum) throws IOException {
_out.write("<row r=\"" + (rownum + 1) + "\">"+LINE_SEPARATOR);
_out.write("<row r=\"" + (rownum + 1) + "\">" + LINE_SEPARATOR);
this._rownum = rownum;
}
......@@ -172,37 +171,33 @@ public abstract class AbstractExcel2007Writer {
* 插入行结束标志
*/
public void endRow() throws IOException {
_out.write("</row>"+LINE_SEPARATOR);
_out.write("</row>" + LINE_SEPARATOR);
}
/**
* 插入新列
*
* @param columnIndex
* @param value
* @param styleIndex
* @throws IOException
*/
public void createCell(int columnIndex, String value, int styleIndex)
throws IOException {
String ref = new CellReference(_rownum, columnIndex)
.formatAsString();
public void createCell(int columnIndex, String value, int styleIndex) throws IOException {
String ref = new CellReference(_rownum, columnIndex).formatAsString();
_out.write("<c r=\"" + ref + "\" t=\"inlineStr\"");
if (styleIndex != -1)
_out.write(" s=\"" + styleIndex + "\"");
_out.write(">");
_out.write("<is><t>"+XMLEncoder.encode(value)+"</t></is>");
_out.write("<is><t>" + XMLEncoder.encode(value) + "</t></is>");
_out.write("</c>");
}
public void createCell(int columnIndex, String value)
throws IOException {
public void createCell(int columnIndex, String value) throws IOException {
createCell(columnIndex, value, -1);
}
public void createCell(int columnIndex, double value, int styleIndex)
throws IOException {
String ref = new CellReference(_rownum, columnIndex)
.formatAsString();
public void createCell(int columnIndex, double value, int styleIndex) throws IOException {
String ref = new CellReference(_rownum, columnIndex).formatAsString();
_out.write("<c r=\"" + ref + "\" t=\"n\"");
if (styleIndex != -1)
_out.write(" s=\"" + styleIndex + "\"");
......@@ -211,15 +206,12 @@ public abstract class AbstractExcel2007Writer {
_out.write("</c>");
}
public void createCell(int columnIndex, double value)
throws IOException {
public void createCell(int columnIndex, double value) throws IOException {
createCell(columnIndex, value, -1);
}
public void createCell(int columnIndex, Calendar value, int styleIndex)
throws IOException {
createCell(columnIndex, DateUtil.getExcelDate(value, false),
styleIndex);
public void createCell(int columnIndex, Calendar value, int styleIndex) throws IOException {
createCell(columnIndex, DateUtil.getExcelDate(value, false), styleIndex);
}
}
}
\ No newline at end of file
......@@ -18,7 +18,7 @@ public class Excel2003Writer {
try{
writeExcel("tes2003.xls");
} catch (IOException e) {
e.printStackTrace();
}
}
......
package com.x.calendar.assemble.control.service;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.time.Duration;
......@@ -9,8 +8,6 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.x.base.core.project.tools.StringTools;
import com.x.calendar.core.entity.Calendar_EventComment;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
......@@ -23,12 +20,12 @@ import com.x.base.core.project.tools.ListTools;
import com.x.calendar.assemble.control.Business;
import com.x.calendar.common.date.DateOperation;
import com.x.calendar.core.entity.Calendar_Event;
import com.x.calendar.core.entity.Calendar_EventComment;
import com.x.calendar.core.entity.Calendar_EventRepeatMaster;
import net.fortuna.ical4j.data.CalendarOutputter;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.DateTime;
import net.fortuna.ical4j.model.Dur;
import net.fortuna.ical4j.model.Recur;
import net.fortuna.ical4j.model.TimeZone;
import net.fortuna.ical4j.model.TimeZoneRegistry;
......@@ -828,12 +825,12 @@ public class Calendar_EventServiceAdv {
* @throws ValidationException
* @throws IOException
*/
public void writeiCal(Calendar_Event o2_calendar_event, String path) throws ValidationException, IOException {
Calendar calendar = parseToiCal(o2_calendar_event);
FileOutputStream fout = new FileOutputStream("D://2.ics");
CalendarOutputter outputter = new CalendarOutputter();
outputter.output(calendar, fout);
}
// public void writeiCal(Calendar_Event o2_calendar_event, String path) throws ValidationException, IOException {
// Calendar calendar = parseToiCal(o2_calendar_event);
// FileOutputStream fout = new FileOutputStream("D://2.ics");
// CalendarOutputter outputter = new CalendarOutputter();
// outputter.output(calendar, fout);
// }
/**
* 将一个日程事件写为一个ical文件
......@@ -859,9 +856,10 @@ public class Calendar_EventServiceAdv {
public String getiCalContent(Calendar_Event o2_calendar_event) throws ValidationException, IOException {
Calendar calendar = parseToiCal(o2_calendar_event);
CalendarOutputter calendarOutputter = new CalendarOutputter(false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
calendarOutputter.output(calendar, baos);
return new String(baos.toByteArray(), "utf-8");
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
calendarOutputter.output(calendar, baos);
return new String(baos.toByteArray(), "utf-8");
}
}
/**
......@@ -877,8 +875,6 @@ public class Calendar_EventServiceAdv {
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
return calendar_EventService.listNeedAlarmEventIds(emc, date);
} catch (Exception e) {
throw e;
}
}
......@@ -957,9 +953,7 @@ public class Calendar_EventServiceAdv {
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
return calendar_EventService.destoryWithBundle(emc, bundle);
} catch (Exception e) {
throw e;
}
}
}
/**
......@@ -975,8 +969,6 @@ public class Calendar_EventServiceAdv {
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
return emc.find(commentId, Calendar_EventComment.class);
} catch (Exception e) {
throw e;
}
}
}
......@@ -20,91 +20,93 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* 抽象excel2007读入器,先构建.xlsx一张模板,改写模板中的sheet.xml,使用这种方法
* 写入.xlsx文件,不需要太大的内存
* 抽象excel2007读入器,先构建.xlsx一张模板,改写模板中的sheet.xml,使用这种方法 写入.xlsx文件,不需要太大的内存
*
*/
public abstract class AbstractExcel2007Writer {
private SpreadsheetWriter sw;
/**
* 写入电子表格的主要流程
*
* @param fileName
* @throws Exception
*/
@SuppressWarnings("resource")
public void process( String fileName ) throws Exception{
public void process(String fileName) throws Exception {
// 建立工作簿和电子表格对象
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet( "sheet1" );
XSSFSheet sheet = wb.createSheet("sheet1");
// 持有电子表格数据的xml文件名 例如 /xl/worksheets/sheet1.xml
String sheetRef = sheet.getPackagePart().getPartName().getName();
// 保存模板
FileOutputStream os = new FileOutputStream( "template.xlsx" );
FileOutputStream os = new FileOutputStream("template.xlsx");
wb.write(os);
os.close();
// 生成xml文件
File tmp = File.createTempFile( "sheet", ".xml" );
File tmp = File.createTempFile("sheet", ".xml");
Writer fw = new FileWriter(tmp);
sw = new SpreadsheetWriter(fw);
generate();
fw.close();
// 使用产生的数据替换模板
File templateFile = new File( "template.xlsx" );
File templateFile = new File("template.xlsx");
FileOutputStream out = new FileOutputStream(fileName);
substitute(templateFile, tmp, sheetRef.substring(1), out);
out.close();
//删除文件之前调用一下垃圾回收器,否则无法删除模板文件
// 删除文件之前调用一下垃圾回收器,否则无法删除模板文件
System.gc();
// 删除临时模板文件
if (templateFile.isFile()&&templateFile.exists()){
if (templateFile.isFile() && templateFile.exists()) {
templateFile.delete();
}
}
/**
* 写入电子表格的主要流程
*
* @param fileName
* @throws Exception
*/
@SuppressWarnings("resource")
public void process( OutputStream out ) throws Exception{
public void process(OutputStream out) throws Exception {
// 建立工作簿和电子表格对象
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet( "sheet1" );
XSSFSheet sheet = wb.createSheet("sheet1");
// 持有电子表格数据的xml文件名 例如 /xl/worksheets/sheet1.xml
String sheetRef = sheet.getPackagePart().getPartName().getName();
// 保存模板
FileOutputStream os = new FileOutputStream( "template.xlsx" );
FileOutputStream os = new FileOutputStream("template.xlsx");
wb.write(os);
os.close();
// 生成xml文件
File tmp = File.createTempFile( "sheet", ".xml" );
File tmp = File.createTempFile("sheet", ".xml");
Writer fw = new FileWriter(tmp);
sw = new SpreadsheetWriter(fw);
generate();
fw.close();
// 使用产生的数据替换模板
File templateFile = new File( "template.xlsx" );
File templateFile = new File("template.xlsx");
substitute(templateFile, tmp, sheetRef.substring(1), out);
out.close();
//删除文件之前调用一下垃圾回收器,否则无法删除模板文件
// 删除文件之前调用一下垃圾回收器,否则无法删除模板文件
System.gc();
// 删除临时模板文件
if (templateFile.isFile()&&templateFile.exists()){
if (templateFile.isFile() && templateFile.exists()) {
templateFile.delete();
}
}
/**
* 类使用者应该使用此方法进行写操作
*
* @throws Exception
*/
public abstract void generate() throws Exception;
......@@ -137,35 +139,32 @@ public abstract class AbstractExcel2007Writer {
*
* @param zipfile the template file
* @param tmpfile the XML file with the sheet data
* @param entry the name of the sheet entry to substitute, e.g. xl/worksheets/sheet1.xml
* @param out the stream to write the result to
* @param entry the name of the sheet entry to substitute, e.g.
* xl/worksheets/sheet1.xml
* @param out the stream to write the result to
*/
@SuppressWarnings("resource")
private static void substitute(File zipfile, File tmpfile, String entry,
OutputStream out) throws IOException {
ZipFile zip = new ZipFile(zipfile);
ZipOutputStream zos = new ZipOutputStream(out);
@SuppressWarnings( "unchecked" )
Enumeration<ZipEntry> en = (Enumeration<ZipEntry>) zip.entries();
while (en.hasMoreElements()) {
ZipEntry ze = en.nextElement();
if (!ze.getName().equals(entry)) {
zos.putNextEntry(new ZipEntry(ze.getName()));
InputStream is = zip.getInputStream(ze);
private static void substitute(File zipfile, File tmpfile, String entry, OutputStream out) throws IOException {
try (ZipFile zip = new ZipFile(zipfile); ZipOutputStream zos = new ZipOutputStream(out)) {
@SuppressWarnings("unchecked")
Enumeration<ZipEntry> en = (Enumeration<ZipEntry>) zip.entries();
while (en.hasMoreElements()) {
ZipEntry ze = en.nextElement();
if (!ze.getName().equals(entry)) {
zos.putNextEntry(new ZipEntry(ze.getName()));
InputStream is = zip.getInputStream(ze);
copyStream(is, zos);
is.close();
}
}
zos.putNextEntry(new ZipEntry(entry));
try (InputStream is = new FileInputStream(tmpfile)) {
copyStream(is, zos);
is.close();
}
}
zos.putNextEntry(new ZipEntry(entry));
InputStream is = new FileInputStream(tmpfile);
copyStream(is, zos);
is.close();
zos.close();
}
private static void copyStream(InputStream in, OutputStream out)
throws IOException {
private static void copyStream(InputStream in, OutputStream out) throws IOException {
byte[] chunk = new byte[1024];
int count;
while ((count = in.read(chunk)) >= 0) {
......@@ -180,21 +179,21 @@ public abstract class AbstractExcel2007Writer {
public static class SpreadsheetWriter {
private final Writer _out;
private int _rownum;
private static String LINE_SEPARATOR = System.getProperty( "line.separator" );
private static String LINE_SEPARATOR = System.getProperty("line.separator");
public SpreadsheetWriter(Writer out) {
_out = out;
}
public void beginSheet() throws IOException {
_out.write( "<?xml version=\"1.0\" encoding=\"GB2312\"?>"
+ "<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">" );
_out.write( "<sheetData>"+LINE_SEPARATOR);
_out.write("<?xml version=\"1.0\" encoding=\"GB2312\"?>"
+ "<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">");
_out.write("<sheetData>" + LINE_SEPARATOR);
}
public void endSheet() throws IOException {
_out.write( "</sheetData>" );
_out.write( "</worksheet>" );
_out.write("</sheetData>");
_out.write("</worksheet>");
}
/**
......@@ -203,7 +202,7 @@ public abstract class AbstractExcel2007Writer {
* @param rownum 以0开始
*/
public void insertRow(int rownum) throws IOException {
_out.write( "<row r=\"" + (rownum + 1) + "\">"+LINE_SEPARATOR);
_out.write("<row r=\"" + (rownum + 1) + "\">" + LINE_SEPARATOR);
this._rownum = rownum;
}
......@@ -211,54 +210,47 @@ public abstract class AbstractExcel2007Writer {
* 插入行结束标志
*/
public void endRow() throws IOException {
_out.write( "</row>"+LINE_SEPARATOR);
_out.write("</row>" + LINE_SEPARATOR);
}
/**
* 插入新列
*
* @param columnIndex
* @param value
* @param styleIndex
* @throws IOException
*/
public void createCell(int columnIndex, String value, int styleIndex)
throws IOException {
String ref = new CellReference(_rownum, columnIndex)
.formatAsString();
_out.write( "<c r=\"" + ref + "\" t=\"inlineStr\"" );
public void createCell(int columnIndex, String value, int styleIndex) throws IOException {
String ref = new CellReference(_rownum, columnIndex).formatAsString();
_out.write("<c r=\"" + ref + "\" t=\"inlineStr\"");
if (styleIndex != -1)
_out.write( " s=\"" + styleIndex + "\"" );
_out.write( ">" );
_out.write( "<is><t>"+XMLEncoder.encode(value)+"</t></is>" );
_out.write( "</c>" );
_out.write(" s=\"" + styleIndex + "\"");
_out.write(">");
_out.write("<is><t>" + XMLEncoder.encode(value) + "</t></is>");
_out.write("</c>");
}
public void createCell(int columnIndex, String value)
throws IOException {
public void createCell(int columnIndex, String value) throws IOException {
createCell(columnIndex, value, -1);
}
public void createCell(int columnIndex, double value, int styleIndex)
throws IOException {
String ref = new CellReference(_rownum, columnIndex)
.formatAsString();
_out.write( "<c r=\"" + ref + "\" t=\"n\"" );
public void createCell(int columnIndex, double value, int styleIndex) throws IOException {
String ref = new CellReference(_rownum, columnIndex).formatAsString();
_out.write("<c r=\"" + ref + "\" t=\"n\"");
if (styleIndex != -1)
_out.write( " s=\"" + styleIndex + "\"" );
_out.write( ">" );
_out.write( "<v>" + value + "</v>" );
_out.write( "</c>" );
_out.write(" s=\"" + styleIndex + "\"");
_out.write(">");
_out.write("<v>" + value + "</v>");
_out.write("</c>");
}
public void createCell(int columnIndex, double value)
throws IOException {
public void createCell(int columnIndex, double value) throws IOException {
createCell(columnIndex, value, -1);
}
public void createCell(int columnIndex, Calendar value, int styleIndex)
throws IOException {
createCell(columnIndex, DateUtil.getExcelDate(value, false),
styleIndex);
public void createCell(int columnIndex, Calendar value, int styleIndex) throws IOException {
createCell(columnIndex, DateUtil.getExcelDate(value, false), styleIndex);
}
}
}
\ No newline at end of file
......@@ -27,16 +27,18 @@ class ActionListPaging extends BaseAction {
ActionResult<List<Wo>> result = new ActionResult<>();
EntityManager em = emc.get(AppDict.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
Predicate p = cb.conjunction();;
Predicate p = cb.conjunction();
;
List<Wo> wos = emc.fetchDescPaging(AppDict.class, Wo.copier, p, page, size, AppDict.sequence_FIELDNAME);
wos.stream().forEach(wo -> {
try {
AppInfo appInfo = emc.find( wo.getAppId(), AppInfo.class );
if(appInfo != null){
AppInfo appInfo = emc.find(wo.getAppId(), AppInfo.class);
if (appInfo != null) {
wo.setAppName(appInfo.getAppName());
wo.setAppAlias(appInfo.getAppAlias());
}
} catch (Exception e) {
logger.error(e);
}
});
result.setData(wos);
......
package com.x.cms.assemble.control.jaxrs.script;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
......@@ -8,16 +14,16 @@ import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.cms.core.entity.AppInfo;
import com.x.cms.core.entity.element.Script;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import java.util.List;
class ActionListPaging extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionListPaging.class);
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, Integer page, Integer size) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<List<Wo>> result = new ActionResult<>();
......@@ -27,11 +33,12 @@ class ActionListPaging extends BaseAction {
List<Wo> wos = emc.fetchDescPaging(Script.class, Wo.copier, p, page, size, Script.sequence_FIELDNAME);
wos.stream().forEach(wo -> {
try {
AppInfo appInfo = emc.find( wo.getAppId(), AppInfo.class );
if(appInfo != null){
AppInfo appInfo = emc.find(wo.getAppId(), AppInfo.class);
if (appInfo != null) {
wo.setAppName(appInfo.getAppName());
}
} catch (Exception e) {
logger.error(e);
}
});
result.setData(wos);
......
......@@ -91,6 +91,7 @@ public class FileUtil {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
......@@ -119,6 +120,7 @@ public class FileUtil {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
......
......@@ -2,7 +2,6 @@ package com.x.query.assemble.designer.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.AnonymousCipherManagerUserJaxrsFilter;
import com.x.base.core.project.jaxrs.CipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/query/*", asyncSupported = true)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册