예제 #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);
  }
예제 #2
0
파일: Utils.java 프로젝트: canhpv/ecms
 /**
  * Checks if is edits the portlet in create page wizard.
  *
  * @return true, if is edits the portlet in create page wizard
  */
 public static boolean isEditPortletInCreatePageWizard() {
   UIPortalApplication portalApplication = Util.getUIPortalApplication();
   UIMaskWorkspace uiMaskWS = portalApplication.getChildById(UIPortalApplication.UI_MASK_WS_ID);
   // show maskworkpace is being in Portal page edit mode
   if (uiMaskWS.getWindowWidth() > 0 && uiMaskWS.getWindowHeight() < 0) return true;
   return false;
 }
예제 #3
0
파일: Utils.java 프로젝트: canhpv/ecms
  /**
   * Creates a restfull compliant link to the editor for editing a content, adding a content or
   * managing contents. Example : Add Content : isEditable = false, isNew = true, itemPath = the
   * parent folder path Edit Content : isEditable = true, isNew = false, itemPath = the content path
   * Manage Contents = isEditable = false, isNew = false, itemPath = the folder path
   *
   * @param itemPath
   * @param isEditable
   * @param isNew
   * @return
   */
  public static String getEditLink(String itemPath, boolean isEditable, boolean isNew) {
    PortalRequestContext pContext = Util.getPortalRequestContext();
    String backto = pContext.getRequestURI();
    WCMConfigurationService configurationService =
        Util.getUIPortalApplication().getApplicationComponent(WCMConfigurationService.class);
    String editorPageURI =
        configurationService.getRuntimeContextParam(
            isEditable || isNew
                ? WCMConfigurationService.EDITOR_PAGE_URI
                : WCMConfigurationService.SITE_EXPLORER_URI);
    UserNode editorNode = getEditorNode(editorPageURI);

    if (editorNode == null) {
      return "";
    }

    NodeURL nodeURL = pContext.createURL(NodeURL.TYPE);
    nodeURL.setNode(editorNode).setQueryParameterValue("path", itemPath);
    if (isEditable) {
      nodeURL.setQueryParameterValue("edit", "true");
    }
    if (isNew) {
      nodeURL.setQueryParameterValue("addNew", "true");
    }
    nodeURL.setQueryParameterValue(org.exoplatform.ecm.webui.utils.Utils.URL_BACKTO, backto);

    return nodeURL.toString();
  }
예제 #4
0
파일: Utils.java 프로젝트: canhpv/ecms
 /**
  * Refresh whole portal by AJAX.
  *
  * @param context the portlet request context
  */
 public static void updatePortal(PortletRequestContext context) {
   UIPortalApplication portalApplication = Util.getUIPortalApplication();
   PortalRequestContext portalRequestContext =
       (PortalRequestContext) context.getParentAppRequestContext();
   UIWorkingWorkspace uiWorkingWS =
       portalApplication.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
   portalRequestContext.addUIComponentToUpdateByAjax(uiWorkingWS);
   portalRequestContext.ignoreAJAXUpdateOnPortlets(true);
 }
예제 #5
0
파일: Utils.java 프로젝트: canhpv/ecms
 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());
 }
