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.http.HttpServletRequest;
23: import javax.servlet.jsp.JspContext;
24:
25: import org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel;
26: import org.apache.beehive.netui.databinding.datagrid.runtime.model.cell.AnchorCellModel;
27: import org.apache.beehive.netui.databinding.datagrid.api.rendering.CellModel;
28: import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil;
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.tags.rendering.AbstractRenderAppender;
32: import org.apache.beehive.netui.tags.rendering.SpanTag;
33: import org.apache.beehive.netui.tags.rendering.AnchorTag;
34: import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
35: import org.apache.beehive.netui.util.logging.Logger;
36: import org.apache.beehive.netui.util.Bundle;
37:
38: /**
39: *
40: */
41: public final class AnchorCellDecorator extends CellDecorator {
42:
43: private static final Logger LOGGER = Logger
44: .getInstance(AnchorCellDecorator.class);
45:
46: public void decorate(JspContext jspContext,
47: AbstractRenderAppender appender, CellModel columnModel)
48: throws CellDecoratorException {
49:
50: assert columnModel instanceof AnchorCellModel;
51:
52: AnchorCellModel anchorCellModel = (AnchorCellModel) columnModel;
53: HttpServletRequest request = JspUtil.getRequest(jspContext);
54:
55: SpanTag.State spanState = new SpanTag.State();
56: AnchorTag.State anchorState = anchorCellModel.getAnchorState();
57:
58: DataGridTagModel dgm = columnModel.getDataGridTagModel();
59: assert dgm != null;
60:
61: String url = null;
62: try {
63: url = JspUtil.createURL(anchorCellModel.getHref(),
64: anchorCellModel.getAction(), null, anchorCellModel
65: .getScopeId(), anchorCellModel.getParams(),
66: jspContext);
67: } catch (URISyntaxException use) {
68: String message = Bundle.getErrorString(
69: "Rendering_URLException", new Object[] {
70: anchorCellModel.getHref(),
71: anchorCellModel.getAction() });
72: LOGGER.error(message, use);
73: throw new CellDecoratorException(message, use);
74: }
75:
76: anchorState.href = url;
77:
78: TagRenderingBase anchorTag = TagRenderingBase.Factory
79: .getRendering(TagRenderingBase.ANCHOR_TAG, request);
80: TagRenderingBase spanTag = TagRenderingBase.Factory
81: .getRendering(TagRenderingBase.SPAN_TAG, request);
82:
83: anchorTag.doStartTag(appender, anchorState);
84: spanTag.doStartTag(appender, spanState);
85:
86: if (anchorCellModel.getValue() != null)
87: appender.append(anchorCellModel.getValue().toString());
88:
89: spanTag.doEndTag(appender);
90: anchorTag.doEndTag(appender);
91:
92: String javascript = anchorCellModel.getJavascript();
93: if (javascript != null)
94: appender.append(javascript);
95: }
96: }
|