<commit_before>/**
 * Copyright 2010 55 Minutes (http://www.55minutes.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package fiftyfive.wicket.resource;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.Resource;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.behavior.AbstractHeaderContributor;
import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.IHeaderContributor;
import org.apache.wicket.markup.html.JavascriptPackageResource;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WicketURLEncoder;
import org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy;
import org.wicketstuff.mergedresources.ResourceMount;
import org.wicketstuff.mergedresources.ResourceSpec;
import static org.apache.wicket.Application.DEVELOPMENT;

/**
 * Simplifies usage of the wicketstuff-merged-resources library by mounting
 * merged resources with an easy builder API and a good set defaults.
 * <p>
 * More importantly, this builder applies the DRY principle so that you only
 * have to list your resources once; then you can attach this list of
 * resources to any number of pages or components without redeclaring
 * HeaderContributors for them by hand.
 * See {@link #build} for details.
 * <p>
 * The reasonable defaults provided by this builder are as follows:
 * <ul>
 * <li>Only merge resources in deployment mode. In development, bypass the
 *     wicketstuff-merged-resources facility entirely and mount
 *     the resources separately as Wicket shared resources.</li>
 * <li>Set aggressive cache headers and gzip resources in deployment mode.</li>
 * <li>Disable the resource minify feature. This feature is buggy and
 *     does not add much value over gzip.</li>
 * </ul>
 * Furthermore, this builder fixes some shortcomings of the
 * wicketstuff-merged-resources library, namely:
 * <ul>
 * <li>With wicketstuff-merged-resources, if Wicket's
 *     addLastModifiedTimeToResourceReferenceUrl setting is enabled, extra
 *     path elements like {@code /w:lm/123456789} are appended to the
 *     resource URLs. This makes it difficult to use relative paths within
 *     CSS resources, since the presence or absence of the timestamp changes
 *     the depth of the URL. MergedResourceBuilder ensures that the timestamp
 *     is appended as a query string, thereby leaving the path unaltered,
 *     like this: {@code ?w:lm=123456789}.</li>
 * <li>With wicketstuff-merged-resources, in non-merged mode the individual
 *     resource path is appended to the merged mount point. So you might end
 *     up with {@code /styles/all.css} in merged mode, but
 *     {@code /styles/all.css/com.mypackage.Class/layout.css} in non-merged
 *     mode. Again, this makes it very difficult to use relative paths within
 *     CSS files (e.g. for background images). MergedResourceBuilder ensures
 *     that merged and non-merged modes produce paths of the same depth. In
 *     this example the URLs would be:
 *     {@code /styles/all.css} (merged) and
 *     {@code /styles/all.css-com.mypackage.Class%2Flayout.css} (non-merged).
 *     </li>
 * </ul>
 * Example usage:
 * <pre>
 * new MergedResourceBuilder()
 *     .setPath("/styles/all.css")
 *     .addCss(WicketApplication.class, "styles/reset.css")
 *     .addCss(WicketApplication.class, "styles/core.css")
 *     .addCss(WicketApplication.class, "styles/layout.css")
 *     .addCss(WicketApplication.class, "styles/content.css")
 *     .addCss(WicketApplication.class, "styles/forms.css")
 *     .addCss(WicketApplication.class, "styles/page-specific.css")
 *     .build(this);
 * </pre>
 */
public class MergedResourceBuilder
{
    private Boolean _isCss;
    private String _media;
    
    private String _path;
    private List<ResourceReference> _references;
    
    /**
     * Creates an empty builder object. See the
     * {@link MergedResourceBuilder class documentation} for 
     * example usage.
     */
    public MergedResourceBuilder()
    {
        _references = new ArrayList<ResourceReference>();
    }
    
    /**
     * Sets the path at which the merged resources will be mounted.
     * For example, "/styles/all.css".
     */
    public MergedResourceBuilder setPath(String path)
    {
        _path = path;
        return this;
    }
    
