Package org.codehaus.staxmate.out

Examples of org.codehaus.staxmate.out.SMOutputElement


    // set the indentation for the next element
    element.setIndentation(whitespaces, indent + indentCount, indentCount);

    // Creating an SMOutputElement to be sure that the previous nested element tag is closed properly.
    SMNamespace sbmlSMNamespace = element.getNamespace();
    SMOutputElement messageElement = element.addElement(sbmlSMNamespace, "message");
    messageElement.setIndentation(createIndentationString(indent + 2), indent + indentCount, indentCount);

    writer.writeCharacters(whitespaces);
    writer.writeCharacters("\n");

    XMLNodeWriter xmlNodeWriter = new XMLNodeWriter(writer,
View Full Code Here


    String whiteSpace = createIndentationString(indent);
    SMNamespace namespace = annotationElement.getNamespace(
        Annotation.URI_RDF_SYNTAX_NS, "rdf");
    annotationElement.setIndentation(whiteSpace, indent, indentCount);
    SMOutputElement rdfElement = annotationElement.addElement(namespace,
        "RDF");

    /*
     * TODO: Check which name spaces are really required and add only those;
     * particularly, if name spaces are missing and it is known from the
     * kind of RDF annotation, which name spaces are needed, these should be
     * added automatically here.
     */
    Map<String, String> rdfNamespaces = annotation.getRDFAnnotationNamespaces();

    for (String namespaceURI : rdfNamespaces.keySet()) {
     
      if (!namespaceURI.equals(namespace.getURI())) {
        writer.writeNamespace(rdfNamespaces.get(namespaceURI), namespaceURI);
      }
    }

    // Checking if all the necessary namespaces are defined
    // In fact, we could remove the rdfNamespaces map ?
   
    if (annotation.isSetHistory() && annotation.getHistory().getNumCreators() > 0)
    {
      if (rdfNamespaces.get(JSBML.URI_PURL_ELEMENTS) == null) {
        writer.writeNamespace("dc", JSBML.URI_PURL_ELEMENTS);
        rdfNamespaces.put(JSBML.URI_PURL_ELEMENTS, "dc");
      }

      if (rdfNamespaces.get(Creator.URI_RDF_VCARD_NS) == null) {
        writer.writeNamespace("vCard", Creator.URI_RDF_VCARD_NS);
        rdfNamespaces.put(Creator.URI_RDF_VCARD_NS, "vCard");
      }
    }
   
    if (annotation.isSetHistory() && (annotation.getHistory().isSetCreatedDate() || annotation.getHistory().isSetModifiedDate()) 
        && rdfNamespaces.get(JSBML.URI_PURL_TERMS) == null)
    {
      writer.writeNamespace("dcterms", JSBML.URI_PURL_TERMS);
      rdfNamespaces.put(JSBML.URI_PURL_TERMS, "dcterms");
    }
   
    if (annotation.getNumCVTerms() > 0)
    {
      if (rdfNamespaces.get(CVTerm.URI_BIOMODELS_NET_BIOLOGY_QUALIFIERS) == null) {
        writer.writeNamespace("bqbiol", CVTerm.URI_BIOMODELS_NET_BIOLOGY_QUALIFIERS);
        rdfNamespaces.put(CVTerm.URI_BIOMODELS_NET_BIOLOGY_QUALIFIERS, "bqbiol");
      }

      if (rdfNamespaces.get(CVTerm.URI_BIOMODELS_NET_MODEL_QUALIFIERS) == null) {
        writer.writeNamespace("bqmodel", CVTerm.URI_BIOMODELS_NET_MODEL_QUALIFIERS);
        rdfNamespaces.put(CVTerm.URI_BIOMODELS_NET_MODEL_QUALIFIERS, "bqmodel");
      }
     
    }
   
   
    rdfElement.addCharacters("\n");
    rdfElement.setIndentation(whiteSpace + createIndentationString(indentCount), indent + indentCount, indentCount);
    SMOutputElement descriptionElement = rdfElement.addElement(namespace,
        "Description");
    descriptionElement.addAttribute(namespace, "about",
        annotation.getAbout());
    descriptionElement.addCharacters("\n");
    if (annotation.isSetHistory()) {
      writeHistory(annotation.getHistory(), rdfNamespaces, writer,
          indent + 4);
    }
    if (annotation.getListOfCVTerms().size() > 0) {
      writeCVTerms(annotation.getListOfCVTerms(), rdfNamespaces, writer,
          indent + indentCount);
    }
    descriptionElement.setIndentation(whiteSpace + createIndentationString(indentCount), indent + indentCount, indentCount);
    descriptionElement.addCharacters(whiteSpace + createIndentationString(indentCount));
    annotationElement.setIndentation(whiteSpace, indent, indentCount);
    rdfElement.addCharacters("\n");
    rdfElement.addCharacters(whiteSpace);
    annotationElement.addCharacters("\n");
  }
