Esempio n. 1
0
 public static KeyServerBackend getBackend() {
   if (backend == null) {
     Element eDB = getConfig().getChild("db");
     if (eDB != null) {
       File dataPath = null;
       String sDP = eDB.getChildText("data_path");
       if (sDP != null && sDP.length() > 0) {
         dataPath = new File(sDP);
         if (!dataPath.exists() || !dataPath.isDirectory()) {
           dataPath = null;
         }
       }
       if (dataPath != null) {
         System.out.println("data_path = " + dataPath.getAbsolutePath());
       }
       backend =
           PostgresBackend.init(
               eDB.getChildTextNN("user"),
               eDB.getChildTextNN("password"),
               eDB.getChildTextNN("name"),
               dataPath);
     } else {
       throw new RuntimeException("missing DB configuration");
     }
   }
   return backend;
 }
Esempio n. 2
0
 public int getIndex(TreeNode node) {
   XMLTreeNode n = (XMLTreeNode) node;
   int index = xml.getChildren().indexOf(n.xml);
   int count = xml.getChildren().size();
   for (int i = 0; i < count; i++) {
     if (xml.getChildren().get(i).getName().equals(n.xml.getName())) {
       index = i;
       break;
     }
   }
   System.out.println("index of " + n.xml.getName() + " :: " + index);
   return index;
 }
Esempio n. 3
0
  public static APICall fromElemet(Element e) {
    APICall c = new APICall();
    c.classname = e.getChildText("class");
    c.methodname = e.getChildText("method");
    Vector<Element> params = e.getChildren("param");
    if (params == null || params.size() == 0) {
      c.paramTypes = null;
      c.params = null;
    } else {
      int pCount = params.size();
      c.paramTypes = new Class[pCount];
      c.params = new Object[pCount];
      for (int i = 0; i < pCount; i++) {
        Element ep = params.get(i);
        String pUse = ep.getAttribute("use");
        if (pUse != null) {
          // replace with parameter
          c.paramTypes[i] = String.class;
          c.params[i] = "${" + pUse + "}";
          c.placeHolder.put(i, pUse);
        } else {
          String pType = ep.getAttribute("type");
          String value = ep.getText();
          if (value == null) value = "";

          if (pType.equalsIgnoreCase("int")) {
            c.paramTypes[i] = Integer.TYPE;
            c.params[i] = Integer.parseInt(value);
          } else if (pType.equalsIgnoreCase("byte")) {
            c.paramTypes[i] = Byte.TYPE;
            c.params[i] = Byte.parseByte(value);
          } else if (pType.equalsIgnoreCase("long")) {
            c.paramTypes[i] = Long.TYPE;
            c.params[i] = Long.parseLong(value);
          } else if (pType.equalsIgnoreCase("double")) {
            c.paramTypes[i] = Double.TYPE;
            c.params[i] = Double.parseDouble(value);
          } else if (pType.equalsIgnoreCase("float")) {
            c.paramTypes[i] = Float.TYPE;
            c.params[i] = Float.parseFloat(value);
          } else if (pType.equalsIgnoreCase("file")) {
            c.paramTypes[i] = File.class;
            c.params[i] = new File(value);
          } else {
            // use String for no type or anything else
            c.paramTypes[i] = String.class;
            c.params[i] = value;
          }
        }
      }
    }
    return c;
  }
Esempio n. 4
0
 public static Element getConfig() {
   if (config == null) {
     try {
       config =
           Document.fromStream(ActionServlet.class.getResourceAsStream("resources/config.xml"))
               .getRootElement();
       System.out.println("Config loaded from resources");
     } catch (Exception ex) {
       System.out.println("WARNING: config resource not found: using STATIC config!");
       config = new Element("config");
       String vmtemp = "/var/lib/tomcat6/webapps/osdx_keyserver/vm_templates";
       System.out.println("vmtemplatepath: " + vmtemp);
       config.addContent("vmtemplatepath", vmtemp);
       Element eDB = new Element("db");
       eDB.addContent("name", "jdbc:postgresql://localhost:5432/keyserverdb");
       eDB.addContent("user", "keyserver");
       eDB.addContent("password", "oo0oo_keyserverDBpassword_..Q..");
       eDB.addContent("data_path", "/home/neo/db_data");
       config.addContent(eDB);
     }
   }
   return config;
 }
Esempio n. 5
0
  // 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();
      }
    }
  }
Esempio n. 6
0
 public boolean isLeaf() {
   if (xml.getChildren().size() == 0) return true;
   return false;
 }
Esempio n. 7
0
 public int getChildCount() {
   return xml.getChildren().size();
 }
Esempio n. 8
0
 public TreeNode getChildAt(int childIndex) {
   if (isLeaf()) return null;
   return new XMLTreeNode(this, tree, xml.getChildren().get(childIndex));
 }