if (src==null) throw new BuildException ("Must specify source web.xml file with 'src' attribute");
if (! (src.exists () && src.isFile ())) throw new BuildException ("Source web.xml does not exist or is not a file: "+src.getCanonicalPath ());
if (dst==null) throw new BuildException ("Must specify destination web.xml file with 'dst' attribute");
if (dir==null) throw new BuildException ("Must specify root directory to search with 'dir' attribute");
if (! (dir.exists () && dir.isDirectory ())) throw new BuildException ("Search root does not exist or is not a directory: "+dir.getCanonicalPath ());
if (include!=null && ! (include.exists () && (include.isFile () || include.isDirectory()))) throw new BuildException ("Include file does not exist or is not a file/directory: "+include.getCanonicalPath ());
if (links!=null && links.exists () && !links.isFile ()) throw new BuildException ("Links target exists but is not a file: "+links.getCanonicalPath ());
if (startupBegin!=null && startupBegin<0) throw new BuildException ("Startup begin parameter must be positive");
if (sqlStart!=null && sqlStart<0) throw new BuildException ("sqlStart parameter must be positive");
if (projectKey==null) projectKey = "";
}
public void execute () throws BuildException
{
final int rootln = dir.getAbsolutePath ().length ();
try
{
final Map<File,String> iovar = findLinks ();
final BufferedReader in = new BufferedReader (new FileReader (src));
final BufferedWriter out = new BufferedWriter (new FileWriter (dst));
for (String line; (line = in.readLine ())!=null; )
{
if (line.contains ("[iovar]"))
{
if (include!=null)
{
if (include.isFile ())
{
includeFile (include, out);
}
else if (include.isDirectory ())
{
for (final File file : include.listFiles ())
{
includeFile (file, out);
}
}
else
{
throw new IOException ("not a file or directory: " + include);
}
}
out.write (" <!-- iovar auto-generation begin -->");
out.newLine ();
final Set<String> servlets = new HashSet<String> ();
final BufferedWriter lout;
if (links!=null) lout = new BufferedWriter (new FileWriter (links));
else lout = null;
if (iovar!=null) for (final Iterator<Map.Entry<File,String>> links = iovar.entrySet ().iterator (); links.hasNext (); )
{
final Map.Entry<File,String> entry = links.next ();
// FIXME: make this more robust
final File file = entry.getKey ().getAbsoluteFile ();
final String url = file.getPath ().substring (rootln);
boolean check = true;
String clname = entry.getValue ();
if (clname.startsWith (":"))
{
clname = clname.substring (1);
check = false;
}
//try
{
final int mysql = clname.indexOf ("dev/mysql/");
if (mysql >= 0)
{
if (! servlets.contains (clname))
{
String config = new File (file, "../" + clname).getCanonicalPath ();
+ // FIXME: store config path relative to project root
+ // (facilitates app embedded and running on different systems)
+ final ServletContext context = getServletContext ();
final String query = req.getQueryString ();
-
- if (query==null)
+ final Map<String,List<String>> params = Utils.getParams (query);
+
+ if (params.containsKey ("help"))
{
usage (resp);
+ Shell.exit (req, context, 0);
return;
}
-
- final Map<String,List<String>> params = Utils.getParams (query);
+
final List<String> vals = params.get (null);
-
if (vals==null || vals.size ()<1 || vals.size ()>2)
{
usage (resp);
+ Shell.exit (req, context, 1);
return;
}
try
{
final int status = Integer.parseInt (vals.get (0));
if (status < 0) set (resp, resp.SC_BAD_REQUEST, "not a valid http status code: "+status); // FIXME: throw IllegalArgumentException instead (to differentiate status here vs status passed in)
void displayRow (final Connection conn, final String table, final String path, final Map<String,List<String>> params, final HttpServletResponse resp) throws IOException, SQLException
{
Log.info ("displaying row "+path+" for table "+table);
final PrintWriter out = resp.getWriter ();
final ResultSet row = getRow (conn, table, path, params.get ("id"));
final ResultSetMetaData meta = row.getMetaData ();
protected ResultSet getList (final Connection conn, final String table, final List<String> cols, final List<String> join, final List<String> where, final List<String> group, final List<String> order, final List<String> limit) throws SQLException
{
final StringBuffer stmt = new StringBuffer ("SELECT ");
if (cols!=null && !cols.isEmpty ())
{
if (cols.size ()==1 && "*".equals (cols.get (0)))
{
stmt.append ("*");
}
else
{
String sep = "";
for (final String col : cols)
{
// FIXME: this is all so hacky and brittle...
if (col.indexOf ("(")>0 || col.indexOf (" AS ")>0)
throw new SQLException ("unexpected update count for row add: "+count);
}
if (getId)
{
// FIXME: this is dangerous and not safe for concurrency
// (should be in a single transaction with the insert)
stmt = conn.prepareStatement ("SELECT MAX(id) FROM `"+table+"`");
final ResultSet id = stmt.executeQuery ();
if (id.first () && id.isLast ())
{
return id.getInt (1);
}
else
{
throw new SQLException ("zero or multiple rows returned for MAX(id)");
}
}
else
{
return null;
}
}
protected void update (final Connection conn, final String table, final String idPath, final List<String> idCols, final Map<String,String> data) throws SQLException
{
final StringBuffer sb = new StringBuffer ("UPDATE `"+table+"` SET ");