{"id":8958,"date":"2012-09-27T17:11:35","date_gmt":"2012-09-27T11:41:35","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=8958"},"modified":"2012-09-27T17:11:35","modified_gmt":"2012-09-27T11:41:35","slug":"cool-way-to-getset-processed-html-markup-in-filters","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/","title":{"rendered":"Cool way to get\/set processed HTML Markup in filters"},"content":{"rendered":"<p>Hi, <\/p>\n<p>&nbsp;<\/p>\n<p>There was a case where i had to encrypt the HTML output of the GSP before displaying it to user. There are a lot of ways to do it, but i wanted to make is as simple as possible. Hence here is the pattern i used:<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Note:<\/strong> This is just an example, you can use this concept to do thousands of cool things, like: <strong>pdf export etc.. <\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>ON THE GSP<br \/>\n[html]<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;meta name=&quot;encrypt&quot; value=&quot;true&quot; \/&gt;<br \/>\n    &#8230;<br \/>\n&lt;\/head&gt;<br \/>\n &#8230;. misc code<br \/>\n&lt;\/html&gt;<br \/>\n[\/html]<br \/>\nHere what is did is, i created a GSP and just added a meta property to it saying &#8220;encrypt true&#8221;.<\/p>\n<p>&nbsp;<\/p>\n<p>Now here is the Code for the Grails Filters (See inline comments)<br \/>\n[java]<br \/>\ndef filters = {<br \/>\n        all(controller: &#8216;*&#8217;, action: &#8216;*&#8217;) {<br \/>\n            before = {<br \/>\n            }<br \/>\n            after = { Map model -&gt;<br \/>\n                try {<br \/>\n                    \/\/Get the Site Mesh Page Instance<br \/>\n                    GSPSitemeshPage sitemeshPage = response?.getContent() as GSPSitemeshPage<\/p>\n<p>                    \/\/Check if it is actual sitemest page, not just plain rendered content<br \/>\n                    if (sitemeshPage &amp;&amp; sitemeshPage.getPage()) {<br \/>\n                        \/\/Get the meta property value.<br \/>\n                        String metaPropValue = sitemeshPage.getProperty(&quot;meta.encrypt&quot;)<br \/>\n                        if (metaPropValue &amp;&amp; metaPropValue == &quot;true&quot;) {<br \/>\n                            \/\/This is how you can get html contents of head\/body after all tags resolved.<br \/>\n                            String head = new String(sitemeshPage.getHead())<br \/>\n                            String body = new String(sitemeshPage.getBody())<\/p>\n<p>                            \/\/Buffer for new body<br \/>\n                            StreamCharBuffer writer = new StreamCharBuffer()<br \/>\n                            \/\/Write to buffer new content<br \/>\n                            writer.getWriter().write(encryptionService.encrypt(body))<br \/>\n                            sitemeshPage.setBodyBuffer(writer)<br \/>\n                        }<br \/>\n                    }<br \/>\n                } catch (Throwable ex) {<br \/>\n                    ex.printStackTrace()<br \/>\n                }<br \/>\n            }<br \/>\n            afterView = { Exception e -&gt;<\/p>\n<p>            }<br \/>\n        }<br \/>\n    }<br \/>\n[\/java]<\/p>\n<p>&nbsp;<\/p>\n<p>And hence we have this processed content in response \ud83d\ude42<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Regards<br \/>\nKushal Likhi<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, &nbsp; There was a case where i had to encrypt the HTML output of the GSP before displaying it to user. There are a lot of ways to do it, but i wanted to make is as simple as possible. Hence here is the pattern i used: &nbsp; Note: This is just an example, [&hellip;]<\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4,"footnotes":""},"categories":[7],"tags":[1093,4840,9],"class_list":["post-8958","post","type-post","status-publish","format-standard","hentry","category-grails","tag-filters","tag-grails","tag-groovy"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Hi, There was a case where i had to encrypt the HTML output of the GSP before displaying it to user. There are a lot of ways to do it, but i wanted to make is as simple as possible. Hence here is the pattern i used: Note: This is just an example,\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Kushal Likhi\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Cool way to get\/set processed HTML Markup in filters | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Hi, There was a case where i had to encrypt the HTML output of the GSP before displaying it to user. There are a lot of ways to do it, but i wanted to make is as simple as possible. Hence here is the pattern i used: Note: This is just an example,\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Cool way to get\/set processed HTML Markup in filters | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Hi, There was a case where i had to encrypt the HTML output of the GSP before displaying it to user. There are a lot of ways to do it, but i wanted to make is as simple as possible. Hence here is the pattern i used: Note: This is just an example,\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/cool-way-to-getset-processed-html-markup-in-filters\\\/#article\",\"name\":\"Cool way to get\\\/set processed HTML Markup in filters | TO THE NEW Blog\",\"headline\":\"Cool way to get\\\/set processed HTML Markup in filters\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/kushal\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2012-09-27T17:11:35+05:30\",\"dateModified\":\"2012-09-27T17:11:35+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":1,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/cool-way-to-getset-processed-html-markup-in-filters\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/cool-way-to-getset-processed-html-markup-in-filters\\\/#webpage\"},\"articleSection\":\"Grails, Filters, Grails, Groovy\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/cool-way-to-getset-processed-html-markup-in-filters\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"position\":2,\"name\":\"Grails\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/cool-way-to-getset-processed-html-markup-in-filters\\\/#listItem\",\"name\":\"Cool way to get\\\/set processed HTML Markup in filters\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/cool-way-to-getset-processed-html-markup-in-filters\\\/#listItem\",\"position\":3,\"name\":\"Cool way to get\\\/set processed HTML Markup in filters\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/kushal\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/kushal\\\/\",\"name\":\"Kushal Likhi\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/cool-way-to-getset-processed-html-markup-in-filters\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9311812a092d64f47eb30d7ad28378cfae924a0cac140ffbb686fcd8a565a57e?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Kushal Likhi\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/cool-way-to-getset-processed-html-markup-in-filters\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/cool-way-to-getset-processed-html-markup-in-filters\\\/\",\"name\":\"Cool way to get\\\/set processed HTML Markup in filters | TO THE NEW Blog\",\"description\":\"Hi, There was a case where i had to encrypt the HTML output of the GSP before displaying it to user. There are a lot of ways to do it, but i wanted to make is as simple as possible. Hence here is the pattern i used: Note: This is just an example,\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/cool-way-to-getset-processed-html-markup-in-filters\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/kushal\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/kushal\\\/#author\"},\"datePublished\":\"2012-09-27T17:11:35+05:30\",\"dateModified\":\"2012-09-27T17:11:35+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Cool way to get\/set processed HTML Markup in filters | TO THE NEW Blog","description":"Hi, There was a case where i had to encrypt the HTML output of the GSP before displaying it to user. There are a lot of ways to do it, but i wanted to make is as simple as possible. Hence here is the pattern i used: Note: This is just an example,","canonical_url":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/#article","name":"Cool way to get\/set processed HTML Markup in filters | TO THE NEW Blog","headline":"Cool way to get\/set processed HTML Markup in filters","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/kushal\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2012-09-27T17:11:35+05:30","dateModified":"2012-09-27T17:11:35+05:30","inLanguage":"en-US","commentCount":1,"mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/#webpage"},"articleSection":"Grails, Filters, Grails, Groovy"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","position":2,"name":"Grails","item":"https:\/\/www.tothenew.com\/blog\/category\/grails\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/#listItem","name":"Cool way to get\/set processed HTML Markup in filters"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/#listItem","position":3,"name":"Cool way to get\/set processed HTML Markup in filters","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/kushal\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/kushal\/","name":"Kushal Likhi","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/9311812a092d64f47eb30d7ad28378cfae924a0cac140ffbb686fcd8a565a57e?s=96&d=mm&r=g","width":96,"height":96,"caption":"Kushal Likhi"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/","name":"Cool way to get\/set processed HTML Markup in filters | TO THE NEW Blog","description":"Hi, There was a case where i had to encrypt the HTML output of the GSP before displaying it to user. There are a lot of ways to do it, but i wanted to make is as simple as possible. Hence here is the pattern i used: Note: This is just an example,","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/kushal\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/kushal\/#author"},"datePublished":"2012-09-27T17:11:35+05:30","dateModified":"2012-09-27T17:11:35+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Cool way to get\/set processed HTML Markup in filters | TO THE NEW Blog","og:description":"Hi, There was a case where i had to encrypt the HTML output of the GSP before displaying it to user. There are a lot of ways to do it, but i wanted to make is as simple as possible. Hence here is the pattern i used: Note: This is just an example,","og:url":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Cool way to get\/set processed HTML Markup in filters | TO THE NEW Blog","twitter:description":"Hi, There was a case where i had to encrypt the HTML output of the GSP before displaying it to user. There are a lot of ways to do it, but i wanted to make is as simple as possible. Hence here is the pattern i used: Note: This is just an example,","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"8958","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-30 00:18:05","updated":"2024-02-29 08:46:20","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/grails\/\" title=\"Grails\">Grails<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tCool way to get\/set processed HTML Markup in filters\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Grails","link":"https:\/\/www.tothenew.com\/blog\/category\/grails\/"},{"label":"Cool way to get\/set processed HTML Markup in filters","link":"https:\/\/www.tothenew.com\/blog\/cool-way-to-getset-processed-html-markup-in-filters\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=8958"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8958\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=8958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=8958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=8958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}