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

com.adaptrex.core.view.BootstrapComponent Maven / Gradle / Ivy

There is a newer version: 1.0-Alpha3
Show newest version
/*
 * Copyright 2012 Adaptrex, LLC
 *
 * 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 com.adaptrex.core.view;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

import com.adaptrex.core.Adaptrex;
import com.adaptrex.core.AdaptrexProperties;

public class BootstrapComponent {

	private String env;
	private HttpServletRequest request;
	private AdaptrexProperties properties;
	
	public BootstrapComponent(HttpServletRequest request) {
		ConfigComponent configComponent = ((ConfigComponent) request.getAttribute(ConfigComponent.ATTRIBUTE));
		this.env = configComponent.getEnv();
		this.request = request;
		this.properties = Adaptrex.get(request.getServletContext()).getProperties();
	};
	
	public String getJavaScript() {
		boolean debug = properties.get(AdaptrexProperties.DEBUG, "false").equals("true");
		
		String appsrc = "build/app-all" + (debug ? "-debug" : "") + ".js";
		if (!this.env.equals("production")) {
			appsrc = "app.js";
		}
		
		String appPath = request.getRequestURI();
		
		/*
		 * If the URI ends with an index.* file, strip the /index.* to get the path to the folder
		 */
		if (appPath.contains("index.")) appPath = appPath.split("index\\.")[0];
		
		/*
		 * If the URI doesn't end in a slash, add the trailing slash to set the root for the js folders
		 */
		if (!appPath.endsWith("/")) appPath += "/";
		
		/*
		 * If our page is @ the context root, serve app.js from the "index" folder
		 */
		if (appPath.equals(request.getContextPath() + "/")) appPath += "index/";
		
		return "\n";
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy