|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ValuePart.java | 100% | 100% | 100% | 100% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.tapestry.multipart;
|
|
16 |
|
|
17 |
import java.util.ArrayList;
|
|
18 |
import java.util.List;
|
|
19 |
|
|
20 |
/**
|
|
21 |
* A portion of a multipart request that stores a value, or values, for
|
|
22 |
* a parameter.
|
|
23 |
*
|
|
24 |
* @author Howard Lewis Ship
|
|
25 |
* @since 2.0.1
|
|
26 |
*
|
|
27 |
**/
|
|
28 |
|
|
29 |
public class ValuePart implements IPart |
|
30 |
{ |
|
31 |
private int _count; |
|
32 |
// Stores either String or List of String
|
|
33 |
private Object _value;
|
|
34 |
|
|
35 | 32 |
public ValuePart(String value)
|
36 |
{ |
|
37 | 32 |
_count = 1; |
38 | 32 |
_value = value; |
39 |
} |
|
40 |
|
|
41 | 2 |
public int getCount() |
42 |
{ |
|
43 | 2 |
return _count;
|
44 |
} |
|
45 |
|
|
46 |
/**
|
|
47 |
* Returns the value, or the first value (if multi-valued).
|
|
48 |
*
|
|
49 |
**/
|
|
50 |
|
|
51 | 2 |
public String getValue()
|
52 |
{ |
|
53 | 2 |
if (_count == 1)
|
54 | 1 |
return (String) _value;
|
55 |
|
|
56 | 1 |
List l = (List) _value; |
57 |
|
|
58 | 1 |
return (String) l.get(0);
|
59 |
} |
|
60 |
|
|
61 |
/**
|
|
62 |
* Returns the values as an array of strings. If there is only one value,
|
|
63 |
* it is returned wrapped as a single element array.
|
|
64 |
*
|
|
65 |
**/
|
|
66 |
|
|
67 | 33 |
public String[] getValues()
|
68 |
{ |
|
69 | 33 |
if (_count == 1)
|
70 | 29 |
return new String[] {(String) _value }; |
71 |
|
|
72 | 4 |
List l = (List) _value; |
73 |
|
|
74 | 4 |
return (String[]) l.toArray(new String[_count]); |
75 |
} |
|
76 |
|
|
77 | 4 |
public void add(String newValue) |
78 |
{ |
|
79 | 4 |
if (_count == 1)
|
80 |
{ |
|
81 | 3 |
List l = new ArrayList();
|
82 | 3 |
l.add(_value); |
83 | 3 |
l.add(newValue); |
84 |
|
|
85 | 3 |
_value = l; |
86 | 3 |
_count++; |
87 | 3 |
return;
|
88 |
} |
|
89 |
|
|
90 | 1 |
List l = (List) _value; |
91 | 1 |
l.add(newValue); |
92 | 1 |
_count++; |
93 |
} |
|
94 |
|
|
95 |
/**
|
|
96 |
* Does nothing.
|
|
97 |
*
|
|
98 |
**/
|
|
99 |
|
|
100 | 29 |
public void cleanup() |
101 |
{ |
|
102 |
} |
|
103 |
} |
|