| Method from org.apache.tiles.impl.BasicTilesContainer Detail: |
protected void checkInit() {
if (initialized) {
throw new IllegalStateException("Container allready initialized");
}
}
Determine whether or not the container has been
initialized. Utility method used for methods which
can not be invoked after the container has been
started. |
public void endContext(Object requestItems) {
TilesRequestContext tilesContext = getRequestContext(requestItems);
endContext(tilesContext);
}
|
public TilesApplicationContext getApplicationContext() {
return context;
}
Returns the Tiles application context used by this container. |
public AttributeContext getAttributeContext(Object requestItems) {
TilesRequestContext tilesContext = getRequestContext(requestItems);
return getAttributeContext(tilesContext);
}
|
protected AttributeContext getContext(TilesRequestContext tilesContext) {
Stack< AttributeContext > contextStack = getContextStack(tilesContext);
if (!contextStack.isEmpty()) {
return contextStack.peek();
} else {
return null;
}
}
Get attribute context from request. |
public TilesContextFactory getContextFactory() {
return contextFactory;
}
Returns the context factory. |
protected Stack getContextStack(TilesRequestContext tilesContext) {
Stack< AttributeContext > contextStack =
(Stack< AttributeContext >) tilesContext
.getRequestScope().get(ATTRIBUTE_CONTEXT_STACK);
if (contextStack == null) {
contextStack = new Stack< AttributeContext >();
tilesContext.getRequestScope().put(ATTRIBUTE_CONTEXT_STACK,
contextStack);
}
return contextStack;
}
Returns the context stack. |
protected Definition getDefinition(String definitionName,
TilesRequestContext request) throws DefinitionsFactoryException {
Definition definition =
definitionsFactory.getDefinition(definitionName, request);
return definition;
}
Returns a definition specifying its name. |
public DefinitionsFactory getDefinitionsFactory() {
return definitionsFactory;
}
Returns the definitions factory. |
public PreparerFactory getPreparerFactory() {
return preparerFactory;
}
Returns the preparer factory used by this container. |
protected List getResourceNames(String resourceString) {
StringTokenizer tokenizer = new StringTokenizer(resourceString, ",");
List< String > filenames = new ArrayList< String >(tokenizer.countTokens());
while (tokenizer.hasMoreTokens()) {
filenames.add(tokenizer.nextToken().trim());
}
return filenames;
}
Parse the resourceString into a list of resource paths
which can be loaded by the application context. |
protected String getResourceString() {
return getResourceString(context.getInitParams());
}
|
protected String getResourceString(Map parms) {
String resourceStr = parms.get(DEFINITIONS_CONFIG);
if (resourceStr == null) {
resourceStr = parms.get(LEGACY_DEFINITIONS_CONFIG);
}
if (resourceStr == null) {
resourceStr = "/WEB-INF/tiles.xml";
}
return resourceStr;
}
|
public void init(Map initParameters) throws TilesException {
checkInit();
initialized = true;
if (LOG.isInfoEnabled()) {
LOG.info("Initializing Tiles2 container. . .");
}
//Everything is now initialized. We will populate
// our definitions
initializeDefinitionsFactory(definitionsFactory, getResourceString(),
initParameters);
}
Initialize the Container with the given configuration. |
protected void initializeDefinitionsFactory(DefinitionsFactory definitionsFactory,
String resourceString,
Map initParameters) throws TilesException {
List< String > resources = getResourceNames(resourceString);
try {
for (String resource : resources) {
URL resourceUrl = context.getResource(resource);
if (resourceUrl != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding resource '" + resourceUrl + "' to definitions factory.");
}
definitionsFactory.addSource(resourceUrl);
} else {
LOG.warn("Unable to find configured definition '" + resource + "'");
}
}
} catch (IOException e) {
throw new DefinitionsFactoryException("Unable to parse definitions from "
+ resourceString, e);
}
definitionsFactory.init(initParameters);
if (LOG.isInfoEnabled()) {
LOG.info("Tiles2 container initialization complete.");
}
}
Initializes a definitions factory. |
public boolean isValidDefinition(String definitionName,
Object requestItems) {
return isValidDefinition(getRequestContext(requestItems), definitionName);
}
|
protected AttributeContext popContext(TilesRequestContext tilesContext) {
Stack< AttributeContext > contextStack = getContextStack(tilesContext);
return contextStack.pop();
}
Pops a context object out of the stack. |
public void prepare(String preparer,
Object requestItems) throws TilesException {
TilesRequestContext requestContext = getContextFactory().createRequestContext(
getApplicationContext(),
requestItems
);
prepare(requestContext, preparer, false);
}
|
protected void pushContext(AttributeContext context,
TilesRequestContext tilesContext) {
Stack< AttributeContext > contextStack = getContextStack(tilesContext);
contextStack.push(context);
}
Pushes a context object in the stack. |
public void render(String definitionName,
Object requestItems) throws TilesException {
TilesRequestContext requestContext = getContextFactory().createRequestContext(
getApplicationContext(),
requestItems
);
render(requestContext, definitionName);
}
|
public void render(Attribute attr,
Writer writer,
Object requestItems) throws IOException, TilesException {
TilesRequestContext request = getRequestContext(requestItems);
if (attr == null) {
throw new TilesException("Cannot render a null attribute");
}
if (!isPermitted(request, attr.getRoles())) {
if (LOG.isDebugEnabled()) {
LOG.debug("Access to attribute denied. User not in role '"
+ attr.getRoles() + "'");
}
return;
}
AttributeType type = attr.getType();
if (type == null) {
type = calculateType(attr, request);
attr.setType(type);
}
switch (type) {
case OBJECT:
throw new TilesException(
"Cannot insert an attribute of 'object' type");
case STRING:
writer.write(attr.getValue().toString());
break;
case DEFINITION:
render(request, attr.getValue().toString());
break;
case TEMPLATE:
request.dispatch(attr.getValue().toString());
break;
default: // should not happen
throw new TilesException(
"Unrecognized type for attribute value "
+ attr.getValue());
}
}
|
public void setApplicationContext(TilesApplicationContext context) {
this.context = context;
}
Sets the Tiles application context to use. |
public void setContextFactory(TilesContextFactory contextFactory) {
checkInit();
this.contextFactory = contextFactory;
}
Sets the context factory. |
public void setDefinitionsFactory(DefinitionsFactory definitionsFactory) {
checkInit();
this.definitionsFactory = definitionsFactory;
}
Set the definitions factory. This method first ensures
that the container has not yet been initialized. |
public void setPreparerFactory(PreparerFactory preparerFactory) {
this.preparerFactory = preparerFactory;
}
Set the preparerInstance factory. This method first ensures
that the container has not yet been initialized. |
public AttributeContext startContext(Object requestItems) {
TilesRequestContext tilesContext = getRequestContext(requestItems);
return startContext(tilesContext);
}
|