Ejemplo n.º 1
0
  public static List<SelectItem> createSelectItems(UIComponent component) {
    List<SelectItem> items = new ArrayList<SelectItem>();
    Iterator<UIComponent> children = component.getChildren().iterator();

    while (children.hasNext()) {
      UIComponent child = children.next();

      if (child instanceof UISelectItem) {
        UISelectItem selectItem = (UISelectItem) child;

        items.add(new SelectItem(selectItem.getItemValue(), selectItem.getItemLabel()));
      } else if (child instanceof UISelectItems) {
        Object selectItems = ((UISelectItems) child).getValue();

        if (selectItems instanceof SelectItem[]) {
          SelectItem[] itemsArray = (SelectItem[]) selectItems;

          for (SelectItem item : itemsArray)
            items.add(new SelectItem(item.getValue(), item.getLabel()));

        } else if (selectItems instanceof Collection) {
          Collection<SelectItem> collection = (Collection<SelectItem>) selectItems;

          for (SelectItem item : collection)
            items.add(new SelectItem(item.getValue(), item.getLabel()));
        }
      }
    }

    return items;
  }
Ejemplo n.º 2
0
 public int compare(Object o1, Object o2) {
   SelectItem i1 = (SelectItem) o1;
   SelectItem i2 = (SelectItem) o2;
   RuleBasedCollator collator_ini = (RuleBasedCollator) Collator.getInstance();
   try {
     RuleBasedCollator collator =
         new RuleBasedCollator(collator_ini.getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
     return collator.compare(i1.getLabel(), i2.getLabel());
   } catch (ParseException e) {
   }
   return Collator.getInstance().compare(i1.getLabel(), i2.getLabel());
 }
  protected void encodeOption(
      FacesContext context,
      SelectCheckboxMenu menu,
      Object values,
      Object submittedValues,
      Converter converter,
      SelectItem option,
      int idx)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String itemValueAsString = getOptionAsString(context, menu, converter, option.getValue());
    String name = menu.getClientId(context);
    String id = name + UINamingContainer.getSeparatorChar(context) + idx;
    boolean disabled = option.isDisabled() || menu.isDisabled();

    Object valuesArray;
    Object itemValue;
    if (submittedValues != null) {
      valuesArray = submittedValues;
      itemValue = itemValueAsString;
    } else {
      valuesArray = values;
      itemValue = option.getValue();
    }

    boolean checked = isSelected(context, menu, itemValue, valuesArray, converter);
    if (option.isNoSelectionOption() && values != null && !checked) {
      return;
    }

    // input
    writer.startElement("input", null);
    writer.writeAttribute("id", id, null);
    writer.writeAttribute("name", name, null);
    writer.writeAttribute("type", "checkbox", null);
    writer.writeAttribute("value", itemValueAsString, null);

    if (checked) writer.writeAttribute("checked", "checked", null);
    if (disabled) writer.writeAttribute("disabled", "disabled", null);
    if (menu.getOnchange() != null) writer.writeAttribute("onchange", menu.getOnchange(), null);

    writer.endElement("input");

    // label
    writer.startElement("label", null);
    writer.writeAttribute("for", id, null);
    if (disabled) writer.writeAttribute("class", "ui-state-disabled", null);

    if (option.isEscape()) writer.writeText(option.getLabel(), null);
    else writer.write(option.getLabel());

    writer.endElement("label");
  }
Ejemplo n.º 4
0
 public static String getLabelByValueOnSelectItems(Object value, List<SelectItem> list) {
   for (SelectItem item : list) {
     if (item.getValue().equals(value)) {
       return item.getLabel();
     }
   }
   return null;
 }
 /**
  * Return the label of the language
  *
  * @param lang
  * @return
  */
 public String getLanguageLabel(String lang) {
   for (SelectItem iso : isolanguages) {
     if (((String) iso.getValue()).equals(lang)) {
       return iso.getLabel();
     }
   }
   return lang;
 }
  private String getTablePassword(String tableName) {
    String tablePass = "";

    for (Iterator iter = getViewIconTablesManagedBean().getIconTableNameList().iterator();
        iter.hasNext(); ) {
      SelectItem element = (SelectItem) iter.next();
      // if we have a match
      if (((String) element.getValue()).equalsIgnoreCase(tableName)) {
        tablePass = element.getDescription();
        getViewIconTablesManagedBean().setSelectedTableName(element.getLabel());
        logger.info("Table Name: " + element.getLabel());
        break;
      }
    }

    logger.info("In getTablePassword() -- Table Pass: " + tablePass);
    return tablePass;
  }
