01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.databinding.datagrid.runtime.rendering.cell;
20:
21: import java.net.URISyntaxException;
22: import javax.servlet.jsp.JspContext;
23: import javax.servlet.http.HttpServletRequest;
24:
25: import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender;
26: import org.apache.beehive.netui.tags.rendering.AnchorTag;
27: import org.apache.beehive.netui.tags.rendering.ImageTag;
28: import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
29: import org.apache.beehive.netui.databinding.datagrid.api.exceptions.CellDecoratorException;
30: import org.apache.beehive.netui.databinding.datagrid.api.rendering.CellDecorator;
31: import org.apache.beehive.netui.databinding.datagrid.api.rendering.CellModel;
32: import org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel;
33: import org.apache.beehive.netui.databinding.datagrid.runtime.model.cell.ImageAnchorCellModel;
34: import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil;
35: import org.apache.beehive.netui.util.logging.Logger;
36: import org.apache.beehive.netui.util.Bundle;
37:
38: /**
39: */
40: public final class ImageAnchorCellDecorator extends CellDecorator {
41:
42: private static final Logger LOGGER = Logger
43: .getInstance(ImageAnchorCellDecorator.class);
44:
45: public void decorate(JspContext jspContext,
46: AbstractRenderAppender appender, CellModel cellModel)
47: throws CellDecoratorException {
48: HttpServletRequest request = JspUtil.getRequest(jspContext);
49:
50: assert cellModel instanceof ImageAnchorCellModel;
51: ImageAnchorCellModel imageAnchorCellModel = (ImageAnchorCellModel) cellModel;
52:
53: AnchorTag.State anchorState = imageAnchorCellModel
54: .getAnchorState();
55: ImageTag.State imageState = imageAnchorCellModel
56: .getImageState();
57:
58: DataGridTagModel dgm = cellModel.getDataGridTagModel();
59: assert dgm != null;
60:
61: String url = null;
62: try {
63: url = JspUtil.createURL(imageAnchorCellModel.getHref(),
64: imageAnchorCellModel.getAction(), null,
65: imageAnchorCellModel.getScopeId(),
66: imageAnchorCellModel.getParams(), jspContext);
67: } catch (URISyntaxException use) {
68: String message = Bundle.getErrorString(
69: "Rendering_URLException", new Object[] {
70: imageAnchorCellModel.getHref(),
71: imageAnchorCellModel.getAction() });
72: LOGGER.error(message, use);
73: throw new CellDecoratorException(message, use);
74: }
75:
76: anchorState.href = url;
77:
78: TagRenderingBase imageTag = TagRenderingBase.Factory
79: .getRendering(TagRenderingBase.IMAGE_TAG, request);
80: TagRenderingBase anchorTag = TagRenderingBase.Factory
81: .getRendering(TagRenderingBase.ANCHOR_TAG, request);
82:
83: anchorTag.doStartTag(appender, anchorState);
84: imageTag.doStartTag(appender, imageState);
85: imageTag.doEndTag(appender);
86: anchorTag.doEndTag(appender);
87:
88: String script = imageAnchorCellModel.getJavascript();
89: if (script != null)
90: appender.append(script);
91: }
92: }
|