Example usage for javax.servlet ServletContext getRequestDispatcher

List of usage examples for javax.servlet ServletContext getRequestDispatcher

Introduction

In this page you can find the example usage for javax.servlet ServletContext getRequestDispatcher.

Prototype

public RequestDispatcher getRequestDispatcher(String path);

Source Link

Document

Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.

Usage

From source file:com.ikon.servlet.admin.DatabaseQueryServlet.java

/**
 * Execute Hibernate query/*from  ww w.  j  a v a 2s .co  m*/
 */
private void executeHibernate(Session session, String qs, ServletContext sc, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException, HibernateException,
        DatabaseException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    StringTokenizer st = new StringTokenizer(qs, "\n\r");
    List<GlobalResult> globalResults = new ArrayList<DatabaseQueryServlet.GlobalResult>();

    // For each query line
    while (st.hasMoreTokens()) {
        String tk = st.nextToken().trim();

        if (tk.toUpperCase().startsWith("--") || tk.equals("") || tk.equals("\r")) {
            // Is a comment, so ignore it
        } else {
            if (tk.endsWith(";")) {
                tk = tk.substring(0, tk.length() - 1);
            }

            globalResults.add(executeHQL(session, tk, null));
        }
    }

    //sc.setAttribute("sql", HibernateUtil.toSql(qs));
    sc.setAttribute("exception", null);
    sc.setAttribute("globalResults", globalResults);
    sc.getRequestDispatcher("/admin/database_query.jsp").forward(request, response);
}

From source file:org.etudes.ambrosia.impl.UiServiceImpl.java

/**
 * {@inheritDoc}//from  www.ja  v  a 2  s  . c  o m
 */
public boolean dispatchResource(HttpServletRequest req, HttpServletResponse res, ServletContext context,
        Set<String> prefixes) throws IOException, ServletException {
    // see if we have a resource request
    String path = req.getPathInfo();
    if (isResourceRequest(prefixes, path)) {
        // get a dispatcher to the path
        RequestDispatcher resourceDispatcher = context.getRequestDispatcher(path);
        if (resourceDispatcher != null) {
            resourceDispatcher.forward(req, res);
            return true;
        }
    }

    return false;
}

From source file:it.classhidra.core.controller.bsController.java

public static void service_ActionErrorRedirect(String id_action, ServletContext servletContext,
        HttpServletRequest request, HttpServletResponse response) {
    String redirectURI = "";
    try {/*from  ww w.  j ava 2  s . co m*/
        i_action action_instance = getAction_config().actionFactory(id_action, request.getSession(),
                request.getSession().getServletContext());
        redirectURI = action_instance.get_infoaction().getError();
        if (redirectURI.equals("")) {
            if (getAction_config() == null || getAction_config().getError() == null
                    || getAction_config().getError().equals(""))
                redirectURI = "";
            else
                redirectURI = getAction_config().getError();
        }
        if (!response.isCommitted())
            servletContext.getRequestDispatcher(redirectURI).forward(request, response);
        else
            servletContext.getRequestDispatcher(redirectURI).include(request, response);

    } catch (Exception ex) {
        writeLog(request,
                "Controller generic redirect error. Action: [" + id_action + "] URI: [" + redirectURI + "]");
    }
}

From source file:com.ikon.servlet.admin.ConfigServlet.java

/**
 * List config/*from w ww .jav a  2  s  .co  m*/
 */
