Serve JAD files OTA with PHP

November 3, 2008 on 2:14 pm | In J2ME, PHP, Uncategorized | No Comments

Some handy code to dynamtically serve JAD files for OTA installation. The below script sets the appropriate headers types, also tidies up the JAD file removing stray characters which can cause issues and setting the correct file paths internally.

Place the PH script in a root directory as serveJAD.php. Place your JAR and JAD files in a subdirectory /J2ME

Call the script by serveJAD.php?format=J2ME&file={jad minus extension} or you can use the Apache rewrite below and call as /J2ME/file.jad

ie

serveJAD.php?format=J2ME&file=game

or with Apache rewrite

/J2ME/game.jad

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?
	$format   = $_GET["format"];
	$file     = $_GET["file"].".jad";
    header("Cache-Control: no-cache, must-revalidate,no-transform" );
    header("Pragma: no-cache" );
	header("Content-type: text/vnd.sun.j2me.app-descriptor");
	header("Content-Disposition: attachment; filename=".$file.";");
	$jad = file_get_contents("./".$format."/".$file);
	$lines = explode("\n",$jad);
	$final = "";
	foreach($lines as $line){
		$line = trim($line);
		if(strlen($line)>0){
			$keypair = explode(": ",$line);
			if($keypair[0]=='MIDlet-Jar-URL' || stristr($keypair[0],"RIM-COD-URL")){
				$url = trim($keypair[1]);
				if(!stristr($url,"http:")){
					$keypair[1] = "http://".$_SERVER["HTTP_HOST"]."/$format/".$url;
				}
			}else if($keypair[0]=='MIDlet-Jar-Size'){
				$keypair[1] =  filesize("./".$format."/".$_GET["file"].".jar");
			}
 
			$line = join(": ",$keypair);
			$l = trim($line);
			if(!empty($final))$final.="\n";
			$final.=$l;
		}
	}
	print($final);
?>


RewriteEngine On
RewriteRule /J2ME/(.*)\.jad /serveJAD.php?format=J2ME&file=$1

You can also use this to build automatic index pages, using this as dir.php?format=J2ME

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
	$format   = $_GET["format"];
	$scanthis = "./".$format;
 	$scanlisting = scandir($scanthis);
    $dirlisting = array();
    foreach($scanlisting as $key => $value){
		if(stristr($value,"jad")){
			$name = explode(".",$value);
			$dirlisting[$name[0]] = $name[0];
		}
	}
	ksort($dirlisting);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="apps.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Application listing</title>
</head>
<body>
<p>
<?php foreach($dirlisting as $name){
?>
<a href="/<?php print($format);?>/<?php print($name);?>.jad"><?php print($name);?></a><br />
<?php
}
?></p>
</body>
</html>
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Google] [StumbleUpon]

Drawing filled polygons in J2ME

May 11, 2007 on 10:13 am | In J2ME, Java, Useful stuff | No Comments

Check this sourceforge project for a really useful class.

http://sourceforge.net/projects/jmicropolygon/

Works really well on most of the phones we have tried it one. Once you have this class you can then do filled and stroked thick lines in J2ME.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Google] [StumbleUpon]

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^