Search in sources :

Example 16 with ResourceURL

use of javax.portlet.ResourceURL in project core by wicketstuff.

the class PortletRequestMapper method encodeResourceUrl.

private Url encodeResourceUrl(Url url) {
    if (url != null) {
        String qualifiedPath = getQualifiedPath(url.toString());
        PortletResponse portletResponse = ThreadPortletContext.getPortletResponse();
        if ((portletResponse != null) && (portletResponse instanceof MimeResponse)) {
            try {
                ResourceURL resourceUrl = ((MimeResponse) portletResponse).createResourceURL();
                resourceUrl.setResourceID(qualifiedPath);
                qualifiedPath = resourceUrl.toString();
                // resource URLs preserve all request render parameters (at
                // least for Liferay even all POST parameters), so we have
                // to remove all Wicket parameters (that have the portlet
                // namespace), otherwise we would have all submited values
                // in the URL
                int queryStringSeparator = qualifiedPath.indexOf('?');
                if (queryStringSeparator > 0) {
                    Map<String, String[]> parameterMap = Utils.parseQueryString(qualifiedPath.substring(queryStringSeparator + 1));
                    boolean changed = false;
                    Iterator<Map.Entry<String, String[]>> it = parameterMap.entrySet().iterator();
                    String namespace = ThreadPortletContext.getNamespace();
                    while (it.hasNext()) {
                        if (it.next().getKey().startsWith(namespace)) {
                            changed = true;
                            it.remove();
                        }
                    }
                    if (changed) {
                        qualifiedPath = qualifiedPath.substring(0, queryStringSeparator) + '?' + Utils.buildQueryString(parameterMap);
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        url = parseUrl(qualifiedPath);
    }
    return markAsPortletUrl(url);
}
Also used : PortletResponse(javax.portlet.PortletResponse) MimeResponse(javax.portlet.MimeResponse) ResourceURL(javax.portlet.ResourceURL)

Example 17 with ResourceURL

use of javax.portlet.ResourceURL in project ecms by exoplatform.

the class UISingleContentViewerPortlet method toJSON.

private JSONObject toJSON(UserNode node, MimeResponse res) throws Exception {
    JSONObject json = new JSONObject();
    String nodeId = node.getId();
    json.put("label", node.getEncodedResolvedLabel());
    json.put("hasChild", node.getChildrenCount() > 0);
    UserNode selectedNode = Util.getUIPortal().getNavPath();
    json.put("isSelected", nodeId.equals(selectedNode.getId()));
    json.put("icon", node.getIcon());
    String nodeURI = "";
    if (node.getPageRef() != null) {
        nodeURI = node.getURI();
    }
    json.put("uri", nodeURI);
    ResourceURL rsURL = res.createResourceURL();
    rsURL.setResourceID(res.encodeURL(node.getURI()));
    json.put("getNodeURL", rsURL.toString());
    JSONArray jsonChildren = new JSONArray();
    for (UserNode child : node.getChildren()) {
        jsonChildren.put(toJSON(child, res));
    }
    json.put("childs", jsonChildren);
    return json;
}
Also used : JSONObject(org.json.JSONObject) UserNode(org.exoplatform.portal.mop.user.UserNode) JSONArray(org.json.JSONArray) ResourceURL(javax.portlet.ResourceURL)

Aggregations

ResourceURL (javax.portlet.ResourceURL)17 MimeResponse (javax.portlet.MimeResponse)6 UserNode (org.exoplatform.portal.mop.user.UserNode)5 JSONArray (org.json.JSONArray)5 JSONObject (org.json.JSONObject)5 ExternalContext (javax.faces.context.ExternalContext)3 NavigationResource (org.exoplatform.web.url.navigation.NavigationResource)3 NodeURL (org.exoplatform.web.url.navigation.NodeURL)3 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 MalformedURLException (java.net.MalformedURLException)2 PortletResponse (javax.portlet.PortletResponse)2 PortletURL (javax.portlet.PortletURL)2 WebuiRequestContext (org.exoplatform.webui.application.WebuiRequestContext)2 BridgeTest (com.liferay.faces.bridge.tck.annotation.BridgeTest)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1