echo REST::html_start('Metadata for handle ' . htmlspecialchars($handle->handle(), ENT_COMPAT, 'UTF-8'));
        echo <<<EOS
<table class="handledata"><tbody><tr>
<th class="idx">idx</th>
<th class="type">type</th>
<th class="data">data</th>
<th class="data">refs</th>
<th class="modified">timestamp</th>
</tr>
EOS;
        foreach ($handle->type as $idx => $type) {
            if (strpos($type, 'HS_') === 0) {
                continue;
            }
            echo '<tr><td class="idx">' . $idx . '</td><td class="type">' . htmlspecialchars($type, ENT_COMPAT, 'UTF-8') . '</td><td class="data">';
            if ($type == 'URL' && REST::isValidURI($handle->data[$idx])) {
                echo '<a href="' . $handle->data[$idx] . '">' . htmlspecialchars($handle->data[$idx]) . '</a>';
            } elseif ($type == 'EMAIL') {
                echo '<a href="mailto:' . $handle->data[$idx] . '">' . htmlspecialchars($handle->data[$idx]) . '</a>';
            } else {
                echo $handle->data[$idx] === mb_convert_encoding(mb_convert_encoding($handle->data[$idx], 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32') ? htmlspecialchars($handle->data[$idx], ENT_COMPAT, 'ISO-8859-1') : '<pre>' . htmlspecialchars(addcslashes($handle->data[$idx], "\\..\t\v....ÿ"), ENT_COMPAT, 'ISO-8859-1') . '</pre>';
            }
            echo '</td><td class="refs">' . htmlspecialchars($handle->refs[$idx]) . '</td><td class="modified">' . REST::http_date($handle->timestamp[$idx]) . "</td></tr>\n";
        }
        echo '</tbody></table>' . REST::html_end();
    } elseif ($content_type == 'application/json') {
        $json = array();
        foreach ($handle->type as $idx => $type) {
            if (strpos($type, 'HS_') !== 0) {
                // Was: $type != 'HS_ADMIN'
                $json[$idx] = array('type' => (string) $type, 'data' => (string) $handle->data[$idx], 'timestamp' => (int) $handle->timestamp[$idx], 'refs' => (string) $handle->refs[$idx]);
$appversion = @$path_info[1];
$portlet = Portal_App::factory($appname, $appversion);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $user_id = Portal_User::current()->user_id();
    $applicationURL = "http://{$_SERVER['SERVER_NAME']}/gridapps/{$appname}-{$appversion}.tgz";
    $TEMPNAM = tempnam('/tmp', 'portal_');
    register_shutdown_function('myRemoveTempFiles');
    $sandbox = "{$TEMPNAM}.d/";
    mkdir($sandbox);
    $bashcode = $database = '';
    $portlet->doPOST($sandbox, $bashcode, $database);
    if (substr($database, 0, 1) === '/') {
        $database = REST::urlbase() . $database;
    }
    $database = str_replace(REST::urlbase(), 'https://' . $_SERVER['SERVER_NAME'] . ':' . Portal::PORT_SSL_CSA, $database);
    if (!empty($database) && !REST::isValidURI($database)) {
        REST::fatal(REST::HTTP_BAD_REQUEST, "{$database} is not a valid URL.");
    }
    $escdatabase = escapeshellarg($database);
    file_put_contents($sandbox . 'run.sh', <<<EOS
#!/bin/bash

DATABASE={$escdatabase}
APPLICATION='{$applicationURL}'
USER_ID={$user_id}

function runJob() (
{$bashcode}
)

EOS