Author: tyrell
Date: Sun Jan 13 10:02:08 2008
New Revision: 12169
Log:
Adding mashup source code saving.
Modified:
trunk/mashup/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
trunk/mashup/java/modules/www/editor.jsp
trunk/mashup/java/modules/www/js/services.js
Modified:
trunk/mashup/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
==============================================================================
---
trunk/mashup/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
(original)
+++
trunk/mashup/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
Sun Jan 13 10:02:08 2008
@@ -16,6 +16,7 @@
package org.wso2.mashup.coreservices.servicemetadatalister;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.description.AxisService;
@@ -26,11 +27,13 @@
import org.wso2.mashup.MashupConstants;
import org.wso2.mashup.MashupFault;
import org.wso2.mashup.utils.MashupUtils;
+import org.wso2.mashup.webapp.utils.RegistryUtils;
import org.wso2.registry.RegistryConstants;
import org.wso2.registry.RegistryException;
import org.wso2.registry.Resource;
import org.wso2.registry.jdbc.JDBCRegistry;
import org.wso2.wsas.ServerConstants;
+import org.wso2.wsas.ServerManager;
import org.wso2.wsas.persistence.PersistenceManager;
import org.wso2.wsas.persistence.dataobject.OperationDO;
import org.wso2.wsas.persistence.dataobject.ServiceDO;
@@ -212,27 +215,38 @@
}
- public Boolean saveServiceSource(String serviceName, String
modifiedSource) {
+ public Boolean saveServiceSource(String path, String modifiedSource) {
boolean success = false;
- MessageContext currentMessageContext =
MessageContext.getCurrentMessageContext();
- AxisConfiguration configuration =
- currentMessageContext.getAxisService().getAxisConfiguration();
-
try {
- AxisService mashupService = configuration.getService(serviceName);
- Parameter serviceJSParameter = mashupService
- .getParameter(JavaScriptEngineConstants.SERVICE_JS);
+ String[] pathContents = path.split("/");
- if (serviceJSParameter != null && serviceJSParameter.getValue() !=
null) {
- File serviceJS = (File) serviceJSParameter.getValue();
- BufferedWriter out = new BufferedWriter(new
FileWriter(serviceJS));
- out.write(modifiedSource);
- out.flush();
- out.close();
- success = true;
+ // Extracting the service author from the path.
+ // Not using the registry here on purpose to allow saving the
service source even when it's undeployed.
+ String author = pathContents[2];
+
+ //todo Add verification and validation routines to ensure only the
author of the service and admins can write.
+
+ //Extracting the real path from the registry path provided
+ path = "";
+ for (int x = 2; x < pathContents.length; x++) {
+ path = path + "/" + pathContents[x];
}
+
+ ServerManager serverManager = ServerManager.getInstance();
+ ConfigurationContext configContext = serverManager.configContext;
+
+ File serviceJs = new
File(configContext.getRealPath(configContext.getContextRoot()) +
+ "/scripts/" + path + ".js");
+
+ //Writing the file with the source provided
+ BufferedWriter out = new BufferedWriter(new FileWriter(serviceJs));
+ out.write(modifiedSource);
+ out.flush();
+ out.close();
+ success = true;
+
} catch (Exception e) {
e.printStackTrace();
}
@@ -604,7 +618,7 @@
String serviceName;
ArrayList temp = new ArrayList();
-
+
while (keys.hasMoreElements()) {
serviceName = (String) keys.nextElement();
Modified: trunk/mashup/java/modules/www/editor.jsp
==============================================================================
--- trunk/mashup/java/modules/www/editor.jsp (original)
+++ trunk/mashup/java/modules/www/editor.jsp Sun Jan 13 10:02:08 2008
@@ -77,91 +77,150 @@
%>
<html>
<head>
- <!--Do not cache -->
- <meta http-equiv="PRAGMA" content="NO-CACHE">
- <meta http-equiv="expires" content=<%= new java.util.Date() %>>
-
- <title>Mashup Editor [ Editing the mashup <%=mashupName%> authored by
<%=RegistryUtils.getFullName(request,author)%> ]</title>
- <!-- Required CSS -->
- <link href="css/styles.css" rel="stylesheet" type="text/css"/>
- <style type="text/css">
- #tabs {
- display: block;
- float: left;
- width: 100%;
- }
+<!--Do not cache -->
+<meta http-equiv="PRAGMA" content="NO-CACHE">
+<meta http-equiv="expires" content=<%= new java.util.Date() %>>
+
+<title>Mashup Editor [ Editing the mashup <%=mashupName%> authored by
<%=RegistryUtils
+ .getFullName(request, author)%> ]</title>
+<!-- Required CSS -->
+<link href="css/styles.css" rel="stylesheet" type="text/css"/>
+<style type="text/css">
+ #tabs {
+ display: block;
+ float: left;
+ width: 100%;
+ }
+
+ a.tab {
+ border-collapse: collapse;
+ border-style: solid solid none solid;
+ border-color: black;
+ border-width: 1px 1px 0px 1px;
+ background-color: silver;
+ padding: 4px 0.5em 0px 0.5em;
+ margin-top: 4px;
+ margin-right: 2px;
+ text-decoration: none;
+ width: 11%;
+ text-align: center;
+ float: left;
+ }
+
+ a.tab:hover {
+ border-color: black;
+ background-color: white;
+ }
- a.tab {
- border-collapse: collapse;
- border-style: solid solid none solid;
- border-color: black;
- border-width: 1px 1px 0px 1px;
- background-color: silver;
- padding: 4px 0.5em 0px 0.5em;
- margin-top: 4px;
- margin-right: 2px;
- text-decoration: none;
- width: 11%;
- text-align: center;
- float: left;
+ .panel {
+ /*border: solid 1px black;*/
+ background-color: white; /* padding: 5px;*/
+ height: 95%;
+ overflow: auto;
+ clear: left;
+ }
+</style>
+
+<!-- Required Javascript -->
+<script language="javascript" src="js/common.js"
type="text/javascript"></script>
+<script type="text/javascript" src="../wsasadmin/global_params.js"></script>
+<script type="text/javascript" src="../wsasadmin/js/main.js"></script>
+<script type="text/javascript" src="js/mashup-main.js"></script>
+<script language="javascript" src="js/wso2/WSRequest.js"
type="text/javascript"></script>
+<script language="javascript" src="js/services.js"
type="text/javascript"></script>
+<script language="javascript"
+ type="text/javascript">userLoggedOn =
<%=RegistryUtils.isLoggedIn(registry) %>;</script>
+
+<script language="JavaScript" type="text/javascript">
+ var panels = new Array('mashup_code', 'ui_code');
+ var selectedTab = null;
+ function showPanel(tab, name)
+ {
+ if (selectedTab)
+ {
+ selectedTab.style.backgroundColor = '';
+ selectedTab.style.paddingTop = '';
+ selectedTab.style.marginTop = '4px';
+ }
+ selectedTab = tab;
+ selectedTab.style.backgroundColor = 'white';
+ selectedTab.style.paddingTop = '6px';
+ selectedTab.style.marginTop = '0px';
+ for (var i = 0; i < panels.length; i++)
+ {
+ document.getElementById(panels[i]).style.display =
+ (name == panels[i]) ? 'block' : 'none';
}
+ return false;
+ }
- a.tab:hover {
- border-color: black;
- background-color: white;
+ function init() {
+ try {
+ showPanel(document.getElementById('tab1'), 'mashup_code');
+ } catch(e) {
}
+ }
+
+ function saveServiceSourceCallback() {
+ var lblInfo = document.getElementById("source_save_status");
- .panel {
- /*border: solid 1px black;*/
- background-color: white; /* padding: 5px;*/
- height: 95%;
- overflow: auto;
- clear: left;
+ var saveSuccess;
+
+ var browser = WSRequest.util._getBrowser();
+ if (browser == "ie" || browser == "ie7") {
+ saveSuccess =
+
this.req.responseXML.getElementsByTagName("ns:return")[0].firstChild.nodeValue;
+ } else {
+ saveSuccess =
+
this.req.responseXML.getElementsByTagName("return")[0].firstChild.nodeValue;
}
- </style>
- <!-- Required Javascript -->
- <script language="javascript" src="js/common.js"
type="text/javascript"></script>
- <script language="javascript"
- type="text/javascript">userLoggedOn =
<%=RegistryUtils.isLoggedIn(registry) %>;</script>
-
- <script language="JavaScript" type="text/javascript">
- var panels = new Array('mashup_code', 'ui_code');
- var selectedTab = null;
- function showPanel(tab, name)
- {
- if (selectedTab)
- {
- selectedTab.style.backgroundColor = '';
- selectedTab.style.paddingTop = '';
- selectedTab.style.marginTop = '4px';
- }
- selectedTab = tab;
- selectedTab.style.backgroundColor = 'white';
- selectedTab.style.paddingTop = '6px';
- selectedTab.style.marginTop = '0px';
- for (var i = 0; i < panels.length; i++)
- {
- document.getElementById(panels[i]).style.display =
- (name == panels[i]) ? 'block' : 'none';
- }
- return false;
+ var currentTime = new Date();
+ var hours = currentTime.getHours();
+ var minutes = currentTime.getMinutes();
+ var month = currentTime.getMonth() + 1;
+ var day = currentTime.getDate();
+ var year = currentTime.getFullYear();
+
+ if (minutes < 10)
+ minutes = "0" + minutes;
+
+ var timeStamp = "at " + hours + ":" + minutes;
+
+ if (hours > 11) {
+ timeStamp = timeStamp + " PM";
+ } else {
+ timeStamp = timeStamp + " AM";
}
- function init() {
- try {
- showPanel(document.getElementById('tab1'), 'mashup_code');
- } catch(e) {
- }
+ timeStamp = timeStamp + " on " + month + "/" + day + "/" + year;
+
+ if (saveSuccess == "true") {
+ lblInfo.innerHTML = "";
+ lblInfo.innerHTML =
+ "<font color=green>Your source edits were successfully updated " +
timeStamp +
+ "</font>";
+ } else {
+ lblInfo.innerHTML = "";
+ lblInfo.innerHTML =
+ "<font color=red>Failed to update source edits " + timeStamp +
"</font>";
}
- </script>
+ }
+
+ function saveServiceSource(newSource) {
+ wso2.mashup.services.saveServiceSource('<%=mashup%>', newSource,
saveServiceSourceCallback, "");
+ }
+
+</script>
</head>
<body onload="init();">
<div id="page">
<%@ include file="header.jsp" %>
<div id="search"></div>
-<div id="welcome">Editing the mashup <b><%=mashupName%></b> authored by
<i><%=RegistryUtils.getFullName(request,author)%></i>.
+<div id="welcome">Editing the mashup <b><%=mashupName%>
+</b> authored by <i><%=RegistryUtils.getFullName(request, author)%>
+</i>.
</div>
<div id="content">
<%
@@ -224,9 +283,17 @@
}
%>
<textarea id="mashup_code_text" rows="" cols="" class="codepress
javascript"
- style="width: 100%; height: 100%;">
+ style="width: 100%; height: 95%;">
<%=serviceSource%>
</textarea>
+ <br>
+
+ <div style="padding-top: 10px;"><label id="source_save_status"
style="float: left;">Tip: You can use the button on
+ the right to save changes.</label> <input type="button"
+ value="Save mashup code"
+
onclick="saveServiceSource(mashup_code_text.getCode());"
+ style="float: right;"/>
+ </div>
</div>
<div class="panel" id="ui_code" style="display: block">
<%
Modified: trunk/mashup/java/modules/www/js/services.js
==============================================================================
--- trunk/mashup/java/modules/www/js/services.js (original)
+++ trunk/mashup/java/modules/www/js/services.js Sun Jan 13 10:02:08 2008
@@ -326,19 +326,19 @@
* @method saveServiceSource
* @public
* @static
- * @param {String} serviceName Name of the service
+ * @param {String} path Path of the service
* @param {String} modifiedSource Ammended source code
* @param {callback} callBack User-defined callback function or object
* @param {callback} params Parameters to be set in the callback
*/
-wso2.mashup.services.saveServiceSource = function (serviceName,
modifiedSource, callback, params) {
+wso2.mashup.services.saveServiceSource = function (path, modifiedSource,
callback, params) {
var callURL = serverURL + "/" + "ServiceMetaDataLister" + "/" ;
var serviceSource = "<![CDATA[" + modifiedSource + "]]>";
var body_xml = '<req:saveServiceSourceOpRequest
xmlns:req="http://servicemetadatalister.coreservices.mashup.wso2.org/xsd">\n' +
- ' <req:serviceName>' + serviceName + '</req:serviceName>\n'
+
+ ' <req:path>' + path + '</req:path>\n' +
' <req:modifiedSource>' + serviceSource +
'</req:modifiedSource>\n' +
' </req:saveServiceSourceOpRequest>\n';
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev