Example usage for org.apache.commons.lang StringUtils substringAfter

List of usage examples for org.apache.commons.lang StringUtils substringAfter

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substringAfter.

Prototype

public static String substringAfter(String str, String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:com.bjwg.back.util.PropertyFilter.java

/**
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value//  w w  w . ja  v  a  2  s  .c om
 */
public PropertyFilter(final String filterName, final String value) {

    String firstPart = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
    String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());

    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(filterName, e);
    }

    try {
        propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(filterName, e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    AssertUtils.isTrue(StringUtils.isNotBlank(propertyNameStr), filterName);
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    this.matchValue = ObjectMapper.convertToObject(value, propertyClass);
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.xmi.importer.XmiHelper.java

/**
 * Returns the entity id out of the specified {@code eObject}. The id must have
 * the following pattern - {@code 'type_id'}. For example {@code 'Transport_330'}.
 * /*from   w w w .  j  a  v  a 2s  . c  om*/
 * @param eObject the eObject instance to get the id from
 * @return the id or {@code null}, if the id cannot be parsed
 */
public static Integer getEId(EObject eObject) {
    String eIdString = getEIdString(eObject);
    if (StringUtils.isEmpty(eIdString)) {
        return null;
    }

    try {
        if (eIdString.contains(ID_SEPARATOR)) {
            String numberValue = StringUtils.substringAfter(eIdString, ID_SEPARATOR);
            return Integer.valueOf(numberValue);
        }
        return Integer.valueOf(eIdString);
    } catch (NumberFormatException e) {
        LOGGER.error("Cannot resolve id: " + eIdString, e);
        return null;
    }
}

From source file:cec.easyshop.storefront.filters.CustomerLocationRestorationFilter.java

protected UserLocationData decipherUserLocationData(final String customerLocationString) {
    final UserLocationData userLocationData = new UserLocationData();
    final String searchTerm = StringUtils.substringBefore(customerLocationString,
            CustomerLocationCookieGenerator.LOCATION_SEPARATOR);
    final String latitudeAndLongitude = StringUtils.substringAfter(customerLocationString,
            CustomerLocationCookieGenerator.LOCATION_SEPARATOR);

    if (StringUtils.isNotEmpty(latitudeAndLongitude)) {
        final GeoPoint geoPoint = new GeoPoint();
        geoPoint.setLatitude(Double.parseDouble(StringUtils.substringBefore(latitudeAndLongitude,
                CustomerLocationCookieGenerator.LATITUDE_LONGITUDE_SEPARATOR)));
        geoPoint.setLongitude(Double.parseDouble(StringUtils.substringAfter(latitudeAndLongitude,
                CustomerLocationCookieGenerator.LATITUDE_LONGITUDE_SEPARATOR)));
        userLocationData.setPoint(geoPoint);
    }/*  w  w  w.j a va2 s .c  o  m*/

    userLocationData.setSearchTerm(searchTerm);
    return userLocationData;
}

From source file:com.ewcms.web.pubsub.PubsubServlet.java

private void initPathMapSender() {
    Enumeration<?> names = this.getInitParameterNames();
    for (; names.hasMoreElements();) {
        String path = (String) names.nextElement();
        if (path.equals(INITIALDELAY_PARAM_NAME) || path.equals(DELAY_PARAM_NAME)) {
            continue;
        }//from  w  w w  .  jav a  2  s. c  o m
        String className = this.getInitParameter(path);
        String pubSubPath = StringUtils.substringAfter(path, PUBSUB_CONTEXT);
        pathSender.put(pubSubPath, className);
    }
}

From source file:info.magnolia.rendering.template.configured.ConfiguredTemplateDefinition.java

public ConfiguredTemplateDefinition() {
    this.templateAvailability = new TemplateAvailability() {

        @Override/*from   w  w  w . j av  a  2  s. c om*/
        public boolean isAvailable(Node content, TemplateDefinition templateDefinition) {
            // by default a template is available only in the website workspace
            try {
                return content.getSession().getWorkspace().getName().equals("website")
                        && StringUtils.substringAfter(templateDefinition.getId(), ":").startsWith("pages/");
            } catch (RepositoryException e) {
                return false;
            }
        }
    };
}

From source file:com.manpowergroup.cn.core.orm.PropertyFilter.java

/**
 * @param filterName ,???. /* w w  w . j  a v  a 2  s .c o  m*/
 *                   eg LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final Object value) {

    String matchTypeStr = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1);
    String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1,
            matchTypeStr.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");

    this.propertyValue = value;
}

From source file:it.openutils.mgnlaws.magnolia.init.ClasspathMgnlServletContextListener.java

