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

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

Introduction

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

Prototype

public static String substringAfter(final String str, final String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:io.wcm.devops.conga.resource.ResourceLoader.java

/**
 * Removes resource type prefix if a prefix is given.
 * @param path Path//from w  w  w.j a  v a2s  . c o m
 * @return Path without prefix
 */
private static String removePrefix(String path) {
    for (ResourceType resourceType : ResourceType.values()) {
        if (StringUtils.startsWith(path, resourceType.getPrefix())) {
            return StringUtils.substringAfter(path, resourceType.getPrefix());
        }
    }
    return path;
}

From source file:io.wcm.config.core.override.impl.RequestHeaderOverrideProvider.java

private Map<String, String> buildMapFromHeaders(SlingHttpServletRequest request) {
    Map<String, String> map = new HashMap<>();
    Enumeration keys = request.getHeaderNames();
    while (keys.hasMoreElements()) {
        Object keyObject = keys.nextElement();
        if (keyObject instanceof String) {
            String key = (String) keyObject;
            if (StringUtils.startsWith(key, REQUEST_HEADER_PREFIX)) {
                map.put(StringUtils.substringAfter(key, REQUEST_HEADER_PREFIX), request.getHeader(key));
            }/*w w  w. j  a  v  a2s  .co  m*/
        }
    }
    return map;
}

From source file:com.norconex.commons.lang.url.QueryString.java

/**
 * Constructor.  /*  w w  w.  j av a2  s  .co m*/
 * It is possible to only supply a query string as opposed to an
 * entire URL.
 * Key and values making up a query string are assumed to be URL-encoded.
 * Will throw a {@link URLException} if the supplied encoding is 
 * unsupported or invalid.
 * @param urlWithQueryString a URL from which to extract a query string.
 * @param encoding character encoding
 */
public QueryString(String urlWithQueryString, String encoding) {
    super(new ListOrderedMap<String, List<String>>());
    if (StringUtils.isBlank(encoding)) {
        this.encoding = CharEncoding.UTF_8;
    } else {
        this.encoding = encoding;
    }
    String paramString = urlWithQueryString;
    if (StringUtils.contains(paramString, "?")) {
        paramString = paramString.replaceAll("(.*?)(\\?)(.*)", "$3");
    }
    String[] paramParts = paramString.split("\\&");
    for (int i = 0; i < paramParts.length; i++) {
        String paramPart = paramParts[i];
        if (StringUtils.contains(paramPart, "=")) {
            String key = StringUtils.substringBefore(paramPart, "=");
            String value = StringUtils.substringAfter(paramPart, "=");
            try {
                addString(URLDecoder.decode(key, this.encoding), URLDecoder.decode(value, this.encoding));
            } catch (UnsupportedEncodingException e) {
                throw new URLException("Cannot URL-decode query string (key=" + key + "; value=" + value + ").",
                        e);
            }
        }
    }
}

From source file:de.blizzy.documentr.markdown.HtmlSerializer.java

@Override
protected void printImageTag(SuperNode imageNode, String url) {
    String params = StringUtils.EMPTY;
    if (url.contains("|")) { //$NON-NLS-1$
        params = StringUtils.substringAfter(url, "|").trim(); //$NON-NLS-1$
        url = StringUtils.substringBefore(url, "|").trim(); //$NON-NLS-1$
    }/*from w  ww  .jav  a2 s .  com*/

    boolean thumbnail = params.contains(IMAGE_PARAM_THUMB);
    String altText = printChildrenToString(imageNode);
    String title = null;
    if (imageNode instanceof ExpImageNode) {
        title = StringUtils.defaultIfBlank(((ExpImageNode) imageNode).title, altText);
    }

    if (thumbnail) {
        printer.print("<ul class=\"thumbnails\"><li class=\"span3\"><a class=\"thumbnail\" href=\"") //$NON-NLS-1$
                .print(context.getAttachmentUri(url)).print("\">"); //$NON-NLS-1$
    }

    printer.print("<img src=\"").print(context.getAttachmentUri(url)).print("\""); //$NON-NLS-1$ //$NON-NLS-2$
    if (StringUtils.isNotBlank(altText)) {
        printer.print(" alt=\"").printEncoded(altText).print("\""); //$NON-NLS-1$ //$NON-NLS-2$
    }
    if (thumbnail) {
        printer.print(" data-lightbox=\"lightbox\" width=\"260\""); //$NON-NLS-1$
    }
    if (StringUtils.isNotBlank(title)) {
        printer.print(" rel=\"tooltip\" data-title=\"").printEncoded(title).print("\""); //$NON-NLS-1$ //$NON-NLS-2$
    }
    printer.print("/>"); //$NON-NLS-1$

    if (thumbnail) {
        printer.print("</a></li></ul>"); //$NON-NLS-1$
    }
}

From source file:cool.pandora.modeller.DocManifestBuilder.java

/**
 * getBboxForId./*from  w  w  w  .  j  a  v a  2 s  .  c om*/
 *
 * @param hocr hOCRData
 * @param id   String
 * @return TitleForId
 */
public static String getBboxForId(final hOCRData hocr, final String id) {
    return StringUtils.substringBefore(StringUtils.substringAfter(hocr.getTitleForId(id), "bbox "), ";");
}

From source file:kenh.expl.Environment.java

/**
 * Load function packages through system properties
 *//*from   w  w  w .j  a  v a2 s.c  om*/
private void loadFunctionPackages_SystemProperties() {
    Properties p = System.getProperties();
    Set keys = p.keySet();
    for (Object key_ : keys) {
        if (key_ instanceof String) {
            String key = (String) key_;
            if (StringUtils.startsWith(key, FUNCTION_PATH_PREFIX + ".")) {
                String name = StringUtils.substringAfter(key, FUNCTION_PATH_PREFIX + ".");
                String funcPackage = p.getProperty(key);
                setFunctionPackage(name, funcPackage);
            }
        }
    }
}

From source file:com.zhumeng.dream.orm.PropertyFilter.java

/**
 * @param filterName ,???. eg.//w w w. j ava 2  s . co  m
 *            LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final String value) {
    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    init(filterName, value, propertyNameStr);
    if (propertyClass == Enum.class) {
        for (Class<?> clazz : enumObjects) {
            if (propertyNameStr.equalsIgnoreCase(clazz.getSimpleName())) {
                Class<Enum> enumObjet = (Class<Enum>) clazz;

                // add by wucong
                String[] values = StringUtils.split(value, "_");
                if (!StringUtils.contains(value, "_"))
                    this.matchValue = Enum.valueOf(enumObjet, value);
                else
                    this.matchValue = Enum.valueOf(enumObjet, values[0]);// ?
                if (values != null) {
                    matchValues = new Object[values.length];
                    for (int i = 0; i < values.length; i++) {
                        matchValues[i] = Enum.valueOf(enumObjet, values[i]);
                    }
                    if (values.length == 0) {
                        matchValues = new Object[1];
                        matchValues[0] = this.matchValue;
                    }
                }
                break;
            }
        }
    } else {
        /*
         * if(!StringUtils.contains(value, "_")) this.matchValue =
         * ConvertUtils.convertStringToObject(value, propertyClass);
         */

        // add by wucong
        String[] values = null;
        //???"_"
        if (filterName.lastIndexOf("unionId") > 0 || filterName.lastIndexOf("openId") > 0
                || (!StringUtils.contains(value, "_")))//???"_"
            values = new String[] { value };

        else
            values = StringUtils.split(value, "_");
        if ((!StringUtils.contains(value, "_") || filterName.lastIndexOf("unionId") > 0)
                || (!StringUtils.contains(value, "_") && filterName.lastIndexOf("openId") > 0))//???"_"
            this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass);
        else
            this.matchValue = ConvertUtils.convertStringToObject(values[0], propertyClass);// ?
        if (values != null) {
            matchValues = new Object[values.length];
            for (int i = 0; i < values.length; i++) {
                matchValues[i] = ConvertUtils.convertStringToObject(values[i], propertyClass);
            }
            if (values.length == 0) {
                matchValues = new Object[1];
                matchValues[0] = this.matchValue;
            }
        }
    }

}

