Package org.apache.beehive.netui.util.internal

Examples of org.apache.beehive.netui.util.internal.InternalStringBuilder


    protected void writeAfterBlocks(AbstractRenderAppender sb)
    {
        if (_codeAfter == null || _codeAfter.size() == 0)
            return;

        InternalStringBuilder s = new InternalStringBuilder(256);
        for (Iterator i = _codeAfter.iterator(); i.hasNext();)
        {
            String code = ( String ) i.next();
            s.append(code);
            s.append("\n");
        }
        ScriptRequestState.writeScriptBlock(pageContext.getRequest(), sb, s.toString());
    }
View Full Code Here



        // 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;
        }

        // finish the tree representation and write it
        divRenderer.doEndTag(writer);
        sb.append("\n");
        write(sb.toString());

        if (!(treeRoot instanceof ITreeRootElement)) {
            boolean error = false;
            if (_rootNodeExpandedImage != null) {
                String s = Bundle.getString("Tags_TreeRootImageError", null);
View Full Code Here

        while (true) {
            int index = template.indexOf(placeholder);
            if (index < 0)
                break;
            InternalStringBuilder temp = new InternalStringBuilder(template.substring(0, index));
            temp.append(value);
            temp.append(template.substring(index + placeholder.length()));
            template = temp.toString();
        }
        return template;
    }
View Full Code Here

    {
        // if no map or empty then return
        if (map == null || map.size() == 0)
            return null;

        InternalStringBuilder results = new InternalStringBuilder(128);
        Iterator/*<String>*/ ids = map.keySet().iterator();
        while (ids.hasNext()) {
            String id = (String) ids.next();
            String value = (String) map.get(id);
            if (idScope != null)
                id = idScope + "__" + id;
            String entry = ScriptRequestState.getString(mapEntry, new Object[]{id, value});
            results.append(entry);
        }
        return results.toString();
    }
View Full Code Here

     * @param error
     */
    public void collectChildError(String error)
    {
        if (_errorText == null) {
            _errorText = new InternalStringBuilder(32);
        }
        _errorText.append(error);
    }
View Full Code Here

        // add any attributes to the renderer
        AttributeRenderer.RemoveInfo removes = attrs.addElement(node);

        // get the renderers for this tree...
        InternalStringBuilder img = new InternalStringBuilder(32);


        // Render the beginning of this node
        _divState.clear();
        String tagId = node.getTagId();
        String script = null;
        if (tagId != null) {
            script = renderTagId(_req, tagId, _divState);
        }
        attrs.renderDiv(_divState, node);
        if (_trs.runAtClient) {
            _divState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, TreeElement.TREE_LEVEL, Integer.toString(level));
        }
        sb.append("   ");
        StringBuilderRenderAppender writer = new StringBuilderRenderAppender(sb);
        renderBeforeNode(writer, node);
        _divRenderer.doStartTag(writer, _divState);
        sb.append("\n");
        if (script != null)
            sb.append(script);

        // In devMode we will verify the structure of the tree.  This will not run in
        // production mode.
        ServletContext servletContext = InternalUtils.getServletContext(_req);
        boolean devMode = !AdapterManager.getServletContainerAdapter(servletContext).isInProductionMode();
        if (devMode) {
            boolean error = false;
            InternalStringBuilder errorText = new InternalStringBuilder(64);
            if (node.getName() == null) {
                errorText.append("name");
                error = true;
            }
            if (node.getParent() == null) {
                if (error)
                    errorText.append(", ");
                errorText.append("parent");
            }

            if (error)
                registerTagError(Bundle.getString("Tags_TreeStructureError", errorText.toString()), null);
        }

        // check for tree override properties, the second
        // case here is because the root runs through this an by definitions
        // has InheritableState == state
        InheritableState is = node.getInheritableState();
        if (is != null && is != state) {
            is.setParent(state);
            state = is;
        }

        // Create the appropriate number of indents
        // These are either the spacer.gif if the parent is the last in the line or the
        // vertical line gif if the parent is not the last child.
        _imgState.clear();
        _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, WIDTH, "16px");
        _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, BORDER, "0");
        _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, ALT, "", false);
        for (int i = 0; i < level; i++) {
            int levels = level - i;
            TreeElement parent = node;
            for (int j = 1; j <= levels; j++)
                parent = parent.getParent();

            img.setLength(0);
            img.append(state.getImageRoot());
            img.append('/');
            if (parent.isLast()) {
                img.append(state.getImageSpacer());
                _imgState.style = null;
            }
            else {
                img.append(state.getVerticalLineImage());
                _imgState.style = "vertical-align:bottom;";
            }
            sb.append("      ");
            _imgState.src = img.toString();
            _imageRenderer.doStartTag(writer, _imgState);
            _imageRenderer.doEndTag(writer);
            sb.append("\n");
        }

        // boolean flag that will indicate if there is an open anchor created
        boolean closeAnchor = false;
        if (!_trs.runAtClient)
            closeAnchor = renderExpansionAnchor(sb, _anchorRenderer, node, nodeName, state);
        else {
            // Render client expansion and initialize the tree JavaScript support
            closeAnchor = renderClientExpansionAnchor(sb, _anchorRenderer, node, encodedNodeName, state);
        }

        // place the image into the anchor....
        // The type of the image depends upon the position and the type of the node.
        String alt = "";
        img.setLength(0);
        img.append(state.getImageRoot());
        img.append('/');
        if (node.isLeaf()) {                        // leaf node either last or middle
            if (node.isLast())
                img.append(state.getLastLineJoinImage());
            else
                img.append(state.getLineJoinImage());
        }
        else if (node.isExpanded()) {               // interior node that is expanded
            alt = Bundle.getString("Tags_TreeAltTextCollapse", null);
            String rImg = null;
            if (node.getParent() == null && node instanceof ITreeRootElement) {
                rImg = ((ITreeRootElement) node).getRootNodeExpandedImage();
                if (rImg != null) {
                    img.append(rImg);
                }
            }
            if (rImg == null) {
                if (node.isLast())
                    img.append(state.getLastNodeExpandedImage());
                else
                    img.append(state.getNodeExpandedImage());
            }
        }
        else {                                      // interior not expanded
            alt = Bundle.getString("Tags_TreeAltTextExpand", null);
            String rImg = null;
            if (node.getParent() == null && node instanceof ITreeRootElement) {
                rImg = ((ITreeRootElement) node).getRootNodeCollapsedImage();
                if (rImg != null) {
                    img.append(rImg);
                }
            }
            if (rImg == null) {
                if (node.isLast())
                    img.append(state.getLastNodeCollapsedImage());
                else
                    img.append(state.getNodeCollapsedImage());
            }
        }

        // write out the image which occurs next to the icon
        if (!closeAnchor)
            sb.append("      ");

        _imgState.clear();
        _imgState.src = img.toString();
        _imgState.style = "vertical-align:bottom;";
        _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, BORDER, "0");
        _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, ALT, alt, false);

        _imageRenderer.doStartTag(writer, _imgState);
        _imageRenderer.doEndTag(writer);

        // close the anchor if one was openned...
        if (closeAnchor)
            _anchorRenderer.doEndTag(writer);
        sb.append("\n");

        // Calculate the selection link for this node, if the node is disabled, we can skip
        // this because a disabled node may not be selected.
        String selectionLink = null;
        if (!node.isDisabled()) {

            // The action on the node overrides all.  Otherwise, check to see if there
            // is either an href or clientAction.  If neither is set, then we inherit the
            // action defined on the trees inheritable state.
            String action = node.getAction();
            if (action == null) {
                selectionLink = node.getHref();
                if (selectionLink == null && node.getClientAction() != null)
                    selectionLink = "";
                if (selectionLink == null)
                    action = state.getSelectionAction();
            }

            // create the selection link
            if (action != null && selectionLink == null) {

                HashMap params = null;
                boolean remove = false;
                params = node.getParams();
                if (params == null) {
                    params = new HashMap();
                    remove = true;
                }
                params.put(TreeElement.SELECTED_NODE, nodeName);
                if (_trs.tagId != null) {
                    params.put(TreeElement.TREE_ID, _trs.tagId);
                }

                // Add the jpf ScopeID param if necessary.
                String scope = node.getScope();
                if (scope != null) {
                    params.put(ScopedServletUtils.SCOPE_ID_PARAM, scope);
                }

                String uri = null;
                try {
                    boolean xml = TagRenderingBase.Factory.isXHTML(_req);
                    uri = PageFlowUtils.getRewrittenActionURI(_servletContext, _req, _res, action, params, null, xml);
                }
                catch (URISyntaxException e) {
                    // report the error...
                    String s = Bundle.getString("Tags_Tree_Node_URLException",
                            new Object[]{action, e.getMessage()});
                    registerTagError(s, e);
                }

                if (remove) {
                    params.remove(TreeElement.SELECTED_NODE);
                    if (_trs.tagId != null) {
                        params.remove(TreeElement.TREE_ID);
                    }

                    if (scope != null) {
                        params.remove(ScopedServletUtils.SCOPE_ID_PARAM);
                    }
                }

                if (uri != null) {
                    selectionLink = _res.encodeURL(uri);
                }
            }
        }

        TagRenderingBase endRender = null;
        // if there is a selection link we need to put an anchor out.
        if (selectionLink != null) {
            _anchorState.clear();
            _anchorState.href = selectionLink;
            String target = node.getTarget();
            if (target == null) {
                target = state.getSelectionTarget();
            }
            _anchorState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, TARGET, target);
            String title = node.getTitle();
            _anchorState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, TITLE, title);

            // set the selection styles
            if (node.isSelected()) {
                _anchorState.style = _trs.selectedStyle;
                _anchorState.styleClass = _trs.selectedStyleClass;
            }
            else {
                _anchorState.style = _trs.unselectedStyle;
                _anchorState.styleClass = _trs.unselectedStyleClass;
            }
            if (_anchorState.style == null && _anchorState.styleClass == null) {
                _anchorState.style = "text-decoration: none";
            }

            // render any attributes applied to the HTML
            attrs.renderSelectionLink(_anchorState, node);

            // render the runAtClient attributes
            if (_trs.runAtClient) {
                String action = node.getClientAction();
                if (action != null) {
                    action = HtmlUtils.escapeEscapes(action);
                    action = ScriptRequestState.getString("netuiAction", new Object[]{action});
                }
                _anchorState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, ONCLICK, action);
                // Jira 299
                //_anchorState.onClick = action;
            }

            // actually render the anchor.
            sb.append("      ");
            _anchorRenderer.doStartTag(writer, _anchorState);
            endRender = _anchorRenderer;
        }
        else {
            // This node doesn's support selection.  This means we consider it disabled.  We will
            // put a span around it and set the style/class to indicate that it is disabled.
            _spanState.clear();
            _spanState.styleClass = _trs.disabledStyleClass;
            _spanState.style = _trs.disabledStyle;
            sb.append("      ");
            _spanRenderer.doStartTag(writer, _spanState);
            endRender = _spanRenderer;
        }
        sb.append("&nbsp;");

        // Render the icon for this node, there will always unless the tree turns off default
        // icons by setting the useDefaultIcons attribute to false.
        String icon = node.getIcon();
        if (icon == null) {
            icon = state.getIconRoot() + "/" + state.getItemIcon();
        }
        else {
            icon = state.getIconRoot() + "/" + icon;
        }

        // write out the icon
        String label = node.getLabel();
        if (icon != null) {
            _imgState.clear();
            _imgState.src = icon;
            _imgState.style = "vertical-align:text-top";
            alt = null;
            if (label != null && node.isLabelLegalAsAlt())
                alt = label;
            else
                alt = node.getTitle();
            if (alt == null)
                alt = Bundle.getString("Tags_TreeAltText", null);
            _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, ALT, alt, false);
            _imgState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, BORDER, "0");

            // set the inheritted attributes
            attrs.renderIconImage(_imgState, node);
            _imageRenderer.doStartTag(writer, _imgState);
            _imageRenderer.doEndTag(writer);
            sb.append("&nbsp;");
        }

        // Render the label for this node (if any)
        if (label != null) {
            if (_trs.escapeContent) {
                InternalStringBuilder s = new InternalStringBuilder(label.length() + 16);
                StringBuilderRenderAppender sbAppend = new StringBuilderRenderAppender(sb);
                HtmlUtils.filter(label, sbAppend);
                label = s.toString();
            }
            sb.append(label);
            sb.append("&nbsp;");
        }
        endRender.doEndTag(writer);

        // if there is content then we should render that here...
        String ctnt = node.getContent();
        if (ctnt != null) {
            if (_trs.escapeContent) {
                InternalStringBuilder s = new InternalStringBuilder(ctnt.length() + 16);
                StringBuilderRenderAppender sbAppend = new StringBuilderRenderAppender(sb);
                HtmlUtils.filter(ctnt, sbAppend);
                ctnt = s.toString();
            }
            sb.append("\n      ");
            sb.append(ctnt);
        }
