コード例 #1
0
/**
 * Imports data from DocBook XML
 *
 * @return array of map
 *
 */
function importReqDataFromDocBook($fileName)
{
    $req_cfg = config_get('req_cfg');
    $docbookCfg = $req_cfg->importDocBook;
    $xmlReqs = null;
    $xmlData = null;
    $field_size = config_get('field_size');
    $simpleXMLObj = simplexml_load_file($fileName);
    $num_elem = count($simpleXMLObj->{$docbookCfg->requirement});
    $idx = 0;
    foreach ($simpleXMLObj->{$docbookCfg->requirement} as $xmlReq) {
        // get all child elements of this requirement
        $title = "";
        $description = "";
        $children = $xmlReq->children();
        foreach ($children as $child) {
            $nodeName = $child->getName();
            if ($nodeName == $docbookCfg->title) {
                $title = (string) $child;
            } else {
                if ($nodeName == $docbookCfg->ordered_list) {
                    $list = "";
                    foreach ($child->children() as $item) {
                        if ($item->getName() == $docbookCfg->list_item) {
                            if ($item->count() == 0) {
                                $list .= "<li>" . (string) $item . "</li>";
                            } else {
                                foreach ($docbookCfg->list_item_children as $ck) {
                                    if (property_exists($item, $ck)) {
                                        $list .= "<li>" . (string) $item->{$ck} . "</li>";
                                    }
                                }
                            }
                        }
                    }
                    $description .= "<ul>" . $list . "</ul>";
                } else {
                    if ($nodeName == $docbookCfg->table) {
                        $description .= getDocBookTableAsHtmlString($child, $docbookCfg);
                    } else {
                        if ($nodeName == $docbookCfg->paragraph) {
                            $description .= "<p>" . (string) $child . "</p>";
                        } else {
                            $description .= "<p>" . (string) $child . "</p>";
                        }
                    }
                }
            }
        }
        $xmlData[$idx]['description'] = $description;
        $xmlData[$idx]['title'] = trim_and_limit($title, $field_size->req_title);
        // parse Doc ID from requirement title
        // first remove any weird characters before the title. This could be probably omitted
        $xmlData[$idx]['title'] = preg_replace("/^[^a-zA-Z_0-9]*/", "", $xmlData[$idx]['title']);
        // get Doc ID
        //
        // this will create Doc ID as words ended with number
        // Example: Req BL 20 Business Logic
        // Doc ID: Req BL 20
        //if (preg_match("/[ a-zA-Z_]*[0-9]*/", $xmlData[$i]['title'], $matches))
        //{
        //  $xmlData[$i]['req_doc_id'] = $matches[0];
        //}
        // this matches first two words in Title and adds counter started from 1
        // Doc ID is grouped (case insensitive), so different groups have their own counter running
        // Example: Req BL Business Logic
        // Doc ID: Req BL 1
        // Note: Doc ID doesn't need trim_and_limit since it is parsed from Title
        // new dBug($xmlData[$idx]['title']);
        if (preg_match("/[ ]*[a-zA-Z_0-9]*[ ][a-zA-Z_0-9]*/", $xmlData[$idx]['title'], $matches)) {
            $index = strtolower($matches[0]);
            if (!isset($counter[$index])) {
                $counter[$index] = 0;
            }
            $counter[$index]++;
            $xmlData[$idx]['docid'] = $matches[0] . " " . $counter[$index];
        } else {
            $xmlData[$idx]['docid'] = uniqid('REQ-');
        }
        $xmlData[$idx]['node_order'] = $idx;
        $xmlData[$idx]['expected_coverage'] = 0;
        $xmlData[$idx]['type'] = TL_REQ_TYPE_FEATURE;
        $xmlData[$idx]['status'] = TL_REQ_STATUS_VALID;
        $idx++;
    }
    return $xmlData;
}
コード例 #2
0
/**
 * Imports data from DocBook XML
 *
 * 20081103 - sisajr
 */
