Changeset 1187
- Timestamp:
- 04/01/11 20:04:33 (13 years ago)
- Location:
- MDService2/trunk/MDService2
- Files:
-
- 3 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService2/trunk/MDService2/WebContent/Exception.jsp
r466 r1187 11 11 <h2>MDService2: An error has occurred</h2> 12 12 <hr/> 13 <!-- <h3>Error Message</h3><span id="err_details_caller">details</span> --> 13 14 14 <s:property value="userMsg"/><br/> 15 15 <s:actionerror/> -
MDService2/trunk/MDService2/WebContent/scripts/mdservice_ui.js
r1177 r1187 53 53 function getSelectedRepository(){ 54 54 //var id = parseInt($('#repositories_select').find("option:selected").val()); 55 return $('#repositories_select').find("option:selected"). val();55 return $('#repositories_select').find("option:selected").text();//val(); 56 56 57 57 } -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/AdminAction.java
r1059 r1187 29 29 @Override 30 30 protected void initialize(){ 31 setRepository (0);31 setRepositoryByIndex(0); 32 32 } 33 33 public String getDate() { … … 79 79 clear_params.put("type", getActionkey()); 80 80 } 81 if (this.getRepository() != 0){81 if (this.getRepository() != null){ 82 82 clear_params.put("repository", String.valueOf(getRepository())); 83 83 } -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java
r1076 r1187 27 27 import com.opensymphony.xwork2.ActionSupport; 28 28 29 import eu.clarin.cmdi.mdservice.model.Diagnostics; 30 29 31 /** 30 32 * main Struts 2 controller … … 42 44 43 45 private static JSONArray repositories = null; 46 47 private Diagnostics diagnostics; 48 44 49 /** 45 50 * Properties to be filled by Struts with according request-parameters … … 60 65 private String actionContentType; 61 66 private String userMsg; 62 private intrepository;67 private String repository; 63 68 //private Map<String,Object> session; 64 69 private HttpServletRequest request; … … 70 75 } 71 76 77 public void setRepositoryByIndex(int id){ 78 try { 79 setRepositories(GenericProxyAction.createRepositories()); 80 // static repositories 81 net.sf.json.JSONArray json = getRepositories(); 82 if (json.size() > 0){ 83 repository = json.getJSONObject(id).getString("name"); 84 } 85 } catch (IOException e) { 86 // TODO Auto-generated catch block 87 e.printStackTrace(); 88 } catch (InterruptedException e) { 89 // TODO Auto-generated catch block 90 e.printStackTrace(); 91 } catch (TransformerException e) { 92 // TODO Auto-generated catch block 93 e.printStackTrace(); 94 } 95 } 96 72 97 protected void initialize(){ 73 repository = 1; 98 //repository = 1; 99 setRepositoryByIndex(0); 100 } 101 102 public Diagnostics getDiagnostics(){ 103 return this.diagnostics; 104 } 105 106 public void setDiagnostics(Diagnostics diagnostics){ 107 this.diagnostics = diagnostics; 108 } 109 public Diagnostics Diagnostics(){ 110 if (diagnostics == null){ 111 diagnostics = new Diagnostics(); 112 } 113 return this.diagnostics; 74 114 } 75 115 public String getQ() { … … 167 207 168 208 169 public void setRepository( intrepository) {209 public void setRepository(String repository) { 170 210 this.repository = repository; 171 211 } 172 212 173 public intgetRepository() {213 public String getRepository() { 174 214 //default repository = 1 (set on init) 175 176 215 return repository; 177 216 } … … 278 317 279 318 public void setRepositories(JSONArray rep){ 280 this.repositories = rep;319 GenericProxyAction.repositories = rep; 281 320 } 282 321 … … 453 492 net.sf.json.JSONArray json = getRepositories(); 454 493 for(int i=0;i<json.size();i++){ 455 if (json.getJSONObject(i).get Int("id") == getRepository()){494 if (json.getJSONObject(i).getString("name").equals(getRepository())){ 456 495 repository_path = json.getJSONObject(i).getString("uri"); 457 496 } … … 507 546 hm.put("q", getQ()); 508 547 } 509 if (getRepository() != 0){510 hm.put("repository_ id", String.valueOf(getRepository()));511 }548 //if (getRepository() != null){ 549 hm.put("repository_name", String.valueOf(getRepository())); 550 //} 512 551 513 552 return hm; -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/SRUProxyAction.java
r1184 r1187 3 3 import java.io.BufferedInputStream; 4 4 import java.io.BufferedReader; 5 import java.io.ByteArrayInputStream; 5 6 import java.io.File; 6 7 import java.io.FileInputStream; … … 8 9 import java.io.InputStream; 9 10 import java.io.InputStreamReader; 11 import java.io.StringWriter; 12 import java.io.UnsupportedEncodingException; 10 13 import java.net.MalformedURLException; 11 14 import java.net.URISyntaxException; … … 15 18 import javax.servlet.http.HttpServletRequest; 16 19 import javax.servlet.http.HttpSession; 20 import javax.xml.parsers.DocumentBuilder; 21 import javax.xml.parsers.DocumentBuilderFactory; 22 import javax.xml.parsers.ParserConfigurationException; 23 import javax.xml.transform.TransformerConfigurationException; 17 24 import javax.xml.transform.TransformerException; 25 import javax.xml.transform.TransformerFactory; 26 import javax.xml.transform.TransformerFactoryConfigurationError; 27 import javax.xml.transform.dom.DOMSource; 28 import javax.xml.transform.stream.StreamResult; 18 29 19 30 import net.sf.json.JSON; … … 26 37 import org.apache.commons.lang.StringEscapeUtils; 27 38 import org.apache.struts2.interceptor.ServletRequestAware; 39 import org.w3c.dom.Document; 40 import org.w3c.dom.Element; 41 import org.w3c.dom.Node; 42 import org.xml.sax.InputSource; 43 import org.xml.sax.SAXException; 28 44 29 45 import com.opensymphony.xwork2.ActionSupport; 30 46 31 /** 32 * main Struts 2 controller 33 * responds to requests (collections, model, recordset) 34 * by dispatching the requests to appropriate internal methods and filling the inputStream with the result 35 * 36 * @author vronk 37 * 38 */ 39 public class SRUProxyAction extends ActionSupport 47 import eu.clarin.cmdi.mdservice.model.Diagnostic; 48 import eu.clarin.cmdi.mdservice.model.Diagnostics; 49 50 51 public class SRUProxyAction extends ActionSupport 52 implements ServletRequestAware 40 53 { 41 54 42 55 private static final long serialVersionUID = 1L; 56 57 private Diagnostics diagnostics; 43 58 44 59 /** 45 60 * Properties to be filled by Struts with according request-parameters 46 61 */ 62 private String q; 47 63 private String version; 48 64 private String operation; … … 56 72 private String sortKeys; 57 73 private String stylesheet; 58 private String extraRequestData; 74 private String x_cmd_repository; 75 private String x_cmd_collections; 59 76 60 77 private MDRepoProxyAction mdrepoproxyaction; 61 78 private InputStream resultStream; 79 private HttpServletRequest request; 62 80 63 81 private final static HashMap<String,String> hash_operations = new HashMap<String,String>(); … … 76 94 } 77 95 96 @Override 97 public void setServletRequest(HttpServletRequest arg0) { 98 request = arg0; 99 } 100 101 public HttpServletRequest getServletRequest() { 102 return request; 103 } 104 105 public Diagnostics getDiagnostics(){ 106 return this.diagnostics; 107 } 108 109 public void setDiagnostics(Diagnostics diagnostics){ 110 this.diagnostics = diagnostics; 111 } 112 113 114 public String getQ() { 115 return q; 116 } 117 118 public void setQ(String q) { 119 this.q = q; 120 } 121 78 122 public InputStream getResultStream() { 79 123 return resultStream; … … 83 127 } 84 128 129 85 130 public String getVersion() { 86 131 return version; … … 170 215 } 171 216 172 public String getExtraRequestData() { 173 return extraRequestData; 174 } 175 176 public void setExtraRequestData(String extraRequestData) { 177 this.extraRequestData = extraRequestData; 178 } 179 180 217 public String getX_cmd_repository(){ 218 return x_cmd_repository; 219 } 220 221 public void setX_cmd_repository(String x_cmd_repository){ 222 this.x_cmd_repository = x_cmd_repository; 223 } 224 225 public String getX_cmd_collections(){ 226 return x_cmd_collections; 227 } 228 229 public void setX_cmd_collections(String x_cmd_collections){ 230 this.x_cmd_collections = x_cmd_collections; 231 } 232 233 234 public String getDiagnosticStreamName() throws TransformerConfigurationException, UnsupportedEncodingException, ParserConfigurationException, TransformerException, TransformerFactoryConfigurationError{ 235 resultStream = this.Diagnostics().buildXMLStream(); 236 return "resultStream"; 237 } 181 238 /** 182 239 * primitive identification of the target-proxy … … 189 246 } 190 247 248 public Diagnostics Diagnostics(){ 249 if (this.diagnostics == null){ 250 this.diagnostics = new Diagnostics(); 251 } 252 return this.diagnostics; 253 } 254 191 255 public void prepare(){ 256 // special handling of parameter setting, x-cmd-... not alowed in java 257 this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository")); 258 this.setX_cmd_collections(getServletRequest().getParameter("x-cmd-collections")); 259 192 260 mdrepoproxyaction = new MDRepoProxyAction(); 193 mdrepoproxyaction.setRepository(2); 194 261 mdrepoproxyaction.setDiagnostics(diagnostics); 262 263 //operation 264 if (this.operation == null) { 265 this.Diagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "operation"); 266 //return -1; 267 } 268 if (!operation.equals("searchRetrieve")) { 269 this.Diagnostics().Add(Diagnostic.UNSUPPOERTED_OPERATION, "Only searchRetrieve supported."); 270 //return -1; 271 } 195 272 mdrepoproxyaction.setActionkey(hash_operations.get(this.getOperation())); 273 //version 274 if (this.version == null) { 275 this.Diagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "version"); 276 //return -1; 277 } 278 if (!version.equals("1.2")) { 279 this.Diagnostics().Add(Diagnostic.UNSUPPORTED_VERSION, "Version 1.2 supported."); 280 //return -1; 281 } 282 //query 196 283 mdrepoproxyaction.setSquery(""); 284 if (this.query == null) { 285 this.Diagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "query"); 286 //return -1; 287 } 197 288 mdrepoproxyaction.setQ(getQuery()); 289 198 290 mdrepoproxyaction.setFormat("xml"); 199 291 200 if (getStartRecord() > 0 ){ 292 if ((this.startRecord < 0 ) ||(getServletRequest().getParameter("startRecord").equals("0"))) { 293 this.Diagnostics().Add(new Diagnostic(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "startRecord must by grater than 0."));//,Diagnostic.NONFATALNONSURORGATE)); 294 //mdrepoproxyaction.setStartItem("1"); 295 } else { 201 296 mdrepoproxyaction.setStartItem(Integer.toString(getStartRecord())); 202 297 } 203 if (getMaximumRecords() > 0 ) { 204 mdrepoproxyaction.setMaximumItems(Integer.toString(this.getMaximumRecords())); 205 } 206 298 299 if ((this.maximumRecords < 0 ) ||(getServletRequest().getParameter("maximumRecords").equals("0"))){ 300 this.Diagnostics().Add(new Diagnostic(Diagnostic.UNSUPPORTED_PARAMETERVALUE, 301 "maximumRecords must by grater than 0.")); 302 } else { 303 mdrepoproxyaction.setMaximumItems(Integer.toString(this.getMaximumRecords())); 304 } 305 306 if (this.getX_cmd_repository() != null ) { 307 mdrepoproxyaction.setRepository(this.getX_cmd_repository()); 308 //TODO\ 309 if (mdrepoproxyaction.getBaseURI() == null) this.Diagnostics().Add(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "Unknown repository." + getX_cmd_repository()); 310 } 311 if (this.getX_cmd_collections() != null ) { 312 mdrepoproxyaction.setCollection(this.getX_cmd_collections()); 313 } 314 315 //return 1; 207 316 } 208 317 public static String inputStreamAsString(InputStream stream) … … 220 329 } 221 330 222 public void postprocess(){ 331 public static Document newDocumentFromInputStream(InputStream in) { 332 DocumentBuilderFactory factory = null; 333 DocumentBuilder builder = null; 334 Document ret = null; 335 336 try { 337 factory = DocumentBuilderFactory.newInstance(); 338 builder = factory.newDocumentBuilder(); 339 } catch (ParserConfigurationException e) { 340 e.printStackTrace(); 341 } 342 343 try { 344 ret = builder.parse(new InputSource(in)); 345 } catch (SAXException e) { 346 e.printStackTrace(); 347 } catch (IOException e) { 348 e.printStackTrace(); 349 } 350 return ret; 351 } 352 353 354 public void postprocess() throws TransformerConfigurationException, UnsupportedEncodingException, ParserConfigurationException, TransformerException, TransformerFactoryConfigurationError{ 223 355 //recordPacking 224 356 if (this.getRecordPacking() != null){ … … 233 365 } 234 366 } 235 } 367 368 // add diagnostics 369 if (Diagnostics().Exists()){ 370 Document doc = newDocumentFromInputStream(resultStream); 371 Node r_element= doc.getElementsByTagName("searchRetrieveResponse").item(0); 372 Document ddoc = Diagnostics().buildXMLDocument(); 373 Node d_element= ddoc.getElementsByTagName("diagnostics").item(0); 374 doc.adoptNode(d_element); 375 r_element.appendChild(d_element); 376 DOMSource source = new DOMSource(doc); 377 StringWriter xmlAsWriter = new StringWriter(); 378 StreamResult result = new StreamResult(xmlAsWriter); 379 TransformerFactory.newInstance().newTransformer().transform(source, result); 380 resultStream = new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8")); 381 } 382 } 383 236 384 /** 237 385 * default Action method 238 386 */ 239 387 public String execute() throws Exception { 240 241 388 prepare(); 242 if (this.mdrepoproxyaction.execute() == SUCCESS){ 243 resultStream = this.mdrepoproxyaction.getResultStream(); 244 postprocess(); 245 return SUCCESS; 389 if (Diagnostics().Accepted()){ 390 //TODO diagnostic 391 if (this.mdrepoproxyaction.getTargetRequest() == null) { 392 Diagnostics().Add(Diagnostic.QUERYSYNTAXERROR); 393 return ERROR; 394 } 395 if (this.mdrepoproxyaction.execute() == SUCCESS){ 396 resultStream = this.mdrepoproxyaction.getResultStream(); 397 postprocess(); 398 return SUCCESS; 399 } 246 400 } 247 401 return ERROR; -
MDService2/trunk/MDService2/src/struts.xml
r1183 r1187 13 13 14 14 <global-results> 15 <result name="exception">/Exception.jsp</result> 15 <!-- <result name="exception">/Exception.jsp</result>--> 16 <result name="exception">/ExceptionXML.jsp</result> 16 17 <!-- tried setting html-status, didn't work: 17 18 <result name="exception"> … … 20 21 </result> --> 21 22 <result name="error">/Error.jsp</result> 23 <!-- <result name="error" type="redirectAction"></result> 24 --> 22 25 </global-results> 23 26 … … 228 231 <action name="sru/*" class="eu.clarin.cmdi.mdservice.action.SRUProxyAction" method="execute"> 229 232 <param name="q">{1}</param> 230 <result type="stream">233 <result name="success" type="stream"> 231 234 <param name="contentType">text/xml</param> 232 235 <param name="inputName">resultStream</param> 236 </result> 237 <result name="error" type="stream"> 238 <param name="contentType">text/xml</param> 239 <param name="inputName">${getDiagnosticStreamName()}</param> 233 240 </result> 234 241 </action> -
MDService2/trunk/MDService2/src/xsl/cmd_functions.xsl
r1155 r1187 186 186 <xsl:choose> 187 187 <xsl:when test="$action=''"> 188 <xsl:value-of select="concat($base_dir, '/?q=', $q, '&repository=', $repository_ id)" />188 <xsl:value-of select="concat($base_dir, '/?q=', $q, '&repository=', $repository_name)" /> 189 189 </xsl:when> 190 190 <xsl:otherwise> 191 <xsl:value-of select="concat($base_dir, '/',$action, '/', $format, '/?q=', $q, '&repository=', $repository_ id)" />191 <xsl:value-of select="concat($base_dir, '/',$action, '/', $format, '/?q=', $q, '&repository=', $repository_name)" /> 192 192 </xsl:otherwise> 193 193 </xsl:choose> -
MDService2/trunk/MDService2/src/xsl/mdset2view.xsl
r1179 r1187 260 260 <xsl:choose> 261 261 <xsl:when test="exists(.//MdSelfLink)" > 262 <a class="internal" href="{concat('record/htmldetail/', my:encodePID(.//MdSelfLink), '?repository=', $repository_ id)}" >262 <a class="internal" href="{concat('record/htmldetail/', my:encodePID(.//MdSelfLink), '?repository=', $repository_name)}" > 263 263 <xsl:value-of select="$absolute_position" /> 264 264 </a> -
MDService2/trunk/MDService2/src/xsl/model2matrix.xsl
r1081 r1187 42 42 </xsl:when> 43 43 <xsl:when test="$termset_name='Components'" > 44 <xsl:message>model2matrix.Components.repo_ id: <xsl:value-of select="$repository_id" /></xsl:message>44 <xsl:message>model2matrix.Components.repo_name: <xsl:value-of select="$repository_name" /></xsl:message> 45 45 <!-- get the whole Termset for every root-node (teiHeader, TCP, ...) --> 46 46 <Termsets> … … 62 62 <!-- else get the full summary for given termset --> 63 63 <xsl:otherwise> 64 <xsl:variable name="resolved_termset_uri" select="concat($model_matrix_uri,$termset_name,'&maxdepth=8&repository=',$repository_ id)" />64 <xsl:variable name="resolved_termset_uri" select="concat($model_matrix_uri,$termset_name,'&maxdepth=8&repository=',$repository_name)" /> 65 65 <xsl:message>processing model-term($resolved_termset_uri): <xsl:value-of select="$resolved_termset_uri" /> </xsl:message> 66 66 <xsl:copy-of select="document($resolved_termset_uri)" /> … … 134 134 <xsl:template name="full-matrix" > 135 135 <!-- collect all model termMatrix --> 136 <xsl:variable name="model_termsets_uri" select="concat($model_matrix_uri,'Components', '&maxdepth=1&repository=',$repository_ id)" />136 <xsl:variable name="model_termsets_uri" select="concat($model_matrix_uri,'Components', '&maxdepth=1&repository=',$repository_name)" /> 137 137 <xsl:message>full-matrix.model_termsets_uri: <xsl:value-of select="$model_termsets_uri"/> </xsl:message> 138 138 <xsl:variable name="model_termsets" select="document($model_termsets_uri)" /> -
MDService2/trunk/MDService2/src/xsl/params.xsl
r1081 r1187 24 24 25 25 26 <xsl:param name="repository_ id" select="''" />26 <xsl:param name="repository_name" select="''" /> 27 27 28 28 <!-- for resolving components by suffixing with @ComponentId -->
Note: See TracChangeset
for help on using the changeset viewer.