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

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

There is a newer version: 1.0-Alpha3
Show newest version
package com.adaptrex.core.view;

import javax.servlet.http.HttpServletRequest;

import com.adaptrex.core.AdaptrexConfig;
import com.adaptrex.core.services.AdaptrexServices;

public class ConfigComponent {

	private String contextPath;
	private String weblibPath;
	private String extVersion;
	private String extBuild;
	private String extPath;
	private String extTheme;
	
	private String senchaTouchPath;
	private String senchaTouchVersion;
	private boolean touch = false;
	
	private String namespace;
	
	public ConfigComponent(HttpServletRequest request) {
		this.contextPath = request.getContextPath();
	};
	
	public String toString() {
		AdaptrexConfig config = AdaptrexServices.getConfig();
		
		StringBuilder output = new StringBuilder("\n");
		
		String contextPathOut = this.contextPath;
		
		String extVersionOut = this.extVersion;
		if (extVersionOut == null) extVersionOut = config.get(AdaptrexConfig.EXT_VERSION);
		
		String extBuildOut = this.extBuild;
		if (extBuildOut == null) extBuildOut = config.get(AdaptrexConfig.EXT_BUILD, "production");
		
		String webLibPathOut = this.weblibPath;
		if (webLibPathOut == null) webLibPathOut = config.get(AdaptrexConfig.WEBLIB, "lib");
		
		String senchaTouchVersionOut = this.senchaTouchVersion;
		if (senchaTouchVersionOut == null) senchaTouchVersionOut = config.get(AdaptrexConfig.SENCHATOUCH_VERSION);

		String senchaTouchPathOut = this.senchaTouchPath;
		if (senchaTouchPathOut == null) senchaTouchPathOut = config.get(AdaptrexConfig.SENCHATOUCH_PATH);
		
		
		if (!this.touch){
			/*
			 * Ext Desktop
			 */
			String extPathOut = this.extPath;
			if (extPathOut == null) extPathOut = config.get(AdaptrexConfig.EXT_PATH);
			if (extPathOut == null && extVersionOut != null) {
				extPathOut = "/extjs-" + extVersionOut + "/ext" + (extBuildOut.equals("production") ? "" : "-" + extBuildOut) + ".js";
			}
			
			String extThemeOut = null;
			String extFolder = null;
			if (extPathOut != null) {
				extFolder = extPathOut.substring(0, extPathOut.lastIndexOf("/"));
				
				extThemeOut = this.extTheme;
				if (extThemeOut == null) extThemeOut = config.get(AdaptrexConfig.EXT_THEME, "all");
				if (!extThemeOut.contains("/")) {
					extThemeOut = extFolder + "/resources/css/ext-" + extThemeOut + ".css";
				}	
			}
			
			/*
			 * Write ext bootstrap code
			 */
			if (extPathOut != null) {
				output.append("\n");
				output.append("\n");
				
	    		if (extThemeOut.contains("neptune")) {
	    			output.append("\n");
				}
	    		
	    		output.append("\n");
			}			
		} else {
			
			/*
			 * Sencha Touch
			 */
			if (senchaTouchPathOut != null) {
				output.append("\n");
			} else {
				output.append("\n");
			}
		}

		
		
		output.append("\n");
		
		return output.toString();
	}
	
	public ConfigComponent setContextPath(String contextPath) {
		this.contextPath = contextPath;
		return this;
	}
	
	public ConfigComponent setWeblibPath(String weblibPath) {
		this.weblibPath = weblibPath;
		return this;
	}
	
	public ConfigComponent setExtVersion(String extVersion) {
		this.extVersion = extVersion;
		return this;
	}
	
	public ConfigComponent setExtBuild(String extBuild) {
		this.extBuild = extBuild;
		return this;
	}
	
	public ConfigComponent setExtPath(String extPath) {
		this.extPath = extPath;
		return this;
	}
	
	public ConfigComponent setNamespace(String namespace) {
		this.namespace = namespace;
		return this;
	}
	
	public ConfigComponent setExtTheme(String extTheme) {
		this.extTheme = extTheme;
		return this;
	}

	
	public ConfigComponent setSenchaTouchVersion(String senchaTouchVersion) {
		this.senchaTouchVersion = senchaTouchVersion;
		return this;
	}
	
	public ConfigComponent setSenchaTouchPath(String senchaTouchPath) {
		this.senchaTouchPath = senchaTouchPath;
		return this;
	}
	
	public ConfigComponent setTouch(boolean touch) {
		this.touch = touch;
		return this;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy