示例#1
0
文件: Utils.java 项目: canhpv/ecms
  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);
  }
    public void execute(Event<UIPortlet> event) throws Exception {
      UIPortlet uiPortlet = event.getSource();

      UIPortalApplication uiPortalApp = uiPortlet.getAncestorOfType(UIPortalApplication.class);
      UIWorkingWorkspace uiWorkingWS =
          uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
      PortalRequestContext pcontext = (PortalRequestContext) event.getRequestContext();
      pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);
      pcontext.ignoreAJAXUpdateOnPortlets(true);

      String windowState = null;

      Object changeWindowStateAttribute =
          event.getRequestContext().getAttribute(CHANGE_WINDOW_STATE_EVENT);
      if (changeWindowStateAttribute != null && changeWindowStateAttribute instanceof String) {
        windowState = (String) changeWindowStateAttribute;
      }

      if (windowState == null) {
        windowState = event.getRequestContext().getRequestParameter(Constants.PORTAL_WINDOW_STATE);
      }
      if (windowState == null) {
        if (event.getRequestContext().getRequestParameter(UIComponent.OBJECTID) != null) {
          windowState = event.getRequestContext().getRequestParameter(UIComponent.OBJECTID).trim();
        }
      }

      if (windowState == null) {
        windowState = uiPortlet.getCurrentWindowState().toString();
      }

      UIPage uiPage = uiPortlet.getAncestorOfType(UIPage.class);
      if (windowState.equals(WindowState.MAXIMIZED.toString())) {
        if (uiPage != null) {
          uiPage.normalizePortletWindowStates();
          uiPage.setMaximizedUIPortlet(uiPortlet);
        }
        uiPortlet.setCurrentWindowState(WindowState.MAXIMIZED);
        return;
      } else {
        if (windowState.equals(WindowState.MINIMIZED.toString())) {
          uiPortlet.setCurrentWindowState(WindowState.MINIMIZED);
        } else {
          uiPortlet.setCurrentWindowState(WindowState.NORMAL);
        }
        if (uiPage != null) {
          clearMaximizedUIComponent(uiPage, uiPortlet);
        }
      }
    }