View Full Code Here

        validateOptions.setErrorListener(errorList);
        boolean isValid = _config.validate(validateOptions);

        // Throw an exception if the XML is invalid.
        if(!isValid) {
            InternalStringBuilder msg = new InternalStringBuilder("Invalid NetUI configuration file.");

            for(int i = 0; i < errorList.size(); i++) {
                XmlError error = (XmlError)errorList.get(i);
                msg.append("\n    line ");
                msg.append(error.getLine());
                msg.append(": ");
                msg.append(error.getMessage());
                msg.append(" (");
                msg.append(error.getCursorLocation().toString());
                msg.append(")");
            }

            throw new ConfigInitializationException(msg.toString());
        }
    }
View Full Code Here

     * @param t                 a Throwable exception to format
     * @param includeStackTrace a boolean that determines whether to include the stack trace in the formatted output
     * @return the formatted error message, optionally including the stack trace.
     */
    public static String format(String message, Throwable t, boolean includeStackTrace) {
        InternalStringBuilder buf = new InternalStringBuilder();

        if(message != null) {
            buf.append(message);

            Throwable cause = discoverRootCause(t);
            if(cause != null) {
                buf.append(HTML_LINE_BREAK);
                buf.append(CAUSED_BY);
                buf.append(": ");
                buf.append(cause.toString());
            }
        }

        if(includeStackTrace) {
            if(message != null)
                buf.append(HTML_LINE_BREAK);

            String st = addStackTrace(t);
            buf.append(st);

            Throwable rootCause = null;
            Throwable tmp = t;
            while(hasRootCause(tmp) && (rootCause = discoverRootCause(tmp)) != null) {
                st = addStackTrace(rootCause);
                buf.append(HTML_LINE_BREAK);
                buf.append(st);
                tmp = rootCause;
            }
        }

        return buf.toString().replaceAll(LINE_BREAK, HTML_LINE_BREAK);
    }
