| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.internal.services; |
| 16 | |
|
| 17 | |
import org.apache.tapestry5.ContentType; |
| 18 | |
import org.apache.tapestry5.MarkupWriter; |
| 19 | |
import org.apache.tapestry5.SymbolConstants; |
| 20 | |
import org.apache.tapestry5.internal.InternalConstants; |
| 21 | |
import org.apache.tapestry5.ioc.annotations.Inject; |
| 22 | |
import org.apache.tapestry5.ioc.annotations.Symbol; |
| 23 | |
import org.apache.tapestry5.json.JSONObject; |
| 24 | |
import org.apache.tapestry5.services.MarkupWriterFactory; |
| 25 | |
import org.apache.tapestry5.services.PartialMarkupRenderer; |
| 26 | |
import org.apache.tapestry5.services.Request; |
| 27 | |
import org.apache.tapestry5.services.Response; |
| 28 | |
|
| 29 | |
import java.io.IOException; |
| 30 | |
import java.io.PrintWriter; |
| 31 | |
|
| 32 | |
public class AjaxPartialResponseRendererImpl implements AjaxPartialResponseRenderer |
| 33 | |
{ |
| 34 | |
private final MarkupWriterFactory factory; |
| 35 | |
|
| 36 | |
private final Request request; |
| 37 | |
|
| 38 | |
private final Response response; |
| 39 | |
|
| 40 | |
private final PartialMarkupRenderer partialMarkupRenderer; |
| 41 | |
|
| 42 | |
private final String outputEncoding; |
| 43 | |
|
| 44 | |
public AjaxPartialResponseRendererImpl(MarkupWriterFactory factory, |
| 45 | |
|
| 46 | |
Request request, |
| 47 | |
|
| 48 | |
Response response, |
| 49 | |
|
| 50 | |
PartialMarkupRenderer partialMarkupRenderer, |
| 51 | |
|
| 52 | |
@Inject @Symbol(SymbolConstants.CHARSET) |
| 53 | |
String outputEncoding) |
| 54 | 2 | { |
| 55 | 2 | this.factory = factory; |
| 56 | 2 | this.request = request; |
| 57 | 2 | this.response = response; |
| 58 | 2 | this.partialMarkupRenderer = partialMarkupRenderer; |
| 59 | 2 | this.outputEncoding = outputEncoding; |
| 60 | 2 | } |
| 61 | |
|
| 62 | |
public void renderPartialPageMarkup() throws IOException |
| 63 | |
{ |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | 36 | ContentType pageContentType = |
| 69 | |
(ContentType) request.getAttribute(InternalConstants.CONTENT_TYPE_ATTRIBUTE_NAME); |
| 70 | |
|
| 71 | 36 | ContentType contentType = new ContentType(InternalConstants.JSON_MIME_TYPE, outputEncoding); |
| 72 | |
|
| 73 | 36 | MarkupWriter writer = factory.newPartialMarkupWriter(pageContentType); |
| 74 | |
|
| 75 | 36 | JSONObject reply = new JSONObject(); |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | 36 | partialMarkupRenderer.renderMarkup(writer, reply); |
| 80 | |
|
| 81 | 36 | PrintWriter pw = response.getPrintWriter(contentType.toString()); |
| 82 | |
|
| 83 | 36 | pw.print(reply); |
| 84 | |
|
| 85 | 36 | pw.close(); |
| 86 | 36 | } |
| 87 | |
} |