Package com.adaptrex.core.view

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

/*
* 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.AdaptrexConfig;
import com.adaptrex.core.AdaptrexRegistry;

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;
 
  private HttpServletRequest request;
 
  public ConfigComponent(HttpServletRequest request) {
    this(request, null);
  };
 
  public ConfigComponent(HttpServletRequest request, String namespace) {
    this.request = request;
    this.contextPath = request.getContextPath();
    this.setNamespace(namespace);
  };
 
  public String toString() {
    AdaptrexConfig config = AdaptrexRegistry.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 setNamespace(String namespace) {
    this.namespace = namespace;
    if (namespace != null) {
      request.setAttribute("adaptrex_namespace", namespace);
    }
    return this;
  }
 
//  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 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;
    if (touch) {
      request.setAttribute("adaptrex_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.