Create XStream for template load/save.

@return XStream
559029
public static XStream createTemplateXStream() {
        XStream xstream = new XStream(new DomDriver("UTF-8"));
        xstream.setMode(XStream.NO_REFERENCES);
        xstream.registerConverter(new FontConverter());
        
        xstream.alias("template", ReportTemplate.class);
        xstream.useAttributeFor(ReportTemplate.class, "version");
        xstream.alias("band-element", BandElement.class);
        xstream.alias("column-band-element", ColumnBandElement.class);
        
        return xstream;
    }
1358614
protected XStream createXStream(HierarchicalStreamDriver driver, NaaccrPatientConverter patientConverter) {
        XStream xstream = new XStream(driver) {
            @Override
            protected void setupConverters() {
                registerConverter(new NullConverter(), PRIORITY_VERY_HIGH);
                registerConverter(new IntConverter(), PRIORITY_NORMAL);
                registerConverter(new FloatConverter(), PRIORITY_NORMAL);
                registerConverter(new DoubleConverter(), PRIORITY_NORMAL);
                registerConverter(new LongConverter(), PRIORITY_NORMAL);
                registerConverter(new ShortConverter(), PRIORITY_NORMAL);
                registerConverter(new BooleanConverter(), PRIORITY_NORMAL);
                registerConverter(new ByteConverter(), PRIORITY_NORMAL);
                registerConverter(new StringConverter(), PRIORITY_NORMAL);
                registerConverter(new DateConverter(), PRIORITY_NORMAL);
                registerConverter(new CollectionConverter(getMapper()), PRIORITY_NORMAL);
                registerConverter(new ReflectionConverter(getMapper(), getReflectionProvider()), PRIORITY_VERY_LOW);
            }
        };

        // setup proper security environment
        xstream.addPermission(NoTypePermission.NONE);
        xstream.addPermission(new WildcardTypePermission(new String[] {"com.imsweb.naaccrxml.**"}));

        // tell XStream how to read/write our main entities
        xstream.alias(NaaccrXmlUtils.NAACCR_XML_TAG_ROOT, NaaccrData.class);
        xstream.alias(NaaccrXmlUtils.NAACCR_XML_TAG_ITEM, Item.class);
        xstream.alias(NaaccrXmlUtils.NAACCR_XML_TAG_PATIENT, Patient.class);

        // add some attributes
        xstream.aliasAttribute(NaaccrData.class, "_baseDictionaryUri", NaaccrXmlUtils.NAACCR_XML_ROOT_ATT_BASE_DICT);
        xstream.aliasAttribute(NaaccrData.class, "_userDictionaryUri", NaaccrXmlUtils.NAACCR_XML_ROOT_ATT_USER_DICT);
        xstream.aliasAttribute(NaaccrData.class, "_recordType", NaaccrXmlUtils.NAACCR_XML_ROOT_ATT_REC_TYPE);
        xstream.aliasAttribute(NaaccrData.class, "_timeGenerated", NaaccrXmlUtils.NAACCR_XML_ROOT_ATT_TIME_GENERATED);
        xstream.aliasAttribute(NaaccrData.class, "_specificationVersion", NaaccrXmlUtils.NAACCR_XML_ROOT_ATT_SPEC_VERSION);

        // all collections should be wrap into collection tags, but it's nicer to omit them in the XML; we have to tell XStream though
        xstream.addImplicitCollection(NaaccrData.class, "_items", Item.class);
        xstream.addImplicitCollection(NaaccrData.class, "_patients", Patient.class);

        // handle patients
        xstream.registerConverter(patientConverter);

        return xstream;
    }
110070
protected function _buildFOpenStreamContext()
    {
        # Set the headers required to work with fopen
        $headers =  $this->_generateProxyRequestHeaders(TRUE);
        $headers.= 'Cookie: ' . $this->_buildProxyRequestCookieString();

        # Create the stream context
        $stream_context = array (
            'header'        => $headers,
            'user_agent'    => $this->_requestUserAgent
        );

        # Figure out what kind of request we're making, and what to fill it with
        $stream_context['method'] = $this->_requestMethod;

        if($this->_requestMethod === 'POST' ||
           $this->_requestMethod === 'PUT')
        {
            $stream_context['content'] = $this->_requestBody;
        }

        return stream_context_create(array('http' => $stream_context));
    }
