3rd party Extensions

e.g. Flash FIXME

app.properties.extensions

demoExtensions.zip

 
### mysql.sql ### 
 
CREATE DATABASE demoSessionUser; 
USE demoSessionUser; 
 
GRANT ALL ON demoSessionUser.* TO helma@localhost IDENTIFIED BY 'secret'; 
 
CREATE TABLE tb_user ( 
  user_id MEDIUMINT(10) NOT NULL, 
  user_name TINYTEXT, 
  user_password TINYTEXT, 
  PRIMARY KEY (user_id) 
); 
 
INSERT INTO tb_user values (1, "michi", "ihcim"); 
INSERT INTO tb_user values (2, "matthias", "saihttam"); 
INSERT INTO tb_user values (3, "dieter", "reteid"); 
INSERT INTO tb_user values (4, "hannes", "sennah"); 


### app.properties ### 
 
XmlRpcAccess = api.demoXmlRpcServer 
XmlRpcHandlerName = *  

 
### db.properties ### 
 
jad.url      = jdbc:mysql://localhost/demoSessionUser 
jad.driver   = com.mysql.jdbc.Driver 
jad.user     = helma 
jad.password = secret 
 
 
### static/foto.jpg ### 
-> put any king of image here 
 
 
### Root/type.properties ### 
 
api = mountpoint(Api) 
 
 
### Api/functions.js ### 
 
function demoXmlRpcServer() { 
   return "HELLO WORLD!"; 
} 
 
 
### Root/functions.js ### 
 
function main_action() { 
   return; 
} 
 
 
// make sure that you start Helma with enabled XML-RPC-Port at 8081 
// and that you have the following two lines in app.properties: 
//   XmlRpcAccess = api.demoXmlRpcServer 
//   XmlRpcHandlerName = * 
function demoXmlRpcClient_action() { 
   var client = new Remote("http://betty.userland.com/RPC2"); 
   var i = 12; 
   var obj = client.examples.getStateName(i); 
   if (!obj.error) { 
      res.writeln(i + ": " + obj.result); 
   } else { 
      res.debug(obj.error); 
   } 
   res.writeln("-----------------------"); 
   var client = new Remote("http://localhost:8081/"); 
   var obj = client.api.demoXmlRpcServer(i); 
   if (!obj.error) { 
      res.writeln(obj.result); 
   } else { 
      res.debug(obj.error); 
   } 
} 
 
 
function demoDB_action() { 
   var dbc = getDBConnection("jad"); 
   var sql = "SELECT * from tb_user"; 
   var rows = dbc.executeRetrieval(sql); 
   if (rows) { 
      while (rows.next()) { 
         var userId = rows.getColumnItem("user_id"); 
         res.writeln(userId + ": " + rows.getColumnItem("user_name")); 
      } 
      rows.release(); 
      var sql = "INSERT into tb_user values (" + (userId+1) + ", \"joe" + (userId+1) + "\", \"secret\")"; 
      var i = dbc.executeCommand(sql); 
      if (i > 0) { 
         res.writeln("Inserted new User " + i); 
      } else { 
         res.debug(dbc.getLastError()); 
      } 
   } else { 
      res.debug(dbc.getLastError()); 
   } 
 
   dbc.release(); 
   return; 
} 
 
 
function demoFtp_action() { 
   // FIXME 
   return; 
} 
 
 
function demoXml_action() { 
   res.contentType = "text/plain"; 
   var obj = new HopObject(); 
      obj.name = "michi"; 
      obj.height = 180; 
   res.write(uneval(obj)); 
   res.write("\n-----------------\n"); 
 
   var str = Xml.writeToString(obj) 
   res.write(str); 
   res.write("\n-----------------\n"); 
 
   var obj2 = Xml.readFromString(str); 
   obj2.height++; 
   res.write(uneval(obj2)); 
   res.write("\n-----------------\n"); 
} 
 
 
function demoImage_action() { 
   var staticDir = new File(app.dir, "static"); 
   var img = new Image(staticDir.getAbsolutePath() + "/foto.jpg"); 
   var w = img.getWidth(); 
   var h = img.getHeight(); 
   res.writeln("Image Original: " + w + "x" + h); 
   img.resize(parseInt(w/2), parseInt(h/2)); 
   img.saveAs(staticDir + "/foto_small.jpg"); 
   img.dispose(); 
   res.write("<img src=/static/justademo/foto_small.jpg>"); 
} 
 
 
function demoMail_action() { 
   var m = new Mail(); 
   m.addTo("michi@knallgrau.at", "michi"); 
   m.setFrom("bill@microsoft.com", "Bill Gates"); 
   m.setSubject("MS Office for free $$"); 
   m.addText("Wow! This is so incredible."); 
   var f = new java.io.File(app.dir, "test.txt"); 
   if (f.exists()) m.addPart(f); 
   m.send(); 
   if (m.status == 0) { 
      res.write("Mail OK"); 
   } else { 
      res.write("Error occurred! Make sure that you set smtp in your app.properties correctly!" + m.status); 
   } 
   return; 
} 
 
 
function demoFile_action() { 
   var dir = new File(app.dir); 
   var files = dir.list(); 
   for (var i in files) { 
      var f = new File(dir, files[i]); 
      if (f.isFile()) { 
         res.writeln("File " + f.getName()); 
      } else { 
         res.writeln("Dir " + f.getName()); 
      } 
   } 
   res.write("<hr>"); 
   var staticDir = new File(dir, "static"); 
   if (staticDir.exists() == false) staticDir.mkdir(); 
   var f = new File(staticDir + "/test.txt"); 
   res.writeln("File:" + f.getAbsolutePath()); 
   if (f.exists()) { 
      res.writeln("Read and remove " + f.getName()); 
      res.write(format(f.readAll())); 
      f.remove(); 
   } else { 
      f.open(); 
      var nr = 10; 
      for (var i=0; i<nr; i++) { 
         f.writeln("Line " + i); 
      } 
      f.close(); 
      res.writeln("Wrote " + nr + " lines to " + f.getName()); 
   } 
   return; 
}