Changeset 2101
- Timestamp:
- 2006-02-22 22:11:51 (3 years ago)
- Files:
-
- phpannodex/trunk/phpannodex/SimpleCMMLElement.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
phpannodex/trunk/phpannodex/SimpleCMMLElement.php
r1801 r2101 30 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 31 */ 32 33 /** 34 * \file AnxCMMLSource.php 35 * \author Chris Ford 36 * \date February 2006 37 */ 38 39 require_once("phpannodex/Exceptions/AnxBadFormatException.php"); 40 32 41 /* These functions are wrappers for equivilent static methods in 33 42 * SimpleCMMLElement. They are provided to maintain consistency with the 34 43 * standard SimpleXMLElement functions. 35 44 */ 36 function simplecmml_load_anx_file( $filename ) { 37 return SimpleCMMLElement::load_anx_file( $filename ); 45 /** 46 * A SimpleCMMLElement equivalent of simplexml_load_file(). 47 */ 48 function simplecmml_load_file( $filename ) { 49 return simplexml_load_file( $filename, 'SimpleCMMLElement'); 38 50 } 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 */ 42 54 function simplecmml_load_string( $xml_str ) { 43 return SimpleCMMLElement::load_string( $xml_str);55 return simplexml_load_string( $xml_str, 'SimpleCMMLElement'); 44 56 } 45 57 58 /** 59 * \class SimpleCMMLElement 60 * A subclass of SimpleXML specifically for CMML. 61 */ 46 62 class SimpleCMMLElement extends SimpleXMLElement { 47 63 48 const anxripper = 'anxrip';49 const max_size = 20000;50 51 64 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 } 53 70 } 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 } 61 77 } 62 78 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 }88 79 }