@SuppressWarnings("unchecked") private void handleAction( RenderVelocityAction action, String cmd, Vector[] args, HttpServletRequest request) { if (action != null) { // add parameter from path for (int p = 0; p < args[0].size(); p++) { action.putParam((String) args[0].get(p), (String) args[1].get(p)); } VelocityContext c = new VelocityContext(); try { c.put("action", action); c.put("encoding", action.encoding); c.put("cmd", cmd); // c.put("au", action.user); c.put("reqaddress", request.getRemoteAddr()); c.put("scheme", request.getScheme()); c.put("querystring", request.getQueryString()); if (c.get("querystring") == null) { c.put("querystring", ""); } String requesturl = request.getRequestURL().toString(); // c.put("mid", ma.user.mandantid); c.put("request", request); c.put("requesturl", requesturl); c.put("server", request.getServerName()); c.put("port", request.getServerPort()); String ref = request.getHeader("Referer"); if (ref == null) { ref = "#"; } c.put("referer", ref); // process and render template action.process(c); } catch (Exception ex) { ex.printStackTrace(); // action.makeErrorOutput("Internal Error", null, c); } } }
// doGet, doPost delegate to this method @SuppressWarnings("unchecked") public void doPGU(HttpServletRequest request, HttpServletResponse response, String method) { initVelocity(); // parse command and arguments from request path String pathinfo = request.getPathInfo(); if (pathinfo == null) { pathinfo = ""; } System.out.println("REQUEST: " + pathinfo); String cmd = null; StringTokenizer kk = new StringTokenizer(pathinfo, "/"); int i = 0; Vector[] args = {new Vector<String>(), new Vector<String>()}; if (kk.countTokens() != 0) { cmd = kk.nextToken(); while (kk.hasMoreTokens()) { String kkk = URLDecoder.decode(kk.nextToken()); System.out.println("[" + method + "] PATHINFO[" + i + "]: " + kkk); args[i % 2].add(kkk); i++; } } // Default-cmd == index if (cmd == null || cmd.equals("")) { cmd = "index"; } if ("keyinfo".equals(cmd)) { handleKeyInfo(request, response, method, cmd, args); } else if ("keygraph".equals(cmd)) { handleKeyGraph(request, response, method, cmd, args); } else if ("index".equals(cmd)) { RenderVelocityAction action = new RenderVelocityAction(request, response, method, "index.vm"); handleAction(action, cmd, args, request); } else if ("echo".equals(cmd)) { RenderVelocityAction action = new RenderVelocityAction(request, response, method, "echo.vm"); handleAction(action, cmd, args, request); } else if ("ajax_nodes_edges".equals(cmd)) { Element res = new Element("nodes_edges"); // add key String keyid = getValueString("keyid", args); if (keyid != null) { System.out.println("ajax_nodes_edges:: keyid=" + keyid); Vector<String> keyids = new Vector<String>(); // key basics OSDXKey key = getBackend().getKey(keyid); if (key != null) { res.addContent(key.getSimplePubKeyElement()); keyids.add(key.getKeyID()); // add keylogs and fromKeys Vector<KeyLog> logs = getBackend().getKeyLogsToID(key.getKeyID()); if (logs != null && logs.size() > 0) { for (KeyLog l : logs) { if (!keyids.contains(l.getKeyIDFrom())) { OSDXKey fromkey = getBackend().getKey(l.getKeyIDFrom()); if (fromkey != null) { res.addContent(fromkey.getSimplePubKeyElement()); keyids.add(fromkey.getKeyID()); } } res.addContent(l.toElement(false)); } } } } response.setContentType("text/xml"); try { PrintWriter out = response.getWriter(); out.println(Document.buildDocument(res).toStringCompact()); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } } }