[icinga-checkins] icinga.org: icinga-web/jmosshammer/default: * Added module specific routing xml

git at icinga.org git at icinga.org
Sun Mar 20 11:26:10 CET 2011


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

Author: Marius Hein <marius.hein at netways.de>
Date:   Fri Feb 25 13:33:02 2011 +0100

* Added module specific routing xml

---

 app/config/config_handlers.xml                     |   11 +++++
 app/modules/AppKit/config/autoload.xml             |    6 ++-
 .../module/AppKitModuleRoutingHandler.class.php    |   26 +++++++++++++
 .../{util => module}/AppKitModuleUtil.class.php    |    8 +++-
 .../AppKit/lib/util/AppKitXmlUtil.class.php        |   40 ++++++++++++++++++++
 5 files changed, 88 insertions(+), 3 deletions(-)

diff --git a/app/config/config_handlers.xml b/app/config/config_handlers.xml
index b1885db..cfbba7a 100755
--- a/app/config/config_handlers.xml
+++ b/app/config/config_handlers.xml
@@ -1,3 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ae:configurations xmlns:ae="http://agavi.org/agavi/config/global/envelope/1.0" xmlns="http://agavi.org/agavi/config/parts/config_handlers/1.0" parent="%core.system_config_dir%/config_handlers.xml">
+
+	<ae:configuration>
+		<handlers>
+
+			<handler pattern="%core.config_dir%/routing.xml" class="AppKitModuleRoutingHandler">
+				<validation>%core.agavi_dir%/config/xsd/routing.xsd</validation>
+				<transformation>%core.agavi_dir%/config/xsl/routing.xsl</transformation>
+			</handler>
+		
+		</handlers>
+	</ae:configuration>
 </ae:configurations>
\ No newline at end of file
diff --git a/app/modules/AppKit/config/autoload.xml b/app/modules/AppKit/config/autoload.xml
index 808191d..d1fd8b9 100755
--- a/app/modules/AppKit/config/autoload.xml
+++ b/app/modules/AppKit/config/autoload.xml
@@ -85,7 +85,6 @@
 		<autoload name="JavaScriptPacker">%core.module_dir%/AppKit/lib/util/JavaScriptPacker.class.php</autoload>
 		<autoload name="JSMin">%core.module_dir%/AppKit/lib/util/JSMin.class.php</autoload>
 		<autoload name="AppKitFormatParserUtil">%core.module_dir%/AppKit/lib/util/AppKitFormatParserUtil.class.php</autoload>
-		<autoload name="AppKitModuleUtil">%core.module_dir%/AppKit/lib/util/AppKitModuleUtil.class.php</autoload>
 		<autoload name="AppKitAgaviUtil">%core.module_dir%/AppKit/lib/util/AppKitAgaviUtil.class.php</autoload>
 		<autoload name="AppKitHtmlUtil">%core.module_dir%/AppKit/lib/util/AppKitHtmlUtil.class.php</autoload>
 		<autoload name="AppKitFileUtil">%core.module_dir%/AppKit/lib/util/AppKitFileUtil.class.php</autoload>
@@ -95,5 +94,10 @@
 		<autoload name="AppKitURLFilterValidator">%core.module_dir%/AppKit/lib/validator/AppKitURLFilterValidator.class.php</autoload>
 		<autoload name="AppKitSoapFilterValidator">%core.module_dir%/AppKit/lib/validator/AppKitSoapFilterValidator.class.php</autoload>
 		
+		<!-- Module util classes -->
+		<autoload name="AppKitModuleUtil">%core.module_dir%/AppKit/lib/module/AppKitModuleUtil.class.php</autoload>
+		<autoload name="AppKitModuleRoutingHandler">%core.module_dir%/AppKit/lib/module/AppKitModuleRoutingHandler.class.php</autoload>
+		<autoload name="AppKitXmlUtil">%core.module_dir%/AppKit/lib/util/AppKitXmlUtil.class.php</autoload>
+		
 	</ae:configuration>
 </ae:configurations>
