/**
  * Returns the defined encoding for the given module.
  *
  * <pre>
  * The search for the encoding is done in this order:
  * 1. Check the encoding that is set specifically to a LocalModule.
  * 2. Check the workspace default charset.
  * 3. If all the above fails, get ResourcesPlugin.getEncoding(), which actually gets the encoding from the system.
  * </pre>
  *
  * @param module an {@link IModule}.
  * @return The module's encoding.
  */
 public static String getModuleEncoding(IModule module) {
   String charset = null;
   try {
     if (module instanceof LocalModule) {
       IFile file = ((LocalModule) module).getFile();
       if (file != null) {
         String fileCharset = file.getCharset(true);
         if (fileCharset != null) {
           charset = fileCharset;
         }
       }
     }
   } catch (Throwable e) {
     // If there is any error, return the default
     IdeLog.logInfo(
         PHPEditorPlugin.getDefault(),
         "PHP encoding utils - Returning the default encoding due to an error (getModuleEncoding)", //$NON-NLS-1$
         e,
         PHPEditorPlugin.DEBUG_SCOPE);
   }
   if (charset == null) {
     try {
       IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
       charset = workspaceRoot.getDefaultCharset(true);
     } catch (CoreException ce) {
       charset = WorkbenchEncoding.getWorkbenchDefaultEncoding();
     }
   }
   if (charset == null) {
     // Use the system's encoding
     charset = ResourcesPlugin.getEncoding();
   }
   return charset;
 }
  /**
   * Add value to the list of workbench encodings.
   *
   * @param value
   */
  public static void addIDEEncoding(String value) {

    if (WorkbenchEncoding.getDefinedEncodings().contains(value)) {
      return;
    }

    writeEncodingsPreference(value, getIDEEncodingsPreference());
  }
  /**
   * Get all of the available encodings including any that were saved as a preference in the IDE or
   * in core resources.
   *
   * @return List of String
   */
  public static List getIDEEncodings() {
    List encodings = getIDEEncodingsPreference();
    encodings.addAll(WorkbenchEncoding.getDefinedEncodings());

    String enc = getResourceEncoding();

    if (!(enc == null || encodings.contains(enc))) {
      encodings.add(enc);
    }

    Collections.sort(encodings);
    return encodings;
  }