ResourcePath.java

  1. /*
  2.  * #%L
  3.  * wcm.io
  4.  * %%
  5.  * Copyright (C) 2017 wcm.io
  6.  * %%
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *      http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  * #L%
  19.  */
  20. package io.wcm.sling.commons.resource;

  21. import org.apache.commons.lang3.StringUtils;
  22. import org.jetbrains.annotations.NotNull;

  23. /**
  24.  * Helper methods for resource path handling.
  25.  * @deprecated Use <code>io.wcm.wcm.commons.util.Path</code> instead.
  26.  */
  27. @Deprecated(since = "1.2.0")
  28. public final class ResourcePath {

  29.   private ResourcePath() {
  30.     // utility methods only
  31.   }

  32.   /**
  33.    * Gets level from parent use same logic (but reverse) as {@link com.day.text.Text#getAbsoluteParent(String, int)}.
  34.    * @param path Path
  35.    * @return level &gt;= 0 if path is value, -1 if path is invalid
  36.    */
  37.   public static int getAbsoluteLevel(@NotNull String path) {
  38.     if (StringUtils.isEmpty(path) || StringUtils.equals(path, "/")) {
  39.       return -1;
  40.     }
  41.     return StringUtils.countMatches(path, "/") - 1;
  42.   }

  43. }