/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @SuppressWarnings("unchecked") public <Type> Type resolveProperty (final @Nonnull Id propertyGroupId, final @Nonnull Key<Type> propertyName) throws NotFoundException, IOException { log.trace("resolveProperty({})", propertyName); final ResourceFile propertyFile = findLocalizedFile(propertyName.stringValue()); log.trace(">>>> reading from {}", propertyFile.getPath()); final String mimeType = propertyFile.getMimeType(); final String charset = mimeType.equals("application/xhtml+xml") ? "UTF-8" : Charset.defaultCharset().name(); try { // return (Type)filterSetExpander.get().filter(propertyFile.asText(charset), mimeType); return (Type)propertyFile.asText(charset); } catch (RuntimeException e) // FIXME: introduce a FilterException { throw new IOException(e); } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @SuppressWarnings("unchecked") public <Type> Type resolveProperty (final @Nonnull Id propertyGroupId, final @Nonnull Key<Type> propertyName) throws NotFoundException, IOException { log.trace("resolveProperty({})", propertyName); final ResourceFile propertyFile = findLocalizedFile(propertyName.stringValue()); log.trace(">>>> reading from {}", propertyFile.getPath()); final String mimeType = propertyFile.getMimeType(); final String charset = mimeType.equals("application/xhtml+xml") ? "UTF-8" : Charset.defaultCharset().name(); try { return (Type)filterSetExpander.get().filter(propertyFile.asText(charset), mimeType); } catch (RuntimeException e) // FIXME: introduce a FilterException { throw new IOException(e); } }
/******************************************************************************************************************* * ******************************************************************************************************************/ // FIXME: this should be shared between instances private void initialize() throws IOException, NotFoundException { log.info("Retrieving XSLT templates"); final String template = IOUtils.toString(getClass().getResourceAsStream("/it/tidalwave/northernwind/core/impl/filter/XsltTemplate.xslt")); final StringBuilder xsltBuffer = new StringBuilder(); for (final Resource resource : siteProvider.get().getSite().find(Resource.class).withRelativePath(XSLT_TEMPLATES_PATH).results()) { final ResourceFile file = resource.getFile(); log.info(">>>> {}", file.getPath().asString()); xsltBuffer.append(file.asText("UTF-8")); } final ST t = new ST(template, '%', '%').add("content", xsltBuffer.toString()); xslt = t.render(); }
final String xslt = IOUtils.toString(getClass().getResourceAsStream(resourceName), "UTF-8"); when(file.getPath()).thenReturn(new ResourcePath(resourceName)); when(file.asText(anyString())).thenReturn(xslt);
final ResourceFile file = resource.getFile(); final String mimeType = file.getMimeType(); final Object content = mimeType.startsWith("text/") ? macroExpander.get().filter(file.asText("UTF-8"), mimeType) : file.asBytes(); responseHolder.response().forRequest(request)
/******************************************************************************************************************* * * * ******************************************************************************************************************/ private static void dump (final @Nonnull List<String> lines, final @Nonnull ResourceFile fileObject) throws IOException { if (fileObject.isData()) { lines.add(String.format("%s: %s", fileObject.getPath().asString(), fileObject.asText("UTF-8"))); } else { for (final ResourceFile child : fileObject.findChildren().results()) { dump(lines, child); } } }