All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.day.cq.wcm.api.PageManager Maven / Gradle / Ivy

There is a newer version: 2024.11.18751.20241128T090041Z-241100
Show newest version
/*
 * Copyright 1997-2008 Day Management AG
 * Barfuesserplatz 6, 4001 Basel, Switzerland
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * Day Management AG, ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Day.
 */
package com.day.cq.wcm.api;

import java.util.Calendar;
import java.util.Collection;
import java.util.function.Predicate;

import javax.jcr.Node;

import org.apache.sling.api.resource.Resource;
import org.osgi.annotation.versioning.ProviderType;

import com.day.cq.wcm.api.msm.Blueprint;


/**
 * The page manager provides methods for page level operations.
 */
@ProviderType
public interface PageManager {

    /**
     * Convenience method that returns the page at the given path. If the
     * resource at that path does not exist or is not adaptable to Page,
     * null is returned.
     * @param path path of the page
     * @return page or null
     */
    Page getPage(String path);

    /**
     * Returns the page that contains this resource. If the resource is a page
     * the resource is returned. Otherwise it walks up the parent resources
     * until a page is found.
     * @param resource resource to find the page for
     * @return page or null if not found.
     */
    Page getContainingPage(Resource resource);

    /**
     * Returns the page that contains the resource at the given path. If the path addresses a page, that page is
     * returned. Otherwise it walks up the parent resources until a page is found.
     * @param path path to find the page for
     * @return page or null if not found.
     */
    Page getContainingPage(String path);

    /**
     * Creates a new page at the given path using the provided template as
     * content template. If a no pageName is given but a title, then the title
     * is used as hint for the name of the new page.  Changes are automatically
     * saved.
     *
     * @param parentPath the path of the parent page
     * @param pageName the name of the new page
     * @param template the template for the new page
     * @param title the title of the new page
     * @return the page that was created
     * @throws WCMException if an error during this operation occurs.
     */
    Page create(String parentPath, String pageName, String template, String title)
            throws WCMException;

    /**
     * Creates a new page at the given path using the provided template as
     * content template. If a no pageName is given but a title, then the title
     * is used as hint for the name of the new page.
     *
     * @param parentPath the path of the parent page
     * @param pageName the name of the new page
     * @param template the template for the new page
     * @param title the title of the new page
     * @param autoSave if true saves the modifications.
     * @return the page that was created
     * @throws WCMException if an error during this operation occurs.
     */
    Page create(String parentPath, String pageName, String template, String title,
                boolean autoSave) throws WCMException;

    /**
     * Moves the given page to the new destination and automatically saves the changes.
     * If source and destination are equals the page is just ordered.
     *
     * @param page the page to move
     * @param destination the path of the new destination
     * @param beforeName the name of the next page. if null the page
     *        is ordered at the end.
     * @param shallow if true only the page content is moved
     * @param resolveConflict if true resolves name conflict if
     *        destination already exists.
     * @param adjustRefs list of paths to pages that refer to the moved one.
     *        those references will be adjusted.
     * @return the new page at the new location
     * @throws WCMException if an error during this operation occurs.
     */
    Page move(Page page, String destination, String beforeName, boolean shallow,
              boolean resolveConflict, String[] adjustRefs)
            throws WCMException;

    /**
     * Moves the given page to the new destination and automatically saves the changes.
     * If source and destination are equals the page is just ordered.
     *
     * @param page the page to move
     * @param destination the path of the new destination
     * @param beforeName the name of the next page. if null the page
     *        is ordered at the end.
     * @param shallow if true only the page content is moved
     * @param resolveConflict if true resolves name conflict if
     *        destination already exists.
     * @param adjustRefs list of paths to pages that refer to the moved one.
     *        those references will be adjusted.
     * @param publishRefs list of referencing paths that will be republished.
     * @return the new page at the new location
     * @throws WCMException if an error during this operation occurs.
     */
    Page move(Page page, String destination, String beforeName, boolean shallow,
              boolean resolveConflict, String[] adjustRefs, String[] publishRefs)
            throws WCMException;

    /**
     * Moves the given resource to the new destination and automatically saves the changes.
     * If source and destination are equals the resource is just ordered.
     *
     * @param resource the resource to move
     * @param destination the path of the new destination
     * @param beforeName the name of the next resource. if null the resource
     *        is ordered at the end.
     * @param shallow if true only the resource content is moved.
     *        this is currently only supported for pages.
     * @param resolveConflict if true resolves name conflict if
     *        destination already exists.
     * @param adjustRefs list of paths to pages that refer to the moved one.
     *        those references will be adjusted.
     * @return the new resource at the new location
     * @throws WCMException if an error during this operation occurs.
     */
    Resource move(Resource resource, String destination, String beforeName,
                  boolean shallow, boolean resolveConflict, String[] adjustRefs)
            throws WCMException;

