List of usage examples for java.lang Float floatValue
@HotSpotIntrinsicCandidate public float floatValue()
From source file:org.etudes.mneme.impl.SubmissionServiceImpl.java
/** * Check if the candidate has a better score than the best so far. * //from w ww . ja v a2 s . c o m * @param bestSubmission * The best so far. * @param candidateSub * The candidate. * @return true if the candidate is better, false if not. */ protected boolean candidateBetter(SubmissionImpl bestSubmission, SubmissionImpl candidateSub) { Float best = bestSubmission.getTotalScore(); Float candidate = candidateSub.getTotalScore(); if ((best == null) && (candidate == null)) return false; if (candidate == null) return false; if (best == null) return true; if (best.floatValue() < candidate.floatValue()) return true; return false; }
From source file:org.etudes.jforum.view.forum.GradeAction.java
/** * evaluate user category/*from w ww . java2s. c o m*/ * @throws Exception */ public void evaluateCategoryUser() throws Exception { boolean isfacilitator = JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()) || SecurityService.isSuperUser(); if (!isfacilitator) { this.context.put("errorMessage", I18n.getMessage("User.NotAuthorizedToGrade")); this.setTemplateName(TemplateKeys.USER_NOT_AUTHORIZED_POP_UP); return; } int categoryId = this.request.getIntParameter("category_id"); int userId = this.request.getIntParameter("user_id"); String release = this.request.getParameter("release"); boolean releaseGrade = false; if ((release != null) && (Integer.parseInt(release) == 1)) { releaseGrade = true; } JForumCategoryService jforumCategoryService = (JForumCategoryService) ComponentManager .get("org.etudes.api.app.jforum.JForumCategoryService"); org.etudes.api.app.jforum.Category category = jforumCategoryService.getCategory(categoryId); if (!category.isGradable()) { return; } this.context.put("category", category); this.context.put("userId", userId); JForumUserService jforumUserService = (JForumUserService) ComponentManager .get("org.etudes.api.app.jforum.JForumUserService"); org.etudes.api.app.jforum.User user = jforumUserService.getByUserId(userId); org.etudes.api.app.jforum.Evaluation evaluation = null; JForumGradeService jforumGradeService = (JForumGradeService) ComponentManager .get("org.etudes.api.app.jforum.JForumGradeService"); evaluation = jforumGradeService.getUserCategoryEvaluation(categoryId, user.getSakaiUserId()); if (evaluation == null) { org.etudes.api.app.jforum.Grade grade = jforumGradeService.getByCategoryId(categoryId); evaluation = jforumGradeService.newEvaluation(grade.getId(), UserDirectoryService.getCurrentUser().getId(), user.getSakaiUserId()); } Float score = null; try { score = Float.parseFloat(this.request.getParameter("score")); // if (score.floatValue() < 0) score = Float.valueOf(0.0f); if (score.floatValue() > 1000) score = Float.valueOf(1000.0f); score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); } catch (NumberFormatException ne) { if (logger.isWarnEnabled()) { logger.warn("evaluateCategoryUser() : " + ne); } } String comments = this.request.getParameter("comments"); evaluation.setReleased(releaseGrade); evaluation.setScore(score); evaluation.setComments(comments); evaluation.setEvaluatedBySakaiUserId(UserDirectoryService.getCurrentUser().getId()); jforumGradeService.addModifyUserEvaluation(evaluation); this.context.put("updatesucess", true); this.showEvalCategoryUser(); }
From source file:org.etudes.jforum.view.forum.GradeAction.java
/** * evaluate user forum// www . j a v a 2s .c om * * @throws Exception */ /*public void evaluateForumUser() throws Exception { boolean isfacilitator = JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()) || SecurityService.isSuperUser(); if (!isfacilitator) { this.context.put("errorMessage", I18n.getMessage("User.NotAuthorizedToGrade")); this.setTemplateName(TemplateKeys.USER_NOT_AUTHORIZED_POP_UP); return; } int forumId = this.request.getIntParameter("forum_id"); int userId = this.request.getIntParameter("user_id"); Forum forum = ForumRepository.getForum(forumId); if (forum == null) return; this.context.put("forum", forum); this.context.put("userId", userId); String release = this.request.getParameter("release"); String sendToGradeBook = this.request.getParameter("send_to_grade_book"); boolean releaseGrade = false, evalSuccess = false; if ((release != null) && (Integer.parseInt(release) == 1)) { releaseGrade = true; } String sakuserId = UserDirectoryService.getCurrentUser().getId(); int evaluatedBy = (DataAccessDriver.getInstance().newUserDAO().selectBySakaiUserId(sakuserId)).getId(); Evaluation evaluation = DataAccessDriver.getInstance().newEvaluationDAO().selectEvaluationByForumIdUserId(forumId, userId); if (evaluation == null) { Grade grade = DataAccessDriver.getInstance().newGradeDAO().selectByForumId(forum.getId()); evaluation = new Evaluation(); evaluation.setGradeId(grade.getId()); evaluation.setUserId(userId); evaluation.setReleased(releaseGrade); String userSakaiUserId = (DataAccessDriver.getInstance().newUserDAO().selectById(userId)).getSakaiUserId(); evaluation.setSakaiUserId(userSakaiUserId); Float score = null; boolean evaluated = false; try { if ((this.request.getParameter("score") != null) && (this.request.getParameter("score").trim().length() > 0)) { score = Float.parseFloat(this.request.getParameter("score")); //if (score.floatValue() < 0) score = Float.valueOf(0.0f); if (score.floatValue() > 1000) score = Float.valueOf(1000.0f); score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); evaluated = true; } else { String comments = this.request.getParameter("comments"); if (comments != null && comments.trim().length() > 0) { evaluated = true; } } if (evaluated) { evaluation.setReleased(releaseGrade); evaluation.setScore(score); evaluation.setComments(this.request.getParameter("comments")); evaluation.setEvaluatedBy(evaluatedBy); int evaluationId = DataAccessDriver.getInstance().newEvaluationDAO().addNew(evaluation); evaluation.setId(evaluationId); evalSuccess = true; } } catch (NumberFormatException ne) { if (logger.isWarnEnabled()) logger.warn("evaluateForum() : " + ne); } } else { Float score = null; boolean evaluated = false; try { Evaluation exisEval = new Evaluation(evaluation); if ((this.request.getParameter("score") != null) && (this.request.getParameter("score").trim().length() > 0)) { score = Float.parseFloat(this.request.getParameter("score")); //if (score.floatValue() < 0) score = Float.valueOf(0.0f); if (score.floatValue() > 1000) score = Float.valueOf(1000.0f); score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); evaluated = true; } else { String comments = this.request.getParameter("comments"); if (comments != null && comments.trim().length() > 0) { evaluated = true; } } if (evaluated) { evaluation.setReleased(releaseGrade); evaluation.setScore(score); evaluation.setComments(this.request.getParameter("comments")); evaluation.setEvaluatedBy(evaluatedBy); if (checkEvaluationChanges(exisEval, evaluation)) { DataAccessDriver.getInstance().newEvaluationDAO().update(evaluation); } evalSuccess = true; } } catch (NumberFormatException ne) { if (logger.isWarnEnabled()) logger.warn("evaluateForum() : " + ne); } } //send grade to gradebook if (evalSuccess) { Grade grade = DataAccessDriver.getInstance().newGradeDAO().selectByForumId(forumId); if (forum.getAccessType() == Forum.ACCESS_DENY) { this.context.put("errorMessage", I18n.getMessage("Grade.CannotSentToGradebook")); } else { sendToGradebook(evaluation, grade); } } this.context.put("updatesucess", true); this.showEvalForumUser(); }*/ public void evaluateForumUser() throws Exception { boolean isfacilitator = JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()) || SecurityService.isSuperUser(); if (!isfacilitator) { this.context.put("errorMessage", I18n.getMessage("User.NotAuthorizedToGrade")); this.setTemplateName(TemplateKeys.USER_NOT_AUTHORIZED_POP_UP); return; } int forumId = this.request.getIntParameter("forum_id"); int userId = this.request.getIntParameter("user_id"); JForumForumService jforumForumService = (JForumForumService) ComponentManager .get("org.etudes.api.app.jforum.JForumForumService"); org.etudes.api.app.jforum.Forum forum = jforumForumService.getForum(forumId); if (forum == null || forum.getGradeType() != org.etudes.api.app.jforum.Grade.GradeType.FORUM.getType()) { return; } this.context.put("forum", forum); this.context.put("userId", userId); String release = this.request.getParameter("release"); boolean releaseGrade = false; if ((release != null) && (Integer.parseInt(release) == 1)) { releaseGrade = true; } JForumUserService jforumUserService = (JForumUserService) ComponentManager .get("org.etudes.api.app.jforum.JForumUserService"); org.etudes.api.app.jforum.User user = jforumUserService.getByUserId(userId); org.etudes.api.app.jforum.Evaluation evaluation = null; JForumGradeService jforumGradeService = (JForumGradeService) ComponentManager .get("org.etudes.api.app.jforum.JForumGradeService"); evaluation = jforumGradeService.getUserForumEvaluation(forumId, user.getSakaiUserId()); if (evaluation == null) { org.etudes.api.app.jforum.Grade grade = jforumGradeService.getByForumId(forumId); evaluation = jforumGradeService.newEvaluation(grade.getId(), UserDirectoryService.getCurrentUser().getId(), user.getSakaiUserId()); } Float score = null; try { score = Float.parseFloat(this.request.getParameter("score")); // if (score.floatValue() < 0) score = Float.valueOf(0.0f); if (score.floatValue() > 1000) score = Float.valueOf(1000.0f); score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); } catch (NumberFormatException ne) { if (logger.isWarnEnabled()) { logger.warn("evaluateForumUser() : " + ne); } } String comments = this.request.getParameter("comments"); evaluation.setReleased(releaseGrade); evaluation.setScore(score); evaluation.setComments(comments); evaluation.setEvaluatedBySakaiUserId(UserDirectoryService.getCurrentUser().getId()); jforumGradeService.addModifyUserEvaluation(evaluation); this.context.put("updatesucess", true); this.showEvalForumUser(); }
From source file:org.etudes.jforum.view.forum.GradeAction.java
/** * evaluate user topic/* w ww. j ava 2s . com*/ * @throws Exception */ /*public void evaluateTopicUser() throws Exception { boolean isfacilitator = JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()) || SecurityService.isSuperUser(); if (!isfacilitator) { this.context.put("errorMessage", I18n.getMessage("User.NotAuthorizedToGrade")); this.setTemplateName(TemplateKeys.USER_NOT_AUTHORIZED_POP_UP); return; } int topicId = this.request.getIntParameter("topic_id"); int userId = this.request.getIntParameter("user_id"); String release = this.request.getParameter("release"); boolean releaseGrade = false, evalSuccess = false; if ((release != null) && (Integer.parseInt(release) == 1)) { releaseGrade = true; } TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO(); Topic topic = tm.selectById(topicId); this.context.put("topic", topic); this.context.put("userId", userId); Forum forum = ForumRepository.getForum(topic.getForumId()); this.context.put("forum", forum); Evaluation evaluation = DataAccessDriver.getInstance().newEvaluationDAO().selectEvaluationByForumIdTopicIdUserId(topic.getForumId(), topicId, userId); String sakuserId = UserDirectoryService.getCurrentUser().getId(); int evaluatedBy = (DataAccessDriver.getInstance().newUserDAO().selectBySakaiUserId(sakuserId)).getId(); if (evaluation == null) { Grade grade = DataAccessDriver.getInstance().newGradeDAO().selectByForumTopicId(topic.getForumId(), topicId); evaluation = new Evaluation(); evaluation.setGradeId(grade.getId()); evaluation.setUserId(userId); evaluation.setReleased(releaseGrade); String userSakaiUserId = (DataAccessDriver.getInstance().newUserDAO().selectById(userId)).getSakaiUserId(); evaluation.setSakaiUserId(userSakaiUserId); Float score = null; boolean evaluated = false; try { if ((this.request.getParameter("score") != null) && (this.request.getParameter("score").trim().length() > 0)) { score = Float.parseFloat(this.request.getParameter("score")); //if (score.floatValue() < 0) score = Float.valueOf(0.0f); if (score.floatValue() > 1000) score = Float.valueOf(1000.0f); score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); evaluated = true; } else { String comments = this.request.getParameter("comments"); if (comments != null && comments.trim().length() > 0) { evaluated = true; } } if (evaluated) { evaluation.setScore(score); evaluation.setComments(this.request.getParameter("comments")); evaluation.setEvaluatedBy(evaluatedBy); int evaluationId = DataAccessDriver.getInstance().newEvaluationDAO().addNew(evaluation); evaluation.setId(evaluationId); evalSuccess = true; } } catch (NumberFormatException ne) { if (logger.isWarnEnabled()) logger.warn("evaluateTopic() : " + ne); } } else { Float score = null; boolean evaluated = false; try { Evaluation exisEval = new Evaluation(evaluation); if ((this.request.getParameter("score") != null) && (this.request.getParameter("score").trim().length() > 0)) { score = Float.parseFloat(this.request.getParameter("score")); //if (score.floatValue() < 0) score = Float.valueOf(0.0f); if (score.floatValue() > 1000) score = Float.valueOf(1000.0f); score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); evaluated = true; } else { String comments = this.request.getParameter("comments"); if (comments != null && comments.trim().length() > 0) { evaluated = true; } } if (evaluated) { evaluation.setReleased(releaseGrade); evaluation.setScore(score); evaluation.setComments(this.request.getParameter("comments")); evaluation.setEvaluatedBy(evaluatedBy); if (checkEvaluationChanges(exisEval, evaluation)) { DataAccessDriver.getInstance().newEvaluationDAO().update(evaluation); } evalSuccess = true; } } catch (NumberFormatException ne) { if (logger.isWarnEnabled()) logger.warn("evaluateForum() : " + ne); } } //send grade to gradebook if (evalSuccess) { Grade grade = DataAccessDriver.getInstance().newGradeDAO().selectByForumTopicId(topic.getForumId(), topic.getId()); if (forum.getAccessType() == Forum.ACCESS_DENY) { this.context.put("errorMessage", I18n.getMessage("Grade.CannotSentToGradebook")); } else { sendToGradebook(evaluation, grade); } } this.context.put("updatesucess", true); this.showEvalTopicUser(); }*/ public void evaluateTopicUser() throws Exception { boolean isfacilitator = JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()) || SecurityService.isSuperUser(); if (!isfacilitator) { this.context.put("errorMessage", I18n.getMessage("User.NotAuthorizedToGrade")); this.setTemplateName(TemplateKeys.USER_NOT_AUTHORIZED_POP_UP); return; } int topicId = this.request.getIntParameter("topic_id"); int userId = this.request.getIntParameter("user_id"); String release = this.request.getParameter("release"); boolean releaseGrade = false; if ((release != null) && (Integer.parseInt(release) == 1)) { releaseGrade = true; } JForumPostService jforumPostService = (JForumPostService) ComponentManager .get("org.etudes.api.app.jforum.JForumPostService"); org.etudes.api.app.jforum.Topic topic = jforumPostService.getTopic(topicId); if (!topic.isGradeTopic()) { return; } this.context.put("topic", topic); this.context.put("userId", userId); this.context.put("forum", topic.getForum()); JForumUserService jforumUserService = (JForumUserService) ComponentManager .get("org.etudes.api.app.jforum.JForumUserService"); org.etudes.api.app.jforum.User user = jforumUserService.getByUserId(userId); org.etudes.api.app.jforum.Evaluation evaluation = null; JForumGradeService jforumGradeService = (JForumGradeService) ComponentManager .get("org.etudes.api.app.jforum.JForumGradeService"); evaluation = jforumGradeService.getUserTopicEvaluation(topicId, user.getSakaiUserId()); if (evaluation == null) { org.etudes.api.app.jforum.Grade grade = jforumGradeService.getByForumTopicId(topic.getForumId(), topic.getId()); evaluation = jforumGradeService.newEvaluation(grade.getId(), UserDirectoryService.getCurrentUser().getId(), user.getSakaiUserId()); } Float score = null; try { score = Float.parseFloat(this.request.getParameter("score")); // if (score.floatValue() < 0) score = Float.valueOf(0.0f); if (score.floatValue() > 1000) score = Float.valueOf(1000.0f); score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); } catch (NumberFormatException ne) { if (logger.isWarnEnabled()) { logger.warn("evaluateTopicUser() : " + ne); } } String comments = this.request.getParameter("comments"); evaluation.setReleased(releaseGrade); evaluation.setScore(score); evaluation.setComments(comments); evaluation.setEvaluatedBySakaiUserId(UserDirectoryService.getCurrentUser().getId()); jforumGradeService.addModifyUserEvaluation(evaluation); this.context.put("updatesucess", true); this.showEvalTopicUser(); }
From source file:org.etudes.jforum.view.forum.GradeAction.java
protected void evaluateForumGrades() throws Exception { boolean isfacilitator = JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()) || SecurityService.isSuperUser(); if (!isfacilitator) { this.context.put("message", I18n.getMessage("User.NotAuthorizedToGrade")); this.setTemplateName(TemplateKeys.GRADE_EVAL_NOT_AUTHORIZED); return;// w ww .j ava2 s .c om } /*adjust scores for all evaluations who have scores or if there are replies / posts for a user*/ String adjustScores = this.request.getParameter("adjust_scores"); Float adjustScore = null; if (adjustScores != null && adjustScores.trim().length() > 0) { try { adjustScore = Float.parseFloat(adjustScores); if (adjustScore.floatValue() > 1000) adjustScore = Float.valueOf(1000.0f); adjustScore = Float.valueOf(((float) Math.round(adjustScore.floatValue() * 100.0f)) / 100.0f); } catch (NumberFormatException ne) { if (logger.isWarnEnabled()) logger.warn("evaluateForumGrades(): adjust scores: " + ne); } } /*adjust comments will be added to all users/evaluations, if there are replies / posts for a user * and if a user doesn't have any posts but has a score (manually added by the teacher), * add/append comments*/ String adjustComments = this.request.getParameter("adjust_comments"); Enumeration<?> paramNames = this.request.getParameterNames(); String currentSakuserId = UserDirectoryService.getCurrentUser().getId(); JForumUserService jforumUserService = (JForumUserService) ComponentManager .get("org.etudes.api.app.jforum.JForumUserService"); org.etudes.api.app.jforum.User user = jforumUserService.getBySakaiUserId(currentSakuserId); String releaseAllEvaluated = this.request.getParameter("releaseall"); boolean releaseEvaluatedScore = false; if ((releaseAllEvaluated != null) && (Integer.parseInt(releaseAllEvaluated) == 1)) { releaseEvaluatedScore = true; } JForumGradeService jforumGradeService = (JForumGradeService) ComponentManager .get("org.etudes.api.app.jforum.JForumGradeService"); int gradeId = Integer.parseInt(this.request.getParameter("grade_id")); int forumId = this.request.getIntParameter("forum_id"); JForumForumService jforumForumService = (JForumForumService) ComponentManager .get("org.etudes.api.app.jforum.JForumForumService"); org.etudes.api.app.jforum.Forum forum = jforumForumService.getForum(forumId); org.etudes.api.app.jforum.Grade grade = forum.getGrade(); if (grade == null || grade.getType() != org.etudes.api.app.jforum.Grade.GradeType.FORUM.getType()) { this.context.put("errorMessage", I18n.getMessage("Grade.ItemNotGradable")); return; } List<org.etudes.api.app.jforum.Evaluation> evaluations = null; org.etudes.api.app.jforum.Evaluation.EvaluationsSort evalSort = org.etudes.api.app.jforum.Evaluation.EvaluationsSort.last_name_a; List<org.etudes.api.app.jforum.Evaluation> gradeEvaluations = new ArrayList<org.etudes.api.app.jforum.Evaluation>(); evaluations = jforumGradeService.getForumEvaluations(forumId); Map<Integer, org.etudes.api.app.jforum.Evaluation> exisEvalMap = new HashMap<Integer, org.etudes.api.app.jforum.Evaluation>(); for (org.etudes.api.app.jforum.Evaluation eval : evaluations) { exisEvalMap.put(eval.getId(), eval); } while (paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); boolean noScore = false; if (paramName.endsWith("_score")) { noScore = false; String paramScore = this.request.getParameter(paramName); // paramName is in the format gradeId_evalutionId_jforumUserId_score String ids[] = paramName.split("_"); String sakUserId = null; //sakUserId_userId sakUserId = this.request.getParameter("sakUserId_" + ids[2]); Float score = null; int totalPostCount = 0; try { String paramTotalPosts = paramName.replace("score", "totalposts"); String userTotalPosts = this.request.getParameter(paramTotalPosts); if ((userTotalPosts != null) && (userTotalPosts.trim().length() > 0)) { totalPostCount = Integer.parseInt(userTotalPosts.trim()); } if ((paramScore != null) && (paramScore.trim().length() > 0)) { score = Float.parseFloat(this.request.getParameter(paramName)); //if (score.floatValue() < 0) score = Float.valueOf(0.0f); if (score.floatValue() > 1000) score = Float.valueOf(1000.0f); score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); if (adjustScore != null && JForumUserUtil.isUserActive(sakUserId)) { score = score + adjustScore; score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); } } else { if (totalPostCount > 0 && adjustScore != null && JForumUserUtil.isUserActive(sakUserId)) { score = adjustScore.floatValue(); score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); } else { noScore = true; } } } catch (NumberFormatException ne) { if (logger.isWarnEnabled()) logger.warn("evaluateForumGrades() : " + ne); continue; } String paramComments = paramName.replace("score", "comments"); String comments = this.request.getParameter(paramComments); if (adjustComments != null && adjustComments.trim().length() > 0) { if ((totalPostCount > 0 || !noScore) && JForumUserUtil.isUserActive(sakUserId)) { StringBuffer strBufComments = new StringBuffer(); strBufComments.append(comments); strBufComments.append("\n"); strBufComments.append(adjustComments); comments = strBufComments.toString(); } } boolean releaseScore = false; if (releaseEvaluatedScore) { releaseScore = true; } else { String paramRelease = paramName.replace("score", "release"); String released = this.request.getParameter(paramRelease); if ((released != null) && (Integer.parseInt(released) == 1)) { releaseScore = true; } } /* * create evaluation if evaluation id is -1 and has valid grade id * update evaluation if evaluation is valid id and has valid grade id */ org.etudes.api.app.jforum.Evaluation evaluation = null; if (Integer.parseInt(ids[1]) == -1) { evaluation = jforumGradeService.newEvaluation(Integer.parseInt(ids[0]), currentSakuserId, sakUserId); if (noScore) { if (comments == null || comments.trim().length() == 0) { continue; } } evaluation.setScore(score); evaluation.setComments(comments.trim()); evaluation.setReleased(releaseScore); gradeEvaluations.add(evaluation); } else if (Integer.parseInt(ids[1]) > 0) { // check for changes don't update if not changed int evaluationId = Integer.parseInt(ids[1]); org.etudes.api.app.jforum.Evaluation exisEval = exisEvalMap.get(evaluationId); if (noScore) { if (comments != null && comments.trim().length() == 0) { exisEval.setScore(null); exisEval.setComments(null); exisEval.setReleased(releaseScore); exisEval.setEvaluatedBySakaiUserId(currentSakuserId); } else { exisEval.setScore(null); exisEval.setComments(comments.trim()); exisEval.setReleased(releaseScore); exisEval.setEvaluatedBySakaiUserId(currentSakuserId); } gradeEvaluations.add(exisEval); } else { exisEval.setScore(score); exisEval.setComments(comments.trim()); exisEval.setReleased(releaseScore); exisEval.setEvaluatedBySakaiUserId(currentSakuserId); gradeEvaluations.add(exisEval); } } } } /* If evaluated and checked "Send to Gradebook", update grade "add to gradebook" to true * and send the grades to grade book * If "Send to Gradebook" is unchecked, update grade "add to gradebook" to false * Remove grades from grade book if grade "add to gradebook" is true before */ String sendToGradeBook = this.request.getParameter("send_to_grade_book"); boolean addToGradeBook = false; if ((sendToGradeBook != null) && (Integer.parseInt(sendToGradeBook) == 1)) { addToGradeBook = true; } grade.setAddToGradeBook(Boolean.valueOf(addToGradeBook)); forum.getEvaluations().clear(); forum.getEvaluations().addAll(gradeEvaluations); jforumForumService.evaluateForum(forum); // if add to grade option unchecked after saving show the error that there is existing title in the gradebook if (addToGradeBook) { /* String gradebookUid = ToolManager.getInstance().getCurrentPlacement().getContext(); JForumGBService jForumGBService = null; jForumGBService = (JForumGBService)ComponentManager.get("org.etudes.api.app.jforum.JForumGBService"); if (jForumGBService.isAssignmentDefined(gradebookUid, category.getName())) { } */ org.etudes.api.app.jforum.Grade forumGrade = jforumGradeService.getByForumId(forumId); if (forumGrade != null && !forumGrade.isAddToGradeBook()) { if (forumGrade.getPoints() <= 0) { this.context.put("errorMessage", I18n.getMessage("Grade.GradeBookAssignmentHasIllegalPointsException")); } else { this.context.put("errorMessage", I18n.getMessage("Grade.GradeBookConflictingAssignmentNameException")); } } } }
From source file:org.etudes.jforum.view.forum.GradeAction.java
protected void evaluateTopicGrades() throws Exception { boolean isfacilitator = JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()) || SecurityService.isSuperUser(); if (!isfacilitator) { this.context.put("message", I18n.getMessage("User.NotAuthorizedToGrade")); this.setTemplateName(TemplateKeys.GRADE_EVAL_NOT_AUTHORIZED); return;//from w w w.j a v a 2 s .co m } /*adjust scores for all evaluations who have scores or if there are replies / posts for a user*/ String adjustScores = this.request.getParameter("adjust_scores"); Float adjustScore = null; if (adjustScores != null && adjustScores.trim().length() > 0) { try { adjustScore = Float.parseFloat(adjustScores); if (adjustScore.floatValue() > 1000) adjustScore = Float.valueOf(1000.0f); adjustScore = Float.valueOf(((float) Math.round(adjustScore.floatValue() * 100.0f)) / 100.0f); } catch (NumberFormatException ne) { if (logger.isWarnEnabled()) logger.warn("evaluateForumGrades(): adjust scores: " + ne); } } /*adjust comments will be added to all users/evaluations, if there are replies / posts for a user * and if a user doesn't have any posts but has a score (manually added by the teacher), * add/append comments*/ String adjustComments = this.request.getParameter("adjust_comments"); Enumeration<?> paramNames = this.request.getParameterNames(); String currentSakuserId = UserDirectoryService.getCurrentUser().getId(); JForumUserService jforumUserService = (JForumUserService) ComponentManager .get("org.etudes.api.app.jforum.JForumUserService"); org.etudes.api.app.jforum.User user = jforumUserService.getBySakaiUserId(currentSakuserId); String releaseAllEvaluated = this.request.getParameter("releaseall"); boolean releaseEvaluatedScore = false; if ((releaseAllEvaluated != null) && (Integer.parseInt(releaseAllEvaluated) == 1)) { releaseEvaluatedScore = true; } JForumGradeService jforumGradeService = (JForumGradeService) ComponentManager .get("org.etudes.api.app.jforum.JForumGradeService"); int gradeId = Integer.parseInt(this.request.getParameter("grade_id")); int topicId = this.request.getIntParameter("topic_id"); JForumPostService jforumPostService = (JForumPostService) ComponentManager .get("org.etudes.api.app.jforum.JForumPostService"); org.etudes.api.app.jforum.Topic topic = jforumPostService.getTopic(topicId); org.etudes.api.app.jforum.Grade grade = topic.getGrade(); if (grade == null || grade.getType() != org.etudes.api.app.jforum.Grade.GradeType.TOPIC.getType()) { this.context.put("errorMessage", I18n.getMessage("Grade.ItemNotGradable")); return; } List<org.etudes.api.app.jforum.Evaluation> evaluations = null; org.etudes.api.app.jforum.Evaluation.EvaluationsSort evalSort = org.etudes.api.app.jforum.Evaluation.EvaluationsSort.last_name_a; List<org.etudes.api.app.jforum.Evaluation> gradeEvaluations = new ArrayList<org.etudes.api.app.jforum.Evaluation>(); evaluations = jforumGradeService.getTopicEvaluations(topic.getForumId(), topic.getId()); Map<Integer, org.etudes.api.app.jforum.Evaluation> exisEvalMap = new HashMap<Integer, org.etudes.api.app.jforum.Evaluation>(); for (org.etudes.api.app.jforum.Evaluation eval : evaluations) { exisEvalMap.put(eval.getId(), eval); } while (paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); boolean noScore = false; if (paramName.endsWith("_score")) { noScore = false; String paramScore = this.request.getParameter(paramName); // paramName is in the format gradeId_evalutionId_jforumUserId_score String ids[] = paramName.split("_"); String sakUserId = null; //sakUserId_userId sakUserId = this.request.getParameter("sakUserId_" + ids[2]); Float score = null; int totalPostCount = 0; try { String paramTotalPosts = paramName.replace("score", "totalposts"); String userTotalPosts = this.request.getParameter(paramTotalPosts); if ((userTotalPosts != null) && (userTotalPosts.trim().length() > 0)) { totalPostCount = Integer.parseInt(userTotalPosts.trim()); } if ((paramScore != null) && (paramScore.trim().length() > 0)) { score = Float.parseFloat(this.request.getParameter(paramName)); //if (score.floatValue() < 0) score = Float.valueOf(0.0f); if (score.floatValue() > 1000) score = Float.valueOf(1000.0f); score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); if (adjustScore != null && JForumUserUtil.isUserActive(sakUserId)) { score = score + adjustScore; score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); } } else { if (totalPostCount > 0 && adjustScore != null && JForumUserUtil.isUserActive(sakUserId)) { score = adjustScore.floatValue(); score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); } else { noScore = true; } } } catch (NumberFormatException ne) { if (logger.isWarnEnabled()) logger.warn("evaluateForumGrades() : " + ne); continue; } String paramComments = paramName.replace("score", "comments"); String comments = this.request.getParameter(paramComments); if (adjustComments != null && adjustComments.trim().length() > 0) { if ((totalPostCount > 0 || !noScore) && JForumUserUtil.isUserActive(sakUserId)) { StringBuffer strBufComments = new StringBuffer(); strBufComments.append(comments); strBufComments.append("\n"); strBufComments.append(adjustComments); comments = strBufComments.toString(); } } boolean releaseScore = false; if (releaseEvaluatedScore) { releaseScore = true; } else { String paramRelease = paramName.replace("score", "release"); String released = this.request.getParameter(paramRelease); if ((released != null) && (Integer.parseInt(released) == 1)) { releaseScore = true; } } /* * create evaluation if evaluation id is -1 and has valid grade id * update evaluation if evaluation is valid id and has valid grade id */ org.etudes.api.app.jforum.Evaluation evaluation = null; if (Integer.parseInt(ids[1]) == -1) { evaluation = jforumGradeService.newEvaluation(Integer.parseInt(ids[0]), currentSakuserId, sakUserId); if (noScore) { if (comments == null || comments.trim().length() == 0) { continue; } } evaluation.setScore(score); evaluation.setComments(comments.trim()); evaluation.setReleased(releaseScore); gradeEvaluations.add(evaluation); } else if (Integer.parseInt(ids[1]) > 0) { // check for changes don't update if not changed int evaluationId = Integer.parseInt(ids[1]); org.etudes.api.app.jforum.Evaluation exisEval = exisEvalMap.get(evaluationId); if (noScore) { if (comments != null && comments.trim().length() == 0) { exisEval.setScore(null); exisEval.setComments(null); exisEval.setReleased(releaseScore); exisEval.setEvaluatedBySakaiUserId(currentSakuserId); } else { exisEval.setScore(null); exisEval.setComments(comments.trim()); exisEval.setReleased(releaseScore); exisEval.setEvaluatedBySakaiUserId(currentSakuserId); } gradeEvaluations.add(exisEval); } else { exisEval.setScore(score); exisEval.setComments(comments.trim()); exisEval.setReleased(releaseScore); exisEval.setEvaluatedBySakaiUserId(currentSakuserId); gradeEvaluations.add(exisEval); } } } } /* If evaluated and checked "Send to Gradebook", update grade "add to gradebook" to true * and send the grades to grade book * If "Send to Gradebook" is unchecked, update grade "add to gradebook" to false * Remove grades from grade book if grade "add to gradebook" is true before */ String sendToGradeBook = this.request.getParameter("send_to_grade_book"); boolean addToGradeBook = false; if ((sendToGradeBook != null) && (Integer.parseInt(sendToGradeBook) == 1)) { addToGradeBook = true; } grade.setAddToGradeBook(Boolean.valueOf(addToGradeBook)); topic.getEvaluations().clear(); topic.getEvaluations().addAll(gradeEvaluations); jforumPostService.evaluateTopic(topic); // if add to grade option unchecked after saving show the error that there is existing title in the gradebook if (addToGradeBook) { /* String gradebookUid = ToolManager.getInstance().getCurrentPlacement().getContext(); JForumGBService jForumGBService = null; jForumGBService = (JForumGBService)ComponentManager.get("org.etudes.api.app.jforum.JForumGBService"); if (jForumGBService.isAssignmentDefined(gradebookUid, category.getName())) { } */ org.etudes.api.app.jforum.Grade topicGrade = jforumGradeService.getByForumTopicId(topic.getForumId(), topic.getId()); if (topicGrade != null && !topicGrade.isAddToGradeBook()) { if (topicGrade.getPoints() <= 0) { this.context.put("errorMessage", I18n.getMessage("Grade.GradeBookAssignmentHasIllegalPointsException")); } else { this.context.put("errorMessage", I18n.getMessage("Grade.GradeBookConflictingAssignmentNameException")); } } } }
From source file:org.etudes.jforum.view.forum.GradeAction.java
protected void evaluateCategoryGrades() throws Exception { boolean isfacilitator = JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()) || SecurityService.isSuperUser(); if (!isfacilitator) { this.context.put("message", I18n.getMessage("User.NotAuthorizedToGrade")); this.setTemplateName(TemplateKeys.GRADE_EVAL_NOT_AUTHORIZED); return;/*from w w w . j a va2 s . c o m*/ } /*adjust scores for all evaluations who have scores or if there are replies / posts for a user*/ String adjustScores = this.request.getParameter("adjust_scores"); Float adjustScore = null; if (adjustScores != null && adjustScores.trim().length() > 0) { try { adjustScore = Float.parseFloat(adjustScores); if (adjustScore.floatValue() > 1000) adjustScore = Float.valueOf(1000.0f); adjustScore = Float.valueOf(((float) Math.round(adjustScore.floatValue() * 100.0f)) / 100.0f); } catch (NumberFormatException ne) { if (logger.isWarnEnabled()) logger.warn("evaluateCategoryGrades(): adjust scores: " + ne); } } /*adjust comments will be added to all users/evaluations, if there are replies / posts for a user * and if a user doesn't have any posts but has a score (manually added by the teacher), * add/append comments*/ String adjustComments = this.request.getParameter("adjust_comments"); Enumeration<?> paramNames = this.request.getParameterNames(); String currentSakuserId = UserDirectoryService.getCurrentUser().getId(); //int evaluatedBy = (DataAccessDriver.getInstance().newUserDAO().selectBySakaiUserId(sakuserId)).getId(); JForumUserService jforumUserService = (JForumUserService) ComponentManager .get("org.etudes.api.app.jforum.JForumUserService"); org.etudes.api.app.jforum.User user = jforumUserService.getBySakaiUserId(currentSakuserId); String releaseAllEvaluated = this.request.getParameter("releaseall"); boolean releaseEvaluatedScore = false; if ((releaseAllEvaluated != null) && (Integer.parseInt(releaseAllEvaluated) == 1)) { releaseEvaluatedScore = true; } JForumGradeService jforumGradeService = (JForumGradeService) ComponentManager .get("org.etudes.api.app.jforum.JForumGradeService"); int gradeId = Integer.parseInt(this.request.getParameter("grade_id")); int categoryId = this.request.getIntParameter("category_id"); JForumCategoryService jforumCategoryService = (JForumCategoryService) ComponentManager .get("org.etudes.api.app.jforum.JForumCategoryService"); org.etudes.api.app.jforum.Grade grade = jforumGradeService.getByCategoryId(categoryId); org.etudes.api.app.jforum.Category category = jforumCategoryService.getCategory(categoryId); //org.etudes.api.app.jforum.Grade grade = category.getGrade(); if (grade == null || grade.getType() != org.etudes.api.app.jforum.Grade.GradeType.CATEGORY.getType()) { this.context.put("errorMessage", I18n.getMessage("Grade.ItemNotGradable")); return; } category.setGrade(grade); List<org.etudes.api.app.jforum.Evaluation> evaluations = null; org.etudes.api.app.jforum.Evaluation.EvaluationsSort evalSort = org.etudes.api.app.jforum.Evaluation.EvaluationsSort.last_name_a; List<org.etudes.api.app.jforum.Evaluation> gradeEvaluations = new ArrayList<org.etudes.api.app.jforum.Evaluation>(); //evaluations = jforumGradeService.getCategoryEvaluationsWithPosts(categoryId, evalSort, UserDirectoryService.getCurrentUser().getId()); evaluations = jforumGradeService.getCategoryEvaluations(categoryId); Map<Integer, org.etudes.api.app.jforum.Evaluation> exisEvalMap = new HashMap<Integer, org.etudes.api.app.jforum.Evaluation>(); for (org.etudes.api.app.jforum.Evaluation eval : evaluations) { exisEvalMap.put(eval.getId(), eval); } while (paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); boolean noScore = false; if (paramName.endsWith("_score")) { noScore = false; String paramScore = this.request.getParameter(paramName); // paramName is in the format gradeId_evalutionId_jforumUserId_score String ids[] = paramName.split("_"); String sakUserId = null; //sakUserId_userId sakUserId = this.request.getParameter("sakUserId_" + ids[2]); Float score = null; int totalPostCount = 0; try { String paramTotalPosts = paramName.replace("score", "totalposts"); String userTotalPosts = this.request.getParameter(paramTotalPosts); if ((userTotalPosts != null) && (userTotalPosts.trim().length() > 0)) { totalPostCount = Integer.parseInt(userTotalPosts.trim()); } if ((paramScore != null) && (paramScore.trim().length() > 0)) { score = Float.parseFloat(this.request.getParameter(paramName)); //if (score.floatValue() < 0) score = Float.valueOf(0.0f); if (score.floatValue() > 1000) score = Float.valueOf(1000.0f); score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); if (adjustScore != null && JForumUserUtil.isUserActive(sakUserId)) { score = score + adjustScore; score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); } } else { if (totalPostCount > 0 && adjustScore != null && JForumUserUtil.isUserActive(sakUserId)) { score = adjustScore.floatValue(); score = Float.valueOf(((float) Math.round(score.floatValue() * 100.0f)) / 100.0f); } else { noScore = true; } } } catch (NumberFormatException ne) { if (logger.isWarnEnabled()) logger.warn("evaluateCategoryGrades() : " + ne); continue; } String paramComments = paramName.replace("score", "comments"); String comments = this.request.getParameter(paramComments); if (adjustComments != null && adjustComments.trim().length() > 0) { if ((totalPostCount > 0 || !noScore) && JForumUserUtil.isUserActive(sakUserId)) { StringBuffer strBufComments = new StringBuffer(); strBufComments.append(comments); strBufComments.append("\n"); strBufComments.append(adjustComments); comments = strBufComments.toString(); } } boolean releaseScore = false; if (releaseEvaluatedScore) { releaseScore = true; } else { String paramRelease = paramName.replace("score", "release"); String released = this.request.getParameter(paramRelease); if ((released != null) && (Integer.parseInt(released) == 1)) { releaseScore = true; } } /* * create evaluation if evaluation id is -1 and has valid grade id * update evaluation if evaluation is valid id and has valid grade id */ org.etudes.api.app.jforum.Evaluation evaluation = null; if (Integer.parseInt(ids[1]) == -1) { evaluation = jforumGradeService.newEvaluation(Integer.parseInt(ids[0]), currentSakuserId, sakUserId); if (noScore) { if (comments == null || comments.trim().length() == 0) { continue; } } evaluation.setScore(score); evaluation.setComments(comments.trim()); evaluation.setReleased(releaseScore); gradeEvaluations.add(evaluation); } else if (Integer.parseInt(ids[1]) > 0) { // check for changes don't update if not changed int evaluationId = Integer.parseInt(ids[1]); org.etudes.api.app.jforum.Evaluation exisEval = exisEvalMap.get(evaluationId); if (noScore) { if (comments != null && comments.trim().length() == 0) { exisEval.setScore(null); exisEval.setComments(null); exisEval.setReleased(releaseScore); exisEval.setEvaluatedBySakaiUserId(currentSakuserId); } else { exisEval.setScore(null); exisEval.setComments(comments.trim()); exisEval.setReleased(releaseScore); exisEval.setEvaluatedBySakaiUserId(currentSakuserId); } gradeEvaluations.add(exisEval); } else { exisEval.setScore(score); exisEval.setComments(comments.trim()); exisEval.setReleased(releaseScore); exisEval.setEvaluatedBySakaiUserId(currentSakuserId); gradeEvaluations.add(exisEval); } } } } /* If evaluated and checked "Send to Gradebook", update grade "add to gradebook" to true * and send the grades to grade book * If "Send to Gradebook" is unchecked, update grade "add to gradebook" to false * Remove grades from grade book if grade "add to gradebook" is true before */ String sendToGradeBook = this.request.getParameter("send_to_grade_book"); boolean addToGradeBook = false; if ((sendToGradeBook != null) && (Integer.parseInt(sendToGradeBook) == 1)) { addToGradeBook = true; } grade.setAddToGradeBook(Boolean.valueOf(addToGradeBook)); category.getEvaluations().clear(); category.getEvaluations().addAll(gradeEvaluations); jforumCategoryService.evaluateCategory(category); // if add to grade option unchecked after saving show the error that there is existing title in the gradebook if (addToGradeBook) { /* String gradebookUid = ToolManager.getInstance().getCurrentPlacement().getContext(); JForumGBService jForumGBService = null; jForumGBService = (JForumGBService)ComponentManager.get("org.etudes.api.app.jforum.JForumGBService"); if (jForumGBService.isAssignmentDefined(gradebookUid, category.getName())) { } */ //if (!category.getGrade().isAddToGradeBook()) org.etudes.api.app.jforum.Grade catGrade = jforumGradeService.getByCategoryId(categoryId); if (catGrade != null && !catGrade.isAddToGradeBook()) { if (catGrade.getPoints() <= 0) { this.context.put("errorMessage", I18n.getMessage("Grade.GradeBookAssignmentHasIllegalPointsException")); } else { this.context.put("errorMessage", I18n.getMessage("Grade.GradeBookConflictingAssignmentNameException")); } } } }
From source file:net.sf.jasperreports.engine.export.JRHtmlExporter.java
/** * *//*from w w w. j a va2 s .c om*/ protected void exportStyledTextRun(Map<Attribute, Object> attributes, String text, String tooltip, Locale locale, LineSpacingEnum lineSpacing, Float lineSpacingSize, float lineSpacingFactor, Color backcolor) throws IOException { boolean isBold = TextAttribute.WEIGHT_BOLD.equals(attributes.get(TextAttribute.WEIGHT)); boolean isItalic = TextAttribute.POSTURE_OBLIQUE.equals(attributes.get(TextAttribute.POSTURE)); String fontFamilyAttr = (String) attributes.get(TextAttribute.FAMILY); String fontFamily = fontFamilyAttr; FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(fontFamilyAttr, locale); if (fontInfo != null) { //fontName found in font extensions FontFamily family = fontInfo.getFontFamily(); String exportFont = family.getExportFont(getExporterKey()); if (exportFont == null) { HtmlResourceHandler fontHandler = getExporterOutput().getFontHandler() == null ? getFontHandler() : getExporterOutput().getFontHandler(); HtmlResourceHandler resourceHandler = getExporterOutput().getResourceHandler() == null ? getResourceHandler() : getExporterOutput().getResourceHandler(); if (fontHandler != null && resourceHandler != null) { HtmlFont htmlFont = HtmlFont.getInstance(locale, fontInfo, isBold, isItalic); if (htmlFont != null) { if (!fontsToProcess.containsKey(htmlFont.getId())) { fontsToProcess.put(htmlFont.getId(), htmlFont); HtmlFontUtil.handleFont(resourceHandler, htmlFont); } fontFamily = htmlFont.getId(); } } } else { fontFamily = exportFont; } } boolean localHyperlink = false; JRPrintHyperlink hyperlink = (JRPrintHyperlink) attributes.get(JRTextAttribute.HYPERLINK); if (!hyperlinkStarted && hyperlink != null) { startHyperlink(hyperlink); localHyperlink = true; } writer.write("<span style=\"font-family: "); writer.write(fontFamily); writer.write("; "); Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND); if (!hyperlinkStarted || !Color.black.equals(forecolor)) { writer.write("color: "); writer.write(JRColorUtil.getCssColor(forecolor)); writer.write("; "); } Color runBackcolor = (Color) attributes.get(TextAttribute.BACKGROUND); if (runBackcolor != null && !runBackcolor.equals(backcolor)) { writer.write("background-color: "); writer.write(JRColorUtil.getCssColor(runBackcolor)); writer.write("; "); } writer.write("font-size: "); writer.write(toSizeUnit((Float) attributes.get(TextAttribute.SIZE))); writer.write(";"); switch (lineSpacing) { case SINGLE: default: { if (lineSpacingFactor == 0) { writer.write(" line-height: 1; *line-height: normal;"); } else { writer.write(" line-height: " + lineSpacingFactor + ";"); } break; } case ONE_AND_HALF: { if (lineSpacingFactor == 0) { writer.write(" line-height: 1.5;"); } else { writer.write(" line-height: " + lineSpacingFactor + ";"); } break; } case DOUBLE: { if (lineSpacingFactor == 0) { writer.write(" line-height: 2.0;"); } else { writer.write(" line-height: " + lineSpacingFactor + ";"); } break; } case PROPORTIONAL: { if (lineSpacingSize != null) { writer.write(" line-height: " + lineSpacingSize.floatValue() + ";"); } break; } case AT_LEAST: case FIXED: { if (lineSpacingSize != null) { writer.write(" line-height: " + lineSpacingSize.floatValue() + "px;"); } break; } } /* if (!horizontalAlignment.equals(CSS_TEXT_ALIGN_LEFT)) { writer.write(" text-align: "); writer.write(horizontalAlignment); writer.write(";"); } */ if (isBold) { writer.write(" font-weight: bold;"); } if (isItalic) { writer.write(" font-style: italic;"); } if (TextAttribute.UNDERLINE_ON.equals(attributes.get(TextAttribute.UNDERLINE))) { writer.write(" text-decoration: underline;"); } if (TextAttribute.STRIKETHROUGH_ON.equals(attributes.get(TextAttribute.STRIKETHROUGH))) { writer.write(" text-decoration: line-through;"); } if (TextAttribute.SUPERSCRIPT_SUPER.equals(attributes.get(TextAttribute.SUPERSCRIPT))) { writer.write(" vertical-align: super;"); } else if (TextAttribute.SUPERSCRIPT_SUB.equals(attributes.get(TextAttribute.SUPERSCRIPT))) { writer.write(" vertical-align: sub;"); } writer.write("\""); if (tooltip != null) { writer.write(" title=\""); writer.write(JRStringUtil.xmlEncode(tooltip)); writer.write("\""); } writer.write(">"); writer.write(JRStringUtil.htmlEncode(text)); writer.write("</span>"); if (localHyperlink) { endHyperlink(); } }
From source file:net.sf.jasperreports.engine.export.JRXhtmlExporter.java
/** * *///from ww w . ja va2s. c om protected void exportStyledTextRun(Map<Attribute, Object> attributes, String text, String tooltip, Locale locale, LineSpacingEnum lineSpacing, Float lineSpacingSize, float lineSpacingFactor, Color backcolor) throws IOException { boolean isBold = TextAttribute.WEIGHT_BOLD.equals(attributes.get(TextAttribute.WEIGHT)); boolean isItalic = TextAttribute.POSTURE_OBLIQUE.equals(attributes.get(TextAttribute.POSTURE)); String fontFamilyAttr = (String) attributes.get(TextAttribute.FAMILY);//FIXMENOW reuse this font lookup code everywhere String fontFamily = fontFamilyAttr; FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(fontFamilyAttr, locale); if (fontInfo != null) { //fontName found in font extensions FontFamily family = fontInfo.getFontFamily(); String exportFont = family.getExportFont(getExporterKey()); if (exportFont == null) { HtmlResourceHandler fontHandler = getExporterOutput().getFontHandler() == null ? getFontHandler() : getExporterOutput().getFontHandler(); HtmlResourceHandler resourceHandler = getExporterOutput().getResourceHandler() == null ? getResourceHandler() : getExporterOutput().getResourceHandler(); if (fontHandler != null && resourceHandler != null) { HtmlFont htmlFont = HtmlFont.getInstance(locale, fontInfo, isBold, isItalic); if (htmlFont != null) { if (!fontsToProcess.containsKey(htmlFont.getId())) { fontsToProcess.put(htmlFont.getId(), htmlFont); HtmlFontUtil.handleFont(resourceHandler, htmlFont); } fontFamily = htmlFont.getId(); } } } else { fontFamily = exportFont; } } boolean localHyperlink = false; JRPrintHyperlink hyperlink = (JRPrintHyperlink) attributes.get(JRTextAttribute.HYPERLINK); if (!hyperlinkStarted && hyperlink != null) { startHyperlink(hyperlink); localHyperlink = true; } writer.write("<span style=\"font-family: "); writer.write(fontFamily); writer.write("; "); Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND); if (!hyperlinkStarted || !Color.black.equals(forecolor)) { writer.write("color: "); writer.write(JRColorUtil.getCssColor(forecolor)); writer.write("; "); } Color runBackcolor = (Color) attributes.get(TextAttribute.BACKGROUND); if (runBackcolor != null && !runBackcolor.equals(backcolor)) { writer.write("background-color: "); writer.write(JRColorUtil.getCssColor(runBackcolor)); writer.write("; "); } writer.write("font-size: "); writer.write(toSizeUnit((Float) attributes.get(TextAttribute.SIZE))); writer.write(";"); switch (lineSpacing) { case SINGLE: default: { if (lineSpacingFactor == 0) { writer.write(" line-height: 1; *line-height: normal;"); } else { writer.write(" line-height: " + lineSpacingFactor + ";"); } break; } case ONE_AND_HALF: { if (lineSpacingFactor == 0) { writer.write(" line-height: 1.5;"); } else { writer.write(" line-height: " + lineSpacingFactor + ";"); } break; } case DOUBLE: { if (lineSpacingFactor == 0) { writer.write(" line-height: 2.0;"); } else { writer.write(" line-height: " + lineSpacingFactor + ";"); } break; } case PROPORTIONAL: { if (lineSpacingSize != null) { writer.write(" line-height: " + lineSpacingSize.floatValue() + ";"); } break; } case AT_LEAST: case FIXED: { if (lineSpacingSize != null) { writer.write(" line-height: " + lineSpacingSize.floatValue() + "px;"); } break; } } /* if (!horizontalAlignment.equals(CSS_TEXT_ALIGN_LEFT)) { writer.write(" text-align: "); writer.write(horizontalAlignment); writer.write(";"); } */ if (isBold) { writer.write(" font-weight: bold;"); } if (isItalic) { writer.write(" font-style: italic;"); } if (TextAttribute.UNDERLINE_ON.equals(attributes.get(TextAttribute.UNDERLINE))) { writer.write(" text-decoration: underline;"); } if (TextAttribute.STRIKETHROUGH_ON.equals(attributes.get(TextAttribute.STRIKETHROUGH))) { writer.write(" text-decoration: line-through;"); } if (TextAttribute.SUPERSCRIPT_SUPER.equals(attributes.get(TextAttribute.SUPERSCRIPT))) { writer.write(" vertical-align: super;"); } else if (TextAttribute.SUPERSCRIPT_SUB.equals(attributes.get(TextAttribute.SUPERSCRIPT))) { writer.write(" vertical-align: sub;"); } writer.write("\""); if (tooltip != null) { writer.write(" title=\""); writer.write(JRStringUtil.xmlEncode(tooltip)); writer.write("\""); } writer.write(">"); writer.write(JRStringUtil.htmlEncode(text)); writer.write("</span>"); if (localHyperlink) { endHyperlink(); } }
From source file:com.clark.func.Functions.java
/** * <p>// www .jav a2 s . c om * Turns a string value into a java.lang.Number. * </p> * * <p> * First, the value is examined for a type qualifier on the end ( * <code>'f','F','d','D','l','L'</code>). If it is found, it starts trying * to create successively larger types from the type specified until one is * found that can represent the value. * </p> * * <p> * If a type specifier is not found, it will check for a decimal point and * then try successively larger types from <code>Integer</code> to * <code>BigInteger</code> and from <code>Float</code> to * <code>BigDecimal</code>. * </p> * * <p> * If the string starts with <code>0x</code> or <code>-0x</code>, it will be * interpreted as a hexadecimal integer. Values with leading <code>0</code> * 's will not be interpreted as octal. * </p> * * <p> * Returns <code>null</code> if the string is <code>null</code>. * </p> * * <p> * This method does not trim the input string, i.e., strings with leading or * trailing spaces will generate NumberFormatExceptions. * </p> * * @param str * String containing a number, may be null * @return Number created from the string * @throws NumberFormatException * if the value cannot be converted */ public static Number createNumber(String str) throws NumberFormatException { if (str == null) { return null; } if (isBlank(str)) { throw new NumberFormatException("A blank string is not a valid number"); } if (str.startsWith("--")) { // this is protection for poorness in java.lang.BigDecimal. // it accepts this as a legal value, but it does not appear // to be in specification of class. OS X Java parses it to // a wrong value. return null; } if (str.startsWith("0x") || str.startsWith("-0x")) { return createInteger(str); } char lastChar = str.charAt(str.length() - 1); String mant; String dec; String exp; int decPos = str.indexOf('.'); int expPos = str.indexOf('e') + str.indexOf('E') + 1; if (decPos > -1) { if (expPos > -1) { if (expPos < decPos) { throw new NumberFormatException(str + " is not a valid number."); } dec = str.substring(decPos + 1, expPos); } else { dec = str.substring(decPos + 1); } mant = str.substring(0, decPos); } else { if (expPos > -1) { mant = str.substring(0, expPos); } else { mant = str; } dec = null; } if (!Character.isDigit(lastChar) && lastChar != '.') { if (expPos > -1 && expPos < str.length() - 1) { exp = str.substring(expPos + 1, str.length() - 1); } else { exp = null; } // Requesting a specific type.. String numeric = str.substring(0, str.length() - 1); boolean allZeros = isAllZeros(mant) && isAllZeros(exp); switch (lastChar) { case 'l': case 'L': if (dec == null && exp == null && (numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) { try { return createLong(numeric); } catch (NumberFormatException nfe) { // Too big for a long } return createBigInteger(numeric); } throw new NumberFormatException(str + " is not a valid number."); case 'f': case 'F': try { Float f = createFloat(numeric); if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) { // If it's too big for a float or the float value = // 0 // and the string // has non-zeros in it, then float does not have the // precision we want return f; } } catch (NumberFormatException nfe) { // ignore the bad number } //$FALL-THROUGH$ case 'd': case 'D': try { Double d = createDouble(numeric); if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) { return d; } } catch (NumberFormatException nfe) { // ignore the bad number } try { return createBigDecimal(numeric); } catch (NumberFormatException e) { // ignore the bad number } //$FALL-THROUGH$ default: throw new NumberFormatException(str + " is not a valid number."); } } else { // User doesn't have a preference on the return type, so let's start // small and go from there... if (expPos > -1 && expPos < str.length() - 1) { exp = str.substring(expPos + 1, str.length()); } else { exp = null; } if (dec == null && exp == null) { // Must be an int,long,bigint try { return createInteger(str); } catch (NumberFormatException nfe) { // ignore the bad number } try { return createLong(str); } catch (NumberFormatException nfe) { // ignore the bad number } return createBigInteger(str); } else { // Must be a float,double,BigDec boolean allZeros = isAllZeros(mant) && isAllZeros(exp); try { Float f = createFloat(str); if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) { return f; } } catch (NumberFormatException nfe) { // ignore the bad number } try { Double d = createDouble(str); if (!(d.isInfinite() || (d.doubleValue() == 0.0D && !allZeros))) { return d; } } catch (NumberFormatException nfe) { // ignore the bad number } return createBigDecimal(str); } } }