From source file:com.nesscomputing.service.discovery.server.announce.ConfigStaticAnnouncer.java

private Map<UUID, Map<String, String>> getAnnouncements() {
    final AbstractConfiguration subconfig = config.getConfiguration(CONFIG_ROOT);

    final Iterator<String> keys = subconfig.getKeys();

    final Map<UUID, Map<String, String>> configTree = Maps.newHashMap();

    while (keys.hasNext()) {
        final String key = keys.next();

        final String id = StringUtils.substringBefore(key, ".");

        UUID serviceId;//from  w  ww.ja  va 2  s  .  c  o  m

        try {
            serviceId = UUID.fromString(id);
        } catch (final IllegalArgumentException e) {
            throw new IllegalArgumentException(String.format("Invalid serviceId \"%s\"", id), e);
        }

        Map<String, String> configMap = configTree.get(serviceId);
        if (configMap == null) {
            configTree.put(serviceId, configMap = Maps.newHashMap());
        }

        configMap.put(StringUtils.substringAfter(key, "."), subconfig.getString(key));
    }
    return configTree;
}

From source file:com.cognifide.aet.rest.LockServlet.java

private String getKey(HttpServletRequest req) {
    return StringUtils.substringAfter(req.getRequestURI(), Helper.getLocksPath()).replace(Helper.PATH_SEPARATOR,
            "");
}

