File[] files = dir.listFiles();
for (int k = 0; k < files.length; k++) {
File file = files[k];
if (file.isFile()) {
InputStream in = new FileInputStream(file);
ZipEntry ze =
new ZipEntry(
"resources/"
+ bean.getId()
+ "/"
+ file.getName());
zip.putNextEntry(ze);
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
zip.write(buf, 0, len);
}
zip.closeEntry();
in.close();
}
}
}
// add images
File root =
new File(getServletContext().getRealPath("/"), imagesPath);
File[] files = root.listFiles();
for (int k = 0; k < files.length; k++) {
File file = files[k];
if (file.isFile()) {
InputStream in = new FileInputStream(file);
ZipEntry ze = new ZipEntry("images/" + file.getName());
zip.putNextEntry(ze);
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
zip.write(buf, 0, len);
}
zip.closeEntry();
in.close();
}
}
// add sections
Mapping.begin();
Vector sections = Section.listAll();
Mapping.rollback();
for (int i = 0; i < sections.size(); i++) {
Section section = (Section) sections.get(i);
try {
URL url =
new URL(
frontUrl+"/section/"
+ section.getId()
+ ".html?static=true&nocache=true");
BufferedReader reader =
new BufferedReader(
new InputStreamReader(url.openStream()));
String content = "<!-- �ON static export -->";
String line = "";
while (line != null) {
line = reader.readLine();
if (line != null) {
content += line;
}
}
ZipEntry ze =
new ZipEntry("section/" + section.getId() + ".html");
zip.putNextEntry(ze);
zip.write(content.getBytes());
zip.closeEntry();
} catch (Exception e) {
System.out.println(
"Static export error, section " + section.getId());
}
}
// add publications
Mapping.begin();
Vector publications = Publication.listAll();
Mapping.rollback();
for (int i = 0; i < publications.size(); i++) {
Publication publication = (Publication) publications.get(i);
try {
URL url =
new URL(
frontUrl+"/publication/"
+ publication.getId()
+ ".html?static=true&nocache=true");
BufferedReader reader =
new BufferedReader(
new InputStreamReader(url.openStream()));
String content = "<!-- �ON static export -->";
String line = "";
while (line != null) {
line = reader.readLine();
if (line != null) {
content += line;
}
}
ZipEntry ze =
new ZipEntry(
"publication/" + publication.getId() + ".html");
zip.putNextEntry(ze);
zip.write(content.getBytes());
zip.closeEntry();
} catch (Exception e) {
System.out.println(
"Static export error, publication "
+ publication.getId());
}
}
// add index
URL url =
new URL(
frontUrl+"?static=true&nocache=true");
BufferedReader reader =
new BufferedReader(new InputStreamReader(url.openStream()));
String content = "<!-- �ON static export -->";
String line = "";
while (line != null) {
line = reader.readLine();
if (line != null) {
content += line;
}
}
ZipEntry ze = new ZipEntry("section/index.html");
zip.putNextEntry(ze);
zip.write(content.getBytes());
zip.closeEntry();
ze = new ZipEntry("index.html");
zip.putNextEntry(ze);
String redirect =
"<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=section/index.html\">";
zip.write(redirect.getBytes());
zip.closeEntry();