Пример #1
0
  public XMLDOMLayout getXMLDOMLayoutCacheByMarkup(
      String markup,
      String itsNatServerVersion,
      XMLDOMLayoutParser.LayoutType layoutType,
      XMLDOMParserContext xmlDOMParserContext) {
    // Este método DEBE ser multihilo, el objeto layoutCacheByMarkup ya lo es.
    // No pasa nada si por una rarísima casualidad dos Layout idénticos hacen put, quedará el
    // último, ten en cuenta que esto
    // es un caché.

    // Extraemos el markup sin el script de carga porque dos páginas generadas "iguales" SIEMPRE
    // serán diferentes a nivel
    // de markup en el loadInitScript porque el id cambia y algún token aleatorio, sin el
    // loadInitScript podemos conseguir
    // muchos más aciertos de cacheo y acelerar un montón al tener el parseo ya hecho.
    // Si el template no es generado por ItsNat server o bien el scripting está desactivado
    // (itsNatServerVersion puede
    // ser no null pues es un header), loadInitScript será null y no pasa nada markupNoLoadScript[0]
    // es el markup original
    String[] markupWithoutLoadScript = new String[1];
    String loadScript = null;
    if (itsNatServerVersion != null && layoutType == XMLDOMLayoutParser.LayoutType.PAGE)
      loadScript = XMLDOMLayout.extractLoadScriptMarkup(markup, markupWithoutLoadScript);
    else markupWithoutLoadScript[0] = markup;

    XMLDOMLayout cachedXMLDOMLayout = layoutCacheByMarkup.get(markupWithoutLoadScript[0]);
    if (cachedXMLDOMLayout == null) {
      XMLDOMLayoutParser layoutParser =
          XMLDOMLayoutParser.createXMLDOMLayoutParser(
              itsNatServerVersion, layoutType, xmlDOMParserContext);
      cachedXMLDOMLayout = layoutParser.createXMLDOMLayout();
      layoutCacheByMarkup.put(
          markupWithoutLoadScript[0],
          cachedXMLDOMLayout); // Cacheamos cuanto antes pues puede haber recursividad

      layoutParser.parse(markup, cachedXMLDOMLayout);
      if (cachedXMLDOMLayout instanceof XMLDOMLayoutPageItsNat)
        ((XMLDOMLayoutPageItsNat) cachedXMLDOMLayout)
            .setLoadInitScript(
                null); // Que quede claro que no se puede utilizar directamente en el cacheado
      // guardado

    } else // cachedDOMLayout != null
    {
      // Recuerda que cachedDOMLayout devuelto tiene el timestamp actualizado por el hecho de llamar
      // al get()
    }

    XMLDOMLayout clonedDOMLayout =
        cachedXMLDOMLayout
            .partialClone(); // Necesitamos un clone parcial porque el loadInitScript necesitamos
    // alojarlo en un objeto nuevo pues no puede cachearse
    if (clonedDOMLayout instanceof XMLDOMLayoutPageItsNat)
      ((XMLDOMLayoutPageItsNat) clonedDOMLayout).setLoadInitScript(loadScript);
    return clonedDOMLayout;
  }
Пример #2
0
  public XMLDOMAnimator getXMLDOMAnimatorCacheByMarkup(
      String markup, ResourceDescDynamic resourceDesc, XMLDOMParserContext xmlDOMParserContext) {
    // Ver notas de getXMLDOMLayoutCacheByMarkup()
    String resourceDescValue = resourceDesc.getResourceDescValue();
    if (animatorCacheByResDescValue.get(resourceDescValue) == null)
      animatorCacheByResDescValue.put(
          resourceDescValue,
          resourceDesc); // Lo hacemos antes de animatorCacheByMarkup.get() de esta manera cacheamos
    // también en el caso raro de dos archivos con el mismo markup, por otra
    // parte en el caso de que ya exista se actualiza el timestamp del recurso
    // al hacer el get (recurso recientemente usado)

    XMLDOMAnimator cachedXMLDOMAnimator = animatorCacheByMarkup.get(markup);
    if (cachedXMLDOMAnimator != null) return cachedXMLDOMAnimator;

    cachedXMLDOMAnimator = new XMLDOMAnimator();
    animatorCacheByMarkup.put(
        markup, cachedXMLDOMAnimator); // Cacheamos cuanto antes pues puede haber recursividad

    XMLDOMAnimatorParser parser =
        XMLDOMAnimatorParser.createXMLDOMAnimatorParser(xmlDOMParserContext);
    parser.parse(markup, cachedXMLDOMAnimator);
    return cachedXMLDOMAnimator;
  }
Пример #3
0
  public XMLDOMDrawable getXMLDOMDrawableCacheByMarkup(
      String markup, XMLDOMParserContext xmlDOMParserContext) {
    // Ver notas de getXMLDOMLayoutCacheByMarkup()
    XMLDOMDrawable cachedXMLDOMDrawable = drawableCacheByMarkup.get(markup);
    if (cachedXMLDOMDrawable != null) return cachedXMLDOMDrawable;

    cachedXMLDOMDrawable = new XMLDOMDrawable();
    drawableCacheByMarkup.put(
        markup, cachedXMLDOMDrawable); // Cacheamos cuanto antes pues puede haber recursividad

    XMLDOMDrawableParser parser =
        XMLDOMDrawableParser.createXMLDOMDrawableParser(xmlDOMParserContext);
    parser.parse(markup, cachedXMLDOMDrawable);
    return cachedXMLDOMDrawable;
  }
