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

com.day.cq.wcm.contentsync.PathRewriterOptions Maven / Gradle / Ivy

There is a newer version: 2024.11.18751.20241128T090041Z-241100
Show newest version
/*
 * Copyright 1997-2011 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.contentsync;

import org.apache.commons.lang.StringUtils;

import java.util.HashMap;

/**
 * The PathRewriterOptions configure in which way
 * links and references should be rewritten. To enable path rewriting
 * you have to set an instance of PathRewriterOptions as
 * a request attribute.
 */
public class PathRewriterOptions extends HashMap {
	
	private static final long serialVersionUID = 7042302195945834350L;

	/** The request attribute name. */
	public static final String ATTRIBUTE_PATH_REWRITING_OPTIONS = "pathRewritingOptions";

	/**	 */
	public static final String OPTION_REWRITE_LINKS = "links";
	public static final String OPTION_REWRITE_CLIENTLIBS = "clientlibs";
	public static final String OPTION_REWRITE_IMAGES = "images";
	public static final String OPTION_TEMP_DESIGNS = "tempDesign";
	private String tempDesignPath = null;

    private String relativeParentPath;

	public PathRewriterOptions(RewriteMode links, RewriteMode clientlibs, RewriteMode images) {
		setRewriteMode(OPTION_REWRITE_LINKS, links);
		setRewriteMode(OPTION_REWRITE_CLIENTLIBS, clientlibs);
		setRewriteMode(OPTION_REWRITE_IMAGES, images);
	}

	/*
	    Initialize PathRewriter with Temp design (CQ-4208243)
	    Temp designs are created at runtime and are stored as tempDesignPath. If temp design is present in path rewriter
	    than that along with rewriter configurations are together used to rewrite the path
	 */
	public PathRewriterOptions(String tempDesignPath, RewriteMode links, RewriteMode clientlibs, RewriteMode images) {
		this(links, clientlibs, images);
		this.tempDesignPath = tempDesignPath;
	}
	
	public boolean isExternal(String option) {
		return getRewriteMode(option) == RewriteMode.REWRITE_EXTERNAL;
	}
	
	public boolean isRelative(String option) {
		return getRewriteMode(option) == RewriteMode.REWRITE_RELATIVE;
	}

    public boolean hasRelativeParent() { return StringUtils.isNotEmpty(relativeParentPath); }

	/**
	 * Get configured rewrite mode.
	 * @return the rewriteLinks
	 */
	public RewriteMode getRewriteMode(String option) {
		return get(option);
	}

	/**
	 * Set a new rewrite mode.
	 * @param mode The new rewrite mode
	 */
	public void setRewriteMode(String option, RewriteMode mode) {
		put(option, mode);
	}

	public String getTempDesignPath() {
		return tempDesignPath;
	}

    /**
     * Get configured relative parent path.
     * @return the relative parent path
     */
    public String getRelativeParentPath() {
        return relativeParentPath;
    }

    /**
     * Set a new relative parent.
     * @param path The new relative parent path
     */
    public void setRelativeParentPath(String path) {
        relativeParentPath = path;
    }

	/**
	 * Available rewrite modes.
	 */
	public enum RewriteMode {
		REWRITE_EXTERNAL,
		REWRITE_RELATIVE
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy