Changeset 2641

Show
Ignore:
Timestamp:
08/01/08 13:06:36 (5 months ago)
Author:
impl
Message:

branches/david-xml_only_config_system (refs #519): introduce annotation namespace for internal matched attribute; refactoring

Location:
branches/david-xml_only_config_system/src/config
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • branches/david-xml_only_config_system/src/config/AgaviConfigCache.class.php

    r2634 r2641  
    112112        $data = $handler->execute($doc); 
    113113      } catch(AgaviException $e) { 
    114         throw new $e(sprintf("Compliation of configuration file '%s' failed for the following reason(s):\n\n%s", $config, $e->getMessage())); 
     114        throw new $e(sprintf("Compilation of configuration file '%s' failed for the following reason(s):\n\n%s", $config, $e->getMessage())); 
    115115      } 
    116116    } else { 
  • branches/david-xml_only_config_system/src/config/AgaviConfigParser.class.php

    r2632 r2641  
    8484  { 
    8585    foreach($nodes as $node) { 
    86       if($node->nodeType == XML_ELEMENT_NODE && (!$node->namespaceURI || $node->namespaceURI == AgaviXmlConfigParser::AGAVI_ENVELOPE_NAMESPACE_0_11)) { 
     86      if($node->nodeType == XML_ELEMENT_NODE && (!$node->namespaceURI || $node->namespaceURI == AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_0_11)) { 
    8787        $vh = new AgaviConfigValueHolder(); 
    8888        $nodeName = $this->convertEncoding($node->localName); 
     
    9191 
    9292        foreach($node->attributes as $attribute) { 
    93           if((!$attribute->namespaceURI || $attribute->namespaceURI == AgaviXmlConfigParser::AGAVI_ENVELOPE_NAMESPACE_0_11)) { 
     93          if((!$attribute->namespaceURI || $attribute->namespaceURI == AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_0_11)) { 
    9494            $vh->setAttribute($this->convertEncoding($attribute->localName), $this->convertEncoding($attribute->nodeValue)); 
    9595          } 
  • branches/david-xml_only_config_system/src/config/AgaviFactoryConfigHandler.class.php

    r2633 r2641  
    3333class AgaviFactoryConfigHandler extends AgaviXmlConfigHandler 
    3434{ 
    35   const NAMESPACE = 'http://agavi.org/agavi/config/factories/1.0'; 
     35  const NAMESPACE = 'http://agavi.org/agavi/config/item/factories/1.0'; 
    3636   
    3737  /** 
  • branches/david-xml_only_config_system/src/config/AgaviXmlConfigParser.class.php

    r2634 r2641  
    3232class AgaviXmlConfigParser 
    3333{ 
    34   const AGAVI_ENVELOPE_NAMESPACE_0_11 = 'http://agavi.org/agavi/1.0/config'; 
    35    
    36   const AGAVI_ENVELOPE_NAMESPACE_1_0 = 'http://agavi.org/agavi/config/1.0'; 
    37    
    38   const AGAVI_ENVELOPE_NAMESPACE_LATEST = self::AGAVI_ENVELOPE_NAMESPACE_1_0; 
     34  const NAMESPACE_AGAVI_ENVELOPE_0_11 = 'http://agavi.org/agavi/1.0/config'; 
     35   
     36  const NAMESPACE_AGAVI_ENVELOPE_1_0 = 'http://agavi.org/agavi/config/envelope/1.0'; 
     37   
     38  const NAMESPACE_AGAVI_ENVELOPE_LATEST = self::NAMESPACE_AGAVI_ENVELOPE_1_0; 
     39   
     40  const NAMESPACE_AGAVI_ANNOTATION_1_0 = 'http://agavi.org/agavi/config/annotation/1.0'; 
     41   
     42  const NAMESPACE_AGAVI_ANNOTATION_LATEST = self::NAMESPACE_AGAVI_ANNOTATION_1_0; 
    3943   
    4044  const VALIDATION_TYPE_XMLSCHEMA = 'xml_schema'; 
     
    4448  const VALIDATION_TYPE_SCHEMATRON = 'schematron'; 
    4549   
    46   const SCHEMATRON_ISO_NAMESPACE = 'http://purl.oclc.org/dsdl/schematron'; 
    47    
    48   const SVRL_ISO_NAMESPACE = 'http://purl.oclc.org/dsdl/svrl'; 
    49    
    50   const XSL_NAMESPACE_1999 = 'http://www.w3.org/1999/XSL/Transform'; 
     50  const NAMESPACE_SCHEMATRON_ISO = 'http://purl.oclc.org/dsdl/schematron'; 
     51   
     52  const NAMESPACE_SVRL_ISO = 'http://purl.oclc.org/dsdl/svrl'; 
     53   
     54  const NAMESPACE_XSL_1999 = 'http://www.w3.org/1999/XSL/Transform'; 
    5155   
    5256  /** 
     
    5559   */ 
    5660  public static $agaviEnvelopeNamespaces = array( 
    57     self::AGAVI_ENVELOPE_NAMESPACE_0_11 => 'agavi_envelope_0_11', 
    58     self::AGAVI_ENVELOPE_NAMESPACE_1_0 => 'agavi_envelope_1_0', 
     61    self::NAMESPACE_AGAVI_ENVELOPE_0_11 => 'agavi_envelope_0_11', 
     62    self::NAMESPACE_AGAVI_ENVELOPE_1_0 => 'agavi_envelope_1_0', 
    5963  ); 
    6064   
    6165  /** 
     66   * @var        array A list of all XML namespaces that are used internally by 
     67   *                   the configuration parser. 
     68   */ 
     69  public static $agaviNamespaces = array( 
     70    self::NAMESPACE_AGAVI_ENVELOPE_0_11 => 'agavi_envelope_0_11', 
     71    self::NAMESPACE_AGAVI_ENVELOPE_1_0 => 'agavi_envelope_1_0', 
     72     
     73    self::NAMESPACE_AGAVI_ANNOTATION_1_0 => 'agavi_annotation_1_0' 
     74  ); 
     75   
     76  /** 
    6277   * @var        string Path to the config file we're parsing in this instance. 
    6378   */ 
     
    107122  { 
    108123    return isset(self::$agaviEnvelopeNamespaces[$namespaceUri]); 
     124  } 
     125   
     126  /** 
     127   * Check if a given namespace URI is a valid Agavi namespace. 
     128   * 
     129   * @param      string The namespace URI. 
     130   * 
     131   * @return     bool True if the given URI is a valid namespace URI, 
     132   *                  false otherwise. 
     133   * 
     134   * @author     Noah Fontes <noah.fontes@bitextender.com> 
     135   * @since      1.0.0 
     136   */ 
     137  public static function isAgaviNamespace($namespaceUri) 
     138  { 
     139    return isset(self::$agaviNamespaces[$namespaceUri]); 
    109140  } 
    110141   
     
    120151   * @since      1.0.0 
    121152   */ 
    122   public static function getAgaviEnvelopePrefix($namespaceUri) 
    123   { 
    124     if(self::isAgaviEnvelopeNamespace($namespaceUri)) { 
    125       return self::$agaviEnvelopeNamespaces[$namespaceUri]; 
     153  public static function getAgaviNamespacePrefix($namespaceUri) 
     154  { 
     155    if(self::isAgaviNamespace($namespaceUri)) { 
     156      return self::$agaviNamespaces[$namespaceUri]; 
    126157    } 
    127158    return null; 
     159  } 
     160   
     161  /** 
     162   * Register Agavi namespace prefixes in a given document. 
     163   * 
     164   * @param      AgaviXmlConfigDomDocument The document. 
     165   * 
     166   * @author     Noah Fontes <noah.fontes@bitextender.com> 
     167   * @since      1.0.0 
     168   */ 
     169  public static function registerAgaviNamespaces(AgaviXmlConfigDomDocument $document) 
     170  { 
     171    $xpath = $document->getXpath(); 
     172     
     173    foreach(self::$agaviNamespaces as $namespaceUri => $prefix) { 
     174      $xpath->registerNamespace($prefix, $namespaceUri); 
     175    } 
     176     
     177    /* Register the latest namespaces. */ 
     178    $xpath->registerNamespace('agavi_envelope_latest', self::NAMESPACE_AGAVI_ENVELOPE_LATEST); 
     179    $xpath->registerNamespace('agavi_annotation_latest', self::NAMESPACE_AGAVI_ANNOTATION_LATEST); 
    128180  } 
    129181   
     
    176228    if($isAgaviConfigFormat) { 
    177229      // if it is an Agavi config, we'll create a new document with all files' <configuration> blocks inside 
    178       $retval->appendChild(new AgaviXmlConfigDomElement('configurations', null, self::AGAVI_ENVELOPE_NAMESPACE_LATEST)); 
     230      $retval->appendChild(new AgaviXmlConfigDomElement('configurations', null, self::NAMESPACE_AGAVI_ENVELOPE_LATEST)); 
    179231       
    180232      // reverse the array - we want the parents first! 
     
    201253      // generic <configuration> first, then those with an environment attribute, then those with context, then those with both 
    202254      $configurationOrder = array( 
    203         'count(self::node()[@agavi_envelope_1_0:matched and not(@environment) and not(@context)])', 
    204         'count(self::node()[@agavi_envelope_1_0:matched and @environment and not(@context)])', 
    205         'count(self::node()[@agavi_envelope_1_0:matched and not(@environment) and @context])', 
    206         'count(self::node()[@agavi_envelope_1_0:matched and @environment and @context])', 
     255        'count(self::node()[@agavi_annotation_latest:matched and not(@environment) and not(@context)])', 
     256        'count(self::node()[@agavi_annotation_latest:matched and @environment and not(@context)])', 
     257        'count(self::node()[@agavi_annotation_latest:matched and not(@environment) and @context])', 
     258        'count(self::node()[@agavi_annotation_latest:matched and @environment and @context])', 
    207259      ); 
    208260       
     
    424476        if($matched) { 
    425477          // if all was fine, we set the attribute. the element will then be kept in the merged result doc later 
    426           $configuration->setAttributeNS(self::AGAVI_ENVELOPE_NAMESPACE_LATEST, 'agavi:matched', 'true'); 
     478          $configuration->setAttributeNS(self::NAMESPACE_AGAVI_ANNOTATION_LATEST, 'agavi_annotation_latest:matched', 'true'); 
    427479        } 
    428480      } 
     
    697749       
    698750      // is it an ISO Schematron file? 
    699       if(!$sch->documentElement || $sch->documentElement->namespaceURI != self::SCHEMATRON_ISO_NAMESPACE) { 
     751      if(!$sch->documentElement || $sch->documentElement->namespaceURI != self::NAMESPACE_SCHEMATRON_ISO) { 
    700752        throw new AgaviParseException(sprintf('Schematron validation of configuration file "%s" failed because schema file "%s" is invalid', $this->path, $href)); 
    701753      } 
     
    709761       
    710762      // it transformed fine. but did we get a proper stylesheet instance at all? wrong namespaces can lead to empty docs that only have an XML prolog 
    711       if(!$schema->documentElement || $schema->documentElement->namespaceURI != self::XSL_NAMESPACE_1999) { 
     763      if(!$schema->documentElement || $schema->documentElement->namespaceURI != self::NAMESPACE_XSL_1999) { 
    712764        throw new AgaviParseException(sprintf('Schematron validation of configuration file "%s" failed because schema file "%s" resulted in an invalid stylesheet', $this->path, $href)); 
    713765      } 
     
    730782      // validation ran okay, now we need to look at the result document to see if there are errors 
    731783      $xpath = $result->getXpath(); 
    732       $xpath->registerNamespace('svrl', self::SVRL_ISO_NAMESPACE); 
     784      $xpath->registerNamespace('svrl', self::NAMESPACE_SVRL_ISO); 
    733785       
    734786      $results = $xpath->query('//svrl:failed-assert | //svrl:successful-report'); 
  • branches/david-xml_only_config_system/src/config/rng/_common.rng

    r2632 r2641  
    11<?xml version="1.0" encoding="UTF-8"?> 
    22<grammar xmlns="http://relaxng.org/ns/structure/1.0" 
    3   xmlns:agavi="http://agavi.org/agavi/config/1.0" 
    4   ns="http://agavi.org/agavi/config/1.0" 
     3  xmlns:envelope_1_0="http://agavi.org/agavi/config/envelope/1.0" 
     4  xmlns:annotation_1_0="http://agavi.org/agavi/config/annotation/1.0" 
     5  ns="http://agavi.org/agavi/config/envelope/1.0" 
    56  datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> 
    67   
     
    4344    <!-- XXX: Here, or no? --> 
    4445    <optional> 
    45       <attribute name="agavi:matched"> 
     46      <attribute name="annotation_1_0:matched"> 
    4647        <ref name="data-matched" /> 
    4748      </attribute> 
     
    149150            <nsName /> 
    150151            <nsName ns="" /> 
    151             <nsName ns="http://agavi.org/agavi/config/1.0" /> 
     152            <nsName ns="http://agavi.org/agavi/config/envelope/1.0" /> 
     153            <nsName ns="http://agavi.org/agavi/config/annotation/1.0" /> 
    152154          </except> 
    153155        </anyName> 
     
    164166            <nsName /> 
    165167            <nsName ns="" /> 
    166             <nsName ns="http://agavi.org/agavi/config/1.0" /> 
     168            <nsName ns="http://agavi.org/agavi/config/envelope/1.0" /> 
     169            <nsName ns="http://agavi.org/agavi/config/annotation/1.0" /> 
    167170          </except> 
    168171        </anyName> 
  • branches/david-xml_only_config_system/src/config/rng/factories.rng

    r2632 r2641  
    11<?xml version="1.0" encoding="UTF-8"?> 
    22<grammar xmlns="http://relaxng.org/ns/structure/1.0" 
    3   xmlns:factories="http://agavi.org/agavi/config/factories/1.0" 
    4   ns="http://agavi.org/agavi/config/factories/1.0" 
     3  xmlns:factories_1_0="http://agavi.org/agavi/config/item/factories/1.0" 
     4  ns="http://agavi.org/agavi/config/item/factories/1.0" 
    55  datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> 
    66   
  • branches/david-xml_only_config_system/src/config/util/dom/AgaviXmlConfigDomDocument.class.php

    r2632 r2641  
    102102     
    103103    if($this->isAgaviConfiguration()) { 
    104       /* Register Agavi namespace prefixes. */ 
    105       foreach(AgaviXmlConfigParser::$agaviEnvelopeNamespaces as $namespaceUri => $prefix) { 
    106         $this->xpath->registerNamespace($prefix, $namespaceUri); 
    107       } 
    108        
    109       /* Register the default envelope namespace. */ 
    110       $this->xpath->registerNamespace('agavi_envelope_latest', AgaviXmlConfigParser::AGAVI_ENVELOPE_NAMESPACE_LATEST); 
     104      AgaviXmlConfigParser::registerAgaviNamespaces($this); 
    111105    } 
    112106     
     
    154148     
    155149    if($this->isAgaviConfiguration()) { 
    156       /* Register Agavi namespace prefixes. */ 
    157       foreach(AgaviXmlConfigParser::$agaviEnvelopeNamespaces as $namespaceUri => $prefix) { 
    158         $this->xpath->registerNamespace($prefix, $namespaceUri); 
    159       } 
    160        
    161       /* Register the default envelope namespace. */ 
    162       $this->xpath->registerNamespace('agavi_envelope_latest', AgaviXmlConfigParser::AGAVI_ENVELOPE_NAMESPACE_LATEST); 
     150      AgaviXmlConfigParser::registerAgaviNamespaces($this); 
    163151    } 
    164152     
  • branches/david-xml_only_config_system/src/config/util/dom/AgaviXmlConfigDomElement.class.php

    r2640 r2641  
    268268     
    269269    if($this->ownerDocument->isAgaviConfiguration()) { 
    270       $elements = $this->getChildren('parameters', AgaviXmlConfigParser::AGAVI_ENVELOPE_NAMESPACE_LATEST); 
     270      $elements = $this->getChildren('parameters', AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_LATEST); 
    271271       
    272272      foreach($elements as $element) { 
     
    280280        } 
    281281         
    282         if($element->hasChildren('parameters', AgaviXmlConfigParser::AGAVI_ENVELOPE_NAMESPACE_LATEST)) { 
     282        if($element->hasChildren('parameters', AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_LATEST)) { 
    283283          $result[$key] = isset($result[$key]) && is_array($result[$key]) ? $result[$key] : array(); 
    284284          $result[$key] = $element->getAgaviParameters($result[$key], $literalize); 
  • branches/david-xml_only_config_system/src/config/xsl/_common.xsl

    r2632 r2641  
    44  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    55  xmlns:envelope_0_11="http://agavi.org/agavi/1.0/config" 
    6   xmlns:envelope_1_0="http://agavi.org/agavi/config/1.0"> 
     6  xmlns:envelope_1_0="http://agavi.org/agavi/config/envelope/1.0"> 
    77   
    88  <xsl:variable name="envelope_0_11" select="'http://agavi.org/agavi/1.0/config'" /> 
    9   <xsl:variable name="envelope_1_0" select="'http://agavi.org/agavi/config/1.0'" /> 
     9  <xsl:variable name="envelope_1_0" select="'http://agavi.org/agavi/config/envelope/1.0'" /> 
    1010   
    1111  <xsl:template match="envelope_0_11:configurations | envelope_0_11:configuration | envelope_0_11:sandbox | envelope_0_11:parameters | envelope_0_11:parameter"> 
  • branches/david-xml_only_config_system/src/config/xsl/factories.xsl

    r2632 r2641  
    44  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    55  xmlns:envelope_0_11="http://agavi.org/agavi/1.0/config" 
    6   xmlns:factories_1_0="http://agavi.org/agavi/config/factories/1.0" 
     6  xmlns:factories_1_0="http://agavi.org/agavi/config/item/factories/1.0" 
    77> 
    88  <!--xmlns:factories_1_1="http://agavi.org/agavi/1.1/config/factories"--> 
     
    1212  <xsl:include href="_common.xsl" /> 
    1313   
    14   <xsl:variable name="factories_1_0" select="'http://agavi.org/agavi/config/factories/1.0'" /> 
     14  <xsl:variable name="factories_1_0" select="'http://agavi.org/agavi/config/item/factories/1.0'" /> 
    1515  <!--<xsl:variable name="factories11" select="'http://agavi.org/agavi/1.1/config/factories'" />--> 
    1616