|
|||||||||||||||||||
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 | |||||||||||||||
LetToken.java | 75% | 92.3% | 100% | 89.5% |
|
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.script;
|
|
16 |
|
|
17 |
import java.util.Map;
|
|
18 |
|
|
19 |
import org.apache.hivemind.Location;
|
|
20 |
|
|
21 |
/**
|
|
22 |
* Allows for the creation of new symbols that can be used in the script
|
|
23 |
* or returned to the caller.
|
|
24 |
*
|
|
25 |
* <p>The <let> tag wraps around static text and <insert>
|
|
26 |
* elements. The results are trimmed.
|
|
27 |
*
|
|
28 |
* @author Howard Lewis Ship
|
|
29 |
* @since 0.2.9
|
|
30 |
*
|
|
31 |
**/
|
|
32 |
|
|
33 |
class LetToken extends AbstractToken |
|
34 |
{ |
|
35 |
private String _key;
|
|
36 |
private boolean _unique; |
|
37 |
private int _bufferLengthHighwater = 20; |
|
38 |
|
|
39 | 13 |
public LetToken(String key, boolean unique, Location location) |
40 |
{ |
|
41 | 13 |
super(location);
|
42 |
|
|
43 | 13 |
_key = key; |
44 | 13 |
_unique = unique; |
45 |
} |
|
46 |
|
|
47 | 15 |
public void write(StringBuffer buffer, ScriptSession session) |
48 |
{ |
|
49 | 15 |
if (buffer != null) |
50 | 0 |
throw new IllegalArgumentException(); |
51 |
|
|
52 | 15 |
buffer = new StringBuffer(_bufferLengthHighwater);
|
53 |
|
|
54 | 15 |
writeChildren(buffer, session); |
55 |
|
|
56 |
// Store the symbol back into the root set of symbols.
|
|
57 |
|
|
58 | 15 |
Map symbols = session.getSymbols(); |
59 |
|
|
60 | 15 |
String value = buffer.toString().trim(); |
61 |
|
|
62 | 15 |
if (_unique)
|
63 | 7 |
value = session.getUniqueString(value); |
64 |
|
|
65 | 15 |
symbols.put(_key, value); |
66 |
|
|
67 |
// Store the buffer length from this run for the next run, since its
|
|
68 |
// going to be approximately the right size.
|
|
69 |
|
|
70 | 15 |
_bufferLengthHighwater = Math.max(_bufferLengthHighwater, buffer.length()); |
71 |
} |
|
72 |
} |
|