Ejemplo n.º 7
0
  @SuppressWarnings("rawtypes")
  @Test
  public void metodo1() throws IllegalArgumentException, Exception {
    this.scanningProvider = new ClassPathScanningCandidateComponentProvider(false);
    this.scanningProvider.addIncludeFilter(
        new AnnotationTypeFilter(javax.persistence.Entity.class));

    List<Class<? extends Object>> classes = new ArrayList<Class<? extends Object>>();
    for (BeanDefinition beanDef : this.scanningProvider.findCandidateComponents("br.com")) {
      classes.add(Class.forName(beanDef.getBeanClassName()));
    }

    CLAZZ:
    for (Class clazz : classes) {

      Field listaCampo[] = clazz.getDeclaredFields();
      for (Field campo : listaCampo) {
        if (campo.getName().trim().equalsIgnoreCase("id")) {

          for (Annotation anotacao : campo.getAnnotations()) {
            if (anotacao.toString().contains("sequenceName")) {
              String array[] = anotacao.toString().split(",");
              String sequence = "";
              for (String item : array) {
                if (item.contains("sequenceName")) {
                  sequence = item.replace("sequenceName=", "");
                  break;
                }
              }
              if (sequence != null && !sequence.equals("")) {
                // Descobre o maior id do banco
                Integer ultimoId = dao.max(clazz);
                if (ultimoId == null) {
                  ultimoId = 1;
                }
                Session session = dao.getCurrentSession();

                String sql = "SELECT setval('SISFIE." + sequence.trim() + "', " + ultimoId + ");";

                if (duplicadas.contains(sequence.trim())) {
                  throw new IllegalArgumentException();
                }
                duplicadas.add(sequence.trim());
                session.createSQLQuery(sql).uniqueResult();
                sequences.add(new SelectItem(ultimoId, sequence.trim()));
                continue CLAZZ;
              }
            }
          }
        }
      }
    }
    System.out.println("Total :" + sequences.size());
    for (SelectItem item : sequences) {
      System.out.println(item.getLabel() + ": " + item.getValue());
    }
  }
Ejemplo n.º 8
0
 /**
  * Inserts the SelectItem _si representing a project into the list used by the combo
  *
  * @param _projectsList the projectsList
  * @param _si the SelectItem
  */
 private void addSelectItemToList(List<SelectItem> _projectsList, SelectItem _si) {
   if (_projectsList.size() == 0) _projectsList.add(_si);
   else {
     int i;
     // inserting the project in an alphabetically ordered list
     for (i = 0;
         i < _projectsList.size() && _si.getLabel().compareTo(_projectsList.get(i).getLabel()) > 0;
         i++) {}
     _projectsList.add(i, _si);
   }
 }
Ejemplo n.º 9
0
  @Test
  public void shouldSupportMap() throws Exception {
    Map<Object, Object> map = new LinkedHashMap<Object, Object>();
    map.put("ka", "va");
    map.put(null, "vb");
    map.put("c", null);
    Iterator<SelectItem> iterator = newSelectItemsIterator(map);
    SelectItem a = iterator.next();
    SelectItem b = iterator.next();
    SelectItem c = iterator.next();
    assertFalse(iterator.hasNext());

    assertThat(a.getLabel(), is("ka"));
    assertThat(a.getValue(), is((Object) "va"));

    assertThat(b.getLabel(), is("vb"));
    assertThat(b.getValue(), is((Object) "vb"));

    assertThat(c.getLabel(), is("c"));
    assertThat(c.getValue(), is((Object) ""));
  }
  protected void encodeOption(
      FacesContext context,
      SelectOneListbox listbox,
      SelectItem option,
      Object values,
      Object submittedValues,
      Converter converter)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String itemValueAsString = getOptionAsString(context, listbox, converter, option.getValue());
    boolean disabled = option.isDisabled() || listbox.isDisabled();

    Object valuesArray;
    Object itemValue;
    if (submittedValues != null) {
      valuesArray = submittedValues;
      itemValue = itemValueAsString;
    } else {
      valuesArray = values;
      itemValue = option.getValue();
    }

    boolean selected = isSelected(context, listbox, itemValue, valuesArray, converter);
    if (option.isNoSelectionOption() && values != null && !selected) {
      return;
    }

    writer.startElement("option", null);
    writer.writeAttribute("value", itemValueAsString, null);
    if (disabled) writer.writeAttribute("disabled", "disabled", null);
    if (selected) writer.writeAttribute("selected", "selected", null);

    if (option.isEscape()) {
      writer.writeText(option.getLabel(), null);
    } else {
      writer.write(option.getLabel());
    }

    writer.endElement("option");
  }
 /**
  * Menu with first, the supported languages out of the properties, second all the iso languages
  *
  * @param SUPPORTED_LANGUAGES
  */
 public void initLanguagesMenu() {
   // Add first languages out of properties
   languages = new ArrayList<SelectItem>();
   languages.addAll(getsupportedLanguages(true));
   // add a separator
   // languages.add(new SelectItem(null, "--"));
   // Add the other languages (non supported)
   // languages.addAll(getsupportedLanguages(false));
   // init the string of all languages
   languagesAsString = "";
   for (SelectItem s : languages) {
     languagesAsString += s.getValue() + "," + s.getLabel() + "|";
   }
 }
  protected void renderSelectItems(
      FacesContext context,
      UIComponent component,
      ResponseWriter writer,
      Iterator it,
      String[] selectedValues)
      throws IOException {

    while (it.hasNext()) {
      final SelectItem selectItem = (SelectItem) it.next();

      if (selectItem instanceof SelectItemGroup) {
        SelectItemGroup selectItemGroup = (SelectItemGroup) selectItem;
        SelectItem[] selectItems = selectItemGroup.getSelectItems();
        Iterator selectItemsIt = new ArrayIterator(selectItems);
        writer.startElement(JsfConstants.OPTGROUP_ELEM, component);
        RendererUtil.renderAttribute(writer, JsfConstants.LABEL_ATTR, selectItemGroup.getLabel());
        // TODO case: optgroup is disabled
        renderSelectItems(context, component, writer, selectItemsIt, selectedValues);
        writer.endElement(JsfConstants.OPTGROUP_ELEM);
      } else {
        writer.startElement(JsfConstants.OPTION_ELEM, component);
        final Object value = selectItem.getValue();
        RendererUtil.renderAttribute(writer, JsfConstants.VALUE_ATTR, value);

        final boolean disabled = UIComponentUtil.isDisabled(component) || selectItem.isDisabled();
        final String labelClass = getLabelStyleClass(component, disabled);
        if (labelClass != null) {
          RendererUtil.renderAttribute(writer, JsfConstants.CLASS_ATTR, labelClass);
        }
        if (value != null && isSelected(selectedValues, value.toString())) {
          renderSelectedAttribute(writer);
        }
        if (selectItem.isDisabled()) {
          renderDisabledAttribute(writer);
        }
        writer.writeText(selectItem.getLabel(), null);
        writer.endElement(JsfConstants.OPTION_ELEM);
      }
    }
  }
