Changeset 1018

Show
Ignore:
Timestamp:
11/09/07 18:01:44 (8 months ago)
Author:
mikey
Message:

added new getEncoding() method which returns the encoding that will be used by the writer

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/xml/stubAbstractXMLStreamWriter.php

    r678 r1018  
    33 * Abstract base class for XML stream writers 
    44 * 
    5  * @author     Stephan Schmidt <schst@stubbles.net> 
    6  * @package    stubbles 
    7  * @subpackage xml 
     5 * @author      Stephan Schmidt <schst@stubbles.net> 
     6 * @author      Frank Kleine <mikey@stubbles.net> 
     7 * @package     stubbles 
     8 * @subpackage  xml 
    89 */ 
    9  
    1010/** 
    1111 * Abstract base class for XML stream writers 
    1212 * 
    13  * @package    stubbles 
    14  * @subpackage xml 
     13 * @package    stubbles 
     14 * @subpackage xml 
    1515 */ 
    16 abstract class stubAbstractXMLStreamWriter extends stubBaseObject { 
    17  
     16abstract class stubAbstractXMLStreamWriter extends stubBaseObject 
     17
     18    /** 
     19     * encoding used by the writer 
     20     * 
     21     * @var  string 
     22     */ 
     23    protected $encoding; 
    1824    /** 
    1925     * List of supported features 
     
    2228     */ 
    2329    protected $features = array(); 
     30 
     31    /** 
     32     * returns the encoding used by the writer 
     33     * 
     34     * @return  string 
     35     */ 
     36    public function getEncoding() 
     37    { 
     38        return $this->encoding; 
     39    } 
    2440 
    2541    /** 
  • trunk/src/main/php/net/stubbles/xml/stubDomXMLStreamWriter.php

    r1017 r1018  
    1818 * @subpackage xml 
    1919 */ 
    20 class stubDomXMLStreamWriter extends stubAbstractXMLStreamWriter implements stubXMLStreamWriter { 
    21  
     20class stubDomXMLStreamWriter extends stubAbstractXMLStreamWriter implements stubXMLStreamWriter 
     21
    2222    /** 
    2323     * List of supported features 
     
    2727    protected $features = array(stubXMLStreamWriter::FEATURE_AS_DOM, 
    2828                                stubXMLStreamWriter::FEATURE_IMPORT_WRITER); 
    29  
    3029    /** 
    3130     * DOM Document 
     
    3433     */ 
    3534    protected $doc; 
    36  
    3735    /** 
    3836     * Stores al opened elements 
     
    4139     */ 
    4240    protected $elementStack = array(); 
    43  
    4441    /** 
    4542     * XML version 
     
    4845     */ 
    4946    protected $xmlVersion; 
    50  
    51     /** 
    52      * XML encoding 
    53      * 
    54      * @var string 
    55      */ 
    56     protected $encoding; 
    5747 
    5848    /** 
     
    6454    public function __construct($xmlVersion = '1.0', $encoding = 'UTF-8') { 
    6555        $this->xmlVersion = $xmlVersion; 
    66         $this->encoding = $encoding; 
    67         $this->doc = new DOMDocument($xmlVersion, $encoding); 
     56        $this->encoding   = $encoding; 
     57        $this->doc        = new DOMDocument($xmlVersion, $encoding); 
    6858    } 
    6959 
  • trunk/src/main/php/net/stubbles/xml/stubLibXmlXMLStreamWriter.php

    r1017 r1018  
    1717 * @subpackage xml 
    1818 */ 
    19 class stubLibXmlXMLStreamWriter extends stubAbstractXMLStreamWriter implements stubXMLStreamWriter { 
    20  
     19class stubLibXmlXMLStreamWriter extends stubAbstractXMLStreamWriter implements stubXMLStreamWriter 
     20
    2121    /** 
    2222     * List of supported features 
     
    2525     */ 
    2626    protected $features = array(stubXMLStreamWriter::FEATURE_AS_DOM); 
    27  
    2827    /** 
    2928     * Writer 
     
    3231     */ 
    3332    protected $writer; 
    34  
    3533    /** 
    3634     * XML version 
     
    3937     */ 
    4038    protected $xmlVersion; 
    41  
    42     /** 
    43      * XML encoding 
    44      * 
    45      * @var string 
    46      */ 
    47     protected $encoding; 
    4839 
    4940    /** 
     
    5546    public function __construct($xmlVersion = '1.0', $encoding = 'UTF-8') { 
    5647        $this->xmlVersion = $xmlVersion; 
    57         $this->encoding = $encoding; 
    58         $this->writer = new XMLWriter(); 
     48        $this->encoding   = $encoding; 
     49        $this->writer     = new XMLWriter(); 
    5950        $this->writer->openMemory(); 
    6051        $this->writer->startDocument($xmlVersion, $encoding); 
  • trunk/src/main/php/net/stubbles/xml/stubXMLStreamWriter.php

    r760 r1018  
    33 * Interface to create XML documents 
    44 * 
    5  * @author     Stephan Schmidt <schst@stubbles.net> 
    6  * @package    stubbles 
    7  * @subpackage xml 
     5 * @author      Stephan Schmidt <schst@stubbles.net> 
     6 * @author      Frank Kleine <mikey@stubbles.net> 
     7 * @package     stubbles 
     8 * @subpackage  xml 
    89 */ 
    910stubClassLoader::load('net.stubbles.xml.stubXMLException'); 
     
    1112 * Interface to create XML documents 
    1213 * 
    13  * @package    stubbles 
    14  * @subpackage xml 
     14 * @package    stubbles 
     15 * @subpackage xml 
    1516 */ 
    1617interface stubXMLStreamWriter extends stubObject { 
     
    3637     * @param string $encoding 
    3738     */ 
    38     #public function __construct($xmlVersion = '1.0', $encoding = 'ISO-8859-1'); 
     39    #public function __construct($xmlVersion = '1.0', $encoding = 'UTF-8'); 
     40 
     41    /** 
     42     * returns the encoding used by the writer 
     43     * 
     44     * @return  string 
     45     */ 
     46    public function getEncoding(); 
    3947 
    4048    /** 
  • trunk/src/test/php/net/stubbles/xml/stubDomXMLStreamWriterTestCase.php

    r1017 r1018  
    2424        $writer = new stubDomXMLStreamWriter(); 
    2525        $this->assertEqual('<?xml version="1.0" encoding="UTF-8"?>', $writer->asXML()); 
     26        $this->assertEqual($writer->getEncoding(), 'UTF-8'); 
     27        $writer = new stubDomXMLStreamWriter('1.0', 'ISO-8859-1'); 
     28        $this->assertEqual($writer->getEncoding(), 'ISO-8859-1'); 
    2629    } 
    2730 
  • trunk/src/test/php/net/stubbles/xml/stubLibXmlXMLStreamWriterTestCase.php

    r1017 r1018  
    2424        $writer = new stubLibXmlXMLStreamWriter(); 
    2525        $this->assertEqual('<?xml version="1.0" encoding="UTF-8"?>', $writer->asXML()); 
     26        $this->assertEqual($writer->getEncoding(), 'UTF-8'); 
     27        $writer = new stubLibXmlXMLStreamWriter('1.0', 'ISO-8859-1'); 
     28        $this->assertEqual($writer->getEncoding(), 'ISO-8859-1'); 
    2629    } 
    2730