Search in sources :

Example 1 with NavigationResource

use of org.exoplatform.web.url.navigation.NavigationResource in project gatein-portal by Meeds-io.

the class UISitemapPortlet method toJSON.

private JSONObject toJSON(TreeNode tnode, MimeResponse res) throws Exception {
    UIPortalNavigation uiPortalNavigation = getChild(UIPortalNavigation.class);
    JSONObject json = new JSONObject();
    UserNode node = tnode.getNode();
    String nodeId = node.getId();
    json.put("label", node.getEncodedResolvedLabel());
    json.put("hasChild", tnode.hasChild());
    json.put("isExpanded", tnode.isExpanded());
    json.put("collapseURL", uiPortalNavigation.url("CollapseNode", nodeId));
    ResourceURL rsURL = res.createResourceURL();
    rsURL.setResourceID(nodeId);
    json.put("getNodeURL", rsURL.toString());
    if (node.getPageRef() != null) {
        NavigationResource resource = new NavigationResource(node);
        NodeURL url = Util.getPortalRequestContext().createURL(NodeURL.TYPE, resource);
        url.setAjax(isUseAjax());
        json.put("actionLink", url.toString());
    }
    JSONArray childs = new JSONArray();
    for (TreeNode child : tnode.getChildren()) {
        childs.put(toJSON(child, res));
    }
    json.put("childs", childs);
    return json;
}
Also used : JSONObject(org.json.JSONObject) TreeNode(org.exoplatform.portal.webui.navigation.TreeNode) UserNode(org.exoplatform.portal.mop.user.UserNode) JSONArray(org.json.JSONArray) UIPortalNavigation(org.exoplatform.portal.webui.navigation.UIPortalNavigation) NavigationResource(org.exoplatform.web.url.navigation.NavigationResource) NodeURL(org.exoplatform.web.url.navigation.NodeURL) ResourceURL(javax.portlet.ResourceURL)

Example 2 with NavigationResource

use of org.exoplatform.web.url.navigation.NavigationResource in project gatein-portal by Meeds-io.

the class BasePartialUpdateToolbar method toJSON.

protected JSONObject toJSON(UserNode node, String navId, MimeResponse res) throws Exception {
    JSONObject json = new JSONObject();
    String nodeId = node.getId();
    json.put("label", node.getEncodedResolvedLabel());
    json.put("hasChild", node.getChildrenCount() > 0);
    json.put("isSelected", nodeId.equals(getSelectedNode().getId()));
    json.put("icon", node.getIcon());
    ResourceURL rsURL = res.createResourceURL();
    rsURL.setResourceID(getResourceIdFromNode(node, navId));
    json.put("getNodeURL", rsURL.toString());
    if (node.getPageRef() != null) {
        NavigationResource resource = new NavigationResource(node);
        NodeURL url = Util.getPortalRequestContext().createURL(NodeURL.TYPE, resource);
        json.put("actionLink", url.setAjax(false).toString());
    }
    JSONArray childs = new JSONArray();
    for (UserNode child : node.getChildren()) {
        childs.put(toJSON(child, navId, res));
    }
    json.put("childs", childs);
    return json;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) UserNode(org.exoplatform.portal.mop.user.UserNode) NavigationResource(org.exoplatform.web.url.navigation.NavigationResource) NodeURL(org.exoplatform.web.url.navigation.NodeURL) ResourceURL(javax.portlet.ResourceURL)

Example 3 with NavigationResource

use of org.exoplatform.web.url.navigation.NavigationResource in project gatein-portal by Meeds-io.

the class GateInApiManagementResource method setCurrentPortalRequest.

private void setCurrentPortalRequest(OperationContext context) {
    final ManagedUser managedUser = context.getUser();
    final PathAddress address = context.getAddress();
    // Retrieve siteId from address (can be null)
    SiteId siteId = getSiteId(address);
    // Retrieve nodePath from address (can be null)
    NodePath nodePath = getNodePath(address);
    Locale locale = context.getLocale();
    // For some HTTP requests the locale is set to *, I guess to indicate a header 'Accept-Language: *' ?
    if (locale != null && locale.getLanguage().equals("*")) {
        locale = null;
    }
    User user = (managedUser == null || managedUser.getUserName() == null) ? User.anonymous() : new User(managedUser.getUserName());
    final PortalContainer container = PortalContainer.getInstance();
    final WebAppController controller = (WebAppController) container.getComponentInstanceOfType(WebAppController.class);
    URIResolver uriResolver = new URIResolver() {

        @Override
        public String resolveURI(SiteId siteId) {
            SiteKey siteKey = Util.from(siteId);
            NavigationResource navResource = new NavigationResource(siteKey, "");
            SimpleURL url = new SimpleURL(new SimpleURLContext(container, controller));
            url.setSchemeUse(false);
            url.setAuthorityUse(false);
            String urlString = url.setResource(navResource).toString();
            return urlString.substring(0, urlString.length() - 1);
        }
    };
    BasicPortalRequest.setInstance(new BasicPortalRequest(user, siteId, nodePath, locale, portal, uriResolver));
}
Also used : Locale(java.util.Locale) SiteId(org.gatein.api.site.SiteId) User(org.gatein.api.security.User) ManagedUser(org.gatein.management.api.ManagedUser) URIResolver(org.gatein.api.common.URIResolver) ModelString(org.gatein.management.api.model.ModelString) WebAppController(org.exoplatform.web.WebAppController) NodePath(org.gatein.api.navigation.NodePath) SimpleURL(org.exoplatform.web.url.simple.SimpleURL) ManagedUser(org.gatein.management.api.ManagedUser) PathAddress(org.gatein.management.api.PathAddress) BasicPortalRequest(org.gatein.api.BasicPortalRequest) SiteKey(org.exoplatform.portal.mop.SiteKey) NavigationResource(org.exoplatform.web.url.navigation.NavigationResource) SimpleURLContext(org.exoplatform.web.url.simple.SimpleURLContext) PortalContainer(org.exoplatform.container.PortalContainer)

