Ejemplo n.º 1
0
  private List<Panel> getRegionPanels() {
    Panel[] allPanels = currentSectionRegion.getPanels();
    List<Panel> panels = new ArrayList<Panel>();

    boolean onlyOnePanel = false;
    // When a panel is maximized in region, only show it.
    for (int i = 0; i < allPanels.length; i++) {
      Panel panel = allPanels[i];
      PanelSession status = panel.getPanelSession();
      if (status.isMaximizedInRegion()) {
        PanelPermission viewPerm = PanelPermission.newInstance(panel, PanelPermission.ACTION_VIEW);
        boolean canViewPanel = getUserStatus().hasPermission(viewPerm);
        if (canViewPanel) {
          panels.add(panel);
          onlyOnePanel = true;
          break;
        }
      }
    }
    if (!onlyOnePanel)
      for (int i = 0; i < allPanels.length; i++) {
        Panel panel = allPanels[i];
        PanelPermission viewPerm = PanelPermission.newInstance(panel, PanelPermission.ACTION_VIEW);
        boolean canViewPanel = getUserStatus().hasPermission(viewPerm);
        if (canViewPanel) {
          panels.add(panel);
        }
      }

    return panels;
  }
Ejemplo n.º 2
0
 /**
  * Determine the text being shown for given panel.
  *
  * @param panel
  * @return The text shown, i18n.
  */
 public Map getHtmlCode(Panel panel) {
   PanelSession pSession = SessionManager.getPanelSession(panel);
   Map m = (Map) pSession.getAttribute(ATTR_TEXT);
   if (m != null) return m;
   HTMLText text = load(panel.getInstance());
   if (text != null) return text.getText();
   try {
     HTMLText textToCreate = new HTMLText();
     textToCreate.setPanelInstance(panel.getInstance());
     Locale[] locales = LocaleManager.lookup().getPlatformAvailableLocales();
     for (int i = 0; i < locales.length; i++) {
       Locale locale = locales[i];
       ResourceBundle i18n =
           localeManager.getBundle("org.jboss.dashboard.ui.panel.advancedHTML.messages", locale);
       textToCreate.setText(locale.getLanguage(), i18n.getString("defaultContent"));
     }
     textToCreate.save();
   } catch (Exception e) {
     log.error("Error creating empty text for panel: ", e);
   }
   text = load(panel.getInstance());
   if (text != null) return text.getText();
   log.error("Current HTML code is null for panel " + panel);
   return null;
 }