Пример #4
0
  public XMLDOMValues getXMLDOMValuesCacheByMarkup(
      String markup, XMLDOMParserContext xmlDOMParserContext) {
    // Ver notas de getXMLDOMLayoutCacheByMarkup()
    XMLDOMValues cachedXMLDOMValues = valuesCacheByMarkup.get(markup);
    if (cachedXMLDOMValues != null) {
      // System.out.println("CACHED cachedXMLDOMValues");
      return cachedXMLDOMValues;
    }

    cachedXMLDOMValues = new XMLDOMValues();
    valuesCacheByMarkup.put(
        markup, cachedXMLDOMValues); // Cacheamos cuanto antes pues puede haber recursividad

    XMLDOMValuesParser parser = XMLDOMValuesParser.createXMLDOMValuesParser(xmlDOMParserContext);
    parser.parse(markup, cachedXMLDOMValues);
    return cachedXMLDOMValues;
  }
  @Before
  public void mockResourcePersister() {
    duplicationCache = mock(DuplicationCache.class);

    ResourceCache resourceCache = mock(ResourceCache.class);
    BatchResource batchResource = mock(BatchResource.class);
    when(batchResource.resource()).thenReturn(aFile);
    when(batchResource.snapshotId()).thenReturn(FILE_SNAPSHOT_ID);
    when(resourceCache.get("foo:org/foo/Bar.java")).thenReturn(batchResource);

    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.findByKey(CoreMetrics.DUPLICATIONS_DATA_KEY))
        .thenReturn(CoreMetrics.DUPLICATIONS_DATA.setId(2));

    duplicationPersister =
        new DuplicationPersister(
            getMyBatis(), ruleFinder, resourceCache, duplicationCache, metricFinder);
  }
Пример #6
0
 public ResourceDescDynamic getAnimatorResourceDescDynamicCacheByResourceDescValue(
     String resourceDescValue) {
   return animatorCacheByResDescValue.get(resourceDescValue);
 }
Пример #7
0
  /**
   * Loads, parses and returns the resource of the specified URI, or null if not found. The parser
   * is defined by the loader defined in {@link ResourceCache}.
   *
   * @param cache the resource cache. Note: its loader must extend from {@link ResourceLoader}.
   * @param path the URI path
   * @param extra the extra parameter that will be passed to {@link
   *     ResourceLoader#parse(String,File,Object)} and {@link
   *     ResourceLoader#parse(String,URL,Object)}
   */
  public static final <V> V get(
      ResourceCache<V> cache, ServletContext ctx, String path, Object extra) {
    // 20050905: Tom Yeh
    // We don't need to handle the default name if user specifies only a dir
    // because it is handled by the container directly
    // And, web  developer has to specify <welcome-file> in web.xml
    URL url = null;
    if (path == null || path.length() == 0) path = "/";
    else if (path.charAt(0) != '/') {
      if (path.indexOf("://") > 0) {
        try {
          url = new URL(path);
        } catch (java.net.MalformedURLException ex) {
          throw new SystemException(ex);
        }
      } else path = '/' + path;
    }

    if (url == null) {
      if (path.startsWith("/~")) {
        final ServletContext ctx0 = ctx;
        final String path0 = path;
        final int j = path.indexOf('/', 2);
        final String ctxpath;
        if (j >= 0) {
          ctxpath = "/" + path.substring(2, j);
          path = path.substring(j);
        } else {
          ctxpath = "/" + path.substring(2);
          path = "/";
        }

        final ExtendletContext extctx = Servlets.getExtendletContext(ctx, ctxpath.substring(1));
        if (extctx != null) {
          url = extctx.getResource(path);
          //					if (log.debugable()) log.debug("Resolving "+path0+" to "+url);
          if (url == null) return null;
          try {
            return cache.get(new ResourceInfo(path, url, extra));
          } catch (Throwable ex) {
            final IOException ioex = getIOException(ex);
            if (ioex == null) throw SystemException.Aide.wrap(ex);
            log.warningBriefly("Unable to load " + url, ioex);
          }
          return null;
        }

        ctx = ctx.getContext(ctxpath);
        if (ctx == null) { // failed
          //					if (log.debugable()) log.debug("Context not found: "+ctxpath);
          ctx = ctx0;
          path = path0; // restore
        }
      }

      final String flnm = ctx.getRealPath(path);
      if (flnm != null) {
        try {
          return cache.get(new ResourceInfo(path, new File(flnm), extra));
          // it is loader's job to check the existence
        } catch (Throwable ex) {
          final IOException ioex = getIOException(ex);
          if (ioex == null) throw SystemException.Aide.wrap(ex);
          log.warningBriefly("Unable to load " + flnm, ioex);
        }
        return null;
      }
    }

    // try url because some server uses JAR format
    try {
      if (url == null) url = ctx.getResource(path);
      if (url != null) return cache.get(new ResourceInfo(path, url, extra));
    } catch (Throwable ex) {
      final IOException ioex = getIOException(ex);
      if (ioex == null) throw SystemException.Aide.wrap(ex);
      log.warningBriefly("Unable to load " + path, ioex);
    }
    return null;
  }