/** * Checks if is node content published to page node. * * @param contentNode the content node * @param navNodeURI the nav node uri * @return true, if is node content published to page node * @throws Exception the exception */ public static boolean isNodeContentPublishedToPageNode(Node contentNode, String navNodeURI) throws Exception { UserPortal userPortal = Util.getPortalRequestContext().getUserPortalConfig().getUserPortal(); // make filter UserNodeFilterConfig.Builder filterConfigBuilder = UserNodeFilterConfig.builder(); filterConfigBuilder .withReadWriteCheck() .withVisibility(Visibility.DISPLAYED, Visibility.TEMPORAL); filterConfigBuilder.withTemporalCheck(); UserNodeFilterConfig filterConfig = filterConfigBuilder.build(); // get user node String nodeURI = navNodeURI.replace("/" + Util.getPortalRequestContext().getPortalOwner() + "/", ""); UserNode userNode; UserNavigation userNavigation = NavigationUtils.getUserNavigationOfPortal( userPortal, Util.getUIPortal().getSiteKey().getName()); if (userNavigation != null) { userNode = userPortal.resolvePath(userNavigation, filterConfig, nodeURI); } else { userNode = userPortal.resolvePath(filterConfig, nodeURI); } if (userNode == null || userNode.getPageRef() == null) return false; return PublicationUtil.getValuesAsString(contentNode, "publication:webPageIDs") .contains(userNode.getPageRef()); }
public String getTitle() throws Exception { String title = (String) request_.getAttribute(REQUEST_TITLE); // if (title == null) { UIPortal uiportal = Util.getUIPortal(); // UserNode node = uiportal.getSelectedUserNode(); if (node != null) { ExoContainer container = getApplication().getApplicationServiceContainer(); container.getComponentInstanceOfType(UserPortalConfigService.class); UserPortalConfigService configService = (UserPortalConfigService) container.getComponentInstanceOfType(UserPortalConfigService.class); Page page = configService.getPage(node.getPageRef(), getRemoteUser()); // if (page != null) { title = page.getTitle(); return ExpressionUtil.getExpressionValue(this.getApplicationResourceBundle(), title); } else { title = node.getResolvedLabel(); } } } // return title; }
public static Node findNodeByUUID(String uuid) throws Exception { RepositoryService repositoryService = Util.getUIPortal().getApplicationComponent(RepositoryService.class); SessionProviderService sessionProviderService = Util.getUIPortal().getApplicationComponent(SessionProviderService.class); SessionProvider sessionProvider = sessionProviderService.getSessionProvider(null); ManageableRepository manageableRepository = repositoryService.getCurrentRepository(); Node node = null; for (String wsName : manageableRepository.getWorkspaceNames()) { try { node = sessionProvider.getSession(wsName, manageableRepository).getNodeByUUID(uuid); } catch (ItemNotFoundException e) { continue; } } return node; }
public void execute(Event<UIComponent> event) throws Exception { PortalRequestContext prContext = Util.getPortalRequestContext(); prContext.getRequest().getSession().invalidate(); HttpServletRequest request = prContext.getRequest(); String portalName = URLEncoder.encode(Util.getUIPortal().getName(), "UTF-8"); String redirect = request.getContextPath() + "/public/" + portalName + "/"; prContext.getResponse().sendRedirect(redirect); prContext.setResponseComplete(true); }
public void execute(Event<UIPageForm> event) throws Exception { UIPageForm uiForm = event.getSource(); UIFormSelectBox uiSelectBox = uiForm.getUIFormSelectBox(OWNER_TYPE); String ownerType = uiSelectBox.getValue(); PortalRequestContext prContext = Util.getPortalRequestContext(); UIFormInputSet uiSettingSet = uiForm.getChildById("PageSetting"); uiForm.setSelectedTab("PageSetting"); List<UIComponent> list = uiSettingSet.getChildren(); if (PortalConfig.USER_TYPE.equals(ownerType)) { uiForm.removeChildById("PermissionSetting"); list.remove(2); list.add(2, uiForm.ownerIdInput); uiForm.ownerIdInput.setValue(prContext.getRemoteUser()); } else { if (uiForm.getChildById("PermissionSetting") == null) { uiForm.addUIComponentInput(uiForm.uiPermissionSetting); } if (PortalConfig.PORTAL_TYPE.equals(ownerType)) { list.remove(2); list.add(2, uiForm.ownerIdInput); uiForm.ownerIdInput.setValue(prContext.getPortalOwner()); uiForm .findFirstComponentOfType(UIListPermissionSelector.class) .setValue(Util.getUIPortal().getAccessPermissions()); uiForm .findFirstComponentOfType(UIPermissionSelector.class) .setValue(Util.getUIPortal().getEditPermission()); } else { list.remove(2); list.add(2, uiForm.groupIdSelectBox); String groupIdSelected = uiForm.groupIdSelectBox.getValue(); groupIdSelected = groupIdSelected.startsWith("/") ? groupIdSelected : "/" + groupIdSelected; String permission = "*:" + groupIdSelected; uiForm .findFirstComponentOfType(UIListPermissionSelector.class) .setValue(new String[] {permission}); UserACL userACL = uiForm.getApplicationComponent(UserACL.class); permission = userACL.getMakableMT() + ":" + groupIdSelected; uiForm.findFirstComponentOfType(UIPermissionSelector.class).setValue(permission); } } prContext.addUIComponentToUpdateByAjax(uiForm.getParent()); }
/** * Get question uri by question id of question relative path. * * @param: param the question id or question relative path. * @param: isAnswer is display form answer question or not. * @return: the link go to the question and show form answer or not. * @throws Exception */ public static String getQuestionURI(String param, boolean isAnswer) throws Exception { PortalRequestContext portalContext = Util.getPortalRequestContext(); String selectedNode = Util.getUIPortal().getSelectedUserNode().getURI(); return portalContext .getPortalURI() .concat(selectedNode) .concat(Utils.QUESTION_ID) .concat(param) .concat((isAnswer) ? Utils.ANSWER_NOW.concat("true") : ""); }
/** * Can edit current portal. * * @param remoteUser the remote user * @return true, if successful * @throws Exception the exception */ public static boolean canEditCurrentPortal(String remoteUser) throws Exception { if (remoteUser == null) return false; IdentityRegistry identityRegistry = Util.getUIPortalApplication().getApplicationComponent(IdentityRegistry.class); Identity identity = identityRegistry.getIdentity(remoteUser); if (identity == null) return false; UIPortal uiPortal = Util.getUIPortal(); // this code only work for single edit permission String editPermission = uiPortal.getEditPermission(); MembershipEntry membershipEntry = MembershipEntry.parse(editPermission); return identity.isMemberOf(membershipEntry); }
public static Node getNodeSymLink(Node node) throws Exception { LinkManager linkManager = Util.getUIPortal().getApplicationComponent(LinkManager.class); Node realNode = null; if (linkManager.isLink(node)) { if (linkManager.isTargetReachable(node)) { realNode = linkManager.getTarget(node); } } else { realNode = node; } return realNode; }
public static String getThumbnailImage(Node node, String propertyName) throws Exception { ThumbnailService thumbnailService = Util.getUIPortal().getApplicationComponent(ThumbnailService.class); if (node.isNodeType(NT_FILE)) { String mimeType = node.getNode(JCR_CONTENT).getProperty(JCR_MIMETYPE).getString(); if (mimeType.startsWith("image")) { Node thumbnailNode = thumbnailService.addThumbnailNode(node); InputStream inputStream = node.getNode(JCR_CONTENT).getProperty(JCR_DATA).getStream(); thumbnailService.createSpecifiedThumbnail( thumbnailNode, ImageIO.read(inputStream), propertyName); } } Node thumbnailNode = thumbnailService.getThumbnailNode(node); if (thumbnailNode != null && thumbnailNode.hasProperty(propertyName)) { DownloadService dservice = Util.getUIPortal().getApplicationComponent(DownloadService.class); InputStream input = thumbnailNode.getProperty(propertyName).getStream(); InputStreamDownloadResource dresource = new InputStreamDownloadResource(input, "image"); dresource.setDownloadName(node.getName()); return dservice.getDownloadLink(dservice.addDownloadResource(dresource)); } return null; }
public boolean isSpaceManager() throws Exception { if (spaceService != null) { UserNavigation currentUserNavigation = Util.getUIPortal().getSelectedUserNode().getNavigation(); if (SiteType.GROUP.equals((currentUserNavigation.getKey().getType())) && currentUserNavigation.getKey().getName().contains("/spaces")) { String remoteUser = getUserId(); String spaceId = currentUserNavigation.getKey().getName(); Space space = spaceService.getSpaceByGroupId(spaceId); return (space != null && spaceService.hasSettingPermission(space, remoteUser)); } } return true; }
/** * @return the base URL to the current calendar application * @throws Exception */ public static String getCalendarURL() throws Exception { PortalRequestContext pContext = Util.getPortalRequestContext(); String url = pContext.getRequest().getRequestURL().toString(); String selectedNode = Util.getUIPortal().getSelectedUserNode().getURI(); String portalName = pContext.getPortalOwner(); if (url.indexOf(portalName) > 0) { String s = new StringBuilder().append(portalName).append("/").append(selectedNode).toString(); if (url.indexOf(s) < 0) { url = url.replaceFirst(portalName, s); } selectedNode = s; url = url.substring(0, url.lastIndexOf(selectedNode) + selectedNode.length()); } return url; }
/** * This method is called by the process action and render action listeners, aka during the * processDecode() phase of our UI framework * * <p>It goes throughs all the request parameters and add to the public render parameters Map the * one that are supported by the targeted portlet */ public static void setupPublicRenderParams( UIPortlet uiPortlet, Map<String, String[]> requestParams) { if (ParameterValidation.existsAndIsNotEmpty(requestParams)) { UIPortal uiPortal = Util.getUIPortal(); Map<String, String[]> publicParams = uiPortal.getPublicParameters(); for (String key : requestParams.keySet()) { String[] value = requestParams.get(key); if (uiPortlet.supportsPublicParam(key)) { if (value.length > 0) { publicParams.put(key, value); } else { publicParams.remove(key); } } } } }
public Collection<Skin> getPortalSkins() { SkinService skinService = getApplicationComponent(SkinService.class); // Collection<Skin> skins = new ArrayList<Skin>(skinService.getPortalSkins(skin_)); // SkinConfig skinConfig = skinService.getSkin(Util.getUIPortal().getName(), skin_); if (skinConfig != null) { skins.add(skinConfig); } // Set<SkinConfig> portletConfigs = getPortalPortletSkins(); // don't merge portlet if portlet not available if (!portletConfigs.isEmpty()) { skins.add(skinService.merge(portletConfigs)); } // return skins; }
public JSONArray getChildrenAsJSON(String nodeURI) throws Exception { WebuiRequestContext context = WebuiRequestContext.getCurrentInstance(); Collection<UserNode> children = null; UserPortal userPortal = Util.getPortalRequestContext().getUserPortalConfig().getUserPortal(); // make filter UserNodeFilterConfig.Builder filterConfigBuilder = UserNodeFilterConfig.builder(); filterConfigBuilder .withReadWriteCheck() .withVisibility(Visibility.DISPLAYED, Visibility.TEMPORAL); filterConfigBuilder.withTemporalCheck(); UserNodeFilterConfig filterConfig = filterConfigBuilder.build(); // get user node & update children UserNode userNode; if (context.getRemoteUser() != null) { userNode = userPortal.resolvePath(Util.getUIPortal().getUserNavigation(), filterConfig, nodeURI); } else { userNode = userPortal.resolvePath(filterConfig, nodeURI); } if (userNode != null) { userPortal.updateNode(userNode, NavigationUtils.ECMS_NAVIGATION_SCOPE, null); children = userNode.getChildren(); } // build JSON result JSONArray jsChildren = new JSONArray(); if (children == null) { return null; } MimeResponse res = context.getResponse(); for (UserNode child : children) { jsChildren.put(toJSON(child, res)); } return jsChildren; }
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()); json.put("uri", node.getURI()); 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; }
public static UserNavigation getSelectedNavigation() throws Exception { return Util.getUIPortal().getUserNavigation(); }
public void execute(Event<UIForgetPassword> event) throws Exception { UIForgetPassword uiForm = event.getSource(); UILogin uilogin = uiForm.getParent(); WebuiRequestContext requestContext = event.getRequestContext(); PortalRequestContext portalContext = PortalRequestContext.getCurrentInstance(); String url = portalContext.getRequest().getRequestURL().toString(); MailService mailSrc = uiForm.getApplicationComponent(MailService.class); OrganizationService orgSrc = uiForm.getApplicationComponent(OrganizationService.class); String userName = uiForm.getUIStringInput(Username).getValue(); String email = uiForm.getUIStringInput(Email).getValue(); uiForm.reset(); User user = null; String tokenId = null; // User provided his username if (userName != null) { user = orgSrc.getUserHandler().findUserByName(userName); if (user == null) { requestContext .getUIApplication() .addMessage(new ApplicationMessage("UIForgetPassword.msg.user-not-exist", null)); return; } } // User provided his email address if (user == null && email != null) { Query query = new Query(); // Querying on email won't work. PLIDM-12 // Note that querying on email is inefficient as it loops over all users... query.setEmail(email); PageList<User> users = orgSrc.getUserHandler().findUsers(query); if (users.getAll().size() > 0) { user = users.getAll().get(0); } else { requestContext .getUIApplication() .addMessage(new ApplicationMessage("UIForgetPassword.msg.email-not-exist", null)); return; } } email = user.getEmail(); // Create token RemindPasswordTokenService tokenService = uiForm.getApplicationComponent(RemindPasswordTokenService.class); Credentials credentials = new Credentials(user.getUserName(), ""); tokenId = tokenService.createToken(credentials); String portalName = URLEncoder.encode(Util.getUIPortal().getName(), "UTF-8"); ResourceBundle res = requestContext.getApplicationResourceBundle(); String headerMail = "headermail"; String footerMail = "footer"; try { headerMail = res.getString(uiForm.getId() + ".mail.header") + "\n\n" + res.getString(uiForm.getId() + ".mail.user") + user.getUserName() + "\n" + res.getString(uiForm.getId() + ".mail.link"); footerMail = "\n\n\n" + res.getString(uiForm.getId() + ".mail.footer"); } catch (MissingResourceException e) { e.printStackTrace(); } String host = url.substring(0, url.indexOf(requestContext.getRequestContextPath())); String activeLink = host + requestContext.getRequestContextPath() + "/public/" + portalName + "?portal:componentId=UIPortal&portal:action=RecoveryPasswordAndUsername&tokenId=" + tokenId; String mailText = headerMail + "\n" + activeLink + footerMail; try { mailSrc.sendMessage( res.getString("UIForgetPassword.mail.from"), email, res.getString("UIForgetPassword.mail.subject"), mailText); } catch (Exception e) { requestContext .getUIApplication() .addMessage(new ApplicationMessage("UIForgetPassword.msg.send-mail-fail", null)); requestContext.addUIComponentToUpdateByAjax(uilogin); return; } uilogin.getChild(UILoginForm.class).setRendered(true); uilogin.getChild(UIForgetPasswordWizard.class).setRendered(false); uilogin.getChild(UIForgetPassword.class).setRendered(false); requestContext .getUIApplication() .addMessage(new ApplicationMessage("UIForgetPassword.msg.send-mail-success", null)); requestContext.addUIComponentToUpdateByAjax(uilogin); }
public void execute(Event<UISpaceInfo> event) throws Exception { UISpaceInfo uiSpaceInfo = event.getSource(); SpaceService spaceService = uiSpaceInfo.getSpaceService(); UIPortal uiPortal = Util.getUIPortal(); String id = uiSpaceInfo.getUIStringInput(SPACE_ID).getValue(); String name = uiSpaceInfo.getUIStringInput(SPACE_DISPLAY_NAME).getValue(); Space space = spaceService.getSpaceById(id); String oldDisplayName = space.getDisplayName(); String existingDescription = space.getDescription(); if (space == null) { // redirect to spaces event.getRequestContext().sendRedirect(Utils.getURI("all-spaces")); return; } UserNode selectedNode = uiPortal.getSelectedUserNode(); UserNode renamedNode = null; boolean nameChanged = (!space.getDisplayName().equals(name)); UIPortletApplication uiApp = uiSpaceInfo.getAncestorOfType(UIPortletApplication.class); if (nameChanged) { String cleanedString = SpaceUtils.cleanString(name); if (spaceService.getSpaceByUrl(cleanedString) != null) { // reset to origin values uiSpaceInfo.getUIStringInput(SPACE_DISPLAY_NAME).setValue(oldDisplayName); uiSpaceInfo.getUIFormTextAreaInput(SPACE_DESCRIPTION).setValue(existingDescription); // uiApp.addMessage( new ApplicationMessage( "UISpaceInfo.msg.current-name-exist", null, ApplicationMessage.INFO)); return; } renamedNode = uiSpaceInfo.renamePageNode(name, space); if (renamedNode == null) { return; } } uiSpaceInfo.invokeSetBindingBean(space); String spaceDescription = space.getDescription(); if (spaceDescription == null || spaceDescription.trim().length() == 0) { ResourceBundle resourceBundle = event.getRequestContext().getApplicationResourceBundle(); space.setDescription(resourceBundle.getString(MSG_DEFAULT_SPACE_DESCRIPTION)); uiSpaceInfo.getUIFormTextAreaInput(SPACE_DESCRIPTION).setValue(space.getDescription()); } else { space.setDescription(StringEscapeUtils.escapeHtml(space.getDescription())); if (!existingDescription.equals(spaceDescription)) { space.setField(UpdatedField.DESCRIPTION); } } space.setEditor(Utils.getViewerRemoteId()); if (nameChanged) { space.setDisplayName(oldDisplayName); String remoteId = Utils.getViewerRemoteId(); spaceService.renameSpace(remoteId, space, name); // rename group label OrganizationService organizationService = (OrganizationService) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(OrganizationService.class); GroupHandler groupHandler = organizationService.getGroupHandler(); Group group = groupHandler.findGroupById(space.getGroupId()); group.setLabel(space.getDisplayName()); groupHandler.saveGroup(group, true); } else { spaceService.updateSpace(space); } if (nameChanged) { if (renamedNode != null) { // update space navigation (change name). selectedNode = renamedNode; PortalRequestContext prContext = Util.getPortalRequestContext(); prContext.createURL(NodeURL.TYPE).setNode(selectedNode); event.getRequestContext().sendRedirect(Utils.getSpaceURL(selectedNode)); return; } } else { uiApp.addMessage( new ApplicationMessage( "UISpaceInfo.msg.update-success", null, ApplicationMessage.INFO)); } }
public String event(String name, String beanId) throws Exception { if (Util.getUIPortal().getName().equals(beanId)) return super.url(name, beanId); return super.event(name, beanId); }
public static boolean isSymLink(Node node) throws RepositoryException { LinkManager linkManager = Util.getUIPortal().getApplicationComponent(LinkManager.class); return linkManager.isLink(node); }