Examples of SAXSerializer


Examples of org.exist.util.serializer.SAXSerializer

            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            DocumentImpl doc = (DocumentImpl) broker.getXMLResource(TEST_COLLECTION_URI.append("test.xml"));
            NodeProxy p = new NodeProxy(doc, pool.getNodeFactory().createFromString("1.1"));

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

            Sequence seq = Marshaller.demarshall(broker, new StringReader(serialized));
            assertTrue(Type.subTypeOf(seq.getItemType(), Type.NODE));
            NodeValue n = (NodeValue) seq.itemAt(0);

            writer = new StringWriter();
            serializer.reset();
            serializer.setOutput(writer, new Properties());
            n.toSAX(broker, serializer, new Properties());
            System.out.println(writer.toString());
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
View Full Code Here

Examples of org.exist.util.serializer.SAXSerializer

      
        try {
           Node n = Marshaller.streamToNode(TEST_DOC);
            StringWriter writer = new StringWriter();
//            SAXSerializer serializer =
                new SAXSerializer(writer, new Properties());
            //n.toSAX(null, serializer, new Properties());
           
            assertEquals("test",n.getLocalName());
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

Examples of org.exist.util.serializer.SAXSerializer

            assertNotNull(seq);
            //TODO : check cardinality
            StringWriter out = new StringWriter();
            Properties props = new Properties();
            props.setProperty(OutputKeys.INDENT, "yes");
            SAXSerializer serializer = new SAXSerializer(out, props);
            serializer.startDocument();
            for (SequenceIterator i = seq.iterate(); i.hasNext(); ) {
                Item next = i.nextItem();
                next.toSAX(broker, serializer, props);
            }
            serializer.endDocument();
            //TODO : check content
            System.out.println(out.toString());

        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

Examples of org.exist.util.serializer.SAXSerializer

    @Override
    protected void serializeNodeBody(final Sequence result, final HttpResponse response, final Map<SerializationProperty, String> serializationProperties) throws RestXqServiceException {
       
        DBBroker broker = null;
        SAXSerializer sax = null;
       
        final SerializerPool serializerPool = SerializerPool.getInstance();
        try {
            broker = getBrokerPool().get(brokerPool.getSubject());
           
            final Serializer serializer = broker.getSerializer();
            serializer.reset();
           
            sax = (SAXSerializer) serializerPool.borrowObject(SAXSerializer.class);
         
            final Writer writer = new OutputStreamWriter(response.getOutputStream(), serializationProperties.get(SerializationProperty.ENCODING));
            final Properties outputProperties = serializationPropertiesToProperties(serializationProperties);
            sax.setOutput(writer, outputProperties);
 
            serializer.setProperties(outputProperties);
            serializer.setSAXHandlers(sax, sax);
 
            serializer.toSAX(((SequenceAdapter)result).getExistSequence());
View Full Code Here

Examples of org.exist.util.serializer.SAXSerializer

          } else {
              outputProperties.setProperty(OutputKeys.INDENT, "no");
          }
          xmlWriter.setOutputProperties(outputProperties);
 
          SAXSerializer sax       = new SAXSerializer();
 
          sax.setReceiver( xmlWriter );
 
          try {
              payload.toSAX( context.getBroker(), sax, new Properties() );
              osw.flush();
              osw.close();
View Full Code Here

Examples of org.exist.util.serializer.SAXSerializer

    File targetFile = new File(targetDir, doc.getFileURI().toASCIIString());
    if (targetFile.exists() && targetFile.lastModified() >= doc.getMetadata().getLastModified()) {
      return;
    }
        boolean isRepoXML = targetFile.exists() && targetFile.getName().equals("repo.xml");
    SAXSerializer sax = (SAXSerializer)SerializerPool.getInstance().borrowObject( SAXSerializer.class );
    try {
      output.startElement(new QName("update", FileModule.NAMESPACE_URI), null);
      output.addAttribute(new QName("file"), targetFile.getAbsolutePath());
      output.addAttribute(new QName("name"), doc.getFileURI().toString());
      output.addAttribute(new QName("collection"), doc.getCollection().getURI().toString());
      output.addAttribute(new QName("type"), "xml");
      output.addAttribute(new QName("modified"), new DateTimeValue(new Date(doc.getMetadata().getLastModified())).getStringValue());
            if (isRepoXML) {
                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);
View Full Code Here

Examples of org.exist.util.serializer.SAXSerializer

            Sequence result = xquery.execute(XQUERY, null, AccessContext.TEST);
            System.out.println("Found: " + result.getItemCount());
            StringWriter out = new StringWriter();
            Properties props = new Properties();
            props.setProperty(OutputKeys.INDENT, "yes");
            SAXSerializer serializer = new SAXSerializer(out, props);
            serializer.startDocument();
            for(SequenceIterator i = result.iterate(); i.hasNext(); ) {
                Item next = i.nextItem();
                next.toSAX(broker, serializer, props);
            }
            serializer.endDocument();
            System.out.println(out.toString());
        } finally {
            pool.release(broker);
        }
    }
View Full Code Here

Examples of org.exist.util.serializer.SAXSerializer

    }

    public String diff2XML() throws DiffException {
        try {
            StringWriter writer = new StringWriter();
            SAXSerializer sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(
                    SAXSerializer.class);
            Properties outputProperties = new Properties();
            outputProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
            outputProperties.setProperty(OutputKeys.INDENT, "no");
            sax.setOutput(writer, outputProperties);
            sax.startDocument();
            diff2XML(sax);
            sax.endDocument();
            return writer.toString();
        } catch (SAXException e) {
            throw new DiffException("error while serializing diff: " + e.getMessage(), e);
        }
    }
View Full Code Here

Examples of org.exist.util.serializer.SAXSerializer

  }
 
 
  private void serializeXML(final SequenceIterator siNode, final Properties outputProperties, final File file, final boolean doAppend) throws XPathException {
            // serialize the node set
            SAXSerializer sax = null;
            Writer writer = null;
            try {
                sax = (SAXSerializer)SerializerPool.getInstance().borrowObject(SAXSerializer.class);
                final OutputStream os = new FileOutputStream(file, doAppend);
                final String encoding = outputProperties.getProperty(OutputKeys.ENCODING, "UTF-8");
                writer = new OutputStreamWriter(os, encoding);

                sax.setOutput(writer, outputProperties);
                final Serializer serializer = context.getBroker().getSerializer();
                serializer.reset();
                serializer.setProperties(outputProperties);
                serializer.setReceiver(sax);

                sax.startDocument();

                while(siNode.hasNext()) {
                    final NodeValue next = (NodeValue)siNode.nextItem();
                    serializer.toSAX(next)
                }

                sax.endDocument();
               
            } catch(final SAXException e) {
                throw new XPathException(this, "Cannot serialize file. A problem occurred while serializing the node set: " + e.getMessage(), e);
               
            } catch(final IOException e) {
View Full Code Here

Examples of org.exist.util.serializer.SAXSerializer

            XmldbURI diffUri = XmldbURI.createInternal(documentPath.toString() + '.' + revision);

            vCollection.setTriggersEnabled(false);

            StringWriter writer = new StringWriter();
            SAXSerializer sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(
                SAXSerializer.class);
            Properties outputProperties = new Properties();
            outputProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
            outputProperties.setProperty(OutputKeys.INDENT, "no");
            sax.setOutput(writer, outputProperties);

            sax.startDocument();
            sax.startElement(ELEMENT_VERSION, null);
            writeProperties(sax, getVersionProperties(revision, documentPath, activeSubject));

            if(event == REMOVE_DOCUMENT_EVENT) {
              sax.startElement(ELEMENT_REMOVED, null);
              sax.endElement(ELEMENT_REMOVED);
            } else {

              //Diff
              if(document instanceof BinaryDocument) {
                //create a copy of the last Binary revision
                XmldbURI binUri = XmldbURI.create(diffUri.toString() + BINARY_SUFFIX);
                broker.copyResource(transaction, document, vCollection, binUri);

                //Create metadata about the last Binary Version
                sax.startElement(ELEMENT_REPLACED_BINARY, null);
                sax.attribute(ATTRIBUTE_REF, binUri.toString());
                sax.endElement(ELEMENT_REPLACED_BINARY);
              } else if(lastRev instanceof BinaryDocument) {
                //create a copy of the last XML revision
                XmldbURI xmlUri = XmldbURI.create(diffUri.toString() + XML_SUFFIX);
                broker.copyResource(transaction, document, vCollection, xmlUri);

                //Create metadata about the last Binary Version
                sax.startElement(ELEMENT_REPLACED_XML, null);
                sax.attribute(ATTRIBUTE_REF, xmlUri.toString());
                sax.endElement(ELEMENT_REPLACED_BINARY);
              } else {
                //Diff the XML versions
                Diff diff = new StandardDiff(broker);
                diff.diff(lastRev, document);
                diff.diff2XML(sax);
              }

              sax.endElement(ELEMENT_VERSION);

              sax.endDocument();
              String editscript = writer.toString();

              if (removeLast) {
                if(lastRev instanceof BinaryDocument) {
                  vCollection.removeBinaryResource(transaction, broker, lastRev.getFileURI());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.