Search in sources :

Example 6 with CorsEnable

use of org.opengrok.web.api.v1.filter.CorsEnable in project OpenGrok by OpenGrok.

the class FileController method getContentPlain.

@GET
@CorsEnable
@PathAuthorized
@Path("/content")
@Produces(MediaType.TEXT_PLAIN)
public StreamingOutput getContentPlain(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("path") final String path) throws IOException, ParseException, NoPathParameterException {
    File file = toFile(path);
    Document doc;
    if ((doc = getDocument(file)) == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Cannot get document for file");
        return null;
    }
    String fileType = doc.get(QueryBuilder.T);
    if (!AbstractAnalyzer.Genre.PLAIN.typeName().equals(fileType)) {
        response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE, "Not a text file");
        return null;
    }
    return transfer(file);
}
Also used : Document(org.apache.lucene.document.Document) IndexDatabase.getDocument(org.opengrok.indexer.index.IndexDatabase.getDocument) FileUtil.toFile(org.opengrok.web.util.FileUtil.toFile) File(java.io.File) Path(jakarta.ws.rs.Path) CorsEnable(org.opengrok.web.api.v1.filter.CorsEnable) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET) PathAuthorized(org.opengrok.web.api.v1.filter.PathAuthorized)

Aggregations

GET (jakarta.ws.rs.GET)6 Produces (jakarta.ws.rs.Produces)6 CorsEnable (org.opengrok.web.api.v1.filter.CorsEnable)6 File (java.io.File)4 PathAuthorized (org.opengrok.web.api.v1.filter.PathAuthorized)4 FileUtil.toFile (org.opengrok.web.util.FileUtil.toFile)4 Path (jakarta.ws.rs.Path)2 WebApplicationException (jakarta.ws.rs.WebApplicationException)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 Document (org.apache.lucene.document.Document)2 IndexDatabase.getDocument (org.opengrok.indexer.index.IndexDatabase.getDocument)2 List (java.util.List)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 AbstractAnalyzer (org.opengrok.indexer.analysis.AbstractAnalyzer)1 SuggesterConfig (org.opengrok.indexer.configuration.SuggesterConfig)1 Annotation (org.opengrok.indexer.history.Annotation)1 History (org.opengrok.indexer.history.History)1 Suggestions (org.opengrok.suggest.Suggester.Suggestions)1 SuggesterData (org.opengrok.web.api.v1.suggester.model.SuggesterData)1