1 /*
2 * $Id: DefinitionRenderer.java 1215008 2011-12-16 00:31:49Z nlebas $
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;
22
23 import java.io.IOException;
24
25 import org.apache.tiles.TilesContainer;
26 import org.apache.tiles.request.Request;
27 import org.apache.tiles.request.render.CannotRenderException;
28 import org.apache.tiles.request.render.Renderer;
29
30 /**
31 * Renders an attribute that contains a reference to a definition.
32 *
33 * @version $Rev: 1215008 $ $Date: 2011-12-16 11:31:49 +1100 (Fri, 16 Dec 2011) $
34 * @since 3.0.0
35 */
36 public class DefinitionRenderer implements Renderer {
37
38 /**
39 * The Tiles container.
40 */
41 private TilesContainer container;
42
43 /**
44 * Constructor.
45 *
46 * @param container The Tiles container.
47 */
48 public DefinitionRenderer(TilesContainer container) {
49 this.container = container;
50 }
51
52 /** {@inheritDoc} */
53 @Override
54 public void render(String path, Request request) throws IOException {
55 if (path == null) {
56 throw new CannotRenderException("Cannot dispatch a null path");
57 }
58
59 container.render(path, request);
60 }
61
62 /** {@inheritDoc} */
63 public boolean isRenderable(String path, Request request) {
64 return path != null && container.isValidDefinition(path, request);
65 }
66 }