protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
ApplicationTemplate template = (ApplicationTemplate) req
.getAttribute("template");
ApplicationConfig config = (ApplicationConfig) req
.getAttribute("config");
log.warning("--------do post from test servlet---------");
BlobstoreService blobService = BlobstoreServiceFactory
.getBlobstoreService();
byte b[] = null;
try {
Map<String, List<BlobKey>> blobs = blobService.getUploads(req);
List<BlobKey> blobKeys = blobs.get("template");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
if (blobKeys != null && blobKeys.size() > 0) {
for (BlobKey blobKey : blobKeys) {
b = blobService.fetchData(blobKey, 0, 20);
if (b.length > 0) {
FileService fileService = FileServiceFactory
.getFileService();
AppEngineFile file = fileService
.getBlobFile(blobKey);
FileReadChannel readChannel = fileService
.openReadChannel(file, false);
InputStream is = Channels
.newInputStream(readChannel);
int nRead;
byte[] buffer = new byte[10240];
while ((nRead = is.read(buffer, 0, buffer.length)) != -1) {
bos.write(buffer, 0, nRead);
}
bos.flush();
}
}
ByteArrayInputStream bais = new ByteArrayInputStream(
bos.toByteArray());
ZipInputStream zis = new ZipInputStream(bais);
ZipEntry entry;
InputStreamReader isr = new InputStreamReader(zis);
while ((entry = zis.getNextEntry()) != null) {
log.warning("-----------------size " + entry.getSize());
char[] buffer = new char[10240];
StringBuilder strTemp = new StringBuilder();
int length;
while ((length = isr.read(buffer, 0, buffer.length)) != -1) {
strTemp.append(buffer, 0, length);
}
if (entry.toString().contains("home.php")) {
template.setHome(strTemp.toString());
log.warning("--------home ok---------");
} else if (entry.toString().contains("category.php")) {
template.setCategory(strTemp.toString());
log.warning("--------category ok---------");
} else if (entry.toString().contains("tag.php")) {
template.setTag(strTemp.toString());
log.warning("--------tag ok---------");
} else if (entry.toString().contains("search.php")) {
template.setSearch(strTemp.toString());
log.warning("--------search ok---------");
} else if (entry.toString().contains("style.css")) {
template.setCss(strTemp.toString());
log.warning("--------css ok---------");
} else if (entry.toString().contains("javascript.js")) {
template.setJs(strTemp.toString());
log.warning("--------js ok---------");
} else {
log.warning("--------not ok---------"
+ entry.toString());
}
// read the contents into the buffer
}
ApplicationTemplateModel.insert(config.getApplicationId(),
template);
CompileScriptEngine.removeCache();
resp.getWriter().println("Ok babe !");
}