Java Code Examples for org.apache.commons.lang.StringEscapeUtils.escapeJavaScript()

The following are Jave code examples for showing how to use escapeJavaScript() of the org.apache.commons.lang.StringEscapeUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: NotebookUserDTO.java   View Source Code Vote up 6 votes
public NotebookUserDTO(NotebookUser user, NotebookEntry entry) {
this.uid = user.getUid();
this.loginName = user.getLoginName();
this.firstName = user.getFirstName();
this.lastName = user.getLastName();
this.finishedActivity = user.isFinishedActivity();
this.entryUID = user.getEntryUID();
if (user.getTeachersComment() != null) {
    this.teachersComment = StringEscapeUtils.escapeJavaScript(user.getTeachersComment());
}
this.entryDTO = new NotebookEntryDTO(entry);
   }
 
Example 2
Project: lams   File: NotebookUserDTO.java   View Source Code Vote up 6 votes
public NotebookUserDTO(NotebookUser user) {
this.uid = user.getUid();
this.loginName = user.getLoginName();
this.firstName = user.getFirstName();
this.lastName = user.getLastName();
this.finishedActivity = user.isFinishedActivity();
this.entryUID = user.getEntryUID();
if (user.getTeachersComment() != null) {
    this.teachersComment = StringEscapeUtils.escapeJavaScript(user.getTeachersComment());
}
   }
 
Example 3
Project: otter-G   File: NumberFormatUtil.java   View Source Code Vote up 6 votes
public String getHtmlOriginalContent(String originalContent, String escape) {
    originalContent = StringUtils.replace(originalContent, "\n", "<br>");
    originalContent = StringEscapeUtils.escapeJavaScript(originalContent);
    if ("HTML".equalsIgnoreCase(escape)) {
        originalContent = StringEscapeUtils.escapeHtml(originalContent);
        originalContent = StringUtils.replace(originalContent, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
        originalContent = StringUtils.replace(originalContent, "\\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
        return originalContent;
    } else {
        return originalContent;
    }
}
 
Example 4
Project: lams   File: AssessmentEscapeUtils.java   View Source Code Vote up 5 votes
private static void escapeQuotesInQuestionResult(AssessmentQuestionResult questionResult) {
String answerString = questionResult.getAnswerString();
if (answerString != null) {
    String answerStringEscaped = StringEscapeUtils.escapeJavaScript(answerString);
    questionResult.setAnswerStringEscaped(answerStringEscaped);
}

AssessmentQuestion question = questionResult.getAssessmentQuestion();
String title = question.getTitle();
if (title != null) {
    String titleEscaped = StringEscapeUtils.escapeJavaScript(title);
    question.setTitleEscaped(titleEscaped);
}

for (AssessmentQuestionOption option : question.getOptions()) {
    String questionStr = option.getQuestion();
    if (questionStr != null) {
	String questionEscaped = StringEscapeUtils.escapeJavaScript(questionStr);
	option.setQuestionEscaped(questionEscaped);
    }

    String optionStr = option.getOptionString();
    if (optionStr != null) {
	String optionEscaped = StringEscapeUtils.escapeJavaScript(optionStr);
	option.setOptionStringEscaped(optionEscaped);
    }
}
   }
 
Example 5
Project: lams   File: NotebookEntryDTO.java   View Source Code Vote up 5 votes
public NotebookEntryDTO(NotebookEntry entry) {
this.uid = entry.getUid();
this.entry = entry.getEntry();
if (this.entry != null) {
    this.entryEscaped = StringEscapeUtils.escapeJavaScript(this.entry);
}
this.createDate = entry.getCreateDate();
this.lastModified = (entry.getLastModified() == null) ? entry.getCreateDate() : entry.getLastModified();
   }
 
Example 6
Project: lams   File: McMonitoringAction.java   View Source Code Vote up 5 votes
/**
    * Populate user jqgrid table on summary page.
    */
   public ActionForward userMasterDetail(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) {
IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext());

Long userUid = WebUtil.readLongParam(request, McAppConstants.USER_UID);
McQueUsr user = mcService.getMcUserByUID(userUid);
List<McUsrAttempt> userAttempts = mcService.getFinalizedUserAttempts(user);

// Escapes all characters that may brake JS code on assigning Java value to JS String variable (particularly
// escapes all quotes in the following way \").
if (userAttempts != null) {
    for (McUsrAttempt userAttempt : userAttempts) {
	McQueContent question = userAttempt.getMcQueContent();
	McOptsContent option = userAttempt.getMcOptionsContent();

	String questionText = question.getQuestion();
	if (questionText != null) {
	    String escapedQuestion = StringEscapeUtils.escapeJavaScript(questionText);
	    question.setEscapedQuestion(escapedQuestion);
	}

	String optionText = option.getMcQueOptionText();
	if (optionText != null) {
	    String escapedOptionText = StringEscapeUtils.escapeJavaScript(optionText);
	    option.setEscapedOptionText(escapedOptionText);
	}
    }
}

request.setAttribute(McAppConstants.ATTR_CONTENT, user.getMcSession().getMcContent());
request.setAttribute(McAppConstants.USER_ATTEMPTS, userAttempts);
request.setAttribute(McAppConstants.TOOL_SESSION_ID, user.getMcSession().getMcSessionId());
return (userAttempts == null || userAttempts.isEmpty()) ? null
	: mapping.findForward(McAppConstants.USER_MASTER_DETAIL);
   }
 
Example 7
Project: lams   File: MonitoringAction.java   View Source Code Vote up 5 votes
private ActionForward itemSummary(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) {

initializeScratchieService();
String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);
request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID());