    /**
     * Sets the CSS media type that will be used for the merged CSS resources.
     * By default the merged CSS will not have a media type, meaning it will
     * apply to all media. Alternatively you could specify "screen" or "print"
     * to limit the CSS to those media.
     */
    public MergedResourceBuilder setCssMedia(String media)<commit_msg>Make `_resources` available to subclasses for future possible javascript enhancements.<commit_after>/**
 * Copyright 2010 55 Minutes (http://www.55minutes.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package fiftyfive.wicket.resource;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.Resource;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.behavior.AbstractHeaderContributor;
import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.IHeaderContributor;
import org.apache.wicket.markup.html.JavascriptPackageResource;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WicketURLEncoder;
import org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy;
import org.wicketstuff.mergedresources.ResourceMount;
import org.wicketstuff.mergedresources.ResourceSpec;
import static org.apache.wicket.Application.DEVELOPMENT;

/**
 * Simplifies usage of the wicketstuff-merged-resources library by mounting
 * merged resources with an easy builder API and a good set defaults.
 * <p>
 * More importantly, this builder applies the DRY principle so that you only
 * have to list your resources once; then you can attach this list of
 * resources to any number of pages or components without redeclaring
 * HeaderContributors for them by hand.
 * See {@link #build} for details.
 * <p>
 * The reasonable defaults provided by this builder are as follows:
 * <ul>
 * <li>Only merge resources in deployment mode. In development, bypass the
 *     wicketstuff-merged-resources facility entirely and mount
 *     the resources separately as Wicket shared resources.</li>
 * <li>Set aggressive cache headers and gzip resources in deployment mode.</li>
 * <li>Disable the resource minify feature. This feature is buggy and
 *     does not add much value over gzip.</li>
 * </ul>
 * Furthermore, this builder fixes some shortcomings of the
 * wicketstuff-merged-resources library, namely:
 * <ul>
 * <li>With wicketstuff-merged-resources, if Wicket's
 *     addLastModifiedTimeToResourceReferenceUrl setting is enabled, extra
 *     path elements like {@code /w:lm/123456789} are appended to the
 *     resource URLs. This makes it difficult to use relative paths within
 *     CSS resources, since the presence or absence of the timestamp changes
 *     the depth of the URL. MergedResourceBuilder ensures that the timestamp
 *     is appended as a query string, thereby leaving the path unaltered,
 *     like this: {@code ?w:lm=123456789}.</li>
 * <li>With wicketstuff-merged-resources, in non-merged mode the individual
 *     resource path is appended to the merged mount point. So you might end
 *     up with {@code /styles/all.css} in merged mode, but
 *     {@code /styles/all.css/com.mypackage.Class/layout.css} in non-merged
 *     mode. Again, this makes it very difficult to use relative paths within
 *     CSS files (e.g. for background images). MergedResourceBuilder ensures
 *     that merged and non-merged modes produce paths of the same depth. In
 *     this example the URLs would be:
 *     {@code /styles/all.css} (merged) and
 *     {@code /styles/all.css-com.mypackage.Class%2Flayout.css} (non-merged).
 *     </li>
 * </ul>
 * Example usage:
 * <pre>
 * new MergedResourceBuilder()
 *     .setPath("/styles/all.css")
 *     .addCss(WicketApplication.class, "styles/reset.css")
 *     .addCss(WicketApplication.class, "styles/core.css")
 *     .addCss(WicketApplication.class, "styles/layout.css")
 *     .addCss(WicketApplication.class, "styles/content.css")
 *     .addCss(WicketApplication.class, "styles/forms.css")
 *     .addCss(WicketApplication.class, "styles/page-specific.css")
 *     .build(this);
 * </pre>
 */
public class MergedResourceBuilder
{
    private Boolean _isCss;
    private String _media;
    
    private String _path;
    protected List<ResourceReference> _references;
    
    /**
     * Creates an empty builder object. See the
     * {@link MergedResourceBuilder class documentation} for 
     * example usage.
     */
    public MergedResourceBuilder()
    {
        _references = new ArrayList<ResourceReference>();
    }
    
    /**
     * Sets the path at which the merged resources will be mounted.
     * For example, "/styles/all.css".
     */
    public MergedResourceBuilder setPath(String path)
    {
        _path = path;
        return this;
    }
    
    /**
     * Sets the CSS media type that will be used for the merged CSS resources.
     * By default the merged CSS will not have a media type, meaning it will
     * apply to all media. Alternatively you could specify "screen" or "print"
     * to limit the CSS to those media.
     */
    public MergedResourceBuilder setCssMedia(String media)
{'fraction_non_alphanumeric': 0.08978328173374613, 'fraction_numerical': 0.005816680739281359, 'mean_word_length': 3.5968089693833547, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4044659', 'n_tokens_mistral': 3039, 'n_tokens_neox': 2922, 'n_words': 1062}