@ Override public void paint ( final RenderContext renderContext ) { if ( ! doTransform ) { super . paint ( renderContext ) ; return ; } if ( ! ( renderContext instanceof WebXmlRenderContext ) ) { LOG . warn ( "Unable to transform a " + renderContext ) ; super . paint ( renderContext ) ; return ; } LOG . debug ( "Transform XML Interceptor: Start" ) ; UIContext uic = UIContextHolder . getCurrent ( ) ; // Set up a render context to buffer the XML payload. StringWriter xmlBuffer = new StringWriter ( ) ; PrintWriter xmlWriter = new PrintWriter ( xmlBuffer ) ; WebXmlRenderContext xmlContext = new WebXmlRenderContext ( xmlWriter , uic . getLocale ( ) ) ; super . paint ( xmlContext ) ; // write the XML to the buffer // Get a handle to the true PrintWriter. WebXmlRenderContext webRenderContext = ( WebXmlRenderContext ) renderContext ; PrintWriter writer = webRenderContext . getWriter ( ) ; /* * Switch the response content-type to HTML. * In theory the transformation could be to ANYTHING (not just HTML) so perhaps it would make more sense to * write a new interceptor "ContentTypeInterceptor" which attempts to sniff payloads and choose the correct * content-type. This is exactly the kind of thing IE6 loved to do, so perhaps it's a bad idea. */ Response response = getResponse ( ) ; response . setContentType ( WebUtilities . CONTENT_TYPE_HTML ) ; String xml = xmlBuffer . toString ( ) ; if ( isAllowCorruptCharacters ( ) && ! Util . empty ( xml ) ) { // Remove illegal HTML characters from the content before transforming it. xml = removeCorruptCharacters ( xml ) ; } // Double encode template tokens in the XML xml = WebUtilities . doubleEncodeBrackets ( xml ) ; // Setup temp writer StringWriter tempBuffer = new StringWriter ( ) ; PrintWriter tempWriter = new PrintWriter ( tempBuffer ) ; // Perform the transformation and write the result. transform ( xml , uic , tempWriter ) ; // Decode Double Encoded Brackets String tempResp = tempBuffer . toString ( ) ; tempResp = WebUtilities . doubleDecodeBrackets ( tempResp ) ; // Write response writer . write ( tempResp ) ; LOG . debug ( "Transform XML Interceptor: Finished" ) ; }
Override paint to perform XML to HTML transformation .