View Full Code Here

          parser.writeElement(parentXmlObject, nextObjectToWrite);
          parser.writeNamespaces(parentXmlObject, nextObjectToWrite);
          parser.writeAttributes(parentXmlObject, nextObjectToWrite);
         
         
          SMOutputElement newOutPutElement = null;
          if (parentXmlObject.isSetName()) {
            boolean isClosedMathContainer = false, isClosedAnnotation = false;
           
            if (parentXmlObject.isSetNamespace()) {
              SMNamespace namespaceContext = smOutputParentElement
                  .getNamespace(
                      parentXmlObject.getNamespace(),
                      parentXmlObject.getPrefix());
              newOutPutElement = smOutputParentElement
                  .addElement(namespaceContext,
                      parentXmlObject.getName());
            } else {
              newOutPutElement = smOutputParentElement
                  .addElement(smOutputParentElement
                      .getNamespace(), parentXmlObject
                      .getName());
            }

            Iterator<Entry<String, String>> it = parentXmlObject
                .getAttributes().entrySet().iterator();
            while (it.hasNext()) {
              Entry<String, String> entry = it.next();
              newOutPutElement.addAttribute(entry.getKey(),
                  entry.getValue());
            }
            if (nextObjectToWrite instanceof SBase) {
              SBase s = (SBase) nextObjectToWrite;
              if (s.isSetNotes()) {
                writeNotes(s, newOutPutElement, streamWriter,
                    newOutPutElement.getNamespace()
                        .getURI(), indent + indentCount);
                elementIsNested = isClosedAnnotation = true;
              }
              if (s.isSetAnnotation()) {
                writeAnnotation(s, newOutPutElement,
                    streamWriter,
                    indent + indentCount, false);
                elementIsNested = true;
              }
              if (s.getChildCount() > 0) {
                // make sure that we'll have line breaks if an element has any sub elements.
                elementIsNested = true;
              }
            }
            if (nextObjectToWrite instanceof Constraint) {
              Constraint constraint = (Constraint) nextObjectToWrite;
              if (constraint.isSetMessage()) {
                writeMessage(constraint, newOutPutElement,
                    streamWriter, newOutPutElement
                        .getNamespace().getURI(),
                    indent + indentCount);
                elementIsNested = true;
              }
            }
            if (nextObjectToWrite instanceof MathContainer) {
              MathContainer mathContainer = (MathContainer) nextObjectToWrite;
              if (mathContainer.getLevel() > 1) {
                writeMathML(mathContainer, newOutPutElement,
                    streamWriter, indent + indentCount);
                elementIsNested = true;
              } else {
                elementIsNested = false;
              }
              isClosedMathContainer = true;
            }
            if (!elementIsNested
                && ((nextObjectToWrite instanceof Model) || (nextObjectToWrite instanceof UnitDefinition))) {
              elementIsNested = true;
            }
           
            // to allow the XML parser to prune empty element, this line should not be added in all the cases.
            if (elementIsNested) {
              newOutPutElement.addCharacters("\n");
              if (isClosedMathContainer || isClosedAnnotation) {
                newOutPutElement.addCharacters(whiteSpaces);
              }
            }

            writeSBMLElements(parentXmlObject, newOutPutElement,
                streamWriter, nextObjectToWrite, indent + indentCount);
View Full Code Here

              && (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());

      }
    }

    it = xmlObject.getAttributes().entrySet().iterator();
    while (it.hasNext()) {
      Entry<String, String> entry = it.next();
      smOutputElement.addAttribute(entry.getKey(), entry.getValue());
    }

    int indent = indentCount;
    if (sbmlDocument.isSetNotes()) {
      writeNotes(sbmlDocument, smOutputElement, streamWriter,
          SBMLNamespace, indent);
    }
    if (sbmlDocument.isSetAnnotation()) {
      writeAnnotation(sbmlDocument, smOutputElement, streamWriter,
          indent, false);
    }
    smOutputElement.addCharacters("\n");

    writeSBMLElements(xmlObject, smOutputElement, streamWriter,
        sbmlDocument, indent);

    outputDocument.closeRoot();
