Пример #1
0
 /**
  *
  * @param string
  * The name of a {@link Property} of $this {@link Node}
  * @param mixed
  * The value to be assigned
  * @param int|null
  * The type of the {@link Property} (Optional: NULL if not
  * specified).
  * @return object
  * A {@link Property} object
  * @throws {@link ValueFormatException}
  * If <i>$value</i> cannot be converted to the specified type or
  * if the property already exists and is multi-valued.
  * @throws {@link VersionException}
  * If this node is versionable and checked-in or is non-versionable but
  * its nearest versionable ancestor is checked-in and this implementation
  * performs this validation immediately instead of waiting until
  * {@link save()}.
  * @throws {@link LockException}
  * If a lock prevents the setting of the property and this implementation
  * performs this validation immediately instead of waiting until
  * {@link save()}.
  * @throws {@link ConstraintViolationException}
  * If the change would violate a node-type or other constraint and this
  * implementation performs this validation immediately instead of
  * waiting until {@link save()}.
  * @throws {@link RepositoryException}
  * If another error occurs.
  * @see PHPCR_Node::setProperty()
  */
 public function setProperty($name, $value, $type = 1)
 {
     $isNew = true;
     if ($this->hasProperty($name)) {
         $isNew = false;
     }
     $filename = null;
     switch ($type) {
         case PHPCR_PropertyType::BINARY:
             $pr = new Java("javax.jcr.PropertyType");
             $type = $pr->BINARY;
             $strlen = strlen($value);
             // keep it in memory, if small
             if ($strlen < 500) {
                 $out = new Java("java.io.ByteArrayOutputStream");
                 $arr = array();
                 for ($i = 0; $i < $strlen; $i++) {
                     $val = ord(substr($value, $i, 1));
                     if ($val >= 128) {
                         $val = $val - 256;
                     }
                     $arr[] = $val;
                 }
                 $out->write($arr);
                 $value = new Java("java.io.ByteArrayInputStream", $out->toByteArray());
             } else {
                 $filename = tempnam(sys_get_temp_dir(), "jrcr");
                 chmod($filename, 0666);
                 file_put_contents($filename, $value);
                 $value = new Java("java.io.FileInputStream", $filename);
             }
             break;
         case PHPCR_PropertyType::DATE:
             $pr = new Java("javax.jcr.PropertyType");
             $type = $pr->DATE;
             //$ValueFactory = new Java("javax.jcr.ValueFactory");
             $cal = new Java("java.util.Calendar");
             $val = $cal->getInstance();
             if ($value instanceof DateTime) {
                 $val->setTimeInMillis($value->format('U') * 1000);
             } else {
                 $val->setTimeInMillis($value * 1000);
             }
             $value = $val;
             break;
     }
     if (!is_object($value) && $type) {
         $jrprop = $this->JRnode->setProperty($name, $value, $type);
     } elseif ($value instanceof jr_cr_node) {
         $jrprop = $this->JRnode->setProperty($name, $value->JRnode);
     } else {
         $jrprop = $this->JRnode->setProperty($name, $value);
     }
     if (null === $jrprop) {
         throw new PHPCR_RepositoryException("Couldn't create new property");
     }
     if ($filename) {
         unlink($filename);
     }
     $property = new jr_cr_property($this, $jrprop);
     $this->addPropertyToList($property);
     if ($isNew) {
         $property->setNew(true);
     }
     $property->setModified(true);
     $this->setModified(true);
     if ($this->session->cache) {
         $this->session->cache->clean(Zend_Cache::CLEANING_MODE_ALL);
     }
 }
Пример #2
0
 /**
  * @param $path
  * @return Java object Input Stream
  */
 public function createJavaInputStream($path)
 {
     $handle = fopen($path, "r");
     $contents = fread($handle, filesize($path));
     fclose($handle);
     $out = new Java("java.io.ByteArrayOutputStream");
     $arr = array();
     $strlen = strlen($contents);
     for ($i = 0; $i < $strlen; $i++) {
         $val = ord(substr($contents, $i, 1));
         if ($val >= 128) {
             $val = $val - 256;
         }
         $arr[] = $val;
     }
     $out->write($arr);
     $value = new Java("java.io.ByteArrayInputStream", $out->toByteArray());
     return $value;
 }