Search in sources :

Example 1 with XhtmlBuffer

use of com.manydesigns.elements.xml.XhtmlBuffer in project Portofino by ManyDesigns.

the class SessionMessagesTag method doStartTag.

public int doStartTag() {
    JspWriter out = pageContext.getOut();
    XhtmlBuffer xb = new XhtmlBuffer(out);
    List<String> errorMessages = com.manydesigns.elements.messages.SessionMessages.consumeErrorMessages();
    List<String> warningMessages = com.manydesigns.elements.messages.SessionMessages.consumeWarningMessages();
    List<String> infoMessages = com.manydesigns.elements.messages.SessionMessages.consumeInfoMessages();
    if (!errorMessages.isEmpty()) {
        xb.openElement("div");
        xb.addAttribute("class", "alert alert-danger alert-dismissable fade in");
        writeCloseButton(xb);
        writeList(xb, errorMessages, "errorMessages");
        xb.closeElement("div");
    }
    if (!warningMessages.isEmpty()) {
        xb.openElement("div");
        xb.addAttribute("class", "alert alert-warning alert-dismissable fade in");
        writeCloseButton(xb);
        writeList(xb, warningMessages, "warningMessages");
        xb.closeElement("div");
    }
    if (!infoMessages.isEmpty()) {
        xb.openElement("div");
        xb.addAttribute("class", "alert alert-success alert-dismissable fade in");
        writeCloseButton(xb);
        writeList(xb, infoMessages, "infoMessages");
        xb.closeElement("div");
    }
    return SKIP_BODY;
}
Also used : XhtmlBuffer(com.manydesigns.elements.xml.XhtmlBuffer) JspWriter(javax.servlet.jsp.JspWriter)

Example 2 with XhtmlBuffer

use of com.manydesigns.elements.xml.XhtmlBuffer in project Portofino by ManyDesigns.

the class WriteTag method doTag.

private void doTag(JspWriter out) throws OgnlException {
    Integer scopeCode;
    if (scope == null) {
        scopeCode = null;
    } else if (APPLICATION_SCOPE.equals(scope)) {
        scopeCode = PageContext.APPLICATION_SCOPE;
    } else if (SESSION_SCOPE.equals(scope)) {
        scopeCode = PageContext.SESSION_SCOPE;
    } else if (REQUEST_SCOPE.equals(scope)) {
        scopeCode = PageContext.REQUEST_SCOPE;
    } else if (PAGE_SCOPE.equals(scope)) {
        scopeCode = PageContext.PAGE_SCOPE;
    } else {
        logger.warn("Unknown scope: {}", scope);
        return;
    }
    Object bean;
    if (scopeCode != null) {
        bean = pageContext.getAttribute(name, scopeCode);
    } else {
        bean = pageContext.findAttribute(name);
    }
    if (bean == null) {
        logger.warn("Bean {} not found in scope {}", name, scope);
        return;
    }
    if (property != null) {
        // use property as Ognl expression
        OgnlContext ognlContext = ElementsThreadLocals.getOgnlContext();
        bean = OgnlUtils.getValueQuietly(property, ognlContext, bean);
    }
    if (bean instanceof XhtmlFragment) {
        XhtmlFragment xhtmlFragment = (XhtmlFragment) bean;
        XhtmlBuffer xb = new XhtmlBuffer(out);
        xhtmlFragment.toXhtml(xb);
    } else {
        logger.warn("Bean {} scope {} property {} not of type XhtmlFragment: {}", new String[] { name, scope, property, bean != null ? bean.getClass().getName() : null });
    }
}
Also used : XhtmlFragment(com.manydesigns.elements.xml.XhtmlFragment) XhtmlBuffer(com.manydesigns.elements.xml.XhtmlBuffer) OgnlContext(ognl.OgnlContext)

Example 3 with XhtmlBuffer

use of com.manydesigns.elements.xml.XhtmlBuffer in project Portofino by ManyDesigns.

the class RequestMessages method addErrorMessage.

public static void addErrorMessage(XhtmlFragment xml) {
    XhtmlBuffer buf = new XhtmlBuffer();
    xml.toXhtml(buf);
    getErrorQueue().add(buf.toString());
}
Also used : XhtmlBuffer(com.manydesigns.elements.xml.XhtmlBuffer)

Example 4 with XhtmlBuffer

use of com.manydesigns.elements.xml.XhtmlBuffer in project Portofino by ManyDesigns.

the class SessionMessages method addWarningMessage.

public static void addWarningMessage(XhtmlFragment xml) {
    XhtmlBuffer buf = new XhtmlBuffer();
    xml.toXhtml(buf);
    getWarningQueue().add(buf.toString());
}
Also used : XhtmlBuffer(com.manydesigns.elements.xml.XhtmlBuffer)

Example 5 with XhtmlBuffer

use of com.manydesigns.elements.xml.XhtmlBuffer in project Portofino by ManyDesigns.

the class SessionMessages method addErrorMessage.

public static void addErrorMessage(XhtmlFragment xml) {
    XhtmlBuffer buf = new XhtmlBuffer();
    xml.toXhtml(buf);
    getErrorQueue().add(buf.toString());
}
Also used : XhtmlBuffer(com.manydesigns.elements.xml.XhtmlBuffer)

Aggregations

XhtmlBuffer (com.manydesigns.elements.xml.XhtmlBuffer)14 PropertyAccessor (com.manydesigns.elements.reflection.PropertyAccessor)1 UrlBuilder (com.manydesigns.elements.servlet.UrlBuilder)1 OgnlTextFormat (com.manydesigns.elements.text.OgnlTextFormat)1 XhtmlFragment (com.manydesigns.elements.xml.XhtmlFragment)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringWriter (java.io.StringWriter)1 Charset (java.nio.charset.Charset)1 JspWriter (javax.servlet.jsp.JspWriter)1 OgnlContext (ognl.OgnlContext)1 JSONObject (org.json.JSONObject)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 Test (org.testng.annotations.Test)1