08 Март, 2010

richfaces modal panel for ajax request

layout.xhtml
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view locale="#{localeSelector.localeString}" contentType="text/html"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a="http://richfaces.org/a4j"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:rich="http://richfaces.org/rich" >
<html>
<head>
<!--...-->
</head>
<body>
<ui:include src="spiner.xhtml" />
<!--...-->
</body>
</html>
</f:view>


spiner.xhtml
 
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:a="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">

<rich:modalPanel id="spiner" resizeable="false" autosized="false"
moveable="false" width="200" height="65" shadowOpacity="0">
<f:facet name="header">One moment please..</f:facet>
<h:outputText value="Your request is being processed." />
<h:graphicImage value="/img/spinner.gif"
style="vertical-align: middle;" />
</rich:modalPanel>

<a:status onstart="Richfaces.showModalPanel('spiner')"
onstop="Richfaces.hideModalPanel('spiner')" />

</ui:composition>


it may fix following for Jboss Seam:
HTTP Status 503 – Concurrent call to conversation !!!

java zip utils


public static void main(String... strings) throws Exception {
File[] sourceFiles = { new File("D:\\download\\dbf\\BMP\\KEY.BMP"),//
new File("D:\\download\\favicon.ico"), //
new File("D:\\download\\SDelete.zip"), //
new File("D:\\download\\iepngfix\\") //
};
File rootDir = new File("D:\\download\\");
File zipFile = new File(rootDir, "download.zip");
ZipUtils.zip(rootDir, sourceFiles, zipFile, Deflater.DEFAULT_COMPRESSION);
for (String s : ZipUtils.unzip(zipFile)) {
System.out.println(s);
}
}


output

dbf/BMP/KEY.BMP
favicon.ico
SDelete.zip
iepngfix/.htaccess
iepngfix/blank.gif
iepngfix/checkerboard.gif
iepngfix/helix.gif
iepngfix/iepngfix.htc
iepngfix/iepngfix.html
iepngfix/iepngfix.php
iepngfix/iepngfix_tilebg.js
iepngfix/opacity.png
iepngfix/opacity2.png
iepngfix/shadow.png



ru.olimpiks.common.utils.ZipUtils.java

package ru.olimpiks.common.utils;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

public class ZipUtils {
private static final int BATCH_SIZE = 4096;

private static long copyLarge(InputStream input, OutputStream output)
throws IOException {
byte buffer[] = new byte[BATCH_SIZE];
long count = 0L;
for (int n = 0; -1 != (n = input.read(buffer));) {
output.write(buffer, 0, n);
count += n;
}

return count;
}

private static final void closeQuietly(Closeable zos) {
try {
if (zos != null) {
zos.close();
}
} catch (Exception e) {
}
}

private static String normalizeEntryName(String entryName) {
return entryName.replace(File.separatorChar, '/');
}

private static String getEntryName(File rootDir, File zippedFile) {
if (rootDir != null && zippedFile.getPath().startsWith(rootDir.getPath())) {
return zippedFile.getPath().substring(rootDir.getPath().length() + 1);
} else {
return zippedFile.getPath();
}
}

private static void zipFile(File zippedFile, String entryName,
ZipOutputStream zos) throws FileNotFoundException, IOException {
FileInputStream fis = new FileInputStream(zippedFile);
ZipEntry anEntry = new ZipEntry(normalizeEntryName(entryName));
zos.putNextEntry(anEntry);
copyLarge(fis, zos);
fis.close();
zos.flush();
}

private static void zipDir(File zippedDir, String entryName,
ZipOutputStream zos) throws FileNotFoundException, IOException {
File[] dirList = zippedDir.listFiles();
for (File f : dirList) {
if (f.isDirectory()) {
zipDir(f, entryName + "/" + f.getName(), zos);
continue;
}
zipFile(f, entryName + "/" + f.getName(), zos);
}
}

public static final void zipFile(File rootDir, File zippedFile, File zipFile,
int level) throws FileNotFoundException, IOException {
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(
zipFile)));
zos.setLevel(level);
zipFile(zippedFile, getEntryName(rootDir, zippedFile), zos);
} finally {
closeQuietly(zos);
}
}

public static final void zipDir(File rootDir, File zippedDir, File zipFile,
int level) throws FileNotFoundException, IOException {
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(
zipFile)));
zos.setLevel(level);
zipDir(zippedDir, getEntryName(rootDir, zippedDir), zos);
} finally {
closeQuietly(zos);
}
}

public static final void zip(File rootDir, File[] zipped, File zipFile,
int level) throws FileNotFoundException, IOException {
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(
zipFile)));
zos.setLevel(level);
for (File f : zipped) {
if (f.isDirectory()) {
zipDir(f, getEntryName(rootDir, f), zos);
} else {
zipFile(f, getEntryName(rootDir, f), zos);
}
}
} finally {
closeQuietly(zos);
}
}

public static final void unzip(File zipFile, File outDir)
throws FileNotFoundException, IOException {
ZipInputStream in = null;
try {
in = new ZipInputStream(new BufferedInputStream(new FileInputStream(
zipFile)));
ZipEntry entry;
while ((entry = in.getNextEntry()) != null) {
File file = new File(outDir, entry.getName());
System.out.println(file);
if (!file.exists()) {
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
throw new IOException("Could not create directory : "
+ file.getParentFile());
}
if (!file.createNewFile()) {
throw new IOException("Could not create file : "
+ file.getParentFile());
}
}
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(file));
copyLarge(in, out);
out.flush();
out.close();
}
} finally {
closeQuietly(in);
}
}

public static final String[] unzip(File zipFile)
throws FileNotFoundException, IOException {
List<String> list = new ArrayList<String>(0);
ZipInputStream in = null;
try {
in = new ZipInputStream(new BufferedInputStream(new FileInputStream(
zipFile)));
ZipEntry entry;
while ((entry = in.getNextEntry()) != null) {
list.add(entry.getName());
}
return list.toArray(new String[0]);
} finally {
closeQuietly(in);
}
}
}