LessCompiler.CompilationResult compilationResult = compiler.compile(new LessSource.FileSource(new File(inputLess)), configuration);
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; FileSource other = (FileSource) obj; String absoluteInputFile = getCanonicalPath(); if (absoluteInputFile == null) { if (other.getInputFile() != null) return false; } else if (!absoluteInputFile.equals(other.getCanonicalPath())) return false; if (charsetName == null) { if (other.charsetName != null) return false; } else if (!charsetName.equals(other.charsetName)) return false; return true; }
@Override public String getContent() throws FileNotFound, CannotReadFile { try { Reader input; if (charsetName != null) { input = new InputStreamReader(new FileInputStream(getInputFile()), charsetName); } else { input = new FileReader(getInputFile()); } try { String content = IOUtils.toString(input).replace("\r\n", "\n"); setLastModified(getInputFile().lastModified()); return content; } finally { input.close(); } } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } }
@Override public String printSourceName(LessSource source) { if (source == null) return ""; File file = source instanceof LessSource.FileSource ? ((LessSource.FileSource) source).getInputFile() : null; if (file == null) { String name = source.getName(); return name == null ? "" : name; } if (rootInputFile == null) { return file.getPath(); } File absoluteRoot = rootInputFile.getAbsoluteFile(); File absoluteFile = file.getAbsoluteFile(); if (sameFile(absoluteRoot, absoluteFile)) return ""; return URIUtils.relativize(absoluteRoot.getParentFile(), absoluteFile); }
@Override public String getName() { return getInputFile().getName(); }
public String toString() { return getInputFile().toString(); }
public FileSource(FileSource parent, String filename, String charsetName) { this(parent, new File(parent.getInputFile().getParentFile(), filename), charsetName); }
public URI getURI() { FileSource fileSource = new FileSource(file, charsetName); return fileSource.getURI(); }
@Override public CompilationResult compile(File lessFile, Configuration options) throws Less4jException { return compile(new LessSource.FileSource(lessFile, "utf-8"), options); }
@Override public CompilationResult compile(File lessFile, Configuration options) throws Less4jException { return compile(new LessSource.FileSource(lessFile, "utf-8"), options); }
public void setCssResultLocation(File cssResultLocation) { this.cssResultLocation = cssResultLocation == null ? null : new LessSource.FileSource(cssResultLocation); }
private LessCompiler.Configuration createConfiguration(File cssOutut) { LessCompiler.Configuration configuration = new LessCompiler.Configuration(); configuration.setCssResultLocation(new LessSource.FileSource(cssOutut)); configuration.setCompressing(compress); return configuration; }
@Override public FileSource relativeSource(String filename) { return new FileSource(this, filename, charsetName); }
@Override public int hashCode() { final int prime = 31; int result = 1; String canonicalInputFile = getCanonicalPath(); result = prime * result + ((canonicalInputFile == null) ? 0 : canonicalInputFile.hashCode()); result = prime * result + ((charsetName == null) ? 0 : charsetName.hashCode()); return result; }
@Override public byte[] getBytes() throws FileNotFound, CannotReadFile { FileSource fileSource = new FileSource(file, charsetName); return fileSource.getBytes(); }
@Override public byte[] getBytes() throws FileNotFound, CannotReadFile { try { byte[] content = FileUtils.readFileToByteArray(getInputFile()); setLastModified(getInputFile().lastModified()); return content; } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } }
private String getCanonicalPath() { try { return getInputFile().getCanonicalPath(); } catch (IOException e) { return getInputFile().getAbsolutePath(); } }
@Override public URI getURI() { try { String path = getInputFile().toString(); path = URIUtils.convertPlatformSeparatorToUri(path); return new URI(path); } catch (URISyntaxException e) { return null; } }
public FileSource(FileSource parent, File inputFile, String charsetName) { super(parent); this.inputFile = inputFile; this.charsetName = charsetName; parent.addImportedSource(this); }
@Override public String getName() { FileSource fileSource = new FileSource(file, charsetName); return fileSource.getName(); }