Changeset 1495


Ignore:
Timestamp:
08/25/11 20:21:23 (13 years ago)
Author:
vronk
Message:

started cleaning up code, adding inline-documentation;
also changes to output method in xsl (xhtml)

Location:
MDService2/trunk/MDService2
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • MDService2/trunk/MDService2/WebContent/static/queries2.xml

    r1488 r1495  
    66                        <dd><p>just one word like:</p>
    77                                <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>                                                                                             
    911                                </ul>
    1012                        </dd>
    1113                       
    12                         <!--
     14                       
    1315                        <dt >all of multiple terms (AND)</dt>
    1416                        <dd>
    1517                                <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>                     
    1820                                </ul>
    1921                        </dd>
     
    2123                        <dd>a sequence of terms
    2224                                <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>
    2426                                </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&amp;repository=localhost-mirror">WS registry</a></li>
     33                                </ul>
     34                        </dd>
     35                         
     36                        <!--
     37                                        <dt >Bookmarks</dt>     
    2738                        <dd>search/remember individual records (by handle/identifier)
    2839                                <ul>                   
  • MDService2/trunk/MDService2/WebContent/style/cmds-ui.css

    r1423 r1495  
    2121.data {display: none; }
    2222.hilight { font-size: 1.1em; font-weight: bold}
    23 .error { font-color: red}
     23.error { color: #660000; border: 1px solid red; background-color: #ffcccc; }
    2424/* this is temporary for MdREcordView-Titlebar; -> move to ui-box-header */
    2525/* 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  
    3737        private static String config_path = "mdservice.properties";
    3838        private static Properties  config;
    39         public static Logger log = Logger.getLogger("Admin.class");
     39        public static Logger log = Logger.getLogger(Admin.class);
    4040       
    4141        public static String FATAL = "fatal";
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Cache.java

    r1234 r1495  
    3838/**
    3939 * 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())
    4242 *
    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>
    4545 *
    4646 * This is an internal object, direct user access to cache-data via interface is only possible via <code>AdminAction</code>
     
    4848 *
    4949 */
    50 /* TODO: necessary to maintain own index
    51  * for resolution of IDs to filenames
    52  */
    53 
    5450
    5551public class Cache {
     
    353349         * read counter-integer from file in cache
    354350         * or start that file
    355          * @return
     351         * @return The current maximum cache counter
    356352         */
    357353        public Integer initCachecounter() {
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java

    r1491 r1495  
    2626
    2727import org.apache.struts2.interceptor.ServletRequestAware;
    28 
    2928import com.opensymphony.xwork2.ActionSupport;
    30 
    3129import eu.clarin.cmdi.mdservice.model.Diagnostics;
    3230
    3331/**
    34  * main Struts 2 controller
    35  * responds to requests (collections, model, recordset)
    36  * by dispatching the requests to appropriate internal methods and filling the inputStream with the result
     32 * 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.
    3735 * 
    3836 * @author vronk
    39  *
    4037 */
    4138public class GenericProxyAction extends ActionSupport
     
    6966        private String repository;
    7067        //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               
    7474         public GenericProxyAction(){
    7575                 super();
     
    198198        }
    199199
     200        /**
     201         * is used in struts.xml to dynamically set the mime-type of the result, depending on the format-parameter
     202         * @return
     203         */
    200204        public String getActionContentType() {
    201205                if (format.toLowerCase().startsWith("html")) {
     
    269273
    270274        /**
    271          * primitive identification of the target-proxy
    272          * base for finding the right base_url in the props
     275         * internal identification of the target-proxy
     276         * base for finding the right base_url in the properties
    273277         * subclass has to override with its specific proxykey
    274          * @return
     278         * @return the key identifying this type of proxy
    275279         */
    276280        public String getProxyKey() {
     
    278282        }
    279283       
     284        /**
     285         * TODO: check what this does, where it is used?
     286         * @return
     287         */
    280288        public String getUserMsg() {
    281289                return userMsg;
     
    286294        }
    287295       
     296        /**
     297         * TODO: check what this does, where it is used?
     298         * @return
     299         */
    288300        @Override
    289301        public void setServletRequest(HttpServletRequest arg0) {
     
    294306                return request;
    295307        }
    296 
    297 
    298         private InputStream resultStream;
    299         private InputStream sourceStream;
    300308
    301309        /**
     
    335343        }
    336344       
    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         */     
    339359        public URL getBaseURL() throws MalformedURLException {         
    340360                if (base_url == null) {
     
    344364        }
    345365       
    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         */
    352373        public URL getTargetRequest() throws IOException {
    353         // URL targetURL =new URL( base_url, compname + ".xml");
    354                 URL targetURL = getBaseURL();     
    355                      
     374                URL targetURL = getBaseURL();                     
    356375        return targetURL;
    357376        }
    358377       
    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       
    376384         public String getRequestKey() {
    377385                        String key="";
     
    416424                        }else{
    417425                                key +="//-" ;
    418                         }
    419                        
     426                        }                       
    420427                         
    421                         return key;
    422         }
     428                return key;
     429        }
     430         
     431         
    423432        public InputStream getSourceStream() throws IOException, NoStylesheetException {               
    424433                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         */
    428440        public  static String convertStreamToString(InputStream is) { 
    429441               
     
    677689        }
    678690       
     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         */
    679701       
    680702        public void prepare() throws Exception {               
     
    716738                        resultStream = sourceStream;   
    717739                }else {
     740                        MDTransformer transformer = new MDTransformer();
    718741                        // set URL as srcFile (for MDTransformer to pass to xsl-scripts)
    719                         MDTransformer transformer = new MDTransformer();
     742                        // TODO: WHY??
    720743                        transformer.setSrcFile(getTargetRequest());
    721                         // getColumns
    722                 //      Admin.notifyUser("GPA.getRepository, before xsl:" + getRepository());
    723744                        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);
    726747                }
    727748                       
     
    730751
    731752        /**
    732          * default Action method
     753         * default Action method that gets called by Struts. Everything interesting happens in prepare()
    733754         */
    734755        public String execute() throws Exception {
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/MDRepoProxyAction.java

    r1234 r1495  
    2929
    3030/**
    31  * Main Struts 2 controller
    32  * responds to requests (collections, model, recordset)
     31 * Proxy to the Metadata Repository.
     32 * Responds to requests (collections, model, recordset)
    3333 * by dispatching the requests to appropriate internal methods and filling the inputStream with the result
    3434 *
     
    4444        private String proxy_key = "mdrepository";
    4545       
    46         @Override
     46        /**
     47         * Override of the basic method provided by the super-class
     48         */     
     49        @Override       
    4750        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();               
    5152                return uri;
    5253        }
     
    5657                super.setFormat(format);               
    5758        }
     59       
    5860        @Override
    5961        public String getProxyKey() {
     
    6163        }
    6264       
    63        
     65        /**
     66         * A mapping between the actionkeys in the request and the operation-parameter expected by the MDRepository
     67         */
    6468        private final static HashMap<String,String> urls = new HashMap<String,String>();
    6569         static
     
    7074                 urls.put("record", "?operation=searchRetrieve&query=");
    7175         }
    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 
    9577        /**
    9678         * uses base_url + url_pattern (parametrized by actionkey) to form a url
     
    10284               
    10385                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());               
    10687               
    10788                Query query = new Query(getSquery(), getQ(),getActionkey());
     89
     90        // check if the query could get parsed
    10891                if (query.isStatus(Query.PARSEERROR)) {
    10992                        Admin.notifyUser("MDRPA.query.PARSEERROR:" + query.getMsg());
     
    119102                        query.setOptions(getOptions());
    120103                        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;
    125106                        targetURL =new URL( getBaseURL(), urls.get(getActionkey()) + query.toURLParam() );
    126107                        Admin.notifyUser("MDRPA.targetURL.query.toURLParam:" + query.toURLParam());
     
    130111        }
    131112
    132        
    133 /*
    134  * FOLLOWING ARE OBSOLETE METHODS
    135  * for processing the requests and serving the results
    136  * they stay here for reference (as bad examples) temporarily
    137  * and can/shall be removed in the near future.
    138  */
    139        
    140 /**
    141  * serves the collections, passes the Request to MDRepositoryProxy
    142  * @return
    143  * @throws Exception
    144  */
    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          * @return
    158          * @throws Exception
    159          */
    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 MDRepository
    174          * and getting back the MD-recordset
    175          * using Query-object (not asking MDRepository yet)
    176          *   
    177          * @return
    178          * @throws Exception
    179          * @throws Exception
    180          */     
    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();                               
    188113
    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        
    199114        @Override
    200115        public void prepare() throws Exception{
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/MDTransformer.java

    r1488 r1495  
    5252
    5353/**
    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.
    5758 *   
    5859 *
     
    6667        private HashMap<String,String> params;
    6768               
    68         private MDTransformer singleton;
     69        // don't use singleton!! Bad things happen
     70        // private MDTransformer singleton;
    6971        TransformerFactory tfactory ;
    7072       
     
    7375        }
    7476       
    75         /*
    76         public static MDTransformer getMDTransformer () {
    77                 if (singleton == null) {
    78                         singleton = new MDTransformer();
    79                 }
    80                 return singleton;
    81         }
    82         */
    8377       
    8478        public URL getSrcFile() {
     
    9084        }
    9185
     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         */
    9292        public void setParams(HashMap<String,String> params){
    9393                this.params = params;
    9494        }
    9595       
     96       
    9697        public HashMap<String,String> getParams(){
    9798                return this.params;
    9899        }
    99100        /**
    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)
    101102         * @param key
    102103         * @return
     
    116117        }
    117118
     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         */
    118129        private StreamSource getXSLStreamSource (String key) throws NoStylesheetException{             
    119130               
     
    126137                StreamSource streamSource = new StreamSource(xslstream);
    127138
    128                 //Admin.notifyUser(this.getClass().getClassLoader().getResource(xslPath).toString());
    129                 //Admin.notifyUser(this.getClass().getClassLoader().getResource(xslPath).getPath());
    130                
    131                
    132139                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               
    186142        }
    187143       
     
    189145                return params.get("format");
    190146        }
    191        
     147
     148        /**
     149         * Makes the request-parameters available in the stylesheets
     150         * by translating them to stylesheet-parameters
     151         * @param transformer
     152         */
    192153        public void SetTransformerParameters(Transformer transformer){
    193154               
     
    231192                me.setWriter(w);
    232193               ((net.sf.saxon.Controller)transformer).setMessageEmitter(me);//new net.sf.saxon.event.MessageWarner());
     194
    233195               
    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                
    254196                if (srcFile!=null) {
    255197                       
     
    288230                writeXslMessages(w);
    289231                ///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
    292320        private void writeXslMessages(StringWriter w){
    293321       
     
    304332                        e.printStackTrace();
    305333                }
    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        }
    421335       
    422336        public static HashMap<String,String> createParamsMap(String transkey){
  • MDService2/trunk/MDService2/src/xsl/mdinst2view.xsl

    r1488 r1495  
    1919-->
    2020   
    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"
     23doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />
     24
    2225
    2326<xsl:include href="cmd_commons.xsl"/>
  • MDService2/trunk/MDService2/src/xsl/mdset2view.xsl

    r1488 r1495  
    2020<xsl:import href="terms2view.xsl"/>
    2121
     22<!--  method="xhtml" is saxon-specific! prevents  collapsing empty <script> tags, that makes browsers choke -->
    2223<xsl:output method="xhtml" media-type="application/xhtml+xml" indent="yes" encoding="UTF-8"
    2324doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />
  • MDService2/trunk/MDService2/src/xsl/test2view.xsl

    r1488 r1495  
    2727<xsl:template match="a">
    2828
     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       
    2949 <div class="cmds-ui-block" >
    3050         <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>]
    3252        </div> 
    3353       
    3454        <div class="ui-widget-content">
    3555                <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>
    3960                        </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'">
    4169                                        <xsl:variable name="data" select="document(concat($base_url,'recordset/htmltable/', @href))" />
    4270                                        <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> -->         
    4872                        <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" />
    5075                        </xsl:otherwise>
    5176                </xsl:choose>
     
    6186</xsl:template>
    6287
    63 <xsl:template match="*|@*" mode="process-query" >
     88<xsl:template match="*|@*" mode="process-result" >
    6489        <xsl:copy>
    65                 <xsl:apply-templates select="node()|@*" mode="process-query" />
     90                <xsl:apply-templates select="node()|@*" mode="process-result" />
    6691        </xsl:copy>     
    6792</xsl:template>
     
    7398    <message>Exception occurred: Connection refused: connect</message>
    7499-->
    75 <xsl:template match="diagnostics" mode="process-query" >
     100<xsl:template match="diagnostics" mode="process-result" >
    76101        <div class="error" >
    77102                 <xsl:value-of select="diag:diagnostic/diag:message" />
Note: See TracChangeset for help on using the changeset viewer.