@SuppressWarnings("deprecation")
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
BlobstoreService blobService = BlobstoreServiceFactory
.getBlobstoreService();
ImagesService imageService = ImagesServiceFactory.getImagesService();
try {
String action = req.getParameter("action");
String title = req.getParameter("title");
String content = req.getParameter("content");
String source = req.getParameter("source");
String category = req.getParameter("category");
String tags = req.getParameter("tags");
News obj = new News();
if (action != null && action.equals("add")) {
obj.setTitle(title);
obj.setAlias(StringHelper.replaceVietnamese(title));
News checkObj = NewsModel.getById(obj.getAlias());
if (checkObj != null) {
obj.setAlias(obj.getAlias() + "-"
+ IdUniqueHelper.getId().toLowerCase());
}
obj.setContent(content);
obj.setSource(source);
/*
* process thumb image
*/
try {
Map<String, List<BlobKey>> blobs = blobService
.getUploads(req);
List<BlobKey> blobKeys = blobs.get("img");
if (blobKeys != null && blobKeys.size() > 0) {
for (BlobKey blobKey : blobKeys) {
byte[] arr = blobService.fetchData(blobKey, 0, 20);
if (arr.length > 0) {
obj.setThumb(imageService
.getServingUrl(blobKey));
}
}