Ejemplo n.º 13
0
  protected void encodeFilter(FacesContext context, DataTable table, UIColumn column)
      throws IOException {
    Map<String, String> params = context.getExternalContext().getRequestParameterMap();
    ResponseWriter writer = context.getResponseWriter();
    String separator = String.valueOf(UINamingContainer.getSeparatorChar(context));

    String filterId = column.getContainerClientId(context) + separator + "filter";
    String filterStyleClass = column.getFilterStyleClass();

    String filterValue = null;
    if (table.isReset()) {
      filterValue = "";
    } else {
      if (params.containsKey(filterId)) {
        filterValue = params.get(filterId);
      } else {
        ValueExpression filterValueVE = column.getValueExpression("filterValue");
        if (filterValueVE != null) {
          filterValue = (String) filterValueVE.getValue(context.getELContext());
        } else {
          filterValue = "";
        }
      }
    }

    if (column.getValueExpression("filterOptions") == null) {
      filterStyleClass =
          filterStyleClass == null
              ? DataTable.COLUMN_INPUT_FILTER_CLASS
              : DataTable.COLUMN_INPUT_FILTER_CLASS + " " + filterStyleClass;

      writer.startElement("input", null);
      writer.writeAttribute("id", filterId, null);
      writer.writeAttribute("name", filterId, null);
      writer.writeAttribute("class", filterStyleClass, null);
      writer.writeAttribute("value", filterValue, null);
      writer.writeAttribute("autocomplete", "off", null);

      if (column.getFilterStyle() != null)
        writer.writeAttribute("style", column.getFilterStyle(), null);

      if (column.getFilterMaxLength() != Integer.MAX_VALUE)
        writer.writeAttribute("maxlength", column.getFilterMaxLength(), null);

      writer.endElement("input");
    } else {
      filterStyleClass =
          filterStyleClass == null
              ? DataTable.COLUMN_FILTER_CLASS
              : DataTable.COLUMN_FILTER_CLASS + " " + filterStyleClass;

      writer.startElement("select", null);
      writer.writeAttribute("id", filterId, null);
      writer.writeAttribute("name", filterId, null);
      writer.writeAttribute("class", filterStyleClass, null);

      SelectItem[] itemsArray = (SelectItem[]) getFilterOptions(column);

      for (SelectItem item : itemsArray) {
        Object itemValue = item.getValue();

        writer.startElement("option", null);
        writer.writeAttribute("value", item.getValue(), null);
        if (itemValue != null && String.valueOf(itemValue).equals(filterValue)) {
          writer.writeAttribute("selected", "selected", null);
        }
        writer.writeText(item.getLabel(), null);
        writer.endElement("option");
      }

      writer.endElement("select");
    }
  }
  protected void encodeItem(
      FacesContext context,
      SelectOneListbox listbox,
      SelectItem option,
      Object values,
      Object submittedValues,
      Converter converter,
      boolean customContent)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String itemValueAsString = getOptionAsString(context, listbox, converter, option.getValue());
    boolean disabled = option.isDisabled() || listbox.isDisabled();
    String itemClass =
        disabled ? SelectOneListbox.ITEM_CLASS + " ui-state-disabled" : SelectOneListbox.ITEM_CLASS;

    Object valuesArray;
    Object itemValue;
    if (submittedValues != null) {
      valuesArray = submittedValues;
      itemValue = itemValueAsString;
    } else {
      valuesArray = values;
      itemValue = option.getValue();
    }

    boolean selected = isSelected(context, listbox, itemValue, valuesArray, converter);
    if (option.isNoSelectionOption() && values != null && !selected) {
      return;
    }

    if (selected) {
      itemClass = itemClass + " ui-state-highlight";
    }

    if (customContent) {
      String var = listbox.getVar();
      context.getExternalContext().getRequestMap().put(var, option.getValue());

      writer.startElement("tr", null);
      writer.writeAttribute("class", itemClass, null);
      if (option.getDescription() != null) {
        writer.writeAttribute("title", option.getDescription(), null);
      }

      for (UIComponent child : listbox.getChildren()) {
        if (child instanceof Column && child.isRendered()) {
          writer.startElement("td", null);
          renderChildren(context, child);
          writer.endElement("td");
        }
      }

      writer.endElement("tr");
    } else {
      writer.startElement("li", null);
      writer.writeAttribute("class", itemClass, null);
      if (option.isEscape()) {
        writer.writeText(option.getLabel(), null);
      } else {
        writer.write(option.getLabel());
      }

      writer.endElement("li");
    }
  }