private void list(String userId, String filter, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, DatabaseException {
    log.debug("list({}, {}, {}, {})", new Object[] { userId, filter, request, response });
    ServletContext sc = getServletContext();
    List<Config> list = ConfigDAO.findAll();

    for (Iterator<Config> it = list.iterator(); it.hasNext();) {
        Config cfg = it.next();

        if (Config.STRING.equals(cfg.getType())) {
            cfg.setType("String");
        } else if (Config.TEXT.equals(cfg.getType())) {
            cfg.setType("Text");
        } else if (Config.BOOLEAN.equals(cfg.getType())) {
            cfg.setType("Boolean");
        } else if (Config.INTEGER.equals(cfg.getType())) {
            cfg.setType("Integer");
        } else if (Config.LONG.equals(cfg.getType())) {
            cfg.setType("Long");
        } else if (Config.LIST.equals(cfg.getType())) {
            cfg.setType("List");
        } else if (Config.SELECT.equals(cfg.getType())) {
            cfg.setType("Select");
            ConfigStoredSelect stSelect = new Gson().fromJson(cfg.getValue(), ConfigStoredSelect.class);

            for (ConfigStoredOption stOption : stSelect.getOptions()) {
                if (stOption.isSelected()) {
                    cfg.setValue(stOption.getValue());
                }
            }
        } else if (Config.HIDDEN.equals(cfg.getType())) {
            it.remove();
        }

        if (!Config.HIDDEN.equals(cfg.getType()) && !cfg.getKey().contains(filter)) {
            it.remove();
        }
    }

    sc.setAttribute("configs", list);
    sc.setAttribute("filter", filter);
    sc.getRequestDispatcher("/admin/config_list.jsp").forward(request, response);
    log.debug("list: void");
}

From source file:org.telscenter.sail.webapp.presentation.web.controllers.BridgeController.java

private void handleViewStudentAssets(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ServletContext servletContext2 = this.getServletContext();
    ServletContext vlewrappercontext = servletContext2.getContext("/vlewrapper");
    User user = ControllerUtil.getSignedInUser();
    String studentuploads_base_dir = portalProperties.getProperty("studentuploads_base_dir");

    try {/* w w w.  j a  v  a2 s  . c  o  m*/
        //get the run
        String runId = request.getParameter("runId");
        Run run = runService.retrieveById(new Long(runId));

        //get the project id
        Project project = run.getProject();
        Serializable projectId = project.getId();

        //set the project id into the request so the vlewrapper controller has access to it
        request.setAttribute("projectId", projectId + "");

        //set the workgroup id into the request so the vlewrapper controller has access to it
        if (studentuploads_base_dir != null) {
            request.setAttribute("studentuploads_base_dir", studentuploads_base_dir);
        }

        // workgroups is a ":" separated string of workgroups
        String workgroups = request.getParameter("workgroups");

        request.setAttribute("dirName", workgroups);

        //forward the request to the vlewrapper controller
        RequestDispatcher requestDispatcher = vlewrappercontext
                .getRequestDispatcher("/vle/studentassetmanager.html");
        requestDispatcher.forward(request, response);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.openkm.servlet.admin.ConfigServlet.java

/**
 * List config//from   ww  w .  j  a va  2  s.c  o  m
 */
private void list(String userId, String filter, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, DatabaseException {
    log.debug("list({}, {}, {}, {})", new Object[] { userId, filter, request, response });
    ServletContext sc = getServletContext();
    List<Config> list = ConfigDAO.findAll();

    for (Iterator<Config> it = list.iterator(); it.hasNext();) {
        Config cfg = it.next();

        if (Config.STRING.equals(cfg.getType())) {
            cfg.setType("String");
        } else if (Config.TEXT.equals(cfg.getType())) {
            cfg.setType("Text");
        } else if (Config.BOOLEAN.equals(cfg.getType())) {
            cfg.setType("Boolean");
        } else if (Config.INTEGER.equals(cfg.getType())) {
            cfg.setType("Integer");
        } else if (Config.LONG.equals(cfg.getType())) {
            cfg.setType("Long");
        } else if (Config.FILE.equals(cfg.getType())) {
            cfg.setType("File");
        } else if (Config.LIST.equals(cfg.getType())) {
            cfg.setType("List");
        } else if (Config.SELECT.equals(cfg.getType())) {
            cfg.setType("Select");
            ConfigStoredSelect stSelect = new Gson().fromJson(cfg.getValue(), ConfigStoredSelect.class);

            for (ConfigStoredOption stOption : stSelect.getOptions()) {
                if (stOption.isSelected()) {
                    cfg.setValue(stOption.getValue());
                }
            }
        } else if (Config.HIDDEN.equals(cfg.getType())) {
            it.remove();
        }

        if (!Config.HIDDEN.equals(cfg.getType()) && !cfg.getKey().contains(filter)) {
            it.remove();
        }
    }

    sc.setAttribute("configs", list);
    sc.setAttribute("filter", filter);
    sc.getRequestDispatcher("/admin/config_list.jsp").forward(request, response);
    log.debug("list: void");
}

From source file:org.telscenter.sail.webapp.presentation.web.controllers.BridgeController.java

private void handleStudentAssetManager(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ServletContext servletContext2 = this.getServletContext();
    ServletContext vlewrappercontext = servletContext2.getContext("/vlewrapper");
    User user = ControllerUtil.getSignedInUser();
    String studentuploads_base_dir = portalProperties.getProperty("studentuploads_base_dir");

    try {/*from  www  . j  a va  2  s . c  o m*/
        //get the run
        String runId = request.getParameter("runId");
        Run run = runService.retrieveById(new Long(runId));

        //get the project id
        Project project = run.getProject();
        Serializable projectId = project.getId();

        //set the project id into the request so the vlewrapper controller has access to it
        request.setAttribute("projectId", projectId + "");

        //get the workgroup id
        List<Workgroup> workgroupListByOfferingAndUser = workgroupService.getWorkgroupListByOfferingAndUser(run,
                user);
        Workgroup workgroup = workgroupListByOfferingAndUser.get(0);
        Long workgroupId = workgroup.getId();

        //set the workgroup id into the request so the vlewrapper controller has access to it
        request.setAttribute("dirName", workgroupId + "");
        if (studentuploads_base_dir != null) {
            request.setAttribute("studentuploads_base_dir", studentuploads_base_dir);
        }
        //forward the request to the vlewrapper controller
        RequestDispatcher requestDispatcher = vlewrappercontext
                .getRequestDispatcher("/vle/studentassetmanager.html");
        requestDispatcher.forward(request, response);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
    }

}

From source file:org.telscenter.sail.webapp.presentation.web.controllers.BridgeController.java

private void handleIdeaBasket(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ServletContext servletContext2 = this.getServletContext();
    ServletContext vlewrappercontext = servletContext2.getContext("/vlewrapper");
    User user = ControllerUtil.getSignedInUser();
    String action = request.getParameter("action");

    try {//from  w ww .  jav  a  2  s . c  o  m
        //check if the request is for all idea baskets and the user is not a teacher
        if (action.equals("getAllIdeaBaskets") && !(user.getUserDetails() instanceof TeacherUserDetails)) {
            /*
             * the request is for all idea baskets and the user is not a teacher
             * so we will not allow this
             */
            response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
                    "You are not authorized to access this page");
        } else {
            //get the run
            String runId = request.getParameter("runId");
            Run run = runService.retrieveById(new Long(runId));

            //get the project id
            Project project = run.getProject();
            Serializable projectId = project.getId();

            //set the project id into the request so the vlewrapper controller has access to it
            request.setAttribute("projectId", projectId + "");

            // if admin is requesting all baskets, there is no need to get the workgroupId.
            if (!user.isAdmin()) {

                //get the workgroup id
                List<Workgroup> workgroupListByOfferingAndUser = workgroupService
                        .getWorkgroupListByOfferingAndUser(run, user);
                Workgroup workgroup = workgroupListByOfferingAndUser.get(0);
                Long workgroupId = workgroup.getId();

                //set the workgroup id into the request so the vlewrapper controller has access to it
                request.setAttribute("workgroupId", workgroupId + "");
            }

            //forward the request to the vlewrapper controller
            RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/ideaBasket.html");
            requestDispatcher.forward(request, response);
        }
    } catch (NumberFormatException e) {
        e.printStackTrace();
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.openkm.servlet.admin.JcrRepositoryViewServlet.java

/**
 * List node properties and children/*w w  w . jav a  2s.  c  o m*/
 */
private void list(Session session, String path, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, javax.jcr.PathNotFoundException, RepositoryException {
    log.debug("list({}, {}, {}, {})", new Object[] { session, path, request, response });
    String stats = WebUtils.getString(request, "stats");
    String uuid = WebUtils.getString(request, "uuid");
    ServletContext sc = getServletContext();
    ContentInfo ci = null;
    Node node = null;

    // Respository stats calculation
    if (!stats.equals("")) {
        if (stats.equals("0")) {
            request.getSession().removeAttribute("stats");
        } else {
            request.getSession().setAttribute("stats", true);
        }
    }

    // Handle path or uuid
    if (!path.equals("")) {
        if (path.equals("/")) {
            node = session.getRootNode();
        } else {
            node = session.getRootNode().getNode(path.substring(1));
        }
    } else if (!uuid.equals("")) {
        node = session.getNodeByUUID(uuid);
        path = node.getPath();
    } else {
        node = session.getRootNode();
    }

    if (request.getSession().getAttribute("stats") != null && node.isNodeType(Folder.TYPE)) {
        try {
            ci = OKMFolder.getInstance().getContentInfo(null, node.getPath());
        } catch (AccessDeniedException e) {
            log.warn(e.getMessage(), e);
        } catch (com.openkm.core.RepositoryException e) {
            log.warn(e.getMessage(), e);
        } catch (PathNotFoundException e) {
            log.warn(e.getMessage(), e);
        } catch (DatabaseException e) {
            log.warn(e.getMessage(), e);
        }
    }

    // Activity log
    if (node.isNodeType(JcrConstants.MIX_REFERENCEABLE)) {
        UserActivity.log(session.getUserID(), "ADMIN_REPOSITORY_LIST", node.getUUID(), node.getPath(), null);
    } else {
        UserActivity.log(session.getUserID(), "ADMIN_REPOSITORY_LIST", ((NodeImpl) node).getId().toString(),
                node.getPath(), null);
    }

    sc.setAttribute("contentInfo", ci);
    sc.setAttribute("node", node);
    sc.setAttribute("isFolder", node.isNodeType(Folder.TYPE));
    sc.setAttribute("isDocument", node.isNodeType(Document.TYPE));
    sc.setAttribute("isDocumentContent", node.isNodeType(Document.CONTENT_TYPE));
    sc.setAttribute("isScripting", node.isNodeType(Scripting.TYPE));
    sc.setAttribute("holdsLock", node.holdsLock());
    sc.setAttribute("breadcrumb", createBreadcrumb(node.getPath()));
    sc.setAttribute("properties", getProperties(node));
    sc.setAttribute("children", getChildren(node));
    sc.getRequestDispatcher("/admin/jcr_repository_list.jsp").forward(request, response);
    log.debug("list: void");
}

From source file:com.ikon.servlet.admin.RepositoryViewServlet.java

/**
 * List node properties and children/*from w  ww  .  j  av  a  2 s.  c o  m*/
 */
private void list(Session session, String path, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, javax.jcr.PathNotFoundException, RepositoryException {
    log.debug("list({}, {}, {}, {})", new Object[] { session, path, request, response });
    String stats = WebUtils.getString(request, "stats");
    String uuid = WebUtils.getString(request, "uuid");
    ServletContext sc = getServletContext();
    ContentInfo ci = null;
    Node node = null;

    // Respository stats calculation
    if (!stats.equals("")) {
        if (stats.equals("0")) {
            request.getSession().removeAttribute("stats");
        } else {
            request.getSession().setAttribute("stats", true);
        }
    }

    // Handle path or uuid
    if (!path.equals("")) {
        if (path.equals("/")) {
            node = session.getRootNode();
        } else {
            node = session.getRootNode().getNode(path.substring(1));
        }
    } else if (!uuid.equals("")) {
        node = session.getNodeByUUID(uuid);
        path = node.getPath();
    } else {
        node = session.getRootNode();
    }

    if (request.getSession().getAttribute("stats") != null && node.isNodeType(Folder.TYPE)) {
        try {
            ci = OKMFolder.getInstance().getContentInfo(null, node.getPath());
        } catch (AccessDeniedException e) {
            log.warn(e.getMessage(), e);
        } catch (com.ikon.core.RepositoryException e) {
            log.warn(e.getMessage(), e);
        } catch (PathNotFoundException e) {
            log.warn(e.getMessage(), e);
        } catch (DatabaseException e) {
            log.warn(e.getMessage(), e);
        }
    }

    // Activity log
    if (node.isNodeType(JcrConstants.MIX_REFERENCEABLE)) {
        UserActivity.log(session.getUserID(), "ADMIN_REPOSITORY_LIST", node.getUUID(), node.getPath(), null);
    } else {
        UserActivity.log(session.getUserID(), "ADMIN_REPOSITORY_LIST", ((NodeImpl) node).getId().toString(),
                node.getPath(), null);
    }

    sc.setAttribute("contentInfo", ci);
    sc.setAttribute("node", node);
    sc.setAttribute("isFolder", node.isNodeType(Folder.TYPE));
    sc.setAttribute("isDocument", node.isNodeType(Document.TYPE));
    sc.setAttribute("isDocumentContent", node.isNodeType(Document.CONTENT_TYPE));
    sc.setAttribute("isScripting", node.isNodeType(Scripting.TYPE));
    sc.setAttribute("holdsLock", node.holdsLock());
    sc.setAttribute("breadcrumb", createBreadcrumb(node.getPath()));
    sc.setAttribute("properties", getProperties(node));
    sc.setAttribute("children", getChildren(node));
    sc.getRequestDispatcher("/admin/repository_list.jsp").forward(request, response);
    log.debug("list: void");
}