Package ch.entwine.weblounge.common.site

Examples of ch.entwine.weblounge.common.site.Module


    String identifier = XPathHelper.valueOf(config, "@id", xpathProcessor);
    if (identifier == null)
      throw new IllegalStateException("Unable to create module without identifier");

    // class
    Module module = null;
    String className = XPathHelper.valueOf(config, "m:class", xpathProcessor);
    if (className != null) {
      try {
        Class<? extends Module> c = (Class<? extends Module>) classLoader.loadClass(className);
        module = c.newInstance();
        module.setIdentifier(identifier);
      } catch (ClassNotFoundException e) {
        throw new IllegalStateException("Implementation " + className + " for module '" + identifier + "' not found", e);
      } catch (InstantiationException e) {
        throw new IllegalStateException("Error instantiating impelementation " + className + " for module '" + identifier + "'", e);
      } catch (IllegalAccessException e) {
        throw new IllegalStateException("Access violation instantiating implementation " + className + " for module '" + identifier + "'", e);
      } catch (Throwable t) {
        throw new IllegalStateException("Error loading implementation " + className + " for module '" + identifier + "'", t);
      }
    } else {
      module = new ModuleImpl();
      module.setIdentifier(identifier);
    }
   
    // Check if module is enabled
    Boolean enabled = Boolean.valueOf(XPathHelper.valueOf(config, "m:enable", xpathProcessor));
    module.setEnabled(enabled);
   
    // name
    String name = XPathHelper.valueOf(config, "m:name", xpathProcessor);
    module.setName(name);

    // pagelets
    NodeList pageletNodes = XPathHelper.selectList(config, "m:pagelets/m:pagelet", xpathProcessor);
    for (int i = 0; i < pageletNodes.getLength(); i++) {
      PageletRenderer pagelet = PageletRendererImpl.fromXml(pageletNodes.item(i), xpathProcessor);
      module.addRenderer(pagelet);
    }

    // actions
    NodeList actionNodes = XPathHelper.selectList(config, "m:actions/m:action", xpathProcessor);
    for (int i = 0; i < actionNodes.getLength(); i++) {
      module.addAction(ActionSupport.fromXml(actionNodes.item(i), xpathProcessor));
    }

    // image styles
    NodeList imagestyleNodes = XPathHelper.selectList(config, "m:imagestyles/m:imagestyle", xpathProcessor);
    for (int i = 0; i < imagestyleNodes.getLength(); i++) {
      module.addImageStyle(ImageStyleImpl.fromXml(imagestyleNodes.item(i), xpathProcessor));
    }

    // jobs
    NodeList jobNodes = XPathHelper.selectList(config, "m:jobs/m:job", xpathProcessor);
    for (int i = 0; i < jobNodes.getLength(); i++) {
      module.addJob(QuartzJob.fromXml(jobNodes.item(i), xpathProcessor));
    }

    // options
    Node optionsNode = XPathHelper.select(config, "m:options", xpathProcessor);
    OptionsHelper.fromXml(optionsNode, module, xpathProcessor);
View Full Code Here


   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(Object obj) {
    if (obj != null && obj instanceof Module) {
      Module m = (Module) obj;
      if (identifier == null || m.getIdentifier() == null || !identifier.equals(m.getIdentifier()))
        return false;
      if (site == null && m.getSite() != null)
        return false;
      if (site != null && !site.equals(m.getSite()))
        return false;
      return true;
    }
    return false;
  }
