import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ReadXMLFile_bak {
public static String directory;
public static String fXmlFile;
public static String ZipedFileName;
public static void main(String argv[]) throws Exception {
ReadXMLFile_bak mLFile = new ReadXMLFile_bak();
mLFile.zippedJRXML();
}
public void zippedJRXML() throws Exception {
NodeList nList = getDocument().getElementsByTagName("jasperReport");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
List
files.add(fXmlFile);
files.addAll(getSubReportList(nNode));
files.addAll(getImageList(nNode));
createZip(files);
}
}
}
private List
Element eElement = (Element) node;
List
for (String sb : getTagValue("subreportExpression", eElement)) {
sb = sb.substring(1, sb.length() - 1);
if (!sb.contains("\\")) {
subReps.add(directory + sb);
System.out.println("subReps : " + directory + sb);
} else {
subReps.add(sb);
}
}
return subReps;
}
private List
Element eElement = (Element) node;
List
for (String sb : getTagValue("imageExpression", eElement)) {
sb = sb.substring(1, sb.length() - 1);
if (!sb.contains("\\")) {
images.add(directory + sb);
} else {
images.add(sb);
}
}
return images;
}
private List
int size = eElement.getElementsByTagName(sTag).getLength();
List
for (int i = 0; i < size; i++) {
NodeList nlList = eElement.getElementsByTagName(sTag).item(i).getChildNodes();
Node nValue = (Node) nlList.item(0);
list.add(nValue.getNodeValue());
}
return list;
}
private void createZip(List
FileOutputStream outputFile = new FileOutputStream(ZipedFileName);
ZipOutputStream zipFile = new ZipOutputStream(outputFile);
byte[] buffer = new byte[1024];
for (int i = 0; i < files.size(); i++) {
FileInputStream inFile = new FileInputStream(files.get(i));
zipFile.putNextEntry(new ZipEntry(files.get(i)));
int length;
while ((length = inFile.read(buffer)) > 0) {
zipFile.write(buffer, 0, length);
}
zipFile.closeEntry();
inFile.close();
}
System.out.println(".....Created ZIP file Successfully.....");
zipFile.close();
}
private Document getDocument() throws Exception {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
return doc;
}
}
Hiç yorum yok:
Yorum Gönder