コード例 #1
0
  public String buildOptions(
      ArrayList<Properties> ar, String selectValue, String selectText, boolean bSorted) {
    StringBuilder valret = new StringBuilder();
    Properties elmt = null;
    String selected;
    ArrayList<Properties> arToDisplay = ar;
    int i;

    if (selectText != null) {
      if ((selectValue == null) || (selectValue.length() <= 0)) {
        selected = "SELECTED";
      } else {
        selected = "";
      }
      valret
          .append("<option value=\"\" ")
          .append(selected)
          .append(">")
          .append(EncodeHelper.javaStringToHtmlString(selectText))
          .append("</option>\n");
    }
    if (bSorted) {
      Properties[] theList = ar.toArray(new Properties[ar.size()]);
      Arrays.sort(
          theList,
          new Comparator<Properties>() {

            @Override
            public int compare(Properties o1, Properties o2) {
              return o1.getProperty("name")
                  .toUpperCase()
                  .compareTo(o2.getProperty("name").toUpperCase());
            }
          });
      arToDisplay = new ArrayList<Properties>(theList.length);
      for (i = 0; i < theList.length; i++) {
        arToDisplay.add(theList[i]);
      }
    }
    if (arToDisplay != null) {
      for (i = 0; i < arToDisplay.size(); i++) {
        elmt = arToDisplay.get(i);
        if (elmt.getProperty("id").equalsIgnoreCase(selectValue)) {
          selected = "SELECTED";
        } else {
          selected = "";
        }
        valret
            .append("<option value=\"")
            .append(elmt.getProperty("id"))
            .append("\" ")
            .append(selected)
            .append(">")
            .append(EncodeHelper.javaStringToHtmlString(elmt.getProperty("name")))
            .append("</option>\n");
      }
    }
    return valret.toString();
  }
コード例 #2
0
  private String printBreadCrumb() {
    StringBuilder result = new StringBuilder();
    String information = getExtraInformation();
    String path = getPath();
    // print javascript to go to spaces in displayed path
    result.append(printScript());
    if (!StringUtil.isDefined(getSpaceJavascriptCallback())) {
      setSpaceJavascriptCallback("goSpace");
    }
    result.append("<div id=\"breadCrumb\">");

    boolean emptyBreadCrumb = true;

    // Display spaces path from root to component
    String language =
        (getMainSessionController() == null)
            ? ""
            : getMainSessionController().getFavoriteLanguage();
    if (StringUtil.isDefined(getComponentId()) || StringUtil.isDefined(getSpaceId())) {
      List<SpaceInst> spaces;

      OrganizationController organizationController =
          OrganizationControllerProvider.getOrganisationController();
      if (StringUtil.isDefined(getComponentId())) {
        spaces = organizationController.getSpacePathToComponent(getComponentId());
      } else {
        spaces = organizationController.getSpacePath(getSpaceId());
      }
      boolean firstSpace = true;
      for (SpaceInst spaceInst : spaces) {
        String spaceId = spaceInst.getId();
        if (!spaceId.startsWith("WA")) {
          spaceId = "WA" + spaceId;
        }
        String href = "javascript:" + getSpaceJavascriptCallback() + "('" + spaceId + "')";
        if (!isClickable()) {
          href = "#";
        }

        if (!firstSpace) {
          result.append(CONNECTOR);
        }
        result.append("<a href=\"").append(href).append("\"");
        result.append(" class=\"space\"");
        result.append(" id=\"space").append(spaceId).append("\"");
        result.append(">");
        result.append(Encode.forHtml(spaceInst.getName(language)));
        result.append("</a>");

        firstSpace = false;
        emptyBreadCrumb = false;
      }

      if (StringUtil.isDefined(getComponentId())) {
        // Display component's label
        ComponentInstLight componentInstLight =
            organizationController.getComponentInstLight(getComponentId());
        if (componentInstLight != null) {
          result.append(CONNECTOR);
          result.append("<a href=\"");
          if (!isClickable()) {
            result.append("#");
          } else if (StringUtil.isDefined(getComponentJavascriptCallback())) {
            result
                .append("javascript:")
                .append(getComponentJavascriptCallback())
                .append("('")
                .append(getComponentId())
                .append("')");
          } else {
            result
                .append(URLUtil.getApplicationURL())
                .append(URLUtil.getURL(getSpaceId(), getComponentId()));
            if (ignoreComponentLink()) {
              result.append("Main");
            } else {
              result.append(getComponentLink());
            }
          }
          result.append("\"");
          result.append(" class=\"component\"");
          result.append(" id=\"bc_").append(componentInstLight.getId()).append("\"");
          result.append(">");
          result.append(Encode.forHtml(componentInstLight.getLabel(language)));
          result.append("</a>");
          emptyBreadCrumb = false;
        }
      }
    } else {
      if (getDomainName() != null) {
        result.append(getDomainName());
        emptyBreadCrumb = false;
      }
      if (getComponentName() != null) {
        if (getDomainName() != null) {
          result.append(CONNECTOR);
        }
        if (getComponentLink() != null) {
          result
              .append("<a href=\"")
              .append(getComponentLink())
              .append("\">")
              .append(getComponentName())
              .append("</a>");
        } else {
          result.append(getComponentName());
        }
        emptyBreadCrumb = false;
      }
    }

    // Display path
    List<BrowseBarElement> elements = getElements();
    if (!elements.isEmpty()) {
      for (BrowseBarElement element : elements) {
        if (!emptyBreadCrumb) {
          result.append(CONNECTOR);
        }
        result.append("<a href=\"").append(element.getLink()).append("\"");
        result.append(" class=\"element\"");
        if (StringUtil.isDefined(element.getId())) {
          result.append(" id=\"").append(element.getId()).append("\"");
        }
        result.append(">");
        result.append(EncodeHelper.javaStringToHtmlString(element.getLabel()));
        result.append("</a>");
        emptyBreadCrumb = false;
      }
    } else if (StringUtil.isDefined(path)) {
      if (!emptyBreadCrumb) {
        result.append(CONNECTOR);
      }
      result.append("<span class=\"path\">");
      result.append(path);
      result.append("</span>");
    }

    // Display extra information
    if (StringUtil.isDefined(information)) {
      if (!emptyBreadCrumb) {
        result.append(CONNECTOR);
      }
      result.append("<span class=\"information\">");
      result.append(information);
      result.append("</span>");
    }

    result.append("</div>");

    return result.toString();
  }