Skip to content

Commit

Permalink
Updating formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
LightGuard committed May 10, 2011
1 parent a5dcd48 commit 662a32e
Show file tree
Hide file tree
Showing 50 changed files with 8,852 additions and 9,270 deletions.
268 changes: 127 additions & 141 deletions src/main/java/org/jboss/seam/render/TemplateCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,145 +50,131 @@
/**
* @author <a href="mailto:[email protected]">Lincoln Baxter, III</a>
*/
public class TemplateCompiler
{
private final TemplateRegistry registry;
private final VariableResolverFactory variableFactory;
private final TemplateResolverFactory resolverFactory;

private final Map<String, Class<? extends Node>> nodes = new HashMap<String, Class<? extends Node>>();

@Inject
public TemplateCompiler(final VariableResolverFactory variableFactory)
{
this.variableFactory = variableFactory;
this.resolverFactory = new TemplateResolverFactory();
this.registry = new SimpleTemplateRegistry();
addNode("param", ParamNode.class);
addNode("extends", ExtendsNode.class);
addNode("define", DefineNode.class);
addNode("insert", InsertNode.class);
addNode("include", IncludeNode.class);
// create a map resolve to hold the functions we want to inject, and chain
// the ELVariableResolverFactory to this factory.
}

/**
* Convenience method for compiling a template from a {@link String}.
*/
public CompiledTemplateResource compileResource(final String template)
{
return compile(new StringTemplateResource(template));
}

/**
* Convenience method for compiling a template from an {@link InputStream}.
*/
public CompiledTemplateResource compileResource(final InputStream template)
{
return compile(new InputStreamTemplateResource(template));
}

/**
* Convenience method for compiling a template from a {@link File}.
*/
public CompiledTemplateResource compileResource(final File template)
{
return compile(new FileTemplateResource(template));
}

/**
* Resolve the given path using any configured {@link TemplateResolver} instances and compile it with the default
* nodes. Return the result as a {@link CompiledTemplateResource}.
*/
public CompiledTemplateResource compile(final String path) throws TemplateResolutionException
{
TemplateResource<?> resource = resolverFactory.resolve(path);
return compile(resource);
}

/**
* Resolve the given path using any configured {@link TemplateResolver} instances and compile it with the given map
* of named {@link Node} types. Return the result as a {@link CompiledTemplateResource}.
*/
public CompiledTemplateResource compile(final String path,
final Map<String, Class<? extends Node>> nodes) throws TemplateResolutionException
{
TemplateResource<?> resource = resolverFactory.resolve(path);
return compile(resource, nodes);
}

/**
* Compile the given {@link TemplateResource}. Return the result as a {@link CompiledTemplateResource}.
*/
public CompiledTemplateResource compile(final TemplateResource<?> templateResource)
throws TemplateResolutionException
{
Assert.notNull(templateResource, "Cannot compile a null TemplateResource.");
Map<String, Class<? extends Node>> nodes = getNodes();
return compile(templateResource, nodes);

}

/**
* Compile the given {@link TemplateResource} along with the given map of named {@link Node} types. Return the result
* as a {@link CompiledTemplateResource}.
*/
public CompiledTemplateResource compile(final TemplateResource<?> templateResource,
final Map<String, Class<? extends Node>> nodes) throws TemplateResolutionException
{
CompiledTemplateResource view = new CompiledTemplateResource(this, variableFactory, registry, templateResource,
nodes);
return view;
}

/**
* Resolve the given relative path using the {@link TemplateResolver} of the given {@link TemplateResource}. If that
* resolver is unable to locate the requested resource, attempt to discover it using any other register
* {@link TemplateResolver} instances. Compile the resolved {@link TemplateResource} and return the result as a
* {@link CompiledTemplateResource}.
*/
public CompiledTemplateResource compileRelative(final TemplateResource<?> originResource, final String relativePath)
throws TemplateResolutionException
{
TemplateResource<?> resource = resolverFactory.resolveRelative(originResource, relativePath);
return compile(resource);
}

/**
* Resolve the given relative path using the {@link TemplateResolver} of the given {@link TemplateResource}. If that
* resolver is unable to locate the requested resource, attempt to discover it using any other register
* {@link TemplateResolver} instances. Compile the resolved {@link TemplateResource} along with the given map of
* named {@link Node} types. Return the result as a {@link CompiledTemplateResource}.
*/
public CompiledTemplateResource compileRelative(final TemplateResource<?> originResource, final String relativePath,
final Map<String, Class<? extends Node>> nodes) throws TemplateResolutionException
{
TemplateResource<?> resource = resolverFactory.resolveRelative(originResource, relativePath);
return compile(resource, nodes);
}

/**
* Get the list of {@link Node} types that have been added to this {@link TemplateCompiler} instance.
*/
public Map<String, Class<? extends Node>> getNodes()
{
return nodes;
}

/**
* Add a {@link Node} to this {@link TemplateCompiler} instance.
*/
public void addNode(final String name, final Class<? extends Node> type)
{
nodes.put(name, type);
}

/**
* Get the {@link TemplateResolverFactory} currently in use by this {@link TemplateCompiler}
*/
public TemplateResolverFactory getTemplateResolverFactory()
{
return resolverFactory;
}
public class TemplateCompiler {
private final TemplateRegistry registry;
private final VariableResolverFactory variableFactory;
private final TemplateResolverFactory resolverFactory;

private final Map<String, Class<? extends Node>> nodes = new HashMap<String, Class<? extends Node>>();

@Inject
public TemplateCompiler(final VariableResolverFactory variableFactory) {
this.variableFactory = variableFactory;
this.resolverFactory = new TemplateResolverFactory();
this.registry = new SimpleTemplateRegistry();
addNode("param", ParamNode.class);
addNode("extends", ExtendsNode.class);
addNode("define", DefineNode.class);
addNode("insert", InsertNode.class);
addNode("include", IncludeNode.class);
// create a map resolve to hold the functions we want to inject, and chain
// the ELVariableResolverFactory to this factory.
}

/**
* Convenience method for compiling a template from a {@link String}.
*/
public CompiledTemplateResource compileResource(final String template) {
return compile(new StringTemplateResource(template));
}

/**
* Convenience method for compiling a template from an {@link InputStream}.
*/
public CompiledTemplateResource compileResource(final InputStream template) {
return compile(new InputStreamTemplateResource(template));
}

/**
* Convenience method for compiling a template from a {@link File}.
*/
public CompiledTemplateResource compileResource(final File template) {
return compile(new FileTemplateResource(template));
}

/**
* Resolve the given path using any configured {@link TemplateResolver} instances and compile it with the default
* nodes. Return the result as a {@link CompiledTemplateResource}.
*/
public CompiledTemplateResource compile(final String path) throws TemplateResolutionException {
TemplateResource<?> resource = resolverFactory.resolve(path);
return compile(resource);
}

/**
* Resolve the given path using any configured {@link TemplateResolver} instances and compile it with the given map
* of named {@link Node} types. Return the result as a {@link CompiledTemplateResource}.
*/
public CompiledTemplateResource compile(final String path,
final Map<String, Class<? extends Node>> nodes) throws TemplateResolutionException {
TemplateResource<?> resource = resolverFactory.resolve(path);
return compile(resource, nodes);
}

/**
* Compile the given {@link TemplateResource}. Return the result as a {@link CompiledTemplateResource}.
*/
public CompiledTemplateResource compile(final TemplateResource<?> templateResource)
throws TemplateResolutionException {
Assert.notNull(templateResource, "Cannot compile a null TemplateResource.");
Map<String, Class<? extends Node>> nodes = getNodes();
return compile(templateResource, nodes);

}

/**
* Compile the given {@link TemplateResource} along with the given map of named {@link Node} types. Return the result
* as a {@link CompiledTemplateResource}.
*/
public CompiledTemplateResource compile(final TemplateResource<?> templateResource,
final Map<String, Class<? extends Node>> nodes) throws TemplateResolutionException {
CompiledTemplateResource view = new CompiledTemplateResource(this, variableFactory, registry, templateResource,
nodes);
return view;
}

/**
* Resolve the given relative path using the {@link TemplateResolver} of the given {@link TemplateResource}. If that
* resolver is unable to locate the requested resource, attempt to discover it using any other register
* {@link TemplateResolver} instances. Compile the resolved {@link TemplateResource} and return the result as a
* {@link CompiledTemplateResource}.
*/
public CompiledTemplateResource compileRelative(final TemplateResource<?> originResource, final String relativePath)
throws TemplateResolutionException {
TemplateResource<?> resource = resolverFactory.resolveRelative(originResource, relativePath);
return compile(resource);
}

/**
* Resolve the given relative path using the {@link TemplateResolver} of the given {@link TemplateResource}. If that
* resolver is unable to locate the requested resource, attempt to discover it using any other register
* {@link TemplateResolver} instances. Compile the resolved {@link TemplateResource} along with the given map of
* named {@link Node} types. Return the result as a {@link CompiledTemplateResource}.
*/
public CompiledTemplateResource compileRelative(final TemplateResource<?> originResource, final String relativePath,
final Map<String, Class<? extends Node>> nodes) throws TemplateResolutionException {
TemplateResource<?> resource = resolverFactory.resolveRelative(originResource, relativePath);
return compile(resource, nodes);
}

/**
* Get the list of {@link Node} types that have been added to this {@link TemplateCompiler} instance.
*/
public Map<String, Class<? extends Node>> getNodes() {
return nodes;
}

/**
* Add a {@link Node} to this {@link TemplateCompiler} instance.
*/
public void addNode(final String name, final Class<? extends Node> type) {
nodes.put(name, type);
}

/**
* Get the {@link TemplateResolverFactory} currently in use by this {@link TemplateCompiler}
*/
public TemplateResolverFactory getTemplateResolverFactory() {
return resolverFactory;
}
}
31 changes: 15 additions & 16 deletions src/main/java/org/jboss/seam/render/spi/TemplateResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,31 @@
* {@link ServiceLoader} interface. This should be used to provide resolvers that know how to decode your specific
* resource location scheme. For instance, a database or web-service loaded {@link TemplateResource} could be specified
* using a custom path:
* <p>
* <p/>
* E.g: <code>"REST:/users/1/views/23"</code>
* <p>
* <p/>
* Next, in your application, create a service file containing the qualified class names of your
* {@link TemplateResolver} implementations:
* <p>
* <p/>
* <strong>For example:</strong><br>
* /META-INF/services/org.jboss.seam.render.spi.TemplateResolver<br>
* -----<br>
* <code>com.example.templates.CustomTemplateResolver</code> <br>
* <code>com.example.templates.CustomTemplateResolver2</code> <br>
* -----<br>
* <p>
*
* <p/>
*
* @author <a href="mailto:[email protected]">Lincoln Baxter, III</a>
*/
public interface TemplateResolver<T>
{
/**
* Attempt to resolve a {@link TemplateResource} using the given path. Return null if resolution fails.
*/
public TemplateResource<T> resolve(String target);
public interface TemplateResolver<T> {
/**
* Attempt to resolve a {@link TemplateResource} using the given path. Return null if resolution fails.
*/
public TemplateResource<T> resolve(String target);

/**
* Attempt to resolve a {@link TemplateResource} using the given origin and relative path. Return null if resolution
* fails.
*/
public TemplateResource<T> resolveRelative(TemplateResource<T> origin, String target);
/**
* Attempt to resolve a {@link TemplateResource} using the given origin and relative path. Return null if resolution
* fails.
*/
public TemplateResource<T> resolveRelative(TemplateResource<T> origin, String target);
}
48 changes: 23 additions & 25 deletions src/main/java/org/jboss/seam/render/spi/TemplateResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,33 @@

/**
* Handle to a template-able resource.
*
*
* @author <a href="mailto:[email protected]">Lincoln Baxter, III</a>
*
*/
public interface TemplateResource<T>
{
/**
* Get the unique path at which this resource can be located. A resource with a null path cannot be located by the
* {@link TemplateResolverFactory}.
*/
String getPath();
public interface TemplateResource<T> {
/**
* Get the unique path at which this resource can be located. A resource with a null path cannot be located by the
* {@link TemplateResolverFactory}.
*/
String getPath();

/**
* Get the underlying data for this {@link TemplateResource} in the form of an {@link InputStream}.
*/
InputStream getInputStream();
/**
* Get the underlying data for this {@link TemplateResource} in the form of an {@link InputStream}.
*/
InputStream getInputStream();

/**
* Get the last modified time of this resource. If zero, the last modified time is not available.
*/
long getLastModified();
/**
* Get the last modified time of this resource. If zero, the last modified time is not available.
*/
long getLastModified();

/**
* Get the underlying {@link T} resource object for this {@link TemplateResource}
*/
T getUnderlyingResource();
/**
* Get the underlying {@link T} resource object for this {@link TemplateResource}
*/
T getUnderlyingResource();

/**
* Get the {@link TemplateResolver} with which this {@link TemplateResource} was resolved.
*/
TemplateResolver<T> getResolvedBy();
/**
* Get the {@link TemplateResolver} with which this {@link TemplateResource} was resolved.
*/
TemplateResolver<T> getResolvedBy();
}
Loading

0 comments on commit 662a32e

Please sign in to comment.