Java Code Examples for org.eclipse.core.resources.ResourcesPlugin#getEncoding()

The following examples show how to use org.eclipse.core.resources.ResourcesPlugin#getEncoding() . 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 check out the related API usage on the sidebar.
Example 1
Source File: PyContentViewer.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public static String readString(IStreamContentAccessor sa) throws CoreException {
    InputStream is = sa.getContents();
    if (is != null) {
        String encoding = null;
        if (sa instanceof IEncodedStreamContentAccessor) {
            try {
                encoding = ((IEncodedStreamContentAccessor) sa).getCharset();
            } catch (Exception e) {
            }
        }
        if (encoding == null) {
            encoding = ResourcesPlugin.getEncoding();
        }
        return readString(is, encoding);
    }
    return null;
}
 
Example 2
Source File: JavaCompareUtilities.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static String readString(IStreamContentAccessor sa) throws CoreException {
	InputStream is= sa.getContents();
	if (is != null) {
		String encoding= null;
		if (sa instanceof IEncodedStreamContentAccessor) {
			try {
				encoding= ((IEncodedStreamContentAccessor) sa).getCharset();
			} catch (Exception e) {
			}
		}
		if (encoding == null)
			encoding= ResourcesPlugin.getEncoding();
		return readString(is, encoding);
	}
	return null;
}
 
Example 3
Source File: JavadocContentAccess2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static String getSourceAttachmentEncoding(IPackageFragmentRoot root) throws JavaModelException {
	String encoding = ResourcesPlugin.getEncoding();
	IClasspathEntry entry = root.getRawClasspathEntry();

	if (entry != null) {
		int kind = entry.getEntryKind();
		if (kind == IClasspathEntry.CPE_LIBRARY || kind == IClasspathEntry.CPE_VARIABLE) {
			IClasspathAttribute[] extraAttributes = entry.getExtraAttributes();
			for (int i = 0; i < extraAttributes.length; i++) {
				IClasspathAttribute attrib = extraAttributes[i];
				if (IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING.equals(attrib.getName())) {
					return attrib.getValue();
				}
			}
		}
	}

	return encoding;
}
 
Example 4
Source File: JavadocContentAccess2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static String getSourceAttachmentEncoding(IPackageFragmentRoot root) throws JavaModelException {
	String encoding= ResourcesPlugin.getEncoding();
	IClasspathEntry entry= root.getRawClasspathEntry();

	if (entry != null) {
		int kind= entry.getEntryKind();
		if (kind == IClasspathEntry.CPE_LIBRARY || kind == IClasspathEntry.CPE_VARIABLE) {
			IClasspathAttribute[] extraAttributes= entry.getExtraAttributes();
			for (int i= 0; i < extraAttributes.length; i++) {
				IClasspathAttribute attrib= extraAttributes[i];
				if (IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING.equals(attrib.getName())) {
					return attrib.getValue();
				}
			}
		}
	}

	return encoding;
}
 
Example 5
Source File: ClassFileSingleDocument.java    From eclipse-encoding-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void updateStatus() {

	super.updateStatus();

	inheritedEncoding = ResourcesPlugin.getEncoding();
	detectedCharset = Charsets.detect(getInputStream());
	lineSeparator = LineSeparators.ofContent(getInputStream(), getCurrentEncoding());
}
 
Example 6
Source File: AbstractSpellDictionary.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the encoding of this dictionary.
 *
 * @return the encoding of this dictionary
 * @since 3.3
 */
protected String getEncoding() {
	String encoding= JavaPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.SPELLING_USER_DICTIONARY_ENCODING);
	if (encoding == null || encoding.length() == 0)
		encoding= ResourcesPlugin.getEncoding();
	return encoding;
}
 
Example 7
Source File: CreateFileChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void initializeEncoding() {
	if (fEncoding == null) {
		fExplicitEncoding= false;
		IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(fPath);
		if (file != null) {
			try {
				if (file.exists()) {
					fEncoding= file.getCharset(false);
					if (fEncoding == null) {
						fEncoding= file.getCharset(true);
					} else {
						fExplicitEncoding= true;
					}
				} else {
					IContentType contentType= Platform.getContentTypeManager().findContentTypeFor(file.getName());
					if (contentType != null)
						fEncoding= contentType.getDefaultCharset();
					if (fEncoding == null)
						fEncoding= file.getCharset(true);
				}
			} catch (CoreException e) {
				fEncoding= ResourcesPlugin.getEncoding();
				fExplicitEncoding= true;
			}
		} else {
			fEncoding= ResourcesPlugin.getEncoding();
			fExplicitEncoding= true;
		}
	}
	Assert.isNotNull(fEncoding);
}
 
