package net.pterodactylus.wotns.ui.web;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
import net.pterodactylus.wotns.freenet.wot.IdentityManager;
import net.pterodactylus.wotns.freenet.wot.OwnIdentity;
import net.pterodactylus.wotns.web.FreenetRequest;
public class BasicPage extends FreenetTemplatePage {
protected final WebInterface webInterface;
+
protected final IdentityManager identityManager;
public BasicPage(WebInterface webInterface, String path, Template template) {
// PROTECTED METHODS
//
+ protected OwnIdentity getIdentity(FreenetRequest request) {
+ if (request.getMethod() == Method.POST) {
+ String ownIdentityId = request.getHttpRequest().getPartAsStringFailsafe("ownIdentity", 43);
+ return identityManager.getOwnIdentity(ownIdentityId);
+ } else if (request.getMethod() == Method.GET) {
+ String ownIdentityId = request.getHttpRequest().getParam("ownIdentity");
+ return identityManager.getOwnIdentity(ownIdentityId);
+ }
+ return null;
+ }
+
+ //
+ // FREENETTEMPLATEPAGE METHODS
+ //
+
/**
* {@inheritDoc}
*/
@Override
protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
super.processTemplate(request, templateContext);
-
- List<OwnIdentity> ownIdentities = new ArrayList<OwnIdentity>(webInterface.getWoTNSPlugin().getIdentityManager().getAllOwnIdentities());
- Collections.sort(ownIdentities, new Comparator<OwnIdentity>() {
-
- @Override
- public int compare(OwnIdentity leftOwnIdentity, OwnIdentity rightOwnIdentity) {
- return leftOwnIdentity.getNickname().compareTo(rightOwnIdentity.getNickname());
- }
- });
-
- templateContext.set("ownIdentities", ownIdentities);
+ templateContext.set("ownIdentities", identityManager.getAllOwnIdentities());
templateContext.set("formPassword", webInterface.getWoTNSPlugin().getToadletContainer().getFormPassword());
}
}