Ejemplo n.º 3
0
  protected void renderPanel(Panel panel, boolean canEditPanel) {
    if (!isPanelOk(panel)) return;

    setAttribute("panel", panel);
    setAttribute("recommendedWidth", panelRecommendedWidth + "%");
    renderFragment("panelOutputStart");
    if (panel.isPaintTitle()
        || panel.getPanelSession().isMinimized()
        || (userAdmin)
        || (panel.getProvider().getDriver().supportsEditMode(panel) && canEditPanel)) {
      setAttribute("panel", panel);
      setAttribute("administratorMode", userAdmin);
      setAttribute(
          "panelTitle",
          StringEscapeUtils.ESCAPE_HTML4.translate(getLocalizedValue(panel.getTitle())));
      setAttribute("recommendedWidth", panelRecommendedWidth + "%");
      setAttribute("editMode", panel.getPanelSession().isEditMode());
      renderFragment("panelContentWithMenu");
    } else {
      setAttribute("panel", panel);
      setAttribute("recommendedWidth", panelRecommendedWidth + "%");
      renderFragment("panelContentWithoutMenu");
    }
    setAttribute("panel", panel);
    renderFragment("panelOutputEnd");
  }
 /**
  * Mapping to the controller servlet. By default it is Controller, but in case there is friendly
  * url, can be replaced by workspace/&lt;friendly_url&gt; It is NOT preceded by "/"
  *
  * @return Mapping to the controller servlet.
  */
 public String getBaseURI() {
   // Avoid an extra Controller in URL when it is already friendly
   Panel panel = RequestContext.lookup().getActivePanel();
   if (panel != null) { // There will be a friendly url here
     return getLinkToPage(panel.getSection(), true);
   }
   return getServletMapping();
 }
 /**
  * Get an url that leads to a given panel action
  *
  * @param panel Page to take to
  * @param allowFriendly allow friendly url
  * @param action action to perform on panel
  * @param extraParams Aditional parameters
  * @return an url that leads to a given panel
  */
 public String getLinkToPanelAction(
     Panel panel, String action, String extraParams, boolean allowFriendly) {
   StringBuffer sb = new StringBuffer();
   Map paramsMap = new HashMap();
   paramsMap.put(Parameters.DISPATCH_IDPANEL, panel.getPanelId());
   paramsMap.put(Parameters.DISPATCH_ACTION, action);
   sb.append(
       getRelativeLinkToPage(panel.getSection(), allowFriendly, LocaleManager.currentLang()));
   sb.append("?");
   String paramsMarkup = getParamsMarkup(paramsMap);
   sb.append(paramsMarkup);
   if (extraParams != null) {
     sb.append(PARAM_SEPARATOR).append(extraParams);
   }
   return postProcessURL(sb).toString();
 }
 protected HttpSession getSession() {
   RequestContext reqCtx = RequestContext.lookup();
   if (reqCtx != null) {
     CommandRequest request = reqCtx.getRequest();
     if (request != null) {
       Panel currentPanel = RequestContext.lookup().getActivePanel();
       if (currentPanel != null) {
         return currentPanel.getPanelSession();
       } else {
         if (log.isDebugEnabled())
           log.debug("Using a PanelScoped bean outside a panel. Will default to SessionScoped.");
         return request.getSessionObject();
       }
     }
   }
   return null;
 }
  /**
   * Generate a link to a factory component action
   *
   * @param beanName Factory component that will perform the action
   * @param action Bean's property (method) that will be invoked
   * @param params Extra parameters for link
   * @return A link url to a bean action
   */
  public String getMarkup(String beanName, String action, Map params) {
    try {
      if (params == null) params = new HashMap();
      Panel panel = RequestContext.lookup().getActivePanel();
      if (panel != null) {
        params.put(Parameters.DISPATCH_IDPANEL, panel.getPanelId());
        params.put(Parameters.DISPATCH_ACTION, "_factory");
      }

      StringBuffer sb = new StringBuffer();
      sb.append(_getServletMapping()).append("?");
      BeanHandler bean = (BeanHandler) CDIBeanLocator.getBeanByNameOrType(beanName);
      params.put(FactoryURL.PARAMETER_BEAN, bean.getBeanName());
      params.put(FactoryURL.PARAMETER_ACTION, bean.getActionName(action));
      sb.append(getParamsMarkup(params));
      bean.setEnabledForActionHandling(true);
      return postProcessURL(sb).toString();
    } catch (ClassCastException cce) {
      log.error("Bean " + beanName + " is not a BeanHandler.");
      return "#";
    }
  }
Ejemplo n.º 8
0
 public CommandResponse actionSaveChanges(Panel panel, CommandRequest request) throws Exception {
   String currentText = request.getRequestObject().getParameter(PARAMETER_HTML);
   Map m = (Map) SessionManager.getPanelSession(panel).getAttribute(ATTR_TEXT);
   HTMLText text = load(panel.getInstance());
   for (Iterator it = m.keySet().iterator(); it.hasNext(); ) {
     String lang = (String) it.next();
     String val = (String) m.get(lang);
     text.setText(lang, val);
   }
   text.setText(getEditingLanguage(panel), currentText);
   text.save();
   activateNormalMode(panel, request);
   return new ShowPanelPage();
 }
Ejemplo n.º 9
0
 public CommandResponse actionChangeEditingLanguage(Panel panel, CommandRequest request)
     throws Exception {
   String currentText = request.getRequestObject().getParameter(PARAMETER_HTML);
   Map text = (Map) SessionManager.getPanelSession(panel).getAttribute(ATTR_TEXT);
   if (text == null) {
     text = toEditableObject(load(panel.getInstance()));
     SessionManager.getPanelSession(panel).setAttribute(ATTR_TEXT, text);
   }
   text.put(getEditingLanguage(panel), currentText);
   SessionManager.getPanelSession(panel).setAttribute(ATTR_TEXT, text);
   String paramLang = request.getRequestObject().getParameter(PARAMETER_EDITING_LANG);
   SessionManager.getPanelSession(panel).setAttribute(ATTR_EDITING_LANGUAGE, paramLang);
   return new ShowPanelPage();
 }
Ejemplo n.º 10
0
 /**
  * Returns if this driver is using default language
  *
  * @param panel
  * @return if this driver is using default language
  */
 public boolean isUsingDefaultLanguage(Panel panel) {
   return Boolean.valueOf(panel.getParameterValue(PARAMETER_USE_DEFAULTS)).booleanValue();
 }
