Package net.sf.saxon.s9api

Examples of net.sf.saxon.s9api.Serializer


        writer = step;
    }

    public void write(final XdmNode doc) {
        try {
            serializer = new Serializer();

            serializer.setOutputProperty(Serializer.Property.BYTE_ORDER_MARK, serial.getByteOrderMark() ? "yes" : "no");
            // FIXME: support CDATA_SECTION_ELEMENTS
            if (serial.getDoctypePublic() != null) {
                serializer.setOutputProperty(Serializer.Property.DOCTYPE_PUBLIC, serial.getDoctypePublic());
View Full Code Here


        if (logstyle == LogOptions.OFF) {
            // there's nothing to do here...
            return;
        }

        serializer = new Serializer();
        serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
        serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8");
        serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes");

        switch (logstyle) {
View Full Code Here

        return result;
    }

    public String serializeAsXML(XdmNode node) {
        try {
            Serializer serializer = new Serializer();

            serializer.setOutputProperty(Serializer.Property.BYTE_ORDER_MARK, "no");
            serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8");
            serializer.setOutputProperty(Serializer.Property.INDENT, "yes");
            serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
            serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes");

            ByteArrayOutputStream os = new ByteArrayOutputStream();
            serializer.setOutputStream(os);

            S9apiUtils.serialize(runtime, node, serializer);
            String result = os.toString();

            return result;
View Full Code Here

                    String content = null;
                    String contentType = null;
                    if (html) {
                        ByteArrayOutputStream stream = new ByteArrayOutputStream();
                        Serializer serializer = new Serializer();
                        serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8");
                        serializer.setOutputProperty(Serializer.Property.INDENT, "no");
                        serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes");
                        serializer.setOutputProperty(Serializer.Property.METHOD, "html");
                        serializer.setOutputStream(stream);
                        S9apiUtils.serialize(runtime, nodes, serializer);
                        content = stream.toString();
                        contentType = "text/html; charset=utf-8";
                    } else {
                        content = field.getStringValue();
View Full Code Here

            writer.close();
        }
    }

    public void storeXML(FileToZip file, XdmNode doc, OutputStream out) throws SaxonApiException {
        Serializer serializer = makeSerializer(file.getOptions());
        serializer.setOutputStream(out);
        S9apiUtils.serialize(runtime, doc, serializer);
    }
View Full Code Here

        reporter.endReport();
    }

    public String serializeAsXML(XdmNode node) {
        try {
            Serializer serializer = new Serializer();

            serializer.setOutputProperty(Serializer.Property.BYTE_ORDER_MARK, "no");
            serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8");
            serializer.setOutputProperty(Serializer.Property.INDENT, "yes");
            serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
            serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes");

            ByteArrayOutputStream os = new ByteArrayOutputStream();
            serializer.setOutputStream(os);

            S9apiUtils.serialize(runtime, node, serializer);
            String result = os.toString();

            return result;
View Full Code Here

    }

    private static void storeXML(XProcRuntime runtime, XdmNode doc, OutputStream stream) {
        try {
            try {
                Serializer serializer = new Serializer();
                serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8");
                serializer.setOutputProperty(Serializer.Property.INDENT, "no");
                serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes");
                serializer.setOutputProperty(Serializer.Property.METHOD, "xml");

                serializer.setOutputStream(stream);
                S9apiUtils.serialize(runtime, doc, serializer);
            } finally {
                stream.close();
            }
        } catch (IOException ioe) {
View Full Code Here

        serializer.setOutputStream(out);
        S9apiUtils.serialize(runtime, doc, serializer);
    }

    public Serializer makeSerializer(Hashtable<QName,String> options) {
        Serializer serializer = new Serializer();

        if (options == null) {
            return serializer;
        }

        if (options.containsKey(_byte_order_mark)) {
            serializer.setOutputProperty(Serializer.Property.BYTE_ORDER_MARK, "false".equals(options.get(_byte_order_mark)) ? "yes" : "no");
        }

        if (options.containsKey(_cdata_section_elements)) {
            String list = options.get(_cdata_section_elements);

            // FIXME: Why is list="" sometimes?
            if (!"".equals(list)) {
                String[] names = list.split("\\s+");
                list = "";
                for (String name : names) {
                    QName q = new QName(name, step.getNode());
                    list += q.getClarkName() + " ";
                }

                serializer.setOutputProperty(Serializer.Property.CDATA_SECTION_ELEMENTS, list);
            }
        }

        if (options.containsKey(_doctype_public)) {
            serializer.setOutputProperty(Serializer.Property.DOCTYPE_PUBLIC, options.get(_doctype_public));
        }

        if (options.containsKey(_doctype_system)) {
            serializer.setOutputProperty(Serializer.Property.DOCTYPE_SYSTEM, options.get(_doctype_system));
        }

        if (options.containsKey(_encoding)) {
            serializer.setOutputProperty(Serializer.Property.ENCODING, options.get(_encoding));
        }

        if (options.containsKey(_escape_uri_attributes)) {
            serializer.setOutputProperty(Serializer.Property.ESCAPE_URI_ATTRIBUTES, "true".equals(options.get(_escape_uri_attributes)) ? "yes" : "no");
        }

        if (options.containsKey(_include_content_type)) {
            serializer.setOutputProperty(Serializer.Property.INCLUDE_CONTENT_TYPE, "true".equals(options.get(_include_content_type)) ? "yes" : "no");
        }

        if (options.containsKey(_indent)) {
            serializer.setOutputProperty(Serializer.Property.INDENT, "true".equals(options.get(_indent)) ? "yes" : "no");
        }

        if (options.containsKey(_media_type)) {
            serializer.setOutputProperty(Serializer.Property.MEDIA_TYPE, options.get(_media_type));
        }

        if (options.containsKey(_method)) {
            serializer.setOutputProperty(Serializer.Property.METHOD, options.get(_method));
        }

        if (options.containsKey(_normalization_form)) {
            serializer.setOutputProperty(Serializer.Property.NORMALIZATION_FORM, options.get(_normalization_form));
        }

        if (options.containsKey(_omit_xml_declaration)) {
            serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "true".equals(options.get(_omit_xml_declaration)) ? "yes" : "no");
        }

        if (options.containsKey(_standalone)) {
            String standalone = options.get(_standalone);
            if ("true".equals(standalone)) {
                serializer.setOutputProperty(Serializer.Property.STANDALONE, "yes");
            } else if ("false".equals(standalone)) {
                serializer.setOutputProperty(Serializer.Property.STANDALONE, "no");
            }
            // What about omit?
        }

        if (options.containsKey(_undeclare_prefixes)) {
            serializer.setOutputProperty(Serializer.Property.UNDECLARE_PREFIXES, "true".equals(options.get(_undeclare_prefixes)) ? "yes" : "no");
        }

        if (options.containsKey(_version)) {
            serializer.setOutputProperty(Serializer.Property.VERSION, options.get(_version));
        }

        return serializer;
    }
View Full Code Here

                transformer.setInitialContextNode(profile);
                XdmDestination result = new XdmDestination();
                transformer.setDestination(result);
                transformer.transform();

                Serializer serializer = new Serializer();
                serializer.setOutputProperty(Serializer.Property.INDENT, "yes");

                OutputStream outstr = null;
                try {
                    switch (this.profile.getKind()) {
                    case URI:
                        URI furi = URI.create(this.profile.getUri());
                        outstr = new FileOutputStream(new File(furi));
                        break;

                    case OUTPUT_STREAM:
                        outstr = this.profile.getOutputStream();
                        break;

                    default:
                        throw new UnsupportedOperationException(format("Unsupported profile kind '%s'", this.profile.getKind()));
                    }

                    serializer.setOutputStream(outstr);
                    S9apiUtils.serialize(this, result.getXdmNode(), serializer);
                } finally {
                    if (!System.out.equals(outstr) && !System.err.equals(outstr)) {
                        outstr.close();
                    }
View Full Code Here

                }

                OutputStream os = process.getOutputStream();

                try {
                    Serializer serializer = makeSerializer();

                    // FIXME: there must be a better way to print text descendants
                    String queryexpr = null;
                    if (sourceIsXML) {
                        queryexpr = ".";
                    } else {
                        queryexpr = "//text()";
                        serializer.setOutputProperty(Serializer.Property.METHOD, "text");
                        serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes");
                    }

                    Processor qtproc = runtime.getProcessor();
                    XQueryCompiler xqcomp = qtproc.newXQueryCompiler();
                    xqcomp.setModuleURIResolver(runtime.getResolver());
                    XQueryExecutable xqexec = xqcomp.compile(queryexpr);
                    XQueryEvaluator xqeval = xqexec.load();
                    xqeval.setContextItem(srcDoc);

                    serializer.setOutputStream(os);
                    xqeval.setDestination(serializer);
                    xqeval.run();
                } finally {
                    os.close();
                }
View Full Code Here

TOP

Related Classes of net.sf.saxon.s9api.Serializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.