Search in sources :

Example 1 with Element

use of com.revolsys.ui.html.view.Element in project com.revolsys.open by revolsys.

the class ViewAttributeController method render.

private void render(final HttpServletResponse response, final Object object) throws IOException {
    if (object != null) {
        final PrintWriter out = response.getWriter();
        if (object instanceof Element) {
            final Element element = (Element) object;
            element.serialize(out, false);
        } else {
            out.print(object);
        }
    }
}
Also used : Element(com.revolsys.ui.html.view.Element) PrintWriter(java.io.PrintWriter)

Example 2 with Element

use of com.revolsys.ui.html.view.Element in project com.revolsys.open by revolsys.

the class PageInfoHttpMessageConverter method writeHtml.

@SuppressWarnings("unchecked")
private void writeHtml(final OutputStream out, final String url, final PageInfo pageInfo, final boolean showTitle) {
    final XmlWriter writer = new XmlWriter(out);
    writer.startTag(HtmlElem.DIV);
    if (showTitle) {
        writer.element(HtmlElem.H1, pageInfo.getTitle());
        final DocInfo docInfo = pageInfo.getDefaultDocumentation();
        if (docInfo != null) {
            writer.startTag(HtmlElem.DIV);
            writer.attribute(HtmlAttr.STYLE, "margin-bottom: 1em");
            final String description = docInfo.getDescription();
            if (description != null) {
                if (docInfo.isHtml()) {
                    writer.write(description);
                } else {
                    writer.element(HtmlElem.P, description);
                }
            }
            writer.endTag(HtmlElem.DIV);
        }
    }
    final HttpServletRequest request = HttpServletUtils.getRequest();
    for (final String method : pageInfo.getMethods()) {
        @SuppressWarnings("rawtypes") final Map parameterMap = request.getParameterMap();
        writeMethod(writer, url, pageInfo, method, parameterMap);
    }
    final Map<String, PageInfo> pages = pageInfo.getPages();
    final Element pagesElement = pageInfo.getPagesElement();
    if (pagesElement != null) {
        pagesElement.serialize(writer);
    } else if (!pages.isEmpty()) {
        writer.startTag(HtmlElem.DIV);
        writer.attribute(HtmlAttr.CLASS, "resources");
        writer.startTag(HtmlElem.DL);
        for (final Entry<String, PageInfo> childPage : pages.entrySet()) {
            final String childPath = childPage.getKey();
            final PageInfo childPageInfo = childPage.getValue();
            String childUri;
            if (childPath.startsWith("/") || childPath.startsWith("http")) {
                childUri = childPath;
            } else if (url.charAt(url.length() - 1) != '/') {
                childUri = url + "/" + childPath;
            } else {
                childUri = url + childPath;
            }
            writer.startTag(HtmlElem.DT);
            final String childTitle = childPageInfo.getTitle();
            HtmlUtil.serializeA(writer, null, childUri, childTitle);
            writer.endTag(HtmlElem.DT);
            final boolean isTemplate = childPath.matches(".*(\\{[^\\}]+\\}.*)+");
            final String childDescription = childPageInfo.getDescription();
            if (childDescription != null || isTemplate) {
                writer.startTag(HtmlElem.DD);
                if (childDescription != null) {
                    writer.element(HtmlElem.P, childDescription);
                }
                if (isTemplate) {
                    writer.startTag(HtmlElem.FORM);
                    writer.attribute(HtmlAttr.ACTION, childUri);
                    writer.attribute(HtmlAttr.METHOD, "get");
                    for (final String pathElement : childPath.split("/")) {
                        if (pathElement.matches("\\{[^\\}]+\\}")) {
                            final String name = pathElement.substring(1, pathElement.length() - 1);
                            HtmlUtil.serializeTextInput(writer, name, name, 20, 255);
                        }
                    }
                    HtmlUtil.serializeButtonInput(writer, "go", "doGet(this.form)");
                    writer.endTag(HtmlElem.FORM);
                }
                writer.endTag(HtmlElem.DD);
            }
        }
        writer.endTag(HtmlElem.DL);
        writer.endTag(HtmlElem.DIV);
    }
    writer.endTag(HtmlElem.DIV);
    writer.endDocument();
    writer.close();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DocInfo(com.revolsys.ui.model.DocInfo) PageInfo(com.revolsys.ui.model.PageInfo) Entry(java.util.Map.Entry) Element(com.revolsys.ui.html.view.Element) HashMap(java.util.HashMap) Map(java.util.Map) XmlWriter(com.revolsys.record.io.format.xml.XmlWriter)

Example 3 with Element

use of com.revolsys.ui.html.view.Element in project com.revolsys.open by revolsys.

the class StylesTag method serializeElements.

/**
 * Write out the HTML tags for each element.
 *
 * @param styles The styles.
 * @throws IOException If there was an error writing the styles.
 */
private void serializeElements(final Collection styles) throws IOException {
    final JspWriter out = this.pageContext.getOut();
    final Iterator elements = styles.iterator();
    while (elements.hasNext()) {
        final Element element = (Element) elements.next();
        element.serialize(out);
    }
}
Also used : Element(com.revolsys.ui.html.view.Element) Iterator(java.util.Iterator) JspWriter(javax.servlet.jsp.JspWriter)

Example 4 with Element

use of com.revolsys.ui.html.view.Element in project com.revolsys.open by revolsys.

the class ElementComponent method includeComponent.

@Override
public void includeComponent(final PageContext context) throws ServletException, IOException {
    final Object object = context.findAttribute(this.attribute);
    if (object instanceof Element) {
        final Element element = (Element) object;
        final Writer out = context.getOut();
        element.serialize(out);
    }
}
Also used : Element(com.revolsys.ui.html.view.Element) Writer(java.io.Writer)

Example 5 with Element

use of com.revolsys.ui.html.view.Element in project com.revolsys.open by revolsys.

the class HtmlUiBuilder method addObjectViewPage.

public void addObjectViewPage(final TabElementContainer tabs, final Object object, final String prefix) {
    final HttpServletRequest request = getRequest();
    if (object == null) {
        throw new PageNotFoundException();
    } else {
        final String pageName = getName(prefix, "view");
        final Page page = getPage(pageName);
        if (page == null) {
            throw new PageNotFoundException("Page not found " + pageName);
        } else {
            final List<KeySerializer> serializers = getSerializers(pageName, "view");
            final Element detailView = newDetailView(object, serializers);
            setPageTitle(request, pageName);
            final Menu actionMenu = new Menu();
            final Menu editMenu = addMenuItem(actionMenu, prefix, "edit", "Edit", "_top");
            if (editMenu != null) {
                editMenu.addProperty("buttonClass", "btn-primary");
            }
            final ElementContainer view = new ElementContainer(detailView);
            addMenuElement(view, actionMenu);
            final String tabId = getTypeName() + "_" + pageName;
            final String title = getPageTitle(pageName);
            tabs.add(tabId, title, view);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) ElementContainer(com.revolsys.ui.html.view.ElementContainer) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) ButtonsToolbarElement(com.revolsys.ui.html.view.ButtonsToolbarElement) Element(com.revolsys.ui.html.view.Element) Page(com.revolsys.ui.web.config.Page) Menu(com.revolsys.ui.model.Menu) KeySerializer(com.revolsys.ui.html.serializer.key.KeySerializer)

Aggregations

Element (com.revolsys.ui.html.view.Element)15 Iterator (java.util.Iterator)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Decorator (com.revolsys.ui.html.decorator.Decorator)2 SetObject (com.revolsys.ui.html.view.SetObject)2 Writer (java.io.Writer)2 XmlWriter (com.revolsys.record.io.format.xml.XmlWriter)1 HiddenField (com.revolsys.ui.html.fields.HiddenField)1 KeySerializer (com.revolsys.ui.html.serializer.key.KeySerializer)1 ButtonsToolbarElement (com.revolsys.ui.html.view.ButtonsToolbarElement)1 ElementContainer (com.revolsys.ui.html.view.ElementContainer)1 TabElementContainer (com.revolsys.ui.html.view.TabElementContainer)1 DocInfo (com.revolsys.ui.model.DocInfo)1 Menu (com.revolsys.ui.model.Menu)1 PageInfo (com.revolsys.ui.model.PageInfo)1 Page (com.revolsys.ui.web.config.Page)1 PageNotFoundException (com.revolsys.ui.web.exception.PageNotFoundException)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1