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/02/28 20:46:28 UTC
svn commit: r632100 - in /tiles/framework/trunk:
tiles-api/src/main/java/org/apache/tiles/
tiles-core/src/main/java/org/apache/tiles/impl/
Author: apetrelli
Date: Thu Feb 28 11:46:25 2008
New Revision: 632100
URL: http://svn.apache.org/viewvc?rev=632100&view=rev
Log:
TILES-259
Moved code from Definition to AttributeContext and BasicAttributeContext.
Modified BasicTilesContainer to separate the handling of the context to the handling of the definition.
Modified:
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/AttributeContext.java
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/BasicAttributeContext.java
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Definition.java
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
Modified: tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/AttributeContext.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/AttributeContext.java?rev=632100&r1=632099&r2=632100&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/AttributeContext.java (original)
+++ tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/AttributeContext.java Thu Feb 28 11:46:25 2008
@@ -31,6 +31,69 @@
* @version $Rev$ $Date$
*/
public interface AttributeContext {
+ /**
+ * Access method for the template property.
+ *
+ * @return the current value of the template property
+ * @since 2.1.0
+ */
+ String getTemplate();
+
+ /**
+ * Sets the value of the template property.
+ *
+ * @param template the new value of the path property
+ * @since 2.1.0
+ */
+ void setTemplate(String template);
+
+ /**
+ * Access method for the role property.
+ *
+ * @return the current value of the role property
+ * @since 2.1.0
+ */
+ String getRole();
+
+ /**
+ * Returns the roles that can render this attribute.
+ *
+ * @return The enabled roles.
+ * @since 2.1.0
+ */
+ Set<String> getRoles();
+
+ /**
+ * Sets the value of the role property.
+ *
+ * @param role the new value of the role property
+ * @since 2.1.0
+ */
+ void setRole(String role);
+
+ /**
+ * Sets the roles that can render this attribute.
+ *
+ * @param roles The enabled roles.
+ * @since 2.1.0
+ */
+ void setRoles(Set<String> roles);
+
+ /**
+ * Get associated preparer instance.
+ *
+ * @return The preparer name.
+ * @since 2.1.0
+ */
+ String getPreparer();
+
+ /**
+ * Set associated preparer instance.
+ *
+ * @param url The preparer name.
+ * @since 2.1.0
+ */
+ void setPreparer(String url);
/**
* Add all attributes to the context.
Modified: tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/BasicAttributeContext.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/BasicAttributeContext.java?rev=632100&r1=632099&r2=632100&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/BasicAttributeContext.java (original)
+++ tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/BasicAttributeContext.java Thu Feb 28 11:46:25 2008
@@ -38,6 +38,27 @@
public class BasicAttributeContext implements AttributeContext, Serializable {
/**
+ * Template path.
+ *
+ * @since 2.1.0
+ */
+ protected String template = null;
+
+ /**
+ * The roles that can render this definition.
+ *
+ * @since 2.1.0
+ */
+ protected Set<String> roles = null;
+
+ /**
+ * Associated ViewPreparer URL or classname, if defined.
+ *
+ * @since 2.1.0
+ */
+ protected String preparer = null;
+
+ /**
* Template attributes.
* @since 2.1.0
*/
@@ -100,6 +121,69 @@
}
/** {@inheritDoc} */
+ public String getTemplate() {
+ return template;
+ }
+
+ /** {@inheritDoc} */
+ public void setTemplate(String template) {
+ this.template = template;
+ }
+
+ /** {@inheritDoc} */
+ public String getRole() {
+ String retValue = null;
+
+ if (roles != null && !roles.isEmpty()) {
+ StringBuilder builder = new StringBuilder();
+ Iterator<String> roleIt = roles.iterator();
+ if (roleIt.hasNext()) {
+ builder.append(roleIt.next());
+ while (roleIt.hasNext()) {
+ builder.append(",");
+ builder.append(roleIt.next());
+ }
+ retValue = builder.toString();
+ }
+ }
+
+ return retValue;
+ }
+
+ /** {@inheritDoc} */
+ public Set<String> getRoles() {
+ return roles;
+ }
+
+ /** {@inheritDoc} */
+ public void setRole(String role) {
+ if (role != null && role.trim().length() > 0) {
+ String[] rolesStrings = role.split("\\s*,\\s*");
+ roles = new HashSet<String>();
+ for (int i = 0; i < rolesStrings.length; i++) {
+ roles.add(rolesStrings[i]);
+ }
+ } else {
+ roles = null;
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void setRoles(Set<String> roles) {
+ this.roles = roles;
+ }
+
+ /** {@inheritDoc} */
+ public String getPreparer() {
+ return preparer;
+ }
+
+ /** {@inheritDoc} */
+ public void setPreparer(String url) {
+ this.preparer = url;
+ }
+
+ /** {@inheritDoc} */
public void inheritCascadedAttributes(AttributeContext context) {
if (context instanceof BasicAttributeContext) {
copyCascadedAttributes((BasicAttributeContext) context);
@@ -117,6 +201,20 @@
if (parent instanceof BasicAttributeContext) {
inherit((BasicAttributeContext) parent);
} else {
+ // Inheriting template, roles and preparer.
+ if (template == null) {
+ template = parent.getTemplate();
+ }
+ Set<String> parentRoles = parent.getRoles();
+ if ((roles == null || roles.isEmpty()) && parentRoles != null
+ && !parentRoles.isEmpty()) {
+ roles = new HashSet<String>(parentRoles);
+ }
+ if (preparer == null) {
+ preparer = parent.getPreparer();
+ }
+
+ // Inheriting attributes.
Set<String> names = parent.getCascadedAttributeNames();
if (names != null && !names.isEmpty()) {
for (String name : names) {
@@ -142,6 +240,19 @@
* @since 2.1.0
*/
public void inherit(BasicAttributeContext parent) {
+ // Set template, roles and preparer if not set.
+ if (template == null) {
+ template = parent.template;
+ }
+ if ((roles == null || roles.isEmpty()) && parent.roles != null
+ && !parent.roles.isEmpty()) {
+ roles = new HashSet<String>(parent.roles);
+ }
+ if (preparer == null) {
+ preparer = parent.preparer;
+ }
+
+ // Sets attributes.
cascadedAttributes = addMissingAttributes(
((BasicAttributeContext) parent).cascadedAttributes,
cascadedAttributes);
@@ -302,6 +413,9 @@
/** {@inheritDoc} */
public void clear() {
+ template = null;
+ preparer = null;
+ roles = null;
attributes.clear();
cascadedAttributes.clear();
}
Modified: tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Definition.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Definition.java?rev=632100&r1=632099&r2=632100&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Definition.java (original)
+++ tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Definition.java Thu Feb 28 11:46:25 2008
@@ -20,11 +20,7 @@
*/
package org.apache.tiles;
-
-import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
-import java.util.Set;
/**
* A definition, i.e. a template with (completely or not) filled attributes.
@@ -44,20 +40,6 @@
* Definition name.
*/
protected String name = null;
- /**
- * Template path.
- */
- protected String template = null;
- /**
- * The roles that can render this definition.
- * @since 2.0.6
- */
- protected Set<String> roles = null;
- /**
- * Associated ViewPreparer URL or classname, if defined.
- */
- protected String preparer = null;
-
/**
* Constructor.
@@ -115,85 +97,6 @@
}
/**
- * Access method for the template property.
- *
- * @return the current value of the template property
- */
- public String getTemplate() {
- return template;
- }
-
- /**
- * Sets the value of the template property.
- *
- * @param template the new value of the path property
- */
- public void setTemplate(String template) {
- this.template = template;
- }
-
- /**
- * Access method for the role property.
- *
- * @return the current value of the role property
- */
- public String getRole() {
- String retValue = null;
-
- if (roles != null && !roles.isEmpty()) {
- StringBuilder builder = new StringBuilder();
- Iterator<String> roleIt = roles.iterator();
- if (roleIt.hasNext()) {
- builder.append(roleIt.next());
- while (roleIt.hasNext()) {
- builder.append(",");
- builder.append(roleIt.next());
- }
- retValue = builder.toString();
- }
- }
-
- return retValue;
- }
-
- /**
- * Returns the roles that can render this attribute.
- *
- * @return The enabled roles.
- * @since 2.0.6
- */
- public Set<String> getRoles() {
- return roles;
- }
-
- /**
- * Sets the value of the role property.
- *
- * @param role the new value of the role property
- */
- public void setRole(String role) {
- if (role != null && role.trim().length() > 0) {
- String[] rolesStrings = role.split("\\s*,\\s*");
- roles = new HashSet<String>();
- for (int i = 0; i < rolesStrings.length; i++) {
- roles.add(rolesStrings[i]);
- }
- } else {
- roles = null;
- }
- }
-
- /**
- * Sets the roles that can render this attribute.
- *
- * @param roles The enabled roles.
- * @since 2.0.6
- */
- public void setRoles(Set<String> roles) {
- this.roles = roles;
- }
-
- /**
* Access method for the attributes property. If there is no attributes,
* return an empty map.
*
@@ -284,24 +187,6 @@
}
/**
- * Get associated preparerInstance.
- *
- * @return The preparer name.
- */
- public String getPreparer() {
- return preparer;
- }
-
- /**
- * Set associated preparerInstance URL.
- *
- * @param url Url called locally
- */
- public void setPreparer(String url) {
- this.preparer = url;
- }
-
- /**
* Set extends.
*
* @param name Name of the extended definition.
@@ -317,61 +202,6 @@
*/
public String getExtends() {
return inherit;
- }
-
- /**
- * Inherits the attribute context. If the parameter is a Definition, the
- * other properties (roles, template, preparer) are inherited.
- *
- * @param parent The attribute context to inherit.
- * @since 2.1.0
- */
- @Override
- public void inherit(AttributeContext parent) {
- if (parent instanceof Definition) {
- inherit((Definition) parent);
- } else {
- super.inherit(parent);
- }
- }
-
- /**
- * Inherits the attribute context. If the parameter is a Definition, the
- * other properties (roles, template, preparer) are inherited.
- *
- * @param parent The attribute context to inherit.
- * @since 2.1.0
- */
- @Override
- public void inherit(BasicAttributeContext parent) {
- if (parent instanceof Definition) {
- inherit((Definition) parent);
- } else {
- super.inherit(parent);
- }
- }
-
- /**
- * Inherits the definition, inheriting attribute, i.e. copying if not
- * present, attributes, template, roles, preparer.
- *
- * @param parent The definition to inherit.
- * @since 2.1.0
- */
- public void inherit(Definition parent) {
- super.inherit(parent);
-
- // Set template, roles and preparer if not set
- if (template == null) {
- template = parent.template;
- }
- if ((roles == null || roles.isEmpty()) && parent.roles != null
- && !parent.roles.isEmpty()) {
- roles = new HashSet<String>(parent.roles);
- }
- if (preparer == null) {
- preparer = parent.preparer;
- }
}
/** {@inheritDoc} */
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=632100&r1=632099&r2=632100&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 Thu Feb 28 11:46:25 2008
@@ -599,6 +599,23 @@
pushContext(subContext, request);
try {
+ render(request, definition);
+ } finally {
+ popContext(request);
+ }
+ }
+
+ /**
+ * Renders the specified attribute context.
+ *
+ * @param request The request context.
+ * @param definition The context to render.
+ * @throws TilesException If something goes wrong during rendering.
+ */
+ private void render(TilesRequestContext request, AttributeContext definition)
+ throws TilesException {
+
+ try {
if (definition.getPreparer() != null) {
prepare(request, definition.getPreparer(), true);
}
@@ -612,14 +629,10 @@
request.dispatch(dispatchPath);
// tiles exception so that it doesn't need to be rethrown.
- } catch (TilesException e) {
- throw e;
- } catch (Exception e) {
+ } catch (IOException e) {
LOG.error("Error rendering tile", e);
// TODO it would be nice to make the preparerInstance throw a more specific
throw new TilesException(e.getMessage(), e);
- } finally {
- popContext(request);
}
}