Changeset 1540 for MDService2
- Timestamp:
- 09/19/11 10:39:55 (13 years ago)
- Location:
- MDService2/branches/MDService_simple3
- Files:
-
- 1 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService2/branches/MDService_simple3/WorkspaceProfile.xml
r1516 r1540 78 78 </item> 79 79 <item> 80 <type></type> 81 <id>compreg</id> 82 <name>compreg</name> 83 <url>http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/</url> 84 <url_prefix></url_prefix> 85 <format>xml</format> 86 </item> 87 <item> 80 88 <type>dcr</type> 81 89 <id>isocat</id> -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/AdminAction.java
r1512 r1540 1 1 package eu.clarin.cmdi.mdservice.action; 2 2 3 import java.io.ByteArrayInputStream;4 import java.io.IOException;5 import java.net.MalformedURLException;6 import java.net.URL;7 import java.text.DateFormat;8 import java.text.SimpleDateFormat;9 import java.util.Date;10 3 import java.util.HashMap; 11 4 12 5 import eu.clarin.cmdi.mdservice.internal.Cache; 13 14 import net.sf.json.JSONObject;15 import net.sf.json.xml.XMLSerializer;16 6 17 7 /* -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/CompRegistryProxyAction.java
r1536 r1540 1 1 package eu.clarin.cmdi.mdservice.action; 2 2 3 import java.io.IOException;4 3 import java.io.InputStream; 5 import java.net.URL;6 7 import eu.clarin.cmdi.mdservice.internal.Admin;8 4 import eu.clarin.cmdi.mdservice.internal.Cache; 9 5 import eu.clarin.cmdi.mdservice.internal.MDTransformer; 10 import eu.clarin.cmdi.mdservice.model.Diagnostic;11 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;12 6 import eu.clarin.cmdi.mdservice.proxy.BasicProxy; 13 import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy;14 import eu.clarin.cmdi.mdservice.proxy.Pz2Proxy;15 import eu.clarin.cmdi.mdservice.proxy.SRUProxy;16 7 17 8 /** … … 128 119 try { 129 120 130 // Admin.notifyUser("CRPA.prepare");121 //log.debug("CRPA.prepare"); 131 122 if (!getActionkey().equals("elements")) { 132 123 super.prepare(); … … 136 127 getTargetProxy().checkParams(); 137 128 138 // Admin.notifyUser("CRPA.prepareSourceStream - elements");129 // log.debug("CRPA.prepareSourceStream - elements"); 139 130 String xcid; 140 131 InputStream _sourceStream; … … 144 135 _sourceStream = Cache.getCache().getFromCache(getRequestKey()); 145 136 if (_sourceStream == null) { 146 // Admin.notifyUser("CRPA.prepareSourceStream- profiles");137 // log.debug("CRPA.prepareSourceStream- profiles"); 147 138 //setActionkey("profiles"); 148 139 //setFormat("xmlresolved"); … … 151 142 __sourceStream = getSourceStream(); 152 143 xcid = Cache.getCache().putInCache(getRequestKey(),__sourceStream); 153 // Admin.notifyUser("CRPA-putting in cache: " + getRequestKey());144 //log.debug("CRPA-putting in cache: " + getRequestKey()); 154 145 __sourceStream = Cache.getCache().getFromCache(getRequestKey()); 155 146 } else{ 156 // Admin.notifyUser("CRPA-reading from cache: " + getRequestKey());147 //log.debug("CRPA-reading from cache: " + getRequestKey()); 157 148 } 158 // Admin.notifyUser("CCCRPA." + getTargetRequest());159 // Admin.notifyUser("CCCRPA." + getFullFormat());149 // log.debug("CCCRPA." + getTargetRequest()); 150 // log.debug("CCCRPA." + getFullFormat()); 160 151 MDTransformer transformer = new MDTransformer(); 161 152 transformer.setSrcFile(getTargetProxy().getTargetRequest()); 162 153 //transformer.setParams(createTransformerParams()); 163 154 _sourceStream = transformer.transformXML(__sourceStream);//, getFullFormat(),null,null,null,null,null,null); 164 // Admin.notifyUser("CRPA.- elements");155 // log.debug("CRPA.- elements"); 165 156 //setActionkey("elements"); 166 157 //setFormat("htmllist"); 167 158 xcid = Cache.getCache().putInCache(getRequestKey(),_sourceStream); 168 // Admin.notifyUser("CRPA-putting in cache: " + getRequestKey());159 // log.debug("CRPA-putting in cache: " + getRequestKey()); 169 160 _sourceStream = Cache.getCache().getFromCache(getRequestKey()); 170 161 } /*else { 171 Admin.notifyUser("CRPA-reading from cache: " + getRequestKey());162 log.debug("CRPA-reading from cache: " + getRequestKey()); 172 163 }*/ 173 164 /* 174 165 File file=new File(Cache.getCache().formPath(getRequestKey())); 175 Admin.notifyUser("File-absolutePath " + file.getAbsolutePath());166 log.debug("File-absolutePath " + file.getAbsolutePath()); 176 167 URL url = null; 177 168 try{ 178 169 url = file.toURL(); 179 Admin.notifyUser("URL-tostring " + url.toString());170 log.debug("URL-tostring " + url.toString()); 180 171 } catch (MalformedURLException me){ 181 172 } … … 193 184 } 194 185 195 Admin.notifyUser(getProxyKey() + " success:" + (_resultStream!=null));186 log.debug(getProxyKey() + " success:" + (_resultStream!=null)); 196 187 197 188 setSourceStream(_sourceStream); … … 207 198 out.write(buf,0,len); 208 199 out.close(); 209 Admin.notifyUser("terms_autocomplete.txt");200 log.debug("terms_autocomplete.txt"); 210 201 } 211 202 */ … … 244 235 targetURL =new URL( getTargetProxy().getBaseURL(), getActionkey() + "/clarin.eu:cr1:" + compid); 245 236 } 246 // Admin.notifyUser("CompReg.targetURL:" + targetURL);237 // log.debug("CompReg.targetURL:" + targetURL); 247 238 // URLConnection urlConnection = targetURL.openConnection(); 248 239 // urlConnection.setRequestProperty("Accept", "application/xml"); -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/DCRProxyAction.java
r1536 r1540 1 1 package eu.clarin.cmdi.mdservice.action; 2 2 3 import java.io.IOException;4 import java.io.InputStream;5 import java.net.MalformedURLException;6 import java.net.URL;7 3 import java.net.URLConnection; 8 import java.util.HashMap;9 10 import javax.xml.transform.stream.StreamSource;11 import javax.xml.xpath.XPath;12 import javax.xml.xpath.XPathConstants;13 import javax.xml.xpath.XPathExpression;14 import javax.xml.xpath.XPathExpressionException;15 import javax.xml.xpath.XPathFactory;16 17 4 import org.apache.log4j.Logger; 18 import org.w3c.dom.Document;19 import org.w3c.dom.Node;20 import org.w3c.dom.NodeList;21 22 import eu.clarin.cmdi.mdservice.internal.Admin;23 5 import eu.clarin.cmdi.mdservice.model.Termset; 24 6 import eu.clarin.cmdi.mdservice.proxy.BasicProxy; … … 62 44 63 45 Termset res = (Termset) Termset.getTermset(dcr_id); 64 if (res==null) Admin.notifyUser("getDCR(): no termset found for:" + dcr_id);46 if (res==null) log.debug("getDCR(): no termset found for:" + dcr_id); 65 47 //else 66 // Admin.notifyUser("getDCR():" + res.getAttr("id") + ":" + res.getAttr("url") );48 //log.debug("getDCR():" + res.getAttr("id") + ":" + res.getAttr("url") ); 67 49 68 50 return res; … … 155 137 } 156 138 157 // Admin.notifyUser("DCRProxy.targetURL:" + targetURL);139 // log.debug("DCRProxy.targetURL:" + targetURL); 158 140 159 141 return targetURL; … … 168 150 //TODO NOT integrated in PROXY 169 151 if ((getQ().equals(ALL) || getQ()==null || getQ().equals("")) && (getActionkey().equals(DATCATS))) { 170 log.debug("serving terms.file:" + Admin.getConfig().getProperty("terms.file"));171 resultStream = this.getClass().getClassLoader().getResourceAsStream( Admin.getConfig().getProperty("terms.file"));152 log.debug("serving terms.file:" + Utils.getConfig().getProperty("terms.file")); 153 resultStream = this.getClass().getClassLoader().getResourceAsStream(Utils.getConfig().getProperty("terms.file")); 172 154 } else { 173 155 -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericAction.java
r1536 r1540 1 1 package eu.clarin.cmdi.mdservice.action; 2 2 3 import java.io.ByteArrayInputStream;4 3 import java.io.IOException; 5 4 import java.io.InputStream; 6 import java.io.StringWriter;7 5 import java.net.URLConnection; 8 6 import java.util.HashMap; … … 10 8 11 9 import javax.servlet.http.HttpServletRequest; 12 import javax.xml.transform.TransformerFactory;13 import javax.xml.transform.dom.DOMSource;14 import javax.xml.transform.stream.StreamResult;15 16 10 import org.apache.log4j.Logger; 17 11 import org.apache.struts2.interceptor.ServletRequestAware; 18 12 import org.w3c.dom.Document; 19 import org.w3c.dom.Node;20 13 21 14 import com.opensymphony.xwork2.ActionSupport; 22 15 23 16 import eu.clarin.cmdi.mdservice.internal.Cache; 24 import eu.clarin.cmdi.mdservice.internal.Helpers;25 17 import eu.clarin.cmdi.mdservice.internal.MDTransformer; 26 18 import eu.clarin.cmdi.mdservice.internal.NoStylesheetException; 19 import eu.clarin.cmdi.mdservice.internal.Utils; 20 import eu.clarin.cmdi.mdservice.model.Diagnostic; 27 21 import eu.clarin.cmdi.mdservice.model.Diagnostics; 28 22 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; … … 32 26 33 27 /** 34 * main Struts2 controller (ie implemenets the struts' execute()-method), all other Actions are derived from.28 * Main Struts2 controller (ie implemenets the struts' execute()-method), all other Actions are derived from. 35 29 * Defines the methods used for retrieving the data 36 30 * and provides basic implementation where possible. … … 42 36 implements ServletRequestAware 43 37 { 38 44 39 public static Logger log = Logger.getLogger("GenericAction"); 45 40 private static final long serialVersionUID = 1L; 46 41 47 48 42 private Diagnostics diagnostics; 43 49 44 /** 50 45 * Properties to be filled by Struts with according request-parameters … … 55 50 56 51 private String actionContentType; 57 private String userMsg;58 52 private HttpServletRequest request; 59 53 private long duration = 0; … … 65 59 private ProxyInterface target_proxy; 66 60 67 61 /** 62 * Gets the target proxy. 63 * 64 * @return target proxy 65 */ 68 66 public ProxyInterface getTargetProxy() { 69 67 return target_proxy; 70 68 } 71 69 70 /** 71 * Sets the particular proxy and its source action. 72 * 73 * @param proxy - interface to be set 74 */ 72 75 public void setTargetProxy(ProxyInterface proxy) { 73 76 target_proxy = proxy; … … 75 78 } 76 79 77 /**78 * Empty implementation, subclasses have to decide themselves, which proxy to take.79 */80 /** 81 * Empty implementation, subclasses have to decide themselves, which proxy to take. 82 */ 80 83 public void setTargetProxy() { 81 84 } 82 85 83 public Diagnostics getDiagnostics(){ 86 87 /** 88 * Gets the diagnostics. 89 * 90 * @return diagnostics 91 */ 92 public Diagnostics getDiagnostics(){ 84 93 if (diagnostics == null){ 85 94 diagnostics = new Diagnostics(); 86 95 } 87 96 return this.diagnostics; 88 97 } 89 98 90 public void setDiagnostics(Diagnostics diagnostics){ 99 /** 100 * Sets the diagnostics. 101 * 102 * @param diagnostics 103 */ 104 public void setDiagnostics(Diagnostics diagnostics){ 91 105 this.diagnostics = diagnostics; 92 106 } 93 107 94 public String getQ() { 108 /** 109 * Gets string variable q. 110 * 111 * @return 112 */ 113 public String getQ() { 95 114 return q; 96 } 97 98 public void setQ(String q) { 115 } 116 117 /** 118 * Sets the variable q. 119 * 120 * @param q 121 */ 122 public void setQ(String q) { 99 123 this.q = q; 100 } 101 102 public void setFormat(String format) { 124 } 125 126 /** 127 * Sets the variable format. Used by Struts in case the format is part of the request path. 128 * In the case the format is part of the request parameters, it is read by servlet request. 129 * 130 * @param format 131 */ 132 public void setFormat(String format) { 103 133 this.format = format; 104 } 105 106 public String getActionkey() { 134 } 135 136 137 public String getActionkey() { 107 138 return actionkey; 108 139 } … … 111 142 actionkey = actionKey; 112 143 } 113 114 public String getScanClause() { 144 145 /** 146 * Gets the scanClause parameter from the parameter map. 147 * 148 * @return 149 */ 150 public String getScanClause() { 115 151 return getParam("scanClause"); 116 } 117 public String getRecordPacking() { 152 } 153 154 /** 155 * Gets the recordPacking parameter from the parameter map. 156 * 157 * @return 158 */ 159 public String getRecordPacking() { 118 160 return getParam("recordPacking"); 119 } 120 public String getQuery() { 161 } 162 163 public String getQuery() { 121 164 return getParam("query"); 122 } 123 public String getStartRecord() { 165 } 166 167 public String getStartRecord() { 124 168 return getParam("startRecord"); 125 } 126 public String getMaximumRecords() { 169 } 170 171 public String getMaximumRecords() { 127 172 return getParam("maximumRecords"); 128 } 129 public String getFormat() { 173 } 174 175 public String getFormat() { 130 176 return getParam("format"); 131 } 132 public String getCache() { 177 } 178 179 public String getCache() { 133 180 return getParam("cache"); 134 } 135 public String getRepository() { 181 } 182 183 public String getRepository() { 136 184 return getParam("repository"); 137 } 138 public String getLang() { 185 } 186 187 public String getLang() { 139 188 return getParam("lang"); 140 } 141 public String getCollections() { 189 } 190 191 public String getCollections() { 142 192 return getParam("collections"); 143 } 144 public String getColumns() { 193 } 194 195 public String getColumns() { 145 196 return getParam("columns"); 146 } 147 public String getMaxdepth() { 197 } 198 199 public String getMaxdepth() { 148 200 return getParam("maxdepth"); 149 201 } 150 202 151 203 152 204 /** 153 * is used in struts.xml to dynamically set the mime-type of the result, depending on the format-parameter 205 * Is used in struts.xml to dynamically set the mime-type of the result, depending on the format-parameter 206 * 154 207 * @return 155 208 */ … … 173 226 return actionkey + "2" + getFormat(); 174 227 } 175 176 177 /** 178 * TODO: this should be replaced by the diagnostics-mechanism 179 * @return 180 */ 181 public String getUserMsg() { 182 return userMsg; 183 } 184 185 public void setUserMsg(String userMsg) { 186 this.userMsg = this.userMsg + "\n" + userMsg; 187 } 188 189 /** 190 * needed to acquire the original ServletRequest 228 229 /** 230 * Needed to acquire the original ServletRequest 191 231 * (want to access the raw params - in loadParams()) 192 232 * @return … … 202 242 203 243 /** 204 * The stream holding the resulting data to be sent back to the user as response 244 * The stream holding the resulting data to be sent back to the user as response. 205 245 * @return 206 246 */ … … 208 248 return resultStream; 209 249 } 250 210 251 public void setResultStream(InputStream _resultStream){ 211 252 resultStream = _resultStream; 212 253 } 254 213 255 public void setSourceStream(InputStream _sourceStream){ 214 256 sourceStream = _sourceStream; … … 217 259 218 260 /** 219 * Get the sourceStream from the target proxy 261 * Get the sourceStream from the target proxy. 220 262 * @return 221 263 * @throws IOException 222 264 * @throws NoStylesheetException 223 265 */ 224 266 public InputStream getSourceStream() throws IOException, NoStylesheetException { 225 267 return getTargetProxy().getSourceStream(); 226 } 227 268 } 269 270 /** 271 * Add parameter into local parameter map. 272 * 273 * @param key - parameter key 274 * @param value - parameter value 275 */ 276 public void addParam(String key, String value){ 277 String[] sarr = new String[1]; 278 sarr[0] = value; 279 params.put(key, sarr); 280 } 228 281 /** 229 282 * Reads in all the parameters of the request into an internal structure. … … 233 286 * This shall allow more flexibility in using the parameters in the subclasses (and less getter/setter stuff) 234 287 * at the cost of circumventing the Struts-way. 235 */ 236 public void addParam(String key, String value){ 237 String[] sarr = new String[1]; 238 sarr[0] = value; 239 params.put(key, sarr); 240 } 241 242 /* 243 * sru params 244 * /* 288 * 289 * 290 * The params are completed to fulfill sru params standard an also the params needed by XSL transformation 291 * are added. 292 * 293 * SRU PARAMS: 245 294 * version 246 295 * operation … … 338 387 } 339 388 389 /** 390 * Gets the local parameter map. 391 * 392 * @return 393 */ 340 394 public Map<String,String[]> getParams() { 341 395 return params; … … 364 418 /** 365 419 * Constructs an unambiguous key for the request (encoding all the parameters). 366 * This is used as identifier for caching 420 * This is used as identifier for caching . 421 * 367 422 * @return key unambiguously encoding the request 368 423 */ … … 411 466 412 467 468 /** 469 * Adds the duration value of the action execution to the request key. 470 * 471 * @return 472 */ 413 473 public String addDurationKey(){ 414 474 String req_key = getRequestKey(); … … 423 483 424 484 425 /**426 * This is the work-horse function.427 * It does two things:428 * a) check if the source data is already in cache (based on cache-key that is constructed from the request parameters)429 * b) if format-parameter provided, invokes the transformation.430 * at the end the data to be returned as result is contained in the resultStream431 * If format is xml, then the data from sourceStream is passed further as resultStream.432 *433 * @throws Exception This is handled by struts (is mapped to some result in struts.xml based on the Exception-Class)434 */435 485 public String getTargetRequestParams(){ 436 486 return ""; … … 441 491 } 442 492 493 /** 494 * This is the work-horse function. 495 * It does more things: 496 * a) Loads the request parameters. 497 * b) Creates the concerned proxy object. 498 * c) Checks if the source data is already in cache (based on cache-key that is constructed from the request parameters). 499 * d) If diagnostics occurred during function, the diagnostics data will be added into source data. 500 * e) If format-parameter provided, invokes the transformation. 501 * 502 * 503 * At the end the data to be returned as result is contained in the resultStream 504 * If format is xml, then the data from sourceStream is passed further as resultStream. 505 * 506 * If exception occurred within prepare function , it will be caught and written 507 * as diagnostics system error. 508 * 509 */ 443 510 public void prepare() { 444 511 445 512 try{ 446 513 loadParams(); 514 447 515 setTargetProxy(); 516 if (getTargetProxy() == null) return; 448 517 getTargetProxy().checkParams(); 518 519 // Do not continue if something is fatal. 520 if (getDiagnostics().Exists()) return; 449 521 450 522 String req_key = getRequestKey(); … … 453 525 log.debug(getActionkey() + ".targetURL: " + getTargetProxy().getTargetRequest() + " .format:" + getFullFormat()); 454 526 455 // Caching 456 String xcid; 527 //Caching 457 528 458 529 if (getCache().equals(Cache.SKIP)) { … … 465 536 } 466 537 if (sourceStream == null) { // either not in cache or cache_flag=refresh 467 //sourceStream = getTargetRequest().openStream();468 538 long startMillis = System.currentTimeMillis(); 469 539 sourceStream = getSourceStream(); 470 540 duration = System.currentTimeMillis() - startMillis; 471 541 req_key = addDurationKey(); 472 473 long now = System.currentTimeMillis(); 474 xcid = Cache.getCache().putInCache(req_key,sourceStream); 475 //Admin.notifyUser("putting in cache: " + req_key); 542 String xcid = Cache.getCache().putInCache(req_key,sourceStream); 543 log.debug("putting in cache: " + req_key + ", " + xcid); 476 544 sourceStream = Cache.getCache().getFromCache(req_key); 477 } /*else {478 Admin.notifyUser("reading from cache: " + req_key);479 } */480 } 481 482 // a dd diagnostics non fatal545 } else { 546 log.debug("reading from cache: " + req_key); 547 } 548 } 549 550 // append diagnostics to sourcestream 483 551 if (getDiagnostics().Exists()){ 484 Document doc ; 485 Node r_element; 486 // fatal error 487 //TODO getDiagnostics().Exists("fatal"); 488 if (sourceStream == null){ 489 //TODO rootelemname ??? 490 doc = Helpers.createDocument("rootelemname"); 491 r_element = doc.getFirstChild(); 492 } else { 493 doc = Helpers.getDocument(sourceStream); 494 //TODO tagname by class 495 r_element= doc.getElementsByTagName("searchRetrieveResponse").item(0); 496 } 552 if (sourceStream == null) return; 497 553 498 Document ddoc = getDiagnostics().buildXMLDocument(); 499 Node d_element= ddoc.getElementsByTagName("diagnostics").item(0); 500 doc.adoptNode(d_element); 501 r_element.appendChild(d_element); 502 DOMSource source = new DOMSource(doc); 503 StringWriter xmlAsWriter = new StringWriter(); 504 StreamResult result = new StreamResult(xmlAsWriter); 505 TransformerFactory.newInstance().newTransformer().transform(source, result); 506 this.setSourceStream(new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"))); 554 Document doc = Utils.stream2Document(sourceStream); 555 //TODO tagname by class 556 doc = Utils.append2Document(doc, "searchRetrieveResponse", getDiagnostics().buildXMLDocument()); 557 this.setSourceStream(Utils.document2Stream(doc)); 507 558 } 508 559 … … 515 566 // TODO: WHY?? 516 567 transformer.setSrcFile(getTargetProxy().getTargetRequest()); 517 //transformer.setParams(createTransformerParams());518 568 transformer.setParams(getParams()); 519 569 // here the transformation is invoked … … 522 572 523 573 }catch (Exception e){ 574 log.error(Utils.errorMessage(e)); 524 575 //TODO add exception to diagnostic ? 576 getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, Utils.errorMessage(e)); 525 577 return; 526 578 } … … 530 582 531 583 /** 532 * default Action method that gets called by Struts. Everything interesting happens in prepare() 584 * Default Action method that gets called by Struts. Everything interesting happens in prepare() 585 * In case an error occurred in prepare and the result stream is not returned, the diagnostics will be returned 586 * as result. 587 * 588 * @throws Exception This is handled by struts (is mapped to some result in struts.xml based on the Exception-Class). 533 589 */ 534 590 public String execute() throws Exception { 535 // HttpServletRequest request = ServletActionContext.getRequest(); 536 //Admin.notifyUser("session-attrs:"); 537 //Admin.notifyUser(getServletRequest().getRemoteUser() ); 538 //Admin.notifyUser(String.valueOf(getSession())); 539 540 long now = System.currentTimeMillis(); 541 542 prepare(); 543 long duration = (System.currentTimeMillis() - now); 544 //duration 545 591 592 prepare(); 593 546 594 if (resultStream == null) { 595 // diagnostics to resultstream 547 596 if (getDiagnostics().Exists()){ 548 Document doc ; 549 Node r_element; 550 // fatal error 551 //TODO getDiagnostics().Exists("fatal"); 552 doc = Helpers.createDocument("Error"); 553 r_element = doc.getFirstChild(); 554 555 Document ddoc = getDiagnostics().buildXMLDocument(); 556 Node d_element= ddoc.getElementsByTagName("diagnostics").item(0); 557 doc.adoptNode(d_element); 558 r_element.appendChild(d_element); 559 DOMSource source = new DOMSource(doc); 560 StringWriter xmlAsWriter = new StringWriter(); 561 StreamResult result = new StreamResult(xmlAsWriter); 562 TransformerFactory.newInstance().newTransformer().transform(source, result); 563 this.setResultStream(new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"))); 564 597 this.setResultStream( Utils.document2Stream(getDiagnostics().buildXMLDocument())); 598 return SUCCESS; 565 599 } 566 600 return ERROR; -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java
r1532 r1540 12 12 import org.apache.struts2.interceptor.ServletRequestAware; 13 13 14 import eu.clarin.cmdi.mdservice.internal. Admin;14 import eu.clarin.cmdi.mdservice.internal.Utils; 15 15 import eu.clarin.cmdi.mdservice.internal.Cache; 16 16 import eu.clarin.cmdi.mdservice.internal.MDTransformer; … … 303 303 */ 304 304 public String getBaseURI() { 305 String uri = Admin.getConfig().getProperty(getProxyKey() + ".uri");305 String uri =Utils.getConfig().getProperty(getProxyKey() + ".uri"); 306 306 return uri; 307 307 } … … 314 314 public URL getBaseURL() throws MalformedURLException { 315 315 if (base_url == null) { 316 base_url = new URL(getBaseURI());// Admin.getConfig().getProperty(getProxyKey() + ".uri"));316 base_url = new URL(getBaseURI());//Utils.getConfig().getProperty(getProxyKey() + ".uri")); 317 317 } 318 318 return base_url; … … 453 453 try{ 454 454 String req_key = getRequestKey(); 455 Admin.notifyUser("request_key: " + req_key);456 Admin.notifyUser(getProxyKey() + ".targetURL: " + getTargetRequest() + " .format:" + getFullFormat());455 //log.debug("request_key: " + req_key); 456 //log.debug(getProxyKey() + ".targetURL: " + getTargetRequest() + " .format:" + getFullFormat()); 457 457 458 458 // Caching 459 459 String xcid; 460 460 461 // Admin.notifyUser("GPA.prepareSourceStream");461 // log.debug("GPA.prepareSourceStream"); 462 462 463 463 if (getCache().equals(Cache.SKIP)) { … … 478 478 long now = System.currentTimeMillis(); 479 479 xcid = Cache.getCache().putInCache(req_key,sourceStream); 480 // Admin.notifyUser("putting in cache: " + req_key);480 //log.debug("putting in cache: " + req_key); 481 481 sourceStream = Cache.getCache().getFromCache(req_key); 482 482 } /* else { 483 Admin.notifyUser("reading from cache: " + req_key);483 log.debug("reading from cache: " + req_key); 484 484 } */ 485 485 } … … 511 511 512 512 513 // Admin.notifyUser("session-attrs:");514 // Admin.notifyUser(getServletRequest().getRemoteUser() );515 // Admin.notifyUser(String.valueOf(getSession()));513 //log.debug("session-attrs:"); 514 //log.debug(getServletRequest().getRemoteUser() ); 515 //log.debug(String.valueOf(getSession())); 516 516 517 517 long now = System.currentTimeMillis(); -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/RepoAction.java
r1532 r1540 1 1 package eu.clarin.cmdi.mdservice.action; 2 2 3 import java.io.BufferedInputStream;4 import java.io.BufferedReader;5 import java.io.File;6 import java.io.FileInputStream;7 import java.io.IOException;8 import java.io.InputStream;9 import java.io.InputStreamReader;10 import java.net.MalformedURLException;11 import java.net.URISyntaxException;12 3 import java.net.URL; 13 import java.util.Arrays;14 import java.util.Collections;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;20 21 import javax.servlet.http.HttpServletRequest;22 import javax.servlet.http.HttpSession;23 import javax.xml.transform.TransformerException;24 25 import net.sf.json.JSON;26 import net.sf.json.JSONArray;27 import net.sf.json.JSONObject;28 import net.sf.json.JSONSerializer;29 //import net.sf.saxon.Controller;30 //import net.sf.saxon.event.MessageEmitter;31 32 4 33 5 import org.apache.log4j.Logger; 34 import org.apache.struts2.interceptor.ServletRequestAware;35 import com.opensymphony.xwork2.ActionSupport;36 37 import eu.clarin.cmdi.mdservice.internal.Cache;38 import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;39 6 import eu.clarin.cmdi.mdservice.model.Diagnostic; 40 import eu.clarin.cmdi.mdservice.model.Diagnostics;41 7 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; 42 8 import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy; … … 45 11 46 12 /** 47 * aStruts2 controller, responsible for calls to repositories.13 * A Struts2 controller, responsible for calls to repositories. 48 14 * After 2011-09 rework Action and Proxy are decoupled. 49 15 * So Action calls appropriate Proxy based upon the target repository type … … 57 23 */ 58 24 public class RepoAction extends GenericAction 59 //implements ServletRequestAware60 25 { 61 26 … … 63 28 private static Logger log = Logger.getLogger("RepoAction"); 64 29 65 /**66 * Properties to be filled by Struts with according request-parameters67 */68 private String actionkey;69 70 private String squery;71 private String collection;72 private String columns;73 private String startItem;74 private String maximumItems;75 private String sort;76 private int maxdepth;77 //private String format="xml"; // default no transformation78 private String options;79 80 //private Map<String,Object> session;81 30 protected URL base_url ; 82 31 … … 89 38 * If the type is not recognized - that is a bad user error 90 39 */ 91 40 public void setTargetProxy(){ 92 41 93 42 if (getRepository()==null) { … … 113 62 default: 114 63 //TODO error = bad workspaceProfile configuration 115 getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, " error in workspaceprofile configuration", "repository=" + getRepository() );64 getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, "Error in workspaceprofile configuration", "repository=" + getRepository() ); 116 65 } 117 66 118 }119 /*120 public String getSquery() {121 return squery;122 }123 124 public void setSquery(String psquery) {125 if (psquery==null) psquery="";126 this.squery = psquery;127 }128 129 public String getCollection() {130 return collection;131 }132 133 public void setCollection(String collection) {134 this.collection = collection;135 }136 137 //TODO defaults138 public String getColumns() {139 String cols = columns;140 return cols;141 }142 143 public void setColumns(String columns) {144 this.columns = columns;145 }146 147 public int getMaxdepth() {148 return maxdepth;149 }150 151 public void setMaxdepth(int maxdepth) {152 this.maxdepth = maxdepth;153 }154 /*155 public String getFormat() {156 return format;157 }158 159 public void setFormat(String format) {160 this.format = format;161 }162 163 public String getOptions() {164 return options;165 }166 167 public void setOptions(String options) {168 this.options = options;169 }170 171 172 public String getActionkey() {173 return actionkey;174 }175 176 public void setActionkey(String actionKey) {177 actionkey = actionKey;178 }179 180 181 public String getStartItem() {182 return startItem;183 }184 185 public void setStartItem(String startItem) {186 this.startItem = startItem;187 }188 189 public String getMaximumItems() {190 return maximumItems;191 }192 193 public void setMaximumItems(String maximumItems) {194 this.maximumItems = maximumItems;195 67 } 196 68 197 69 198 public String getSort() {199 return sort;200 }201 202 public void setSort(String sort) {203 this.sort = sort;204 }205 */206 207 70 /** 208 * internal identification of the target-proxy71 * Internal identification of the target-proxy 209 72 * base for finding the right base_url in the properties 210 * subclass has to override with its specific proxykey 73 * subclass has to override with its specific proxykey. 74 * 211 75 * @return the key identifying this type of proxy 212 76 */ 213 77 public String getProxyKey() { 214 78 return ""; 215 } 216 217 /** 218 * Constructs an unambiguous key for the request (encoding all the parameters). 219 * This is used as identifier for caching 220 * @return key unambiguously encoding the request 221 */ 222 /* 223 public String getRequestKey() { 224 String key=""; 225 if (getActionkey()!=null) { 226 key += getActionkey() + "//-" ; 227 }else { 228 key +="//-" ; 229 } 230 if (getQ()!=null) { 231 key += getQ() + "//-" ; 232 } else { 233 key +="//-" ; 234 } 235 if (getCollection()!=null) { 236 key += getCollection() + "//-"; 237 } else { 238 key +="//-" ; 239 } 240 if (getSquery()!=null) { 241 key += getSquery() + "//-" ; 242 } else { 243 key +="//-" ; 244 } 245 if (getStartItem()!=null) { 246 key += getStartItem() + "//-"; 247 } 248 else{ 249 key +="//-" ; 250 } 251 if (getMaximumItems()!=null) { 252 key += getMaximumItems() + "//-"; 253 } 254 else{ 255 key +="//-" ; 256 } 257 258 key += getRepository() + "//-"; 259 key += getMaxdepth() + "//-"; 260 261 if (getLang()!=null) { 262 key += getLang() + "//-"; 263 }else{ 264 key +="//-" ; 265 } 266 267 return key; 268 } 269 */ 270 /* 271 @Override 272 public Map<String,String> createTransformerParams(){ 273 274 Map<String, String> map = new HashMap<String, String>(); 275 276 Set<Entry<String, String[]>> set = getParams().entrySet(); 277 Iterator<Entry<String, String[]>> i = set.iterator(); 278 279 while(i.hasNext()){ 280 Map.Entry<String,String[]> e = (Map.Entry<String,String[]>)i.next(); 281 if (xsl_map.containsKey((String)e.getKey())) { 282 map.put(xsl_map.get((String)e.getKey()), (String)e.getValue()[0]); 283 } 284 285 } 286 return map; 287 */ 288 /* 289 HashMap<String,String> hm = new HashMap<String,String>(); 290 291 if (getFullFormat() != null){ 292 hm.put("format", getFullFormat()); 293 } 294 if (getColumns() != null){ 295 hm.put("cols", getColumns()); 296 } else { 297 hm.put("cols", ""); 298 } 299 if (getStartItem() != null){ 300 hm.put("startItem", getStartItem()); 301 } 302 if (getMaximumItems() != null){ 303 hm.put("maximumItems", getMaximumItems()); 304 } 305 if (getLang() != null){ 306 hm.put("lang", getLang()); 307 } 308 if (getQ() != null){ 309 hm.put("q", getQ()); 310 } 311 //if (getRepository() != null){ 312 hm.put("repository_name", String.valueOf(getRepository())); 313 hm.put("repository_type", WorkspaceProfile.getRepositoryType(this.getRepository())); 314 //} 315 316 return hm; 317 } 318 */ 319 320 79 } 321 80 322 81 } -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/SRUAction.java
r1524 r1540 9 9 import java.io.UnsupportedEncodingException; 10 10 import java.util.HashMap; 11 import java.util.Iterator;12 import java.util.Map;13 import java.util.Set;14 15 import javax.xml.parsers.DocumentBuilder;16 import javax.xml.parsers.DocumentBuilderFactory;17 11 import javax.xml.parsers.ParserConfigurationException; 18 12 import javax.xml.transform.TransformerConfigurationException; … … 25 19 import org.w3c.dom.Document; 26 20 import org.w3c.dom.Node; 27 import org.xml.sax.InputSource;28 import org.xml.sax.SAXException;29 21 30 22 import eu.clarin.cmdi.mdservice.internal.Cache; 31 import eu.clarin.cmdi.mdservice.internal. Helpers;23 import eu.clarin.cmdi.mdservice.internal.Utils; 32 24 33 25 … … 230 222 */ 231 223 public String getDiagnosticStreamName() throws TransformerConfigurationException, UnsupportedEncodingException, ParserConfigurationException, TransformerException, TransformerFactoryConfigurationError{ 232 this.setResultStream( getDiagnostics().buildXMLStream());224 this.setResultStream(Utils.document2Stream(getDiagnostics().buildXMLDocument()));//getDiagnostics().buildXMLStream()); 233 225 return "resultStream"; 234 226 } … … 246 238 @Override 247 239 public String getBaseURI() { 248 Admin.notifyUser("SRU-repositorypath:" + WorkspaceProfile.getRepositoryPath(getRepository()));249 String uri = WorkspaceProfile.getRepositoryPath(getRepository());// Admin.getConfig().getProperty(getProxyKey() + ".uri");240 log.debug("SRU-repositorypath:" + WorkspaceProfile.getRepositoryPath(getRepository())); 241 String uri = WorkspaceProfile.getRepositoryPath(getRepository());//Utils.getConfig().getProperty(getProxyKey() + ".uri"); 250 242 return uri; 251 243 } … … 302 294 } else { 303 295 if (operation.equals("explain") || operation == null){ 304 Admin.notifyUser("explaining", "debug");296 log.debug("explaining", "debug"); 305 297 }else { 306 298 if (operation.equals("scan")){ … … 426 418 // add diagnostics 427 419 if (getDiagnostics().Exists()){ 428 Document doc = Helpers.getDocument(this.getResultStream());420 Document doc = Utils.stream2Document(getResultStream()); 429 421 Node r_element= doc.getElementsByTagName("searchRetrieveResponse").item(0); 430 422 Document ddoc = getDiagnostics().buildXMLDocument(); -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/TermsProxyAction.java
r1524 r1540 8 8 import javax.xml.transform.TransformerException; 9 9 10 import eu.clarin.cmdi.mdservice.internal.Admin; 10 import org.apache.log4j.Logger; 11 12 import eu.clarin.cmdi.mdservice.internal.Utils; 11 13 import eu.clarin.cmdi.mdservice.internal.MDTransformer; 12 14 import eu.clarin.cmdi.mdservice.internal.NoStylesheetException; … … 23 25 public class TermsProxyAction extends GenericProxyAction { 24 26 27 public static Logger log = Logger.getLogger("TermsProxyAction"); 28 25 29 private static final long serialVersionUID = 1L; 26 30 … … 115 119 URL targetURL = null; 116 120 //targetURL = new URL(getBaseURI() + getQ()); 117 Admin.notifyUser("TPA.q: " + getBaseURI() + getQ() + getRepository());121 log.debug("TPA.q: " + getBaseURI() + getQ() + getRepository()); 118 122 // FIXME: this looks like an ugly hack! 119 123 //if (getMaxdepth()==0) setMaxdepth(1); … … 126 130 public InputStream getSourceStream() throws IOException, NoStylesheetException{ 127 131 String type = getTSAttr("type"); 128 Admin.notifyUser("TPA.getSourceStream.TStype: " + type);132 log.debug("TPA.getSourceStream.TStype: " + type); 129 133 if (type.equals("dcr") | type.equals("rr")) { 130 134 // if dcr|rr call model/matrix/all: http://localhost:8080/MDService2/model/matrix/?q=all … … 132 136 URL matrix_all_URL = new URL(getBaseURI() + ALL + "&repository="+ getRepository()); 133 137 //URL matrix_all_URL = new URL(getBaseURI() + ALL ); 134 Admin.notifyUser("TPA.getSourceStream: " + getBaseURI() + ALL);138 log.debug("TPA.getSourceStream: " + getBaseURI() + ALL); 135 139 InputStream stream_matrix_all = matrix_all_URL.openStream(); 136 140 InputStream resultStream=null; … … 143 147 //transformer.getParams().put("format","terms2extract"); 144 148 145 Admin.notifyUser("TPA.getSourceStream.transformer.effectiveTranskey: " + transformer.getTranskey() + ", for Termset:" + getTSAttr("name") + '#' + getTSAttr("id"));149 log.debug("TPA.getSourceStream.transformer.effectiveTranskey: " + transformer.getTranskey() + ", for Termset:" + getTSAttr("name") + '#' + getTSAttr("id")); 146 150 resultStream = transformer.transformXML(stream_matrix_all);//, "terms2extract", getColumns(), getStartRecord(), getMaximumRecords(),getLang(),getQ(), getRepositoryPath()); 147 151 148 152 } catch (InterruptedException e) { 149 Admin.notifyUser("TPA.getSourceStream(): "+ e.getMessage());153 log.debug("TPA.getSourceStream(): "+ e.getMessage()); 150 154 } catch (TransformerException e) { 151 Admin.notifyUser("TPA.getSourceStream(): "+ e.getMessage());155 log.debug("TPA.getSourceStream(): "+ e.getMessage()); 152 156 } 153 157 return resultStream; -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/VirtualCollectionProxyAction.java
r1530 r1540 8 8 import java.net.URL; 9 9 import java.net.URLConnection; 10 import java.util.HashMap;11 12 10 import org.w3c.dom.NodeList; 13 11 14 import eu.clarin.cmdi.mdservice.internal. Admin;12 import eu.clarin.cmdi.mdservice.internal.Utils; 15 13 import eu.clarin.cmdi.mdservice.internal.Cache; 16 import eu.clarin.cmdi.mdservice.internal.Helpers;17 14 import eu.clarin.cmdi.mdservice.internal.MDTransformer; 15 import eu.clarin.cmdi.mdservice.internal.Utils; 18 16 19 17 /** … … 79 77 // find the workspace data 80 78 NodeList list = (NodeList) getWorkspaceData(); 81 InputStream is = Helpers.DocumentToStream(list.item(0));79 InputStream is = Utils.document2Stream(list.item(0)); 82 80 //xslt transform to request data 83 81 MDTransformer transformer = new MDTransformer(); … … 100 98 // find out 101 99 //"http://clarin.ids-mannheim.de/vcr/service/virtualcollection"; 102 String urlstring = Admin.getConfig().getProperty("virtualcollection.uri");100 String urlstring = Utils.getConfig().getProperty("virtualcollection.uri"); 103 101 String vcrstr = (String)getVcrid();//getQueryVcrid(); 104 102 if (!vcrstr.equals("0")){ -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/WorkspaceAction.java
r1532 r1540 3 3 import java.io.BufferedInputStream; 4 4 import java.io.ByteArrayInputStream; 5 import java.io.ByteArrayOutputStream;6 5 import java.io.File; 7 6 import java.io.FileInputStream; … … 21 20 import javax.xml.parsers.ParserConfigurationException; 22 21 import javax.xml.transform.OutputKeys; 23 import javax.xml.transform.Result;24 import javax.xml.transform.Source;25 22 import javax.xml.transform.Transformer; 26 23 import javax.xml.transform.TransformerConfigurationException; … … 49 46 import org.xml.sax.SAXException; 50 47 51 import eu.clarin.cmdi.mdservice.internal.Admin; 52 import eu.clarin.cmdi.mdservice.internal.Helpers; 48 import eu.clarin.cmdi.mdservice.internal.Utils; 53 49 import eu.clarin.cmdi.mdservice.internal.MDTransformer; 54 50 import eu.clarin.cmdi.mdservice.model.Diagnostic; … … 164 160 public WorkspaceAction () { 165 161 this.elementtype = WorkspaceAction.SE_WORKSPACE; 166 workspacefilename = Admin.getConfig().getProperty("workspaceprofile.path") + Admin.getConfig().getProperty("workspace.file");162 workspacefilename = Utils.getConfig().getProperty("workspaceprofile.path") + Utils.getConfig().getProperty("workspace.file"); 167 163 if (workspace_doc == null){ 168 //workspacefilename = Admin.getConfig().getProperty("workspace.path") + Admin.getConfig().getProperty("workspace.file");164 //workspacefilename = Utils.getConfig().getProperty("workspace.path") + Utils.getConfig().getProperty("workspace.file"); 169 165 initDocument(); 170 166 } … … 228 224 public String getBasePath() { 229 225 if (base_path == null) { 230 base_path = Admin.getConfig().getProperty(getProxyKey() + ".path");226 base_path = Utils.getConfig().getProperty(getProxyKey() + ".path"); 231 227 } 232 228 return base_path; … … 248 244 File f = new File(getBasePath() + profilename); 249 245 if (! f.exists()){ 250 // Admin.notifyUser(" not exists");246 //log.debug(" not exists"); 251 247 profilename = "WorkspaceProfile_default.xml"; 252 248 } … … 260 256 if (profilename == null){ 261 257 profilename = PROFILENAME_DEFAULT; 262 Admin.notifyUser("WorkspaceProfilePath not specified (USER, SERVER)!");263 } 264 265 Admin.notifyUser("WorkspaceProfilename : " + profilename);258 log.debug("WorkspaceProfilePath not specified (USER, SERVER)!"); 259 } 260 261 log.debug("WorkspaceProfilename : " + profilename); 266 262 return profilename; 267 263 } … … 277 273 try{ 278 274 url=file.toURI().toURL(); 279 // Admin.notifyUser("url " + url);275 //log.debug("url " + url); 280 276 } catch (MalformedURLException e){ 281 // Admin.notifyUser("" + e);277 //log.debug("" + e); 282 278 } 283 279 return url; … … 308 304 } 309 305 310 /* 311 @Override 312 public void prepare() throws Exception { 313 314 //Admin.notifyUser("execute:"); 315 InputStream in = getSourceStream(); 316 this.setSourceStream(in); 317 if (getFormat().equals("xml")) { 318 setResultStream(in); 319 }else { //JSON 320 // set srcFile (for MDTransformer to pass to xsl-scripts) 321 MDTransformer transformer = new MDTransformer(); 322 transformer.setSrcFile(getURL()); 323 transformer.setParams(MDTransformer.createParamsMap(getFullFormat())); 324 setResultStream(transformer.transformXML(in));//, getFullFormat())); 325 //setSessionData(getResultStream()); 326 } 327 328 Admin.notifyUser(getProxyKey() + " success:" + (getResultStream()!=null)); 329 } 330 331 public void changeNodeName(Document doc, Node node, String new_name){ 332 // Create an element with the new name 333 Node node2 = (Node ) doc.createElement(new_name); 334 // Copy the attributes to the new element NamedNodeMap attrs = element.getAttributes(); for (int i=0; i<attrs.getLength(); i++) { Attr attr2 = (Attr)doc.importNode(attrs.item(i), true); element2.getAttributes().setNamedItem(attr2); } 335 // Move all the children 336 while (node.hasChildNodes()) { node2.appendChild(node.getFirstChild()); } 337 // Replace the old node with the new node 338 Admin.notifyUser("replace:" + node2.getNodeName() + "," + node.getNodeName()); 339 node.getParentNode().replaceChild(node2, node); 340 } 341 342 public void administrateQid() throws IOException, SAXException, ParserConfigurationException, TransformerException{ 343 WorkspaceAction wa = new WorkspaceAction(); 344 wa.setType("Admin"); 345 346 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 347 DocumentBuilder builder; 348 349 builder = factory.newDocumentBuilder(); 350 Document document = builder.parse(wa.getSourceStream()); 351 // find user-filename-id or create one 352 //add qid 353 //NodeList list = document.getElementsByTagName("e"); 354 //Admin.notifyUser("list:" + list.getLength()); 355 356 // save the changes 357 Transformer transformer; 358 transformer = TransformerFactory.newInstance().newTransformer(); 359 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 360 StreamResult result = new StreamResult(new StringWriter()); 361 DOMSource source = new DOMSource(document); 362 transformer.transform(source, result); 363 String xmlString = result.getWriter().toString(); 364 InputStream is_xml = new ByteArrayInputStream( xmlString.getBytes( ) ); 365 Admin.writeToFile(wa.getPath(), is_xml); 366 //wa.save(); 367 } 368 369 public String save() throws IOException, SAXException, ParserConfigurationException, TransformerException { 370 371 String jsonData = getData(); 372 373 Admin.notifyUser("JSON data:"+jsonData); 374 if ((!this.getType().equals(ADMIN)) && this.getQid() != null) { 375 administrateQid(); 376 } 377 378 XMLSerializer serializer = new XMLSerializer(); 379 JSON json = JSONSerializer.toJSON( jsonData ); 380 if (this.getType().equals(ADMIN)){ 381 serializer.setRootName("Admin"); 382 } else { 383 serializer.setRootName("WorkspaceProfile"); 384 } 385 serializer.setElementName("item"); 386 serializer.setTypeHintsEnabled(false); 387 String xml = serializer.write( json ); 388 Admin.notifyUser("XML:" + xml); 389 390 InputStream is_xml = new ByteArrayInputStream( xml.getBytes( ) ); 391 392 Admin.writeToFile(getPath(), is_xml); 393 394 String ret = "1"; 395 this.setResultStream( new ByteArrayInputStream(ret.getBytes())); 396 397 398 return SUCCESS; 399 } 400 */ 306 401 307 public void changeQueryId(Document doc, String from_id, String to_id) throws XPathExpressionException{ 402 308 InputStream is = null; … … 692 598 serializer.setTypeHintsEnabled(false); 693 599 String xml = serializer.write( json ); 694 // Admin.notifyUser("XML:" + xml);600 //log.debug("XML:" + xml); 695 601 InputStream is_xml = new ByteArrayInputStream( xml.getBytes( ) ); 696 602 // add to document 697 // Admin.writeToFile(getPath(), is_xml);603 //Utils.writeToFile(getPath(), is_xml); 698 604 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 699 605 DocumentBuilder builder = factory.newDocumentBuilder(); … … 970 876 } 971 877 // nodelistto stream 972 InputStream is = Helpers.DocumentToStream(list.item(0));878 InputStream is = Utils.document2Stream(list.item(0)); 973 879 this.setSourceStream(is); 974 880 … … 1022 928 this.saveDocument(); 1023 929 1024 // Admin.notifyUser("new document");930 //log.debug("new document"); 1025 931 } catch (ParserConfigurationException e) { 1026 932 // TODO Auto-generated catch block … … 1051 957 init = true; 1052 958 } catch (IOException ex){ 1053 // Admin.notifyUser("initCacheCounter:" + ex.toString());959 //log.debug("initCacheCounter:" + ex.toString()); 1054 960 ex.printStackTrace(); 1055 961 } … … 1070 976 //workspace_doc.getFirstChild().getAttributes().getNamedItem("idcounter").setNodeValue(i.toString()); 1071 977 1072 // Admin.notifyUser("writeCacheCounter:" + i.toString());978 //log.debug("writeCacheCounter:" + i.toString()); 1073 979 // write xml 1074 980 Transformer transformer; -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/WorkspaceRepositoryAction.java
r1530 r1540 1 1 package eu.clarin.cmdi.mdservice.action; 2 2 3 import java.io.BufferedInputStream;4 import java.io.ByteArrayInputStream;5 import java.io.ByteArrayOutputStream;6 import java.io.File;7 import java.io.FileInputStream;8 import java.io.FileWriter;9 import java.io.IOException;10 import java.io.InputStream;11 import java.io.StringWriter;12 import java.io.UnsupportedEncodingException;13 import java.net.MalformedURLException;14 import java.net.URL;15 import java.text.DateFormat;16 import java.text.SimpleDateFormat;17 import java.util.Date;18 import java.util.HashMap;19 20 import javax.xml.parsers.DocumentBuilder;21 import javax.xml.parsers.DocumentBuilderFactory;22 import javax.xml.parsers.ParserConfigurationException;23 import javax.xml.transform.OutputKeys;24 import javax.xml.transform.Result;25 import javax.xml.transform.Source;26 import javax.xml.transform.Transformer;27 import javax.xml.transform.TransformerConfigurationException;28 import javax.xml.transform.TransformerException;29 import javax.xml.transform.TransformerFactory;30 import javax.xml.transform.TransformerFactoryConfigurationError;31 import javax.xml.transform.dom.DOMSource;32 import javax.xml.transform.stream.StreamResult;33 import javax.xml.xpath.XPath;34 import javax.xml.xpath.XPathConstants;35 import javax.xml.xpath.XPathExpression;36 import javax.xml.xpath.XPathExpressionException;37 import javax.xml.xpath.XPathFactory;38 39 import net.sf.json.JSON;40 import net.sf.json.JSONObject;41 import net.sf.json.JSONSerializer;42 import net.sf.json.xml.XMLSerializer;43 44 3 import org.apache.log4j.Logger; 45 import org.w3c.dom.DOMException;46 import org.w3c.dom.Document;47 import org.w3c.dom.Element;48 import org.w3c.dom.Node;49 import org.w3c.dom.NodeList;50 import org.xml.sax.SAXException;51 52 import eu.clarin.cmdi.mdservice.internal.Admin;53 import eu.clarin.cmdi.mdservice.internal.Cache;54 import eu.clarin.cmdi.mdservice.internal.MDTransformer;55 import eu.clarin.cmdi.mdservice.model.Diagnostic;56 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;57 58 4 59 5 /** -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/internal/Cache.java
r1513 r1540 35 35 36 36 import org.apache.commons.lang.StringEscapeUtils; 37 import org.apache.log4j.Logger; 37 38 import org.w3c.dom.Document; 38 39 import org.w3c.dom.Element; … … 50 51 * mapping the request parameters to the indexed files.</p> 51 52 * 52 * This is an internal object, direct user access to cache-data via interface is only possible via <code> AdminAction</code>53 * This is an internal object, direct user access to cache-data via interface is only possible via <code>...Action</code> 53 54 * @author master 54 55 * … … 56 57 57 58 public class Cache { 59 60 private static Logger log = Logger.getLogger("Cache"); 61 58 62 public static String PREFIX = "xc_"; 59 63 … … 72 76 73 77 public Cache () { 74 cachepath = Admin.getConfig().getProperty("cache.path");75 cacheindex_path = cachepath + Admin.getConfig().getProperty("cacheindex.file");78 cachepath = Utils.getConfig().getProperty("cache.path"); 79 cacheindex_path = cachepath + Utils.getConfig().getProperty("cacheindex.file"); 76 80 cachecounter = initCachecounter(); 77 81 … … 125 129 public String putInCache(String key_info, InputStream instream) { 126 130 127 Admin.notifyUser("CACHE.putInCache:"+key_info);131 log.debug("CACHE.putInCache:"+key_info); 128 132 Integer c = getCounter(); 129 133 String xc; 130 134 131 132 135 //update xml_structure 133 136 Element e = cacheindex_doc.createElement("f"); 134 //Attr attr = cacheindex_doc.createAttribute("id");135 //attr.setValue(c.toString());136 //e.setNamedItem(attr);137 137 e.setAttribute("id", c.toString()); 138 138 String[] key_array = key_info.split("//-"); … … 197 197 198 198 // update XML-counter 199 //Admin.writeToFile(formPath(id + xc),instream);200 201 199 updateCachecounter(); 202 200 203 201 xc = PREFIX + key_array[0] + "_" + c.toString(); 204 Admin.notifyUser("CACHE.putInCache.filename:" + xc + ".xml");205 Admin.writeToFile(cachepath + xc + ".xml",instream);202 log.debug("CACHE.putInCache.filename:" + xc + ".xml"); 203 Utils.write2File(cachepath + xc + ".xml",instream); 206 204 207 205 return xc; … … 213 211 214 212 File f = new File (formPath(key_info)); 215 //Admin.notifyUser("CACHE.getFromCache:"+key_info);216 217 213 218 214 if (f.exists()) { // read from file to InputStream; 219 Admin.notifyUser("CACHE.getFromCache.fromfile:"+f.getName() + "[#" + key_info + "]");215 log.debug("CACHE.getFromCache.fromfile:"+f.getName() + "[#" + key_info + "]"); 220 216 InputStream instream; 221 217 try { … … 224 220 return instream; 225 221 } catch (FileNotFoundException e) { 226 // TODO Auto-generated catch block 227 e.printStackTrace(); 222 Utils.errorMessage(e); 228 223 return null; 229 224 } 230 225 231 226 } else { //not cached, my dear 232 Admin.notifyUser("CACHE.getFromCache: NOT CACHED" + "[#" + key_info + "]");227 log.debug("CACHE.getFromCache: NOT CACHED" + "[#" + key_info + "]"); 233 228 return null; 234 229 } … … 245 240 query = new Query("", str,"recordset",""); 246 241 if (query.isStatus(Query.PARSEERROR)) { 247 Admin.notifyUser("Cache.transformQuery.PARSEERROR:" + query.getMsg());242 log.debug("Cache.transformQuery.PARSEERROR:" + query.getMsg()); 248 243 // pass this bad news to the client 249 //setUserMsg(query.getMsg());250 244 transformed = ""; 251 245 } else { 252 246 transformed = Query.getSimpleQueryString(str); 253 247 transformed = StringEscapeUtils.escapeXml(transformed); 254 // Admin.notifyUser("CACHE.transformQuery:"+transformed);248 //log.debug("CACHE.transformQuery:"+transformed); 255 249 } 256 250 return transformed; … … 268 262 269 263 if(key_array.length > 1){ 270 // Admin.notifyUser("formPATH- querystring:" + key_array[1]);264 // log.debug("formPATH- querystring:" + key_array[1]); 271 265 if (key_array[0].equals("recordset")){ 272 266 query_str = this.transformQuery(key_array[1]); 273 // Admin.notifyUser("formPATH- querystring-transformed:" + query_str);267 // log.debug("formPATH- querystring-transformed:" + query_str); 274 268 } 275 269 else { … … 319 313 } 320 314 321 // Admin.notifyUser("formPath:xpath:"+xpath_expr);315 //log.debug("formPath:xpath:"+xpath_expr); 322 316 //creating an XPathFactory: 323 317 XPathFactory factory = XPathFactory.newInstance(); … … 335 329 path = cachepath + PREFIX + key_array[0] + "_"+id + ".xml"; 336 330 } else if (list.getLength() > 1){ 337 Admin.notifyUser("formPath ERROR:!!!:multiple paths:"+key_info);331 log.debug("formPath ERROR:!!!:multiple paths:"+key_info); 338 332 339 333 } 340 334 341 335 } catch (XPathExpressionException e) { 342 // TODO Auto-generated catch block343 Admin.notifyUser("ERROR Cache.formPath: "+xpath_expr);336 log.debug("ERROR Cache.formPath: "+xpath_expr); 337 log.error(Utils.errorMessage(e)); 344 338 } 345 339 … … 353 347 354 348 /** 355 * read counter-integer from file in cache349 * Read counter-integer from file in cache 356 350 * or start that file 357 351 * @return The current maximum cache counter … … 360 354 361 355 Integer counter = start_cache; 362 boolean init=false;363 356 String fname = cacheindex_path; 364 357 File f = new File (fname); 365 358 366 //Admin.notifyUser("initCacheCounter");367 359 if (!f.exists()) { 368 360 // create new counter document … … 378 370 writeCachecounter(counter); 379 371 380 //Admin.notifyUser("new document");381 372 } catch (ParserConfigurationException e) { 382 // TODO Auto-generated catch block 383 e.printStackTrace(); 373 log.error(Utils.errorMessage(e)); 384 374 } 385 386 //} catch (IOException e2) {387 // Admin.notifyUser("ERROR creating cache counter");388 // e2.printStackTrace();389 //}390 375 } 391 376 else { … … 399 384 cacheindex_doc = docBuilder.parse(fname); 400 385 } catch (SAXException e) { 401 // TODO Auto-generated catch block 402 403 e.printStackTrace(); 386 log.error(Utils.errorMessage(e)); 404 387 } 405 388 } catch (ParserConfigurationException e) { 406 // TODO Auto-generated catch block 407 e.printStackTrace(); 389 log.error(Utils.errorMessage(e)); 408 390 } 409 391 410 392 //read counter 411 393 counter = new Integer(cacheindex_doc.getFirstChild().getAttributes().getNamedItem("idcounter").getNodeValue()); 412 init = true; 413 } catch (IOException ex){ 414 //Admin.notifyUser("initCacheCounter:" + ex.toString()); 415 ex.printStackTrace(); 394 } catch (IOException e){ 395 log.error(Utils.errorMessage(e)); 416 396 } 417 397 } 418 398 419 399 return counter; 420 /*421 //use buffering, reading one line at a time422 //FileReader always assumes default encoding is OK!423 BufferedReader input = new BufferedReader(new FileReader(f));424 try {425 String line = null; //not declared within while loop426 /*427 * readLine is a bit quirky :428 * it returns the content of a line MINUS the newline.429 * it returns null only for the END of the stream.430 * it returns an empty String if two newlines appear in a row.431 *432 try {433 if (( line = input.readLine()) != null){434 try {435 counter = new Integer(line);436 } catch (NumberFormatException e) {437 // if not a number, write a number438 init=true;439 }440 } else {441 init=true;442 }443 } catch (IOException e) {444 init=true;445 }446 447 if (init) {448 writeCachecounter( start_cache);449 }450 451 } finally {452 input.close();453 }454 */455 400 } 456 401 457 402 public void updateCachecounter () { 458 //Admin.notifyUser("CACHEcounter:" + cachecounter);459 403 writeCachecounter( cachecounter); 460 404 } … … 464 408 cacheindex_doc.getFirstChild().getAttributes().getNamedItem("idcounter").setNodeValue(i.toString()); 465 409 466 //Admin.notifyUser("writeCacheCounter:" + i.toString());467 410 // write xml 468 411 Transformer transformer; … … 476 419 try { 477 420 transformer.transform(source, result); 478 } catch (TransformerException e1) { 479 // TODO Auto-generated catch block 480 e1.printStackTrace(); 421 } catch (TransformerException e) { 422 log.error(Utils.errorMessage(e)); 481 423 } 482 424 483 425 String xmlString = result.getWriter().toString(); 484 //Admin.notifyUser("writeCacheCounter:" + xmlString);485 //Admin.writeToFile("", result);486 487 426 488 427 File f = new File (cacheindex_path); … … 494 433 fw.close(); 495 434 } catch (IOException e) { 496 // TODO Auto-generated catch block 497 e.printStackTrace(); 435 log.error(Utils.errorMessage(e)); 498 436 } 499 437 } catch (IOException e) { 500 // TODO Auto-generated catch block 501 e.printStackTrace(); 502 } 503 } catch (TransformerConfigurationException e2) { 504 // TODO Auto-generated catch block 505 e2.printStackTrace(); 506 } catch (TransformerFactoryConfigurationError e2) { 507 // TODO Auto-generated catch block 508 e2.printStackTrace(); 509 } 510 511 512 513 /* 514 File f = new File (Admin.getConfig().getProperty("cache.path") + "counter.txt"); 515 516 try { 517 Writer output = new BufferedWriter(new FileWriter(f)); 518 //FileWriter always assumes default encoding is OK! 519 try { 520 output.write( i); 521 } finally { 522 output.close(); 523 } 524 } catch (IOException e) { 525 // TODO Auto-generated catch block 526 e.printStackTrace(); 527 } 528 */ 438 log.error(Utils.errorMessage(e)); 439 } 440 } catch (TransformerConfigurationException e) { 441 log.error(Utils.errorMessage(e)); 442 } catch (TransformerFactoryConfigurationError e) { 443 log.error(Utils.errorMessage(e)); 444 } 445 529 446 } 530 447 531 448 public InputStream clear(HashMap<String,String> clear_params) throws ParserConfigurationException, TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError { 532 449 String xpath_expr = ""; 533 Integer removed = 0;534 450 InputStream is = null; 535 451 … … 604 520 Result outputTarget = new StreamResult(outputStream); 605 521 TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget); 606 is = new ByteArrayInputStream(outputStream.toByteArray()); 607 608 removed = list.getLength(); 522 is = new ByteArrayInputStream(outputStream.toByteArray()); 609 523 610 524 } catch (XPathExpressionException e) { 611 // TODO Auto-generated catch block 612 e.printStackTrace(); 525 log.error(Utils.errorMessage(e)); 613 526 } 614 527 -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/internal/MDTransformer.java
r1527 r1540 31 31 import net.sf.saxon.event.MessageEmitter; 32 32 33 //import com.icl.saxon.*;34 //import com.icl.saxon.FeatureKeys;35 //import com.icl.saxon.Loader;36 //import com.icl.saxon.output.Emitter;37 38 39 33 /** 40 34 * Helper class, encapsulating the xsl-transformations handling. 41 * The contract is, that the requester passes a key, which can be resolved to a xsl-script (momentary mapped in properties: Admin.getConfig())35 * The contract is, that the requester passes a key, which can be resolved to a xsl-script (momentary mapped in properties: Utils.getConfig()) 42 36 * 43 37 * Bad things happen, if the key or the appropriate xsl-file do not exist - well the client gets a diagnostic message. … … 50 44 public class MDTransformer { 51 45 52 private static Logger log = Logger.getLogger("MD RepoProxy");46 private static Logger log = Logger.getLogger("MDTransformer"); 53 47 54 48 private URL srcFile ; … … 86 80 return this.params; 87 81 } 88 /** 89 * get the path to the transform-xsl file from properties, based on the key (aka format-parameter) 82 83 /** 84 * Get the path to the xsl file from properties, based on the key (aka format-parameter) 90 85 * @param key 91 86 * @return … … 94 89 private String getXSLPath (String key) throws NoStylesheetException { 95 90 String xslpath = ""; 96 String xslfilename= Admin.getConfig().getProperty("xsl." + key);91 String xslfilename= Utils.getConfig().getProperty("xsl." + key); 97 92 98 93 if (xslfilename!=null) { 99 xslpath = Admin.getConfig().getProperty("scripts.path") + xslfilename;94 xslpath = Utils.getConfig().getProperty("scripts.path") + xslfilename; 100 95 } else { 101 96 throw new NoStylesheetException("No Stylesheet found for format-key: " + key); … … 104 99 return xslpath; 105 100 } 106 107 101 /** 108 102 * Tries to load the stylesheet based on the key. … … 135 129 } 136 130 137 /**138 * Makes the request-parameters available in the stylesheets139 * by translating them to stylesheet-parameters140 * @param transformer141 */142 public void SetTransformerParameters(Transformer transformer){143 144 Set<Entry<String, String[]>> set = params.entrySet();145 Iterator<Entry<String, String[]>> i = set.iterator();146 147 while(i.hasNext()){148 Map.Entry<String,String[]> e = (Map.Entry<String,String[]>)i.next();149 transformer.setParameter((String)e.getKey(), (String)e.getValue()[0]);150 }151 }152 131 153 132 /** … … 187 166 File f = new File(srcFile.getPath()); 188 167 189 // Admin.notifyUser("src:" + srcFile.getFile());190 // Admin.notifyUser("fpath:" + f.getAbsolutePath());168 //log.debug("src:" + srcFile.getFile()); 169 //log.debug("fpath:" + f.getAbsolutePath()); 191 170 String root_uri = srcFile.toString(); 192 171 String xsrcfile = srcFile.getFile(); … … 218 197 // Write <xsl:message> 219 198 writeXslMessages(w); 220 /// Admin.notifyUser(w.getBuffer().toString());199 ///log.debug(w.getBuffer().toString()); 221 200 } 222 201 … … 258 237 return transformXML ( xmlStream); 259 238 } 260 261 239 262 240 /** … … 315 293 try { 316 294 while ((s = br.readLine()) != null){ 317 Admin.notifyUser(s);295 log.debug(s); 318 296 } 319 297 } catch (IOException e) { 320 // TODO Auto-generated catch block 321 e.printStackTrace(); 298 log.error(Utils.errorMessage(e)); 322 299 } 323 300 } 301 302 /** 303 * Makes the request-parameters available in the stylesheets 304 * by translating them to stylesheet-parameters 305 * @param transformer 306 */ 307 public void SetTransformerParameters(Transformer transformer){ 308 309 Set<Entry<String, String[]>> set = params.entrySet(); 310 Iterator<Entry<String, String[]>> i = set.iterator(); 311 312 while(i.hasNext()){ 313 Map.Entry<String,String[]> e = (Map.Entry<String,String[]>)i.next(); 314 transformer.setParameter((String)e.getKey(), (String)e.getValue()[0]); 315 } 316 } 317 324 318 325 319 public static HashMap<String,String[]> createParamsMap(String key){ -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Diagnostic.java
r1511 r1540 11 11 */ 12 12 13 import java.io.IOException;14 import java.io.InputStream;15 import java.net.MalformedURLException;16 import java.net.URL;17 13 import java.util.HashMap; 18 14 19 import javax.xml.parsers.DocumentBuilder;20 import javax.xml.parsers.DocumentBuilderFactory;21 22 import org.apache.commons.io.IOUtils;23 15 import org.w3c.dom.Attr; 24 16 import org.w3c.dom.Document; 25 17 import org.w3c.dom.Element; 26 import org.z3950.zing.cql.CQLNode;27 import org.z3950.zing.cql.CQLParseException;28 import org.z3950.zing.cql.CQLParser;29 30 import eu.clarin.cmdi.mdservice.internal.Admin;31 import eu.clarin.cmdi.mdservice.internal.MDTransformer;32 18 33 19 public class Diagnostic { -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Diagnostics.java
r1514 r1540 11 11 */ 12 12 13 import java.io.ByteArrayInputStream;14 import java.io.IOException;15 13 import java.io.InputStream; 16 import java.io.StringWriter;17 import java.io.UnsupportedEncodingException;18 import java.net.MalformedURLException;19 import java.net.URL;20 14 import java.util.ArrayList; 21 15 import java.util.Iterator; 22 import java.util.List;23 16 24 17 import javax.xml.parsers.DocumentBuilder; 25 18 import javax.xml.parsers.DocumentBuilderFactory; 26 19 import javax.xml.parsers.ParserConfigurationException; 27 import javax.xml.transform.OutputKeys;28 import javax.xml.transform.Transformer;29 import javax.xml.transform.TransformerConfigurationException;30 import javax.xml.transform.TransformerException;31 import javax.xml.transform.TransformerFactory;32 import javax.xml.transform.TransformerFactoryConfigurationError;33 import javax.xml.transform.dom.DOMSource;34 import javax.xml.transform.stream.StreamResult;35 20 36 import org.apache.commons.io.IOUtils;37 21 import org.w3c.dom.Document; 38 22 import org.w3c.dom.Element; 39 import org.z3950.zing.cql.CQLNode;40 import org.z3950.zing.cql.CQLParseException;41 import org.z3950.zing.cql.CQLParser;42 43 import eu.clarin.cmdi.mdservice.internal.Admin;44 import eu.clarin.cmdi.mdservice.internal.MDTransformer;45 23 46 24 public class Diagnostics { … … 87 65 88 66 Element d = doc.createElement("diagnostics"); 89 Iterator itr = list.iterator();67 Iterator<Diagnostic> itr = list.iterator(); 90 68 while(itr.hasNext()) 91 69 d.appendChild(((Diagnostic)itr.next()).buildXMLNode(doc)); … … 95 73 return doc; 96 74 } 97 // @SuppressWarnings("unchecked") 75 76 //TODO to Utils.java 77 /* 98 78 public InputStream buildXMLStream() throws ParserConfigurationException, TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError, UnsupportedEncodingException{ 99 79 if (xmlstream == null){ … … 107 87 return xmlstream; 108 88 } 89 */ 109 90 110 91 public boolean Accepted(){ … … 112 93 113 94 if (this.list.size() > 0){ 114 Iterator itr = list.iterator();95 Iterator<Diagnostic> itr = list.iterator(); 115 96 while(itr.hasNext() && accepted) 116 97 { -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Query.java
r1517 r1540 21 21 import javax.xml.parsers.DocumentBuilderFactory; 22 22 23 import org.apache.log4j.Logger; 23 24 import org.w3c.dom.Document; 24 25 import org.z3950.zing.cql.CQLNode; … … 26 27 import org.z3950.zing.cql.CQLParser; 27 28 28 import eu.clarin.cmdi.mdservice.internal. Admin;29 import eu.clarin.cmdi.mdservice.internal.Utils; 29 30 import eu.clarin.cmdi.mdservice.internal.MDTransformer; 30 31 import eu.clarin.cmdi.mdservice.internal.NoStylesheetException; 31 32 32 33 public class Query { 34 35 public static Logger log = Logger.getLogger("Query"); 36 33 37 public static String COLLECTION = "collection"; 34 38 public static String COLUMNS = "columns"; … … 170 174 full_query_string = ""; 171 175 } 172 Admin.notifyUser("QUERY.FULLQUERYSTRING:" + full_query_string);176 log.debug("QUERY.FULLQUERYSTRING:" + full_query_string); 173 177 if (type.equals(RECORDSET) && (full_query_string.length() > 0)) { 174 178 parse(); … … 331 335 simple_form = simple_form + rel + arr_or[j]; 332 336 } 333 //Admin.notifyUser(simple_form);337 334 338 if (arr_or.length > 1){ 335 339 simple_form = "(" + simple_form + ") "; … … 392 396 // probably not the best place to handle -> move to repository: sanitize-query? 393 397 String corrid = getQueryString().replace(":","\\:").toLowerCase(); 394 Admin.notifyUser("Query.toURLParam.corrid=" + corrid);398 log.debug("Query.toURLParam.corrid=" + corrid); 395 399 targetRequest = "//MdSelfLink[ft:query(.,'" + corrid + "')]"; 396 400 } else { … … 446 450 447 451 try { 448 Admin.notifyUser(toXCQL());452 log.debug(toXCQL()); 449 453 450 454 … … 453 457 Document doc = builder.parse(new org.xml.sax.InputSource(new java.io.StringReader(toXCQL()))); 454 458 455 // Admin.notifyUser("document created");459 //log.debug("document created"); 456 460 SearchClauses searchclauses = new SearchClauses(doc); 457 461 //do the processing … … 459 463 String xml_s = searchclauses.toXML(); 460 464 461 //Admin.notifyUser("AAAA2:" + xml_s);465 462 466 } 463 467 catch (Exception e) { -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Result.java
r1511 r1540 6 6 import javax.xml.transform.TransformerException; 7 7 8 import eu.clarin.cmdi.mdservice.internal.Admin; 8 import org.apache.log4j.Logger; 9 10 import eu.clarin.cmdi.mdservice.internal.Utils; 9 11 import eu.clarin.cmdi.mdservice.internal.MDTransformer; 10 12 import eu.clarin.cmdi.mdservice.internal.NoStylesheetException; … … 21 23 public class Result { 22 24 25 public static Logger log = Logger.getLogger("Result"); 23 26 /** 24 27 * available formats … … 59 62 } else { 60 63 transformkey = parentQuery.getType() + "2" + format; 61 Admin.notifyUser("transformkey: " + transformkey );64 log.debug("transformkey: " + transformkey ); 62 65 MDTransformer transformer = new MDTransformer(); 63 66 transformer.setParams(MDTransformer.createParamsMap(transformkey)); -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/SearchClauses.java
r1511 r1540 16 16 import org.w3c.dom.NodeList; 17 17 18 import eu.clarin.cmdi.mdservice.internal. Admin;18 import eu.clarin.cmdi.mdservice.internal.Utils; 19 19 import eu.clarin.cmdi.mdservice.action.DCRProxyAction; 20 20 … … 35 35 } 36 36 xml_document= _doc; 37 Admin.notifyUser("SCCCCC: constuctor");37 //log.debug("SCCCCC: constuctor"); 38 38 deserialize(); 39 39 // do processing … … 103 103 deserialize(b,nodeList.item(1), nodeList.item(2),0); 104 104 }else{ 105 Admin.notifyUser("SCCCCC: deserialize");105 //log.debug("SCCCCC: deserialize"); 106 106 if (node.getNodeName().equals("searchClause")){ 107 107 … … 111 111 } 112 112 } 113 Admin.notifyUser("SCCCCC: list " + list[0][0].getIndex() + list[0][0].getValue());113 //log.debug("SCCCCC: list " + list[0][0].getIndex() + list[0][0].getValue()); 114 114 115 115 … … 165 165 166 166 // remove old document 167 Admin.notifyUser("SCCCCC: serialize");168 Admin.notifyUser("SCCCCC: " + xml_document.getChildNodes().getLength());167 //log.debug("SCCCCC: serialize"); 168 //log.debug("SCCCCC: " + xml_document.getChildNodes().getLength()); 169 169 xml_document.removeChild(xml_document.getFirstChild()); 170 Admin.notifyUser("SCCCCC: CLEARED " + xml_document.getChildNodes().getLength());170 //log.debug("SCCCCC: CLEARED " + xml_document.getChildNodes().getLength()); 171 171 172 172 if ((getLastAnd() == 1) && (getLastOr(0) == 1)){ 173 Admin.notifyUser("SCCCCC: searchClause ");173 //log.debug("SCCCCC: searchClause "); 174 174 root = xml_document.createElement("searchClause"); 175 175 e = xml_document.createElement("index"); … … 232 232 } 233 233 xml_string = sw.toString(); 234 Admin.notifyUser("SERIALIZED-XML: " + xml_string);234 //log.debug("SERIALIZED-XML: " + xml_string); 235 235 } catch (TransformerConfigurationException e1) { 236 236 // TODO Auto-generated catch block -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Termset.java
r1511 r1540 9 9 import javax.xml.xpath.XPathFactory; 10 10 11 import org.apache.log4j.Logger; 11 12 import org.w3c.dom.Document; 12 13 import org.w3c.dom.Node; 13 14 import org.w3c.dom.NodeList; 14 15 15 import eu.clarin.cmdi.mdservice.internal. Admin;16 import eu.clarin.cmdi.mdservice.internal.Utils; 16 17 17 18 public class Termset { 18 19 20 public static Logger log = Logger.getLogger("Termset"); 21 19 22 private final static HashMap<String,Object> termsets = new HashMap<String,Object>(); 20 23 … … 51 54 52 55 Termset res = (Termset) getTermsets().get(ts_id); 53 if (res==null) Admin.notifyUser("getTermset(): no termset found for:" + ts_id);56 if (res==null) log.debug("getTermset(): no termset found for:" + ts_id); 54 57 //else 55 // Admin.notifyUser("getDCR():" + res.getAttr("id") + ":" + res.getAttr("url") );58 //log.debug("getDCR():" + res.getAttr("id") + ":" + res.getAttr("url") ); 56 59 return res; 57 60 } … … 65 68 66 69 public static void initTermsets() { 67 Document dcrs_setup = Admin.getXMLDocument(Admin.getConfig().getProperty("terms.file"));70 Document dcrs_setup = Utils.load2Document(Utils.getConfig().getProperty("terms.file")); 68 71 69 // Admin.loadFile(Admin.getConfig().getProperty("service.list.file"));70 Admin.notifyUser("initTermsets().loaded.");72 // Utils.load2(Utils.getConfig().getProperty("service.list.file")); 73 log.debug("initTermsets().loaded."); 71 74 //.getDocumentElement().getLocalName() 72 //Document chains_doc = Admin.getXMLDocument(Admin.getConfig().getProperty("chains.file"));75 //Document chains_doc = Utils.load2Document(Utils.getConfig().getProperty("chains.file")); 73 76 74 // Admin.notifyUser("formPath:xpath:"+xpath_expr);77 //log.debug("formPath:xpath:"+xpath_expr); 75 78 //creating an XPathFactory: 76 79 XPathFactory factory = XPathFactory.newInstance(); … … 91 94 Termset ts = new Termset(n); 92 95 93 Admin.notifyUser("reading in Termset: " + ts.getAttr("id"));96 log.debug("reading in Termset: " + ts.getAttr("id")); 94 97 termsets.put(ts.getAttr("id"), ts ); 95 98 } -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/WorkspaceProfile.java
r1538 r1540 11 11 import net.sf.json.JSONArray; 12 12 import net.sf.json.JSONObject; 13 import eu.clarin.cmdi.mdservice.internal.Admin;14 import eu.clarin.cmdi.mdservice.action.GenericProxyAction;15 import eu.clarin.cmdi.mdservice.internal.Helpers;16 13 import eu.clarin.cmdi.mdservice.internal.MDTransformer; 14 import eu.clarin.cmdi.mdservice.internal.Utils; 17 15 import eu.clarin.cmdi.mdservice.action.WorkspaceAction; 18 16 import eu.clarin.cmdi.mdservice.internal.NoStylesheetException; … … 220 218 221 219 public static JSONArray createRepositories() throws IOException, InterruptedException, TransformerException, NoStylesheetException{ 222 String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;220 String path = Utils.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER; 223 221 File file=new File(path); 224 222 InputStream in = new BufferedInputStream( new FileInputStream(path));; … … 229 227 InputStream jsonstream = transformer.transformXML(in); 230 228 231 JSONObject json = JSONObject.fromObject( Helpers.convertStreamToString(jsonstream));229 JSONObject json = JSONObject.fromObject(Utils.streamToString(jsonstream)); 232 230 JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles"); 233 231 JSONArray array = null; … … 254 252 255 253 public static JSONObject createOptions() throws IOException, InterruptedException, TransformerException, NoStylesheetException{ 256 String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;254 String path = Utils.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER; 257 255 File file=new File(path); 258 256 InputStream in = new BufferedInputStream( new FileInputStream(path));; … … 263 261 InputStream jsonstream = transformer.transformXML(in); 264 262 265 JSONObject json = JSONObject.fromObject( Helpers.convertStreamToString(jsonstream));263 JSONObject json = JSONObject.fromObject(Utils.streamToString(jsonstream)); 266 264 JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles"); 267 265 JSONObject obj = null; … … 306 304 307 305 public static JSONArray createTermsets() throws IOException, InterruptedException, TransformerException, NoStylesheetException{ 308 String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;306 String path = Utils.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER; 309 307 File file=new File(path); 310 308 InputStream in = new BufferedInputStream( new FileInputStream(path));; … … 315 313 InputStream jsonstream = transformer.transformXML(in); 316 314 317 JSONObject json = JSONObject.fromObject( Helpers.convertStreamToString(jsonstream));315 JSONObject json = JSONObject.fromObject(Utils.streamToString(jsonstream)); 318 316 JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles"); 319 317 JSONArray array = null; -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/BasicProxy.java
r1536 r1540 1 1 package eu.clarin.cmdi.mdservice.proxy; 2 2 3 import java.io.File;4 3 import java.io.IOException; 5 4 import java.io.InputStream; 6 import java.io.StringReader;7 import java.io.StringWriter;8 5 import java.net.MalformedURLException; 9 import java.net.URISyntaxException;10 6 import java.net.URL; 11 7 import java.net.URLConnection; 12 import java.util.HashMap;13 import java.io.ByteArrayInputStream;14 15 import javax.xml.parsers.DocumentBuilder;16 import javax.xml.parsers.DocumentBuilderFactory;17 import javax.xml.transform.OutputKeys;18 import javax.xml.transform.Transformer;19 import javax.xml.transform.TransformerException;20 import javax.xml.transform.TransformerFactory;21 import javax.xml.transform.dom.DOMSource;22 import javax.xml.transform.stream.StreamResult;23 24 8 import org.apache.log4j.Logger; 25 import org.w3c.dom.Document;26 import org.w3c.dom.Node;27 import org.w3c.dom.NodeList;28 import org.xml.sax.InputSource;29 30 9 import eu.clarin.cmdi.mdservice.action.GenericAction; 31 import eu.clarin.cmdi.mdservice.action.RepoAction;32 import eu.clarin.cmdi.mdservice.internal.Admin;33 10 import eu.clarin.cmdi.mdservice.internal.NoStylesheetException; 34 import eu.clarin.cmdi.mdservice.model.Diagnostic; 35 import eu.clarin.cmdi.mdservice.model.Query; 36 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; 11 import eu.clarin.cmdi.mdservice.model.Termset; 37 12 38 13 /** … … 96 71 97 72 public String getBaseURI() { 98 String uri =Admin.getConfig().getProperty(getSourceAction().getActionkey() + ".uri"); 73 //String uri =Utils.getConfig().getProperty(getSourceAction().getActionkey() + ".uri"); 74 String uri = Termset.getTermsetAttr(getSourceAction().getActionkey(), "url"); 99 75 return uri; 100 76 } -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/MDRepoProxy.java
r1515 r1540 1 1 package eu.clarin.cmdi.mdservice.proxy; 2 2 3 import java.io.File;4 3 import java.io.IOException; 5 import java.io.InputStream;6 import java.io.StringReader;7 import java.io.StringWriter;8 import java.net.MalformedURLException;9 import java.net.URISyntaxException;10 4 import java.net.URL; 11 5 import java.util.HashMap; 12 import java.io.ByteArrayInputStream;13 14 import javax.xml.parsers.DocumentBuilder;15 import javax.xml.parsers.DocumentBuilderFactory;16 import javax.xml.transform.OutputKeys;17 import javax.xml.transform.Transformer;18 import javax.xml.transform.TransformerException;19 import javax.xml.transform.TransformerFactory;20 import javax.xml.transform.dom.DOMSource;21 import javax.xml.transform.stream.StreamResult;22 23 6 import org.apache.log4j.Logger; 24 import org.w3c.dom.Document;25 import org.w3c.dom.Node;26 import org.w3c.dom.NodeList;27 import org.xml.sax.InputSource;28 29 import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;30 7 import eu.clarin.cmdi.mdservice.model.Query; 31 8 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; … … 110 87 URL targetURL = null; 111 88 targetURL =new URL( getBaseURL(), urls.get(getActionkey()) + query.toURLParam() ); 112 Admin.notifyUser("MDRPA.targetURL.query.toURLParam:" + query.toURLParam());113 Admin.notifyUser("MDRPA.targetURL:" + targetURL);89 log.debug("MDRPA.targetURL.query.toURLParam:" + query.toURLParam()); 90 log.debug("MDRPA.targetURL:" + targetURL); 114 91 return targetURL; 115 92 } -
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/SRUProxy.java
r1511 r1540 259 259 public String getBaseURI() { 260 260 log.debug("SRU-repositorypath:" + WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository())); 261 String uri = WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository());// Admin.getConfig().getProperty(getProxyKey() + ".uri");261 String uri = WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository());//Utils.getConfig().getProperty(getProxyKey() + ".uri"); 262 262 return uri; 263 263 } … … 319 319 } else { 320 320 if (operation.equals("explain") || operation == null){ 321 Admin.notifyUser("explaining", "debug");321 log.debug("explaining", "debug"); 322 322 }else { 323 323 if (operation.equals("scan")){ -
MDService2/branches/MDService_simple3/src/struts.xml
r1532 r1540 1 <?xml version="1.0" encoding="UTF-8"?>2 1 <!DOCTYPE struts PUBLIC 3 2 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" … … 21 20 <param name="location">/Error.jsp</param> 22 21 </result> --> 23 <result name="error" type="stream"> 24 <param name="contentType">text/xml</param> 25 <param name="inputName">resultStream</param> 26 </result> 22 <result name="error">/Error.jsp</result> 27 23 <!-- <result name="error" type="redirectAction"></result> 28 24 -->
Note: See TracChangeset
for help on using the changeset viewer.