Package com.adaptrex.core.view

Source Code of com.adaptrex.core.view.ConfigComponent

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("<script type='text/javascript' src='" + contextPathOut + webLibPathOut + extPathOut + "'></script>\n");
        output.append("<link rel='stylesheet' type='text/css' href='" + contextPathOut + extThemeOut + "' />\n");
       
          if (extThemeOut.contains("neptune")) {
            output.append("<script type='text/javascript' src='" + contextPathOut + extFolder + "/ext-neptune.js'></script>\n");
        }
         
          output.append("<script type='text/javascript' src='" + contextPathOut + webLibPathOut + "/adaptrex-bootstrap-ext-" + extVersionOut + ".js'></script>\n");
      }     
    } else {
     
      /*
       * Sencha Touch
       */
      if (senchaTouchPathOut != null) {
        output.append("<script type='text/javascript' src='" + contextPathOut + senchaTouchPathOut + "/sdk/microloader/development.js'></script>\n");
      } else {
        output.append("<script type='text/javascript' src='sdk/microloader/development.js'></script>\n");
      }
    }

   
   
    output.append("<script type='text/javascript'>\n");
    output.append("Ext.ns('Adaptrex');\n");
    output.append("Adaptrex.Context={path:'" + contextPathOut + "'}\n");
    if (this.namespace != null) output.append("Ext.ns('" + this.namespace + "');\n");
    output.append("</script>\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;
  }
}
TOP

Related Classes of com.adaptrex.core.view.ConfigComponent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.