/**
  *
  * @param \DOMDocument $doc
  * @return XmlConfigurationDriver
  */
 private function parseDom(\blaze\persistence\cfg\Configuration $config, \DOMDocument $doc, \blaze\lang\String $name, \blaze\io\File $file = null)
 {
     if ($doc->documentElement->localName != 'persistence-configuration') {
         throw new \blaze\lang\IllegalArgumentException($name . ': The first node has to be of the type "persistence-configuration"');
     }
     if ($doc->documentElement->firstChild->localName != 'persistence-factory') {
         throw new \blaze\lang\IllegalArgumentException($name . ': The first child node has to be of the type "persistence-factory"');
     }
     foreach ($doc->documentElement->firstChild->childNodes as $child) {
         switch ($child->localName) {
             case 'property':
                 if ($child->firstChild instanceof \DOMText) {
                     $config->setProperty($child->getAttribute('name'), $child->firstChild->wholeText);
                 } else {
                     $config->setProperty($child->getAttribute('name'), '');
                 }
                 break;
             case 'mapping':
                 if ($file === null) {
                     throw new \blaze\lang\Exception('The mapping-tag can only be used if a file or a base path is given.');
                 }
                 $config->addRessource(new \blaze\io\File($file->getParent(), $child->getAttribute('ressource')));
                 break;
         }
     }
 }
 public function forwardEngineerXmlFiles(\blaze\io\File $dir)
 {
     foreach ($dir->listFiles() as $file) {
         if ($file->getName()->substring($file->getName()->lastIndexOf('.') + 1)->compareTo('xml') == 0) {
             $this->forwardEngineerXmlFile($file);
         }
     }
     // Lookup the classdescriptors and tabledescriptors
 }
Example #3
0
 /**
  *
  * @param \blaze\io\File $dir
  * @param boolean $recursive
  * @return \blaze\collections\ListI
  */
 private function parseDir(\blaze\io\File $dir, $recursive)
 {
     $mappings = new \blaze\collections\lists\ArrayList();
     $files = $dir->listFiles();
     foreach ($files as $file) {
         if ($recursive && $file->isDirectory()) {
             $mappings->addAll($this->parseDir($file, $recursive));
         }
         if ($file->getFileName()->endsWith('.xml')) {
             $mappings->add($this->parseFile($file));
         }
     }
     return $mappings;
 }
Example #4
0
 private function parseAndCreateView(\blaze\io\File $file, $compositionChildren = null)
 {
     $path = $file->getAbsolutePath();
     $dom = new \DOMDocument();
     $dom->load($file->getAbsolutePath()->toNative());
     $viewId = $path->substring($this->viewDir->getAbsolutePath()->length())->replace(\blaze\io\File::$directorySeparator, '/')->trim('/');
     $root = new \blaze\web\component\UIViewRoot();
     if ($compositionChildren == null) {
         $root->setViewId($viewId->toNative());
         $this->views->put($root->getViewId(), $root);
     }
     $this->handleChildren($root, $dom->documentElement->childNodes, $compositionChildren);
     if ($compositionChildren != null) {
         return $root;
     }
 }
Example #5
0
 /**
  * Static method that creates a unique filename whose name begins with
  * $prefix and ends with $suffix in the directory $directory. $directory
  * is a reference to a File Object.
  * Then, the file is locked for exclusive reading/writing.
  *
  * @author      manuel holtgrewe, grin@gmx.net
  * @throws      IOException
  * @access      public
  */
 public function createTempFile(string $prefix, string $suffix, File $directory)
 {
     // quick but efficient hack to create a unique filename ;-)
     $result = null;
     do {
         $result = new File($directory, $prefix . substr(md5(time()), 0, 8) . $suffix);
     } while (file_exists($result->getPath()->toNative()));
     self::$fs->createNewFile($result->getPath()->toNative());
     self::$fs->lock($result);
     return $result;
 }
 private function initApplication()
 {
     if ($this->netletContext != null) {
         return;
     }
     $f = new File(ClassLoader::getSystemClassLoader()->getClassPath(), $this->package . File::$directorySeparator . 'web.xml');
     $doc = new \DOMDocument();
     $doc->load($f->getAbsolutePath());
     $this->config = $doc;
     $useDefault = true;
     foreach ($doc->documentElement->childNodes as $node) {
         if ($node->nodeType == XML_ELEMENT_NODE && $node->localName == 'netletConfig') {
             $this->netletContext = new NetletContextImpl(self::getInitParams($node), $this);
             $useDefault = false;
             self::handleConfigChildren($node);
         }
     }
     if ($useDefault) {
         $this->netletContext = new NetletContextImpl($this->getInitParams(self::$defaultNetletConfig), $this);
         self::handleConfigChildren(self::$defaultNetletConfig);
     }
 }
Example #7
0
 /**
  * Unlocks a file and throws an IO Error if this is not possible.
  *
  * @throws Exception
  * @return void
  */
 public function unlock(File $f)
 {
     $filename = $f->getPath()->toNative();
     $fp = @fopen($filename, "w");
     $result = @flock($fp, LOCK_UN);
     fclose($fp);
     if (!$result) {
         throw new Exception("Could not unlock file '{$filename}'");
     }
 }