Changeset 1350 for MDService2/trunk/MDService2
- Timestamp:
- 05/22/11 21:55:04 (13 years ago)
- Location:
- MDService2/trunk/MDService2
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService2/trunk/MDService2/WebContent/scripts/mdservice_model.js
r1310 r1350 11 11 //var workspace; 12 12 13 // json for user and server data 13 14 function Workspace(){ 14 15 }; 16 Workspace.save = function(type, query, id, iq){ 15 user_json = undefined; 16 server_json = undefined; 17 }; 18 Workspace.prototype.addquery = function(jsonquery, qsid){ 19 var qsjson = this.user_json["WorkspaceProfile"]["Querysets"][qsid]; 20 var queries = qsjson["Queries"]; //this.user_json["WorkspaceProfile"]["Querysets"][qsid]["Queries"]; 21 var iq = 0; 22 23 if (queries == "null"){ 24 //this.user_json["WorkspaceProfile"]["Querysets"][qsid]["Queries"] = [{}]; 25 qsjson["Queries"] = [{}]; 26 } else { 27 iq = queries.length; 28 } 29 //this.user_json["WorkspaceProfile"]["Querysets"][qsid]["Queries"][iq] = jsonq; 30 qsjson["Queries"][iq] = jsonquery; 31 }; 32 Workspace.prototype.addqueryset = function(name){ 33 34 var id = $('#qts_select option').size(); 35 var dt = new Date(); 36 var str_time = dateFormat(dt);//dt.toString("yyyy-MM-dd HH:mm:ss"); 37 38 if (id == 0){ 39 this.user_json["WorkspaceProfile"]["Querysets"] = [{}]; 40 } 41 42 this.user_json["WorkspaceProfile"]["Querysets"][id] = {"name":name,"created":str_time , "Queries" : "null"}; 43 44 }; 45 Workspace.prototype.removequeryset = function(qsid){ 46 //var ind; 47 //$.each(this.user_json["WorkspaceProfile"]["Querysets"], function(index,jdata){ 48 // if (jdata == json){ 49 // ind = index; 50 // } 51 //}); 52 var size = this.user_json["WorkspaceProfile"].Querysets.length; 53 54 for (var i=qsid;i<size-1;i++){ 55 this.user_json["WorkspaceProfile"].Querysets[i] = this.user_json["WorkspaceProfile"].Querysets[i+1]; 56 } 57 58 delete this.user_json["WorkspaceProfile"].Querysets[size-1]; 59 this.user_json["WorkspaceProfile"]["Querysets"].length = size-1; 60 // set null string , if 0 querysets 61 if (size == 1) { 62 this.user_json["WorkspaceProfile"]["Querysets"] = "null"; 63 } 64 }; 65 Workspace.prototype.getQuerysets = function(type){ 66 var json; 67 if (type == "user"){ 68 return this.user_json["WorkspaceProfile"]["Querysets"]; 69 } 70 return this.server_json["WorkspaceProfile"]["Querysets"]; 71 }; 72 73 Workspace.prototype.getCustomTermsets = function(){ 74 var json; 75 json = this.user_json["WorkspaceProfile"]["CustomTermsets"]; 76 return json; 77 }; 78 Workspace.prototype.save = function(type){ 79 var JSONText; 80 81 JSONText = JSON.stringify(this.user_json["WorkspaceProfile"]); 82 $.post("/MDService2/workspaceprofilesave/" + type + "/",{"data":JSONText}, function(data) { 83 }); 84 85 }; 86 Workspace.prototype.savequery = function(json, querysetname){ 87 var JSONText; 88 var type = "user"; 89 var qdata = "/" + querysetname; 90 JSONText = JSON.stringify(json); 91 92 $.post("/MDService2/workspaceprofilesave/" + type + qdata,{"data":JSONText}, function(data) { 93 if (json.id == 0){ 94 json.id = $(data).text(); 95 appendQueryUI(json,querysetname, $('#userqueries')); 96 } else { 97 changeQueryUI(json,querysetname, $('#userqueries')); 98 } 99 }); 100 }; 101 /*Workspace.save = function(type, query, id, iq){ 17 102 var JSONText; 18 103 var qdata = "/"; 19 /*20 if (type == "ADMIN"){21 JSONText = JSON.stringify(json_admin["WorkspaceProfile"]);22 } else {23 JSONText = JSON.stringify(jsonw["WorkspaceProfile"]);24 }25 */26 //var JSONText = JSON.stringify({"aa.a":"r"});27 //notifyUser(JSONText,'debug');28 104 29 105 JSONText = JSON.stringify(jsonw["WorkspaceProfile"]); … … 32 108 } 33 109 $.post("/MDService2/workspaceprofilesave/" + type + qdata,{"data":JSONText}, function(data) { 34 query.id = $(data).text(); 35 jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq]["id"] = query.id; 36 appendQueryUI(jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq],iq, $('#userqueries')); 37 // alert("success"); 110 if (query != undefined){ 111 if (query.id == 0){ 112 query.id = $(data).text(); 113 jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq]["id"] = query.id; 114 appendQueryUI(jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq],iq, $('#userqueries')); 115 } 116 } 38 117 }); 39 //.success(function() { alert("second success"); }) 40 //.error(function(e) { alert("error"); }) 41 //.complete(function() { alert("complete"); }); 42 43 44 }; 45 /* 46 Workspace.newQueryID = function(){ 47 var new_id; 48 49 loadAdminFile(); 50 json_admin["Admin"]["maxqid"] = parseInt(json_admin["Admin"]["maxqid"]) + 1; 51 new_id = json_admin["Admin"]["maxqid"]; 52 Workspace.save("ADMIN"); 53 return new_id; 118 54 119 }; 55 120 */ … … 72 137 this.listid = ""; 73 138 this.container = {}; 139 this.bookmark = 0; 74 140 // page 75 141 this.startItem = 1; … … 83 149 this.format = 'htmltable'; 84 150 this.columns_widget = null; 151 152 //vcr 153 this.vcrid = 0; 85 154 }; 86 155 … … 141 210 } 142 211 this.id = json.id; 143 };144 212 this.vcrid = json.vcrid; 213 }; 145 214 Query.prototype.save = function(){ 146 215 //queryset id 147 var id = parseInt($("#qts_select option:selected").val()); 216 var qsid = parseInt($("#qts_select option:selected").val()); 217 //var qsname = $("#qts_select option:selected").text(); 218 //var qsjson = $("#qts_select option:selected").val(); 219 var qsjson = workspace.getQuerysets("user")[qsid]; 220 var jsonq = this.toJSON(); 221 if (this.id == 0){ 222 workspace.addquery(jsonq, qsid);//qsjson); 223 workspace.savequery(jsonq, qsjson["name"]); 224 } else { 225 workspace.savequery(jsonq); 226 } 227 }; 228 /* 229 Query.prototype.save = function(){ 230 //queryset id 231 var qsid = parseInt($("#qts_select option:selected").val()); 148 232 var iq = 0; 149 var queries = jsonw["WorkspaceProfile"]["Querysets"][ id]["Queries"];233 var queries = jsonw["WorkspaceProfile"]["Querysets"][qsid]["Queries"]; 150 234 151 235 //var iq = $('#userqueries').children().size(); 152 if (queries == "null"){ 153 jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"] = [{}]; 236 var jsonq = this.toJSON(); 237 if (this.id == 0){ 238 if (queries == "null"){ 239 jsonw["WorkspaceProfile"]["Querysets"][qsid]["Queries"] = [{}]; 240 } else { 241 iq = queries.length; 242 } 243 jsonw["WorkspaceProfile"]["Querysets"][qsid]["Queries"][iq] = jsonq; 244 Workspace.save("USER", this, qsid, iq); 154 245 } else { 155 iq = queries.length; 156 } 157 // create queryID 158 this.id = 0;//Workspace.newQueryID();//id + "_" + iq; 159 var jsonq = this.toJSON(); 160 jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq] = jsonq; 161 Workspace.save("USER", this, id, iq); 246 $.each(jsonw["WorkspaceProfile"]["Querysets"][qsid]["Queries"], function(index,value){ 247 if (value.id == jsonq.id){ 248 iq = index; 249 } 250 }); 251 jsonw["WorkspaceProfile"]["Querysets"][qsid]["Queries"][iq] = jsonq; 252 Workspace.save("USER", this, qsid, iq); 253 } 254 255 162 256 //appendQueryUI(jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq],iq, $('#userqueries')); 163 257 164 258 }; 165 259 */ 166 260 167 261 Query.prototype.getcolumnstext = function (){ … … 238 332 239 333 Query.prototype.publish = function() { 240 $.post("/MDService2/virtualcollection/USER/" + this.id,""); 334 //$.data("query",this); 335 var q = this; 336 if (q.vcrid == 0){ 337 $.get("/MDService2/virtualcollection/USER/" + this.id,"", function(data){ 338 var id = parseInt($(data).children().children('virtualcollectionid').text()); 339 q.vcrid = id; 340 q.save(); 341 }); 342 } 241 343 }; 242 344 … … 266 368 //columns 267 369 var json_cols; 268 var col ls = this.columns;269 if (col ls == "") {370 var cols = this.columns; 371 if (cols == "") { 270 372 //json_cols = {}; 271 373 json_cols = "null"; … … 299 401 "maximumItems" : this.maximumItems, 300 402 "options" : json_options, 301 "bookmark" : "0", 302 "time" : str_time}; 303 304 jsonq.name = Query.fullformatstring(jsonq); 403 "bookmark" : this.bookmark, 404 "time" : str_time, 405 "vcrid": this.vcrid}; 406 407 if (this.bookmark == "1") { 408 qstring = Url.decode(qstring); 409 var s = qstring.split(':'); 410 jsonq.name = s[s.length - 2] + ":" + s[s.length - 1]; 411 } else { 412 jsonq.name = Query.fullformatstring(jsonq); 413 } 305 414 306 415 return jsonq;//JSON.stringify(jsonq); -
MDService2/trunk/MDService2/WebContent/scripts/mdservice_ui.js
r1273 r1350 30 30 // get url parameters 31 31 url_params = getUrlVars(); 32 workspace = new Workspace(); 32 33 // create searchclauses 33 34 //searchclauseset.addsearchclause(new SearchClause("","",""),"",0,0); … … 363 364 */ 364 365 $('#querylist .cmd_save').live('click', function(event) { 366 // bookmark 367 if ($(this).parents('.result').length > 0){ 368 qstring = $(this).parent().find("a").attr('href'); 369 qstring = qstring.substring(18,qstring.length); 370 371 var q = new Query([],"",qstring,""); 372 q.bookmark = 1; 373 q.save(); 374 375 } 376 }); 377 /* 378 $('#querylist .cmd_save').live('click', function(event) { 365 379 366 380 var qid = ""; … … 420 434 //$("#qs_select").append(new Option(Query.simplequerystring(qstring),iq)); 421 435 }); 436 */ 422 437 /* 423 438 $('#querylist .cmd-xml').live('click', function(event) { … … 504 519 var id = $("#qts_select option:selected").val(); 505 520 //notifyUser($('#qts_input').val() + $('#qts_input').text(),'debug'); 506 jsonw["WorkspaceProfile"]["Querysets"][id]["name"] = $('#qts_input').val(); 507 521 workspace.user_json["WorkspaceProfile"]["Querysets"][id]["name"] = $('#qts_input').val(); 522 workspace.save("USER"); 523 508 524 $("#qts_select option:selected").text( $('#qts_input').val()); 509 //saveWorkspace("USER"); 510 Workspace.save("USER"); 525 511 526 }); 512 527 $('#qts_add').click(function(){ 513 528 var new_name = "new_queryset"; 514 529 530 workspace.addqueryset(new_name); 531 workspace.save("USER"); 532 //todo 515 533 var id = $('#qts_select option').size(); 516 var dt = new Date();517 var str_time = dateFormat(dt);//dt.toString("yyyy-MM-dd HH:mm:ss");518 519 if (id == 0){520 jsonw["WorkspaceProfile"]["Querysets"] = [{}];521 }522 523 jsonw["WorkspaceProfile"]["Querysets"][id] = {"name":new_name,"created":str_time , "Queries" : "null"};524 525 //saveWorkspace("USER");526 Workspace.save("USER");527 //todo528 529 //loadWorkspace(jsonw["WorkspaceProfile"]["Querysets"]);530 534 $("#qts_select").append(new Option(new_name, id)); 531 535 $("#qts_select").find('option').attr("selected","false"); … … 537 541 538 542 //if (count > 1){ 543 /* 539 544 var id = parseInt($("#qts_select option:selected").val()); 540 545 var size = jsonw["WorkspaceProfile"].Querysets.length; … … 556 561 557 562 //} 563 */ 564 var qsid = parseInt($("#qts_select option:selected").val()); 565 //var json = $("#qts_select option:selected").val(); 566 workspace.removequeryset(qsid); 567 workspace.save("USER"); 568 //update 569 //loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user"); 570 loadQuerysets("user"); 558 571 }); 559 572 … … 663 676 $('#serverqueries .cmd_load').live('click',function(event){ 664 677 665 var id = parseInt( $("#serverqts_select option:selected").val()); 666 var str = $(this).parent().find('a').attr("href"); 667 var iq = parseInt(str.substring(9)); 668 var json = jQuery.parseJSON($("#serverqs").attr("data")); 669 var q = json["WorkspaceProfile"]["Querysets"][id]["Queries"][iq]; 670 678 //var id = parseInt( $("#serverqts_select option:selected").val()); 679 //var str = $(this).parent().find('a').attr("href"); 680 //var iq = parseInt(str.substring(9)); 681 //var json = jQuery.parseJSON($("#serverqs").attr("data")); 682 //var q = json["WorkspaceProfile"]["Querysets"][id]["Queries"][iq]; 683 684 var q = $(this).closest('.cmds-elem-plus').data("queryjson"); 671 685 loadQuery(q); 672 686 }); 673 687 $('#userqueries .cmd_load').live('click',function(event){ 674 688 675 var id = parseInt( $("#qts_select option:selected").val());676 var str = $(this).parent().find('a').attr("href");677 var iq = parseInt(str.substring(7));678 var q = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq];679 689 //var id = parseInt( $("#qts_select option:selected").val()); 690 //var str = $(this).parent().find('a').attr("href"); 691 //var iq = parseInt(str.substring(7)); 692 //var q = workspace.getQuerysets("user")[id]["Queries"][iq]; 693 var q = $(this).closest('.cmds-elem-plus').data("queryjson"); 680 694 loadQuery(q); 681 695 }); … … 685 699 var str = $(this).parent().find('a').attr("href"); 686 700 var iq = parseInt(str.substring(7)); 687 var size = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"].length;701 var size = workspace.user_json["WorkspaceProfile"]["Querysets"][id]["Queries"].length; 688 702 689 703 for (var i=iq;i<size-1;i++){ 690 jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][i] = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][i+1];691 } 692 693 delete jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][size-1];694 jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"].length = size-1;704 workspace.user_json["WorkspaceProfile"]["Querysets"][id]["Queries"][i] = workspace.user_json["WorkspaceProfile"]["Querysets"][id]["Queries"][i+1]; 705 } 706 707 delete workspace.user_json["WorkspaceProfile"]["Querysets"][id]["Queries"][size-1]; 708 workspace.user_json["WorkspaceProfile"]["Querysets"][id]["Queries"].length = size-1; 695 709 696 710 if (size == 1){ 697 jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"] = "null";711 workspace.user_json["WorkspaceProfile"]["Querysets"][id]["Queries"] = "null"; 698 712 } 699 713 700 714 //saveWorkspace("USER"); 701 Workspace.save("USER");702 loadQuerysets( jsonw["WorkspaceProfile"]["Querysets"],"user");715 workspace.save("USER"); 716 loadQuerysets("user"); 703 717 //$("#qs_select option").remove(); 704 718 //$("#qs_select option").first().attr("selected","true"); -
MDService2/trunk/MDService2/WebContent/scripts/mdservice_ui_detail.js
r1274 r1350 114 114 selectionlistset.add(selectionlist); 115 115 //selectionlist.listwidget.query = query; 116 selectionlist.load( jsonw["WorkspaceProfile"]["CustomTermsets"]);116 selectionlist.load(workspace.getCustomTermsets());//jsonw["WorkspaceProfile"]["CustomTermsets"]); 117 117 $(this.content).find('.cmd_reload').data('selectionlist',selectionlist); 118 118 if (query.columns == ""){ -
MDService2/trunk/MDService2/WebContent/scripts/mdservice_ui_load.js
r1273 r1350 45 45 function loadWorkspaceProfiles(){ 46 46 //empty json 47 jsonw= {'WorkspaceProfile':{'CustomTermsets':'null','Termsets':'null','Repositories':'null','Querysets':'null','created':'null','lastchanged':'null','profilename':'null'}};47 workspace.user_json = {'WorkspaceProfile':{'CustomTermsets':'null','Termsets':'null','Repositories':'null','Querysets':'null','created':'null','lastchanged':'null','profilename':'null'}}; 48 48 $('#qts_input').val(""); 49 49 … … 51 51 jQuery.getJSON("/MDService2/workspaceprofile/user",function(data){ 52 52 notifyUser(data['WorkspaceProfile'],'debug'); 53 jsonw= preprocessJSON(data);53 workspace.user_json = preprocessJSON(data); 54 54 55 55 jQuery.getJSON("/MDService2/workspaceprofile/server",function(data){ 56 56 notifyUser(data['WorkspaceProfile'],'debug'); 57 57 var json = preprocessJSON(data); 58 workspace.server_json = json; 58 59 $("#serverqs").attr("data",JSON.stringify(json)); 59 loadQuerysets(json["WorkspaceProfile"]["Querysets"],"server"); 60 //loadQuerysets(json["WorkspaceProfile"]["Querysets"],"server"); 61 loadQuerysets("server"); 60 62 loadRepositories(json["WorkspaceProfile"]["Repositories"]); 61 63 loadCollections(true); … … 67 69 }); 68 70 69 loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user"); 71 //loadQuerysets(workspace.user_json["WorkspaceProfile"]["Querysets"],"user"); 72 loadQuerysets("user"); 70 73 //loadTermsets(jsonw["WorkspaceProfile"]["CustomTermsets"]); 71 74 createTooltip(this); … … 293 296 query.load(json); 294 297 $(qs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('query',query); 298 $(qs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('queryjson',json); 299 $(qs).find('.input-name').data('queryjson',json); 295 300 $(qs).find('.detail').css({'z-index' : '1000'}); 296 301 … … 301 306 }; 302 307 if (ev.which === 13) { 308 $(this).data("queryjson").name = $(this).val(); 309 Workspace.save("user"); 310 //var query = new Query(); 311 //query.load($(this).data("queryjson")); 312 //query.save(); 313 /* 303 314 var id = parseInt( $("#qts_select option:selected").val()); 304 315 $(this).parent().parent().parent().find('a').text($(this).val()); … … 309 320 //saveWorkspace("USER"); 310 321 Workspace.save("USER"); 322 */ 311 323 evStop(); 312 324 } … … 326 338 327 339 } 328 function loadQuerysets(json, type) { 329 340 function loadQuerysets(type) { 341 342 var json = workspace.getQuerysets(type); 330 343 var $select; 331 344 if (type == "user") { … … 350 363 var id = parseInt($select.find("option:selected").val()); 351 364 var jsonq = json[id]; 365 //var jsonq = $select.find("option:selected").val(); 352 366 353 367 if (type == "user") { … … 365 379 var id = parseInt($select.find("option:selected").val()); 366 380 var jsonq = json[id]; 367 381 //var jsonq = $select.find("option:selected").val(); 382 368 383 if (type == "user") { 369 384 $('#qts_input').val(jsonq["name"]); -
MDService2/trunk/MDService2/WebContent/scripts/mdservice_ui_settings.js
r1273 r1350 12 12 13 13 //VARIABLES 14 var jsonw, json_admin; 14 //var jsonw, json_admin; 15 var workspace; 16 var json_admin; 15 17 var url_params; 16 18 var local_collections = false; -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/WorkspaceAction.java
r1310 r1350 88 88 public static String USER = "user"; 89 89 public static String SERVER = "server"; 90 91 // save element type 92 public static String SE_WORKSPACE = "workspace"; 93 public static String SE_QUERY = "query"; 94 90 95 // administration query identification 91 96 public static String ADMIN = "admin"; … … 103 108 //private String actionkey; 104 109 private String data; 105 private String type; 110 private String type; //workspacetype 111 private String elementtype; 106 112 private String qid; 113 private String qsid; 107 114 //private String format; 108 115 //private String userMsg; … … 138 145 } 139 146 147 public String getEelemnttype(){ 148 return elementtype; 149 } 150 151 public void setElementtype(String elementtype) { 152 this.elementtype = elementtype; 153 } 154 140 155 public String getType() { 141 156 return type; … … 149 164 return qid; 150 165 } 151 166 152 167 public void setQid(String qid) { 153 168 this.qid = qid; 154 169 } 155 170 156 public WorkspaceAction () { 171 public void setQsid(String qsid) { 172 this.qsid = qsid; 173 } 174 175 public String getQsid() { 176 return qsid; 177 } 178 179 public WorkspaceAction () { 180 this.elementtype = WorkspaceAction.SE_WORKSPACE; 157 181 workspacefilename = Admin.getConfig().getProperty("workspaceprofile.path") + Admin.getConfig().getProperty("workspace.file"); 158 182 if (workspace_doc == null){ … … 423 447 XPathExpression expr; 424 448 String xpath_expr = ""; 425 xpath_expr = "//WorkspaceProfile/Querysets/item/Queries/item/id[.='" + from_id + "']"; 449 //xpath_expr = "//WorkspaceProfile/Querysets/item/Queries/item/id[.='" + from_id + "']"; 450 xpath_expr = "//item/id[.='" + from_id + "']"; 426 451 expr = xpath.compile(xpath_expr); 427 452 Object result = null; … … 474 499 475 500 } 501 public String getXMLRootName(){ 502 String rootname = "WorkspaceProfile"; 503 if (this.elementtype.equals(WorkspaceAction.SE_QUERY)){ 504 rootname = "Query"; 505 } 506 return rootname; 507 } 508 public String DocumentReplaceNewElement(Document new_doc) throws XPathExpressionException{ 509 String newid = ""; 510 if (this.elementtype.equals(WorkspaceAction.SE_WORKSPACE)){ 511 NodeList wsnodelist = (NodeList) getWorkspace(); 512 // remove 513 //childeNode 514 if (wsnodelist.getLength() > 0){ 515 ((Node)wsnodelist.item(0)).getParentNode().removeChild(wsnodelist.item(0)); 516 } 517 //String qidstring = ""; 518 //if (qid.equals("0")) { 519 // newid = createNewQid(); 520 // changeQueryId(new_doc,qid,newid); 521 //} 522 523 Node node = new_doc.getFirstChild(); 524 Node node2 = workspace_doc.adoptNode(node.cloneNode(true)); 525 ((Element)node2).setAttribute("user", getUserName()); 526 workspace_doc.getElementsByTagName("WorkspaceProfiles").item(0).appendChild(node2); 527 } 528 if (this.elementtype.equals(WorkspaceAction.SE_QUERY)){ 529 // new query 530 Node node = new_doc.getFirstChild(); 531 if (this.qid.equals("0")){ 532 newid = createNewQid(); 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 queryset 538 NodeList wsnodelist = (NodeList) getQueryset(); 539 wsnodelist.item(0).appendChild(node2); 540 } 541 542 else { 543 // edit existing query 544 NodeList wsnodelist = (NodeList) getQuery(); 545 // remove 546 //childeNode 547 if (wsnodelist.getLength() > 0){ 548 //Element root = workspace_doc.getDocumentElement(); 549 Node node2 = workspace_doc.adoptNode(node.cloneNode(true)); 550 node2 = workspace_doc.renameNode(node2, "", "item"); 551 Node qnode = (Node)wsnodelist.item(0); 552 //root.replaceChild(node2,(Node)wsnodelist.item(0)); 553 554 Element parentElement = (Element)qnode.getParentNode(); 555 parentElement.insertBefore(node2, qnode); 556 qnode.getParentNode().removeChild(qnode); 557 parentElement.normalize(); 558 } 559 } 560 } 561 return newid; 562 } 563 564 //todo 565 public void parseDataInit(JSONObject json){ 566 // workspaceelement 567 if (json.containsKey("Querysets")) { 568 this.setQid("0"); 569 this.setElementtype(WorkspaceAction.SE_WORKSPACE); 570 } else { 571 // Queryelement 572 this.setElementtype(WorkspaceAction.SE_QUERY); 573 this.setQid(json.getString("id")); 574 //this.// 575 } 576 577 } 476 578 public String save() throws ParserConfigurationException, SAXException, IOException, DOMException, XPathExpressionException, TransformerException, TransformerFactoryConfigurationError{ 477 579 … … 480 582 XMLSerializer serializer = new XMLSerializer(); 481 583 JSON json = JSONSerializer.toJSON( jsonData ); 482 serializer.setRootName("WorkspaceProfile"); 584 // init qid, elementtype 585 parseDataInit((JSONObject)json); 586 serializer.setRootName(getXMLRootName()); //"WorkspaceProfile"); 483 587 serializer.setElementName("item"); 484 588 serializer.setTypeHintsEnabled(false); … … 490 594 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 491 595 DocumentBuilder builder = factory.newDocumentBuilder(); 492 Document d= builder.parse( is_xml );596 Document new_doc = builder.parse( is_xml ); 493 597 // set user 494 598 //((Element)d.getFirstChild()).setAttribute("user", getServletRequest().getRemoteUser()); 495 NodeList wsnodelist = (NodeList) getWorkspace(); 496 // remove 497 //childeNode 498 if (wsnodelist.getLength() > 0){ 499 ((Node)wsnodelist.item(0)).getParentNode().removeChild(wsnodelist.item(0)); 500 } 501 String qidstring = ""; 502 if (qid.equals("0")) { 503 qidstring = createNewQid(); 504 changeQueryId(d,qid,qidstring); 505 } 599 String newid = DocumentReplaceNewElement(new_doc); 506 600 507 Node node = d.getFirstChild();508 Node node2 = workspace_doc.adoptNode(node.cloneNode(true));509 ((Element)node2).setAttribute("user", getUserName());510 workspace_doc.getElementsByTagName("WorkspaceProfiles").item(0).appendChild(node2);511 601 512 602 //TODO … … 516 606 //javax.xml.transform.stream.StreamSource s = new StreamSource(src); 517 607 //InputStream in = s.getInputStream(); 518 this.setResultStream(createStream( qidstring));//(InputStream)(new ByteArrayInputStream(qidstring.getBytes())));608 this.setResultStream(createStream(newid));//(InputStream)(new ByteArrayInputStream(qidstring.getBytes()))); 519 609 520 610 … … 645 735 } 646 736 647 737 public Object getQuery() throws XPathExpressionException{ 738 739 XPathFactory factory = XPathFactory.newInstance(); 740 XPath xpath = factory.newXPath(); 741 XPathExpression expr; 742 expr = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item/Queries/item[id='" + this.qid + "']"); 743 //expr = xpath.compile("//item[@id='" + this.qid + "']"); 744 //expression is evaluated with respect to a certain context node which is doc. 745 Object result = null; 746 try{ 747 result = expr.evaluate(workspace_doc, XPathConstants.NODESET); 748 } catch(Exception e){ 749 750 } 751 752 return result; 753 } 754 755 public Object getQueryset() throws XPathExpressionException{ 756 757 XPathFactory factory = XPathFactory.newInstance(); 758 XPath xpath = factory.newXPath(); 759 XPathExpression expr; 760 expr = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item[name='" + this.qsid + "']/Queries"); 761 //expression is evaluated with respect to a certain context node which is doc. 762 Object result = null; 763 try{ 764 result = expr.evaluate(workspace_doc, XPathConstants.NODESET); 765 } catch(Exception e){ 766 767 } 768 769 return result; 770 } 771 648 772 @Override 649 773 public void prepare() throws Exception { -
MDService2/trunk/MDService2/src/struts.xml
r1310 r1350 190 190 <param name="format">JSON</param> 191 191 <param name="type">{1}</param> 192 <param name="q id">{2}</param>192 <param name="qsid">{2}</param> 193 193 <!-- <param name="data">{1}</param> 194 194 <param name="actionkey"></param>
Note: See TracChangeset
for help on using the changeset viewer.