@Test public void serializeWithCSSPathAdjustments() throws Exception { FilesystemExportContext exportContext = new FilesystemExportContext(); exportContext.setExportDir(BASEDIR); exportContext.pushCSSParentLevels(3); Provider<FilesystemExportContext> exportContextProvider = this.mocker.getInstance(new DefaultParameterizedType( null, Provider.class, FilesystemExportContext.class)); Mockito.when(exportContextProvider.get()).thenReturn(exportContext); WebJarsResourceReference reference = new WebJarsResourceReference("wiki:wiki", Arrays.asList( "font-awesome", "4.7.0", "fonts/FontAwesome.otf")); assertEquals("../../../webjars/font-awesome/4.7.0/fonts/FontAwesome.otf", this.mocker.getComponentUnderTest().serialize(reference).serialize()); assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/FontAwesome.otf").exists()); }
@Override public ExtendedURL serialize(WebJarsResourceReference reference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException { FilesystemExportContext exportContext = this.exportContextProvider.get(); try { FilesystemResourceReferenceCopier copier = new FilesystemResourceReferenceCopier(); copier.copyResourceFromJAR(WEBJARS_RESOURCE_PREFIX, reference.getResourceName(), WEBJAR_PATH, exportContext); if (reference.getResourceName().toLowerCase().endsWith("css")) { copier.processCSS(WEBJARS_RESOURCE_PREFIX, reference.getResourceName(), WEBJAR_PATH, exportContext); } } catch (Exception e) { throw new SerializeResourceReferenceException( String.format("Failed to extract and copy WebJAR resource [%s]", reference.getResourceName()), e); } List<String> pathSegments = new ArrayList<>(); if (exportContext.getCSSParentLevel() == 0) { for (int i = 0; i < exportContext.getDocParentLevel(); i++) { pathSegments.add(PARENT); } } else { for (int i = 0; i < exportContext.getCSSParentLevel(); i++) { pathSegments.add(PARENT); } } pathSegments.add(WEBJAR_PATH); for (String resourceSegment : StringUtils.split(reference.getResourceName(), '/')) { pathSegments.add(resourceSegment); } return new RelativeExtendedURL(pathSegments); }
FilesystemResourceReferenceSerializer implements ResourceReferenceSerializer<WebJarsResourceReference, ExtendedURL> { @Override public ExtendedURL serialize(WebJarsResourceReference reference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException { FilesystemExportContext exportContext = this.exportContextProvider.get(); try { FilesystemResourceReferenceCopier copier = new FilesystemResourceReferenceCopier(); copier.copyResourceFromJAR(WEBJARS_RESOURCE_PREFIX, reference.getResourceName(), WEBJAR_PATH, exportContext); if (reference.getResourceName().toLowerCase().endsWith("css")) { copier.processCSS(WEBJARS_RESOURCE_PREFIX, reference.getResourceName(), WEBJAR_PATH, exportContext); } } catch (Exception e) { throw new SerializeResourceReferenceException( String.format("Failed to extract and copy WebJAR resource [%s]", reference.getResourceName()), e); } List<String> pathSegments = new ArrayList<>(); if (exportContext.getCSSParentLevel() == 0) { for (int i = 0; i < exportContext.getDocParentLevel(); i++) { pathSegments.add(PARENT); } } else { for (int i = 0; i < exportContext.getCSSParentLevel(); i++) { pathSegments.add(PARENT); } } pathSegments.add(WEBJAR_PATH); for (String resourceSegment : StringUtils.split(reference.getResourceName(), '/')) { pathSegments.add(resourceSegment); } return new RelativeExtendedURL(pathSegments); } }
FilesystemResourceReferenceSerializer implements ResourceReferenceSerializer<WebJarsResourceReference, ExtendedURL> { @Override public ExtendedURL serialize(WebJarsResourceReference reference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException { FilesystemExportContext exportContext = this.exportContextProvider.get(); try { FilesystemResourceReferenceCopier copier = new FilesystemResourceReferenceCopier(); copier.copyResourceFromJAR(WEBJARS_RESOURCE_PREFIX, reference.getResourceName(), WEBJAR_PATH, exportContext); if (reference.getResourceName().toLowerCase().endsWith("css")) { copier.processCSS(WEBJARS_RESOURCE_PREFIX, reference.getResourceName(), WEBJAR_PATH, exportContext); } } catch (Exception e) { throw new SerializeResourceReferenceException( String.format("Failed to extract and copy WebJAR resource [%s]", reference.getResourceName()), e); } List<String> pathSegments = new ArrayList<>(); if (exportContext.getCSSParentLevel() == 0) { for (int i = 0; i < exportContext.getDocParentLevel(); i++) { pathSegments.add(PARENT); } } else { for (int i = 0; i < exportContext.getCSSParentLevel(); i++) { pathSegments.add(PARENT); } } pathSegments.add(WEBJAR_PATH); for (String resourceSegment : StringUtils.split(reference.getResourceName(), '/')) { pathSegments.add(resourceSegment); } return new RelativeExtendedURL(pathSegments); }  }
FilesystemResourceReferenceSerializer implements ResourceReferenceSerializer<WebJarsResourceReference, ExtendedURL> { @Override public ExtendedURL serialize(WebJarsResourceReference reference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException { FilesystemExportContext exportContext = this.exportContextProvider.get(); try { FilesystemResourceReferenceCopier copier = new FilesystemResourceReferenceCopier(); copier.copyResourceFromJAR(WEBJARS_RESOURCE_PREFIX, reference.getResourceName(), WEBJAR_PATH, exportContext); if (reference.getResourceName().toLowerCase().endsWith("css")) { copier.processCSS(WEBJARS_RESOURCE_PREFIX, reference.getResourceName(), WEBJAR_PATH, exportContext); } } catch (Exception e) { throw new SerializeResourceReferenceException( String.format("Failed to extract and copy WebJAR resource [%s]", reference.getResourceName()), e); } List<String> pathSegments = new ArrayList<>(); if (exportContext.getCSSParentLevel() == 0) { for (int i = 0; i < exportContext.getDocParentLevel(); i++) { pathSegments.add(PARENT); } } else { for (int i = 0; i < exportContext.getCSSParentLevel(); i++) { pathSegments.add(PARENT); } } pathSegments.add(WEBJAR_PATH); for (String resourceSegment : StringUtils.split(reference.getResourceName(), '/')) { pathSegments.add(resourceSegment); } return new RelativeExtendedURL(pathSegments); }  @Override ExtendedURL serialize(WebJarsResourceReference reference); }
FilesystemResourceReferenceSerializer implements ResourceReferenceSerializer<WebJarsResourceReference, ExtendedURL> { @Override public ExtendedURL serialize(WebJarsResourceReference reference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException { FilesystemExportContext exportContext = this.exportContextProvider.get(); try { FilesystemResourceReferenceCopier copier = new FilesystemResourceReferenceCopier(); copier.copyResourceFromJAR(WEBJARS_RESOURCE_PREFIX, reference.getResourceName(), WEBJAR_PATH, exportContext); if (reference.getResourceName().toLowerCase().endsWith("css")) { copier.processCSS(WEBJARS_RESOURCE_PREFIX, reference.getResourceName(), WEBJAR_PATH, exportContext); } } catch (Exception e) { throw new SerializeResourceReferenceException( String.format("Failed to extract and copy WebJAR resource [%s]", reference.getResourceName()), e); } List<String> pathSegments = new ArrayList<>(); if (exportContext.getCSSParentLevel() == 0) { for (int i = 0; i < exportContext.getDocParentLevel(); i++) { pathSegments.add(PARENT); } } else { for (int i = 0; i < exportContext.getCSSParentLevel(); i++) { pathSegments.add(PARENT); } } pathSegments.add(WEBJAR_PATH); for (String resourceSegment : StringUtils.split(reference.getResourceName(), '/')) { pathSegments.add(resourceSegment); } return new RelativeExtendedURL(pathSegments); }  @Override ExtendedURL serialize(WebJarsResourceReference reference);  }