Beispiel #1
0
  @Override
  protected boolean accepts(ProcessingContext context, PathElementsProvider provider) {
    String current = provider.current();
    Degree degree = Degree.readBySigla(current);

    if (degree == null) {
      return false;
    } else {
      DegreeContext ownContext = (DegreeContext) context;
      ownContext.setDegree(degree);

      /*
       * This is an ugly hack so this process still works until the
       * semester ends where we can easily notify everyone that the link
       * format has changed.
       *
       * 04-02-2007 pcma
       */
      DegreeSite portalInstance = degree.getSite();
      MetaDomainObjectPortal portal =
          (MetaDomainObjectPortal)
              MetaDomainObject.getMeta(portalInstance.getClass()).getAssociatedPortal();

      List<Content> contents = new ArrayList<Content>();
      contents.add(portal);
      contents.add(portalInstance);

      HttpServletRequest request = context.getRequest();
      FilterFunctionalityContext filterContext = new FilterFunctionalityContext(request, contents);
      filterContext.setHasBeenForwarded();
      request.setAttribute(FunctionalityContext.CONTEXT_KEY, filterContext);
      return true;
    }
  }
  protected Unit getUnit(HttpServletRequest request) {
    Unit unit = (Unit) request.getAttribute("unit");

    if (unit == null) {
      FilterFunctionalityContext context =
          (FilterFunctionalityContext) AbstractFunctionalityContext.getCurrentContext(request);
      UnitSite site = (UnitSite) context.getSelectedContainer();
      unit = site.getUnit();
    }

    return unit;
  }
Beispiel #3
0
 private void dispatchTo(
     final HttpServletRequest httpServletRequest,
     final HttpServletResponse httpServletResponse,
     final FilterFunctionalityContext functionalityContext,
     String path)
     throws ServletException, IOException {
   httpServletRequest.setAttribute(
       ContentInjectionRewriter.CONTEXT_ATTRIBUTE_NAME,
       functionalityContext.getCurrentContextPath());
   final RequestDispatcher requestDispatcher = httpServletRequest.getRequestDispatcher(path);
   functionalityContext.setHasBeenForwarded();
   requestDispatcher.forward(httpServletRequest, httpServletResponse);
 }
Beispiel #4
0
  @Override
  protected boolean forward(ProcessingContext context, PathElementsProvider provider)
      throws IOException, ServletException {
    if (provider.hasNext()) {
      return false;
    } else {
      SemesterContext ownContext = (SemesterContext) context;
      ExecutionCourse executionCourse = ownContext.getExecutionCourse();

      if (executionCourse == null) {
        return false;
      } else {

        /*
         * This is an ugly hack so this process still works until the
         * semester ends where we can easily notify everyone that the
         * link format has changed.
         *
         * 04-02-2007 pcma
         */
        HttpServletRequest request = context.getRequest();
        ExecutionCourseSite portalInstance = executionCourse.getSite();
        MetaDomainObjectPortal portal = MetaDomainObjectPortal.getPortal(portalInstance.getClass());

        List<Content> contents = new ArrayList<Content>();
        contents.add(portal);
        contents.add(portalInstance);

        FilterFunctionalityContext filterContext =
            (FilterFunctionalityContext) request.getAttribute(FunctionalityContext.CONTEXT_KEY);
        if (filterContext != null) {
          request.removeAttribute(FunctionalityContext.CONTEXT_KEY);
        }
        filterContext = new FilterFunctionalityContext(request, contents);
        filterContext.setHasBeenForwarded();
        request.setAttribute(FunctionalityContext.CONTEXT_KEY, filterContext);

        String url = portalInstance.getReversePath();
        context.getResponse().sendRedirect(context.getRequest().getContextPath() + url);
        return true;
      }
    }
  }
Beispiel #5
0
  @Override
  public void doFilter(
      ServletRequest initialRequest, ServletResponse initialResponse, FilterChain chain)
      throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) initialRequest;
    HttpServletResponse response = (HttpServletResponse) initialResponse;

    final FilterFunctionalityContext functionalityContext =
        (FilterFunctionalityContext) getContextAttibute((HttpServletRequest) initialRequest);

    if (functionalityContext == null
        || functionalityContext.getSelectedContents().isEmpty()
        || functionalityContext.hasBeenForwarded()) {
      chain.doFilter(request, response);
    } else {
      contentsForward(
          (HttpServletRequest) initialRequest,
          (HttpServletResponse) initialResponse,
          functionalityContext);
    }
  }
Beispiel #6
0
  private void contentsForward(
      final HttpServletRequest httpServletRequest,
      final HttpServletResponse httpServletResponse,
      final FilterFunctionalityContext functionalityContext)
      throws ServletException, IOException {

    Content content = functionalityContext.getSelectedContent();

    if (LogLevel.INFO) {
      if (content == null) {
        System.out.println(httpServletRequest.getRequestURI() + " ---> null");
      } else {
        System.out.println(
            httpServletRequest.getRequestURI() + " ---> " + content.getClass().getName());
      }
    }

    if (content instanceof Redirect) {
      final Redirect redirect = (Redirect) content;
      sendRedirect(httpServletResponse, redirect.getUrl());
    } else if (content instanceof Section) {
      dispatchTo(httpServletRequest, httpServletResponse, functionalityContext, SECTION_PATH);

    } else if (content instanceof Item) {
      dispatchTo(httpServletRequest, httpServletResponse, functionalityContext, ITEM_PATH);

    } else if (content instanceof Attachment) {
      Attachment attachment = (Attachment) content;
      httpServletResponse.sendRedirect(attachment.getFile().getDownloadUrl());
    } else if (content instanceof FunctionalityCall) {
      Functionality functionality = ((FunctionalityCall) content).getFunctionality();
      dispatchTo(
          httpServletRequest, httpServletResponse, functionalityContext, functionality.getPath());

    } else if (content instanceof Functionality) {
      Functionality functionality = ((Functionality) content);
      dispatchTo(
          httpServletRequest, httpServletResponse, functionalityContext, functionality.getPath());
    }
  }
 protected UnitSite getUnitSite(HttpServletRequest request) {
   FilterFunctionalityContext context =
       (FilterFunctionalityContext) AbstractFunctionalityContext.getCurrentContext(request);
   Container container = (Container) context.getLastContentInPath(UnitSite.class);
   return (UnitSite) container;
 }