}
keyword = URLDecoder.decode(keyword, "UTF8");
System.out.println("Keyword to search : " + keyword);
TagModel tagModel = new TagModel();
Tag tag = tagModel.getByAlias(keyword);
if (tag != null) {
List<Tube> result = new ArrayList<Tube>();
int startPoint = (page - 1) * itemPerPage;
if (tag.getListTubeId().size() > startPoint) {
for (int i = startPoint; i < tag.getListTubeId().size(); i++) {
if (i == (itemPerPage + startPoint)) {
break;
}
String id = tag.getListTubeId().get(i).getValue();
System.out.println(id);
Tube tub = TubeModel.getByTubeId(id);
if (tub != null) {
result.add(tub);
}
}
} else {
page = 1;
for (int i = 0; i < tag.getListTubeId().size(); i++) {
if (i == itemPerPage) {
break;
}
String id = tag.getListTubeId().get(i).getValue();
Tube tub = TubeModel.getByTubeId(id);
if (tub != null) {
result.add(tub);
}
}
}
request.setAttribute("url", request.getRequestURL());
request.setAttribute("listCategory",
JavaCacheHandle.getCategory());
request.setAttribute("listChannel",
JavaCacheHandle.getChannels());
request.setAttribute("result", result);
request.setAttribute("currentPage", page);
request.setAttribute("keyword", keyword.replaceAll("\\+", " "));
request.setAttribute("totalResult", tag.getListTubeId().size());
request.getRequestDispatcher("/keyword_show.jsp").forward(request,
response);
} else {
System.out.println("Tag is not exits.");
response.sendRedirect("/home");