Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

HtmlDecorator.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * SonarQube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.colorizer;
  21. import org.sonar.channel.CodeReader;
  22. /**
  23. * @deprecated since 4.5.2 replace by highlighting mechanism
  24. */
  25. @Deprecated
  26. public class HtmlDecorator extends Tokenizer {
  27. private HtmlOptions options;
  28. private int lineId;
  29. private static final int LF = '\n';
  30. private static final int CR = '\r';
  31. public HtmlDecorator(HtmlOptions options) {
  32. this.options = options;
  33. this.lineId = options.getFirstLineId();
  34. }
  35. public String getTagBeginOfFile() {
  36. StringBuilder sb = new StringBuilder();
  37. if (options.isGenerateHtmlHeader()) {
  38. sb.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "
  39. + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><body>");
  40. }
  41. sb.append("<table class=\"code\" id=\"");
  42. if (options.getTableId() != null) {
  43. sb.append(options.getTableId());
  44. }
  45. sb.append("\"><tbody><tr id=\"").append(lineId++).append("\"><td><pre>");
  46. return sb.toString();
  47. }
  48. public String getTagEndOfFile() {
  49. StringBuilder sb = new StringBuilder();
  50. sb.append("</pre></td></tr></tbody></table>");
  51. if (options.isGenerateHtmlHeader()) {
  52. sb.append("</body></html>");
  53. }
  54. return sb.toString();
  55. }
  56. public String getTagBefore() {
  57. String tag = "<tr id=\"" + lineId + "\"><td><pre>";
  58. lineId++;
  59. return tag;
  60. }
  61. public String getTagAfter() {
  62. return "</pre></td></tr>";
  63. }
  64. @Override
  65. public boolean consume(CodeReader code, HtmlCodeBuilder codeBuilder) {
  66. int lineNumber = code.getLinePosition();
  67. if (code.peek() == LF || code.peek() == CR) {
  68. code.pop();
  69. if (lineNumber != code.getLinePosition()) {
  70. codeBuilder.appendWithoutTransforming(getTagAfter());
  71. codeBuilder.appendWithoutTransforming(getTagBefore());
  72. }
  73. return true;
  74. }
  75. return false;
  76. }
  77. }