001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2014 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube 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 * SonarQube 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 License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.api.profiles; 021 022import java.io.Writer; 023import org.apache.commons.lang.StringUtils; 024import org.apache.commons.lang.builder.ToStringBuilder; 025import org.apache.commons.lang.builder.ToStringStyle; 026import org.sonar.api.ExtensionPoint; 027import org.sonar.api.batch.BatchSide; 028import org.sonar.api.server.ServerSide; 029 030/** 031 * @since 2.3 032 */ 033@BatchSide 034@ServerSide 035@ExtensionPoint 036public abstract class ProfileExporter { 037 038 private String[] supportedLanguages = new String[0]; 039 private String key; 040 private String name; 041 private String mimeType = "plain/text"; 042 043 protected ProfileExporter(String key, String name) { 044 this.key = key; 045 this.name = name; 046 } 047 048 public abstract void exportProfile(RulesProfile profile, Writer writer); 049 050 public String getKey() { 051 return key; 052 } 053 054 public final ProfileExporter setKey(String s) { 055 this.key = s; 056 return this; 057 } 058 059 public final String getName() { 060 return name; 061 } 062 063 public final ProfileExporter setName(String s) { 064 this.name = s; 065 return this; 066 } 067 068 protected final ProfileExporter setSupportedLanguages(String... languages) { 069 supportedLanguages = (languages != null) ? languages : new String[0]; 070 return this; 071 } 072 073 public String getMimeType() { 074 return mimeType; 075 } 076 077 public final ProfileExporter setMimeType(String s) { 078 if (StringUtils.isNotBlank(s)) { 079 this.mimeType = s; 080 } 081 return this; 082 } 083 084 /** 085 * @return if empty, then any languages are supported. 086 */ 087 public String[] getSupportedLanguages() { 088 return supportedLanguages; 089 } 090 091 @Override 092 public final boolean equals(Object o) { 093 if (this == o) { 094 return true; 095 } 096 if (o == null || getClass() != o.getClass()) { 097 return false; 098 } 099 ProfileExporter that = (ProfileExporter) o; 100 return !((key != null) ? !key.equals(that.key) : (that.key != null)); 101 } 102 103 @Override 104 public final int hashCode() { 105 return key != null ? key.hashCode() : 0; 106 } 107 108 @Override 109 public String toString() { 110 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) 111 .append("key", key) 112 .append("name", name) 113 .append("mimeType", mimeType) 114 .append("languages", supportedLanguages) 115 .toString(); 116 } 117}