-
Notifications
You must be signed in to change notification settings - Fork 1
/
xml_payload_m.f90
61 lines (46 loc) · 1.86 KB
/
xml_payload_m.f90
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
module xml_payload_m
use http_response_m
use persistent_collection_m
use http_response_codes
use http_content_types
implicit none
private
type, public, extends(http_response_t) :: xml_payload_t
private
contains
procedure, public, pass(this) :: write_success, &
write_error, &
write_body
end type xml_payload_t
contains
subroutine write_success(this, the_data)
class(xml_payload_t), intent(inout) :: this
class(persistent_collection_t), intent(inout) :: the_data
call this%write_headers()
print '(a)', '<?xml version="1.0" encoding="UTF-8"?>'
print '(a)', '<response>'
print '(a)', '<status>Success</status>'
print '(a,i9,a)', '<count>', the_data%get_collection_size(), '</count>'
print '(a,a,a)', '<type>', trim(the_data%get_object_name()), '</type>'
print '(a)', '<results>'
call this%write_body(the_data)
print '(a)', '</results>'
print '(a)', '</response>'
end subroutine write_success
subroutine write_error(this, error_msg)
class(xml_payload_t), intent(inout) :: this
character(len=*), intent(in) :: error_msg
call this%write_headers()
print '(a)', '<?xml version="1.0" encoding="UTF-8"?>'
print '(a)', '<response>'
print '(a,a,a)', '<status>', error_msg, '</status>'
print '(a)', '<count>0</count>'
print '(a)', '<type>Error</type>'
print '(a)', '<results></results>'
print '(a)', '</response>'
end subroutine write_error
subroutine write_body(this, the_data)
class(xml_payload_t), intent(inout) :: this
class(persistent_collection_t), intent(inout) :: the_data
end subroutine write_body
end module xml_payload_m