Search in sources :

Example 51 with ContentPath

use of com.enonic.xp.content.ContentPath in project xp by enonic.

the class BaseSiteHandler method doCreatePortalRequest.

protected PortalRequest doCreatePortalRequest(final WebRequest webRequest, final String baseUri, final String baseSubPath) {
    final RepositoryId repositoryId = findRepository(baseSubPath);
    final Branch branch = findBranch(baseSubPath);
    final ContentPath contentPath = findContentPath(baseSubPath);
    final PortalRequest portalRequest = new PortalRequest(webRequest);
    portalRequest.setBaseUri(baseUri);
    portalRequest.setRepositoryId(repositoryId);
    portalRequest.setBranch(branch);
    portalRequest.setContentPath(contentPath);
    return portalRequest;
}
Also used : Branch(com.enonic.xp.branch.Branch) ContentPath(com.enonic.xp.content.ContentPath) RepositoryId(com.enonic.xp.repository.RepositoryId) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 52 with ContentPath

use of com.enonic.xp.content.ContentPath in project xp by enonic.

the class ControllerHandlerWorker method contentExists.

private boolean contentExists(final String contentSelector) {
    final ContentId contentId = ContentId.from(contentSelector.substring(1));
    final ContentPath contentPath = ContentPath.from(contentSelector).asAbsolute();
    return this.contentService.contentExists(contentId) || (!ContentPath.ROOT.equals(contentPath) && this.contentService.contentExists(contentPath));
}
Also used : ContentId(com.enonic.xp.content.ContentId) ContentPath(com.enonic.xp.content.ContentPath)

Example 53 with ContentPath

use of com.enonic.xp.content.ContentPath in project xp by enonic.

the class ControllerHandlerWorker method getContentOrNull.

protected final Content getContentOrNull(final String contentSelector) {
    if (request.getMode() == RenderMode.EDIT) {
        final ContentId contentId = ContentId.from(contentSelector.substring(1));
        final Content contentById = getContentById(contentId);
        if (contentById != null) {
            return contentById;
        }
    }
    final ContentPath contentPath = ContentPath.from(contentSelector).asAbsolute();
    return getContentByPath(contentPath);
}
Also used : Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) ContentPath(com.enonic.xp.content.ContentPath)

Example 54 with ContentPath

use of com.enonic.xp.content.ContentPath in project xp by enonic.

the class ContentIdResolver method resolveId.

private ContentId resolveId(final ContentPath path) {
    final ContentPath resolved = resolvePath(path);
    final Content content = this.contentService.getByPath(resolved);
    return content != null ? content.getId() : null;
}
Also used : Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath)

Example 55 with ContentPath

use of com.enonic.xp.content.ContentPath in project xp by enonic.

the class GenericEndpointUrlBuilder method removeContentPath.

private String removeContentPath(final String path) {
    final String[] splitPreEndpointPath = path.split("/");
    int preEndpointPathIndex = splitPreEndpointPath.length - 1;
    final ContentPath normalizedContentPath = ContentPath.from(normalizePath(this.portalRequest.getContentPath().toString()));
    int contentPathIndex = normalizedContentPath.elementCount() - 1;
    while (preEndpointPathIndex >= 0 && contentPathIndex >= 0 && normalizedContentPath.getElement(contentPathIndex).equals(splitPreEndpointPath[preEndpointPathIndex])) {
        preEndpointPathIndex--;
        contentPathIndex--;
    }
    final String[] preEndpointPathWithoutContentPath = Arrays.copyOfRange(splitPreEndpointPath, 0, preEndpointPathIndex + 1);
    return String.join(ELEMENT_DIVIDER, preEndpointPathWithoutContentPath);
}
Also used : ContentPath(com.enonic.xp.content.ContentPath)

Aggregations

ContentPath (com.enonic.xp.content.ContentPath)56 Content (com.enonic.xp.content.Content)30 Test (org.junit.jupiter.api.Test)30 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)13 ContentId (com.enonic.xp.content.ContentId)11 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)10 WebException (com.enonic.xp.web.WebException)8 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)6 ArrayList (java.util.ArrayList)5 FindContentIdsByParentResult (com.enonic.xp.content.FindContentIdsByParentResult)4 Node (com.enonic.xp.node.Node)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4 ContentInheritType (com.enonic.xp.content.ContentInheritType)3 Context (com.enonic.xp.context.Context)3 Site (com.enonic.xp.site.Site)3 ContentAlreadyExistsException (com.enonic.xp.content.ContentAlreadyExistsException)2 CONTENT_ROOT_PATH_ATTRIBUTE (com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE)2 ContentVersionId (com.enonic.xp.content.ContentVersionId)2 List (java.util.List)2 Set (java.util.Set)2