Package com.adaptrex.core.ext.jsf

Source Code of com.adaptrex.core.ext.jsf.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.ext.jsf;

import com.adaptrex.core.Adaptrex;
import com.adaptrex.core.config.AdaptrexConfig;
import java.io.IOException;
import java.util.Map;
import javax.faces.component.FacesComponent;
import javax.faces.context.FacesContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@FacesComponent("ext.data.Config")
public class ConfigComponent extends ExtComponentBase {

  private static Logger log = LoggerFactory.getLogger(ConfigComponent.class);
 
  @Override
  public String getFamily() {
    return "ext.data.config";
  }

    @SuppressWarnings("unchecked")
  @Override
    public void encodeBegin(FacesContext context) throws IOException {
      try {
      Adaptrex adaptrex = Adaptrex.getAdaptrex();
     
      AdaptrexConfig config = adaptrex.getConfig();
          Map<String,Object> tagAttr = getAttributes();
       
      String contextPath = context.getExternalContext().getRequestContextPath();
      if (contextPath.isEmpty()) contextPath = "/";

      /*
       * Weblib path
       */
      String weblibPath = (String) tagAttr.get(AdaptrexConfig.WEBLIB);
      if (weblibPath == null) weblibPath = config.get(AdaptrexConfig.WEBLIB);
     
          /*
           * If we're configuring Ext, do it here
           */
      String extBuild = (String) tagAttr.get(AdaptrexConfig.EXT_BUILD);
      if (extBuild == null) extBuild = config.get(AdaptrexConfig.EXT_BUILD, "production");     
     
     
      String extPath = (String) tagAttr.get(AdaptrexConfig.EXT_PATH);       
      if (extPath == null) extPath = config.get(AdaptrexConfig.EXT_PATH);
      if (extPath == null) {
        String extVersion = (String) tagAttr.get(AdaptrexConfig.EXT_VERSION);
        if (extVersion == null) extVersion = config.get(AdaptrexConfig.EXT_VERSION);
       
        if (extVersion != null) {
          extPath = weblibPath + "/extjs-" + extVersion + "/ext" + (extBuild.equals("production") ? "" : "-" + extBuild) + ".js";
        }
      }
     
      if (extPath != null) {
        write("<script type='text/javascript' src='" + contextPath + extPath + "'></script>");
        String extFolder = extPath.substring(0, extPath.lastIndexOf("/"));
       
        String theme = (String) tagAttr.get(AdaptrexConfig.EXT_THEME);
        if (theme == null) theme = config.get(AdaptrexConfig.EXT_THEME, "all");
        if (!theme.contains("/")) {
          theme = extFolder + "/resources/css/ext-" + theme + ".css";
        }
       
        write("<link rel='stylesheet' type='text/css' href='" + contextPath + theme + "' />");
       
            if (theme.contains("neptune")) {
            write("<script type='text/javascript' src='" + contextPath + extFolder + "/ext-neptune.js'></script>");
          }
       
         if (!extBuild.equals("production")) {
          write("<script type='text/javascript' src='app.js'></script>");
         }       
      }

         
         
              /*
               * Set up adaptrex loader if we're in debug mode
               */
          String adaptrexFolder = contextPath + weblibPath + "/adaptrexjs";
          write("<script type='text/javascript' src='" + adaptrexFolder + "/adaptrex.js'></script>");
          write("<script type='text/javascript'>Adaptrex.Context={path:'" + contextPath + "'}</script>");
          if (config.get(AdaptrexConfig.DEBUG).equals("true")) {
            write("<script type='text/javascript'>" +
                "Ext.Loader.setPath('Adaptrex', '" + adaptrexFolder + "/src')</script>");
          }

//
//         if (tagAttr.get("touch") != null) {
//           setAttribute("touch", Boolean.parseBoolean((String) tagAttr.get("touch")));
//         } else {
//           setAttribute("touch", false);
//         }

     
          /*
           * Set up namespace
           */
          String namespace = (String) tagAttr.get(AdaptrexConfig.EXT_NAMESPACE);
      if (namespace == null) namespace = (String) tagAttr.get("ns");
      if (namespace == null) namespace = (String) tagAttr.get("namespace");
      if (namespace == null) namespace = config.get(AdaptrexConfig.EXT_NAMESPACE);
          if (namespace != null) {
            setAttribute("namespace", namespace);
          }
     
      } catch (Exception e) {
        log.warn("Error", e);
      }
    }
}
TOP

Related Classes of com.adaptrex.core.ext.jsf.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.