use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.
the class TestContentTypeHandlers method testCreation.
public void testCreation() {
IContentTypeManager registry = getContentTypeRegistry();
assertTrue("content type identifer registry must exist", registry != null);
if (DEBUG) {
IContentType[] allTypes = registry.getAllContentTypes();
for (int i = 0; i < allTypes.length; i++) {
System.out.println(allTypes[i]);
}
}
}
use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.
the class FileUtil method isXMLFile.
/**
* Determines if a file is one of the valid XML content types.
* @param file The input IFile to check
* @return True if it is a XML file, false otherwise.
*/
public static boolean isXMLFile(IFile file) {
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
IContentType[] types = contentTypeManager.findContentTypesFor(file.getName());
for (IContentType contentType : types) {
if (// $NON-NLS-1$ //$NON-NLS-2$
contentType.isKindOf(contentTypeManager.getContentType("org.eclipse.core.runtime.xml")) || contentType.isKindOf(contentTypeManager.getContentType("org.eclipse.wst.xml.core.xmlsource"))) {
return true;
}
}
return false;
}
use of org.eclipse.core.runtime.content.IContentTypeManager in project polymap4-core by Polymap4.
the class FileState method getCharset.
/* (non-Javadoc)
* @see org.eclipse.core.resources.IEncodedStorage#getCharset()
*/
public String getCharset() throws CoreException {
// if there is an existing file at this state's path, use the encoding of that file
IResource file = workspace.getRoot().findMember(fullPath);
if (file != null && file.getType() == IResource.FILE)
return ((IFile) file).getCharset();
// tries to obtain a description for the file contents
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
InputStream contents = new BufferedInputStream(getContents());
boolean failed = false;
try {
IContentDescription description = contentTypeManager.getDescriptionFor(contents, getName(), new QualifiedName[] { IContentDescription.CHARSET });
return description == null ? null : description.getCharset();
} catch (IOException e) {
failed = true;
String message = NLS.bind(Messages.history_errorContentDescription, getFullPath());
throw new ResourceException(IResourceStatus.FAILED_DESCRIBING_CONTENTS, getFullPath(), message, e);
} finally {
try {
contents.close();
} catch (IOException e) {
if (!failed) {
String message = NLS.bind(Messages.history_errorContentDescription, getFullPath());
throw new ResourceException(IResourceStatus.FAILED_DESCRIBING_CONTENTS, getFullPath(), message, e);
}
}
}
}
use of org.eclipse.core.runtime.content.IContentTypeManager in project polymap4-core by Polymap4.
the class File method getCharsetFor.
/* (non-Javadoc)
* @see IFile#getCharsetFor(Reader)
*/
public String getCharsetFor(Reader contents) throws CoreException {
String charset;
ResourceInfo info = getResourceInfo(false, false);
int flags = getFlags(info);
if (exists(flags, true))
// the file exists, look for user setting
if ((charset = workspace.getCharsetManager().getCharsetFor(getFullPath(), false)) != null)
// if there is a file-specific user setting, use it
return charset;
// tries to obtain a description from the contents provided
IContentDescription description;
try {
// TODO need to take project specific settings into account
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
description = contentTypeManager.getDescriptionFor(contents, getName(), new QualifiedName[] { IContentDescription.CHARSET });
} catch (IOException e) {
String message = NLS.bind(Messages.resources_errorContentDescription, getFullPath());
throw new ResourceException(IResourceStatus.FAILED_DESCRIBING_CONTENTS, getFullPath(), message, e);
}
if (description != null)
if ((charset = description.getCharset()) != null)
// the description contained charset info, we are done
return charset;
// could not find out the encoding based on the contents... default to parent's
return workspace.getCharsetManager().getCharsetFor(getFullPath().removeLastSegments(1), true);
}
use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.
the class ValidatorStrategy method calculateParentContentTypeIds.
/**
* The content type passed in should be the most specific one. TODO: This
* exact method is also in ValidatorMetaData. Should be in a common place.
*
* @param contentType
* @return
*/
private String[] calculateParentContentTypeIds(String contentTypeId) {
Set parentTypes = new HashSet();
IContentTypeManager ctManager = Platform.getContentTypeManager();
IContentType ct = ctManager.getContentType(contentTypeId);
String id = contentTypeId;
while (ct != null && id != null) {
parentTypes.add(id);
ct = ctManager.getContentType(id);
if (ct != null) {
IContentType baseType = ct.getBaseType();
id = (baseType != null) ? baseType.getId() : null;
}
}
return (String[]) parentTypes.toArray(new String[parentTypes.size()]);
}
Aggregations