if (tokens.length > 0 && tokens[0].length() == 0) { String[] tokensTemp = new String[tokens.length - 1]; for (int i = 1; i < tokens.length; i++) { tokensTemp[i - 1] = tokens[i]; } tokens = tokensTemp; }
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,            ServletException {        HttpServletRequest request = (HttpServletRequest) req;        HttpServletResponse response = (HttpServletResponse) res;        String uri = request.getRequestURI();        if (!StringUtils.contains(uri, "/disciplinas")) {            chain.doFilter(request, response);            return;        }        String context = request.getContextPath();        String newURI = uri.replaceFirst(app, "");        String[] tokens = newURI.split("/");        StringBuffer forwardURI = new StringBuffer(context);        if (tokens.length >= 2 && !(tokens[1].equalsIgnoreCase("disciplinas"))) {            forwardURI.append(notFoundURI);        }        else {            String degreeCode = tokens[0];            Integer degreeId;            try {                degreeId = getDegreeId(degreeCode);            } catch (FenixServiceException e) {                throw new ServletException(e);            }            if (degreeId != null) {                if (tokens.length == 2) {                    /* fenix/curso/disciplinas */                    forwardURI.append(forwardSiteList);                    forwardURI.append(degreeId);                }                if (tokens.length == 3) {                    /* fenix/curso/disciplinas/sigla */                    String acronym = tokens[2];                    InfoCurricularCourse infoCurricularCourseRecent;                    try {                        infoCurricularCourseRecent = getCurricularCourseRecent(degreeId, acronym);                    } catch (FenixServiceException e1) {                        throw new ServletException(e1);                    }                    if (infoCurricularCourseRecent != null) {                        InfoExecutionCourse infoExecutionCourseRecent;                        try {                            infoExecutionCourseRecent = getExecutionCourseRecent(infoCurricularCourseRecent);                        } catch (FenixServiceException e2) {                            throw new ServletException(e2);                        }                        if (infoExecutionCourseRecent != null) {                            constructForwardExecutionCourseURI(forwardURI, infoExecutionCourseRecent);                        } else {                            forwardURI.append(notFoundURI);                        }                    } else {                        forwardURI.append(notFoundURI);                    }                }                if (tokens.length > 3) {                    String token_2 = tokens[2];                    InfoCurricularCourse infoCurricularCourse = null;                    int i;                    try {                        if (isDegreeCurricularPlanYear(token_2, degreeId)) {                            String acronym = tokens[3];                            InfoDegreeCurricularPlan degreeCurricularPlan = getDegreeCurricularPlan(                                    token_2, degreeId);                            if (degreeCurricularPlan != null) {                                infoCurricularCourse = getExecutionCourseByDegreeCurricularPlan(                                        degreeCurricularPlan.getIdInternal(), acronym);                            }                            i = 4;                        } else {                            infoCurricularCourse = getCurricularCourseRecent(degreeId, token_2);                            i = 3;                        }                        if (infoCurricularCourse != null ) {                            InfoExecutionCourse infoExecutionCourse;                            if ( i >= tokens.length ){                                infoExecutionCourse = getExecutionCourseRecent(infoCurricularCourse);                                constructForwardExecutionCourseURI(forwardURI, infoExecutionCourse);                            }                            else{	                            String nextToken = tokens[i++];	                            if (isExecutionYear(nextToken.replaceFirst("-", "/"))) {	                                if (i < tokens.length) {	                                    String semestre = tokens[i++];	                                    if (isExecutionPeriod(semestre.replaceFirst("-", " "))) {	                                        infoExecutionCourse = getExecutionCourse(infoCurricularCourse,	                                                nextToken.replaceFirst("-", "/"), semestre.replaceFirst(	                                                        "-", " "));	                                        if (infoExecutionCourse != null) {	                                            constructForwardExecutionCourseURI(forwardURI,	                                                    infoExecutionCourse);	                                        } else {	                                            forwardURI.append(notFoundURI);	                                        }	                                    } else {	                                        infoExecutionCourse = getExecutionCourseByExecutionYear(	                                                infoCurricularCourse, nextToken.replaceFirst("-", "/"));	                                        if (infoExecutionCourse != null) {	                                            constructForwardExecutionCourseURI(forwardURI,	                                                    infoExecutionCourse);	                                        } else {	                                            forwardURI.append(notFoundURI);	                                        }	                                    }	                                } else {	                                    infoExecutionCourse = getExecutionCourseByExecutionYear(	                                            infoCurricularCourse, nextToken.replaceFirst("-", "/"));	                                    if (infoExecutionCourse != null) {	                                        constructForwardExecutionCourseURI(forwardURI,	                                                infoExecutionCourse);	                                    } else {	                                        forwardURI.append(notFoundURI);	                                    }	                                }	                            } else if (isExecutionPeriod(nextToken.replaceFirst("-", " "))) {	                                infoExecutionCourse = getExecutionCourseByExecutionPeriod(	                                        infoCurricularCourse, nextToken.replaceFirst("-", " "));	                                if (infoExecutionCourse != null) {	                                    constructForwardExecutionCourseURI(forwardURI, infoExecutionCourse);	                                } else {	                                    forwardURI.append(notFoundURI);	                                }	                            } else {	                                forwardURI.append(notFoundURI);	                            }		                        }                        }                    } catch (FenixServiceException e3) {                        throw new ServletException(e3);                    }                }            } else {                forwardURI.append(notFoundURI);            }        }        response.sendRedirect(forwardURI.toString());    }