/**
   * Download the meeting start time for the given meeting uri.
   *
   * @param sMeetingID, the id of the meeting whose start time to download.
   * @return the time the meeting is due to start as a String represting the time in milliseconds.
   */
  public String getStartTime(String sMeetingID) {
    String sTime = ""; // $NON-NLS-1$

    String sQuery =
        "SELECT ?has-abs-start-time WHERE (<"
            + sMeetingID
            + "> memetic:has-abs-start-time ?has-abs-start-time) " //$NON-NLS-1$ //$NON-NLS-2$
            + "USING memetic FOR <"
            + MEMETIC_NS
            + ">"; //$NON-NLS-1$ //$NON-NLS-2$

    Query query = new Query(sQuery);
    QueryExecution qe = new QueryEngineHTTP(query, sUrl);
    QueryResults results = qe.exec();
    Iterator iter = results;

    if (iter.hasNext()) {
      ResultBinding rbind = (ResultBinding) iter.next();

      Object obj = rbind.get("has-abs-start-time"); // $NON-NLS-1$
      sTime = obj.toString();

      // System.out.println("Meeting time = "+sTime);
    } else {
      System.out.println("No meeting date found for " + sMeetingID); // $NON-NLS-1$
    }

    return sTime;
  }
  /**
   * Download the meeting title for the given meeting uri.
   *
   * @param sMeetingID, the id of the meeting whose title to download.
   * @return the title of the meeting as a String.
   */
  public String getTitle(String sMeetingID) {
    String sName = ""; // $NON-NLS-1$

    String sQuery =
        "SELECT ?title WHERE (<"
            + sMeetingID
            + "> dc:title ?title) " //$NON-NLS-1$ //$NON-NLS-2$
            + "USING dc FOR <"
            + DC_NS
            + ">"; //$NON-NLS-1$ //$NON-NLS-2$

    Query query = new Query(sQuery);
    QueryExecution qe = new QueryEngineHTTP(query, sUrl);
    QueryResults results = qe.exec();
    Iterator iter = results;

    if (iter.hasNext()) {
      ResultBinding rbind = (ResultBinding) iter.next();

      Object obj = rbind.get("title"); // $NON-NLS-1$
      sName = obj.toString();

      // System.out.println("Meeting name = "+sName);
      // System.out.flush();

    } else {
      System.out.println("No meeting title found for " + sMeetingID); // $NON-NLS-1$
    }

    return sName;
  }
  /**
   * Return the session id associated with the given meeting id
   *
   * @param sMeetingID the id to return the session for.
   */
  public String getSessionID(String sMeetingID) {

    String sSessionID = ""; // $NON-NLS-1$

    String sQuery =
        "SELECT ?sessionid WHERE (<"
            + sMeetingID
            + "> memetic:has-session-id ?sessionid) " //$NON-NLS-1$ //$NON-NLS-2$
            + "USING memetic FOR <"
            + MEMETIC_NS
            + ">"; //$NON-NLS-1$ //$NON-NLS-2$

    Query query = new Query(sQuery);
    QueryExecution qe = new QueryEngineHTTP(query, sUrl);
    QueryResults results = qe.exec();
    Iterator iter = results;

    if (iter.hasNext()) {
      ResultBinding rbind = (ResultBinding) iter.next();

      Object obj = rbind.get("sessionid"); // $NON-NLS-1$
      sSessionID = obj.toString();

      // System.out.println("SessionID = "+sSessionID);
      // System.out.flush();

    } else {
      System.out.println("No meeting session id found for " + sMeetingID); // $NON-NLS-1$
    }

    return sSessionID;
  }
  /**
   * Download the agenda data for the given meeting uri.
   *
   * @param sMeetingID, the id for this meeting.
   * @return a Vector holding a list of {@Link com.compendium.meeting.MeetingAgendaItem
   *     MeetingAgendaItem} objects to represent the meeting agenda.
   */
  public Vector getAgenda(String sMeetingID) {

    Vector vtAgenda = new Vector();

    String sQuery =
        "SELECT ?agendum ?label ?number WHERE (<"
            + sMeetingID
            + "> portal:has-sub-event ?agendum), " //$NON-NLS-1$ //$NON-NLS-2$
            + "(?agendum rdf:type memetic:Agenda-Item), " //$NON-NLS-1$
            + "(?agendum memetic:has-label ?label), " //$NON-NLS-1$
            + "(?agendum memetic:has-item-number ?number) " //$NON-NLS-1$
            + "USING memetic FOR <"
            + MEMETIC_NS
            + "> portal FOR <"
            + PORTAL_NS
            + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    Query query = new Query(sQuery);
    QueryExecution qe = new QueryEngineHTTP(query, sUrl);
    QueryResults results = qe.exec();
    Iterator iter = results;

    // HAS AN AGENDA BEEN SET?
    if (iter.hasNext()) {

      String sOriginalID = ""; // $NON-NLS-1$
      String sLabel = ""; // $NON-NLS-1$
      float fNumber = 0;

      for (iter = results; iter.hasNext(); ) {

        ResultBinding rbind = (ResultBinding) iter.next();

        sOriginalID = new String((rbind.get("agendum")).toString()); // $NON-NLS-1$
        // System.out.println("URI of current agendum = " + sOriginalID);

        sLabel = new String((rbind.get("label")).toString()); // $NON-NLS-1$
        if (sLabel.matches("\\d+\\.\\d+ (.*)")) { // $NON-NLS-1$
          sLabel = sLabel.substring(sLabel.indexOf(' '));
        }
        // System.out.println("label of current agendum = " + sLabel);

        fNumber = new Float((rbind.get("number")).toString()).floatValue(); // $NON-NLS-1$
        // System.out.println("number of current agendum = " + fNumber);

        MeetingAgendaItem item = new MeetingAgendaItem(sMeetingID, sLabel, fNumber);
        item.setOriginalID(sOriginalID);

        vtAgenda.addElement(item);
      }
    }

    vtAgenda = sortAgenda(vtAgenda);

    return vtAgenda;
  }
  /**
   * Download the reference documents for the meeting uri.
   *
   * @param sMeetingID the id for this meeting.
   * @return a Vector listing the {@Link com.compendium.meeting.MeetingDocument MeetingDocument}
   *     objects representing additional documents for this meeting.
   */
  public Vector getDocuments(String sMeetingID) {

    Vector vtDocuments = new Vector();

    String sQuery =
        "SELECT ?anon_ref ?ref_url ?pretty_name WHERE "
            + //$NON-NLS-1$
            "(<"
            + sMeetingID
            + "> memetic:has-relevant-resource ?anon_ref), "
            + //$NON-NLS-1$ //$NON-NLS-2$
            "(?anon_ref support:has-pretty-name ?pretty_name), (?anon_ref "
            + //$NON-NLS-1$
            "memetic:has-url ?ref_url) USING memetic FOR <"
            + MEMETIC_NS
            + "> "
            + //$NON-NLS-1$ //$NON-NLS-2$
            "support FOR <"
            + SUPPORT_NS
            + ">"; //$NON-NLS-1$ //$NON-NLS-2$

    Query query = new Query(sQuery);
    QueryExecution qe = new QueryEngineHTTP(query, sUrl);
    QueryResults results = qe.exec();
    Iterator iter = results;

    if (iter.hasNext()) {

      String sURL = ""; // $NON-NLS-1$
      String sName = ""; // $NON-NLS-1$
      String sOriginalID = ""; // $NON-NLS-1$

      for (iter = results; iter.hasNext(); ) {
        ResultBinding rbind = (ResultBinding) iter.next();

        sOriginalID = new String((rbind.get("anon_ref")).toString()); // $NON-NLS-1$
        // System.out.println("ID of current reference = " + sOriginalID);

        sURL = new String((rbind.get("ref_url")).toString()); // $NON-NLS-1$
        // System.out.println("URL of current reference = " + sURL);

        sName = new String((rbind.get("pretty_name")).toString()); // $NON-NLS-1$
        // System.out.println("prettyname of current reference = " + sName);

        MeetingDocument doc = new MeetingDocument(sMeetingID, sName, sURL);
        doc.setOriginalID(sURL);
        vtDocuments.addElement(doc);
      }
    }

    return vtDocuments;
  }
 // Returns the uri of the given user
 private String getUserURI(String username) {
   String uri = null;
   String sQuery =
       "SELECT ?user WHERE (?user <memetic:has-username> \""
           + username
           + "\")"; //$NON-NLS-1$ //$NON-NLS-2$
   sQuery += " USING memetic FOR <" + MEMETIC_NS + ">"; // $NON-NLS-1$ //$NON-NLS-2$
   Query query = new Query(sQuery);
   QueryExecution qe = new QueryEngineHTTP(query, sUrl);
   QueryResults results = qe.exec();
   if (results.hasNext()) {
     ResultBinding rbind = (ResultBinding) results.next();
     uri = rbind.get("user").toString(); // $NON-NLS-1$
     // System.out.println("User URI = " + uri);
   } else {
     System.out.println("User URI Not found for user " + username); // $NON-NLS-1$
   }
   return uri;
 }
  /**
   * Download the attendee data for the given meeting uri.
   *
   * @param sMeetingID the id for this meeting.
   * @return a Vector of {@Link com.compendium.meeting.MeetingAttendee MeetingAttendee} items for
   *     those people attending the meeting.
   */
  public Vector getAttendees(String sMeetingID) {
    Vector vtAttendees = new Vector();

    String sQuery =
        "SELECT ?person ?name WHERE (<"
            + sMeetingID
            + "> meeting:has-local-event ?meeting), " //$NON-NLS-1$ //$NON-NLS-2$
            + "(?meeting portal:meeting-attendee ?person), " //$NON-NLS-1$
            + "(?person  portal:full-name ?name) " //$NON-NLS-1$
            + "USING meeting FOR <"
            + MEETING_NS
            + "> portal FOR <"
            + PORTAL_NS
            + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    Query query = new Query(sQuery);
    QueryExecution qe = new QueryEngineHTTP(query, sUrl);
    QueryResults results = qe.exec();
    Iterator iter = results;

    String sOriginalID = ""; // $NON-NLS-1$
    String sName = ""; // $NON-NLS-1$

    for (iter = results; iter.hasNext(); ) {

      ResultBinding rbind = (ResultBinding) iter.next();

      sOriginalID = new String((rbind.get("person")).toString()); // $NON-NLS-1$
      // System.out.println("URI of current person = " + sOriginalID);

      sName = new String((rbind.get("name")).toString()); // $NON-NLS-1$
      // System.out.println("name of current person = " + sName);

      MeetingAttendee item = new MeetingAttendee(sMeetingID, sName);
      item.setOriginalID(sOriginalID);
      vtAttendees.addElement(item);
    }

    return vtAttendees;
  }
  /**
   * Download the list of node creation events for the given meeting and add pass them to the given
   * {@Link com.compendium.meeting.MeetingManager MeetingManager}.
   *
   * @param oMeetingManager the {@Link com.compendium.meeting.MeetingManager MeetingManager} object
   *     controlling this meeting recording/replay.
   * @param sMeetingID the id for this meeting.
   */
  public void loadNodes(MeetingManager oMeetingManager, String sMeetingID) {

    String sQuery =
        "SELECT ?node_id ?map_id ?media_start_time WHERE "
            + //$NON-NLS-1$
            "(<"
            + sMeetingID
            + "> portal:has-sub-event ?creation_event), "
            + //$NON-NLS-1$ //$NON-NLS-2$
            "(?creation_event rdf:type memetic:Creating-Compendium-Node), "
            + //$NON-NLS-1$
            "(?creation_event memetic:has-media-start-time ?media_start_time), "
            + //$NON-NLS-1$
            "(?creation_event memetic:has-node ?node_id), "
            + //$NON-NLS-1$
            "(?creation_event memetic:has-map ?map_id) "
            + //$NON-NLS-1$
            "USING portal FOR <"
            + PORTAL_NS
            + "> memetic FOR <"
            + MEMETIC_NS
            + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    Query query = new Query(sQuery);
    QueryExecution qe = new QueryEngineHTTP(query, sUrl);
    QueryResults results = qe.exec();
    Iterator iter = results;

    String sID = ""; // $NON-NLS-1$
    String sNodeID = ""; // $NON-NLS-1$
    String sID2 = ""; // $NON-NLS-1$
    String sViewID = ""; // $NON-NLS-1$
    String sMediaIndex = ""; // $NON-NLS-1$

    for (iter = results; iter.hasNext(); ) {

      ResultBinding rbind = (ResultBinding) iter.next();

      sID = new String((rbind.get("node_id")).toString()); // $NON-NLS-1$
      // System.out.println("sID = " + sID);

      if (!sID.equals("")) { // $NON-NLS-1$
        int ind = sID.lastIndexOf("-"); // $NON-NLS-1$
        sNodeID = sID.substring(ind + 1);

        // System.out.println("sNodeID = "+sNodeID);
      }

      sID2 = new String((rbind.get("map_id")).toString()); // $NON-NLS-1$
      // System.out.println("sID2 = " + sID2);

      if (!sID2.equals("")) { // $NON-NLS-1$
        int ind2 = sID2.lastIndexOf("-"); // $NON-NLS-1$
        sViewID = sID2.substring(ind2 + 1);

        // System.out.println("sViewID = "+sViewID);
      }

      sMediaIndex = new String((rbind.get("media_start_time")).toString()); // $NON-NLS-1$

      if (!sViewID.equals("") && !sNodeID.equals("")) { // $NON-NLS-1$ //$NON-NLS-2$
        oMeetingManager.addNodeView(sNodeID, sViewID, sMediaIndex);
      }
    }
  }