001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.servlet.taglib.aui;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.kernel.util.StringUtil;
019    import com.liferay.portal.kernel.util.Validator;
020    
021    import java.util.Set;
022    import java.util.TreeSet;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class ScriptData {
028    
029            public void append(String content, String use) {
030                    if (Validator.isNull(use)) {
031                            _rawSB.append(content);
032                    }
033                    else {
034                            _callbackSB.append("(function() {");
035                            _callbackSB.append(content);
036                            _callbackSB.append("})();");
037    
038                            String[] useArray = StringUtil.split(use);
039    
040                            for (int i = 0; i < useArray.length; i++) {
041                                    _useSet.add(useArray[i]);
042                            }
043                    }
044            }
045    
046            public void append(StringBundler contentSB, String use) {
047                    if (Validator.isNull(use)) {
048                            _rawSB.append(contentSB);
049                    }
050                    else {
051                            _callbackSB.append("(function() {");
052                            _callbackSB.append(contentSB);
053                            _callbackSB.append("})();");
054    
055                            String[] useArray = StringUtil.split(use);
056    
057                            for (int i = 0; i < useArray.length; i++) {
058                                    _useSet.add(useArray[i]);
059                            }
060                    }
061            }
062    
063            public StringBundler getCallbackSB() {
064                    return _callbackSB;
065            }
066    
067            public StringBundler getRawSB() {
068                    return _rawSB;
069            }
070    
071            public Set<String> getUseSet() {
072                    return _useSet;
073            }
074    
075            private StringBundler _callbackSB = new StringBundler();
076            private StringBundler _rawSB = new StringBundler();
077            private Set<String> _useSet = new TreeSet<String>();
078    
079    }