You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2008/01/29 19:56:45 UTC
svn commit: r616478 -
/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
Author: apetrelli
Date: Tue Jan 29 10:56:29 2008
New Revision: 616478
URL: http://svn.apache.org/viewvc?rev=616478&view=rev
Log:
TILES-243
Sorted BasicTilesContainer methods in order of visibility.
Modified:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java?rev=616478&r1=616477&r2=616478&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java Tue Jan 29 10:56:29 2008
@@ -137,24 +137,218 @@
}
/**
- * Starts an attribute context inside the container.
+ * Returns the Tiles application context used by this container.
*
- * @param tilesContext The request context to use.
- * @return The newly created attribute context.
+ * @return the application context for this container.
*/
- private AttributeContext startContext(TilesRequestContext tilesContext) {
- AttributeContext context = new BasicAttributeContext();
- BasicAttributeContext.pushContext(context, tilesContext);
+ public TilesApplicationContext getApplicationContext() {
return context;
}
/**
- * Releases and removes a previously created attribute context.
+ * Sets the Tiles application context to use.
*
- * @param tilesContext The request context to use.
+ * @param context The Tiles application context.
*/
- private void endContext(TilesRequestContext tilesContext) {
- BasicAttributeContext.popContext(tilesContext);
+ public void setApplicationContext(TilesApplicationContext context) {
+ this.context = context;
+ }
+
+ /** {@inheritDoc} */
+ public AttributeContext getAttributeContext(Object... requestItems) {
+ TilesRequestContext tilesContext = getRequestContext(requestItems);
+ return getAttributeContext(tilesContext);
+
+ }
+
+ /**
+ * Returns the context factory.
+ *
+ * @return The context factory.
+ */
+ public TilesContextFactory getContextFactory() {
+ return contextFactory;
+ }
+
+ /**
+ * Sets the context factory.
+ *
+ * @param contextFactory The context factory.
+ */
+ public void setContextFactory(TilesContextFactory contextFactory) {
+ checkInit();
+ this.contextFactory = contextFactory;
+ }
+
+ /**
+ * Returns the definitions factory.
+ *
+ * @return The definitions factory used by this container.
+ */
+ public DefinitionsFactory getDefinitionsFactory() {
+ return definitionsFactory;
+ }
+
+ /**
+ * Set the definitions factory. This method first ensures
+ * that the container has not yet been initialized.
+ *
+ * @param definitionsFactory the definitions factory for this instance.
+ */
+ public void setDefinitionsFactory(DefinitionsFactory definitionsFactory) {
+ checkInit();
+ this.definitionsFactory = definitionsFactory;
+ }
+
+ /**
+ * Returns the preparer factory used by this container.
+ *
+ * @return return the preparerInstance factory used by this container.
+ */
+ public PreparerFactory getPreparerFactory() {
+ return preparerFactory;
+ }
+
+ /**
+ * Set the preparerInstance factory. This method first ensures
+ * that the container has not yet been initialized.
+ *
+ * @param preparerFactory the preparerInstance factory for this conainer.
+ */
+ public void setPreparerFactory(PreparerFactory preparerFactory) {
+ this.preparerFactory = preparerFactory;
+ }
+
+ /** {@inheritDoc} */
+ public void prepare(String preparer, Object... requestItems)
+ throws TilesException {
+ TilesRequestContext requestContext = getContextFactory().createRequestContext(
+ getApplicationContext(),
+ requestItems
+ );
+ prepare(requestContext, preparer, false);
+ }
+
+ /** {@inheritDoc} */
+ public void render(String definitionName, Object... requestItems)
+ throws TilesException {
+ TilesRequestContext requestContext = getContextFactory().createRequestContext(
+ getApplicationContext(),
+ requestItems
+ );
+ render(requestContext, definitionName);
+ }
+
+ /** {@inheritDoc} */
+ public void render(Attribute attr, Writer writer, Object... requestItems)
+ throws TilesException, IOException {
+ 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 '" + attr.getName()
+ + "' 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());
+ }
+ }
+
+ /** {@inheritDoc} */
+ public boolean isValidDefinition(String definitionName, Object... requestItems) {
+ return isValidDefinition(getRequestContext(requestItems), definitionName);
+ }
+
+ /**
+ * Returns a definition specifying its name.
+ *
+ * @param definitionName The name of the definition to find.
+ * @param request The request context.
+ * @return The definition, if found.
+ * @throws DefinitionsFactoryException If the definitions factory throws an
+ * exception.
+ */
+ protected Definition getDefinition(String definitionName,
+ TilesRequestContext request) throws DefinitionsFactoryException {
+ Definition definition =
+ definitionsFactory.getDefinition(definitionName, request);
+ return definition;
+ }
+
+ /**
+ * Derive the resource string from the initialization parameters.
+ * If no parameter {@link #DEFINITIONS_CONFIG} is available, attempts
+ * to retrieve {@link #LEGACY_DEFINITIONS_CONFIG}. If niether are
+ * available, returns "/WEB-INF/tiles.xml".
+ *
+ * @return resource string to be parsed.
+ */
+ protected String getResourceString() {
+ return getResourceString(context.getInitParams());
+ }
+
+ /**
+ * Derive the resource string from the initialization parameters.
+ * If no parameter {@link #DEFINITIONS_CONFIG} is available, attempts
+ * to retrieve {@link #LEGACY_DEFINITIONS_CONFIG}. If niether are
+ * available, returns "/WEB-INF/tiles.xml".
+ *
+ * @param parms The initialization parameters.
+ * @return resource string to be parsed.
+ */
+ protected String getResourceString(Map<String, String> 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;
+ }
+
+ /**
+ * Parse the resourceString into a list of resource paths
+ * which can be loaded by the application context.
+ *
+ * @param resourceString comma seperated resources
+ * @return parsed resources
+ */
+ protected List<String> 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;
}
/**
@@ -210,31 +404,6 @@
}
/**
- * Returns the Tiles application context used by this container.
- *
- * @return the application context for this container.
- */
- public TilesApplicationContext getApplicationContext() {
- return context;
- }
-
- /**
- * Sets the Tiles application context to use.
- *
- * @param context The Tiles application context.
- */
- public void setApplicationContext(TilesApplicationContext context) {
- this.context = context;
- }
-
- /** {@inheritDoc} */
- public AttributeContext getAttributeContext(Object... requestItems) {
- TilesRequestContext tilesContext = getRequestContext(requestItems);
- return getAttributeContext(tilesContext);
-
- }
-
- /**
* Returns the current attribute context.
*
* @param tilesContext The request context to use.
@@ -263,71 +432,24 @@
}
/**
- * Returns the context factory.
- *
- * @return The context factory.
- */
- public TilesContextFactory getContextFactory() {
- return contextFactory;
- }
-
- /**
- * Sets the context factory.
- *
- * @param contextFactory The context factory.
- */
- public void setContextFactory(TilesContextFactory contextFactory) {
- checkInit();
- this.contextFactory = contextFactory;
- }
-
- /**
- * Returns the definitions factory.
- *
- * @return The definitions factory used by this container.
- */
- public DefinitionsFactory getDefinitionsFactory() {
- return definitionsFactory;
- }
-
- /**
- * Set the definitions factory. This method first ensures
- * that the container has not yet been initialized.
- *
- * @param definitionsFactory the definitions factory for this instance.
- */
- public void setDefinitionsFactory(DefinitionsFactory definitionsFactory) {
- checkInit();
- this.definitionsFactory = definitionsFactory;
- }
-
- /**
- * Returns the preparer factory used by this container.
+ * Starts an attribute context inside the container.
*
- * @return return the preparerInstance factory used by this container.
+ * @param tilesContext The request context to use.
+ * @return The newly created attribute context.
*/
- public PreparerFactory getPreparerFactory() {
- return preparerFactory;
+ private AttributeContext startContext(TilesRequestContext tilesContext) {
+ AttributeContext context = new BasicAttributeContext();
+ BasicAttributeContext.pushContext(context, tilesContext);
+ return context;
}
/**
- * Set the preparerInstance factory. This method first ensures
- * that the container has not yet been initialized.
+ * Releases and removes a previously created attribute context.
*
- * @param preparerFactory the preparerInstance factory for this conainer.
+ * @param tilesContext The request context to use.
*/
- public void setPreparerFactory(PreparerFactory preparerFactory) {
- this.preparerFactory = preparerFactory;
- }
-
- /** {@inheritDoc} */
- public void prepare(String preparer, Object... requestItems)
- throws TilesException {
- TilesRequestContext requestContext = getContextFactory().createRequestContext(
- getApplicationContext(),
- requestItems
- );
- prepare(requestContext, preparer, false);
+ private void endContext(TilesRequestContext tilesContext) {
+ BasicAttributeContext.popContext(tilesContext);
}
/**
@@ -362,16 +484,6 @@
preparer.execute(context, attributeContext);
}
- /** {@inheritDoc} */
- public void render(String definitionName, Object... requestItems)
- throws TilesException {
- TilesRequestContext requestContext = getContextFactory().createRequestContext(
- getApplicationContext(),
- requestItems
- );
- render(requestContext, definitionName);
- }
-
/**
* Renders the specified definition.
*
@@ -435,49 +547,6 @@
}
}
- /** {@inheritDoc} */
- public void render(Attribute attr, Writer writer, Object... requestItems)
- throws TilesException, IOException {
- 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 '" + attr.getName()
- + "' 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());
- }
- }
-
/**
* Calculates the type of an attribute.
*
@@ -507,22 +576,6 @@
}
/**
- * Returns a definition specifying its name.
- *
- * @param definitionName The name of the definition to find.
- * @param request The request context.
- * @return The definition, if found.
- * @throws DefinitionsFactoryException If the definitions factory throws an
- * exception.
- */
- protected Definition getDefinition(String definitionName,
- TilesRequestContext request) throws DefinitionsFactoryException {
- Definition definition =
- definitionsFactory.getDefinition(definitionName, request);
- return definition;
- }
-
- /**
* Checks if the current user is in one of the comma-separated roles
* specified in the <code>role</code> parameter.
*
@@ -543,59 +596,6 @@
}
return retValue;
- }
-
- /**
- * Derive the resource string from the initialization parameters.
- * If no parameter {@link #DEFINITIONS_CONFIG} is available, attempts
- * to retrieve {@link #LEGACY_DEFINITIONS_CONFIG}. If niether are
- * available, returns "/WEB-INF/tiles.xml".
- *
- * @return resource string to be parsed.
- */
- protected String getResourceString() {
- return getResourceString(context.getInitParams());
- }
-
- /**
- * Derive the resource string from the initialization parameters.
- * If no parameter {@link #DEFINITIONS_CONFIG} is available, attempts
- * to retrieve {@link #LEGACY_DEFINITIONS_CONFIG}. If niether are
- * available, returns "/WEB-INF/tiles.xml".
- *
- * @param parms The initialization parameters.
- * @return resource string to be parsed.
- */
- protected String getResourceString(Map<String, String> 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;
- }
-
- /**
- * Parse the resourceString into a list of resource paths
- * which can be loaded by the application context.
- *
- * @param resourceString comma seperated resources
- * @return parsed resources
- */
- protected List<String> 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;
- }
-
- /** {@inheritDoc} */
- public boolean isValidDefinition(String definitionName, Object... requestItems) {
- return isValidDefinition(getRequestContext(requestItems), definitionName);
}
/**