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

com.adobe.granite.ui.clientlibs.LibraryType Maven / Gradle / Ivy

/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2011 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 **************************************************************************/
package com.adobe.granite.ui.clientlibs;

import org.apache.jackrabbit.util.Text;
import org.apache.sling.api.SlingHttpServletRequest;

/**
 * LibraryType...
 */
public enum LibraryType {

    /**
     * JS library type
     */
    JS(".js", "application/javascript"),

    /**
     * CSS library type
     */
    CSS(".css", "text/css");

    /**
     * The extension, including the dot (.)
     */
    public final String extension;

    /**
     * The content type of the library
     */
    public final String contentType;

    LibraryType(String extension, String contentType) {
        this.extension = extension;
        this.contentType = contentType;
    }
    
    public static LibraryType fromRequest(SlingHttpServletRequest request) {
        String ext = request.getRequestPathInfo().getExtension();
        if (ext == null || ext.length() == 0) {
            // legacy check
            ext = Text.getName(request.getRequestPathInfo().getResourcePath(), '.');
        }
        if (!ext.startsWith(".")) {
            ext = "." + ext;
        }
        if (ext.equals(LibraryType.JS.extension)) {
            return LibraryType.JS;
        } else if (ext.equals(LibraryType.CSS.extension)) {
            return LibraryType.CSS;
        } else {
            return null;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy