}
String strMilis = Long.toString(System.currentTimeMillis());
//create a post with attributes set to given values
SiocPostBean post = new SiocPostBean();
post.setUri(request.getRequestURL()+"/"+Sha1sum.getInstance().calc(person.getMbox().toString()+strMilis));
post.setPostedBy(person);
post.setPostedResource(resourceUri);
post.setPostBody(postBody);
post.setPostedWhen(strMilis);
post.setPostTitle(postTitle);
post.setKeywords(hasKeywords);
// try {
// add new post on current resource to the reposistory and get its uri
if (parentPostUri != null && !"0".equals(parentPostUri)) {
//System.out.println("if");
postedResource.addPost(post, parentPostUri);
} else {
//System.out.println("else");
postedResource.addPost(post, null);
}
List<SiocPostBean> posts = postedResource.getRootPosts();
int postsNo = 0;
for (SiocPostBean p : posts) {
postsNo += p.getRepliesNo();
}
request.setAttribute("postUri", post.getUri());
request.setAttribute("postTitle", post.getPostTitle());
request.setAttribute("postsNo", postsNo);
request.setAttribute("parentPostUri", parentPostUri);
request.setAttribute("postedBy", post.getPostedBy().getMbox());
request.setAttribute("postedWhen", post.getPostedWhenNice());
request.setAttribute("postBody", post.getPostBody());
request.setAttribute("postKeywords", post.getKeywords());
request.getRequestDispatcher("siocPostNew_xml.jsp").forward(request,response);
/*} catch (AccessDeniedException e) {
e.printStackTrace();
}*/
return;
}
//as an action to "show more"
if (request.getParameter("postUri") != null) {
//System.out.println("show post - postUri set");
// this parameter provides information wheter the post's details
// should be showed or hidden
String action = request.getParameter("action");
String postUri = request.getParameter("postUri");
SiocPostBean post = getPost(postedResource, postUri);
// TODO error handling
if (post == null) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST,MISSING_ADD_POST_FORM_PARAM);
return;
}