private LessSource source(final String filename) throws StringSourceException { String[] files = {path + filename, filename }; for (String file : files) { InputStream stream = getClass().getResourceAsStream(file); if (stream != null) { try { return new LessStrSource( new String(ByteStreams.toByteArray(stream), StandardCharsets.UTF_8), file); } catch (IOException ex) { log.debug("Can't read file: " + path, ex); throw new StringSourceException(); } finally { Closeables.closeQuietly(stream); } } } throw new StringSourceException(); }
@Override public LessSource relativeSource(String filename) throws StringSourceException { throw new StringSourceException(); }
private LessSource computeRelative(final Resource resource, final String relativePath) throws StringSourceException { try { final String relativeResourceUri = computeRelativeResourceUri(resource.getUri(), relativePath); final Resource relativeResource = Resource.create(relativeResourceUri, ResourceType.CSS); final String relativeResourceContent = IOUtils.toString(locatorFactory.locate(relativeResourceUri), "UTF-8"); return new RelativeAwareLessSource(relativeResource, relativeResourceContent, locatorFactory); } catch (final IOException e) { LOG.error("Failed to compute relative resource: " + resource, e); throw new StringSourceException(); } }
@Override public LessSource relativeSource(String relativePath) throws StringSourceException { try { Resource relativeResource = resource.resolve(relativePath); importedResources.add(relativeResource); return new RelativeAwareLessSource(relativeResource, relativeResource.getOutput().getContent()); } catch (Exception e) { LOG.error("Failed to compute relative resource: {}", resource, e); throw new StringSourceException(); } } }
private LessSource computeRelative(final Resource resource, final String relativePath) throws StringSourceException { try { final String relativeResourceUri = computeRelativeResourceUri(resource.getUri(), relativePath); final Resource relativeResource = Resource.create(relativeResourceUri, ResourceType.CSS); final String relativeResourceContent = IOUtils.toString(locatorFactory.locate(relativeResourceUri), "UTF-8"); return new RelativeAwareLessSource(relativeResource, relativeResourceContent, locatorFactory); } catch (final IOException e) { LOG.error("Failed to compute relative resource: " + resource, e); throw new StringSourceException(); } }