Search in sources :

Example 1 with Resource

use of com.github.dreamhead.moco.resource.Resource in project moco by dreamhead.

the class DynamicResponseHandlerFactory method fileResource.

private Resource fileResource(final String name, final FileContainer fileContainer) {
    if (fileContainer.isForTemplate()) {
        if ("version".equalsIgnoreCase(name)) {
            return version(fileContainer.asTemplateResource());
        }
        return fileContainer.asTemplateResource(name);
    }
    TextContainer filename = fileContainer.getName();
    if (filename.isRawText()) {
        return asResource(name, fileContainer);
    }
    if (filename.isForTemplate()) {
        Optional<Charset> charset = fileContainer.getCharset();
        Resource resource = filename.asTemplateResource();
        return asResource(name, resource, charset);
    }
    throw new IllegalArgumentException(format("unknown file container:[%s]", fileContainer));
}
Also used : Resource(com.github.dreamhead.moco.resource.Resource) Charset(java.nio.charset.Charset)

Example 2 with Resource

use of com.github.dreamhead.moco.resource.Resource in project moco by dreamhead.

the class ContentHandler method apply.

@Override
public ResponseHandler apply(final MocoConfig config) {
    ResponseHandler handler = super.apply(config);
    if (handler != this) {
        return handler;
    }
    Resource appliedReosurce = this.resource.apply(config);
    if (appliedReosurce != this.resource) {
        return new ContentHandler((ContentResource) appliedReosurce);
    }
    return this;
}
Also used : ResponseHandler(com.github.dreamhead.moco.ResponseHandler) Resource(com.github.dreamhead.moco.resource.Resource) ContentResource(com.github.dreamhead.moco.resource.ContentResource)

Aggregations

Resource (com.github.dreamhead.moco.resource.Resource)2 ResponseHandler (com.github.dreamhead.moco.ResponseHandler)1 ContentResource (com.github.dreamhead.moco.resource.ContentResource)1 Charset (java.nio.charset.Charset)1