    /**
     * Moves the given resource to the new destination and automatically saves the changes.
     * If source and destination are equals the resource is just ordered.
     *
     * @param resource the resource to move
     * @param destination the path of the new destination
     * @param beforeName the name of the next resource. if null the resource
     *        is ordered at the end.
     * @param shallow if true only the resource content is moved.
     *        this is currently only supported for pages.
     * @param resolveConflict if true resolves name conflict if
     *        destination already exists.
     * @param adjustRefs list of paths to pages that refer to the moved one.
     *        those references will be adjusted.
     * @param publishRefs list of referencing paths that will be republished.
     * @return the new resource at the new location
     * @throws WCMException if an error during this operation occurs.
     */
    Resource move(Resource resource, String destination, String beforeName,
                  boolean shallow, boolean resolveConflict, String[] adjustRefs, String[] publishRefs)
            throws WCMException;

    /**
     * Options object used for {@link #copy(CopyOptions)}.
     */
    public static class CopyOptions {
        /**
         * The page to copy (if {@link #resource} is not provided).
         */
        public Page page;
        /**
         * The resource to copy
         */
        public Resource resource;
        /**
         * The destination
         */
        public String destination;
        /**
         * The name of the next page. If {@code null} the page is ordered at the end.
         */
        public String beforeName;
        /**
         * If {@code true} a non-recursive copy is performed.
         */
        public boolean shallow;
        /**
         * If {@code true} resolves name conflict if destination already exists.
         */
        public boolean resolveConflict;
        /**
         * If {@code true} saves the modifications.
         */
        public boolean autoSave;
        /**
         * If {@code true} adjusts any content references to the new location.
         */
        public boolean adjustReferences;
        /**
         * If {@code true} the current resource needs to be overridden (mainly because it has a resourceType outofscope)
         */
        public boolean overridePage;
    }

    /**
     * Overrides the given page.
     *
     * @param options the options for this override operation. {@code page} or {@code resource} are required to be
     *                defined, as well as {@code destination}. Also, it is important to define
     *                {@code overridePage} in case the page already exists and needs to be overridden
     * @return the overridden page
     * @throws WCMException if an error during this operation occurs.
     */
    Resource override(CopyOptions options) throws WCMException;

    /**
     * Copies the given page to the new destination.
     *
     * @param options the options for this copy operation. {@code page} or {@code resource} are required
     *                defined, as well as {@code destination}.
     * @return the copied page
     * @throws WCMException if an error during this operation occurs.
     */
    Resource copy(CopyOptions options) throws WCMException;

    /**
     * Copies the given page to the new destination and automatically saves the modifications
     *
     * @param page the page to copy
     * @param destination the destination
     * @param beforeName the name of the next page. if null the page
     *        is ordered at the end.
     * @param shallow if true a non-recursive copy is performed.
     * @param resolveConflict if true resolves name conflict if
     *        destination already exists.
     * @return the copied page
     * @throws WCMException if an error during this operation occurs.
     */
    Page copy(Page page, String destination, String beforeName, boolean shallow,
              boolean resolveConflict) throws WCMException;

    /**
     * Copies the given page to the new destination
     *
     * @param page the page to copy
     * @param destination the destination
     * @param beforeName the name of the next page. if null the page
     *        is ordered at the end.
     * @param shallow if true a non-recursive copy is performed.
     * @param resolveConflict if true resolves name conflict if
     *        destination already exists.
     * @param autoSave if true saves the modifications.
     * @return the copied page
     * @throws WCMException if an error during this operation occurs.
     */
    Page copy(Page page, String destination, String beforeName, boolean shallow,
              boolean resolveConflict, boolean autoSave) throws WCMException;

    /**
     * Copies the given resource to the new destination and automatically saves the modifications
     *
     * @param resource the resource to copy
     * @param destination the destination
     * @param beforeName the name of the next resource. if null the
     *        resource is ordered at the end.
     * @param shallow if true a non-recursive copy is performed.
     *        this is currently only supported for pages.
     * @param resolveConflict if true resolves name conflict if
     *        destination already exists.
     * @return the copied resource
     * @throws WCMException if an error during this operation occurs.
     */
    Resource copy(Resource resource, String destination, String beforeName,
                  boolean shallow, boolean resolveConflict) throws WCMException;

