List of usage examples for org.apache.commons.lang3 StringUtils substringBeforeLast
public static String substringBeforeLast(final String str, final String separator)
Gets the substring before the last occurrence of a separator.
From source file:com.neatresults.mgnltweaks.ui.field.DialogIdSelectFieldFactory.java
@Override public List<SelectFieldOptionDefinition> getSelectFieldOptionDefinition() { List<SelectFieldOptionDefinition> fields = new ArrayList<SelectFieldOptionDefinition>(); try {/* w ww .j a v a2 s . c o m*/ DialogDefinitionRegistry ddr = Components.getComponent(DialogDefinitionRegistry.class); Field registryField = ddr.getClass().getDeclaredField("registry"); registryField.setAccessible(true); RegistryMap<String, DialogDefinitionProvider> registry = (RegistryMap<String, DialogDefinitionProvider>) registryField .get(ddr); for (String id : registry.keySet()) { SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); FormDialogDefinition dialogDef = registry.get(id).getDialogDefinition(); // directly defined label String label = dialogDef.getLabel(); if (label == null) { // new i18n maybe? String name = dialogDef.getId().indexOf("/") > 0 ? StringUtils.substringAfterLast(dialogDef.getId(), "/") : StringUtils.substringAfterLast(dialogDef.getId(), ":"); String key = StringUtils.substringBefore(dialogDef.getId(), ":") + "." + name + ".label"; label = i18n.translate(key); // old i18n maybe? if (key.equals(label)) { // no .level suffix maybe? label = i18n.translate(StringUtils.substringBeforeLast(key, ".")); if (StringUtils.substringBeforeLast(key, ".").equals(label)) { String oldFormLabel = dialogDef.getForm().getLabel(); if (StringUtils.isNotBlank(oldFormLabel)) { label = oldi18n.getMessages(dialogDef.getForm().getI18nBasename()) .get(oldFormLabel); } else { // some weird guessing label = oldi18n.getMessages(dialogDef.getForm().getI18nBasename()).get(key); if (label.startsWith("???")) { // one last try - pbly old not translated dialog, get label from first tab List<TabDefinition> tabs = dialogDef.getForm().getTabs(); if (tabs.size() > 0) { label = tabs.get(0).getLabel(); } } } } } } field.setLabel(id + " (" + label + ")"); field.setName(definition.getName()); field.setValue(id); fields.add(field); } } catch (SecurityException | IllegalArgumentException | IllegalAccessException | RegistrationException | NoSuchFieldException e) { log.error(e.getMessage(), e); SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); field.setName("It looks like an error has occured. Please contact admin or developers about it: " + e.getMessage()); field.setValue(e.getMessage()); fields.add(field); } return fields; }
From source file:com.neatresults.mgnltweaks.ui.field.NodeTypeSelectFieldFactory.java
@Override public List<SelectFieldOptionDefinition> getSelectFieldOptionDefinition() { List<SelectFieldOptionDefinition> fields = new ArrayList<SelectFieldOptionDefinition>(); try {//from ww w . j a v a 2s .c o m Field registryField = registry.getClass().getDeclaredField("registry"); registryField.setAccessible(true); RegistryMap<String, DialogDefinitionProvider> registryMap = (RegistryMap<String, DialogDefinitionProvider>) registryField .get(this.registry); for (String id : registryMap.keySet()) { SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); FormDialogDefinition dialogDef = registryMap.get(id).getDialogDefinition(); // directly defined label String label = dialogDef.getLabel(); if (label == null) { // new i18n maybe? String name = dialogDef.getId().indexOf("/") > 0 ? StringUtils.substringAfterLast(dialogDef.getId(), "/") : StringUtils.substringAfterLast(dialogDef.getId(), ":"); String key = StringUtils.substringBefore(dialogDef.getId(), ":") + "." + name + ".label"; label = i18n.translate(key); // old i18n maybe? if (key.equals(label)) { // no .level suffix maybe? label = i18n.translate(StringUtils.substringBeforeLast(key, ".")); if (StringUtils.substringBeforeLast(key, ".").equals(label)) { String oldFormLabel = dialogDef.getForm().getLabel(); if (StringUtils.isNotBlank(oldFormLabel)) { label = oldi18n.getMessages(dialogDef.getForm().getI18nBasename()) .get(oldFormLabel); } else { // some weird guessing label = oldi18n.getMessages(dialogDef.getForm().getI18nBasename()).get(key); if (label.startsWith("???")) { // one last try - pbly old not translated dialog, get label from first tab List<TabDefinition> tabs = dialogDef.getForm().getTabs(); if (tabs.size() > 0) { label = tabs.get(0).getLabel(); } } } } } } field.setLabel(id + " (" + label + ")"); field.setName(definition.getName()); field.setValue(id); fields.add(field); } } catch (SecurityException | IllegalArgumentException | IllegalAccessException | RegistrationException | NoSuchFieldException e) { log.error(e.getMessage(), e); SelectFieldOptionDefinition field = new SelectFieldOptionDefinition(); field.setName("It looks like an error has occured. Please contact admin or developers about it: " + e.getMessage()); field.setValue(e.getMessage()); fields.add(field); } return fields; }
From source file:com.quartercode.femtoweb.api.resolutions.View.java
@Override public Action execute(HttpServletRequest request, HttpServletResponse response, Context context) throws IOException, ServletException { // Generate the actual target path (depending on the invoked constructor, use the set path or combine the "directory" URI of the set action's URI with the set name) String actualPath;// w w w .j ava2 s .c o m if (path != null) { actualPath = path; } else { String dirUri = StringUtils.substringBeforeLast(context.getUri(dir), "/"); actualPath = dirUri + "/" + name; } // Add the path prefix to the directory containing dynamic content actualPath = context.getDynamicAssetPath() + "/" + StringUtils.stripStart(actualPath, "/"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Forwarding request to '{}' to '{}'", RequestUtils.getRequestUri(request), actualPath); } // Actually forward the request request.getRequestDispatcher(actualPath).forward(request, response); return null; }
From source file:com.netflix.spinnaker.clouddriver.ecs.services.EcsCloudMetricService.java
private Set<String> buildResourceList(List<String> metricAlarmArn, String serviceName) { return metricAlarmArn.stream().filter(arn -> arn.contains(serviceName)).map(arn -> { String resource = StringUtils.substringAfterLast(arn, ":resource/"); resource = StringUtils.substringBeforeLast(resource, ":policyName"); return resource; }).collect(Collectors.toSet()); }
From source file:com.neatresults.mgnltweaks.ui.contentapp.browser.QueryableJcrContainer.java
private String buildExtends(String path) { // one nasty bugger ... generate all possible combinations of extends for search // /a/b/c/d://from w w w. j a va2 s.c om // /d : /a/b/c // /c/d : /a/b // /b/c/d : /a // /a/b/c/d : -- String end = StringUtils.substringAfterLast(path, "/"); String limit = StringUtils.substringBeforeLast(path, "/" + end); // extends w/ absolute path or too deeply nested StringBuilder or = new StringBuilder(" or t.extends like '%" + path + "' "); // and all other possible relative extends while (StringUtils.isNotEmpty(limit)) { or.append(" or (t.extends like '%/" + end + "' and ISDESCENDANTNODE([" + limit + "]))"); end = StringUtils.substringAfterLast(limit, "/") + "/" + end; limit = StringUtils.substringBeforeLast(limit, "/"); } return or.toString(); }
From source file:keepinchecker.utility.EmailUtilities.java
protected static String getMailServer(String senderEmail) { String mailServer = ""; List<String> googleDomains = Arrays.asList("gmail", "googlemail"); List<String> microsoftDomains = Arrays.asList("hotmail", "outlook", "msn", "live", "passport"); List<String> yahooDomains = Arrays.asList("yahoo", "ymail"); List<String> aolDomains = Arrays.asList("aol", "aim"); List<String> comcastDomains = Arrays.asList("comcast"); List<String> verizonDomains = Arrays.asList("verizon"); List<String> attDomains = Arrays.asList("att"); // get the domain portion of the email String senderEmailDomain = StringUtils.substringAfter(senderEmail, "@"); // remove the TLD portion senderEmailDomain = StringUtils.substringBeforeLast(senderEmailDomain, "."); if (googleDomains.contains(senderEmailDomain)) { mailServer = GOOGLE_MAIL_SERVER; } else if (microsoftDomains.contains(senderEmailDomain)) { mailServer = MICROSOFT_MAIL_SERVER; } else if (yahooDomains.contains(senderEmailDomain)) { mailServer = YAHOO_MAIL_SERVER;//w w w.j a va2 s . c om } else if (aolDomains.contains(senderEmailDomain)) { mailServer = AOL_MAIL_SERVER; } else if (comcastDomains.contains(senderEmailDomain)) { mailServer = COMCAST_MAIL_SERVER; } else if (verizonDomains.contains(senderEmailDomain)) { mailServer = VERIZON_MAIL_SERVER; } else if (attDomains.contains(senderEmailDomain)) { mailServer = ATT_MAIL_SERVER; } return mailServer; }
From source file:kenh.xscript.elements.Call.java
@Override public int invoke() throws UnsupportedScriptException { logger.info(getInfo());/*from www . j a v a 2 s . c o m*/ this.getEnvironment().removeVariable(Return.VARIABLE_RETURN); // clear {return} // 1) find Method Map<String, Element> methods = this.getEnvironment().getMethods(); String name = getAttribute(ATTRIBUTE_METHOD_NAME); if (StringUtils.isBlank(name)) { UnsupportedScriptException ex = new UnsupportedScriptException(this, "The method name is empty."); throw ex; } try { name = (String) this.getEnvironment().parse(name); } catch (Exception e) { throw new UnsupportedScriptException(this, e); } String var = getAttribute(ATTRIBUTE_RETURN_NAME); if (StringUtils.isNotBlank(var)) { try { var = StringUtils.trimToNull((String) this.getEnvironment().parse(var)); } catch (Exception e) { throw new UnsupportedScriptException(this, e); } } Element e = methods.get(name); if (e == null || !(e instanceof Method)) { UnsupportedScriptException ex = new UnsupportedScriptException(this, "Could't find the method to invoke. [" + name + "]"); throw ex; } // 2) handle the Method's parameter Method m = (Method) e; String[][] parameters = m.getParameters(); Map<String, Object> new_vars = new LinkedHashMap(); List<String> new_cons = new LinkedList(); Vector parameterCallback = new Vector(); for (String[] parameter : parameters) { String paraName = StringUtils.trimToEmpty(parameter[0]); if (StringUtils.isBlank(paraName)) continue; boolean required = false; Object defaultValue = null; if (parameter.length > 1) { for (int i = 1; i < parameter.length; i++) { String modi = StringUtils.trimToEmpty(parameter[i]); if (modi.equals(Method.MODI_FINAL)) { new_cons.add(paraName); } if (modi.equals(Method.MODI_REQUIRED)) { required = true; } if ((modi.startsWith(Method.MODI_DEFAULT + "(") && modi.endsWith(")"))) { String defaultValue_ = StringUtils.substringAfter(modi, Method.MODI_DEFAULT + "("); defaultValue_ = StringUtils.substringBeforeLast(defaultValue_, ")"); try { defaultValue = this.getEnvironment().parse(defaultValue_); } catch (UnsupportedExpressionException e_) { UnsupportedScriptException ex = new UnsupportedScriptException(this, e_); throw ex; } } } } String paraValue = this.getAttribute(paraName); Object paraObj = null; if (paraValue == null) { if (required) { UnsupportedScriptException ex = new UnsupportedScriptException(this, "Missing parameter. [" + paraName + "]"); throw ex; } else { if (defaultValue != null) { new_vars.put(paraName, defaultValue); } } } else { try { paraObj = this.getEnvironment().parse(paraValue); new_vars.put(paraName, paraObj); if (paraObj instanceof kenh.expl.Callback) { parameterCallback.add(paraObj); } } catch (UnsupportedExpressionException ex) { throw new UnsupportedScriptException(this, ex); } } } if (this.getAttributes().size() > new_vars.size() + (this.getAttributes().containsKey(ATTRIBUTE_RETURN_NAME) ? 2 : 1)) { java.util.Set<String> keys = this.getAttributes().keySet(); String additional = ""; for (String key : keys) { if (key.equals(ATTRIBUTE_METHOD_NAME)) continue; if (key.equals(ATTRIBUTE_RETURN_NAME)) continue; if (new_vars.containsKey(key)) continue; additional = additional + key + ", "; } UnsupportedScriptException ex = new UnsupportedScriptException(this, "Unknown parameter. [" + StringUtils.substringBeforeLast(additional, ",") + "]"); throw ex; } // 3) remove non-public variable in Environment. save Method's parameter in Environment. List<String> publics = this.getEnvironment().getPublics(); List<String> constant = this.getEnvironment().getContants(); Map<String, Object> keep_vars = new LinkedHashMap(); List<String> keep_cons = new LinkedList(); List<String> keep_pubs = new LinkedList(); java.util.Set<String> keys = this.getEnvironment().getVariables().keySet(); for (String key : keys) { if (!publics.contains(key)) { keep_vars.put(key, this.getEnvironment().getVariable(key)); if (constant.contains(key)) keep_cons.add(key); } } keys = keep_vars.keySet(); for (String key : keys) { if (constant.contains(key)) constant.remove(key); this.getEnvironment().removeVariable(key, false); } // public variable in Environment have the same name with Method's parameter for (String[] parameter : parameters) { String key = StringUtils.trimToEmpty(parameter[0]); if (this.getEnvironment().containsVariable(key)) { if (constant.contains(key)) { constant.remove(key); keep_cons.add(key); } publics.remove(key); keep_pubs.add(key); keep_vars.put(key, this.getEnvironment().removeVariable(key, false)); } this.getEnvironment().setVariable(key, new_vars.get(key)); if (new_cons.contains(key)) constant.add(key); } // 4)invoke the Method's child elements. int r = m.processChildren(); if (r != RETURN && r != NONE) { if (r == EXCEPTION) { Object ex = this.getEnvironment().getVariable(Constant.VARIABLE_EXCEPTION); if (ex instanceof Exception) { if (ex instanceof UnsupportedScriptException) { throw (UnsupportedScriptException) ex; } else { UnsupportedScriptException ex_ = new UnsupportedScriptException(this, (Exception) ex); throw ex_; } } } UnsupportedScriptException ex = new UnsupportedScriptException(this, "Unsupported value is returned. [" + r + "]"); throw ex; } Object returnObj = null; if (StringUtils.isNotBlank(var)) { if (r == RETURN) { returnObj = this.getEnvironment().getVariable(Return.VARIABLE_RETURN); } else { UnsupportedScriptException ex = new UnsupportedScriptException(this, "The method does not have return value. [" + name + "]"); throw ex; } } // 5) remove non-public variable from Environment. restore original variables List<String> remove_vars = new LinkedList(); keys = this.getEnvironment().getVariables().keySet(); for (String key : keys) { if (!publics.contains(key)) { remove_vars.add(key); } } for (String key : remove_vars) { if (constant.contains(key)) constant.remove(key); Object obj = this.getEnvironment().getVariable(key); if (parameterCallback.contains(obj)) { this.getEnvironment().removeVariable(key, false); } else { this.getEnvironment().removeVariable(key); } } keys = keep_vars.keySet(); for (String key : keys) { if (!constant.contains(key)) { if (!this.getEnvironment().containsVariable(key)) this.getEnvironment().setVariable(key, keep_vars.get(key)); } if (keep_cons.contains(key)) constant.add(key); if (keep_pubs.contains(key)) publics.add(key); } // 6) store {return} if (returnObj != null) { this.saveVariable(var, returnObj, null); } return NONE; }
From source file:com.quartercode.femtoweb.impl.ActionUriResolver.java
private static String[] splitAtLastSeparator(String string, String separator) { if (!string.contains(separator)) { return new String[] { "", string }; } else {/*from w w w . ja va2 s .co m*/ return new String[] { StringUtils.substringBeforeLast(string, separator), StringUtils.substringAfterLast(string, separator) }; } }
From source file:com.zht.common.codegen.util.HiberStrUtil.java
public static void handlerProperty_Long$Integer$Short$Byte(GenEntityProperty prop) { StringBuffer hiberColumnStr = new StringBuffer(""); StringBuffer hiberValidateStr = new StringBuffer(""); String clumnname = prop.getColumnName(); Boolean nullAble = prop.getNullable(); Boolean unique = prop.getUnique(); //-------hiberValidateStr--------- Double min = prop.getMinValue(); Double max = prop.getMaxValue(); if (min != null) { hiberValidateStr.append("@javax.validation.constraints.Min(" + Math.round(min) + ") \r\t"); }// w w w .j a va 2 s . c o m if (max != null) { hiberValidateStr.append("@javax.validation.constraints.Max(" + Math.round(max) + ") \r\t"); } if (nullAble != null && nullAble == false) { hiberValidateStr.append("@javax.validation.constraints.NotNull \r\t"); } //-------hiberValidateStr--------- hiberColumnStr.append("name = \"" + clumnname + "\","); if (unique != null) { hiberColumnStr.append("unique = " + unique + ","); } if (nullAble != null) { hiberColumnStr.append("nullable = " + nullAble + ","); } String sd = hiberColumnStr.toString().trim(); if (sd.endsWith(",")) { sd = StringUtils.substringBeforeLast(sd, ","); } sd = "@javax.persistence.Column(" + sd + ")"; sd = hiberValidateStr + sd; prop.setGeneratedHibernateModelOfPropertyStr(sd); }
From source file:kenh.xscript.impl.BaseElement.java
@Override public void setAttribute(String name, String value) throws UnsupportedScriptException { if (StringUtils.isBlank(name)) throw new UnsupportedScriptException(this, "Attribute is empty."); if (attributes.containsKey(name)) throw new UnsupportedScriptException(this, "Reduplicate attribute. [" + name + "]"); attributes.put(name, value);/* w ww .ja va 2 s. c o m*/ readAttributeAnnotation(); // Check attributes, if current attributes combination is suit for process method's attribute group. for (String[] group : allAttributeAnnotation) { int i = 0; for (String key : group) { if (attributes.containsKey(key)) { i++; } } if (i == attributes.size()) return; } Set<String> keys = attributes.keySet(); String keyStr = ""; for (String key : keys) { keyStr = keyStr + key + ","; } keyStr = StringUtils.substringBeforeLast(keyStr, ","); throw new UnsupportedScriptException(this, "Do not support this attribute group. [" + keyStr + "]"); }