Created
June 10, 2016 04:35
-
-
Save daehwann/64f5601addd70f6d0b8b9cfcb606b132 to your computer and use it in GitHub Desktop.
Html template response. Copied from Apache Sling project (org.apache.sling.servlets.post.HtmlResponse)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //in servlet | |
| response.setContentType("text/html"); | |
| response.setCharacterEncoding("UTF-8"); | |
| // get changelog | |
| changes.insert(0, "<pre>"); | |
| changes.append("</pre>"); | |
| setProperty(PN_CHANGE_LOG, changes.toString()); | |
| Writer out = response.getWriter(); | |
| String templateName; | |
| if(isSafeReferer()) { | |
| templateName = TEMPLATE_NAME; | |
| } else { | |
| templateName = NO_GO_BACK_TEMPLATE_NAME; | |
| } | |
| InputStream template = getClass().getResourceAsStream(templateName); | |
| Reader in = new BufferedReader(new InputStreamReader(template)); | |
| StringBuilder varBuffer = new StringBuilder(); | |
| int state = 0; | |
| int read; | |
| while ((read = in.read()) >= 0) { | |
| char c = (char) read; | |
| switch (state) { | |
| // initial | |
| case 0: | |
| if (c == '$') { | |
| state = 1; | |
| } else { | |
| out.write(c); | |
| } | |
| break; | |
| // $ read | |
| case 1: | |
| if (c == '{') { | |
| state = 2; | |
| } else { | |
| state = 0; | |
| out.write('$'); | |
| out.write(c); | |
| } | |
| break; | |
| // { read | |
| case 2: | |
| if (c == '}') { | |
| state = 0; | |
| Object prop = getProperty(varBuffer.toString()); | |
| if (prop != null) { | |
| out.write(ResponseUtil.escapeXml(prop.toString())); | |
| } | |
| varBuffer.setLength(0); | |
| } else { | |
| varBuffer.append(c); | |
| } | |
| } | |
| } | |
| in.close(); | |
| out.flush(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <title>${title}</title> | |
| </head> | |
| <body> | |
| <h1>${title}</h1> | |
| <table> | |
| <tbody> | |
| <tr> | |
| <td>Status</td> | |
| <td><div id="Status">${status.code}</div></td> | |
| </tr> | |
| <tr> | |
| <td>Message</td> | |
| <td><div id="Message">${status.message}</div></td> | |
| </tr> | |
| <tr> | |
| <td>Location</td> | |
| <td><a href="${location}" id="Location">${location}</a></td> | |
| </tr> | |
| <tr> | |
| <td>Parent Location</td> | |
| <td><a href="${parentLocation}" id="ParentLocation">${parentLocation}</a></td> | |
| </tr> | |
| <tr> | |
| <td>Path</td> | |
| <td><div id="Path">${path}</div></td> | |
| </tr> | |
| <tr> | |
| <td>Referer</td> | |
| <td><a href="${referer}" id="Referer">${referer}</a></td> | |
| </tr> | |
| <tr> | |
| <td>ChangeLog</td> | |
| <td><div id="ChangeLog">${changeLog}</div></td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| <p><a href="${referer}">Go Back</a></p> | |
| <p><a href="${location}">Modified Resource</a></p> | |
| <p><a href="${parentLocation}">Parent of Modified Resource</a></p> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment