Exemplo n.º 1
0
  /**
   * Loads markup from a resource stream.
   *
   * @param container The original requesting markup container
   * @param markupResourceStream The markup resource stream to load
   * @param enforceReload The cache will be ignored and all, including inherited markup files, will
   *     be reloaded. Whatever is in the cache, it will be ignored
   * @return The markup. Markup.NO_MARKUP, if not found.
   */
  private final Markup loadMarkup(
      final MarkupContainer container,
      final MarkupResourceStream markupResourceStream,
      final boolean enforceReload) {
    String cacheKey = markupResourceStream.getCacheKey();
    String locationString = markupResourceStream.locationAsString();
    if (locationString == null) {
      // set the cache key as location string, because location string
      // couldn't be resolved.
      locationString = cacheKey;
    }

    Markup markup = MarkupFactory.get().loadMarkup(container, markupResourceStream, enforceReload);
    if (markup != null) {
      if (cacheKey != null) {
        String temp = markup.locationAsString();
        if (temp != null) {
          locationString = temp;
        }

        // add the markup to the cache.
        markupKeyCache.put(cacheKey, locationString);
        return putIntoCache(locationString, container, markup);
      }
      return markup;
    }

    // In case the markup could not be loaded (without exception) then ..
    if (cacheKey != null) {
      removeMarkup(cacheKey);
    }

    return Markup.NO_MARKUP;
  }
Exemplo n.º 2
0
 /** @throws Exception */
 @Test
 public void doctype_InheritedPage() throws Exception {
   executeTest(Doctype_1_InheritedPage.class, "DoctypeExpectedResult_1_Inherited.html");
   MarkupResourceStream rs =
       MarkupFactory.get().getMarkup(tester.getLastRenderedPage(), true).getMarkupResourceStream();
   assertEquals("html", rs.getDoctype());
   assertEquals(true, rs.isHtml5());
 }
Exemplo n.º 3
0
  @Override
  public final Markup getMarkup(
      final MarkupContainer container, final Class<?> clazz, final boolean enforceReload) {
    Class<?> containerClass = MarkupFactory.get().getContainerClass(container, clazz);

    // Get the cache key to be associated with the markup resource stream.
    // If the cacheKey returned == null, than caching is disabled for the resource stream.
    final String cacheKey =
        getMarkupCacheKeyProvider(container).getCacheKey(container, containerClass);

    // Is the markup already in the cache?
    Markup markup = null;
    if ((enforceReload == false) && (cacheKey != null)) {
      markup = getMarkupFromCache(cacheKey, container);
    }

    // If markup not found in cache or cache disabled, than ...
    if (markup == null) {
      if (log.isDebugEnabled()) {
        log.debug("Load markup: cacheKey=" + cacheKey);
      }

      // Get the markup resource stream for the container
      final MarkupResourceStream resourceStream =
          MarkupFactory.get().getMarkupResourceStream(container, containerClass);

      // Found markup?
      if (resourceStream != null) {
        resourceStream.setCacheKey(cacheKey);

        // load the markup and watch for changes
        markup = loadMarkupAndWatchForChanges(container, resourceStream, enforceReload);
      } else {
        markup = onMarkupNotFound(cacheKey, container, Markup.NO_MARKUP);
      }
    }

    // NO_MARKUP should only be used inside the Cache.
    if (markup == Markup.NO_MARKUP) {
      markup = null;
    }

    return markup;
  }
Exemplo n.º 4
0
 /** @throws Exception */
 @Test
 public void doctype_2() throws Exception {
   executeTest(Doctype_2.class, "DoctypeExpectedResult_2.html");
   MarkupResourceStream rs =
       MarkupFactory.get().getMarkup(tester.getLastRenderedPage(), true).getMarkupResourceStream();
   assertEquals(
       rs.getDoctype(),
       "html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"");
   assertEquals(false, rs.isHtml5());
 }