001/*
002 * Copyright (c) 2004-2010, Kohsuke Kawaguchi
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification, are permitted provided
006 * that the following conditions are met:
007 *
008 *     * Redistributions of source code must retain the above copyright notice, this list of
009 *       conditions and the following disclaimer.
010 *     * Redistributions in binary form must reproduce the above copyright notice, this list of
011 *       conditions and the following disclaimer in the documentation and/or other materials
012 *       provided with the distribution.
013 *
014 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
015 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
016 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
017 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
018 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
019 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
020 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
021 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
022 */
023
024package org.kohsuke.stapler;
025
026import javax.servlet.http.HttpServletRequest;
027
028/**
029 * Information about ancestor of the "it" node.
030 *
031 * @author Kohsuke Kawaguchi
032 */
033public interface Ancestor {
034    /**
035     * Gets the model object of the application.
036     */
037    Object getObject();
038
039    /**
040     * Gets the URL to this ancestor.
041     *
042     * <p>
043     * The returned string represents the portion of the request URL
044     * that matches this object. It starts with
045     * {@link HttpServletRequest#getContextPath() context path},
046     * and it ends without '/'. So, for example, if your web app
047     * is deployed as "mywebapp" and this ancestor object is
048     * obtained from the app root object by <tt>getFoo().getBar(3)</tt>,
049     * then this string will be <tt>/mywebapp/foo/bar/3</tt>
050     *
051     * <p>
052     * Any ASCII-unsafe characters are escaped.
053     *
054     * @return
055     *      never null.
056     */
057    String getUrl();
058
059    /**
060     * Gets the remaining URL after this ancestor.
061     *
062     * <p>
063     * The returned string represents the portion of the request URL
064     * that follows this ancestor. It starts and ends without '/'.
065     * So, for example, if the request URL is "foo/bar/3" and this ancestor object is
066     * obtained from the app root object by <tt>getFoo()</tt>,
067     * then this string will be <tt>bar/3</tt>
068     */
069    String getRestOfUrl();
070
071    /**
072     * Of the tokens that constitute {@link #getRestOfUrl()},
073     * return the n-th token. So in the example described in {@link #getRestOfUrl()},
074     * {@code getNextToken(0).equals("bar")} and
075     * {@code getNextToken(1).equals("3")}
076     */
077    String getNextToken(int n);
078
079    /**
080     * Gets the complete URL to this ancestor.
081     *
082     * <p>
083     * This method works like {@link #getUrl()} except it contains
084     * the host name and the port number.
085     */
086    String getFullUrl();
087
088    /**
089     * Gets the relative path from the current object to this ancestor.
090     *
091     * <p>
092     * The returned string looks like "../.." (ends without '/')
093     *
094     * @return
095     *      never null.
096     */
097    String getRelativePath();
098
099    /**
100     * Gets the previous ancestor, or null if none (meaning
101     * this is the root object.)
102     */
103    Ancestor getPrev();
104
105    /**
106     * Gets the next ancestor, or null if none (meaning
107     * this is the 'it' object.
108     */
109    Ancestor getNext();
110}