%@ page contentType="text/html" %>
<%@ page import="java.net.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.regex.*" %>
<%@ page import="java.util.zip.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="org.openlaszlo.utils.FileUtils.*" %>
<%@ page import="org.openlaszlo.xml.internal.XMLUtils.*" %>
<%@ page import="org.openlaszlo.server.LPS" %>
<%@ page import="org.openlaszlo.utils.DeployUtils" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="javax.xml.transform.*" %>
<%@ page import="javax.xml.transform.dom.*" %>
<%@ page import="javax.xml.transform.stream.*" %>
<%@ page import="javax.xml.parsers.DocumentBuilderFactory" %>
W3C Widget HTML5 Application Deployment Wizard
<%
/*
We want an option to deploy an app and it's entire directory.
So, for an app with is at /foo/bar/baz.lzx
+ /lps/includes/** ==> lps/includes/**
+ /foo/bar/** -- will include the SOLO .lzx.js file(s)
+ /foo/bar/baz.lzx.html -- the wrapper file
+ A copy of the LFC will be placed in lps/includes/LFC-dhtml.js
+ All resources which are external to /foo/bar will be copied into
a subdir named /foo/bar/lps/resources/**
*/
// Set this to make a limit on the size of zip file that is created
String whatpage = request.getParameter("whatpage");
if (whatpage == null) {
whatpage = "configure";
}
String appUrl = request.getParameter("appurl");
if (appUrl == null) {
appUrl = "examples/animation/animation.lzx";
}
appUrl = appUrl.trim();
// Directory on server where generated widget files are stored
String WGT_WORKING_DIR = "tmpwgt";
int maxZipFileSize = 64000000; // 64MB max
int warnZipFileSize = 10000000; // warn at 10MB of content (before compression)
boolean warned = false;
String zipfilename = "";
String title = request.getParameter("apptitle");
if (title == null) { title = ""; }
URL wrapperUrl = null;
URL canvasUrl = null;
String appwidth = request.getParameter("appwidth");
String appheight = request.getParameter("appheight");
// The "widgettype" arg controls which flavor of config.xml file we generate.
// We will look for a config file named config.WIDGET_TYPE.xslt,
// fallback to Opera format config file
String widgetType = request.getParameter("widgettype");
// Get app width/height from its canvas wrapper
// download text content of URL
StringBuffer wrapperbuf = new StringBuffer();
StringBuffer canvasbuf = new StringBuffer();
Element canvasElt = null;
String wrapper = null;
/*
request.getContextPath(): /lps-dev
request.getRequestURI(): /lps-dev/hqm/test/solo-deploy.jsp
request.getRequestURL(): http://localhost:8080/lps-dev/hqm/test/solo-deploy.jsp
request.getServletPath(): /hqm/test/solo-deploy.jsp
*/
String sUrl = request.getRequestURL().toString();
String servletPath = request.getServletPath();
String baseUrl = sUrl.substring(0, (sUrl.length() - servletPath.length())+1);
//LPS.initialize();
// remove dangerous pathname components, "..", and "//"
if (appUrl.indexOf("..") != -1 || appUrl.indexOf("//") != -1) {
%>
Error, do not use '..' or '//' in your app pathname: <%= appUrl %>
<%
}
try
{
// okee dokee. Now we have to adjust the app path to be relative to
// the server document root.
// say that appUrl == demos/vacation-survey/vacation-survey.lzx
// trim leading slash
if (appUrl.charAt(0) == '/') {
appUrl = appUrl.substring(1);
}
// If there are no "/" separators in the non-zero position in the
// url string , then the app url is at the LPS_HOME root, and that
// is bad thing to try to zip up recursively, so issue a warning
// and refuse to do it.
if (appUrl.indexOf("/") == -1) {
%>
Error bad location for app file
You entered <%= appUrl %>, which names a file in the server document root directory. Please
place the file in a subdirectory of the server root directory and run this deployment tool
again with the new path.
Explanation: The W3C Widget deployment tool creates an
archive of all files, recursively, starting in the directory that
contains the application source file. If the application source file
is in the servlet root directory, this tool will create a zip that
contains all the files inside the root directory. This directory
contains the entire OpenLaszlo binary distribution, so this is
probably not what you want.
<%
return;
}
wrapperUrl = new URL(new URL(baseUrl),
appUrl + "?lzr=dhtml&lzt=html&lzproxied=false&lzcopyresources=true");
canvasUrl = new URL(new URL(baseUrl),
appUrl + "?lzr=dhtml&lzt=canvas&lzproxied=false&lzcopyresources=true");
// load the app's canvas descriptor from the compiler
String str;
BufferedReader in;
try {
in = new BufferedReader(new InputStreamReader(canvasUrl.openStream()));
} catch (IOException urlex) {
%> Error occurred when trying to fetch url <%=canvasUrl%> <%
return;
}
// Need to check for HTTP 404 or other error
while ((str = in.readLine()) != null)
{
canvasbuf.append(str+"\n");
}
in.close();
canvasElt = DeployUtils.parse(canvasbuf.toString());
String canvasdebug = canvasElt.getAttribute("debug");
if ("true".equals(canvasdebug)) {
%>
Note: your app has its canvas debug flag enabled,
the Laszlo DHTML debugger curently does not work in a standalone widget deployment, continue?
<%
}
// load a copy of the HTML wrapper
in = new BufferedReader(new InputStreamReader(wrapperUrl.openStream()));
while ((str = in.readLine()) != null)
{
wrapperbuf.append(str+"\n");
}
in.close();
wrapper = wrapperbuf.toString();
// We need to adjust the wrapper, to make the path to lps/includes/dhtml-embed.js
// be relative rather than absolute.
wrapper = DeployUtils.adjustDHTMLWrapper(wrapper, request.getContextPath());
// debugging print
if (false) {
out.println("lpspath="+request.getContextPath()+"
");
%><%= org.openlaszlo.xml.internal.XMLUtils.escapeXml(wrapper)%>
<%
}
}
catch (MalformedURLException e) { %>
Error retrieving URL <%= appUrl %>: <%= e.toString() %>
<% }
catch (IOException e) { %>
Error retrieving URL <%= appUrl %>: <%= e.toString() %>
<% }
// replace title
// wrapper = wrapper.replaceFirst(".*", ""+title+"\n");
// extract width and height with regexp
appwidth = canvasElt.getAttribute("width");
appheight = canvasElt.getAttribute("height");
int nwidth = 640;
int nheight = 400;
try {
nwidth = Integer.parseInt(appwidth);
} catch (Exception e) {
if (!appwidth.matches("\\d+%")) {
out.println("
Error: can't parse app canvas width string "+appwidth+". "+e.toString()+
"");
}
}
try {
nheight = Integer.parseInt(appheight);
} catch (Exception e) {
if (!appheight.matches("\\d+%")) {
out.println("
Error: can't parse app canvas height string "+appheight+". "+e.toString()+
"");
}
}
// if no form vars, we are at page #0
if (whatpage.equals("configure")) {
%>
Setup W3C Widget HTML5 Application Deployment
This wizard will generate a zip file containing all the resources you need to deploy a serverless (Widget) application. For deployments which do not require the Javscript browser integration support files, it will also generate some simple HTML wrappers which can be cut and pasted into HTML pages.
|
Note
The W3C Widget deployment tool creates a
Zip archive of all files, recursively, from the directory that
contains your specified application source file. So it is best to use this tool
on an application which resides in its own directory.
If there are other applications in the same directory, this tool will copy
all of those apps and their assets (and subdirectories) into the Zip file. That may not be what you want.
|
<%
} else if (whatpage.equals("preview")){
%>
Preview W3C Widget Application in Browser
<%
String soloURL = (request.getContextPath()+"/" + appUrl + ".html?lzr=dhtml&lzproxied=false");
String exampleURL = (request.getContextPath()+"/" + appUrl + "?lzr=dhtml&lzproxied=false");
%>
Using URL <%= exampleURL %>
Size = <%= appwidth %> x <%= appheight %>