From source file:com.brianscottrussell.gameoflife.GameGrid.java

/**
 * Constructor which builds a GameGrid object from the given String
 *
 * if there is an invalid header format then this will initialize the grid as 0x0, empty grid
 * if there is an invalid body format then this will initialize the grid as the header size, all Dead cells
 *
 * @param gridAsString String//  ww w .j av a 2  s  .  co  m
 */
public GameGrid(String gridAsString) {
    // initialize empty grid
    initializeGrid(0, 0);

    if (StringUtils.isNotBlank(gridAsString)) {
        // default the row & col counts to 0
        int rowCount = 0;
        int colCount = 0;

        // get row/col counts from input
        try {
            rowCount = parseRowCountFromInputString(gridAsString);
        } catch (InvalidGameGridInputException e) {
            // TODO: handle error?
            // System.out.println(e.getClass().getSimpleName() + ": " + e.getMessage());
        }
        try {
            // get the character(s), before the 1st carriage return as the rowCount
            colCount = parseColumnCountFromInputString(gridAsString);
        } catch (InvalidGameGridInputException e) {
            // TODO: handle error?
            // System.out.println(e.getClass().getSimpleName() + ": " + e.getMessage());
        }

        // only need to move forward if we retrieved valid row & col counts
        if (rowCount > 0 && colCount > 0) {
            // initialize grid
            initializeGrid(rowCount, colCount);

            // split the input string so that we're getting all lines of the string as rows, after the first line.
            //   this is the input Grid that will give us the starting point of each cell as Alive or Dead
            String[] gridRows = StringUtils.split(StringUtils.substringAfter(gridAsString, GameOfLife.LF),
                    GameOfLife.LF);
            // iterate over the rows of the grid
            // todo: improve from O(n^2)
            int rowIndex = 0;
            for (String row : gridRows) {
                // iterate over the chars of the row String
                int colIndex = 0;
                for (char symbol : row.toCharArray()) {
                    // check if a valid CellStatus symbol, otherwise skip it.
                    if (CellStatus.isValidCellStatusSymbol(symbol)) {
                        // if the cell is "alive", make it Alive in the CellStatus grid
                        this.grid[rowIndex][colIndex] = CellStatus.getCellStatusBySymbol(symbol);
                        colIndex++;
                    }
                }
                rowIndex++;
            }
        }
    }

    // start the generation at 1
    this.generation = 1;
}