Package ro.isdc.wro.model.resource.locator

Examples of ro.isdc.wro.model.resource.locator.UriLocator


        }

        assertEquals(7, resources.size());
        for (Resource resource : resources) {
            final UriLocatorFactory uriLocatorFactory = new GeonetworkMavenWrojManagerFactory().newUriLocatorFactory();
            final UriLocator instance = uriLocatorFactory.getInstance(resource.getUri());
            final String deps = IOUtils.toString(instance.locate(resource.getUri()), "UTF-8");
            if (resource.getUri().contains("sampleFile1a.js")) {
                assertEquals("goog.addDependency('" + PATH_TO_WEBAPP_BASE_FROM_CLOSURE_BASE_JS_FILE + "/" + jsTestBaseDirAsPath +
                             "/sampleFile1a.js', ['1a'], ['2a']);\n", deps);
            } else if (resource.getUri().contains("sampleFile1b.js")) {
                assertEquals("goog.addDependency('" + PATH_TO_WEBAPP_BASE_FROM_CLOSURE_BASE_JS_FILE + "/" + jsTestBaseDirAsPath +
View Full Code Here


        }
        assertTrue(exists);
    }

    private void assertCanLoadResource(UriLocatorFactory uriLocatorFactory, Resource resource) throws IOException {
        final UriLocator instance = uriLocatorFactory.getInstance(resource.getUri());
        final InputStream locate = instance.locate(resource.getUri());
        try {
            assertNotNull(locate);

            final int read = locate.read();
            assertTrue(-1 != read);
View Full Code Here

   * @return {@link InputStream} of the resource.
   * @throws IOException if uri is invalid or resource couldn't be located.
   */
  public final InputStream locate(final String uri)
    throws IOException {
    final UriLocator uriLocator = getInstance(uri);
    if (uriLocator == null) {
      throw new WroRuntimeException("No locator is capable of handling uri: " + uri);
    }
    LOG.debug("[OK] locating {} using locator: {}", uri, uriLocator.getClass().getSimpleName());
    return new AutoCloseInputStream(uriLocator.locate(uri));
  }
View Full Code Here

  /**
   * This implementation shows the problem with current design of locator implementation. Needs to be changed.
   */
  public InputStream locate(final String uri)
      throws IOException {
    final UriLocator locator = getInstance(uri);
    if (locator == null) {
      return getDecoratedObject().locate(uri);
    }
    return locator.locate(uri);
  }
View Full Code Here

    }
    return locator.locate(uri);
  }

  public UriLocator getInstance(final String uri) {
    final UriLocator instance = getDecoratedObject().getInstance(uri);
    if (instance != null) {
      injector.inject(instance);
    }
    return instance;
  }
View Full Code Here

  /**
   * @return an implementation of {@link UriLocator} which always return a valid stream which contains the resource uri
   *         as content.
   */
  public static UriLocator createResourceMockingLocator() {
    return new UriLocator() {
      public InputStream locate(final String uri)
          throws IOException {
        return new ByteArrayInputStream(uri.getBytes());
      }

View Full Code Here

  /**
   * Process each resource and replace it with a collection of resources if it contains wildcard.
   */
  private void processResource(final Group group, final Resource resource) {
    final UriLocator uriLocator = locatorFactory.getInstance(resource.getUri());

    if (uriLocator instanceof WildcardUriLocatorSupport) {
      final WildcardStreamLocator wildcardStreamLocator = ((WildcardUriLocatorSupport) uriLocator).getWildcardStreamLocator();

      // TODO should we probably handle the situation when wildcard is present, but the implementation is not
      // expandedHandledAware?
      if (wildcardStreamLocator.hasWildcard(resource.getUri())
          && wildcardStreamLocator instanceof WildcardExpanderHandlerAware) {

        final WildcardExpanderHandlerAware expandedHandler = (WildcardExpanderHandlerAware) wildcardStreamLocator;
        LOG.debug("Expanding resource: {}", resource.getUri());

        final String baseNameFolder = computeBaseNameFolder(resource, uriLocator, expandedHandler);
        LOG.debug("baseNameFolder: {}", baseNameFolder);

        expandedHandler.setWildcardExpanderHandler(createExpanderHandler(group, resource, baseNameFolder));
        try {
          // trigger the wildcard replacement
          uriLocator.locate(resource.getUri());
        } catch (final IOException e) {
          // log only
          LOG.debug("[FAIL] problem while trying to expand wildcard for the following resource uri: {}",
              resource.getUri());
        } finally {
View Full Code Here

    assertEquals(UrlUriLocator.class, iterator.next().getClass());
  }

  @Test
  public void shouldUseDefaultLocatorWhenNoneIsConfigured() {
    final UriLocator locator = victim.getInstance("/");
    assertEquals(ServletContextUriLocator.class, locator.getClass());
  }
View Full Code Here

              "tools.expose-1.0.5.js", "tools.overlay-1.1.2.js", "tools.overlay.apple-1.0.1.js",
              "tools.overlay.gallery-1.0.0.js"
            }), Arrays.toString(filenameList.toArray()));
      };
    };
    final UriLocator uriLocator = new ClasspathUriLocator() {
      @Override
      public WildcardStreamLocator newWildcardStreamLocator() {
        return locator;
      }
    };
    uriLocator.locate("classpath:" + WroUtil.toPackageAsFolder(getClass()) + "/*.js");
  }
View Full Code Here

      void triggerWildcardExpander(final Collection<File> allFiles, final WildcardContext wildcardContext)
          throws IOException {
        assertEquals(2, allFiles.size());
      };
    };
    final UriLocator uriLocator = new ClasspathUriLocator() {
      @Override
      public WildcardStreamLocator newWildcardStreamLocator() {
        return locator;
      }
    };
    uriLocator.locate("classpath:" + WroUtil.toPackageAsFolder(getClass()) + "/*.css");
  }
View Full Code Here

TOP

Related Classes of ro.isdc.wro.model.resource.locator.UriLocator

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.