Changeset 1521 for MDService2
- Timestamp:
- 09/06/11 13:04:37 (13 years ago)
- Location:
- MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericAction.java
r1520 r1521 1 1 package eu.clarin.cmdi.mdservice.action; 2 2 3 import java.io.ByteArrayInputStream; 3 4 import java.io.IOException; 4 5 import java.io.InputStream; 6 import java.io.StringWriter; 5 7 import java.util.HashMap; 6 8 import java.util.Map; 7 9 import javax.servlet.http.HttpServletRequest; 10 import javax.xml.transform.TransformerFactory; 11 import javax.xml.transform.dom.DOMSource; 12 import javax.xml.transform.stream.StreamResult; 8 13 9 14 import org.apache.log4j.Logger; 10 15 import org.apache.struts2.interceptor.ServletRequestAware; 16 import org.w3c.dom.Document; 17 import org.w3c.dom.Node; 11 18 12 19 import com.opensymphony.xwork2.ActionSupport; 13 20 14 21 import eu.clarin.cmdi.mdservice.internal.Cache; 22 import eu.clarin.cmdi.mdservice.internal.Helpers; 15 23 import eu.clarin.cmdi.mdservice.internal.MDTransformer; 16 24 import eu.clarin.cmdi.mdservice.internal.NoStylesheetException; … … 79 87 } 80 88 return this.diagnostics; 89 81 90 } 82 91 … … 229 238 protected void loadParams() { 230 239 params = getServletRequest().getParameterMap(); 240 241 // add fullformat 242 String[] str = new String[1]; 243 str[0] = getFullFormat(); 244 params.put("fullformat", str);//getFullFormat()); 231 245 } 232 246 … … 245 259 public String getParam(String key) { 246 260 String v = ""; 247 if (!(params.get(key)==null)) v=(String)params.get(key)[0]; 261 if (key.equals("q")){ 262 if (params.get(key)==null){ 263 v = getQ(); 264 } else { 265 v=(String)params.get(key)[0]; 266 } 267 }else if (key.equals("format")){ 268 if (params.get(key)==null){ 269 v = getFormat(); 270 } else { 271 v=(String)params.get(key)[0]; 272 } 273 } else { 274 if (!(params.get(key)==null)) v=(String)params.get(key)[0]; 275 } 248 276 return v; 249 277 } … … 320 348 } 321 349 322 public HashMap<String,String> createTransformerParams(){ 323 324 HashMap<String,String> hm = new HashMap<String,String>(); 325 326 if (getFullFormat() != null){ 350 public Map<String,String> createTransformerParams(){ 351 352 Map<String,String> hm = null; 353 354 return hm; 355 356 //new HashMap<String,String[]>(); 357 358 /*if (getFullFormat() != null){ 327 359 hm.put("format", getFullFormat()); 328 360 } 329 /*361 330 362 if (getColumns() != null){ 331 363 hm.put("cols", getColumns()); … … 350 382 //} 351 383 */ 352 return hm;384 //return hm; 353 385 354 386 } … … 403 435 } 404 436 437 // add diagnostics 438 if (getDiagnostics().Exists()){ 439 Document doc ; 440 Node r_element; 441 // fatal error 442 //TODO getDiagnostics().Exists("fatal"); 443 if (sourceStream == null){ 444 //TODO rootelemname ??? 445 doc = Helpers.createDocument("rootelemname"); 446 r_element = doc.getFirstChild(); 447 } else { 448 doc = Helpers.getDocument(sourceStream); 449 //TODO tagname by class 450 r_element= doc.getElementsByTagName("searchRetrieveResponse").item(0); 451 } 452 453 Document ddoc = getDiagnostics().buildXMLDocument(); 454 Node d_element= ddoc.getElementsByTagName("diagnostics").item(0); 455 doc.adoptNode(d_element); 456 r_element.appendChild(d_element); 457 DOMSource source = new DOMSource(doc); 458 StringWriter xmlAsWriter = new StringWriter(); 459 StreamResult result = new StreamResult(xmlAsWriter); 460 TransformerFactory.newInstance().newTransformer().transform(source, result); 461 this.setSourceStream(new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"))); 462 } 463 405 464 if (getFormat().equals("xml")) { 406 465 resultStream = sourceStream; … … 411 470 transformer.setSrcFile(getTargetProxy().getTargetRequest()); 412 471 transformer.setParams(createTransformerParams()); 472 //transformer.setParams(getParams()); 413 473 // here the transformation is invoked 414 474 resultStream = transformer.transformXML(sourceStream); 415 475 } 416 476 477 //TODO 417 478 log.debug(getActionkey() + " success:" + (resultStream!=null)); 479 480 418 481 } 419 482 -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java
r1512 r1521 407 407 } 408 408 409 /* 409 410 public HashMap<String,String> createTransformerParams(){ 410 411 … … 439 440 440 441 } 441 442 */ 442 443 /** 443 444 * This is the work-horse function. -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/RepoAction.java
r1512 r1521 11 11 import java.net.URISyntaxException; 12 12 import java.net.URL; 13 import java.util.Arrays; 14 import java.util.Collections; 13 15 import java.util.HashMap; 16 import java.util.Iterator; 17 import java.util.Map; 18 import java.util.Set; 19 import java.util.Map.Entry; 14 20 15 21 import javax.servlet.http.HttpServletRequest; … … 75 81 protected URL base_url ; 76 82 77 83 private static final Map<String, String> xsl_map; 84 static { 85 Map<String, String> aMap = new HashMap<String,String>(); 86 aMap.put("fullformat","format"); 87 aMap.put("columns", "cols"); 88 aMap.put("maximumItems","maximumItems"); 89 aMap.put("startItem", "startItem"); 90 aMap.put("lang","lang"); 91 aMap.put("q", "q"); 92 aMap.put("repository","repository_name"); 93 //aMap.put("repository_type", "repository_type"); 94 xsl_map = Collections.unmodifiableMap(aMap); 95 } 96 97 78 98 79 99 /** … … 89 109 case PAZPAR: 90 110 setTargetProxy(new Pz2Proxy()); 111 return; 91 112 case SRU: 92 113 setTargetProxy(new SRUProxy()); 114 return; 93 115 case MD: 94 116 setTargetProxy(new MDRepoProxy()); 117 return; 95 118 default: 96 119 getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "repository", "repository=" + getRepository() ); … … 258 281 259 282 260 public HashMap<String,String> createTransformerParams(){ 283 @Override 284 public Map<String,String> createTransformerParams(){ 261 285 286 Map<String, String> map = new HashMap<String, String>(); 287 288 Set<Entry<String, String[]>> set = getParams().entrySet(); 289 Iterator<Entry<String, String[]>> i = set.iterator(); 290 291 while(i.hasNext()){ 292 Map.Entry<String,String[]> e = (Map.Entry<String,String[]>)i.next(); 293 if (xsl_map.containsKey((String)e.getKey())) { 294 map.put(xsl_map.get((String)e.getKey()), (String)e.getValue()[0]); 295 } 296 297 } 298 return map; 299 /* 262 300 HashMap<String,String> hm = new HashMap<String,String>(); 263 301 … … 288 326 289 327 return hm; 290 328 */ 291 329 } 292 330 -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/SRUAction.java
r1512 r1521 29 29 30 30 import eu.clarin.cmdi.mdservice.internal.Cache; 31 import eu.clarin.cmdi.mdservice.internal.Helpers; 31 32 32 33 … … 402 403 } 403 404 404 public static Document newDocumentFromInputStream(InputStream in) { 405 DocumentBuilderFactory factory = null; 406 DocumentBuilder builder = null; 407 Document ret = null; 408 409 try { 410 factory = DocumentBuilderFactory.newInstance(); 411 builder = factory.newDocumentBuilder(); 412 } catch (ParserConfigurationException e) { 413 e.printStackTrace(); 414 } 415 416 try { 417 ret = builder.parse(new InputSource(in)); 418 } catch (SAXException e) { 419 e.printStackTrace(); 420 } catch (IOException e) { 421 e.printStackTrace(); 422 } 423 return ret; 424 } 425 405 426 406 427 407 public void postprocess() throws TransformerConfigurationException, UnsupportedEncodingException, ParserConfigurationException, TransformerException, TransformerFactoryConfigurationError{ … … 443 423 // add diagnostics 444 424 if (getDiagnostics().Exists()){ 445 Document doc = newDocumentFromInputStream(this.getResultStream());425 Document doc = Helpers.getDocument(this.getResultStream()); 446 426 Node r_element= doc.getElementsByTagName("searchRetrieveResponse").item(0); 447 427 Document ddoc = getDiagnostics().buildXMLDocument(); -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/internal/Helpers.java
r1513 r1521 19 19 20 20 import org.w3c.dom.Document; 21 import org.w3c.dom.Element; 22 import org.xml.sax.InputSource; 21 23 import org.xml.sax.SAXException; 22 24 … … 92 94 return doc; 93 95 } 96 94 97 95 98 public static String getDocumentData(InputStream is, String expression){ … … 109 112 return data; 110 113 114 } 115 public static Document createDocument(String rootelemname){ 116 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); 117 DocumentBuilder docBuilder; 118 Document doc = null; 119 try { 120 docBuilder = docFactory.newDocumentBuilder(); 121 doc = docBuilder.newDocument(); 122 // append root tag <index > 123 Element root = (Element) doc.createElement(rootelemname); 124 doc.appendChild(root); 125 } catch (Exception e){ 126 127 } 128 return doc; 111 129 } 112 130 /* -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/internal/MDTransformer.java
r1513 r1521 19 19 import java.util.Map; 20 20 import java.util.Set; 21 import java.util.Map.Entry; 21 22 22 23 import javax.xml.transform.Transformer; … … 52 53 53 54 private URL srcFile ; 54 private HashMap<String,String> params;55 private Map<String, String> params; 55 56 56 57 // don't use singleton!! Bad things happen … … 77 78 * @return 78 79 */ 79 public void setParams( HashMap<String,String> params){80 this.params = params;81 } 82 83 84 public HashMap<String,String> getParams(){80 public void setParams(Map<String, String> map){ 81 this.params = map; 82 } 83 84 85 public Map<String,String> getParams(){ 85 86 return this.params; 86 87 } … … 140 141 public void SetTransformerParameters(Transformer transformer){ 141 142 142 Set< Map.Entry<String,String>> set = params.entrySet();143 Iterator< Map.Entry<String,String>> i = set.iterator();143 Set<Entry<String, String>> set = params.entrySet(); 144 Iterator<Entry<String, String>> i = set.iterator(); 144 145 145 146 while(i.hasNext()){ -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/RepoProxy.java
r1515 r1521 10 10 import java.net.URL; 11 11 import java.util.HashMap; 12 import java.util.Map; 12 13 import java.io.ByteArrayInputStream; 13 14 … … 79 80 } 80 81 82 public Map<String,String[]> getParams() { 83 return getSourceAction().getParams(); 84 } 85 81 86 public void checkParams() { 82 87 // required Params 88 // check and set defaults 89 if (WorkspaceProfile.getRepositoryPath(getParam("repository")) == null) { 90 getSourceAction().getDiagnostics().Add(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "repository"); 91 } 83 92 if (getParam("repository")=="") { 84 93 getSourceAction().getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "repository");
Note: See TracChangeset
for help on using the changeset viewer.