1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.servlet.taglib.aui;
16  
17  import com.liferay.portal.kernel.util.StringBundler;
18  import com.liferay.portal.kernel.util.StringUtil;
19  import com.liferay.portal.kernel.util.Validator;
20  
21  import java.util.Set;
22  import java.util.TreeSet;
23  
24  /**
25   * <a href="ScriptData.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class ScriptData {
30  
31      public void append(String content, String use) {
32          if (Validator.isNull(use)) {
33              _rawSB.append(content);
34          }
35          else {
36              _callbackSB.append("(function() {");
37              _callbackSB.append(content);
38              _callbackSB.append("})();");
39  
40              String[] useArray = StringUtil.split(use);
41  
42              for (int i = 0; i < useArray.length; i++) {
43                  _useSet.add(useArray[i]);
44              }
45          }
46      }
47  
48      public void append(StringBundler contentSB, String use) {
49          if (Validator.isNull(use)) {
50              _rawSB.append(contentSB);
51          }
52          else {
53              _callbackSB.append("(function() {");
54              _callbackSB.append(contentSB);
55              _callbackSB.append("})();");
56  
57              String[] useArray = StringUtil.split(use);
58  
59              for (int i = 0; i < useArray.length; i++) {
60                  _useSet.add(useArray[i]);
61              }
62          }
63      }
64  
65      public StringBundler getCallbackSB() {
66          return _callbackSB;
67      }
68  
69      public StringBundler getRawSB() {
70          return _rawSB;
71      }
72  
73      public Set<String> getUseSet() {
74          return _useSet;
75      }
76  
77      private StringBundler _callbackSB = new StringBundler();
78      private StringBundler _rawSB = new StringBundler();
79      private Set<String> _useSet = new TreeSet<String>();
80  
81  }