use of org.apache.commons.lang3.StringUtils.capitalize in project polymap4-core by Polymap4.
the class ConstantRasterColorMapTypeEditor method createContents.
@Override
public Composite createContents(Composite parent) {
Composite contents = super.createContents(parent);
Combo combo = new Combo(contents, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
combo.setItems(Arrays.stream(RasterColorMapType.values()).map(type -> StringUtils.capitalize(type.toString().toLowerCase())).collect(Collectors.toList()).toArray(new String[0]));
prop.opt().ifPresent(constant -> {
combo.select(constant.type.get().ordinal());
});
combo.addSelectionListener(UIUtils.selectionListener(ev -> {
RasterColorMapType selected = Arrays.stream(RasterColorMapType.values()).filter(v -> v.ordinal() == combo.getSelectionIndex()).findAny().get();
prop.get().type.set(selected);
}));
return contents;
}
use of org.apache.commons.lang3.StringUtils.capitalize in project Saber-Bot by notem.
the class ParsingUtilities method parseMessageFormat.
/**
* @param format the base string to parse into a message
* @param entry the entry associated with the message
* @return a new message which has entry specific information inserted into the format string
*/
public static String parseMessageFormat(String format, ScheduleEntry entry, boolean displayComments) {
// determine time formatter from schedule settings
String clock = Main.getScheduleManager().getClockFormat(entry.getChannelId());
DateTimeFormatter timeFormatter;
if (clock.equalsIgnoreCase("12"))
timeFormatter = DateTimeFormatter.ofPattern("hh:mm a");
else
timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
// advanced parsing
/*
* parses the format string using regex grouping
* allows for an 'if element exists, print string + element + string' type of insertion
*/
Matcher matcher = Pattern.compile("%\\{(.*?)}").matcher(format);
while (matcher.find()) {
String group = matcher.group();
String trimmed = group.substring(2, group.length() - 1);
StringBuilder sub = new StringBuilder();
if (!trimmed.isEmpty()) {
Matcher matcher2 = Pattern.compile("\\[.*?]").matcher(trimmed);
if (// advanced comment
trimmed.matches("(\\[.*?])?c\\d+(\\[.*?])?") && displayComments) {
int i = Integer.parseInt(trimmed.replaceAll("(\\[.*?])?c|\\[.*?]", ""));
if (entry.getComments().size() >= i && i > 0) {
sub.append(messageFormatHelper(entry.getComments().get(i - 1), matcher2));
}
} else if (// advanced start
trimmed.matches("(\\[.*?])?s(\\[.*?])?")) {
if (!entry.hasStarted()) {
while (matcher2.find()) {
sub.append(matcher2.group().replaceAll("[\\[\\]]", ""));
}
}
} else if (// advanced end
trimmed.matches("(\\[.*?])?e(\\[.*?])?")) {
if (entry.hasStarted()) {
while (matcher2.find()) {
sub.append(matcher2.group().replaceAll("[\\[\\]]", ""));
}
}
} else if (// advanced end
trimmed.matches("(\\[.*?])?start .+(\\[.*?])?")) {
String formatter = trimmed.replaceAll("start ", "").replaceAll("^[GuyDMLdQqYwWEeCFahkKHmsSAnNVzOXxZp'\\[\\]#{}.,\\- ]", " ").replaceAll("\\[.*?]", "");
String startString = "";
try {
startString = entry.getStart().format(DateTimeFormatter.ofPattern(formatter));
} catch (Exception ignored) {
}
sub.append(startString);
} else if (// advanced end
trimmed.matches("(\\[.*?])?end .+(\\[.*?])?")) {
String formatter = trimmed.replaceAll("end ", "").replaceAll("^[GuyDMLdQqYwWEeCFahkKHmsSAnNVzOXxZp'\\[\\]#{}.,\\- ]", " ").replaceAll("\\[.*?]", "");
String endString = "";
try {
endString = entry.getEnd().format(DateTimeFormatter.ofPattern(formatter));
} catch (Exception ignored) {
}
sub.append(endString);
} else if (// advanced remind in minutes
trimmed.matches("(\\[.*?])?m(\\[.*?])?")) {
if (!entry.hasStarted()) {
long minutes = ZonedDateTime.now().until(entry.getStart(), ChronoUnit.MINUTES);
if (minutes > 0) {
sub.append(messageFormatHelper("" + (minutes + 1), matcher2));
}
} else {
long minutes = ZonedDateTime.now().until(entry.getEnd(), ChronoUnit.MINUTES);
if (minutes > 0) {
sub.append(messageFormatHelper("" + (minutes + 1), matcher2));
}
}
} else if (// advanced remind in hours
trimmed.matches("(\\[.*?])?h(\\[.*?])?")) {
if (!entry.hasStarted()) {
long minutes = ZonedDateTime.now().until(entry.getStart(), ChronoUnit.MINUTES);
if (minutes > 0) {
sub.append(messageFormatHelper("" + (minutes + 1) / 60, matcher2));
}
} else {
long minutes = ZonedDateTime.now().until(entry.getEnd(), ChronoUnit.MINUTES);
if (minutes > 0) {
sub.append(messageFormatHelper("" + (minutes + 1) / 60, matcher2));
}
}
} else if (// rsvp count
trimmed.matches("(\\[.*?])?rsvp .+(\\[.*?])?")) {
String name = trimmed.replaceAll("rsvp ", "").replaceAll("\\[.*?]", "");
List<String> members = entry.getRsvpMembers().get(name);
if (members != null) {
sub.append(messageFormatHelper("" + members.size(), matcher2));
}
} else if (// rsvp mentions
trimmed.matches("(\\[.*?])?mention .+(\\[.*?])?")) {
String name = trimmed.replaceAll("mention ", "").replaceAll("\\[.*?]", "");
List<String> users = compileUserList(entry, name);
if (// a valid mention option was used
users != null) {
StringBuilder userMentions = new StringBuilder();
for (int i = 0; i < users.size(); i++) {
if (users.get(i).matches("\\d+"))
userMentions.append("<@").append(users.get(i)).append(">");
if (i + 1 < users.size())
userMentions.append(", ");
}
sub.append(messageFormatHelper(userMentions.toString(), matcher2));
}
} else if (trimmed.matches("(\\[.*?])?mentionm .+(\\[.*?])?") || // rsvp mentions
trimmed.matches("(\\[.*?])?list .+(\\[.*?])?")) {
String name = trimmed.replace("mentionm ", "").replace("list", "").replaceAll("\\[.*?]", "");
List<String> users = compileUserList(entry, name);
if (users != null) {
StringBuilder userMentions = new StringBuilder();
for (int i = 0; i < users.size(); i++) {
if (users.get(i).matches("\\d+")) {
Member member = Main.getShardManager().getJDA(entry.getGuildId()).getGuildById(entry.getGuildId()).getMemberById(users.get(i));
userMentions.append(member.getEffectiveName());
}
if (i + 1 < users.size())
userMentions.append(", ");
}
sub.append(messageFormatHelper(userMentions.toString(), matcher2));
}
} else if (// advanced title url
trimmed.matches("(\\[.*?])?u(\\[.*?])?")) {
if (entry.getTitleUrl() != null) {
sub.append(messageFormatHelper(entry.getTitleUrl(), matcher2));
}
} else if (// advanced image url
trimmed.matches("(\\[.*?])?v(\\[.*?])?")) {
if (entry.getImageUrl() != null) {
sub.append(messageFormatHelper(entry.getImageUrl(), matcher2));
}
} else if (// advanced thumbnail url
trimmed.matches("(\\[.*?])?w(\\[.*?])?")) {
if (entry.getThumbnailUrl() != null) {
sub.append(messageFormatHelper(entry.getThumbnailUrl(), matcher2));
}
}
}
format = format.replace(group, sub.toString());
}
// legacy parsing
/*
* parses the format string character by character looking for % characters
* a token is one % character followed by a key character
*/
StringBuilder announceMsg = new StringBuilder();
for (int i = 0; i < format.length(); i++) {
char ch = format.charAt(i);
if (ch == '%' && i + 1 < format.length()) {
i++;
ch = format.charAt(i);
switch(ch) {
case 'c':
if (i + 1 < format.length() && displayComments) {
ch = format.charAt(i + 1);
if (Character.isDigit(ch)) {
i++;
int x = Integer.parseInt("" + ch);
if (entry.getComments().size() >= x && x != 0) {
String parsedComment = ParsingUtilities.parseMessageFormat(entry.getComments().get(x - 1), entry, false);
announceMsg.append(parsedComment);
}
}
}
break;
case 'f':
if (displayComments) {
// if this call of the parser is nested, don't insert comments
announceMsg.append(String.join("\n", entry.getComments().stream().map(comment -> ParsingUtilities.parseMessageFormat(comment, entry, false)).collect(Collectors.toList())));
}
break;
case 'a':
if (!entry.hasStarted()) {
announceMsg.append("begins");
long minutes = ZonedDateTime.now().until(entry.getStart(), ChronoUnit.MINUTES);
if (minutes > 0) {
if (minutes > 120)
announceMsg.append(" in ").append((minutes + 1) / 60).append(" hours");
else
announceMsg.append(" in ").append(minutes + 1).append(" minutes");
}
} else {
announceMsg.append("ends");
long minutes = ZonedDateTime.now().until(entry.getEnd(), ChronoUnit.MINUTES);
if (minutes > 0) {
if (minutes > 120)
announceMsg.append(" in ").append((minutes + 1) / 60).append(" hours");
else
announceMsg.append(" in ").append(minutes + 1).append(" minutes");
}
}
break;
case 'b':
if (!entry.hasStarted())
announceMsg.append("begins");
else
announceMsg.append("ends");
break;
case 'x':
if (!entry.hasStarted()) {
long minutes = ZonedDateTime.now().until(entry.getStart(), ChronoUnit.MINUTES);
if (minutes > 0) {
if (minutes > 120)
announceMsg.append(" in ").append((minutes + 1) / 60).append(" hours");
else
announceMsg.append(" in ").append(minutes + 1).append(" minutes");
}
} else {
long minutes = ZonedDateTime.now().until(entry.getEnd(), ChronoUnit.MINUTES);
if (minutes > 0) {
if (minutes > 120)
announceMsg.append(" in ").append((minutes + 1) / 60).append(" hours");
else
announceMsg.append(" in ").append(minutes + 1).append(" minutes");
}
}
break;
case 's':
announceMsg.append(entry.getStart().format(timeFormatter));
break;
case 'e':
announceMsg.append(entry.getEnd().format(timeFormatter));
break;
case 't':
announceMsg.append(entry.getTitle());
break;
case 'd':
announceMsg.append(String.format("%02d", entry.getStart().getDayOfMonth()));
break;
case 'D':
announceMsg.append(StringUtils.capitalize(entry.getStart().getDayOfWeek().toString()));
break;
case 'm':
announceMsg.append(String.format("%02d", entry.getStart().getMonthValue()));
break;
case 'M':
announceMsg.append(StringUtils.capitalize(entry.getStart().getMonth().toString()));
break;
case 'y':
announceMsg.append(entry.getStart().getYear());
break;
case 'i':
announceMsg.append(ParsingUtilities.intToEncodedID(entry.getId()));
break;
case '%':
announceMsg.append('%');
break;
case 'u':
announceMsg.append(entry.getTitleUrl() == null ? "" : entry.getTitleUrl());
break;
case 'v':
announceMsg.append(entry.getImageUrl() == null ? "" : entry.getImageUrl());
break;
case 'w':
announceMsg.append(entry.getThumbnailUrl() == null ? "" : entry.getThumbnailUrl());
break;
case 'n':
announceMsg.append("\n");
break;
case 'h':
announceMsg.append(String.format("%02d", entry.getStart().getHour()));
break;
case 'k':
announceMsg.append(String.format("%02d", entry.getStart().getMinute()));
break;
case 'l':
announceMsg.append(entry.getLocation());
break;
}
} else {
announceMsg.append(ch);
}
}
return announceMsg.toString();
}
use of org.apache.commons.lang3.StringUtils.capitalize in project RFToolsControl by McJty.
the class GuiProgrammer method createValuePanel.
private Panel createValuePanel(ParameterDescription parameter, IIcon icon, IconHolder iconHolder, String tempDefault, boolean constantOnly) {
Label<?> label = (Label<?>) new Label(mc, this).setText(StringUtils.capitalize(parameter.getName()) + ":").setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT).setDesiredHeight(13).setLayoutHint(new PositionalLayout.PositionalHint(0, 0, 53, 13));
List<String> description = new ArrayList<>(parameter.getDescription());
if (parameter.isOptional()) {
description.set(description.size() - 1, description.get(description.size() - 1) + TextFormatting.GOLD + " [Optional]");
}
if (tempDefault != null && !tempDefault.isEmpty()) {
description.add(TextFormatting.BLUE + tempDefault);
}
String[] tooltips = description.toArray(new String[description.size()]);
TextField field = new TextField(mc, this).setText(tempDefault).setTooltips(tooltips).setDesiredHeight(13).setEditable(false).setLayoutHint(new PositionalLayout.PositionalHint(0, 12, 68, 13));
Button button = new Button(mc, this).setText("...").setDesiredHeight(13).setTooltips(tooltips).addButtonEvent(w -> openValueEditor(icon, iconHolder, parameter, field, constantOnly)).setLayoutHint(new PositionalLayout.PositionalHint(58, 0, 11, 13));
return new Panel(mc, this).setLayout(new PositionalLayout()).addChild(label).addChild(field).addChild(button).setDesiredWidth(68);
}
use of org.apache.commons.lang3.StringUtils.capitalize in project cas by apereo.
the class InitialFlowSetupAction method configureWebflowContext.
/**
* Configure the webflow.
*
* @param context the webflow context
*/
protected void configureWebflowContext(final RequestContext context) {
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(context);
WebUtils.putWarningCookie(context, Boolean.valueOf(this.warnCookieGenerator.retrieveCookieValue(request)));
WebUtils.putGeoLocationTrackingIntoFlowScope(context, casProperties.getEvents().getCore().isTrackGeolocation());
WebUtils.putRememberMeAuthenticationEnabled(context, casProperties.getTicket().getTgt().getRememberMe().isEnabled());
val staticAuthEnabled = (casProperties.getAuthn().getAccept().isEnabled() && StringUtils.isNotBlank(casProperties.getAuthn().getAccept().getUsers())) || StringUtils.isNotBlank(casProperties.getAuthn().getReject().getUsers());
WebUtils.putStaticAuthenticationIntoFlowScope(context, staticAuthEnabled);
if (casProperties.getAuthn().getPolicy().isSourceSelectionEnabled()) {
val availableHandlers = authenticationEventExecutionPlan.getAuthenticationHandlers().stream().filter(h -> h.supports(UsernamePasswordCredential.class)).map(h -> StringUtils.capitalize(h.getName().trim())).distinct().sorted().collect(Collectors.toList());
WebUtils.putAvailableAuthenticationHandleNames(context, availableHandlers);
}
}
Aggregations