コード例 #1
0
    /**
     * This gets called whenever one of the ConfigElements we are editing adds a new property value.
     */
    public void propertyValueAdded(ConfigElementEvent evt) {
      ConfigElement src = (ConfigElement) evt.getSource();
      int idx = evt.getIndex();
      PropertyDefinition prop_def = src.getDefinition().getPropertyDefinition(evt.getProperty());
      DefaultMutableTreeNode elt_node = getNodeFor(src);

      // Get the node containing the property description under the source
      // ConfigElement node
      for (Enumeration e = elt_node.children(); e.hasMoreElements(); ) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
        if (node.getUserObject().equals(prop_def)) {
          // The newly inserted property value must be added as a child to
          // this node
          if (prop_def.getType() != ConfigElement.class) {
            DefaultMutableTreeNode new_child = new DefaultMutableTreeNode(evt.getValue());
            insertNodeInto(new_child, node, idx);
          } else {
            // Embedded elements are handled specially in that all of their
            // respective child properties and such also need to be added to
            // the tree at this time.
            addEmbeddedElement(node, (ConfigElement) evt.getValue(), idx);
          }
        }
      }
    }
コード例 #2
0
 public String getDeprecatedKey(String key) {
   PropertyDefinition def = get(key);
   if (def == null) {
     return null;
   }
   return StringUtils.defaultIfEmpty(def.deprecatedKey(), null);
 }
コード例 #3
0
  @Test
  public void getTemplatePropertyDefinitions() throws Exception {
    HashSet<String> props = new HashSet<String>();

    deployVdb();

    Collection<? extends PropertyDefinition> pds = admin.getTemplatePropertyDefinitions("h2");
    for (PropertyDefinition pd : pds) {
      props.add(pd.getName());
    }
    assertTrue(props.contains("connection-url"));
    assertTrue(props.contains("user-name"));
    assertTrue(props.contains("password"));
    assertTrue(props.contains("check-valid-connection-sql"));
    assertTrue(props.contains("max-pool-size"));
    assertTrue(props.contains("connection-properties"));
    assertTrue(props.contains("max-pool-size"));

    HashSet<String> rar_props = new HashSet<String>();
    pds = admin.getTemplatePropertyDefinitions("file");
    for (PropertyDefinition pd : pds) {
      rar_props.add(pd.getName());
    }

    assertTrue(rar_props.contains("ParentDirectory"));
    assertTrue(rar_props.contains("FileMapping"));
    assertTrue(rar_props.contains("AllowParentPaths"));
    assertTrue(rar_props.contains("resourceadapter-class"));
    assertTrue(rar_props.contains("managedconnectionfactory-class"));
    assertTrue(rar_props.contains("max-pool-size"));
  }
コード例 #4
0
  /**
   * If propertyDefinition.order is <= 0 or > Map.size() it will be set to the current number of
   * propDefs for the map (placing it at the end). Otherwise, it will be inserted, incrementing the
   * order of existing Map entries.
   *
   * @param propertyDefinition
   */
  public void put(PropertyDefinition propertyDefinition) {
    Map<String, PropertyDefinition> map = getMap();

    if (map.isEmpty()) {
      propertyDefinition.setOrder(0);

    } else {
      int order = propertyDefinition.getOrder();
      int size = map.size();

      if ((order <= 0) || (order >= size)) {
        propertyDefinition.setOrder(size);

      } else {
        // insert into existing ordering by bumping up existing entries
        for (PropertyDefinition p : map.values()) {
          if (p.getOrder() >= order) {
            p.setOrder(p.getOrder() + 1);
          }
        }
      }
    }

    map.put(propertyDefinition.getName(), propertyDefinition);
    propertyDefinition.setParentPropertyMapDefinition(this);
  }
