Beispiel #1
0
  public StringBuffer getTransferData(Transferable t) {
    StringBuffer xferData = null;
    Object dropped;
    DataFlavor dtf;

    dtf = testAllFlavors(t);

    JConfig.log().logVerboseDebug("dtf == " + dtf);

    try {
      if (dtf == _htmlFlavor || dtf == _utf8HtmlFlavor || dtf == _thtmlFlavor) {
        /*
         * Annoying.
         */
        if (JConfig.queryConfiguration("debug.uber", "false").equals("true") && JConfig.debugging)
          System.out.println("Ick: " + t.getTransferData(DataFlavor.getTextPlainUnicodeFlavor()));
      }
      dropped = t.getTransferData(dtf);
    } catch (IOException ioe) {
      try {
        dropped = t.getTransferData(DataFlavor.stringFlavor);
      } catch (Exception e) {
        JConfig.log().logDebug("I/O Exception: " + ioe);
        return null;
      }
    } catch (UnsupportedFlavorException ufe) {
      try {
        dropped = t.getTransferData(DataFlavor.stringFlavor);
      } catch (Exception e) {
        JConfig.log().logDebug("Unsupported flavor: " + dtf);
        return null;
      }
    }

    if (dropped != null) {
      if (dropped instanceof InputStream) {
        JConfig.log().logVerboseDebug("Dropped an InputStream");
        xferData = getInputStreamData(t, dtf, (InputStream) dropped);
      } else if (dropped instanceof Reader) {
        JConfig.log().logVerboseDebug("Dropped a Reader");
        xferData = getDataFromReader(new BufferedReader((Reader) dropped));
      } else if (dropped instanceof java.net.URL) {
        JConfig.log().logVerboseDebug("Dropped a URL");
        JConfig.log().logVerboseDebug("Got: " + dropped.toString());

        xferData = new StringBuffer(dropped.toString());
      } else if (dropped instanceof String) {
        JConfig.log().logVerboseDebug("Dropped a String");
        xferData = new StringBuffer((String) dropped);
      }

      return (xferData);
    }
    return null;
  }
Beispiel #2
0
 private boolean testFlavor(DataFlavor inFlavor, Transferable t) {
   if (inFlavor != null) {
     if (t.isDataFlavorSupported(inFlavor)) {
       JConfig.log().logVerboseDebug("Accepting(2): " + inFlavor.getMimeType());
       return true;
     }
   }
   return false;
 }
Beispiel #3
0
  private void dumpFlavorsOld(Transferable t) {
    DataFlavor[] dfa = t.getTransferDataFlavors();

    if (dfa != null) {
      if (dfa.length == 0) {
        JConfig.log().logVerboseDebug("Trying a second attack...");
        try {
          Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
          Transferable t2 = sysClip.getContents(null);
          StringBuffer stBuff;

          stBuff = getTransferData(t2);
          JConfig.log().logVerboseDebug("Check out: " + stBuff);
        } catch (Exception e) {
          JConfig.log().handleException("Caught: " + e, e);
        }
        JConfig.log().logVerboseDebug("Done trying a second attack...");
      }
    }
    dumpDataFlavors(dfa);
  }
Beispiel #4
0
  public void drop(DropTargetDropEvent dtde) {
    Transferable t = dtde.getTransferable();
    StringBuffer dropData = null;
    DataFlavor dtf;

    JConfig.log().logVerboseDebug("Dropping!");

    if (t.getTransferDataFlavors().length == 0) {
      Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
      Transferable t2 = sysClip.getContents(null);
      DataFlavor[] dfa2;
      int j;

      JConfig.log().logDebug("Dropped 0 data flavors, trying clipboard.");
      dfa2 = null;

      if (t2 != null) {
        JConfig.log().logVerboseDebug("t2 is not null: " + t2);
        dfa2 = t2.getTransferDataFlavors();
        JConfig.log().logVerboseDebug("Back from getTransferDataFlavors()!");
      } else {
        JConfig.log().logVerboseDebug("t2 is null!");
      }

      if (JConfig.queryConfiguration("debug.uber", "false").equals("true")) {
        if (dfa2 != null) {
          if (dfa2.length == 0) {
            JConfig.log().logVerboseDebug("Length is still zero!");
          }
          for (j = 0; j < dfa2.length; j++) {
            JConfig.log()
                .logVerboseDebug("Flavah " + j + " == " + dfa2[j].getHumanPresentableName());
            JConfig.log().logVerboseDebug("Flavah/mime " + j + " == " + dfa2[j].getMimeType());
          }
        } else {
          JConfig.log().logVerboseDebug("Flavahs supported: none!\n");
        }
      }
    }

    if (JConfig.queryConfiguration("debug.uber", "false").equals("true") && JConfig.debugging)
      dumpFlavorsOld(t);

    dtf = testAllFlavors(t);
    if (dtf != null) {
      JConfig.log().logVerboseDebug("Accepting!");
      acceptDrop(dtde);

      dropData = getTransferData(t);
      dtde.dropComplete(true);
      dtde.getDropTargetContext().dropComplete(true);
      if (dropData != null) {
        if (handler != null) {
          handler.receiveDropString(dropData);
        }
      }
    } else {
      JConfig.log().logVerboseDebug("Rejecting!");
      dtde.rejectDrop();
      handler.receiveDropString(dropData);
    }
  }