Example usage for javax.servlet ServletContext getContext

List of usage examples for javax.servlet ServletContext getContext

Introduction

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

Prototype

public ServletContext getContext(String uripath);

Source Link

Document

Returns a ServletContext object that corresponds to a specified URL on the server.

Usage

From source file:org.sakaiproject.portal.render.portlet.PortletToolRenderService.java

private boolean isPortletApplication(ServletContext context, ToolConfiguration configuration)
        throws ToolRenderException, MalformedURLException {
    SakaiPortletWindow window = registry.getOrCreatePortletWindow(configuration);
    if (window == null) {
        return false;
    }/*from  w ww. j  a va2s . c o m*/
    if (LOG.isDebugEnabled()) {
        LOG.debug("Checking context for potential portlet ");
    }
    ServletContext crossContext = context.getContext(window.getContextPath());
    if (LOG.isDebugEnabled()) {
        LOG.debug("Got servlet context as  " + crossContext);
        LOG.debug("Getting Context for path " + window.getContextPath());
        LOG.debug("Base Path " + crossContext.getRealPath("/"));
        LOG.debug("Context Name " + crossContext.getServletContextName());
        LOG.debug("Server Info " + crossContext.getServerInfo());
        LOG.debug("      and it is a portlet ? :" + (crossContext.getResource("/WEB-INF/portlet.xml") != null));
    }
    return crossContext.getResource("/WEB-INF/portlet.xml") != null;
}

From source file:org.sipfoundry.sipxconfig.cmcprov.ProvisioningServlet.java

@Override
public void init() {
    if (s_context == null) {
        ServletContext ctx = getServletContext();
        ServletContext sipxconfigCtx = ctx.getContext(SIPXCONFIG_SERVLET_PATH);
        WebApplicationContext webContext = WebApplicationContextUtils
                .getRequiredWebApplicationContext(sipxconfigCtx);
        CoreContext sipxCoreContext = ((CoreContext) (webContext.getBean(CORE_CONTEXT_BEAN_NAME)));
        PhoneContext sipxPhoneContext = ((PhoneContext) (webContext.getBean(PHONE_CONTEXT_BEAN_NAME)));
        Upload sipxUpload = ((Upload) (webContext.getBean(UPLOAD_BEAN_NAME)));
        s_context = new ProvisioningContextImpl();
        s_context.setSipxCoreContext(sipxCoreContext);
        s_context.setSipxPhoneContext(sipxPhoneContext);
        s_context.setSipxUpload(sipxUpload);
    }/*w  ww.  j a  va2 s  .  c o  m*/
}

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

private ModelAndView handleGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String type = request.getParameter("type");
    ServletContext servletContext2 = this.getServletContext();
    ServletContext vlewrappercontext = servletContext2.getContext("/vlewrapper");

    User user = ControllerUtil.getSignedInUser();
    CredentialManager.setRequestCredentials(request, user);

    //get the run id
    String runIdString = request.getParameter("runId");
    Long runId = null;//from  w  w  w  .j  a  v a 2 s .c  o m

    if (runIdString != null) {
        runId = Long.parseLong(runIdString);
    }

    Run run = null;
    try {
        if (runId != null) {
            //get the run object
            run = runService.retrieveById(runId);
        }
    } catch (ObjectNotFoundException e1) {
        e1.printStackTrace();
    }

    if (type == null) {
        // get student data
        RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/getdata.html");
        requestDispatcher.forward(request, response);
    } else if (type.equals("brainstorm")) {
        RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/getdata.html");
        requestDispatcher.forward(request, response);
    } else if (type.equals("flag") || type.equals("annotation")) { // get flags
        /*
         * set the user info JSONObjects into the request so the vlewrapper servlet
         * has access to the teacher and classmate info
         */
        setUserInfos(run, request);

        RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/annotations.html");
        requestDispatcher.forward(request, response);
    } else if (type.equals("journal")) {
        RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/journaldata.html");
        requestDispatcher.forward(request, response);
    } else if (type.equals("peerreview")) {
        //get the period id
        String periodString = request.getParameter("periodId");
        Long period = null;
        if (periodString != null) {
            period = Long.parseLong(periodString);
        }

        try {
            /*
             * set the number of students in the class period for when we need
             * to calculate peer review opening
             */
            Set<Workgroup> classmateWorkgroups = runService.getWorkgroups(runId, period);
            request.setAttribute("numWorkgroups", classmateWorkgroups.size());
        } catch (ObjectNotFoundException e) {
            e.printStackTrace();
        }
        RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/peerreview.html");
        requestDispatcher.forward(request, response);
    } else if (type.equals("xlsexport")) {
        //set the user info into the request object
        setUserInfos(run, request);

        //set the project path into the request object
        setProjectPath(run, request);

        RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/getxls.html");
        requestDispatcher.forward(request, response);
    } else if (type.equals("ideaBasket")) {
        handleIdeaBasket(request, response);
    } else if (type.equals("studentAssetManager")) {
        handleStudentAssetManager(request, response);
    } else if (type.equals("viewStudentAssets")) {
        handleViewStudentAssets(request, response);
    } else if (type.equals("xmppAuthenticate")) {
        // check if this portal is xmpp enabled first
        String isXMPPEnabled = portalProperties.getProperty("isXMPPEnabled");
        if (isXMPPEnabled != null && Boolean.valueOf(isXMPPEnabled)) {
            handleWISEXMPPAuthenticate(request, response);
        }
    }
    return null;
}

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

private ModelAndView handlePost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String type = request.getParameter("type");
    ServletContext servletContext2 = this.getServletContext();
    ServletContext vlewrappercontext = servletContext2.getContext("/vlewrapper");
    User user = ControllerUtil.getSignedInUser();
    CredentialManager.setRequestCredentials(request, user);

    if (type == null) {
        // post student data
        RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/postdata.html");
        requestDispatcher.forward(request, response);
    } else if (type.equals("flag") || type.equals("annotation")) {
        RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/annotations.html");
        requestDispatcher.forward(request, response);
    } else if (type.equals("journal")) {
        RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/journaldata.html");
        requestDispatcher.forward(request, response);
    } else if (type.equals("peerreview")) {
        RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/peerreview.html");
        requestDispatcher.forward(request, response);
    } else if (type.equals("ideaBasket")) {
        handleIdeaBasket(request, response);
    } else if (type.equals("studentAssetManager")) {
        handleStudentAssetManager(request, response);
    } else if (type.equals("viewStudentAssets")) {
        handleViewStudentAssets(request, response);
    }/* w  w w. j  ava2  s  . co  m*/
    return null;
}

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 {// www  .  j  a  v a2s.  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: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 {//from  w  w  w  . ja v  a 2s  .co  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: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  w  w w  .  j a v a 2  s.c  om
        //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();
    }

}