Exemple #1
0
 private Sone createSone(FreenetURI insertUri, String fingerprint) {
   Sone sone = mock(Sone.class);
   when(sone.getInsertUri()).thenReturn(insertUri);
   when(sone.getFingerprint()).thenReturn(fingerprint);
   when(sone.getRootAlbum()).thenReturn(mock(Album.class));
   when(core.getSone(anyString())).thenReturn(of(sone));
   return sone;
 }
Exemple #2
0
 /** {@inheritDoc} */
 @Override
 public Object get(DataProvider dataProvider, Object object, String member) {
   Reply reply = (Reply) object;
   if ("likes".equals(member)) {
     return core.getLikes(reply);
   } else if (member.equals("liked")) {
     Sone currentSone = (Sone) dataProvider.getData("currentSone");
     return (currentSone != null) && (currentSone.isLikedReplyId(reply.getId()));
   }
   return super.get(dataProvider, object, member);
 }
 /**
  * Creates a JSON object that contains all options that are currently in effect for the given Sone
  * (or overall, if the given Sone is {@code null} ).
  *
  * @param currentSone The current Sone (may be {@code null})
  * @return The current options
  */
 private static JsonObject createJsonOptions(Sone currentSone) {
   JsonObject options = new JsonObject();
   if (currentSone != null) {
     options.put(
         "ShowNotification/NewSones",
         currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get());
     options.put(
         "ShowNotification/NewPosts",
         currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get());
     options.put(
         "ShowNotification/NewReplies",
         currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").get());
   }
   return options;
 }
Exemple #4
0
 /** {@inheritDoc} */
 @Override
 protected void handleRequest(FreenetRequest request, TemplateContext templateContext)
     throws RedirectException {
   if (request.getMethod() == Method.POST) {
     String type = request.getHttpRequest().getPartAsStringFailsafe("type", 16);
     String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36);
     String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
     Sone currentSone = getCurrentSone(request.getToadletContext());
     if ("post".equals(type)) {
       currentSone.addLikedPostId(id);
     } else if ("reply".equals(type)) {
       currentSone.addLikedReplyId(id);
     }
     throw new RedirectException(returnPage);
   }
 }
 public Set<Post> parsePosts(PostBuilderFactory postBuilderFactory) throws InvalidPostFound {
   Set<Post> posts = new HashSet<Post>();
   while (true) {
     String postPrefix = "/Posts/" + posts.size();
     String postId = getString(postPrefix + "/ID", null);
     if (postId == null) {
       break;
     }
     long postTime = getLong(postPrefix + "/Time", 0L);
     String postText = getString(postPrefix + "/Text", null);
     if (postAttributesAreInvalid(postTime, postText)) {
       throw new InvalidPostFound();
     }
     PostBuilder postBuilder =
         postBuilderFactory
             .newPostBuilder()
             .withId(postId)
             .from(sone.getId())
             .withTime(postTime)
             .withText(postText);
     String postRecipientId = getString(postPrefix + "/Recipient", null);
     if (postRecipientIsValid(postRecipientId)) {
       postBuilder.to(postRecipientId);
     }
     posts.add(postBuilder.build());
   }
   return posts;
 }
 public Set<PostReply> parsePostReplies(PostReplyBuilderFactory postReplyBuilderFactory) {
   Set<PostReply> replies = new HashSet<PostReply>();
   while (true) {
     String replyPrefix = "/Replies/" + replies.size();
     String replyId = getString(replyPrefix + "/ID", null);
     if (replyId == null) {
       break;
     }
     String postId = getString(replyPrefix + "/Post/ID", null);
     long replyTime = getLong(replyPrefix + "/Time", 0L);
     String replyText = getString(replyPrefix + "/Text", null);
     if ((postId == null) || (replyTime == 0) || (replyText == null)) {
       throw new InvalidPostReplyFound();
     }
     PostReplyBuilder postReplyBuilder =
         postReplyBuilderFactory
             .newPostReplyBuilder()
             .withId(replyId)
             .from(sone.getId())
             .to(postId)
             .withTime(replyTime)
             .withText(replyText);
     replies.add(postReplyBuilder.build());
   }
   return replies;
 }
Exemple #7
0
 /** {@inheritDoc} */
 @Override
 protected void processTemplate(FreenetRequest request, TemplateContext templateContext)
     throws RedirectException {
   super.processTemplate(request, templateContext);
   String albumId = request.getHttpRequest().getParam("album", null);
   if (albumId != null) {
     Album album = webInterface.getCore().getAlbum(albumId, false);
     templateContext.set("albumRequested", true);
     templateContext.set("album", album);
     templateContext.set("page", request.getHttpRequest().getParam("page"));
     return;
   }
   String imageId = request.getHttpRequest().getParam("image", null);
   if (imageId != null) {
     Image image = webInterface.getCore().getImage(imageId, false);
     templateContext.set("imageRequested", true);
     templateContext.set("image", image);
     return;
   }
   String soneId = request.getHttpRequest().getParam("sone", null);
   if (soneId != null) {
     Sone sone = webInterface.getCore().getSone(soneId, false);
     templateContext.set("soneRequested", true);
     templateContext.set("sone", sone);
     return;
   }
   String mode = request.getHttpRequest().getParam("mode", null);
   if ("gallery".equals(mode)) {
     templateContext.set("galleryRequested", true);
     List<Album> albums = new ArrayList<Album>();
     for (Sone sone : webInterface.getCore().getSones()) {
       albums.addAll(sone.getAllAlbums());
     }
     Collections.sort(albums, Album.TITLE_COMPARATOR);
     Pagination<Album> albumPagination =
         new Pagination<Album>(albums, 12)
             .setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
     templateContext.set("albumPagination", albumPagination);
     templateContext.set("albums", albumPagination.getItems());
     return;
   }
   Sone sone = getCurrentSone(request.getToadletContext(), false);
   templateContext.set("soneRequested", true);
   templateContext.set("sone", sone);
 }
 public ConfigurationSoneParser(Configuration configuration, Sone sone) {
   this.configuration = configuration;
   this.sone = sone;
   sonePrefix = "Sone/" + sone.getId();
 }