reportErrors();
}
}
// Set the image Root if it is not set.
PageContext pageContext = getPageContext();
if (_iState.getImageRoot() == null)
_iState.setImageRoot(((HttpServletRequest) pageContext.getRequest()).getContextPath() + "/" +
TagConfig.getTreeImageLocation());
// errors should have been caught above
TreeElement treeRoot = getTreeRoot(_expr);
// if the tree root hasn't been defined, then we need to update the what the object that is
// pointed at by the dataSource expression.
if (treeRoot == null) {
if (_rootNode != null) {
try {
String datasource = "{" + _dataSource + "}";
_expr.updateExpression(datasource, _rootNode, pageContext);
}
catch (ExpressionUpdateException e) {
String s = Bundle.getString("Tags_UnableToWriteTree", new Object[]{_dataSource, e.getMessage()});
registerTagError(s, null);
reportErrors();
return;
}
treeRoot = _rootNode;
}
// indicate an update error and return
if (treeRoot == null) {
String s = Bundle.getString("Tags_TreeNoAttribute", _dataSource);
registerTagError(s, null);
reportErrors();
return;
}
}
// set the root image
if (treeRoot instanceof ITreeRootElement) {
ITreeRootElement tre = (ITreeRootElement) treeRoot;
if (tre.getRootNodeExpandedImage() == null) {
tre.setRootNodeExpandedImage((_rootNodeExpandedImage != null) ?
_rootNodeExpandedImage : InheritableState.IMAGE_ROOT_EXPANDED);
}
if (tre.getRootNodeCollapsedImage() == null) {
tre.setRootNodeCollapsedImage((_rootNodeCollapsedImage != null) ?
_rootNodeCollapsedImage : InheritableState.IMAGE_ROOT_COLLAPSED);
}
}
// if we are running the tree at the client, then
// we need to register the tree with the NameService
if (_trs.runAtClient) {
// it's currently not legal to have a runAtClient but not be an instance of INameable which is
// implemented by the ITreeRootElement.
if (!(treeRoot instanceof INameable)) {
String s = Bundle.getString("Tags_TreeRunAtClientRoot", null);
registerTagError(s, null);
reportErrors();
return;
}
// name the tree if it hasn't been named already
INameable in = (INameable) treeRoot;
String o = in.getObjectName();
if (o == null) {
NameService ns = NameService.instance(pageContext.getSession());
ns.nameObject("Tree", in);
ns.put(in);
}
}
// prepare to render the tree
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
InternalStringBuilder sb = new InternalStringBuilder(1024);
StringBuilderRenderAppender writer = new StringBuilderRenderAppender(sb);
// this is the treeId from the request. If there was an tree expansion this will be
// non-null and it identifies what tree had the expansion request.
// we need to qualify the tree based upon the tagId
assert(_trs.tagId != null);
_trs.tagId = getIdForTagId(_trs.tagId);
String treeId = request.getParameter(TreeElement.TREE_ID);
if (treeId != null && _trs.tagId.equals(treeId)) {
TreeHelpers.processTreeRequest(treeId, treeRoot, request, response);
}
// check for the nodes that are expanded...
// Add the script support for the tree.
if (_trs.runAtClient) {
IScriptReporter sr = getScriptReporter();
if (sr == null) {
String s = Bundle.getString("Tags_TreeRunAtClientSC", null);
registerTagError(s, null);
reportErrors();
return;
}
ScriptRequestState srs = ScriptRequestState.getScriptRequestState(request);
if (!srs.isFeatureWritten(CoreScriptFeature.DYNAMIC_INIT)) {
String s = Bundle.getString("Tags_TreeHtmlRunAtClient", null);
registerTagError(s, null);
reportErrors();
return;
}
assert(treeRoot instanceof ITreeRootElement);
ITreeRootElement tre = (ITreeRootElement) treeRoot;
Object[] args = new Object[8];
args[0] = _iState.getImageRoot() + "/";
args[1] = tre.getObjectName();
args[2] = _iState.getNodeCollapsedImage();
args[3] = _iState.getNodeExpandedImage();
args[4] = _iState.getLastNodeCollapsedImage();
args[5] = _iState.getLastNodeExpandedImage();
args[6] = Bundle.getString("Tags_TreeAltTextExpand", null);
args[7] = Bundle.getString("Tags_TreeAltTextCollapse", null);
srs.writeFeature(sr, writer, CoreScriptFeature.TREE_INIT, false, false, args);
tre.setTreeRenderState(_trs);
tre.setInheritableState(_iState);
}
// create a containing tree level <div> and place the tree level styles on it.
_divState.styleClass = _treeStyleClass;
_divState.style = _treeStyle;
String divId = null;
if (_renderTagIdLookup) {
_divState.id = _trs.tagId;
divId = _divState.id;
}
// if we are running on the client then we need to output the tree name into the top level tree <div> tag
if (_trs.runAtClient) {
_divState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, "netui:treeName",
((INameable) treeRoot).getObjectName());
}
TagRenderingBase divRenderer = TagRenderingBase.Factory.getRendering(TagRenderingBase.DIV_TAG, request);
divRenderer.doStartTag(writer, _divState);
sb.append("\n");
// Render the tree.
AttributeRenderer extraAttrs = new AttributeRenderer();
TagTreeRenderer ttr = new TagTreeRenderer(this, _trs, request, response, pageContext.getServletContext());
ttr.render(sb, treeRoot, 0, extraAttrs, _iState);
if (hasErrors()) {
reportErrors();
return;
}