]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/acr/CmsContent.java
1 package org
.argeo
.cms
.acr
;
3 import java
.util
.Objects
;
5 import org
.argeo
.api
.acr
.Content
;
6 import org
.argeo
.api
.acr
.spi
.ProvidedContent
;
8 /** A content within a CMS system. */
9 public interface CmsContent
extends ProvidedContent
{
12 * Split a path (with {@link Content#PATH_SEPARATOR} separator) in an array of
13 * length 2, the first part being the parent path (which could be either
14 * absolute or relative), the second one being the last segment, (guaranteed to
17 static String
[] getParentPath(String path
) {
19 throw new IllegalArgumentException("Path cannot be null");
20 if (path
.length() == 0)
21 throw new IllegalArgumentException("Path cannot be empty");
22 ContentUtils
.checkDoubleSlash(path
);
23 int parentIndex
= path
.lastIndexOf(PATH_SEPARATOR
);
24 if (parentIndex
== path
.length() - 1) {// trailing '/'
25 path
= path
.substring(0, path
.length() - 1);
26 parentIndex
= path
.lastIndexOf(PATH_SEPARATOR
);
29 if (parentIndex
== -1) // no '/'
30 return new String
[] { "", path
};
32 return new String
[] { parentIndex
!= 0 ? path
.substring(0, parentIndex
) : ContentUtils
.PATH_SEPARATOR_STRING
,
33 path
.substring(parentIndex
+ 1) };
37 * Constructs a relative path between a base path and a given path.
39 * @throws IllegalArgumentException if the base path is not an ancestor of the
42 static String
relativize(String basePath
, String path
) throws IllegalArgumentException
{
43 Objects
.requireNonNull(basePath
);
44 Objects
.requireNonNull(path
);
45 if (!path
.startsWith(basePath
))
46 throw new IllegalArgumentException(basePath
+ " is not an ancestor of " + path
);
47 String relativePath
= path
.substring(basePath
.length());
48 if (relativePath
.length() > 0 && relativePath
.charAt(0) == PATH_SEPARATOR
)
49 relativePath
= relativePath
.substring(1);