Ignore:
Timestamp:
09/19/11 10:39:55 (13 years ago)
Author:
gaba
Message:

Utils.java in place of Helpers and Admin
Diagnostics changes in GenericAction?
code arrangement, comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/WorkspaceAction.java

    r1532 r1540  
    33import java.io.BufferedInputStream;
    44import java.io.ByteArrayInputStream;
    5 import java.io.ByteArrayOutputStream;
    65import java.io.File;
    76import java.io.FileInputStream;
     
    2120import javax.xml.parsers.ParserConfigurationException;
    2221import javax.xml.transform.OutputKeys;
    23 import javax.xml.transform.Result;
    24 import javax.xml.transform.Source;
    2522import javax.xml.transform.Transformer;
    2623import javax.xml.transform.TransformerConfigurationException;
     
    4946import org.xml.sax.SAXException;
    5047
    51 import eu.clarin.cmdi.mdservice.internal.Admin;
    52 import eu.clarin.cmdi.mdservice.internal.Helpers;
     48import eu.clarin.cmdi.mdservice.internal.Utils;
    5349import eu.clarin.cmdi.mdservice.internal.MDTransformer;
    5450import eu.clarin.cmdi.mdservice.model.Diagnostic;
     
    164160        public WorkspaceAction () {     
    165161                this.elementtype = WorkspaceAction.SE_WORKSPACE;
    166                 workspacefilename = Admin.getConfig().getProperty("workspaceprofile.path") + Admin.getConfig().getProperty("workspace.file");
     162                workspacefilename = Utils.getConfig().getProperty("workspaceprofile.path") + Utils.getConfig().getProperty("workspace.file");
    167163                if (workspace_doc == null){
    168                         //workspacefilename = Admin.getConfig().getProperty("workspace.path") + Admin.getConfig().getProperty("workspace.file");
     164                        //workspacefilename = Utils.getConfig().getProperty("workspace.path") + Utils.getConfig().getProperty("workspace.file");
    169165                        initDocument();
    170166                }
     
    228224        public String getBasePath() {           
    229225                if (base_path == null) {
    230                         base_path = Admin.getConfig().getProperty(getProxyKey() + ".path");
     226                        base_path = Utils.getConfig().getProperty(getProxyKey() + ".path");
    231227                }
    232228                return base_path;
     
    248244                        File f = new File(getBasePath() + profilename);
    249245                        if (! f.exists()){
    250                                 //Admin.notifyUser(" not exists");
     246                                //log.debug(" not exists");
    251247                                profilename = "WorkspaceProfile_default.xml";
    252248                        }
     
    260256                if (profilename == null){
    261257                        profilename = PROFILENAME_DEFAULT;
    262                         Admin.notifyUser("WorkspaceProfilePath not specified (USER, SERVER)!");
    263                 }
    264                
    265                 Admin.notifyUser("WorkspaceProfilename : " + profilename);
     258                        log.debug("WorkspaceProfilePath not specified (USER, SERVER)!");
     259                }
     260               
     261                log.debug("WorkspaceProfilename : " + profilename);
    266262                return profilename;
    267263        }
     
    277273            try{
    278274                    url=file.toURI().toURL();
    279                     //Admin.notifyUser("url "  + url);
     275                    //log.debug("url "  + url);
    280276            } catch (MalformedURLException e){
    281                 //Admin.notifyUser("" + e);
     277                //log.debug("" + e);
    282278            }
    283279                return url;
     
    308304        }
    309305       
    310         /*
    311         @Override
    312         public void prepare() throws Exception {               
    313                
    314                 //Admin.notifyUser("execute:");
    315                 InputStream in = getSourceStream();
    316                 this.setSourceStream(in);
    317                 if (getFormat().equals("xml")) {                       
    318                         setResultStream(in);   
    319                 }else { //JSON
    320                         // set srcFile (for MDTransformer to pass to xsl-scripts)
    321                         MDTransformer transformer = new MDTransformer();
    322                         transformer.setSrcFile(getURL());
    323                         transformer.setParams(MDTransformer.createParamsMap(getFullFormat()));
    324                         setResultStream(transformer.transformXML(in));//, getFullFormat()));
    325                         //setSessionData(getResultStream());
    326                 }
    327                        
    328                 Admin.notifyUser(getProxyKey() + " success:" + (getResultStream()!=null));
    329         }
    330 
    331         public void changeNodeName(Document doc, Node node, String new_name){
    332                 // Create an element with the new name
    333                 Node node2 = (Node ) doc.createElement(new_name);
    334                 // Copy the attributes to the new element NamedNodeMap attrs = element.getAttributes(); for (int i=0; i<attrs.getLength(); i++) { Attr attr2 = (Attr)doc.importNode(attrs.item(i), true); element2.getAttributes().setNamedItem(attr2); }
    335                 // Move all the children
    336                 while (node.hasChildNodes()) { node2.appendChild(node.getFirstChild()); }
    337                 // Replace the old node with the new node
    338                 Admin.notifyUser("replace:" + node2.getNodeName() + "," + node.getNodeName());
    339                 node.getParentNode().replaceChild(node2, node);
    340         }
    341 
    342         public void administrateQid() throws IOException, SAXException, ParserConfigurationException, TransformerException{
    343                 WorkspaceAction wa = new WorkspaceAction();
    344                 wa.setType("Admin");
    345                
    346                 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    347         DocumentBuilder builder;
    348 
    349                 builder = factory.newDocumentBuilder();
    350                 Document  document = builder.parse(wa.getSourceStream());
    351                 // find user-filename-id or create one
    352                 //add qid
    353                 //NodeList list = document.getElementsByTagName("e");
    354                 //Admin.notifyUser("list:" + list.getLength());
    355 
    356                 // save the changes
    357                 Transformer transformer;
    358                 transformer = TransformerFactory.newInstance().newTransformer();
    359                 transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    360                 StreamResult result = new StreamResult(new StringWriter());
    361                 DOMSource source = new DOMSource(document);
    362                 transformer.transform(source, result);
    363                 String xmlString = result.getWriter().toString();
    364                 InputStream is_xml = new ByteArrayInputStream( xmlString.getBytes( ) );
    365                 Admin.writeToFile(wa.getPath(), is_xml);
    366                 //wa.save();
    367         }
    368        
    369         public String save() throws IOException, SAXException, ParserConfigurationException, TransformerException {
    370                
    371         String jsonData = getData();
    372              
    373         Admin.notifyUser("JSON data:"+jsonData);
    374         if ((!this.getType().equals(ADMIN)) && this.getQid() != null) {
    375                         administrateQid();
    376                 }
    377        
    378         XMLSerializer serializer = new XMLSerializer();
    379                 JSON json = JSONSerializer.toJSON( jsonData );
    380                 if (this.getType().equals(ADMIN)){
    381                         serializer.setRootName("Admin");
    382                 } else {
    383                         serializer.setRootName("WorkspaceProfile");     
    384                 }
    385                 serializer.setElementName("item");
    386         serializer.setTypeHintsEnabled(false);
    387         String xml = serializer.write( json );
    388         Admin.notifyUser("XML:" + xml);
    389        
    390         InputStream is_xml = new ByteArrayInputStream( xml.getBytes( ) );
    391        
    392         Admin.writeToFile(getPath(), is_xml);
    393    
    394         String ret = "1";
    395                 this.setResultStream( new ByteArrayInputStream(ret.getBytes()));
    396                                
    397 
    398                 return SUCCESS;
    399         }
    400 */
     306       
    401307        public void changeQueryId(Document doc, String from_id, String to_id) throws XPathExpressionException{
    402308                InputStream is = null;
     
    692598        serializer.setTypeHintsEnabled(false);
    693599        String xml = serializer.write( json );
    694         //Admin.notifyUser("XML:" + xml);
     600        //log.debug("XML:" + xml);
    695601        InputStream is_xml = new ByteArrayInputStream( xml.getBytes( ) );
    696602        // add to document
    697         //Admin.writeToFile(getPath(), is_xml);
     603        //Utils.writeToFile(getPath(), is_xml);
    698604        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    699605        DocumentBuilder builder = factory.newDocumentBuilder();
     
    970876                }
    971877                // nodelistto stream
    972                 InputStream is = Helpers.DocumentToStream(list.item(0));
     878                InputStream is = Utils.document2Stream(list.item(0));
    973879                this.setSourceStream(is);     
    974880               
     
    1022928                                        this.saveDocument();
    1023929                                       
    1024                                         //Admin.notifyUser("new document");
     930                                        //log.debug("new document");
    1025931                                } catch (ParserConfigurationException e) {
    1026932                                        // TODO Auto-generated catch block
     
    1051957                         init = true;
    1052958                    }  catch (IOException ex){
    1053                         //Admin.notifyUser("initCacheCounter:" + ex.toString());
     959                        //log.debug("initCacheCounter:" + ex.toString());
    1054960                        ex.printStackTrace();
    1055961                    }
     
    1070976                //workspace_doc.getFirstChild().getAttributes().getNamedItem("idcounter").setNodeValue(i.toString());
    1071977               
    1072                 //Admin.notifyUser("writeCacheCounter:" + i.toString());
     978                //log.debug("writeCacheCounter:" + i.toString());
    1073979                // write xml
    1074980                Transformer transformer;
Note: See TracChangeset for help on using the changeset viewer.