/** * Handles reading in the content of a Resource, and then replacing tokens in it if a tokenReplacer has been set. */ protected String readAndReplaceTokens(Resource r) { String content; try { content = new String(FileCopyUtils.copyToByteArray(r.getInputStream())); } catch (IOException e) { throw new RuntimeException("Unable to read content from: " + r.getDescription() + "; cause: " + e.getMessage(), e); } if (tokenReplacer != null) { content = tokenReplacer.replaceTokens(content); } return content; }
@Override public DocumentFile processDocumentFile(DocumentFile documentFile) { if (tokenReplacer != null && moduleCanBeReadAsString(documentFile.getFormat())) { String text = documentFile.getModifiedContent(); if (text == null) { Resource resource = documentFile.getResource(); if (resource != null) { try { text = new String(FileCopyUtils.copyToByteArray(resource.getInputStream())); } catch (IOException ie) { logger.warn("Unable to replace tokens in file: " + documentFile.getUri() + "; cause: " + ie.getMessage()); } } } if (text != null) { text = tokenReplacer.replaceTokens(text); documentFile.setModifiedContent(text); } } return documentFile; }