Changeset 1832


Ignore:
Timestamp:
04/01/12 20:33:03 (12 years ago)
Author:
gaba
Message:

workspace actions - new version

Location:
MDService2/branches/MDService_simple3/src
Files:
5 added
15 edited

Legend:

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

    r1810 r1832  
    33import java.io.BufferedReader;
    44import java.io.ByteArrayInputStream;
     5import java.io.File;
    56import java.io.IOException;
    67import java.io.InputStream;
     
    89import java.io.StringWriter;
    910import java.io.UnsupportedEncodingException;
     11import java.net.MalformedURLException;
     12import java.net.URL;
    1013import java.util.HashMap;
    1114import java.util.Map;
     
    2730import eu.clarin.cmdi.mdservice.internal.Utils;
    2831import eu.clarin.cmdi.mdservice.model.Diagnostic;
     32import eu.clarin.cmdi.mdservice.model.FCSRepositories;
    2933import eu.clarin.cmdi.mdservice.model.Query;
     34import eu.clarin.cmdi.mdservice.model.Repositories;
    3035import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    3136import eu.clarin.cmdi.mdservice.proxy.FCSProxy;
     
    3338import eu.clarin.cmdi.mdservice.proxy.Pz2Proxy;
    3439import eu.clarin.cmdi.mdservice.proxy.SRUProxy;
     40import eu.clarin.cmdi.mdservice.proxy.WorkspaceProxy;
    3541
    3642
     
    7783        }
    7884       
    79         /*
     85       
    8086        @Override
    8187        public String getRepository() {
    82                 //return getParam("x-content");
    83                 if (WorkspaceProfile.getFCSMapping(params.get("x-context")[0]) == null){
    84                                         return getParam("x-context");
    85                                 } else {
    86                                         return WorkspaceProfile.getFCSMapping(params.get("x-context")[0]);
    87                                 }
    88         }
    89 */
     88                if (getParam("operation").equals("searchRetrieve") && !getParam("x-context").equals("")){
     89                        if (FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]) == null){
     90                                                return getParam("x-context");
     91                                        } else {
     92                                                return FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]);
     93                                        }
     94                }
     95                return getParam("x-context");
     96
     97        }
     98
    9099         
    91100        /**
     
    124133                        }
    125134                        if ( params.get("x-context") != null){
    126                                 if (WorkspaceProfile.getFCSMapping(params.get("x-context")[0]) != null){
     135                                /*if (WorkspaceProfile.getFCSMapping(params.get("x-context")[0]) != null){
    127136                                        addFCSParam("x-context",params.get("x-context")[0]);
    128137                                }
     138                                */
    129139                               
    130140                        }
     
    151161                        if (params.get("x-context") != null){
    152162                               
    153                                 // search in fcs-mapping
    154                                 if (WorkspaceProfile.getFCSMapping(params.get("x-context")[0]) == null){
    155                                         addParam("repository",params.get("x-context")[0]);
    156                                 } else {
    157                                         addParam("repository",WorkspaceProfile.getFCSMapping(params.get("x-context")[0]));
     163                                // not for scan operation , search in fcs-mapping
     164                                if (!params.get("operation")[0].equals("scan")){
     165                                        if (FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]) == null){
     166                                                addParam("repository",params.get("x-context")[0]);
     167                                        } else {
     168                                                addParam("repository",FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]));
     169                                        }
    158170                                }
    159171                        }       
     
    171183                        addParam("cache",Cache.SKIP);
    172184                }
     185               
     186                if ((getRepository().equals("")) && (getParam("operation").equals("scan"))){
     187                        addParam("part","repositories");
     188                        addParam("extradata","fcs.resource");
     189                }
    173190        }
    174191       
    175192        @Override
    176193        public boolean checkTargetProxy(){
    177                 //if ( getTargetProxy() == null) return false;
    178                 return true;
     194                return false;
    179195        }
    180196       
     
    186202        }
    187203        @Override
    188         public InputStream getSourceStream() throws IOException, NoStylesheetException, CQLParseException {             
    189                 // TODO condition case scan
    190                 if (getTargetProxy() == null){
    191                         WorkspaceRepositoryAction wra = new WorkspaceRepositoryAction();
    192                         wra.setParam("format","sruscan");
    193                         wra.setType("SERVER");
    194                         try {
    195                                 if (wra.execute() == SUCCESS){
    196                                         return wra.getResultStream();
    197                                 }
    198                         } catch (Exception e) {
    199                                 // TODO Auto-generated catch block
    200                                 e.printStackTrace();
    201                         }
    202                         return null;
    203                 }
    204                 return getTargetProxy().getSourceStream();
    205                
    206         }
    207         /*
    208         @Override
    209         public void prepare()  {
    210                
    211                 loadParams();
    212                 // case scan
     204        public String getUserName(){
     205               
     206                return WorkspaceProfile.SERVER;
     207        }
     208        @Override
     209        public void setTargetProxy(){
     210               
     211                //Query query = new Query();
     212                //TODO case scan,explain
     213               
    213214                if ((getRepository().equals("")) && (getParam("operation").equals("scan"))){
    214                         //TODO
    215                         WorkspaceRepositoryAction wra = new WorkspaceRepositoryAction();
    216                         wra.setParam("format","sruscan");
    217                         wra.setType("SERVER");
    218                         try {
    219                                 if (wra.execute() == SUCCESS){
    220                                         setResultStream(wra.getResultStream());
    221                                 }
    222                         } catch (Exception e) {
    223                                 // TODO Auto-generated catch block
    224                                 e.printStackTrace();
    225                         }
    226                        
    227                         //WorkspaceProfile.getRepositories()
    228                         return;
    229                 }
    230                 super.prepare();
    231         }
    232                 */
    233         @Override
    234         public void setTargetProxy(){
    235                
    236                 //Query query = new Query();
    237                
    238                 if ((getRepository().equals("")) && (getParam("operation").equals("scan"))){
    239                         return;
    240                 }
    241                 switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
     215                        setTargetProxy(new WorkspaceProxy());
     216                return;
     217                }
     218               
     219                switch (Repositories.RepositoryType.toRepositoryType(Repositories.getRepositories().getRepositoryType(getRepository())))
    242220                {               
    243221                    case PAZPAR:
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericAction.java

    r1813 r1832  
    2626import eu.clarin.cmdi.mdservice.model.Diagnostic;
    2727import eu.clarin.cmdi.mdservice.model.Diagnostics;
     28import eu.clarin.cmdi.mdservice.model.Repositories;
    2829import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    2930import eu.clarin.cmdi.mdservice.proxy.ProxyInterface;
     
    5051        private String actionkey = "generic";
    5152        private String q;
    52         private String format = "xml";
     53        protected String format = "xml";
    5354       
    5455        private String actionContentType;
     
    127128        }
    128129       
     130        public String getUserName(){
     131               
     132                return null;
     133        }
    129134        /**
    130135         * Sets the variable format. Used by Struts in case the format is part of the request path.
     
    380385                        if (params.get("repository") == null){
    381386                                if (params.get("x-context") == null){
    382                                         addParam("repository",WorkspaceProfile.getRepositoryByIndex(0));
     387                                        addParam("repository",Repositories.getRepositories().getRepositoryByIndex(0));
    383388                                } else {
    384389                                        // search in fcs-mapping
    385                                         addParam("repository",WorkspaceProfile.getFCSMapping(params.get("x-context")[0]));
     390                                        //addParam("repository",WorkspaceProfile.getFCSMapping(params.get("x-context")[0]));
    386391                                        //addParam("repository",params.get("x-context")[0]);
    387392                                }
     
    528533
    529534        public boolean checkTargetProxy(){
    530                 if ( getTargetProxy() == null) return false;
    531535                return true;
    532536        }
     
    566570                       
    567571                        setTargetProxy();
    568                         if (!checkTargetProxy()) return;
     572                        if (checkTargetProxy()) {
     573                                if (getTargetProxy() == null)   
     574                                        return;
     575                        }
    569576                        checkParams();
    570577                       
     
    576583                        log.debug("request_key: " +  req_key);
    577584                        log.debug("params.size: " +  params.size());
    578                         log.debug(getActionkey() + ".targetURL: " + getTargetRequest() + " .format:" + getFullFormat());
     585                        if (getTargetRequest() != null){
     586                                log.debug(getActionkey() + ".targetURL: " + getTargetRequest() + " .format:" + getFullFormat());
     587                        }
    579588                       
    580589                        //Caching
     
    617626                                // set URL as srcFile (for MDTransformer to pass to xsl-scripts)
    618627                                // TODO: WHY??
    619                                 transformer.setSrcFile(getTargetProxy().getTargetRequest());
     628                                transformer.setSrcFile(getTargetRequest());
    620629                                transformer.setParams(getParams());
    621630                                // here the transformation is invoked
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/RepoAction.java

    r1800 r1832  
    99import eu.clarin.cmdi.mdservice.model.Diagnostic;
    1010import eu.clarin.cmdi.mdservice.model.Query;
     11import eu.clarin.cmdi.mdservice.model.Repositories;
    1112import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    1213import eu.clarin.cmdi.mdservice.proxy.FCSProxy;
     
    130131                        }
    131132                       
    132                         if (!WorkspaceProfile.repositoryExists(getRepository())){
     133                        if (!Repositories.getRepositories().repositoryExists(getRepository())){
    133134                                getDiagnostics().Add(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "repository", "repository=" + getRepository() );
    134135                                return;
     
    136137
    137138                        //Query query = new Query();
    138                         switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
     139                        switch (Repositories.RepositoryType.toRepositoryType(Repositories.getRepositories().getRepositoryType(getRepository())))
    139140                        {               
    140141                            case PAZPAR:
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/SRUAction.java

    r1807 r1832  
    2424import eu.clarin.cmdi.mdservice.model.Diagnostic;
    2525import eu.clarin.cmdi.mdservice.model.Query;
     26import eu.clarin.cmdi.mdservice.model.Repositories;
    2627import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    2728import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy;
     
    439440               
    440441                //Query query = new Query();
    441                 switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
     442                switch (Repositories.RepositoryType.toRepositoryType(Repositories.getRepositories().getRepositoryType(getRepository())))
    442443                {               
    443444                    case PAZPAR:
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/VirtualCollectionProxyAction.java

    r1663 r1832  
    88import java.net.URL;
    99import java.net.URLConnection;
     10
     11import javax.xml.xpath.XPathConstants;
     12
    1013import org.w3c.dom.NodeList;
    1114
     
    1417import eu.clarin.cmdi.mdservice.internal.MDTransformer;
    1518import eu.clarin.cmdi.mdservice.internal.Utils;
     19import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    1620
    1721/**
     
    7680               
    7781                // find the workspace data
    78                 NodeList list = (NodeList) getWorkspaceData();
     82                NodeList list = (NodeList) WorkspaceProfile.getWorkspaceProfile().getWorkspaceData(
     83                                WorkspaceProfile.getWorkspaceProfile().getXPathExpressionDummy(WorkspaceProfile.XPATH_EXPR_WORKSPACE, this.getUserName()),
     84                                XPathConstants.NODESET);
    7985        InputStream is = Utils.document2Stream(list.item(0));
    8086                //xslt transform to request data
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/WorkspaceAction.java

    r1810 r1832  
    4646import org.xml.sax.SAXException;
    4747
     48import eu.clarin.cmdi.mdservice.internal.CQLParseException;
    4849import eu.clarin.cmdi.mdservice.internal.Cache;
     50import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
    4951import eu.clarin.cmdi.mdservice.internal.Utils;
    5052import eu.clarin.cmdi.mdservice.internal.MDTransformer;
    5153import eu.clarin.cmdi.mdservice.model.Diagnostic;
     54import eu.clarin.cmdi.mdservice.model.Query;
    5255import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
     56import eu.clarin.cmdi.mdservice.proxy.FCSProxy;
     57import eu.clarin.cmdi.mdservice.proxy.WorkspaceProxy;
    5358
    5459
     
    5964 */
    6065public class WorkspaceAction extends GenericAction
    61 //implements ServletRequestAware
    6266{
    6367
     
    6569        private static Logger log = Logger.getLogger("WorkspaceAction");
    6670       
    67         // workspaceprofiles
    68         public static String USER = "user";
    69         public static String SERVER = "server";
    70        
    71         // save element type
    72         public static String SE_WORKSPACE = "workspace";
    73         public static String SE_QUERYSET = "queryset";
    74         public static String SE_QUERY = "query";
    75         public static String SE_BOOKMARKSET = "bookmarkset";
    76         public static String SE_BOOKMARK = "bookmark";
    77        
    78         // administration query identification
    79         public static String ADMIN = "admin";
    80         public static String FILENAME = "filename";
    81        
    82         public static String PROFILENAME_BASE = "WorkspaceProfile_";
    83         public static String PROFILENAME_SERVER = "WorkspaceProfileServer.xml";
    84         public static String PROFILENAME_DEFAULT = PROFILENAME_BASE + "default.xml";
    85         public static String ADMINISTRATION_FILENAME = "Administration.xml";
    86        
    87         public static String WORKSPACE_FILENAME = "WorkspaceProfile.xml";
    8871        /**
    8972         * Properties to be filled by Struts with according request-parameters
     
    9174        //private String actionkey;
    9275        private String data;
    93         private String type;  //workspacetype
    94         private String elementtype;
     76        private String type;  //workspacetype   
     77        //TODO
    9578        private String qid;
    9679        private String qsid;
    97         //private String format;
    98         //private String userMsg;
    99         private String base_path;
    100        
    101        
    102         private static WorkspaceAction singleton;
    103         private static String workspacefilename;
    104         private static Document workspace_doc;
    105        
    106         //private String workspaceindex_path;
    107         //private static Integer querycounter;
    108         private static final Integer start_query = 1;
    109        
    110        
    111        
    112         //private HttpServletRequest request;
    113        
    114         public String Workspace_filename(){
    115                 return WORKSPACE_FILENAME;
    116         }
    117 
    118         public void setWorkspace_filename(String workspace_filename) {
    119                 this.WORKSPACE_FILENAME = workspace_filename;
    120         }
    12180       
    12281        public String getData(){
     
    12887        }
    12988
    130         public String getEelemnttype(){
    131                 return elementtype;
    132         }
    133 
    134         public void setElementtype(String elementtype) {
    135                 this.elementtype = elementtype;
    136         }
    137 
    13889        public String getType() {
    13990                return type;
     
    159110                return qsid;
    160111        }
    161 
    162         public WorkspaceAction () {     
    163                 this.elementtype = WorkspaceAction.SE_WORKSPACE;
    164                 //workspacefilename = Utils.getConfig).getProperty("workspaceprofile.path") + Utils.getConfig().getProperty("workspace.file");
    165                 workspacefilename = Utils.getConfig("workspaceprofile.path") + Utils.getConfig("workspace.file");
    166                 if (workspace_doc == null){
    167                         //workspacefilename = Utils.getConfig).getProperty("workspace.path") + Utils.getConfig).getProperty("workspace.file");
    168                         initDocument();
    169                 }
    170         }
    171        
    172         public static WorkspaceAction getWorkspaceAction() {
    173                 if (singleton == null) {
    174                         singleton = new WorkspaceAction();
    175                 }
    176                 return singleton;
    177         }
    178 
    179         protected void finalize() throws Throwable {       
    180             try {               
    181                 //updateQuerycounter();
    182                 //saveDocument();
    183             } catch(Exception e) {
    184             }       
    185             finally {           
    186                 super.finalize();
    187                 //more code can be written here as per need of application             
    188             }
    189         }
     112       
    190113        /**
    191114         * primitive identification of the target-proxy
     
    194117         * @return
    195118         */
    196         public String getProxyKey() {
     119        public static String getProxyKey() {
    197120                return "workspaceprofile";
    198121        }
     
    202125                if (this.getFormat().toLowerCase().startsWith("json")) {
    203126                        this.setActionContentType("application/json");         
    204                         //this.actionContentType = "application/xhtml+xml";
    205127                } else {
    206128                        this.setActionContentType("text/xml"); 
     
    212134        @Override
    213135        protected void setDefaultParams(){
    214                
     136                if (getFormat().equals("")){
     137                        addParam("format", this.format);
     138                }
     139                if (params.get("cache") == null){
     140                        addParam("cache",Cache.SKIP);
     141                }
    215142                addParam("fullformat",getFullFormat());
    216         }
    217         //@Override
    218         public URL getBaseURL() {
    219                 File file=new File(getPath());
    220             URL url=null;
    221             try{
    222                     url=file.toURI().toURL();
    223                     log.debug("DEBUG: WorkspaceAction.getBaseURL(): "  + url);
    224             } catch (MalformedURLException e){
    225                 log.error("getBaseURL: JSON exception has been caught;\n getPath=" + getPath() );
    226                 getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, "WorkspaceAction.getBaseURL()", "JSON exception has been caught;\n getPath=" + getPath() );               
    227             }
    228            
    229             return url;
    230         }
    231        
    232         public String getBasePath() {           
    233                 if (base_path == null) {
    234                         //base_path = Utils.getConfig).getProperty(getProxyKey() + ".path");
    235                         base_path = Utils.getConfig(getProxyKey() + ".path");
    236                 }
    237                 return base_path;
    238         }
    239        
    240        
    241         public String getWorkspaceProfile() {
    242                 String profilename = null;
    243                
    244                 if (type.toLowerCase().equals(USER)) {
    245                         if (getServletRequest().getRemoteUser() != null) {
    246                                 profilename =  PROFILENAME_BASE + getServletRequest().getRemoteUser() + ".xml";
    247                         } else {
    248                                 profilename = PROFILENAME_DEFAULT;
    249                         }
    250                 } else if (type.toLowerCase().equals(SERVER)) {
    251                         profilename =  PROFILENAME_SERVER;
    252                         /*
    253                         File f = new File(getBasePath() + profilename);
    254                         if (! f.exists()){
    255                                 //log.debug(" not exists");
    256                                 profilename = "WorkspaceProfile_default.xml";
    257                         }
    258                         */
    259                 } else if (type.toLowerCase().equals(ADMIN)){
    260                         profilename =  ADMINISTRATION_FILENAME;
    261                 } else if (type.toLowerCase().equals(FILENAME)){
    262                         profilename = WORKSPACE_FILENAME;
    263                 }
    264                
    265                 if (profilename == null){
    266                         profilename = PROFILENAME_DEFAULT;
    267                         log.debug("WorkspaceProfilePath not specified (USER, SERVER)!");
    268                 }
    269                
    270                 log.debug("WorkspaceProfilename : " + profilename);
    271                 return profilename;
    272         }
    273        
     143        }       
     144
    274145        @Override
    275146        public String getFullFormat() {
    276147                return "xml2" + getFormat();
    277148        }
    278        
    279         public URL getURL() {
    280                 File file=new File(getPath());
    281             URL url=null;
    282             try{
    283                     url=file.toURI().toURL();
    284                     //log.debug("url "  + url);
    285             } catch (MalformedURLException e){
    286                 //log.debug("" + e);
    287             }
    288                 return url;
    289         }
    290        
    291        
    292         public String getPath() {
    293                 String targetPath = getBasePath() + this.WORKSPACE_FILENAME;//getWorkspaceProfile();       
    294         log.debug("WorkspaceAction TARGETPATH: " + targetPath);             
    295         return targetPath;
    296         }
    297 
    298         @Override
    299         public InputStream getSourceStream() throws IOException {       
    300                 InputStream stream = new BufferedInputStream( new FileInputStream(getPath()));
    301        
    302                
    303                 return   stream;
    304         }
    305        
    306         // set the server - session data =  repositories, termsets
    307         public void setSessionData(InputStream source) throws IOException {
    308                 if (source == null) return;
    309                 if (this.getWorkspaceProfile() != PROFILENAME_SERVER) return;
    310                
    311                
    312                        
    313         }
    314        
    315        
    316         public void changeQueryId(Document doc, String from_id, String to_id) throws XPathExpressionException{
    317                 InputStream is = null;
    318                 XPathFactory factory = XPathFactory.newInstance();
    319             XPath xpath = factory.newXPath();
    320             XPathExpression expr;
    321             String xpath_expr = "";
    322                 //xpath_expr = "//WorkspaceProfile/Querysets/item/Queries/item/id[.='" + from_id + "']";
    323             xpath_expr = "//item/id[.='" + from_id + "']";
    324                 expr = xpath.compile(xpath_expr);
    325                 Object result = null;
    326                 result = expr.evaluate(doc, XPathConstants.NODESET);
    327                
    328             NodeList nodelist = (NodeList) result;
    329             nodelist.item(0).setTextContent(to_id);
    330         }
    331         public String createNewId(){//String name){
    332                 String name = "maxid";
    333                 String id = workspace_doc.getElementsByTagName(name).item(0).getTextContent();
    334                 Integer i = Integer.parseInt(id) + 1;
    335                 id = i.toString();
    336                 workspace_doc.getElementsByTagName(name).item(0).setTextContent(id);
    337                 return id.toString();
    338         }
    339         /*
    340         public String createNewQsid(){
    341                 String id = workspace_doc.getElementsByTagName("maxqsid").item(0).getTextContent();
    342                 Integer i = Integer.parseInt(id) + 1;
    343                 id = i.toString();
    344                 workspace_doc.getElementsByTagName("maxqsid").item(0).setTextContent(id);
    345                 return id.toString();
    346         }
    347         */
    348         public InputStream createStream(String value) throws TransformerException, TransformerFactoryConfigurationError, ParserConfigurationException, UnsupportedEncodingException{
    349         DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    350         DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
    351         Document doc = docBuilder.newDocument();
    352 
    353         ////////////////////////
    354         //Creating the XML tree
    355         Element root = doc.createElement("root");
    356         root.setTextContent(value);
    357         doc.appendChild(root);
    358         //set up a transformer
    359         TransformerFactory transfac = TransformerFactory.newInstance();
    360         Transformer trans = transfac.newTransformer();
    361         //trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    362         //trans.setOutputProperty(OutputKeys.INDENT, "yes");
    363 
    364         //create string from xml tree
    365         //StringWriter sw = new StringWriter();
    366         //StreamResult result = new StreamResult(sw);
    367         //DOMSource source = new DOMSource(doc);
    368         //trans.transform(source, result);
    369        
    370 
    371         DOMSource source = new DOMSource(doc);   
    372         StringWriter xmlAsWriter = new StringWriter();   
    373         StreamResult result = new StreamResult(xmlAsWriter);     
    374         TransformerFactory.newInstance().newTransformer().transform(source, result);   
    375          
    376         // write changes   
    377         ByteArrayInputStream is = new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8")); 
    378            
    379 
    380        return is;
    381 
    382 
    383         }
    384         public String getXMLRootName(){
    385                 String rootname = "WorkspaceProfile";
    386                 if (this.elementtype.equals(WorkspaceAction.SE_QUERY)){
    387                         rootname = "item";
    388                 }
    389                 if (this.elementtype.equals(WorkspaceAction.SE_QUERYSET)){
    390                         rootname = "item";
    391                 }
    392                 return rootname;
    393         }
    394         public  String  DocumentReplaceNewElement(Document new_doc) throws XPathExpressionException{
    395                 String newid = "";
    396                 if (this.elementtype.equals(WorkspaceAction.SE_WORKSPACE)){
    397                         NodeList wsnodelist = (NodeList) getWorkspaceData();
    398                 // remove
    399                 //childeNode
    400                 if (wsnodelist.getLength() > 0){
    401                         ((Node)wsnodelist.item(0)).getParentNode().removeChild(wsnodelist.item(0));
    402                 }
    403                 //String qidstring = "";
    404                 //if (qid.equals("0")) {
    405                 //    newid = createNewQid();
    406                 //    changeQueryId(new_doc,qid,newid);
    407                 //}
    408                
    409                 Node node = new_doc.getFirstChild();
    410                 Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
    411                 ((Element)node2).setAttribute("user", getUserName());
    412                 workspace_doc.getElementsByTagName("WorkspaceProfiles").item(0).appendChild(node2);
    413                 }
    414                 if (this.elementtype.equals(WorkspaceAction.SE_QUERY)){
    415 // new query
    416                         Node node = new_doc.getFirstChild();
    417                         if (this.qid.equals("0")){
    418                                 newid = createNewId();//"maxqid");       
    419                                 new_doc.getElementsByTagName("id").item(0).setTextContent(newid);
    420                         Element root = workspace_doc.getDocumentElement();
    421                         Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
    422                         node2 = workspace_doc.renameNode(node2, "", "item");
    423                    // apend to specific queryset
    424                                 NodeList wsnodelist = (NodeList) getQueryParent();
    425                                 Node anode = wsnodelist.item(0);
    426                                 if (anode.getTextContent().trim().toLowerCase().equals("null")){
    427                                         anode.setTextContent("");
    428                                 }
    429                         anode.appendChild(node2);
    430                         }
    431                        
    432                         else {
    433                                 // edit existing query
    434                                 NodeList wsnodelist = (NodeList) getWorkspaceQuery();
    435                         // remove
    436                         //childeNode
    437                         if (wsnodelist.getLength() > 0){
    438                                 //Element root = workspace_doc.getDocumentElement();
    439                                 Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
    440                                 node2 = workspace_doc.renameNode(node2, "", "item");
    441                                 Node qnode  = (Node)wsnodelist.item(0);
    442                                 //root.replaceChild(node2,(Node)wsnodelist.item(0));   
    443                                
    444                                 Element parentElement = (Element)qnode.getParentNode();
    445                                         parentElement.insertBefore(node2, qnode);
    446                                         qnode.getParentNode().removeChild(qnode);
    447                                         parentElement.normalize();
    448                         }
    449                         }
    450                 }
    451                 if (this.elementtype.equals(WorkspaceAction.SE_BOOKMARK)){
    452                         // new bookmark
    453                                                 Node node = new_doc.getFirstChild();
    454                                                 if (this.qid.equals("0")){
    455                                                         newid = createNewId();//"maxbid");       
    456                                                         new_doc.getElementsByTagName("id").item(0).setTextContent(newid);
    457                                                 Element root = workspace_doc.getDocumentElement();
    458                                                 Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
    459                                                 node2 = workspace_doc.renameNode(node2, "", "item");
    460                                            // apend to specific bookmarkset
    461                                                         NodeList wsnodelist = (NodeList) getBookmarkParent();
    462                                                         Node anode = wsnodelist.item(0);
    463                                                         if (anode.getTextContent().trim().toLowerCase().equals("null")){
    464                                                                 anode.setTextContent("");
    465                                                         }
    466                                                 anode.appendChild(node2);
    467                                                 }
    468                                                
    469                                                 else {
    470                                                         // edit existing query
    471                                                         NodeList wsnodelist = (NodeList) getWorkspaceQuery();
    472                                                 // remove
    473                                                 //childeNode
    474                                                 if (wsnodelist.getLength() > 0){
    475                                                         //Element root = workspace_doc.getDocumentElement();
    476                                                         Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
    477                                                         node2 = workspace_doc.renameNode(node2, "", "item");
    478                                                         Node qnode  = (Node)wsnodelist.item(0);
    479                                                         //root.replaceChild(node2,(Node)wsnodelist.item(0));   
    480                                                        
    481                                                         Element parentElement = (Element)qnode.getParentNode();
    482                                                                 parentElement.insertBefore(node2, qnode);
    483                                                                 qnode.getParentNode().removeChild(qnode);
    484                                                                 parentElement.normalize();
    485                                                 }
    486                                                 }
    487                                         }
    488                 //new queryset
    489                 if (this.elementtype.equals(WorkspaceAction.SE_QUERYSET)){
    490                         // new queryset
    491                                                 Node node = new_doc.getFirstChild();
    492                                                 if (this.qsid.equals("0")){
    493                                                         newid = createNewId();//"maxqsid");     
    494                                                         new_doc.getElementsByTagName("id").item(0).setTextContent(newid);
    495                                                 Element root = workspace_doc.getDocumentElement();
    496                                                 Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
    497                                                 node2 = workspace_doc.renameNode(node2, "", "item");
    498                                            // apend to specific querysets
    499                                                 NodeList wsnodelist = (NodeList) this.getWorkspaceData();
    500                                                 Element welem = (Element)wsnodelist.item(0);
    501                                                         Node anode = welem.getElementsByTagName("Querysets").item(0);
    502                                                         if (anode.getTextContent().trim().toLowerCase().equals("null")){
    503                                                                 anode.setTextContent("");
    504                                                         }
    505                                                         anode.appendChild(node2);
    506                                                 }
    507                                                
    508                                                 else {
    509                                                         // edit existing queryset
    510                                                         NodeList wsnodelist = (NodeList) getQueryset();
    511                                                 // remove
    512                                                 //childeNode
    513                                                 if (wsnodelist.getLength() > 0){
    514                                                         //Element root = workspace_doc.getDocumentElement();
    515                                                         Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
    516                                                         node2 = workspace_doc.renameNode(node2, "", "item");
    517                                                         Node qset  = (Node)wsnodelist.item(0);
    518                                                        
    519                                                         Element parentElement = (Element)qset.getParentNode();
    520                                                                 parentElement.insertBefore(node2, qset);
    521                                                                 qset.getParentNode().removeChild(qset);
    522                                                                 parentElement.normalize();
    523                                                 }
    524                                                 }
    525                                         }
    526                
    527                 //new bookmarkset
    528                 if (this.elementtype.equals(WorkspaceAction.SE_BOOKMARKSET)){
    529                         // new queryset
    530                                                 Node node = new_doc.getFirstChild();
    531                                                 if (this.qsid.equals("0")){
    532                                                         newid = createNewId();//"maxbsid");     
    533                                                         new_doc.getElementsByTagName("id").item(0).setTextContent(newid);
    534                                                 Element root = workspace_doc.getDocumentElement();
    535                                                 Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
    536                                                 node2 = workspace_doc.renameNode(node2, "", "item");
    537                                            // apend to specific querysets
    538                                                 NodeList wsnodelist = (NodeList) this.getWorkspaceData();
    539                                                 Element welem = (Element)wsnodelist.item(0);
    540                                                 Node anode = welem.getElementsByTagName("Bookmarksets").item(0);
    541                                                if (anode.getTextContent().trim().toLowerCase().equals("null")){
    542                                                                 anode.setTextContent("");
    543                                                         }
    544                                                 anode.appendChild(node2);
    545                                                 }
    546                                                
    547                                                 else {
    548                                                         // edit existing bookmarkset
    549                                                         NodeList wsnodelist = (NodeList) getBookmarkset();
    550                                                 // remove
    551                                                 //childeNode
    552                                                 if (wsnodelist.getLength() > 0){
    553                                                         //Element root = workspace_doc.getDocumentElement();
    554                                                         Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
    555                                                         node2 = workspace_doc.renameNode(node2, "", "item");
    556                                                         Node qset  = (Node)wsnodelist.item(0);
    557                                                        
    558                                                         Element parentElement = (Element)qset.getParentNode();
    559                                                                 parentElement.insertBefore(node2, qset);
    560                                                                 qset.getParentNode().removeChild(qset);
    561                                                                 parentElement.normalize();
    562                                                 }
    563                                                 }
    564                                         }
    565                 return newid;
    566         }
    567        
    568         //todo .has("Queries")
    569         public void parseDataInit(JSONObject json){
    570                 // workspaceelement
    571                 if (json.has("Querysets")) {
    572                         this.setQid("0");
    573                         this.setElementtype(WorkspaceAction.SE_WORKSPACE);
    574                 } else {
    575                         // Querysetelement
    576                         if (json.has("Queries")) {
    577                                 this.setElementtype(WorkspaceAction.SE_QUERYSET);
    578                                 this.setQsid(json.getString("id"));
    579                         } else {
    580                                 if (json.has("Bookmarks")) {
    581                                         this.setElementtype(WorkspaceAction.SE_BOOKMARKSET);
    582                                         this.setQsid(json.getString("id"));
    583                                 } else {
    584                                         // Query-Bookmark-element
    585                                         if (json.getString("bookmark").equals("1")) {
    586                                                 this.setElementtype(WorkspaceAction.SE_BOOKMARK);
    587                                         } else {
    588                                                 // Queryelement
    589                                                 this.setElementtype(WorkspaceAction.SE_QUERY);
    590                                         }
    591                                         this.setQid(json.getString("id"));
    592                                 }
    593                         }
    594                 }
    595 
    596         }
    597         public String save() throws ParserConfigurationException, SAXException, IOException, DOMException, XPathExpressionException, TransformerException, TransformerFactoryConfigurationError{
    598                
    599                 // user data
    600                 String jsonData = getData();
    601         XMLSerializer serializer = new XMLSerializer();
    602                 JSON json = JSONSerializer.toJSON( jsonData );
    603                 // init qid, elementtype
    604                 parseDataInit((JSONObject)json);
    605                 serializer.setRootName(getXMLRootName()); //"WorkspaceProfile");       
    606                 serializer.setElementName("item");
    607         serializer.setTypeHintsEnabled(false);
    608         String xml = serializer.write( json );
    609         //log.debug("XML:" + xml);
    610         InputStream is_xml = new ByteArrayInputStream( xml.getBytes( ) );
    611         // add to document
    612         //Utils.writeToFile(getPath(), is_xml);
    613         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    614         DocumentBuilder builder = factory.newDocumentBuilder();
    615         Document new_doc = builder.parse( is_xml );
    616         // set user
    617         //((Element)d.getFirstChild()).setAttribute("user", getServletRequest().getRemoteUser());
    618         String newid = DocumentReplaceNewElement(new_doc);
    619        
    620 
    621       //TODO
    622         saveDocument();
    623         // return new qid
    624         //String src = "<body>" + qidstring + "</body>";
    625         //javax.xml.transform.stream.StreamSource s = new StreamSource(src);
    626         //InputStream in = s.getInputStream();
    627                 this.setResultStream(createStream(newid));//(InputStream)(new ByteArrayInputStream(qidstring.getBytes())));
    628                
    629                
    630                 return SUCCESS;
    631                
    632         }
    633 
    634         public String DocumentToXMLString(){
    635                 Transformer transformer;
    636                 String xmlString = "";
    637                 try {
    638                                 transformer = TransformerFactory.newInstance().newTransformer();
    639                                 transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    640 
    641                                 //initialize StreamResult with File object to save to file
    642                                 StreamResult result = new StreamResult(new StringWriter());
    643                                 DOMSource source = new DOMSource(workspace_doc);
    644                                 try {
    645                                         transformer.transform(source, result);
    646                                 } catch (TransformerException e1) {
    647                                         // TODO Auto-generated catch block
    648                                         e1.printStackTrace();
    649                                 }
    650 
    651                                 xmlString = result.getWriter().toString();
    652                         } catch (TransformerConfigurationException e) {
    653                                 // TODO Auto-generated catch block
    654                                 e.printStackTrace();
    655                         } catch (TransformerFactoryConfigurationError e) {
    656                                 // TODO Auto-generated catch block
    657                                 e.printStackTrace();
    658                         }
    659                        
    660                 return xmlString;
    661         }
    662        
    663         public void addWorkspaceToDocument(){
    664                 //{'WorkspaceProfile':{'CustomTermsets':'null',
    665                 //                     'Termsets':'null',
    666                 //                     'Repositories':'null',
    667                 //                     'Querysets':'null','created':'null','lastchanged':'null','profilename':'null'}};
    668                 Element we = workspace_doc.createElement("WorkspaceProfile");
    669                 we.setAttribute("user", getType().toLowerCase());
    670                 workspace_doc.getFirstChild().appendChild(we);
    671                
    672                 Element e = workspace_doc.createElement("CustomTermsets");
    673                 e.setNodeValue("null");
    674                 we.appendChild(e);
    675                
    676                 e = workspace_doc.createElement("Termsets");
    677                 e.setNodeValue("null");
    678                 we.appendChild(e);
    679                
    680                 e = workspace_doc.createElement("Repositories");
    681                 e.setNodeValue("null");
    682                 we.appendChild(e);
    683                
    684                 e = workspace_doc.createElement("Querysets");
    685                 e.setNodeValue("null");
    686                 we.appendChild(e);
    687                
    688                 DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    689                 String strdate = dateFormat.format(new Date()).toString();
    690                 e = workspace_doc.createElement("created");
    691                 e.setNodeValue(strdate);
    692                 we.appendChild(e);
    693                
    694                 e = workspace_doc.createElement("lastchanged");
    695                 e.setNodeValue(strdate);
    696                 we.appendChild(e);
    697                
    698                 e = workspace_doc.createElement("profilename");
    699                 e.setNodeValue(getType().toLowerCase());
    700                 we.appendChild(e);
    701         }
    702        
     149
     150        @Override
    703151        public String getUserName(){
    704152                String userstring;
    705                 if (getType().toLowerCase().equals(SERVER)){
    706                         userstring = SERVER;
     153                if (getType().toLowerCase().equals(WorkspaceProfile.SERVER)){
     154                        userstring = WorkspaceProfile.SERVER;
    707155                }else {
    708156                        userstring = getServletRequest().getRemoteUser();
     
    713161                return userstring;
    714162        }
    715         public String getWorkspaceDataXPathExpression(){
    716                 String xpath_expr = "";
    717 
    718                 xpath_expr = "//Profiles/WorkspaceProfiles/WorkspaceProfile[@user='" + getUserName() + "']";
    719 
    720                 return xpath_expr;
    721         }
    722        
    723         public Object getWorkspaceData() throws XPathExpressionException{
    724                 InputStream is = null;
     163       
     164        public Object getVcrid() throws XPathExpressionException{
     165                /*
    725166                XPathFactory factory = XPathFactory.newInstance();
    726167            XPath xpath = factory.newXPath();
    727             XPathExpression expr;
    728                         expr = xpath.compile(getWorkspaceDataXPathExpression());
     168            XPathExpression expr1, expr2;
     169                        //expr = xpath.compile("item[id='" + this.qid + "']/vcrid");
     170                        expr1 = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item/Queries/item[id='" + this.qid + "']/vcrid");
     171                        expr2 = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Bookmarksets/item[id='" + this.qid + "']/vcrid");
     172                   
    729173                        //expression is evaluated with respect to a certain context node which is doc.
    730174                        Object result = null;
    731175                        try{
    732                         result = expr.evaluate(workspace_doc, XPathConstants.NODESET);
     176                        result = expr1.evaluate(workspace_doc, XPathConstants.STRING);
    733177                        } catch(Exception e){
    734178                               
    735179                        }
    736 
     180                        if (result.equals("")){
     181                                try{
     182                                result = expr2.evaluate(workspace_doc, XPathConstants.STRING);
     183                                } catch(Exception e){
     184                                       
     185                                }
     186                        }
    737187             return result;
    738         }
    739        
    740         public Object getWorkspaceQuery() throws XPathExpressionException{
    741                
    742                 XPathFactory factory = XPathFactory.newInstance();
    743             XPath xpath = factory.newXPath();
    744             XPathExpression expr;
    745                         expr = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item/Queries/item[id='" + this.qid + "']");
    746                         //expr = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item/Queries/item[id='" +this.qid.toString()+"']");
    747                                 //expr = xpath.compile("//item[@id='" + this.qid + "']");
    748                         //expression is evaluated with respect to a certain context node which is doc.
    749                         Object result = null;
    750                         try{
    751                         result = expr.evaluate(workspace_doc, XPathConstants.NODESET);
    752                         } catch(Exception e){
    753                                
    754                         }
    755 
    756              return result;
    757         }
    758 
    759         public Object getQueryParent() throws XPathExpressionException{
    760                
    761                 XPathFactory factory = XPathFactory.newInstance();
    762             XPath xpath = factory.newXPath();
    763             XPathExpression expr;
    764                         expr = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item[id='" + this.qsid + "']/Queries");
    765                         //expression is evaluated with respect to a certain context node which is doc.
    766                         Object result = null;
    767                         try{
    768                         result = expr.evaluate(workspace_doc, XPathConstants.NODESET);
    769                         } catch(Exception e){
    770                                
    771                         }
    772 
    773              return result;
    774         }
    775 
    776         public Object getQueryVcrid() throws XPathExpressionException{
    777        
    778         XPathFactory factory = XPathFactory.newInstance();
    779     XPath xpath = factory.newXPath();
    780     XPathExpression expr;
    781 //              expr = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item[id='" + this.qsid + "']/vcrid");
    782                 expr = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item/Queries/item[id='" + this.qid + "']/vcrid");
    783            
    784                 //expression is evaluated with respect to a certain context node which is doc.
    785                 Object result = null;
    786                 try{
    787                 result = expr.evaluate(workspace_doc, XPathConstants.STRING);
    788                 } catch(Exception e){
    789                        
    790                 }
    791 
    792      return result;
     188             */
     189                return null;
     190        }
     191       
     192        @Override
     193        public void setTargetProxy() {
     194                setTargetProxy(new WorkspaceProxy());
     195        }
     196       
     197        @Override
     198        public InputStream getSourceStream() throws IOException {
     199                try {
     200                        return getTargetProxy().getSourceStream();
     201                } catch (NoStylesheetException e) {
     202                        // TODO Auto-generated catch block
     203                        e.printStackTrace();
     204                } catch (CQLParseException e) {
     205                        // TODO Auto-generated catch block
     206                        e.printStackTrace();
     207                }
     208                return null;
     209                /*
     210                WorkspaceProfile wsp = WorkspaceProfile.getWorkspaceProfile();
     211                wsp.setUsername(this.getUserName());
     212                ;
     213                try {
     214                        return wsp.getXMLStream(wsp.getXPathExpressionDummy(WorkspaceProfile.XPATH_EXPR_WORKSPACE, getUserName()));
     215                } catch (XPathExpressionException e) {
     216                        // TODO Auto-generated catch block
     217                        e.printStackTrace();
     218                } catch (TransformerConfigurationException e) {
     219                        // TODO Auto-generated catch block
     220                        e.printStackTrace();
     221                } catch (TransformerException e) {
     222                        // TODO Auto-generated catch block
     223                        e.printStackTrace();
     224                } catch (TransformerFactoryConfigurationError e) {
     225                        // TODO Auto-generated catch block
     226                        e.printStackTrace();
     227                }
     228                return null;
     229                */
     230        }
     231               
     232        public String save() throws ParserConfigurationException, SAXException, IOException, DOMException, XPathExpressionException, TransformerException, TransformerFactoryConfigurationError{
     233               
     234                String newid = WorkspaceProfile.getWorkspaceProfile().save(getData());
     235                this.setResultStream(WorkspaceProfile.createStream(newid));
     236               
     237               
     238                return SUCCESS;
     239               
     240        }
     241       
     242
    793243}
    794 
    795         public Object getVcrid() throws XPathExpressionException{
    796        
    797         XPathFactory factory = XPathFactory.newInstance();
    798     XPath xpath = factory.newXPath();
    799     XPathExpression expr1, expr2;
    800                 //expr = xpath.compile("item[id='" + this.qid + "']/vcrid");
    801                 expr1 = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item/Queries/item[id='" + this.qid + "']/vcrid");
    802                 expr2 = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Bookmarksets/item[id='" + this.qid + "']/vcrid");
    803            
    804                 //expression is evaluated with respect to a certain context node which is doc.
    805                 Object result = null;
    806                 try{
    807                 result = expr1.evaluate(workspace_doc, XPathConstants.STRING);
    808                 } catch(Exception e){
    809                        
    810                 }
    811                 if (result.equals("")){
    812                         try{
    813                         result = expr2.evaluate(workspace_doc, XPathConstants.STRING);
    814                         } catch(Exception e){
    815                                
    816                         }
    817                 }
    818      return result;
    819 }
    820         public Object getQueryset() throws XPathExpressionException{
    821                
    822                 XPathFactory factory = XPathFactory.newInstance();
    823             XPath xpath = factory.newXPath();
    824             XPathExpression expr;
    825                         expr = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item[id='" + this.qsid + "']");
    826                         //expression is evaluated with respect to a certain context node which is doc.
    827                         Object result = null;
    828                         try{
    829                         result = expr.evaluate(workspace_doc, XPathConstants.NODESET);
    830                         } catch(Exception e){
    831                                
    832                         }
    833 
    834              return result;
    835         }
    836 
    837         public Object getBookmarkParent() throws XPathExpressionException{
    838                
    839                 XPathFactory factory = XPathFactory.newInstance();
    840             XPath xpath = factory.newXPath();
    841             XPathExpression expr;
    842                         expr = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Bookmarksets/item[id='" + this.qsid + "']/Bookmarks");
    843                         //expression is evaluated with respect to a certain context node which is doc.
    844                         Object result = null;
    845                         try{
    846                         result = expr.evaluate(workspace_doc, XPathConstants.NODESET);
    847                         } catch(Exception e){
    848                                
    849                         }
    850 
    851              return result;
    852         }
    853        
    854         public Object getBookmarkset() throws XPathExpressionException{
    855                
    856                 XPathFactory factory = XPathFactory.newInstance();
    857             XPath xpath = factory.newXPath();
    858             XPathExpression expr;
    859                         expr = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Bookmarksets/item[id='" + this.qsid + "']");
    860                         //expression is evaluated with respect to a certain context node which is doc.
    861                         Object result = null;
    862                         try{
    863                         result = expr.evaluate(workspace_doc, XPathConstants.NODESET);
    864                         } catch(Exception e){
    865                                
    866                         }
    867 
    868              return result;
    869         }
    870 
    871        
    872         @Override
    873         public void prepare()  {               
    874                
    875                 try{
    876                         loadParams();
    877                        
    878                 NodeList list = (NodeList) getWorkspaceData();//result;
    879                 if (list.getLength() < 1) {
    880                         addWorkspaceToDocument();
    881                         list = (NodeList) getWorkspaceData();
    882                 }
    883                 if (list.getLength() > 1){
    884                         // error
    885                 }
    886                 // nodelistto stream
    887                 InputStream is = Utils.document2Stream(list.item(0));
    888                 this.setSourceStream(is);     
    889                
    890                 if (getFormat().equals("xml")) {                       
    891                         setResultStream(is);   
    892                 }else { //JSON
    893                         // set srcFile (for MDTransformer to pass to xsl-scripts)
    894                         MDTransformer transformer = new MDTransformer();
    895                         transformer.configure(Utils.getAppConfig("mdservice"), this.getClass().getClassLoader());
    896                         transformer.setSrcFile(getURL());
    897                         transformer.setParams(getParams());
    898                         //transformer.setParams(MDTransformer.createParamsMap(getFullFormat()));
    899                         setResultStream(transformer.transformXML(is));//, getFullFormat()));
    900                         //setSessionData(getResultStream());
    901                 }
    902                        
    903                 log.debug(getProxyKey() + " success:" + (getResultStream()!=null));
    904 
    905                 } catch (Exception e){
    906                        
    907                 }
    908         }
    909 
    910        
    911        
    912 public void initDocument() {
    913        
    914         boolean init=false;
    915         Integer counter = start_query;
    916         //String fname = getPath();//workspacefile;
    917         File f = new File (workspacefilename);
    918                
    919         if (!f.exists()) {
    920                                 // create new  counter document
    921                                 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    922                         DocumentBuilder docBuilder;
    923                                 try {
    924                                         docBuilder = docFactory.newDocumentBuilder();
    925                                         workspace_doc = docBuilder.newDocument();
    926                                         // append root tag <index >
    927                                         Element root = (Element) workspace_doc.createElement("Profiles");
    928                                         //root.setAttribute("idcounter", "1");
    929                                         workspace_doc.appendChild(root);
    930                                         Element e = workspace_doc.createElement("Querycounter");
    931                                         root.appendChild(e);
    932                                         e = workspace_doc.createElement("maxqid");
    933                                         e.setNodeValue(counter.toString());
    934                                         e = workspace_doc.createElement("WorkspaceProfiles");
    935                                         root.appendChild(e);
    936 
    937                                         //updateQuerycounter();
    938                                         this.saveDocument();
    939                                        
    940                                         //log.debug("new document");
    941                                 } catch (ParserConfigurationException e) {
    942                                         // TODO Auto-generated catch block
    943                                         e.printStackTrace();
    944                                 }
    945             }
    946                 else {
    947                         try {
    948                                
    949                         DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    950                         DocumentBuilder docBuilder;
    951                                 try {
    952                                         docBuilder = docFactory.newDocumentBuilder();               
    953                                         try {
    954                                                         workspace_doc = docBuilder.parse(workspacefilename);
    955                                         } catch (SAXException e) {
    956                                                         // TODO Auto-generated catch block
    957                                                        
    958                                                         e.printStackTrace();
    959                                         }
    960                                 } catch (ParserConfigurationException e) {
    961                                                 // TODO Auto-generated catch block
    962                                                 e.printStackTrace();
    963                                 }
    964                                
    965                          //read counter
    966                          //counter = new Integer(workspace_doc.getFirstChild().getFirstChild().getFirstChild().getNodeValue());
    967                          init = true;
    968                     }  catch (IOException ex){
    969                         //log.debug("initCacheCounter:" + ex.toString());
    970                         ex.printStackTrace();
    971                     }
    972                 }
    973                
    974             //return counter;
    975         }
    976 /*
    977         public void updateQuerycounter () {
    978                 workspace_doc.getFirstChild().getAttributes().getNamedItem("idcounter").setNodeValue(querycounter.toString());
    979             saveDocument();
    980         }
    981         */
    982         public void saveDocument() {
    983         //public void writeQuerycounter (Integer i) {           
    984                
    985                 // first update <index idcounter>
    986                 //workspace_doc.getFirstChild().getAttributes().getNamedItem("idcounter").setNodeValue(i.toString());
    987                
    988                 //log.debug("writeCacheCounter:" + i.toString());
    989                 // write xml
    990                 Transformer transformer;
    991                 try {
    992                         transformer = TransformerFactory.newInstance().newTransformer();
    993                         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    994 
    995                         //initialize StreamResult with File object to save to file
    996                         StreamResult result = new StreamResult(new StringWriter());
    997                         DOMSource source = new DOMSource(workspace_doc);
    998                         try {
    999                                 transformer.transform(source, result);
    1000                         } catch (TransformerException e1) {
    1001                                 // TODO Auto-generated catch block
    1002                                 e1.printStackTrace();
    1003                         }
    1004 
    1005                         String xmlString = result.getWriter().toString();
    1006 
    1007                         File f = new File (workspacefilename);
    1008                         FileWriter fw;
    1009                         try {
    1010                                 fw = new FileWriter(f);
    1011                                 try {
    1012                                         fw.write(xmlString);
    1013                                         fw.close();
    1014                                 } catch (IOException e) {
    1015                                         // TODO Auto-generated catch block
    1016                                         e.printStackTrace();
    1017                                 }       
    1018                         } catch (IOException e) {
    1019                                 // TODO Auto-generated catch block
    1020                                 e.printStackTrace();
    1021                         }
    1022                 } catch (TransformerConfigurationException e2) {
    1023                         // TODO Auto-generated catch block
    1024                         e2.printStackTrace();
    1025                 } catch (TransformerFactoryConfigurationError e2) {
    1026                         // TODO Auto-generated catch block
    1027                         e2.printStackTrace();
    1028                 }
    1029         }
    1030        
    1031 
    1032 }
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/WorkspaceProfile.java

    r1800 r1832  
    22
    33import java.io.BufferedInputStream;
     4import java.io.ByteArrayInputStream;
    45import java.io.File;
    56import java.io.FileInputStream;
     7import java.io.FileWriter;
    68import java.io.IOException;
    79import java.io.InputStream;
     10import java.io.StringWriter;
     11import java.io.UnsupportedEncodingException;
    812import java.net.URL;
     13import java.text.DateFormat;
     14import java.text.SimpleDateFormat;
     15import java.util.Date;
    916import java.util.HashMap;
    1017
     18import javax.xml.namespace.QName;
     19import javax.xml.parsers.DocumentBuilder;
     20import javax.xml.parsers.DocumentBuilderFactory;
     21import javax.xml.parsers.ParserConfigurationException;
     22import javax.xml.transform.OutputKeys;
     23import javax.xml.transform.Transformer;
     24import javax.xml.transform.TransformerConfigurationException;
    1125import javax.xml.transform.TransformerException;
    12 
     26import javax.xml.transform.TransformerFactory;
     27import javax.xml.transform.TransformerFactoryConfigurationError;
     28import javax.xml.transform.dom.DOMSource;
     29import javax.xml.transform.stream.StreamResult;
     30import javax.xml.xpath.XPath;
     31import javax.xml.xpath.XPathConstants;
     32import javax.xml.xpath.XPathExpression;
     33import javax.xml.xpath.XPathExpressionException;
     34import javax.xml.xpath.XPathFactory;
     35
     36import org.w3c.dom.DOMException;
     37import org.w3c.dom.Document;
     38import org.w3c.dom.Element;
     39import org.w3c.dom.Node;
     40import org.w3c.dom.NodeList;
     41import org.xml.sax.SAXException;
     42
     43import net.sf.json.JSON;
    1344import net.sf.json.JSONArray;
    1445import net.sf.json.JSONObject;
     46import net.sf.json.JSONSerializer;
     47import net.sf.json.xml.XMLSerializer;
    1548import eu.clarin.cmdi.mdservice.internal.MDTransformer;
    1649import eu.clarin.cmdi.mdservice.internal.Utils;
    1750import eu.clarin.cmdi.mdservice.action.FCSAction;
    1851import eu.clarin.cmdi.mdservice.action.WorkspaceAction;
     52import eu.clarin.cmdi.mdservice.action.WorkspaceAction_old;
    1953import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
    2054
     
    2761public class WorkspaceProfile{ 
    2862
    29         //TODO new class
    30         public static enum RepositoryType
    31         {
    32                 MD, SRU, PAZPAR, FCS, FCSRESOURCE, NOVALUE;
    33 
    34             public static RepositoryType toRepositoryType(String str)
    35             {
    36                 try {
    37                     return valueOf(str.replace(".", "").toUpperCase());
    38                 }
    39                 catch (Exception ex) {
    40                     return NOVALUE;
    41                 }
    42             }   
    43         }
    44         public static enum TermsetType
    45         {
    46                 MODEL, DCR, RR, NOVALUE;
    47 
    48             public static TermsetType toTermsetType(String str)
    49             {
    50                 try {
    51                     return valueOf(str.toUpperCase());
    52                 }
    53                 catch (Exception ex) {
    54                     return NOVALUE;
    55                 }
    56             }   
    57         }
    58         private static JSONArray repositories = null;
    59         private static JSONArray termsets = null;
    60         private static JSONObject options = null;
    61        
     63        private static WorkspaceProfile singleton;
     64        private static Document workspace_doc;
     65       
     66        private String workspacefilename;
     67        private String username;
     68        private String elementtype;
     69        private String qid;
     70        private String qsid;
     71        //TODO counter not working
     72        private static final Integer START_QUERY = 1;
     73       
     74        // save element type
     75        public static String SE_WORKSPACE = "workspace";
     76        public static String SE_QUERYSET = "queryset";
     77        public static String SE_QUERY = "query";
     78        public static String SE_BOOKMARKSET = "bookmarkset";
     79        public static String SE_BOOKMARK = "bookmark";
     80       
     81        public static String USER = "user";
     82        public static String SERVER = "server";
     83       
     84        public static String XPATH_EXPR_WORKSPACE = "//Profiles/WorkspaceProfiles/WorkspaceProfile[@user='dummy']";
     85        public static String XPATH_EXPR_REPOSITORIES = "//Profiles/WorkspaceProfiles/WorkspaceProfile[@user='server']/Repositories";
     86        public static String XPATH_EXPR_OPTIONS = "//Profiles/WorkspaceProfiles/WorkspaceProfile[@user='server']/Options";
     87        public static String XPATH_EXPR_TERMSETS = "//Profiles/WorkspaceProfiles/WorkspaceProfile[@user='server']/Termsets";
     88        public static String XPATH_EXPR_REPOPATH = "//Profiles/WorkspaceProfiles/WorkspaceProfile[@user='server']/Repositories/item[@name='dummy']/uri";
     89        public static String XPATH_EXPR_QUERY_PARENT = "//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item[id='dummy']/Queries";
     90        public static String XPATH_EXPR_QUERYSET = "//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item[id='dummy']";
     91        public static String XPATH_EXPR_WORKSPACE_QUERY = "//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item/Queries/item[id='dummy']";
     92        public static String XPATH_EXPR_BOOKMARKSET = "//Profiles/WorkspaceProfiles/WorkspaceProfile/Bookmarksets/item[id='dummy']";
     93        public static String XPATH_EXPR_BOOKMARK_PARENT = "//Profiles/WorkspaceProfiles/WorkspaceProfile/Bookmarksets/item[id='dummy']/Bookmarks";
    6294        /////
    6395        private static HashMap<String,String> fcs_mapping = null;
    6496       
    65         public static JSONArray getRepositories(){
    66                 if (repositories == null){
    67                         try {
    68                                 WorkspaceProfile.setRepositories(WorkspaceProfile.createRepositories());
    69                                 WorkspaceProfile.createFCSRepositories();
    70                         } catch (IOException e) {
    71                                 // TODO Auto-generated catch block
    72                                 e.printStackTrace();
    73                         } catch (InterruptedException e) {
    74                                 // TODO Auto-generated catch block
    75                                 e.printStackTrace();
    76                         } catch (TransformerException e) {
    77                                 // TODO Auto-generated catch block
    78                                 e.printStackTrace();
    79                         } catch (NoStylesheetException e) {
    80                                 // TODO Auto-generated catch block
    81                                 e.printStackTrace();
    82                         }
    83                 }
    84                 return repositories;
    85         }
    86        
    87         public static void setRepositories(JSONArray rep){
    88                 WorkspaceProfile.repositories = rep;
    89         }
    90        
    91         public static JSONObject getOptions(){
    92                 if (options == null ) {
    93                         try {
    94                                 WorkspaceProfile.setOptions(WorkspaceProfile.createOptions());
    95                         } catch (IOException e) {
    96                                 // TODO Auto-generated catch block
    97                                 e.printStackTrace();
    98                         } catch (InterruptedException e) {
    99                                 // TODO Auto-generated catch block
    100                                 e.printStackTrace();
    101                         } catch (TransformerException e) {
    102                                 // TODO Auto-generated catch block
    103                                 e.printStackTrace();
    104                         } catch (NoStylesheetException e) {
    105                                 // TODO Auto-generated catch block
    106                                 e.printStackTrace();
    107                         }
    108                 }
    109                 return options;
    110         }
    111        
    112         public static void setOptions(JSONObject op){
    113                 WorkspaceProfile.options = op;
    114         }
    115        
    116         public static JSONArray getTermsets(){
    117                 if (termsets == null ) {
    118                         try {
    119                                 WorkspaceProfile.setTermsets(WorkspaceProfile.createTermsets());
    120                         } catch (IOException e) {
    121                                 // TODO Auto-generated catch block
    122                                 e.printStackTrace();
    123                         } catch (InterruptedException e) {
    124                                 // TODO Auto-generated catch block
    125                                 e.printStackTrace();
    126                         } catch (TransformerException e) {
    127                                 // TODO Auto-generated catch block
    128                                 e.printStackTrace();
    129                         } catch (NoStylesheetException e) {
    130                                 // TODO Auto-generated catch block
    131                                 e.printStackTrace();
    132                         }
    133                 }
    134                 return termsets;
    135         }
    136        
    137         public static void setTermsets(JSONArray op){
    138                 WorkspaceProfile.termsets = op;
    139         }
    140        
     97       
     98        public void setQsid(String qsid) {
     99                this.qsid = qsid;
     100        }
     101
     102        public String getQsid() {
     103                return qsid;
     104        }
     105
     106        public void setQid(String qid) {
     107                this.qid = qid;
     108        }
     109
     110        public String getQid() {
     111                return qid;
     112        }
     113
     114        public void setElementtype(String elementtype) {
     115                this.elementtype = elementtype;
     116        }
     117
     118        public String getElementtype() {
     119                return elementtype;
     120        }
     121
     122        public void setUsername(String username) {
     123                this.username = username;
     124        }
     125
     126        public String getUsername() {
     127                return username;
     128        }
    141129
    142130        public WorkspaceProfile() {
     131                Init();
     132        }
     133       
     134        public static WorkspaceProfile getWorkspaceProfile() {
     135                if (singleton == null) {
     136                        singleton = new WorkspaceProfile();
     137                }
     138                return singleton;
     139        }
     140       
     141        public void Init(){
    143142                //configure
    144143                Utils.loadConfig("mdservice", "mdservice.properties", this.getClass().getClassLoader());
    145 
    146         }
    147        
    148         // FCS
    149         public static String getFCSMapping(String context){
    150                 if (fcs_mapping == null){
    151                         WorkspaceProfile.createFCSRepositories();
     144                workspacefilename = Utils.getConfig("workspaceprofile.path") + Utils.getConfig("workspace.file");
     145                username = SERVER;
     146               
     147                if (workspace_doc == null){
     148                        initDocument();
    152149                }
    153                 return fcs_mapping.get(context);
    154         }
    155        
    156         public static void createFCSRepositories(){
    157        
    158         // static repositories
    159         net.sf.json.JSONArray json = WorkspaceProfile.getRepositories();
    160         for(int i=0;i<json.size();i++){
    161                         if (json.getJSONObject(i).getString("type").equals("fcs.resource")){
    162                                 if (!json.getJSONObject(i).containsKey("fcsresource")){
    163                                         if (createFCSRepository(json.getJSONObject(i))){
     150        }
     151       
     152        public void initDocument() {
     153               
     154                Integer counter = START_QUERY;
     155                File f = new File (workspacefilename);
     156                       
     157                if (!f.exists()) {
     158                                        // create new  counter document
     159                                        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
     160                                DocumentBuilder docBuilder;
     161                                        try {
     162                                                docBuilder = docFactory.newDocumentBuilder();
     163                                                workspace_doc = docBuilder.newDocument();
     164                                                // append root tag <index >
     165                                                Element root = (Element) workspace_doc.createElement("Profiles");
     166                                                //root.setAttribute("idcounter", "1");
     167                                                workspace_doc.appendChild(root);
     168                                                Element e = workspace_doc.createElement("Querycounter");
     169                                                root.appendChild(e);
     170                                                e = workspace_doc.createElement("maxqid");
     171                                                e.setNodeValue(counter.toString());
     172                                                e = workspace_doc.createElement("WorkspaceProfiles");
     173                                                root.appendChild(e);
     174
     175                                                //updateQuerycounter();
     176                                                this.saveDocument();
     177                                               
     178                                                //log.debug("new document");
     179                                        } catch (ParserConfigurationException e) {
     180                                                // TODO Auto-generated catch block
     181                                                e.printStackTrace();
    164182                                        }
     183                    }
     184                        else {
     185                                try {
     186                                       
     187                                DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
     188                                DocumentBuilder docBuilder;
     189                                        try {
     190                                                docBuilder = docFactory.newDocumentBuilder();               
     191                                                try {
     192                                                                workspace_doc = docBuilder.parse(f);//workspacefilename);
     193                                                } catch (SAXException e) {
     194                                                                // TODO Auto-generated catch block
     195                                                               
     196                                                                e.printStackTrace();
     197                                                }
     198                                        } catch (ParserConfigurationException e) {
     199                                                        // TODO Auto-generated catch block
     200                                                        e.printStackTrace();
     201                                        }
     202                                       
     203                                 //read counter
     204                                 //counter = new Integer(workspace_doc.getFirstChild().getFirstChild().getFirstChild().getNodeValue());
     205                                 //init = true;
     206                            }  catch (IOException ex){
     207                                //log.debug("initCacheCounter:" + ex.toString());
     208                                ex.printStackTrace();
     209                            }
     210                        }
     211                       
     212                    //return counter;
     213                }
     214
     215        public void saveDocument() {
     216                //public void writeQuerycounter (Integer i) {           
     217                       
     218                        // first update <index idcounter>
     219                        //workspace_doc.getFirstChild().getAttributes().getNamedItem("idcounter").setNodeValue(i.toString());
     220                       
     221                        //log.debug("writeCacheCounter:" + i.toString());
     222                        // write xml
     223                        Transformer transformer;
     224                        try {
     225                                transformer = TransformerFactory.newInstance().newTransformer();
     226                                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
     227
     228                                //initialize StreamResult with File object to save to file
     229                                StreamResult result = new StreamResult(new StringWriter());
     230                                DOMSource source = new DOMSource(workspace_doc);
     231                                try {
     232                                        transformer.transform(source, result);
     233                                } catch (TransformerException e1) {
     234                                        // TODO Auto-generated catch block
     235                                        e1.printStackTrace();
     236                                }
     237
     238                                String xmlString = result.getWriter().toString();
     239
     240                                File f = new File (workspacefilename);
     241                                FileWriter fw;
     242                                try {
     243                                        fw = new FileWriter(f);
     244                                        try {
     245                                                fw.write(xmlString);
     246                                                fw.close();
     247                                        } catch (IOException e) {
     248                                                // TODO Auto-generated catch block
     249                                                e.printStackTrace();
     250                                        }       
     251                                } catch (IOException e) {
     252                                        // TODO Auto-generated catch block
     253                                        e.printStackTrace();
     254                                }
     255                        } catch (TransformerConfigurationException e2) {
     256                                // TODO Auto-generated catch block
     257                                e2.printStackTrace();
     258                        } catch (TransformerFactoryConfigurationError e2) {
     259                                // TODO Auto-generated catch block
     260                                e2.printStackTrace();
     261                        }
     262        }
     263       
     264        public String getXPathExpressionDummy(String xpath_expr, String new_dummy){
     265
     266                return xpath_expr.replace("dummy", new_dummy);
     267        }
     268
     269        public Object getWorkspaceData(String xpath_str, QName type) throws XPathExpressionException{
     270                XPathFactory factory = XPathFactory.newInstance();
     271            XPath xpath = factory.newXPath();
     272            XPathExpression expr;
     273                        expr = xpath.compile(xpath_str);
     274                        //expression is evaluated with respect to a certain context node which is doc.
     275                        Object result = null;
     276                        try{
     277                        result = expr.evaluate(workspace_doc, type);//XPathConstants.NODESET);
     278                        } catch(Exception e){
     279                               
     280                        }
     281
     282             return result;
     283        }
     284       
     285        public void addWorkspaceToDocument(){
     286                //{'WorkspaceProfile':{'CustomTermsets':'null',
     287                //                     'Termsets':'null',
     288                //                     'Repositories':'null',
     289                //                     'Querysets':'null','created':'null','lastchanged':'null','profilename':'null'}};
     290                Element we = workspace_doc.createElement("WorkspaceProfile");
     291                we.setAttribute("user", getUsername().toLowerCase());
     292                workspace_doc.getFirstChild().appendChild(we);
     293               
     294                Element e = workspace_doc.createElement("CustomTermsets");
     295                e.setNodeValue("null");
     296                we.appendChild(e);
     297               
     298                e = workspace_doc.createElement("Termsets");
     299                e.setNodeValue("null");
     300                we.appendChild(e);
     301               
     302                e = workspace_doc.createElement("Repositories");
     303                e.setNodeValue("null");
     304                we.appendChild(e);
     305               
     306                e = workspace_doc.createElement("Querysets");
     307                e.setNodeValue("null");
     308                we.appendChild(e);
     309               
     310                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
     311                String strdate = dateFormat.format(new Date()).toString();
     312                e = workspace_doc.createElement("created");
     313                e.setNodeValue(strdate);
     314                we.appendChild(e);
     315               
     316                e = workspace_doc.createElement("lastchanged");
     317                e.setNodeValue(strdate);
     318                we.appendChild(e);
     319               
     320                e = workspace_doc.createElement("profilename");
     321                e.setNodeValue(getUsername().toLowerCase());
     322                we.appendChild(e);
     323        }
     324       
     325        public InputStream getXMLStream(String xpath_expr) throws XPathExpressionException, TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError{
     326                InputStream is;
     327                NodeList list = (NodeList) getWorkspaceData(xpath_expr, XPathConstants.NODESET);//result;
     328            if (list.getLength() < 1) {
     329                addWorkspaceToDocument();
     330                list = (NodeList) getWorkspaceData(xpath_expr, XPathConstants.NODESET);
     331            }
     332            if (list.getLength() > 1){
     333                // error
     334            }
     335            // nodelist2stream
     336            is = Utils.document2Stream(list.item(0));
     337            return is;
     338
     339        }
     340       
     341        //todo .has("Queries")
     342        public void parseDataInit(JSONObject json){
     343                // workspaceelement
     344                if (json.has("Querysets")) {
     345                        this.setQid("0");
     346                        this.setElementtype(WorkspaceProfile.SE_WORKSPACE);
     347                } else {
     348                        // Querysetelement
     349                        if (json.has("Queries")) {
     350                                this.setElementtype(WorkspaceProfile.SE_QUERYSET);
     351                                this.setQsid(json.getString("id"));
     352                        } else {
     353                                if (json.has("Bookmarks")) {
     354                                        this.setElementtype(WorkspaceProfile.SE_BOOKMARKSET);
     355                                        this.setQsid(json.getString("id"));
     356                                } else {
     357                                        // Query-Bookmark-element
     358                                        if (json.getString("bookmark").equals("1")) {
     359                                                this.setElementtype(WorkspaceProfile.SE_BOOKMARK);
     360                                        } else {
     361                                                // Queryelement
     362                                                this.setElementtype(WorkspaceProfile.SE_QUERY);
     363                                        }
     364                                        this.setQid(json.getString("id"));
    165365                                }
    166366                        }
    167367                }
    168         }
    169 
    170         public static void addToFCSMapping(JSONObject jsonendpoint, JSONObject json){
    171                 String endpoint;
    172                 JSONObject extradata, extratermsobject;
    173                 net.sf.json.JSONArray extraterms;
    174        
    175         if (fcs_mapping == null){
    176                 fcs_mapping  = new HashMap<String,String>();
    177         }
    178         net.sf.json.JSONArray jsonterms = json.getJSONObject("sru:scanResponse").getJSONArray("sru:terms");
    179         for(int i=0;i<jsonterms.size();i++){
    180                 endpoint = jsonterms.getJSONObject(i).getString("sru:value");
    181                 if (jsonterms.getJSONObject(i).containsKey("sru:extraTermData")){
    182                         extradata = jsonterms.getJSONObject(i).getJSONObject("sru:extraTermData");
    183                         if (extradata.get("sru:terms").getClass().getName().equals("net.sf.json.JSONArray")){
    184                                 extraterms = extradata.getJSONArray("sru:terms");
    185                                 for(int j=0;j<extraterms.size();j++){
    186                                         fcs_mapping.put(extraterms.getJSONObject(j).getString("sru:value"), endpoint);
     368
     369        }
     370       
     371        public String getXMLRootName(){
     372                String rootname = "WorkspaceProfile";
     373                if (this.elementtype.equals(WorkspaceProfile.SE_QUERY)){
     374                        rootname = "item";
     375                }
     376                if (this.elementtype.equals(WorkspaceProfile.SE_QUERYSET)){
     377                        rootname = "item";
     378                }
     379                return rootname;
     380        }
     381       
     382        public  String save(String jsonData) throws ParserConfigurationException, SAXException, IOException, DOMException, XPathExpressionException, TransformerException, TransformerFactoryConfigurationError{
     383               
     384        XMLSerializer serializer = new XMLSerializer();
     385                JSON json = JSONSerializer.toJSON( jsonData );
     386                // init qid, elementtype
     387                parseDataInit((JSONObject)json);
     388                serializer.setRootName(getXMLRootName()); //"WorkspaceProfile");       
     389                serializer.setElementName("item");
     390        serializer.setTypeHintsEnabled(false);
     391        String xml = serializer.write( json );
     392        //log.debug("XML:" + xml);
     393        InputStream is_xml = new ByteArrayInputStream( xml.getBytes( ) );
     394        // add to document
     395        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     396        DocumentBuilder builder = factory.newDocumentBuilder();
     397        Document new_doc = builder.parse( is_xml );
     398        String newid = DocumentReplaceNewElement(new_doc);
     399      //TODO
     400        saveDocument();
     401       
     402                return newid.toString();
     403               
     404        }
     405       
     406        public String createNewId(){//String name){
     407                String name = "maxid";
     408                String id = workspace_doc.getElementsByTagName(name).item(0).getTextContent();
     409                Integer i = Integer.parseInt(id) + 1;
     410                id = i.toString();
     411                workspace_doc.getElementsByTagName(name).item(0).setTextContent(id);
     412                return id.toString();
     413        }
     414       
     415        public  String  DocumentReplaceNewElement(Document new_doc) throws XPathExpressionException{
     416                String newid = "";
     417                if (this.elementtype.equals(WorkspaceProfile.SE_WORKSPACE)){
     418                        NodeList wsnodelist = (NodeList) getWorkspaceData(this.getXPathExpressionDummy(WorkspaceProfile.XPATH_EXPR_QUERY_PARENT, this.qsid),XPathConstants.NODESET);
     419                // remove
     420                //childeNode
     421                if (wsnodelist.getLength() > 0){
     422                        ((Node)wsnodelist.item(0)).getParentNode().removeChild(wsnodelist.item(0));
     423                }
     424               
     425                Node node = new_doc.getFirstChild();
     426                Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
     427                ((Element)node2).setAttribute("user", this.getUsername());
     428                workspace_doc.getElementsByTagName("WorkspaceProfiles").item(0).appendChild(node2);
     429                }
     430                if (this.elementtype.equals(WorkspaceProfile.SE_QUERY)){
     431// new query
     432                        Node node = new_doc.getFirstChild();
     433                        if (this.qid.equals("0")){
     434                                newid = createNewId();//"maxqid");       
     435                                new_doc.getElementsByTagName("id").item(0).setTextContent(newid);
     436                        Element root = workspace_doc.getDocumentElement();
     437                        Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
     438                        node2 = workspace_doc.renameNode(node2, "", "item");
     439                   // apend to specific queryset
     440                                NodeList wsnodelist = (NodeList) getWorkspaceData(this.getXPathExpressionDummy(WorkspaceProfile.XPATH_EXPR_QUERY_PARENT, this.qsid),XPathConstants.NODESET);;
     441                                Node anode = wsnodelist.item(0);
     442                                if (anode.getTextContent().trim().toLowerCase().equals("null")){
     443                                        anode.setTextContent("");
    187444                                }
    188                         } else {
    189                                 extratermsobject = extradata.getJSONObject("sru:terms");
    190                                 fcs_mapping.put(extratermsobject.getJSONObject("sru:term").getString("sru:value"), endpoint);
     445                        anode.appendChild(node2);
     446                        }
     447                       
     448                        else {
     449                                // edit existing query
     450                                NodeList wsnodelist = (NodeList) getWorkspaceData(this.getXPathExpressionDummy(WorkspaceProfile.XPATH_EXPR_WORKSPACE_QUERY, this.qsid),XPathConstants.NODESET);;;
     451                        // remove
     452                        //childeNode
     453                        if (wsnodelist.getLength() > 0){
     454                                //Element root = workspace_doc.getDocumentElement();
     455                                Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
     456                                node2 = workspace_doc.renameNode(node2, "", "item");
     457                                Node qnode  = (Node)wsnodelist.item(0);
     458                                //root.replaceChild(node2,(Node)wsnodelist.item(0));   
     459                               
     460                                Element parentElement = (Element)qnode.getParentNode();
     461                                        parentElement.insertBefore(node2, qnode);
     462                                        qnode.getParentNode().removeChild(qnode);
     463                                        parentElement.normalize();
     464                        }
    191465                        }
    192466                }
    193         }
    194         //["sru:extratermdata"]["sru:terms"]
    195         }
    196 
    197         public static boolean createFCSRepository(JSONObject jsonitem){
    198                
    199                 //create FCSAction to scan repository data
    200                 FCSAction fcsa = new FCSAction();
    201                 fcsa.setActionkey("fcs");
    202                 fcsa.setParam("operation", "scan");
    203                 fcsa.setParam("scanClause", "fcs.resource");
    204                 fcsa.setParam("repository", jsonitem.getString("name"));
    205                 try {
    206                         fcsa.execute();
    207                         InputStream in  = fcsa.getResultStream();
    208                        
    209                         // convert to json
    210                         MDTransformer transformer = new MDTransformer();
    211                         transformer.configure(Utils.getAppConfig("mdservice"), WorkspaceProfile.class.getClassLoader());
    212                        
    213                         transformer.setSrcFile(new URL(jsonitem.getString("uri")));
    214                         transformer.setParams(MDTransformer.createParamsMap("xml2json"));
    215                         InputStream jsonstream = transformer.transformXML(in);
    216                        
    217                         JSONObject json = JSONObject.fromObject(Utils.streamToString(jsonstream));
    218                         jsonitem.put("fcsresource", json);
    219                         addToFCSMapping(jsonitem, json);
    220                        
    221                 } catch (Exception e) {
    222                         // TODO Auto-generated catch block
    223                         e.printStackTrace();
    224                 }
    225                
    226                
    227                 return true;
    228         }
    229        
    230         // FCS END
    231        
    232         public static Boolean repositoryExists(String repository_name){
    233                
    234                 // static repositories
    235                 net.sf.json.JSONArray json = WorkspaceProfile.getRepositories();
    236                 for(int i=0;i<json.size();i++){
    237                         if (json.getJSONObject(i).getString("name").equals(repository_name)){
    238                                 return true;
    239                         }
    240                 }
    241                
    242                 return false;
    243 
    244         }
    245 
    246         public static String getRepositoryByIndex(int ind){
    247                 String repository_name = null;
    248                
    249                 net.sf.json.JSONArray json = WorkspaceProfile.getRepositories();
    250                 if (json.size() > ind){
    251                         repository_name = json.getJSONObject(ind).getString("name");
    252                 }
    253                 return repository_name;
    254                
    255         }
    256        
    257         public static String getRepositoryPath(String repository_name){
    258         String repository_path = null;
    259        
    260         // static repositories
    261         net.sf.json.JSONArray json = WorkspaceProfile.getRepositories();
    262         for(int i=0;i<json.size();i++){
    263                 if (json.getJSONObject(i).getString("name").equals(repository_name)){
    264                         repository_path =  json.getJSONObject(i).getString("uri");
    265                 }
    266         }
    267        
    268         return repository_path;
     467                if (this.elementtype.equals(WorkspaceProfile.SE_BOOKMARK)){
     468                        // new bookmark
     469                                                Node node = new_doc.getFirstChild();
     470                                                if (this.qid.equals("0")){
     471                                                        newid = createNewId();//"maxbid");       
     472                                                        new_doc.getElementsByTagName("id").item(0).setTextContent(newid);
     473                                                Element root = workspace_doc.getDocumentElement();
     474                                                Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
     475                                                node2 = workspace_doc.renameNode(node2, "", "item");
     476                                           // apend to specific bookmarkset
     477                                                        NodeList wsnodelist = (NodeList) getWorkspaceData(this.getXPathExpressionDummy(WorkspaceProfile.XPATH_EXPR_BOOKMARK_PARENT, this.qsid),XPathConstants.NODESET);
     478                                                        Node anode = wsnodelist.item(0);
     479                                                        if (anode.getTextContent().trim().toLowerCase().equals("null")){
     480                                                                anode.setTextContent("");
     481                                                        }
     482                                                anode.appendChild(node2);
     483                                                }
     484                                               
     485                                                else {
     486                                                        // edit existing query
     487                                                        NodeList wsnodelist = (NodeList) getWorkspaceData(this.getXPathExpressionDummy(WorkspaceProfile.XPATH_EXPR_WORKSPACE_QUERY, this.qsid),XPathConstants.NODESET);
     488                                                // remove
     489                                                //childeNode
     490                                                if (wsnodelist.getLength() > 0){
     491                                                        //Element root = workspace_doc.getDocumentElement();
     492                                                        Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
     493                                                        node2 = workspace_doc.renameNode(node2, "", "item");
     494                                                        Node qnode  = (Node)wsnodelist.item(0);
     495                                                        //root.replaceChild(node2,(Node)wsnodelist.item(0));   
     496                                                       
     497                                                        Element parentElement = (Element)qnode.getParentNode();
     498                                                                parentElement.insertBefore(node2, qnode);
     499                                                                qnode.getParentNode().removeChild(qnode);
     500                                                                parentElement.normalize();
     501                                                }
     502                                                }
     503                                        }
     504                //new queryset
     505                if (this.elementtype.equals(WorkspaceProfile.SE_QUERYSET)){
     506                        // new queryset
     507                                                Node node = new_doc.getFirstChild();
     508                                                if (this.qsid.equals("0")){
     509                                                        newid = createNewId();//"maxqsid");     
     510                                                        new_doc.getElementsByTagName("id").item(0).setTextContent(newid);
     511                                                Element root = workspace_doc.getDocumentElement();
     512                                                Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
     513                                                node2 = workspace_doc.renameNode(node2, "", "item");
     514                                           // apend to specific querysets
     515                                                NodeList wsnodelist = (NodeList) getWorkspaceData(this.getXPathExpressionDummy(WorkspaceProfile.XPATH_EXPR_WORKSPACE, this.qsid),XPathConstants.NODESET);
     516                                                Element welem = (Element)wsnodelist.item(0);
     517                                                        Node anode = welem.getElementsByTagName("Querysets").item(0);
     518                                                        if (anode.getTextContent().trim().toLowerCase().equals("null")){
     519                                                                anode.setTextContent("");
     520                                                        }
     521                                                        anode.appendChild(node2);
     522                                                }
     523                                               
     524                                                else {
     525                                                        // edit existing queryset
     526                                                        NodeList wsnodelist = (NodeList) getWorkspaceData(this.getXPathExpressionDummy(WorkspaceProfile.XPATH_EXPR_QUERYSET, this.qsid),XPathConstants.NODESET);
     527                                                // remove
     528                                                //childeNode
     529                                                if (wsnodelist.getLength() > 0){
     530                                                        //Element root = workspace_doc.getDocumentElement();
     531                                                        Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
     532                                                        node2 = workspace_doc.renameNode(node2, "", "item");
     533                                                        Node qset  = (Node)wsnodelist.item(0);
     534                                                       
     535                                                        Element parentElement = (Element)qset.getParentNode();
     536                                                                parentElement.insertBefore(node2, qset);
     537                                                                qset.getParentNode().removeChild(qset);
     538                                                                parentElement.normalize();
     539                                                }
     540                                                }
     541                                        }
     542               
     543                //new bookmarkset
     544                if (this.elementtype.equals(WorkspaceProfile.SE_BOOKMARKSET)){
     545                        // new queryset
     546                                                Node node = new_doc.getFirstChild();
     547                                                if (this.qsid.equals("0")){
     548                                                        newid = createNewId();//"maxbsid");     
     549                                                        new_doc.getElementsByTagName("id").item(0).setTextContent(newid);
     550                                                Element root = workspace_doc.getDocumentElement();
     551                                                Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
     552                                                node2 = workspace_doc.renameNode(node2, "", "item");
     553                                           // apend to specific querysets
     554                                                NodeList wsnodelist = (NodeList) getWorkspaceData(this.getXPathExpressionDummy(WorkspaceProfile.XPATH_EXPR_WORKSPACE, this.qsid),XPathConstants.NODESET);
     555                                                Element welem = (Element)wsnodelist.item(0);
     556                                                Node anode = welem.getElementsByTagName("Bookmarksets").item(0);
     557                                               if (anode.getTextContent().trim().toLowerCase().equals("null")){
     558                                                                anode.setTextContent("");
     559                                                        }
     560                                                anode.appendChild(node2);
     561                                                }
     562                                               
     563                                                else {
     564                                                        // edit existing bookmarkset
     565                                                        NodeList wsnodelist = (NodeList) getWorkspaceData(this.getXPathExpressionDummy(WorkspaceProfile.XPATH_EXPR_BOOKMARKSET, this.qsid),XPathConstants.NODESET);
     566                                                // remove
     567                                                //childeNode
     568                                                if (wsnodelist.getLength() > 0){
     569                                                        //Element root = workspace_doc.getDocumentElement();
     570                                                        Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
     571                                                        node2 = workspace_doc.renameNode(node2, "", "item");
     572                                                        Node qset  = (Node)wsnodelist.item(0);
     573                                                       
     574                                                        Element parentElement = (Element)qset.getParentNode();
     575                                                                parentElement.insertBefore(node2, qset);
     576                                                                qset.getParentNode().removeChild(qset);
     577                                                                parentElement.normalize();
     578                                                }
     579                                                }
     580                                        }
     581                return newid;
     582        }
     583       
     584        //TODO Utils
     585        public static InputStream createStream(String value) throws TransformerException, TransformerFactoryConfigurationError, ParserConfigurationException, UnsupportedEncodingException{
     586        DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
     587        DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
     588        Document doc = docBuilder.newDocument();
     589
     590        ////////////////////////
     591        //Creating the XML tree
     592        Element root = doc.createElement("root");
     593        root.setTextContent(value);
     594        doc.appendChild(root);
     595       
     596        DOMSource source = new DOMSource(doc);   
     597        StringWriter xmlAsWriter = new StringWriter();   
     598        StreamResult result = new StreamResult(xmlAsWriter);     
     599        TransformerFactory.newInstance().newTransformer().transform(source, result);   
     600         
     601        // write changes   
     602        ByteArrayInputStream is = new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8")); 
     603           
     604
     605       return is;
     606
     607
     608        }
    269609       
    270610}
    271611
    272         public static String getRepositoryType(String repository_name){
    273                 String typestr = "";
    274        
    275        
    276         // static repositories
    277         net.sf.json.JSONArray json = WorkspaceProfile.getRepositories();
    278         for(int i=0;i<json.size();i++){
    279                 if (json.getJSONObject(i).getString("name").equals(repository_name)){
    280                         typestr =  json.getJSONObject(i).getString("type");
    281                 }
    282         }
    283        
    284         return (typestr);
    285 
    286 }
    287        
    288         public static Boolean isSRURepository(String repository_name){
    289         //Boolean issru = false;
    290         String typestr = getRepositoryType(repository_name);
    291        
    292         return (typestr.equals("sru"));
    293        
    294 }
    295 
    296        
    297         public static String getRepositoryProperty(String repo_id, String propname){
    298                 String typestr = "";
    299        
    300        
    301         // static repositories
    302         net.sf.json.JSONArray json = WorkspaceProfile.getRepositories();
    303         for(int i=0;i<json.size();i++){
    304                 if (json.getJSONObject(i).getString("id").equals(repo_id)){
    305                         typestr =  json.getJSONObject(i).getString(propname);
    306                 }
    307         }
    308        
    309         return (typestr);
    310 }
    311 
    312         public static JSONArray createRepositories() throws IOException, InterruptedException, TransformerException, NoStylesheetException{
    313                 String path = Utils.getConfig("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;
    314                 File file=new File(path);
    315                 InputStream in  = new BufferedInputStream( new FileInputStream(path));;
    316                
    317                 MDTransformer transformer = new MDTransformer();
    318                 //transformer.configure(Utils.getAppConfig(WorkspaceProfile.class.getProtectionDomain().getCodeSource().getLocation().getPath()), WorkspaceProfile.class.getClassLoader());
    319                 transformer.configure(Utils.getAppConfig("mdservice"), WorkspaceProfile.class.getClassLoader());
    320                
    321                 transformer.setSrcFile(file.toURI().toURL());
    322                 transformer.setParams(MDTransformer.createParamsMap("xml2json"));
    323                 InputStream jsonstream = transformer.transformXML(in);
    324                
    325                 JSONObject json = JSONObject.fromObject(Utils.streamToString(jsonstream));
    326                 JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles");
    327                 JSONArray array = null;
    328                 for (int i = 0; i < wparray.size(); ++i) {     
    329                         JSONObject wp = wparray.getJSONObject(i);
    330                         if (wp.get("Repositories") != null){
    331                                 array = wp.getJSONArray("Repositories");
    332                                 break;
    333                         }
    334                 }       
    335                
    336                 // repository as static variable
    337                 return array;
    338        
    339                 // repository as session attribute
    340                 /*
    341                 HttpSession session = getServletRequest().getSession();
    342                 //JSONArray param = (JSONArray) session.getAttribute("repositories");
    343                 JSONArray param = new JSONArray();
    344         param.add(array);
    345         session.setAttribute("repositories", param);
    346                  */
    347         }
    348        
    349         public static JSONObject createOptions() throws IOException, InterruptedException, TransformerException, NoStylesheetException{
    350                 String path = Utils.getConfig("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;
    351                 File file=new File(path);
    352                 InputStream in  = new BufferedInputStream( new FileInputStream(path));;
    353                
    354                 MDTransformer transformer = new MDTransformer();
    355                 transformer.configure(Utils.getAppConfig("mdservice"), WorkspaceProfile.class.getClassLoader());
    356                 transformer.setSrcFile(file.toURI().toURL());
    357                 transformer.setParams(MDTransformer.createParamsMap("xml2json"));
    358                 InputStream jsonstream = transformer.transformXML(in);
    359                
    360                 JSONObject json = JSONObject.fromObject(Utils.streamToString(jsonstream));
    361                 JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles");
    362                 JSONObject obj = null;
    363                 for (int i = 0; i < wparray.size(); ++i) {     
    364                         JSONObject wp = wparray.getJSONObject(i);
    365                         if (wp.get("Options") != null){
    366                                 obj = wp.getJSONObject("Options");
    367                                 break;
    368                         }
    369                 }       
    370                
    371                 // options as static variable
    372                 return obj;
    373        
    374         }
    375        
    376         public static String getOption(String opt_key){
    377                 String option_val = null;
    378                
    379                 net.sf.json.JSONObject json = getOptions();
    380                 option_val = json.getString(opt_key);
    381 
    382                 return option_val;
    383                
    384         }
    385        
    386         public static String getTermsetProperty(String termset_id, String propname){
    387                 String typestr = "";
    388        
    389        
    390         // static repositories
    391         net.sf.json.JSONArray json = WorkspaceProfile.getTermsets();
    392         for(int i=0;i<json.size();i++){
    393                 if (json.getJSONObject(i).getString("id").equals(termset_id)){
    394                         typestr =  json.getJSONObject(i).getString(propname);
    395                 }
    396         }
    397        
    398         return (typestr);
    399 
    400 }
    401        
    402         public static JSONArray createTermsets() throws IOException, InterruptedException, TransformerException, NoStylesheetException{
    403                 String path = Utils.getConfig("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;
    404                 File file=new File(path);
    405                 InputStream in  = new BufferedInputStream( new FileInputStream(path));;
    406                
    407                 MDTransformer transformer = new MDTransformer();
    408                 transformer.configure(Utils.getAppConfig("mdservice"), WorkspaceProfile.class.getClassLoader());
    409                 transformer.setSrcFile(file.toURI().toURL());
    410                 transformer.setParams(MDTransformer.createParamsMap("xml2json"));
    411                 InputStream jsonstream = transformer.transformXML(in);
    412                
    413                 JSONObject json = JSONObject.fromObject(Utils.streamToString(jsonstream));
    414                 JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles");
    415                 JSONArray array = null;
    416                 for (int i = 0; i < wparray.size(); ++i) {     
    417                         JSONObject wp = wparray.getJSONObject(i);
    418                         if (wp.get("Termsets") != null){
    419                                 array = wp.getJSONArray("Termsets");
    420                                 break;
    421                         }
    422                 }       
    423                
    424                 // termset as static variable
    425                 return array;
    426         }
    427        
    428        
    429 }
    430 
    431 
     612
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/FCSProxy.java

    r1807 r1832  
    1212import eu.clarin.cmdi.mdservice.model.Diagnostics;
    1313import eu.clarin.cmdi.mdservice.model.Query;
     14import eu.clarin.cmdi.mdservice.model.Repositories;
    1415import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    1516
     
    5354        }
    5455       
    55         public String getRepositoryURI() {             
    56                 String uri = "http://localhost:8080/MDService2/repository?format=scanxml";//WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository());             
    57                 return uri;
    58         }
    59 
    6056       
    6157        /**
     
    6561         */     
    6662        public URL getScanRepositoryURL() throws MalformedURLException {               
    67                 URL url = new URL(getRepositoryURI() + "?format=sruscan" );             
     63                URL url = new URL(Repositories.getRepositories().getRepositoryPath(getSourceAction().getRepository()) + "?operation=scan&scanClause=fcs.resource" );           
    6864                return url;
    6965        }
     
    7268         * or in getSOurceStream??
    7369         */     
    74         /*
     70       
    7571        @Override
    7672        public URL getTargetRequest() throws IOException, CQLParseException {
    7773               
    7874                URL targetURL;
    79                 if (getSourceAction().getParam("operation").equals("scan") && getSourceAction().getParam("x-context").equals("")) {// && getSourceAction().getParam("scanClause").equals("fcs.resource")){
     75                if (getSourceAction().getParam("operation").equals("scan") && !getSourceAction().getParam("x-context").equals("")) {// && getSourceAction().getParam("scanClause").equals("fcs.resource")){
    8076                        targetURL = getScanRepositoryURL();
    8177                } else {
     
    8783               
    8884        }
    89         */
     85       
    9086}
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/MDRepoProxy.java

    r1800 r1832  
    1515import eu.clarin.cmdi.mdservice.model.Diagnostic;
    1616import eu.clarin.cmdi.mdservice.model.Query;
     17import eu.clarin.cmdi.mdservice.model.Repositories;
    1718import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    1819
     
    5354        @Override       
    5455        public String getBaseURI() {           
    55                 String uri = WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository());             
     56                String uri = Repositories.getRepositories().getRepositoryPath(getSourceAction().getRepository());               
    5657                return uri;
    5758        }
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/Pz2Proxy.java

    r1627 r1832  
    3636import eu.clarin.cmdi.mdservice.internal.CQLParseException;
    3737import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
     38import eu.clarin.cmdi.mdservice.model.Options;
    3839import eu.clarin.cmdi.mdservice.model.Query;
     40import eu.clarin.cmdi.mdservice.model.Repositories;
    3941import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    4042
     
    125127        @Override
    126128        public String getBaseURI() {           
    127                 String uri = WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository());             
     129                String uri = Repositories.getRepositories().getRepositoryPath(getSourceAction().getRepository());               
    128130                return uri;
    129131        }
     
    235237                long startMillis = System.currentTimeMillis();
    236238                long timeout = 0;
    237                 if (WorkspaceProfile.getOption("pazpartimeout") == null){
     239                if (Options.getOptions().getOption("pazpartimeout") == null){
    238240                        timeout = 1000;
    239241                } else {
    240                         timeout = Integer.parseInt(WorkspaceProfile.getOption("pazpartimeout"));
     242                        timeout = Integer.parseInt(Options.getOptions().getOption("pazpartimeout"));
    241243                }
    242244                while (Integer.parseInt(activeclients) > 0){
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/RepoProxy.java

    r1663 r1832  
    1616import eu.clarin.cmdi.mdservice.model.Diagnostics;
    1717import eu.clarin.cmdi.mdservice.model.Query;
     18import eu.clarin.cmdi.mdservice.model.Repositories;
    1819import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    1920
     
    5253        }
    5354       
    54 /*      public RepoAction getSourceAction() {
    55                 return source_action;
    56 }*/
    57        
    5855        @Override
    5956        public void setSourceAction(GenericAction action) {             
     
    8683                //super.checkParams();
    8784                // check and set defaults
    88                 if (WorkspaceProfile.getRepositoryPath(getParam("repository")) == null) {
     85                if (Repositories.getRepositories().getRepositoryPath(getParam("repository")) == null) {
    8986                        getSourceAction().getDiagnostics().Add(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "repository");
    9087                }
     
    111108               
    112109        public String getBaseURI() {           
    113                 String uri = WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository());             
     110                String uri = Repositories.getRepositories().getRepositoryPath(getSourceAction().getRepository());               
    114111                return uri;
    115112        }
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/SRUProxy.java

    r1800 r1832  
    99import eu.clarin.cmdi.mdservice.model.Diagnostic;
    1010import eu.clarin.cmdi.mdservice.model.Query;
     11import eu.clarin.cmdi.mdservice.model.Repositories;
    1112import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    1213
     
    5455        @Override
    5556        public String getBaseURI() {           
    56                 log.debug("SRU-repositorypath:" + WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository()));
    57                 String uri = WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository());//Utils.getConfig).getProperty(getProxyKey() + ".uri");             
     57                log.debug("SRU-repositorypath:" + Repositories.getRepositories().getRepositoryPath(getSourceAction().getRepository()));
     58                String uri = Repositories.getRepositories().getRepositoryPath(getSourceAction().getRepository());//Utils.getConfig).getProperty(getProxyKey() + ".uri");               
    5859                return uri;
    5960        }
  • MDService2/branches/MDService_simple3/src/mdservice.properties

    r1810 r1832  
    3030xsl.sru2htmltable = sru2view.xsl
    3131xsl.fcsscan2htmlpage = fcs/scan2view.xsl
     32//xsl.fcsscan2xml = fcs/scan2view.xsl
    3233xsl.fcsexplain2htmlpage = fcs/explain2view.xsl
    3334xsl.fcssearchRetrieve2htmlpage = fcs/result2view_v1.xsl
  • MDService2/branches/MDService_simple3/src/struts.xml

    r1808 r1832  
    231231-->
    232232<!-- SPECIAL ACTIONS - Workspace(save), VirtualCollection(publish), Admin(cache) -->
    233                 <action name="workspaceprofile/*/*" class="eu.clarin.cmdi.mdservice.action.WorkspaceAction" method="execute">
     233                <action name="workspaceprofile/*" class="eu.clarin.cmdi.mdservice.action.WorkspaceAction" method="execute">
    234234                           <!-- <param name="format">JSON</param> -->
    235                            <param name="format">{1}</param>
    236                            <param name="type">{2}</param>
     235                           <param name="actionkey">workspaceprofile</param>
     236                           <!--  <param name="format">{1}</param>-->
     237                           <param name="type">{1}</param>
    237238                           <!-- + workspace, queryset or as params
    238239                           <param name="workspace">{2}</param>
  • MDService2/branches/MDService_simple3/src/xsl/xml2sruscan.xsl

    r1814 r1832  
    2727<sru:displayTerm><xsl:value-of select="label"></xsl:value-of></sru:displayTerm>
    2828<sru:extraTermData>
    29 <xsl:apply-templates select="./extraitems" />
     29<xsl:apply-templates select="./sru:extraTermData" />
    3030</sru:extraTermData>
    3131</sru:term>
    3232</xsl:template>
    3333
    34 <xsl:template match="extraitems" >
    35 <sru:terms>
    36 <xsl:apply-templates select="./item" mode="extra"/>
    37 </sru:terms>
     34<xsl:template match="sru:extraTermData" >
     35
     36<xsl:copy-of select="./sru:terms"/>
    3837</xsl:template>
    39 
     38<!--
    4039<xsl:template match="item" mode="extra" >
    4140<sru:term>
     
    4645</xsl:template>
    4746
     47 -->
     48
    4849</xsl:stylesheet>
Note: See TracChangeset for help on using the changeset viewer.