@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 getContent() throws FileNotFound, CannotReadFile { try { // We execute velocity on the main skin file only (which is included by SSX objects using LESS). // // This a limitation we introduce because when we do an HTML export, we must execute velocity to know which // resources have to be included in the ZIP file, but we avoid executing LESS and we use the cache instead // (otherwise the export would be too slow). // // When we do an HTML export, we execute Velocity on the main skin file, but not on any .less.vm that the // skin might have. Actually we have no way to know which .less.vm are included, without running LESS. // // That is why we do not execute Velocity on any ".less.vm" file but only on the main skin template. String mainSkinTemplate = "less/" + CachedLESSCompiler.MAIN_SKIN_STYLE_FILENAME; if (mainSkinTemplate.equals(templateName)) { return templateManager.renderFromSkin(templateName, skin); } // Otherwise, return the raw content Template template = templateManager.getTemplate(templateName, skin); TemplateContent templateContent = template.getContent(); return templateContent.getContent(); } catch (Exception e) { throw new CannotReadFile(); } }
@Override public byte[] getBytes() throws FileNotFound, CannotReadFile { Reader input = null; try { input = new InputStreamReader(resource.openStream()); return IOUtils.toByteArray(input); } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } finally { InternalUtils.close(input); } } }
@Override public String getContent() throws FileNotFound, CannotReadFile { // Adapted from Less's URLSource Reader input = null; try { input = new InputStreamReader(resource.openStream()); String content = IOUtils.toString(input).replace("\r\n", "\n"); return content; } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } finally { InternalUtils.close(input); } }
@Override public LessSource relativeSource(String filename) throws CannotReadFile, FileNotFound { if (filename.startsWith("/webjars/")) { URL webjarResource = ClassPaths.getResource("META-INF/resources" + filename); if (webjarResource == null) { throw new FileNotFound(); } return new LessSource.URLSource(webjarResource); } Path relativePath = Paths.get(filename); if (!resources.exists(relativePath)) { throw new FileNotFound(); } try { return new PathSource(resources, resources.sourceFile(relativePath)); } catch (IOException e) { throw new CannotReadFile(); } }
@Override public byte[] getBytes() throws FileNotFound, CannotReadFile { Reader input = null; try { input = new InputStreamReader(resource.openStream()); return IOUtils.toByteArray(input); } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } finally { InternalUtils.close(input); } } }
@Override public String getContent() throws FileNotFound, CannotReadFile { // Adapted from Less's URLSource Reader input = null; try { input = new InputStreamReader(resource.openStream()); String content = IOUtils.toString(input).replace("\r\n", "\n"); return content; } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } finally { InternalUtils.close(input); } }
@Override public byte[] getBytes() throws FileNotFound, CannotReadFile { try { URLConnection connection = getInputURL().openConnection(); Reader input = new InputStreamReader(connection.getInputStream()); setLastModified(connection.getLastModified()); byte[] content = IOUtils.toByteArray(input); input.close(); return content; } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } }
@Override public String getContent() throws FileNotFound, CannotReadFile { try { URLConnection connection = getInputURL().openConnection(); Reader input = charsetName != null ? new InputStreamReader(connection.getInputStream(), charsetName) : new InputStreamReader(connection.getInputStream()); String content = IOUtils.toString(input).replace("\r\n", "\n"); setLastModified(connection.getLastModified()); input.close(); return content; } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } }
@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(); } }