/**
  * Copy needed resources to output directory
  * 
  * @param boolean $hasErrors Flag to define which index.html will be generated.
  * 
  * @return void
  * @throws Exception
  * @see cbFDHandler::copyFile
  */
 public function copyRessourceFolders($hasErrors = true)
 {
     if (!isset($this->_outputDir)) {
         throw new Exception('Output directory is not set!');
     }
     foreach ($this->_ressourceFolders as $folder) {
         $this->_cbFDHandler->copyDirectory($this->_templateDir . DIRECTORY_SEPARATOR . $folder, $this->_outputDir . DIRECTORY_SEPARATOR . $folder);
     }
     $template = $hasErrors ? 'index.tpl' : 'noErrors.tpl';
     $content = $this->_cbFDHandler->loadFile($this->_templateDir . DIRECTORY_SEPARATOR . $template);
     $this->_cbFDHandler->createFile($this->_outputDir . DIRECTORY_SEPARATOR . 'index.html', $content);
 }
 /**
  * Generate javascript highlighted source for HTML files.
  *
  * @param string $fileName The filename where source should be highlighted
  * @param arry   $errors   The error list for this files as highlight base
  *
  * @return string
  * @see cbFDHandler::loadFile
  */
 public function getHighlightedSource($fileName, $errors, $projectSource)
 {
     ob_start();
     $code = $this->cbFDHandler->loadFile($projectSource . '/' . $fileName);
     ini_set('highlight.comment', 'comment');
     ini_set('highlight.default', 'default');
     ini_set('highlight.keyword', 'keyword');
     ini_set('highlight.string', 'string');
     ini_set('highlight.html', 'html');
     $code = highlight_string($code, true);
     $code = str_replace(array('&nbsp;', '&amp;', '<br />', '<span style="color: '), array(' ', '&#38;', "\n", '<span class="'), substr($code, 33, -15));
     $code = trim($code);
     $code = str_replace("\r", "\n", $code);
     $code = preg_replace("!\n\n\n+!", "\n\n", $code);
     $lines = explode("\n", $code);
     $previous = false;
     // Output Listing
     echo " <ol class=\"code\">\n";
     foreach ($lines as $key => $line) {
         if (substr($line, 0, 7) == '</span>') {
             $previous = false;
             $line = substr($line, 7);
         }
         if (empty($line)) {
             $line = '&#160;';
         }
         if ($previous) {
             $line = "<span class=\"{$previous}\">" . $line;
         }
         // Set Previous Style
         if (strpos($line, '<span') !== false) {
             switch (substr($line, strrpos($line, '<span') + 13, 1)) {
                 case 'c':
                     $previous = 'comment';
                     break;
                 case 'd':
                     $previous = 'default';
                     break;
                 case 'k':
                     $previous = 'keyword';
                     break;
                 case 's':
                     $previous = 'string';
                     break;
             }
         }
         // Unset Previous Style Unless Span Continues
         if (substr($line, -7) == '</span>') {
             $previous = false;
         } elseif ($previous) {
             $line .= '</span>';
         }
         $num = $key + 1;
         $classname = 'white';
         $classnameEven = 'even';
         $prefix = '';
         $suffix = '';
         $max = 0;
         $min = count($lines);
         $singleRow = false;
         foreach ($errors as $error) {
             if ($error['line'] <= $num && $error['to-line'] >= $num) {
                 if ($max <= (int) $error['to-line']) {
                     $max = (int) $error['to-line'];
                 }
                 if ($min >= (int) $error['line']) {
                     $min = (int) $error['line'];
                 }
                 $classnameEven = 'transparent';
                 $classname = 'transparent';
                 if ((int) $error['line'] == $num) {
                     $prefix = sprintf('<li id="line-%s-%s" class="%s" ><ul>', $error['line'], $error['to-line'], $prefix != '' ? 'moreErrors' : $error['source']);
                 }
                 if ((int) $error['to-line'] == $num) {
                     $suffix = "</ul></li>";
                 }
             }
         }
         if ($num < $max && $min == $num) {
             $suffix = '';
         }
         echo sprintf('%s<li id="line-%d" class="%s"> <a name="line-%d"></a> <code>%s</code></li>%s' . "\n", $prefix, $num, $key % 2 ? $classnameEven : $classname, $num, $line, $suffix);
     }
     echo "</ol>\n";
     $contents = ob_get_contents();
     ob_end_clean();
     return $contents;
 }