}
/**
- * Returns the post with the given ID, optionally creating a new post.
- *
- * @param postId
- * The ID of the post to get
- * @param create
- * {@code true} it create a new post if no post with the given ID
- * exists, {@code false} to return {@code null}
- * @return The post, or {@code null} if there is no such post
+ * {@inheritDoc}
*/
@Override
- public Post getPost(String postId, boolean create) {
+ public Post getPost(String postId) {
synchronized (posts) {
- Post post = posts.get(postId);
- if ((post == null) && create) {
- post = new PostImpl(postId);
- posts.put(postId, post);
- }
- return post;
+ return posts.get(postId);
}
}
Set<Post> posts = new HashSet<Post>();
synchronized (bookmarkedPosts) {
for (String bookmarkedPostId : bookmarkedPosts) {
- Post post = getPost(bookmarkedPostId, false);
+ Post post = getPost(bookmarkedPostId);
if (post != null) {
posts.add(post);
}
public interface PostProvider {
/**
- * Returns the post with the given ID, if it exists. If it does not exist
- * and {@code create} is {@code false}, {@code null} is returned; otherwise,
- * a new post with the given ID is created and returned.
+ * Returns the post with the given ID.
*
* @param postId
* The ID of the post to return
- * @param create
- * {@code true} to create a new post if no post with the given ID
- * exists, {@code false} to return {@code null} instead
* @return The post with the given ID, or {@code null}
*/
- public Post getPost(String postId, boolean create);
+ public Post getPost(String postId);
}
protected Post getPost(SimpleFieldSet simpleFieldSet, String parameterName) throws FcpException {
try {
String postId = simpleFieldSet.getString(parameterName);
- Post post = core.getPost(postId, false);
+ Post post = core.getPost(postId);
if (post == null) {
throw new FcpException("Could not load post from “" + postId + "”.");
}
if (linkType == LinkType.POST) {
if (line.length() >= (7 + 36)) {
String postId = line.substring(7, 43);
- Post post = postProvider.getPost(postId, false);
+ Post post = postProvider.getPost(postId);
if ((post != null) && (post.getSone() != null)) {
parts.add(new PostPart(post));
} else {
for (StringTokenizer idTokenizer = new StringTokenizer(ids); idTokenizer.hasMoreTokens();) {
String id = idTokenizer.nextToken();
if (type.equals("post")) {
- Post post = webInterface.getCore().getPost(id, false);
+ Post post = webInterface.getCore().getPost(id);
if (post == null) {
continue;
}
*/
private String getPostId(String phrase) {
String postId = phrase.startsWith("post://") ? phrase.substring(7) : phrase;
- return (webInterface.getCore().getPost(postId, false) != null) ? postId : null;
+ return (webInterface.getCore().getPost(postId) != null) ? postId : null;
}
/**
@Override
protected String getPageTitle(FreenetRequest request) {
String postId = request.getHttpRequest().getParam("post");
- Post post = webInterface.getCore().getPost(postId, false);
+ Post post = webInterface.getCore().getPost(postId);
String title = "";
if ((post != null) && (post.getSone() != null)) {
title = post.getText().substring(0, Math.min(20, post.getText().length())) + "…";
@Override
protected JsonObject createJsonObject(FreenetRequest request) {
String postId = request.getHttpRequest().getParam("post");
- Post post = webInterface.getCore().getPost(postId, false);
+ Post post = webInterface.getCore().getPost(postId);
if ((post == null) || (post.getSone() == null)) {
return createErrorJsonObject("invalid-post-id");
}
@Override
protected JsonObject createJsonObject(FreenetRequest request) {
String postId = request.getHttpRequest().getParam("post");
- Post post = webInterface.getCore().getPost(postId, false);
+ Post post = webInterface.getCore().getPost(postId);
if (post == null) {
return createErrorJsonObject("invalid-post-id");
}
if (allIds.length() > 0) {
String[] ids = allIds.split(",");
for (String id : ids) {
- Post post = webInterface.getCore().getPost(id, false);
+ Post post = webInterface.getCore().getPost(id);
if (post == null) {
continue;
}
Core core = webInterface.getCore();
for (String id : ids) {
if (type.equals("post")) {
- Post post = core.getPost(id, false);
+ Post post = core.getPost(id);
if (post == null) {
continue;
}