413767
public function loadAsXML()
    {
        $this->checkFileExists();
        $xml = new \DomDocument ();
        libxml_use_internal_errors(true);
        $result = $xml->load($this->absoluteFileName);
        if ($result) {
            return $xml;
        }
        $messageObject = ArrayUtil::getFromArray(libxml_get_errors(), 0);
        $libXMLMessage = ObjectUtil::getFromObject($messageObject, "message");
        $message = sprintf(self::EXCEPTION_INVALID_XML, $this->absoluteFileName, $libXMLMessage);
        $e = new \Exception(libxml_get_errors()[0]->message);
        libxml_clear_errors();
        throw $e;
    }
221728
public function loadAsXSLTProcessor()
    {
        $this->checkFileExists();
        $xsl = new \XSLTProcessor();
        $xsl->importStylesheet($this->loadAsXML());
        return $xsl;
    }
866011
private function prepareCreateXMLChildObject()
    {
        $fragment = new CNabuPHPMethodBuilder(
            $this, 'createXMLChildObject', CNabuPHPMethodBuilder::METHOD_PROTECTED,
            false, false, false, true, 'CNabuXMLDataObject'
        );
        $this->getDocument()->addUse('\nabu\xml\CNabuXMLDataObject');

        $fragment->addComment("Create the XML Child object filled with their Data Object.");
        $fragment->addComment("@return CNabuXMLDataObject Returns a XML instance with the child data object instance.");

        $fragment->addParam(
            'nb_child', 'CNabuDataObject', true, null, 'CNabuDataObject',
            'Child data object.'
        );
        $this->getDocument()->addUse('\nabu\data\CNabuDataObject');

        $class_name = preg_replace('/List(Base)*$/', '', $this->class_name);
        $class_ns = preg_replace('/\\\\base$/', '', $this->class_namespace);

        $fragment->addFragment("return new $class_name(\$nb_child);");
        $this->getDocument()->addUse("\\$class_ns\\$class_name");

        $this->addFragment($fragment);
    }
93697
public function stream()
    {
        $stream = fopen($this->file, 'r');

        $stream = $stream === false ? null : $stream;

        return new Stream($stream);
    }
126085
protected function createCoreXmlFile()
    {
        $createdDate = (new \DateTime())->format(\DateTime::W3C);
        $coreXmlFileContents = <<<EOD
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <dcterms:created xsi:type="dcterms:W3CDTF">$createdDate</dcterms:created>
    <dcterms:modified xsi:type="dcterms:W3CDTF">$createdDate</dcterms:modified>
    <cp:revision>0</cp:revision>
</cp:coreProperties>
EOD;

        $this->createFileWithContents($this->docPropsFolder, self::CORE_XML_FILE_NAME, $coreXmlFileContents);

        return $this;
    }
917133
public function toXML()
    {
        $namespace = 'tns';
        $writer = new XMLWriter();
        $writer->openMemory();
        $writer->setIndent(true);
        $writer->setIndentString('    ');
        $writer->startElementNs($namespace, 'Porez', null);
        if ($this->getName()) {
            $writer->writeElementNs($namespace, 'Naziv', null, $this->getName());
        }
        $writer->writeElementNs($namespace, 'Stopa', null, $this->getRate());
        $writer->writeElementNs($namespace, 'Osnovica', null, $this->getBaseValue());
        $writer->writeElementNs($namespace, 'Iznos', null, $this->getValue());
        $writer->endElement();

        return $writer->outputMemory();
    }
754209
@Override
    public XMLStreamReader createXMLStreamReader(InputStream in)
        throws XMLStreamException
    {
        // false for auto-close, since caller has access to the input stream
        return createSR(null, in, null, false, false);
    }
1142410
public InputStream toInputStream() {
        
        String text = toXml();
        return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
        
    }
