Package org.exist.storage.serializers

Examples of org.exist.storage.serializers.Serializer


            // If it is not a collection, check if it is a document
            document = broker.getXMLResource(xmldbUri, Lock.READ_LOCK);

            if (document.getResourceType() == DocumentImpl.XML_FILE) {
                // Stream XML document
                Serializer serializer = broker.getSerializer();
                serializer.reset();
                try {
                    // Set serialization options
                    serializer.setProperties(configuration);

                    // Serialize document
                    try (Writer w = new OutputStreamWriter(os, "UTF-8")) {
                        serializer.serialize(document, w);
                        w.flush();
                    }

                    // don;t flush
                    if (!(os instanceof VirtualTempFile)) {
View Full Code Here


        NGramIndexWorker index = (NGramIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(NGramIndex.ID);
        MemTreeBuilder builder = context.getDocumentBuilder();
        DocumentBuilderReceiver docBuilder = new DocumentBuilderReceiver(builder);
        MatchCallback matchCb = new MatchCallback(func, docBuilder);
        Serializer serializer = context.getBroker().getSerializer();
        serializer.reset();
        ValueSequence result = new ValueSequence();
        for (SequenceIterator i = args[0].iterate(); i.hasNext(); ) {
            NodeValue v = (NodeValue) i.nextItem();
            try {
                int nodeNr = builder.getDocument().getLastNode();
                if (v.getImplementationType() == NodeValue.IN_MEMORY_NODE) {
                    ((NodeImpl)v).copyTo(context.getBroker(), docBuilder);
                } else {
                    NodeProxy p = (NodeProxy) v;
                    MatchListener ml = index.getMatchListener(context.getBroker(), p, matchCb);
                    Receiver receiver;
                    if (ml == null)
                        receiver = docBuilder;
                    else {
                        ml.setNextInChain(docBuilder);
                        receiver = ml;
                    }
                    serializer.setReceiver(receiver);
                    serializer.toReceiver((NodeProxy) v, false);
                }
                result.add(builder.getDocument().getNode(++nodeNr));
            } catch (SAXException e) {
                LOG.warn(e.getMessage(), e);
                throw new XPathException(this, e.getMessage());
View Full Code Here

                processRepoDesc(targetFile, doc, sax, output);
            } else {
                OutputStream os = new FileOutputStream(targetFile);
                            try (Writer writer = new OutputStreamWriter(os, "UTF-8")) {
                                sax.setOutput(writer, DEFAULT_PROPERTIES);
                                Serializer serializer = context.getBroker().getSerializer();
                                serializer.reset();
                                serializer.setProperties(DEFAULT_PROPERTIES);
                               
                                serializer.setSAXHandlers(sax, sax);
                                serializer.toSAX(doc);
                            }
            }
    } catch (IOException e) {
      reportError(output, "IO error while saving file: " + targetFile.getAbsolutePath());
    } catch (SAXException e) {
View Full Code Here

                final SAXTransformerFactory factory = TransformerFactoryAllocator.getTransformerFactory(context.getBroker().getBrokerPool());
                TransformerHandler handler = factory.newTransformerHandler(stylesource);
                handler.getTransformer().setParameter("original", original.getDocumentElement());
                handler.setResult(new SAXResult(sax));
               
                final Serializer serializer = context.getBroker().getSerializer();
                serializer.reset();
                serializer.setProperties(DEFAULT_PROPERTIES);
                serializer.setSAXHandlers(handler, handler);
               
                serializer.toSAX(doc);
            }
        } catch (ParserConfigurationException e) {
            reportError(output, "Parser exception while saving file " + targetFile.getAbsolutePath() + ": " + e.getMessage());
        } catch (SAXException e) {
            reportError(output, "SAX exception while saving file " + targetFile.getAbsolutePath() + ": " + e.getMessage());
View Full Code Here

                streamSource.setSystemId(url);
            }
            */

            // Node provided
            Serializer serializer = context.getBroker().newSerializer();

            NodeValue node = (NodeValue) item;
            return new NodeInputStream(serializer, node);
        }
        else {
View Full Code Here

                        for (int j = i; j < nodes.length; j++) {
                            if (nodes[j].nodeType == XMLStreamReader.END_ELEMENT &&
                                    nodes[j].nodeId.equals(nodeId)) {
                                isClosed = true;
                                NodeProxy proxy = new NodeProxy(otherDoc, nodes[i].nodeId);
                                Serializer serializer = broker.getSerializer();
                                serializer.reset();
                                serializer.setProperty(Serializer.GENERATE_DOC_EVENTS, "false");
                                serializer.setReceiver(handler);
                                serializer.toReceiver(proxy, false);
                                i = j;
                                break;
                            }
                        }
                        if (!isClosed) {
                            attribs = new AttrList();
                            if (nodes[i].qname.needsNamespaceDecl())
                                attribs.addAttribute(ATTR_NAMESPACE, nodes[i].qname.getNamespaceURI());
                            attribs.addAttribute(ATTR_NAME, nodes[i].qname.getStringValue());
                            handler.startElement(ELEMENT_START, attribs);
                            handler.endElement(ELEMENT_START);
                        }
                        break;
                    case XMLStreamReader.END_ELEMENT:
                        attribs = new AttrList();
                        if (nodes[i].qname.needsNamespaceDecl())
                            attribs.addAttribute(ATTR_NAMESPACE, nodes[i].qname.getNamespaceURI());
                        attribs.addAttribute(ATTR_NAME, nodes[i].qname.getStringValue());
                        handler.startElement(ELEMENT_END, attribs);
                        handler.endElement(ELEMENT_END);
                        break;
                    case XMLStreamReader.COMMENT:
                        attribs = new AttrList();
                        handler.startElement(ELEMENT_COMMENT, attribs);
                        handler.characters(nodes[i].value);
                        handler.endElement(ELEMENT_COMMENT);
                        break;
                    default:
                        NodeProxy proxy = new NodeProxy(otherDoc, nodes[i].nodeId);
                        Serializer serializer = broker.getSerializer();
                        serializer.reset();
                        serializer.setProperty(Serializer.GENERATE_DOC_EVENTS, "false");
                        serializer.setReceiver(handler);
                        serializer.toReceiver(proxy, false);
                        break;
                }
            }
        }
