public function executeJson(AgaviRequestDataHolder $rd)
 {
     try {
         $modules = AgaviConfig::get("org.icinga.modules", array());
         $fileName = $rd->getParameter('template');
         $file = null;
         foreach ($modules as $name => $path) {
             if (file_exists($path . "/config/templates/" . $fileName . '.xml')) {
                 $file = AppKitFileUtil::getAlternateFilename($path . "/config/templates/", $fileName, '.xml');
             }
         }
         if ($file === null) {
             $file = AppKitFileUtil::getAlternateFilename(AgaviConfig::get('modules.cronks.xml.path.grid'), $rd->getParameter('template'), '.xml');
         }
         $template = new CronkGridTemplateXmlParser($file->getRealPath());
         $template->parseTemplate();
         $user = $this->getContext()->getUser()->getNsmUser();
         $data = $template->getTemplateData();
         if ($user->hasTarget('IcingaCommandRestrictions')) {
             $template->removeRestrictedCommands();
         }
         return json_encode(array('template' => $template->getTemplateData(), 'fields' => $template->getFields(), 'keys' => $template->getFieldKeys(), 'params' => $rd->getParameters(), 'connections' => IcingaDoctrineDatabase::$icingaConnections));
     } catch (AppKitFileUtilException $e) {
         $msg = 'Could not find template for ' . $rd->getParameter('template');
         AppKitAgaviUtil::log('Could not find template for ' . $rd->getParameter('template'), AgaviLogger::ERROR);
         return $msg;
     }
 }
 public function execute(AgaviXmlConfigDomDocument $document)
 {
     $code = array();
     $parser = new CronkGridTemplateXmlParser();
     $parser->disableCache();
     $templates = $document->getElementsByTagName("template");
     foreach ($templates as $extension) {
         $attrs = $extension->attributes;
         $pattern = $attrs->getNamedItem('match-pattern');
         if (!$pattern) {
             continue;
         }
         // we don't have a dtd, so this can happen
         $parser->setDom($extension);
         $parser->parseTemplate(true);
         $code[] = array("pattern" => $pattern->value, "data" => $parser->getTemplateData(), "fields" => $parser->getFields());
     }
     return $this->generate('return ' . var_export($code, true));
 }