コード例 #5
0
ファイル: Settings.java プロジェクト: jamesbjackson/sonarqube
  /**
   * Value is split by comma and trimmed. Never returns null.
   *
   * <p>Examples :
   *
   * <ul>
   *   <li>"one,two,three " -> ["one", "two", "three"]
   *   <li>" one, two, three " -> ["one", "two", "three"]
   *   <li>"one, , three" -> ["one", "", "three"]
   * </ul>
   */
  public String[] getStringArray(String key) {
    PropertyDefinition property = getDefinitions().get(key);
    if ((null != property) && (property.multiValues())) {
      String value = getString(key);
      if (value == null) {
        return ArrayUtils.EMPTY_STRING_ARRAY;
      }

      List<String> values = new ArrayList<>();
      for (String v : Splitter.on(",").trimResults().split(value)) {
        values.add(v.replace("%2C", ","));
      }
      return values.toArray(new String[values.size()]);
    }

    return getStringArrayBySeparator(key, ",");
  }
コード例 #6
0
  /**
   * Convenience routine to get only the summary property definitions.
   *
   * @return the summary property definitions. If no property definitions were defined as summary
   *     properties in the plugin descriptor, all property definitions will be returned. The
   *     property definitions will be sorted by PropertyDefinition.order, ascending. Min(order) is
   *     0.
   */
  @NotNull
  public List<PropertyDefinition> getSummaryPropertyDefinitions() {
    List<PropertyDefinition> result = new ArrayList<PropertyDefinition>();
    Collection<PropertyDefinition> propDefs = getOrderedPropertyDefinitions();

    for (PropertyDefinition pd : propDefs) {
      if (pd.isSummary()) {
        result.add(pd);
      }
    }

    if (result.isEmpty()) {
      result.addAll(propDefs);
    }

    return result;
  }
コード例 #7
0
    /**
     * This gets called whenever one of the ConfigElements we are editing has the values of a
     * property get reordered.
     */
    public void propertyValueOrderChanged(ConfigElementEvent evt) {
      ConfigElement src = (ConfigElement) evt.getSource();
      int idx = evt.getIndex();
      PropertyDefinition prop_def = src.getDefinition().getPropertyDefinition(evt.getProperty());
      DefaultMutableTreeNode elt_node = getNodeFor(src);

      // Get the node containing the property description under the source
      // ConfigElement node.
      for (Enumeration e = elt_node.children(); e.hasMoreElements(); ) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();

        if (node.getUserObject().equals(prop_def)) {
          int start_index = Math.min(evt.getIndex0(), evt.getIndex1());
          int end_index = Math.max(evt.getIndex0(), evt.getIndex1());

          List removed_children = new ArrayList();
          for (int c = start_index; c <= end_index; ++c) {
            removed_children.add(getChild(node, c));
          }

          for (Iterator c = removed_children.iterator(); c.hasNext(); ) {
            removeNodeFromParent((MutableTreeNode) c.next());
          }

          String prop_token = prop_def.getToken();
          for (int v = start_index; v <= end_index; ++v) {
            if (prop_def.getType() != ConfigElement.class) {
              // Create a new node for the reordered property value.
              DefaultMutableTreeNode new_node =
                  new DefaultMutableTreeNode(src.getProperty(prop_token, v));

              // Add the new node into the tree.
              insertNodeInto(new_node, node, v);
            } else {
              // Embedded elements are handled specially in that all of
              // their respective child properties and such also need to
              // be added to the tree at this time.
              ConfigElement cur_value = (ConfigElement) src.getProperty(prop_token, v);
              addEmbeddedElement(node, cur_value, v);
            }
          }
        }
      }
    }
