コード例 #1
0
ファイル: TeaServlet.java プロジェクト: jodiestjohn/teatrove
  @SuppressWarnings("unchecked")
  private void loadDefaults(PropertyMap properties, Set<String> files) throws Exception {
    // update substitutions if provided
    PropertyMap substitutions = properties.subMap("substitutions");
    if (substitutions != null && substitutions.size() > 0) {
      PropertyMap subs = SubstitutionFactory.getSubstitutions(substitutions, mResourceFactory);

      if (subs != null) {
        mSubstitutions.putAll(subs);
      }

      properties.remove("substitutions");
    }

    // Get file and perform substitution of env variables/system props
    String fileName = properties.getString("properties.file");
    if (mDebugEnabled) {
      mServletContext.log("properties.file: " + fileName);
    }

    if (fileName != null) {
      fileName = SubstitutionFactory.substitute(fileName, mSubstitutions);
    }

    // parse file if not yet parsed
    if (fileName != null && !files.contains(fileName)) {
      // Prevent properties file cycle.
      files.add(fileName);

      // load properties
      PropertyMap props = mResourceFactory.getResourceAsProperties(fileName);

      if (props != null) {
        properties.putAll(props);
      }

      loadDefaults(properties, files);
    } else {
      PropertyMap factoryProps = properties.subMap("properties.factory");
      if (factoryProps != null && factoryProps.size() > 0) {
        PropertyMap map = loadProperties(factoryProps);
        properties.putAll(map);
      }
    }
  }
コード例 #2
0
ファイル: TeaServlet.java プロジェクト: jodiestjohn/teatrove
  private PropertyMap loadProperties(PropertyMap factoryProps) throws Exception {

    String className = null;
    PropertyMapFactory factory = null;
    if (factoryProps != null
        && factoryProps.size() > 0
        && (className = factoryProps.getString("class")) != null) {
      if (mDebugEnabled) {
        mServletContext.log("Using property factory: " + className);
      }

      // Load and use custom PropertyMapFactory.
      Class<?> factoryClass = Class.forName(className);
      java.lang.reflect.Constructor<?> ctor = factoryClass.getConstructor(new Class[] {Map.class});
      factory = (PropertyMapFactory) ctor.newInstance(new Object[] {factoryProps.subMap("init")});
    } else if (factoryProps == null) {
      if (mDebugEnabled) {
        mServletContext.log("factoryProps is null.");
      }
    } else if (factoryProps.size() == 0) {
      if (mDebugEnabled) {
        mServletContext.log("factory props size is 0.");
      }
    } else {
      if (mDebugEnabled) {
        mServletContext.log("className is null");
      }
    }

    // return properties
    PropertyMap result = null;
    if (factory != null) {
      result = factory.createProperties();
      if (mDebugEnabled) {
        mServletContext.log("properties: " + result);
      }
    }
    return result;
  }