001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // This program is free software; you can redistribute it and/or modify
004: // it under the terms of the GNU General Public License and GNU Library
005: // General Public License as published by the Free Software Foundation;
006: // either version 2, or (at your option) any later version.
007: //
008: // This program is distributed in the hope that it will be useful,
009: // but WITHOUT ANY WARRANTY; without even the implied warranty of
010: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: // GNU General Public License and GNU Library General Public License
012: // for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // and GNU Library General Public License along with this program; if
016: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
017: // MA 02139, USA.
018: //
019: //////////////////////////////////////////////////////////////////////////////
020:
021: package org.rdesktop.server.rdp.rdp5.cliprdr;
022:
023: import java.awt.datatransfer.*;
024:
025: import org.rdesktop.server.rdp.RdpPacket;
026:
027: public class TextHandler extends TypeHandler {
028: public boolean formatValid(int format) {
029: return (format == CF_TEXT);
030: }
031:
032: public boolean mimeTypeValid(String mimeType) {
033: return mimeType.equals("text");
034: }
035:
036: public int preferredFormat() {
037: return CF_TEXT;
038: }
039:
040: public Transferable handleData(RdpPacket data, int length) {
041: String thingy = "";
042: for (int i = 0; i < length; i++) {
043: int aByte = data.get8();
044: if (aByte != 0) {
045: thingy += (char) (aByte & 0xFF);
046: }
047: }
048:
049: return new StringSelection(thingy);
050: }
051:
052: public String name() {
053: return "CF_TEXT";
054: }
055:
056: public byte[] fromTransferable(Transferable in) {
057: String thingy;
058: if (in != null) {
059: try {
060: thingy = (String) (in
061: .getTransferData(DataFlavor.stringFlavor));
062: } catch (Exception e) {
063: thingy = e.toString();
064: }
065:
066: thingy = thingy.replace('\n', (char) 0x0a);
067: thingy = thingy.replaceAll("" + (char) 0x0a, ""
068: + (char) 0x0d + (char) 0x0a);
069: return thingy.getBytes();
070: }
071: return null;
072: }
073:
074: public void handleData(RdpPacket data, int length,
075: ClipInterface clipInterface) {
076: String thingy = "";
077: for (int i = 0; i < length; i++) {
078: int aByte = data.get8();
079: if (aByte != 0) {
080: thingy += (char) (aByte & 0xFF);
081: }
082: }
083:
084: clipInterface.copyToClipboard(new StringSelection(thingy));
085: }
086:
087: public void send_data(Transferable in, ClipInterface clipInterface) {
088: String thingy;
089: if (in != null) {
090: try {
091: thingy = (String) in
092: .getTransferData(DataFlavor.stringFlavor);
093: } catch (Exception e) {
094: thingy = e.toString();
095: }
096:
097: thingy = thingy.replace('\n', (char) 0x0a);
098: thingy = thingy.replaceAll("" + (char) 0x0a, ""
099: + (char) 0x0d + (char) 0x0a);
100:
101: clipInterface.send_data(thingy.getBytes(), thingy.length());
102: }
103: }
104: }
|