Java Code Examples for org.eclipse.core.resources.IEncodedStorage

The following examples show how to use org.eclipse.core.resources.IEncodedStorage. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public String getEncoding(Object element) {
	String encoding = super.getEncoding(element);
	if (encoding == null && element instanceof IStorageEditorInput) {
		try {
			IStorage storage = ((IStorageEditorInput) element).getStorage();
			URI uri = storage2UriMapper.getUri(storage);
			if (uri != null) {
				encoding = encodingProvider.getEncoding(uri);
			} else if (storage instanceof IEncodedStorage) {
				encoding = ((IEncodedStorage)storage).getCharset();
			}
		} catch (CoreException e) {
			throw new WrappedException(e);
		}
	}
	if (encoding == null) {
		if (isWorkspaceExternalEditorInput(element))
			encoding = getWorkspaceExternalEncoding((IURIEditorInput)element);
		else
			encoding = getWorkspaceOrDefaultEncoding();
	}
	return encoding;
}
 
Example 2
private static IResourceVariant createBaseResourceVariant(IResource local, LocalResourceStatus baseStatusInfo) {
    if( baseStatusInfo == null
            || baseStatusInfo.getLastChangedRevision() == null )
      return null;
    
    if( local.getType() == IResource.FILE ) {
    	String charset = null;
    	try {
    		charset = ((IEncodedStorage)local).getCharset();
    	} catch (CoreException e) {
    		SVNProviderPlugin.log(IStatus.ERROR, e.getMessage(), e);
    	}
    	return new BaseFile(local, baseStatusInfo, charset);
    }
    else {
        return new BaseFolder(local, baseStatusInfo);
    }
}
 
Example 3
Source Project: birt   Source File: StorageDocumentProvider.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the persisted encoding for the given element.
 * 
 * @param element
 *            the element for which to get the persisted encoding
 * @return the persisted encoding
 */
protected String getPersistedEncoding( Object element )
{
	if ( element instanceof IStorageEditorInput )
	{
		IStorage storage;
		try
		{
			storage = ( (IStorageEditorInput) element ).getStorage( );
			if ( storage instanceof IEncodedStorage )
				return ( (IEncodedStorage) storage ).getCharset( );
		}
		catch ( CoreException e )
		{
			return null;
		}
	}
	return null;
}
 
Example 4
Source Project: birt   Source File: FileReportDocumentProvider.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the persisted encoding for the given element.
 * 
 * @param element
 *            the element for which to get the persisted encoding
 * @return the persisted encoding
 */
protected String getPersistedEncoding( Object element )
{
	if ( element instanceof IEncodedStorage )
	{
		try
		{
			return ( (IEncodedStorage) element ).getCharset( );
		}
		catch ( CoreException e )
		{
			return null;
		}
	}
	return null;
}
 
Example 5
Source Project: xtext-eclipse   Source File: StorageAwareTrace.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected Reader getContentsAsText(IStorage storage) throws WrappedCoreException {
	if (storage instanceof IEncodedStorage) {
		try {
			IEncodedStorage enc = (IEncodedStorage) storage;
			Charset charset = Charset.forName(enc.getCharset());
			InputStream contents = storage.getContents();
			return new InputStreamReader(contents, charset);
		} catch (CoreException e) {
			throw new WrappedCoreException(e);
		}
	}
	return null;
}
 
Example 6
Source Project: APICloud-Studio   Source File: Utilities.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static String getCharset(IResource resource) {
	if (resource instanceof IEncodedStorage) {
		try {
			return ((IEncodedStorage)resource).getCharset();
		} catch (CoreException ex) {
			// fall  through
		}
	}
	return ResourcesPlugin.getEncoding();
}