FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
dom-parseLicenseTable.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2010 Hewlett-Packard Development Company, L.P.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
18 
37 {
38  public $page;
39  public $hList = array();
40  public $noRows = FALSE;
41  public $emptyTable = FALSE;
42  private $tableId;
43  private $title;
44 
45  function __construct($page,$tblId,$title=1)
46  {
47  if (empty ($page)) { return; }
48  $this->page = $page;
49  if (strlen($tblId) == 0) { return; }
50  $this->tableId = $tblId;
51  $this->title = $title;
52  }
68  function parseLicenseTbl()
69  {
70  /*
71  * Each table row has 3 td's in it. First is the license count, second
72  * is the show link and third is the license name.
73  */
74 
75  $dom = new domDocument;
76  @$dom->loadHTML($this->page);
77  /*** discard white space ***/
78  $dom->preserveWhiteSpace = false;
79  $table = $dom->getElementById($this->tableId);
80  if(empty($table)) {
81  $this->emptyTable = TRUE;
82  //print "DPLTDB: table is empty, can't find table! with table id of:$this->tableId\n";
83  return($this->hList=array());
84  }
85 
86  foreach ($table->childNodes as $tblChildNode)
87  {
88  $histogram = array();
89  foreach($tblChildNode->childNodes as $childNode){
90  if($childNode->nodeName == 'td'){
91  if(is_numeric($childNode->nodeValue)) {
92  $histogram['count'] = trim($childNode->nodeValue);
93  }
94  if ($childNode->nodeValue == 'Show') {
95  $anchorList = $childNode->getElementsByTagName('a');
96  foreach($anchorList as $anchorEle) {
97  $histogram['showLink'] = $anchorEle->getAttribute('href');
98  }
99  }
100  if(is_string($childNode->nodeValue)) {
101  $histogram['textOrLink'] = trim($childNode->nodeValue);
102  }
103  }
104  } // foreach($tblChildNode
105  $this->hList[] = $histogram;
106  $histogram = array();
107  } // foreach
108  // for tables with titles, the first row is empty as no childNodes match
109  // what we are looking for, remove the first row.
110  if($this->title)
111  {
112  // remove empty 1st entry
113  unset($this->hList[0]);
114  }
115  if(empty($this->hList)) {
116  $this->noRows = TRUE;
117  }
118  } // parseLicenseTbl
119 }
120 ?>
parseLicenseTbl()
given a fossology license histogram, parse it into license names and Show links.
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:695