1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 import com.sun.star.datatransfer.DataFlavor; 25 import com.sun.star.datatransfer.UnsupportedFlavorException; 26 import com.sun.star.datatransfer.XTransferable; 27 import com.sun.star.uno.Type; 28 29 //--------------------------------------- 30 // A simple transferable containing only 31 // one format, unicode text 32 //--------------------------------------- 33 34 public class TextTransferable implements XTransferable 35 { TextTransferable(String aText)36 public TextTransferable(String aText) 37 { 38 text = aText; 39 } 40 41 // XTransferable methods 42 getTransferData(DataFlavor aFlavor)43 public Object getTransferData(DataFlavor aFlavor) throws UnsupportedFlavorException 44 { 45 if ( !aFlavor.MimeType.equalsIgnoreCase( UNICODE_CONTENT_TYPE ) ) 46 throw new UnsupportedFlavorException(); 47 48 return text; 49 } 50 getTransferDataFlavors()51 public DataFlavor[] getTransferDataFlavors() 52 { 53 DataFlavor[] adf = new DataFlavor[1]; 54 55 DataFlavor uniflv = new DataFlavor( 56 UNICODE_CONTENT_TYPE, 57 "Unicode Text", 58 new Type(String.class) ); 59 60 adf[0] = uniflv; 61 62 return adf; 63 } 64 isDataFlavorSupported(DataFlavor aFlavor)65 public boolean isDataFlavorSupported(DataFlavor aFlavor) 66 { 67 return aFlavor.MimeType.equalsIgnoreCase(UNICODE_CONTENT_TYPE); 68 } 69 70 // members 71 72 private final String text; 73 private final String UNICODE_CONTENT_TYPE = "text/plain;charset=utf-16"; 74 } 75