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
31 redef fun http_init
(req
) do
32 var name
= req
.param
("id")
33 if name
!= null then name
= name
.from_percent_encoding
34 self.mentity_name
= name
41 redef fun http_init
(req
) do
42 limit
= req
.int_arg
("l")
43 page
= req
.int_arg
("p")
52 redef class CmdMessage
53 # HTTP code to return for this message
54 var http_status_code
= 200
58 redef var http_status_code
= 400
61 redef class CmdWarning
62 redef var http_status_code
= 404
65 redef class ErrorMEntityNoName
66 redef var http_status_code
= 400
69 redef class ErrorMEntityNotFound
70 redef var http_status_code
= 404
73 redef class ErrorMEntityConflict
74 redef var http_status_code
= 300
79 redef class CmdComment
80 redef fun http_init
(req
) do
81 full_doc
= req
.bool_arg
("full_doc") or else true
82 fallback
= req
.bool_arg
("fallback") or else true
83 format
= req
.string_arg
("format") or else "raw"
88 redef class CmdEntityLink
89 redef fun http_init
(req
) do
90 text
= req
.string_arg
("text")
91 title
= req
.string_arg
("title")
96 redef class CmdAncestors
97 redef fun http_init
(req
) do
98 parents
= req
.bool_arg
("parents") or else true
103 redef class CmdDescendants
104 redef fun http_init
(req
) do
105 children
= req
.bool_arg
("children") or else true
110 redef class CmdEntityList
111 # FIXME avoid linearization conflict
112 redef fun http_init
(req
) do return super
115 redef class CmdSearch
116 redef fun http_init
(req
) do
117 query
= req
.string_arg
("q")
122 redef class CmdModelEntities
123 redef fun http_init
(req
) do
124 kind
= req
.string_arg
("kind") or else "all"
130 redef fun http_init
(req
) do
131 format
= req
.string_arg
("format") or else "raw"
136 redef class CmdEntityCode
137 # FIXME avoid linearization conflict
138 redef fun http_init
(req
) do
139 var name
= req
.param
("id")
140 if name
!= null then name
= name
.from_percent_encoding
143 format
= req
.string_arg
("format") or else "raw"
151 redef fun http_init
(req
) do
152 format
= req
.string_arg
("format") or else "dot"
157 redef class CmdInheritanceGraph
158 redef fun http_init
(req
) do
159 pdepth
= req
.int_arg
("pdepth")
160 cdepth
= req
.int_arg
("cdepth")
167 redef class CmdCatalogTag
168 redef fun http_init
(req
) do
169 var tag
= req
.param
("tid")
170 if tag
!= null then tag
= tag
.from_percent_encoding
176 redef class CmdCatalogPerson
177 redef fun http_init
(req
) do
178 var name
= req
.param
("pid")
179 if name
!= null then name
= name
.from_percent_encoding
180 self.person_name
= name