Index: /src/components/org/apache/jmeter/display/interfaces/ResultsRender.java =================================================================== --- /src/components/org/apache/jmeter/display/interfaces/ResultsRender.java (revision 0) +++ /src/components/org/apache/jmeter/display/interfaces/ResultsRender.java (revision 0) @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * + */ +package org.apache.jmeter.display.interfaces; + +import javax.swing.JTabbedPane; + +import org.apache.jmeter.samplers.SampleResult; + + +/** + * Interface to results render + */ +public interface ResultsRender { + + public void clearData(); + + public void init(); + + public void setupTabPane(); + + public void setRightSide(JTabbedPane rightSide); + + public void showRender(); + + public void setSamplerResult(SampleResult sample); + + public String toString(); + +} Index: /src/components/org/apache/jmeter/display/resources/MessagesResultRender.properties =================================================================== --- /src/components/org/apache/jmeter/display/resources/MessagesResultRender.properties (revision 0) +++ /src/components/org/apache/jmeter/display/resources/MessagesResultRender.properties (revision 0) @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#Stored by I18NEdit, may be edited! +regexp_tester_button_test=Test +regexp_tester_field=Regular expression\: +regexp_render_no_text=Data response result isn't plain text. +regexp_tester_title=RegExp Tester +simple_render_no_text=Data response result isn't plain text. +simple_render_title=Simple render +view_results_tab_regexp_tester=Regexp tester Index: /src/components/org/apache/jmeter/display/resources/MessagesResultRender_fr.properties =================================================================== --- /src/components/org/apache/jmeter/display/resources/MessagesResultRender_fr.properties (revision 0) +++ /src/components/org/apache/jmeter/display/resources/MessagesResultRender_fr.properties (revision 0) @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#Stored by I18NEdit, may be edited! +regexp_tester_button_test=Tester +regexp_tester_field=Expression r\u00E9guli\u00E8re \: +regexp_render_no_text=Les donn\u00E9es de r\u00E9ponse ne sont pas du texte. +regexp_tester_title=Testeur de RegExp +simple_render_no_text=Les donn\u00E9es de r\u00E9ponse ne sont pas du texte. +simple_render_title=Afficheur simple +view_results_tab_regexp_tester=Testeur de regexp Index: /src/components/org/apache/jmeter/display/results/ResultsRenderRegexpImpl.java =================================================================== --- /src/components/org/apache/jmeter/display/results/ResultsRenderRegexpImpl.java (revision 0) +++ /src/components/org/apache/jmeter/display/results/ResultsRenderRegexpImpl.java (revision 0) @@ -0,0 +1,208 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * + */ +package org.apache.jmeter.display.results; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; + +import org.apache.jmeter.display.interfaces.ResultsRender; +import org.apache.jmeter.display.utils.RegexpExtractor; +import org.apache.jmeter.display.utils.ResourceUtil; +import org.apache.jmeter.display.utils.VisualizerUtilGUI; +import org.apache.jmeter.samplers.SampleResult; +import org.apache.jorphan.gui.JLabeledTextField; +import org.apache.jorphan.logging.LoggingManager; +import org.apache.log.Logger; + +/** + * Implement ResultsRender for Regexp tester + */ +public class ResultsRenderRegexpImpl implements ResultsRender, ActionListener { + + private static final Logger log = LoggingManager.getLoggerForClass(); + + private static final String REGEXP_TESTER_COMMAND = "regexp_tester"; // $NON-NLS-1$ + + private static String BUNDLE_RESOURCE = "org.apache.jmeter.display.resources.MessagesResultRender"; + + private static ResourceUtil resource = new ResourceUtil(BUNDLE_RESOURCE); + + // set command to RegExp Tester + private String command = REGEXP_TESTER_COMMAND; + + private JPanel regexpPane; + + private JTextArea regexpDataField; + + private JLabeledTextField regexpField; + + private JTextArea regexpResultField; + + private JTabbedPane rightSide; + + private SampleResult sampleResult = null; + + /* (non-Javadoc) + * @see org.apache.jmeter.visualizers.interfaces.ResultsRender#clearData() + */ + public void clearData() { + this.clearFields(); + } + + /* (non-Javadoc) + * @see org.apache.jmeter.visualizers.interfaces.ResultsRender#init() + */ + public void init() { + log.debug("init() - pass"); + // Create the panels for the regexp tab + regexpPane = createRegexpPanel(); + } + + /** + * Display the response as text or as rendered HTML. Change the text on the + * button appropriate to the current display. + * + * @param e the ActionEvent being processed + */ + public void actionPerformed(ActionEvent e) { + command = e.getActionCommand(); + if ((sampleResult != null) && command != null + && (command.equals(REGEXP_TESTER_COMMAND))) { + String response = VisualizerUtilGUI.getResponseAsString(sampleResult); + executeAndShowRegexpTester(response); + } + } + + /** + * Launch regexp engine to parse a input text + * @param textToParse + */ + private void executeAndShowRegexpTester(String textToParse) { + if (textToParse != null && textToParse.length() > 0 && this.regexpField.getText().length() > 0) { + RegexpExtractor ree = new RegexpExtractor(); + log.debug("regexpField = " + this.regexpField.getText()); + ree.setRegex(this.regexpField.getText()); + ree.setInputString(textToParse); + this.regexpResultField.setText(ree.process()); + } + } + + public void showRender() { + log.debug("showRender() - pass"); + this.clearFields(); + + if ((SampleResult.TEXT).equals(sampleResult.getDataType())) { + String response = VisualizerUtilGUI.getResponseAsString(sampleResult); + regexpDataField.setText(response); + regexpDataField.setCaretPosition(0); + } else { + // TODO : showImage? + regexpDataField.setText(resource.getResString("regexp_render_no_text")); + } + } + + public void setupTabPane() { + log.debug("setupTabPane() - pass"); + // Add regexp tester pane + if (rightSide.indexOfTab(resource.getResString("view_results_tab_regexp_tester")) < 0) { // $NON-NLS-1$ + rightSide.addTab(resource.getResString("view_results_tab_regexp_tester"), regexpPane); // $NON-NLS-1$ + } + } + + /** + * @return RegExp Tester panel + */ + private JPanel createRegexpPanel() { + regexpDataField = new JTextArea(); + regexpDataField.setEditable(false); + regexpDataField.setLineWrap(true); + regexpDataField.setWrapStyleWord(true); + + JScrollPane regexpDataPane = VisualizerUtilGUI.makeScrollPane(regexpDataField); + regexpDataPane.setMinimumSize(new Dimension(0, 200)); + + JPanel pane = new JPanel(new BorderLayout(0, 5)); + + JSplitPane mainSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, + regexpDataPane, createRegexpTasksPanel()); + mainSplit.setDividerLocation(300); + pane.add(mainSplit, BorderLayout.CENTER); + return pane; + } + + /** + * Create the Regexp task pane + * + * @return Regexp task pane + */ + private JPanel createRegexpTasksPanel() { + JPanel regexpActionPanel = new JPanel(); + regexpField = new JLabeledTextField(resource.getResString("regexp_tester_field"), 30); // $NON-NLS-1$ + regexpActionPanel.add(regexpField, BorderLayout.WEST); + + JButton regexpTester = new JButton(resource.getResString("regexp_tester_button_test")); + regexpTester.setActionCommand(REGEXP_TESTER_COMMAND); + regexpTester.addActionListener(this); + regexpActionPanel.add(regexpTester, BorderLayout.EAST); + + regexpResultField = new JTextArea(); + regexpResultField.setEditable(false); + regexpResultField.setLineWrap(true); + regexpResultField.setWrapStyleWord(true); + + JPanel regexpTasksPanel = new JPanel(new BorderLayout(0, 5)); + regexpTasksPanel.add(regexpActionPanel, BorderLayout.NORTH); + regexpTasksPanel.add(VisualizerUtilGUI.makeScrollPane(regexpResultField), BorderLayout.CENTER); + + return regexpTasksPanel; + } + + private void clearFields() { + regexpDataField.setText(""); // $NON-NLS-1$ + // don't set empty to keep regexp + // regexpField.setText(""); // $NON-NLS-1$ + regexpResultField.setText(""); // $NON-NLS-1$ + } + + public synchronized void setRightSide(JTabbedPane side) { + rightSide = side; + } + + public synchronized void setSamplerResult(SampleResult sample) { + sampleResult = sample; + } + + public String toString() { + return resource.getResString("regexp_tester_title"); + } + +} Index: /src/components/org/apache/jmeter/display/results/ResultsRenderSimpleTextImpl.java =================================================================== --- /src/components/org/apache/jmeter/display/results/ResultsRenderSimpleTextImpl.java (revision 0) +++ /src/components/org/apache/jmeter/display/results/ResultsRenderSimpleTextImpl.java (revision 0) @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jmeter.display.results; + +import java.awt.BorderLayout; +import java.awt.Dimension; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; + +import org.apache.jmeter.display.interfaces.ResultsRender; +import org.apache.jmeter.display.utils.ResourceUtil; +import org.apache.jmeter.display.utils.VisualizerUtilGUI; +import org.apache.jmeter.samplers.SampleResult; + +public class ResultsRenderSimpleTextImpl implements ResultsRender { + + private static String BUNDLE_RESOURCE = "org.apache.jmeter.display.resources.MessagesResultRender"; + + private static ResourceUtil resource = new ResourceUtil(BUNDLE_RESOURCE); + + private JPanel simplePane; + + private JTextArea dataField; + + private JTabbedPane rightSide; + + private SampleResult sampleResult = null; + + public void clearData() { + dataField.setText(""); + } + + public void init() { + simplePane = createPane(); + } + + public synchronized void setRightSide(JTabbedPane side) { + rightSide = side; + } + + public synchronized void setSamplerResult(SampleResult sample) { + sampleResult = sample; + } + + public String toString() { + return resource.getResString("simple_render_title"); + } + + public void setupTabPane() { + // Add tab pane + if (rightSide.indexOfTab(resource.getResString("simple_render_title")) < 0) { // $NON-NLS-1$ + rightSide.addTab(resource.getResString("simple_render_title"), simplePane); // $NON-NLS-1$ + } + + } + + public void showRender() { + if ((SampleResult.TEXT).equals(sampleResult.getDataType())) { + String response = VisualizerUtilGUI.getResponseAsString(sampleResult); + dataField.setText(response); + dataField.setCaretPosition(0); + } else { + // TODO : showImage perhaps? + dataField.setText(resource.getResString("simple_render_no_text")); + } + } + + private JPanel createPane() { + dataField = new JTextArea(); + dataField.setEditable(false); + dataField.setLineWrap(true); + dataField.setWrapStyleWord(true); + + JScrollPane regexpDataPane = VisualizerUtilGUI.makeScrollPane(dataField); + regexpDataPane.setMinimumSize(new Dimension(0, 200)); + + JPanel pane = new JPanel(new BorderLayout(0, 5)); + pane.add(regexpDataPane, BorderLayout.CENTER); + + return pane; + } + +} Index: /src/components/org/apache/jmeter/display/results/ResultsRenderStandardImpl.java =================================================================== --- /src/components/org/apache/jmeter/display/results/ResultsRenderStandardImpl.java (revision 0) +++ /src/components/org/apache/jmeter/display/results/ResultsRenderStandardImpl.java (revision 0) @@ -0,0 +1,768 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jmeter.display.results; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.ByteArrayInputStream; +import java.io.StringWriter; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JCheckBox; +import javax.swing.JEditorPane; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.JTextPane; +import javax.swing.JTree; +import javax.swing.ToolTipManager; +import javax.swing.text.BadLocationException; +import javax.swing.text.ComponentView; +import javax.swing.text.Document; +import javax.swing.text.EditorKit; +import javax.swing.text.Element; +import javax.swing.text.Style; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyledDocument; +import javax.swing.text.View; +import javax.swing.text.ViewFactory; +import javax.swing.text.html.HTML; +import javax.swing.text.html.HTMLEditorKit; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.TreeSelectionModel; + +import org.apache.jmeter.display.interfaces.ResultsRender; +import org.apache.jmeter.display.utils.VisualizerUtilGUI; +import org.apache.jmeter.samplers.SampleResult; +import org.apache.jmeter.util.JMeterUtils; +import org.apache.jmeter.util.XPathUtil; +import org.apache.jmeter.visualizers.XMLDefaultMutableTreeNode; +import org.apache.jorphan.logging.LoggingManager; +import org.apache.jorphan.util.JOrphanUtils; +import org.apache.log.Logger; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.tidy.Tidy; +import org.xml.sax.SAXException; + +public class ResultsRenderStandardImpl implements ResultsRender, ActionListener { + + private static final Logger log = LoggingManager.getLoggerForClass(); + + // N.B. these are not multi-threaded, so don't make it static + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); // ISO format $NON-NLS-1$ + + private static final String NL = "\n"; // $NON-NLS-1$ + + private static final byte[] XML_PFX = "= 0) { + rightSide.removeTabAt(requestTabIndex); + } + int responseTabIndex = rightSide.indexOfTab(JMeterUtils.getResString("view_results_tab_response")); // $NON-NLS-1$ + if(responseTabIndex >= 0) { + rightSide.removeTabAt(responseTabIndex); + } + } + + private Component createResponseMetadataPanel() { + stats = new JTextPane(); + stats.setEditable(false); + // TODO find a way to get system background color + //stats.setBackground(getBackground()); + + // Add styles to use for different types of status messages + StyledDocument doc = (StyledDocument) stats.getDocument(); + + Style style = doc.addStyle(STYLE_REDIRECT, null); + StyleConstants.setForeground(style, REDIRECT_COLOR); + + style = doc.addStyle(STYLE_CLIENT_ERROR, null); + StyleConstants.setForeground(style, CLIENT_ERROR_COLOR); + + style = doc.addStyle(STYLE_SERVER_ERROR, null); + StyleConstants.setForeground(style, SERVER_ERROR_COLOR); + + JScrollPane pane = VisualizerUtilGUI.makeScrollPane(stats); + pane.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); + return pane; + } + + private JPanel createRequestPanel() { + sampleDataField = new JTextArea(); + sampleDataField.setEditable(false); + sampleDataField.setLineWrap(true); + sampleDataField.setWrapStyleWord(true); + + JPanel pane = new JPanel(new BorderLayout(0, 5)); + pane.add(VisualizerUtilGUI.makeScrollPane(sampleDataField)); + return pane; + } + + private JPanel createResponseDataPanel() { + results = new JEditorPane(); + results.setEditable(false); + + resultsScrollPane = VisualizerUtilGUI.makeScrollPane(results); + imageLabel = new JLabel(); + + JPanel panel = new JPanel(new BorderLayout()); + panel.add(resultsScrollPane, BorderLayout.CENTER); + panel.add(createHtmlOrTextPane(), BorderLayout.SOUTH); + + return panel; + } + + private Component createHtmlOrTextPane() { + ButtonGroup group = new ButtonGroup(); + + textButton = new JRadioButton(JMeterUtils.getResString("view_results_render_text")); // $NON-NLS-1$ + textButton.setActionCommand(TEXT_COMMAND); + textButton.addActionListener(this); + textButton.setSelected(textMode); + group.add(textButton); + + htmlButton = new JRadioButton(JMeterUtils.getResString("view_results_render_html")); // $NON-NLS-1$ + htmlButton.setActionCommand(HTML_COMMAND); + htmlButton.addActionListener(this); + htmlButton.setSelected(!textMode); + group.add(htmlButton); + + jsonButton = new JRadioButton(JMeterUtils.getResString("view_results_render_json")); // $NON-NLS-1$ + jsonButton.setActionCommand(JSON_COMMAND); + jsonButton.addActionListener(this); + jsonButton.setSelected(!textMode); + group.add(jsonButton); + + xmlButton = new JRadioButton(JMeterUtils.getResString("view_results_render_xml")); // $NON-NLS-1$ + xmlButton.setActionCommand(XML_COMMAND); + xmlButton.addActionListener(this); + xmlButton.setSelected(!textMode); + group.add(xmlButton); + + downloadAll = new JCheckBox(JMeterUtils.getResString("view_results_render_embedded")); // $NON-NLS-1$ + + JPanel pane = new JPanel(); + pane.add(textButton); + pane.add(htmlButton); + pane.add(xmlButton); + pane.add(jsonButton); + pane.add(downloadAll); + return pane; + } + + protected void showRenderedResponse(String response, SampleResult res) { + if (response == null) { + results.setText(""); + return; + } + + int htmlIndex = response.indexOf(" // $NON-NLS-1$ + + // Look for a case variation + if (htmlIndex < 0) { + htmlIndex = response.indexOf(" See + * http://issues.apache.org/bugzilla/show_bug.cgi?id=23315 + * + * Is this due to a bug in Java? + */ + results.getDocument().putProperty("IgnoreCharsetDirective", Boolean.TRUE); // $NON-NLS-1$ + + results.setText(html); + results.setCaretPosition(0); + resultsScrollPane.setViewportView(results); + + textButton.setEnabled(true); + htmlButton.setEnabled(true); + jsonButton.setEnabled(true); + xmlButton.setEnabled(true); + } + + protected void showRenderJSONResponse(String response) { + results.setContentType("text/plain"); // $NON-NLS-1$ + results.setText(response == null ? "" : prettyJSON(response)); + results.setCaretPosition(0); + resultsScrollPane.setViewportView(results); + + textButton.setEnabled(true); + htmlButton.setEnabled(true); + jsonButton.setEnabled(true); + xmlButton.setEnabled(true); + } + + protected void showRenderXMLResponse(SampleResult res) { + results.setContentType("text/xml"); // $NON-NLS-1$ + results.setCaretPosition(0); + byte[] source = res.getResponseData(); + final ByteArrayInputStream baIS = new ByteArrayInputStream(source); + for(int i=0; i 0) { + showErrorMessageDialog(sw.toString(), + "Tidy: " + tidy.getParseErrors() + " errors, " + tidy.getParseWarnings() + " warnings", + JOptionPane.WARNING_MESSAGE); + } + + JPanel domTreePanel = new DOMTreePanel(document); + view = domTreePanel; + resultsScrollPane.setViewportView(view); + textButton.setEnabled(true); + htmlButton.setEnabled(true); + jsonButton.setEnabled(true); + xmlButton.setEnabled(true); + } + + protected void showTextResponse(String response) { + results.setContentType("text/plain"); // $NON-NLS-1$ + results.setText(response == null ? "" : response); // $NON-NLS-1$ + results.setCaretPosition(0); + resultsScrollPane.setViewportView(results); + + textButton.setEnabled(true); + htmlButton.setEnabled(true); + jsonButton.setEnabled(true); + xmlButton.setEnabled(true); + } + + // It might be useful also to make this available in the 'Request' tab, for + // when posting JSON. + private static String prettyJSON(String json) { + StringBuffer pretty = new StringBuffer(json.length() * 2); // Educated guess + + final String tab = ": "; // $NON-NLS-1$ + StringBuffer index = new StringBuffer(); + String nl = ""; // $NON-NLS-1$ + + Matcher valueOrPair = VALUE_OR_PAIR_PATTERN.matcher(json); + + boolean misparse = false; + + for (int i = 0; i < json.length(); ) { + final char currentChar = json.charAt(i); + if ((currentChar == '{') || (currentChar == '[')) { + pretty.append(nl).append(index).append(currentChar); + i++; + index.append(tab); + misparse = false; + } + else if ((currentChar == '}') || (currentChar == ']')) { + if (index.length() > 0) { + index.delete(0, tab.length()); + } + pretty.append(nl).append(index).append(currentChar); + i++; + int j = i; + while ((j < json.length()) && Character.isWhitespace(json.charAt(j))) { + j++; + } + if ((j < json.length()) && (json.charAt(j) == ',')) { + pretty.append(","); // $NON-NLS-1$ + i=j+1; + } + misparse = false; + } + else if (valueOrPair.find(i) && valueOrPair.group().length() > 0) { + pretty.append(nl).append(index).append(valueOrPair.group()); + i=valueOrPair.end(); + misparse = false; + } + else { + if (!misparse) { + pretty.append(nl).append("- Parse failed from:"); + } + pretty.append(currentChar); + i++; + misparse = true; + } + nl = "\n"; // $NON-NLS-1$ + } + return pretty.toString(); + } + + private static class LocalHTMLEditorKit extends HTMLEditorKit { + + private static final long serialVersionUID = -3399554318202905392L; + + private static final ViewFactory defaultFactory = new LocalHTMLFactory(); + + public ViewFactory getViewFactory() { + return defaultFactory; + } + + private static class LocalHTMLFactory extends javax.swing.text.html.HTMLEditorKit.HTMLFactory { + /* + * Provide dummy implementations to suppress download and display of + * related resources: - FRAMEs - IMAGEs TODO create better dummy + * displays TODO suppress LINK somehow + */ + public View create(Element elem) { + Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute); + if (o instanceof HTML.Tag) { + HTML.Tag kind = (HTML.Tag) o; + if (kind == HTML.Tag.FRAME) { + return new ComponentView(elem); + } else if (kind == HTML.Tag.IMG) { + return new ComponentView(elem); + } + } + return super.create(elem); + } + } + } + + /** + * + * A Dom tree panel for to display response as tree view author Dave Maung TODO implement to find any + * nodes in the tree using TreePath. + * + */ + private static class DOMTreePanel extends JPanel { + + private static final long serialVersionUID = 6871690021183779153L; + + private JTree domJTree; + + public DOMTreePanel(org.w3c.dom.Document document) { + super(new GridLayout(1, 0)); + try { + Node firstElement = getFirstElement(document); + DefaultMutableTreeNode top = new XMLDefaultMutableTreeNode(firstElement); + domJTree = new JTree(top); + + domJTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + domJTree.setShowsRootHandles(true); + JScrollPane domJScrollPane = new JScrollPane(domJTree); + domJTree.setAutoscrolls(true); + this.add(domJScrollPane); + ToolTipManager.sharedInstance().registerComponent(domJTree); + domJTree.setCellRenderer(new DomTreeRenderer()); + } catch (SAXException e) { + log.warn("", e); + } + + } + + /** + * Skip all DTD nodes, all prolog nodes. They dont support in tree view + * We let user to insert them however in DOMTreeView, we dont display it + * + * @param root + * @return + */ + private Node getFirstElement(Node parent) { + NodeList childNodes = parent.getChildNodes(); + Node toReturn = parent; // Must return a valid node, or may generate an NPE + for (int i = 0; i < childNodes.getLength(); i++) { + Node childNode = childNodes.item(i); + toReturn = childNode; + if (childNode.getNodeType() == Node.ELEMENT_NODE){ + break; + } + + } + return toReturn; + } + + /** + * This class is to view as tooltext. This is very useful, when the + * contents has long string and does not fit in the view. it will also + * automatically wrap line for each 100 characters since tool tip + * support html. author Dave Maung + */ + private static class DomTreeRenderer extends DefaultTreeCellRenderer { + + private static final long serialVersionUID = 240210061375790195L; + + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, + boolean leaf, int row, boolean phasFocus) { + super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, phasFocus); + + DefaultMutableTreeNode valueTreeNode = (DefaultMutableTreeNode) value; + setToolTipText(getHTML(valueTreeNode.toString(), "
", 100)); // $NON-NLS-1$ + return this; + } + + /** + * get the html + * + * @param str + * @param separator + * @param maxChar + * @return + */ + private String getHTML(String str, String separator, int maxChar) { + StringBuffer strBuf = new StringBuffer(""); // $NON-NLS-1$ + char[] chars = str.toCharArray(); + for (int i = 0; i < chars.length; i++) { + + if (i % maxChar == 0 && i != 0) { + strBuf.append(separator); + } + strBuf.append(encode(chars[i])); + + } + strBuf.append(""); // $NON-NLS-1$ + return strBuf.toString(); + + } + + private String encode(char c) { + String toReturn = String.valueOf(c); + switch (c) { + case '<': // $NON-NLS-1$ + toReturn = "<"; // $NON-NLS-1$ + break; + case '>': // $NON-NLS-1$ + toReturn = ">"; // $NON-NLS-1$ + break; + case '\'': // $NON-NLS-1$ + toReturn = "'"; // $NON-NLS-1$ + break; + case '\"': // $NON-NLS-1$ + toReturn = """; // $NON-NLS-1$ + break; + + } + return toReturn; + } + } + } + + protected void showImage(Icon image) { + imageLabel.setIcon(image); + resultsScrollPane.setViewportView(imageLabel); + } + + private static void showErrorMessageDialog(String message, String title, int messageType) { + JOptionPane.showMessageDialog(null, message, title, messageType); + } + + public synchronized void setRightSide(JTabbedPane side) { + rightSide = side; + } + + public synchronized void setSamplerResult(SampleResult sample) { + sampleResult = sample; + } + + public String toString() { + // TODO : I18N + return "Standard Results"; + } + +} Index: /src/components/org/apache/jmeter/display/results/ViewResultsBase.java =================================================================== --- /src/components/org/apache/jmeter/display/results/ViewResultsBase.java (revision 0) +++ /src/components/org/apache/jmeter/display/results/ViewResultsBase.java (revision 0) @@ -0,0 +1,335 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * + */ +package org.apache.jmeter.display.results; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.ComboBoxModel; +import javax.swing.DefaultComboBoxModel; +import javax.swing.ImageIcon; +import javax.swing.JComboBox; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTabbedPane; +import javax.swing.JTree; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; + +import org.apache.jmeter.assertions.AssertionResult; +import org.apache.jmeter.display.interfaces.ResultsRender; +import org.apache.jmeter.gui.util.VerticalPanel; +import org.apache.jmeter.samplers.Clearable; +import org.apache.jmeter.samplers.SampleResult; +import org.apache.jmeter.util.JMeterUtils; +import org.apache.jmeter.visualizers.gui.AbstractVisualizer; +import org.apache.jorphan.logging.LoggingManager; +import org.apache.log.Logger; + +/** + * Base for ViewResults + * + */ +public class ViewResultsBase extends AbstractVisualizer +implements ActionListener, TreeSelectionListener, Clearable { + + private static final long serialVersionUID = 7338676747296593842L; + + private static final Logger log = LoggingManager.getLoggerForClass(); + + public static final Color SERVER_ERROR_COLOR = Color.red; + + public static final Color CLIENT_ERROR_COLOR = Color.blue; + + public static final Color REDIRECT_COLOR = Color.green; + + private JSplitPane mainSplit; + + private DefaultMutableTreeNode root; + + private DefaultTreeModel treeModel; + + //private JScrollPane resultsScrollPane; + + //private JLabel imageLabel = new JLabel(); + + private JTree jTree; + + private Component leftSide; + + private JTabbedPane rightSide; + + private JComboBox selectRenderPanel; + + protected static final String COMBO_CHANGE_COMMAND = "change_combo"; // $NON-NLS-1$ + + // set default command to change combo + //private String command = null; + + private static final ImageIcon imageSuccess = JMeterUtils.getImage( + JMeterUtils.getPropDefault("viewResultsTree.success", //$NON-NLS-1$ + "icon_success_sml.gif")); //$NON-NLS-1$ + + private static final ImageIcon imageFailure = JMeterUtils.getImage( + JMeterUtils.getPropDefault("viewResultsTree.failure", //$NON-NLS-1$ + "icon_warning_sml.gif")); //$NON-NLS-1$ + + private ResultsRender resultsRender = null; + + private TreeSelectionEvent lastSelectionEvent; + + /** + * Constructor + */ + public ViewResultsBase() { + super(); + init(); + } + + /* (non-Javadoc) + * @see org.apache.jmeter.visualizers.Visualizer#add(org.apache.jmeter.samplers.SampleResult) + */ + public void add(SampleResult sample) { + updateGui(sample); + } + + /** + * Update the visualizer with new data. + */ + private synchronized void updateGui(SampleResult res) { + // Add sample + DefaultMutableTreeNode currNode = new DefaultMutableTreeNode(res); + treeModel.insertNodeInto(currNode, root, root.getChildCount()); + addSubResults(currNode, res); + // Add any assertion that failed as children of the sample node + AssertionResult assertionResults[] = res.getAssertionResults(); + int assertionIndex = currNode.getChildCount(); + for (int j = 0; j < assertionResults.length; j++) { + AssertionResult item = assertionResults[j]; + + if (item.isFailure() || item.isError()) { + DefaultMutableTreeNode assertionNode = new DefaultMutableTreeNode(item); + treeModel.insertNodeInto(assertionNode, currNode, assertionIndex++); + } + } + + if (root.getChildCount() == 1) { + jTree.expandPath(new TreePath(root)); + } + } + + private void addSubResults(DefaultMutableTreeNode currNode, SampleResult res) { + SampleResult[] subResults = res.getSubResults(); + + int leafIndex = 0; + + for (int i = 0; i < subResults.length; i++) { + SampleResult child = subResults[i]; + + if (log.isDebugEnabled()) { + log.debug("updateGui1 : child sample result - " + child); + } + DefaultMutableTreeNode leafNode = new DefaultMutableTreeNode(child); + + treeModel.insertNodeInto(leafNode, currNode, leafIndex++); + addSubResults(leafNode, child); + // Add any assertion that failed as children of the sample node + AssertionResult assertionResults[] = child.getAssertionResults(); + int assertionIndex = leafNode.getChildCount(); + for (int j = 0; j < assertionResults.length; j++) { + AssertionResult item = assertionResults[j]; + + if (item.isFailure() || item.isError()) { + DefaultMutableTreeNode assertionNode = new DefaultMutableTreeNode(item); + treeModel.insertNodeInto(assertionNode, leafNode, assertionIndex++); + } + } + } + } + + /* (non-Javadoc) + * @see org.apache.jmeter.samplers.Clearable#clearData() + */ + public void clearData() { + while (root.getChildCount() > 0) { + // the child to be removed will always be 0 'cos as the nodes are + // removed the nth node will become (n-1)th + treeModel.removeNodeFromParent((DefaultMutableTreeNode) root.getChildAt(0)); + } + resultsRender.clearData(); + } + + /* (non-Javadoc) + * @see org.apache.jmeter.gui.JMeterGUIComponent#getLabelResource() + */ + public String getLabelResource() { + return "view_results_base_title"; // $NON-NLS-1$ + } + + /** + * Initialize this visualizer + */ + protected void init() { + log.debug("init() - pass"); + setLayout(new BorderLayout(0, 5)); + setBorder(makeBorder()); + add(makeTitlePanel(), BorderLayout.NORTH); + + leftSide = createLeftPanel(); + // Prepare the common tab + rightSide = new JTabbedPane(); + // Create the split pane + mainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftSide, rightSide); + add(mainSplit, BorderLayout.CENTER); + + // TODO: Implement dynamic ResultsRender +// resultsRender = new ResultsRenderRegexpImpl(); + resultsRender = new ResultsRenderStandardImpl(); + + resultsRender.setRightSide(rightSide); + resultsRender.init(); + } + + public void valueChanged(TreeSelectionEvent e) { + log.debug("valueChanged() - pass"); + lastSelectionEvent = e; + DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree.getLastSelectedPathComponent(); + + if (node != null) { + Object userObject = node.getUserObject(); + if (userObject instanceof SampleResult) { + SampleResult res = (SampleResult) userObject; + + // We are displaying a SampleResult + resultsRender.setSamplerResult(res); + resultsRender.setupTabPane(); + // Call Render to display result + resultsRender.showRender(); + } + } + } + + private Component createLeftPanel() { + SampleResult rootSampleResult = new SampleResult(); + rootSampleResult.setSampleLabel("Root"); + rootSampleResult.setSuccessful(true); + root = new DefaultMutableTreeNode(rootSampleResult); + + treeModel = new DefaultTreeModel(root); + jTree = new JTree(treeModel); + jTree.setCellRenderer(new ResultsNodeRenderer()); + jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + jTree.addTreeSelectionListener(this); + jTree.setRootVisible(false); + jTree.setShowsRootHandles(true); + + JScrollPane treePane = new JScrollPane(jTree); + treePane.setPreferredSize(new Dimension(200, 300)); + + VerticalPanel leftPane = new VerticalPanel(); + leftPane.add(treePane, BorderLayout.CENTER); + leftPane.add(createComboRender(), BorderLayout.SOUTH); + + return leftPane; + } + + /** + * @return List of all render (extended ViewResultsBase) + */ + private Component createComboRender() { + ComboBoxModel nodesModel = new DefaultComboBoxModel(); + + selectRenderPanel = new JComboBox(nodesModel); + selectRenderPanel.setActionCommand(COMBO_CHANGE_COMMAND); + selectRenderPanel.addActionListener(this); + // TODO implements dynamic render + selectRenderPanel.addItem(new ResultsRenderStandardImpl()); + selectRenderPanel.addItem(new ResultsRenderRegexpImpl()); + selectRenderPanel.addItem(new ResultsRenderSimpleTextImpl()); + + return selectRenderPanel; + + } + + /* + * (non-Javadoc) + * + * @see + * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) { + // TODO Add check to perform only on change drop-down choice + JComboBox jcb = (JComboBox) e.getSource(); + if (jcb != null) { + resultsRender = (ResultsRender) jcb.getSelectedItem(); + if (rightSide != null) { + // Remove old right side + mainSplit.remove(rightSide); + // create and add a new right side + rightSide = new JTabbedPane(); + mainSplit.add(rightSide); + resultsRender.setRightSide(rightSide); + resultsRender.init(); + // To display current sampler result before change + this.valueChanged(lastSelectionEvent); + } + } + } + + private static class ResultsNodeRenderer extends DefaultTreeCellRenderer { + + private static final long serialVersionUID = 4159626601097711565L; + + public Component getTreeCellRendererComponent(JTree tree, Object value, + boolean sel, boolean expanded, boolean leaf, int row, boolean focus) { + super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, focus); + boolean failure = true; + Object userObject = ((DefaultMutableTreeNode) value).getUserObject(); + if (userObject instanceof SampleResult) { + failure = !(((SampleResult) userObject).isSuccessful()); + } else if (userObject instanceof AssertionResult) { + AssertionResult assertion = (AssertionResult) userObject; + failure = assertion.isError() || assertion.isFailure(); + } + + // Set the status for the node + if (failure) { + this.setForeground(Color.red); + this.setIcon(imageFailure); + } else { + this.setIcon(imageSuccess); + } + return this; + } + } + +} Index: /src/components/org/apache/jmeter/display/utils/RegexpExtractor.java =================================================================== --- /src/components/org/apache/jmeter/display/utils/RegexpExtractor.java (revision 0) +++ /src/components/org/apache/jmeter/display/utils/RegexpExtractor.java (revision 0) @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jmeter.display.utils; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.oro.text.PatternCacheLRU; +import org.apache.oro.text.regex.MatchResult; +import org.apache.oro.text.regex.Pattern; +import org.apache.oro.text.regex.PatternMatcherInput; +import org.apache.oro.text.regex.Perl5Compiler; +import org.apache.oro.text.regex.Perl5Matcher; + +/** + * Util to parse a test with a regexp + * + */ +public class RegexpExtractor { + + /** + * @return Multi-line string found by regexp engine + */ + public String process() { + + Perl5Matcher matcher = new Perl5Matcher(); + PatternMatcherInput input = new PatternMatcherInput(this.getInputString()); + + PatternCacheLRU pcLRU = new PatternCacheLRU(); + Pattern pattern = pcLRU.getPattern(this.getRegex(), Perl5Compiler.READ_ONLY_MASK); + List matches = new ArrayList(); + int x = 0; + boolean done = false; + do { + if (matcher.contains(input, pattern)) { + //log.debug("RegexExtractor: Match found!"); + matches.add(matcher.getMatch()); + } else { + done = true; + } + x++; + } while (!done); + + // Construct a multi-line string with all matches + StringBuffer sb = new StringBuffer(); + for (int j = 0; j < matches.size(); j++) { + MatchResult mr = (MatchResult) matches.get(j); + final int groups = mr.groups(); + for (int i = 0; i < groups; i++) { + sb.append(" group[" + j + "][" + i + "]=" + mr.group(i) + "\n"); + + } + } + return sb.toString(); + + } + private String inputString; + private String regex; + + public String getRegex() { + return regex; + } + + public void setRegex(String regex) { + this.regex = regex; + } + + public String getInputString() { + return inputString; + } + + public void setInputString(String inputString) { + this.inputString = inputString; + } +} Index: /src/components/org/apache/jmeter/display/utils/ResourceUtil.java =================================================================== --- /src/components/org/apache/jmeter/display/utils/ResourceUtil.java (revision 0) +++ /src/components/org/apache/jmeter/display/utils/ResourceUtil.java (revision 0) @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jmeter.display.utils; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +import org.apache.jmeter.util.JMeterUtils; +import org.apache.jorphan.logging.LoggingManager; +import org.apache.log.Logger; + +public class ResourceUtil { + + private static final Logger log = LoggingManager.getLoggerForClass(); + + private ResourceBundle resources; + + private static volatile boolean ignoreResorces = false; // Special flag for use in debugging resources + + public ResourceUtil(String resourceFile) { + init(resourceFile); + } + + public void init(String resourceFile) { + if (resourceFile != null && resourceFile.length() > 0) { + // Get resource messages (I18N) + resources = ResourceBundle.getBundle(resourceFile, JMeterUtils + .getLocale()); + log.debug("I18N init() - pass: " + resourceFile); + } + } + /** + * Gets the resource string for this key. + * + * If the resource is not found, a warning is logged + * + * @param key + * the key in the resource file + * @return the resource string if the key is found; otherwise, return + * "[res_key="+key+"]" + */ + public String getResString(String key) { + return getResStringDefault(key, RES_KEY_PFX + key + "]"); // $NON-NLS-1$ + } + + public static final String RES_KEY_PFX = "[res_key="; // $NON-NLS-1$ + + /* + * Helper method to do the actual work of fetching resources; allows + * getResString(S,S) to be deprecated without affecting getResString(S); + */ + private String getResStringDefault(String key, String defaultValue) { + if (key == null) { + return null; + } + // Resource keys cannot contain spaces, and are forced to lower case + String resKey = key.replace(' ', '_'); // $NON-NLS-1$ // $NON-NLS-2$ + resKey = resKey.toLowerCase(java.util.Locale.ENGLISH); + String resString = null; + try { + resString = resources.getString(resKey); + if (ignoreResorces ){ // Special mode for debugging resource handling + return "["+key+"]"; + } + } catch (MissingResourceException mre) { + if (ignoreResorces ){ // Special mode for debugging resource handling + return "[?"+key+"?]"; + } + log.warn("ERROR! Resource string not found: [" + resKey + "]", mre); + resString = defaultValue; + } + return resString; + } + + /** + * @param resources the resources to set + */ + public synchronized void setResources(ResourceBundle resources) { + this.resources = resources; + } +} Index: /src/components/org/apache/jmeter/display/utils/VisualizerUtilGUI.java =================================================================== --- /src/components/org/apache/jmeter/display/utils/VisualizerUtilGUI.java (revision 0) +++ /src/components/org/apache/jmeter/display/utils/VisualizerUtilGUI.java (revision 0) @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jmeter.display.utils; + +import java.awt.Component; + +import javax.swing.JScrollPane; + +import org.apache.jmeter.samplers.SampleResult; +import org.apache.jmeter.util.JMeterUtils; +import org.apache.jorphan.logging.LoggingManager; +import org.apache.log.Logger; + +public class VisualizerUtilGUI { + + private static final Logger log = LoggingManager.getLoggerForClass(); + + // Maximum size that we will display + private static final int MAX_DISPLAY_SIZE = + JMeterUtils.getPropDefault("view.results.tree.max_size", 200 * 1024); // $NON-NLS-1$ + + /** + * Create a scroll panel that sets it's preferred size to it's minimum size. + * Explicitly for scroll panes that live inside other scroll panes, or + * within containers that stretch components to fill the area they exist in. + * Use this for any component you would put in a scroll pane (such as + * TextAreas, tables, JLists, etc). It is here for convenience and to avoid + * duplicate code. JMeter displays best if you follow this custom. + * + * @param comp + * the component which should be placed inside the scroll pane + * @return a JScrollPane containing the specified component + */ + public static JScrollPane makeScrollPane(Component comp) { + JScrollPane pane = new JScrollPane(comp); + pane.setPreferredSize(pane.getMinimumSize()); + return pane; + } + + public static String getResponseAsString(SampleResult res) { + + String response = null; + if ((SampleResult.TEXT).equals(res.getDataType())) { + // Showing large strings can be VERY costly, so we will avoid + // doing so if the response + // data is larger than 200K. TODO: instead, we could delay doing + // the result.setText + // call until the user chooses the "Response data" tab. Plus we + // could warn the user + // if this happens and revert the choice if he doesn't confirm + // he's ready to wait. + int len = res.getResponseData().length; + if (MAX_DISPLAY_SIZE > 0 && len > MAX_DISPLAY_SIZE) { + response = JMeterUtils.getResString("view_results_response_too_large_message") //$NON-NLS-1$ + + len + " > Max: "+MAX_DISPLAY_SIZE; + log.warn(response); + } else { + response = res.getResponseDataAsString(); + } + } + return response; + } + +} Index: /src/core/org/apache/jmeter/resources/messages.properties =================================================================== --- /src/core/org/apache/jmeter/resources/messages.properties (revision 788817) +++ /src/core/org/apache/jmeter/resources/messages.properties (working copy) @@ -866,6 +866,7 @@ view_results_assertion_error=Assertion error: view_results_assertion_failure=Assertion failure: view_results_assertion_failure_message=Assertion failure message: +view_results_base_title=View Results Base view_results_desc=Shows the text results of sampling in tree form view_results_error_count=Error Count: view_results_fields=fields: Index: /src/core/org/apache/jmeter/resources/messages_fr.properties =================================================================== --- /src/core/org/apache/jmeter/resources/messages_fr.properties (revision 788817) +++ /src/core/org/apache/jmeter/resources/messages_fr.properties (working copy) @@ -713,6 +713,7 @@ view_results_assertion_error=Erreur d'assertion \: view_results_assertion_failure=Echec d'assertion \: view_results_assertion_failure_message=Message d'\u00E9chec d'assertion \: +view_results_base_title=Afficheur de r\u00E9sultats view_results_desc=Affiche les r\u00E9sultats d'un \u00E9chantillon dans un arbre de r\u00E9sultats view_results_error_count=Compteur erreur\: view_results_fields=champs \: