use of org.sonar.api.server.ws.Response.Stream in project sonarqube by SonarSource.
the class ExportAction method define.
@Override
public void define(WebService.NewController controller) {
NewAction action = controller.createAction("export").setSince("5.2").setDescription("Export a quality profile.").setResponseExample(getClass().getResource("export-example.xml")).setHandler(this);
action.createParam(PARAM_PROFILE_NAME).setDescription("The name of the quality profile to export. If left empty, will export the default profile for the language.").setExampleValue("My Sonar way");
action.createParam(PARAM_LANGUAGE).setDescription("The language for the quality profile.").setExampleValue(LanguageParamUtils.getExampleValue(languages)).setPossibleValues(LanguageParamUtils.getLanguageKeys(languages)).setRequired(true);
Set<String> exporterKeys = Arrays.stream(languages.all()).map(language -> exporters.exportersForLanguage(language.getKey())).flatMap(Collection::stream).map(ProfileExporter::getKey).collect(Collectors.toSet());
if (!exporterKeys.isEmpty()) {
action.createParam(PARAM_FORMAT).setDescription("Output format. If left empty, the same format as api/qualityprofiles/backup is used. " + "Possible values are described by api/qualityprofiles/exporters.").setPossibleValues(exporterKeys).setDeprecatedKey("format", "6.3");
}
}
use of org.sonar.api.server.ws.Response.Stream in project sonarqube by SonarSource.
the class BackupAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
Stream stream = response.stream();
stream.setMediaType(MediaTypes.XML);
try (OutputStreamWriter writer = new OutputStreamWriter(stream.output(), StandardCharsets.UTF_8);
DbSession dbSession = dbClient.openSession(false)) {
QualityProfileDto profile = profileFactory.find(dbSession, QProfileRef.from(request));
response.setHeader("Content-Disposition", String.format("attachment; filename=%s.xml", profile.getKee()));
backuper.backup(profile.getKee(), writer);
}
}
use of org.sonar.api.server.ws.Response.Stream in project sonarqube by SonarSource.
the class ExportAction method writeResponse.
private void writeResponse(QualityProfileDto profile, @Nullable String exporterKey, Response response) throws IOException {
Stream stream = response.stream();
try (DbSession dbSession = dbClient.openSession(false);
OutputStream output = response.stream().output();
Writer writer = new OutputStreamWriter(output, StandardCharsets.UTF_8)) {
if (exporterKey == null) {
stream.setMediaType(MediaTypes.XML);
backuper.backup(dbSession, profile, writer);
} else {
stream.setMediaType(exporters.mimeType(exporterKey));
exporters.export(profile, exporterKey, writer);
}
}
}
Aggregations