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

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

Introduction

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

Prototype

public static String substringBefore(String str, String separator) 

Source Link

Document

Gets the substring before the first occurrence of a separator.

Usage

From source file:info.magnolia.commands.CommandsManager.java

/**
 * Use a delimiter to separate the catalog and command name
 * @param commandName/*from   ww  w . j  a  v  a 2 s .co m*/
 * @return the command
 */
public Command getCommand(String commandName) {
    String catalogName = DEFAULT_CATALOG;
    if (StringUtils.contains(commandName, COMMAND_DELIM)) {
        catalogName = StringUtils.substringBefore(commandName, COMMAND_DELIM);
        commandName = StringUtils.substringAfter(commandName, COMMAND_DELIM);
    }

    Command command = getCommand(catalogName, commandName);
    if (command == null) {
        command = getCommand(DEFAULT_CATALOG, commandName);
    }
    return command;
}

From source file:info.magnolia.cms.module.ModuleUtil.java

/**
 * registers the properties in the repository
 * @param hm/*ww  w .  j av a  2 s . c  om*/
 * @param name
 * @throws IOException
 * @throws RepositoryException
 * @throws PathNotFoundException
 * @throws AccessDeniedException
 */
public static void registerProperties(HierarchyManager hm, String name)
        throws IOException, AccessDeniedException, PathNotFoundException, RepositoryException {
    Map map = new ListOrderedMap();

    // not using properties since they are not ordered
    // Properties props = new Properties();
    // props.load(ModuleUtil.class.getResourceAsStream("/" + name.replace('.', '/') + ".properties"));
    InputStream stream = ModuleUtil.class.getResourceAsStream("/" + name.replace('.', '/') + ".properties"); //$NON-NLS-1$ //$NON-NLS-2$
    LineNumberReader lines = new LineNumberReader(new InputStreamReader(stream));

    String line = lines.readLine();
    while (line != null) {
        line = line.trim();
        if (line.length() > 0 && !line.startsWith("#")) { //$NON-NLS-1$
            String key = StringUtils.substringBefore(line, "=").trim(); //$NON-NLS-1$
            String value = StringUtils.substringAfter(line, "=").trim(); //$NON-NLS-1$
            map.put(key, value);
        }
        line = lines.readLine();
    }
    IOUtils.closeQuietly(lines);
    IOUtils.closeQuietly(stream);
    registerProperties(hm, map);
}

From source file:mitm.djigzo.web.components.MultiSelectCertificateGrid.java

public void onCheckboxEvent() {
    String data = request.getParameter("data");

    if (StringUtils.isEmpty(data)) {
        throw new IllegalArgumentException("data is missing.");
    }//from   w ww . j a v  a 2  s  .com

    JSONObject json = new JSONObject(data);

    String element = json.getString("element");
    boolean checked = json.getBoolean("checked");

    /*
     * If the Grid is inside a Zone the Id is no longer just the thumbprint. Some :.* part
     * is added. We should therefore remove everything after :.* to get the thumbprint back 
     */
    element = StringUtils.substringBefore(element, ":");

    if (checked) {
        getSelected().add(element);
    } else {
        getSelected().remove(element);
    }
}

From source file:com.weixin.core.util.Struts2Utils.java

/**
 * ?contentTypeheaders.//w  w w  . j  av a2s  .  c o  m
 */
private static HttpServletResponse initResponseHeader(final String contentType, final String... headers) {
    // ?headers?
    String encoding = DEFAULT_ENCODING;
    boolean noCache = DEFAULT_NOCACHE;
    HttpServletResponse response = ServletActionContext.getResponse();
    for (String header : headers) {
        String headerName = StringUtils.substringBefore(header, ":");
        String headerValue = StringUtils.substringAfter(header, ":");

        if (StringUtils.equalsIgnoreCase(headerName, HEADER_ENCODING)) {
            encoding = headerValue;
        } else if (StringUtils.equalsIgnoreCase(headerName, HEADER_NOCACHE)) {
            noCache = Boolean.parseBoolean(headerValue);
        } else if (StringUtils.equalsIgnoreCase(headerName, "Cache-Control")
                || StringUtils.equalsIgnoreCase(headerName, "Pragma")) {
            response.setHeader(headerName, headerValue);
            noCache = false;
        } else {
            throw new IllegalArgumentException(headerName + "??header");
        }
    }

    // headers?
    String fullContentType = contentType + ";charset=" + encoding;
    response.setContentType(fullContentType);

    response.setHeader("Pragma:", "public");
    if (noCache) {
        ServletUtils.setDisableCacheHeader(response);
    }

    return response;
}

