001: // Copyright 2007 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package org.apache.tapestry.internal.services;
016:
017: import java.util.List;
018:
019: import org.apache.tapestry.MarkupWriter;
020: import org.apache.tapestry.internal.InternalConstants;
021: import org.apache.tapestry.services.ObjectRenderer;
022: import org.apache.tapestry.services.Request;
023:
024: public class RequestRenderer implements ObjectRenderer<Request> {
025: public void render(Request request, MarkupWriter writer) {
026: writer.element("dl");
027:
028: dt(writer, "Context Path");
029:
030: writer.element("dd");
031:
032: String contextPath = request.getContextPath();
033:
034: if (contextPath.equals("")) {
035: writer.element("em");
036: writer.write("none (deployed as root)");
037: writer.end();
038: } else {
039: writer.write(contextPath);
040: }
041: writer.end(); // dd
042:
043: dt(writer, "Request Path");
044: dd(writer, request.getPath());
045:
046: dt(writer, "Locale");
047: dd(writer, request.getLocale().toString());
048:
049: writer.end();
050:
051: parameters(request, writer);
052: headers(request, writer);
053: }
054:
055: private void parameters(Request request, MarkupWriter writer) {
056: List<String> parameterNames = request.getParameterNames();
057:
058: if (parameterNames.isEmpty())
059: return;
060:
061: section(writer, "Query Parameters");
062:
063: writer.element("dl");
064:
065: for (String name : parameterNames) {
066: String[] values = request.getParameters(name);
067:
068: dt(writer, name);
069:
070: writer.element("dd");
071:
072: if (values.length > 1) {
073: writer.element("ul");
074:
075: for (String value : values) {
076: writer.element("li");
077: writer.write(value);
078: writer.end();
079: }
080:
081: writer.end(); // ul
082: } else {
083: writer.write(values[0]);
084: }
085:
086: writer.end(); // dd
087: }
088:
089: writer.end(); // dl
090: }
091:
092: private void dt(MarkupWriter writer, String name) {
093: writer.element("dt");
094: writer.write(name);
095: writer.end();
096: }
097:
098: private void dd(MarkupWriter writer, String name) {
099: writer.element("dd");
100: writer.write(name);
101: writer.end();
102: }
103:
104: private void section(MarkupWriter writer, String name) {
105: writer.element("div", "class",
106: InternalConstants.OBJECT_RENDER_DIV_SECTION);
107: writer.write(name);
108: writer.end();
109: }
110:
111: private void headers(Request request, MarkupWriter writer) {
112: section(writer, "Headers");
113:
114: writer.element("dl");
115:
116: for (String name : request.getHeaderNames()) {
117: dt(writer, name);
118: dd(writer, request.getHeader(name));
119: }
120:
121: writer.end(); // dl
122:
123: }
124:
125: }
|