@Override
protected void startServer(ServletContext context) {
    if (!jaasConfigFileFromContainer
            && StringUtils.isNotEmpty(SystemProperty.getProperty(MGNL_JAAS_PROPERTYNAME))) {
        String jaasConfigFile = SystemProperty.getProperty(MGNL_JAAS_PROPERTYNAME);
        if (jaasConfigFile.startsWith(ClasspathPropertiesInitializer.CLASSPATH_PREFIX)) {
            jaasConfigFile = StringUtils.substringAfter(jaasConfigFile,
                    ClasspathPropertiesInitializer.CLASSPATH_PREFIX);
            InputStream jaasConfigFileInputStream = null;
            FileOutputStream jaasConfigFileTmpOutputStream = null;
            try {
                jaasConfigFileInputStream = ClasspathResourcesUtil.getStream(jaasConfigFile);
                if (jaasConfigFileInputStream != null) {
                    File jaasConfigFileTmp = File.createTempFile("jaas", ".config");
                    jaasConfigFileTmpOutputStream = new FileOutputStream(jaasConfigFileTmp);
                    IOUtils.copyLarge(jaasConfigFileInputStream, jaasConfigFileTmpOutputStream);
                    jaasConfigFile = jaasConfigFileTmp.getAbsolutePath();
                }//from w ww. j ava 2  s .  com
            } catch (IOException ex) {
                throw new RuntimeException("Cannot copy jaas config file to filesystem", ex);
            } finally {
                IOUtils.closeQuietly(jaasConfigFileInputStream);
                IOUtils.closeQuietly(jaasConfigFileTmpOutputStream);
            }
        } else {
            jaasConfigFile = Path.getAbsoluteFileSystemPath(jaasConfigFile);
        }
        System.setProperty(JAAS_PROPERTYNAME, jaasConfigFile);
    }
    super.startServer(context);
}

From source file:com.opengamma.component.ComponentConfigLoader.java

/**
 * Starts the components defined in the specified resource.
 * <p>// w  w  w . jav a 2  s.  c om
 * The specified properties are simple key=value pairs and must not be surrounded with ${}.
 * 
 * @param resource  the config resource to load, not null
 * @param properties  the default set of replacements, not null
 * @return the config, not null
 */
public ComponentConfig load(Resource resource, ConcurrentMap<String, String> properties) {
    Map<String, String> iniProperties = extractIniProperties(properties);
    properties = adjustProperties(properties);

    List<String> lines = readLines(resource);
    ComponentConfig config = new ComponentConfig();
    String group = "global";
    int lineNum = 0;
    for (String line : lines) {
        lineNum++;
        line = line.trim();
        if (line.length() == 0 || line.startsWith("#") || line.startsWith(";")) {
            continue;
        }
        if (line.startsWith("${") && line.substring(2).contains("=")
                && StringUtils.substringBefore(line, "=").trim().endsWith("}")) {
            parseReplacement(line, properties);

        } else {
            line = applyReplacements(line, properties);

            if (line.startsWith("[") && line.endsWith("]")) {
                group = line.substring(1, line.length() - 1);

            } else {
                String key = StringUtils.substringBefore(line, "=").trim();
                String value = StringUtils.substringAfter(line, "=").trim();
                if (key.length() == 0) {
                    throw new IllegalArgumentException("Invalid key, line " + lineNum);
                }
                config.add(group, key, value);
            }
        }
    }

    // override config with properties prefixed by INI
    for (Entry<String, String> entry : iniProperties.entrySet()) {
        String iniGroup = StringUtils.substringBefore(entry.getKey(), ".");
        String iniKey = StringUtils.substringAfter(entry.getKey(), ".");
        config.getGroup(iniGroup).put(iniKey, entry.getValue()); // throws exception if iniGroup not found
    }
    return config;
}

From source file:gov.guilin.controller.admin.StatisticsController.java

/**
 * /*  w w  w  .ja v a  2 s.c  o  m*/
 */
@RequestMapping(value = "/setting", method = RequestMethod.POST)
public String setting(@RequestParam(defaultValue = "false") Boolean isEnabled,
        RedirectAttributes redirectAttributes) {
    Setting setting = SettingUtils.get();
    if (isEnabled) {
        if (StringUtils.isEmpty(setting.getCnzzSiteId()) || StringUtils.isEmpty(setting.getCnzzPassword())) {
            try {
                String createAccountUrl = "http://intf.cnzz.com/user/companion/guilin.php?domain="
                        + setting.getSiteUrl() + "&key="
                        + DigestUtils.md5Hex(setting.getSiteUrl() + "Lfg4uP0H");
                URLConnection urlConnection = new URL(createAccountUrl).openConnection();
                BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
                String line = null;
                while ((line = in.readLine()) != null) {
                    if (line.contains("@")) {
                        break;
                    }
                }
                if (line != null) {
                    setting.setCnzzSiteId(StringUtils.substringBefore(line, "@"));
                    setting.setCnzzPassword(StringUtils.substringAfter(line, "@"));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    setting.setIsCnzzEnabled(isEnabled);
    SettingUtils.set(setting);
    cacheService.clear();
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:setting.jhtml";
}

From source file:jp.ac.tokushima_u.is.ll.common.orm.PropertyFilter.java

/**
 * @param filterName ,???. // ww  w  .j a  v  a 2 s.co  m
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final Object value) {

    String matchTypeStr = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1);
    String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1,
            matchTypeStr.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");
    //entity property.
    this.propertyValue = ReflectionUtils.convertValue(value, propertyType);
}