Ejemplo n.º 11
0
 /** Defines the action to be taken when activating edit mode */
 public void activateEditMode(Panel panel, CommandRequest request) throws Exception {
   super.activateEditMode(panel, request);
   HTMLText text = load(panel.getInstance());
   SessionManager.getPanelSession(panel).setAttribute(ATTR_TEXT, toEditableObject(text));
 }
  /**
   * Perform the required logic for this Formatter. Inside, the methods setAttribute and
   * renderFragment are intended to be used to generate the output and set parameters for this
   * output. Method getParameter is intended to retrieve input parameters by name.
   *
   * <p>Exceptions are to be catched inside the method, and not to be thrown, normally, formatters
   * could use a error fragment to be displayed when an error happens in displaying. But if the
   * error is unexpected, it can be wrapped inside a FormatterException.
   *
   * @param request user request
   * @param response response to the user
   * @throws org.jboss.dashboard.ui.taglib.formatter.FormatterException in case of an unexpected
   *     exception.
   */
  public void service(HttpServletRequest request, HttpServletResponse response)
      throws FormatterException {
    Panel panel = (Panel) getParameter("panel");
    PanelSession status = panel.getPanelSession();
    SectionRegion sectionRegion = panel.getSection().getSectionRegion(panel.getRegion().getId());
    boolean columnRegion = panel.getRegion().isColumnRegion();
    WorkspaceImpl workspace = NavigationManager.lookup().getCurrentWorkspace();
    boolean userIsAdmin = false;
    if (workspace != null) {
      WorkspacePermission permToCheck =
          WorkspacePermission.newInstance(workspace, WorkspacePermission.ACTION_ADMIN);
      userIsAdmin = UserStatus.lookup().hasPermission(permToCheck);
    }

    if (!userIsAdmin) return;

    PanelPermission editPanelPerm = PanelPermission.newInstance(panel, PanelPermission.ACTION_EDIT);
    boolean userCanEditPanel = UserStatus.lookup().hasPermission(editPanelPerm);

    renderFragment("movePanel");

    setAttribute("cursorStyle", "move");
    setAttribute(
        "title",
        StringEscapeUtils.escapeHtml((String) LocaleManager.lookup().localize(panel.getTitle())));
    renderFragment("menuLink");
    renderFragment("menuStart");

    setAttribute("title", LocalizeTag.getLocalizedValue(panel.getTitle(), getLang(), true));
    renderFragment("menuTitle");

    // Invalidate cache button.
    if (panel.getCacheTime() > 0)
      renderMenuOption(
          "ui.panel.refresh",
          getPanelActionLink(request, response, panel, "_invalidate-cache"),
          refreshIco,
          "R",
          panel.getCacheTime() > 0);

    if (status.isShowMode()) {
      boolean isEditModeEnabled =
          !status.isEditMode() && panel.supportsEditMode() && userCanEditPanel;
      // Edit button.
      if (isEditModeEnabled)
        renderMenuOption(
            "ui.panel.editMode",
            getPanelActionLink(request, response, panel, "_edit-mode"),
            editModeIco,
            "L",
            isEditModeEnabled);
    } else {
      // Show mode.
      renderMenuOption(
          "ui.panel.showMode",
          getPanelActionLink(request, response, panel, "_show-mode"),
          showModeIco,
          "S",
          !status.isShowMode());
    }
    // Properties mode
    renderMenuOption(
        "ui.panel.editProperties",
        getPanelActionLink(request, response, panel, "_start-config"),
        propertiesModeIco,
        "P",
        true);

    // Close button
    renderFragment("menuSeparator");
    renderMenuOption(
        "ui.panel.close",
        getPanelActionLink(request, response, panel, "_close"),
        eraseIco,
        "D",
        true,
        false);

    // Help mode
    renderMenuOption(
        "ui.panel.helpMode",
        getPanelActionLink(request, response, panel, "_help-mode"),
        helpModeIco,
        "?",
        !status.isHelpMode() && panel.supportsHelpMode());

    setAttribute("imageKey", closeIco);
    renderFragment("menuEnd");
  }
Ejemplo n.º 13
0
 protected boolean isPanelOk(Panel panel) {
   if (panel == null) return false;
   if (panel.getInstance() == null) return false;
   if (panel.getProvider() == null) return false;
   return true;
 }