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 39099 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]
Motif implementation of URLTransfer
URLTransferMotif.java (text/plain), 6.36 KB, created by
Veronika Irvine
on 2006-04-20 15:58:19 EDT
(
hide
)
Description:
Motif implementation of URLTransfer
Filename:
MIME Type:
Creator:
Veronika Irvine
Created:
2006-04-20 15:58:19 EDT
Size:
6.36 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 java.net.URL; > >import org.eclipse.swt.internal.Converter; >import org.eclipse.swt.internal.motif.*; >import org.eclipse.swt.widgets.Display; > >/** >* 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(); >// static final String TEXT_URL = "text/url"; //$NON-NLS-1$ >// static final int TEXT_URL_ID = registerType(TEXT_URL); >// static final String URL_LIST = "text/url-list"; //$NON-NLS-1$ >// static final int URL_LIST_ID = registerType(URL_LIST); >// static final String TEXT2_URL = "TEXT/URL"; //$NON-NLS-1$ >// static final int TEXT2_URL_ID = registerType(TEXT2_URL); >// static final String URL2_LIST = "TEXT/URL-LIST"; //$NON-NLS-1$ >// static final int URL2_LIST_ID = registerType(URL2_LIST); >// static final String STR_URL = "UniformResourceLocator"; //$NON-NLS-1$ >// static final int STR_URL_ID = registerType(STR_URL); > > static final String COMPOUND_TEXT = "COMPOUND_TEXT"; //$NON-NLS-1$ > static final String STRING = "STRING"; //$NON-NLS-1$ > static final int COMPOUND_TEXT_ID = registerType(COMPOUND_TEXT); > static final int STRING_ID = registerType(STRING); > >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]; > byte[] buffer = Converter.wcsToMbcs (null, url, true); > Display display = Display.getCurrent(); > if (display == null) return; > int xDisplay = display.xDisplay; > int pBuffer = OS.XtMalloc(buffer.length); > if (pBuffer == 0) return; > try { > OS.memmove(pBuffer, buffer, buffer.length); > int list = OS.XtMalloc(4); > if (list == 0) return; > OS.memmove(list, new int[] {pBuffer}, 4); > XTextProperty text_prop_return = new XTextProperty(); > int result = OS.XmbTextListToTextProperty (xDisplay, list, 1, OS.XCompoundTextStyle, text_prop_return); > OS.XtFree(list); > if (result != 0)return; > transferData.format = text_prop_return.format; > transferData.length = text_prop_return.nitems; > transferData.pValue = text_prop_return.value; > transferData.type = text_prop_return.encoding; > transferData.result = 1; > } finally { > OS.XtFree(pBuffer); > } >} > >/** >* 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; > > Display display = Display.getCurrent(); > if (display == null) return null; > int xDisplay = display.xDisplay; > XTextProperty text_prop = new XTextProperty(); > text_prop.encoding = transferData.type; > text_prop.format = transferData.format; > text_prop.nitems = transferData.length; > text_prop.value = transferData.pValue; > int[] list_return = new int[1]; > int[] count_return = new int[1]; > int result = OS.XmbTextPropertyToTextList (xDisplay, text_prop, list_return, count_return); > if (result != 0 || list_return[0] == 0) return null; > > int[] ptr = new int[1]; > OS.memmove(ptr, list_return[0], 4); > int length = OS.strlen(ptr[0]); > byte[] buffer = new byte[length]; > OS.memmove(buffer, ptr[0], length); > OS.XFreeStringList(list_return[0]); > if (buffer == null) return null; > > char [] unicode = Converter.mbcsToWcs (null, buffer); > String url = new String (unicode); > int end = url.indexOf('\0'); > if (end == -1) { > return new String[]{url}; > } else { > return new String[] {url.substring(0, url.indexOf('\0'))}; > } >} > >protected int[] getTypeIds(){ > //return new int[] {URL2_LIST_ID, URL_LIST_ID,TEXT2_URL_ID, TEXT_URL_ID}; > return new int[] {COMPOUND_TEXT_ID, STRING_ID}; >} > >protected String[] getTypeNames(){ > //return new String[] {URL_LIST, TEXT_URL, URL2_LIST, TEXT2_URL}; > return new String[] {COMPOUND_TEXT, 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