View Full Code Here

    String sbmlNamespace = JSBML.getNamespaceFrom(sbase.getLevel(), sbase.getVersion());
    SMNamespace namespace = element.getContext().getNamespace(sbmlNamespace);

    namespace.setPreferredPrefix("");
    Annotation annotation = sbase.getAnnotation();
    SMOutputElement annotationElement;
    String whiteSpaces = createIndentationString(indent);
   
    if (xmlFragment) {
      annotationElement = element.addElement("annotation");
    } else {
      element.addCharacters("\n");
      element.setIndentation(whiteSpaces, indent, indentCount);   
      annotationElement = element.addElement(namespace, "annotation");
    }
    annotationElement.setIndentation(whiteSpaces, indent, indentCount);

    if ((annotation.getNonRDFannotation() != null)
        && (annotation.getNonRDFannotation().length() > 0)) {
      StringBuffer annotationBeginning = StringTools.concat(whiteSpaces,
          "<annotation");

      // Adding the name spaces of the annotation element
      Map<String, String> otherNamespaces = annotation
          .getAnnotationNamespaces();

      for (String namespacePrefix : otherNamespaces.keySet()) {
        StringTools.append(annotationBeginning, " ", namespacePrefix,
            "=\"", otherNamespaces.get(namespacePrefix), "\"");
        annotationElement.addAttribute(namespacePrefix, otherNamespaces.get(namespacePrefix));
      }
           
      boolean allNamespacesDefined = true;
     
      // Adding the name spaces of the sbml element
View Full Code Here

      // set the indentation for the math opening tag     
      element.setIndentation(whitespaces, indent + indentCount, indentCount);

      // Creating an SMOutputElement to be sure that the previous nested element tag is closed properly.
      SMNamespace mathMLNamespace = element.getNamespace(ASTNode.URI_MATHML_DEFINITION, ASTNode.URI_MATHML_PREFIX);
      SMOutputElement mathElement = element.addElement(mathMLNamespace, "math");
      MathMLXMLStreamCompiler compiler = new MathMLXMLStreamCompiler(
          writer, createIndentationString(indent + indentCount));
      boolean isSBMLNamespaceNeeded = compiler.isSBMLNamespaceNeeded(m.getMath());

      // TODO : add all other namespaces !!

      if (isSBMLNamespaceNeeded) {
        // writing the SBML namespace
        SBMLDocument doc = null;
        SBase sbase = m.getMath().getParentSBMLObject();
        String sbmlNamespace = SBMLDocument.URI_NAMESPACE_L3V1Core;
       
        if (sbase != null) {
          doc = sbase.getSBMLDocument();
          sbmlNamespace = doc.getSBMLDocumentNamespaces().get("xmlns");
         
          if (sbmlNamespace == null) {
            logger.warn("writeMathML : the SBML namespace of this SBMLDocument" +
                " could not be found, using the default namespace (" +
                SBMLDocument.URI_NAMESPACE_L3V1Core + ") instead.");
            sbmlNamespace = SBMLDocument.URI_NAMESPACE_L3V1Core;
          }
        }
        writer.writeNamespace("sbml", sbmlNamespace);
      }
     
      mathElement.setIndentation(createIndentationString(indent + 2), indent + indentCount, indentCount);
     
      writer.writeCharacters(whitespaces);
      writer.writeCharacters("\n");

      compiler.compile(m.getMath());
View Full Code Here

    // set the indentation for the next element
    element.setIndentation(whitespaces, indent + indentCount, indentCount);

    // Creating an SMOutputElement to be sure that the previous nested element tag is closed properly.
    SMNamespace sbmlSMNamespace = element.getNamespace();
    SMOutputElement messageElement = element.addElement(sbmlSMNamespace, "message");
    messageElement.setIndentation(createIndentationString(indent + 2), indent + indentCount, indentCount);

    writer.writeCharacters(whitespaces);
    writer.writeCharacters("\n");

    XMLNodeWriter xmlNodeWriter = new XMLNodeWriter(writer,
View Full Code Here

    String whiteSpace = createIndentationString(indent);
    SMNamespace namespace = annotationElement.getNamespace(
        Annotation.URI_RDF_SYNTAX_NS, "rdf");
    annotationElement.setIndentation(whiteSpace, indent, indentCount);
    SMOutputElement rdfElement = annotationElement.addElement(namespace,
        "RDF");

    /*
     * TODO: Check which name spaces are really required and add only those;
     * particularly, if name spaces are missing and it is known from the
     * kind of RDF annotation, which name spaces are needed, these should be
     * added automatically here.
     */
    Map<String, String> rdfNamespaces = annotation.getRDFAnnotationNamespaces();

    for (String namespaceURI : rdfNamespaces.keySet()) {
     
      if (!namespaceURI.equals(namespace.getURI())) {
        writer.writeNamespace(rdfNamespaces.get(namespaceURI), namespaceURI);
      }
    }

    // Checking if all the necessary namespaces are defined
    // TODO : In fact, we could remove the rdfNamespaces map ?

    if (rdfNamespaces.get(Annotation.URI_RDF_SYNTAX_NS) == null
        || rdfNamespaces.get(Annotation.URI_RDF_SYNTAX_NS).equals("xmlns"))
    {
      // writer.writeNamespace("rdf", Annotation.URI_RDF_SYNTAX_NS); // already registered previously
      rdfNamespaces.put(Annotation.URI_RDF_SYNTAX_NS, "rdf");
    }

    if (annotation.isSetHistory() && annotation.getHistory().getNumCreators() > 0)
    {
      if (rdfNamespaces.get(JSBML.URI_PURL_ELEMENTS) == null) {
        writer.writeNamespace("dc", JSBML.URI_PURL_ELEMENTS);
        rdfNamespaces.put(JSBML.URI_PURL_ELEMENTS, "dc");
      }

      if (rdfNamespaces.get(Creator.URI_RDF_VCARD_NS) == null) {
        writer.writeNamespace("vCard", Creator.URI_RDF_VCARD_NS);
        rdfNamespaces.put(Creator.URI_RDF_VCARD_NS, "vCard");
      }
    }
   
    if (annotation.isSetHistory() && rdfNamespaces.get(JSBML.URI_PURL_TERMS) == null)
    {
      boolean isModelHistory = annotation.getParent() instanceof Model;
     
      if (isModelHistory || (annotation.getHistory().isSetCreatedDate() || annotation.getHistory().isSetModifiedDate())) {
        writer.writeNamespace("dcterms", JSBML.URI_PURL_TERMS);
        rdfNamespaces.put(JSBML.URI_PURL_TERMS, "dcterms");
      }     
    }
   
    if (annotation.getNumCVTerms() > 0)
    {
      if (rdfNamespaces.get(CVTerm.URI_BIOMODELS_NET_BIOLOGY_QUALIFIERS) == null) {
        writer.writeNamespace("bqbiol", CVTerm.URI_BIOMODELS_NET_BIOLOGY_QUALIFIERS);
        rdfNamespaces.put(CVTerm.URI_BIOMODELS_NET_BIOLOGY_QUALIFIERS, "bqbiol");
      }

      if (rdfNamespaces.get(CVTerm.URI_BIOMODELS_NET_MODEL_QUALIFIERS) == null) {
        writer.writeNamespace("bqmodel", CVTerm.URI_BIOMODELS_NET_MODEL_QUALIFIERS);
        rdfNamespaces.put(CVTerm.URI_BIOMODELS_NET_MODEL_QUALIFIERS, "bqmodel");
      }
     
    }
   
   
    rdfElement.addCharacters("\n");
    rdfElement.setIndentation(whiteSpace + createIndentationString(indentCount), indent + indentCount, indentCount);
    SMOutputElement descriptionElement = rdfElement.addElement(namespace,
        "Description");
    descriptionElement.addAttribute(namespace, "about",
        annotation.getAbout());
    descriptionElement.addCharacters("\n");
    if (annotation.isSetHistory()) {
      writeHistory(annotation.getHistory(), rdfNamespaces, writer,
          indent + 4);
    }
    if (annotation.getListOfCVTerms().size() > 0) {
      writeCVTerms(annotation.getListOfCVTerms(), rdfNamespaces, writer,
          indent + indentCount);
    }
    descriptionElement.setIndentation(whiteSpace + createIndentationString(indentCount), indent + indentCount, indentCount);
    descriptionElement.addCharacters(whiteSpace + createIndentationString(indentCount));
    annotationElement.setIndentation(whiteSpace, indent, indentCount);
    rdfElement.addCharacters("\n");
    rdfElement.addCharacters(whiteSpace);
    annotationElement.addCharacters("\n");
  }
View Full Code Here

          parser.writeElement(parentXmlObject, nextObjectToWrite);
          parser.writeNamespaces(parentXmlObject, nextObjectToWrite);
          parser.writeAttributes(parentXmlObject, nextObjectToWrite);
         
         
          SMOutputElement newOutPutElement = null;
          if (parentXmlObject.isSetName()) {
            boolean isClosedMathContainer = false, isClosedAnnotation = false;
           
            if (parentXmlObject.isSetNamespace()) {
              SMNamespace namespaceContext = smOutputParentElement
                  .getNamespace(
                      parentXmlObject.getNamespace(),
                      parentXmlObject.getPrefix());
              newOutPutElement = smOutputParentElement
                  .addElement(namespaceContext,
                      parentXmlObject.getName());
            } else {
              newOutPutElement = smOutputParentElement
                  .addElement(smOutputParentElement
                      .getNamespace(), parentXmlObject
                      .getName());
            }

            Iterator<Entry<String, String>> it = parentXmlObject
                .getAttributes().entrySet().iterator();
            while (it.hasNext()) {
              Entry<String, String> entry = it.next();
              newOutPutElement.addAttribute(entry.getKey(),
                  entry.getValue());
            }
            if (nextObjectToWrite instanceof SBase) {
              SBase s = (SBase) nextObjectToWrite;
              if (s.isSetNotes()) {
                writeNotes(s, newOutPutElement, streamWriter,
                    newOutPutElement.getNamespace()
                        .getURI(), indent + indentCount);
                elementIsNested = isClosedAnnotation = true;
              }
              if (s.isSetAnnotation()) {
                writeAnnotation(s, newOutPutElement,
                    streamWriter,
                    indent + indentCount, false);
                elementIsNested = true;
              }
              if (s.getChildCount() > 0) {
                // make sure that we'll have line breaks if an element has any sub elements.
                elementIsNested = true;
              }
            }
            if (nextObjectToWrite instanceof Constraint) {
              Constraint constraint = (Constraint) nextObjectToWrite;
              if (constraint.isSetMessage()) {
                writeMessage(constraint, newOutPutElement,
                    streamWriter, newOutPutElement
                        .getNamespace().getURI(),
                    indent + indentCount);
                elementIsNested = true;
              }
            }
            if (nextObjectToWrite instanceof MathContainer) {
              MathContainer mathContainer = (MathContainer) nextObjectToWrite;
              if (mathContainer.getLevel() > 1) {
                writeMathML(mathContainer, newOutPutElement,
                    streamWriter, indent + indentCount);
                elementIsNested = true;
              } else {
                elementIsNested = false;
              }
              isClosedMathContainer = true;
            }
            if (!elementIsNested
                && ((nextObjectToWrite instanceof Model) || (nextObjectToWrite instanceof UnitDefinition))) {
              elementIsNested = true;
            }
           
            // to allow the XML parser to prune empty element, this line should not be added in all the cases.
            if (elementIsNested) {
              newOutPutElement.addCharacters("\n");
              if (isClosedMathContainer || isClosedAnnotation) {
                newOutPutElement.addCharacters(whiteSpaces);
              }
            }

            writeSBMLElements(parentXmlObject, newOutPutElement,
                streamWriter, nextObjectToWrite, indent + indentCount);
View Full Code Here

  @Override
  @NotNull
  public SMOutputElement serialize( @NotNull SMOutputElement serializeTo, @NotNull Application object, @NotNull Lookup context ) throws IOException, XMLStreamException {
    serializeTo.addElement( ELEMENT_NAME ).addCharacters( object.getName() );

    SMOutputElement versionElement = serializeTo.addElement( ELEMENT_VERSION );
    versionSerializer.serialize( versionElement, object.getVersion(), context );

    return serializeTo;
  }
View Full Code Here

TOP

Related Classes of org.codehaus.staxmate.out.SMOutputElement

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.