001// Licensed under the Apache License, Version 2.0 (the "License");
002// you may not use this file except in compliance with the License.
003// You may obtain a copy of the License at
004//
005// http://www.apache.org/licenses/LICENSE-2.0
006//
007// Unless required by applicable law or agreed to in writing, software
008// distributed under the License is distributed on an "AS IS" BASIS,
009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010// See the License for the specific language governing permissions and
011// limitations under the License.
012
013package org.apache.tapestry5.services.javascript;
014
015/**
016 * A contribution to an extensible {@link JavaScriptStack}. Such a stack is created in terms of all the contributions.
017 *
018 * @see ExtensibleJavaScriptStack
019 * @since 5.3
020 */
021public class StackExtension
022{
023    /**
024     * The type of extension.
025     */
026    public final StackExtensionType type;
027
028    /**
029     * The value contributed; will have symbols expanded, then be converted to the appropriate type.
030     */
031    public final String value;
032
033    public StackExtension(StackExtensionType type, String value)
034    {
035        this.type = type;
036        this.value = value;
037    }
038
039    @Override
040    public String toString()
041    {
042        return String.format("StackExtension[%s %s]", type.name(), value);
043    }
044
045    /**
046     * Convenience for defining a LIBRARY.
047     *
048     * @since 5.4
049     */
050    public static StackExtension library(String path)
051    {
052        return new StackExtension(StackExtensionType.LIBRARY, path);
053    }
054
055    /**
056     * Convenience for defining a MODULE.
057     *
058     * @since 5.4
059     */
060    public static StackExtension module(String name)
061    {
062        return new StackExtension(StackExtensionType.MODULE, name);
063    }
064
065    /**
066     * Convenience for defining a STYLESHEET.
067     *
068     * @since 5.4
069     */
070    public static StackExtension stylesheet(String path)
071    {
072        return new StackExtension(StackExtensionType.STYLESHEET, path);
073    }
074
075    /**
076     * Convenience for defining a STACK.
077     *
078     * @since 5.4
079     */
080    public static StackExtension stack(String name)
081    {
082        return new StackExtension(StackExtensionType.STACK, name);
083    }
084
085    /**
086     * Convenience for defining the {@link JavaScriptStack#getJavaScriptAggregationStrategy()}.
087     *
088     * @since 5.4
089     */
090    public static StackExtension javascriptAggregation(JavaScriptAggregationStrategy strategy)
091    {
092        return new StackExtension(StackExtensionType.AGGREGATION_STRATEGY, strategy.name());
093    }
094
095}