/**
  * 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;
 }