コード例 #8
0
  /** @since 3.7 */
  public Map<Category, Map<SubCategory, Collection<PropertyDefinition>>> propertiesByCategory(
      @Nullable String qualifier) {
    Map<Category, Map<SubCategory, Collection<PropertyDefinition>>> byCategory =
        new HashMap<Category, Map<SubCategory, Collection<PropertyDefinition>>>();
    if (qualifier == null) {
      // Special categories on global page
      Map<SubCategory, Collection<PropertyDefinition>> emailSubCategories =
          new HashMap<SubCategory, Collection<PropertyDefinition>>();
      emailSubCategories.put(new SubCategory("email", true), new ArrayList<PropertyDefinition>());
      byCategory.put(new Category(CoreProperties.CATEGORY_GENERAL, false), emailSubCategories);

      HashMap<SubCategory, Collection<PropertyDefinition>> licenseSubCategories =
          new HashMap<SubCategory, Collection<PropertyDefinition>>();
      licenseSubCategories.put(
          new SubCategory("server_id", true), new ArrayList<PropertyDefinition>());
      byCategory.put(new Category(CoreProperties.CATEGORY_LICENSES, false), licenseSubCategories);

      HashMap<SubCategory, Collection<PropertyDefinition>> encryptionSubCategories =
          new HashMap<SubCategory, Collection<PropertyDefinition>>();
      encryptionSubCategories.put(
          new SubCategory("encryption", true), new ArrayList<PropertyDefinition>());
      byCategory.put(
          new Category(CoreProperties.CATEGORY_SECURITY, false), encryptionSubCategories);
    }
    for (PropertyDefinition definition : getAll()) {
      if (qualifier == null ? definition.global() : definition.qualifiers().contains(qualifier)) {
        Category category = categories.get(definition.key());
        if (!byCategory.containsKey(category)) {
          byCategory.put(category, new HashMap<SubCategory, Collection<PropertyDefinition>>());
        }
        SubCategory subCategory = subcategories.get(definition.key());
        if (!byCategory.get(category).containsKey(subCategory)) {
          byCategory.get(category).put(subCategory, new ArrayList<PropertyDefinition>());
        }
        byCategory.get(category).get(subCategory).add(definition);
      }
    }
    return byCategory;
  }
コード例 #9
0
ファイル: Settings.java プロジェクト: jamesbjackson/sonarqube
  public Settings setProperty(String key, @Nullable String[] values) {
    PropertyDefinition property = getDefinitions().get(key);
    if ((null == property) || (!property.multiValues())) {
      throw new IllegalStateException(
          "Fail to set multiple values on a single value property " + key);
    }

    String text = null;
    if (values != null) {
      List<String> escaped = new ArrayList<>();
      for (String value : values) {
        if (null != value) {
          escaped.add(value.replace(",", "%2C"));
        } else {
          escaped.add("");
        }
      }

      String escapedValue = Joiner.on(',').join(escaped);
      text = StringUtils.trim(escapedValue);
    }
    return setProperty(key, text);
  }
コード例 #10
0
    /**
     * This gets called whenever one of the ConfigElements we are editing has one of its property
     * values change.
     */
    public void propertyValueChanged(ConfigElementEvent evt) {
      ConfigElement src = (ConfigElement) evt.getSource();
      int idx = evt.getIndex();
      PropertyDefinition prop_def = src.getDefinition().getPropertyDefinition(evt.getProperty());
      DefaultMutableTreeNode elt_node = getNodeFor(src);

      // Multi-valued properties and embedded elements are treated specially
      if ((prop_def.getPropertyValueDefinitionCount() > 1)
          || (prop_def.isVariable())
          || (prop_def.getType() == ConfigElement.class)) {
        // Look for the property definition node
        for (Enumeration e = elt_node.children(); e.hasMoreElements(); ) {
          DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
          if (node.getUserObject().equals(prop_def)) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(idx);
            fireTreeNodesChanged(
                this,
                new Object[] {getPathToRoot(node)},
                new int[] {node.getIndex(child)},
                new Object[] {child});
          }
        }
      }
      // Property value is not an embedded element
      else {
        // Take into account the extra two rows at the top of the table
        if (elt_node == getRoot()) {
          idx += 2;
        }

        fireTreeNodesChanged(
            this,
            new Object[] {getPathToRoot(elt_node)},
            new int[] {idx},
            new Object[] {elt_node.getChildAt(idx)});
      }
    }
