瀏覽代碼

added parse ant -p for main templates; added output type XML or HTML

Piotr Labudda 9 年之前
父節點
當前提交
786d2fa0d1

+ 52 - 2
SE/schema/ant-url_action/default_db.in7_dziennik_koresp/test-get-wfs-xml/build.xml

@@ -1,5 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project basedir="." name="example wfs GetFeature" default="http_first_input">
+<project basedir="." name="example wfs" default="http_first_input">
+  <description>
+    Test WFS actions for given featureID
+  </description>
 
     <!-- file:/SE/schema/ant-url_action/default_db.in7_dziennik_koresp/test-get-wfs-xml/build.xml -->
 
@@ -21,9 +24,56 @@
 
     <target name="http_first_input">
         <exec executable="curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result">
-            <arg line="-H 'Authorization: Basic ${passwordBase64Basic}' ${url}"/>
+            <arg line="-H 'Authorization: Basic ${passwordBase64Basic}' ${url}&amp;REQUEST=GetFeature"/>
         </exec>
         <echo message="curl -H 'Authorization: Basic ${passwordBase64Basic}' '${url}'"/>
+        <echo message="OUTPUT__TYPE__XML"/>
+        <echo message="OUTPUT__START"/>
+        <echo message="${wfs_output}"/>
+
+        <echo message="webRootUrl"></echo>
+        <echo message="${webRootUrl}"></echo>
+
+        <echo message="OUTPUT__END"/>
+
+        <echo message="RESULT__START"/>
+        <echo message="${wfs_result}"/>
+        <echo message="RESULT__END"/>
+
+        <echo message="ERROR__START"/>
+        <echo message="${wfs_error}"/>
+        <echo message="ERROR__END"/>
+    </target>
+
+    <target name="DescribeFeatureType" description="URL_TASK Target DescribeFeatureType">
+        <exec executable="curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result">
+            <arg line="-H 'Authorization: Basic ${passwordBase64Basic}' ${url}&amp;REQUEST=DescribeFeatureType"/>
+        </exec>
+        <echo message="curl -H 'Authorization: Basic ${passwordBase64Basic}' '${url}'"/>
+        <echo message="OUTPUT__TYPE__XML"/>
+        <echo message="OUTPUT__START"/>
+        <echo message="${wfs_output}"/>
+
+        <echo message="webRootUrl"></echo>
+        <echo message="${webRootUrl}"></echo>
+
+        <echo message="OUTPUT__END"/>
+
+        <echo message="RESULT__START"/>
+        <echo message="${wfs_result}"/>
+        <echo message="RESULT__END"/>
+
+        <echo message="ERROR__START"/>
+        <echo message="${wfs_error}"/>
+        <echo message="ERROR__END"/>
+    </target>
+
+    <target name="GetFeature" description="URL_TASK Target GetFeature">
+        <exec executable="curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result">
+            <arg line="-H 'Authorization: Basic ${passwordBase64Basic}' ${url}&amp;REQUEST=GetFeature"/>
+        </exec>
+        <echo message="curl -H 'Authorization: Basic ${passwordBase64Basic}' '${url}'"/>
+        <echo message="OUTPUT__TYPE__XML"/>
         <echo message="OUTPUT__START"/>
         <echo message="${wfs_output}"/>
 

+ 53 - 4
SE/se-lib/Route/Ant.php