示例#3
0
  public static void toUIPage(UIPage uiPage, Page model) throws Exception {
    toUIContainer(uiPage, model);
    uiPage.setSiteKey(new SiteKey(model.getOwnerType(), model.getOwnerId()));
    uiPage.setIcon(model.getIcon());
    uiPage.setAccessPermissions(model.getAccessPermissions());
    uiPage.setEditPermission(model.getEditPermission());
    uiPage.setFactoryId(model.getFactoryId());
    uiPage.setPageId(model.getPageId());
    uiPage.setTitle(model.getTitle());
    uiPage.setShowMaxWindow(model.isShowMaxWindow());
    uiPage.setModifiable(model.isModifiable());

    List<UIPortlet> portlets = new ArrayList<UIPortlet>();
    uiPage.findComponentOfType(portlets, UIPortlet.class);
    for (UIPortlet portlet : portlets) {
      portlet.setPortletInPortal(false);
    }
  }
 /**
  * This method is used to set the next portlet window state if this one needs to be modified
  * because of the incoming request
  */
 public static void setNextState(UIPortlet uiPortlet, WindowState state) {
   if (state != null) {
     UIPage uiPage = uiPortlet.getAncestorOfType(UIPage.class);
     if (WindowState.MAXIMIZED.equals(state)) {
       uiPortlet.setCurrentWindowState(WindowState.MAXIMIZED);
       if (uiPage != null) {
         uiPage.setMaximizedUIPortlet(uiPortlet);
       }
     } else if (WindowState.MINIMIZED.equals(state)) {
       uiPortlet.setCurrentWindowState(WindowState.MINIMIZED);
       if (uiPage != null) {
         uiPage.setMaximizedUIPortlet(null);
       }
     } else {
       uiPortlet.setCurrentWindowState(WindowState.NORMAL);
       if (uiPage != null) {
         uiPage.setMaximizedUIPortlet(null);
       }
     }
   }
 }
 public String getUIPageId() {
   UIPortalApplication portalApp = Util.getUIPortalApplication();
   UIPage uiPage = portalApp.findFirstComponentOfType(UIPage.class);
   return uiPage.getId();
 }
    public void execute(Event<UIPortlet> event) throws Exception {
      UIPortlet uiPortlet = event.getSource();

      UIPortalApplication uiPortalApp = uiPortlet.getAncestorOfType(UIPortalApplication.class);
      UIWorkingWorkspace uiWorkingWS =
          uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
      PortalRequestContext pcontext = (PortalRequestContext) event.getRequestContext();
      pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);
      pcontext.ignoreAJAXUpdateOnPortlets(true);

      String windowState = null;

      Object changeWindowStateAttribute =
          event.getRequestContext().getAttribute(CHANGE_WINDOW_STATE_EVENT);
      if (changeWindowStateAttribute != null && changeWindowStateAttribute instanceof String) {
        windowState = (String) changeWindowStateAttribute;
      }

      if (windowState == null) {
        windowState = event.getRequestContext().getRequestParameter(Constants.PORTAL_WINDOW_STATE);
      }
      if (windowState == null) {
        windowState = event.getRequestContext().getRequestParameter(UIComponent.OBJECTID).trim();
      }

      if (windowState == null) {
        windowState = uiPortlet.getCurrentWindowState().toString();
      }

      UIPageBody uiPageBody = uiPortlet.getAncestorOfType(UIPageBody.class);
      UIPage uiPage = uiPortlet.getAncestorOfType(UIPage.class);
      if (windowState.equals(WindowState.MAXIMIZED.toString())) {
        if (uiPageBody != null) {
          uiPortlet.setCurrentWindowState(WindowState.MAXIMIZED);
          // TODO dang.tung: we have to set maximized portlet for page because in ShowMaxWindow case
          // the PageBody isn't rendered
          //                reference: UIPortalLifecycle, UIPageLifecycle, renderChildren() in
          // UIPageBody
          // ---------------------------------------------------------
          if (uiPage != null && uiPage.isShowMaxWindow()) {
            uiPage.setMaximizedUIPortlet(uiPortlet);
          }
          // ---------------------------------------------------------
          uiPageBody.setMaximizedUIComponent(uiPortlet);
        } else {
          uiPortlet.setCurrentWindowState(WindowState.NORMAL);
        }
        return;
      }
      if (uiPageBody != null) {
        UIPortlet maxPortlet = (UIPortlet) uiPageBody.getMaximizedUIComponent();
        if (maxPortlet == uiPortlet) {
          uiPageBody.setMaximizedUIComponent(null);
        }
      }
      // TODO dang.tung: for ShowMaxWindow situation
      // ----------------------------------------------------------------
      if (uiPage != null) {
        UIPortlet maxPortlet = (UIPortlet) uiPage.getMaximizedUIPortlet();
        if (maxPortlet == uiPortlet) {
          uiPage.setMaximizedUIPortlet(null);
        }
      }
      // -----------------------------------------------------------------
      if (windowState.equals(WindowState.MINIMIZED.toString())) {
        uiPortlet.setCurrentWindowState(WindowState.MINIMIZED);
        return;
      }
      uiPortlet.setCurrentWindowState(WindowState.NORMAL);
    }
 private static void clearMaximizedUIComponent(UIPage uiPage, UIPortlet uiPortlet) {
   if (uiPage.getMaximizedUIPortlet() != null
       && uiPage.getMaximizedUIPortlet().getId().equals(uiPortlet.getId())) {
     uiPage.setMaximizedUIPortlet(null);
   }
 }
示例#8
0
 public static Page toPageModel(UIPage uiPage) {
   Page model = new Page(uiPage.getStorageId());
   toContainer(model, uiPage);
   model.setOwnerId(uiPage.getSiteKey().getName());
   model.setOwnerType(uiPage.getSiteKey().getTypeName());
   model.setIcon(uiPage.getIcon());
   model.setPageId(uiPage.getPageId());
   model.setTitle(uiPage.getTitle());
   model.setAccessPermissions(uiPage.getAccessPermissions());
   model.setEditPermission(uiPage.getEditPermission());
   model.setFactoryId(uiPage.getFactoryId());
   model.setShowMaxWindow(uiPage.isShowMaxWindow());
   model.setModifiable(uiPage.isModifiable());
   return model;
 }