コード例 #1
0
 /**
  * Builds an expression manager.
  *
  * @param maps an array of maps of strings with the values of the properties.
  * @since 0.1.0
  */
 public ExpressionManager(Map<String, String>... maps) {
   final RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
   for (Map<String, String> map : maps) {
     interpolator.addValueSource(new MapBasedValueSource(map));
   }
   this.interpolator = interpolator;
 }
コード例 #2
0
  private Map<Object, Object> buildContext(ServletContext servletContext) {
    servletContext.log(
        "Loading plexus context properties from: '" + DEFAULT_PLEXUS_PROPERTIES + "'");

    Map<Object, Object> context = new HashMap<Object, Object>();

    String plexusPropertiesPath = servletContext.getInitParameter(PLEXUS_PROPERTIES_PARAM);

    if (plexusPropertiesPath == null) {
      plexusPropertiesPath = DEFAULT_PLEXUS_PROPERTIES;
    }

    try {
      URL url = servletContext.getResource(plexusPropertiesPath);

      // if the user has not specified the plexus.props file then just return the context
      if (url == null && plexusPropertiesPath == DEFAULT_PLEXUS_PROPERTIES) {
        return context;
      }

      Properties properties = PropertyUtils.loadProperties(url);

      if (properties == null) {
        throw new Exception("Could not locate url: " + url.toString());
      }

      String baseDir = servletContext.getRealPath("/WEB-INF");

      if (!StringUtils.isEmpty(baseDir)) {
        servletContext.log("Setting Plexus context variable " + PLEXUS_HOME + " to: " + baseDir);

        properties.put(PLEXUS_HOME, baseDir);
      } else {
        servletContext.log("CANNOT set Plexus basedir! (are we in unpacked WAR?)");
      }

      RegexBasedInterpolator ip = new RegexBasedInterpolator();

      ip.addValueSource(new MapBasedValueSource(properties));

      ip.addValueSource(new MapBasedValueSource(System.getProperties()));

      for (Enumeration n = properties.propertyNames(); n.hasMoreElements(); ) {
        String propertyKey = (String) n.nextElement();

        String propertyValue = ip.interpolate(properties.getProperty(propertyKey), "");

        servletContext.log("Added '" + propertyKey + "=" + propertyValue + "' to Plexus context.");

        context.put(propertyKey, propertyValue);
      }
    } catch (Exception e) {
      throw new RuntimeException(
          "Could not load plexus context properties from: '" + plexusPropertiesPath + "'", e);
    }

    return context;
  }