|
| 1 | +package org.seqra.complexity; |
| 2 | + |
| 3 | +import org.springframework.stereotype.Controller; |
| 4 | +import org.springframework.web.bind.annotation.GetMapping; |
| 5 | +import org.springframework.web.bind.annotation.RequestParam; |
| 6 | +import org.springframework.web.bind.annotation.ResponseBody; |
| 7 | +import org.springframework.web.util.HtmlUtils; |
| 8 | + |
| 9 | +@Controller |
| 10 | +public class UserProfileController { |
| 11 | + |
| 12 | + // Display user profile with custom message |
| 13 | + @GetMapping("/profile/display") |
| 14 | + @ResponseBody |
| 15 | + public String displayUserProfile( |
| 16 | + @RequestParam(defaultValue = "Welcome") String message) { |
| 17 | + // Direct output without escaping |
| 18 | + return "<html><body><h1>Profile Message: " + message + "</h1></body></html>"; |
| 19 | + } |
| 20 | + |
| 21 | + // Display user profile with escaped message |
| 22 | + @GetMapping("/profile/secureDisplay") |
| 23 | + @ResponseBody |
| 24 | + public String displaySecureUserProfile( |
| 25 | + @RequestParam(defaultValue = "Welcome") String message) { |
| 26 | + // Properly escaped output |
| 27 | + return "<html><body><h1>Profile Message: " + |
| 28 | + HtmlUtils.htmlEscape(message) + "</h1></body></html>"; |
| 29 | + } |
| 30 | + |
| 31 | + // Display user status with local variable assignment |
| 32 | + @GetMapping("/profile/status") |
| 33 | + @ResponseBody |
| 34 | + public String displayUserStatus( |
| 35 | + @RequestParam(defaultValue = "Active") String message) { |
| 36 | + // Assign to local variable |
| 37 | + String htmlContent = "<html><body><h1>User Status: " + |
| 38 | + message + "</h1></body></html>"; |
| 39 | + return htmlContent; |
| 40 | + } |
| 41 | + |
| 42 | + // Display escaped user status with local variable assignment |
| 43 | + @GetMapping("/profile/secureStatus") |
| 44 | + @ResponseBody |
| 45 | + public String displaySecureUserStatus( |
| 46 | + @RequestParam(defaultValue = "Active") String message) { |
| 47 | + // Assign to local variable |
| 48 | + String htmlContent = "<html><body><h1>User Status: " + |
| 49 | + HtmlUtils.htmlEscape(message) + "</h1></body></html>"; |
| 50 | + return htmlContent; |
| 51 | + } |
| 52 | + |
| 53 | + // Generate user dashboard with escaped greeting |
| 54 | + @GetMapping("/dashboard/greeting") |
| 55 | + @ResponseBody |
| 56 | + public String generateDashboard( |
| 57 | + @RequestParam(defaultValue = "Welcome") String greeting) { |
| 58 | + String htmlContent = buildDashboardContent(greeting); |
| 59 | + return htmlContent; |
| 60 | + } |
| 61 | + |
| 62 | + private static String buildDashboardContent(String greeting) { |
| 63 | + // Generate dashboard HTML content |
| 64 | + return "<html><body><h1>Dashboard: " + greeting + "</h1></body></html>"; |
| 65 | + } |
| 66 | + |
| 67 | + // Generate user dashboard with custom greeting |
| 68 | + @GetMapping("/dashboard/secureGreeting") |
| 69 | + @ResponseBody |
| 70 | + public String generateSecureDashboard( |
| 71 | + @RequestParam(defaultValue = "Welcome") String greeting) { |
| 72 | + String htmlContent = buildSecureDashboardContent(greeting); |
| 73 | + return htmlContent; |
| 74 | + } |
| 75 | + |
| 76 | + private static String buildSecureDashboardContent(String greeting) { |
| 77 | + // Generate dashboard HTML content with escaped greeting |
| 78 | + return "<html><body><h1>Dashboard: " + |
| 79 | + HtmlUtils.htmlEscape(greeting) + "</h1></body></html>"; |
| 80 | + } |
| 81 | + |
| 82 | + // Generate message template |
| 83 | + @GetMapping("/notifications/template") |
| 84 | + @ResponseBody |
| 85 | + public String generateTemplate( |
| 86 | + @RequestParam(defaultValue = "New Message") String content) { |
| 87 | + Profile.MessageTemplate template = new Profile.MessageTemplate(content); |
| 88 | + // Return nested content |
| 89 | + return template.body.content.text; |
| 90 | + } |
| 91 | + |
| 92 | + // Generate message template |
| 93 | + @GetMapping("/notifications/secureTemplate") |
| 94 | + @ResponseBody |
| 95 | + public String generateSecureTemplate( |
| 96 | + @RequestParam(defaultValue = "New Message") String content) { |
| 97 | + Profile.MessageTemplate template = new Profile.MessageTemplate(content); |
| 98 | + // Return nested escaped content |
| 99 | + return template.body.content.secureText; |
| 100 | + } |
| 101 | + |
| 102 | + // Generate user notification with complex data structure |
| 103 | + @GetMapping("/notifications/generate") |
| 104 | + @ResponseBody |
| 105 | + public String generateNotification( |
| 106 | + @RequestParam(defaultValue = "New Message") String content) { |
| 107 | + // Create user profile with nested message structure using constructors |
| 108 | + Profile.UserProfile profile = new Profile.UserProfile(content); |
| 109 | + |
| 110 | + // Return nested content |
| 111 | + return profile.settings.config.template.body.content.text; |
| 112 | + } |
| 113 | + |
| 114 | + // Generate user notification with complex data structure |
| 115 | + @GetMapping("/notifications/secureGenerate") |
| 116 | + @ResponseBody |
| 117 | + public String generateSecureNotification( |
| 118 | + @RequestParam(defaultValue = "New Message") String content) { |
| 119 | + // Create user profile with nested message structure using constructors |
| 120 | + Profile.UserProfile profile = new Profile.UserProfile(content); |
| 121 | + |
| 122 | + // Return nested content |
| 123 | + return profile.settings.config.template.body.content.secureText; |
| 124 | + } |
| 125 | + |
| 126 | + // Display custom message |
| 127 | + @GetMapping("/message/display") |
| 128 | + @ResponseBody |
| 129 | + public String displayMessage( |
| 130 | + @RequestParam(defaultValue = "Welcome") String message) { |
| 131 | + // Construct a page using a chain of builders |
| 132 | + String page = new HtmlPageBuilder().message(message).buildPage(); |
| 133 | + |
| 134 | + return page; |
| 135 | + } |
| 136 | + |
| 137 | + // Display custom message |
| 138 | + @GetMapping("/message/secureDisplay") |
| 139 | + @ResponseBody |
| 140 | + public String displaySecureMessage( |
| 141 | + @RequestParam(defaultValue = "Welcome") String message) { |
| 142 | + // Construct a page using a chain of builders |
| 143 | + String page = new HtmlPageBuilder().message(message).escape().buildPage(); |
| 144 | + |
| 145 | + return page; |
| 146 | + } |
| 147 | + |
| 148 | + // Display formatted message |
| 149 | + @GetMapping("/message/format") |
| 150 | + @ResponseBody |
| 151 | + public String formatMessage( |
| 152 | + @RequestParam(defaultValue = "Welcome") String message) { |
| 153 | + // Construct a page using a formatter as a parameter for a chain of builders |
| 154 | + String page = new HtmlPageBuilder().message(message) |
| 155 | + .format(new DefaultFormatter()).buildPage(); |
| 156 | + |
| 157 | + return page; |
| 158 | + } |
| 159 | + |
| 160 | + // Display escaped message |
| 161 | + @GetMapping("/message/escape") |
| 162 | + @ResponseBody |
| 163 | + public String escapeMessage( |
| 164 | + @RequestParam(defaultValue = "Welcome") String message) { |
| 165 | + // Construct a page using a formatter as a parameter for a chain of builders |
| 166 | + String page = new HtmlPageBuilder().message(message) |
| 167 | + .format(new EscapeFormatter()).buildPage(); |
| 168 | + |
| 169 | + return page; |
| 170 | + } |
| 171 | +} |
0 commit comments