From source file:com.bsi.summer.core.dao.PropertyFilter.java

/**
 * @param filterName ,???. /* w  w w .j a  v  a2 s  . co  m*/
 *                      FILTER_LIKES_NAME_OR_LOGIN_NAME
 *                   
 *                value "SYS_" ??? 
 * 
 * @param value .
 */
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(
                "filter??" + filterName + ",.", e);
    }

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

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    Assert.isTrue(StringUtils.isNotBlank(propertyNameStr),
            "filter??" + filterName + ",??.");
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);
    if (StringUtils.split(value, "-").length == 1) {
        this.matchValue = getValue(value);
    } else {
        this.matchValue = getValue(StringUtils.split(value, "-")[0]);
        this.matchBetweenValue = getValue(StringUtils.split(value, "-")[1]);
    }
}

From source file:jetbrick.tools.chm.reader.JavaInfoReader.java

private void addClassFieldMethod(ClassInfo classinfo) throws IOException {
    File file = new File(Config.apiLocation, classinfo.getUrl());
    String html = FileUtils.readFileToString(file, Config.encoding);

    Pattern p = Config.style.getJavaFieldRegex();
    Matcher m = p.matcher(html);// w ww .j av a2s.  com

    while (m.find()) {
        String name = m.group(2);
        String url = m.group(1);

        url = StringUtils.remove(url, "../");
        url = StringUtils.remove(url, "./");

        String anchor = StringUtils.substringAfter(url, "#");
        String linkUrl = StringUtils.substringBefore(url, "#") + "#"
                + AnchorNameManager.getNewAnchorName(anchor);

        if (Config.style.isMethod(url)) {
            MethodInfo info = new MethodInfo();
            info.setName(name);
            info.setFullName(Config.style.getMethodFullName(url));
            info.setUrl(linkUrl);
            classinfo.addMethod(info);
        } else {
            FieldInfo info = new FieldInfo();
            info.setName(name);
            info.setUrl(linkUrl);
            classinfo.addField(info);
        }
    }
}

From source file:com.cognifide.actions.msg.websocket.client.SocketClient.java

private SocketClientRunnable createLoop(AgentConfig config) throws URISyntaxException {
    final String url = StringUtils.substringBefore(config.getTransportURI(), "/bin");
    final String username = config.getTransportUser();
    final String password = config.getTransportPassword();
    return new SocketClientRunnable(receivers, url, username, password);
}

From source file:eionet.cr.util.FolderUtil.java

/**
 * Extracts user name from the given URI. A user name is returned only if the given URI returns true for
 * {@link URIUtil#startsWithUserHome(String)}. Otherwise null is returned.
 *
 * @param uri The given URI./*from w w w .j a v  a 2s. co m*/
 * @return See method description.
 */
public static String extractUserName(String uri) {

    if (!startsWithUserHome(uri)) {
        return null;
    }

    String str = StringUtils.substringAfter(uri,
            GeneralConfig.getRequiredProperty(GeneralConfig.APPLICATION_HOME_URL) + "/home/");
    return StringUtils.substringBefore(str, "/");
}

From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.MemberLookupResolver.java

/**
 * The actual lookup// w ww  .jav  a 2  s  .c om
 *
 * @return set of all elements which match the lookup
 */
public Set<MemberLookupResult> performMemberLookup(String variable) {
    // if there is more than one "." we need to do some magic and resolve the definition fragmented
    if (variable.contains(".")) {
        return performNestedLookup(variable);
    }

    Set<MemberLookupResult> ret = new LinkedHashSet<>();
    // check, if the current variable resolves to a data-sly-use command
    ParsedStatement statement = getParsedStatement(variable);
    if (statement == null) {
        return ret;
    }
    if (StringUtils.equals(statement.getCommand(), DataSlyCommands.DATA_SLY_USE.getCommand())) {
        // this ends the search and we can perform the actual lookup
        ret.addAll(getResultsForClass(statement.getValue(), variable));
    } else {
        Set<MemberLookupResult> subResults = performMemberLookup(
                StringUtils.substringBefore(statement.getValue(), "."));
        for (MemberLookupResult result : subResults) {
            if (result.matches(StringUtils.substringAfter(statement.getValue(), "."))) {
                ret.addAll(getResultsForClass(result.getReturnType(), variable));
            }
        }
    }
    return ret;
}

From source file:net.poemerchant.scraper.ShopScraper.java

private String scrapeShopId() {
    this.shopId = StringUtils.substringAfterLast(url, "/");
    this.shopId = StringUtils.substringBefore(shopId, ".");
    return shopId;
}