A small helper for extracting location name and path from full location path

@param stageLocationPath stage location
@return remoteLocation object
331024
static public remoteLocation extractLocationAndPath(String stageLocationPath)
  {
    String location = stageLocationPath;
    String path = "";

    // split stage location as location name and path
    if (stageLocationPath.contains("/"))
    {
      location = stageLocationPath.substring(0, stageLocationPath.indexOf("/"));
      path = stageLocationPath.substring(stageLocationPath.indexOf("/") + 1);
    }

    return new remoteLocation(location, path);
  }
256948
public Locale getMainLocale(String rootPath) {

        CmsSite site = OpenCms.getSiteManager().getSiteForRootPath(rootPath);
        if (site == null) {
            return null;
        }
        return site.getMainTranslationLocale(null);
    }
1243658
public URI toUri(JimfsPath path) {
    fileStore.state().checkOpen();
    return pathService.toUri(uri, path.toAbsolutePath());
  }
449546
protected String getSimpleRootPath(CmsObject cms, String targetUri, String basePath) {

        if (cms == null) {
            // required by unit test cases
            return targetUri;
        }

        URI uri;
        String path;
        String suffix = "";

        // malformed uri
        try {
            uri = new URI(targetUri);
            path = uri.getPath();
            suffix = getSuffix(uri);
        } catch (Exception e) {
            if (LOG.isWarnEnabled()) {
                LOG.warn(Messages.get().getBundle().key(Messages.LOG_MALFORMED_URI_1, targetUri), e);
            }
            return null;
        }
        // opaque URI
        if (uri.isOpaque()) {
            return null;
        }

        // in case the target is the workplace UI
        if (CmsLinkManager.isWorkplaceUri(uri)) {
            return null;
        }

        // in case the target is a static resource served from the class path
        if (CmsStaticResourceHandler.isStaticResourceUri(uri)) {
            return CmsStringUtil.joinPaths(
                CmsStaticResourceHandler.STATIC_RESOURCE_PREFIX,
                CmsStaticResourceHandler.removeStaticResourcePrefix(path));
        }

        CmsStaticExportManager exportManager = OpenCms.getStaticExportManager();
        if (exportManager.isValidRfsName(path)) {
            String originalSiteRoot = cms.getRequestContext().getSiteRoot();
            String vfsName = null;
            try {
                cms.getRequestContext().setSiteRoot("");
                vfsName = exportManager.getVfsName(cms, path);
                if (vfsName != null) {
                    return vfsName;
                }
            } finally {
                cms.getRequestContext().setSiteRoot(originalSiteRoot);
            }
        }

        // absolute URI (i.e. URI has a scheme component like http:// ...)
        if (uri.isAbsolute()) {
            CmsSiteMatcher targetMatcher = new CmsSiteMatcher(targetUri);
            if (OpenCms.getSiteManager().isMatching(targetMatcher)
                || targetMatcher.equals(cms.getRequestContext().getRequestMatcher())) {

                path = CmsLinkManager.removeOpenCmsContext(path);
                boolean isWorkplaceServer = OpenCms.getSiteManager().isWorkplaceRequest(targetMatcher)
                    || targetMatcher.equals(cms.getRequestContext().getRequestMatcher());
                if (isWorkplaceServer) {
                    String selectedPath;
                    String targetSiteRoot = OpenCms.getSiteManager().getSiteRoot(path);
                    if (targetSiteRoot != null) {
                        selectedPath = getRootPathForSite(cms, path, targetSiteRoot, true);
                    } else {
                        // set selectedPath with the path for the current site
                        selectedPath = getRootPathForSite(cms, path, cms.getRequestContext().getSiteRoot(), false);
                        String pathForMatchedSite = getRootPathForSite(
                            cms,
                            path,
                            OpenCms.getSiteManager().matchSite(targetMatcher).getSiteRoot(),
                            false);
                        String originalSiteRoot = cms.getRequestContext().getSiteRoot();
                        try {
                            cms.getRequestContext().setSiteRoot("");
                            // the path for the current site normally is preferred, but if it doesn't exist and the path for the matched site
                            // does exist, then use the path for the matched site
                            if (!cms.existsResource(selectedPath, CmsResourceFilter.ALL)
                                && cms.existsResource(pathForMatchedSite, CmsResourceFilter.ALL)) {
                                selectedPath = pathForMatchedSite;
                            }
                        } finally {
                            cms.getRequestContext().setSiteRoot(originalSiteRoot);
                        }
                    }
                    return selectedPath + suffix;
                } else {
                    // add the site root of the matching site
                    return getRootPathForSite(
                        cms,
                        path + suffix,
                        OpenCms.getSiteManager().matchSite(targetMatcher).getSiteRoot(),
                        false);
                }
            } else {
                return null;
            }
        }

        // relative URI (i.e. no scheme component, but filename can still start with "/")
        String context = OpenCms.getSystemInfo().getOpenCmsContext();
        String vfsPrefix = OpenCms.getStaticExportManager().getVfsPrefix();
        if ((context != null) && (path.startsWith(context + "/") || (path.startsWith(vfsPrefix + "/")))) {
            // URI is starting with opencms context

            // cut context from path
            path = CmsLinkManager.removeOpenCmsContext(path);

            String targetSiteRoot = getTargetSiteRoot(cms, path, basePath);

            return getRootPathForSite(
                cms,
                path + suffix,
                targetSiteRoot,
                (targetSiteRoot != null) && path.startsWith(targetSiteRoot));
        }

        // URI with relative path is relative to the given relativePath if available and in a site,
        // otherwise invalid
        if (CmsStringUtil.isNotEmpty(path) && (path.charAt(0) != '/')) {
            if (basePath != null) {
                String absolutePath;
                int pos = path.indexOf("../../galleries/pics/");
                if (pos >= 0) {
                    // HACK: mixed up editor path to system gallery image folder
                    return CmsWorkplace.VFS_PATH_SYSTEM + path.substring(pos + 6) + suffix;
                }
                absolutePath = CmsLinkManager.getAbsoluteUri(path, cms.getRequestContext().addSiteRoot(basePath));
                if (OpenCms.getSiteManager().getSiteRoot(absolutePath) != null) {
                    return absolutePath + suffix;
                }
                // HACK: some editor components (e.g. HtmlArea) mix up the editor URL with the current request URL
                absolutePath = CmsLinkManager.getAbsoluteUri(
                    path,
                    cms.getRequestContext().getSiteRoot() + CmsWorkplace.VFS_PATH_EDITORS);
                if (OpenCms.getSiteManager().getSiteRoot(absolutePath) != null) {
                    return absolutePath + suffix;
                }
                // HACK: same as above, but XmlContent editor has one path element more
                absolutePath = CmsLinkManager.getAbsoluteUri(
                    path,
                    cms.getRequestContext().getSiteRoot() + CmsWorkplace.VFS_PATH_EDITORS + "xmlcontent/");
                if (OpenCms.getSiteManager().getSiteRoot(absolutePath) != null) {
                    return absolutePath + suffix;
                }
            }

            return null;
        }

        if (CmsStringUtil.isNotEmpty(path)) {
            String targetSiteRoot = getTargetSiteRoot(cms, path, basePath);

            return getRootPathForSite(
                cms,
                path + suffix,
                targetSiteRoot,
                (targetSiteRoot != null) && path.startsWith(targetSiteRoot));
        }

        // URI without path (typically local link)
        return suffix;
    }
