Package net.sf.saxon.event

Examples of net.sf.saxon.event.Receiver


     * @param event the pull event to be copied
     */

    private void copyEvent(int event) throws XPathException {
        PullProvider in = getUnderlyingProvider();
        Receiver out = branch;
        switch (event) {
            case START_DOCUMENT:
                out.startDocument(0);
                break;

            case START_ELEMENT:
                out.startElement(in.getNameCode(), in.getTypeAnnotation(), 0, 0);

                NamespaceDeclarations decl = in.getNamespaceDeclarations();
                for (int i=0; i<decl.getNumberOfNamespaces(); i++) {
                    out.namespace(decl.getNamespaceCode(i), 0);
                }

                AttributeCollection atts = in.getAttributes();
                for (int i=0; i<atts.getLength(); i++) {
                    out.attribute(atts.getNameCode(i), atts.getTypeAnnotation(i),
                            atts.getValue(i), 0, atts.getProperties(i));
                }

                out.startContent();
                break;

            case TEXT:

                out.characters(in.getStringValue(), 0, 0);
                break;

            case COMMENT:

                out.comment(in.getStringValue(), 0, 0);
                break;

            case PROCESSING_INSTRUCTION:

                out.processingInstruction(
                        in.getPipelineConfiguration().getConfiguration().getNamePool().getLocalName(in.getNameCode()),
                        in.getStringValue(), 0, 0);
                break;

            case END_ELEMENT:

                out.endElement();
                break;

            case END_DOCUMENT:
                List entities = in.getUnparsedEntities();
                if (entities != null) {
                    for (int i=0; i<entities.size(); i++) {
                        UnparsedEntity ue = (UnparsedEntity)entities.get(i);
                        out.setUnparsedEntity(ue.getName(), ue.getSystemId(), ue.getPublicId());
                    }
                }
                out.endDocument();
                break;

            case END_OF_INPUT:
                in.close();
                //out.close();
                break;

            case ATOMIC_VALUE:
                if (out instanceof SequenceReceiver) {
                    ((SequenceReceiver)out).append(super.getAtomicValue(), 0, 0);
                    break;
                } else {
                    if (previousAtomic) {
                        out.characters(" ", 0, 0);
                    }
                    CharSequence chars = in.getStringValue();
                    out.characters(chars, 0, 0);
                    break;
                }

            case ATTRIBUTE:
                if (out instanceof SequenceReceiver) {
                    Orphan o = new Orphan(in.getPipelineConfiguration().getConfiguration());
                    o.setNameCode(getNameCode());
                    o.setNodeKind(Type.ATTRIBUTE);
                    o.setStringValue(getStringValue());
                    ((SequenceReceiver)out).append(o, 0, 0);
                    break;
                } else {
                    out.attribute(getNameCode(), getTypeAnnotation(), getStringValue(), 0, 0);
                    break;
                    //throw new XPathException("Cannot serialize a free-standing attribute node");
                }

            case NAMESPACE:
                 if (out instanceof SequenceReceiver) {
                    Orphan o = new Orphan(in.getPipelineConfiguration().getConfiguration());
                    o.setNameCode(getNameCode());
                    o.setNodeKind(Type.NAMESPACE);
                    o.setStringValue(getStringValue());
                    ((SequenceReceiver)out).append(o, 0, 0);
                    break;
                } else {
                     int nsCode = getNamePool().getNamespaceCode(getNameCode());
                     out.namespace(nsCode, 0);
                     break;
                    //throw new XPathException("Cannot serialize a free-standing namespace node");
                }

            default:
View Full Code Here


        InputSource is = new InputSource(sr);
        is.setSystemId(baseURI);
        Source source = new SAXSource(is);
        source.setSystemId(baseURI);
        Builder b = controller.makeBuilder();
        Receiver s = b;
        source = AugmentedSource.makeAugmentedSource(source);
                ((AugmentedSource)source).setStripSpace(Whitespace.XSLT);
        if (controller.getExecutable().stripsInputTypeAnnotations()) {
            s = controller.getConfiguration().getAnnotationStripper(s);
        }
View Full Code Here

    public static void writeXdmValue(Processor proc, Vector<XdmValue> values, Destination destination, URI baseURI) throws SaxonApiException {
        try {
            Configuration config = proc.getUnderlyingConfiguration();
            PipelineConfiguration pipeConfig = config.makePipelineConfiguration();

            Receiver out = destination.getReceiver(config);
            out = new NamespaceReducer(out);
            TreeReceiver tree = new TreeReceiver(out);
            tree.setPipelineConfiguration(pipeConfig);
            if (baseURI != null) {
                tree.setSystemId(baseURI.toASCIIString());
View Full Code Here

        try {
            Processor proc = runtime.getProcessor();
            Configuration config = proc.getUnderlyingConfiguration();
            PipelineConfiguration pipeConfig = config.makePipelineConfiguration();

            Receiver out = destination.getReceiver(config);
            out = new NamespaceReducer(out);
            TreeReceiver tree = new TreeReceiver(out);
            tree.setPipelineConfiguration(pipeConfig);
            if (baseURI != null) {
                tree.setSystemId(baseURI.toASCIIString());
View Full Code Here

            logger.trace(MessageFormatter.nodeMessage(step.getNode(), "XSLT secondary result document: " + baseURI));

            try {
                XdmDestination xdmResult = new XdmDestination();
                secondaryResults.put(baseURI.toASCIIString(), xdmResult);
                Receiver receiver = xdmResult.getReceiver(runtime.getProcessor().getUnderlyingConfiguration());
                receiver.setSystemId(baseURI.toASCIIString());
                return receiver;
            } catch (SaxonApiException sae) {
                throw new XProcException(sae);
            }
        }
View Full Code Here

        XdmNode schema = builder.build(source);
        manager.load(schema.asSource());

        XdmDestination destination = new XdmDestination();
        Controller controller = new Controller(processor.getUnderlyingConfiguration());
        Receiver receiver = destination.getReceiver(controller.getConfiguration());
        PipelineConfiguration pipe = controller.makePipelineConfiguration();
        pipe.setRecoverFromValidationErrors(false);
        receiver.setPipelineConfiguration(pipe);

        SchemaValidator validator = manager.newSchemaValidator();
        validator.setDestination(destination);

        dumpTree(document, "Input");
View Full Code Here

            manager.load(source);
        }

        XdmDestination destination = new XdmDestination();
        Controller controller = new Controller(config);
        Receiver receiver = destination.getReceiver(controller.getConfiguration());
        PipelineConfiguration pipe = controller.makePipelineConfiguration();
        pipe.setRecoverFromValidationErrors(!getOption(_assert_valid,false));
        receiver.setPipelineConfiguration(pipe);

        SchemaValidator validator = manager.newSchemaValidator();
        validator.setDestination(destination);
        validator.setErrorListener(new XSDErrorHandler());
View Full Code Here

    public void serialize(PullProvider in, OutputStream out) throws XPathException, IOException {
        Properties props = new Properties();
        props.setProperty(OutputKeys.METHOD, "xml");
        props.setProperty(OutputKeys.INDENT, "yes");
        SerializerFactory sf = config.getSerializerFactory();
        Receiver receiver = sf.getReceiver(new StreamResult(out),
                                                        in.getPipelineConfiguration(),
                                                        props);
        new PullPushCopier(in, receiver).copy();
    }
View Full Code Here

    public void validate(PullProvider in) throws XPathException, IOException {
        EnterpriseConfiguration config = new EnterpriseConfiguration();
        PipelineConfiguration pipe = in.getPipelineConfiguration();
        pipe.setConfiguration(config);
        pipe.setSchemaURIResolver(config.getSchemaURIResolver());
        Receiver sink = new Sink(pipe);
        Receiver validator = config.getDocumentValidator(
                sink, in.getSourceLocator().getSystemId(), Validation.STRICT, Whitespace.NONE, null, -1);
        new PullPushCopier(in, validator).copy();
        System.out.println("Done.");
    }
View Full Code Here

    public void serialize(PullProvider in, OutputStream out) throws XPathException, IOException {
        Properties props = new Properties();
        props.setProperty(OutputKeys.METHOD, "xml");
        props.setProperty(OutputKeys.INDENT, "yes");
        Receiver receiver = ResultWrapper.getReceiver(new StreamResult(out),
                                                        in.getPipelineConfiguration(),
                                                        props);
        new PullPushCopier(in, receiver).copy();
    }
View Full Code Here

TOP

Related Classes of net.sf.saxon.event.Receiver

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.