示例#1
0
  public void sendHighlights() {

    // send highlights to everybody
    try {
      Iterator i = highlights.getHighlights().iterator();
      while (i.hasNext()) {
        Highlights.Highlight h = (Highlights.Highlight) i.next();
        Paragraph sPar = lockManager.getParFromOffset(h.getStart());
        Paragraph ePar = lockManager.getParFromOffset(h.getEnd());

        if (EditorServer_Debug) {
          System.out.println("StartPar: " + sPar.toString());
          System.out.println("EndPar: " + ePar.toString());
        }

        Message.HighlightAddMsg msg =
            new Message.HighlightAddMsg(
                -1,
                h.getId(),
                h.getType().getId(),
                sPar.getID(),
                ePar.getID(),
                h.getStart() - sPar.getOffset(),
                h.getEnd() - ePar.getOffset());
        textChannel.sendToOthers(client, new Data(msg));
      }
    } catch (Exception e) {
      System.err.println("EditorServer: sendHighlights: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
示例#2
0
  public void textInserted(Message.TextInsertMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer-> textInserted.");

    try {
      int ClientId = m.getClientId();
      int offset = m.getOffset();
      String characterInserted = m.getText();

      if (EditorServer_Debug)
        System.out.println("EditorServer-> textInserted : *" + characterInserted + "*");

      Vector pars = lockManager.textInserted(m.getPar(), offset, characterInserted, ClientId);

      textChannel.sendToOthers(client, new Data(m));
      EditorClient c = getEditorClient(ClientId);

      // new condition inserted to avoid timestamp generation if the character
      // is a newline

      if (characterInserted.equals("\n")) {
        if (EditorServer_Debug)
          System.out.println("EditorServer-> textInserted : attempting to insert a newLine");
      }
      c.addTextInsertAction(System.currentTimeMillis(), pars, offset, characterInserted);
      clientsPanel.updateActionTableFor(c);
      updateParagraphList();

    } catch (Exception e) {
      System.err.println("EditorServer-> textInserted: error receiving-sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
示例#3
0
  public void textInserted(Message.TextPasteMsg m) {

    try {

      int SenderId = m.getClientId();
      int offset = m.getOffset();
      String textPasted = m.getText();

      if (EditorServer_Debug)
        System.err.println("EditorServer->textinserted : PASTED by : " + SenderId);

      Vector pars = null;
      try {
        pars = lockManager.textInserted(m.getPar(), offset, textPasted, SenderId);
        if (EditorServer_Debug)
          System.err.println("\n+=*%EditorServer--> textInserted recovered VECTOR...");
      } catch (Exception e) {
        System.err.println("\n+=*%EditorServer--> textInserted VECTOR error ");
      }

      textChannel.sendToOthers(client, new Data(m));

      EditorClient SenderClient = getEditorClient(SenderId);
      SenderClient.addTextPasteAction(System.currentTimeMillis(), pars, offset, textPasted);
      clientsPanel.updateActionTableFor(SenderClient);
      updateParagraphList();
    } catch (Exception e) {
      System.err.println("\nEditorServer--> textPasted: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
  public static void main(String[] arg) {

    String xhost = "127.0.0.1";
    int xport = 0;

    try {
      JSch jsch = new JSch();

      String host = null;
      if (arg.length > 0) {
        host = arg[0];
      } else {
        host =
            JOptionPane.showInputDialog(
                "Enter username@hostname", System.getProperty("user.name") + "@localhost");
      }
      String user = host.substring(0, host.indexOf('@'));
      host = host.substring(host.indexOf('@') + 1);

      Session session = jsch.getSession(user, host, 22);

      String display =
          JOptionPane.showInputDialog("Please enter display name", xhost + ":" + xport);
      xhost = display.substring(0, display.indexOf(':'));
      xport = Integer.parseInt(display.substring(display.indexOf(':') + 1));

      session.setX11Host(xhost);
      session.setX11Port(xport + 6000);

      // username and password will be given via UserInfo interface.
      UserInfo ui = new MyUserInfo();
      session.setUserInfo(ui);
      session.connect();

      Channel channel = session.openChannel("shell");

      channel.setXForwarding(true);

      channel.setInputStream(System.in);
      channel.setOutputStream(System.out);

      channel.connect();
    } catch (Exception e) {
      System.out.println(e);
    }
  }
示例#5
0
 public void sendClientReject(int keyValue, int reason) {
   Message.ClientRejectMsg msg = new Message.ClientRejectMsg(-1, keyValue, reason);
   try {
     clientChannel.sendToOthers(client, new Data(msg));
   } catch (Exception e) {
     System.err.println("EditorServer: clientRejected: error sending msg");
     if (EditorServer_Debug) e.printStackTrace();
   }
 }
示例#6
0
 public void scrollMoved(Message.ScrollMoveMsg m) {
   // if(EditorServer_Debug) System.err.println("EditorServer: scrollMoved.") ;
   try {
     clientChannel.sendToOthers(client, new Data(m));
   } catch (Exception e) {
     System.err.println("EditorServer: scrollMoved: error sending msg");
     if (EditorServer_Debug) e.printStackTrace();
   }
 }
示例#7
0
 public void sendDocumentState(int clientId) {
   Message.DocumentStateMsg msg =
       new Message.DocumentStateMsg(clientId, lockManager.getDocumentAsXML());
   try {
     clientChannel.sendToOthers(client, new Data(msg));
   } catch (Exception e) {
     System.err.println("EditorServer: sendDocumentState: error sending msg");
     if (EditorServer_Debug) e.printStackTrace();
   }
 }
示例#8
0
  public void lockReleased(Message.LockReleaseMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer: lockReleased.");

    lockManager.lockReleased(m.getStartPar(), m.getEndPar(), m.getClientId());
    try {
      textChannel.sendToOthers(client, new Data(m));
    } catch (Exception e) {
      System.err.println("EditorServer: lockReleased: error sending lock released");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
示例#9
0
  public void highlightTypeAdded(Message.HighlightTypeMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer: highlightTypeAdded.");

    highlights.addHighlightType(m.getId(), m.getName(), m.getColor());

    try {
      textChannel.sendToOthers(client, new Data(m));
    } catch (Exception e) {
      System.err.println("EditorServer: highlightTypeAdded: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
示例#10
0
  public void highlightDeleted(Message.HighlightDeleteMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer: highlightDeleted.");

    highlights.deleteHighlight(m.getId());
    EditorClient c = getEditorClient(m.getClientId());
    try {
      textChannel.sendToOthers(client, new Data(m));
    } catch (Exception e) {
      System.err.println("EditorServer: highlightDeleted: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
示例#11
0
  public void highlightEdited(Message.HighlightEditMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer: highlightEdited.");

    highlights.editHighlight(
        m.getId(), m.getStartPar(), m.getStartOffset(), m.getEndPar(), m.getEndOffset());

    try {
      textChannel.sendToOthers(client, new Data(m));
    } catch (Exception e) {
      System.err.println("EditorServer: highlightEdited: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
示例#12
0
  public void lockRequested(Message.LockRequestMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer -> lockRequested.");

    /*
      java.util.Timer t = new java.util.Timer() ;
      t.schedule(new TimerTask() {
      public void run() {
      client.lockDenied(id) ;
      }
      }, 3000) ;
    */

    if (lockManager.lockRequested(m.getStartPar(), m.getEndPar(), m.getClientId())) {

      if (EditorServer_Debug) System.out.println("Lock Granted");

      Message.LockGrantMsg reply =
          new Message.LockGrantMsg(
              m.getClientId(), m.getStartPar(), m.getEndPar(), m.getIdNumber());
      try {
        textChannel.sendToOthers(client, new Data(reply));
      } catch (Exception e) {
        System.err.println("EditorServer: lockRequested: error sending lock granted");
        if (EditorServer_Debug) e.printStackTrace();
      }
    } else {
      if (EditorServer_Debug) System.out.println("Lock Denied");
      // send lock denied to sender

      Message.LockDenyMsg reply = new Message.LockDenyMsg(m.getClientId(), m.getIdNumber());
      try {
        textChannel.sendToOthers(client, new Data(reply));
      } catch (Exception e) {
        System.err.println("EditorServer: lockRequested: error sending lock denied");
        if (EditorServer_Debug) e.printStackTrace();
      }
    }
  }
示例#13
0
  public void clientLeft(Message.ClientLeaveMsg m) {
    System.out.println("EditorServer: clientLeft");

    EditorClient ec = getEditorClient(m.getClientId());
    ec.setPresent(false);
    clientsPanel.updateClientList();

    try {
      clientChannel.sendToOthers(client, new Data(m));
    } catch (Exception e) {
      System.err.println("EditorServer: clientLeft: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
示例#14
0
  public void gestureLine(Message.GestureLineMsg m) {
    if (EditorServer_Debug)
      System.err.println("EditorServer: gestureLine." + String.valueOf(m.getId()));

    try {
      clientChannel.sendToOthers(client, new Data(m));
      EditorClient c = getEditorClient(m.getClientId());
      long par = getParIdForGesture(m.getPar(), m.getAY());
      c.addGestureAction(System.currentTimeMillis(), m.getId(), par, m.getAX(), m.getAY(), this);
      c.addGestureAction(System.currentTimeMillis(), m.getId(), par, m.getBX(), m.getBY(), this);
      clientsPanel.updateActionTableFor(c);
    } catch (Exception e) {
      System.err.println("EditorServer: gestureLine: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
示例#15
0
  public void clientAppeared() {
    if (EditorServer_Debug) System.out.println("EditorServer: clientAppeared.");

    // send client list to everybody
    try {
      Iterator i = clients.iterator();

      while (i.hasNext()) {
        EditorClient ec = (EditorClient) i.next();
        if (ec.isPresent()) clientChannel.sendToOthers(client, new Data(ec.getMessage()));
      }

    } catch (Exception e) {
      System.err.println("EditorServer: clientAppeared: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
示例#16
0
  public void sendHighlightTypes() {
    //      send highlightTypes to everybody
    try {
      Iterator i = highlights.getHighlightTypes().iterator();

      while (i.hasNext()) {
        HighlightType type = (HighlightType) i.next();

        if (EditorServer_Debug)
          System.out.println("EditorServer: sendHighlightTypes. " + String.valueOf(type.getId()));

        Message.HighlightTypeMsg msg =
            new Message.HighlightTypeMsg(-1, type.getId(), type.getName(), type.getColor());
        textChannel.sendToOthers(client, new Data(msg));
      }
    } catch (Exception e) {
      System.err.println("EditorServer: sendHighlightTypes: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
示例#17
0
  public void textDeleted(Message.TextCutMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer ->textCut.");

    try {

      long StartPar = m.getStartPar();
      long EndPar = m.getEndPar();
      int StartOffset = m.getStartOffset();
      int EndOffset = m.getEndOffset();

      String text = lockManager.getText(StartPar, StartOffset, EndPar, EndOffset);
      Vector pars = lockManager.textDeleted(StartPar, StartOffset, EndPar, EndOffset);
      textChannel.sendToOthers(client, new Data(m));
      EditorClient c = getEditorClient(m.getClientId());
      c.addTextCutAction(System.currentTimeMillis(), pars, StartOffset, EndOffset, text);
      clientsPanel.updateActionTableFor(c);
      updateParagraphList();
    } catch (Exception e) {
      System.err.println("EditorServer---> textDeleted(cut): error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
示例#18
0
  public void clientJoined(Message.ClientJoinMsg m) {

    Iterator i = clients.iterator();

    while (i.hasNext()) {
      EditorClient ec = (EditorClient) i.next();
      if (ec.isPresent()) {
        if (m.getName().equals(ec.getName())) {
          sendClientReject(m.getKeyValue(), Message.ClientRejectMsg.REASON_NAME);
          return;
        }
        if (m.getColorCode() == ec.getColorCode()) {
          sendClientReject(m.getKeyValue(), Message.ClientRejectMsg.REASON_COLOR);
          return;
        }
      }
    }

    // clientAccepted
    // mach... added ClientIPaddress + added server to EditorClient const
    EditorClient newClient =
        new EditorClient(
            this,
            nextClientId,
            m.getName(),
            m.getColorCode(),
            m.getKeyValue(),
            m.getClientIPaddress());

    if (EditorServer_Debug)
      System.out.println(
          ">>> In EditorServer.clientJoined  : client NAME is : *"
              + m.getName()
              + "* IPAddress : is : *"
              + m.getClientIPaddress()
              + "*");

    clients.add(newClient);
    nextClientId++;
    clientsPanel.updateClientList();

    // here... match Audio & Text client
    // iterate through list of audio client

    String audioClientIP = "";

    int offset = -1;

    if (isAudioOptionSelected) {

      if (EditorServer_Debug) System.out.println("\n>>>In Client Accepted !!!");

      for (int n = 0; n < plistModel.getSize(); n++) {

        audioClientIP = (plistModel.getElementAt(n)).toString();

        offset = audioClientIP.indexOf('@');

        audioClientIP = audioClientIP.substring(offset + 1);

        if (audioClientIP.equals(m.getClientIPaddress())) {

          System.out.println("MATCH found!!!" + m.getName() + "<>" + audioClientIP);

          // change ...

          plistModel.set(n, m.getName());
        }
      }
    } // endif isAudioOptionSelected

    try {
      clientChannel.sendToOthers(client, new Data(newClient.getMessage()));
      sendDocumentState(nextClientId - 1);
      sendHighlightTypes();
      sendHighlights();
    } catch (Exception e) {
      System.err.println("EditorServer: clientJoined: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
  public static void main(String[] arg) {
    if (arg.length != 2) {
      System.err.println("usage: java ScpTo file1 user@remotehost:file2");
      System.exit(-1);
    }

    FileInputStream fis = null;
    try {

      String lfile = arg[0];
      String user = arg[1].substring(0, arg[1].indexOf('@'));
      arg[1] = arg[1].substring(arg[1].indexOf('@') + 1);
      String host = arg[1].substring(0, arg[1].indexOf(':'));
      String rfile = arg[1].substring(arg[1].indexOf(':') + 1);

      JSch jsch = new JSch();
      Session session = jsch.getSession(user, host, 22);

      // username and password will be given via UserInfo interface.
      UserInfo ui = new MyUserInfo();
      session.setUserInfo(ui);
      session.connect();

      boolean ptimestamp = true;

      // exec 'scp -t rfile' remotely
      String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + rfile;
      Channel channel = session.openChannel("exec");
      ((ChannelExec) channel).setCommand(command);

      // get I/O streams for remote scp
      OutputStream out = channel.getOutputStream();
      InputStream in = channel.getInputStream();

      channel.connect();

      if (checkAck(in) != 0) {
        System.exit(0);
      }

      File _lfile = new File(lfile);

      if (ptimestamp) {
        command = "T " + (_lfile.lastModified() / 1000) + " 0";
        // The access time should be sent here,
        // but it is not accessible with JavaAPI ;-<
        command += (" " + (_lfile.lastModified() / 1000) + " 0\n");
        out.write(command.getBytes());
        out.flush();
        if (checkAck(in) != 0) {
          System.exit(0);
        }
      }

      // send "C0644 filesize filename", where filename should not include '/'
      long filesize = _lfile.length();
      command = "C0644 " + filesize + " ";
      if (lfile.lastIndexOf('/') > 0) {
        command += lfile.substring(lfile.lastIndexOf('/') + 1);
      } else {
        command += lfile;
      }
      command += "\n";
      out.write(command.getBytes());
      out.flush();
      if (checkAck(in) != 0) {
        System.exit(0);
      }

      // send a content of lfile
      fis = new FileInputStream(lfile);
      byte[] buf = new byte[1024];
      while (true) {
        int len = fis.read(buf, 0, buf.length);
        if (len <= 0) break;
        out.write(buf, 0, len); // out.flush();
      }
      fis.close();
      fis = null;
      // send '\0'
      buf[0] = 0;
      out.write(buf, 0, 1);
      out.flush();
      if (checkAck(in) != 0) {
        System.exit(0);
      }
      out.close();

      channel.disconnect();
      session.disconnect();

      System.exit(0);
    } catch (Exception e) {
      System.out.println(e);
      try {
        if (fis != null) fis.close();
      } catch (Exception ee) {
      }
    }
  }
示例#20
0
  public static void main(String[] arg) {
    if (arg.length != 2) {
      System.err.println("usage: java ScpFrom user@remotehost:file1 file2");
      System.exit(-1);
    }

    FileOutputStream fos = null;
    try {

      String user = arg[0].substring(0, arg[0].indexOf('@'));
      arg[0] = arg[0].substring(arg[0].indexOf('@') + 1);
      String host = arg[0].substring(0, arg[0].indexOf(':'));
      String rfile = arg[0].substring(arg[0].indexOf(':') + 1);
      String lfile = arg[1];

      String prefix = null;
      if (new File(lfile).isDirectory()) {
        prefix = lfile + File.separator;
      }

      JSch jsch = new JSch();
      Session session = jsch.getSession(user, host, 22);

      // username and password will be given via UserInfo interface.
      UserInfo ui = new MyUserInfo();
      session.setUserInfo(ui);
      session.connect();

      // exec 'scp -f rfile' remotely
      String command = "scp -f " + rfile;
      Channel channel = session.openChannel("exec");
      ((ChannelExec) channel).setCommand(command);

      // get I/O streams for remote scp
      OutputStream out = channel.getOutputStream();
      InputStream in = channel.getInputStream();

      channel.connect();

      byte[] buf = new byte[1024];

      // send '\0'
      buf[0] = 0;
      out.write(buf, 0, 1);
      out.flush();

      while (true) {
        int c = checkAck(in);
        if (c != 'C') {
          break;
        }

        // read '0644 '
        in.read(buf, 0, 5);

        long filesize = 0L;
        while (true) {
          if (in.read(buf, 0, 1) < 0) {
            // error
            break;
          }
          if (buf[0] == ' ') break;
          filesize = filesize * 10L + (long) (buf[0] - '0');
        }

        String file = null;
        for (int i = 0; ; i++) {
          in.read(buf, i, 1);
          if (buf[i] == (byte) 0x0a) {
            file = new String(buf, 0, i);
            break;
          }
        }

        // System.out.println("filesize="+filesize+", file="+file);

        // send '\0'
        buf[0] = 0;
        out.write(buf, 0, 1);
        out.flush();

        // read a content of lfile
        fos = new FileOutputStream(prefix == null ? lfile : prefix + file);
        int foo;
        while (true) {
          if (buf.length < filesize) foo = buf.length;
          else foo = (int) filesize;
          foo = in.read(buf, 0, foo);
          if (foo < 0) {
            // error
            break;
          }
          fos.write(buf, 0, foo);
          filesize -= foo;
          if (filesize == 0L) break;
        }
        fos.close();
        fos = null;

        if (checkAck(in) != 0) {
          System.exit(0);
        }

        // send '\0'
        buf[0] = 0;
        out.write(buf, 0, 1);
        out.flush();
      }

      session.disconnect();

      System.exit(0);
    } catch (Exception e) {
      System.out.println(e);
      try {
        if (fos != null) fos.close();
      } catch (Exception ee) {
      }
    }
  }