624492
public static Path extractSubPath(Path basePath, Path sourcePath) {
		return sourcePath.subpath(basePath.getNameCount() - 1,
				sourcePath.getNameCount());
	}
483885
private String resolvePathVariables(String inputPath) {
        if (PathUtil.containsSymbol(inputPath)) {
            return locationService.resolveString(inputPath);
        } else {
            return inputPath;
        }
    }
1293939
@Override
    public String getPath() {
        ServletRESTRequestImpl ret = castRequest();
        if (ret != null)
            return ret.getPath();
        return null;
    }
1039463
public String getDisplayedUrl(String sitePath) {

        if (getSitemapEntry().isLeafType() && sitePath.endsWith("/")) {
            sitePath = sitePath.substring(0, sitePath.length() - 1);
        }
        CmsSitemapController controller = CmsSitemapView.getInstance().getController();
        String exportProp = controller.getEffectiveProperty(getSitemapEntry(), "export");
        if ("true".equals(exportProp)) {
            String exportName = getSitemapEntry().getExportName();
            if (exportName == null) {
                exportName = CmsCoreProvider.get().getSiteRoot();
            }
            String rfsPrefix = CmsSitemapView.getInstance().getController().getData().getExportRfsPrefix();
            if (rfsPrefix != null) {
                return CmsStringUtil.joinPaths(rfsPrefix, exportName, sitePath);
            }
        }
        return CmsCoreProvider.get().link(sitePath);
    }
