Implementation of save.

@param string $uri
@param boolean $formatOutput
@throws \qtism\data\storage\xml\XmlStorageException
@return string
168447
protected function saveImplementation($uri = '', $formatOutput = true)
    {
        $qtiComponent = $this->getDocumentComponent();

        if (!empty($qtiComponent)) {
            $this->setDomDocument(new DOMDocument('1.0', 'UTF-8'));

            if ($formatOutput == true) {
                $this->getDomDocument()->formatOutput = true;
            }

            try {
                // If overriden, beforeSave may alter a last time
                // the documentComponent prior serialization.
                // Note: in use only when saving to a file.
                if (empty($uri) === false) {
                    $this->beforeSave($this->getDocumentComponent(), $uri);
                }

                $factory = $this->createMarshallerFactory();
                $marshaller = $factory->createMarshaller($this->getDocumentComponent());
                $element = $marshaller->marshall($this->getDocumentComponent());

                $rootElement = $this->getDomDocument()->importNode($element, true);
                $this->getDomDocument()->appendChild($rootElement);
                $this->decorateRootElement($rootElement);

                if (empty($uri) === false) {

                    if (@$this->getDomDocument()->save($uri) === false) {
                        // An error occured while saving.
                        $msg = "An error occured while saving QTI-XML file at '${uri}'. Maybe the save location is not reachable?";
                        throw new XmlStorageException($msg, XmlStorageException::WRITE);
                    }
                } else {
                    if (($strXml = $this->getDomDocument()->saveXML()) !== false) {
                        return $strXml;
                    } else {
                        // An error occured while saving.
                        $msg = "An internal error occured while exporting QTI-XML as string.";
                        throw new XmlStorageException($msg, XmlStorageException::WRITE);
                    }
                }
            } catch (DOMException $e) {
                $msg = "An internal error occured while saving QTI-XML data.";
                throw new XmlStorageException($msg, XmlStorageException::UNKNOWN, $e);
            } catch (MarshallerNotFoundException $e) {
                $version = $this->getVersion();
                $problematicQtiClassName = $e->getQtiClassName();
                $msg = "'${problematicQtiClassName}' components are not supported in QTI version '${version}'.";
                throw new XmlStorageException($msg, XmlStorageException::VERSION, $e);
            }
        } else {
            $msg = "The document cannot be saved. No document component object to be saved.";
            throw new XmlStorageException($msg, XmlStorageException::WRITE);
        }
    }
823926
private function createUri($uri)
    {
        if ($this->hasBaseUri() && (stripos($uri, $baseUri = (string) $this->getBaseUri()) === false)) {
            return $baseUri.$uri;
        }

        return $uri;
    }
342390
public function fromUri(Uri $uri): Configuration
    {
        $filename = (string) $uri;

        if (!file_exists($filename)) {
            throw new \InvalidArgumentException(sprintf('File %s could not be found', $filename));
        }

        $xml = new \SimpleXMLElement($filename, 0, true);
        foreach ($this->strategies as $strategy) {
            if ($strategy->supports($xml) !== true) {
                continue;
            }

            return new Configuration($this->applyMiddleware($strategy->convert($xml)));
        }

        throw new RuntimeException('No supported configuration files were found');
    }
769310
public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface
    {
        $clone = clone $this;
        $clone->uri = $uri;

        if ($uri->getHost() !== '') {
            $clone->headers->set('Host', $uri->getHost());
        }

        return $clone;
    }
1139471
public function dump($formatOutput = true)
    {
        // Format output
        if ($formatOutput === true) {
            $this->dom->formatOutput = true;
        }

        return $this->dom->saveXML();
    }
176259
public function retrieve(string $uri): Promise
    {
        return $this->client->textDocument->xcontent(new TextDocumentIdentifier($uri))
            ->then(function (TextDocumentItem $textDocument) {
                return $textDocument->text;
            });
    }
344767
public function save($uri)
    {
        $this->connect($uri);
        //Only attempt to savePClasses if there are any.
        if (!is_array($this->pclasses)) {
            return;
        }
        if (count($this->pclasses) == 0) {
            return;
        }
        $this->savePClasses();
    }
1250350
@Override
    public final void xmlRequestWriteOnSystemOut() throws IOException
    {
        FormattedWriter writer = new FormattedWriter(new OutputStreamWriter(System.out));
        xmlWriteOn(writer);
        writer.flush();
    }
613005
public function save($userid, $apikey, $scope, $name, $args, $xml)
    {
        $key = $this->getKey($userid, $apikey, $scope, $name, $args);
        $ttl = $this->getTimeout($xml);
        $time = time();
        $timeout = $time + $ttl;

        $replace = $this->memcached->replace($key, $xml, $timeout);

        $set = $set_age = false;

        if (!$replace) {
            $set = $this->memcached->set($key, $xml, $timeout);
        }

        $replace_age = $this->memcached->replace($key.'_age', array('age' => $time, 'ttl' => $ttl), $timeout);

        if (!$replace_age) {
            $set_age = $this->memcached->set($key.'_age', array('age' => $time, 'ttl' => $ttl), $timeout);
        }

        return (($replace || $set) && ($replace_age || $set_age));
    }
525798
public void transform(final URI input, final URI output, final List<XMLFilter> filters) throws DITAOTException {
        if (input.equals(output)) {
            transform(input, filters);
        } else {
            transformURI(input, output, filters);
        }
    }
