antonio@apache.org wrote:
> Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/NetUtils.java
> @@ -231,27 +230,18 @@
> int dot = uri.lastIndexOf('.');
> if (dot > -1) {
> uri = uri.substring(dot);
> - int slash = uri.lastIndexOf('/');
> - if (slash > -1) {
> - return null;
> - } else {
> - int sharp = uri.lastIndexOf('#');
> - if (sharp > -1) {
> - // uri starts with dot already
> - return uri.substring(0, sharp);
> + if (StringUtils.containsNone(uri, "/")) {
> + final char [] chars = {'#', '?'};
> + int end = StringUtils.indexOfAny(uri, chars);
> + // uri starts with dot already
> + if (end > -1) {
> + return uri.substring(0, end);
> } else {
> - int mark = uri.lastIndexOf('?');
> - if (mark > -1) {
> - // uri starts with dot already
> - return uri.substring(0, mark);
> - } else {
> - return uri;
> - }
> + return uri;
> }
> }
> - } else {
> - return null;
> }
> + return null;
> }
You have changed the logic: it does not look for the last #, ? anymore, and #
has no precedence as it used to.
> @@ -304,19 +294,14 @@
> } else {
> // resource is not direct descendant
> int index = StringUtils.indexOfDifference(path, absoluteResource);
> - if (index > 0 && path.charAt(index-1) != '/') {
> - index = path.substring(0, index).lastIndexOf('/');
> + if (index > 0 && path.charAt(index - 1) != '/') {
> + index = StringUtils.lastIndexOf(path, '/', index);
> index++;
> }
> String pathDiff = path.substring(index);
> String resource = absoluteResource.substring(index);
> int levels = StringUtils.countMatches(pathDiff, "/");
> - StringBuffer b = new StringBuffer();
> - for (int i = 0; i < levels; i++) {
> - b.append("../");
> - }
> - b.append(resource);
> - return b.toString();
> + return StringUtils.repeat("../", levels) + resource;
> }
> }
>
StringBuffer version is more efficient: at least one less copying of data.
Vadim
|