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;
}
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;
}
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));
}
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();
}
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());
}
}
Aggregations