コード例 #1
0
 protected PanelInstanceNode getNewInstanceNode(PanelInstance instance) {
   PanelInstanceNode instanceNode = CDIBeanLocator.getBeanByType(PanelInstanceNode.class);
   instanceNode.setWorkspaceId(instance.getWorkspace().getId());
   instanceNode.setPanelInstanceId(instance.getInstanceId());
   instanceNode.setParent(this);
   instanceNode.setTree(getTree());
   return instanceNode;
 }
コード例 #2
0
 protected List listChildren() {
   List children = new ArrayList();
   PanelInstancesNode parent = (PanelInstancesNode) getParent();
   final String language = LocaleManager.currentLang();
   try {
     String workspaceId = parent.getHandler().getWorkspaceId();
     WorkspaceImpl workspace =
         (WorkspaceImpl) UIServices.lookup().getWorkspacesManager().getWorkspace(workspaceId);
     PanelInstance[] instances = workspace.getPanelInstancesInGroup(providerId);
     if (instances != null) {
       TreeSet<PanelInstance> panelInstances =
           new TreeSet<PanelInstance>(
               new Comparator<PanelInstance>() {
                 public int compare(PanelInstance p1, PanelInstance p2) {
                   return p1.getTitle(language).compareToIgnoreCase(p2.getTitle(language));
                 }
               });
       TreeSet<String> groups = new TreeSet<String>();
       for (PanelInstance pi : instances) {
         String group = pi.getParameterValue(PanelInstance.PARAMETER_GROUP, language);
         if (group != null && !"".equals(group.trim())) {
           groups.add(group);
         } else {
           panelInstances.add(pi);
         }
       }
       for (String gr : groups) {
         children.add(getNewGroupNode(workspaceId, gr));
       }
       for (PanelInstance pi : panelInstances) {
         children.add(getNewInstanceNode(pi));
       }
     }
   } catch (Exception e) {
     log.error("Error: ", e);
   }
   return children;
 }
コード例 #3
0
  private List getPanels() {
    List panels = new ArrayList();
    UserStatus userStatus = getUserStatus();
    if (instance != null) {
      PanelInstance[] instances = instance.getWorkspace().getPanelInstances();
      for (int i = 0; i < instances.length; i++) {
        if (panelProvider.isAssignableFrom(instances[i].getProvider().getDriver().getClass())) {
          PanelPermission viewPerm =
              PanelPermission.newInstance(instances[i], PanelPermission.ACTION_VIEW);
          if (userStatus.hasPermission(viewPerm)) panels.add(instances[i]);
        }
      }
    }

    return panels;
  }
コード例 #4
0
  /**
   * Replicates panel data.
   *
   * @param src Source PanelInstance
   * @param dest Destinaton PanelInstance
   */
  public void replicateData(final PanelInstance src, PanelInstance dest) throws Exception {
    super.replicateData(src, dest);
    log.debug(
        "HTMLDriver replicating Data from PanelInstance "
            + src.getDbid()
            + " to "
            + dest.getDbid()
            + ").");
    if (src.equals(dest)) {
      log.debug("Ignoring replication, panel instance is the same.");
      return;
    }

    final HTMLText[] textArray = new HTMLText[1];
    try {
      new HibernateTxFragment() {
        protected void txFragment(Session session) throws Exception {
          log.debug("Getting text to duplicate for instance " + src.getDbid());
          FlushMode oldMode = session.getFlushMode();
          session.setFlushMode(
              FlushMode
                  .COMMIT); // Avoids flushing, as we know the text was not modified in this
                            // transaction.
          textArray[0] = load(src);
          session.setFlushMode(oldMode);
          log.debug("Got text to duplicate for instance " + src.getDbid());
        }
      }.execute();
    } catch (Exception e) {
      log.error("Error loading text for instance. ", e);
    }
    HTMLText text = textArray[0];
    if (text == null) {
      log.debug(
          "Nothing to replicate from PanelInstance " + src.getDbid() + " to " + dest.getDbid());
      return;
    }
    Map htmlSrc = text.getText();

    log.debug("htmlCode to replicate = " + htmlSrc);
    HTMLText htmlDest = new HTMLText();
    htmlDest.setPanelInstance(dest.getInstance());
    for (Iterator it = htmlSrc.keySet().iterator(); it.hasNext(); ) {
      String key = (String) it.next();
      String val = (String) htmlSrc.get(key);
      htmlDest.setText(key, val);
    }
    try {
      log.debug("Updating HTMLText: IDText " + htmlDest.getDbid() + " Text " + htmlDest.getText());
      htmlDest.save();
    } catch (Exception e) {
      log.error("Replicating panel data", e);
    }
  }
コード例 #5
0
 /**
  * Returns if this driver is using default language
  *
  * @param panel
  * @return if this driver is using default language
  */
 public boolean isUsingDefaultLanguage(PanelInstance panel) {
   return Boolean.valueOf(panel.getParameterValue(PARAMETER_USE_DEFAULTS)).booleanValue();
 }
コード例 #6
0
 protected boolean setCustomParameters(CommandRequest request, PanelInstance instance)
     throws Exception {
   return setParameters(request, instance.getCustomParameters(), instance, true);
 }
コード例 #7
0
  protected boolean setParameters(
      final CommandRequest request,
      final PanelProviderParameter[] params,
      final PanelInstance instance,
      final boolean specificParameters)
      throws Exception {
    final boolean anyParamWritten[] = new boolean[] {false};

    new HibernateTxFragment() {
      @Override
      protected void txFragment(Session session) throws Throwable {
        super.txFragment(session);
        String language = LocaleManager.lookup().getCurrentLang();

        if (params != null && params.length > 0) {
          for (int i = 0; i < params.length; i++) {
            if (params[i]
                .getProvider()
                .getProperties()
                .containsKey("parameter." + params[i].getId())) {
              continue;
            }
            String value = params[i].readFromRequest(request.getRequestObject());
            log.debug(
                "Panel "
                    + instance.getInstanceId()
                    + " field:"
                    + params[i].getId()
                    + " = "
                    + value);
            if (params[i].isI18n()) {
              String oldValue = instance.getParameterValue(params[i].getId(), language);
              if (!RenderUtils.noNull(oldValue).equals(RenderUtils.noNull(value))
                  && params[i].isValid(value)) {
                instance.setParameterValue(params[i].getId(), value, language);
                anyParamWritten[0] = true;
              }
            } else {
              String oldValue = instance.getParameterValue(params[i].getId());
              if (!RenderUtils.noNull(oldValue).equals(RenderUtils.noNull(value))
                  && params[i].isValid(value)) {
                instance.setParameterValue(params[i].getId(), value);
                anyParamWritten[0] = true;
              }
            }

            if (!params[i].isValid(value)) formStatus.addWrongField(params[i].getId());
          }
        }
      }
    }.execute();

    if (formStatus.getWrongFields().length == 0) {
      if (anyParamWritten[0]) {
        if (specificParameters) instance.saveCustomProperties();
        else instance.saveProperties();
      }
      return true;
    }
    return false;
  }
コード例 #8
0
 private String getTitle(PanelInstance instance) {
   return (String) (LocaleManager.lookup()).localize(instance.getTitle());
 }