Skip to content

Commit ffc1e32

Browse files
committed
Updated toJSONObject(Reader reader, JSONPointer path) method to be more efficient.
1 parent d9172d1 commit ffc1e32

3 files changed

Lines changed: 106 additions & 160 deletions

File tree

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

Lines changed: 90 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -712,29 +712,108 @@ public static JSONObject toJSONObject(String string, XMLParserConfiguration conf
712712
//[RJ ADDED] Overloaded static method
713713
public static JSONObject toJSONObject(Reader reader, JSONPointer path)
714714
{
715-
//System.out.println("instantiated Rahul method");
715+
//Need substring to take out first / so can use split successfully.
716+
String[] pathArray = path.toString().substring(1).split("[\\\\/]", -1);
717+
int pathSize = pathArray.length;
718+
719+
716720
JSONObject jo = new JSONObject();
717721
XMLParserConfiguration config = new XMLParserConfiguration();
718722
XMLTokener x = new XMLTokener(reader);
723+
724+
//Find the last non-numerical tag in pathArray
725+
int containsNumber = 0; //index of array where number is
726+
for(int i = 0; i < pathSize; i ++)
727+
{
728+
if(pathArray[i].matches("-?\\d+(\\.\\d+)?"))
729+
{
730+
containsNumber = i;
731+
}
732+
}
733+
System.out.println("Contains number: " + containsNumber);
734+
String parseTag;// = (containsNumber == 0) ? pathArray[pathSize - 1] : pathArray[containsNumber - 1];
735+
if(containsNumber == 0)
736+
{
737+
parseTag = pathArray[pathSize -1];
738+
}
739+
else
740+
{
741+
if(pathSize < 2)
742+
{
743+
parseTag = pathArray[0];
744+
}
745+
else
746+
{
747+
parseTag = pathArray[containsNumber - 1];
748+
}
749+
}
750+
String remArr = "";
751+
752+
//Need to get the new string array that can use JSONPointer to solve
753+
if(containsNumber != 0)
754+
{
755+
for(int z = containsNumber-1; z < pathSize; z ++)
756+
remArr += "/" + pathArray[z];
757+
}
758+
759+
System.out.println("remArr: " + remArr);
760+
System.out.println("Parse Tag: " + parseTag);
761+
762+
//rebuild the sub xml
763+
String rebuildXML = "";
764+
boolean cycle = false;
765+
766+
String currTag ="";
767+
768+
String startString = "<" + parseTag + ">";
769+
String exitString = "</" + parseTag + ">";
770+
719771
while (x.more()) {
720772
x.skipPast("<");
721-
if(x.more()) {
722-
parse(x, jo, null, XMLParserConfiguration.ORIGINAL);
723-
//System.out.println(x.toString());
773+
currTag = "<" + x.nextContent();
774+
//System.out.println(currTag);
775+
776+
//Start recording after start string reached.
777+
if(currTag.equalsIgnoreCase(startString))
778+
cycle = true;
779+
780+
781+
if(cycle)
782+
{
783+
rebuildXML += currTag;
784+
//System.out.println("Pre If: " + currTag);
724785
}
786+
787+
//Start recording after start string reached.
788+
if(currTag.equalsIgnoreCase(exitString))
789+
{
790+
if(containsNumber != 0)
791+
cycle = false;
792+
else
793+
break;
794+
}
795+
}
796+
797+
System.out.println(rebuildXML);
798+
JSONObject query = XML.toJSONObject(rebuildXML);
799+
System.out.println(query.toString());
800+
801+
if(containsNumber != 0)
802+
{
803+
Object jsquery = query.query(remArr);
804+
//System.out.println(jsquery);
805+
query = (JSONObject) jsquery;
725806
}
726807

727808
//System.out.println("PrintingJSON");
728809

729-
Object query = jo.query(path.toString());
730-
System.out.println(query);
731-
return (JSONObject) query;
810+
return query;
732811

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()))));
812+
}
737813

814+
public static JSONObject toJSONObject(Reader reader, JSONPointer path, JSONObject replacement)
815+
{
816+
return null;
738817
}
739818

740819
/**

src/test/java/org/json/junit/XMLTest_SWE262.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void testMethodOne() {
3434

3535
try {
3636
FileReader filereader = new FileReader("src/test/resources/file.xml");
37-
JSONObject jo = XML.toJSONObject(filereader, new JSONPointer("/clinical_study"));
37+
JSONObject jo = XML.toJSONObject(filereader, new JSONPointer("/clinical_study/required_header/1"));
3838

3939
System.out.println(jo);
4040

src/test/resources/file.xml

Lines changed: 15 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<clinical_study>
3-
<!-- This xml conforms to an XML Schema at:
4-
https://clinicaltrials.gov/ct2/html/images/info/public.xsd -->
53
<required_header>
6-
<download_date>ClinicalTrials.gov processed this data on July 19, 2020</download_date>
4+
<download_date>11ClinicalTrials.gov processed this data on July 19, 2020</download_date>
5+
<link_text>Link to the current ClinicalTrials.gov record.</link_text>
6+
<url>https://clinicaltrials.gov/show/NCT03874338</url>
7+
</required_header>
8+
<required_header>
9+
<download_date>22ClinicalTrials.gov processed this data on July 19, 2020</download_date>
710
<link_text>Link to the current ClinicalTrials.gov record.</link_text>
811
<url>https://clinicaltrials.gov/show/NCT03874338</url>
912
</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>
13+
<required_header>
14+
<download_date>ClinicalTrials.gov processed this data on July 19, 2020</download_date>
15+
<link_text>Link to the current ClinicalTrials.gov record.</link_text>
16+
<url>https://clinicaltrials.gov/show/NCT03874338</url>
17+
</required_header><required_header>
18+
<download_date>ClinicalTrials.gov processed this data on July 19, 2020</download_date>
19+
<link_text>Link to the current ClinicalTrials.gov record.</link_text>
20+
<url>https://clinicaltrials.gov/show/NCT03874338</url>
21+
</required_header>
1722
<sponsors>
1823
<lead_sponsor>
1924
<agency>NYU Langone Health</agency>
@@ -28,142 +33,4 @@
2833
<agency_class>NIH</agency_class>
2934
</collaborator>
3035
</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 -->
16936
</clinical_study>

0 commit comments

Comments
 (0)