213078
public function save($uri)
    {
        $this->checkURI($uri);

        //Reset DOMDocument.
        if (!$this->dom->loadXML(
            "<?xml version='$this->version' encoding='$this->encoding'?"
            ."><klarna/>"
        )
        ) {
            throw new Klarna_XMLParseException($uri);
        }

        ksort($this->pclasses, SORT_NUMERIC);
        $xpath = new DOMXpath($this->dom);

        foreach ($this->pclasses as $eid => $pclasses) {
            $estore = $xpath->query('/klarna/estore[@id="'.$eid.'"]');

            if ($estore === false || $estore->length === 0) {
                //No estore with matching eid, create it.
                $estore = $this->dom->createElement('estore');
                $estore->setAttribute('id', $eid);
                $this->dom->documentElement->appendChild($estore);
            } else {
                $estore = $estore->item(0);
            }

            foreach ($pclasses as $pclass) {
                if ($eid != $pclass->getEid()) {
                    //This should never occur, failsafe.
                    continue;
                }

                $pnode = $this->dom->createElement('pclass');

                foreach ($this->createFields($pclass) as $field) {
                    $pnode->appendChild($field);
                }

                $pnode->setAttribute('pid', $pclass->getId());
                $pnode->setAttribute('type', $pclass->getType());

                $estore->appendChild($pnode);
            }
        }

        if (!$this->dom->save($uri)) {
            throw new KlarnaException('Failed to save XML document!');
        }
    }
514919
public function save($path, $format = Document::XML)
    {
        switch ($format) {
            case Document::XML:
                $format = 'saveXML';
                break;
            case Document::HTML:
                $format = 'saveHTML';
                break;
            case Document::JSON:
                $format = 'toJson';
                break;
            default:
                throw new DomException('Invalid format', 2);
        }

        $tmp = Storage::temp($this->$format(), 'tmp', '~xml-');

        if ($tmp === false) {
            throw new DomException('Can\'t create tmp file', 2);
        } elseif (copy($tmp, $path) === false) {
            throw new DomException('Can\'t copy tmp file to ' . $path, 2);
        } else {
            unlink($tmp);
        }
    }
1248767
public function convertLocalFile($inputPath, $outputFormat)
    {
        //check whether files are set or not
        if ($inputPath == '')
            throw new Exception('Input file not specified');

        if ($outputFormat == '')
            throw new Exception('Format not specified');

        //build URI
        $strURI = Product::$baseProductUri . '/imaging/' . $this->getFileName() . '/saveAs?format=' . $outputFormat;

        //sign URI
        $signedURI = Utils::sign($strURI);

        $responseStream = Utils::uploadFileBinary($signedURI, $inputPath, 'xml', 'POST');

        $v_output = Utils::validateOutput($responseStream);

        if ($v_output === '') {
            if ($outputFormat == 'html') {
                $saveFormat = 'zip';
            } else {
                $saveFormat = $outputFormat;
            }

            $outputFilename = Utils::getFileName($inputPath) . '.' . $saveFormat;

            Utils::saveFile($responseStream, AsposeApp::$outPutLocation . $outputFilename);
            return $outputFilename;
        } else
            return $v_output;
    }
1316690
public function SaveAbout($UserID, $About) {
      $About = substr($About, 0, 1000);
      $this->SetField($UserID, 'About', $About);
   }
199613
public function save($userid, $apikey, $scope, $name, $args, $xml)
    {
        $this->prepareStatements();

        $argumentString = $this->serializeArguments($args);

        /* @var $deleteStatement \PDOStatement */
        $deleteStatement = $this->statements['delete'];

        if ($userid === null) {
            // Fix for null value userids
            // e. g. for global calls to /eve/
            $userid = 0;
        }

        try {
            $deleteStatement->execute(
                array(
                    ':userId' => $userid,
                    ':scope'  => $scope,
                    ':name'   => $name,
                    ':args'   => $argumentString,
                )
            );
        } catch (\PDOException $e) {
            throw new PhealException('Deleting old cache entries failed!', null, $e);
        }

        /* @var $statement \PDOStatement */
        $statement = $this->statements['save'];

        try {
            $xml = new \SimpleXMLElement($xml);

            $statement->execute(
                array(
                    ':userId' => $userid,
                    ':scope'  => $scope,
                    ':name'   => $name,
                    ':args'   => $argumentString,
                    ':cachedUntil' => $xml->cachedUntil,
                    ':xml'    => $xml->asXML(),
                )
            );
        } catch (\PDOException $e) {
            throw new PhealException('Saving to cache failed!', null, $e);
        }
    }
716754
public function storeImageReference($uri, $fieldId)
    {
        // legacy stores the path to the image without a leading /
        $path = $this->redecorator->redecorateFromSource($uri);

        $insertQuery = $this->connection->createQueryBuilder();
        $insertQuery
            ->insert($this->connection->quoteIdentifier(self::IMAGE_FILE_TABLE))
            ->values(
                [
                    $this->connection->quoteIdentifier('contentobject_attribute_id') => ':fieldId',
                    $this->connection->quoteIdentifier('filepath') => ':path',
                ]
            )
            ->setParameter(':fieldId', $fieldId, PDO::PARAM_INT)
            ->setParameter(':path', $path)
        ;

        $insertQuery->execute();
    }
561802
public function dataFormatoOrigemDestino($data, $formatoOrigem, $formatoDestino)
    {
        $data = $this->converterParaDateTime($data, $formatoOrigem);
        if (!$data) {
            return false;
        }

        return ($data->format($formatoDestino));
    }