Example usage for com.liferay.portal.kernel.util StringUtil startsWithWeight

List of usage examples for com.liferay.portal.kernel.util StringUtil startsWithWeight

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringUtil startsWithWeight.

Prototype

public static int startsWithWeight(String s1, String s2) 

Source Link

Document

Returns the number of starting characters that s1 and s2 have in common before their characters deviate.

Usage

From source file:com.liferay.tools.sourceformatter.JSPSourceProcessor.java

License:Open Source License

protected void addJSPReferenceFileNames(String fileName) {
    for (Map.Entry<String, String> entry : _jspContents.entrySet()) {
        String referenceFileName = entry.getKey();

        if (_includeFileNames.contains(referenceFileName)) {
            continue;
        }/*w  ww .  ja  v  a  2 s  .  c  om*/

        String sharedPath = fileName.substring(0, StringUtil.startsWithWeight(referenceFileName, fileName));

        if (Validator.isNull(sharedPath) || !sharedPath.contains(StringPool.SLASH)) {

            continue;
        }

        if (!sharedPath.endsWith(StringPool.SLASH)) {
            sharedPath = sharedPath.substring(0, sharedPath.lastIndexOf(CharPool.SLASH) + 1);
        }

        String content = null;

        for (int x = -1;;) {
            x = sharedPath.indexOf(CharPool.SLASH, x + 1);

            if (x == -1) {
                break;
            }

            if (content == null) {
                content = entry.getValue();
            }

            if (content.contains("<%@ include file=\"" + fileName.substring(x))) {

                _includeFileNames.add(referenceFileName);

                break;
            }
        }
    }
}