Changeset 795


Ignore:
Timestamp:
10/16/10 20:09:34 (14 years ago)
Author:
vronk
Message:

dcr/rr terms htmllist, welcome-message

Location:
MDService2/trunk/MDService2
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • MDService2/trunk/MDService2/WebContent/scripts/mdservice2_ui.js

    r794 r795  
    2929
    3030                isocat: {
    31                                 base_uri: "/MDService2/isocatprofile/",
     31                                base_uri: "/MDService2/datcats/",
    3232                                current:5
    3333                                }
     
    5252//////////////         
    5353               
     54                loadWelcomeMessage();
    5455                loadWorkspaceProfiles();
    5556                loadCollections();                     
     
    384385}
    385386////////////////////////////////////////////////
     387function loadWelcomeMessage(){ 
     388        $('#detail').load("/MDService2/static/welcome.xml"); //profile.collections.base_uri,
     389}
     390
    386391function loadWorkspaceProfiles(){
    387392        //empty json
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/CompRegistryProxyAction.java

    r789 r795  
    9292                                        Admin.notifyUser("CCCRPA." + getFullFormat());
    9393                                        MDTransformer.getMDTransformer().setSrcFile(getTargetRequest());
    94                                         _sourceStream = MDTransformer.getMDTransformer().transformXML(__sourceStream, getFullFormat(),null,null,null,null);
     94                                        _sourceStream = MDTransformer.getMDTransformer().transformXML(__sourceStream, getFullFormat(),null,null,null,null,null);
    9595                                        Admin.notifyUser("CRPA.- elements");
    9696                                        setActionkey("elements");
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/DCRProxyAction.java

    r789 r795  
    4242        private static final long serialVersionUID = 1L;
    4343       
    44         private final static HashMap<String,Object> dcrs = new HashMap<String,Object>();
    45        
    4644       
    4745        public String getDcrid() {
     
    5351        }
    5452
    55         public HashMap<String, Object> getDCRs() {
    56                 if (dcrs.size()==0) {
    57                         initDCRs();                             
    58                 }
    59                 return dcrs;
    60         }
    61 
    6253        public Termset getDCR() {               
    6354                String dcr_id="";
     
    6657                if (getDcrid()!=null && !getDcrid().equals("")) dcr_id = getDcrid();                   
    6758
    68                 Termset res = (Termset) getDCRs().get(dcr_id);
     59                Termset res = (Termset) Termset.getTermset(dcr_id);
    6960                if (res==null)          Admin.notifyUser("getDCR(): no termset found for:" + dcr_id);
    7061                //else
     
    109100       
    110101        public String getBaseURI() {           
    111                 return getDCRAttr("url");       
    112                
     102                return getDCRAttr("url");
    113103        }
    114104       
     
    163153                resultStream = urlConnection.getInputStream();
    164154                }
    165         return resultStream;
    166        
     155        return resultStream;   
    167156   
    168157        }
    169        
    170 
    171         public void initDCRs() {
    172                 if (dcrs.size() > 0) { 
    173                 }
    174                
    175                 Document dcrs_setup = Admin.getXMLDocument(Admin.getConfig().getProperty("datcats.file"));
    176        
    177         //      Admin.loadFile(Admin.getConfig().getProperty("service.list.file"));             
    178                 Admin.notifyUser("initDCRs().loaded:" + dcrs_setup.getDocumentURI());
    179                 Admin.notifyUser("firstchild:" + dcrs_setup.getFirstChild());           
    180                 //.getDocumentElement().getLocalName()
    181                 //Document chains_doc = Admin.getXMLDocument(Admin.getConfig().getProperty("chains.file"));
    182 
    183                 //Admin.notifyUser("formPath:xpath:"+xpath_expr);
    184                 //creating an XPathFactory:
    185         XPathFactory factory = XPathFactory.newInstance();
    186         //using this factory to create an XPath object:
    187         XPath xpath = factory.newXPath();
    188         //XPath object created compiles the XPath expression:
    189         XPathExpression expr;
    190                 try {
    191                         expr = xpath.compile("//Termset");
    192                         //expression is evaluated with respect to a certain context node which is doc.
    193                 Object result = expr.evaluate(dcrs_setup, XPathConstants.NODESET);
    194                 NodeList list = (NodeList) result;
    195 
    196                 // <Termset type="dcr" id="isocat" label="isoCAT" url="http://www.isocat.org/rest/" format="dcif" />
    197                 for (int i = 0; i<list.getLength();i++) {
    198                         //String value = list.item(i).getTextContent();
    199                         Node n = list.item(i);                         
    200                         Termset ts = new Termset(n);                   
    201                                                
    202                         Admin.notifyUser("reading in dcr:" + ts.getAttr("id"));
    203                         dcrs.put(ts.getAttr("id"), ts );
    204                 }   
    205                 } catch (XPathExpressionException e) {
    206                         // TODO Auto-generated catch block
    207                         e.printStackTrace();
    208                 }
    209 
    210         }
    211        
    212158
    213159}
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java

    r789 r795  
    211211        }
    212212
    213         public String getBaseURI() throws MalformedURLException {               
     213        public String getBaseURI() {           
    214214                String uri =Admin.getConfig().getProperty(getProxyKey() + ".uri");             
    215215                return uri;
     
    281281                        MDTransformer.getMDTransformer().setSrcFile(getTargetRequest());
    282282                        // getColumns
    283                         resultStream = MDTransformer.getMDTransformer().transformXML(sourceStream, getFullFormat(), getColumns(), getStartRecord(), getMaximumRecords(),getLang());
     283                        resultStream = MDTransformer.getMDTransformer().transformXML(sourceStream, getFullFormat(), getColumns(), getStartRecord(), getMaximumRecords(),getLang(),getQ());
    284284                }
    285285                       
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/MDTransformer.java

    r789 r795  
    165165         * @throws IOException
    166166         */             
    167         public void transformXML (InputStream in, String transkey, String cols, String startRecord, String maximumRecords, String lang, OutputStream out ) throws TransformerException, IOException {
     167        public void transformXML (InputStream in, String transkey, String cols, String startRecord, String maximumRecords, String lang, String q, OutputStream out ) throws TransformerException, IOException {
    168168       
    169169                // Create a transform factory instance.
     
    177177                                                                        getXSLStreamSource(transkey));
    178178               
     179                transformer.setParameter("q", q);
    179180                transformer.setParameter("lang", lang);
    180181                transformer.setParameter("format", transkey);
     
    204205                        }
    205206                        Admin.notifyUser("root_uri:" +  root_uri );
    206                         Admin.notifyUser("xsrcfile:" +  root_uri );
     207                        Admin.notifyUser("xsrcfile:" +  xsrcfile );
    207208                        transformer.setParameter("root_uri", root_uri );
    208209                        transformer.setParameter("src_file", xsrcfile);
     
    226227         * @throws TransformerException
    227228         */
    228         public InputStream transformXML ( InputStream xmlStream, String transkey, String cols, String startRecord, String maximumRecords, String lang) throws IOException, InterruptedException, TransformerException {
     229        public InputStream transformXML ( InputStream xmlStream, String transkey, String cols, String startRecord, String maximumRecords, String lang, String q) throws IOException, InterruptedException, TransformerException {
    229230               
    230231                ByteArrayOutputStream out = new ByteArrayOutputStream();
    231                 transformXML(xmlStream, transkey, cols, startRecord, maximumRecords, lang, out);               
     232                transformXML(xmlStream, transkey, cols, startRecord, maximumRecords, lang, q, out);             
    232233            InputStream transformedStream = new ByteArrayInputStream(out.toByteArray());
    233234            //Admin.notifyUser("transformedStream:" + transformedStream.toString());
     
    247248               
    248249                ByteArrayOutputStream out = new ByteArrayOutputStream();
    249                 transformXML(xmlStream, transkey, "", "", "","", out);         
     250                transformXML(xmlStream, transkey, "", "", "","","", out);               
    250251            InputStream transformedStream = new ByteArrayInputStream(out.toByteArray());
    251252            //Admin.notifyUser("transformedStream:" + transformedStream.toString());
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/TermsProxyAction.java

    r772 r795  
    1515
    1616import eu.clarin.cmdi.mdservice.model.Query;
     17import eu.clarin.cmdi.mdservice.model.Termset;
    1718
    1819/**
     
    2829        private static final long serialVersionUID = 1L;
    2930
     31        public static String ALL = "all";
     32       
    3033        private String proxy_key = "terms";
    3134       
     
    6669                        return key;
    6770        }
    68         /**
     71         
     72        public Termset getTermset() {           
     73                String ts_id="";
     74                if (getQ()!=null && !getQ().equals("")) ts_id = getQ();
     75       
     76                Termset res = (Termset) Termset.getTermset(ts_id);
     77               
     78                return res;
     79        }
     80       
     81        public String getTSAttr(String key) {   
     82                Termset ts = getTermset();
     83                String val="";
     84                if (ts!=null) val= ts.getAttr(key);
     85                 return val;
     86        }
     87
     88
     89        public URL getBaseURL() throws MalformedURLException {
     90                       
     91                if (base_url == null) {
     92                        base_url = new URL(getBaseURI());
     93                }
     94               
     95                return base_url;
     96        }
     97       
     98         /**
    6999         * uses base_url + url_pattern (parametrized by actionkey) to form a url
    70          * @return the URL to the component-file
     100         * @return the URL to the terms
    71101         * @throws Exception
    72102         */
    73103        public URL getTargetRequest() throws IOException {
    74104        // URL targetURL =new URL( base_url, compname + ".xml");
    75                
    76                 Admin.notifyUser("TPA.getQ:" + getQ() );
    77                 Admin.notifyUser("TPA.getActionkey:" + getActionkey());
    78                 Admin.notifyUser("TPA.getMaxdepth:" + getMaxdepth());
     105       
    79106               
    80107                URL targetURL = null;
     108                //targetURL = new URL(getBaseURI() + getQ());
     109                Admin.notifyUser("TPA.q: " + getQ());           
    81110                targetURL = new URL(getBaseURI() + getQ());
    82                 Admin.notifyUser("TPA.targetURL:" + targetURL);
    83111                // TPA.targetURL:http://localhost:8080/MDService2/model/matrix/?q=all
    84112            return targetURL;
     
    86114        }
    87115       
     116        public InputStream getSourceStream() throws IOException{
     117                String type = getTSAttr("type");
     118                if (type.equals("dcr") | type.equals("rr")) {   
     119                        // if dcr|rr call model/matrix/all: http://localhost:8080/MDService2/model/matrix/?q=all
     120                        // + run through terms2extract transform (parametrized with getQ()-param!!), to serve the subset = appropriate Termset
     121                        URL matrix_all_URL = new URL(getBaseURI() + ALL);
     122                        InputStream stream_matrix_all = matrix_all_URL.openStream();
     123                        InputStream resultStream=null;
     124                        try {
     125                                resultStream = MDTransformer.getMDTransformer().transformXML(stream_matrix_all, "terms2extract", getColumns(), getStartRecord(), getMaximumRecords(),getLang(),getQ());
     126                        } catch (InterruptedException e) {                             
     127                                Admin.notifyUser("TPA.getSourceStream(): "+ e.getMessage());
     128                        } catch (TransformerException e) {                             
     129                                Admin.notifyUser("TPA.getSourceStream(): "+ e.getMessage());
     130                        }                       
     131                        return resultStream;
     132                       
     133                } else {
     134                        return getTargetRequest().openStream();
     135                }                 
     136        }
     137       
    88138}
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/model/Termset.java

    r768 r795  
    33import java.util.HashMap;
    44
     5import javax.xml.xpath.XPath;
     6import javax.xml.xpath.XPathConstants;
     7import javax.xml.xpath.XPathExpression;
     8import javax.xml.xpath.XPathExpressionException;
     9import javax.xml.xpath.XPathFactory;
     10
     11import org.w3c.dom.Document;
    512import org.w3c.dom.Node;
     13import org.w3c.dom.NodeList;
     14
     15import eu.clarin.cmdi.mdservice.action.Admin;
    616
    717public class Termset {
    818
     19        private final static HashMap<String,Object> termsets = new HashMap<String,Object>();
     20       
    921        private final HashMap<String,String> attrs = new HashMap<String,String>();
    1022       
    11         public Termset () {
    12                
     23        public Termset () {             
    1324        }
    1425
     
    1627                this.setAttrs(n);
    1728        }
    18 
     29       
    1930        public void setAttrs(Node n) {
    2031       
     
    2940          return attrs.get(key);
    3041        }
     42
     43        public static HashMap<String, Object> getTermsets() {
     44                if (termsets.size() == 0) {
     45                        initTermsets();                 
     46                }
     47                return termsets;
     48        }
     49
     50        public static Termset getTermset(String ts_id) {               
     51               
     52                Termset res = (Termset) getTermsets().get(ts_id);
     53                if (res==null) Admin.notifyUser("getTermset(): no termset found for:" + ts_id);
     54                //else
     55                        //Admin.notifyUser("getDCR():" + res.getAttr("id") + ":" + res.getAttr("url") );               
     56                return res;
     57        }
     58       
     59        public static String getTermsetAttr(String ts_id, String key) {
     60                Termset ts = getTermset(ts_id);
     61                String val="";
     62                if (ts!=null) val= ts.getAttr(key);
     63                 return val;
     64        }
     65
     66        public static void initTermsets() {
     67                        Document dcrs_setup = Admin.getXMLDocument(Admin.getConfig().getProperty("terms.file"));
     68               
     69                //      Admin.loadFile(Admin.getConfig().getProperty("service.list.file"));             
     70                        Admin.notifyUser("initTermsets().loaded.");                                     
     71                        //.getDocumentElement().getLocalName()
     72                        //Document chains_doc = Admin.getXMLDocument(Admin.getConfig().getProperty("chains.file"));
     73       
     74                        //Admin.notifyUser("formPath:xpath:"+xpath_expr);
     75                        //creating an XPathFactory:
     76                XPathFactory factory = XPathFactory.newInstance();
     77                //using this factory to create an XPath object:
     78                XPath xpath = factory.newXPath();
     79                //XPath object created compiles the XPath expression:
     80                XPathExpression expr;
     81                        try {
     82                                expr = xpath.compile("//Termset");
     83                                //expression is evaluated with respect to a certain context node which is doc.
     84                        Object result = expr.evaluate(dcrs_setup, XPathConstants.NODESET);
     85                        NodeList list = (NodeList) result;
     86       
     87                        // <Termset type="dcr" id="isocat" label="isoCAT" url="http://www.isocat.org/rest/" format="dcif" />
     88                        for (int i = 0; i<list.getLength();i++) {
     89                                //String value = list.item(i).getTextContent();
     90                                Node n = list.item(i);                         
     91                                Termset ts = new Termset(n);                   
     92                                                       
     93                                Admin.notifyUser("reading in Termset: " + ts.getAttr("id"));
     94                                termsets.put(ts.getAttr("id"), ts );
     95                        }   
     96                        } catch (XPathExpressionException e) {
     97                                // TODO Auto-generated catch block
     98                                e.printStackTrace();
     99                        }
     100
     101        }
     102       
    31103       
    32104}
  • MDService2/trunk/MDService2/src/mdservice.properties

    r794 r795  
    33mdrepository.uri = http://clarin.aac.ac.at/exist/rest/db/clarin/cmd-model.xql/
    44terms.uri = http://localhost:8080/MDService2/model/matrix/?q=
    5 datcats.file=terms_setup.xml
     5terms.dcr.uri = http://localhost:8080/MDService2/terms/extract/?q=
     6terms.file=terms_setup.xml
    67
    78//dcregistry.uri = http://www.isocat.org/rest/
     
    3031xsl.model2htmllist = model2view.xsl
    3132xsl.model2htmlselect = model2view.xsl
     33xsl.terms2extract = terms_extract.xsl
    3234xsl.terms2htmlselect = terms2view.xsl
    3335xsl.terms2htmllist = terms2view.xsl
     36xsl.terms2flat = terms2view.xsl
    3437xsl.terms2autocomplete = terms2view.xsl
    3538xsl.terms2htmlpage = terms2view.xsl
  • MDService2/trunk/MDService2/src/xsl/terms2view.xsl

    r794 r795  
    5454                <xsl:when test="$format='terms2htmllist'" >                     
    5555                        <xsl:call-template name="list"/>   
     56                </xsl:when>
     57                <xsl:when test="$format='terms2flat'" >                                                                 
     58                                <xsl:call-template name="terms-flat"/>                                                     
    5659                </xsl:when>
    5760                <xsl:when test="$format='terms2autocomplete'" >
     
    202205       
    203206        <xsl:variable name="count" select="Term/@count" />     
    204         <option value="{@name}" ><xsl:value-of select="@name" /> |<xsl:value-of select="$count" />|</option>                                   
     207        <option value="{@id}" ><xsl:value-of select="@name" /> |<xsl:value-of select="$count" />|</option>                                     
    205208</xsl:template>
    206209
Note: See TracChangeset for help on using the changeset viewer.