コード例 #11
0
  /**
   * Adds the nodes necessary to display the property values for the given configuration element
   * described by the given property definition.
   */
  private void addProperty(ConfigElement elt, PropertyDefinition propDef) {
    DefaultMutableTreeNode parent = getNodeFor(elt);

    // This property has only one value, add it in
    if ((propDef.getPropertyValueDefinitionCount() == 1)
        && (!propDef.isVariable())
        && (propDef.getType() != ConfigElement.class)) {
      int idx = parent.getChildCount();
      //         System.out.println("Adding property node for single-valued property: "+
      //                            propDesc.getToken()+"["+idx+"]");
      Object value = elt.getProperty(propDef.getToken(), 0);
      DefaultMutableTreeNode value_node = new DefaultMutableTreeNode(value);
      insertNodeInto(value_node, parent, idx);
    }
    // This property has (or can have) more than one value, add a node that is
    // the parent for all its values.
    else {
      int idx = parent.getChildCount();
      //         System.out.println("Adding property node for multi-valued property: "+
      //                            propDesc.getToken()+"["+idx+"]");
      DefaultMutableTreeNode prop_def_node = new DefaultMutableTreeNode(propDef);
      insertNodeInto(prop_def_node, parent, idx);
      parent = prop_def_node;

      int num_props = elt.getPropertyValueCount(propDef.getToken());
      for (int i = 0; i < num_props; ++i) {
        Object value = elt.getProperty(propDef.getToken(), i);
        if (propDef.getType() != ConfigElement.class) {
          //               System.out.println("Adding property value:
          // "+propDesc.getToken()+"["+i+"]");
          DefaultMutableTreeNode child = new DefaultMutableTreeNode(value);
          int prop_idx = parent.getChildCount();
          insertNodeInto(child, parent, prop_idx);
        } else {
          addEmbeddedElement(parent, (ConfigElement) value, i);
        }
      }
    }
  }
コード例 #12
0
  /** Sets the value for the given node at the given column to the given value. */
  public void setValueAt(Object value, Object node, int col) {
    DefaultMutableTreeNode tree_node = (DefaultMutableTreeNode) node;
    Object node_value = tree_node.getUserObject();

    switch (col) {
        // Name (not supported)
      case 0:
        break;
        // Value
      case 1:
        DefaultMutableTreeNode parent_node = (DefaultMutableTreeNode) tree_node.getParent();

        // First child of root is always the element name
        if (parent_node == getRoot() && parent_node.getIndex((TreeNode) node) == 0) {
          ConfigElement elt = (ConfigElement) parent_node.getUserObject();
          elt.setName((String) value);
          tree_node.setUserObject(value);
        } else if (node_value instanceof PropertyDefinition) {
          // Hey, we're editing a property definition. If it's type is not a
          // configuration element, we're probably editing a summary list of
          // the valuesof the children.
          if (((PropertyDefinition) node_value).getType() != ConfigElement.class) {
            ConfigElement elt = (ConfigElement) parent_node.getUserObject();
            PropertyDefinition prop_def = (PropertyDefinition) node_value;
            StringTokenizer tokenizer = new StringTokenizer((String) value, ", ");
            int idx = 0;
            while (tokenizer.hasMoreTokens()) {
              String token = tokenizer.nextToken();

              // Make sure we don't overrun the property values
              if ((idx >= prop_def.getPropertyValueDefinitionCount()) && (!prop_def.isVariable())) {
                break;
              }

              // Convert the value to the appropriate type
              Object new_value = null;
              Class type = prop_def.getType();
              if (type == Boolean.class) {
                new_value = new Boolean(token);
              } else if (type == Integer.class) {
                new_value = new Integer(token);
              } else if (type == Float.class) {
                new_value = new Float(token);
              } else if (type == String.class) {
                new_value = new String(token);
              } else if (type == ConfigElementPointer.class) {
                new_value = new ConfigElementPointer(token);
              }

              setProperty(new_value, elt, prop_def.getToken(), idx);

              // Get the node for the current property value and update it
              if (idx < tree_node.getChildCount()) {
                DefaultMutableTreeNode child_node =
                    (DefaultMutableTreeNode) tree_node.getChildAt(idx);
                child_node.setUserObject(new_value);
              } else {
                // Insert the new property
                DefaultMutableTreeNode new_node = new DefaultMutableTreeNode(new_value);
                tree_node.add(new_node);
                fireTreeNodesInserted(
                    this,
                    new Object[] {getPathToRoot(tree_node)},
                    new int[] {tree_node.getIndex(new_node)},
                    new Object[] {new_node});
              }
              ++idx;
            }
          }
        } else {
          // Parent is a ConfigElement ... must be a single-valued property
          if (parent_node.getUserObject() instanceof ConfigElement) {
            ConfigElement elt = (ConfigElement) parent_node.getUserObject();
            int desc_idx = parent_node.getIndex(tree_node);

            // If the parent is the root, take into account the extra name
            // and type nodes
            if (parent_node == getRoot()) {
              desc_idx -= 2;
            }
            PropertyDefinition prop_def =
                (PropertyDefinition) elt.getDefinition().getPropertyDefinitions().get(desc_idx);
            setProperty(value, elt, prop_def.getToken(), 0);
            tree_node.setUserObject(value);
          } else {
            // Parent must be a PropertyDefinition
            PropertyDefinition prop_def = (PropertyDefinition) parent_node.getUserObject();
            int value_idx = parent_node.getIndex(tree_node);
            DefaultMutableTreeNode elt_node = (DefaultMutableTreeNode) parent_node.getParent();
            ConfigElement elt = (ConfigElement) elt_node.getUserObject();
            setProperty(value, elt, prop_def.getToken(), value_idx);
            tree_node.setUserObject(value);
          }
        }
        fireTreeNodesChanged(
            this,
            new Object[] {getPathToRoot(parent_node)},
            new int[] {parent_node.getIndex(tree_node)},
            new Object[] {tree_node});
        break;
      default:
        throw new IllegalArgumentException("Invalid column: " + col);
    }
  }
