Package org.exist.util.serializer

Examples of org.exist.util.serializer.SAXSerializer


            console.getHistory().flushBuffer();
        } catch (final Exception e) {
        }
        try {
            final BufferedWriter writer = new BufferedWriter(new FileWriter(queryHistoryFile));
            final SAXSerializer serializer = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
            serializer.setOutput(writer, null);
            int p = 0;
            if (queryHistory.size() > 20) {
                p = queryHistory.size() - 20;
            }
            final AttributesImpl attrs = new AttributesImpl();
            serializer.startDocument();
            serializer.startElement("", "history", "history", attrs);
            for(final ListIterator<String> i = queryHistory.listIterator(p); i.hasNext(); ) {
                serializer.startElement("", "query", "query", attrs);
                final String next = i.next();
                serializer.characters(next.toCharArray(), 0, next.length());
                serializer.endElement("", "query", "query");
            }
            serializer.endElement("", "history", "history");
            serializer.endDocument();
            writer.close();
            SerializerPool.getInstance().returnObject(serializer);
        } catch (final IOException e) {
            System.err.println("IO error while writing query history.");
        } catch (final SAXException e) {
View Full Code Here


        }

        if( ( dest != null ) || ( overwrite == true ) ) {
            final Properties outputProperties = new Properties();
            outputProperties.setProperty( OutputKeys.INDENT, "yes" );
            final SAXSerializer serializer = (SAXSerializer)SerializerPool.getInstance().borrowObject( SAXSerializer.class );

            Writer        writer     = null;

            if( dest.isDirectory() ) {
                String fname = res.getId();

//                if( !fname.endsWith( "." + type ) ) {
//                    fname += "." + type;
//                }
                final File file = new File( dest, fname );
                writer = new OutputStreamWriter( new FileOutputStream( file ), encoding );

            } else {

                writer = new OutputStreamWriter( new FileOutputStream( dest ), encoding );
            }

            log( "Writing resource " + res.getId() + " to destination " + dest.getAbsolutePath(), Project.MSG_DEBUG );
            serializer.setOutput( writer, outputProperties );
            res.getContentAsSAX( serializer );
            SerializerPool.getInstance().returnObject( serializer );
            writer.close();

        } else {
View Full Code Here

                    return;
                }
                final Resource resource;
                final FileOutputStream os;
                final BufferedWriter writer;
                final SAXSerializer contentSerializer;
                try {
                    final Collection collection = client.getCollection();

                    try {
                        resource = collection
                            .getResource(desc.getName().toString());
                        os = new FileOutputStream(file);
                        if (resource instanceof ExtendedResource) {
                            ((ExtendedResource) resource).getContentIntoAStream(os);
                        } else {

                            writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
                            // write resource to contentSerializer
                            contentSerializer = (SAXSerializer) SerializerPool
                                .getInstance()
                                .borrowObject(SAXSerializer.class);
                            contentSerializer.setOutput(writer, properties);
                            ((EXistResource) resource)
                            .setLexicalHandler(contentSerializer);
                            ((XMLResource) resource)
                            .getContentAsSAX(contentSerializer);
                            SerializerPool.getInstance().returnObject(contentSerializer);
View Full Code Here

    {
        if( dest != null ) {
            final Properties outputProperties = new Properties();
            outputProperties.setProperty( OutputKeys.INDENT, "yes" );

            final SAXSerializer serializer = (SAXSerializer)SerializerPool.getInstance().borrowObject( SAXSerializer.class );

            Writer        writer     = null;

            if( dest.isDirectory() ) {

                if( !dest.exists() ) {
                    dest.mkdirs();
                }

                String fname = resource.getId();

                if( !fname.endsWith( ".xml" ) ) {
                    fname += ".xml";
                }

                final File file = new File( dest, fname );
                writer = new OutputStreamWriter( new FileOutputStream( file ), encoding );

            } else {
                writer = new OutputStreamWriter( new FileOutputStream( dest ), encoding );
            }

            serializer.setOutput( writer, outputProperties );
            resource.getContentAsSAX( serializer );
            writer.close();
            SerializerPool.getInstance().returnObject( serializer );

        } else {
View Full Code Here

              final Serializer serializer = broker.getSerializer();
              serializer.reset();
           
              final SerializerPool serializerPool = SerializerPool.getInstance();

              final SAXSerializer sax = (SAXSerializer) serializerPool.borrowObject(SAXSerializer.class);
              try {
                sax.setOutput(output, outputProperties);
                serializer.setProperties(outputProperties);
                serializer.setSAXHandlers(sax, sax);
                serializer.toSAX(resultSequence, 1, resultSequence.getItemCount(), false, false);
                   
              } finally {
View Full Code Here

    private static final Properties properties = new Properties();

    private String toString(Item item) throws SAXException {
        StringWriter writer = new StringWriter();
        SAXSerializer serializer = new SAXSerializer(writer, properties);
        item.toSAX(broker, serializer, properties);
        String serialized = writer.toString();
        // System.out.println(serialized);
        return serialized;
    }
View Full Code Here

                }
                catch( UnsupportedEncodingException e ) {
                    throw( new XPathException( this, e.getMessage() ) );
                }

                SAXSerializer sax = new SAXSerializer( osw, new Properties() );

                try {
                    payload.toSAX( context.getBroker(), sax, new Properties() );
                    osw.flush();
                    osw.close();
View Full Code Here

                Sequence results = service.execute(compiled, Sequence.EMPTY_SEQUENCE);

                Serializer serializer = broker.getSerializer();
                serializer.reset();
                Writer out = new OutputStreamWriter(new FileOutputStream(generatedFiles[i]), "UTF-8");
                SAXSerializer sax = new SAXSerializer(out, outputProps);
                serializer.setSAXHandlers(sax, sax);
                for (SequenceIterator iter = results.iterate(); iter.hasNext(); ) {
                    Item item = iter.nextItem();
                    if (!Type.subTypeOf(item.getType(), Type.NODE))
                        continue;
View Full Code Here

                service.declareVariable("filename", generatedFiles[i].getName());
                service.declareVariable("count", new Integer(i));
                ResourceSet result = service.execute(compiled);

                Writer out = new OutputStreamWriter(new FileOutputStream(generatedFiles[i]), "UTF-8");
                SAXSerializer sax = new SAXSerializer(out, outputProps);
                for (ResourceIterator iter = result.getIterator(); iter.hasMoreResources(); ) {
                    XMLResource r = (XMLResource) iter.nextResource();
                    r.getContentAsSAX(sax);
                }
                out.close();
View Full Code Here

            values.add(new IntegerValue(1000, Type.LONG));
            values.add(new BooleanValue(false));
            values.add(new DoubleValue(1000.1));

            StringWriter writer = new StringWriter();
            SAXSerializer serializer = new SAXSerializer(writer, new Properties());
            Marshaller.marshall(broker, values, serializer);
            String serialized = writer.toString();
            System.out.println(serialized);

            Sequence seq = Marshaller.demarshall(broker, new StringReader(serialized));
View Full Code Here

TOP

Related Classes of org.exist.util.serializer.SAXSerializer

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.