Changeset 2101

Show
Ignore:
Timestamp:
2006-02-22 22:11:51 (3 years ago)
Author:
ctford
Message:

Remove silly ripping stuff, add Exception throwing and Doxygen commenting.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • phpannodex/trunk/phpannodex/SimpleCMMLElement.php

    r1801 r2101  
    3030 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    3131 */ 
     32 
     33/** 
     34 * \file AnxCMMLSource.php 
     35 * \author Chris Ford 
     36 * \date February 2006 
     37 */ 
     38 
     39require_once("phpannodex/Exceptions/AnxBadFormatException.php"); 
     40 
    3241/* These functions are wrappers for equivilent static methods in  
    3342 * SimpleCMMLElement. They are provided to maintain consistency with the  
    3443 * standard SimpleXMLElement functions. 
    3544 */  
    36 function simplecmml_load_anx_file( $filename ) { 
    37   return SimpleCMMLElement::load_anx_file( $filename ); 
     45/** 
     46 * A SimpleCMMLElement equivalent of simplexml_load_file(). 
     47 */ 
     48function simplecmml_load_file( $filename ) { 
     49  return simplexml_load_file( $filename, 'SimpleCMMLElement'); 
    3850} 
    39 function simplecmml_load_cmml_file( $filename ) { 
    40   return SimpleCMMLElement::load_cmml_file( $filename ); 
    41 
     51/** 
     52 * A SimpleCMMLElement equivalent of simplexml_load_string(). 
     53 */ 
    4254function simplecmml_load_string( $xml_str ) { 
    43   return SimpleCMMLElement::load_string( $xml_str ); 
     55  return simplexml_load_string( $xml_str, 'SimpleCMMLElement'); 
    4456} 
    4557   
     58/** 
     59 * \class SimpleCMMLElement  
     60 * A subclass of SimpleXML specifically for CMML. 
     61 */ 
    4662class SimpleCMMLElement extends SimpleXMLElement { 
    4763 
    48   const anxripper = 'anxrip'; 
    49   const max_size = 20000; 
    50  
    5164  public static function load_string( $xml_str ) { 
    52     return simplexml_load_string( $xml_str, 'SimpleCMMLElement'); 
     65    if( $elem = simplecmml_load_string( $xml_str, 'SimpleCMMLElement') ) { 
     66      return $elem; 
     67    } else { 
     68      throw new AnxBadFormatException("Badly formatted CMML."); 
     69    } 
    5370  } 
    54   public static function load_cmml_file( $filename ) { 
    55     return simplexml_load_file( $filename, 'SimpleCMMLElement'); 
    56   } 
    57   public function load_anx_file( $filename ) { 
    58    
    59     $xml_str = SimpleCMMLElement::anx_rip( $filename ); 
    60     return SimpleCMMLElement::load_string( $xml_str );   
     71  public static function load_file( $filename ) { 
     72    if( $elem = simplecmml_load_file( $filename, 'SimpleCMMLElement') ) { 
     73      return $elem; 
     74    } else { 
     75      throw new AnxBadFormatException("Badly formatted CMML file."); 
     76    }  
    6177  } 
    6278 
    63   protected static function anx_rip( $filename ) { 
    64      
    65     if ( !file_exists( $filename ) ) { 
    66       throw new Exception("File doesn't exist"); 
    67     } 
    68      
    69     $handle = popen(SimpleCMMLElement::anxripper." $filename", "r"); 
    70     if( !$handle ) { 
    71       throw new Exception("Unable to open pipe"); 
    72     } 
    73     else { 
    74       $xml_str = fread($handle, SimpleCMMLElement::max_size); 
    75     } 
    76  
    77     pclose( $handle ); 
    78     return $xml_str; 
    79   } 
    80    
    81   public function set_max_size( $new_max ) { 
    82     $this->max_size = $new_max; 
    83     return; 
    84   } 
    85   public function get_max_size() { 
    86     return $this->max_size; 
    87   }  
    8879}