Hoa's repository

changeset 1133:f545beb5a9bf Trunk

Add phrasing model element, allows to understand <foo>abc<bar>def</bar>ghi</foo> sequence.
author Ivan Enderlin <ivan.enderlin@hoa-project.net>
date Thu Jan 06 17:11:49 2011 +0100 (16 months ago)
parents e94ff02a9a59
children b69fc31c0a61
files Framework/Library/Xml/Element/Basic.php Framework/Library/Xml/Element/Concrete.php Framework/Library/Xml/Element/Model/Phrasing.php
line diff
     1.1 --- a/Framework/Library/Xml/Element/Basic.php	Thu Jan 06 15:37:11 2011 +0100
     1.2 +++ b/Framework/Library/Xml/Element/Basic.php	Thu Jan 06 17:11:49 2011 +0100
     1.3 @@ -357,6 +357,51 @@
     1.4      }
     1.5  
     1.6      /**
     1.7 +     * Read children as a phrasing model, i.e. transform:
     1.8 +     *     <foo>abc<bar>def</bar>ghi</foo>
     1.9 +     * into
    1.10 +     *     <foo><???>abc</???><bar>def</bar><???>ghi</???></foo>
    1.11 +     * where <???> is the value of the $element argument, i.e. the inter-text
    1.12 +     * element name. Please, see the Hoa_Xml_Element_Model_Phrasing interface.
    1.13 +     *
    1.14 +     * @access  public
    1.15 +     * @param   string  $namespace    Namespace to use ('' if none).
    1.16 +     * @param   string  $element      Inter-text element name.
    1.17 +     * @return  array
    1.18 +     */
    1.19 +    public function readAsPhrasingModel ( $namespace = '', $element = '__text' ) {
    1.20 +
    1.21 +        $out   = array();
    1.22 +        $list  = $this->readDOM()->childNodes;
    1.23 +        $class = get_class($this);
    1.24 +
    1.25 +        for($i = 0, $max = $list->length; $i < $max; ++$i) {
    1.26 +
    1.27 +            $node = $list->item($i);
    1.28 +
    1.29 +            switch($node->nodeType) {
    1.30 +
    1.31 +                case XML_ELEMENT_NODE:
    1.32 +                    $out[] = simplexml_import_dom($node, $class);
    1.33 +                  break;
    1.34 +
    1.35 +                case XML_TEXT_NODE:
    1.36 +                    $out[] = new $class(
    1.37 +                        '<' . $element . '>' . $node->nodeValue .
    1.38 +                        '</' . $element . '>',
    1.39 +                        LIBXML_NOXMLDECL,
    1.40 +                        false,
    1.41 +                        $namespace,
    1.42 +                        false
    1.43 +                    );
    1.44 +                  break;
    1.45 +            }
    1.46 +        }
    1.47 +
    1.48 +        return $out;
    1.49 +    }
    1.50 +
    1.51 +    /**
    1.52       * Use a specific namespace.
    1.53       * For performance reason, we did not test if the namespace exists in the
    1.54       * document. Please, see the Hoa_Xml::namespaceExists() method to do that.
     2.1 --- a/Framework/Library/Xml/Element/Concrete.php	Thu Jan 06 15:37:11 2011 +0100
     2.2 +++ b/Framework/Library/Xml/Element/Concrete.php	Thu Jan 06 17:11:49 2011 +0100
     2.3 @@ -43,6 +43,11 @@
     2.4  import('Xml.Element') and load();
     2.5  
     2.6  /**
     2.7 + * Hoa_Xml_Element_Model_Phrasing
     2.8 + */
     2.9 +import('Xml.Element.Model.Phrasing');
    2.10 +
    2.11 +/**
    2.12   * Class Hoa_Xml_Element_Concrete.
    2.13   *
    2.14   * This class represents a XML element in a XML tree.
    2.15 @@ -153,7 +158,12 @@
    2.16          $this->_abstract     = $abstract;
    2.17          $this->_superRoot    = $superRoot;
    2.18  
    2.19 -        foreach($abstract->selectChildElements() as $child) {
    2.20 +        if($this instanceof Hoa_Xml_Element_Model_Phrasing)
    2.21 +            $iterator = $abstract->readAsPhrasingModel($namespace);
    2.22 +        else
    2.23 +            $iterator = $abstract->selectChildElements();
    2.24 +
    2.25 +        foreach($iterator as $child) {
    2.26  
    2.27              $name = $child->getName();
    2.28  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/Framework/Library/Xml/Element/Model/Phrasing.php	Thu Jan 06 17:11:49 2011 +0100
     3.3 @@ -0,0 +1,51 @@
     3.4 +<?php
     3.5 +
     3.6 +/**
     3.7 + * Hoa Framework
     3.8 + *
     3.9 + *
    3.10 + * @license
    3.11 + *
    3.12 + * GNU General Public License
    3.13 + *
    3.14 + * This file is part of Hoa Open Accessibility.
    3.15 + * Copyright (c) 2007, 2010 Ivan ENDERLIN. All rights reserved.
    3.16 + *
    3.17 + * HOA Open Accessibility is free software; you can redistribute it and/or
    3.18 + * modify it under the terms of the GNU General Public License as published by
    3.19 + * the Free Software Foundation; either version 2 of the License, or
    3.20 + * (at your option) any later version.
    3.21 + *
    3.22 + * HOA Open Accessibility is distributed in the hope that it will be useful,
    3.23 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.24 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.25 + * GNU General Public License for more details.
    3.26 + *
    3.27 + * You should have received a copy of the GNU General Public License
    3.28 + * along with HOA Open Accessibility; if not, write to the Free Software
    3.29 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.30 + *
    3.31 + *
    3.32 + * @category    Framework
    3.33 + * @package     Hoa_Xml
    3.34 + * @subpackage  Hoa_Xml_Element_Model_Phrasing
    3.35 + *
    3.36 + */
    3.37 +
    3.38 +/**
    3.39 + * Interface Hoa_Xml_Element_Model_Phrasing.
    3.40 + *
    3.41 + * A phrasing content model represents an element that have at least one
    3.42 + * descendant text node that is not inter-element whitespace. Typically:
    3.43 + * <foo>abc<bar>def</bar>ghi</foo>.
    3.44 + *
    3.45 + * @author      Ivan ENDERLIN <ivan.enderlin@hoa-project.net>
    3.46 + * @copyright   Copyright (c) 2007, 2010 Ivan ENDERLIN.
    3.47 + * @license     http://gnu.org/licenses/gpl.txt GNU GPL
    3.48 + * @since       PHP 5
    3.49 + * @version     0.1
    3.50 + * @package     Hoa_Xml
    3.51 + * @subpackage  Hoa_Xml_Element_Model_Phrasing
    3.52 + */
    3.53 +
    3.54 +interface Hoa_Xml_Element_Model_Phrasing { }