Package org.codehaus.stax2

Examples of org.codehaus.stax2.XMLStreamWriter2


    }

    public boolean setupValidation(XMLStreamWriter writer, Endpoint endpoint, ServiceInfo serviceInfo)
        throws XMLStreamException {
       
        XMLStreamWriter2 writer2 = (XMLStreamWriter2)writer;
        XMLValidationSchema vs = getValidator(endpoint, serviceInfo);
        if (vs == null) {
            return false;
        }
        writer2.setValidationProblemHandler(new ValidationProblemHandler() {

            public void reportProblem(XMLValidationProblem problem) throws XMLValidationException {
                throw new Fault(problem.getMessage(), LOG);
            }
        });
        writer2.validateAgainst(vs);
        return true;
    }
View Full Code Here


    }

    public XMLEventWriter createXMLEventWriter(XMLStreamWriter sw)
        throws XMLStreamException
    {
        XMLStreamWriter2 sw2 = Stax2WriterAdapter.wrapIfNecessary(sw);
        return new Stax2EventWriterImpl(sw2);
    }
View Full Code Here

     * stream is not closed (as per Stax 1.0 specification).
     */
    public void writeDocument(Document doc, XMLStreamWriter sw0)
        throws XMLStreamException
    {
        XMLStreamWriter2 sw = Stax2WriterAdapter.wrapIfNecessary(sw0);

        sw.writeStartDocument();
        for (Node child = doc.getFirstChild(); child != null; child = child.getNextSibling()) {
            _writeNode(sw, child);
        }
        sw.writeEndDocument();
        sw.close();
    }
View Full Code Here

    }

    public void writeFragment(NodeList nodes, XMLStreamWriter sw0)
        throws XMLStreamException
    {
        XMLStreamWriter2 sw = Stax2WriterAdapter.wrapIfNecessary(sw0);
        for (int i = 0, len = nodes.getLength(); i < len; ++i) {
            _writeNode(sw, (Node) nodes.item(i));
        }
    }
View Full Code Here

    }

    public void writeFragment(Node node, XMLStreamWriter sw0)
        throws XMLStreamException
    {
        XMLStreamWriter2 sw = Stax2WriterAdapter.wrapIfNecessary(sw0);
        _writeNode(sw, node);
    }
