Skip to content

Commit d9172d1

Browse files
committed
Added first toJSONObject(Reader reader, JSONPointer path) class. Also added test cases in XMLTest_SWE262 under tests folder.
1 parent e33f463 commit d9172d1

3 files changed

Lines changed: 246 additions & 0 deletions

File tree

src/main/java/org/json/XML.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,34 @@ public static JSONObject toJSONObject(String string, XMLParserConfiguration conf
709709
return toJSONObject(new StringReader(string), config);
710710
}
711711

712+
//[RJ ADDED] Overloaded static method
713+
public static JSONObject toJSONObject(Reader reader, JSONPointer path)
714+
{
715+
//System.out.println("instantiated Rahul method");
716+
JSONObject jo = new JSONObject();
717+
XMLParserConfiguration config = new XMLParserConfiguration();
718+
XMLTokener x = new XMLTokener(reader);
719+
while (x.more()) {
720+
x.skipPast("<");
721+
if(x.more()) {
722+
parse(x, jo, null, XMLParserConfiguration.ORIGINAL);
723+
//System.out.println(x.toString());
724+
}
725+
}
726+
727+
//System.out.println("PrintingJSON");
728+
729+
Object query = jo.query(path.toString());
730+
System.out.println(query);
731+
return (JSONObject) query;
732+
733+
//System.out.println(checkPath);
734+
// return XML.toJSONObject(checkPath.toString());
735+
// System.out.println(checkPath);
736+
//return jo;//(new JSONObject((jo.query(path.toString()))));
737+
738+
}
739+
712740
/**
713741
* Convert a JSONObject into a well-formed, element-normal XML string.
714742
*
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.json.junit;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertNotEquals;
6+
import static org.junit.Assert.assertTrue;
7+
import static org.junit.Assert.fail;
8+
9+
import java.io.*;
10+
import java.util.HashMap;
11+
import java.util.Map;
12+
13+
import org.json.*;
14+
import org.junit.Rule;
15+
import org.junit.Test;
16+
import org.junit.rules.TemporaryFolder;
17+
18+
public class XMLTest_SWE262 {
19+
/**
20+
* JUnit supports temporary files and folders that are cleaned up after the test.
21+
* https://garygregory.wordpress.com/2010/01/20/junit-tip-use-rules-to-manage-temporary-files-and-folders/
22+
*/
23+
@Rule
24+
public TemporaryFolder testFolder = new TemporaryFolder();
25+
26+
27+
/**
28+
* Empty JSONObject from a non-XML string.
29+
*/
30+
@Test
31+
public void testMethodOne() {
32+
33+
System.out.println("Rahul Hello World");
34+
35+
try {
36+
FileReader filereader = new FileReader("src/test/resources/file.xml");
37+
JSONObject jo = XML.toJSONObject(filereader, new JSONPointer("/clinical_study"));
38+
39+
System.out.println(jo);
40+
41+
} catch (FileNotFoundException e) {
42+
System.out.println("File not found");
43+
e.printStackTrace();
44+
}
45+
//String xmlStr = "{ \"this is\": \"not xml\"}";
46+
//JSONObject jsonObject = XML.toJSONObject(xmlStr);
47+
//assertTrue("xml string should be empty", jsonObject.isEmpty());
48+
}
49+
}