Long itemUid = WebUtil.readLongParam(request, ScratchieConstants.ATTR_ITEM_UID);
if (itemUid.equals(-1)) {
    return null;
}
ScratchieItem item = service.getScratchieItemByUid(itemUid);
request.setAttribute(ScratchieConstants.ATTR_ITEM, item);

Long contentId = (Long) sessionMap.get(ScratchieConstants.ATTR_TOOL_CONTENT_ID);
List<GroupSummary> summaryList = service.getQuestionSummary(contentId, itemUid);

// escape JS sensitive characters in answer descriptions
for (GroupSummary summary : summaryList) {
    for (ScratchieAnswer answer : summary.getAnswers()) {
	String description = (answer.getDescription() == null) ? ""
		: StringEscapeUtils.escapeJavaScript(answer.getDescription());
	answer.setDescription(description);
    }
}

request.setAttribute(ScratchieConstants.ATTR_SUMMARY_LIST, summaryList);
return mapping.findForward(ScratchieConstants.SUCCESS);
   }
 
Example 8
Project: lams   File: ScratchieServiceImpl.java   View Source Code Vote up 5 votes
@Override
   public List<ReflectDTO> getReflectionList(Long contentId) {
ArrayList<ReflectDTO> reflections = new ArrayList<>();

// get all available leaders associated with this content as only leaders have reflections
List<ScratchieSession> sessionList = scratchieSessionDao.getByContentId(contentId);
for (ScratchieSession session : sessionList) {

    ScratchieUser leader = session.getGroupLeader();
    if (leader != null) {
	NotebookEntry notebookEntry = getEntry(session.getSessionId(), CoreNotebookConstants.NOTEBOOK_TOOL,
		ScratchieConstants.TOOL_SIGNATURE, leader.getUserId().intValue());
	if ((notebookEntry != null) && StringUtils.isNotBlank(notebookEntry.getEntry())) {
	    User user = new User();
	    user.setLastName(leader.getLastName());
	    user.setFirstName(leader.getFirstName());
	    ReflectDTO reflectDTO = new ReflectDTO(user);
	    reflectDTO.setGroupName(session.getSessionName());
	    String reflection = notebookEntry.getEntry();
	    reflection = StringEscapeUtils.escapeJavaScript(reflection);
	    reflectDTO.setReflection(reflection);
	    reflectDTO.setIsGroupLeader(session.isUserGroupLeader(leader.getUid()));

	    reflections.add(reflectDTO);
	}
    }
}

return reflections;
   }
 
Example 9
Project: otter-G   File: NumberFormatUtil.java   View Source Code Vote up 5 votes
public String getHtmlOriginalContent(String originalContent) {
    originalContent = StringUtils.replace(originalContent, "\n", "<br>");
    originalContent = StringUtils.replace(originalContent, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
    return StringEscapeUtils.escapeJavaScript(originalContent);
}