Author: tyrell
Date: Sat Jan 12 05:00:18 2008
New Revision: 12159

Log:

Initial, experimental commit of the new Mashup Editor.

Added:
   trunk/mashup/java/modules/www/editor.jsp

Added: trunk/mashup/java/modules/www/editor.jsp
==============================================================================
--- (empty file)
+++ trunk/mashup/java/modules/www/editor.jsp    Sat Jan 12 05:00:18 2008
@@ -0,0 +1,324 @@
+<%--
+ * Copyright 2006,2007 WSO2, Inc. http://www.wso2.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+--%>
+<%@ page isErrorPage="true" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ page import="org.wso2.mashup.webapp.utils.RegistryUtils" %>
+<%@ page import="org.wso2.registry.Registry" %>
+<%@ page import="org.wso2.registry.RegistryConstants" %>
+<%@ page import="java.net.URLDecoder" %>
+<%@ page import="org.wso2.usermanager.UserManagerConstants" %>
+<%
+
+    Registry registry = RegistryUtils.getRegistry(request);
+    String bounceback = request.getParameter("bounceback");
+
+    if (bounceback == null) {
+        bounceback = "index.jsp";
+    } else {
+        bounceback = URLDecoder.decode(bounceback, "UTF-8");
+    }
+
+    // Set bounceback location
+    String queryString = request.getQueryString();
+    String thisPage = URLEncoder
+            .encode("editor.jsp" + (queryString == null ? "" : "?" + 
queryString), "UTF-8");
+
+    //The query for this page will contain two parameters. The 'action' 
parameter, which will
+    // notify whether a new service is being created or an existing one is to 
be edited and an
+    // optional 'mashup' parameter, which will identify the mashup to be 
edited in such an instance.
+
+    String action = request.getParameter("action");
+    String mashup = request.getParameter("mashup");
+
+    //Sanity check. Immediately terminate further processing if this fails.
+    if (action == null) {
+        throw new Exception("Sorry. An action was not specified in the 
request.");
+    } else if ((action.equalsIgnoreCase("edit")) && (mashup == null)) {
+        throw new Exception(
+                "Sorry. An edit request was made without a valid mashup being 
named for editing.");
+    } else if ((action.equalsIgnoreCase("edit")) &&
+            (!RegistryUtils.isAuthorized(registry, mashup, 
UserManagerConstants.EDIT))) {
+        throw new Exception(
+                "Sorry. You are not authorized to perform this operation.");
+    } else if ((action.equalsIgnoreCase("new")) && (mashup == null)) {
+        throw new Exception(
+                "Sorry. A request was made to create a mashup without 
providing a valid name.");
+    }
+%>
+<html>
+<head>
+    <title>Mashup Editor</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;
+            font-family: arial;
+            text-decoration: none;
+            width: 11%;
+            text-align: center;
+            float: left;
+        }
+
+        a.tab:hover {
+            border-color: black;
+            background-color: white;
+        }
+
+        .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 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;
+        }
+
+    </script>
+</head>
+<body onload="showPanel(document.getElementById('tab1'), 'mashup_code');">
+<div id="page">
+<%@ include file="header.jsp" %>
+<div id="search"></div>
+<div id="welcome">
+</div>
+<div id="content">
+<%
+    //Only signed in users can perform editing in the first place
+    if (!RegistryUtils.isLoggedIn(registry)) {
+%>
+<p>You need to <a href="signin.jsp?bounceback=<%=thisPage%>">sign in</a> to 
edit Mashups. If
+    you came here by accident, <a href="<%=bounceback%>">go back</a>.
+</p>
+<%
+} else {
+    //We have an authorized user. Spawning an editor.
+%>
+
+<div id="mashup_editor" style="height: 80%;">
+<div id="tabs">
+    <a href="" class="tab"
+       onmousedown="return event.returnValue = showPanel(this, 'mashup_code');"
+       id="tab1"
+       onclick="return false;">Mashup Code</a>
+    <a href="" class="tab"
+       onmousedown="return event.returnValue = showPanel(this, 'ui_code');"
+       onclick="return false;">Custom UI Code</a>
+</div>
+<div class="panel" id="mashup_code" style="display: block">
+    <textarea id="mashup_code_text" class="codepress javascript"
+              style="width: 100%; height: 100%" cols="" rows="">
+        <%
+            if (action.equalsIgnoreCase("new")) {
+                //Inserting the initial mashup skeleton
+                String serviceSkeleton =
+                        "/*\n" +
+                                "* Copyright 2005-2007 WSO2, Inc. 
http://www.wso2.org\n"; +
+                                "*\n" +
+                                "* Licensed under the Apache License, Version 
2.0 (the \"License\");\n" +
+                                "* you may not use this file except in 
compliance with the License.\n" +
+                                "* You may obtain a copy of the License at\n" +
+                                "*\n" +
+                                "* 
http://www.apache.org/licenses/LICENSE-2.0\n"; +
+                                "*\n" +
+                                "* Unless required by applicable law or agreed 
to in writing, software\n" +
+                                "* distributed under the License is 
distributed on an \"AS IS\" BASIS,\n" +
+                                "* WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express or implied.\n" +
+                                "* See the License for the specific language 
governing permissions and\n" +
+                                "* limitations under the License.\n" +
+                                "*/\n" +
+                                "this.serviceName = \"" + mashup + "\";\n" +
+                                "this.documentation = \"TODO: Add service 
level documentation here\" ;\n" +
+                                "\n" +
+                                "toString.documentation = \"TODO: Add 
operation level documentation here\" ;\n" +
+                                "toString.inputTypes = { /* TODO: Add input 
types of this operation */ };\n" +
+                                "toString.outputType = \"String\"; /* TODO: 
Add output type here */ \n" +
+                                "function toString()\n" +
+                                "{\n" +
+                                "   //TODO: Add function code here\n" +
+                                "   return \"Hi, my name is " + mashup + 
"\";\n" +
+                                "}\n";
+
+        %>
+        <%=serviceSkeleton%>
+        <%
+        } else {
+        %>
+        <p>Existing code here</p>
+        <%
+            }
+        %>
+    </textarea>
+</div>
+<div class="panel" id="ui_code" style="display: block">
+<textarea id="ui_code_text" rows="" cols="" class="codepress html"
+          style="width: 100%; height: 100%">
+<%
+    if (action.equalsIgnoreCase("new")) {
+        String uiSkeleton =
+                "<!--\n" +
+                        "  ~ Copyright 2005-2007 WSO2, Inc. 
http://www.wso2.org\n"; +
+                        "  ~\n" +
+                        "  ~ Licensed under the Apache License, Version 2.0 
(the \"License\");\n" +
+                        "  ~ you may not use this file except in compliance 
with the License.\n" +
+                        "  ~ You may obtain a copy of the License at\n" +
+                        "  ~\n" +
+                        "  ~ http://www.apache.org/licenses/LICENSE-2.0\n"; +
+                        "  ~\n" +
+                        "  ~ Unless required by applicable law or agreed to in 
writing, software\n" +
+                        "  ~ distributed under the License is distributed on 
an \"AS IS\" BASIS,\n" +
+                        "  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
either express or implied.\n" +
+                        "  ~ See the License for the specific language 
governing permissions and\n" +
+                        "  ~ limitations under the License.\n" +
+                        "  -->\n" +
+                        "\n" +
+                        "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 
Transitional//EN\">\n" +
+                        "<html>\n" +
+                        "<head>\n" +
+                        "\n" +
+                        "    <meta content=\"text/html; charset=ISO-8859-1\" 
http-equiv=\"content-type\">\n" +
+                        "    <title>Welcome to " + mashup + "</title>\n" +
+                        "    \n" +
+                        "    <style type=\"text/css\">\n" +
+                        "      body {font: 75%/1.5 \"Lucida Grande\",\"Lucida 
Sans\",\"Microsoft Sans Serif\", \"Lucida Sans 
Unicode\",verdana,sans-serif,\"trebuchet ms\"; color: #111; }\n" +
+                        "      img {margin-bottom: 0.5em}\n" +
+                        "      span {font-weight: bold}\n" +
+                        "      .template {margin-left:1em; margin-bottom:1em; 
font-size:125%}\n" +
+                        "      #console {color:red; font-weight:bold}\n" +
+                        "    </style>\n" +
+                        "    <script type=\"text/javascript\" 
src=\"/js/wso2/WSRequest.js\"></script>\n" +
+                        "    <script type=\"text/javascript\" src=\"../" + 
mashup +
+                        "?stub\"></script>\n" +
+                        "    \n" +
+                        "    <script type=\"text/javascript\" 
language=\"javascript\">\n" +
+                        "\n" +
+                        "\t\t  //Calls the toString operation of the '" + 
mashup +
+                        "' Mashup        \n" +
+                        "        function callMashup() {            \n" +
+                        "\n" +
+                        "            " + mashup + ".setAddress(" +
+                        mashup + ".endpoint, \"services/" + mashup +
+                        "\");\n" +
+                        "            " + mashup +
+                        ".toString.onError = handleError;\n" +
+                        "            " + mashup +
+                        ".toString.callback = function (response) {\n" +
+                        "                fillData(response);\n" +
+                        "            }\n" +
+                        "            " + mashup + ".toString();\n" +
+                        "        }\n" +
+                        " \n" +
+                        "        //Handles and error by displaying the reason 
in a dialog\n" +
+                        "        function handleError(error) {\n" +
+                        "            var console = 
document.getElementById(\"error-console\");" +
+                        "            log (console, \"Fault: \" + error.reason 
+ \"\\n\\n\" + error.detail);\n" +
+                        "        }\n" +
+                        "\n" +
+                        "\t\t  //Writes the received response to the DIV\n" +
+                        "        function fillData(response)\n" +
+                        "        {           \n" +
+                        "            var responseDiv = 
document.getElementById(\"reponse-text\");\n" +
+                        "            responseDiv.innerHTML = '<p>' + response 
+ '</p>';           \n" +
+                        "        }  \n" +
+                        "              \n" +
+                        "        function log(console, data) {\n" +
+                        "           var browser = 
WSRequest.util._getBrowser();\n" +
+                        "           if (browser == \"ie\" || browser == 
\"ie7\")\n" +
+                        "             console.innerText = data;\n" +
+                        "           else\n" +
+                        "             console.textContent = data;\n" +
+                        "        }" +
+                        " \n" +
+                        "    </script>\n" +
+                        "    \n" +
+                        "</head>\n" +
+                        "\n" +
+                        "<body onload='callMashup();'>\n" +
+                        "<img alt=\"WSO2 Mashup Server logo\" 
src=\"/images/wso2_mashup_logo.gif\"/>" +
+                        "\n" +
+                        "\t<div id=\"reponse-text\">    \n" +
+                        "\t<!-- This div will contain the text returned as 
response to the service call -->\n" +
+                        "\t</div>\n" +
+                        "<div>Access all the operations of the " + mashup +
+                        " service through the <a href=\"../" + mashup +
+                        "?tryit\">Try-it page</a>.</div>" +
+                        "\n" +
+                        "<div id=\"error-console\"></div>" +
+                        " \n" +
+                        "</body>\n" +
+                        "</html>";
+%>
+<%=uiSkeleton%>
+<%
+} else {
+%>
+<p>Exisiting ui code here</p>
+<%
+    }
+%>
+</textarea>
+</div>
+</div>
+<%
+    }
+%>
+</div>
+<%@ include file="footer.jsp" %>
+</div>
+<script language="javascript" src="js/codepress/codepress.js" 
type="text/javascript"></script>
+</body>
+</html>
\ No newline at end of file

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to