예제 #6
0
파일: Utils.java 프로젝트: canhpv/ecms
 /**
  * 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);
 }
  private boolean canAcceedMenu() throws Exception {
    UIPortalApplication portalApp = Util.getUIPortalApplication();
    UIPage uiPage = portalApp.findFirstComponentOfType(UIPage.class);
    //    boolean canAccessMenu = (!(uiPage instanceof UIDesktopPage))
    //        && (hasEditPermissionOnNavigation() || hasEditPermissionOnPage() ||
    // hasEditPermissionOnPortal());
    boolean canAccessMenu =
        (hasEditPermissionOnNavigation()
            || hasEditPermissionOnPage()
            || hasEditPermissionOnPortal());

    return canAccessMenu;
  }
예제 #8
0
 public void execute(final Event<UIPortletForm> event) throws Exception {
   UIPortletForm uiPortletForm = event.getSource();
   UIPortlet uiPortlet = uiPortletForm.getUIPortlet();
   if (uiPortletForm.hasEditMode()) {
     uiPortlet.setCurrentPortletMode(PortletMode.VIEW);
   }
   UIPortalApplication uiPortalApp = Util.getUIPortalApplication();
   PortalRequestContext pcontext = (PortalRequestContext) event.getRequestContext();
   // add by Pham Dinh Tan
   UIMaskWorkspace uiMaskWorkspace = uiPortalApp.getChildById(UIPortalApplication.UI_MASK_WS_ID);
   uiMaskWorkspace.broadcast(event, Phase.DECODE);
   pcontext.ignoreAJAXUpdateOnPortlets(true);
 }
예제 #9
0
파일: Utils.java 프로젝트: canhpv/ecms
 public static String getRealPortletId(PortletRequestContext portletRequestContext) {
   String portletId = portletRequestContext.getWindowId();
   int modeState = Util.getUIPortalApplication().getModeState();
   switch (modeState) {
     case UIPortalApplication.NORMAL_MODE:
       return portletId;
     case UIPortalApplication.APP_BLOCK_EDIT_MODE:
       return "UIPortlet-" + portletId;
     case UIPortalApplication.APP_VIEW_EDIT_MODE:
       return "EditMode-" + portletId;
     default:
       return null;
   }
 }
예제 #10
0
파일: Utils.java 프로젝트: canhpv/ecms
 /**
  * Check if the content is editable and current mode of the site is edit mode
  *
  * @param content the content node
  * @return true if there is no content if the content is editable and current mode is edit mode
  */
 public static boolean isShowQuickEdit(Node content) {
   if (content == null) return true;
   try {
     boolean isEditMode = false;
     if (WCMComposer.MODE_EDIT.equals(getCurrentMode())
         || Util.getUIPortalApplication().getModeState() != UIPortalApplication.NORMAL_MODE)
       isEditMode = true;
     ((ExtendedNode) content).checkPermission(PermissionType.SET_PROPERTY);
     ((ExtendedNode) content).checkPermission(PermissionType.ADD_NODE);
     ((ExtendedNode) content).checkPermission(PermissionType.REMOVE);
     return isEditMode;
   } catch (Exception e) {
     return false;
   }
 }
  public void reloadTreeData() throws Exception {
    UserPortal userPortal = Util.getUIPortalApplication().getUserPortalConfig().getUserPortal();
    SpaceService spaceService = getApplicationComponent(SpaceService.class);
    String spaceUrl = Utils.getSpaceUrlByContext();
    Space space = spaceService.getSpaceByUrl(spaceUrl);

    UserNavigation groupNav = SpaceUtils.getGroupNavigation(space.getGroupId());

    setOwner(groupNav.getKey().getName());
    setOwnerType(groupNav.getKey().getTypeName());

    UISpaceNavigationNodeSelector selector = getChild(UISpaceNavigationNodeSelector.class);
    selector.setEdittedNavigation(groupNav);
    selector.setUserPortal(userPortal);
    selector.initTreeData();
  }
    public void execute(Event<UIPortlet> event) throws Exception {
      UIPortlet uiPortlet = event.getSource();
      UIPortalApplication uiApp = Util.getUIPortalApplication();
      UIMaskWorkspace uiMaskWS = uiApp.getChildById(UIPortalApplication.UI_MASK_WS_ID);
      UIPortletForm uiPortletForm = uiMaskWS.createUIComponent(UIPortletForm.class, null, null);

      if (uiPortletForm.setValues(uiPortlet) == false) {
        uiMaskWS.setUIComponent(null);
        WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
        context
            .getUIApplication()
            .addMessage(
                (new ApplicationMessage(
                    "UIPortlet.message.portletDeleted", null, ApplicationMessage.ERROR)));
      } else {
        uiMaskWS.setUpdated(true);
        uiMaskWS.setWindowSize(800, -1);
        event.getRequestContext().addUIComponentToUpdateByAjax(uiMaskWS);
      }
    }
 public String getUIPageId() {
   UIPortalApplication portalApp = Util.getUIPortalApplication();
   UIPage uiPage = portalApp.findFirstComponentOfType(UIPage.class);
   return uiPage.getId();
 }
예제 #14
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);
  }
