//# 0 errors, 38 messages
//#
/*
    //#UserDataServlet.java:1:1: class: org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet
    //#UserDataServlet.java:1:1: method: org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet.org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet__static_init
 * Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  The ASF licenses this file to You
 * under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.  For additional information regarding
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */

package org.apache.roller.weblogger.ui.struts2.ajax;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.roller.weblogger.WebloggerException;
import org.apache.roller.weblogger.business.Weblogger;
import org.apache.roller.weblogger.business.WebloggerFactory;
import org.apache.roller.weblogger.business.UserManager;
import org.apache.roller.weblogger.pojos.User;


/**
 * Return list of users matching a startsWith strings. <br />
 * Accepts request params (none required):<br />
 *     startsWith: string to be matched against username and email address<br />
 *     enabled: true include only enabled users (default: no restriction<br />
 *     offset: offset into results (for paging)<br />
 *     length: number of users to return (max is 50)<br /><br />
 * List format:<br />
 *     username0, emailaddress0 <br/>
 *     username1, emailaddress1 <br/>
 *     username2, emailaddress2 <br/>
 *     usernameN, emailaddressN <br/>
 */
public class UserDataServlet extends HttpServlet {
    //#UserDataServlet.java:48: method: void org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet.org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet()
    //#input(void org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet()): this
    //#output(void org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet()): this.MAX_LENGTH
    //#post(void org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet()): this.MAX_LENGTH == 50
    
    private final int MAX_LENGTH = 50;
    //#UserDataServlet.java:50: end of method: void org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet.org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet()
    
    public void doGet(HttpServletRequest request, 
                      HttpServletResponse response)
            throws ServletException, IOException {
        
        String startsWith = request.getParameter("startsWith");
    //#UserDataServlet.java:56: method: void org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet.doGet(HttpServletRequest, HttpServletResponse)
    //#input(void doGet(HttpServletRequest, HttpServletResponse)): java.lang.Boolean.FALSE
    //#input(void doGet(HttpServletRequest, HttpServletResponse)): java.lang.Boolean.TRUE
    //#input(void doGet(HttpServletRequest, HttpServletResponse)): request
    //#input(void doGet(HttpServletRequest, HttpServletResponse)): response
    //#pre[1] (void doGet(HttpServletRequest, HttpServletResponse)): request != null
    //#pre[2] (void doGet(HttpServletRequest, HttpServletResponse)): response != null
    //#presumption(void doGet(HttpServletRequest, HttpServletResponse)): init'ed(java.lang.Boolean.FALSE)
    //#presumption(void doGet(HttpServletRequest, HttpServletResponse)): init'ed(java.lang.Boolean.TRUE)
    //#presumption(void doGet(HttpServletRequest, HttpServletResponse)): java.util.Iterator:next(...)@74 != null
    //#presumption(void doGet(HttpServletRequest, HttpServletResponse)): javax.servlet.http.HttpServletResponse:getWriter(...)@75 != null
    //#presumption(void doGet(HttpServletRequest, HttpServletResponse)): javax.servlet.http.HttpServletResponse:getWriter(...)@76 != null
    //#presumption(void doGet(HttpServletRequest, HttpServletResponse)): javax.servlet.http.HttpServletResponse:getWriter(...)@77 != null
    //#presumption(void doGet(HttpServletRequest, HttpServletResponse)): org.apache.roller.weblogger.business.UserManager:getUsersStartingWith(...)@70 != null
    //#presumption(void doGet(HttpServletRequest, HttpServletResponse)): org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@69 != null
    //#presumption(void doGet(HttpServletRequest, HttpServletResponse)): org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@67 != null
    //#test_vector(void doGet(HttpServletRequest, HttpServletResponse)): java.lang.String:equals(...)@60: {0}, {1}
    //#test_vector(void doGet(HttpServletRequest, HttpServletResponse)): java.lang.String:equals(...)@61: {0}, {1}
    //#test_vector(void doGet(HttpServletRequest, HttpServletResponse)): java.util.Iterator:hasNext(...)@73: {0}, {1}
        Boolean enabledOnly = null;
        int offset = 0;
        int length = MAX_LENGTH;
        if ("true".equals(request.getParameter("enabled"))) enabledOnly = Boolean.TRUE;
        if ("false".equals(request.getParameter("enabled"))) enabledOnly = Boolean.FALSE;
        try { offset = Integer.parseInt(request.getParameter("offset"));
        } catch (Throwable ignored) {}
        try { length = Integer.parseInt(request.getParameter("length"));
        } catch (Throwable ignored) {}
        
        Weblogger roller = WebloggerFactory.getWeblogger();
    //#UserDataServlet.java:67: Warning: method not available
    //#    -- call on Weblogger org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet
    //#    method: void doGet(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: Weblogger org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger()
        try {
            UserManager umgr = roller.getUserManager();
    //#UserDataServlet.java:69: Warning: method not available
    //#    -- call on UserManager org.apache.roller.weblogger.business.Weblogger:getUserManager()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet
    //#    method: void doGet(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: UserManager org.apache.roller.weblogger.business.Weblogger:getUserManager()
            List users =
    //#UserDataServlet.java:70: Warning: method not available
    //#    -- call on List org.apache.roller.weblogger.business.UserManager:getUsersStartingWith(String, Boolean, int, int)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet
    //#    method: void doGet(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: List org.apache.roller.weblogger.business.UserManager:getUsersStartingWith(String, Boolean, int, int)
                    umgr.getUsersStartingWith(startsWith, enabledOnly, offset, length);
            Iterator userIter = users.iterator();
            while (userIter.hasNext()) {
                User user = (User)userIter.next();
                response.getWriter().print(user.getUserName());
    //#UserDataServlet.java:75: Warning: method not available
    //#    -- call on String org.apache.roller.weblogger.pojos.User:getUserName()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet
    //#    method: void doGet(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: String org.apache.roller.weblogger.pojos.User:getUserName()
                response.getWriter().print(",");
                response.getWriter().println(user.getEmailAddress());
    //#UserDataServlet.java:77: Warning: method not available
    //#    -- call on String org.apache.roller.weblogger.pojos.User:getEmailAddress()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet
    //#    method: void doGet(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: String org.apache.roller.weblogger.pojos.User:getEmailAddress()
            }
            response.flushBuffer();
        } catch (WebloggerException e) {
            throw new ServletException(e.getMessage());
        }
    }
    //#UserDataServlet.java:83: end of method: void org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet.doGet(HttpServletRequest, HttpServletResponse)
    
}
    //#output(org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/struts2/ajax/UserDataServlet]
    //#output(org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet__static_init): __Dispatch_Table.doGet(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V
    //#post(org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/struts2/ajax/UserDataServlet] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet__static_init): __Dispatch_Table.doGet(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V == &doGet
    //#UserDataServlet.java:: end of method: org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet.org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet__static_init
    //#UserDataServlet.java:: end of class: org.apache.roller.weblogger.ui.struts2.ajax.UserDataServlet
