use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class JSPValidator method isFragment.
/**
* Determines if file is jsp fragment or not (does a deep, indepth check,
* looking into contents of file)
*
* @param file
* assumes file is not null and exists
* @return true if file is jsp fragment, false otherwise
*/
private boolean isFragment(IFile file) {
boolean isFragment = false;
InputStream is = null;
try {
IContentDescription contentDescription = file.getContentDescription();
// it can be null
if (contentDescription == null) {
is = file.getContents();
contentDescription = Platform.getContentTypeManager().getDescriptionFor(is, file.getName(), new QualifiedName[] { IContentDescription.CHARSET });
}
if (contentDescription != null) {
String fileCtId = contentDescription.getContentType().getId();
isFragment = (fileCtId != null && ContentTypeIdForJSP.ContentTypeID_JSPFRAGMENT.equals(fileCtId));
}
} catch (IOException e) {
// ignore, assume it's invalid JSP
} catch (CoreException e) {
// ignore, assume it's invalid JSP
} finally {
// must close input stream in case others need it
if (is != null)
try {
is.close();
} catch (Exception e) {
// not sure how to recover at this point
}
}
return isFragment;
}
use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class FormatActionDelegate method processorAvailable.
/* (non-Javadoc)
* @see org.eclipse.wst.sse.ui.internal.actions.ResourceActionDelegate#processorAvailable(org.eclipse.core.resources.IResource)
*/
protected boolean processorAvailable(IResource resource) {
boolean result = false;
if (resource.isAccessible()) {
try {
if (resource instanceof IFile) {
IFile file = (IFile) resource;
IStructuredFormatProcessor formatProcessor = null;
IContentDescription contentDescription = file.getContentDescription();
if (contentDescription != null) {
IContentType contentType = contentDescription.getContentType();
formatProcessor = getFormatProcessor(contentType.getId());
}
if (formatProcessor != null)
result = true;
} else if (resource instanceof IContainer) {
IContainer container = (IContainer) resource;
IResource[] members;
members = container.members();
for (int i = 0; i < members.length; i++) {
boolean available = processorAvailable(members[i]);
if (available) {
result = true;
break;
}
}
}
} catch (CoreException e) {
Logger.logException(e);
}
}
return result;
}
use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class StorageModelProvider method getPersistedEncoding.
/* (non-Javadoc)
* @see org.eclipse.ui.editors.text.StorageDocumentProvider#getPersistedEncoding(java.lang.Object)
*/
protected String getPersistedEncoding(Object element) {
String charset = super.getPersistedEncoding(element);
if (charset == null && element instanceof IStorageEditorInput) {
IStorage storage;
try {
storage = ((IStorageEditorInput) element).getStorage();
if (storage != null && !(storage instanceof IEncodedStorage)) {
InputStream contents = null;
try {
contents = storage.getContents();
if (contents != null) {
QualifiedName[] detectionOptions = new QualifiedName[] { IContentDescription.BYTE_ORDER_MARK, IContentDescription.CHARSET };
IContentDescription description = Platform.getContentTypeManager().getDescriptionFor(contents, storage.getName(), detectionOptions);
if (description != null) {
charset = description.getCharset();
}
}
} catch (IOException e) {
} finally {
if (contents != null)
try {
contents.close();
} catch (IOException e) {
// do nothing
}
}
}
} catch (CoreException e) {
Logger.logException(e);
}
}
return charset;
}
use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class JSPBatchValidator method isFragment.
/**
* Determines if file is jsp fragment or not (does a deep, indepth check,
* looking into contents of file)
*
* @param file
* assumes file is not null and exists
* @return true if file is jsp fragment, false otherwise
*/
private boolean isFragment(IFile file) {
boolean isFragment = false;
InputStream is = null;
try {
IContentDescription contentDescription = file.getContentDescription();
// it can be null
if (contentDescription == null) {
is = file.getContents();
contentDescription = Platform.getContentTypeManager().getDescriptionFor(is, file.getName(), new QualifiedName[] { IContentDescription.CHARSET });
}
if (contentDescription != null) {
String fileCtId = contentDescription.getContentType().getId();
isFragment = (fileCtId != null && ContentTypeIdForJSP.ContentTypeID_JSPFRAGMENT.equals(fileCtId));
}
} catch (IOException e) {
// ignore, assume it's invalid JSP
} catch (CoreException e) {
// ignore, assume it's invalid JSP
} finally {
/*
* must close input stream in case others need it
* (IFile.getContents() requirement as well)
*/
if (is != null)
try {
is.close();
} catch (Exception e) {
// not sure how to recover at this point
}
}
return isFragment;
}
use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class JSPActionSourceValidator method isFragment.
/**
* Determines if file is jsp fragment or not (does a deep, indepth check,
* looking into contents of file)
*
* @param file
* assumes file is not null and exists
* @return true if file is jsp fragment, false otherwise
*/
private boolean isFragment(IFile file) {
// copied from JSPValidator
boolean isFragment = false;
InputStream is = null;
try {
IContentDescription contentDescription = file.getContentDescription();
// it can be null
if (contentDescription == null) {
is = file.getContents();
contentDescription = Platform.getContentTypeManager().getDescriptionFor(is, file.getName(), new QualifiedName[] { IContentDescription.CHARSET });
}
if (contentDescription != null) {
String fileCtId = contentDescription.getContentType().getId();
isFragment = (fileCtId != null && ContentTypeIdForJSP.ContentTypeID_JSPFRAGMENT.equals(fileCtId));
}
} catch (IOException e) {
// ignore, assume it's invalid JSP
} catch (CoreException e) {
// ignore, assume it's invalid JSP
} finally {
// must close input stream in case others need it
if (is != null)
try {
is.close();
} catch (Exception e) {
// not sure how to recover at this point
}
}
return isFragment;
}
Aggregations