String firstName = configuration.getStringValue(sonePrefix + "/Profile/FirstName").getValue(null);
String middleName = configuration.getStringValue(sonePrefix + "/Profile/MiddleName").getValue(null);
String lastName = configuration.getStringValue(sonePrefix + "/Profile/LastName").getValue(null);
+ Integer birthDay = configuration.getIntValue(sonePrefix + "/Profile/BirthDay").getValue(null);
+ Integer birthMonth = configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").getValue(null);
+ Integer birthYear = configuration.getIntValue(sonePrefix + "/Profile/BirthYear").getValue(null);
try {
Profile profile = new Profile();
profile.setFirstName(firstName);
profile.setMiddleName(middleName);
profile.setLastName(lastName);
+ profile.setBirthDay(birthDay).setBirthMonth(birthMonth).setBirthYear(birthYear);
Sone sone = getSone(id).setName(name).setTime(time).setRequestUri(new FreenetURI(requestUri)).setInsertUri(new FreenetURI(insertUri));
sone.setProfile(profile);
int postId = 0;
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());
int postId = 0;
for (Post post : sone.getPosts()) {
String postPrefix = sonePrefix + "/Post." + postId++;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.logging.Logging;
+import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.service.AbstractService;
import net.pterodactylus.util.xml.SimpleXML;
import net.pterodactylus.util.xml.XML;
String profileFirstName = profileXml.getValue("first-name", null);
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().setFirstName(profileFirstName).setMiddleName(profileMiddleName).setLastName(profileLastName);
+ profile.setBirthDay(profileBirthDay).setBirthMonth(profileBirthMonth).setBirthYear(profileBirthYear);
/* parse posts. */
SimpleXML postsXml = soneXml.getNode("posts");
/** The last name. */
private String lastName;
+ /** The day of the birth date. */
+ private Integer birthDay;
+
+ /** The month of the birth date. */
+ private Integer birthMonth;
+
+ /** The year of the birth date. */
+ private Integer birthYear;
+
/**
* Creates a new empty profile.
*/
this.firstName = profile.firstName;
this.middleName = profile.middleName;
this.lastName = profile.lastName;
+ this.birthDay = profile.birthDay;
+ this.birthMonth = profile.birthMonth;
+ this.birthYear = profile.birthYear;
}
//
return this;
}
+ /**
+ * Returns the day of the birth date.
+ *
+ * @return The day of the birth date (from 1 to 31)
+ */
+ public Integer getBirthDay() {
+ return birthDay;
+ }
+
+ /**
+ * Sets the day of the birth date.
+ *
+ * @param birthDay
+ * The day of the birth date (from 1 to 31)
+ * @return This profile (for method chaining)
+ */
+ public Profile setBirthDay(Integer birthDay) {
+ modified |= ((birthDay != null) && (!birthDay.equals(this.birthDay))) || (this.birthDay != null);
+ this.birthDay = birthDay;
+ return this;
+ }
+
+ /**
+ * Returns the month of the birth date.
+ *
+ * @return The month of the birth date (from 1 to 12)
+ */
+ public Integer getBirthMonth() {
+ return birthMonth;
+ }
+
+ /**
+ * Sets the month of the birth date.
+ *
+ * @param birthMonth
+ * The month of the birth date (from 1 to 12)
+ * @return This profile (for method chaining)
+ */
+ public Profile setBirthMonth(Integer birthMonth) {
+ modified |= ((birthMonth != null) && (!birthMonth.equals(this.birthMonth))) || (this.birthMonth != null);
+ this.birthMonth = birthMonth;
+ return this;
+ }
+
+ /**
+ * Returns the year of the birth date.
+ *
+ * @return The year of the birth date
+ */
+ public Integer getBirthYear() {
+ return birthYear;
+ }
+
+ /**
+ * Sets the year of the birth date.
+ *
+ * @param birthYear
+ * The year of the birth date
+ * @return This profile (for method chaining)
+ */
+ public Profile setBirthYear(Integer birthYear) {
+ modified |= ((birthYear != null) && (!birthYear.equals(this.birthYear))) || (this.birthYear != null);
+ this.birthYear = birthYear;
+ return this;
+ }
+
}
import net.pterodactylus.sone.data.Profile;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
+import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.template.Template;
import freenet.clients.http.ToadletContext;
String firstName = profile.getFirstName();
String middleName = profile.getMiddleName();
String lastName = profile.getLastName();
+ Integer birthDay = profile.getBirthDay();
+ Integer birthMonth = profile.getBirthMonth();
+ Integer birthYear = profile.getBirthYear();
if (request.getMethod() == Method.POST) {
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());
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);
if (profile.isModified()) {
currentSone.setProfile(profile);
}
template.set("firstName", firstName);
template.set("middleName", middleName);
template.set("lastName", lastName);
+ template.set("birthDay", birthDay);
+ template.set("birthMonth", birthMonth);
+ template.set("birthYear", birthYear);
}
//
Page.EditProfile.Label.FirstName=First name:
Page.EditProfile.Label.MiddleName=Middle name(s):
Page.EditProfile.Label.LastName=Last name:
+Page.EditProfile.Birthday.Title=Birthday
+Page.EditProfile.Birthday.Label.Day=Day:
+Page.EditProfile.Birthday.Label.Month=Month:
+Page.EditProfile.Birthday.Label.Year=Year:
Page.EditProfile.Page.Status.Changed=Your changes have been saved and will be inserted shortly.
Page.EditProfile.Button.Save=Save Profile
Page.EditProfile.Keys.Title=Sone Keys
WebInterface.DefaultText.FirstName=First name
WebInterface.DefaultText.MiddleName=Middle name(s)
WebInterface.DefaultText.LastName=Last name
+WebInterface.DefaultText.BirthDay=Day
+WebInterface.DefaultText.BirthMonth=Month
+WebInterface.DefaultText.BirthYear=Year
WebInterface.Confirmation.DeletePostButton=Yes, delete!
WebInterface.Confirmation.DeleteReplyButton=Yes, delete!
padding: 1em;
}
+#sone #edit-profile #birth-day, #sone #edit-profile #birth-month, #sone #edit-profile #birth-year {
+ display: inline;
+ width: 15em;
+}
+
+#sone #edit-profile #birth-day input, #sone #edit-profile #birth-month input, #sone #edit-profile #birth-year input {
+ width: 4em;
+ text-align: right;
+}
+
#sone .post {
padding: 1ex 0px;
border-bottom: solid 1px #ccc;
registerInputTextareaSwap("#sone #edit-profile input[name=first-name]", "WebInterface.DefaultText.FirstName", "first-name", true, true);
registerInputTextareaSwap("#sone #edit-profile input[name=middle-name]", "WebInterface.DefaultText.MiddleName", "middle-name", true, true);
registerInputTextareaSwap("#sone #edit-profile input[name=last-name]", "WebInterface.DefaultText.LastName", "last-name", true, true);
+ registerInputTextareaSwap("#sone #edit-profile input[name=birth-day]", "WebInterface.DefaultText.BirthDay", "birth-day", true, true);
+ registerInputTextareaSwap("#sone #edit-profile input[name=birth-month]", "WebInterface.DefaultText.BirthMonth", "birth-month", true, true);
+ registerInputTextareaSwap("#sone #edit-profile input[name=birth-year]", "WebInterface.DefaultText.BirthYear", "birth-year", true, true);
/* hide all the labels. */
$("#sone #edit-profile label").hide();
<input type="text" name="last-name" value="<% lastName|html>" />
</div>
+ <h1><%= Page.EditProfile.Birthday.Title|l10n|html></h1>
+
+ <div id="birth-day">
+ <label for="birth-day"><%= Page.EditProfile.Birthday.Label.Day|l10n|html></label>
+ <input type="text" name="birth-day" value="<% birthDay|html>" />
+ </div>
+
+ <div id="birth-month">
+ <label for="birth-month"><%= Page.EditProfile.Birthday.Label.Month|l10n|html></label>
+ <input type="text" name="birth-month" value="<% birthMonth|html>" />
+ </div>
+
+ <div id="birth-year">
+ <label for="birth-year"><%= Page.EditProfile.Birthday.Label.Year|l10n|html></label>
+ <input type="text" name="birth-year" value="<% birthYear|html>" />
+ </div>
+
<div>
<button type="submit"><%= Page.EditProfile.Button.Save|l10n|html></button>
</div>
<first-name><% currentSone.profile.firstName|xml></first-name>
<middle-name><% currentSone.profile.middleName|xml></middle-name>
<last-name><% currentSone.profile.lastName|xml></last-name>
+ <birth-day><% currentSone.profile.birthDay|xml></birth-day>
+ <birth-month><% currentSone.profile.birthMonth|xml></birth-month>
+ <birth-year><% currentSone.profile.birthYear|xml></birth-year>
</profile>
<posts>