コード例 #13
0
 private PropertyDefinitions add(PropertyDefinition definition, String defaultCategory) {
   if (!definitions.containsKey(definition.key())) {
     definitions.put(definition.key(), definition);
     String category = StringUtils.defaultIfBlank(definition.category(), defaultCategory);
     categories.put(definition.key(), new Category(category));
     String subcategory = StringUtils.defaultIfBlank(definition.subCategory(), category);
     subcategories.put(definition.key(), new SubCategory(subcategory));
     if (!Strings.isNullOrEmpty(definition.deprecatedKey())
         && !definition.deprecatedKey().equals(definition.key())) {
       deprecatedKeys.put(definition.deprecatedKey(), definition.key());
     }
   }
   return this;
 }
コード例 #14
0
 private PropertyDefinitions addProperty(Property property, String defaultCategory) {
   PropertyDefinition definition = PropertyDefinition.create(property);
   return add(definition, defaultCategory);
 }
コード例 #15
0
  @Test
  public void getTranslatorPropertyDefinitions() throws Exception {
    HashSet<String> props = new HashSet<String>();

    Collection<? extends PropertyDefinition> pds = admin.getTranslatorPropertyDefinitions("ws");
    for (PropertyDefinition pd : pds) {
      props.add(pd.getName());
    }
    assertTrue(props.contains("DefaultBinding"));
    assertTrue(props.contains("DefaultServiceMode"));
    assertTrue(props.contains("MaxDependentInPredicates"));

    for (PropertyDefinition pd : pds) {
      if (pd.getName().equals("DefaultBinding")) {
        assertEquals("java.lang.String", pd.getPropertyTypeClassName());
        assertFalse(pd.isRequired());
        assertEquals(
            "Contols what SOAP or HTTP type of invocation will be used if none is specified.",
            pd.getDescription());
        assertEquals("Default Binding", pd.getDisplayName());
        assertTrue(pd.isModifiable());
        assertFalse(pd.isAdvanced());
        assertFalse(pd.isMasked());
        assertEquals("SOAP12", pd.getDefaultValue());
        assertNotNull(pd.getAllowedValues());
      }
    }
  }