001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2011 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * Sonar is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.colorizer; 021 022 public class HtmlOptions { 023 public static final HtmlOptions DEFAULT = new HtmlOptions(true, null, true); 024 public static final OnlySyntaxHtmlOptions ONLY_SYNTAX = new OnlySyntaxHtmlOptions(); 025 026 private boolean generateTable = true; 027 private boolean generateHtmlHeader = true; 028 private String tableId = null; 029 private int firstLineId = 1; 030 031 public HtmlOptions() { 032 } 033 034 public HtmlOptions(boolean generateTable, String tableId, boolean generateHtmlHeader) { 035 this.generateTable = generateTable; 036 this.generateHtmlHeader = generateHtmlHeader; 037 this.tableId = tableId; 038 } 039 040 public boolean isGenerateTable() { 041 return generateTable; 042 } 043 044 public HtmlOptions setGenerateTable(boolean b) { 045 this.generateTable = b; 046 return this; 047 } 048 049 /** 050 * Used only if isGenerateTable() is true 051 */ 052 public boolean isGenerateHtmlHeader() { 053 return generateHtmlHeader; 054 } 055 056 /** 057 * Defines if the HTML header, including CSS, must be generated. 058 */ 059 public HtmlOptions setGenerateHtmlHeader(boolean b) { 060 this.generateHtmlHeader = b; 061 return this; 062 } 063 064 public String getTableId() { 065 return tableId; 066 } 067 068 /** 069 * Used only if isGenerateTable() is true. This field is optional. 070 */ 071 public HtmlOptions setTableId(String id) { 072 this.tableId = id; 073 return this; 074 } 075 076 /** 077 * Used only if isGenerateTable() is true. Default value is 1. 078 */ 079 public int getFirstLineId() { 080 return firstLineId; 081 } 082 083 public HtmlOptions setFirstLineId(int i) { 084 this.firstLineId = i; 085 return this; 086 } 087 } 088 089 class OnlySyntaxHtmlOptions extends HtmlOptions { 090 091 @Override 092 public boolean isGenerateTable() { 093 return false; 094 } 095 096 @Override 097 public boolean isGenerateHtmlHeader() { 098 return false; 099 } 100 101 @Override 102 public String getTableId() { 103 return null; 104 } 105 106 @Override 107 public HtmlOptions setGenerateHtmlHeader(boolean b) { 108 throw new IllegalStateException(); 109 } 110 111 @Override 112 public HtmlOptions setGenerateTable(boolean b) { 113 throw new IllegalStateException(); 114 } 115 116 @Override 117 public HtmlOptions setTableId(String id) { 118 throw new IllegalStateException(); 119 } 120 }