Sitemap3Resource.java

/*
 * Copyright © 2024-2025 The CTAN Team and individual authors
 *
 * This file is distributed under the 3-clause BSD license.
 * See file LICENSE for details.
 */
package org.ctan.site.resources;

import org.ctan.site.services.SitemapService;
import org.ctan.site.services.SitemapService.SitemapList;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.security.PermitAll;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import lombok.NonNull;

/**
 * The class <code>Sitemap3Resource</code> contains the controller for the
 * version resource.
 *
 * @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
 */
@Path("/3.0")
public class Sitemap3Resource {

    /**
     * The field <code>service</code> contains the underlying service.
     */
    private SitemapService service;

    /**
     * This is the constructor for <code>Sitemap3Resource</code>.
     *
     * @param service the underlying service
     */
    @SuppressFBWarnings(value = {"CT_CONSTRUCTOR_THROW", "EI_EXPOSE_REP2"})
    public Sitemap3Resource(@NonNull SitemapService service) {

        this.service = service;
    }

    /**
     * The method <code>sitemap</code> provides means to retrieve the site map
     * as JSON.
     *
     * @return the sitemap items
     */
    @GET
    @Path("sitemap")
    @Produces(MediaType.APPLICATION_JSON)
    @PermitAll
    public SitemapList sitemap() {

        return service.asJson();
    }

    /**
     * The method <code>sitemapVersion</code> provides means to retrieve the
     * current version number.
     *
     * @return the version number as string
     */
    @GET
    @Path("sitemap/version")
    @Produces(MediaType.APPLICATION_JSON)
    @PermitAll
    public String sitemapVersion() {

        return "3.0";
    }

    /**
     * The method <code>sitemapXml</code> provides means to the site map as XML.
     *
     * @return the urlset
     */
    @GET
    @Path("sitemap/xml")
    @Produces(MediaType.APPLICATION_XML)
    @PermitAll
    public String sitemapXml() {

        return service.asXml();
    }

}