|
JMeter example source code file (RenderAsRegexp.java)
The JMeter RenderAsRegexp.java source code
/*
* 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.visualizers;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.List;
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.samplers.SampleResult;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.gui.GuiUtils;
import org.apache.jorphan.gui.JLabeledTextField;
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;
/**
* Implement ResultsRender for Regexp tester
*/
public class RenderAsRegexp implements ResultRenderer, ActionListener {
private static final String REGEXP_TESTER_COMMAND = "regexp_tester"; // $NON-NLS-1$
private JPanel regexpPane;
private JTextArea regexpDataField;
private JLabeledTextField regexpField;
private JTextArea regexpResultField;
private JTabbedPane rightSide;
private SampleResult sampleResult = null;
/** {@inheritDoc} */
public void clearData() {
this.regexpDataField.setText(""); // $NON-NLS-1$
// don't set empty to keep regexp
// regexpField.setText(""); // $NON-NLS-1$
this.regexpResultField.setText(""); // $NON-NLS-1$
}
/** {@inheritDoc} */
public void init() {
// 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) {
String command = e.getActionCommand();
if ((sampleResult != null) && (REGEXP_TESTER_COMMAND.equals(command))) {
String response = ViewResultsFullVisualizer.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) {
this.regexpResultField.setText(process(textToParse));
}
}
private String process(String textToParse) {
Perl5Matcher matcher = new Perl5Matcher();
PatternMatcherInput input = new PatternMatcherInput(textToParse);
PatternCacheLRU pcLRU = new PatternCacheLRU();
Pattern pattern = pcLRU.getPattern(regexpField.getText(), Perl5Compiler.READ_ONLY_MASK);
List<MatchResult> matches = new LinkedList
Other JMeter examples (source code examples)Here is a short list of links related to this JMeter RenderAsRegexp.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.