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;
  }
Example #2
0
  public static boolean hasEditPermissionOnPage() throws Exception {
    UIPortalApplication portalApp = Util.getUIPortalApplication();
    UIWorkingWorkspace uiWorkingWS = portalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
    UIPageBody pageBody = uiWorkingWS.findFirstComponentOfType(UIPageBody.class);
    UIPage uiPage = (UIPage) pageBody.getUIComponent();
    UserACL userACL = portalApp.getApplicationComponent(UserACL.class);

    if (uiPage != null) {
      return userACL.hasEditPermissionOnPage(
          uiPage.getOwnerType(), uiPage.getOwnerId(), uiPage.getEditPermission());
    }
    UIPortal currentUIPortal =
        portalApp
            .<UIWorkingWorkspace>findComponentById(UIPortalApplication.UI_WORKING_WS_ID)
            .findFirstComponentOfType(UIPortal.class);
    UserNode currentNode = currentUIPortal.getSelectedUserNode();
    String pageReference = currentNode.getPageRef();
    if (pageReference == null) {
      return false;
    }
    DataStorage dataStorage = portalApp.getApplicationComponent(DataStorage.class);
    Page page = dataStorage.getPage(pageReference);
    if (page == null) {
      return false;
    }
    return userACL.hasEditPermission(page);
  }
  /**
   * Returns a list of portlets skin that have to be added in the HTML head tag. The skin can
   * directly point to a real css file (this is the case of all the porlet included in a page) or
   * point to a servlet that agregates different portlet CSS files into one to lower the number of
   * HTTP calls (this is the case in production as all the portlets included in a portal, and hence
   * there on everypage are merged into a single CSS file)
   *
   * @return the portlet skins
   */
  public Set<Skin> getPortletSkins() {
    // Set to avoid repetition
    Set<Skin> skins = new HashSet<Skin>();

    // Determine portlets visible on the page
    List<UIPortlet> uiportlets = new ArrayList<UIPortlet>();
    UIWorkingWorkspace uiWorkingWS = getChildById(UI_WORKING_WS_ID);
    UIPortal uiPortal = uiWorkingWS.findFirstComponentOfType(UIPortal.class);
    uiPortal.findComponentOfType(uiportlets, UIPortlet.class);
    UIPortalToolPanel toolPanel = uiWorkingWS.getChild(UIPortalToolPanel.class);
    if (toolPanel != null && toolPanel.isRendered()) {
      toolPanel.findComponentOfType(uiportlets, UIPortlet.class);
    }

    // Get portal portlets to filter since they are already in the portal skins
    Set<SkinConfig> portletConfigs = getPortalPortletSkins();

    //
    for (UIPortlet uiPortlet : uiportlets) {
      SkinConfig skinConfig = getPortletSkinConfig(uiPortlet);
      if (skinConfig != null && !portletConfigs.contains(skinConfig)) {
        skins.add(skinConfig);
      }
    }

    //
    return skins;
  }
Example #4
0
 public static boolean hasEditPermissionOnPortal() throws Exception {
   UIPortalApplication portalApp = Util.getUIPortalApplication();
   UIPortal currentUIPortal =
       portalApp
           .<UIWorkingWorkspace>findComponentById(UIPortalApplication.UI_WORKING_WS_ID)
           .findFirstComponentOfType(UIPortal.class);
   UserACL userACL = portalApp.getApplicationComponent(UserACL.class);
   return userACL.hasEditPermissionOnPortal(
       currentUIPortal.getSiteKey().getTypeName(),
       currentUIPortal.getSiteKey().getName(),
       currentUIPortal.getEditPermission());
 }
