Code with Finding: |
class ServerInputProcessor {
private void processPost() throws ConnectionException {
/* Verify the user is in the right place to create a post */
String boardName = currentPath[0];
boolean canPost = false;
if (boardName == null) {
sendWithNonce("print Must be within a board's region or in the freeforall board to create a post");
} else if (boardName.equals("freeforall")) {
String postNum = currentPath[1];
if (postNum == null) {
canPost = true;
} else {
sendWithNonce("print Must go back to the board page to create a post (not inside a post)");
}
} else { // in a regular board
String regionName = currentPath[1];
if (regionName == null) {
sendWithNonce("print Must be within a board's region or in the freeforall board to create a post");
} else {
String postNum = currentPath[2];
if (postNum == null) { // in a board, region, not in a post
canPost = true;
} else {
sendWithNonce("print Must go back to the region page to create a post (not inside a post)");
}
}
}
if (canPost) {
//AUTHORIZATION FUNCTION and EXISTS CHECK
String authToPost = SocialNetworkPosts.authorizedToPost(user, currentPath[0], currentPath[1]);
if (!authToPost.equals("true")) {
sendWithNonce(authToPost);
return ;
}
sendWithNonce("print Start typing your content. Type 'cancel' after any new line to cancel.;print "
+ "Press enter once to insert a new line.;print Press enter twice to submit.;askForInput ");
String content = recvWithNonce();
while (content.equals("")) {
sendWithNonce("print Content is empty. Please try again. Type 'cancel' to cancel.;askForInput ");
content = recvWithNonce();
}
boolean cancelled = content.trim().equals("cancel");
String additionalContent = "";
while (!cancelled) {
sendWithNonce("print ;askForInput ");
additionalContent = recvWithNonce();
if (additionalContent.equals("")) {
break;
} else if (additionalContent.trim().equals("cancel")) {
cancelled = true;
} else {
content += ";print \t" + additionalContent;
}
}
if (cancelled) {
sendWithNonce("print Post Creation cancelled");
} else {
sendWithNonce(SocialNetworkPosts.createPost(user, content,
currentPath[0], currentPath[1]));
}
}
}
}
|