Ejemplo n.º 1
0
  /**
   * Get an InputStream so that the Runtime can build a template with it.
   *
   * @param name name of template
   * @return InputStream containing template
   */
  public InputStream getResourceStream(String name) throws ResourceNotFoundException {

    logger.debug("Looking for: " + name);

    if (name == null || name.length() == 0) {
      throw new ResourceNotFoundException("Need to specify a template name!");
    }

    // theme templates name are <template>|<deviceType>
    String deviceType = "standard";
    if (name.contains("|")) {
      String[] pair = name.split("\\|");
      name = pair[0];
      deviceType = pair[1];
    }

    logger.debug("   Actually, it's " + name);

    try {
      WeblogTemplate page = WebloggerFactory.getWeblogger().getWeblogManager().getPage(name);

      if (page == null) {
        throw new ResourceNotFoundException(
            "RollerResourceLoader: page \"" + name + "\" not found");
      }
      String contents;
      TemplateCode templateCode = page.getTemplateCode(deviceType);
      if (templateCode != null) {
        contents = templateCode.getTemplate();
      } else {
        contents = page.getContents();
      }
      return new ByteArrayInputStream(contents.getBytes("UTF-8"));

    } catch (UnsupportedEncodingException uex) {
      // This should never actually happen. We expect UTF-8 in all JRE
      // installation.
      // This rethrows as a Runtime exception after logging.
      logger.error(uex);
      throw new RuntimeException(uex);

    } catch (Exception re) {
      String msg =
          "RollerResourceLoader Error: " + "database problem trying to load resource " + name;
      logger.error(msg, re);
      throw new ResourceNotFoundException(msg);
    }
  }
Ejemplo n.º 2
0
  public static void invalidate(WeblogTemplate template) {

    log.debug("invalidating template = " + template.getId());

    Iterator handlers = cacheHandlers.iterator();
    while (handlers.hasNext()) {
      ((CacheHandler) handlers.next()).invalidate(template);
    }
  }