List of usage examples for javax.servlet.jsp PageContext getRequest
abstract public ServletRequest getRequest();
From source file:net.sourceforge.fenixedu.presentationTier.TagLib.sop.examsMapNew.renderers.ExamsMapContentRenderer.java
@Override public StringBuilder renderDayContents(ExamsMapSlot examsMapSlot, Integer year1, Integer year2, String typeUser, PageContext pageContext) { StringBuilder strBuffer = new StringBuilder(); for (int i = 0; i < examsMapSlot.getExams().size(); i++) { InfoExam infoExam = (InfoExam) examsMapSlot.getExams().get(i); Integer curicularYear = infoExam.getInfoExecutionCourse().getCurricularYear(); if (curicularYear.equals(year1) || curicularYear.equals(year2)) { boolean isOnValidWeekDay = onValidWeekDay(infoExam); InfoExecutionCourse infoExecutionCourse = infoExam.getInfoExecutionCourse(); String courseInitials = infoExam.getInfoExecutionCourse().getSigla(); if (typeUser.equals("sop")) { strBuffer.append("<a href='showExamsManagement.do?method=edit&" + PresentationConstants.EXECUTION_COURSE_OID + "=" + infoExecutionCourse.getExternalId() + "&" + PresentationConstants.EXECUTION_PERIOD_OID + "=" + infoExecutionCourse.getInfoExecutionPeriod().getExternalId() + "&" + PresentationConstants.EXECUTION_DEGREE_OID + "=" + examsMap.getInfoExecutionDegree().getExternalId() + "&" + PresentationConstants.CURRICULAR_YEAR_OID + "=" + curicularYear.toString() + "&" + PresentationConstants.EXAM_OID + "=" + infoExam.getExternalId() + "'>"); if (isOnValidWeekDay) { strBuffer.append(courseInitials); } else { strBuffer.append("<span class='redtxt'>" + courseInitials + "</span>"); }/* www. jav a 2 s.c o m*/ } else if (typeUser.equals("public")) { final Site site = infoExecutionCourse.getExecutionCourse().getSite(); strBuffer.append(GenericChecksumRewriter.NO_CHECKSUM_PREFIX); strBuffer.append("<a href=\"") .append(((HttpServletRequest) pageContext.getRequest()).getContextPath()); strBuffer.append(site.getReversePath()); strBuffer.append("\">"); strBuffer.append(courseInitials); } strBuffer.append("</a>"); if (infoExam.getBeginning() != null) { boolean isAtValidHour = atValidHour(infoExam); String hoursText = infoExam.getBeginning().get(Calendar.HOUR_OF_DAY) + "h" + DateFormatUtils.format(infoExam.getBeginning().getTime(), "mm"); strBuffer.append(" "); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.as")); strBuffer.append(" "); if (isAtValidHour || !typeUser.equals("sop")) { strBuffer.append(hoursText); } else { strBuffer.append("<span class='redtxt'>" + hoursText + "</span>"); } } strBuffer.append("<br />"); } } strBuffer.append("<br />"); return strBuffer; }
From source file:net.sourceforge.fenixedu.presentationTier.TagLib.sop.examsMapNew.renderers.ExamsMapContentRenderer.java
@Override public StringBuilder renderDayLabel(ExamsMapSlot examsMapSlot, ExamsMap examsMap, String typeUser, PageContext pageContext) { this.examsMap = examsMap; StringBuilder strBuffer = new StringBuilder(); boolean isFirstDayOfSeason = ((examsMapSlot.getDay().get(Calendar.DAY_OF_MONTH) == examsMap .getFirstDayOfSeason().get(Calendar.DAY_OF_MONTH)) && (examsMapSlot.getDay().get(Calendar.MONTH) == examsMap.getFirstDayOfSeason().get(Calendar.MONTH)) && (examsMapSlot.getDay().get(Calendar.YEAR) == examsMap.getFirstDayOfSeason().get(Calendar.YEAR))); boolean isSecondDayOfMonthAndFirstDayWasASunday = (examsMapSlot.getDay().get(Calendar.DAY_OF_MONTH) == 2 && examsMapSlot.getDay().get(Calendar.DAY_OF_WEEK) == 2); if (examsMap.getInfoExecutionDegree() != null && typeUser.equals("sop")) { strBuffer.append("<a href='showExamsManagement.do?method=createByDay" + "&" + PresentationConstants.EXECUTION_DEGREE_OID + "=" + examsMap.getInfoExecutionDegree().getExternalId() + "&" + PresentationConstants.EXECUTION_PERIOD_OID + "=" + examsMap.getInfoExecutionPeriod().getExternalId() + "&" + PresentationConstants.CURRICULAR_YEAR_OID + "=" + examsMap.getCurricularYears().iterator().next() + "&" + PresentationConstants.DAY + "=" + examsMapSlot.getDay().get(Calendar.DAY_OF_MONTH) + "&" + PresentationConstants.MONTH + "=" + (examsMapSlot.getDay().get(Calendar.MONTH) + 1) + "&" + PresentationConstants.YEAR + "=" + examsMapSlot.getDay().get(Calendar.YEAR) + "'>"); }/* w w w . j a v a 2 s. c o m*/ strBuffer.append(examsMapSlot.getDay().get(Calendar.DAY_OF_MONTH)); if ((examsMapSlot.getDay().get(Calendar.DAY_OF_MONTH) == 1) || isFirstDayOfSeason || isSecondDayOfMonthAndFirstDayWasASunday) { strBuffer.append(" "); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.of")); strBuffer.append(" "); Locale locale = pageContext.getRequest().getLocale(); strBuffer.append(monthToString(examsMapSlot.getDay().get(Calendar.MONTH), locale)); } if (examsMapSlot.getDay().get(Calendar.DAY_OF_YEAR) == 1) { strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.comma")); strBuffer.append(examsMapSlot.getDay().get(Calendar.YEAR)); } if (examsMap.getInfoExecutionDegree() != null && typeUser.equals("sop")) { strBuffer.append("</a>"); } strBuffer.append("<br />"); return strBuffer; }
From source file:net.sourceforge.fenixedu.presentationTier.TagLib.sop.examsMapNew.ExamsMapRenderer.java
private void renderExecutionCourseListForYear(StringBuilder strBuffer, Integer curricularYear, PageContext pageContext) { if (!examsMap.hasExecutionCoursesForGivenCurricularYear(curricularYear)) { strBuffer.append("<i>") .append(getMessageResource(pageContext, "no.execution.courses.for.curricular.year")) .append(curricularYear).append("</i>"); } else {/* w ww .j a v a2 s. c om*/ if (user.equals("public")) { strBuffer.append("<table class='tab_exams_details' cellspacing='0'>"); strBuffer.append("<tr><th rowspan='2' width='250' class='ordYear'>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.year")); strBuffer.append(" "); strBuffer.append(curricularYear); strBuffer.append("</th>"); strBuffer.append("<th colspan='3' width='250'>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.times")); strBuffer.append(" 1"); strBuffer.append("</th>"); strBuffer.append("<th colspan='3'>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.times")); strBuffer.append(" 2"); strBuffer.append("</th></tr>"); strBuffer.append("<tr><td class='subheader' width='70'>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.day")); strBuffer.append("</td><td class='subheader' width='50'>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.hour")); strBuffer.append("</td><td class='subheader' width='130'>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.room")); strBuffer.append("</td>"); strBuffer.append("<td class='subheader' width='70'>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.day")); strBuffer.append("</td>" + "<td class='subheader' width='50'>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.hour")); strBuffer.append("</td><td class='subheader' width='130'>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.room")); strBuffer.append("</td></tr>"); } else { strBuffer.append("<strong>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.courseOf")); strBuffer.append(curricularYear + "º ano:</strong>"); } Collections.sort(examsMap.getExecutionCourses(), new BeanComparator("sigla")); String rowClass = "notFirstRow"; // used for CSS style for (int i = 0; i < examsMap.getExecutionCourses().size(); i++) { InfoExecutionCourse infoExecutionCourse = (InfoExecutionCourse) examsMap.getExecutionCourses() .get(i); if (user.equals("sop")) { strBuffer.append("<table border='1' cellspacing='0' cellpadding='3' width='95%'>"); strBuffer.append("<tr>"); } if (i == 0) { rowClass = "firstRow"; } if (infoExecutionCourse.getCurricularYear().equals(curricularYear)) { boolean showCreateExamLink = infoExecutionCourse.getAssociatedInfoExams().size() < 2; if (user.equals("sop")) { strBuffer.append("<td colspan='6'>"); } if (user.equals("public")) { strBuffer.append("<tr valign='top'>"); strBuffer.append("<td class='" + rowClass + "'>"); final Site site = infoExecutionCourse.getExecutionCourse().getSite(); strBuffer.append(GenericChecksumRewriter.NO_CHECKSUM_PREFIX); strBuffer.append("<a href=\"") .append(((HttpServletRequest) pageContext.getRequest()).getContextPath()); strBuffer.append(site.getReversePath()); strBuffer.append("\">"); } else if (showCreateExamLink && user.equals("sop")) { strBuffer.append("<a href='" + addPublicPrefix("showExamsManagement.do") + "?method=createByCourse&" + PresentationConstants.EXECUTION_COURSE_OID + "=" + infoExecutionCourse.getExternalId() + "&" + PresentationConstants.EXECUTION_PERIOD_OID + "=" + infoExecutionCourse.getInfoExecutionPeriod().getExternalId() + "&" + PresentationConstants.EXECUTION_DEGREE_OID + "=" + examsMap.getInfoExecutionDegree().getExternalId() + "&" + PresentationConstants.CURRICULAR_YEAR_OID + "=" + curricularYear.toString() + "'>"); } strBuffer.append(infoExecutionCourse.getSigla()); strBuffer.append(" - "); strBuffer.append(infoExecutionCourse.getNome()); if (user.equals("public")) { strBuffer.append("</a>"); strBuffer.append("</td>"); } boolean hasComment = infoExecutionCourse.getComment() != null && infoExecutionCourse.getComment().length() > 0 && !infoExecutionCourse.getComment().equals(" "); if (hasComment) { if (user.equals("sop")) { strBuffer.append(" : "); strBuffer.append( "<a href='" + addPublicPrefix("defineComment.do") + "?executionCourseCode="); strBuffer.append(infoExecutionCourse.getSigla()); strBuffer.append("&executionPeriodName=" + infoExecutionCourse.getInfoExecutionPeriod().getName()); strBuffer.append("&executionYear=" + infoExecutionCourse.getInfoExecutionPeriod() .getInfoExecutionYear().getYear()); strBuffer.append("&comment=" + infoExecutionCourse.getComment()); strBuffer.append("&method=prepare"); strBuffer.append("&indexExecutionCourse=" + i); strBuffer.append("&" + PresentationConstants.EXECUTION_PERIOD_OID + "=" + infoExecutionCourse.getInfoExecutionPeriod().getExternalId() + "&" + PresentationConstants.EXECUTION_DEGREE_OID + "=" + examsMap.getInfoExecutionDegree().getExternalId() + getCurricularYearsArgs()); strBuffer.append("'>"); } else if (user.equals("public")) { strBuffer.append("<td colspan='6' class='" + rowClass + "'><i>"); } strBuffer.append(infoExecutionCourse.getComment()); if (user.equals("sop")) { strBuffer.append("</a>"); } else if (user.equals("public")) { strBuffer.append("</i></td>"); } } else { if (user.equals("sop")) { strBuffer.append(" : "); strBuffer.append( "<a href='" + addPublicPrefix("defineComment.do") + "?executionCourseCode="); strBuffer.append(infoExecutionCourse.getSigla()); strBuffer.append("&executionPeriodName=" + infoExecutionCourse.getInfoExecutionPeriod().getName()); strBuffer.append("&executionYear=" + infoExecutionCourse.getInfoExecutionPeriod() .getInfoExecutionYear().getYear()); strBuffer.append("&method=prepare"); strBuffer.append("&indexExecutionCourse=" + i); strBuffer.append("&" + PresentationConstants.EXECUTION_PERIOD_OID + "=" + infoExecutionCourse.getInfoExecutionPeriod().getExternalId() + "&" + PresentationConstants.EXECUTION_DEGREE_OID + "=" + examsMap.getInfoExecutionDegree().getExternalId() + getCurricularYearsArgs()); strBuffer.append("'>"); strBuffer.append("Definir comentário"); strBuffer.append("</a>"); } } if (user.equals("sop")) { strBuffer.append("</td>"); strBuffer.append("</tr>"); } if (infoExecutionCourse.getAssociatedInfoExams().isEmpty() && !hasComment) { strBuffer.append("<td colspan='6' align='center' class='" + rowClass + "'>"); strBuffer.append("<i>") .append(getMessageResource(pageContext, "no.exams.for.curricular.year")) .append("</i>"); strBuffer.append("</td>"); } else { // Get 1st season exam InfoExam season1Exam = (InfoExam) CollectionUtils .find(infoExecutionCourse.getAssociatedInfoExams(), new Predicate() { @Override public boolean evaluate(Object obj) { InfoExam infoExam = (InfoExam) obj; return infoExam.getSeason().equals(new Season(Season.SEASON1)); } }); // Get 2nd season exam InfoExam season2Exam = (InfoExam) CollectionUtils .find(infoExecutionCourse.getAssociatedInfoExams(), new Predicate() { @Override public boolean evaluate(Object obj) { InfoExam infoExam = (InfoExam) obj; return infoExam.getSeason().equals(new Season(Season.SEASON2)); } }); if (user.equals("public")) { if (season1Exam == null && !hasComment) { strBuffer.append("<td colspan='3' class='" + rowClass + "'> </td>"); } if (season2Exam == null && !hasComment) { strBuffer.append("<td colspan='3' class='" + rowClass + "'> </td>"); } } if ((season1Exam != null) // && season1Exam.getAssociatedRooms() != null // && season1Exam.getAssociatedRooms().size() > // 0) || (season2Exam != null)) // && season2Exam.getAssociatedRooms() != null // && season2Exam.getAssociatedRooms().size() > 0)) { if (season1Exam != null) { if (user.equals("sop")) { strBuffer.append("<tr>"); strBuffer.append("<td>"); strBuffer.append("<a href='" + addPublicPrefix("showExamsManagement.do") + "?method=edit&" + PresentationConstants.EXECUTION_COURSE_OID + "=" + infoExecutionCourse.getExternalId() + "&" + PresentationConstants.EXECUTION_PERIOD_OID + "=" + infoExecutionCourse.getInfoExecutionPeriod().getExternalId() + "&" + PresentationConstants.EXECUTION_DEGREE_OID + "=" + examsMap.getInfoExecutionDegree().getExternalId() + "&" + PresentationConstants.CURRICULAR_YEAR_OID + "=" + curricularYear.toString() + "&" + PresentationConstants.EXAM_OID + "=" + season1Exam.getExternalId() + "'>"); } if (user.equals("sop")) { strBuffer.append("1ª Época"); strBuffer.append("</a>"); strBuffer.append("</td>"); strBuffer.append("<td>"); strBuffer.append(season1Exam.getDate()); strBuffer.append("<br/>"); strBuffer.append(season1Exam.getBeginningHour()); strBuffer.append("-"); strBuffer.append(season1Exam.getEndHour()); } else if (user.equals("public")) { strBuffer.append("<td class='" + rowClass + "'>"); strBuffer.append(season1Exam.getDate()); strBuffer.append("</td>"); strBuffer.append("<td class='" + rowClass + "'>"); strBuffer.append(season1Exam.getBeginningHour()); strBuffer.append("</td>"); // strBuffer.append("-"); // strBuffer.append(season1Exam.getEndHour()) // ; } if (user.equals("sop")) { strBuffer.append("</td>"); strBuffer.append("<td>"); // Integer numAlunos = // infoExecutionCourse. // getNumberOfAttendingStudents(); Integer numAlunos = season1Exam.getEnrolledStudents(); strBuffer.append(numAlunos); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.enrolledPupils")); strBuffer.append("</td>"); strBuffer.append("<td>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.lack")); // Obter o num de lugares de exame das salas List roomOccupation = season1Exam.getWrittenEvaluationSpaceOccupations(); int numLugaresSalas = 0; for (int iterRO = 0; iterRO < roomOccupation.size(); iterRO++) { InfoRoomOccupation infoRO = (InfoRoomOccupation) roomOccupation.get(iterRO); numLugaresSalas += infoRO.getInfoRoom().getCapacidadeExame().intValue(); } int numLugaresAPreencher = numAlunos.intValue() - numLugaresSalas; // if (numLugaresAPreencher < 0) // numLugaresAPreencher = 0; strBuffer.append(numLugaresAPreencher); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.places")); strBuffer.append("</td>"); strBuffer.append("<td>"); } List infoRoomOccupations = season1Exam.getWrittenEvaluationSpaceOccupations(); if (infoRoomOccupations != null && infoRoomOccupations.size() > 0) { if (user.equals("sop")) { strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.rooms")); strBuffer.append("<br/>"); } else if (user.equals("public")) { strBuffer.append("<td class='" + rowClass + "'>"); } for (int iterIRO = 0; iterIRO < infoRoomOccupations.size(); iterIRO++) { InfoRoomOccupation infoRoomOccupation = (InfoRoomOccupation) infoRoomOccupations .get(iterIRO); strBuffer.append(infoRoomOccupation.getInfoRoom().getNome() + "; "); } } else { if (user.equals("sop")) { strBuffer.append("-"); } else if (user.equals("public")) { strBuffer.append("<td class='" + rowClass + "'>"); strBuffer.append("<i>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.noRoomsAttributed")); strBuffer.append("</i>"); } } if (user.equals("sop")) { strBuffer.append("</td>"); strBuffer.append("<td>"); strBuffer.append("<a href='" + addPublicPrefix("showExamsManagement.do") + "?method=delete&" + PresentationConstants.EXECUTION_COURSE_OID + "=" + infoExecutionCourse.getExternalId() + "&" + PresentationConstants.EXECUTION_PERIOD_OID + "=" + infoExecutionCourse.getInfoExecutionPeriod().getExternalId() + "&" + PresentationConstants.EXECUTION_DEGREE_OID + "=" + examsMap.getInfoExecutionDegree().getExternalId() + "&" + PresentationConstants.CURRICULAR_YEAR_OID + "=" + curricularYear.toString() + "&" + PresentationConstants.EXAM_OID + "=" + season1Exam.getExternalId() + "'>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.delete")); strBuffer.append("</a>"); strBuffer.append("</td>"); } } if (season2Exam != null) { if (user.equals("sop")) { strBuffer.append("<tr>"); strBuffer.append("<td>"); strBuffer.append("<a href='" + addPublicPrefix("showExamsManagement.do") + "?method=edit&" + PresentationConstants.EXECUTION_COURSE_OID + "=" + infoExecutionCourse.getExternalId() + "&" + PresentationConstants.EXECUTION_PERIOD_OID + "=" + infoExecutionCourse.getInfoExecutionPeriod().getExternalId() + "&" + PresentationConstants.EXECUTION_DEGREE_OID + "=" + examsMap.getInfoExecutionDegree().getExternalId() + "&" + PresentationConstants.CURRICULAR_YEAR_OID + "=" + curricularYear.toString() + "&" + PresentationConstants.EXAM_OID + "=" + season2Exam.getExternalId() + "'>"); } if (user.equals("sop")) { strBuffer.append("2ª "); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.times")); strBuffer.append("</a>"); strBuffer.append("</td>"); strBuffer.append("<td>"); strBuffer.append(season2Exam.getDate()); strBuffer.append("<br/>"); strBuffer.append(season2Exam.getBeginningHour()); strBuffer.append("-"); strBuffer.append(season2Exam.getEndHour()); } else if (user.equals("public")) { strBuffer.append("<td class='" + rowClass + "'>"); strBuffer.append(season2Exam.getDate()); strBuffer.append("</td>"); strBuffer.append("<td class='" + rowClass + "'>"); strBuffer.append(season2Exam.getBeginningHour()); strBuffer.append("</td>"); // strBuffer.append("-"); // strBuffer.append(season2Exam.getEndHour()) // ; } if (user.equals("sop")) { strBuffer.append("</td>"); strBuffer.append("<td>"); // Integer numAlunos = // infoExecutionCourse. // getNumberOfAttendingStudents(); Integer numAlunos = season2Exam.getEnrolledStudents(); strBuffer.append(numAlunos); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.enrolledPupils")); strBuffer.append("</td>"); strBuffer.append("<td>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.lack")); // Obter o num de lugares de exame das salas List roomOccupation = season2Exam.getWrittenEvaluationSpaceOccupations(); int numLugaresSalas = 0; for (int iterRO = 0; iterRO < roomOccupation.size(); iterRO++) { InfoRoomOccupation infoRO = (InfoRoomOccupation) roomOccupation.get(iterRO); numLugaresSalas += infoRO.getInfoRoom().getCapacidadeExame().intValue(); } int numLugaresAPreencher = numAlunos.intValue() - numLugaresSalas; // if (numLugaresAPreencher < 0) // numLugaresAPreencher = 0; strBuffer.append(numLugaresAPreencher); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.places")); strBuffer.append("</td>"); strBuffer.append("<td>"); } List infoRoomOccupations = season2Exam.getWrittenEvaluationSpaceOccupations(); if (infoRoomOccupations != null && infoRoomOccupations.size() > 0) { if (user.equals("sop")) { strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.rooms") + ":"); strBuffer.append("<br/>"); } else if (user.equals("public")) { strBuffer.append("<td class='" + rowClass + "'>"); } for (int iterIRO = 0; iterIRO < infoRoomOccupations.size(); iterIRO++) { InfoRoomOccupation infoRoomOccupation = (InfoRoomOccupation) infoRoomOccupations .get(iterIRO); strBuffer.append(infoRoomOccupation.getInfoRoom().getNome() + "; "); } if (user.equals("public")) { strBuffer.append("</td>"); } } else { if (user.equals("sop")) { strBuffer.append("-"); } else if (user.equals("public")) { strBuffer.append("<td class='" + rowClass + "'>"); strBuffer.append("<i>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.noRoomsAttributed")); strBuffer.append("</i>"); strBuffer.append("</td>"); } } if (user.equals("sop")) { strBuffer.append("</td>"); strBuffer.append("<td>"); strBuffer.append("<a href='" + addPublicPrefix("showExamsManagement.do") + "?method=delete&" + PresentationConstants.EXECUTION_COURSE_OID + "=" + infoExecutionCourse.getExternalId() + "&" + PresentationConstants.EXECUTION_PERIOD_OID + "=" + infoExecutionCourse.getInfoExecutionPeriod().getExternalId() + "&" + PresentationConstants.EXECUTION_DEGREE_OID + "=" + examsMap.getInfoExecutionDegree().getExternalId() + "&" + PresentationConstants.CURRICULAR_YEAR_OID + "=" + curricularYear.toString() + "&" + PresentationConstants.EXAM_OID + "=" + season2Exam.getExternalId() + "'>"); strBuffer.append(getMessageResource(pageContext, "public.degree.information.label.delete")); strBuffer.append("</a>"); strBuffer.append("</td>"); } } } } if (user.equals("public")) { strBuffer.append("</tr>"); if (rowClass == "firstRow") { rowClass = "notFirstRow"; } } } if (user.equals("sop")) { strBuffer.append("</tr>"); strBuffer.append("</table>"); strBuffer.append("<br />"); } } if (user.equals("public")) { strBuffer.append("</table>"); } } }
From source file:no.kantega.publishing.api.taglibs.photoalbum.PhotoAlbumHelper.java
public static List<Multimedia> getPhotos(PageContext pageContext, int albumId) { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String photoalbum = (String) request.getAttribute("photoalbum"); if (albumId == -1 && !StringUtils.isBlank(photoalbum)) { try {// w w w . j a v a 2s . c om albumId = Integer.parseInt(photoalbum); } catch (NumberFormatException e) { e.printStackTrace(); return null; } } if (albumId == -1) return null; List<Multimedia> photos = (List<Multimedia>) request.getAttribute("aksess_photos_" + albumId); if (photos == null) { photos = new ArrayList<>(); try { MultimediaService mediaService = new MultimediaService(request); List<Multimedia> tmp = mediaService.getMultimediaList(albumId); for (Multimedia multimedia : tmp) { if (multimedia.getType() == MultimediaType.MEDIA) { photos.add(multimedia); } } request.setAttribute("aksess_photos_" + albumId, photos); } catch (SystemException e) { log.error("", e); } } return photos; }
From source file:no.kantega.publishing.api.taglibs.util.BylineTag.java
private static String textLabel(PageContext pageContext, String key, String bundle, String locale, String body) {/*w w w . j a v a 2 s . co m*/ String textLabel; HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); if (key != null) { textLabel = LocaleLabels.getLabel(key, bundle, locale(request, locale)); } else { textLabel = body; } return textLabel; }
From source file:no.kantega.publishing.api.taglibs.util.BylineTag.java
private static Content content(PageContext pageContext) throws NotAuthorizedException { try {//from www .j a v a 2 s.c o m HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); Content content = (Content) request.getAttribute("aksess_this"); if (content == null) { if (contentIdHelper == null) { contentIdHelper = WebApplicationContextUtils .getRequiredWebApplicationContext(pageContext.getServletContext()) .getBean(ContentIdHelper.class); } ContentIdentifier ci = contentIdHelper.fromRequest(request); content = new ContentManagementService(request).getContent(ci, true); RequestHelper.setRequestAttributes(request, content); } return content; } catch (ContentNotFoundException e) { return null; // Not an error } }
From source file:org.apache.struts.taglib.TagUtils.java
/** * Compute a hyperlink URL based on the <code>forward</code>, * <code>href</code>, <code>action</code> or <code>page</code> parameter * that is not null. The returned URL will have already been passed to * <code>response.encodeURL()</code> for adding a session identifier. * * @param pageContext PageContext for the tag making this call * @param forward Logical forward name for which to look up the * context-relative URI (if specified) * @param href URL to be utilized unmodified (if specified) * @param page Module-relative page for which a URL should be * created (if specified) * @param action Logical action name for which to look up the * context-relative URI (if specified) * @param params Map of parameters to be dynamically included * (if any)/* w ww. j av a 2s . c o m*/ * @param anchor Anchor to be dynamically included (if any) * @param redirect Is this URL for a <code>response.sendRedirect()</code>? * @param encodeSeparator This is only checked if redirect is set to * false (never encoded for a redirect). If true, * query string parameter separators are encoded * as >amp;, else & is used. * @param useLocalEncoding If set to true, urlencoding is done on the * bytes of character encoding from * ServletResponse#getCharacterEncoding. Use UTF-8 * otherwise. * @return URL with session identifier * @throws java.net.MalformedURLException if a URL cannot be created for * the specified parameters */ public String computeURLWithCharEncoding(PageContext pageContext, String forward, String href, String page, String action, String module, Map params, String anchor, boolean redirect, boolean encodeSeparator, boolean useLocalEncoding) throws MalformedURLException { String charEncoding = "UTF-8"; if (useLocalEncoding) { charEncoding = pageContext.getResponse().getCharacterEncoding(); } // TODO All the computeURL() methods need refactoring! // Validate that exactly one specifier was included int n = 0; if (forward != null) { n++; } if (href != null) { n++; } if (page != null) { n++; } if (action != null) { n++; } if (n != 1) { throw new MalformedURLException(messages.getMessage("computeURL.specifier")); } // Look up the module configuration for this request ModuleConfig moduleConfig = getModuleConfig(module, pageContext); // Calculate the appropriate URL StringBuffer url = new StringBuffer(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); if (forward != null) { ForwardConfig forwardConfig = moduleConfig.findForwardConfig(forward); if (forwardConfig == null) { throw new MalformedURLException(messages.getMessage("computeURL.forward", forward)); } // **** removed - see bug 37817 **** // if (forwardConfig.getRedirect()) { // redirect = true; // } if (forwardConfig.getPath().startsWith("/")) { url.append(request.getContextPath()); url.append(RequestUtils.forwardURL(request, forwardConfig, moduleConfig)); } else { url.append(forwardConfig.getPath()); } } else if (href != null) { url.append(href); } else if (action != null) { ActionServlet servlet = (ActionServlet) pageContext.getServletContext() .getAttribute(Globals.ACTION_SERVLET_KEY); String actionIdPath = RequestUtils.actionIdURL(action, moduleConfig, servlet); if (actionIdPath != null) { action = actionIdPath; url.append(request.getContextPath()); url.append(actionIdPath); } else { url.append(instance.getActionMappingURL(action, module, pageContext, false)); } } else /* if (page != null) */ { url.append(request.getContextPath()); url.append(this.pageURL(request, page, moduleConfig)); } // Add anchor if requested (replacing any existing anchor) if (anchor != null) { String temp = url.toString(); int hash = temp.indexOf('#'); if (hash >= 0) { url.setLength(hash); } url.append('#'); url.append(this.encodeURL(anchor, charEncoding)); } // Add dynamic parameters if requested if ((params != null) && (params.size() > 0)) { // Save any existing anchor String temp = url.toString(); int hash = temp.indexOf('#'); if (hash >= 0) { anchor = temp.substring(hash + 1); url.setLength(hash); temp = url.toString(); } else { anchor = null; } // Define the parameter separator String separator = null; if (redirect) { separator = "&"; } else if (encodeSeparator) { separator = "&"; } else { separator = "&"; } // Add the required request parameters boolean question = temp.indexOf('?') >= 0; Iterator keys = params.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); Object value = params.get(key); if (value == null) { if (!question) { url.append('?'); question = true; } else { url.append(separator); } url.append(this.encodeURL(key, charEncoding)); url.append('='); // Interpret null as "no value" } else if (value instanceof String) { if (!question) { url.append('?'); question = true; } else { url.append(separator); } url.append(this.encodeURL(key, charEncoding)); url.append('='); url.append(this.encodeURL((String) value, charEncoding)); } else if (value instanceof String[]) { String[] values = (String[]) value; for (int i = 0; i < values.length; i++) { if (!question) { url.append('?'); question = true; } else { url.append(separator); } url.append(this.encodeURL(key, charEncoding)); url.append('='); url.append(this.encodeURL(values[i], charEncoding)); } } else /* Convert other objects to a string */ { if (!question) { url.append('?'); question = true; } else { url.append(separator); } url.append(this.encodeURL(key, charEncoding)); url.append('='); url.append(this.encodeURL(value.toString(), charEncoding)); } } // Re-add the saved anchor (if any) if (anchor != null) { url.append('#'); url.append(this.encodeURL(anchor, charEncoding)); } } // Perform URL rewriting to include our session ID (if any) // but only if url is not an external URL if ((href == null) && (pageContext.getSession() != null)) { HttpServletResponse response = (HttpServletResponse) pageContext.getResponse(); if (redirect) { return (response.encodeRedirectURL(url.toString())); } return (response.encodeURL(url.toString())); } return (url.toString()); }
From source file:org.apache.struts.taglib.TagUtils.java
/** * Return the form action converted into a server-relative URL. *//*from w w w . j a v a 2s .c o m*/ public String getActionMappingURL(String action, String module, PageContext pageContext, boolean contextRelative) { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String contextPath = request.getContextPath(); StringBuffer value = new StringBuffer(); // Avoid setting two slashes at the beginning of an action: // the length of contextPath should be more than 1 // in case of non-root context, otherwise length==1 (the slash) if (contextPath.length() > 1) { value.append(contextPath); } ModuleConfig moduleConfig = getModuleConfig(module, pageContext); if ((moduleConfig != null) && (!contextRelative)) { value.append(moduleConfig.getPrefix()); } // Use our servlet mapping, if one is specified String servletMapping = (String) pageContext.getAttribute(Globals.SERVLET_KEY, PageContext.APPLICATION_SCOPE); if (servletMapping != null) { String queryString = null; int question = action.indexOf("?"); if (question >= 0) { queryString = action.substring(question); } String actionMapping = getActionMappingName(action); if (servletMapping.startsWith("*.")) { value.append(actionMapping); value.append(servletMapping.substring(1)); } else if (servletMapping.endsWith("/*")) { value.append(servletMapping.substring(0, servletMapping.length() - 2)); value.append(actionMapping); } else if (servletMapping.equals("/")) { value.append(actionMapping); } if (queryString != null) { value.append(queryString); } } // Otherwise, assume extension mapping is in use and extension is // already included in the action property else { if (!action.startsWith("/")) { value.append("/"); } value.append(action); } return value.toString(); }
From source file:org.apache.struts.taglib.TagUtils.java
/** * Return the specified ModuleConfig object for the given prefix if it * exists, otherwise a NullPointerException will be thrown. * * @param module The module prefix//from ww w . ja v a 2 s .c o m * @param pageContext The page context. * @return the ModuleConfig object * @throws NullPointerException Thrown when module cannot be found */ public ModuleConfig getModuleConfig(String module, PageContext pageContext) { ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(module, (HttpServletRequest) pageContext.getRequest(), pageContext.getServletContext()); // ModuleConfig not found if (config == null) { throw new NullPointerException("Module '" + module + "' not found."); } return config; }
From source file:org.apache.struts.taglib.TagUtils.java
/** * Look up and return current user locale, based on the specified * parameters./* w w w . j a va 2s . c om*/ * * @param pageContext The PageContext associated with this request * @param locale Name of the session attribute for our user's Locale. * If this is <code>null</code>, the default locale key * is used for the lookup. * @return current user locale */ public Locale getUserLocale(PageContext pageContext, String locale) { return RequestUtils.getUserLocale((HttpServletRequest) pageContext.getRequest(), locale); }