751728
private XStream getXStreamObject()
    {
        XStream stream = new XStream();
        stream.alias("indexerProperties", IndexerProperties.class);
        stream.alias("node", IndexerProperties.Node.class);
        return stream;
    }
784566
public function toXML(){

            $oXMLout = new \XMLWriter();
            $oXMLout->openMemory();
            $oXMLout->setIndent(true);
            $oXMLout->setIndentString('    ');


        $oXMLout->startDocument("1.0", 'utf-8');
        $oXMLout->startElement('tasks');

        /**
         * @var \Dlin\Saasu\Task\Task $task
         */
        foreach($this->tasks as $task){
           $oXMLout->writeRaw("\n".$task->toXML());
        }
        $oXMLout->endElement();
        $oXMLout->endDocument();

        $xml = $oXMLout->outputMemory();

        return $xml;
    }
1317602
public function create()
    {
        $loaders = array();

        if (count($this->xmlMappings) > 1) {
            $loaders[] = new XmlFilesLoader($this->xmlMappings, $this->constraintNamespaces);
        } elseif (1 === count($this->xmlMappings)) {
            $loaders[] = new XmlFileLoader($this->xmlMappings[0], $this->constraintNamespaces);
        }

        if (count($this->yamlMappings) > 1) {
            $loaders[] = new YamlFilesLoader($this->yamlMappings, $this->constraintNamespaces);
        } elseif (1 === count($this->yamlMappings)) {
            $loaders[] = new YamlFileLoader($this->yamlMappings[0], $this->constraintNamespaces);
        }

        foreach ($this->methodMappings as $methodName) {
            $loaders[] = new StaticMethodLoader($methodName);
        }

        if ($this->annotationReader) {
            $loaders[] = new AnnotationLoader($this->annotationReader);
        }

        $loader = null;

        if (count($loaders) > 1) {
            $loader = new LoaderChain($loaders);
        } elseif (1 === count($loaders)) {
            $loader = $loaders[0];
        }

        return new LazyLoadingMetadataFactory($loader, $this->metadataCache);
    }
880699
protected function createStream()
    {
        $host = sprintf('udp://%s:%d', $this->config['host'], $this->config['port']);

        // stream the data using UDP and suppress any errors
        $this->stream = @stream_socket_client($host);
    }
712365
public function getEncodedStream()
    {
        if (!$this->_isStream) {
            // require_once 'Zend/Mime/Exception.php';
            throw new Zend_Mime_Exception('Attempt to get a stream from a string part');
        }

        //stream_filter_remove(); // ??? is that right?
        switch ($this->encoding) {
            case Zend_Mime::ENCODING_QUOTEDPRINTABLE:
                $filter = stream_filter_append(
                    $this->_content,
                    'convert.quoted-printable-encode',
                    STREAM_FILTER_READ,
                    array(
                        'line-length'      => 76,
                        'line-break-chars' => Zend_Mime::LINEEND
                    )
                );
                if (!is_resource($filter)) {
                    // require_once 'Zend/Mime/Exception.php';
                    throw new Zend_Mime_Exception('Failed to append quoted-printable filter');
                }
                break;
            case Zend_Mime::ENCODING_BASE64:
                $filter = stream_filter_append(
                    $this->_content,
                    'convert.base64-encode',
                    STREAM_FILTER_READ,
                    array(
                        'line-length'      => 76,
                        'line-break-chars' => Zend_Mime::LINEEND
                    )
                );
                if (!is_resource($filter)) {
                    // require_once 'Zend/Mime/Exception.php';
                    throw new Zend_Mime_Exception('Failed to append base64 filter');
                }
                break;
            default:
        }
        return $this->_content;
    }
69742
protected InputStream getTemplateAsStream(TestContext context) {
        Resource resource;
        if (templateResource != null) {
            resource = templateResource;
        } else {
            resource = FileUtils.getFileResource(template, context);
        }

        String templateYml;
        try {
            templateYml = context.replaceDynamicContentInString(FileUtils.readToString(resource));
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to read template resource", e);
        }
        return new ByteArrayInputStream(templateYml.getBytes());
    }