Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-44239 reduces classpath string by using relative paths. This fixes the issues with open office conversion and Websphere 8.5. #1942

Closed
wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Jun 11, 2014

No description provided.

…s the issues with open office conversion and Websphere 8.5.
@ghost ghost restored the dev branch June 11, 2014 14:53
@hhuijser
Copy link
Owner

Feels like we can simplify this a lot. Especially your logic in _calculateRelativePath can be done much easier using StringUtil.startsWithWeight?

@ghost
Copy link
Author

ghost commented Jun 12, 2014

I wouldn't say so. The equivalent code with StringUtil.startsWithWeight is:

    private static String _calculateRelativePath(
            String baseDir, String targetPath) {

        if (!baseDir.endsWith(File.separator)) {
            baseDir = baseDir.concat(File.separator);
        }

        int commonLength = StringUtil.startsWithWeight(baseDir, targetPath);

        if (commonLength <= 1) {
            return targetPath;
        }

        int index;

        if (commonLength < baseDir.length()) {
            index = baseDir.lastIndexOf(File.separatorChar, commonLength - 1);

            index++;
        }
        else {
            index = commonLength;
        }

        int dirsUp = 0;

        for (int i = commonLength; i < baseDir.length(); i++) {
            if (baseDir.charAt(i) == File.separatorChar) {
                dirsUp++;
            }
        }

        int targetLength = targetPath.length();

        StringBuilder relative = new StringBuilder(
            dirsUp * 3 + targetLength - commonLength + 1);

        for (int i = 0; i < dirsUp; i++) {
            relative.append("..").append(File.separatorChar);
        }

        if (commonLength < targetLength) {
            relative.append(targetPath.substring(index));
        }

        return relative.toString();
    }

Anyhow, if this is easier I will commit and push it back, just please let me know.

@hhuijser
Copy link
Owner

See email... sent to Jonathan McCann to look at this: jonathanmccann#301

@hhuijser hhuijser closed this Jun 16, 2014
@ghost ghost deleted the dev branch June 27, 2014 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants