Ejemplo n.º 1
0
 public static void autoTime() {
   String pattern = "yyyy-MM-dd HH:mm:ss";
   SimpleDateFormat sdf = new SimpleDateFormat(pattern);
   // Parse a sample date starting at position 0.
   Calendar testTime = Calendar.getInstance();
   String text = "2011-8-3 22:18:00";
   testTime.setTime(sdf.parse(text, new ParsePosition(0)));
   Calendar testTime1 = Calendar.getInstance();
   String text1 = "2011-8-3 22:19:00";
   testTime1.setTime(sdf.parse(text1, new ParsePosition(0)));
   long f = testTime.getTimeInMillis() - testTime1.getTimeInMillis();
   int inter = testTime.compareTo(testTime1);
   Date now = Calendar.getInstance().getTime();
   int year = now.getYear() + 1900;
   int month = now.getMonth() + 1;
   int day = now.getDate();
   int hour = now.getHours();
   int minute = now.getMinutes();
   int second = now.getSeconds();
 }
Ejemplo n.º 2
0
 public boolean write() {
   try {
     Properties configFile = new Properties();
     configFile.load(new FileInputStream(settingsFile));
     configFile.put("SMTP_Host", mSMTPHost);
     configFile.put("SMTP_Port", mSMTPPort);
     configFile.put("POP3_Host", mPOP3Host);
     configFile.put("POP3_Port", mPOP3Port);
     configFile.put("From", mFrom);
     configFile.put("Password", mPass);
     configFile.put("Name", mName);
     configFile.put("Mails_Location", mMailsLocation);
     configFile.put("Contacts_Location", mContactsLocation);
     // TODO : There are some wrong and deprecated usage of date formatting, fix it.
     configFile.put(
         "Last_Update",
         Integer.toString(mLastUpdate.getYear() + 1900)
             + "/"
             + Integer.toString(mLastUpdate.getMonth())
             + "/"
             + Integer.toString(mLastUpdate.getDay())
             + "-"
             + Integer.toString(mLastUpdate.getHours())
             + "-"
             + Integer.toString(mLastUpdate.getMinutes())
             + "-"
             + Integer.toString(mLastUpdate.getSeconds()));
     FileOutputStream out = new FileOutputStream(settingsFile);
     // TODO : There is a usage of ini save method that deprecated.
     configFile.save(out, "properties updated");
   } catch (Exception e) {
     System.out.println("Write Exception:" + e.getMessage());
     return false;
   }
   return true;
 }
