Changeset 1495
- Timestamp:
- 08/25/11 20:21:23 (13 years ago)
- Location:
- MDService2/trunk/MDService2
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService2/trunk/MDService2/WebContent/static/queries2.xml
r1488 r1495 6 6 <dd><p>just one word like:</p> 7 7 <ul> 8 <li><a class="query" href="?squery=system">system</a></li> 8 <li><a class="query count" href="?squery=system">system</a></li> 9 <li><a class="query count" href="?squery=-year-olds">-year-olds</a> - a bug solved (parser doesn't like '-' at the beginning!)</li> 10 <li><a class="query count" href="?squery=acquisition">acquisition</a></li> 9 11 </ul> 10 12 </dd> 11 13 12 <!--14 13 15 <dt >all of multiple terms (AND)</dt> 14 16 <dd> 15 17 <ul> 16 <li><a class="query " href="/MDService2/?squery=child%20acquisition">child acquisition</a></li>17 <li><a class="query " href="/MDService2/?squery=longitudinal%20study">longitudinal study</a></li>18 <li><a class="query count" href="?squery=child%20acquisition">child acquisition</a></li> 19 <li><a class="query count" href="?squery=longitudinal%20study">longitudinal study</a></li> 18 20 </ul> 19 21 </dd> … … 21 23 <dd>a sequence of terms 22 24 <ul> 23 <li><a class="query " href="/MDService2/?squery=%22longitudinal%20study%22">"longitudinal study"</a></li>25 <li><a class="query count" href="?squery=%22longitudinal%20study%22">"longitudinal study"</a></li> 24 26 </ul> 25 </dd> 26 <dt >Bookmarks</dt> 27 </dd> 28 29 <dt >Special stuff</dt> 30 <dd> 31 <ul> 32 <li><a class="query" href="?q=clarin.eu:ws-registry&repository=localhost-mirror">WS registry</a></li> 33 </ul> 34 </dd> 35 36 <!-- 37 <dt >Bookmarks</dt> 27 38 <dd>search/remember individual records (by handle/identifier) 28 39 <ul> -
MDService2/trunk/MDService2/WebContent/style/cmds-ui.css
r1423 r1495 21 21 .data {display: none; } 22 22 .hilight { font-size: 1.1em; font-weight: bold} 23 .error { font-color: red}23 .error { color: #660000; border: 1px solid red; background-color: #ffcccc; } 24 24 /* this is temporary for MdREcordView-Titlebar; -> move to ui-box-header */ 25 25 /* obsolete .box_heading { background-color: #014172; color: #FAFAFF; font-weight: bold; padding: 2px; } -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Admin.java
r1429 r1495 37 37 private static String config_path = "mdservice.properties"; 38 38 private static Properties config; 39 public static Logger log = Logger.getLogger( "Admin.class");39 public static Logger log = Logger.getLogger(Admin.class); 40 40 41 41 public static String FATAL = "fatal"; -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Cache.java
r1234 r1495 38 38 /** 39 39 * This is a rudimentary caching mechanism. 40 * serializes the inputstream to a file (identifier => filename)41 * and returns the inpustream based on the identifier.40 * It serializes the inputstream to a file (identifier => filename) (putInCache()) 41 * or returns the inputstream based on the identifier (getFromCache()) 42 42 * 43 * It maintains the cache_index (persisted as xml-file in the cache-folder)44 * mapping the request parameters to the indexed files. 43 * <p>It maintains the cache_index (persisted as xml-file in the cache-folder) 44 * mapping the request parameters to the indexed files.</p> 45 45 * 46 46 * This is an internal object, direct user access to cache-data via interface is only possible via <code>AdminAction</code> … … 48 48 * 49 49 */ 50 /* TODO: necessary to maintain own index51 * for resolution of IDs to filenames52 */53 54 50 55 51 public class Cache { … … 353 349 * read counter-integer from file in cache 354 350 * or start that file 355 * @return 351 * @return The current maximum cache counter 356 352 */ 357 353 public Integer initCachecounter() { -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java
r1491 r1495 26 26 27 27 import org.apache.struts2.interceptor.ServletRequestAware; 28 29 28 import com.opensymphony.xwork2.ActionSupport; 30 31 29 import eu.clarin.cmdi.mdservice.model.Diagnostics; 32 30 33 31 /** 34 * main Struts 2 controller35 * responds to requests (collections, model, recordset)36 * by dispatching the requests to appropriate internal methods and filling the inputStream with the result32 * main Struts2 controller (ie implemenets the struts' execute()-method), all other Actions are derived from. 33 * Defines the methods used for retrieving the data 34 * and provides basic implementation where possible. 37 35 * 38 36 * @author vronk 39 *40 37 */ 41 38 public class GenericProxyAction extends ActionSupport … … 69 66 private String repository; 70 67 //private Map<String,Object> session; 71 private HttpServletRequest request; 72 private long duration = 0; 73 68 private HttpServletRequest request; 69 private long duration = 0; 70 private InputStream resultStream; 71 private InputStream sourceStream; 72 protected URL base_url ; 73 74 74 public GenericProxyAction(){ 75 75 super(); … … 198 198 } 199 199 200 /** 201 * is used in struts.xml to dynamically set the mime-type of the result, depending on the format-parameter 202 * @return 203 */ 200 204 public String getActionContentType() { 201 205 if (format.toLowerCase().startsWith("html")) { … … 269 273 270 274 /** 271 * primitiveidentification of the target-proxy272 * base for finding the right base_url in the prop s275 * internal identification of the target-proxy 276 * base for finding the right base_url in the properties 273 277 * subclass has to override with its specific proxykey 274 * @return 278 * @return the key identifying this type of proxy 275 279 */ 276 280 public String getProxyKey() { … … 278 282 } 279 283 284 /** 285 * TODO: check what this does, where it is used? 286 * @return 287 */ 280 288 public String getUserMsg() { 281 289 return userMsg; … … 286 294 } 287 295 296 /** 297 * TODO: check what this does, where it is used? 298 * @return 299 */ 288 300 @Override 289 301 public void setServletRequest(HttpServletRequest arg0) { … … 294 306 return request; 295 307 } 296 297 298 private InputStream resultStream;299 private InputStream sourceStream;300 308 301 309 /** … … 335 343 } 336 344 337 protected URL base_url ; 338 345 /** 346 * Reads URI from the configuration (mdservice.properties) based on the proxy-key 347 * @return the base-URI of the target repository or registry 348 */ 349 public String getBaseURI() { 350 String uri =Admin.getConfig().getProperty(getProxyKey() + ".uri"); 351 return uri; 352 } 353 354 /** 355 * Provides the base-URL specific to given target repository or registry 356 * @return 357 * @throws MalformedURLException 358 */ 339 359 public URL getBaseURL() throws MalformedURLException { 340 360 if (base_url == null) { … … 344 364 } 345 365 346 public String getBaseURI() { 347 String uri =Admin.getConfig().getProperty(getProxyKey() + ".uri"); 348 return uri; 349 } 350 351 366 /** 367 * Constructs the actual URL to be send to the target repository/registry 368 * It has to be overridden by the subclasses 369 * as every target service has a different request-pattern. 370 * @return URL of the target request 371 * @throws IOException 372 */ 352 373 public URL getTargetRequest() throws IOException { 353 // URL targetURL =new URL( base_url, compname + ".xml"); 354 URL targetURL = getBaseURL(); 355 374 URL targetURL = getBaseURL(); 356 375 return targetURL; 357 376 } 358 377 359 /* 360 public String getRequestKey() { 361 String key=""; 362 if (getActionkey()!=null) { 363 key += getActionkey() + "//-" ; 364 } 365 if (getQ()!=null) { 366 key += getQ() + "//-" ; 367 } 368 if (getCollection()!=null) { 369 key += getCollection(); 370 } 371 372 return key; 373 } 374 */ 375 378 /** 379 * Constructs an unambiguous key for the request (encoding all the parameters). 380 * This is used as identifier for caching 381 * @return key unambiguously encoding the request 382 */ 383 376 384 public String getRequestKey() { 377 385 String key=""; … … 416 424 }else{ 417 425 key +="//-" ; 418 } 419 426 } 420 427 421 return key; 422 } 428 return key; 429 } 430 431 423 432 public InputStream getSourceStream() throws IOException, NoStylesheetException { 424 433 return getTargetRequest().openStream(); 425 // Admin.notifyUser(getProxyKey() + ".getSourceStream() - unable to open stream: " + getTargetRequest(); 426 } 427 434 435 } 436 437 /* 438 * TODO: this should go to Utilities! 439 */ 428 440 public static String convertStreamToString(InputStream is) { 429 441 … … 677 689 } 678 690 691 /** 692 * This is the work-horse function. 693 * It does two things: 694 * a) check if the source data is already in cache (based on cache-key that is constructed from the request parameters) 695 * b) if format-parameter provided, invokes the transformation. 696 * at the end the data to be returned as result is contained in the resultStream 697 * If format is xml, then the data from sourceStream is passed further as resultStream. 698 * 699 * @throws Exception This is handled by struts (is mapped to some result in struts.xml based on the Exception-Class) 700 */ 679 701 680 702 public void prepare() throws Exception { … … 716 738 resultStream = sourceStream; 717 739 }else { 740 MDTransformer transformer = new MDTransformer(); 718 741 // set URL as srcFile (for MDTransformer to pass to xsl-scripts) 719 MDTransformer transformer = new MDTransformer();742 // TODO: WHY?? 720 743 transformer.setSrcFile(getTargetRequest()); 721 // getColumns722 // Admin.notifyUser("GPA.getRepository, before xsl:" + getRepository());723 744 transformer.setParams(createTransformerParams()); 724 725 resultStream = transformer.transformXML(sourceStream); //, getFullFormat(), getColumns(), getStartRecord(), getMaximumRecords(),getLang(),getQ(),String.valueOf(getRepository()));745 // here the transformation is invoked 746 resultStream = transformer.transformXML(sourceStream); 726 747 } 727 748 … … 730 751 731 752 /** 732 * default Action method 753 * default Action method that gets called by Struts. Everything interesting happens in prepare() 733 754 */ 734 755 public String execute() throws Exception { -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/MDRepoProxyAction.java
r1234 r1495 29 29 30 30 /** 31 * Main Struts 2 controller32 * responds to requests (collections, model, recordset)31 * Proxy to the Metadata Repository. 32 * Responds to requests (collections, model, recordset) 33 33 * by dispatching the requests to appropriate internal methods and filling the inputStream with the result 34 34 * … … 44 44 private String proxy_key = "mdrepository"; 45 45 46 @Override 46 /** 47 * Override of the basic method provided by the super-class 48 */ 49 @Override 47 50 public String getBaseURI() { 48 Admin.notifyUser("MDREPO-property:" + Admin.getConfig().getProperty(getProxyKey() + ".uri")); 49 Admin.notifyUser("MDREPO-profile:" + getRepositoryPath()); 50 String uri = getRepositoryPath();//Admin.getConfig().getProperty(getProxyKey() + ".uri"); 51 String uri = getRepositoryPath(); 51 52 return uri; 52 53 } … … 56 57 super.setFormat(format); 57 58 } 59 58 60 @Override 59 61 public String getProxyKey() { … … 61 63 } 62 64 63 65 /** 66 * A mapping between the actionkeys in the request and the operation-parameter expected by the MDRepository 67 */ 64 68 private final static HashMap<String,String> urls = new HashMap<String,String>(); 65 69 static … … 70 74 urls.put("record", "?operation=searchRetrieve&query="); 71 75 } 72 /* 73 @Override 74 public URL getBaseURL() throws MalformedURLException { 75 if (base_url == null) { 76 base_url = new URL(Admin.getConfig().getProperty(getProxyKey() + ".uri")); 77 try { 78 Admin.notifyUser("TEST-URLold:" + base_url.toURI()); 79 } catch (URISyntaxException e) { 80 // TODO Auto-generated catch block 81 e.printStackTrace(); 82 } 83 base_url = new URL(getRepository()); 84 try { 85 Admin.notifyUser("TEST-URLnew:" + base_url.toURI()); 86 } catch (URISyntaxException e) { 87 // TODO Auto-generated catch block 88 e.printStackTrace(); 89 } 90 } 91 return base_url; 92 } 93 */ 94 76 95 77 /** 96 78 * uses base_url + url_pattern (parametrized by actionkey) to form a url … … 102 84 103 85 Admin.notifyUser("MDRPA.getQ:" + getSquery() + " and (" + getQ() + ")"); 104 Admin.notifyUser("MDRPA.getActionkey:" + getActionkey()); 105 Admin.notifyUser("MDRPA.getMaxdepth:" + getMaxdepth()); 86 Admin.notifyUser("MDRPA.getActionkey:" + getActionkey()); 106 87 107 88 Query query = new Query(getSquery(), getQ(),getActionkey()); 89 90 // check if the query could get parsed 108 91 if (query.isStatus(Query.PARSEERROR)) { 109 92 Admin.notifyUser("MDRPA.query.PARSEERROR:" + query.getMsg()); … … 119 102 query.setOptions(getOptions()); 120 103 query.setSort(getSort()); 121 //Admin.notifyUser("MDRPA.records:" + query.getStartRecord()); 122 //Admin.notifyUser("MDRPA.records:" + query.getMaximumRecords()); 123 URL targetURL = null; 124 104 105 URL targetURL = null; 125 106 targetURL =new URL( getBaseURL(), urls.get(getActionkey()) + query.toURLParam() ); 126 107 Admin.notifyUser("MDRPA.targetURL.query.toURLParam:" + query.toURLParam()); … … 130 111 } 131 112 132 133 /*134 * FOLLOWING ARE OBSOLETE METHODS135 * for processing the requests and serving the results136 * they stay here for reference (as bad examples) temporarily137 * and can/shall be removed in the near future.138 */139 140 /**141 * serves the collections, passes the Request to MDRepositoryProxy142 * @return143 * @throws Exception144 */145 /*146 public String collections() throws Exception {147 148 Query query = new Query(getQ(),Query.COLLECTIONS);149 150 // inputStream = getMDRepo().getCollections(query);151 152 return SUCCESS;153 }154 */155 /**156 * serves the model/terms, via Query.execute() and .getResult()157 * @return158 * @throws Exception159 */160 /*161 public String model() throws Exception {162 163 Query query = new Query(getQ(), Query.MODEL, getCollection());164 Admin.notifyUser(query.getTargetRequest().toString());165 query.setMaxdepth(getMaxdepth());166 query.execute();167 168 //inputStream = query.getResult().getResultStream(format);169 return SUCCESS;170 }171 */172 /**173 * the method for actual querying of MDRepository174 * and getting back the MD-recordset175 * using Query-object (not asking MDRepository yet)176 *177 * @return178 * @throws Exception179 * @throws Exception180 */181 /*182 public String recordset() throws Exception {183 184 Query query = new Query(getQ(), Query.RECORDSET, getCollection());185 186 Admin.notifyUser("recordset_target_uri:" + query.getTargetRequest().toString());187 query.execute();188 113 189 // String str =query.getResult().getHeader();190 191 // inputStream = new ByteArrayInputStream(str.getBytes());192 193 // inputStream = query.getResult().getResultStream(format);194 return SUCCESS;195 196 }197 */198 199 114 @Override 200 115 public void prepare() throws Exception{ -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/MDTransformer.java
r1488 r1495 52 52 53 53 /** 54 * Helper class, encapsulating the xsl-transformations handling 55 * the contract is, that the requester passes a key, which can be resolved to a xsl-script (momentary mapped in properties: Admin.getConfig()) 56 * Bad things happen, if the key or the appropriate xsl-file do not exist 54 * Helper class, encapsulating the xsl-transformations handling. 55 * The contract is, that the requester passes a key, which can be resolved to a xsl-script (momentary mapped in properties: Admin.getConfig()) 56 * 57 * Bad things happen, if the key or the appropriate xsl-file do not exist - well the client gets a diagnostic message. 57 58 * 58 59 * … … 66 67 private HashMap<String,String> params; 67 68 68 private MDTransformer singleton; 69 // don't use singleton!! Bad things happen 70 // private MDTransformer singleton; 69 71 TransformerFactory tfactory ; 70 72 … … 73 75 } 74 76 75 /*76 public static MDTransformer getMDTransformer () {77 if (singleton == null) {78 singleton = new MDTransformer();79 }80 return singleton;81 }82 */83 77 84 78 public URL getSrcFile() { … … 90 84 } 91 85 86 /** 87 * This serves the caller (mainly GenericProxyAction.prepare()) 88 * to provide/fill the request parameters. 89 * They then get translated to stylesheet-parameters (in SetTransformerParameters()). 90 * @return 91 */ 92 92 public void setParams(HashMap<String,String> params){ 93 93 this.params = params; 94 94 } 95 95 96 96 97 public HashMap<String,String> getParams(){ 97 98 return this.params; 98 99 } 99 100 /** 100 * get the path to the transform-xsl file from properties, based on the key 101 * get the path to the transform-xsl file from properties, based on the key (aka format-parameter) 101 102 * @param key 102 103 * @return … … 116 117 } 117 118 119 /** 120 * Tries to load the stylesheet based on the key. 121 * This is done in two steps: 122 * 1. try to resolve the key to a path 123 * 2. get the xsl-file as a stream (and establish it as StreamSource) 124 * 125 * @param key The key identifying the stylesheet for the transformation as passed by GenericProxyAction. 126 * @return the stylesheet to be applied (as StreamSource) 127 * @throws NoStylesheetException If the stylesheet could not be located 128 */ 118 129 private StreamSource getXSLStreamSource (String key) throws NoStylesheetException{ 119 130 … … 126 137 StreamSource streamSource = new StreamSource(xslstream); 127 138 128 //Admin.notifyUser(this.getClass().getClassLoader().getResource(xslPath).toString());129 //Admin.notifyUser(this.getClass().getClassLoader().getResource(xslPath).getPath());130 131 132 139 streamSource.setSystemId(this.getClass().getClassLoader().getResource(xslPath).toString()); 133 return streamSource ; 134 135 } 136 137 public Object getCols() throws TransformerConfigurationException, TransformerFactoryConfigurationError{ 138 139 String xmlString = null; 140 // create new document 141 Document doc = null; 142 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); 143 DocumentBuilder docBuilder; 144 try { 145 docBuilder = docFactory.newDocumentBuilder(); 146 doc = docBuilder.newDocument(); 147 // append root tag <col > 148 Element root = (Element) doc.createElement("root"); 149 doc.appendChild(root); 150 151 Element child1 = (Element) doc.createElement("col"); 152 child1.setTextContent("Id"); 153 root.appendChild(child1); 154 Element child = (Element) doc.createElement("col"); 155 child.setTextContent("Name"); 156 root.appendChild(child); 157 //Element child = doc.createElement("col"); 158 //child.setNodeValue("Id"); 159 160 161 Transformer transformer = TransformerFactory.newInstance().newTransformer(); 162 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 163 164 //initialize StreamResult with File object to save to file 165 StreamResult result = new StreamResult(new StringWriter()); 166 DOMSource source = new DOMSource(doc); 167 try { 168 transformer.transform(source, result); 169 xmlString = result.getWriter().toString(); 170 171 Admin.notifyUser(xmlString); 172 } catch (TransformerException e) { 173 // TODO Auto-generated catch block 174 e.printStackTrace(); 175 } 176 177 178 179 } catch (ParserConfigurationException e) { 180 // TODO Auto-generated catch block 181 e.printStackTrace(); 182 } 183 //return xmlString; 184 //return doc.getElementsByTagName("col").item(0); 185 return doc.getDocumentElement(); 140 return streamSource ; 141 186 142 } 187 143 … … 189 145 return params.get("format"); 190 146 } 191 147 148 /** 149 * Makes the request-parameters available in the stylesheets 150 * by translating them to stylesheet-parameters 151 * @param transformer 152 */ 192 153 public void SetTransformerParameters(Transformer transformer){ 193 154 … … 231 192 me.setWriter(w); 232 193 ((net.sf.saxon.Controller)transformer).setMessageEmitter(me);//new net.sf.saxon.event.MessageWarner()); 194 233 195 234 /* transformer.setParameter("q", q);235 transformer.setParameter("lang", lang);236 transformer.setParameter("format", transkey);237 transformer.setParameter("cols", cols);238 if ((startRecord != null) && (maximumRecords != null)) {239 240 transformer.setParameter("startRecord", startRecord);241 transformer.setParameter("maximumRecords", maximumRecords);242 }243 if (repositoryURI != null) {244 245 transformer.setParameter("repository_uri", repositoryURI);246 }247 */248 /* transformer.setParameter("cols", "<col label='id'>Id</col>" +249 "<col label='id'>idno</col>" +250 "<col label='name'>Name</col>" +251 "<col label='title'>Title</col>" +252 "<col label='title'>title</col>"); */253 254 196 if (srcFile!=null) { 255 197 … … 288 230 writeXslMessages(w); 289 231 ///Admin.notifyUser(w.getBuffer().toString()); 290 } 291 232 } 233 234 235 /** 236 * just a wrapper for the main method translating the output-stream into a input-stream (expected by the Controller-Actions to return as response) 237 * @param xmlStream the source xml stream 238 * @param transkey 239 * @return result-stream (converted to InputStream) 240 * @throws IOException 241 * @throws InterruptedException 242 * @throws TransformerException 243 * @throws NoStylesheetException 244 */ 245 public InputStream transformXML ( InputStream xmlStream) throws IOException, InterruptedException, TransformerException, NoStylesheetException { 246 //public InputStream transformXML ( InputStream xmlStream, String transkey, String cols, String startRecord, String maximumRecords, String lang, String q, String repositoryURI) throws IOException, InterruptedException, TransformerException { 247 248 ByteArrayOutputStream out = new ByteArrayOutputStream(); 249 transformXML(xmlStream, out); 250 InputStream transformedStream = new ByteArrayInputStream(out.toByteArray()); 251 return transformedStream; 252 } 253 254 /** 255 * another wrapper for the main method allowing to directly pass a URL to the source-xml 256 * @param xmlFile URL of the source-file 257 * @param transkey 258 * @return the result-stream (already converted to an InputStream) 259 * @throws TransformerException 260 * @throws IOException 261 * @throws NoStylesheetException 262 */ 263 public InputStream transformXML (URL xmlFile ) throws IOException, InterruptedException, TransformerException, NoStylesheetException { 264 //public InputStream transformXML (URL xmlFile, String transkey ) throws IOException, InterruptedException, TransformerException { 265 srcFile= xmlFile; 266 InputStream xmlStream = 267 new BufferedInputStream(new FileInputStream(xmlFile.getPath())); 268 269 return transformXML ( xmlStream); 270 } 271 272 273 /** 274 * this is for xml-data present as string (primarily the query string present as XCQL). 275 * if xml in a file or a stream, use the other methods 276 * @param xml xml-data as string 277 * @param transkey 278 * @return 279 * @throws NoStylesheetException 280 * @throws IOException 281 */ 282 public String transformXML (String xml) throws NoStylesheetException { 283 //public String transformXML (String xml, String transkey ) { 284 String result=""; 285 try { 286 // Create a transform factory instance. 287 System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); 288 //System.setProperty("javax.xml.transform.TransformerFactory", "com.icl.saxon.TransformerFactoryImpl"); 289 TransformerFactory tfactory = TransformerFactory.newInstance(); 290 OutputStream os = new ByteArrayOutputStream(); 291 StreamResult stream = new StreamResult(os); 292 // Create a transformer for the stylesheet. 293 Transformer transformer = tfactory.newTransformer( 294 getXSLStreamSource(getTranskey())); 295 296 MessageEmitter me = new net.sf.saxon.event.MessageEmitter(); 297 StringWriter w = new StringWriter(); 298 me.setWriter(w); 299 ((net.sf.saxon.Controller)transformer).setMessageEmitter(me);//new net.sf.saxon.event.MessageWarner()); 300 301 // Transform the source XML to System.out. 302 StreamSource src =new StreamSource(); 303 Reader reader = new StringReader(xml); 304 src.setReader(reader); 305 306 transformer.transform(src, stream ); 307 // new StreamResult(new File("Simple2.out"))); 308 // Write <xsl:message> 309 writeXslMessages(w); 310 311 result = os.toString(); 312 313 } catch (TransformerException e) { 314 e.printStackTrace(); 315 } 316 317 return result; 318 } 319 292 320 private void writeXslMessages(StringWriter w){ 293 321 … … 304 332 e.printStackTrace(); 305 333 } 306 307 } 308 /** 309 * just a wrapper for the main method translating the output-stream into a input-stream (expected by the Controller-Actions to return as response) 310 * @param xmlStream the source xml stream 311 * @param transkey 312 * @return result-stream (converted to InputStream) 313 * @throws IOException 314 * @throws InterruptedException 315 * @throws TransformerException 316 * @throws NoStylesheetException 317 */ 318 public InputStream transformXML ( InputStream xmlStream) throws IOException, InterruptedException, TransformerException, NoStylesheetException { 319 //public InputStream transformXML ( InputStream xmlStream, String transkey, String cols, String startRecord, String maximumRecords, String lang, String q, String repositoryURI) throws IOException, InterruptedException, TransformerException { 320 321 ByteArrayOutputStream out = new ByteArrayOutputStream(); 322 transformXML(xmlStream, out); 323 //transformXML(xmlStream, transkey, cols, startRecord, maximumRecords, lang, q, repositoryURI, out); 324 InputStream transformedStream = new ByteArrayInputStream(out.toByteArray()); 325 //Admin.notifyUser("transformedStream:" + transformedStream.toString()); 326 return transformedStream; 327 } 328 329 /** 330 * just a wrapper for the main method translating the output-stream into a input-stream (expected by the Controller-Actions to return as response) 331 * @param xmlStream the source xml stream 332 * @param transkey 333 * @return result-stream (converted to InputStream) 334 * @throws IOException 335 * @throws InterruptedException 336 * @throws TransformerException 337 */ 338 /* 339 public InputStream transformXML ( InputStream xmlStream, String transkey) throws IOException, InterruptedException, TransformerException { 340 341 ByteArrayOutputStream out = new ByteArrayOutputStream(); 342 transformXML(xmlStream, transkey, "", "", "","","", "", out); 343 InputStream transformedStream = new ByteArrayInputStream(out.toByteArray()); 344 //Admin.notifyUser("transformedStream:" + transformedStream.toString()); 345 return transformedStream; 346 } 347 */ 348 /** 349 * another wrapper for the main method allowing to directly pass a URL to the source-xml 350 * @param xmlFile URL of the source-file 351 * @param transkey 352 * @return the result-stream (already converted to an InputStream) 353 * @throws TransformerException 354 * @throws IOException 355 * @throws NoStylesheetException 356 */ 357 public InputStream transformXML (URL xmlFile ) throws IOException, InterruptedException, TransformerException, NoStylesheetException { 358 //public InputStream transformXML (URL xmlFile, String transkey ) throws IOException, InterruptedException, TransformerException { 359 srcFile= xmlFile; 360 InputStream xmlStream = 361 new BufferedInputStream(new FileInputStream(xmlFile.getPath())); 362 363 return transformXML ( xmlStream); 364 } 365 366 367 /** 368 * this is for xml present as string. 369 * if xml in a file or a stream, use the other methods 370 * @param xml xml as string 371 * @param transkey 372 * @return 373 * @throws NoStylesheetException 374 * @throws IOException 375 */ 376 public String transformXML (String xml) throws NoStylesheetException { 377 //public String transformXML (String xml, String transkey ) { 378 String result=""; 379 try { 380 // Create a transform factory instance. 381 System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); 382 //System.setProperty("javax.xml.transform.TransformerFactory", "com.icl.saxon.TransformerFactoryImpl"); 383 TransformerFactory tfactory = TransformerFactory.newInstance(); 384 OutputStream os = new ByteArrayOutputStream(); 385 StreamResult stream = new StreamResult(os); 386 // Create a transformer for the stylesheet. 387 Transformer transformer = tfactory.newTransformer( 388 getXSLStreamSource(getTranskey())); 389 /* instead of: 390 InputStream xslIS = 391 new BufferedInputStream(new FileInputStream(getXSLPath(transkey))); 392 393 Transformer transformer = 394 tfactory.newTransformer(new StreamSource(xslIS)); 395 */ 396 //////////////////// 397 MessageEmitter me = new net.sf.saxon.event.MessageEmitter(); 398 StringWriter w = new StringWriter(); 399 me.setWriter(w); 400 ((net.sf.saxon.Controller)transformer).setMessageEmitter(me);//new net.sf.saxon.event.MessageWarner()); 401 402 // Transform the source XML to System.out. 403 StreamSource src =new StreamSource(); 404 Reader reader = new StringReader(xml); 405 src.setReader(reader); 406 407 transformer.transform(src, stream ); 408 // new StreamResult(new File("Simple2.out"))); 409 // Write <xsl:message> 410 writeXslMessages(w); 411 412 result = os.toString(); 413 414 } catch (TransformerException e) { 415 e.printStackTrace(); 416 } 417 418 return result; 419 } 420 334 } 421 335 422 336 public static HashMap<String,String> createParamsMap(String transkey){ -
MDService2/trunk/MDService2/src/xsl/mdinst2view.xsl
r1488 r1495 19 19 --> 20 20 21 <xsl:output method="html" /> 21 <!-- method="xhtml" is saxon-specific! prevents collapsing empty <script> tags, that makes browsers choke --> 22 <xsl:output method="xhtml" media-type="application/xhtml+xml" indent="yes" encoding="UTF-8" 23 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" /> 24 22 25 23 26 <xsl:include href="cmd_commons.xsl"/> -
MDService2/trunk/MDService2/src/xsl/mdset2view.xsl
r1488 r1495 20 20 <xsl:import href="terms2view.xsl"/> 21 21 22 <!-- method="xhtml" is saxon-specific! prevents collapsing empty <script> tags, that makes browsers choke --> 22 23 <xsl:output method="xhtml" media-type="application/xhtml+xml" indent="yes" encoding="UTF-8" 23 24 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" /> -
MDService2/trunk/MDService2/src/xsl/test2view.xsl
r1488 r1495 27 27 <xsl:template match="a"> 28 28 29 <xsl:variable name="specific_prefix" select="if (contains(@href,'query')) then 'recordset/htmlpage/' else ''" /> 30 31 <xsl:variable name="data" > 32 <xsl:choose> 33 <xsl:when test="@class='request count'"> 34 <xsl:copy-of select="document(concat($base_url,@href))" /> 35 </xsl:when> 36 <xsl:when test="@class='query count'"> 37 <xsl:copy-of select="document(concat($base_url, 'recordset/xml/', @href))" /> 38 </xsl:when> 39 <xsl:when test="@class='query'"> 40 <xsl:copy-of select="document(concat($base_url, 'recordset/htmltable/', @href))" /> 41 </xsl:when> 42 <xsl:otherwise> 43 <xsl:copy-of select="document(concat($base_url, @href))" /> 44 </xsl:otherwise> 45 </xsl:choose> 46 </xsl:variable> 47 48 29 49 <div class="cmds-ui-block" > 30 50 <div class="ui-widget-header"> 31 <xsl:value-of select="@class" />: <xsl:copy-of select="." /> [<a href="{concat($base_url, @href)}" ><xsl:value-of select="@href" /></a>]51 <xsl:value-of select="@class" />: <xsl:copy-of select="." /> [<a href="{concat($base_url,$specific_prefix,@href)}" ><xsl:value-of select="@href" /></a>] 32 52 </div> 33 53 34 54 <div class="ui-widget-content"> 35 55 <xsl:choose> 36 <xsl:when test="@class='requestcount'"> 37 <xsl:variable name="data" select="document(concat($base_url,@href))" /> 38 <xsl:value-of select="count($data//*)" /> 56 <xsl:when test="exists($data/diagnostics)"> 57 <span class="error" > 58 <xsl:value-of select="$data/diagnostics/diag:diagnostic/diag:message" /> 59 </span> 39 60 </xsl:when> 40 <xsl:when test="@class='query'"> 61 <xsl:when test="@class='request count'"> 62 root: <xsl:value-of select="$data/*/name()" />|<xsl:value-of select="count($data//*)" />| 63 </xsl:when> 64 <xsl:when test="@class='query count'"> 65 <xsl:value-of select="$data//numberOfRecords" /> 66 </xsl:when> 67 68 <!-- <xsl:when test="@class='query'"> 41 69 <xsl:variable name="data" select="document(concat($base_url,'recordset/htmltable/', @href))" /> 42 70 <xsl:copy-of select="$data" /> 43 </xsl:when> 44 <xsl:when test="@class='query count'"> 45 <xsl:variable name="data" select="document(concat($base_url,'recordset/xml/', @href))" /> 46 <xsl:value-of select="$data//numberOfRecords" /> 47 </xsl:when> 71 </xsl:when> --> 48 72 <xsl:otherwise> 49 <xsl:apply-templates select="document(concat($base_url,@href))" mode="process-query"/> 73 <!-- <xsl:apply-templates select="$data" mode="process-result"/>--> 74 <xsl:copy-of select="$data" /> 50 75 </xsl:otherwise> 51 76 </xsl:choose> … … 61 86 </xsl:template> 62 87 63 <xsl:template match="*|@*" mode="process- query" >88 <xsl:template match="*|@*" mode="process-result" > 64 89 <xsl:copy> 65 <xsl:apply-templates select="node()|@*" mode="process- query" />90 <xsl:apply-templates select="node()|@*" mode="process-result" /> 66 91 </xsl:copy> 67 92 </xsl:template> … … 73 98 <message>Exception occurred: Connection refused: connect</message> 74 99 --> 75 <xsl:template match="diagnostics" mode="process- query" >100 <xsl:template match="diagnostics" mode="process-result" > 76 101 <div class="error" > 77 102 <xsl:value-of select="diag:diagnostic/diag:message" />
Note: See TracChangeset
for help on using the changeset viewer.