summaryrefslogtreecommitdiffstats
path: root/docs/manual/tasks/propertyselector.html
blob: 4e5102e13ab5e47941bd860798c25e62778207f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Ant-contrib Tasks: PropertySelector</title>
  </head>

  <body>
    <h1>PropertySelector</h1>

    <p>Selects property names that match a given regular expression and
       returns them in a delimited list</p>

    <h2>Parameters</h2>
    <table border="1" cellpadding="2" cellspacing="0">
      <tr>
        <th>Attribute</th>
        <th>Description</th>
        <th>Required</th>
      </tr>
      <tr>
        <td valign="top">property</td>
        <td valign="top">The name of the property you wish to set.</td>
        <td align="center" valign="top">Yes.</td>
      </tr>
      <tr>
        <td valign="top">override</td>
        <td valign="top">If the property is already set, should we change it's value.
            Can be <code>true</code> or <code>false</code></td>
        <td align="center" valign="top">No. Defaults to <code>false</code></td>
      </tr>
      <tr>
        <td valign="top">match</td>
        <td valign="top">The regular expression which is used to select
            property names for inclusion in the list.  This follows
            the standard regular expression syntax accepted by ant's
            regular expression tasks.</td>
        <td align="center" valign="top">Yes.</td>
      </tr>
      <tr>
        <td valign="top">select</td>
        <td valign="top">A pattern which indicates what selection pattern you want
            in the returned list.  This used the substitution pattern
            syntax to indicate where to insert groupings created as a result
            of the regular expression match.</td>
        <td align="center" valign="top">No. default is &quot;\0&quot;.</td>
      </tr>
      <tr>
        <td valign="top">casesensitive</td>
        <td valign="top">Should the match be case sensitive</td>
        <td align="center" valign="top">No. default is &quot;true&quot;.</td>
      </tr>
      <tr>
        <td valign="top">delimiter</td>
        <td valign="top">The delimiter used to seperate entries in the resulting
               property</td>
        <td align="center" valign="top">No. default is &quot;,&quot;.</td>
      </tr>
      <tr>
        <td valign="top">distinct</td>
        <td valign="top">Should the returned entries be a distinct set (no duplicate
               entries)</td>
        <td align="center" valign="top">No. default is &quot;false&quot;.</td>
      </tr>
    </table>

   <h2>Select expressions</h2>

   Expressions are selected in a the same syntax as a regular expression
   substitution pattern.

   <ul type="o">
    <li><code>\0</code> indicates the entire property name (default).
    <li><code>\1</code> indicates the first grouping
    <li><code>\2</code> indicates the second grouping
    <li>etc...
   </ul>

    <h2>Example</h2>

    The following code

    <pre>
    <code>
    &lt;property name="package.ABC.name" value="abc pack name" /&gt;
    &lt;property name="package.DEF.name" value="def pack name" /&gt;
    &lt;property name="package.GHI.name" value="ghi pack name" /&gt;
    &lt;property name="package.JKL.name" value="jkl pack name" /&gt;

    &lt;propertyselector property="pack.list"
                         delimiter=","
                         match="package\.([^\.]*)\.name"
                         select="\1"
                         casesensitive="false" /&gt;

    </code>
    </pre>

    would yield the results

    <pre>
    <code>
    ABC,DEF,GHI,JKL
    </code>
    </pre>

    You could then iterate through this list using the <a href="foreach.html"
    >ForEach Task</a> as follows:

    <pre>
    <code>
    &lt;foreach list="${pack.list}"
                delimiter=","
                target="print.name"
                param="pack.id" /&gt;

    &lt;target name="print.name" &gt;
      &lt;propertycopy name="pack.name" value="package.${pack.id}.name" /&gt;
      &lt;echo message="${pack.name}" /&gt;
    &lt;/target&gt;
    </code>
    </pre>

    Would print

    <pre>
    <code>
      [echo] abc pack name
      [echo] def pack name
      [echo] ghi pack name
      [echo] jkl pack name
    </code>
    </pre>

    <hr>
    <p align="center">Copyright &copy; 2003 Ant-Contrib Project. All
    rights Reserved.</p>

  </body>
</html>