|
@@ -150,6 +150,7 @@ type
|
|
|
memDataVariablesfldXPath: TStringField;
|
|
|
dxBarSubItem9: TdxBarSubItem;
|
|
|
tbbtnWebServicePerformance: TdxBarButton;
|
|
|
+ memDataVariablesfldContent: TStringField;
|
|
|
procedure FormShow(Sender: TObject);
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
procedure FormDestroy(Sender: TObject);
|
|
@@ -177,7 +178,6 @@ type
|
|
|
procedure tbbtnAutoOpenLastUsedClick(Sender: TObject);
|
|
|
procedure dxBarButton2Click(Sender: TObject);
|
|
|
procedure tbbtnAutoSaveProjectClick(Sender: TObject);
|
|
|
- procedure pmnuFormatJsonContentClick(Sender: TObject);
|
|
|
procedure EditorContentMouseUp(Sender: TObject; Button: TMouseButton;
|
|
|
Shift: TShiftState; X, Y: Integer);
|
|
|
procedure EditorPostDataMouseUp(Sender: TObject; Button: TMouseButton;
|
|
@@ -194,7 +194,6 @@ type
|
|
|
procedure btnCopyFullURLClick(Sender: TObject);
|
|
|
procedure EditorURLParamsMouseUp(Sender: TObject; Button: TMouseButton;
|
|
|
Shift: TShiftState; X, Y: Integer);
|
|
|
- procedure pmnuFormatXMLClick(Sender: TObject);
|
|
|
procedure pmnuCompactXMLClick(Sender: TObject);
|
|
|
procedure comboPostContentTypePropertiesChange(Sender: TObject);
|
|
|
procedure pmnuBiggerEditorClick(Sender: TObject);
|
|
@@ -218,6 +217,7 @@ type
|
|
|
procedure memDataPresetsBeforeScroll(DataSet: TDataSet);
|
|
|
procedure cxGridDBTableViewDblClick(Sender: TObject);
|
|
|
procedure tbbtnWebServicePerformanceClick(Sender: TObject);
|
|
|
+ procedure pmnuFormatJsonContentClick(Sender: TObject);
|
|
|
private
|
|
|
FProjectConfig: TJSONConfig;
|
|
|
FActiveProject: string;
|
|
@@ -225,6 +225,7 @@ type
|
|
|
FTempProjectFile: string;
|
|
|
FRoamingSavePath: string;
|
|
|
FSearchFromCaret: Boolean;
|
|
|
+ FLastResponseContent: string;
|
|
|
FHTTP: TIdHTTP;
|
|
|
function GetTempProjectFile: string;
|
|
|
procedure UpdateFullURL;
|
|
@@ -246,6 +247,7 @@ type
|
|
|
function Encode(const AText: string): string;
|
|
|
function Decode(const AText: string): string;
|
|
|
function ReplaceGlobalVar(const AText: string): string;
|
|
|
+ procedure ParseAndFormatJsonAndXML(const AFormatted: Boolean);
|
|
|
function GetAppVersion: string;
|
|
|
public
|
|
|
MainConfig: TJSONConfig;
|
|
@@ -702,6 +704,11 @@ begin
|
|
|
ActiveEditor.CutToClipboard;
|
|
|
end;
|
|
|
|
|
|
+procedure TfrmMain.pmnuFormatJsonContentClick(Sender: TObject);
|
|
|
+begin
|
|
|
+ ParseAndFormatJsonAndXML(True);
|
|
|
+end;
|
|
|
+
|
|
|
procedure TfrmMain.DeactivatePresetEvents;
|
|
|
begin
|
|
|
memDataPresets.BeforeScroll := nil;
|
|
@@ -1389,6 +1396,134 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
+procedure TfrmMain.ParseAndFormatJsonAndXML(const AFormatted: Boolean);
|
|
|
+var
|
|
|
+ ja: TJsonArray;
|
|
|
+ jo: TJsonObject;
|
|
|
+ xml: TRwDomDocument;
|
|
|
+begin
|
|
|
+ if ActiveEditor.Lines.Count > 0 then
|
|
|
+ begin
|
|
|
+ if Length(ActiveEditor.Lines[0]) > 0 then
|
|
|
+ begin
|
|
|
+ if Pos('/json', FLastResponseContent) > 0 then
|
|
|
+ begin
|
|
|
+ EditorContent.Highlighter := SynJSONSyn;
|
|
|
+
|
|
|
+ if ActiveEditor.Lines[0][1] = '{' then
|
|
|
+ begin
|
|
|
+ jo := TJsonObject.Create;
|
|
|
+ Screen.Cursor := crHourGlass;
|
|
|
+ try
|
|
|
+ try
|
|
|
+ jo.FromJSON(ActiveEditor.Lines.Text);
|
|
|
+ except
|
|
|
+ on E: Exception do
|
|
|
+ begin
|
|
|
+ ShowError(E.Message);
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+ UpdateEditor(jo.ToJSON(not AFormatted));
|
|
|
+
|
|
|
+ memDataVariables.First;
|
|
|
+ while not memDataVariables.Eof do
|
|
|
+ begin
|
|
|
+ if (memDataVariablesfldType.Value = 'XPath') and (memDataVariablesfldContent.Value = 'JSON') then
|
|
|
+ begin
|
|
|
+ memDataVariables.Edit;
|
|
|
+ memDataVariablesfldValue.Value := jo.Path[memDataVariablesfldXPath.Value].Value;
|
|
|
+ memDataVariables.Post;
|
|
|
+ SaveProject;
|
|
|
+ end;
|
|
|
+ memDataVariables.Next;
|
|
|
+ end;
|
|
|
+
|
|
|
+ finally
|
|
|
+ Screen.Cursor := crDefault;
|
|
|
+ jo.Free;
|
|
|
+ end;
|
|
|
+ end
|
|
|
+ else
|
|
|
+ if ActiveEditor.Lines[0][1] = '[' then
|
|
|
+ begin
|
|
|
+ ja := TJsonArray.Create;
|
|
|
+ Screen.Cursor := crHourGlass;
|
|
|
+ try
|
|
|
+ try
|
|
|
+ ja.FromJSON(ActiveEditor.Lines.Text);
|
|
|
+ except
|
|
|
+ on E: Exception do
|
|
|
+ begin
|
|
|
+ ShowError(E.Message);
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+ UpdateEditor(ja.ToJSON(not AFormatted));
|
|
|
+
|
|
|
+ // XPath not supported on Json Arrays only Json Objects, do nothing here
|
|
|
+
|
|
|
+ finally
|
|
|
+ Screen.Cursor := crDefault;
|
|
|
+ ja.Free;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+ end
|
|
|
+ else
|
|
|
+ if Pos('/xml', FLastResponseContent) > 0 then
|
|
|
+ begin
|
|
|
+ EditorContent.Highlighter := SynXMLSyn;
|
|
|
+
|
|
|
+ xml := TRwDOMDocument.Create;
|
|
|
+ try
|
|
|
+ Screen.Cursor := crHourGlass;
|
|
|
+ xml.LoadXML(ActiveEditor.Lines.Text);
|
|
|
+ if AFormatted then
|
|
|
+ begin
|
|
|
+ UpdateEditor(xml.FormattedXML);
|
|
|
+ end
|
|
|
+ else
|
|
|
+ begin
|
|
|
+ UpdateEditor(xml.XML);
|
|
|
+ end;
|
|
|
+
|
|
|
+ memDataVariables.First;
|
|
|
+ while not memDataVariables.Eof do
|
|
|
+ begin
|
|
|
+ if (memDataVariablesfldType.Value = 'XPath') and (memDataVariablesfldContent.Value = 'XML') then
|
|
|
+ begin
|
|
|
+ memDataVariables.Edit;
|
|
|
+ try
|
|
|
+ if Assigned(xml.SelectSingleNode(memDataVariablesfldXPath.Value)) then
|
|
|
+ begin
|
|
|
+ memDataVariablesfldValue.Value := xml.SelectSingleNode(memDataVariablesfldXPath.Value).NodeValue;
|
|
|
+ end;
|
|
|
+ except
|
|
|
+ ShowMessage('nei');
|
|
|
+ end;
|
|
|
+ memDataVariables.Post;
|
|
|
+ SaveProject;
|
|
|
+ end;
|
|
|
+ memDataVariables.Next;
|
|
|
+ end;
|
|
|
+
|
|
|
+
|
|
|
+ finally
|
|
|
+ xml.Free;
|
|
|
+ Screen.Cursor := crDefault;
|
|
|
+ end;
|
|
|
+ end
|
|
|
+ else
|
|
|
+ if Pos('text/html', FLastResponseContent) > 0 then
|
|
|
+ begin
|
|
|
+ EditorContent.Highlighter := SynHTMLSyn;
|
|
|
+ end
|
|
|
+ else
|
|
|
+ begin
|
|
|
+ EditorContent.Highlighter := nil;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
procedure TfrmMain.pmnuPasteJsonContentClick(Sender: TObject);
|
|
|
begin
|
|
|
ActiveEditor.PasteFromClipboard;
|
|
@@ -1447,73 +1582,6 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
-procedure TfrmMain.pmnuFormatJsonContentClick(Sender: TObject);
|
|
|
-var
|
|
|
- ja: TJsonArray;
|
|
|
- jo: TJsonObject;
|
|
|
-begin
|
|
|
- if ActiveEditor.Lines.Count > 0 then
|
|
|
- begin
|
|
|
- if Length(ActiveEditor.Lines[0]) > 0 then
|
|
|
- begin
|
|
|
- if ActiveEditor.Lines[0][1] = '{' then
|
|
|
- begin
|
|
|
- jo := TJsonObject.Create;
|
|
|
- Screen.Cursor := crHourGlass;
|
|
|
- try
|
|
|
- try
|
|
|
- jo.FromJSON(ActiveEditor.Lines.Text);
|
|
|
- except
|
|
|
- on E: Exception do
|
|
|
- begin
|
|
|
- ShowError(E.Message);
|
|
|
- end;
|
|
|
- end;
|
|
|
- UpdateEditor(jo.ToJSON(False));
|
|
|
- finally
|
|
|
- Screen.Cursor := crDefault;
|
|
|
- jo.Free;
|
|
|
- end;
|
|
|
- end
|
|
|
- else
|
|
|
- if ActiveEditor.Lines[0][1] = '[' then
|
|
|
- begin
|
|
|
- ja := TJsonArray.Create;
|
|
|
- Screen.Cursor := crHourGlass;
|
|
|
- try
|
|
|
- try
|
|
|
- ja.FromJSON(ActiveEditor.Lines.Text);
|
|
|
- except
|
|
|
- on E: Exception do
|
|
|
- begin
|
|
|
- ShowError(E.Message);
|
|
|
- end;
|
|
|
- end;
|
|
|
- UpdateEditor(ja.ToJSON(False));
|
|
|
- finally
|
|
|
- Screen.Cursor := crDefault;
|
|
|
- ja.Free;
|
|
|
- end;
|
|
|
- end;
|
|
|
- end;
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure TfrmMain.pmnuFormatXMLClick(Sender: TObject);
|
|
|
-var
|
|
|
- xml: TRwDomDocument;
|
|
|
-begin
|
|
|
- xml := TRwDOMDocument.Create;
|
|
|
- try
|
|
|
- Screen.Cursor := crHourGlass;
|
|
|
- xml.LoadXML(ActiveEditor.Lines.Text);
|
|
|
- UpdateEditor(xml.FormattedXML);
|
|
|
- finally
|
|
|
- xml.Free;
|
|
|
- Screen.Cursor := crDefault;
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
function TfrmMain.ReplaceGlobalVar(const AText: string): string;
|
|
|
begin
|
|
|
Result := AText;
|
|
@@ -1529,14 +1597,7 @@ begin
|
|
|
SaveProject;
|
|
|
end;
|
|
|
|
|
|
- if memDataVariablesfldType.Value = 'XPath' then
|
|
|
- begin
|
|
|
- //match := TRegEx.Match(AText, memDataVariablesfldName.Value, [roMultiLine]).Value;
|
|
|
- end
|
|
|
- else
|
|
|
- begin
|
|
|
- Result := StringReplace(Result, memDataVariablesfldName.Value, memDataVariablesfldValue.Value, [rfReplaceAll]);
|
|
|
- end;
|
|
|
+ Result := StringReplace(Result, memDataVariablesfldName.Value, memDataVariablesfldValue.Value, [rfReplaceAll]);
|
|
|
|
|
|
memDataVariables.Next;
|
|
|
end;
|
|
@@ -1624,35 +1685,8 @@ begin
|
|
|
ActiveEditor := EditorContent;
|
|
|
EditorContent.SetFocus;
|
|
|
|
|
|
- if Pos('application/json', FHTTP.Response.ContentType) > 0 then
|
|
|
- begin
|
|
|
- EditorContent.Highlighter := SynJSONSyn;
|
|
|
-
|
|
|
- if chkResponseAutoformat.Checked then
|
|
|
- begin
|
|
|
- pmnuFormatJsonContentClick(nil);
|
|
|
- end;
|
|
|
- end
|
|
|
- else
|
|
|
- if Pos('text/xml', FHTTP.Response.ContentType) > 0 then
|
|
|
- begin
|
|
|
- EditorContent.Highlighter := SynXMLSyn;
|
|
|
-
|
|
|
- if chkResponseAutoformat.Checked then
|
|
|
- begin
|
|
|
- pmnuFormatXMLClick(nil);
|
|
|
- end;
|
|
|
- end
|
|
|
- else
|
|
|
- if Pos('text/html', FHTTP.Response.ContentType) > 0 then
|
|
|
- begin
|
|
|
- EditorContent.Highlighter := SynHTMLSyn;
|
|
|
- end
|
|
|
- else
|
|
|
- begin
|
|
|
- EditorContent.Highlighter := nil;
|
|
|
- end;
|
|
|
-
|
|
|
+ FLastResponseContent := FHTTP.Response.ContentType;
|
|
|
+ ParseAndFormatJsonAndXML(chkResponseAutoformat.Checked);
|
|
|
|
|
|
|
|
|
dxStatusBarResponse.Panels[0].Text := FormatFloat('Response Time: 0, ms', GetTickCount - tick);
|