Package org.eclipse.core.runtime.content

Examples of org.eclipse.core.runtime.content.IContentDescription


    if (file != null) {
      try {
        IContentTypeManager contentTypeManager = Platform
            .getContentTypeManager();

        IContentDescription contentDescription = file
            .getContentDescription();
        IContentType phpContentType = contentTypeManager
            .getContentType(ContentTypeIdForPHP.ContentTypeID_PHP);
        if (contentDescription != null) {
          IContentType fileContentType = contentDescription
              .getContentType();

          if (phpContentType != null) {
            if (fileContentType.isKindOf(phpContentType)) {
              result = true;
View Full Code Here


    // 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 {
View Full Code Here

  private boolean testContentType(final IFile file, String contentTypeId) {
    final String expectedValue = contentTypeId.trim();

    String actualValue = null;
    try {
      IContentDescription contentDescription = file.getContentDescription();
      if (contentDescription != null) {
        IContentType contentType = contentDescription.getContentType();
        actualValue = contentType.getId();
      }
    } catch (CoreException e) {
      Policy.log(IStatus.ERROR, "Core exception while retrieving the content description", e);//$NON-NLS-1$
    }
View Full Code Here

      // 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);
  }
View Full Code Here

    // if there is a file-specific user setting, use it
    String charset = workspace.getCharsetManager().getCharsetFor(getFullPath(), false);
    if (charset != null || !checkImplicit)
      return charset;
    // tries to obtain a description for the file contents
    IContentDescription description = workspace.getContentDescriptionManager().getDescriptionFor(this, info);
    if (description != null) {
      String contentCharset = description.getCharset();
      if (contentCharset != null)
        return contentCharset;
    }
    // could not find out the encoding based on the contents... default to parent's
    return workspace.getCharsetManager().getCharsetFor(getFullPath().removeLastSegments(1), true);
View Full Code Here

      String extension = file.getFileExtension();
      if (extension != null && "xml".endsWith(extension.toLowerCase(Locale.US)))
        return true;
    }

    IContentDescription contentDescription = null;
    try {
      contentDescription = ((IFile) file).getContentDescription();
      if (contentDescription != null) {
        IContentType contentType = contentDescription.getContentType();
        return contentDescription != null && contentType.isKindOf(getXMLContentType());
      }
    } catch (CoreException e) {
      Logger.logException(e);
    }
View Full Code Here

    if (element instanceof IStorageEditorInput) {
      IStorage storage= ((IStorageEditorInput) element).getStorage();
      Reader reader= null;
      InputStream stream= null;
      try {
        IContentDescription desc;
        IDocument document= getDocument(element);
        if (document != null) {
          reader= new DocumentReader(document);
          desc= Platform.getContentTypeManager().getDescriptionFor(reader, storage.getName(), NO_PROPERTIES);
        } else {
          stream= storage.getContents();
          desc= Platform.getContentTypeManager().getDescriptionFor(stream, storage.getName(), NO_PROPERTIES);
        }
        if (desc != null && desc.getContentType() != null)
          return desc.getContentType();
      } catch (IOException x) {
        IPath path= storage.getFullPath();
        String name;
        if (path != null)
          name= path.toOSString();
View Full Code Here

TOP

Related Classes of org.eclipse.core.runtime.content.IContentDescription

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.