コード例 #1
0
  private String getContextPath(GrailsWebRequest webRequest, Map argMap) {
    Object cp = argMap.get(ARGUMENT_CONTEXTPATH);
    String contextPath = (cp != null ? cp.toString() : "");

    Object pluginName = argMap.get(ARGUMENT_PLUGIN);
    if (pluginName != null) {
      ApplicationContext applicationContext = webRequest.getApplicationContext();
      GrailsPluginManager pluginManager =
          (GrailsPluginManager) applicationContext.getBean(GrailsPluginManager.BEAN_NAME);
      GrailsPlugin plugin = pluginManager.getGrailsPlugin(pluginName.toString());
      if (plugin != null && !plugin.isBasePlugin()) contextPath = plugin.getPluginPath();
    }
    return contextPath;
  }
コード例 #2
0
  public void afterPropertiesSet() throws Exception {
    if (pluginManager != null && localResourceLoader != null) {
      GrailsPlugin[] plugins = pluginManager.getAllPlugins();
      for (GrailsPlugin plugin : plugins) {
        Resource[] pluginBundles;

        final String pluginName = plugin.getFileSystemName();
        pluginBundles = getPluginBundles(pluginName);
        for (Resource pluginBundle : pluginBundles) {
          String baseName = FilenameUtils.getBaseName(pluginBundle.getFilename());
          baseName = StringUtils.substringBefore(baseName, "_");
          pluginBaseNames.add(
              WEB_INF_PLUGINS_PATH.substring(1) + pluginName + "/grails-app/i18n/" + baseName);
        }
      }
    }
  }
コード例 #3
0
  @SuppressWarnings("rawtypes")
  @Override
  public GrailsClass getArtefactForFeature(Object featureId) {
    if (artefactInfo == null) {
      return null;
    }

    String uri;
    String pluginName = null;

    if (featureId instanceof Map) {
      Map featureIdMap = (Map) featureId;
      uri = (String) featureIdMap.get("uri");
      pluginName = (String) featureIdMap.get("pluginName");
    } else {
      uri = featureId.toString();
    }

    GrailsClass controllerClass = uriToControllerClassCache.get(uri);
    if (controllerClass == null) {
      final ApplicationContext mainContext = grailsApplication.getMainContext();
      GrailsPluginManager grailsPluginManager = null;
      if (mainContext.containsBean(GrailsPluginManager.BEAN_NAME)) {
        final Object pluginManagerBean = mainContext.getBean(GrailsPluginManager.BEAN_NAME);
        if (pluginManagerBean instanceof GrailsPluginManager) {
          grailsPluginManager = (GrailsPluginManager) pluginManagerBean;
        }
      }
      final GrailsClass[] controllerClasses = artefactInfo.getGrailsClasses();
      // iterate in reverse in order to pick up application classes first
      for (int i = (controllerClasses.length - 1); i >= 0; i--) {
        GrailsClass c = controllerClasses[i];
        if (((GrailsControllerClass) c).mapsToURI(uri)) {
          boolean foundController = false;
          if (pluginName != null && grailsPluginManager != null) {
            final GrailsPlugin pluginForClass = grailsPluginManager.getPluginForClass(c.getClazz());
            if (pluginForClass != null && pluginName.equals(pluginForClass.getName())) {
              foundController = true;
            }
          } else {
            foundController = true;
          }
          if (foundController) {
            controllerClass = c;
            break;
          }
        }
      }
      if (controllerClass == null) {
        controllerClass = NO_CONTROLLER;
      }

      // don't cache for dev environment
      if (Environment.getCurrent() != Environment.DEVELOPMENT) {
        uriToControllerClassCache.put(uri, controllerClass);
      }
    }

    if (controllerClass == NO_CONTROLLER) {
      controllerClass = null;
    }
    return controllerClass;
  }