EMMA Coverage Report (generated Fri Sep 15 10:32:43 EDT 2006)
[all classes][org.apache.pluto.driver]

COVERAGE SUMMARY FOR SOURCE FILE [TCKDriverServlet.java]

nameclass, %method, %block, %line, %
TCKDriverServlet.java0%   (0/1)0%   (0/8)0%   (0/238)0%   (0/50)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TCKDriverServlet0%   (0/1)0%   (0/8)0%   (0/238)0%   (0/50)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/1)
TCKDriverServlet (): void 0%   (0/1)0%   (0/6)0%   (0/2)
debugWithName (String): void 0%   (0/1)0%   (0/14)0%   (0/3)
doGet (HttpServletRequest, HttpServletResponse): void 0%   (0/1)0%   (0/25)0%   (0/8)
doPost (HttpServletRequest, HttpServletResponse): void 0%   (0/1)0%   (0/5)0%   (0/2)
doSetup (HttpServletRequest, HttpServletResponse): void 0%   (0/1)0%   (0/172)0%   (0/30)
getServletInfo (): String 0%   (0/1)0%   (0/2)0%   (0/1)
init (): void 0%   (0/1)0%   (0/10)0%   (0/3)

1/*
2 * Copyright 2003,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.apache.pluto.driver;
17 
18import org.apache.pluto.PortletContainer;
19import org.apache.pluto.driver.services.portal.PageConfig;
20import org.apache.pluto.driver.config.AdminConfiguration;
21import org.apache.commons.logging.Log;
22import org.apache.commons.logging.LogFactory;
23 
24import javax.servlet.http.HttpServletRequest;
25import javax.servlet.http.HttpServletResponse;
26import javax.servlet.ServletContext;
27import javax.servlet.ServletException;
28import java.io.IOException;
29import java.text.DecimalFormat;
30 
31/**
32 * TCK Driver Servlet.
33 *
34 * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
35 * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
36 * @version 1.0
37 * @since Dec 11, 2005
38 */
39public class TCKDriverServlet extends PortalDriverServlet {
40        
41        /** Logger. */
42    private static final Log LOG = LogFactory.getLog(TCKDriverServlet.class);
43    
44    private int pageCounter = 0;
45    
46    public String getServletInfo() {
47        return "Pluto TCK Driver Servlet";
48    }
49 
50    public void init() {
51        ServletContext servletContext = getServletContext();
52        container = (PortletContainer) servletContext.getAttribute(
53                AttributeKeys.PORTLET_CONTAINER);
54    }
55    
56    /**
57     * Overwrites <code>super.doGet(..)</code>. If <code>portletName</code>
58     * (multiple occurrences) parameter is received, the driver is attempting
59     * to create a new page. This page must be setup and then redirected to the
60     * actual page. Otherwise, the driver calls <code>super.doGet(..)</code>
61     * to continue as normal.
62     * @param request  the incoming servlet request.
63     * @param response  the incoming servlet response.
64     * @throws IOException
65     * @throws ServletException
66     */
67    public void doGet(HttpServletRequest request, HttpServletResponse response)
68    throws IOException, ServletException {
69        String[] portletNames = request.getParameterValues("portletName");
70        if (portletNames != null && portletNames.length > 0) {
71                debugWithName("Initializing new TCK page...");
72            doSetup(request, response);
73        } else {
74                debugWithName("No portlet names specified. Continue as normal.");
75                super.doGet(request, response);
76        }
77    }
78 
79    public void doPost(HttpServletRequest req, HttpServletResponse response)
80    throws IOException, ServletException {
81        super.doGet(req, response);
82    }
83    
84    
85    // Private Methods ---------------------------------------------------------
86    
87    private void doSetup(HttpServletRequest request,
88                         HttpServletResponse response)
89    throws IOException, ServletException {
90        String[] portletNames = request.getParameterValues("portletName");
91        String pageName = request.getParameter("pageName");
92        if (pageName != null) {
93                debugWithName("Retrieved page name from request: " + pageName);
94        } else {
95                debugWithName("Creating page name...");
96                AdminConfiguration adminConfig = (AdminConfiguration)
97                            getServletContext()
98                            .getAttribute(AttributeKeys.DRIVER_ADMIN_CONFIG);
99            if (adminConfig == null) {
100                throw new ServletException("Invalid configuration: "
101                                + "an AdminConfiguration must be specified "
102                                + "to run the TCK.");
103            }
104            
105            pageName = (new DecimalFormat("TCK00000")).format(pageCounter++);
106            PageConfig pageConfig = new PageConfig();
107            pageConfig.setName(pageName);
108            pageConfig.setUri(DEFAULT_PAGE_URI);
109            for (int i = 0; i < portletNames.length; i++) {
110                    debugWithName("Processing portlet name: " + portletNames[i]);
111                int index = portletNames[i].indexOf("/");
112                String contextPath = "/" + portletNames[i].substring(0, index);
113                String portletName = portletNames[i].substring(index + 1);
114                // IU_MOD--START
115                // TODO: This might cause a problem without the id
116                pageConfig.addPortlet(contextPath, portletName, "");
117                // IU_MOD--END
118                adminConfig.getPortletRegistryAdminService()
119                                .addPortletApplication(contextPath);
120            }
121 
122            adminConfig.getRenderConfigAdminService().addPage(pageConfig);
123            debugWithName("Created TCK Page: " + pageName);
124        }
125 
126        // The other possibility would be to redirect to the actual portal.
127        //   I'm not sure which is better at this point.
128        StringBuffer buffer = new StringBuffer();
129        buffer.append(request.getRequestURL().toString());
130        if (!request.getRequestURL().toString().endsWith("/")) {
131                buffer.append("/");
132        }
133        buffer.append(pageName);
134        debugWithName("Sending redirect to: " + buffer.toString());
135        response.sendRedirect(buffer.toString());
136    }
137    
138    /**
139     * Prints debug message with a <code>[Pluto TCK Driver]</code> prefix.
140     * @param message  message to debug.
141     */
142    private void debugWithName(String message) {
143            if (LOG.isDebugEnabled()) {
144                    LOG.debug("[Pluto TCK Driver] " + message);
145            }
146    }
147    
148}

[all classes][org.apache.pluto.driver]
EMMA 2.0.5312 (C) Vladimir Roubtsov