
com.adaptrex.core.view.ConfigComponent Maven / Gradle / Ivy
/*
* 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 com.adaptrex.core.Adaptrex;
import com.adaptrex.core.AdaptrexProperties;
import com.adaptrex.core.utilities.StringUtilities;
/**
* The ConfigComponent is used to initialize Adaptrex on a webpage. It is used by
* the various available presentation framework components to set up an Ext namespace,
* create a basic context object for the page, and initialize other settings used by
* other Adaptrex components.
*/
public class ConfigComponent {
public static final String ATTRIBUTE = "com.adaptrex.configcomponent";
private String namespace;
private String contextPath;
private String weblibPath;
private String extVersion;
private String extMode;
private String extPath;
private String extTheme;
// private String senchaTouchPath;
// private String senchaTouchVersion;
// private String senchaTouchTheme;
// private String senchaTouchMode;
private HttpServletRequest request;
private AdaptrexProperties properties;
private boolean touch;
private boolean isWritten = false;
public ConfigComponent(HttpServletRequest request, String namespace, Boolean touch) {
this.request = request;
this.contextPath = request.getContextPath();
properties = Adaptrex.get(request.getServletContext()).getProperties();
/*
* Check adaptrex properties for the default namespace
*/
this.namespace = namespace;
if (this.namespace == null) this.namespace = properties.get(AdaptrexProperties.EXT_NAMESPACE);
this.weblibPath = properties.get(AdaptrexProperties.WEBLIB_PATH, "weblib");
this.touch = touch != null && touch;
if (!this.touch) {
this.extPath = properties.get(AdaptrexProperties.EXT_PATH);
this.extVersion = properties.get(AdaptrexProperties.EXT_VERSION);
this.extMode = properties.get(AdaptrexProperties.EXT_MODE, "production");
this.extTheme = properties.get(AdaptrexProperties.EXT_THEME, "all");
} else {
// this.senchaTouchPath = properties.get(AdaptrexProperties.SENCHATOUCH_PATH);
// this.senchaTouchVersion = properties.get(AdaptrexProperties.SENCHATOUCH_VERSION);
// this.senchaTouchTheme = properties.get(AdaptrexProperties.SENCHATOUCH_MODE);
// this.senchaTouchMode = properties.get(AdaptrexProperties.SENCHATOUCH_THEME);
}
this.request.setAttribute(ConfigComponent.ATTRIBUTE, this);
};
public String getJavaScript() {
/*
* If we don't have any namespace, alert and drop out
*/
if (this.namespace == null) {
return StringUtilities.getErrorJavaScript(
"Adaptrex Configuration Error: Missing Ext application namespace", "",
"You must specify an Ext namespace for your application.",
"This can be configured in one of the following places: ",
" - adaptrex.properties: " + AdaptrexProperties.EXT_NAMESPACE + ": configures the Ext namespace for all pages",
" - Adaptrex config component: ns (or namespace): configure the Ext namespace for a single page"
);
}
String contextPath = this.contextPath;
String weblibPathOption = weblibPath;
/*
* Get the parent weblib folder. If the folder doesn't contain a slash, assume it's relative to our context
*/
String fullWeblibPath = weblibPathOption;
if (!fullWeblibPath.contains("/")) {
fullWeblibPath = contextPath + "/" + weblibPathOption;
}
StringBuilder output = new StringBuilder("\n");
if (!this.touch){
if (this.extVersion == null) {
return StringUtilities.getErrorJavaScript(
"Adaptrex Configuration Error: Missing Ext Version", "",
"You must specify an Ext version for your Ext (desktop) based applications.",
"This can be configured in one of the following places: ",
" - adaptrex.properties: " + AdaptrexProperties.EXT_VERSION + ": configures the Ext version for all pages",
" - Adaptrex config component: ext_version: configure the Ext version for a single page"
);
}
/*
* Get the path to our ext folder
*/
String extFolderPath;
if (this.extPath != null) {
if (this.extPath.startsWith("/")) {
extFolderPath = this.extPath;
} else {
extFolderPath = contextPath + "/" + this.extPath;
}
} else {
extFolderPath = fullWeblibPath + "/ext-" + this.extVersion;
}
/*
* Get the path to our ext bootstrap file and our ext theme
*/
String extFilePath = extFolderPath + "/ext" +
(this.extMode.equals("production") ? "" : "-" + this.extMode) + ".js";
String extThemePath;
if (this.extTheme.startsWith("/")) {
extThemePath = this.extTheme;
} else if (this.extTheme.contains("/")) {
extThemePath = contextPath + "/" + this.extTheme;
} else {
extThemePath = extFolderPath + "/resources/css/ext-" + this.extTheme + ".css";
}
/*
* Write our ext/adaptrex script tags
*/
output.append("\n");
output.append("\n");
if (this.extTheme.contains("neptune")) {
output.append("\n");
}
output.append("\n");
} else {
// String senchaTouchPathOption = getOption(this.senchaTouchPath, AdaptrexConfig.SENCHATOUCH_PATH, null);
// String senchaTouchVersionOption = getOption(this.senchaTouchVersion, AdaptrexConfig.SENCHATOUCH_VERSION, null);
/*
* Sencha Touch
*/
// if (senchaTouchPath != null) {
// output.append("\n");
// } else {
// output.append("\n");
// }
}
this.isWritten = true;
output.append("\n");
return output.toString();
}
public boolean isWritten() {
return this.isWritten;
}
public String getNamespace() {
return this.namespace;
}
public ConfigComponent applyWeblibPath(String weblibPath) {
if (weblibPath != null) this.weblibPath = weblibPath;
return this;
}
/*
* Ext Config
*/
public ConfigComponent applyExtVersion(String extVersion) {
if (extVersion != null) this.extVersion = extVersion;
return this;
}
public ConfigComponent applyExtTheme(String extTheme) {
if (extTheme != null) this.extTheme = extTheme;
return this;
}
public ConfigComponent applyExtPath(String extPath) {
if (extPath != null) this.extPath = extPath;
return this;
}
public ConfigComponent applyExtMode(String extMode) {
if (extMode != null) this.extMode = extMode;
return this;
}
public String getExtMode() {
return this.extMode;
}
public ConfigComponent applySenchaTouchVersion(String senchaTouchVersion) {
// this.senchaTouchVersion = senchaTouchVersion;
return this;
}
public ConfigComponent applySenchaTouchTheme(String senchaTouchTheme) {
// this.senchaTouchTheme = senchaTouchTheme;
return this;
}
public ConfigComponent applySenchaTouchPath(String senchaTouchPath) {
// this.senchaTouchPath = senchaTouchPath;
return this;
}
public ConfigComponent applySenchaTouchMode(String senchaTouchMode) {
// this.senchaTouchMode = senchaTouchMode;
return this;
}
public String getSenchaTouchMode() {
// return this.senchaTouchMode;
return null;
}
public boolean isTouch() {
return this.touch;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy