Beispiel #1
0
  /**
   * @param rundata The turbine rundata context for this request.
   * @param portlet The portlet
   * @return The value of the start variable
   */
  private int getStart(RunData rundata, Portlet portlet) {
    int start = 0;
    Integer startInteger = rundata.getParameters().getInteger(START, -1);

    if (startInteger.intValue() == -1) {
      startInteger = (Integer) PortletSessionState.getAttribute(portlet, rundata, START);
      if (startInteger != null) {
        start = startInteger.intValue();
      }
    } else {
      PortletSessionState.setAttribute(portlet, rundata, START, startInteger);
      start = startInteger.intValue();
    }

    return start;
  }
Beispiel #2
0
  /** Subclasses must override this method to provide default behavior for the portlet action */
  protected void buildNormalContext(Portlet portlet, Context context, RunData rundata) {
    String regName = portlet.getPortletConfig().getInitParameter("registry", Registry.PORTLET);

    Boolean refresh =
        (Boolean)
            PortletSessionState.getAttribute(
                rundata, PREFIX + regName + ":" + REFRESH, Boolean.FALSE);

    if (refresh.equals(Boolean.TRUE)) {
      PortletSessionState.clearAttribute(portlet, rundata, START);
      PortletSessionState.clearAttribute(portlet, rundata, RESULTS);
      PortletSessionState.clearAttribute(portlet, rundata, FILTERED_RESULTS);
      PortletSessionState.clearAttribute(rundata, PREFIX + regName + ":" + REFRESH);
    }

    int start = getStart(rundata, portlet);
    if (start < 0) start = 0;

    String pageSize = portlet.getPortletConfig().getInitParameter("page-size", "20");

    int size = Integer.parseInt(pageSize);

    int prev = start - size;

    if (prev < 0) {
      prev = 0;
    }

    String[] filterFields =
        (String[]) PortletSessionState.getAttribute(portlet, rundata, FILTER_FIELDS);
    String[] filterValues =
        (String[]) PortletSessionState.getAttribute(portlet, rundata, FILTER_VALUES);

    List regEntries = (List) PortletSessionState.getAttribute(portlet, rundata, RESULTS);
    List filteredEntries =
        (List) PortletSessionState.getAttribute(portlet, rundata, FILTERED_RESULTS);
    if (regEntries == null) {
      Iterator i = Registry.get(regName).listEntryNames();
      regEntries = new ArrayList();

      while (i.hasNext()) {
        String name = (String) i.next();

        RegistryEntry regEntry = Registry.getEntry(regName, name);

        if ((regEntry != null) && (!regEntry.isHidden())) {
          regEntries.add(regEntry);
        }
      }

      Collections.sort(
          regEntries,
          new Comparator() {
            public int compare(Object o1, Object o2) {
              String t1 = ((RegistryEntry) o1).getName().toLowerCase();
              String t2 = ((RegistryEntry) o2).getName().toLowerCase();

              return t1.compareTo(t2);
            }
          });

      PortletSessionState.setAttribute(portlet, rundata, RESULTS, regEntries);

      filteredEntries = filter(regEntries, filterFields, filterValues);
      PortletSessionState.setAttribute(portlet, rundata, FILTERED_RESULTS, filteredEntries);
    }

    if (filterFields != null
        && filterValues != null
        && filterFields.length == filterValues.length) {
      for (int i = 0; i < filterFields.length; i++) {
        String field = filterFields[i];
        String value = filterValues[i];

        context.put(field + "_filter_value", value);
      }
    }

    int end = start + size;
    if (end > filteredEntries.size()) {
      end = filteredEntries.size();
    }
    List pageEntries = filteredEntries.subList(start, end);

    context.put("registry", pageEntries);
    context.put("filtered_entries", filteredEntries);
    if (start > 0) {
      context.put("prev", String.valueOf(prev));
    }
    if (end < filteredEntries.size()) {
      context.put("next", String.valueOf(end));
    }
  }