@Override
  public IContentFormatter getContentFormatter(final ISourceViewer aSourceViewer) {

    if (pDocFormatter == null) {

      pDocFormatter = new ContentFormatter();
      pDocFormatter.enablePartitionAwareFormatting(true);
      pDocFormatter.setDocumentPartitioning(RestPartitionScanner.PARTITIONING);

      // Sections formatter
      pDocFormatter.setFormattingStrategy(
          new SectionFormattingStrategy(), RestPartitionScanner.SECTION_BLOCK);

      // Tables formatter
      pDocFormatter.setFormattingStrategy(
          new GridTableFormattingStrategy(), RestPartitionScanner.GRID_TABLE_BLOCK);

      // TODO RestPartitionScanner.SIMPLE_TABLE_BLOCK
    }

    if (pPreferenceStore.getBoolean(IEditorPreferenceConstants.EDITOR_SAVE_TRIM)) {

      // Removes trailing spaces
      pDocFormatter.setFormattingStrategy(
          new DefaultTextFormattingStrategy(), IDocument.DEFAULT_CONTENT_TYPE);
    } else {

      // Disable it if not in preferences
      pDocFormatter.setFormattingStrategy(null, IDocument.DEFAULT_CONTENT_TYPE);
    }

    return pDocFormatter;
  }
  /**
   * On-save operations :
   *
   * <p>* Un-wrapping if needed
   *
   * <p>* Auto section markers normalization
   *
   * <p>* Auto formating when the editor saves the file
   *
   * @param aSourceViewer The editor source viewer
   */
  public void onEditorPerformSave(final ISourceViewer aSourceViewer) {

    final IDocument document = aSourceViewer.getDocument();

    if (pPreferenceStore.getBoolean(IEditorPreferenceConstants.EDITOR_SAVE_RESET_MARKERS)) {
      // Auto section blocks normalization

      RestContentOutlinePage outlinePage = null;

      if (pEditor != null) {
        outlinePage = pEditor.getOutlinePage();
      }

      if (outlinePage != null) {

        // Don't forget to refresh the tree !
        outlinePage.update();

        OutlineUtil.normalizeSectionsMarker(
            pEditor.getOutlinePage().getContentProvider().getRoot());
      }
    }

    // Formatting text _must_ be the last thing to do : it modifies the
    // document content, therefore it may induce unpredictable behavior for
    // next document readers
    if (pPreferenceStore.getBoolean(IEditorPreferenceConstants.EDITOR_SAVE_FORMAT)) {
      // Text format on save

      // Doc informations
      IRegion docRegion = new Region(0, document.getLength());

      // Store current pointer location
      Point currentLocation = aSourceViewer.getSelectedRange();

      // Format the document
      pDocFormatter.format(document, docRegion);

      // Reset point location
      aSourceViewer.setSelectedRange(currentLocation.x, currentLocation.y);
    }

    if (LineWrapUtil.get().isActiveMode(LineWrapMode.SOFT)) {
      // Soft wrap mode : remove all added end-of-line

      pAutoEditLineWrap.unregisterListener();
      pAutoEditLineWrap.removeWrapping();
    }
  }
  /**
   * Activated the XWikiFormattingStrategy to implement Code Indentation Code Indentation uses
   * XWikiAdvancedPartitionScanner
   */
  public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
    System.out.println("In getContentFormatter");
    ContentFormatter formatter = new ContentFormatter();
    XWikiFormattingStrategy xwikiFormattingStrategy = new XWikiFormattingStrategy(false);
    XWikiFormattingStrategy velocityStrategy1 = new XWikiFormattingStrategy(true);

    formatter.setFormattingStrategy(xwikiFormattingStrategy, IDocument.DEFAULT_CONTENT_TYPE);
    formatter.setFormattingStrategy(velocityStrategy1, XWikiAdvancedPartitionScanner.VELOCITY);
    formatter.setFormattingStrategy(
        velocityStrategy1, XWikiAdvancedPartitionScanner.VELOCITY_FOREACH);
    formatter.setFormattingStrategy(velocityStrategy1, XWikiAdvancedPartitionScanner.VELOCITY_IF);
    formatter.setFormattingStrategy(
        velocityStrategy1, XWikiAdvancedPartitionScanner.VELOCITY_MACRO);
    return formatter;
  }