Example #5
0
 /**
  * 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);
 }
  /**
   * The processDecode() method is doing 3 actions: 1) if the nodePath is null (case of the first
   * request) a call to super.processDecode(context) is made and we end the method here 2) if the
   * nodePath exist but is equals to the current one then we also call super and stops here 3) if
   * the requested nodePath is not equals to the current one , then an event of type
   * PageNodeEvent.CHANGE_PAGE_NODE is sent to the asociated EventListener; a call to super is then
   * done
   */
  public void processDecode(WebuiRequestContext context) throws Exception {
    PortalRequestContext pcontext = (PortalRequestContext) context;
    String nodePath = pcontext.getNodePath().trim();

    if (!nodePath.equals(nodePath_)) {
      nodePath_ = nodePath;
      UIPortal uiPortal = findFirstComponentOfType(UIPortal.class);
      PageNodeEvent<UIPortal> pnevent =
          new PageNodeEvent<UIPortal>(uiPortal, PageNodeEvent.CHANGE_PAGE_NODE, nodePath_);
      uiPortal.broadcast(pnevent, Event.Phase.PROCESS);
    }
    super.processDecode(context);
  }
  /**
   * 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);
          }
        }
      }
    }
  }
Example #8
0
  /**
   * Add Application to UiPage
   *
   * @param event
   * @throws Exception
   */
  private static void addApplicationToPage(Event<UIAddNewApplication> event, boolean atStartup)
      throws Exception {
    UIPortalApplication uiPortalApp = Util.getUIPortalApplication();
    UIPortal uiPortal = uiPortalApp.getShowedUIPortal();
    PortalRequestContext pcontext = Util.getPortalRequestContext();

    UIDesktopPage uiDesktopPage = uiPortal.findFirstComponentOfType(UIDesktopPage.class);
    if (uiDesktopPage == null) {
      pcontext.addUIComponentToUpdateByAjax(
          uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID));
      UIMaskWorkspace maskWorkspace = uiPortalApp.getChildById(UIPortalApplication.UI_MASK_WS_ID);
      maskWorkspace.createEvent("Close", Event.Phase.DECODE, event.getRequestContext()).broadcast();
      pcontext.setFullRender(true);
      return;
    }

    String applicationId = event.getRequestContext().getRequestParameter(UIComponent.OBJECTID);

    Application application = event.getSource().getApplication(applicationId);
    ApplicationType appType = application.getType();

    UIPortlet uiPortlet = uiDesktopPage.createUIComponent(UIPortlet.class, null, null);
    ApplicationState appState;

    // TODO: Check if there 's already a portlet window of this portlet. A CloneApplicationState
    // should be created in such case
    appState = new TransientApplicationState<Object>(application.getContentId());

    uiPortlet.setState(new PortletState(appState, appType));
    uiPortlet.setPortletInPortal(false);

    if (atStartup) {
      uiPortlet.getProperties().setProperty("appStatus", "HIDE");
    }

    String portletName = application.getApplicationName();
    String displayName = application.getDisplayName();
    if (displayName != null) {
      uiPortlet.setTitle(displayName);
    } else if (portletName != null) {
      uiPortlet.setTitle(portletName);
    }
    uiPortlet.setDescription(application.getDescription());
    List<String> accessPers = application.getAccessPermissions();
    String[] accessPermissions = accessPers.toArray(new String[accessPers.size()]);
    uiPortlet.setAccessPermissions(accessPermissions);

    // Add portlet to page
    uiDesktopPage.addChild(uiPortlet);

    if (uiDesktopPage.isModifiable()) {
      Page page = (Page) PortalDataMapper.buildModelObject(uiDesktopPage);
      if (page.getChildren() == null) {
        page.setChildren(new ArrayList<ModelObject>());
      }
      DataStorage dataService = uiPortalApp.getApplicationComponent(DataStorage.class);
      dataService.save(page);

      // Rebuild the uiPage to synchronize (storageId, storageName) mapping
      page = dataService.getPage(page.getPageId());
      page.setModifiable(true);
      uiDesktopPage.getChildren().clear();
      PortalDataMapper.toUIPage(uiDesktopPage, page);
    }

    UIWorkingWorkspace uiWorkingWS = uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
    pcontext.setFullRender(true);
    pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);
  }
Example #9
0
    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));
      }
    }
Example #10
0
  public static void toUIPortal(UIPortal uiPortal, PortalConfig model) throws Exception {
    uiPortal.setSiteKey(new SiteKey(model.getType(), model.getName()));
    uiPortal.setStorageId(model.getStorageId());
    uiPortal.setName(model.getName());
    uiPortal.setId("UIPortal");
    // uiPortal.setFactoryId(model.getFactoryId());
    uiPortal.setModifiable(model.isModifiable());

    uiPortal.setLabel(model.getLabel());
    uiPortal.setDescription(model.getDescription());
    uiPortal.setLocale(model.getLocale());
    uiPortal.setSkin(model.getSkin());
    uiPortal.setAccessPermissions(model.getAccessPermissions());
    uiPortal.setEditPermission(model.getEditPermission());
    uiPortal.setProperties(model.getProperties());
    uiPortal.setRedirects(model.getPortalRedirects());

    Container layout = model.getPortalLayout();
    uiPortal.setMoveAppsPermissions(layout.getMoveAppsPermissions());
    uiPortal.setMoveContainersPermissions(layout.getMoveContainersPermissions());
    List<ModelObject> children = layout.getChildren();
    if (children != null) {
      for (Object child : children) {
        buildUIContainer(uiPortal, child, false);
      }
    }
  }
Example #11
0
  private static PortalConfig toPortal(UIPortal uiPortal) {
    PortalConfig model =
        new PortalConfig(
            uiPortal.getSiteType().getName(), uiPortal.getName(), uiPortal.getStorageId());
    model.setAccessPermissions(uiPortal.getAccessPermissions());
    model.setEditPermission(uiPortal.getEditPermission());
    model.setLabel(uiPortal.getLabel());
    model.setDescription(uiPortal.getDescription());
    model.setLocale(uiPortal.getLocale());
    model.setSkin(uiPortal.getSkin());
    model.setModifiable(uiPortal.isModifiable());
    model.setProperties(uiPortal.getProperties());
    model.setPortalRedirects(uiPortal.getPortalRedirects());

    model.setPortalLayout(new Container());

    List<UIComponent> children = uiPortal.getChildren();
    if (children == null) return model;
    ArrayList<ModelObject> newChildren = new ArrayList<ModelObject>();
    for (UIComponent child : children) {
      ModelObject component = buildModelObject(child);
      if (component != null) newChildren.add(component);
    }
    model.getPortalLayout().setChildren(newChildren);
    model.getPortalLayout().setMoveAppsPermissions(uiPortal.getMoveAppsPermissions());
    model.getPortalLayout().setMoveContainersPermissions(uiPortal.getMoveContainersPermissions());
    return model;
  }