- Timestamps
- comments out the Extrares
- deletes unwanted server calls (need to specify)
import java.io.*;
import javax.swing.*;
//deletes the unwanted lines
import java.awt.GridLayout;
public class LrScriptFormatter1 {
public static void main(String[] args) {
JPanel panel = new JPanel(new GridLayout(2, 0, 0, 0));
JTextField field1 = new JTextField("C:\\LRScriptFormater\\Raw.txt");
JTextField field2 = new JTextField("C:\\LRScriptFormater\\Out.txt");
panel.add(new JLabel("Raw File:"));
panel.add(field1);
panel.add(new JLabel("Output File:"));
panel.add(field2);
String inFile = field1.getText();
String outFile = field2.getText();
int option = JOptionPane.showConfirmDialog(null, panel,
"LoadRunner Script Formatter - by TLQE", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE);
if (option == JOptionPane.OK_OPTION) {
inFile = field1.getText();
outFile = field2.getText();
JPanel panelOK = new JPanel(new GridLayout(1, 0));
JOptionPane.showMessageDialog(panelOK, "Processing \n1: Web_add_cookies \n2: Timestamps", "TLQE", JOptionPane.INFORMATION_MESSAGE);
}else if (option == JOptionPane.CANCEL_OPTION) {
JPanel panelCancel = new JPanel(new GridLayout(1, 0));
JOptionPane.showMessageDialog(panelCancel, "Bye Bye", "TLQE", JOptionPane.INFORMATION_MESSAGE);
return;
}
File fileTemp = new File(outFile);
if (fileTemp.exists()) {
fileTemp.delete();
}
try {
String fileName = inFile + "";
FileInputStream fstream = new FileInputStream(fileName);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
FileWriter fOutstream = new FileWriter(outFile, true);
BufferedWriter out = new BufferedWriter(fOutstream);
String newString = null;
String strLine;
while ((strLine = br.readLine()) != null){
try {
if (strLine.contains("web_add_cookie")) {
} else if (strLine
.contains("\"Name=_lastSubmitTimestamp\", \"Value=")) {
if (strLine.matches(".*[0-9].*")) {
newString = strLine
.replaceAll(strLine,
"\t\t\"Name=_lastSubmitTimestamp\", \"Value={tStamp}\", ENDITEM,");
out.write(newString);
} else
out.write(strLine);
} else if (strLine
.contains("\"Name=postTimestamp\", \"Value=")) {
if (strLine.matches(".*[0-9].*")) {
newString = strLine
.replaceAll(strLine,
"\t\t\"Name=postTimestamp\", \"Value={tStamp}\", ENDITEM,");
out.write(newString);
} else
out.write(strLine);
}else if (strLine.contains("web_submit_data")) {
out.write("\tweb_save_timestamp_param(\"tStamp\", LAST );");
out.newLine();
out.newLine();
out.write(strLine);
}else if (strLine.contains("web_custom_request(\"TealeafTarget.jsp")) {
out.newLine();
while ((strLine = br.readLine()) != null){
out.newLine();
if (strLine.contains("LAST")) {
break;
}
}
}else if (strLine.contains("web_url(\"SFXClientLogging")) {
while ((strLine = br.readLine()) != null){
if (strLine.contains("LAST")) {
break;
}
}
}else if (strLine.contains("EXTRARES")) {
out.write(strLine);
out.newLine();
while ((strLine = br.readLine()) != null){
if (strLine.contains("LAST")) {
out.write(strLine);
out.newLine();
break;
}else{
out.write("//" +strLine);
out.newLine();
}
}
}
else
out.write(strLine);
out.newLine();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
in.close();
out.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}
No comments:
Post a Comment