1
2
3
4
5 package org.kuali.coeus.s2sgen.impl.hash;
6
7 import org.kuali.coeus.s2sgen.impl.util.XPathExecutor;
8 import org.w3c.dom.Attr;
9 import org.w3c.dom.Element;
10 import org.w3c.dom.Node;
11
12 import javax.xml.transform.TransformerException;
13
14
15
16
17 public class GrantApplicationXpath
18 {
19
20 private static final String HASH_ALGORITHM = "glob:hashAlgorithm";
21 private static final String SHA_1 = "SHA";
22
23 public static final String GS_HEADER_XPATH = "/*[namespace-uri()='http://apply.grants.gov/system/MetaGrantApplication' and local-name()='GrantApplication']/*[namespace-uri()='http://apply.grants.gov/system/Header-V1.0' and local-name()='GrantSubmissionHeader']";
24 public static final String OPPORTUNITY_ID_XPATH = GS_HEADER_XPATH
25 + "/*[namespace-uri()='http://apply.grants.gov/system/Header-V1.0' and local-name()='OpportunityID']";
26 public static final String CFDA_NUMBER_XPATH = GS_HEADER_XPATH
27 + "/*[namespace-uri()='http://apply.grants.gov/system/Header-V1.0' and local-name()='CFDANumber']";
28 public static final String OPPORTUNITY_TITLE_XPATH = GS_HEADER_XPATH
29 + "/*[namespace-uri()='http://apply.grants.gov/system/Header-V1.0' and local-name()='OpportunityTitle']";
30 public static final String CLOSING_DATE_XPATH = GS_HEADER_XPATH
31 + "/*[namespace-uri()='http://apply.grants.gov/system/Header-V1.0' and local-name()='ClosingDate']";
32 public static final String AGENCY_NAME_XPATH = GS_HEADER_XPATH
33 + "/*[namespace-uri()='http://apply.grants.gov/system/Header-V1.0' and local-name()='AgencyName']";
34 public static final String COMPETITION_ID_XPATH = GS_HEADER_XPATH
35 + "/*[namespace-uri()='http://apply.grants.gov/system/Header-V1.0' and local-name()='CompetitionID']";
36 public static final String SUBMISSION_TITLE_XPATH = GS_HEADER_XPATH
37 + "/*[namespace-uri()='http://apply.grants.gov/system/Header-V1.0' and local-name()='SubmissionTitle']";
38 public static final String HASHVALUE = "glob:HashValue";
39 public static final String FORMS_XPATH = "//*[local-name(.) = 'Forms' and namespace-uri(.) = 'http://apply.grants.gov/system/MetaGrantApplication']";
40 public static final String HEADER_XPATH = "//*[local-name(.) = 'GrantSubmissionHeader' and namespace-uri(.) = 'http://apply.grants.gov/system/Header-V1.0']";
41 public static final String HASH_XPATH = "//*[local-name(.) = 'GrantSubmissionHeader' and namespace-uri(.) = 'http://apply.grants.gov/system/Header-V1.0']/*[local-name(.) = 'HashValue' and namespace-uri(.) = 'http://apply.grants.gov/system/Global-V1.0']";
42 public static final String GLOBAL_NS = "http://apply.grants.gov/system/Global-V1.0";
43
44 private XPathExecutor executor;
45
46 public GrantApplicationXpath(String xmlDoc)
47 throws Exception
48 {
49 setExecutor(createExecutor(xmlDoc));
50
51 }
52
53
54
55
56 public XPathExecutor getExecutor()
57 {
58 return executor;
59 }
60
61
62
63
64
65 public void setExecutor(XPathExecutor executor)
66 {
67 this.executor = executor;
68 }
69
70 private XPathExecutor createExecutor(String xmlDoc)
71 throws Exception
72 {
73 return new XPathExecutor(xmlDoc);
74 }
75
76
77
78
79
80
81
82
83 public Node getFormsNode()
84 throws TransformerException
85 {
86 return getExecutor().getNode(FORMS_XPATH);
87 }
88
89
90
91
92
93
94
95
96
97 public Node getHeaderNode()
98 throws TransformerException
99 {
100 return getExecutor().getNode(HEADER_XPATH);
101 }
102
103
104
105
106
107
108
109
110
111 public Node getHashNode()
112 throws TransformerException
113 {
114 Node hashNode = getExecutor().getNode(HASH_XPATH);
115 if (hashNode == null)
116 {
117 hashNode = getExecutor().getDoc().createElementNS(GLOBAL_NS,
118 HASHVALUE);
119 Attr algorithm = getExecutor().getDoc().createAttributeNS(GLOBAL_NS, HASH_ALGORITHM);
120 algorithm.setValue(SHA_1);
121 ((Element) hashNode).setAttributeNodeNS(algorithm);
122 hashNode.appendChild(getExecutor().getDoc().createTextNode(""));
123 Node header = getHeaderNode();
124 header.insertBefore(hashNode, header.getFirstChild());
125 }
126 return hashNode;
127 }
128
129
130
131
132
133
134
135
136
137 public String getHeaderHashValue()
138 throws Exception
139 {
140 return getExecutor().execute(HASH_XPATH);
141 }
142
143
144
145
146 public String getAgencyName()
147 throws Exception
148 {
149 return getExecutor().execute(AGENCY_NAME_XPATH);
150 }
151
152
153
154
155 public String getCfdaNumber()
156 throws Exception
157 {
158 return getExecutor().execute(CFDA_NUMBER_XPATH);
159 }
160
161
162
163
164 public String getClosingDate()
165 throws Exception
166 {
167 return getExecutor().execute(CLOSING_DATE_XPATH);
168 }
169
170
171
172
173 public String getOpportunityId()
174 throws Exception
175 {
176 return getExecutor().execute(OPPORTUNITY_ID_XPATH);
177 }
178
179
180
181
182
183 public String getOpportunityTitle()
184 throws Exception
185 {
186 return getExecutor().execute(OPPORTUNITY_TITLE_XPATH);
187 }
188
189
190
191
192
193 public String getCompetitionId()
194 throws Exception
195 {
196 return getExecutor().execute(COMPETITION_ID_XPATH);
197 }
198
199
200
201
202
203 public String getSubmissionTitle()
204 throws Exception
205 {
206 return getExecutor().execute(SUBMISSION_TITLE_XPATH);
207 }
208 }