Ejemplo n.º 1
0
  /**
   * Internal method which can be used by subclasses to pass the view through the component's view
   * renderer.
   *
   * @param text The raw view
   * @param context The context
   * @param path render the View at the given path
   * @return The merged view
   * @throws Exception if errors are encountered at the rendering process time
   */
  protected String renderView(String text, String path, JPublishContext context) throws Exception {

    ViewRenderer viewRenderer = getViewRenderer();
    StringWriter out = new StringWriter();
    viewRenderer.render(context, path, new StringReader(text), out);
    return out.toString();
  }
Ejemplo n.º 2
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");
    }
  }