Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 39097 Details for
Bug 100095
[DND] Consider making URLTransfer public
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
GTK Implementation of URLTransfer
UrlTransferGTK.java (text/plain), 5.29 KB, created by
Veronika Irvine
on 2006-04-20 15:57:24 EDT
(
hide
)
Description:
GTK Implementation of URLTransfer
Filename:
MIME Type:
Creator:
Veronika Irvine
Created:
2006-04-20 15:57:24 EDT
Size:
5.29 KB
patch
obsolete
>/******************************************************************************* > * Copyright (c) 2000, 2004 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: > * IBM Corporation - initial API and implementation > *******************************************************************************/ >package org.eclipse.swt.dnd; > >import org.eclipse.swt.internal.Converter; >import org.eclipse.swt.internal.gtk.*; > >import java.net.*; > > >/** > * The class <code>URLTransfer</code> provides a platform specific mechanism > * for converting text in URL format represented as a java <code>String[]</code> > * to a platform specific representation of the data and vice versa. See > * <code>Transfer</code> for additional information. The first string in the > * array is mandatory and must contain the fully specified url. The second > * string in the array is optional and if present contains the title for the > * page. > * > * <p>An example of a java <code>String[]</code> containing a URL is shown > * below:</p> > * > * <code><pre> > * String[] urlData = new String[] {"http://www.eclipse.org", "Eclipse.org Main Page"}; > * </code></pre> > */ >public class URLTransfer extends ByteArrayTransfer { > > static URLTransfer _instance = new URLTransfer(); > private static final String COMPOUND_TEXT = "COMPOUND_TEXT"; //$NON-NLS-1$ > private static final String UTF8_STRING = "UTF8_STRING"; //$NON-NLS-1$ > private static final String STRING = "STRING"; //$NON-NLS-1$ > private static final String URI_LIST = "text/uri-list"; //$NON-NLS-1$ > private static final int COMPOUND_TEXT_ID = registerType(COMPOUND_TEXT); > private static final int UTF8_STRING_ID = registerType(UTF8_STRING); > private static final int STRING_ID = registerType(STRING); > private static final int URI_LIST_ID = registerType(URI_LIST); > >private URLTransfer() {} > >/** > * Returns the singleton instance of the URLTransfer class. > * > * @return the singleton instance of the URLTransfer class > */ >public static URLTransfer getInstance () { > return _instance; >} > >/** > * This implementation of <code>javaToNative</code> converts a URL and optionally a title > * represented by a java <code>String[]</code> to a platform specific representation. > * For additional information see <code>Transfer#javaToNative</code>. > * > * @param object a java <code>String[]</code> containing a URL and optionally, a title > * @param transferData an empty <code>TransferData</code> object; this > * object will be filled in on return with the platform specific format of the data > */ >public void javaToNative (Object object, TransferData transferData){ > transferData.result = 0; > if (!checkURL(object) || !isSupportedType(transferData)) { > DND.error(DND.ERROR_INVALID_DATA); > } > String url = ((String[])object)[0]; > if (url == null) return; > byte[] utf8 = Converter.wcsToMbcs (null, url, true); > int /*long*/[] encoding = new int /*long*/[1]; > int[] format = new int[1]; > int /*long*/[] ctext = new int /*long*/[1]; > int[] length = new int[1]; > boolean result = OS.gdk_utf8_to_compound_text(utf8, encoding, format, ctext, length); > if (!result) return; > transferData.type = encoding[0]; > transferData.format = format[0]; > transferData.length = length[0]; > transferData.pValue = ctext[0]; > transferData.result = 1; >} > >/** > * This implementation of <code>nativeToJava</code> converts a platform specific > * representation of a URL and optionally, a title to a java <code>String[]</code>. > * For additional information see <code>Transfer#nativeToJava</code>. > * > * @param transferData the platform specific representation of the data to be > * been converted > * @return a java <code>String[]</code> containing a URL and optionally a title if the > * conversion was successful; otherwise null > */ >public Object nativeToJava(TransferData transferData){ > if (!isSupportedType(transferData) || transferData.pValue == 0) return null; > int /*long*/[] url = new int /*long*/[1]; > int count = OS.gdk_text_property_to_utf8_list(transferData.type, transferData.format, transferData.pValue, transferData.length, url); > if (count == 0) return null; > int /*long*/[] ptr = new int /*long*/[1]; > OS.memmove(ptr, url[0], OS.PTR_SIZEOF); > int urlLength = OS.strlen(ptr[0]); > byte[] utf8 = new byte[urlLength]; > OS.memmove(utf8, ptr[0], urlLength); > OS.g_strfreev(url[0]); > char[] unicode = Converter.mbcsToWcs (null, utf8); > String urlStr = new String (unicode); > int end = urlStr.indexOf('\0'); > if (end == -1) { > return new String[] {urlStr}; > } else { > return new String[] {urlStr.substring(0, end)}; > } >} > >protected int[] getTypeIds(){ > return new int[] {COMPOUND_TEXT_ID, UTF8_STRING_ID, URI_LIST_ID, STRING_ID}; >} > >protected String[] getTypeNames(){ > return new String[] {COMPOUND_TEXT, UTF8_STRING, URI_LIST, STRING}; >} > >boolean checkURL(Object object) { > if (object == null || !(object instanceof String[]) || ((String[])object).length == 0) return false; > String[] url = (String[])object; > if (url[0] == null || url[0].length() == 0) return false; > try { > new URL(url[0]); > } catch (java.net.MalformedURLException e) { > return false; > } > return true; >} > >protected boolean validate(Object object) { > return checkURL(object); >} >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 100095
: 39097 |
39098
|
39099