Ejemplo n.º 15
0
  private void initialize() {

    this.setWspServiceEndPoint("http://<wsp-host-name:portnumber>/<webService>");
    this.setWspSecurityMechanisms(
        new Integer[] {
          SecurityMechanism.SAML2_HOK.toInt(),
          SecurityMechanism.SAML2_SV.toInt(),
          SecurityMechanism.USERNAME_TOKEN.toInt(),
          SecurityMechanism.X509_TOKEN.toInt()
        });
    this.setWspAuthenticationChain(null);

    this.setResponseSigned(false);
    this.setResponseEncrypted(false);
    this.setRequestSignatureVerified(true);
    this.setRequestHeaderDecrypted(false);
    this.setRequestDecrypted(false);

    this.setWscServiceName("WebServiceName");
    this.setWscSecurityMechanism(SecurityMechanism.STS_SECURITY.toInt());
    this.setConfigureWsc(false);

    this.setEncryptionAlgorithm(EncryptionAlgorithm.AES_256.toInt());
    this.setUserNameTokenUserName(null);
    this.setUserNameTokenPassword(null);
    this.setX509TokenSigningReferenceType(X509SigningRefType.DIRECT.toInt());
    this.setKerberosDomain(null);
    this.setKerberosDomainServer(null);
    this.setKerberosServicePrincipal(null);
    this.setKerberosTicketCache(null);

    List<SelectItem> stsConfigs = this.getStsConfigurationNameList();
    if (stsConfigs.size() == 1) {
      SelectItem stsConfig = stsConfigs.iterator().next();
      this.setStsConfigurationName((String) stsConfig.getValue());
    } else {
      this.setStsConfigurationName(null);
    }

    List<SelectItem> aliases = this.getPrivateKeyAliasList();
    if (aliases.size() == 1) {
      SelectItem alias = aliases.iterator().next();
      this.setPrivateKeyAlias(alias.getLabel());
    } else {
      this.setPrivateKeyAlias(null);
    }

    aliases = this.getPublicKeyAliasList();
    if (aliases.size() == 1) {
      SelectItem alias = aliases.iterator().next();
      this.setPublicKeyAlias(alias.getLabel());
    } else {
      this.setPublicKeyAlias(null);
    }

    this.setSummaryRealm(new WssCreateWizardSummaryRealm(this));
    this.setSummaryServiceEndPoint(new WssCreateWizardSummaryServiceEndPoint(this));
    this.setSummaryWspSecurity(new WssCreateWizardSummaryWspSecurity(this));
    this.setSummaryServiceName(new WssCreateWizardSummaryServiceName(this));
    this.setSummaryWscSecurity(new WssCreateWizardSummaryWscSecurity(this));
    this.setSummarySignEncrypt(new WssCreateWizardSummarySignEncrypt(this));
    this.setSummaryKeyAliases(new WssCreateWizardSummaryKeyAliases(this));
    this.setSummaryEncryptAlgorithm(new WssCreateWizardSummaryEncryptAlgorithm(this));
  }