1 package org.cacert.gigi.pages.wot;
3 import java.io.IOException;
4 import java.util.HashMap;
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
9 import org.cacert.gigi.dbObjects.User;
10 import org.cacert.gigi.output.AssurancesDisplay;
11 import org.cacert.gigi.pages.Page;
12 import org.cacert.gigi.util.AuthorizationContext;
14 public class Points extends Page {
16 public static final String SUPPORT_PATH = "/support/user/*/points";
18 public static final String PATH = "/wot/points";
20 private static final int intStart = SUPPORT_PATH.indexOf('*');
22 private boolean support;
24 private AssurancesDisplay myDisplay;
26 private AssurancesDisplay toOtherDisplay;
28 public Points(boolean support) {
29 super(support ? "Support User Points" : "Points");
30 this.support = support;
31 myDisplay = new AssurancesDisplay("asArr", false, support);
32 toOtherDisplay = new AssurancesDisplay("otherAsArr", true, support);
36 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
39 String info = req.getPathInfo();
40 int id = Integer.parseInt(info.substring(intStart, info.length() - SUPPORT_PATH.length() + intStart + 1));
41 user = User.getById(id);
50 HashMap<String, Object> vars = new HashMap<String, Object>();
51 vars.put("support", support);
52 vars.put("username", user.getPreferredName().toString());
53 vars.put("pointlist", myDisplay);
54 vars.put("madelist", toOtherDisplay);
55 vars.put("asArr", user.getReceivedAssurances());
56 vars.put("otherAsArr", user.getMadeAssurances());
57 vars.put("assP", user.getAssurancePoints());
58 if (user.canAssure()) {
59 vars.put("expP", user.getExperiencePoints());
60 vars.put("maxP", user.getMaxAssurePoints());
62 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
66 public boolean isPermitted(AuthorizationContext ac) {
71 return ac.canSupport();
73 return ac.getTarget() instanceof User;