use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.
the class MarkupWriterFactoryImpl method newPartialMarkupWriter.
public MarkupWriter newPartialMarkupWriter(Page page) {
boolean isHTML5 = hasHTML5Doctype(page);
ContentType contentType = pageContentTypeAnalyzer.findContentType(page);
return constructMarkupWriter(contentType, true, isHTML5);
}
use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.
the class PageContentTypeAnalyzerImpl method findContentType.
public ContentType findContentType(Page page) {
ComponentResources pageResources = page.getRootComponent().getComponentResources();
String contentTypeString = metaDataLocator.findMeta(MetaDataConstants.RESPONSE_CONTENT_TYPE, pageResources, String.class);
return new ContentType(contentTypeString).withCharset(outputCharset);
}
use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.
the class ResponseRendererImplTest method content_type_from_component.
@Test
public void content_type_from_component() {
RequestPageCache cache = mockRequestPageCache();
PageContentTypeAnalyzer analyzer = mockPageContentTypeAnalyzer();
Component component = mockComponent();
String pageName = "foo/bar";
Page page = mockPage();
ContentType contentType = new ContentType("zig/zag");
ComponentResources resources = mockComponentResources();
train_getComponentResources(component, resources);
train_getPageName(resources, pageName);
train_get(cache, pageName, page);
train_findContentType(analyzer, page, contentType);
replay();
ResponseRenderer renderer = new ResponseRendererImpl(cache, analyzer, null);
assertSame(renderer.findContentType(component), contentType);
verify();
}
use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.
the class PageTesterModule method setupTestableOverrides.
@Contribute(ServiceOverride.class)
public static void setupTestableOverrides(MappedConfiguration<Class, Object> configuration, @Local TestableRequest request, @Local TestableResponse response, final ObjectLocator locator) {
configuration.add(Request.class, request);
configuration.add(Response.class, response);
TestableCookieSinkSource cookies = new TestableCookieSinkSource();
configuration.add(CookieSink.class, cookies);
configuration.add(CookieSource.class, cookies);
// With the significant changes to the handling of assets in 5.4, we introduced a problem:
// We were checking at page render time whether to generate URLs for normal or compressed
// assets and that peeked at the HttpServletRequest global, which isn't set up by PageTester.
// What we're doing here is using a hacked version of that code to force GZip support
// on.
configuration.add(ResponseCompressionAnalyzer.class, new ResponseCompressionAnalyzer() {
public boolean isGZipEnabled(ContentType contentType) {
return locator.getObject(CompressionAnalyzer.class, null).isCompressable(contentType.getMimeType());
}
public boolean isGZipSupported() {
return true;
}
});
}
use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.
the class StreamableResourceSourceImpl method getStreamableResource.
public StreamableResource getStreamableResource(Resource baseResource, StreamableResourceProcessing processing, ResourceDependencies dependencies) throws IOException {
assert baseResource != null;
if (!baseResource.exists()) {
throw new IOException(String.format("Resource %s does not exist.", baseResource));
}
String fileSuffix = TapestryInternalUtils.toFileSuffix(baseResource.getFile());
// Optionally, transform the resource. The main driver for this is to allow
// for libraries like LessJS (http://lesscss.org/) or
// http://jashkenas.github.com/coffee-script/
ResourceTransformer rt = configuration.get(fileSuffix);
InputStream transformed = rt == null ? baseResource.openStream() : rt.transform(baseResource, dependencies);
assert transformed != null;
BytestreamCache bytestreamCache = readStream(transformed);
transformed.close();
ContentType contentType = rt == null ? new ContentType(contentTypeAnalyzer.getContentType(baseResource)) : rt.getTransformedContentType();
boolean compressable = compressionAnalyzer.isCompressable(contentType.getMimeType());
long lastModified = resourceChangeTracker.trackResource(baseResource);
return new StreamableResourceImpl(baseResource.toString(), contentType, compressable ? CompressionStatus.COMPRESSABLE : CompressionStatus.NOT_COMPRESSABLE, lastModified, bytestreamCache, checksumGenerator, null);
}
Aggregations