Example 8
Source File: Utilities.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public static String readString(IStreamContentAccessor sa) throws CoreException {
	InputStream is= sa.getContents();
	String encoding= null;
	if (sa instanceof IEncodedStreamContentAccessor)
		encoding= ((IEncodedStreamContentAccessor)sa).getCharset();
	if (encoding == null)
		encoding= ResourcesPlugin.getEncoding();
	return Utilities.readString(is, encoding);
}
 
Example 9
Source File: Utilities.java    From APICloud-Studio with 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();
}
 
Example 10
Source File: EncodingControlContribution.java    From eclipse-encoding-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void fillControl() {

		ActiveDocument doc = agent.getDocument();

		// Autodetect: Set Automatically
		if (
			!agent.isDocumentDirty() &&
			doc.canChangeEncoding() &&
			doc.mismatchesEncoding() &&
			prefIs(PREF_AUTODETECT_CHANGE)
		) {
			String message = "Encoding has been set %s automatically.";
			String detectedEncoding = doc.getDetectedCharset();
			IFile file = doc.getFile();
			if (file == null) {
				// Non workspace file, mismatch workspace preferences
				String workspaceEncoding = ResourcesPlugin.getEncoding();
				if (!Charsets.equals(detectedEncoding, workspaceEncoding)) {
					doc.setEncoding(detectedEncoding);
					doc.infoMessage(message, detectedEncoding);
					return; // Reload for setEncoding
				}
			}
			else {
				// Workspace file, if file properties null
				if (Resources.getEncoding(file) == null) {
					doc.setEncoding(detectedEncoding);
					doc.infoMessage(message, detectedEncoding);
					return; // Reload for setEncoding
				}
			}
		}

		encodingLabel.initMenu();
		lineSeparatorLabel.initMenu();
	}
 
Example 11
Source File: PersistentSpellDictionary.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected String getEncoding() {
	String encoding= PreferenceKeys.PKEY_SPELLING_USER_DICTIONARY_ENCODING.getStoredValue();
	if (encoding == null || encoding.length() == 0)
		encoding= ResourcesPlugin.getEncoding();
	return encoding;
}
 
Example 12
Source File: CreateFileChange.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void initializeEncoding() {
	if (fEncoding == null) {
		fExplicitEncoding= false;
		IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(fPath);
		if (file != null) {
			try {
				if (file.exists()) {
					fEncoding= file.getCharset(false);
					if (fEncoding == null) {
						fEncoding= file.getCharset(true);
					} else {
						fExplicitEncoding= true;
					}
				} else {
					IContentType contentType= Platform.getContentTypeManager().findContentTypeFor(file.getName());
					if (contentType != null) {
						fEncoding= contentType.getDefaultCharset();
					}
					if (fEncoding == null) {
						fEncoding= file.getCharset(true);
					}
				}
			} catch (CoreException e) {
				fEncoding= ResourcesPlugin.getEncoding();
				fExplicitEncoding= true;
			}
		} else {
			fEncoding= ResourcesPlugin.getEncoding();
			fExplicitEncoding= true;
		}
	}
	Assert.isNotNull(fEncoding);
}
 
Example 13
Source File: StreamContentDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String getEncoding(Object element) {
	String encoding = ResourcesPlugin.getEncoding();
	if (element instanceof IEncodedStreamContentAccessor) {
		try {
			String streamEncoding = ((IEncodedStreamContentAccessor) element).getCharset();
			if (!Strings.isNullOrEmpty(streamEncoding)) {
				encoding = streamEncoding;
			}
		} catch (CoreException exception) {
		}
	}
	return encoding;
}
 
Example 14
Source File: StreamContentAccessorDelegate.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getCharset() throws CoreException {
	if(streamContentAccessor instanceof IEncodedStreamContentAccessor)
		return ((IEncodedStreamContentAccessor) streamContentAccessor).getCharset();
	else 
		return ResourcesPlugin.getEncoding();
}
 
Example 15
Source File: NonOpenedDocument.java    From eclipse-encoding-plugin with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void updateStatus() {
	// Workspace preferences, not support project prefences
	currentEncoding = ResourcesPlugin.getEncoding();
	lineSeparator = LineSeparators.ofWorkspace();
}
 
Example 16
Source File: DocumentProvider.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public String getDefaultEncoding( )
{
	return ResourcesPlugin.getEncoding( );
}
 
Example 17
Source File: WorkspaceUtilities.java    From ContentAssist with MIT License 2 votes vote down vote up
/**
 * Obtains the encoding to use when reading text files in the workspace.
 * @return the encoding
 */
public static String getEncoding() {
    return ResourcesPlugin.getEncoding();
}