/demo/src/view-dir.adb
http://github.com/ThomasLocke/yolk · Ada · 93 lines · 56 code · 13 blank · 24 comment · 1 complexity · f4fd1e29b59b793efa60b5bd7cb1e7af MD5 · raw file
- -------------------------------------------------------------------------------
- -- --
- -- Copyright (C) 2010-, Thomas Løcke --
- -- --
- -- This is free software; you can redistribute it and/or modify it --
- -- under terms of the GNU General Public License as published by the --
- -- Free Software Foundation; either version 3, or (at your option) any --
- -- later version. This library is distributed in the hope that it will be --
- -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
- -- You should have received a copy of the GNU General Public License and --
- -- a copy of the GCC Runtime Library Exception along with this program; --
- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
- -- <http://www.gnu.org/licenses/>. --
- -- --
- -------------------------------------------------------------------------------
- with Ada.Directories;
- with AWS.Services.Directory;
- with Yolk.Configuration;
- with Yolk.Not_Found;
- package body View.Dir is
- function Directory_Browse_Response
- (Directory_Name : in String;
- Request : in AWS.Status.Data)
- return AWS.Response.Data;
- -- Generate the directory listing response.
- ---------------------------------
- -- Directory_Browse_Response --
- ---------------------------------
- function Directory_Browse_Response
- (Directory_Name : in String;
- Request : in AWS.Status.Data)
- return AWS.Response.Data
- is
- use AWS.Templates;
- use Yolk.Configuration;
- T : Translate_Set;
- begin
- T := AWS.Services.Directory.Browse
- (Directory_Name => Directory_Name,
- Request => Request);
- Insert (T, Assoc ("YOLK_VERSION", Yolk.Version));
- return Build_Response
- (Status_Data => Request,
- Template_File =>
- Config.Get (System_Templates_Path) & "/directory.tmpl",
- Translations => T);
- end Directory_Browse_Response;
- ---------------
- -- Generate --
- ---------------
- function Generate
- (Request : in AWS.Status.Data)
- return AWS.Response.Data
- is
- use Ada.Directories;
- use Yolk.Configuration;
- URL : constant String := AWS.Status.URI (Request);
- Resource : constant String (1 .. (URL'Length - 4))
- := URL (5 .. (URL'Length));
- -- Get rid of the /dir part of the URL
- Parent_Directory : constant String := Config.Get (WWW_Root);
- begin
- if not Exists (Parent_Directory & Resource) then
- return Not_Found.Generate (Request);
- end if;
- case Kind (Parent_Directory & Resource) is
- when Directory =>
- return Directory_Browse_Response
- (Directory_Name => Parent_Directory & Resource,
- Request => Request);
- when Ordinary_File =>
- return AWS.Response.File
- (Content_Type => AWS.Status.Content_Type (Request),
- Filename => Parent_Directory & Resource);
- when others =>
- return Not_Found.Generate (Request);
- end case;
- end Generate;
- end View.Dir;