示例#1
0
  /**
   * Load the component's configuration data. Implementations should override this method if they
   * require configuration. If an implementation does override this method the implementation should
   * call <code>super.loadConfiguration(configuration)</code> first.
   *
   * @param configuration The configuration data
   * @throws ConfigurationException
   */
  public void loadConfiguration(Configuration configuration) throws ConfigurationException {
    // Load the ViewRenderer for this component
    Configuration viewRendererConfiguration = configuration.getChild("view-renderer");
    if (viewRendererConfiguration != null) {
      String viewRendererClass = viewRendererConfiguration.getAttribute("classname");

      try {
        viewRenderer = (ViewRenderer) ClassUtilities.loadClass(viewRendererClass).newInstance();
        viewRenderer.setSiteContext(siteContext);
      } catch (Exception e) {
        throw new ConfigurationException("Error loading view renderer: " + e.getMessage(), e);
      }
      viewRenderer.loadConfiguration(viewRendererConfiguration);
      try {
        viewRenderer.init();
      } catch (Exception e) {
        throw new ConfigurationException("Error initializing view renderer: " + e.getMessage(), e);
      }
    }

    if (viewRenderer == null) {
      viewRenderer = siteContext.getViewRenderer();
    }

    // Select the repository to use
    Configuration repositoryConfiguration = configuration.getChild("repository");
    if (repositoryConfiguration != null) {
      String name = repositoryConfiguration.getAttribute("name");
      if (name == null) {
        throw new ConfigurationException(getName() + ": the repository name attribute required");
      } else {
        if (log.isDebugEnabled()) log.debug("Using repository name: " + name);
        viewRepository = siteContext.getRepository(name);
        if (viewRepository == null) {
          throw new ConfigurationException(
              "View repository must be specified for component " + getName());
        }
      }
    } else {
      log.warn(getName() + ": the repository configuration element not found");
    }
  }