<commit_before>/*
 * Made with all the love in the world
 * by scireum in Remshalden, Germany
 *
 * Copyright by scireum GmbH
 * http://www.scireum.de - <EMAIL>
 */

package ninja.errors;

import sirius.kernel.commons.Strings;
import sirius.kernel.di.std.Register;
import sirius.kernel.xml.XMLStructuredOutput;
import sirius.web.http.WebContext;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * Synthesizes <em>S3</em> <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html">error
 * responses</a>.
 */
@Register(classes = S3ErrorSynthesizer.class)
public class S3ErrorSynthesizer {

    /**
     * Synthesizes an error response.
     *
     * @param ctx the request to process.
     * @param bucket the requested bucket, potentially <b>null</b>.
     * @param key the requested object's key, potentially <b>null</b>.
     * @param code the error code to send.
     * @param message a human-readable description of the error.
     */
    public void synthesiseError(@Nonnull WebContext ctx,
                                @Nullable String bucket,
                                @Nullable String key,
                                @Nonnull S3ErrorCode code,
                                @Nullable String message) {
        XMLStructuredOutput
                xml = new XMLStructuredOutput(ctx.respondWith()
                                                 .outputStream(code.getHttpStatusCode(), "text/xml"));

        String resource = null;
        if (Strings.isFilled(bucket)) {
            resource = "/" + bucket;
            if (Strings.isFilled(key)) {
                resource += "/" + key;
            }
        }

        xml.beginOutput("Error");
        xml.property("Code", code.toString());
        xml.propertyIfFilled("Message", message);
        xml.propertyIfFilled("Resource", resource);
        // xml.property("RequestId", XXX); // a real error includes this request id that would need to be generated here
        xml.endOutput();
    }
}<commit_msg>Removes dead code 😵<commit_after>/*
 * Made with all the love in the world
 * by scireum in Remshalden, Germany
 *
 * Copyright by scireum GmbH
 * http://www.scireum.de - <EMAIL>
 */

package ninja.errors;

import sirius.kernel.commons.Strings;
import sirius.kernel.di.std.Register;
import sirius.kernel.xml.XMLStructuredOutput;
import sirius.web.http.WebContext;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * Synthesizes <em>S3</em> <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html">error
 * responses</a>.
 */
@Register(classes = S3ErrorSynthesizer.class)
public class S3ErrorSynthesizer {

    /**
     * Synthesizes an error response.
     *
     * @param ctx the request to process.
     * @param bucket the requested bucket, potentially <b>null</b>.
     * @param key the requested object's key, potentially <b>null</b>.
     * @param code the error code to send.
     * @param message a human-readable description of the error.
     */
    public void synthesiseError(@Nonnull WebContext ctx,
                                @Nullable String bucket,
                                @Nullable String key,
                                @Nonnull S3ErrorCode code,
                                @Nullable String message) {
        XMLStructuredOutput
                xml = new XMLStructuredOutput(ctx.respondWith()
                                                 .outputStream(code.getHttpStatusCode(), "text/xml"));

        String resource = null;
        if (Strings.isFilled(bucket)) {
            resource = "/" + bucket;
            if (Strings.isFilled(key)) {
                resource += "/" + key;
            }
        }

        xml.beginOutput("Error");
        xml.property("Code", code.toString());
        xml.propertyIfFilled("Message", message);
        xml.propertyIfFilled("Resource", resource);
        xml.endOutput();
    }
}
{'fraction_non_alphanumeric': 0.11215427556457752, 'fraction_numerical': 0.002537427048972342, 'mean_word_length': 2.12609040444092, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 17}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2362388', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1071, 'n_words': 271}