Example 4 with NavigationResource

use of org.exoplatform.web.url.navigation.NavigationResource in project gatein-portal by Meeds-io.

the class UIPortalApplication method getBaseURL.

public String getBaseURL() throws UnsupportedEncodingException {
    PortalRequestContext pcontext = Util.getPortalRequestContext();
    NodeURL nodeURL = pcontext.createURL(NodeURL.TYPE, new NavigationResource(pcontext.getSiteKey(), pcontext.getNodePath()));
    return nodeURL.toString();
}
Also used : PortalRequestContext(org.exoplatform.portal.application.PortalRequestContext) NavigationResource(org.exoplatform.web.url.navigation.NavigationResource) NodeURL(org.exoplatform.web.url.navigation.NodeURL)

Example 5 with NavigationResource

use of org.exoplatform.web.url.navigation.NavigationResource in project gatein-portal by Meeds-io.

the class DefaultRequestHandlerTest method testGetDefaultSite.

@Test
public void testGetDefaultSite() {
    URLFactoryService urlFactory = mock(URLFactoryService.class);
    NodeURL url = mock(NodeURL.class);
    UserPortalConfigService portalConfigService = mock(UserPortalConfigService.class);
    ControllerContext context = mock(ControllerContext.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    HttpServletRequest request = mock(HttpServletRequest.class);
    try {
        String defaultSite = "site2";
        when(portalConfigService.getDefaultPortal()).thenReturn(defaultSite);
        when(portalConfigService.getAllPortalNames()).thenReturn(Arrays.asList("site1", defaultSite));
        when(context.getResponse()).thenReturn(response);
        when(context.getRequest()).thenReturn(request);
        doAnswer(invocation -> {
            @SuppressWarnings("unchecked") Map<QualifiedName, String> parameters = invocation.getArgument(0, Map.class);
            URIWriter uriWriter = invocation.getArgument(1, URIWriter.class);
            uriWriter.append("/portal/");
            uriWriter.append(parameters.get(NodeURL.REQUEST_SITE_NAME));
            return null;
        }).when(context).renderURL(any(), any());
        when(response.encodeRedirectURL(anyString())).thenAnswer(new Answer<String>() {

            public String answer(InvocationOnMock invocation) {
                return invocation.getArgument(0, String.class);
            }
        });
        when(urlFactory.newURL(any(), any())).thenAnswer(new Answer<NodeURL>() {

            public NodeURL answer(InvocationOnMock invocation) {
                PortalURLContext urlContext = invocation.getArgument(1, PortalURLContext.class);
                when(url.getContext()).thenReturn(urlContext);
                return url;
            }
        });
        when(url.setResource(any())).thenAnswer(new Answer<NodeURL>() {

            public NodeURL answer(InvocationOnMock invocation) {
                NavigationResource navigationResource = invocation.getArgument(0, NavigationResource.class);
                when(url.getResource()).thenReturn(navigationResource);
                assertEquals("Site type on which user is redirected is not of type PORTAL", SiteType.PORTAL, navigationResource.getSiteType());
                assertEquals("Site name on which user is redirected is not coherent", defaultSite, navigationResource.getSiteName());
                return url;
            }
        });
        DefaultRequestHandler defaultRequestHandler = new DefaultRequestHandler(portalConfigService, urlFactory);
        defaultRequestHandler.execute(context);
        verify(response).sendRedirect(eq("/portal/site2"));
    } catch (Exception e) {
        LOG.error("Error while executing method", e);
        fail(e.getMessage());
    }
}
Also used : URLFactoryService(org.exoplatform.web.url.URLFactoryService) QualifiedName(org.exoplatform.web.controller.QualifiedName) HttpServletResponse(javax.servlet.http.HttpServletResponse) NodeURL(org.exoplatform.web.url.navigation.NodeURL) HttpServletRequest(javax.servlet.http.HttpServletRequest) PortalURLContext(org.exoplatform.portal.url.PortalURLContext) URIWriter(org.exoplatform.web.controller.router.URIWriter) ControllerContext(org.exoplatform.web.ControllerContext) InvocationOnMock(org.mockito.invocation.InvocationOnMock) UserPortalConfigService(org.exoplatform.portal.config.UserPortalConfigService) NavigationResource(org.exoplatform.web.url.navigation.NavigationResource) Test(org.junit.Test)

Aggregations

NavigationResource (org.exoplatform.web.url.navigation.NavigationResource)30 NodeURL (org.exoplatform.web.url.navigation.NodeURL)29 RequestContext (org.exoplatform.web.application.RequestContext)11 PortalRequestContext (org.exoplatform.portal.application.PortalRequestContext)9 WebuiRequestContext (org.exoplatform.webui.application.WebuiRequestContext)6 Node (javax.jcr.Node)5 PortletRequestContext (org.exoplatform.webui.application.portlet.PortletRequestContext)5 PortletRequest (javax.portlet.PortletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 UserNode (org.exoplatform.portal.mop.user.UserNode)4 PortalURLContext (org.exoplatform.portal.url.PortalURLContext)4 FriendlyService (org.exoplatform.services.wcm.friendly.FriendlyService)4 ResourceURL (javax.portlet.ResourceURL)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 NodeLocation (org.exoplatform.services.wcm.core.NodeLocation)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 PortletPreferences (javax.portlet.PortletPreferences)2 UserPortalConfigService (org.exoplatform.portal.config.UserPortalConfigService)2 SiteKey (org.exoplatform.portal.mop.SiteKey)2