/** * */ public function parseFile($xmlFile) { try { $this->data = array(); try { $fr = new FileReader($xmlFile); } catch (Exception $e) { $f = new PhingFile($xmlFile); throw new BuildException("XML File not found: " . $f->getAbsolutePath()); } $br = new BufferedReader($fr); $this->parser = new ExpatParser($br); $this->parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0); $this->parser->setHandler($this); try { $this->parser->parse(); } catch (Exception $e) { print $e->getMessage() . "\n"; $br->close(); } $br->close(); } catch (Exception $e) { print $e->getMessage() . "\n"; print $e->getTraceAsString(); } return $this->data; }
/** * Returns the next character in the filtered stream. If the desired * number of lines have already been read, the resulting stream is * effectively at an end. Otherwise, the next character from the * underlying stream is read and returned. * * @param int $len * @return int|string the next character in the resulting stream, or -1 * if the end of the resulting stream has been reached * * @throws IOException if the underlying stream throws an IOException * during reading * @throws BuildException */ public function read($len = 0) { // do the "singleton" initialization if (!$this->getInitialized()) { $this->initialize(); $this->setInitialized(true); } $ch = -1; // The readers return -1 if they end. So simply read the "prepend" // after that the "content" and at the end the "append" file. if ($this->prependReader !== null) { $ch = $this->prependReader->read(); if ($ch === -1) { // I am the only one so I have to close the reader $this->prependReader->close(); $this->prependReader = null; } } if ($ch === -1) { $ch = parent::read(); } if ($ch === -1 && $this->appendReader !== null) { $ch = $this->appendReader->read(); if ($ch === -1) { // I am the only one so I have to close the reader $this->appendReader->close(); $this->appendReader = null; } } return $ch; }
/** * set the text using a file * @param file the file to use * @throws BuildException if the file does not exist, or cannot be * read */ public function setFile(PhingFile $file) { // non-existing files are not allowed if (!$file->exists()) { throw new BuildException("File " . $file . " does not exist."); } $reader = null; try { if ($this->encoding == null) { $reader = new BufferedReader(new FileReader($file)); } else { $reader = new BufferedReader(new InputStreamReader(new FileInputStream($file))); } $this->value = $reader->read(); } catch (IOException $ex) { $reader->close(); throw new BuildException($ex); } $reader->close(); }
/** * Creates the ExpatParser, sets root handler and kick off parsing * process. * * @throws BuildException if there is any kind of execption during * the parsing process * @access private */ protected function parse() { try { // get parse context $ctx = $this->project->getReference("phing.parsing.context"); if (null == $ctx) { // make a new context and register it with project $ctx = new PhingXMLContext($this->project); $this->project->addReference("phing.parsing.context", $ctx); } //record this parse with context $ctx->addImport($this->buildFile); if (count($ctx->getImportStack()) > 1) { // this is an imported file // modify project tag parse behavior $this->setIgnoreProjectTag(true); } // push action onto global stack $ctx->startConfigure($this); $reader = new BufferedReader(new FileReader($this->buildFile)); $parser = new ExpatParser($reader); $parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0); $parser->setHandler(new RootHandler($parser, $this)); $this->project->log("parsing buildfile " . $this->buildFile->getName(), Project::MSG_VERBOSE); $parser->parse(); $reader->close(); // mark parse phase as completed $this->isParsing = false; // execute delayed tasks $this->parseEndTarget->main(); // pop this action from the global stack $ctx->endConfigure(); } catch (Exception $exc) { throw new BuildException("Error reading project file", $exc); } }
/** * Does the work. * * @throws BuildException if someting goes wrong with the build */ public final function main() { if ($this->cvsRoot === null) { throw new BuildException("cvsroot is required"); } if ($this->password === null) { throw new BuildException("password is required"); } $this->log("cvsRoot: " . $this->cvsRoot, Project::MSG_DEBUG); $this->log("password: "******"passFile: " . $this->passFile->__toString(), Project::MSG_DEBUG); $reader = null; $writer = null; try { $buf = ""; if ($this->passFile->exists()) { $reader = new BufferedReader(new FileReader($this->passFile)); $line = null; while (($line = $reader->readLine()) !== null) { if (!StringHelper::startsWith($this->cvsRoot, $line)) { $buf .= $line . PHP_EOL; } } } $pwdfile = $buf . $this->cvsRoot . " A" . $this->mangle($this->password); $this->log("Writing -> " . $pwdfile, Project::MSG_DEBUG); $writer = new BufferedWriter(new FileWriter($this->passFile)); $writer->write($pwdfile); $writer->newLine(); $writer->close(); if ($reader) { $reader->close(); } } catch (IOException $e) { if ($reader) { try { $reader->close(); } catch (Exception $e) { } } if ($writer) { try { $writer->close(); } catch (Exception $e) { } } throw new BuildException($e); } }
/** * The heart of the matter. This is where the selector gets to decide * on the inclusion of a file in a particular fileset. * * @param PhingFile $basedir base directory the scan is being done from * @param string $filename the name of the file to check * @param PhingFile $file PhingFile object the selector can use * * @throws BuildException * * @return bool whether the file should be selected or not */ public function isSelected(PhingFile $basedir, $filename, PhingFile $file) { $this->validate(); if ($file->isDirectory()) { return true; } if ($this->myRegExp === null) { $this->myRegExp = new RegularExpression(); $this->myRegExp->setPattern($this->userProvidedExpression); if (!$this->casesensitive) { $this->myRegExp->setIgnoreCase(true); } $this->myExpression = $this->myRegExp->getRegexp($this->getProject()); } $in = null; try { $in = new BufferedReader(new FileReader($file)); $teststr = $in->readLine(); while ($teststr !== null) { if ($this->myExpression->matches($teststr)) { return true; } $teststr = $in->readLine(); } $in->close(); return false; } catch (IOException $ioe) { if ($in) { $in->close(); } throw new BuildException("Could not read file " . $filename); } }
/** * Reads file names from a file and adds them to the files array. * * @param Project $p * * @throws BuildException */ private function readListFile(Project $p) { $listReader = null; try { // Get a FileReader $listReader = new BufferedReader(new FileReader($this->listfile)); $line = $listReader->readLine(); while ($line !== null) { if (!empty($line)) { $line = $p->replaceProperties($line); $this->filenames[] = trim($line); } $line = $listReader->readLine(); } } catch (Exception $e) { if ($listReader) { $listReader->close(); } throw new BuildException("An error occurred while reading from list file " . $this->listfile->__toString() . ": " . $e->getMessage()); } $listReader->close(); }
/** * Parses a XML input file and returns a newly created and * populated AppData structure. * * @param string $xmlFile The input file to parse. * @return AppData populated by <code>xmlFile</code>. */ public function parseFile($xmlFile) { // we don't want infinite recursion if ($this->isAlreadyParsed($xmlFile)) { return; } $domDocument = new DomDocument('1.0', 'UTF-8'); $domDocument->load($xmlFile); // store current schema file path $this->schemasTagsStack[$xmlFile] = array(); $this->currentXmlFile = $xmlFile; try { $fr = new FileReader($xmlFile); } catch (Exception $e) { $f = new PhingFile($xmlFile); throw new Exception("XML File not found: " . $f->getAbsolutePath()); } $br = new BufferedReader($fr); $this->parser = new ExpatParser($br); $this->parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0); $this->parser->setHandler($this); try { $this->parser->parse(); } catch (Exception $e) { $br->close(); throw $e; } $br->close(); array_pop($this->schemasTagsStack); return $this->app; }
/** * The heart of the matter. This is where the selector gets to decide * on the inclusion of a file in a particular fileset. * * @param PhingFile $basedir * @param string $filename * @param PhingFile $file * * @throws BuildException * * @internal param the $basedir base directory the scan is being done from * @internal param is $filename the name of the file to check * @internal param a $file PhingFile object the selector can use * * @return bool whether the file should be selected or not */ public function isSelected(PhingFile $basedir, $filename, PhingFile $file) { $this->validate(); if ($file->isDirectory()) { return true; } $userstr = $this->contains; if (!$this->casesensitive) { $userstr = strtolower($this->contains); } $in = null; try { $in = new BufferedReader(new FileReader($file)); $teststr = $in->readLine(); while ($teststr !== null) { if (!$this->casesensitive) { $teststr = strtolower($teststr); } if (strpos($teststr, $userstr) !== false) { return true; } $teststr = $in->readLine(); } $in->close(); return false; } catch (IOException $ioe) { if ($in) { $in->close(); } throw new BuildException("Could not read file " . $filename); } }
/** * Creates the ExpatParser, sets root handler and kick off parsing * process. * * @throws BuildException if there is any kind of execption during * the parsing process * @access private */ protected function parse() { try { $reader = new BufferedReader(new FileReader($this->buildFile)); $parser = new ExpatParser($reader); $parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0); $parser->setHandler(new RootHandler($parser, $this)); $this->project->log("parsing buildfile " . $this->buildFile->getName(), Project::MSG_VERBOSE); $parser->parse(); $reader->close(); } catch (Exception $exc) { throw new BuildException("Error reading project file", $exc); } }
/** * Reads path matching patterns from a file and adds them to the * includes or excludes list */ private function readPatterns(PhingFile $patternfile, &$patternlist, Project $p) { $patternReader = null; try { // Get a FileReader $patternReader = new BufferedReader(new FileReader($patternfile)); // Create one NameEntry in the appropriate pattern list for each // line in the file. $line = $patternReader->readLine(); while ($line !== null) { if (!empty($line)) { $line = $p->replaceProperties($line); $this->addPatternToList($patternlist)->setName($line); } $line = $patternReader->readLine(); } } catch (IOException $ioe) { $msg = "An error occured while reading from pattern file: " . $patternfile->__toString(); if ($patternReader) { $patternReader->close(); } throw new BuildException($msg, $ioe); } $patternReader->close(); }
/** * Transform the data dump input file into SQL and writes it to the output stream. * * @param PhingFile $xmlFile * @param Writer $out */ public function transform(PhingFile $xmlFile, Writer $out) { $this->sqlWriter = $out; // Reset some vars just in case this is being run multiple times. $this->currTableName = $this->currBuilder = null; $this->builderClazz = $this->generatorConfig->getBuilderClassname('datasql'); try { $fr = new FileReader($xmlFile); } catch (Exception $e) { throw new BuildException("XML File not found: " . $xmlFile->getAbsolutePath()); } $br = new BufferedReader($fr); $this->parser = new ExpatParser($br); $this->parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0); $this->parser->setHandler($this); try { $this->parser->parse(); } catch (Exception $e) { print $e->getMessage() . "\n"; $br->close(); } $br->close(); }
/** * @param PhingXMLContext $ctx * @throws ExpatParseException */ protected function _parse(PhingXMLContext $ctx) { // push action onto global stack $ctx->startConfigure($this); $reader = new BufferedReader(new FileReader($this->buildFile)); $parser = new ExpatParser($reader); $parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0); $parser->setHandler(new RootHandler($parser, $this, $ctx)); $this->project->log("parsing buildfile " . $this->buildFile->getName(), Project::MSG_VERBOSE); $parser->parse(); $reader->close(); // mark parse phase as completed $this->isParsing = false; // execute delayed tasks $this->parseEndTarget->main(); // pop this action from the global stack $ctx->endConfigure(); }