private String merge(final List<Resource> resources, final String separator) throws IOException { final List<String> contents = new ArrayList<String>(); for (final Resource resource : resources) { contents.add(resource.getContents()); } return StringUtils.join(contents, separator); }
@Deprecated private List<Resource> getJsonSourceFiles(final ResourceResolver resolver, final Resource resource) throws IOException { final List<Resource> list = new ArrayList<Resource>(); final Set<String> alreadyHandled = new HashSet<String>(); for (final String s : new ObjectMapper().readValue(resource.getContents(), String[].class)) { if (!isUniqueFileResolved(alreadyHandled, s)) { list.add(resolver.resolve(s)); alreadyHandled.add(s); } } return list; }
private List<Resource> getJsonSourceFiles(final Resource resource) throws IOException { final List<Resource> list = new ArrayList<Resource>(); final Set<String> alreadyHandled = new HashSet<String>(); for (final String s : new ObjectMapper().readValue(resource.getContents(), String[].class)) { if (!isUniqueFileResolved(alreadyHandled, s)) { list.add(resource.getResolver().resolve(s)); alreadyHandled.add(s); } } return list; }
private List<String> scanResource(final Resource resource, final Map<String, Object> options) throws IOException { final List<String> results = new ArrayList<String>(); final Map<String, Object> opts = new HashMap<String, Object>(options); opts.remove("version"); final Map<String, Object> params = new HashMap<String, Object>(); params.put("source", resource.getContents()); params.put("options", opts); final StringWriter writer = new StringWriter(); this.executor .run(new StringReader(new ObjectMapper().writeValueAsString(params)), writer); final JsHintResult result = new ObjectMapper().readValue(writer.toString(), JsHintResult.class); if (result.errors != null) { for (final JsHintError error : result.errors) { results.add(resource.getPath() + " line " + error.line + ": " + error.reason + "\n\t" + error.evidence); } } return results; }
@Override public void call(final Reader reader, final Writer writer) throws IOException { String root = resource.getPath(); final int idx = root.lastIndexOf('/'); root = root.substring(0, idx + 1); final int processorOptions = CSSURLEmbedder.DATAURI_OPTION | CSSURLEmbedder.SKIP_MISSING_OPTION; final int maxUriLength = getMaxUriLength(options); final int maxImageSize = getMaxImageSize(options); new Embedder(resource, new StringReader(resource.getContents()), processorOptions, true, maxUriLength, maxImageSize) .embedImages(writer, root); } });
.resolve(input).getContents());
/** * @see de.matrixweb.smaller.resource.Processor#execute(de.matrixweb.vfs.VFS, * de.matrixweb.smaller.resource.Resource, java.util.Map) */ @Override public Resource execute(final VFS vfs, final Resource resource, final Map<String, Object> options) throws IOException { // Version 1.0.0 handling if (getVersion(options).isAtLeast(Version._1_0_0)) { try { if (!(resource instanceof ResourceGroup) && resource != null && FilenameUtils.isExtension(resource.getPath(), "json")) { return executeSimpleMerge(vfs, resource, options); } return executeComplexMerge(vfs, resource, options); } catch (final IOException e) { throw new SmallerException("Failed to merge files", e); } } final VFile snapshot = vfs.stack(); try { final VFile file = vfs.find(resource.getPath()); VFSUtils.write(file, resource.getContents()); return resource.getResolver().resolve(file.getPath()); } catch (final IOException e) { vfs.rollback(snapshot); throw e; } }