Author: jonathan
Date: Wed May 28 17:54:05 2008
New Revision: 17525
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=17525
Log:
Added ?template support.
Added:
trunk/mashup/java/modules/core/src/org/wso2/mashup/requestprocessor/TemplateProcessor.java
- copied, changed from r17516,
/trunk/mashup/java/modules/core/src/org/wso2/mashup/requestprocessor/GadgetProcessor.java
Modified:
trunk/mashup/java/modules/core/conf/server.xml
trunk/mashup/java/modules/www/mashup.jsp
Modified: trunk/mashup/java/modules/core/conf/server.xml
URL:
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/core/conf/server.xml?rev=17525&r1=17524&r2=17525&view=diff
==============================================================================
--- trunk/mashup/java/modules/core/conf/server.xml (original)
+++ trunk/mashup/java/modules/core/conf/server.xml Wed May 28 17:54:05 2008
@@ -407,6 +407,10 @@
<Item>gadget</Item>
<Class>org.wso2.mashup.requestprocessor.GadgetProcessor</Class>
</Processor>
+ <Processor>
+ <Item>template</Item>
+ <Class>org.wso2.mashup.requestprocessor.TemplateProcessor</Class>
+ </Processor>
</HttpGetRequestProcessors>
<!--
Copied:
trunk/mashup/java/modules/core/src/org/wso2/mashup/requestprocessor/TemplateProcessor.java
(from r17516,
/trunk/mashup/java/modules/core/src/org/wso2/mashup/requestprocessor/GadgetProcessor.java)
URL:
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/core/src/org/wso2/mashup/requestprocessor/TemplateProcessor.java?rev=17525&r1=17516&r2=17525&view=diff
==============================================================================
---
/trunk/mashup/java/modules/core/src/org/wso2/mashup/requestprocessor/GadgetProcessor.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/requestprocessor/TemplateProcessor.java
Wed May 28 17:54:05 2008
@@ -39,8 +39,8 @@
import java.io.ByteArrayInputStream;
import java.io.File;
-public class GadgetProcessor implements HttpGetRequestProcessor {
- private static Log log = LogFactory.getLog(GadgetProcessor.class);
+public class TemplateProcessor implements HttpGetRequestProcessor {
+ private static Log log = LogFactory.getLog(TemplateProcessor.class);
/**
* Process the HTTP GET request
@@ -66,7 +66,7 @@
response.setContentType("text/html");
outputStream
.write(("<h4>Service " + serviceName +
- " is inactive. Cannot generate
Gadget.</h4>")
+ " is inactive. Cannot generate
template.</h4>")
.getBytes());
outputStream.flush();
return;
@@ -74,36 +74,97 @@
ByteArrayOutputStream sigOutStream =
Utils.getSigStream(axisService);
- InputStream gadgetStream =
Thread.currentThread().getContextClassLoader()
- .getResourceAsStream("gadget.xslt");
- if (gadgetStream == null) {
+ String flavorParameter = request.getParameter("flavor");
+ if (flavorParameter != null &&
!(("").equals(flavorParameter))) {
+ if (!flavorParameter.equalsIgnoreCase("googlegadget")
+ && !flavorParameter.equalsIgnoreCase("html")) {
+ response.sendError(404);
+ response.setContentType("text/html; charset=utf-8");
+ outputStream.write(
+ ("<h4>Unsupported template flavor parameter "
+ flavorParameter +
+ "</h4>").getBytes());
+ return;
+ }
+ } else {
+ flavorParameter = "html";
+ }
+
+ InputStream templateStream =
Thread.currentThread().getContextClassLoader()
+ .getResourceAsStream("template-" + flavorParameter +
".xslt");
+ if (templateStream == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.setContentType("text/html; charset=utf-8");
- outputStream.write(("<h4>Cannot find the stylesheet</h4>")
+ outputStream.write(("<h4>Cannot find the stylesheet for "
+ flavorParameter + " templates</h4>")
.getBytes());
return;
}
+ /*
+ * Handling the "service" parameter
+ */
+ String serviceParameter = request.getParameter("service");
+ if (serviceParameter != null &&
!(("").equals(serviceParameter))) {
+ transformer.setParameter("service", serviceParameter);
+ }
+
+ /*
+ * Handling the "lang" parameter
+ */
+ String langParameter = request.getParameter("lang");
+ if ((langParameter == null) || (langParameter.equals(""))
+ || (langParameter.equalsIgnoreCase("javascript"))
+ || (langParameter.equalsIgnoreCase("ecmascript"))
+ || (langParameter.equalsIgnoreCase("js"))) {
+ } else if (langParameter.equalsIgnoreCase("e4x")) {
+ transformer.setParameter("e4x", "true");
+ } else {
+ response.sendError(404);
+ response.setContentType("text/html; charset=utf-8");
+ outputStream.write(
+ ("<h4>Unsupported lang parameter " + langParameter
+
+ "</h4>").getBytes());
+ return;
+ }
+
+ String contentTypeParameter =
request.getParameter(MashupConstants.CONTENT_TYPE_QUERY_PARAM);
+ String contentType;
+ if (contentTypeParameter != null &&
!"".equals(contentTypeParameter.trim())) {
+ contentType = contentTypeParameter;
+ } else {
+ if ("html".equals(flavorParameter)) {
+ contentType = "text/html";
+ } else {
+ contentType = "application/xml";
+ }
+ }
+ response.setContentType(contentType + "; charset=utf-8");
+
+ // Handling the localhost parameter. If set to tru the stub
will use localhost instead of the IP.
+ // Needed when stubs are needed fir inclusion in a mashup.
+ String localhostParameter = request.getParameter("localhost");
+ if ("true".equals(localhostParameter)) {
+ transformer.setParameter("localhost-endpoints", "true");
+ }
+
ByteArrayInputStream sigInStream = new
ByteArrayInputStream(sigOutStream
- .toByteArray());
+ .toByteArray());
/*
- * XSLT transform to generate the stubs
+ * XSLT transform to generate the template
*/
Source xmlSource = new StreamSource(sigInStream);
- Source xsltSource = new StreamSource(gadgetStream);
- Result result = new StreamResult(response.getOutputStream());
+ Source xsltSource = new StreamSource(templateStream);
+ Result result = new StreamResult(outputStream);
TransformerFactory transformerFactory =
TransformerFactory.newInstance();
- transformerFactory.setURIResolver(new GadgetURIResolver());
+ transformerFactory.setURIResolver(new TemplateURIResolver());
Transformer transformer = transformerFactory
.newTransformer(xsltSource);
- response.setContentType("text/xml");
transformer.transform(xmlSource, result);
} else {
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
outputStream
- .write(("<h4>Service cannot be found. Cannot display
<em>Gadget</em>.</h4>")
+ .write(("<h4>Service cannot be found. Cannot display
<em>Template</em>.</h4>")
.getBytes());
outputStream.flush();
}
@@ -114,9 +175,9 @@
}
}
- class GadgetURIResolver implements URIResolver {
+ class TemplateURIResolver implements URIResolver {
- GadgetURIResolver() {
+ TemplateURIResolver() {
}
public Source resolve(String href, String base) {
Modified: trunk/mashup/java/modules/www/mashup.jsp
URL:
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/www/mashup.jsp?rev=17525&r1=17524&r2=17525&view=diff
==============================================================================
--- trunk/mashup/java/modules/www/mashup.jsp (original)
+++ trunk/mashup/java/modules/www/mashup.jsp Wed May 28 17:54:05 2008
@@ -431,6 +431,10 @@
target="_blank">Try</a> the
service
</li>
+ <li><a href="<%=httpUrl%>services/<%=author%>/<%= mashup
%>?gadget" title="?gadget"
+ target="_blank">Try</a> the
+ service as a Google Gadget
+ </li>
<li>Read <a href="<%=httpUrl%>services/<%=author%>/<%= mashup
%>?doc" title="?doc"
target="_blank">API
documentation</a>
@@ -471,6 +475,12 @@
<li><a href="<%=httpUrl%>services/<%=author%>/<%= mashup
%>?stub&lang=e4x&localhost=true&content-type=text/plain">Javascript
(E4X) stub using "localhost" endpoints</a> - optimum for a
Mashup hosted on this server
</li>
+ <li><a href="<%=httpUrl%>services/<%=author%>/<%= mashup
%>?template&flavor=html">Source code template</a>
+ for an HTML interface for this service
+ </li>
+ <li><a href="<%=httpUrl%>services/<%=author%>/<%= mashup
%>?template&flavor=googlegadget">Source code template</a>
+ for a Google Gadget for this service
+ </li>
</ul>
</div>
</td>
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev