1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
------------------------------------------------------------------------------
-- Ada Web Server --
-- --
-- Copyright (C) 2003-2004 --
-- ACT-Europe --
-- --
-- This library is free software; you can redistribute it and/or modify --
-- it under the terms of the GNU General Public License as published by --
-- the Free Software Foundation; either version 2 of the License, 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. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License --
-- along with this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
------------------------------------------------------------------------------
with Ada.Text_IO;
with AWS.Config.Set;
with AWS.Messages;
with AWS.Response;
with AWS.Server.Log;
with AWS.Services.Split_Pages.Alpha;
with AWS.Services.Dispatchers.Transient_Pages;
with AWS.Status;
with AWS.Templates;
with AWS.Utils;
procedure Split is
use Ada;
use AWS;
WS : Server.HTTP;
Disp : Services.Dispatchers.Transient_Pages.Handler;
Conf : Config.Object := Config.Get_Current;
function Vect
(Prefix : in String; Size : in Positive)
return Templates.Vector_Tag;
-- Returns a vector tag with Size values, each having the given Prefix
--------
-- CB --
--------
function CB (Request : in Status.Data) return Response.Data is
use Templates;
URI : constant String := Status.URI (Request);
T1 : Translate_Table
:= (Assoc ("ONE", "one"), Assoc ("TWO", "2"), Assoc ("THREE", "3"));
T2 : Translate_Table
:= (Assoc ("V1", Vect ("vector 1 - value ", 300)),
Assoc ("V2", Vect ("vector 2 - value ", 280)));
T3 : Translate_Table
:= (Assoc ("V1", Vect ("vector 1 - value ", 300)),
Assoc ("V2", Vect ("vector 2 - value ", 280)),
Assoc ("KEY", Vect ("key", 300)));
A_Splitter : Services.Split_Pages.Alpha.Splitter;
begin
if URI = "/main" then
return Services.Split_Pages.Parse ("split.thtml", T1, T2, 15, 10);
elsif URI = "/alpha" then
Services.Split_Pages.Alpha.Set_Key (A_Splitter, "KEY");
return Services.Split_Pages.Parse
("split.thtml", T1 & Assoc ("ALPHA", "true"), T3, A_Splitter);
else
return Response.Acknowledge (Messages.S404);
end if;
end CB;
----------
-- Vect --
----------
function Vect
(Prefix : in String; Size : in Positive)
return Templates.Vector_Tag
is
use type Templates.Vector_Tag;
N : constant Natural := (Size / 26) + 1;
V : Templates.Vector_Tag;
A : Natural := 0;
C : Character := 'A';
begin
if Prefix = "key" then
V := V & "" & "" & "1_key" & "5_key" & "9_key";
end if;
for K in 1 .. Size loop
if Prefix = "key" then
V := V & (C & "_" & Prefix & Utils.Image (K));
A := A + 1;
if A = N then
C := Character'Succ (C);
A := 0;
end if;
else
V := V & (Prefix & Utils.Image (K));
end if;
end loop;
return V;
end Vect;
begin
Config.Set.Server_Port (Conf, 8080);
Config.Set.Max_Connection (Conf, 5);
Services.Dispatchers.Transient_Pages.Register
(Disp, CB'Unrestricted_Access);
Server.Start (WS, Disp, Conf);
Server.Log.Start_Error (WS);
Ada.Text_IO.Put_Line ("started, press key Q to exit");
Server.Wait (Server.Q_Key_Pressed);
Server.Shutdown (WS);
Ada.Text_IO.Put_Line ("shutdown");
end Split;
|