/**
   * This code is used to activate syntax coloring for each section detected by the
   * XWikiPartitionner The partitioner is activated in createDocument in PageDocumentProvider.java
   *
   * @see PageDocumentProvider#createDocument(Object)
   */
  @Override
  public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
    PresentationReconciler reconciler = new PresentationReconciler();
    reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));

    /* Use the XWiki markup for tables and default content. */
    DefaultDamagerRepairer dr = new DefaultDamagerRepairer(new XWikiMarkupScanner());
    reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
    reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);

    reconciler.setDamager(dr, XWikiPartitionScanner.XWIKI_TABLE);
    reconciler.setRepairer(dr, XWikiPartitionScanner.XWIKI_TABLE);

    /* Use the Velocity Scanner for velocity blocks */
    dr = new DefaultDamagerRepairer(new VelocityScanner());
    reconciler.setDamager(dr, XWikiPartitionScanner.VELOCITY);
    reconciler.setRepairer(dr, XWikiPartitionScanner.VELOCITY);

    /* Use the Groovy Scanner for groovy blocks */
    dr = new DefaultDamagerRepairer(new GroovyScanner());
    reconciler.setDamager(dr, XWikiPartitionScanner.GROOVY);
    reconciler.setRepairer(dr, XWikiPartitionScanner.GROOVY);

    /* Use a uniform style for html blocks. */
    RuleBasedScanner codeScanner = new RuleBasedScanner();
    codeScanner.setDefaultReturnToken(
        new Token(Preferences.getDefault().getTextAttribute(Preferences.Style.HTML)));
    dr = new DefaultDamagerRepairer(codeScanner);
    reconciler.setDamager(dr, XWikiPartitionScanner.XWIKI_HTML);
    reconciler.setRepairer(dr, XWikiPartitionScanner.XWIKI_HTML);

    /* Use a uniform style for code blocks. */
    codeScanner = new RuleBasedScanner();
    codeScanner.setDefaultReturnToken(
        new Token(Preferences.getDefault().getTextAttribute(Preferences.Style.CODE)));
    dr = new DefaultDamagerRepairer(codeScanner);
    reconciler.setDamager(dr, XWikiPartitionScanner.XWIKI_CODE);
    reconciler.setRepairer(dr, XWikiPartitionScanner.XWIKI_CODE);

    /* Use a uniform style for pre blocks. */
    RuleBasedScanner preScanner = new RuleBasedScanner();
    preScanner.setDefaultReturnToken(
        new Token(Preferences.getDefault().getTextAttribute(Preferences.Style.CODE)));
    dr = new DefaultDamagerRepairer(preScanner);
    reconciler.setDamager(dr, XWikiPartitionScanner.XWIKI_PRE);
    reconciler.setRepairer(dr, XWikiPartitionScanner.XWIKI_PRE);

    RuleBasedScanner javadocScanner = new GroovyScanner();
    dr = new DefaultDamagerRepairer(javadocScanner);
    reconciler.setDamager(dr, GroovyPartitionScanner.GROOVY_DEFAULT);
    reconciler.setRepairer(dr, GroovyPartitionScanner.GROOVY_DEFAULT);

    return reconciler;
  }
 protected ITokenScanner getStringScanner() {
   if (stringScanner == null) {
     stringScanner = new RuleBasedScanner();
     stringScanner.setDefaultReturnToken(getToken(ICSSConstants.CSS_STRING_SCOPE));
   }
   return stringScanner;
 }
 protected ITokenScanner getWordScanner() {
   if (multilineCommentScanner == null) {
     multilineCommentScanner = new RuleBasedScanner();
     multilineCommentScanner.setDefaultReturnToken(
         getToken(ICSSConstants.CSS_COMMENT_BLOCK_SCOPE));
   }
   return multilineCommentScanner;
 }
Esempio n. 4
0
 ITokenScanner getCommentScanner() {
   // lazy init
   if (this.commentScanner == null) {
     final Token comment =
         new Token(new TextAttribute(JFaceResources.getColorRegistry().get(COMMENT_COLOR)));
     // no rules needed, because this will apply to comment partition only
     final RuleBasedScanner ruleBasedScanner = new RuleBasedScanner();
     // this will apply the syntax
     ruleBasedScanner.setDefaultReturnToken(comment);
     this.commentScanner = ruleBasedScanner;
   }
   return commentScanner;
 }
 private void setupScannerType(PresentationReconciler reconciler, String typeName) {
   String[] contentTypes = mode.getContentTypes();
   for (int i = 0; i < contentTypes.length; i++) {
     String contentType = contentTypes[i];
     if (!contentType.startsWith(typeName)) continue;
     RuleBasedScanner scanner = new RuleBasedScanner();
     String type = contentType.substring(contentType.lastIndexOf('.') + 1);
     IToken defaultToken = newToken(colorManager.colorForType(type));
     scanner.setDefaultReturnToken(defaultToken);
     DefaultDamagerRepairer dr = new DefaultDamagerRepairer(scanner);
     reconciler.setDamager(dr, contentType);
     reconciler.setRepairer(dr, contentType);
   }
 }
 private void setupScannerTypeForMark(PresentationReconciler reconciler) {
   String[] contentTypes = mode.getContentTypes();
   for (int i = 0; i < contentTypes.length; i++) {
     String contentType = contentTypes[i];
     if (contentType.startsWith(Type.MARK_PREVIOUS)
         || contentType.startsWith(Type.MARK_FOLLOWING)) {
       RuleBasedScanner scanner = new RuleBasedScanner();
       String colorType = contentType.substring(contentType.lastIndexOf('.') + 1);
       LToken defaultToken = (LToken) newToken(colorManager.colorForType(colorType), true);
       defaultToken.setLength(getLength(contentType));
       defaultToken.isPrevious(contentType.startsWith(Type.MARK_PREVIOUS));
       scanner.setDefaultReturnToken(defaultToken);
       DefaultDamagerRepairer dr = new MarkDamagerRepairer(scanner);
       reconciler.setDamager(dr, contentType);
       reconciler.setRepairer(dr, contentType);
     }
   }
 }
  private RuleBasedScanner getDelegateScanner(Rule rule) {
    RuleBasedScanner scanner = new RuleBasedScanner();
    List rules = new ArrayList();

    String colorName = colorManager.colorForType(rule.getDefaultTokenType());
    IToken defaultToken = newToken(colorName);
    scanner.setDefaultReturnToken(defaultToken);
    ColoringEditorTools.add(
        rule,
        rules,
        new ITokenFactory() {
          public IToken makeToken(Type type) {
            String color = colorManager.colorForType(type.getColor());
            return newToken(color);
          }
        });
    addTextSequenceRules(rule, rules, defaultToken);

    scanner.setRules((IRule[]) rules.toArray(new IRule[rules.size()]));
    return scanner;
  }