View Full Code Here

        contentsOutputProps.setProperty( OutputKeys.INDENT, "yes" );
        contentsOutputProps.setProperty( EXistOutputKeys.OUTPUT_DOCTYPE, "yes" );
    }
 
  private String serializer(DBBroker broker, DocumentImpl document) throws SAXException {
    Serializer serializer = broker.getSerializer();
    serializer.setUser(broker.getSubject());
    serializer.setProperties(contentsOutputProps);
    return serializer.serialize(document);
  }
View Full Code Here

        try {
          System.out.println("testRead() ...\n");
          pool = startDB();
          assertNotNull(pool);
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            Serializer serializer = broker.getSerializer();
            serializer.reset();
           
            DocumentImpl doc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test/test2/hamlet.xml"), Lock.READ_LOCK);
            assertNotNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/hamlet.xml' should not be null", doc);
            String data = serializer.serialize(doc);
            assertNotNull(data);
            //System.out.println(data);
            doc.getUpdateLock().release(Lock.READ_LOCK);
           
            doc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test/test2/test_string.xml"), Lock.READ_LOCK);
            assertNotNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/test_string.xml' should not be null", doc);
            data = serializer.serialize(doc);
            assertNotNull(data);
            //System.out.println(data);
            doc.getUpdateLock().release(Lock.READ_LOCK);
           
            File files[] = dir.listFiles();
            assertNotNull(files);
           
            doc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append(files[files.length - 1].getName()), Lock.READ_LOCK);
            assertNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/'" + files[files.length - 1].getName() + " should not exist anymore", doc);
           
            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence seq = xquery.execute("//SPEECH[ft:query(LINE, 'king')]", null, AccessContext.TEST);
            assertNotNull(seq);
            System.out.println("Found: " + seq.getItemCount());
            for (SequenceIterator i = seq.iterate(); i.hasNext(); ) {
                Item next = i.nextItem();
                String value = serializer.serialize((NodeValue) next);
                //System.out.println(value);
            }
           
            BinaryDocument binDoc = (BinaryDocument) broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append(TestConstants.TEST_BINARY_URI), Lock.READ_LOCK);
            assertNotNull("Binary document is null", binDoc);
View Full Code Here

        System.out.println("testRead() ...\n");
        pool = startDB();
        assertNotNull(pool);
          broker = pool.get(pool.getSecurityManager().getSystemSubject());
          assertNotNull(broker);
          Serializer serializer = broker.getSerializer();
          serializer.reset();

          DocumentImpl doc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test/new_test.xml"), Lock.READ_LOCK);
          assertNotNull("Document should not be null", doc);
          String data = serializer.serialize(doc);
          assertNotNull(data);
//          System.out.println(data);
          doc.getUpdateLock().release(Lock.READ_LOCK);

            transact = pool.getTransactionManager();
View Full Code Here

        System.out.println("testRead() ...\n");
        pool = startDB();
        assertNotNull(pool);
          broker = pool.get(pool.getSecurityManager().getSystemSubject());
          assertNotNull(broker);
          Serializer serializer = broker.getSerializer();
          serializer.reset();

          DocumentImpl doc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append("new_test2.xml"), Lock.READ_LOCK);
          assertNotNull("Document should not be null", doc);
          String data = serializer.serialize(doc);
          assertNotNull(data);
//          System.out.println(data);
          doc.getUpdateLock().release(Lock.READ_LOCK);

            transact = pool.getTransactionManager();
View Full Code Here

TOP

Related Classes of org.exist.storage.serializers.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.