View Full Code Here

        // We need the module id even if the module initialization fails to log
        // a proper error message
        Node moduleNode = moduleXml.getFirstChild();
        String moduleId = moduleNode.getAttributes().getNamedItem("id").getNodeValue();

        Module module;
        try {
          module = ModuleImpl.fromXml(moduleNode);
          logger.debug("Module '{}' loaded for site '{}'", module, this);
        } catch (Throwable t) {
          logger.error("Error loading module '{}' of site {}", moduleId, identifier);
          if (t instanceof Exception)
            throw (Exception) t;
          throw new Exception(t);
        }

        // If module is disabled, don't add it to the site
        if (!module.isEnabled()) {
          logger.info("Found disabled module '{}' in site '{}'", module, this);
          continue;
        }

        // Make sure there is only one module with this identifier
        if (modules.containsKey(module.getIdentifier())) {
          logger.warn("A module with id '{}' is already registered in site '{}'", module.getIdentifier(), identifier);
          logger.error("Module '{}' is not registered due to conflicting identifier", module.getIdentifier());
          continue;
        }

        // Check inter-module compatibility
        for (Module m : modules.values()) {

          // Check actions
          for (Action a : m.getActions()) {
            for (Action action : module.getActions()) {
              if (action.getIdentifier().equals(a.getIdentifier())) {
                logger.warn("Module '{}' of site '{}' already defines an action with id '{}'", new String[] {
                    m.getIdentifier(),
                    identifier,
                    a.getIdentifier() });
              } else if (action.getPath().equals(a.getPath())) {
                logger.warn("Module '{}' of site '{}' already defines an action at '{}'", new String[] {
                    m.getIdentifier(),
                    identifier,
                    a.getPath() });
                logger.error("Module '{}' of site '{}' is not registered due to conflicting mountpoints", m.getIdentifier(), identifier);
                continue;
              }
            }
          }

          // Check image styles
          for (ImageStyle s : m.getImageStyles()) {
            for (ImageStyle style : module.getImageStyles()) {
              if (style.getIdentifier().equals(s.getIdentifier())) {
                logger.warn("Module '{}' of site '{}' already defines an image style with id '{}'", new String[] {
                    m.getIdentifier(),
                    identifier,
                    s.getIdentifier() });
              }
            }
          }

          // Check jobs
          for (Job j : m.getJobs()) {
            for (Job job : module.getJobs()) {
              if (job.getIdentifier().equals(j.getIdentifier())) {
                logger.warn("Module '{}' of site '{}' already defines a job with id '{}'", new String[] {
                    m.getIdentifier(),
                    identifier,
                    j.getIdentifier() });
View Full Code Here

   * @see ch.entwine.weblounge.common.site.Site#removeModule(java.lang.String)
   */
  public Module removeModule(String module) throws ModuleException {
    if (module == null)
      throw new IllegalArgumentException("Module must not be null");
    Module m = modules.remove(module);
    if (m != null)
      m.destroy();
    return m;
  }
View Full Code Here

      Set<PageletRenderer> previewRenderers = new HashSet<PageletRenderer>();
      if (stage != null) {
        for (Pagelet p : stage) {

          // Load the pagelet's module
          Module m = site.getModule(p.getModule());
          if (m == null) {
            logger.warn("Skipping pagelet '{}' for preview calculation: module '{}' can't be found", p, p.getModule());
            continue;
          }

          // Load the pagelet's renderer
          PageletRenderer r = m.getRenderer(p.getIdentifier());
          if (r == null) {
            logger.warn("Skipping pagelet '{}' for preview calculation: pagelet renderer '{}' can't be found", p, p.getIdentifier());
            continue;
          }
View Full Code Here

      return null;
    }

    // Try to get hold of the weblounge module
    Site site = resource.getURI().getSite();
    Module webloungeModule = site.getModule(Site.WEBLOUNGE_MODULE);
    if (webloungeModule == null) {
      logger.debug("Unable to return pagelet renderer for {}: weblounge module not present", resource);
      return null;
    }

    // Try to get hold of the renderer
    String rendererId = getType() + "-result";
    PageletRenderer renderer = webloungeModule.getRenderer(rendererId);
    if (renderer == null) {
      logger.debug("Unable to return pagelet renderer for {}: renderer '{}' not present in weblounge module", resource, rendererId);
      return null;
    }
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.site.Module

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.