List of usage examples for org.springframework.util StringUtils replace
public static String replace(String inString, String oldPattern, @Nullable String newPattern)
From source file:edu.mayo.cts2.framework.core.util.EncodingUtils.java
/** * Decode entity name./* ww w . ja v a2s. com*/ * * @param text the text * @return the scoped entity name */ public static ScopedEntityName decodeEntityName(String text) { ScopedEntityName scopedName = new ScopedEntityName(); String[] name = text.split(":"); if (name.length == 1) { name = new String[] { null, text }; } scopedName.setNamespace(StringUtils.replace(name[0], ESCAPE_CHAR, SCOPED_ENTITY_NAME_SEPERATOR)); scopedName.setName(StringUtils.replace(name[1], ESCAPE_CHAR, SCOPED_ENTITY_NAME_SEPERATOR)); return scopedName; }
From source file:org.jasig.portlets.FeedbackPortlet.service.EmailForwardingListener.java
public void performAction(FeedbackItem item) { // only forward on email with comments if (item.getFeedback() == null || item.getFeedback().equals("")) return;//from w w w . j a v a2 s .c o m SimpleMailMessage message = new SimpleMailMessage(mailMessage); // set the user's email address as the from and reply to if (item.getUseremail() != null && !item.getUseremail().equals("")) { message.setFrom(item.getUseremail()); message.setReplyTo(item.getUseremail()); } // construct the message text String text = message.getText(); if (item.getUsername() != null && !item.getUsername().equals("")) text = StringUtils.replace(text, "%USERNAME%", item.getUsername()); else text = StringUtils.replace(text, "%USERNAME%", "Anonymous"); if (item.getUserrole() != null && !item.getUserrole().equals("")) text = StringUtils.replace(text, "%USERROLE%", item.getUserrole()); else text = StringUtils.replace(text, "%USERROLE%", "unknown"); text = StringUtils.replace(text, "%USERAGENT%", item.getUseragent()); if (item.getTabname() != null && !item.getTabname().equals("")) text = StringUtils.replace(text, "%TABNAME%", item.getTabname()); else text = StringUtils.replace(text, "%TABNAME%", "none"); text = StringUtils.replace(text, "%FEEDBACKTYPE%", item.getFeedbacktype()); text = StringUtils.replace(text, "%FEEDBACK%", item.getFeedback()); message.setText(text); // send the message mailSender.send(message); }
From source file:fi.helsinki.opintoni.config.locale.AngularCookieLocaleResolver.java
private void parseLocaleCookieIfNecessary(HttpServletRequest request) { if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) { Locale locale = Optional.ofNullable(WebUtils.getCookie(request, getCookieName())).map(Cookie::getValue) .map(value -> StringUtils.replace(value, "%22", "")).map(StringUtils::parseLocaleString) .orElse(determineDefaultLocale(request)); request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME, locale); }/*from www . ja v a 2 s.c o m*/ }
From source file:cyrille.xml.xsd.XsomXsdParserSample.java
protected void dumpElementDeclration(XSElementDecl elementDeclaration, String indentation) { XSType type = elementDeclaration.getType(); String documentation = getDocumentation(elementDeclaration); // TODO DISABLE documentation = StringUtils.replace(documentation, "\n", "<br/>"); if (type.isComplexType()) { XSComplexType currentComplexType = type.asComplexType(); // ATTRIBUTES String valueType = null;//from w w w .j a va 2 s . com Boolean required = null; String defaultValue = null; XSAttributeUse valueAttributeUse = currentComplexType.getAttributeUse("", "value"); if (valueAttributeUse != null) { XSAttributeDecl valueAttributeDeclaration = valueAttributeUse.getDecl(); valueType = valueAttributeDeclaration.getType().getName(); required = valueAttributeUse.isRequired(); defaultValue = ObjectUtils.nullSafeToString(valueAttributeUse.getDefaultValue()); } System.out.println(indentation + "|| *{{{" + elementDeclaration.getName() + "}}}* || " + valueType + " || " + required + " || " + defaultValue + " || " + documentation + " ||"); XSContentType currentContentType = currentComplexType.getContentType(); XSParticle currentParticle = currentContentType.asParticle(); if (currentParticle == null) { System.out.println("skip "); } else { XSTerm term = currentParticle.getTerm(); if (term.isModelGroup()) { XSModelGroup modelGroup = term.asModelGroup(); for (XSParticle particle : modelGroup.getChildren()) { XSTerm particleTerm = particle.getTerm(); if (particleTerm.isElementDecl()) { // xs:element inside complex type dumpElementDeclration(particleTerm.asElementDecl(), indentation + " "); } } } } } else { System.out.println(indentation + elementDeclaration.getName() + " " + documentation); } }
From source file:com.cassius.spring.assembly.test.common.toolbox.LogFormatUtil.java
/** * Format string./*from w w w. j a va2 s.com*/ * * @param logs the logs * @return the string */ public static String format(List<String> logs) { String logSep = formatBegLine(); StringBuilder sb = new StringBuilder(logSep); for (String log : logs) { String LOG_LINE_BEG = RETURN + SYMBOL_2 + BLANK; if (log.length() < LINE_LENGTH - 2) { log = LOG_LINE_BEG + Strings.padEnd(log, LINE_LENGTH - 2, ' '); } else { String LOG_LINE_BREAK = "\n" + SYMBOL_3 + BLANK; log = LOG_LINE_BEG + StringUtils.replace(insertBreakLineSymbol(log, LINE_LENGTH - 2), "\n", LOG_LINE_BREAK); } sb.append(log); } sb.append(RETURN); return sb.toString(); }
From source file:org.obiba.mica.config.locale.AngularCookieLocaleResolver.java
private void parseLocaleCookieIfNecessary(HttpServletRequest request) { if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) { // Retrieve and parse cookie value. Cookie cookie = WebUtils.getCookie(request, getCookieName()); Locale locale = null;//w w w. jav a 2s .c o m TimeZone timeZone = null; if (cookie != null) { String value = cookie.getValue(); // Remove the double quote value = StringUtils.replace(value, "%22", ""); String localePart = value; String timeZonePart = null; int spaceIndex = localePart.indexOf(' '); if (spaceIndex != -1) { localePart = value.substring(0, spaceIndex); timeZonePart = value.substring(spaceIndex + 1); } locale = "-".equals(localePart) ? null : StringUtils.parseLocaleString(localePart); if (timeZonePart != null) { timeZone = StringUtils.parseTimeZoneString(timeZonePart); } if (logger.isTraceEnabled()) { logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale + "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : "")); } } request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME, locale == null ? determineDefaultLocale(request) : locale); request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME, timeZone == null ? determineDefaultTimeZone(request) : timeZone); } }
From source file:io.seldon.api.state.zk.ZkGlobalConfigHandler.java
@Override public void nodeChanged(String node, String value) { String genericNodeName = StringUtils.replace(node, PREFIX, ""); if (nodeListeners.get(genericNodeName).isEmpty()) { logger.warn("Couldn't find listener to tell about zk node change: " + node + " -> " + value); }/*from www . j ava2 s.co m*/ for (GlobalConfigUpdateListener list : nodeListeners.get(genericNodeName)) { list.configUpdated(genericNodeName, value); } }
From source file:io.github.jhipster.config.locale.AngularCookieLocaleResolver.java
private void parseLocaleCookieIfNecessary(HttpServletRequest request) { if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) { // Retrieve and parse cookie value. Cookie cookie = WebUtils.getCookie(request, getCookieName()); Locale locale = null;//from ww w . j a v a 2 s . com TimeZone timeZone = null; if (cookie != null) { String value = cookie.getValue(); // Remove the double quote value = StringUtils.replace(value, "%22", ""); String localePart = value; String timeZonePart = null; int spaceIndex = localePart.indexOf(' '); if (spaceIndex != -1) { localePart = value.substring(0, spaceIndex); timeZonePart = value.substring(spaceIndex + 1); } locale = !"-".equals(localePart) ? StringUtils.parseLocaleString(localePart.replace('-', '_')) : null; if (timeZonePart != null) { timeZone = StringUtils.parseTimeZoneString(timeZonePart); } if (logger.isTraceEnabled()) { logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale + "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : "")); } } request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME, locale != null ? locale : determineDefaultLocale(request)); request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME, timeZone != null ? timeZone : determineDefaultTimeZone(request)); } }
From source file:io.seldon.api.state.ZkSubscriptionHandler.java
public Map<String, String> getChildrenValues(String node) { logger.info("Getting children values for node " + node); Map<String, String> values = new HashMap<>(); Collection<ChildData> currentData = getChildren(node); for (ChildData data : currentData) { values.put(StringUtils.replace(data.getPath(), node + "/", ""), new String(data.getData())); }// www . j av a 2 s .c om return values; }
From source file:fr.xebia.springframework.security.core.userdetails.ExtendedUser.java
public void setAllowedRemoteAddresses(String allowedRemoteAddresses) { allowedRemoteAddresses = StringUtils.replace(allowedRemoteAddresses, ";", ","); String[] allowedRemoteAddressesAsArray = StringUtils .commaDelimitedListToStringArray(allowedRemoteAddresses); List<Pattern> newAllowedRemoteAddresses = new ArrayList<Pattern>(); for (String allowedRemoteAddress : allowedRemoteAddressesAsArray) { allowedRemoteAddress = StringUtils.trimWhitespace(allowedRemoteAddress); try {/* w ww . j a va 2s .c o m*/ newAllowedRemoteAddresses.add(Pattern.compile(allowedRemoteAddress)); } catch (PatternSyntaxException e) { throw new RuntimeException("Exception parsing allowedRemoteAddress '" + allowedRemoteAddress + "' for user '" + this.getUsername() + "'", e); } } this.allowedRemoteAddresses = newAllowedRemoteAddresses; }