This project has retired. For details please refer to its Attic page.
UntypedAttributeRenderer xref
View Javadoc

1   /*
2    * $Id: UntypedAttributeRenderer.java 821299 2009-10-03 12:15:05Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.tiles.renderer.impl;
22  
23  import java.io.IOException;
24  
25  import org.apache.tiles.Attribute;
26  import org.apache.tiles.TilesContainer;
27  import org.apache.tiles.awareness.TilesContainerAware;
28  import org.apache.tiles.context.TilesRequestContext;
29  import org.apache.tiles.renderer.RendererException;
30  
31  /***
32   * Renders an attribute that has no associated renderer.
33   *
34   * @version $Rev: 821299 $ $Date: 2009-10-03 14:15:05 +0200 (sab, 03 ott 2009) $
35   * @since 2.1.0
36   * @deprecated Use {@link ChainedDelegateAttributeRenderer}.
37   */
38  public class UntypedAttributeRenderer extends AbstractBaseAttributeRenderer
39          implements TilesContainerAware {
40  
41      /***
42       * The Tiles container.
43       */
44      private TilesContainer container;
45  
46      /*** {@inheritDoc} */
47      public void setContainer(TilesContainer container) {
48          this.container = container;
49      }
50  
51      /*** {@inheritDoc} */
52      @Override
53      public void write(Object value, Attribute attribute,
54              TilesRequestContext request)
55              throws IOException {
56          if (value instanceof String) {
57              String valueString = (String) value;
58              Object[] requestItems = request.getRequestObjects();
59              if (container.isValidDefinition(valueString, requestItems)) {
60                  container.render(valueString, requestItems);
61              } else if (valueString.startsWith("/")) {
62                  request.dispatch(valueString);
63              } else {
64                  request.getWriter().write(valueString);
65              }
66          } else {
67              throw new RendererException(
68                      "Cannot render an untyped object attribute");
69          }
70      }
71  }