View Full Code Here

        return buf.toString().replaceAll(LINE_BREAK, HTML_LINE_BREAK);
    }

    private static final String addStackTrace(Throwable t) {
        InternalStringBuilder buf = new InternalStringBuilder();
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        t.printStackTrace(pw);
        pw.flush();
        pw.close();

        String error = sw.toString();
        int pos = error.indexOf(LINE_BREAK);
        if(pos != -1) {
            String lineOne = error.substring(0, pos);
            String rest = error.substring(pos);

            buf.append("<span class='pfErrorLineOne'>");
            buf.append(lineOne);
            buf.append("</span>");
            buf.append(rest);
        } else {
            buf.append(sw.toString());
        }

        return buf.toString();
    }
View Full Code Here

    private static String registeredConvertersToString() {
        if(TO_STRING != null)
            return TO_STRING;

        InternalStringBuilder sb = new InternalStringBuilder(256);
        sb.append(TypeUtils.class.getName() + " regestered converters (class name, TypeConverter implementation):\n");
        sb.append(":::::\n");
        Iterator iterator = TYPE_CONVERTERS.keySet().iterator();
        while(iterator.hasNext()) {
            Class key = (Class)iterator.next();
            String keyName = key.getName();
            String value = (TYPE_CONVERTERS.get(key) != null ? TYPE_CONVERTERS.get(key).getClass().getName() : "null");
            sb.append(keyName);
            sb.append(", ");
            sb.append(value);
            sb.append("\n");
        }
        sb.append(":::::\n");
        TO_STRING = sb.toString();

        return TO_STRING;
    }
View Full Code Here

TOP

Related Classes of org.apache.beehive.netui.util.internal.InternalStringBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.