1266566
@Override
	public String getResourcePath(String basePath, String relativePath) {

		String result = null;
		if (binaryGeneratorRegistry.isGeneratedBinaryResource(relativePath)) {
			result = relativePath;
		} else if (contextPath != null && relativePath.startsWith(contextPath)) {
			result = relativePath.substring(contextPath.length() - 1);
		} else {
			result = PathNormalizer.concatWebPath(basePath, relativePath);
		}
		return result;
	}
677893
public static FtpMessage get(String remotePath, String localPath, DataType type) {
        GetCommand cmd = new GetCommand();
        cmd.setSignal(FTPCmd.RETR.getCommand());

        GetCommand.File file = new GetCommand.File();
        file.setPath(remotePath);
        file.setType(type.name());
        cmd.setFile(file);

        GetCommand.Target target = new GetCommand.Target();
        target.setPath(localPath);
        cmd.setTarget(target);
        return new FtpMessage(cmd);
    }
1159703
public static URI getRelativePath(final URI relativePath) {
        final StringTokenizer tokenizer = new StringTokenizer(relativePath.toString(), URI_SEPARATOR);
        final StringBuilder buffer = new StringBuilder();
        if (tokenizer.countTokens() == 1) {
            return null;
        } else {
            while(tokenizer.countTokens() > 1) {
                tokenizer.nextToken();
                buffer.append("..");
                buffer.append(URI_SEPARATOR);
            }
            return toURI(buffer.toString());
        }
    }
831974
@Override
    public ExternalStorageLocation getLocation(Operation operation, PayloadType payloadType, String path) {
        String uri;
        switch (payloadType) {
            case WORKFLOW_INPUT:
            case WORKFLOW_OUTPUT:
                uri = "workflow";
                break;
            case TASK_INPUT:
            case TASK_OUTPUT:
                uri = "tasks";
                break;
            default:
                throw new ConductorClientException(String.format("Invalid payload type: %s for operation: %s", payloadType.toString(), operation.toString()));
        }
        return clientBase.getForEntity(String.format("%s/externalstoragelocation", uri), new Object[]{"path", path, "operation", operation.toString(), "payloadType", payloadType.toString()}, ExternalStorageLocation.class);
    }
1238333
protected static String getCmsPath(String path) {

        String slashPath = path.replace('\\', '/');

        // split path into components, translate each of them separately, then combine them again at the end
        String[] segments = slashPath.split("/");
        List<String> nonEmptySegments = new ArrayList<String>();
        for (String segment : segments) {
            if (segment.length() > 0) {
                String translatedSegment = "*".equals(segment)
                ? "*"
                : OpenCms.getResourceManager().getFileTranslator().translateResource(segment);
                nonEmptySegments.add(translatedSegment);
            }
        }
        String result = "/" + Joiner.on("/").join(nonEmptySegments);
        return result;
    }
1310725
private String getProjectStageFromLocators() {

        // try to locate web.xml
        WebResourceLocator webResourceLocator = new WebResourceLocator();
        URL webXmlLocation = webResourceLocator.getWebResourceUrl("/WEB-INF/web.xml");

        // try to parse the web.xml if the locator returned a result
        if (webXmlLocation != null) {

            String projectStage = parseWebXml(webXmlLocation);

            // accept the first result
            if (projectStage != null) {
                return projectStage;
            }

        }

        // not result found
        return null;

    }
1257457
public static String getClusterForLocation(URI location) {
        Matcher matcher = getLocatorMatcher(location);
        checkArgument(matcher.matches(), "Invalid location: %s", location);

        final String clusterPrefix;

        if (matcher.group("universe") != null) {
            clusterPrefix = matcher.group("universe");
        } else {
            clusterPrefix = "local";
        }

        String group = Objects.firstNonNull(matcher.group("group"), DEFAULT_GROUP);
        return format("%s_%s", clusterPrefix, group);
    }
697648
public static URL codeLocationFromPath(String filePath) {
        try {
            return new File(filePath).toURI().toURL();
        } catch (Exception e) {
            throw new InvalidCodeLocation(filePath);
        }
    }
472978
private static String getRootPath(final String locationPattern) {

        int rootDirEnd = locationPattern.length();

        while (AntPathMatcher.isPattern(locationPattern.substring(0, rootDirEnd))) {
            rootDirEnd = locationPattern.lastIndexOf('/', rootDirEnd - 2) + 1;
        }
        return locationPattern.substring(0, rootDirEnd);
    }