use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.
the class ValidatorMetaData method calculateParentContentTypeIds.
/**
* TODO: This exact method is also in ValidatorStrategy. Should be in a common place.
*
* @param contentTypeId
* @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()]);
}
use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.
the class CodedReaderCreator method checkForEncodingInContents.
private EncodingMemento checkForEncodingInContents(InputStream limitedStream) throws CoreException, IOException {
EncodingMemento result = null;
// have been set, and no need to get again.
if (fEncodingMemento != null) {
result = fEncodingMemento;
} else {
if (fClientSuppliedStream) {
try {
limitedStream.reset();
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
IContentDescription contentDescription = contentTypeManager.getDescriptionFor(limitedStream, fFilename, IContentDescription.ALL);
if (contentDescription != null) {
fEncodingMemento = createMemento(contentDescription);
}
result = fEncodingMemento;
} finally {
limitedStream.reset();
}
} else {
// throw new IllegalStateException("unexpected state:
// encodingMemento was null but no input stream supplied by
// client"); //$NON-NLS-1$
result = null;
}
}
if (result != null && !result.isValid() && !forceDefault()) {
throw new UnsupportedCharsetExceptionWithDetail(result);
}
return result;
}
use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.
the class CodedReaderCreator method findMementoFromStreamCase.
/**
* The primary method which contains the highest level rules for how to
* decide appropriate decoding rules: 1. first check for unicode stream 2.
* then looked for encoding specified in content (according to the type of
* content that is it ... xml, html, jsp, etc. 3. then check for various
* settings: file settings first, if null check project settings, if null,
* check user preferences. 4. lastly (or, what is the last user
* preference) is to use "workbench defaults".
*
* @throws IOException
* @throws CoreException
*/
private EncodingMemento findMementoFromStreamCase() throws CoreException, IOException {
EncodingMemento result = null;
InputStream resettableLimitedStream = null;
try {
resettableLimitedStream = getLimitedStream(getResettableStream());
if (resettableLimitedStream != null) {
// first check for unicode stream
result = checkStreamForBOM(resettableLimitedStream);
// if not that, then check contents
if (result == null) {
resettableLimitedStream.reset();
result = checkForEncodingInContents(resettableLimitedStream);
}
} else {
// stream null, may name's not.
if (fFilename != null) {
// filename not null
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
IContentDescription contentDescription = contentTypeManager.getDescriptionFor(new NullInputStream(), fFilename, IContentDescription.ALL);
if (contentDescription != null) {
result = createMemento(contentDescription);
}
}
}
} finally {
if (resettableLimitedStream != null) {
handleStreamClose(resettableLimitedStream);
}
}
return result;
}
use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.
the class StructuredTextEditor method installCharacterPairing.
private void installCharacterPairing() {
IStructuredModel model = getInternalModel();
if (model != null) {
// $NON-NLS-1$
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(SSEUIPlugin.ID, "characterPairing");
IContentTypeManager mgr = Platform.getContentTypeManager();
IContentType type = mgr.getContentType(model.getContentTypeIdentifier());
if (type != null) {
for (int i = 0; i < elements.length; i++) {
// Create the inserter
IConfigurationElement element = elements[i];
try {
IConfigurationElement[] contentTypes = element.getChildren("contentTypeIdentifier");
for (int j = 0; j < contentTypes.length; j++) {
String id = contentTypes[j].getAttribute("id");
if (id != null) {
IContentType targetType = mgr.getContentType(id);
int priority = calculatePriority(type, targetType, 0);
if (priority >= 0) {
final CharacterPairing pairing = new CharacterPairing();
pairing.priority = priority;
String[] partitions = StringUtils.unpack(contentTypes[j].getAttribute("partitions"));
pairing.partitions = new HashSet(partitions.length);
// Only add the inserter if there is at least one partition for the content type
for (int k = 0; k < partitions.length; k++) {
pairing.partitions.add(partitions[k]);
}
pairing.inserter = (AbstractCharacterPairInserter) element.createExecutableExtension("class");
if (pairing.inserter != null && partitions.length > 0) {
fPairInserter.addInserter(pairing);
/* use a SafeRunner since this method is also invoked during Part creation */
SafeRunner.run(new ISafeRunnable() {
public void run() throws Exception {
pairing.inserter.initialize();
}
public void handleException(Throwable exception) {
// rely on default logging
}
});
}
}
}
}
} catch (CoreException e) {
Logger.logException(e);
}
}
fPairInserter.prioritize();
}
}
}
use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.
the class TestContentTypeHandlers method testJSPExistsByFileExtension.
public void testJSPExistsByFileExtension() throws IOException {
String filename = "test.jsp";
IContentTypeManager registry = getContentTypeRegistry();
IContentType identifier = registry.getDescriptionFor(new NullStream(), filename, IContentDescription.ALL).getContentType();
assertTrue("content type identifier for " + filename + " does not have JSP type ", identifier != null);
}
Aggregations