List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeEcmaScript
public static final String escapeEcmaScript(final String input)
Escapes the characters in a String using EcmaScript String rules.
Escapes any values it finds into their EcmaScript String form.
From source file:org.niord.web.conf.SiteTextsServletFilter.java
/** Encodes the value as a javascript string **/ private String encodeValue(String value) { if (StringUtils.isBlank(value)) { return "''"; }//from w ww .j a va2s . co m // Emit the escaped translation as a javascript string return Arrays.stream(value.split("\n")) .map(v -> String.format("'%s'", StringEscapeUtils.escapeEcmaScript(v))) .collect(Collectors.joining(" +\n")); }
From source file:org.niord.web.DictionaryRestService.java
/** Encodes the value as a property file value **/ private String encodeValue(String value) { return StringEscapeUtils.escapeEcmaScript(value); }
From source file:org.onebusaway.presentation.tags.JsonComponent.java
@Override public boolean end(Writer writer, String body) { if (_value == null) _value = "top"; Object value = findValue(_value); String json = null;// w w w . j ava 2s . c o m try { Collection<Pattern> empty = Collections.emptyList(); json = JSONUtil.serialize(value, empty, empty, _ignoreHierarchy, _excludeNullProperties); } catch (JSONException ex) { LOG.error("Could not generate json from value", ex); } if (json != null) { if (_escapeJavaScript) { json = StringEscapeUtils.escapeEcmaScript(json); } if (getVar() != null) { /** * We either write the url out to a variable */ putInContext(json); } else { /** * Or otherwise print out the url directly */ try { writer.write(json); } catch (IOException e) { LOG.error("Could not write out json value", e); } } } return super.end(writer, ""); }
From source file:org.orcid.frontend.web.controllers.BaseController.java
@ModelAttribute("jsMessagesJson") public String getJavascriptMessages(HttpServletRequest request) { ObjectMapper mapper = new ObjectMapper(); Locale locale = RequestContextUtils.getLocale(request); org.orcid.pojo.Local lPojo = new org.orcid.pojo.Local(); lPojo.setLocale(locale.toString());/*from w ww.j av a 2 s . co m*/ ResourceBundle resources = ResourceBundle.getBundle("i18n/javascript", locale, new UTF8Control()); lPojo.setMessages(OrcidStringUtils.resourceBundleToMap(resources)); String messages = ""; try { messages = StringEscapeUtils.escapeEcmaScript(mapper.writeValueAsString(lPojo)); } catch (IOException e) { LOGGER.error("getJavascriptMessages error:" + e.toString(), e); } return messages; }
From source file:org.orcid.frontend.web.controllers.PublicProfileController.java
@RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}") public ModelAndView publicPreview(HttpServletRequest request, @RequestParam(value = "page", defaultValue = "1") int pageNo, @RequestParam(value = "v", defaultValue = "0") int v, @RequestParam(value = "maxResults", defaultValue = "15") int maxResults, @PathVariable("orcid") String orcid) { OrcidProfile profile = orcidProfileCacheManager.retrievePublic(orcid); if (profile == null) { return new ModelAndView("error-404"); }/* w ww.java 2 s . co m*/ ModelAndView mav = null; mav = new ModelAndView("public_profile_v3"); mav.addObject("isPublicProfile", true); boolean isProfileEmtpy = true; request.getSession().removeAttribute(PUBLIC_WORKS_RESULTS_ATTRIBUTE); mav.addObject("profile", profile); String countryName = getCountryName(profile, true); if (!StringUtil.isBlank(countryName)) mav.addObject("countryName", countryName); LinkedHashMap<Long, WorkForm> minimizedWorksMap = new LinkedHashMap<>(); LinkedHashMap<Long, Affiliation> affiliationMap = new LinkedHashMap<>(); LinkedHashMap<Long, Funding> fundingMap = new LinkedHashMap<>(); LinkedHashMap<Long, PeerReview> peerReviewMap = new LinkedHashMap<>(); if (profile != null && profile.getOrcidBio() != null && profile.getOrcidBio().getBiography() != null && StringUtils.isNotBlank(profile.getOrcidBio().getBiography().getContent())) { isProfileEmtpy = false; } if (profile.isLocked()) { mav.addObject("locked", true); } else if (profile.getOrcidDeprecated() != null) { String primaryRecord = profile.getOrcidDeprecated().getPrimaryRecord().getOrcidIdentifier().getPath(); mav.addObject("deprecated", true); mav.addObject("primaryRecord", primaryRecord); } else { minimizedWorksMap = minimizedWorksMap(orcid); if (minimizedWorksMap.size() > 0) { mav.addObject("works", minimizedWorksMap.values()); isProfileEmtpy = false; } else { mav.addObject("worksEmpty", true); } affiliationMap = affiliationMap(orcid); if (affiliationMap.size() > 0) { mav.addObject("affilations", affiliationMap.values()); isProfileEmtpy = false; } else { mav.addObject("affiliationsEmpty", true); } fundingMap = fundingMap(orcid); if (fundingMap.size() > 0) isProfileEmtpy = false; else { mav.addObject("fundingEmpty", true); } peerReviewMap = peerReviewMap(orcid); if (peerReviewMap.size() > 0) { mav.addObject("peerReviews", peerReviewMap.values()); isProfileEmtpy = false; } else { mav.addObject("peerReviewsEmpty", true); } } ObjectMapper mapper = new ObjectMapper(); try { String worksIdsJson = mapper.writeValueAsString(minimizedWorksMap.keySet()); String affiliationIdsJson = mapper.writeValueAsString(affiliationMap.keySet()); String fundingIdsJson = mapper.writeValueAsString(fundingMap.keySet()); String peerReviewIdsJson = mapper.writeValueAsString(peerReviewMap.keySet()); mav.addObject("workIdsJson", StringEscapeUtils.escapeEcmaScript(worksIdsJson)); mav.addObject("affiliationIdsJson", StringEscapeUtils.escapeEcmaScript(affiliationIdsJson)); mav.addObject("fundingIdsJson", StringEscapeUtils.escapeEcmaScript(fundingIdsJson)); mav.addObject("peerReviewIdsJson", StringEscapeUtils.escapeEcmaScript(peerReviewIdsJson)); mav.addObject("isProfileEmpty", isProfileEmtpy); String creditName = ""; if (profile.getOrcidBio() != null && profile.getOrcidBio().getPersonalDetails() != null) { PersonalDetails personalDetails = profile.getOrcidBio().getPersonalDetails(); if (personalDetails.getCreditName() != null && !PojoUtil.isEmpty(personalDetails.getCreditName().getContent())) creditName = profile.getOrcidBio().getPersonalDetails().getCreditName().getContent(); else { if (personalDetails.getGivenNames() != null && !PojoUtil.isEmpty(personalDetails.getGivenNames().getContent())) creditName += personalDetails.getGivenNames().getContent(); if (personalDetails.getFamilyName() != null && !PojoUtil.isEmpty(personalDetails.getFamilyName().getContent())) creditName += " " + personalDetails.getFamilyName().getContent(); } } if (!PojoUtil.isEmpty(creditName)) { // <Published Name> (<ORCID iD>) - ORCID | Connecting Research // and Researchers mav.addObject("title", getMessage("layout.public-layout.title", creditName.trim(), orcid)); } } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (!profile.isReviewed()) { if (isProfileValidForIndex(profile)) { if (profile.isLocked() || profile.getCountTokens() == 0 || (!CreationMethod.WEBSITE.equals(profile.getOrcidHistory().getCreationMethod()) && !CreationMethod.DIRECT.equals(profile.getOrcidHistory().getCreationMethod()))) { mav.addObject("noIndex", true); } } else { mav.addObject("noIndex", true); } } return mav; }
From source file:org.qifu.ui.UIComponentValueUtils.java
private static void putValue(Map<String, Object> params, String paramMapKey, Object val, boolean escapeHtml, boolean ecmaScript) { if (val == null) { return;//from www.ja va 2 s . c o m } if (val instanceof java.lang.String) { params.put(paramMapKey, String.valueOf(val)); if (ecmaScript) { params.put(paramMapKey, StringEscapeUtils.escapeEcmaScript((String) val)); } if (escapeHtml) { params.put(paramMapKey, StringEscapeUtils.escapeHtml4((String) val)); } if (ecmaScript && escapeHtml) { params.put(paramMapKey, StringEscapeUtils.escapeHtml4(StringEscapeUtils.escapeEcmaScript((String) val))); } return; } if (val instanceof java.lang.Integer) { params.put(paramMapKey, String.valueOf((Integer) val)); return; } if (val instanceof java.lang.Long) { params.put(paramMapKey, String.valueOf((Long) val)); return; } if (val instanceof java.math.BigDecimal) { params.put(paramMapKey, ((java.math.BigDecimal) val).toString()); return; } if (val instanceof java.math.BigInteger) { params.put(paramMapKey, ((java.math.BigInteger) val).toString()); return; } if (val instanceof java.lang.Float) { params.put(paramMapKey, String.valueOf((Float) val)); return; } if (val instanceof java.lang.Double) { params.put(paramMapKey, String.valueOf((Double) val)); return; } params.put(paramMapKey, String.valueOf(val)); }
From source file:org.rythmengine.utils.S.java
/** * Return a {@link org.rythmengine.utils.RawData} type wrapper of * an object with JavaScript escaping// www . ja va 2 s .c om * <p/> * <p>Object is {@link #toString(Object) converted to String} before escaping</p> * <p/> * <p>After the object get escaped, the output string is safe to put inside a pair of * JavaScript quotation marks</p> * * @param o * @return JavaScript escaped data */ @Transformer public static RawData escapeJavaScript(Object o) { if (null == o) return RawData.NULL; if (o instanceof RawData) return (RawData) o; return new RawData(StringEscapeUtils.escapeEcmaScript(o.toString())); }
From source file:org.silverpeas.attachment.tag.SimpleDocumentContextualMenu.java
String prepareActions(SimpleDocument attachment, boolean useXMLForm, boolean useWebDAV, String userId, String contentLanguage, final String userLanguage, ResourceLocator resources, String httpServerBase, boolean showMenuNotif, boolean useContextualMenu) throws UnsupportedEncodingException { String language = I18NHelper.checkLanguage(contentLanguage); String attachmentId = String.valueOf(attachment.getOldSilverpeasId()); boolean webDavOK = useWebDAV && attachment.isOpenOfficeCompatible(); StringBuilder builder = new StringBuilder(2048); builder.append("<div id=\"basicmenu").append(attachmentId).append("\" class=\"yuimenu\">").append(newline); builder.append("<div class=\"bd\">").append(newline); builder.append("<ul class=\"first-of-type\">").append(newline); prepareMenuItem(builder, "checkout('" + attachment.getId() + "'," + attachmentId + ',' + webDavOK + ");", resources.getString("checkOut")); prepareMenuItem(builder,// w w w . j av a 2 s . c o m "checkoutAndDownload('" + attachment.getId() + "'," + attachmentId + ',' + webDavOK + ");", resources.getString("attachment.checkOutAndDownload")); String checkoutAndEditLabel = resources.getString("attachment.checkOutAndEditOnline"); String webdavContentEditionLanguageLabel = ""; if (I18NHelper.isI18nActivated()) { webdavContentEditionLanguageLabel = I18NHelper.getLanguageLabel(StringUtil.defaultStringIfNotDefined( attachment.getWebdavContentEditionLanguage(), attachment.getLanguage()), userLanguage); checkoutAndEditLabel += " (" + webdavContentEditionLanguageLabel + ")"; } prepareMenuItem(builder, "checkoutAndEdit('" + attachment.getId() + "'," + attachmentId + ");", checkoutAndEditLabel); prepareMenuItem(builder, "checkin('" + attachment.getId() + "'," + attachmentId + "," + attachment.isOpenOfficeCompatible() + ", false, " + attachment.isVersioned() + ", '" + webdavContentEditionLanguageLabel + "');", resources.getString("checkIn")); builder.append("</ul>").append(newline); builder.append("<ul>").append(newline); prepareMenuItem(builder, "updateAttachment('" + attachment.getId() + "','" + language + "');", resources.getString("GML.modify")); prepareMenuItem(builder, "EditXmlForm('" + attachment.getId() + "','" + language + "');", resources.getString("attachment.xmlForm.Edit")); String message = resources.getString("attachment.switchState.toVersioned"); if (attachment.isVersioned()) { message = resources.getString("attachment.switchState.toSimple"); } prepareMenuItem(builder, "switchState('" + attachment.getId() + "', " + attachment.isVersioned() + ");", message); prepareMenuItem(builder, "deleteAttachment('" + attachment.getId() + "','" + StringEscapeUtils.escapeEcmaScript(attachment.getFilename()) + "');", resources.getString("GML.delete")); message = resources.getString("attachment.download.allowReaders"); boolean isDownloadAllowedForReaders = attachment.isDownloadAllowedForReaders(); if (isDownloadAllowedForReaders) { message = resources.getString("attachment.download.forbidReaders"); } prepareMenuItem(builder, "switchDownloadAllowedForReaders('" + attachment.getId() + "', " + !isDownloadAllowedForReaders + ");", message); builder.append("</ul>").append(newline); builder.append("<ul>").append(newline); prepareMenuItem(builder, "ShareAttachment('" + attachmentId + "');", resources.getString("GML.share.file")); builder.append("</ul>").append(newline); builder.append("<ul>").append(newline); prepareMenuItem(builder, "notifyAttachment('" + attachmentId + "');", resources.getString("GML.notify")); builder.append("</ul>").append(newline); builder.append("</div>").append(newline); builder.append("</div>").append(newline); builder.append("<script type=\"text/javascript\">"); String oMenuId = "oMenu" + attachmentId; builder.append("var ").append(oMenuId).append(";"); builder.append("var webDav").append(attachmentId).append(" = \""); builder.append(URLEncoder.encode(httpServerBase + attachment.getWebdavUrl(), CharEncoding.UTF_8)) .append("\";"); builder.append("YAHOO.util.Event.onContentReady(\"basicmenu").append(attachmentId) .append("\", function () {"); if (useContextualMenu) { builder.append(oMenuId).append(" = new YAHOO.widget.ContextMenu(\"basicmenu").append(attachmentId) .append("\""); builder.append(", { trigger: \"img_").append(attachmentId).append("\", "); } else { builder.append(oMenuId).append(" = new YAHOO.widget.Menu(\"basicmenu").append(attachmentId).append("\"") .append(", {"); } builder.append("hidedelay: 100, "); builder.append("effect: {effect: YAHOO.widget.ContainerEffect.FADE, duration: 0.30}});"); builder.append(oMenuId).append(".render();"); if (attachment.isReadOnly()) { configureCheckout(builder, attachmentId, true); builder.append(configureCheckoutAndDownload(attachmentId, !isWorker(userId, attachment))); builder.append(configureCheckoutAndEdit(attachmentId, !isEditable(userId, attachment, useWebDAV))); builder.append(configureCheckin(attachmentId, !isWorker(userId, attachment) && !isAdmin(userId))); builder.append(configureUpdate(attachmentId, !isWorker(userId, attachment))); builder.append(configureDelete(attachmentId, true)); builder.append(configureForbidDownloadForReaders(attachmentId, true)); if (!userId.equals(attachment.getEditedBy())) { builder.append(configureXmlForm(attachmentId, true)); } } else { builder.append(configureXmlForm(attachmentId, !useXMLForm)); builder.append(configureCheckin(attachmentId, true)); builder.append( configureCheckoutAndEdit(attachmentId, !useWebDAV || !attachment.isOpenOfficeCompatible())); } builder.append(configureFileSharing(attachmentId, !attachment.isSharingAllowedForRolesFrom(UserDetail.getById(userId)))); builder.append(configureSwitchState(attachmentId, attachment.isReadOnly())); builder.append(configureNotify(attachmentId, !showMenuNotif)); builder.append("YAHOO.util.Event.addListener(\"basicmenu").append(attachmentId); builder.append("\", \"mouseover\", oMenu").append(attachmentId).append(".show);"); builder.append("YAHOO.util.Event.addListener(\"basicmenu").append(attachmentId); builder.append("\", \"mouseout\", oMenu").append(attachmentId).append(".hide);"); if (!useContextualMenu) { builder.append("YAHOO.util.Event.on(\"edit_").append(attachmentId); builder.append("\", \"click\", function (event) {"); builder.append("var xy = YAHOO.util.Event.getXY(event);"); builder.append(oMenuId).append(".cfg.setProperty(\"x\", xy[0]);"); builder.append(oMenuId).append(".cfg.setProperty(\"y\", xy[1]+10);"); builder.append(oMenuId).append(".show();"); builder.append(" })"); } builder.append("});"); builder.append("</script>"); return builder.toString(); }
From source file:org.silverpeas.core.util.WebEncodeHelper.java
/** * Convert a java string to a javascript string Replace \,\n,\r and " * * @param javastring Java string to encode * @return javascript string encoded//from ww w .java 2s. co m */ public static String javaStringToJsString(String javastring) { if (!isDefined(javastring)) { return ""; } return StringEscapeUtils.escapeEcmaScript(javastring); }
From source file:org.silverpeas.core.web.attachment.tag.SimpleDocumentContextualMenu.java
String prepareActions(SimpleDocument attachment, boolean useXMLForm, boolean useWebDAV, UserDetail user, final String userLanguage, LocalizationBundle resources, boolean showMenuNotif) throws UnsupportedEncodingException { String userId = user.getId(); String attachmentId = String.valueOf(attachment.getOldSilverpeasId()); boolean webDavOK = useWebDAV && attachment.isOpenOfficeCompatible(); StringBuilder builder = new StringBuilder(HTML_BUFFER_CAPACITY); builder.append("<ul class=\"first-of-type\">").append(newline); prepareMenuItem(builder, "checkout('" + attachment.getId() + "'," + attachmentId + ',' + webDavOK + ");", resources.getString("checkOut")); prepareMenuItem(builder,/*from w ww. ja va 2 s . co m*/ "checkoutAndDownload('" + attachment.getId() + "'," + attachmentId + ',' + webDavOK + ");", resources.getString("attachment.checkOutAndDownload")); String checkoutAndEditLabel = resources.getString("attachment.checkOutAndEditOnline"); String webdavContentEditionLanguageLabel = ""; if (I18NHelper.isI18nContentEnabled()) { webdavContentEditionLanguageLabel = I18NHelper.getLanguageLabel(StringUtil.defaultStringIfNotDefined( attachment.getWebdavContentEditionLanguage(), attachment.getLanguage()), userLanguage); checkoutAndEditLabel += " (" + webdavContentEditionLanguageLabel + ")"; } prepareMenuItem(builder, "checkoutAndEdit('" + attachment.getId() + "'," + attachmentId + ",'" + StringUtil.defaultStringIfNotDefined(attachment.getWebdavContentEditionLanguage(), attachment.getLanguage()) + "');", checkoutAndEditLabel); prepareMenuItem(builder, "checkin('" + attachment.getId() + "'," + attachmentId + "," + attachment.isOpenOfficeCompatible() + ", false, " + attachment.isVersioned() + ", '" + webdavContentEditionLanguageLabel + "');", resources.getString("checkIn")); builder.append("</ul>").append(newline); builder.append("<ul>").append(newline); prepareMenuItem(builder, "updateAttachment('" + attachment.getId() + "','" + attachment.getLanguage() + "');", resources.getString("GML.modify")); prepareMenuItem(builder, "EditXmlForm('" + attachment.getId() + "','" + attachment.getLanguage() + "');", resources.getString("attachment.xmlForm.Edit")); String message = resources.getString("attachment.switchState.toVersioned"); if (attachment.isVersioned()) { message = resources.getString("attachment.switchState.toSimple"); } final boolean isLastPublicVersion = attachment.getLastPublicVersion() != null; prepareMenuItem(builder, "switchState('" + attachment.getId() + "', " + attachment.isVersioned() + ", " + isLastPublicVersion + ");", message); prepareMenuItem(builder, "deleteAttachment('" + attachment.getId() + "','" + StringEscapeUtils.escapeEcmaScript(attachment.getFilename()) + "');", resources.getString("GML.delete")); message = resources.getString("attachment.download.allowReaders"); boolean isDownloadAllowedForReaders = attachment.isDownloadAllowedForReaders(); if (isDownloadAllowedForReaders) { message = resources.getString("attachment.download.forbidReaders"); } prepareMenuItem(builder, "switchDownloadAllowedForReaders('" + attachment.getId() + "', " + !isDownloadAllowedForReaders + ");", message); if (isDisplayableAsContentForComponentInstanceId(attachment.getInstanceId())) { message = resources.getString("attachment.displayAsContent.enable"); boolean isDisplayAsContentEnabled = attachment.isDisplayableAsContent(); if (isDisplayAsContentEnabled) { message = resources.getString("attachment.displayAsContent.disable"); } prepareMenuItem(builder, "switchDisplayAsContentEnabled('" + attachment.getId() + "', " + !isDisplayAsContentEnabled + ");", message); } builder.append("</ul>").append(newline); builder.append("<ul>").append(newline); prepareMenuItem(builder, "ShareAttachment('" + attachmentId + "');", resources.getString("GML.share.file")); builder.append("</ul>").append(newline); builder.append("<ul>").append(newline); prepareMenuItem(builder, "notifyAttachment('" + attachmentId + "');", resources.getString("GML.notify")); builder.append("</ul>").append(newline); String menuItems = builder.toString(); builder = new StringBuilder(); if (attachment.isReadOnly()) { configureCheckout(builder, attachmentId, true); builder.append(configureCheckoutAndDownload(attachmentId, !isWorker(userId, attachment))); builder.append(configureCheckoutAndEdit(attachmentId, !isEditable(userId, attachment, useWebDAV))); builder.append(configureCheckin(attachmentId, !isWorker(userId, attachment) && !isAdmin(user))); builder.append(configureUpdate(attachmentId, !isWorker(userId, attachment))); builder.append(configureDelete(attachmentId, true)); builder.append(configureForbidDownloadForReaders(attachmentId, true)); if (!userId.equals(attachment.getEditedBy())) { builder.append(configureXmlForm(attachmentId, true)); } } else { builder.append(configureXmlForm(attachmentId, !useXMLForm)); builder.append(configureCheckin(attachmentId, true)); builder.append( configureCheckoutAndEdit(attachmentId, !useWebDAV || !attachment.isOpenOfficeCompatible())); } builder.append(configureFileSharing(attachmentId, !attachment.isSharingAllowedForRolesFrom(user))); builder.append(configureSwitchState(attachmentId, (!attachment.isVersioned() && isComponentPublicationAlwaysVisible(attachment.getInstanceId())) || attachment.isReadOnly())); builder.append(configureNotify(attachmentId, !showMenuNotif)); String itemsConfig = builder.toString(); return getMenu(attachmentId, menuItems, itemsConfig); }