src/test/resources/file.xml

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<clinical_study>
3+
<!-- This xml conforms to an XML Schema at:
4+
https://clinicaltrials.gov/ct2/html/images/info/public.xsd -->
5+
<required_header>
6+
<download_date>ClinicalTrials.gov processed this data on July 19, 2020</download_date>
7+
<link_text>Link to the current ClinicalTrials.gov record.</link_text>
8+
<url>https://clinicaltrials.gov/show/NCT03874338</url>
9+
</required_header>
10+
<id_info>
11+
<org_study_id>18-01323</org_study_id>
12+
<secondary_id>1R01HL146206</secondary_id>
13+
<nct_id>NCT03874338</nct_id>
14+
</id_info>
15+
<brief_title>CLEAR SYNERGY Neutrophil Substudy</brief_title>
16+
<official_title>Studies on the Effects of Colchicine on Neutrophil Biology in Acute Myocardial Infarction: A Substudy of the CLEAR SYNERGY (OASIS 9) Trial</official_title>
17+
<sponsors>
18+
<lead_sponsor>
19+
<agency>NYU Langone Health</agency>
20+
<agency_class>Other</agency_class>
21+
</lead_sponsor>
22+
<collaborator>
23+
<agency>Population Health Research Institute</agency>
24+
<agency_class>Other</agency_class>
25+
</collaborator>
26+
<collaborator>
27+
<agency>National Heart, Lung, and Blood Institute (NHLBI)</agency>
28+
<agency_class>NIH</agency_class>
29+
</collaborator>
30+
</sponsors>
31+
<source>NYU Langone Health</source>
32+
<oversight_info>
33+
<has_dmc>No</has_dmc>
34+
<is_fda_regulated_drug>No</is_fda_regulated_drug>
35+
<is_fda_regulated_device>No</is_fda_regulated_device>
36+
</oversight_info>
37+
<brief_summary>
38+
<textblock>
39+
CLEAR SYNERGY is an international multi center 2x2 randomized placebo controlled trial of
40+
</textblock>
41+
</brief_summary>
42+
<overall_status>Recruiting</overall_status>
43+
<start_date type="Actual">March 4, 2019</start_date>
44+
<completion_date type="Anticipated">February 1, 2022</completion_date>
45+
<primary_completion_date type="Anticipated">February 1, 2021</primary_completion_date>
46+
<study_type>Observational</study_type>
47+
<has_expanded_access>No</has_expanded_access>
48+
<study_design_info>
49+
<observational_model>Other</observational_model>
50+
<time_perspective>Prospective</time_perspective>
51+
</study_design_info>
52+
<primary_outcome>
53+
<measure>soluble L-selectin</measure>
54+
<time_frame>between baseline and 3 months</time_frame>
55+
<description>Change in soluble L-selectin between baseline and 3 mo after STEMI in the placebo vs. colchicine groups.</description>
56+
</primary_outcome>
57+
<secondary_outcome>
58+
<measure>Other soluble markers of neutrophil activity</measure>
59+
<time_frame>between baseline and 3 months</time_frame>
60+
<description>Other markers of neutrophil activity will be evaluated at baseline and 3 months after STEMI (myeloperoxidase, matrix metalloproteinase-9, neutrophil gelatinase-associated lipocalin, neutrophil elastase, intercellular/vascular cellular adhesion molecules)</description>
61+
</secondary_outcome>
62+
<secondary_outcome>
63+
<measure>Markers of systemic inflammation</measure>
64+
<time_frame>between baseline and 3 months</time_frame>
65+
<description>Markers of systemic inflammation will be evaluated at baseline and 3 months after STEMI (high sensitive CRP, IL-1β)</description>
66+
</secondary_outcome>
67+
<secondary_outcome>
68+
<measure>Neutrophil-driven responses that may further propagate injury</measure>
69+
<time_frame>between baseline and 3 months</time_frame>
70+
<description>Neutrophil-driven responses that may further propagate injury will be evaluated at baseline and 3 months after STEMI (neutrophil extracellular traps, neutrophil-derived microparticles)</description>
71+
</secondary_outcome>
72+
<number_of_groups>2</number_of_groups>
73+
<enrollment type="Anticipated">670</enrollment>
74+
<condition>Neutrophils.Hypersegmented ; Bld-Ser-Plas</condition>
75+
<condition>STEMI - ST Elevation Myocardial Infarction</condition>
76+
<arm_group>
77+
<arm_group_label>Colchicine</arm_group_label>
78+
</arm_group>
79+
<arm_group>
80+
<arm_group_label>Placebo</arm_group_label>
81+
</arm_group>
82+
<intervention>
83+
<intervention_type>Drug</intervention_type>
84+
<intervention_name>Colchicine Pill</intervention_name>
85+
<description>Participants in the main CLEAR SYNERGY trial are randomized to colchicine/spironolactone versus placebo in a 2x2 factorial design. The substudy is interested in the evaluation of biospecimens obtained from patients in the colchicine vs placebo group.</description>
86+
<arm_group_label>Colchicine</arm_group_label>
87+
<arm_group_label>Placebo</arm_group_label>
88+
</intervention>
89+
<eligibility>
90+
<study_pop>
91+
<textblock>
92+
Patients who are randomized to the drug RCT portion of the CLEAR SYNERGY (OASIS 9) trial
93+
</textblock>
94+
</study_pop>
95+
<sampling_method>Non-Probability Sample</sampling_method>
96+
<criteria>
97+
<textblock>
98+
Inclusion Criteria:
99+
</textblock>
100+
</criteria>
101+
<gender>All</gender>
102+
<minimum_age>19 Years</minimum_age>
103+
<maximum_age>110 Years</maximum_age>
104+
<healthy_volunteers>No</healthy_volunteers>
105+
</eligibility>
106+
<overall_official>
107+
<last_name>Binita Shah, MD</last_name>
108+
<role>Principal Investigator</role>
109+
<affiliation>NYU School of Medicine</affiliation>
110+
</overall_official>
111+
<overall_contact>
112+
<last_name>Fatmira Curovic</last_name>
113+
<phone>646-501-9648</phone>
114+
<email>[email protected]</email>
115+
</overall_contact>
116+
<overall_contact_backup>
117+
<last_name>Binita Shah, MD</last_name>
118+
</overall_contact_backup>
119+
<location>
120+
<facility>
121+
<name>NYU School of Medicine</name>
122+
<address>
123+
<city>New York</city>
124+
<state>New York</state>
125+
<zip>10016</zip>
126+
<country>United States</country>
127+
</address>
128+
</facility>
129+
<status>Recruiting</status>
130+
<contact>
131+
<last_name>Fatmira Curovic</last_name>
132+
<phone>646-501-9648</phone>
133+
<email>[email protected]</email>
134+
</contact>
135+
<contact_backup>
136+
<last_name>Binita Shah, MD</last_name>
137+
</contact_backup>
138+
</location>
139+
<location_countries>
140+
<country>United States</country>
141+
</location_countries>
142+
<verification_date>September 2019</verification_date>
143+
<study_first_submitted>March 12, 2019</study_first_submitted>
144+
<study_first_submitted_qc>March 12, 2019</study_first_submitted_qc>
145+
<study_first_posted type="Actual">March 14, 2019</study_first_posted>
146+
<last_update_submitted>September 10, 2019</last_update_submitted>
147+
<last_update_submitted_qc>September 10, 2019</last_update_submitted_qc>
148+
<last_update_posted type="Actual">September 12, 2019</last_update_posted>
149+
<responsible_party>
150+
<responsible_party_type>Principal Investigator</responsible_party_type>
151+
<investigator_affiliation>NYU Langone Health</investigator_affiliation>
152+
<investigator_full_name>Binita Shah</investigator_full_name>
153+
<investigator_title>Assistant Professor of Medicine</investigator_title>
154+
</responsible_party>
155+
<condition_browse>
156+
<!-- CAUTION: The following MeSH terms are assigned with an imperfect algorithm -->
157+
<mesh_term>Myocardial Infarction</mesh_term>
158+
<mesh_term>ST Elevation Myocardial Infarction</mesh_term>
159+
<mesh_term>Infarction</mesh_term>
160+
</condition_browse>
161+
<intervention_browse>
162+
<!-- CAUTION: The following MeSH terms are assigned with an imperfect algorithm -->
163+
<mesh_term>Colchicine</mesh_term>
164+
</intervention_browse>
165+
<patient_data>
166+
<sharing_ipd>No</sharing_ipd>
167+
</patient_data>
168+
<!-- Results have not yet been posted for this study -->
169+
</clinical_study>

0 commit comments

Comments
 (0)