+ * Returns a reply whose ID is a parameter in the given simple field set.
+ *
+ * @param simpleFieldSet
+ * The simple field set containing the ID of the reply
+ * @param parameterName
+ * The name under which the reply ID is stored in the simple
+ * field set
+ * @return The reply
+ * @throws FcpException
+ * if there is no reply ID stored under the given parameter
+ * name, or if the reply ID is invalid
+ */
+ protected PostReply getReply(SimpleFieldSet simpleFieldSet, String parameterName) throws FcpException {
+ try {
+ String replyId = simpleFieldSet.getString(parameterName);
+ Optional<PostReply> reply = core.getPostReply(replyId);
+ if (!reply.isPresent()) {
+ throw new FcpException("Could not load reply from “" + replyId + "”.");
+ }
+ return reply.get();
+ } catch (FSParseException fspe1) {
+ throw new FcpException("Could not reply ID from “" + parameterName + "”.", fspe1);
+ }
+ }
+
+ /**
+ * Creates a simple field set from the given Sone, including {@link Profile}
+ * information.
+ *
+ * @param sone
+ * The Sone to encode
+ * @param prefix
+ * The prefix for the field names (may be empty but not {@code
+ * null})
+ * @param localSone
+ * An optional local Sone that is used for Sone-specific data,
+ * such as if the Sone is followed by the local Sone
+ * @return The simple field set containing the given Sone
+ */
+ protected static SimpleFieldSet encodeSone(Sone sone, String prefix, Optional<Sone> localSone) {
+ SimpleFieldSetBuilder soneBuilder = new SimpleFieldSetBuilder();
+
+ soneBuilder.put(prefix + "ID", sone.getId());
+ soneBuilder.put(prefix + "Name", sone.getName());
+ 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;
+ }
+
+ return soneBuilder.get();
+ }
+
+ /**