com.adaptrex.core.view.BootstrapComponent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of adaptrex-core Show documentation
Show all versions of adaptrex-core Show documentation
The Core Adaptrex Framework
/*
* 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