@@ -24,6 +24,8 @@ class Route_Ant extends RouteBase {
   public $pathTools = APP_PATH_SCHEMA . "/ant-tool/";
   public $pathUrlActions = APP_PATH_SCHEMA . "/ant-url_action/";
   public $antBin = APP_PATH_WWW . DS . 'stuff' . DS . 'dita-ot-2.3.3' . DS . 'bin' . DS . 'ant';
+  public $_antUrlProjects = [];// path => label
+  public $_antUrlProjectTemplates = [];// path => [ template => label ]
 
   public function defaultAction() {
     UI::gora();
@@ -79,8 +81,9 @@ class Route_Ant extends RouteBase {
   //
 
   public function getAntUrlActionList() {
+    if (!empty($this->_antUrlProjects)) return $this->_antUrlProjects;
     V::exec("ls -1 {$this->pathUrlActions}*/*/build.xml", $out, $ret);
-    $taskList = array();
+    $this->_antUrlProjects = array();
     foreach ($out as $line) {
       try {
         if ($this->pathUrlActions != substr($line, 0, strlen($this->pathUrlActions))) throw new Exception("Wrong line prefix '{$line}' - skip");
@@ -90,10 +93,56 @@ class Route_Ant extends RouteBase {
         continue;
       }
       $line = substr($line, strlen($this->pathUrlActions));
-      $name = substr($line, 0, -1 * strlen('/build.xml'));
-      $taskList[$name] = $name;// TODO: $name => $description (read from build.xml file first xml tag <project...>)
+      $path = substr($line, 0, -1 * strlen('/build.xml'));
+      $this->_antUrlProjects[$path] = $path;
+      try {
+        V::exec("cd {$this->pathUrlActions}/{$path} && ant -p|grep -v '^Unable to locate'|grep -v '^Buildfile:'", $out, $ret);
+        // Test WFS for actions given featureID   // TODO: first line - project description
+        // Main targets:
+        //
+        //  DescribeFeatureType  URL_TASK Target DescribeFeatureType
+        //  GetFeature           URL_TASK Target GetFeature
+        // Default target: http_first_input
+        if (!empty($out)) {
+          $projectDesc = '';
+          $templates = [];
+          $state = 'projectDesc';// 'projectDesc', 'Main targets', 'Default target'
+          foreach ($out as $line) {
+            switch ($state) {
+              case 'projectDesc': {
+                if ('Main targets' == substr($line, 0, strlen('Main targets'))) {
+                  $state = 'Main targets';
+                } else {
+                  $line = trim($line);
+                  if (!$projectDesc && $line) $projectDesc = $line;
+                }
+              } break;
+              case 'Main targets': {
+                if (false !== ($pos = strpos($line, 'URL_TASK'))) {
+                  $templateName = trim(substr($line, 0, $pos));
+                  $label = trim(substr($line, $pos + 9));
+                  if (!empty($templateName)) $templates[$templateName] = (!empty($label)) ? $label : $templateName;
+                }
+                if ('Default target' == substr($line, 0, strlen('Default target'))) {
+                  $state = 'Default target';
+                }
+              } break;
+            }
+          }
+          if (!empty($projectDesc)) $this->_antUrlProjects[$path] = $projectDesc;
+          if (!empty($templates)) foreach ($templates as $t => $l) $this->_antUrlProjectTemplates[$path][$t] = $l;
+        }
+      } catch (Exception $e) {
+        DBG::log($e);
+      }
     }
-    return $taskList;
+    DBG::log((array)$this, 'array', "Ant projects and main targets");
+    return $this->_antUrlProjects;
+  }
+  public function getAntUrlActionTemplates($path) {
+    if (!empty($this->_antUrlProjectTemplates[$path])) return $this->_antUrlProjectTemplates[$path];
+    $this->getAntUrlActionList();
+    if (!empty($this->_antUrlProjectTemplates[$path])) return $this->_antUrlProjectTemplates[$path];
   }
   public function getAntToolList() {
     V::exec("ls -1 {$this->pathTools}*/build.xml", $out, $ret);

+ 29 - 3
SE/se-lib/Route/UrlAction/Ant.php

@@ -37,6 +37,7 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
       foreach ($taskList as $path => $label) {
         echo UI::h('li', [], [
           UI::h('a', [
+            'class' => 'btn btn-md btn-link',
             'href' => $this->getLink('ant', [
               'path' => $path,
               'typeName' => $typeName,
@@ -45,6 +46,23 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
             ])
           ], "Uruchom '{$label}'")
         ]);
+        $tmpls = $this->getAntUrlActionTemplates($path);
+        if (!empty($tmpls)) {
+          foreach ($tmpls as $tmpl => $labelTmpl) {
+            echo UI::h('div', [ 'style' => "padding-left: 50px" ], [
+              UI::h('a', [
+                'href' => $this->getLink('ant', [
+                  'path' => $path,
+                  'template' => $tmpl,
+                  'typeName' => $typeName,
+                  'primaryKey' => $primaryKey,
+                  'primaryKeyField' => $pkField
+                ]),
+                'class' => 'btn btn-sm btn-link',
+              ], '<i class="glyphicon glyphicon-arrow-right"></i> ' . $labelTmpl)
+            ]);
+          }
+        }
       }
       UI::endTag('ul');
     } catch (Exception $e) {
@@ -82,6 +100,7 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
       DBG::log($parsedInfo, '', "Ant parseTypeName({$typeName})");
       $nsPrefix = $parsedInfo['prefix'];
       $objectName = $parsedInfo['name'];
+      $template = V::get('template', '', $_GET);
 
       // TODO: validate missing ...
       DBG::log($_GET, 'array', '$_GET');
@@ -103,7 +122,7 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
       $outputFunctionUrl = $this->getLink('output') . "&path={$path}&file=";
       DBG::log([ 'msg'=>'$webRootUrl', '$webRootUrl'=>$webRootUrl]);
       DBG::log([ 'msg'=>'$outputFunctionUrl', '$outputFunctionUrl'=>$outputFunctionUrl]);
-      $testUrl = Request::getPathUri() . "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME={$typeName}&SRSNAME=EPSG:3003&featureID={$objectName}.{$primaryKey}";
+      $testUrl = Request::getPathUri() . "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&TYPENAME={$typeName}&SRSNAME=EPSG:3003&featureID={$objectName}.{$primaryKey}";// &REQUEST=GetFeature
       $cryptedPass = base64_encode(User::getLogin() . ":" . Crypt::decrypt($_SESSION['ADM_PASS_HASH']));
       $uniqID = session_id();// TODO: uniq id for every request
       // $cmd = "{$this->pathUrlActions}{$path}/do_build.sh";
@@ -116,6 +135,7 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
       $cmd .= " -Dxpath={$pkField}";
       $cmd .= " -Dxpath_value={$primaryKey}";
       $cmd .= " -DtypeName=\"{$typeName}\"";
+      if ($template) $cmd .= " {$template} ";
       $cmd .= " 2>&1";
 
       $pathCmd = [];
@@ -141,9 +161,12 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
       if (empty($out)) throw new Exception("Empty output");
       if ($useShellExec) $out = explode("\n", $out);
 
+      $outputType = 'HTML';
       $html = []; $startRead = false;
       foreach ($out as $line) {
         if (!$startRead) {
+          if ('OUTPUT__TYPE__XML' == $line) $outputType = 'XML';
+          if ('OUTPUT__TYPE__HTML' == $line) $outputType = 'HTML';
           if ('OUTPUT__START' == $line) {
             $startRead = true;
             continue;
@@ -158,8 +181,11 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
       }
       if (empty($html)) UI::alert('danger', "Empty output!");
       else {
-        // echo UI::h('pre', [], htmlspecialchars(implode("\n", $html)));
-        echo UI::h('div', ['class'=>"container", 'style'=>"padding:12px; border:1px solid #ddd"], $html);
+        if ('XML' == $outputType) {
+          echo UI::h('pre', [], htmlspecialchars(implode("\n", $html)));
+        } else if ('HTML' == $outputType) {
+          echo UI::h('div', ['class'=>"container", 'style'=>"padding:12px; border:1px solid #ddd"], $html);
+        }
       }
     } catch (Exception $e) {
       UI::alert('danger', $e->getMessage());