[icinga-checkins] icinga.org: icinga-web/jmosshammer/default: * Added patch to using xslt files for api queries (rest)

git at icinga.org git at icinga.org
Tue Nov 9 11:32:27 CET 2010


Module: icinga-web
Branch: jmosshammer/default
Commit: 0475bf3ea0edd62904f5a51c2feb22091b5ef8be
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=0475bf3ea0edd62904f5a51c2feb22091b5ef8be

Author: Marius Hein <marius.hein at netways.de>
Date:   Mon Oct 25 16:15:00 2010 +0200

* Added patch to using xslt files for api queries (rest)
* Thanks to William Preston

---

 app/config/output_types.xml                        |    6 +++++
 app/config/routing.xml                             |    2 +-
 app/modules/Web/data/results.xslt                  |   21 ++++++++++++++++++++
 .../Web/views/Icinga/ApiSearchErrorView.class.php  |   13 ++++++++++-
 .../views/Icinga/ApiSearchSuccessView.class.php    |   19 +++++++++++++++++-
 5 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/app/config/output_types.xml b/app/config/output_types.xml
index 3327114..0259974 100755
--- a/app/config/output_types.xml
+++ b/app/config/output_types.xml
@@ -129,6 +129,12 @@
 				</ae:parameter>
 			</output_type>
 			
+			<output_type name="rest">
+				<ae:parameter name="http_headers">
+					<ae:parameter name="Content-Type">text/plain; charset=UTF-8</ae:parameter>
+				</ae:parameter>
+			</output_type>
+			
 			<output_type name="image">
 				<ae:parameter name="http_headers">
 					<!--  <ae:parameter name="Content-Type">text/x-json; charset=UTF-8</ae:parameter> -->
diff --git a/app/config/routing.xml b/app/config/routing.xml
index 13774d7..603c8e0 100755
--- a/app/config/routing.xml
+++ b/app/config/routing.xml
@@ -125,7 +125,7 @@
 						<route name=".limit" stop="false" pattern="limit[({limit_start:\d*};)?(limit:\d*)]"/>												
 						<route name=".countcolumn" stop="false" pattern="countColumn=(countColumn:\w*)"/>
 						<route name=".withMeta" stop="false" pattern="withMeta=(withMeta:\d)"/>
-						<route name=".output" stop="true" pattern="(output:json|xml|soap)$" output_type="${output}">
+						<route name=".output" stop="true" pattern="(output:json|xml|soap|rest)$" output_type="${output}">
 						<ignores>
 							<ignore>output</ignore>
 						</ignores>
diff --git a/app/modules/Web/data/results.xslt b/app/modules/Web/data/results.xslt
new file mode 100644
index 0000000..ebd6ce1
--- /dev/null
+++ b/app/modules/Web/data/results.xslt
@@ -0,0 +1,21 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:output method="xml" omit-xml-declaration="yes"/>
+<xsl:template match="/">
+<xsl:for-each select="results/result">
+<xsl:for-each select="column">
+<xsl:value-of select="@name"/>: <xsl:value-of select="."/>
+<xsl:text disable-output-escaping="yes">
+<br/>
+</xsl:text>
+</xsl:for-each>
+<xsl:if test="position() != last()">
+<xsl:text>
+
+--
+
+</xsl:text>
+</xsl:if>
+</xsl:for-each>
+</xsl:template>
+</xsl:stylesheet>
+
diff --git a/app/modules/Web/views/Icinga/ApiSearchErrorView.class.php b/app/modules/Web/views/Icinga/ApiSearchErrorView.class.php
index 2ae2949..b020bed 100755
--- a/app/modules/Web/views/Icinga/ApiSearchErrorView.class.php
+++ b/app/modules/Web/views/Icinga/ApiSearchErrorView.class.php
@@ -20,12 +20,21 @@ class Web_Icinga_ApiSearchErrorView extends IcingaWebBaseView
 
 	public function executeXml(AgaviRequestDataHolder $rd) 
 	{
-		
-		echo "<?xml version='1.0' encoding='utf-8'><error><message>Invalid arguments!</message></error>";
+		echo "<?xml version='1.0' encoding='utf-8'?>";
+		$validation = $this->getContainer()->getValidationManager();
+		foreach($validation->getErrorMessages() as $error) {
+			echo "<error><message>".$error['message']."</message></error>";
+		}
 	}
 
 	public function executeSimple(AgaviRequestDataHolder $rd) 
 	{
 		echo "Invalid arguments";
 	}
+
+
+	public function executeRest(AgaviRequestDataHolder $rd) 
+	{
+		echo "Invalid arguments";
+	}
 }
\ No newline at end of file
diff --git a/app/modules/Web/views/Icinga/ApiSearchSuccessView.class.php b/app/modules/Web/views/Icinga/ApiSearchSuccessView.class.php
index 019a85d..ada93cd 100755
--- a/app/modules/Web/views/Icinga/ApiSearchSuccessView.class.php
+++ b/app/modules/Web/views/Icinga/ApiSearchSuccessView.class.php
@@ -51,7 +51,7 @@ class Web_Icinga_ApiSearchSuccessView extends IcingaWebBaseView
 		return $metaData;
 	}
 	
-	public function executeXml(AgaviRequestDataHolder $rd) 
+	protected function createDOM(AgaviRequestDataHolder $rd) 
 	{
 		$results = $rd->getParameter("searchResult",null);
 		$count = $rd->getParameter("searchCount");
@@ -77,9 +77,26 @@ class Web_Icinga_ApiSearchSuccessView extends IcingaWebBaseView
 			$node->nodeValue = $count[0];
 			$root->appendChild($node);
 		}
+		return $DOM;
+	}
+
+	public function executeXml(AgaviRequestDataHolder $rd) 
+	{
+		$DOM = $this->createDOM($rd);
 		return $DOM->saveXML();
 	}
 
+	public function executeRest(AgaviRequestDataHolder $rd) 
+	{
+		$xml = $this->createDOM($rd);
+		$xsltproc = new XSLTProcessor();
+		$xsl = new DOMDocument();
+		$xsl->load(AgaviConfig::get('core.module_dir').'/Web/data/results.xslt');
+		$xsltproc->importStylesheet($xsl);
+		$result = $xsltproc->transformToXML($xml);
+		return $result;
+	}
+
 	public function executeSimple(AgaviRequestDataHolder $rd) 
 	{
 		





More information about the icinga-checkins mailing list