예제 #15
0
파일: Utils.java 프로젝트: canhpv/ecms
 public static boolean isPortalEditMode() {
   return Util.getUIPortalApplication().getModeState() != UIPortalApplication.NORMAL_MODE;
 }
    public void execute(Event<UIPortlet<S, C>> event) throws Exception {
      UIPortlet<S, C> uiPortlet = event.getSource();
      log.trace("Serve Resource for portlet: " + uiPortlet.getPortletContext());
      String resourceId = null;

      //
      PortalRequestContext context = (PortalRequestContext) event.getRequestContext();
      HttpServletResponse response = context.getResponse();

      //
      try {
        // Set the NavigationalState
        String navState =
            context.getRequestParameter(ExoPortletInvocationContext.NAVIGATIONAL_STATE_PARAM_NAME);
        if (navState != null) {
          uiPortlet.setNavigationalState(ParametersStateString.create(navState));
        }

        //
        ResourceInvocation resourceInvocation = uiPortlet.create(ResourceInvocation.class, context);

        // set the resourceId to be used in case of a problem
        resourceId = resourceInvocation.getResourceId();

        //
        PortletInvocationResponse portletResponse = uiPortlet.invoke(resourceInvocation);

        //
        int statusCode;
        MultiValuedPropertyMap<String> transportHeaders;
        String contentType;
        String charset;
        Object content;
        if (!(portletResponse instanceof ContentResponse)) {
          if (portletResponse instanceof ErrorResponse) {
            ErrorResponse errorResponse = (ErrorResponse) portletResponse;
            Throwable cause = errorResponse.getCause();
            if (cause != null) {
              log.trace("Got error response from portlet", cause);
            } else if (errorResponse.getMessage() != null) {
              log.trace("Got error response from portlet:" + errorResponse.getMessage());
            } else {
              log.trace("Got error response from portlet");
            }
          } else {
            log.trace(
                "Unexpected response type ["
                    + portletResponse
                    + "]. Expected a ContentResponse or an ErrorResponse.");
          }
          statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
          contentType = null;
          charset = null;
          transportHeaders = null;
          content = null;
        } else {
          //
          ContentResponse piResponse = (ContentResponse) portletResponse;
          ResponseProperties properties = piResponse.getProperties();
          transportHeaders = properties != null ? properties.getTransportHeaders() : null;

          // Look at status code if there is one and honour it
          String status =
              transportHeaders != null
                  ? transportHeaders.getValue(ResourceResponse.HTTP_STATUS_CODE)
                  : null;
          if (status != null) {
            try {
              statusCode = Integer.parseInt(status);
            } catch (NumberFormatException e) {
              statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
            }
          } else {
            statusCode = HttpServletResponse.SC_OK;
          }

          //
          contentType = piResponse.getContentType();
          charset = piResponse.getEncoding();

          //
          log.trace(
              "Try to get a resource of type: "
                  + contentType
                  + " for the portlet: "
                  + uiPortlet.getId());
          if (piResponse.getChars() != null) {
            content = piResponse.getChars();
          } else if (piResponse.getBytes() != null) {
            content = piResponse.getBytes();
          } else {
            content = null;
          }
        }

        //
        response.setStatus(statusCode);

        // Set content type if any
        if (contentType != null) {
          response.setContentType(contentType);
        }

        // Set encoding
        if (charset != null) {
          response.setCharacterEncoding(charset);
        }

        // Send headers if any
        if (transportHeaders != null) {
          sendHeaders(transportHeaders, context);
        }

        // Send body if any
        if (content instanceof String) {
          context.getWriter().write((String) content);
        } else if (content instanceof byte[]) {
          byte[] bytes = (byte[]) content;
          response.setContentLength(bytes.length);
          OutputStream stream = response.getOutputStream();
          try {
            stream.write(bytes);
          } finally {
            Safe.close(stream);
          }
        }

        //
        response.flushBuffer();
      } catch (NoSuchDataException e) {
        UIPortalApplication uiApp = Util.getUIPortalApplication();
        uiApp.refreshCachedUI();
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
      } catch (Exception e) {
        if (!e.getClass().toString().contains("ClientAbortException")) {
          log.error(
              "Problem while serving resource "
                  + (resourceId != null ? resourceId : "")
                  + " for the portlet: "
                  + uiPortlet.getPortletContext().getId(),
              e);
        }
      } finally {
        /** The resource method does not need to go through the render phase */
        event.getRequestContext().setResponseComplete(true);
      }
    }