1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Initialize commands from HTTP requests
17 # FIXME: this module is pretty tied up to the nitwed routes.
18 # To be more generic, param names should be extracted as variables.
22 import commands
::commands_catalog
23 import nitcorn
::vararg_routes
25 redef class DocCommand
26 # Init the command from an HTTPRequest
27 fun http_init
(req
: HttpRequest): CmdMessage do return init_command
33 redef fun http_init
(req
) do
34 var name
= req
.param
("id")
35 if name
!= null then name
= name
.from_percent_encoding
36 self.mentity_name
= name
43 redef fun http_init
(req
) do
44 limit
= req
.int_arg
("l")
45 page
= req
.int_arg
("p")
54 redef class CmdMessage
55 # HTTP code to return for this message
56 var http_status_code
= 200
60 redef var http_status_code
= 400
63 redef class CmdWarning
64 redef var http_status_code
= 404
67 redef class ErrorMEntityNoName
68 redef var http_status_code
= 400
71 redef class ErrorMEntityNotFound
72 redef var http_status_code
= 404
75 redef class ErrorMEntityConflict
76 redef var http_status_code
= 300
81 redef class CmdComment
82 redef fun http_init
(req
) do
83 full_doc
= req
.bool_arg
("full_doc") or else true
84 fallback
= req
.bool_arg
("fallback") or else true
85 format
= req
.string_arg
("format") or else "raw"
90 redef class CmdAncestors
91 redef fun http_init
(req
) do
92 parents
= req
.bool_arg
("parents") or else true
97 redef class CmdDescendants
98 redef fun http_init
(req
) do
99 children
= req
.bool_arg
("children") or else true
104 redef class CmdEntityList
105 # FIXME avoid linearization conflict
106 redef fun http_init
(req
) do return super
109 redef class CmdSearch
110 redef fun http_init
(req
) do
111 query
= req
.string_arg
("q")
116 redef class CmdModelEntities
117 redef fun http_init
(req
) do
118 kind
= req
.string_arg
("kind") or else "all"
124 redef fun http_init
(req
) do
125 format
= req
.string_arg
("format") or else "raw"
133 redef fun http_init
(req
) do
134 format
= req
.string_arg
("format") or else "dot"
139 redef class CmdInheritanceGraph
140 redef fun http_init
(req
) do
141 pdepth
= req
.int_arg
("pdepth")
142 cdepth
= req
.int_arg
("cdepth")
149 redef class CmdCatalogTag
150 redef fun http_init
(req
) do
151 var tag
= req
.param
("tid")
152 if tag
!= null then tag
= tag
.from_percent_encoding
158 redef class CmdCatalogPerson
159 redef fun http_init
(req
) do
160 var name
= req
.param
("pid")
161 if name
!= null then name
= name
.from_percent_encoding
162 self.person_name
= name