View | Details | Raw Unified | Return to bug 52048
Collapse All | Expand All

(-)src/core/org/apache/jmeter/util/BSFBeanInfoSupport.java (+16 lines)
Lines 19-26 Link Here
19
package org.apache.jmeter.util;
19
package org.apache.jmeter.util;
20
20
21
import java.beans.PropertyDescriptor;
21
import java.beans.PropertyDescriptor;
22
import java.util.Properties;
22
23
23
import org.apache.jmeter.testbeans.BeanInfoSupport;
24
import org.apache.jmeter.testbeans.BeanInfoSupport;
25
import org.apache.jmeter.testbeans.gui.FileEditor;
24
import org.apache.jmeter.testbeans.gui.TextAreaEditor;
26
import org.apache.jmeter.testbeans.gui.TextAreaEditor;
25
27
26
/**
28
/**
Lines 28-33 Link Here
28
 */
30
 */
29
public abstract class BSFBeanInfoSupport extends BeanInfoSupport {
31
public abstract class BSFBeanInfoSupport extends BeanInfoSupport {
30
32
33
    private final static String[] LANGUAGE_TAGS;
34
35
    static {
36
        Properties languages = JMeterUtils.loadProperties("org/apache/bsf/Languages.properties"); // $NON-NLS-1$
37
        LANGUAGE_TAGS = new String[languages.size() + 1];
38
        int i = 0;
39
        for (Object language : languages.keySet()) {
40
            LANGUAGE_TAGS[i++] = language.toString();
41
        }
42
        LANGUAGE_TAGS[i] = "jexl";
43
    }
44
31
    protected BSFBeanInfoSupport(Class<?> beanClass) {
45
    protected BSFBeanInfoSupport(Class<?> beanClass) {
32
        super(beanClass);
46
        super(beanClass);
33
        PropertyDescriptor p;
47
        PropertyDescriptor p;
Lines 35-40 Link Here
35
        p = property("scriptLanguage"); // $NON-NLS-1$
49
        p = property("scriptLanguage"); // $NON-NLS-1$
36
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
50
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
37
        p.setValue(DEFAULT, ""); // $NON-NLS-1$
51
        p.setValue(DEFAULT, ""); // $NON-NLS-1$
52
        p.setValue(TAGS, LANGUAGE_TAGS);
38
53
39
        createPropertyGroup("scriptingLanguage", // $NON-NLS-1$
54
        createPropertyGroup("scriptingLanguage", // $NON-NLS-1$
40
                new String[] { "scriptLanguage" }); // $NON-NLS-1$
55
                new String[] { "scriptLanguage" }); // $NON-NLS-1$
Lines 49-54 Link Here
49
        p = property("filename"); // $NON-NLS-1$
64
        p = property("filename"); // $NON-NLS-1$
50
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
65
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
51
        p.setValue(DEFAULT, ""); // $NON-NLS-1$
66
        p.setValue(DEFAULT, ""); // $NON-NLS-1$
67
        p.setPropertyEditorClass(FileEditor.class);
52
68
53
        createPropertyGroup("filenameGroup",  // $NON-NLS-1$
69
        createPropertyGroup("filenameGroup",  // $NON-NLS-1$
54
                new String[] { "filename" }); // $NON-NLS-1$
70
                new String[] { "filename" }); // $NON-NLS-1$
(-)src/protocol/java/org/apache/jmeter/protocol/java/control/gui/BSFSamplerGui.java (-180 lines)
Lines 1-180 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
19
package org.apache.jmeter.protocol.java.control.gui;
20
21
import java.awt.BorderLayout;
22
import java.util.Arrays;
23
import java.util.Properties;
24
import java.util.Set;
25
26
import javax.swing.Box;
27
import javax.swing.JComboBox;
28
import javax.swing.JLabel;
29
import javax.swing.JPanel;
30
import javax.swing.JScrollPane;
31
import javax.swing.JTextArea;
32
import javax.swing.JTextField;
33
34
import org.apache.jmeter.protocol.java.sampler.BSFSampler;
35
import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
36
import org.apache.jmeter.testelement.TestElement;
37
import org.apache.jmeter.util.JMeterUtils;
38
39
public class BSFSamplerGui extends AbstractSamplerGui {
40
    private static final long serialVersionUID = 240L;
41
42
    private JTextArea scriptField;
43
44
    private JComboBox langField;// Language
45
46
    private JTextField filename;// script file name (if present)
47
48
    private JTextField parameters;// parameters to pass to script file (or script)
49
50
    public BSFSamplerGui() {
51
        init();
52
    }
53
54
    @Override
55
    public void configure(TestElement element) {
56
        super.configure(element);
57
        BSFSampler sampler = (BSFSampler) element;
58
        scriptField.setText(sampler.getScript());
59
        langField.setSelectedItem(sampler.getScriptLanguage());
60
        filename.setText(sampler.getFilename());
61
        parameters.setText(sampler.getParameters());
62
    }
63
64
    public TestElement createTestElement() {
65
        BSFSampler sampler = new BSFSampler();
66
        modifyTestElement(sampler);
67
        return sampler;
68
    }
69
70
    /**
71
     * Modifies a given TestElement to mirror the data in the gui components.
72
     *
73
     * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
74
     */
75
    public void modifyTestElement(TestElement te) {
76
        te.clear();
77
        this.configureTestElement(te);
78
        BSFSampler sampler = (BSFSampler) te;
79
        sampler.setFilename(filename.getText());
80
        sampler.setScriptLanguage((String) langField.getSelectedItem());
81
        sampler.setParameters(parameters.getText());
82
        sampler.setScript(scriptField.getText());
83
    }
84
85
    /**
86
     * Implements JMeterGUIComponent.clearGui
87
     */
88
    @Override
89
    public void clearGui() {
90
        super.clearGui();
91
92
        scriptField.setText(""); //$NON-NLS-1$
93
        langField.setSelectedIndex(0);
94
        filename.setText(""); //$NON-NLS-1$
95
        parameters.setText(""); //$NON-NLS-1$
96
    }
97
98
    public String getLabelResource() {
99
        return "bsf_sampler_title"; // $NON-NLS-1$
100
    }
101
102
    private void init() {
103
        setLayout(new BorderLayout(0, 5));
104
        setBorder(makeBorder());
105
106
        Box box = Box.createVerticalBox();
107
        box.add(makeTitlePanel());
108
        box.add(createLanguagePanel());
109
        box.add(createFilenamePanel());
110
        box.add(createParameterPanel());
111
        add(box, BorderLayout.NORTH);
112
113
        JPanel panel = createScriptPanel();
114
        add(panel, BorderLayout.CENTER);
115
        // Don't let the input field shrink too much
116
        add(Box.createVerticalStrut(panel.getPreferredSize().height), BorderLayout.WEST);
117
    }
118
119
    private JPanel createParameterPanel() {
120
        JLabel label = new JLabel(JMeterUtils.getResString("bsf_script_parameters")); // $NON-NLS-1$
121
122
        parameters = new JTextField(10);
123
        label.setLabelFor(parameters);
124
125
        JPanel parameterPanel = new JPanel(new BorderLayout(5, 0));
126
        parameterPanel.add(label, BorderLayout.WEST);
127
        parameterPanel.add(parameters, BorderLayout.CENTER);
128
        return parameterPanel;
129
    }
130
131
    private JPanel createFilenamePanel()// TODO ought to be a FileChooser ...
132
    {
133
        JLabel label = new JLabel(JMeterUtils.getResString("bsf_script_file")); // $NON-NLS-1$
134
135
        filename = new JTextField(10);
136
        label.setLabelFor(filename);
137
138
        JPanel filenamePanel = new JPanel(new BorderLayout(5, 0));
139
        filenamePanel.add(label, BorderLayout.WEST);
140
        filenamePanel.add(filename, BorderLayout.CENTER);
141
        return filenamePanel;
142
    }
143
144
    private JPanel createLanguagePanel() {
145
        JLabel label = new JLabel(JMeterUtils.getResString("bsf_script_language")); // $NON-NLS-1$
146
147
        Properties p = JMeterUtils.loadProperties("org/apache/bsf/Languages.properties"); // $NON-NLS-1$
148
        // We have added Jexl in BSFSampler.
149
        p.put("jexl", ""); // $NON-NLS-1$
150
        Set<Object> keySet = p.keySet();
151
        // TODO - perhaps weed out ones which don't exist?
152
        String [] items = keySet.toArray(new String[keySet.size()]);
153
        Arrays.sort(items);
154
155
        langField = new JComboBox(items);
156
        langField.setEditable(true);
157
        label.setLabelFor(langField);
158
159
        JPanel langPanel = new JPanel(new BorderLayout(5, 0));
160
        langPanel.add(label, BorderLayout.WEST);
161
        langPanel.add(langField, BorderLayout.CENTER);
162
163
        return langPanel;
164
    }
165
166
    private JPanel createScriptPanel() {
167
        scriptField = new JTextArea();
168
        scriptField.setRows(4);
169
        scriptField.setLineWrap(true);
170
        scriptField.setWrapStyleWord(true);
171
172
        JLabel label = new JLabel(JMeterUtils.getResString("bsf_script")); // $NON-NLS-1$
173
        label.setLabelFor(scriptField);
174
175
        JPanel panel = new JPanel(new BorderLayout());
176
        panel.add(label, BorderLayout.NORTH);
177
        panel.add(new JScrollPane(scriptField), BorderLayout.CENTER);
178
        return panel;
179
    }
180
}
(-)src/protocol/java/org/apache/jmeter/protocol/java/sampler/BSFSampler.java (-1 / +2 lines)
Lines 27-32 Link Here
27
import org.apache.jmeter.samplers.Entry;
27
import org.apache.jmeter.samplers.Entry;
28
import org.apache.jmeter.samplers.SampleResult;
28
import org.apache.jmeter.samplers.SampleResult;
29
import org.apache.jmeter.samplers.Sampler;
29
import org.apache.jmeter.samplers.Sampler;
30
import org.apache.jmeter.testbeans.TestBean;
30
import org.apache.jmeter.util.BSFTestElement;
31
import org.apache.jmeter.util.BSFTestElement;
31
import org.apache.jorphan.logging.LoggingManager;
32
import org.apache.jorphan.logging.LoggingManager;
32
import org.apache.log.Logger;
33
import org.apache.log.Logger;
Lines 35-41 Link Here
35
 * A sampler which understands BSF
36
 * A sampler which understands BSF
36
 *
37
 *
37
 */
38
 */
38
public class BSFSampler extends BSFTestElement implements Sampler {
39
public class BSFSampler extends BSFTestElement implements Sampler, TestBean {
39
40
40
    private static final long serialVersionUID = 240L;
41
    private static final long serialVersionUID = 240L;
41
42
(-)src/protocol/java/org/apache/jmeter/protocol/java/sampler/BSFSamplerResources_fr.properties (+29 lines)
Line 0 Link Here
1
#   Licensed to the Apache Software Foundation (ASF) under one or more
2
#   contributor license agreements.  See the NOTICE file distributed with
3
#   this work for additional information regarding copyright ownership.
4
#   The ASF licenses this file to You under the Apache License, Version 2.0
5
#   (the "License"); you may not use this file except in compliance with
6
#   the License.  You may obtain a copy of the License at
7
# 
8
#       http://www.apache.org/licenses/LICENSE-2.0
9
# 
10
#   Unless required by applicable law or agreed to in writing, software
11
#   distributed under the License is distributed on an "AS IS" BASIS,
12
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
#   See the License for the specific language governing permissions and
14
#   limitations under the License.
15
16
#Stored by I18NEdit, may be edited!
17
displayName=Echantillon BSF
18
filename.displayName=Nom de fichier 
19
filename.shortDescription=Fichier script (remplace le script)
20
filenameGroup.displayName=Fichier script (remplace le script)
21
parameterGroup.displayName=Param\u00E8tres \u00E0 passer au script (\=> String Parameters and String []args)
22
parameters.displayName=Param\u00E8tres
23
parameters.shortDescription=Param\u00E8tres \u00E0 passer au fichier ou au script
24
script.displayName=Script
25
script.shortDescription=Script dans le langage BSF appropri\u00E9
26
scriptLanguage.displayName=Langage 
27
scriptLanguage.shortDescription=Nom du langage BSF, ex. beanshell, javascript, jexl
28
scripting.displayName=Script (variables\: ctx vars props SampleResult sampler log Label FileName Parameters args[] OUT)
29
scriptingLanguage.displayName=Langage de script (ex. beanshell, javascript, jexl)
(-)src/protocol/java/org/apache/jmeter/protocol/java/sampler/BSFSamplerBeanInfo.java (+29 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
 * License for the specific language governing permissions and limitations
15
 * under the License.
16
 *
17
 */
18
19
package org.apache.jmeter.protocol.java.sampler;
20
21
import org.apache.jmeter.util.BSFBeanInfoSupport;
22
23
public class BSFSamplerBeanInfo extends BSFBeanInfoSupport {
24
25
    public BSFSamplerBeanInfo() {
26
        super(BSFSampler.class);
27
    }
28
29
}
(-)src/protocol/java/org/apache/jmeter/protocol/java/sampler/BSFSamplerResources.properties (+29 lines)
Line 0 Link Here
1
#   Licensed to the Apache Software Foundation (ASF) under one or more
2
#   contributor license agreements.  See the NOTICE file distributed with
3
#   this work for additional information regarding copyright ownership.
4
#   The ASF licenses this file to You under the Apache License, Version 2.0
5
#   (the "License"); you may not use this file except in compliance with
6
#   the License.  You may obtain a copy of the License at
7
# 
8
#       http://www.apache.org/licenses/LICENSE-2.0
9
# 
10
#   Unless required by applicable law or agreed to in writing, software
11
#   distributed under the License is distributed on an "AS IS" BASIS,
12
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
#   See the License for the specific language governing permissions and
14
#   limitations under the License.
15
16
17
displayName=BSF Sampler
18
filename.displayName=File Name
19
filename.shortDescription=Script file (overrides script)
20
filenameGroup.displayName=Script file (overrides script)
21
parameterGroup.displayName=Parameters to be passed to script (=> String Parameters and String []args)
22
parameters.displayName=Parameters
23
parameters.shortDescription=Parameters to be passed to the file or script
24
script.displayName=Script
25
script.shortDescription=Script in the appropriate BSF language
26
scriptLanguage.displayName=Language
27
scriptLanguage.shortDescription=Name of BSF language, e.g. beanshell, javascript, jexl
28
scripting.displayName=Script (variables: ctx vars props SampleResult sampler log Label FileName Parameters args[] OUT)
29
scriptingLanguage.displayName=Script language (e.g. beanshell, javascript, jexl)

Return to bug 52048