Package net.pterodactylus.sone.data

Examples of net.pterodactylus.sone.data.Profile


   */
  @Override
  protected JsonReturnObject createJsonObject(FreenetRequest request) {
    String fieldId = request.getHttpRequest().getParam("field");
    Sone currentSone = getCurrentSone(request.getToadletContext());
    Profile profile = currentSone.getProfile();
    Field field = profile.getFieldById(fieldId);
    if (field == null) {
      return createErrorJsonObject("invalid-field-id");
    }
    String name = request.getHttpRequest().getParam("name", "").trim();
    if (name.length() == 0) {
      return createErrorJsonObject("invalid-parameter-name");
    }
    Field existingField = profile.getFieldByName(name);
    if ((existingField != null) && !existingField.equals(field)) {
      return createErrorJsonObject("duplicate-field-name");
    }
    field.setName(name);
    currentSone.setProfile(profile);
View Full Code Here


   * {@inheritDoc}
   */
  @Override
  protected JsonReturnObject createJsonObject(FreenetRequest request) {
    Sone currentSone = getCurrentSone(request.getToadletContext());
    Profile profile = currentSone.getProfile();
    String fieldId = request.getHttpRequest().getParam("field");
    Field field = profile.getFieldById(fieldId);
    if (field == null) {
      return createErrorJsonObject("invalid-field-id");
    }
    String direction = request.getHttpRequest().getParam("direction");
    try {
      if ("up".equals(direction)) {
        profile.moveFieldUp(field);
      } else if ("down".equals(direction)) {
        profile.moveFieldDown(field);
      } else {
        return createErrorJsonObject("invalid-direction");
      }
    } catch (IllegalArgumentException iae1) {
      return createErrorJsonObject("not-possible");
View Full Code Here

     */
    @Override
    public String generateString(Sone sone) {
      StringBuilder soneString = new StringBuilder();
      soneString.append(sone.getName());
      Profile soneProfile = sone.getProfile();
      if (soneProfile.getFirstName() != null) {
        soneString.append(' ').append(soneProfile.getFirstName());
      }
      if (soneProfile.getMiddleName() != null) {
        soneString.append(' ').append(soneProfile.getMiddleName());
      }
      if (soneProfile.getLastName() != null) {
        soneString.append(' ').append(soneProfile.getLastName());
      }
      if (complete) {
        for (Field field : soneProfile.getFields()) {
          soneString.append(' ').append(field.getValue());
        }
      }
      return soneString.toString();
    }
View Full Code Here

    String profileMiddleName = profileXml.getValue("middle-name", null);
    String profileLastName = profileXml.getValue("last-name", null);
    Integer profileBirthDay = Numbers.safeParseInteger(profileXml.getValue("birth-day", null));
    Integer profileBirthMonth = Numbers.safeParseInteger(profileXml.getValue("birth-month", null));
    Integer profileBirthYear = Numbers.safeParseInteger(profileXml.getValue("birth-year", null));
    Profile profile = new Profile(sone).setFirstName(profileFirstName).setMiddleName(profileMiddleName).setLastName(profileLastName);
    profile.setBirthDay(profileBirthDay).setBirthMonth(profileBirthMonth).setBirthYear(profileBirthYear);
    /* avatar is processed after images are loaded. */
    String avatarId = profileXml.getValue("avatar", null);

    /* parse profile fields. */
    SimpleXML profileFieldsXml = profileXml.getNode("fields");
    if (profileFieldsXml != null) {
      for (SimpleXML fieldXml : profileFieldsXml.getNodes("field")) {
        String fieldName = fieldXml.getValue("field-name", null);
        String fieldValue = fieldXml.getValue("field-value", "");
        if (fieldName == null) {
          logger.log(Level.WARNING, String.format("Downloaded profile field for Sone %s with missing data! Name: %s, Value: %s", sone, fieldName, fieldValue));
          return null;
        }
        try {
          profile.addField(fieldName).setValue(fieldValue);
        } catch (IllegalArgumentException iae1) {
          logger.log(Level.WARNING, String.format("Duplicate field: %s", fieldName), iae1);
          return null;
        }
      }
    }

    /* parse posts. */
    SimpleXML postsXml = soneXml.getNode("posts");
    Set<Post> posts = new HashSet<Post>();
    if (postsXml == null) {
      /* TODO - mark Sone as bad. */
      logger.log(Level.WARNING, String.format("Downloaded Sone %s has no posts!", sone));
    } else {
      for (SimpleXML postXml : postsXml.getNodes("post")) {
        String postId = postXml.getValue("id", null);
        String postRecipientId = postXml.getValue("recipient", null);
        String postTime = postXml.getValue("time", null);
        String postText = postXml.getValue("text", null);
        if ((postId == null) || (postTime == null) || (postText == null)) {
          /* TODO - mark Sone as bad. */
          logger.log(Level.WARNING, String.format("Downloaded post for Sone %s with missing data! ID: %s, Time: %s, Text: %s", sone, postId, postTime, postText));
          return null;
        }
        try {
          PostBuilder postBuilder = core.postBuilder();
          /* TODO - parse time correctly. */
          postBuilder.withId(postId).from(sone.getId()).withTime(Long.parseLong(postTime)).withText(postText);
          if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
            postBuilder.to(postRecipientId);
          }
          posts.add(postBuilder.build());
        } catch (NumberFormatException nfe1) {
          /* TODO - mark Sone as bad. */
          logger.log(Level.WARNING, String.format("Downloaded post for Sone %s with invalid time: %s", sone, postTime));
          return null;
        }
      }
    }

    /* parse replies. */
    SimpleXML repliesXml = soneXml.getNode("replies");
    Set<PostReply> replies = new HashSet<PostReply>();
    if (repliesXml == null) {
      /* TODO - mark Sone as bad. */
      logger.log(Level.WARNING, String.format("Downloaded Sone %s has no replies!", sone));
    } else {
      for (SimpleXML replyXml : repliesXml.getNodes("reply")) {
        String replyId = replyXml.getValue("id", null);
        String replyPostId = replyXml.getValue("post-id", null);
        String replyTime = replyXml.getValue("time", null);
        String replyText = replyXml.getValue("text", null);
        if ((replyId == null) || (replyPostId == null) || (replyTime == null) || (replyText == null)) {
          /* TODO - mark Sone as bad. */
          logger.log(Level.WARNING, String.format("Downloaded reply for Sone %s with missing data! ID: %s, Post: %s, Time: %s, Text: %s", sone, replyId, replyPostId, replyTime, replyText));
          return null;
        }
        try {
          PostReplyBuilder postReplyBuilder = core.postReplyBuilder();
          /* TODO - parse time correctly. */
          postReplyBuilder.withId(replyId).from(sone.getId()).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
          replies.add(postReplyBuilder.build());
        } catch (NumberFormatException nfe1) {
          /* TODO - mark Sone as bad. */
          logger.log(Level.WARNING, String.format("Downloaded reply for Sone %s with invalid time: %s", sone, replyTime));
          return null;
        }
      }
    }

    /* parse liked post IDs. */
    SimpleXML likePostIdsXml = soneXml.getNode("post-likes");
    Set<String> likedPostIds = new HashSet<String>();
    if (likePostIdsXml == null) {
      /* TODO - mark Sone as bad. */
      logger.log(Level.WARNING, String.format("Downloaded Sone %s has no post likes!", sone));
    } else {
      for (SimpleXML likedPostIdXml : likePostIdsXml.getNodes("post-like")) {
        String postId = likedPostIdXml.getValue();
        likedPostIds.add(postId);
      }
    }

    /* parse liked reply IDs. */
    SimpleXML likeReplyIdsXml = soneXml.getNode("reply-likes");
    Set<String> likedReplyIds = new HashSet<String>();
    if (likeReplyIdsXml == null) {
      /* TODO - mark Sone as bad. */
      logger.log(Level.WARNING, String.format("Downloaded Sone %s has no reply likes!", sone));
    } else {
      for (SimpleXML likedReplyIdXml : likeReplyIdsXml.getNodes("reply-like")) {
        String replyId = likedReplyIdXml.getValue();
        likedReplyIds.add(replyId);
      }
    }

    /* parse albums. */
    SimpleXML albumsXml = soneXml.getNode("albums");
    List<Album> topLevelAlbums = new ArrayList<Album>();
    if (albumsXml != null) {
      for (SimpleXML albumXml : albumsXml.getNodes("album")) {
        String id = albumXml.getValue("id", null);
        String parentId = albumXml.getValue("parent", null);
        String title = albumXml.getValue("title", null);
        String description = albumXml.getValue("description", "");
        String albumImageId = albumXml.getValue("album-image", null);
        if ((id == null) || (title == null) || (description == null)) {
          logger.log(Level.WARNING, String.format("Downloaded Sone %s contains invalid album!", sone));
          return null;
        }
        Album parent = null;
        if (parentId != null) {
          parent = core.getAlbum(parentId, false);
          if (parent == null) {
            logger.log(Level.WARNING, String.format("Downloaded Sone %s has album with invalid parent!", sone));
            return null;
          }
        }
        Album album = core.getAlbum(id).setSone(sone).modify().setTitle(title).setDescription(description).update();
        if (parent != null) {
          parent.addAlbum(album);
        } else {
          topLevelAlbums.add(album);
        }
        SimpleXML imagesXml = albumXml.getNode("images");
        if (imagesXml != null) {
          for (SimpleXML imageXml : imagesXml.getNodes("image")) {
            String imageId = imageXml.getValue("id", null);
            String imageCreationTimeString = imageXml.getValue("creation-time", null);
            String imageKey = imageXml.getValue("key", null);
            String imageTitle = imageXml.getValue("title", null);
            String imageDescription = imageXml.getValue("description", "");
            String imageWidthString = imageXml.getValue("width", null);
            String imageHeightString = imageXml.getValue("height", null);
            if ((imageId == null) || (imageCreationTimeString == null) || (imageKey == null) || (imageTitle == null) || (imageWidthString == null) || (imageHeightString == null)) {
              logger.log(Level.WARNING, String.format("Downloaded Sone %s contains invalid images!", sone));
              return null;
            }
            long creationTime = Numbers.safeParseLong(imageCreationTimeString, 0L);
            int imageWidth = Numbers.safeParseInteger(imageWidthString, 0);
            int imageHeight = Numbers.safeParseInteger(imageHeightString, 0);
            if ((imageWidth < 1) || (imageHeight < 1)) {
              logger.log(Level.WARNING, String.format("Downloaded Sone %s contains image %s with invalid dimensions (%s, %s)!", sone, imageId, imageWidthString, imageHeightString));
              return null;
            }
            Image image = core.getImage(imageId).modify().setSone(sone).setKey(imageKey).setCreationTime(creationTime).update();
            image = image.modify().setTitle(imageTitle).setDescription(imageDescription).update();
            image = image.modify().setWidth(imageWidth).setHeight(imageHeight).update();
            album.addImage(image);
          }
        }
        album.modify().setAlbumImage(albumImageId).update();
      }
    }

    /* process avatar. */
    if (avatarId != null) {
      profile.setAvatar(core.getImage(avatarId, false));
    }

    /* okay, apparently everything was parsed correctly. Now import. */
    /* atomic setter operation on the Sone. */
    synchronized (sone) {
View Full Code Here

  @Override
  protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
    super.processTemplate(request, templateContext);
    ToadletContext toadletContenxt = request.getToadletContext();
    Sone currentSone = getCurrentSone(toadletContenxt);
    Profile profile = currentSone.getProfile();
    String firstName = profile.getFirstName();
    String middleName = profile.getMiddleName();
    String lastName = profile.getLastName();
    Integer birthDay = profile.getBirthDay();
    Integer birthMonth = profile.getBirthMonth();
    Integer birthYear = profile.getBirthYear();
    String avatarId = profile.getAvatar();
    List<Field> fields = profile.getFields();
    if (request.getMethod() == Method.POST) {
      if (request.getHttpRequest().getPartAsStringFailsafe("save-profile", 4).equals("true")) {
        firstName = request.getHttpRequest().getPartAsStringFailsafe("first-name", 256).trim();
        middleName = request.getHttpRequest().getPartAsStringFailsafe("middle-name", 256).trim();
        lastName = request.getHttpRequest().getPartAsStringFailsafe("last-name", 256).trim();
        birthDay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-day", 256).trim());
        birthMonth = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-month", 256).trim());
        birthYear = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-year", 256).trim());
        avatarId = request.getHttpRequest().getPartAsStringFailsafe("avatarId", 36);
        profile.setFirstName(firstName.length() > 0 ? firstName : null);
        profile.setMiddleName(middleName.length() > 0 ? middleName : null);
        profile.setLastName(lastName.length() > 0 ? lastName : null);
        profile.setBirthDay(birthDay).setBirthMonth(birthMonth).setBirthYear(birthYear);
        profile.setAvatar(webInterface.getCore().getImage(avatarId, false));
        for (Field field : fields) {
          String value = request.getHttpRequest().getPartAsStringFailsafe("field-" + field.getId(), 400);
          String filteredValue = filter(request.getHttpRequest().getHeader("Host"), value);
          field.setValue(filteredValue);
        }
        currentSone.setProfile(profile);
        webInterface.getCore().touchConfiguration();
        throw new RedirectException("editProfile.html");
      } else if (request.getHttpRequest().getPartAsStringFailsafe("add-field", 4).equals("true")) {
        String fieldName = request.getHttpRequest().getPartAsStringFailsafe("field-name", 256).trim();
        try {
          profile.addField(fieldName);
          currentSone.setProfile(profile);
          fields = profile.getFields();
          webInterface.getCore().touchConfiguration();
          throw new RedirectException("editProfile.html#profile-fields");
        } catch (IllegalArgumentException iae1) {
          templateContext.set("fieldName", fieldName);
          templateContext.set("duplicateFieldName", true);
        }
      } else {
        String id = getFieldId(request, "delete-field-");
        if (id != null) {
          throw new RedirectException("deleteProfileField.html?field=" + id);
        }
        id = getFieldId(request, "move-up-field-");
        if (id != null) {
          Field field = profile.getFieldById(id);
          if (field == null) {
            throw new RedirectException("invalid.html");
          }
          profile.moveFieldUp(field);
          currentSone.setProfile(profile);
          throw new RedirectException("editProfile.html#profile-fields");
        }
        id = getFieldId(request, "move-down-field-");
        if (id != null) {
          Field field = profile.getFieldById(id);
          if (field == null) {
            throw new RedirectException("invalid.html");
          }
          profile.moveFieldDown(field);
          currentSone.setProfile(profile);
          throw new RedirectException("editProfile.html#profile-fields");
        }
        id = getFieldId(request, "edit-field-");
        if (id != null) {
View Full Code Here

   */
  @Override
  protected JsonReturnObject createJsonObject(FreenetRequest request) {
    String fieldId = request.getHttpRequest().getParam("field");
    Sone currentSone = getCurrentSone(request.getToadletContext());
    Profile profile = currentSone.getProfile();
    Field field = profile.getFieldById(fieldId);
    if (field == null) {
      return createErrorJsonObject("invalid-field-id");
    }
    profile.removeField(field);
    currentSone.setProfile(profile);
    webInterface.getCore().touchConfiguration();
    return createSuccessJsonObject().put("field", new ObjectNode(instance).put("id", new TextNode(field.getId())));
  }
View Full Code Here

      return;
    }
    String lastInsertFingerprint = configuration.getStringValue(sonePrefix + "/LastInsertFingerprint").getValue("");

    /* load profile. */
    Profile profile = new Profile(sone);
    profile.setFirstName(configuration.getStringValue(sonePrefix + "/Profile/FirstName").getValue(null));
    profile.setMiddleName(configuration.getStringValue(sonePrefix + "/Profile/MiddleName").getValue(null));
    profile.setLastName(configuration.getStringValue(sonePrefix + "/Profile/LastName").getValue(null));
    profile.setBirthDay(configuration.getIntValue(sonePrefix + "/Profile/BirthDay").getValue(null));
    profile.setBirthMonth(configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").getValue(null));
    profile.setBirthYear(configuration.getIntValue(sonePrefix + "/Profile/BirthYear").getValue(null));

    /* load profile fields. */
    while (true) {
      String fieldPrefix = sonePrefix + "/Profile/Fields/" + profile.getFields().size();
      String fieldName = configuration.getStringValue(fieldPrefix + "/Name").getValue(null);
      if (fieldName == null) {
        break;
      }
      String fieldValue = configuration.getStringValue(fieldPrefix + "/Value").getValue("");
      profile.addField(fieldName).setValue(fieldValue);
    }

    /* load posts. */
    Set<Post> posts = new HashSet<Post>();
    while (true) {
      String postPrefix = sonePrefix + "/Posts/" + posts.size();
      String postId = configuration.getStringValue(postPrefix + "/ID").getValue(null);
      if (postId == null) {
        break;
      }
      String postRecipientId = configuration.getStringValue(postPrefix + "/Recipient").getValue(null);
      long postTime = configuration.getLongValue(postPrefix + "/Time").getValue((long) 0);
      String postText = configuration.getStringValue(postPrefix + "/Text").getValue(null);
      if ((postTime == 0) || (postText == null)) {
        logger.log(Level.WARNING, "Invalid post found, aborting load!");
        return;
      }
      PostBuilder postBuilder = postBuilder().withId(postId).from(sone.getId()).withTime(postTime).withText(postText);
      if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
        postBuilder.to(postRecipientId);
      }
      posts.add(postBuilder.build());
    }

    /* load replies. */
    Set<PostReply> replies = new HashSet<PostReply>();
    while (true) {
      String replyPrefix = sonePrefix + "/Replies/" + replies.size();
      String replyId = configuration.getStringValue(replyPrefix + "/ID").getValue(null);
      if (replyId == null) {
        break;
      }
      String postId = configuration.getStringValue(replyPrefix + "/Post/ID").getValue(null);
      long replyTime = configuration.getLongValue(replyPrefix + "/Time").getValue((long) 0);
      String replyText = configuration.getStringValue(replyPrefix + "/Text").getValue(null);
      if ((postId == null) || (replyTime == 0) || (replyText == null)) {
        logger.log(Level.WARNING, "Invalid reply found, aborting load!");
        return;
      }
      PostReplyBuilder postReplyBuilder = postReplyBuilder().withId(replyId).from(sone.getId()).to(postId).withTime(replyTime).withText(replyText);
      replies.add(postReplyBuilder.build());
    }

    /* load post likes. */
    Set<String> likedPostIds = new HashSet<String>();
    while (true) {
      String likedPostId = configuration.getStringValue(sonePrefix + "/Likes/Post/" + likedPostIds.size() + "/ID").getValue(null);
      if (likedPostId == null) {
        break;
      }
      likedPostIds.add(likedPostId);
    }

    /* load reply likes. */
    Set<String> likedReplyIds = new HashSet<String>();
    while (true) {
      String likedReplyId = configuration.getStringValue(sonePrefix + "/Likes/Reply/" + likedReplyIds.size() + "/ID").getValue(null);
      if (likedReplyId == null) {
        break;
      }
      likedReplyIds.add(likedReplyId);
    }

    /* load friends. */
    Set<String> friends = new HashSet<String>();
    while (true) {
      String friendId = configuration.getStringValue(sonePrefix + "/Friends/" + friends.size() + "/ID").getValue(null);
      if (friendId == null) {
        break;
      }
      friends.add(friendId);
    }

    /* load albums. */
    List<Album> topLevelAlbums = new ArrayList<Album>();
    int albumCounter = 0;
    while (true) {
      String albumPrefix = sonePrefix + "/Albums/" + albumCounter++;
      String albumId = configuration.getStringValue(albumPrefix + "/ID").getValue(null);
      if (albumId == null) {
        break;
      }
      String albumTitle = configuration.getStringValue(albumPrefix + "/Title").getValue(null);
      String albumDescription = configuration.getStringValue(albumPrefix + "/Description").getValue(null);
      String albumParentId = configuration.getStringValue(albumPrefix + "/Parent").getValue(null);
      String albumImageId = configuration.getStringValue(albumPrefix + "/AlbumImage").getValue(null);
      if ((albumTitle == null) || (albumDescription == null)) {
        logger.log(Level.WARNING, "Invalid album found, aborting load!");
        return;
      }
      Album album = getAlbum(albumId).setSone(sone).modify().setTitle(albumTitle).setDescription(albumDescription).setAlbumImage(albumImageId).update();
      if (albumParentId != null) {
        Album parentAlbum = getAlbum(albumParentId, false);
        if (parentAlbum == null) {
          logger.log(Level.WARNING, String.format("Invalid parent album ID: %s", albumParentId));
          return;
        }
        parentAlbum.addAlbum(album);
      } else {
        if (!topLevelAlbums.contains(album)) {
          topLevelAlbums.add(album);
        }
      }
    }

    /* load images. */
    int imageCounter = 0;
    while (true) {
      String imagePrefix = sonePrefix + "/Images/" + imageCounter++;
      String imageId = configuration.getStringValue(imagePrefix + "/ID").getValue(null);
      if (imageId == null) {
        break;
      }
      String albumId = configuration.getStringValue(imagePrefix + "/Album").getValue(null);
      String key = configuration.getStringValue(imagePrefix + "/Key").getValue(null);
      String title = configuration.getStringValue(imagePrefix + "/Title").getValue(null);
      String description = configuration.getStringValue(imagePrefix + "/Description").getValue(null);
      Long creationTime = configuration.getLongValue(imagePrefix + "/CreationTime").getValue(null);
      Integer width = configuration.getIntValue(imagePrefix + "/Width").getValue(null);
      Integer height = configuration.getIntValue(imagePrefix + "/Height").getValue(null);
      if ((albumId == null) || (key == null) || (title == null) || (description == null) || (creationTime == null) || (width == null) || (height == null)) {
        logger.log(Level.WARNING, "Invalid image found, aborting load!");
        return;
      }
      Album album = getAlbum(albumId, false);
      if (album == null) {
        logger.log(Level.WARNING, "Invalid album image encountered, aborting load!");
        return;
      }
      Image image = getImage(imageId).modify().setSone(sone).setCreationTime(creationTime).setKey(key).setTitle(title).setDescription(description).setWidth(width).setHeight(height).update();
      album.addImage(image);
    }

    /* load avatar. */
    String avatarId = configuration.getStringValue(sonePrefix + "/Profile/Avatar").getValue(null);
    if (avatarId != null) {
      profile.setAvatar(getImage(avatarId, false));
    }

    /* load options. */
    sone.getOptions().getBooleanOption("AutoFollow").set(configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").getValue(null));
    sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").set(configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").getValue(null));
View Full Code Here

      String sonePrefix = "Sone/" + sone.getId();
      configuration.getLongValue(sonePrefix + "/Time").setValue(sone.getTime());
      configuration.getStringValue(sonePrefix + "/LastInsertFingerprint").setValue(soneInserters.get(sone).getLastInsertFingerprint());

      /* save profile. */
      Profile profile = sone.getProfile();
      configuration.getStringValue(sonePrefix + "/Profile/FirstName").setValue(profile.getFirstName());
      configuration.getStringValue(sonePrefix + "/Profile/MiddleName").setValue(profile.getMiddleName());
      configuration.getStringValue(sonePrefix + "/Profile/LastName").setValue(profile.getLastName());
      configuration.getIntValue(sonePrefix + "/Profile/BirthDay").setValue(profile.getBirthDay());
      configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").setValue(profile.getBirthMonth());
      configuration.getIntValue(sonePrefix + "/Profile/BirthYear").setValue(profile.getBirthYear());
      configuration.getStringValue(sonePrefix + "/Profile/Avatar").setValue(profile.getAvatar());

      /* save profile fields. */
      int fieldCounter = 0;
      for (Field profileField : profile.getFields()) {
        String fieldPrefix = sonePrefix + "/Profile/Fields/" + fieldCounter++;
        configuration.getStringValue(fieldPrefix + "/Name").setValue(profileField.getName());
        configuration.getStringValue(fieldPrefix + "/Value").setValue(profileField.getValue());
      }
      configuration.getStringValue(sonePrefix + "/Profile/Fields/" + fieldCounter + "/Name").setValue(null);
View Full Code Here

    soneBuilder.put(prefix + "NiceName", SoneAccessor.getNiceName(sone));
    soneBuilder.put(prefix + "LastUpdated", sone.getTime());
    if (localSone.isPresent()) {
      soneBuilder.put(prefix + "Followed", String.valueOf(localSone.get().hasFriend(sone.getId())));
    }
    Profile profile = sone.getProfile();
    soneBuilder.put(prefix + "Field.Count", profile.getFields().size());
    int fieldIndex = 0;
    for (Field field : profile.getFields()) {
      soneBuilder.put(prefix + "Field." + fieldIndex + ".Name", field.getName());
      soneBuilder.put(prefix + "Field." + fieldIndex + ".Value", field.getValue());
      ++fieldIndex;
    }
View Full Code Here

   */
  @Override
  protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
    super.processTemplate(request, templateContext);
    Sone currentSone = getCurrentSone(request.getToadletContext());
    Profile profile = currentSone.getProfile();

    /* get parameters from request. */
    String fieldId = request.getHttpRequest().getParam("field");
    Field field = profile.getFieldById(fieldId);
    if (field == null) {
      throw new RedirectException("invalid.html");
    }

    /* process the POST request. */
    if (request.getMethod() == Method.POST) {
      if (request.getHttpRequest().getPartAsStringFailsafe("cancel", 4).equals("true")) {
        throw new RedirectException("editProfile.html#profile-fields");
      }
      fieldId = request.getHttpRequest().getPartAsStringFailsafe("field", 36);
      field = profile.getFieldById(fieldId);
      if (field == null) {
        throw new RedirectException("invalid.html");
      }
      String name = request.getHttpRequest().getPartAsStringFailsafe("name", 256);
      Field existingField = profile.getFieldByName(name);
      if ((existingField == null) || (existingField.equals(field))) {
        field.setName(name);
        currentSone.setProfile(profile);
        throw new RedirectException("editProfile.html#profile-fields");
      }
View Full Code Here

TOP

Related Classes of net.pterodactylus.sone.data.Profile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.