Ejemplo n.º 3
0
  /** Updates all train data and refreshes the GUI. */
  public static void timeTick(Date date, int delta) {
    if (!isPaused) {
      refreshUI += delta;
      double time = date.getHours() * 60 * 60 + date.getMinutes() * 60 + date.getSeconds();

      for (int i = 0; i < trainList.size(); i++) {
        // Update the data for each train.
        boolean isSelectedByTNC = false;
        if (!isSolo) {
          isSelectedByTNC = tncUI.uiSelect(trainList.get(i).id);
        }
        trainList.get(i).timeTick(time, ((double) (delta)) / 1000.0, isSolo, isSelectedByTNC);
      }

      if (refreshUI >= 1000) {
        // Refresh the train module GUI.

        if (isSolo) {
          // If TNM is running solo, figure out the new time.
          soloTime += 1;
          if (soloTime >= 24 * 60 * 60) {
            soloTime = soloTime % (24 * 60 * 60);
          }
          int hrs = (int) soloTime / (60 * 60);
          int min = ((int) soloTime / 60) % 60;
          int sec = (int) soloTime - (hrs * 60 * 60 + min * 60);
          soloDate = new Date(93, 2, 2, hrs, min, sec);
        } else {
          soloTime = time;
        }

        refreshUI = refreshUI % 1000;
        setSelectedId(selectedId);
      }
    }
  }
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      address = PAConfiguration.getAddress();
      port = PAConfiguration.getPort(instantiation);
      poslAddress = PAConfiguration.getPOSL(instantiation, topic);
      rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation);
      messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic);
    } catch (BadConfigurationException e) {
      System.out.println(e.getMessage());
      e.printStackTrace();
      System.exit(0);
    }
    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();

    try {
      System.out.println("5 Publicty Chair Servlet");
      System.out.println(response.toString());

      BufferedReader brd = request.getReader();

      String input = "";
      String message = "";

      while (!input.equals("</RuleML>")) {

        input = brd.readLine();

        message = message + input;
      }
      String[] varOrder = getVariableOrder(message);
      System.out.println("Received Message: " + message);

      //	BackwardReasoner br = new BackwardReasoner();
      //   Iterator solit =null;
      //   DefiniteClause dc = null;
      //   SymbolTable.reset();

      POSLParser pp = new POSLParser();
      // String contents = "c(a).\nc(b).\nc(c).";

      Date t1 = new GregorianCalendar().getTime();
      System.out.println(t1.getHours() + ":" + t1.getMinutes());
      // append time to contents

      System.out.println("day: " + t1.getDay());
      System.out.println("day: " + t1.getYear());
      System.out.println("day: " + t1.getMonth());

      // time
      String time = "time(" + t1.getHours() + ":integer).";
      System.out.println(time);

      String url = poslAddress;

      // String url = "http://www.jdrew.org/oojdrew/test.posl";
      String contents = "";

      // day of the week
      int day = t1.getDay();
      boolean weekday = true;

      if (day == 0 || day == 6) {
        weekday = false;
      }

      String dayOfWeek;

      if (weekday) {
        dayOfWeek = "day(weekday).";
      } else {
        dayOfWeek = "day(weekend).";
      }
      // full date
      Calendar cal = new GregorianCalendar();

      int year = cal.get(Calendar.YEAR);
      int month = cal.get(Calendar.MONTH) + 1;
      int day2 = cal.get(Calendar.DAY_OF_MONTH);

      String date;

      String day3 = "" + day2;

      if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7
          || day2 == 8 || day2 == 9) {

        day3 = "0" + day2;
      }

      if (month == 10 || month == 11 || month == 12) date = "" + year + month + day3;
      else date = "" + year + "0" + month + day3;

      date = "date(" + date + ":integer).";

      System.out.println(date);

      String url2 = rdfAddress;
      HttpClient client2 = new HttpClient();
      GetMethod method2 = new GetMethod(url2);
      method2.setFollowRedirects(true);
      String typestr = "";
      // Execute the GET method
      int statusCode2 = client2.executeMethod(method2);
      if (statusCode2 != -1) {
        typestr = method2.getResponseBodyAsString();
      }
      System.out.println("Types: " + typestr);
      Types.reset();
      RDFSParser.parseRDFSString(typestr);

      try {
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(url);
        method.setFollowRedirects(true);

        // Execute the GET method
        int statusCode = client.executeMethod(method);
        if (statusCode != -1) {
          contents = method.getResponseBodyAsString();
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      contents = contents + "\n" + time;
      contents = contents + "\n" + dayOfWeek;
      contents = contents + "\n" + date;

      BackwardReasoner br = new BackwardReasoner();
      Iterator solit = null;
      DefiniteClause dc = null;
      SymbolTable.reset();

      pp.parseDefiniteClauses(contents);

      br.loadClauses(pp.iterator());
      System.out.println("TEST");
      Iterator it = pp.iterator();
      while (it.hasNext()) {
        DefiniteClause d = (DefiniteClause) it.next();
        System.out.println("Loaded clause: " + d.toPOSLString());
      }

      br = new BackwardReasoner(br.clauses, br.oids);

      MessageParser m = new MessageParser(message);
      Element atom = null;

      try {

        atom = m.parseForContent();

      } catch (Exception e) {

        System.out.println("Invalid Message");
        // out.flush();

      }

      QueryBuilder q = new QueryBuilder(atom);
      String query = q.generateDoc();
      System.out.println("ABOUT TO INPUT THIS QUERY:" + query);
      RuleMLParser qp = new RuleMLParser();

      try {

        dc = qp.parseRuleMLQuery(query);

      } catch (Exception e) {
        System.out.println("Invalid Query");
        // out.flush();
      }

      // solit = br.iterativeDepthFirstSolutionIterator(dc);

      solit = br.iterativeDepthFirstSolutionIterator(dc);

      int varSize = 0;

      while (solit.hasNext()) {

        Vector data = new Vector();

        BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next();

        Hashtable varbind = gl.varBindings;
        javax.swing.tree.DefaultMutableTreeNode root = br.toTree();
        root.setAllowsChildren(true);

        javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root);

        int i = 0;
        Object[][] rowdata = new Object[varbind.size()][2];
        varSize = varbind.size();

        Enumeration e = varbind.keys();
        while (e.hasMoreElements()) {
          Object k = e.nextElement();
          Object val = varbind.get(k);
          String ks = (String) k;
          rowdata[i][0] = ks;
          rowdata[i][1] = val;
          i++;
        }

        data.addElement(rowdata);
        String[] messages = new String[data.size()];
        MessageGenerator g =
            new MessageGenerator(
                data, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel(), varOrder);
        messages = g.Messages2();

        String appender = "";

        URL sender = new URL(address + ":" + port);
        HttpMessage msg = new HttpMessage(sender);
        Properties props = new Properties();

        for (int i1 = 0; i1 < data.size(); i1++) {
          System.out.println(i1 + ")" + messages[i1].toString());
          props.put("text", messages[i1].toString());
          InputStream in = msg.sendGetMessage(props);
        }
        System.out.println("NEXT MESSAGE");
      }

      MessageGenerator g =
          new MessageGenerator(
              null, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel());

      URL sender = new URL(address + ":" + port);
      HttpMessage msg = new HttpMessage(sender);
      Properties props = new Properties();

      String finalMessage = g.finalMessage(query);

      System.out.println(finalMessage);

      props.put("text", finalMessage);
      InputStream in = msg.sendGetMessage(props);

      System.out.println("Stop_Communication");

    } catch (Exception e) {
      System.out.println("ERROR has occured : " + e.toString());
    }
    out.close();
  }