/******************************************************************************************************************* * * {@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); } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @BeforeMethod public void setupFixture() throws Exception { MockResponseBuilder.setCurrentTime(currentTime); resourceFile = mock(ResourceFile.class); when(resourceFile.asBytes()).thenReturn("FILE CONTENT".getBytes()); when(resourceFile.getMimeType()).thenReturn("text/plain"); when(resourceFile.getLatestModificationTime()).thenReturn(resourceLatestModifiedTime); headers = new HashMap<>(); request = mock(Request.class); when(request.getHeader(anyString())).thenAnswer(new Answer<String>() { @Override @Nonnull public String answer (final @Nonnull InvocationOnMock invocation) throws NotFoundException { final String name = (String)invocation.getArguments()[0]; return NotFoundException.throwWhenNull(headers.get(name), "Not found " + name); } }); underTest = new MockResponseHolder(); }
final String mimeType = file.getMimeType(); final Object content = mimeType.startsWith("text/") ? macroExpander.get().filter(file.asText("UTF-8"), mimeType) : file.asBytes();