    /**
     * Copies the given resource to the new destination
     *
     * @param resource the resource to copy
     * @param destination the destination
     * @param beforeName the name of the next resource. if null the
     *        resource is ordered at the end.
     * @param shallow if true a non-recursive copy is performed.
     *        this is currently only supported for pages.
     * @param resolveConflict if true resolves name conflict if
     *        destination already exists.
     * @param autoSave if true saves the modifications.
     * @return the copied resource
     * @throws WCMException if an error during this operation occurs.
     */
    Resource copy(Resource resource, String destination, String beforeName,
                  boolean shallow, boolean resolveConflict, boolean autoSave) throws WCMException;

    /**
     * Deletes the page and saves the change.
     * @param page the page to delete
     * @param shallow if true only the content of the page is deleted
     *        but not it's child pages
     * @throws WCMException if an error during this operation occurs.
     */
    void delete(Page page, boolean shallow) throws WCMException;

    /**
     * Deletes the page.
     * @param page the page to delete
     * @param shallow if true only the content of the page is deleted
     *        but not it's child pages
     * @param autoSave if true saves the modifications.
     * @throws WCMException if an error during this operation occurs.
     */
    void delete(Page page, boolean shallow, boolean autoSave) throws WCMException;

    /**
     * Deletes the resource and saves the change.
     * @param resource the resource to delete
     * @param shallow if true only the content of the resource is deleted
     *        but not it's child resources. only supported for pages.
     * @throws WCMException if an error during this operation occurs.
     */
    void delete(Resource resource, boolean shallow) throws WCMException;

    /**
     * Deletes the resource.
     * @param resource the resource to delete
     * @param shallow if true only the content of the resource is deleted
     *        but not it's child resources. only supported for pages.
     * @param autoSave if true saves the modifications.
     * @throws WCMException if an error during this operation occurs.
     */
    void delete(Resource resource, boolean shallow, boolean autoSave) throws WCMException;

    /**
     * Deletes the resource.
     * @param resource the resource to delete
     * @param shallow if true only the content of the resource is deleted
     *        but not it's child resources. only supported for pages.
     * @param autoSave if true saves the modifications.
     * @param archive if true saves the version for deleted resource.
     * @throws WCMException if an error during this operation occurs.
     */
    void delete(Resource resource, boolean shallow, boolean autoSave,boolean archive) throws WCMException;

    /**
     * Orders the given page before the one with the name specified by
     * beforeName if it's null the page is ordered at
     * the end of its siblings.  Changes are automatically saved.
     *
     * @param page the page to order
     * @param beforeName the name of the next page
     * @throws WCMException if an error during this operation occurs.
     */
    void order(Page page, String beforeName) throws WCMException;

    /**
     * Orders the given page before the one with the name specified by
     * beforeName if it's null the page is ordered at
     * the end of its siblings.
     *
     * @param page the page to order
     * @param beforeName the name of the next page
     * @param autoSave if true saves the modifications.
     * @throws WCMException if an error during this operation occurs.
     */
    void order(Page page, String beforeName, boolean autoSave) throws WCMException;

    /**
     * Orders the given resource before the one with the name specified by
     * beforeName if it's null the resource is ordered
     * at the end of its siblings.  Changes are automatically saved.
     *
     * @param resource the resource to order
     * @param beforeName the name of the next resource
     * @throws WCMException if an error during this operation occurs.
     */
    void order(Resource resource, String beforeName) throws WCMException;

    /**
     * Orders the given resource before the one with the name specified by
     * beforeName if it's null the resource is ordered
     * at the end of its siblings.
     *
     * @param resource the resource to order
     * @param beforeName the name of the next resource
     * @param autoSave if true saves the modifications.
     * @throws WCMException if an error during this operation occurs.
     */
    void order(Resource resource, String beforeName, boolean autoSave) throws WCMException;

    /**
     * Returns the template with the given name or null if the template doesn't exist or
     * the current user does not have read access on the template resource identified by the given path.
     * This is the case on publish instances using default ACL configuration (anonymous cannot read templates).
     * @param templatePath the name of the template
     * @return the new template
     * @deprecated Use {@link com.day.cq.wcm.api.TemplateManager#getTemplate(String)} instead.
     */
    Template getTemplate(String templatePath);

    /**
     * Returns a collection of all available templates. If the given path
     * is not null only those templates are returned that are
     * allowed to be used as page templates below that path.
     *
     * @param parentPath path of the parent page or null
     * @return a collection of templates
     * @see Template#isAllowed(String)
     * @deprecated Use {@link com.day.cq.wcm.api.TemplateManager#getAllTemplates()} or
     * {@link com.day.cq.wcm.api.TemplateManager#getTemplates(Predicate)} instead
     */
    Collection