View Full Code Here

    System.setProperty("javax.xml.stream.XMLEventFactory", "com.ctc.wstx.stax.WstxEventFactory");
   
    initializePackageParsers();

    SMOutputFactory smFactory = new SMOutputFactory(XMLOutputFactory.newInstance());
    XMLStreamWriter2 streamWriter = smFactory.createStax2Writer(stream);
   
    // For this to work, the elements need to be completely empty (no whitespace or line return)
    streamWriter.setProperty(XMLOutputFactory2.P_AUTOMATIC_EMPTY_ELEMENTS, Boolean.TRUE);

    SMOutputDocument outputDocument = SMOutputFactory.createOutputDocument(
        streamWriter, "1.0", "UTF-8", false);
    // to have the automatic indentation working, we should probably only be using StaxMate classes and not directly StAX
    // outputDocument.setIndentation("\n  ", 1, 1);

    String SBMLNamespace = JSBML.getNamespaceFrom(sbmlDocument.getLevel(),
        sbmlDocument.getVersion());
    SMOutputContext context = outputDocument.getContext();
    context.setIndentation("\n" + createIndentationString(indentCount), 1, 2);
    SMNamespace namespace = context.getNamespace(SBMLNamespace);
    namespace.setPreferredPrefix("");
    outputDocument.addCharacters("\n");

    /*
     * Write a comment to track which program created this SBML file and
     * which version of JSBML was used for this purpose.
     */
    if ((programName != null) && (programName.length() > 0)) {
      String date = String.format("%1$tY-%1$tm-%1$td %1$tR", Calendar
          .getInstance().getTime());
      String msg = " Created by %s version %s on %s with jsbml version %s. ";
      outputDocument.addComment(
        String.format(msg, programName, (programVersion != null)
              && (programVersion.length() > 0) ? programVersion
              : "?", date, JSBML.getJSBMLDottedVersion()));
      outputDocument.addCharacters("\n");
    }

    SMOutputElement smOutputElement = outputDocument.addElement(namespace,
        sbmlDocument.getElementName());

    SBMLObjectForXML xmlObject = new SBMLObjectForXML();
    xmlObject.setName(sbmlDocument.getElementName());
    xmlObject.setNamespace(SBMLNamespace);
    xmlObject.addAttributes(sbmlDocument.writeXMLAttributes());

    // register all the name spaces of the SBMLDocument to the writer
    Iterator<Map.Entry<String, String>> it = sbmlDocument
        .getSBMLDocumentNamespaces().entrySet().iterator();

    logger.debug(" SBML name spaces size = "
        + sbmlDocument.getSBMLDocumentNamespaces().size());

    while (it.hasNext()) {
      Map.Entry<String, String> entry = it.next();
      if (!entry.getKey().equals("xmlns")) {

        logger.debug(" SBML name spaces : " + entry.getKey() + " = "
            + entry.getValue());

        String namespacePrefix = entry.getKey().substring(
            entry.getKey().indexOf(":") + 1);
        streamWriter.setPrefix(namespacePrefix, entry.getValue());

        logger.debug(" SBML namespaces : " + namespacePrefix + " = "
            + entry.getValue());

      }
View Full Code Here

    StringWriter stream = new StringWriter();
   
    SMOutputFactory smFactory = new SMOutputFactory(WstxOutputFactory.newInstance());

    try {
      XMLStreamWriter2 writer = smFactory.createStax2Writer(stream);

      // For this to work, the elements need to be completely empty (no whitespace or line return)
      writer.setProperty(XMLOutputFactory2.P_AUTOMATIC_EMPTY_ELEMENTS, Boolean.TRUE);

      // Create an xml fragment to avoid having the xml declaration
      SMRootFragment outputDocument = SMOutputFactory.createOutputFragment(writer);

      // create the sbmlNamespace variable
      String sbmlNamespace = JSBML.getNamespaceFrom(sbase.getLevel(), sbase.getVersion());
      SMOutputContext context = outputDocument.getContext();
      SMNamespace namespace = context.getNamespace(sbmlNamespace);
      namespace.setPreferredPrefix("");
     
      // all the sbml element namespaces are registered to the writer in the writeAnnotation method

      // call the writeAnnotation, indicating that we are building an xml fragment
      writeAnnotation(sbase, outputDocument, writer, 0, true);

      writer.writeEndDocument();
      writer.close();

      annotationStr = stream.toString();
    } catch (XMLStreamException e) {
      e.printStackTrace();
    } catch (SBMLException e) {
View Full Code Here

    System.setProperty("javax.xml.stream.XMLEventFactory", "com.ctc.wstx.stax.WstxEventFactory");
   
    initializePackageParsers();

    SMOutputFactory smFactory = new SMOutputFactory(XMLOutputFactory.newInstance());
    XMLStreamWriter2 streamWriter = smFactory.createStax2Writer(stream);
   
    // For this to work, the elements need to be completely empty (no whitespace or line return)
    streamWriter.setProperty(XMLOutputFactory2.P_AUTOMATIC_EMPTY_ELEMENTS, Boolean.TRUE);

    SMOutputDocument outputDocument = SMOutputFactory.createOutputDocument(
        streamWriter, "1.0", "UTF-8", false);
    // to have the automatic indentation working, we should probably only be using StaxMate classes and not directly StAX
    // outputDocument.setIndentation("\n  ", 1, 1);

    String SBMLNamespace = JSBML.getNamespaceFrom(sbmlDocument.getLevel(),
        sbmlDocument.getVersion());
    SMOutputContext context = outputDocument.getContext();
    context.setIndentation("\n" + createIndentationString(indentCount), 1, 2);
    SMNamespace namespace = context.getNamespace(SBMLNamespace);
    namespace.setPreferredPrefix("");
    outputDocument.addCharacters("\n");

    /*
     * Write a comment to track which program created this SBML file and
     * which version of JSBML was used for this purpose.
     */
    if ((programName != null) && (programName.length() > 0)) {
      String date = String.format("%1$tY-%1$tm-%1$td %1$tR", Calendar
          .getInstance().getTime());
      String msg = " Created by %s version %s on %s with jsbml version %s. ";
      outputDocument.addComment(
        String.format(msg, programName, (programVersion != null)
              && (programVersion.length() > 0) ? programVersion
              : "?", date, JSBML.getJSBMLDottedVersion()));
      outputDocument.addCharacters("\n");
    }

    SMOutputElement smOutputElement = outputDocument.addElement(namespace,
        sbmlDocument.getElementName());

    SBMLObjectForXML xmlObject = new SBMLObjectForXML();
    xmlObject.setName(sbmlDocument.getElementName());
    xmlObject.setNamespace(SBMLNamespace);
    xmlObject.addAttributes(sbmlDocument.writeXMLAttributes());

    // register all the name spaces of the SBMLDocument to the writer
    Iterator<Map.Entry<String, String>> it = sbmlDocument
        .getSBMLDocumentNamespaces().entrySet().iterator();

    logger.debug(" SBML name spaces size = "
        + sbmlDocument.getSBMLDocumentNamespaces().size());

    while (it.hasNext()) {
      Map.Entry<String, String> entry = it.next();
      if (!entry.getKey().equals("xmlns")) {

        logger.debug(" SBML name spaces : " + entry.getKey() + " = "
            + entry.getValue());

        String namespacePrefix = entry.getKey().substring(
            entry.getKey().indexOf(":") + 1);
        streamWriter.setPrefix(namespacePrefix, entry.getValue());

        logger.debug(" SBML namespaces : " + namespacePrefix + " = "
            + entry.getValue());

      }
View Full Code Here

    StringWriter stream = new StringWriter();
   
    SMOutputFactory smFactory = new SMOutputFactory(WstxOutputFactory.newInstance());

    try {
      XMLStreamWriter2 writer = smFactory.createStax2Writer(stream);

      // For this to work, the elements need to be completely empty (no whitespace or line return)
      writer.setProperty(XMLOutputFactory2.P_AUTOMATIC_EMPTY_ELEMENTS, Boolean.TRUE);

      // Create an xml fragment to avoid having the xml declaration
      SMRootFragment outputDocument = SMOutputFactory.createOutputFragment(writer);

      // create the sbmlNamespace variable
      String sbmlNamespace = JSBML.getNamespaceFrom(sbase.getLevel(), sbase.getVersion());
      SMOutputContext context = outputDocument.getContext();
      SMNamespace namespace = context.getNamespace(sbmlNamespace);
      namespace.setPreferredPrefix("");
     
      // all the sbml element namespaces are registered to the writer in the writeAnnotation method

      // call the writeAnnotation, indicating that we are building an xml fragment
      writeAnnotation(sbase, outputDocument, writer, 0, true);

      writer.writeEndDocument();
      writer.close();

      annotationStr = stream.toString();
    } catch (XMLStreamException e) {
      e.printStackTrace();
    } catch (SBMLException e) {
View Full Code Here

    @Override
    public XMLEventWriter createXMLEventWriter(XMLStreamWriter sw)
        throws XMLStreamException
    {
        XMLStreamWriter2 sw2 = Stax2WriterAdapter.wrapIfNecessary(sw);
        return new Stax2EventWriterImpl(sw2);
    }
View Full Code Here

TOP

Related Classes of org.codehaus.stax2.XMLStreamWriter2

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.