1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.shared.renderkit.html.util;
20
21 import java.util.Map;
22 import javax.faces.context.FacesContext;
23
24
25
26
27
28 public class SharedStringBuilder
29 {
30 public static StringBuilder get(String stringBuilderKey)
31 {
32 return get(FacesContext.getCurrentInstance(), stringBuilderKey);
33 }
34
35
36 public static StringBuilder get(FacesContext facesContext, String stringBuilderKey)
37 {
38 Map<Object, Object> attributes = facesContext.getAttributes();
39
40 StringBuilder sb = (StringBuilder) attributes.get(stringBuilderKey);
41
42 if (sb == null)
43 {
44 sb = new StringBuilder();
45 attributes.put(stringBuilderKey, sb);
46 }
47 else
48 {
49
50
51 sb.setLength(0);
52 }
53
54 return sb;
55 }
56
57 public static StringBuilder get(FacesContext facesContext, String stringBuilderKey, int initialSize)
58 {
59 Map<Object, Object> attributes = facesContext.getAttributes();
60
61 StringBuilder sb = (StringBuilder) attributes.get(stringBuilderKey);
62
63 if (sb == null)
64 {
65 sb = new StringBuilder(initialSize);
66 attributes.put(stringBuilderKey, sb);
67 }
68 else
69 {
70
71
72 sb.setLength(0);
73 }
74
75 return sb;
76 }
77 }