public StringResourceRepository createRepository(final String className, final String encoding) {
    if (log.isDebugEnabled()) {
      log.debug("Creating string repository using class " + className + "...");
    }

    StringResourceRepository repo;
    try {
      repo = (StringResourceRepository) ClassUtils.getNewInstance(className);
    } catch (ClassNotFoundException cnfe) {
      throw new VelocityException("Could not find '" + className + "'", cnfe);
    } catch (IllegalAccessException iae) {
      throw new VelocityException("Could not access '" + className + "'", iae);
    } catch (InstantiationException ie) {
      throw new VelocityException("Could not instantiate '" + className + "'", ie);
    }

    if (encoding != null) {
      repo.setEncoding(encoding);
    } else {
      repo.setEncoding(REPOSITORY_ENCODING_DEFAULT);
    }

    if (log.isDebugEnabled()) {
      log.debug("Default repository encoding is " + repo.getEncoding());
    }
    return repo;
  }
Beispiel #2
0
  /**
   * Add objects to the context from the current properties.
   *
   * @param context control context to fill with objects that are specified in the
   *     default.properties file
   */
  protected void fillContextProperties(Context context) {
    Enumeration enumeration = props.propertyNames();

    while (enumeration.hasMoreElements()) {
      String nm = (String) enumeration.nextElement();
      if (nm.startsWith("context.objects.")) {

        String contextObj = props.getProperty(nm);
        int colon = nm.lastIndexOf('.');
        String contextName = nm.substring(colon + 1);

        try {
          Object o = ClassUtils.getNewInstance(contextObj);
          context.put(contextName, o);
        } catch (Exception e) {
          e.printStackTrace();
          // TO DO: Log Something Here
        }
      }
    }
  }