keys = jo.keys();
65 | while (keys.hasNext()) {
66 | String name = keys.next();
67 | properties.put(name, jo.getString(name));
68 | }
69 | }
70 | return properties;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/org/json/JSONStringer.java:
--------------------------------------------------------------------------------
1 | package org.json;
2 |
3 | /*
4 | Copyright (c) 2006 JSON.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | The Software shall be used for Good, not Evil.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | SOFTWARE.
25 | */
26 |
27 | import java.io.StringWriter;
28 |
29 | /**
30 | * JSONStringer provides a quick and convenient way of producing JSON text.
31 | * The texts produced strictly conform to JSON syntax rules. No whitespace is
32 | * added, so the results are ready for transmission or storage. Each instance of
33 | * JSONStringer can produce one JSON text.
34 | *
35 | * A JSONStringer instance provides a value method for appending
36 | * values to the
37 | * text, and a key
38 | * method for adding keys before values in objects. There are array
39 | * and endArray methods that make and bound array values, and
40 | * object and endObject methods which make and bound
41 | * object values. All of these methods return the JSONWriter instance,
42 | * permitting cascade style. For example,
43 | * myString = new JSONStringer()
44 | * .object()
45 | * .key("JSON")
46 | * .value("Hello, World!")
47 | * .endObject()
48 | * .toString(); which produces the string
49 | * {"JSON":"Hello, World!"}
50 | *
51 | * The first method called must be array or object.
52 | * There are no methods for adding commas or colons. JSONStringer adds them for
53 | * you. Objects and arrays can be nested up to 20 levels deep.
54 | *
55 | * This can sometimes be easier than using a JSONObject to build a string.
56 | * @author JSON.org
57 | * @version 2015-12-09
58 | */
59 | public class JSONStringer extends JSONWriter {
60 | /**
61 | * Make a fresh JSONStringer. It can be used to build one JSON text.
62 | */
63 | public JSONStringer() {
64 | super(new StringWriter());
65 | }
66 |
67 | /**
68 | * Return the JSON text. This method is used to obtain the product of the
69 | * JSONStringer instance. It will return null if there was a
70 | * problem in the construction of the JSON text (such as the calls to
71 | * array were not properly balanced with calls to
72 | * endArray).
73 | * @return The JSON text.
74 | */
75 | public String toString() {
76 | return this.mode == 'd' ? this.writer.toString() : null;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/pse_gui/ResponseHandler.java:
--------------------------------------------------------------------------------
1 | package pse_gui;
2 | import java.util.ArrayList;
3 | import java.util.Map;
4 |
5 | import javafx.scene.control.Alert;
6 | import javafx.scene.control.ScrollPane;
7 | import javafx.scene.control.Alert.AlertType;
8 | import javafx.scene.layout.GridPane;
9 | import javafx.scene.layout.Priority;
10 | import javafx.scene.web.WebEngine;
11 | import javafx.scene.web.WebView;
12 |
13 | // The interface that is used to handle responses from the JSON thing
14 | @SuppressWarnings("restriction")
15 | public abstract class ResponseHandler {
16 |
17 | private SyntaxAnalyzer syntaxAnalyzer;
18 | private Boolean bypassIfError;
19 | public ResponseHandler(Boolean bypassIfError){
20 | syntaxAnalyzer = new SyntaxAnalyzer();
21 | this.bypassIfError = bypassIfError;
22 | }
23 |
24 | @SuppressWarnings("unchecked")
25 | public void handleResponse(JSON json){
26 | ServerResponse serverResponse = syntaxAnalyzer.jsonToServerResponse(json);
27 | baseHandleResponse(serverResponse);
28 |
29 | if(bypassIfError)
30 | return;
31 |
32 | Map map = serverResponse.getValue();
33 | for(String item : map.keySet()){
34 | if(map.get(item) instanceof Map,?>){
35 | Map map2 = (Map) map.get(item);
36 | if(map2.containsKey(PSEConstants.MESSAGE_KEY) || map2.containsKey(PSEConstants.ERROR_KEY)){
37 | showOutput(map2);
38 | }
39 | else if(map2.containsKey(PSEConstants.EXCEPTION_KEY)){
40 | showException(map2);
41 | }
42 | }
43 | else{
44 | if(item.equals(PSEConstants.MESSAGE_KEY) || item.equals(PSEConstants.ERROR_KEY)){
45 | showOutput(map);
46 | }
47 | else if(item.equals(PSEConstants.EXCEPTION_KEY)){
48 | showException(map);
49 | }
50 | }
51 | }
52 |
53 | }
54 |
55 | private void showOutput(Map map){
56 | String key = "";
57 | AlertType alertType = null;
58 | String messageType = "";
59 | if (map.containsKey(PSEConstants.MESSAGE_KEY)){
60 | key = PSEConstants.MESSAGE_KEY;
61 | alertType = AlertType.INFORMATION;
62 | messageType = "Message";
63 | }
64 | else if (map.containsKey(PSEConstants.ERROR_KEY)){
65 | key = PSEConstants.ERROR_KEY;
66 | alertType = AlertType.ERROR;
67 | messageType = "Error";
68 | }
69 |
70 | Alert alert = new Alert(alertType);
71 | alert.setTitle("PowerShell Empire GUI");
72 | alert.setHeaderText(messageType);
73 | WebView browser = new WebView();
74 | WebEngine engine = browser.getEngine();
75 |
76 | ScrollPane scrollPane = new ScrollPane();
77 | scrollPane.setContent(browser);
78 | engine.loadContent((String) map.get(key.toString()));
79 |
80 | GridPane.setVgrow(scrollPane, Priority.ALWAYS);
81 | GridPane.setHgrow(scrollPane, Priority.ALWAYS);
82 |
83 | GridPane content = new GridPane();
84 | content.setMaxWidth(Double.MAX_VALUE);
85 | content.add(scrollPane, 0, 0);
86 |
87 | alert.getDialogPane().setContent(content);
88 |
89 | alert.showAndWait();
90 | }
91 |
92 | @SuppressWarnings("unchecked")
93 | private void showException(Map map){
94 | ArrayList