diff --git a/app/modules/AppKit/lib/module/AppKitModuleRoutingHandler.class.php b/app/modules/AppKit/lib/module/AppKitModuleRoutingHandler.class.php
new file mode 100644
index 0000000..7a77b29
--- /dev/null
+++ b/app/modules/AppKit/lib/module/AppKitModuleRoutingHandler.class.php
@@ -0,0 +1,26 @@
+<?php
+
+class AppKitModuleRoutingHandler extends AgaviRoutingConfigHandler {
+	
+	const ENTRY_XPATH = '//ae:configurations/ae:configuration[@context=\'web\']/routing:routes/routing:route[@name=\'modules\']';
+	
+	public function execute(AgaviXmlConfigDomDocument $document) {
+		
+		// set up our default namespace
+		$document->setDefaultNamespace(self::XML_NAMESPACE, 'routing');
+		
+		AppKitXmlUtil::includeXmlFilesToTarget(
+			$document, 
+			self::ENTRY_XPATH, 
+			'xmlns(ae=http://agavi.org/agavi/config/global/envelope/1.0) xmlns(r=http://agavi.org/agavi/config/parts/routing/1.0) xpointer(//ae:configurations/ae:configuration/r:routes/node())',
+			AppKitModuleUtil::getInstance()->getSubConfig('agavi.include_xml.routing')
+			);
+		
+		$document->xinclude();
+			
+		return parent::execute($document);
+	}
+		
+}
+
+?>
\ No newline at end of file
diff --git a/app/modules/AppKit/lib/util/AppKitModuleUtil.class.php b/app/modules/AppKit/lib/module/AppKitModuleUtil.class.php
similarity index 96%
rename from app/modules/AppKit/lib/util/AppKitModuleUtil.class.php
rename to app/modules/AppKit/lib/module/AppKitModuleUtil.class.php
index 91dd55a..339e95c 100644
--- a/app/modules/AppKit/lib/util/AppKitModuleUtil.class.php
+++ b/app/modules/AppKit/lib/module/AppKitModuleUtil.class.php
@@ -11,13 +11,17 @@ class AppKitModuleUtil extends AppKitSingleton {
 	const DATA_FLAT			= 'flat';
 	const DATA_DEFAULT		= 'default';
 	const DATA_UNIQUE		= 'unique';
+	const DATA_ARRAY		= 'array';
 
 	protected static $default_config_keys = array (
 		'app.javascript_files'		=> self::DATA_FLAT,
 		'app.javascript_actions'	=> self::DATA_DEFAULT,
 		'app.javascript_dynamic'	=> self::DATA_UNIQUE,
 		'app.css_files'				=> self::DATA_FLAT,
-		'app.meta_tags'				=> self::DATA_DEFAULT
+		'app.meta_tags'				=> self::DATA_DEFAULT,
+	
+		// Namespaces for XML includes
+		'agavi.include_xml.routing'	=> self::DATA_FLAT	
 	);
 
 	private $modules = null;
@@ -98,7 +102,6 @@ class AppKitModuleUtil extends AppKitSingleton {
 		$out = array ();
 		foreach ($this->getValidConfigNamespaces() as $ns) {
 			$test = $ns. '.'. $subkey;
-
 			if (($data = AgaviConfig::get($test, false)) !== false) {
 				$out[$subkey][isset($this->s_modnames[$ns]) ? $this->s_modnames[$ns] : $ns] = $data;
 			}
@@ -135,6 +138,7 @@ class AppKitModuleUtil extends AppKitSingleton {
 		$rq = $container->getContext()->getRequest();
 
 		foreach (self::$default_config_keys as $subkey=>$subtype) {
+			
 			$data = $this->getSubConfig($subkey, $subtype);
 			
 			if (isset($data)) {
diff --git a/app/modules/AppKit/lib/util/AppKitXmlUtil.class.php b/app/modules/AppKit/lib/util/AppKitXmlUtil.class.php
new file mode 100644
index 0000000..ad78a61
--- /dev/null
+++ b/app/modules/AppKit/lib/util/AppKitXmlUtil.class.php
@@ -0,0 +1,40 @@
+<?php
+
+class AppKitXmlUtil {
+	
+	
+	/**
+	 * @param AgaviXmlConfigDomDocument $document
+	 * @param string $query
+	 * @return DOMNodeList
+	 */
+	public static function extractEntryNode(AgaviXmlConfigDomDocument $document, $query) {
+		$list = $document->getXPath()->query($query);
+		
+		if ($list instanceof DOMNodeList && $list->length==1) {
+			return $list->item(0);
+		}
+	}
+	
+	public static function createXIncludeNode(AgaviXmlConfigDomDocument $document, $file, $pointer) {
+		$element = $document->createElementNS('http://www.w3.org/2001/XInclude', 'xi:include');
+		
+		$element->setAttribute('href', $file);
+		$element->setAttribute('xpointer', $pointer);
+		
+		return $element;
+	}
+	
+	public static function includeXmlFilesToTarget(AgaviXmlConfigDomDocument $document, $query, $pointer, array $files) {
+		$targetNode = self::extractEntryNode($document, $query);
+		
+		
+		foreach ($files as $file) {
+			$node = self::createXIncludeNode($document, $file, $pointer);
+			$targetNode->appendChild($node);
+		}
+	}
+	
+}
+
+?>
\ No newline at end of file





More information about the icinga-checkins mailing list