function importReqDataFromDocBook($fileName)
{
    $req_cfg = config_get('req_cfg');
    $docbookCfg = $req_cfg->importDocBook;
    // $docbookCfg->requirement= "sect3";
    // $docbookCfg->title= "title";
    // $docbookCfg->paragraph= "para";
    // $docbookCfg->ordered_list="orderedlist";
    // $docbookCfg->list_item="listitem";
    // $docbookCfg->table="informaltable";
    // $docbookCfg->table_group="tgroup";
    // $docbookCfg->table_head="thead";
    // $docbookCfg->table_body="tbody";
    // $docbookCfg->table_row="row";
    // $docbookCfg->table_entry="entry";
    // $docbookCfg->list_item_children = array('para','title');
    // $docbookCfg->table_entry_children = array('para');
    $xmlReqs = null;
    $xmlData = null;
    $field_size = config_get('field_size');
    $simpleXMLObj = simplexml_load_file($fileName);
    $num_elem = count($simpleXMLObj->sect1);
    $idx = 0;
    foreach ($simpleXMLObj->sect1 as $xmlReq) {
        // get all child elements of this requirement
        // $title = (string)$xmlReq->title;
        // echo $title . '<br>';
        $title = "";
        $description = "";
        $children = $xmlReq->children();
        foreach ($children as $child) {
            $nodeName = $child->getName();
            // echo 'node name:' . $nodeName .'<br>';
            if ($nodeName == $docbookCfg->title) {
                // echo 'INSIDE::' . $nodeName . '<br>';
                $title = (string) $child;
                // echo '$title:' . $title .'<br>';
            } else {
                if ($nodeName == $docbookCfg->ordered_list) {
                    // echo 'INSIDE' . $nodeName . '<br>';
                    $list = "";
                    foreach ($child->children() as $item) {
                        // echo 'xxx' . $item->getName() . '<br>';
                        if ($item->getName() == $docbookCfg->list_item) {
                            if ($item->count() == 0) {
                                $list .= "<li>" . (string) $item . "</li>";
                            } else {
                                foreach ($docbookCfg->list_item_children as $ck) {
                                    if (property_exists($item, $ck)) {
                                        $list .= "<li>" . (string) $item->{$ck} . "</li>";
                                    }
                                }
                            }
                        }
                    }
                    $description .= "<ul>" . $list . "</ul>";
                } else {
                    if ($nodeName == $docbookCfg->table) {
                        // echo 'INSIDE: ' . $nodeName . '<br>';
                        $description .= getDocBookTableAsHtmlString($child, $docbookCfg);
                    } else {
                        if ($nodeName == $docbookCfg->paragraph) {
                            $description .= "<p>" . (string) $child . "</p>";
                        } else {
                            $description .= "<p>" . (string) $child . "</p>";
                        }
                    }
                }
            }
        }
        // echo '$description:' . '<xmp>' . $description . '</xmp>' . '<br>';
        $xmlData[$idx]['description'] = $description;
        $xmlData[$idx]['title'] = trim_and_limit($title, $field_size->req_title);
        // parse Doc ID from requirement title
        // first remove any weird characters before the title. This could be probably omitted
        $xmlData[$idx]['title'] = preg_replace("/^[^a-zA-Z_0-9]*/", "", $xmlData[$idx]['title']);
        // get Doc ID
        //
        // this will create Doc ID as words ended with number
        // Example: Req BL 20 Business Logic
        // Doc ID: Req BL 20
        //if (preg_match("/[ a-zA-Z_]*[0-9]*/", $xmlData[$i]['title'], $matches))
        //{
        //	$xmlData[$i]['req_doc_id'] = $matches[0];
        //}
        // this matches first two words in Title and adds counter started from 1
        // Doc ID is grouped (case insensitive), so different groups have their own counter running
        // Example: Req BL Business Logic
        // Doc ID: Req BL 1
        // Note: Doc ID doesn't need trim_and_limit since it is parsed from Title
        // new dBug($xmlData[$idx]['title']);
        if (preg_match("/[ ]*[a-zA-Z_0-9]*[ ][a-zA-Z_0-9]*/", $xmlData[$idx]['title'], $matches)) {
            $index = strtolower($matches[0]);
            if (!isset($counter[$index])) {
                $counter[$index] = 0;
            }
            $counter[$index]++;
            $xmlData[$idx]['req_doc_id'] = $matches[0] . " " . $counter[$index];
        }
        $idx++;
    }
    new dBug($xmlData);
    return $xmlData;
}