Example usage for com.liferay.portal.kernel.xml.simple Element addElement

List of usage examples for com.liferay.portal.kernel.xml.simple Element addElement

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.xml.simple Element addElement.

Prototype

public Element addElement(String name, String text) 

Source Link

Usage

From source file:com.liferay.util.portlet.PortletRequestUtil.java

License:Open Source License

public static String toXML(PortletRequest portletRequest, PortletResponse portletResponse) {

    Element requestElement = new Element("request");

    requestElement.addElement("container-type", "portlet");
    requestElement.addElement("container-type", "portlet");
    requestElement.addElement("container-namespace", portletRequest.getContextPath());
    requestElement.addElement("content-type", portletRequest.getResponseContentType());
    requestElement.addElement("server-name", portletRequest.getServerName());
    requestElement.addElement("server-port", portletRequest.getServerPort());
    requestElement.addElement("secure", portletRequest.isSecure());
    requestElement.addElement("auth-type", portletRequest.getAuthType());
    requestElement.addElement("remote-user", portletRequest.getRemoteUser());
    requestElement.addElement("context-path", portletRequest.getContextPath());
    requestElement.addElement("locale", portletRequest.getLocale());
    requestElement.addElement("portlet-mode", portletRequest.getPortletMode());
    requestElement.addElement("portlet-session-id", portletRequest.getRequestedSessionId());
    requestElement.addElement("scheme", portletRequest.getScheme());
    requestElement.addElement("window-state", portletRequest.getWindowState());

    if (portletRequest instanceof ActionRequest) {
        requestElement.addElement("lifecycle", RenderRequest.ACTION_PHASE);
    } else if (portletRequest instanceof RenderRequest) {
        requestElement.addElement("lifecycle", RenderRequest.RENDER_PHASE);
    } else if (portletRequest instanceof ResourceRequest) {
        requestElement.addElement("lifecycle", RenderRequest.RESOURCE_PHASE);
    }//from  w ww  .j  av  a2 s .  com

    if (portletResponse instanceof MimeResponse) {
        _mimeResponseToXML((MimeResponse) portletResponse, requestElement);
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (themeDisplay != null) {
        Element themeDisplayElement = requestElement.addElement("theme-display");

        _themeDisplayToXML(themeDisplay, themeDisplayElement);
    }

    Element parametersElement = requestElement.addElement("parameters");

    Enumeration<String> enu = portletRequest.getParameterNames();

    while (enu.hasMoreElements()) {
        String name = enu.nextElement();

        Element parameterElement = parametersElement.addElement("parameter");

        parameterElement.addElement("name", name);

        String[] values = portletRequest.getParameterValues(name);

        for (int i = 0; i < values.length; i++) {
            parameterElement.addElement("value", values[i]);
        }
    }

    Element attributesElement = requestElement.addElement("attributes");

    enu = portletRequest.getAttributeNames();

    while (enu.hasMoreElements()) {
        String name = enu.nextElement();

        if (!_isValidAttributeName(name)) {
            continue;
        }

        Object value = portletRequest.getAttribute(name);

        if (!_isValidAttributeValue(value)) {
            continue;
        }

        Element attributeElement = attributesElement.addElement("attribute");

        attributeElement.addElement("name", name);
        attributeElement.addElement("value", value);
    }

    Element portletSessionElement = requestElement.addElement("portlet-session");

    attributesElement = portletSessionElement.addElement("portlet-attributes");

    PortletSession portletSession = portletRequest.getPortletSession();

    try {
        enu = portletSession.getAttributeNames(PortletSession.PORTLET_SCOPE);

        while (enu.hasMoreElements()) {
            String name = enu.nextElement();

            if (!_isValidAttributeName(name)) {
                continue;
            }

            Object value = portletSession.getAttribute(name, PortletSession.PORTLET_SCOPE);

            if (!_isValidAttributeValue(value)) {
                continue;
            }

            Element attributeElement = attributesElement.addElement("attribute");

            attributeElement.addElement("name", name);
            attributeElement.addElement("value", value);
        }

        attributesElement = portletSessionElement.addElement("application-attributes");

        enu = portletSession.getAttributeNames(PortletSession.APPLICATION_SCOPE);

        while (enu.hasMoreElements()) {
            String name = enu.nextElement();

            if (!_isValidAttributeName(name)) {
                continue;
            }

            Object value = portletSession.getAttribute(name, PortletSession.APPLICATION_SCOPE);

            if (!_isValidAttributeValue(value)) {
                continue;
            }

            Element attributeElement = attributesElement.addElement("attribute");

            attributeElement.addElement("name", name);
            attributeElement.addElement("value", value);
        }
    } catch (IllegalStateException ise) {
        if (_log.isWarnEnabled()) {
            _log.warn(ise.getMessage());
        }
    }

    return requestElement.toXMLString();
}

From source file:com.liferay.util.portlet.PortletRequestUtil.java

License:Open Source License

private static void _mimeResponseToXML(MimeResponse mimeResponse, Element requestElement) {

    String namespace = mimeResponse.getNamespace();

    requestElement.addElement("portlet-namespace", namespace);

    try {/*from   w w  w  . j  a  v a2s .co m*/
        PortletURL actionURL = mimeResponse.createActionURL();

        requestElement.addElement("action-url", actionURL);
    } catch (IllegalStateException ise) {
        if (_log.isWarnEnabled()) {
            _log.warn(ise.getMessage());
        }
    }

    try {
        PortletURL renderURL = mimeResponse.createRenderURL();

        requestElement.addElement("render-url", renderURL);

        try {
            renderURL.setWindowState(LiferayWindowState.EXCLUSIVE);

            requestElement.addElement("render-url-exclusive", renderURL);
        } catch (WindowStateException wse) {
        }

        try {
            renderURL.setWindowState(LiferayWindowState.MAXIMIZED);

            requestElement.addElement("render-url-maximized", renderURL);
        } catch (WindowStateException wse) {
        }

        try {
            renderURL.setWindowState(LiferayWindowState.MINIMIZED);

            requestElement.addElement("render-url-minimized", renderURL);
        } catch (WindowStateException wse) {
        }

        try {
            renderURL.setWindowState(LiferayWindowState.NORMAL);

            requestElement.addElement("render-url-normal", renderURL);
        } catch (WindowStateException wse) {
        }

        try {
            renderURL.setWindowState(LiferayWindowState.POP_UP);

            requestElement.addElement("render-url-pop-up", renderURL);
        } catch (WindowStateException wse) {
        }
    } catch (IllegalStateException ise) {
        if (_log.isWarnEnabled()) {
            _log.warn(ise.getMessage());
        }
    }

    ResourceURL resourceURL = mimeResponse.createResourceURL();

    String resourceURLString = HttpUtil.removeParameter(resourceURL.toString(), namespace + "struts_action");

    resourceURLString = HttpUtil.removeParameter(resourceURLString, namespace + "redirect");

    requestElement.addElement("resource-url", resourceURLString);
}

From source file:com.liferay.util.portlet.PortletRequestUtil.java

License:Open Source License

private static void _portletDisplayToXML(PortletDisplay portletDisplay, Element portletDisplayElement) {

    portletDisplayElement.addElement("id", portletDisplay.getId());
    portletDisplayElement.addElement("instance-id", portletDisplay.getInstanceId());
    portletDisplayElement.addElement("portlet-name", portletDisplay.getPortletName());
    portletDisplayElement.addElement("resource-pk", portletDisplay.getResourcePK());
    portletDisplayElement.addElement("root-portlet-id", portletDisplay.getRootPortletId());
    portletDisplayElement.addElement("title", portletDisplay.getTitle());
}

From source file:com.liferay.util.portlet.PortletRequestUtil.java

License:Open Source License

private static void _themeDisplayToXML(ThemeDisplay themeDisplay, Element themeDisplayElement) {

    themeDisplayElement.addElement("cdn-host", themeDisplay.getCDNHost());
    themeDisplayElement.addElement("company-id", themeDisplay.getCompanyId());
    themeDisplayElement.addElement("do-as-user-id", themeDisplay.getDoAsUserId());
    themeDisplayElement.addElement("i18n-language-id", themeDisplay.getI18nLanguageId());
    themeDisplayElement.addElement("i18n-path", themeDisplay.getI18nPath());
    themeDisplayElement.addElement("language-id", themeDisplay.getLanguageId());
    themeDisplayElement.addElement("locale", themeDisplay.getLocale());
    themeDisplayElement.addElement("path-context", themeDisplay.getPathContext());
    themeDisplayElement.addElement("path-friendly-url-private-group",
            themeDisplay.getPathFriendlyURLPrivateGroup());
    themeDisplayElement.addElement("path-friendly-url-private-user",
            themeDisplay.getPathFriendlyURLPrivateUser());
    themeDisplayElement.addElement("path-friendly-url-public", themeDisplay.getPathFriendlyURLPublic());
    themeDisplayElement.addElement("path-image", themeDisplay.getPathImage());
    themeDisplayElement.addElement("path-main", themeDisplay.getPathMain());
    themeDisplayElement.addElement("path-theme-images", themeDisplay.getPathThemeImages());
    themeDisplayElement.addElement("plid", themeDisplay.getPlid());
    themeDisplayElement.addElement("portal-url", HttpUtil.removeProtocol(themeDisplay.getPortalURL()));
    themeDisplayElement.addElement("real-user-id", themeDisplay.getRealUserId());
    themeDisplayElement.addElement("scope-group-id", themeDisplay.getScopeGroupId());
    themeDisplayElement.addElement("secure", themeDisplay.isSecure());
    themeDisplayElement.addElement("server-name", themeDisplay.getServerName());
    themeDisplayElement.addElement("server-port", themeDisplay.getServerPort());
    themeDisplayElement.addElement("time-zone", themeDisplay.getTimeZone().getID());
    themeDisplayElement.addElement("url-portal", HttpUtil.removeProtocol(themeDisplay.getURLPortal()));
    themeDisplayElement.addElement("user-id", themeDisplay.getUserId());

    if (themeDisplay.getPortletDisplay() != null) {
        Element portletDisplayElement = themeDisplayElement.addElement("portlet-display");

        _portletDisplayToXML(themeDisplay.getPortletDisplay(), portletDisplayElement);
    }/*from   w  w w  .j  a v  a2 s.c o  m*/
}