Changeset 16914

Show
Ignore:
Timestamp:
07/31/08 20:29:04 (5 years ago)
Author:
sasezaki
Message:

lang/php/Scraper: Strategy/Xpathのエラーハンドリングの仮コミットその2

Location:
lang/php/Scraper/library/Diggin/Scraper
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/php/Scraper/library/Diggin/Scraper/Process.php

    r16891 r16914  
    2424    public function __toString() 
    2525    { 
    26         return "\"".$this->expression.' , '.$this->name.' => '.$this->type."\""; 
     26        return '\''.$this->expression.'\' , '. 
     27               $this->name.' => '. 
     28//               if(!($this->type instanceof scraper)) {$this->type} else "" 
     29               '"'; 
    2730    } 
    2831     
  • lang/php/Scraper/library/Diggin/Scraper/Strategy/Abstract.php

    r16891 r16914  
    5353    protected abstract function getValue($values, $process); 
    5454     
    55     protected abstract static function extract($values, $process); 
     55    protected abstract function extract($values, $process); 
    5656 
    5757    public function getValues($context, $process) 
     
    6464            $values = $context->scrape($process); 
    6565        } else { 
    66             $values = null; 
    67             $values = $this->extract($context, $process); 
     66            try { 
     67                $values = $this->extract($context, $process); 
     68            } catch (Diggin_Scraper_Strategy_Exception $e) { 
     69                echo "error";echo PHP_EOL; return false; 
     70            } 
    6871        } 
    6972         
     
    7174            foreach ($values as $count => $val) { 
    7275                foreach ($process->type->processes as $proc) { 
    73                     $returns[$count][$proc->name] = $this->getValues($val, $proc); 
     76                    //@todo 値がとれなかったとき、格納しないか空かどうかはconfigでやるべきかな 
     77                    if (false !== $getval =$this->getValues($val, $proc)) { 
     78                        $returns[$count][$proc->name] = $getval; 
     79                    } 
    7480                } 
    7581                 
  • lang/php/Scraper/library/Diggin/Scraper/Strategy/Xpath.php

    r16913 r16914  
    7676    } 
    7777     
    78     public static function extract($values, $process) 
     78    public function extract($values, $process) 
    7979    { 
    8080        //↓このハンドリングはxpathの記述自体が間違ってたとき(いらないかな?) 
    8181        set_error_handler( 
    8282            create_function('$errno, $errstr', 
    83             'if($errno) require_once "Diggin/Scraper/Strategy/Xpath/Exception.php";  
    84                 throw new Diggin_Scraper_Strategy_Xpath_Exception($errstr, $errno);' 
     83            'if($errno) require_once "Diggin/Scraper/Strategy/Exception.php";  
     84                throw new Diggin_Scraper_Strategy_Exception($errstr, $errno);' 
    8585            ) 
    8686        ); 
     
    8888        restore_error_handler(); 
    8989 
    90         //        if (count($results) === 0) { 
    91         //        //@todo notice error 
    92         //            require_once 'Diggin/Scraper/Strategy/Exception.php'; 
    93         //            throw new Diggin_Scraper_Strategy_Exception("couldn't find By Xpath, Process : $process");             
    94         //        } 
    95 //        if ((isset($results[0])) && ($results[0] === false)) {//これはxpath記述自体が間違ってたとき 
    96 //            require_once 'Diggin/Scraper/Strategy/Exception.php'; 
    97 //            throw new Diggin_Scraper_Strategy_Exception("Couldn't find By Xpath, Process : $process"); 
    98 //        } 
     90        if (count($results) === 0) { 
     91            require_once 'Diggin/Scraper/Strategy/Exception.php'; 
     92            throw new Diggin_Scraper_Strategy_Exception("couldn't find By Xpath, Process : $process");             
     93        } 
    9994         
    10095        return $results;