Ignore:
Timestamp:
08/25/10 20:51:06 (14 years ago)
Author:
vronk
Message:

renamed document_counter to cacheindex_doc in Cache + added its path to .properties. added collection2htmlpage-view.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Cache.java

    r651 r655  
    2323import javax.xml.transform.*;
    2424import javax.xml.transform.sax.*;
    25 import javax.xml.transform.stream.*;
    26 import javax.xml.transform.dom.*;
     25import javax.xml.transform.stream.*;import javax.xml.transform.dom.*;
    2726import javax.xml.xpath.*;
    2827
     
    5251        private static Cache singleton;
    5352        private String cachepath;
     53        private String cacheindex_path;
    5454        private static Integer cachecounter;
    5555        private static final Integer start_cache = 1;
    5656       
    57         private static Document document_counter;
     57        private static Document cacheindex_doc;
    5858       
    5959        public Cache () {               
    6060                cachepath = Admin.getConfig().getProperty("cache.path");
     61                cacheindex_path = cachepath + Admin.getConfig().getProperty("cacheindex.file");
    6162                cachecounter = initCachecounter();
    6263        }
     
    9798               
    9899                //update xml_structure
    99                 Element e = document_counter.createElement("f");
    100                 //Attr attr = document_counter.createAttribute("id");
     100                Element e = cacheindex_doc.createElement("f");
     101                //Attr attr = cacheindex_doc.createAttribute("id");
    101102                //attr.setValue(c.toString());
    102103                //e.setNamedItem(attr);
     
    124125                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd:hh-mm-ss");
    125126                e.setAttribute("date", dateFormat.format(new Date()).toString());
    126                 document_counter.getFirstChild().appendChild(e);
     127                cacheindex_doc.getFirstChild().appendChild(e);
    127128               
    128129                // update XML-counter
     
    132133               
    133134                xc = PREFIX + key_array[0] + "_" + c.toString();
     135                Admin.notifyUser("CACHE.putInCache.filename:" + xc + ".xml");
    134136                Admin.writeToFile(cachepath + xc + ".xml",instream);
    135137               
     
    139141       
    140142        public InputStream getFromCache(String key_info) {
     143                   
     144               
     145                   File f = new File (formPath(key_info));
    141146                   Admin.notifyUser("CACHE.getFromCache:"+key_info);
    142                
    143                    File f = new File (formPath(key_info));
    144                    
     147                   
    145148                    if (f.exists()) { // read from file to InputStream;
     149                        Admin.notifyUser("CACHE.getFromCache.fromfile:"+f.getName());
    146150                        InputStream instream;
    147151                                try {
     
    156160                       
    157161                    } else { //not cached, my dear
     162                        Admin.notifyUser("CACHE.getFromCache: NOT CACHED");
    158163                        return null;
    159164                    }       
     
    222227                        expr = xpath.compile(xpath_expr);
    223228                        //expression is evaluated with respect to a certain context node which is doc.
    224                 Object result = expr.evaluate(document_counter, XPathConstants.NODESET);
     229                Object result = expr.evaluate(cacheindex_doc, XPathConstants.NODESET);
    225230                NodeList list = (NodeList) result;
    226231                if (list.getLength() > 0) {
     
    254259                Integer counter = start_cache;
    255260                boolean init=false;
    256                 String fname = cachepath + "cache_counter.xml";
     261                String fname = cacheindex_path;
    257262                File f = new File (fname);
    258263               
     
    264269                                try {
    265270                                        docBuilder = docFactory.newDocumentBuilder();
    266                                         document_counter = docBuilder.newDocument();
     271                                        cacheindex_doc = docBuilder.newDocument();
    267272                                        // append root tag <index >
    268                                         Element root = (Element) document_counter.createElement("index");
     273                                        Element root = (Element) cacheindex_doc.createElement("index");
    269274                                        root.setAttribute("idcounter", "1");
    270                                         document_counter.appendChild(root);
     275                                        cacheindex_doc.appendChild(root);
    271276                                        writeCachecounter(counter);
    272277                                       
     
    290295                                        docBuilder = docFactory.newDocumentBuilder();               
    291296                                        try {
    292                                                         document_counter = docBuilder.parse(fname);
     297                                                        cacheindex_doc = docBuilder.parse(fname);
    293298                                        } catch (SAXException e) {
    294299                                                        // TODO Auto-generated catch block
     
    302307                               
    303308                         //read counter
    304                          counter = new Integer(document_counter.getFirstChild().getAttributes().getNamedItem("idcounter").getNodeValue());
     309                         counter = new Integer(cacheindex_doc.getFirstChild().getAttributes().getNamedItem("idcounter").getNodeValue());
    305310                         init = true;
    306311                    }  catch (IOException ex){
     
    351356            writeCachecounter( cachecounter);
    352357        }
    353         public void writeCachecounter (Integer i) {
    354                
     358        public void writeCachecounter (Integer i) {             
    355359               
    356360                // first update <index idcounter>
    357                 document_counter.getFirstChild().getAttributes().getNamedItem("idcounter").setNodeValue(i.toString());
     361                cacheindex_doc.getFirstChild().getAttributes().getNamedItem("idcounter").setNodeValue(i.toString());
    358362               
    359363                //Admin.notifyUser("writeCacheCounter:" + i.toString());
     
    366370                        //initialize StreamResult with File object to save to file
    367371                        StreamResult result = new StreamResult(new StringWriter());
    368                         DOMSource source = new DOMSource(document_counter);
     372                        DOMSource source = new DOMSource(cacheindex_doc);
    369373                        try {
    370374                                transformer.transform(source, result);
     
    379383
    380384
    381                         File f = new File (cachepath + "counter.xml");
     385                        File f = new File (cacheindex_path);
    382386                        FileWriter fw;
    383387                        try {
Note: See TracChangeset for help on using the changeset viewer.